瀏覽代碼

Account item template impl

Vijayakrishnan Krishnan 1 周之前
父節點
當前提交
5ec2adcb6c

+ 46 - 0
app/Http/Controllers/AdminController.php

@@ -3,6 +3,7 @@
 namespace App\Http\Controllers;
 
 use App\Models\AccountingItem;
+use App\Models\AccountingItemTemplate;
 use App\Models\AppSetting;
 use App\Models\Claim;
 use App\Models\Lead;
@@ -41,6 +42,7 @@ use Illuminate\Support\Facades\Schema;
 use App\Models\AdminPatient;
 use App\Models\SupplyOrderView;
 use Illuminate\Pagination\LengthAwarePaginator;
+use Ramsey\Uuid\Uuid;
 
 class AdminController extends Controller
 {
@@ -1135,4 +1137,48 @@ class AdminController extends Controller
 
         return $html;
     }
+
+    public function accountingItemTemplates(Request $request) {
+        $records = AccountingItemTemplate::orderBy('entity_type')->get();
+        return view('app.admin.accounting-item-templates', compact('records'));
+    }
+
+    public function createAccountingItemTemplate(Request $request) {
+
+        $id = DB::select("select (coalesce(max(id), 1) + 1) as nextid from accounting_item_template");
+
+        $template = new  AccountingItemTemplate();
+        $template->id =  $id[0]->nextid;
+        $template->uid = Uuid::uuid4();
+        $template->is_active = true;
+        $template->created_at =  date('Y-m-d H:i:s');
+        $template->last_updated_at =  date('Y-m-d H:i:s');
+
+        $template->entity_type = $request->input('entityType');
+        $template->memo = $request->input('memo');
+        $template->expected_value = $request->input('expectedValue');
+        $template->received_value = $request->input('receivedValue');
+        $template->is_open = $request->input('isOpen');
+        $template->positive_or_negative = $request->input('positiveOrNegative');
+
+        $template->save();
+        return $this->pass($template->uid);
+    }
+
+    public function updateAccountingItemTemplate(Request $request) {
+
+        $template = AccountingItemTemplate::where('uid',  $request->input('uid'))->first();
+
+        $template->last_updated_at =  date('Y-m-d H:i:s');
+
+        $template->entity_type = $request->input('entityType');
+        $template->memo = $request->input('memo');
+        $template->expected_value = $request->input('expectedValue');
+        $template->received_value = $request->input('receivedValue');
+        $template->is_open = $request->input('isOpen');
+        $template->positive_or_negative = $request->input('positiveOrNegative');
+
+        $template->save();
+        return $this->pass($template->uid);
+    }
 }

+ 11 - 0
app/Models/AccountingItemTemplate.php

@@ -0,0 +1,11 @@
+<?php
+
+namespace App\Models;
+
+# use Illuminate\Database\Eloquent\Model;
+
+class AccountingItemTemplate extends Model
+{
+    protected $table = 'accounting_item_template';
+
+}

+ 117 - 0
resources/views/app/admin/accounting-item-templates.blade.php

@@ -0,0 +1,117 @@
+@extends ('layouts/template')
+
+@section('content')
+    <?php
+    function selectIf($_cond) {
+        return $_cond ? 'selected' : '';
+    }
+    if(request()->input('_ql')) \Illuminate\Support\Facades\DB::enableQueryLog();
+    ?>
+    <style>
+        .posneg {
+            width: 10px;
+            display: inline-block;
+            text-align: center;
+            font-size: 12px !important;
+            font-weight: bold;
+        }
+    </style>
+    <div class="p-3 mcp-theme-1" id="accounting-items-container">
+        <div class="card">
+
+            <div class="card-header px-2 py-2 d-flex align-items-center">
+                <strong class="mr-4 font-size-14">
+                    <i class="fas fa-user"></i>
+                    Accounting Item Templates
+                </strong>
+                @include('app.patient.partials.create-edit-accounting-item-template')
+            </div>
+            <div class="card-body p-0">
+                <table class="table table-sm table-striped border-0 mb-0">
+                    <thead class="bg-light">
+                    <tr>
+                        <th class="border-bottom-0 width-200px">Created</th>
+                        <th class="border-bottom-0">Context</th>
+                        <th class="border-bottom-0 width-60px text-right">Expected</th>
+                        <th class="border-bottom-0 width-60px text-right">Actual</th>
+                        <th class="border-bottom-0 text-center">Open</th>
+                        <th class="border-bottom-0">Memo</th>
+                        <th class="border-bottom-0">Active</th>
+                        <th class="border-bottom-0">&nbsp;</th>
+                    </tr>
+                    </thead>
+                    <tbody>
+                    @foreach($records as $record)
+                        <tr>
+                            <td class="">
+                                {{friendly_date_time($record->created_at)}}
+                            </td>
+                            <td class="">
+                                {{$record->entity_type}}
+                            </td>
+                            <td class="border-bottom-0 width-60px text-right">
+                                @if($record->expected_value)
+                                    <span class="posneg">{{$record->positive_or_negative == 0 ? '+' : '-'}}</span>
+                                    {{'$' . $record->expected_value}}
+                                @endif
+                            </td>
+                            <td class="border-bottom-0 width-60px text-right">
+                                @if($record->received_value)
+                                    <span class="posneg">{{$record->positive_or_negative == 0 ? '+' : '-'}}</span>
+                                    {{'$' . $record->received_value}}
+                                @endif
+                            </td>
+                            <td class="border-bottom-0 text-center">
+                                {{$record->is_open ? 'Yes' : 'No'}}
+                            </td>
+                            <td class="border-bottom-0">
+                                {{$record->memo ? $record->memo : ''}}
+                            </td>
+                            <td class="border-bottom-0">
+                                {{$record->is_active ? 'Yes' : 'No'}}
+                            </td>
+                            <td class="border-bottom-0">
+                                <div class="d-flex">
+                                    @include('app.patient.partials.create-edit-accounting-item-template', ['record' => $record])
+                                    <span class="mx-2 text-secondary">|</span>
+                                    @if($record->is_active)
+                                        <div moe relative="">
+                                            <a start show class="py-0 mb-3">Deactivate</a>
+                                            <form url="/api/accountingItem/deactivate" class="mcp-theme-1" right="">
+                                                <input type="hidden" name="uid" value="{{$record->uid}}">
+                                                <p>Deactivate this record?</p>
+                                                <div>
+                                                    <button submit class="btn btn-sm btn-primary mr-1">Submit</button>
+                                                    <button cancel class="btn btn-sm btn-default border">Cancel</button>
+                                                </div>
+                                            </form>
+                                        </div>
+                                    @else
+                                        <div moe relative="">
+                                            <a start show class="py-0 mb-3">Reactivate</a>
+                                            <form url="/api/accountingItem/reactivate" class="mcp-theme-1" right="">
+                                                <input type="hidden" name="uid" value="{{$record->uid}}">
+                                                <p>Reactivate this record?</p>
+                                                <div>
+                                                    <button submit class="btn btn-sm btn-primary mr-1">Submit</button>
+                                                    <button cancel class="btn btn-sm btn-default border">Cancel</button>
+                                                </div>
+                                            </form>
+                                        </div>
+                                    @endif
+                                </div>
+                            </td>
+                        </tr>
+                    @endforeach
+                    </tbody>
+                </table>
+            </div>
+
+        </div>
+    </div>
+
+    <?php
+    if(request()->input('_ql')) printQueryLog(DB::getQueryLog());
+    ?>
+@endsection
+

+ 73 - 0
resources/views/app/patient/partials/create-edit-accounting-item-template.blade.php

@@ -0,0 +1,73 @@
+<?php
+$ep = !@$record ? "/papi/accountingItemTemplate/create" : '/papi/accountingItemTemplate/update';
+?>
+<div moe relative id="create-edit-accounting-item-template-container">
+    <a href="" start show class="">{{!@$record ? 'Create' : 'Update'}}</a>
+    <form url="{{$ep}}" class="mcp-theme-1" {{!@$record ? '' : 'right'}}>
+        @if(@$record)
+            <input type="hidden" name="uid" value="{{@$record->uid}}" />
+        @endif
+
+        <div class="mb-2">
+            <label class="text-sm text-secondary mb-1">Applies To:</label>
+            <select name="entityType" class="form-control form-control-sm" required>
+                <option value=""> --select-- </option>
+                <option value="Note" {{@$record->entity_type == 'Note' ? 'selected' : ''}}>Note</option>
+                <option value="CareMonth" {{@$record->entity_type == 'CareMonth' ? 'selected' : ''}}>CareMonth</option>
+                <option value="Bill" {{@$record->entity_type == 'Bill' ? 'selected' : ''}}>Bill</option>
+                <option value="SupplyOrder" {{@$record->entity_type == 'SupplyOrder' ? 'selected' : ''}}>SupplyOrder</option>
+            </select>
+        </div>
+
+        <input type="hidden" name="positiveOrNegative" value="">
+
+        <div class="mb-2">
+            <label class="text-sm text-secondary mb-1">Expected:</label>
+            <input type="number" name="expectedValue" value="{{@$record->expected_value}}" class="form-control form-control-sm">
+        </div>
+        <div class="mb-2">
+            <label class="text-sm text-secondary mb-1">Received/Actual:</label>
+            <input type="number" name="receivedValue" value="{{@$record->received_value}}" class="form-control form-control-sm">
+        </div>
+        <div class="mb-2">
+            <label class="text-sm text-secondary mb-1">Is Open?</label>
+            <select name="isOpen" class="form-control form-control-sm">
+                <option value=""> --select-- </option>
+                <option value="1" {{@$record->is_open == 1 ? 'selected' : ''}}>Yes</option>
+                <option value="0" {{@$record->is_open == 0 ? 'selected' : ''}}>No</option>
+            </select>
+        </div>
+        <div class="mb-2">
+            <label class="text-sm text-secondary mb-1">Memo:</label>
+            <textarea name="memo" class="form-control form-control-sm">{{@$record->memo}}</textarea>
+        </div>
+        <div class="mb-2">
+            <button class="btn btn-sm btn-primary" submit>Submit</button>
+            <button class="btn btn-sm btn-default border" close>Close</button>
+        </div>
+    </form>
+</div>
+<script>
+    (function() {
+        function init() {
+            $('#create-edit-accounting-item-template-container')
+                .find('[name="entityType"]')
+                .off('change')
+                .on('change', function() {
+                    let val = $(this).val(),
+                        posNeg = $(this).closest('form').find('[name="positiveOrNegative"]');
+                    if(!val) {
+                        posNeg.val('');
+                        return;
+                    }
+                    if(val === 'Note' || val === 'CareMonth') {
+                        posNeg.val('0');
+                    }
+                    else {
+                        posNeg.val('1');
+                    }
+                });
+        }
+        addMCInitializer('create-edit-accounting-item-template-container', init, '#create-edit-accounting-item-template-container');
+    }).call(window);
+</script>

+ 41 - 2
resources/views/app/patient/partials/create-edit-accounting-item.blade.php

@@ -1,7 +1,7 @@
 <?php
 $ep = !@$record ? "/api/accountingItem/createFor{$entityType}" : '/api/accountingItem/update';
 ?>
-<div moe relative>
+<div moe relative id="create-edit-accounting-item-container">
     <a href="" start show class="">{{!@$record ? 'Create' : 'Update'}}</a>
     <form url="{{$ep}}" class="mcp-theme-1" {{!@$record ? '' : 'right'}}>
         @if(!@$record)
@@ -9,6 +9,25 @@ $ep = !@$record ? "/api/accountingItem/createFor{$entityType}" : '/api/accountin
         @else
             <input type="hidden" name="uid" value="{{@$record->uid}}" />
         @endif
+
+        @if(!@$record)
+            <?php
+                $templates = \App\Models\AccountingItemTemplate::where('entity_type', $entityType)->get();
+            ?>
+            <div class="mb-2">
+                <label class="text-sm text-secondary mb-1">Template</label>
+                <select name="itemTemplate" class="form-control form-control-sm">
+                    <option value="">None/Custom</option>
+                    @foreach($templates as $t)
+                        <?php
+                            $tVal = implode('___', [$t->expected_value, $t->received_value, $t->memo, $t->is_open]);
+                        ?>
+                        <option value="{!! $tVal !!}">{{$t->memo}}</option>
+                    @endforeach
+                </select>
+            </div>
+        @endif
+
         <div class="mb-2">
             <label class="text-sm text-secondary mb-1">Expected:</label>
             <input type="number" name="expectedValue" value="{{@$record->expected_value}}" class="form-control form-control-sm">
@@ -34,4 +53,24 @@ $ep = !@$record ? "/api/accountingItem/createFor{$entityType}" : '/api/accountin
             <button class="btn btn-sm btn-default border" close>Close</button>
         </div>
     </form>
-</div>
+</div>
+<script>
+    (function() {
+        function init() {
+            let container = $('#create-edit-accounting-item-container');
+            container
+                .find('[name="itemTemplate"]')
+                .off('change')
+                .on('change', function() {
+                    let val = $(this).val();
+                    if(!val) return;
+                    let parts = val.split('___');
+                    container.find('[name="expectedValue"]').val(+parts[0]);
+                    container.find('[name="receivedValue"]').val(+parts[1]);
+                    container.find('[name="isOpen"]').val(parts.length < 4 || !+parts[3] ? 0 : 1);
+                    container.find('[name="memo"]').val(parts[2]);
+                });
+        }
+        addMCInitializer('create-edit-accounting-item', init, '#create-edit-accounting-item-container');
+    }).call(window);
+</script>

+ 1 - 0
resources/views/layouts/template.blade.php

@@ -239,6 +239,7 @@
                         <div class="dropdown-menu mcp-theme-1 no-overflow-menu p-0" aria-labelledby="practice-management">
 
                             <a class="dropdown-item" href="{{ route('accounting-items') }}">Accounting Items</a>
+                            <a class="dropdown-item" href="{{ route('accounting-item-templates') }}">Accounting Item Templates</a>
                             <a class="dropdown-item" href="{{ route('practice-management.claims-report') }}">Claims Report</a>
                             <a class="dropdown-item" href="{{ route('practice-management.problems-report') }}">Problems Report</a>
                             <a class="dropdown-item" href="{{ route('practice-management.coverages') }}">Coverage Center</a>

+ 4 - 0
routes/web.php

@@ -704,6 +704,10 @@ Route::middleware('pro.auth')->group(function () {
     Route::get('/manage-accounting-items-for-bill/{bill}', 'AdminController@manageAccountingItemsForBill')->name('manage-accounting-items-for-bill');
 
     Route::get('/accounting-items', 'AdminController@accountingItems')->name('accounting-items');
+    Route::get('/accounting-item-templates', 'AdminController@accountingItemTemplates')->name('accounting-item-templates');
+    Route::post('/papi/accountingItemTemplate/create', 'AdminController@createAccountingItemTemplate')->name('create-accounting-item-template');
+    Route::post('/papi/accountingItemTemplate/update', 'AdminController@updateAccountingItemTemplate')->name('update-accounting-item-template');
+
 
     Route::post('/put-claim-property', 'AdminController@putClaimProperty')->name('put-claim-property');
     Route::post('/put-app-setting', 'AdminController@putAppSetting')->name('put-app-setting');