浏览代码

Note - generic bills

Vijayakrishnan 4 年之前
父节点
当前提交
3bff3252b2

+ 4 - 0
app/Models/Bill.php

@@ -28,4 +28,8 @@ class Bill extends Model
     public function ally() {
         return $this->hasOne(Pro::class, 'id', 'na_pro_id');
     }
+
+    public function genericPro() {
+        return $this->hasOne(Pro::class, 'id', 'generic_pro_id');
+    }
 }

+ 1 - 0
app/Models/Note.php

@@ -36,6 +36,7 @@ class Note extends Model
     public function bills()
     {
         return $this->hasMany(Bill::class, 'note_id', 'id')
+            ->where('bill_service_type', '<>', 'GENERIC')
             ->orderBy('id', 'asc');
     }
 

+ 9 - 0
app/Models/Pro.php

@@ -78,6 +78,15 @@ class Pro extends Model
             ->where('pro_id', $this->id)
             ->where('code', 'NOT LIKE', 'CM%')
             ->where('code', 'NOT LIKE', 'RM%')
+            ->where('responsibility', '<>', 'GENERIC')
+            ->get();
+    }
+
+    public function genericRates() {
+        return ProRate::distinct('code')
+            ->where('is_active', true)
+            ->where('pro_id', $this->id)
+            ->where('responsibility', 'GENERIC')
             ->get();
     }
 

+ 78 - 0
resources/views/app/generic-bills/create_generic-bill.blade.php

@@ -0,0 +1,78 @@
+<span class="mx-2 text-secondary">|</span>
+<div moe wide relative bottom class="">
+    <a class="" href="" show start>Create Generic Bill</a>
+    <form url="/api/bill/createForGeneric">
+        <div class="mb-2">
+            <label for="" class="text-secondary text-sm">Pro</label>
+            <input type="text" class="form-control form-control-sm" value="{{$pro->displayName()}}" readonly>
+        </div>
+        <input type="hidden" name="genericProUid" value="{{$pro->uid}}">
+        @if(@$note)
+            <input type="hidden" name="optionalNoteUid" value="{{$note->uid}}">
+        @endif
+        @if(@$patient)
+            <input type="hidden" name="optionalClientUid" value="{{$patient->uid}}">
+        @endif
+        <div class="mb-2">
+            <label for="" class="text-secondary text-sm">Service</label>
+<!--            <input type="text" name="code" class="form-control form-control-sm" value="" autofocus required>-->
+            <select autofocus class="form-control" name="code" onchange="switchGenericRate(this)">
+                <option value="">-- Select Code --</option>
+                @foreach($pro->genericRates() as $genericRate)
+                    <option data-amount="{{ $genericRate->amount }}" value="{{ $genericRate->code }}">
+                        {{ $genericRate->code }} (${{ $genericRate->amount }})
+                    </option>
+                @endforeach
+            </select>
+        </div>
+        <div class="mb-2">
+            <?php $maxMinutes = 60; ?>
+            <label for="" class="text-secondary text-sm">Minutes</label>
+            <div class="mb-2">
+                <select name="numberOfUnits" class="form-control form-control-sm"
+                        onchange="calculateGenericBillAmount(this)">
+                    <option value=""> -- select -- </option>
+                    <?php for ($i = 5; $i <= $maxMinutes; $i+=5) { ?>
+                    <option value="{{ $i/60 }}" {{ $i === 30 ? 'selected' : '' }}>{{ $i }} minutes</option>
+                    <?php } ?>
+                </select>
+            </div>
+            <div class="mb-2" calculated-generic-amount></div>
+        </div>
+        <div class="mb-2">
+            <label for="" class="text-secondary text-sm">Description</label>
+            <input type="text" name="genericDescription" class="form-control form-control-sm" value="">
+        </div>
+        <div class="mb-2">
+            <label for="" class="text-secondary text-sm">Effective Date</label>
+            <input type="date" name="effectiveDate" class="form-control form-control-sm" value="{{$note->effective_dateest ? $note->effective_dateest : date('Y-m-d')}}" required>
+        </div>
+        <div class="">
+            <button class="btn btn-primary btn-sm" submit>Submit</button>
+            <button class="btn btn-default border btn-sm" cancel>Cancel</button>
+        </div>
+    </form>
+</div>
+<script>
+    (function() {
+        let selectedGenericRate = 0;
+        window.switchGenericRate = function(_trigger) {
+            selectedGenericRate = 0;
+            if($(_trigger).find('option:selected').first().length) {
+                selectedGenericRate = +($(_trigger).find('option:selected').first().attr('data-amount'));
+            }
+            calculateGenericBillAmount($(_trigger).closest('form').find('[name="numberOfUnits"]'));
+        };
+        window.calculateGenericBillAmount = function(_trigger) {
+            debugger
+            _trigger = $(_trigger);
+            let amountTarget = _trigger.closest('form').find('[calculated-generic-amount]');
+            if(!_trigger.find('option:selected').length) {
+                amountTarget.text('');
+                return;
+            }
+            let hours = +_trigger.find('option:selected').attr('value');
+            amountTarget.html('<b>Reimbursable Amount:</b> $' + (hours * selectedGenericRate).toFixed(2));
+        }
+    }).call(window);
+</script>

+ 274 - 0
resources/views/app/generic-bills/index.blade.php

@@ -0,0 +1,274 @@
+<?php
+
+use App\Models\Note;
+use App\Models\Pro;
+use App\Models\Client;
+
+/** @var Note $note */
+/** @var Pro $genericPro */
+/** @var Pro $pro */
+/** @var Client $patient */
+
+$genericBills = [];
+$genericBills = \App\Models\Bill::where('bill_service_type', 'GENERIC');
+if(@$note) {
+    $genericBills = $genericBills->where('note_id', $note->id);
+}
+if(@$patient) {
+    $genericBills = $genericBills->where('client_id', $patient->id);
+}
+if($pro->pro_type !== 'ADMIN') {
+    $genericBills = $genericBills->where('generic_pro_id', $pro->id);
+}
+$genericBills = $genericBills->orderBy('created_at', 'DESC')->get();
+?>
+
+@if(!count($genericBills))
+    <div class="p-3 border-bottom border-top d-flex align-items-center">
+        <p class="font-weight-bold mb-0 text-secondary">No generic bills</p>
+        @include('app.generic-bills.create_generic-bill')
+    </div>
+@else
+    <div class="p-3 border-bottom border-top">
+        <div class="d-flex align-items-center mb-2">
+            <p class="font-weight-bold text-secondary font-size-13 m-0">Generic Bills</p>
+            @include('app.generic-bills.create_generic-bill')
+        </div>
+            <table class="table table-sm tabe-striped mb-0 table-bordered">
+                <thead class="bg-light">
+                <tr class="text-secondary">
+                    <th class="border-bottom-0">Date</th>
+                    <th class="border-bottom-0">Service</th>
+                    <th class="border-bottom-0">Billable</th>
+                    <th class="border-bottom-0">Pro</th>
+                    <th class="border-bottom-0 screen-only">Total</th>
+                    <th class="border-bottom-0">Sign</th>
+                    @if($pro->pro_type === 'ADMIN')
+                    <th class="border-bottom-0">Verification</th>
+                    <th class="border-bottom-0">Cancellation</th>
+                    <th class="border-bottom-0 screen-only">Payment</th>
+                    @endif
+                </tr>
+                </thead>
+                <tbody>
+                @foreach ($genericBills as $bill)
+                    <tr class="{{$bill->is_cancelled ? 'bg-light text-secondary' : ''}}">
+                        <td class="text-nowrap">{{friendlier_date_time($bill->effective_date, false)}}</td>
+                        <td>{{$bill->code}}</td>
+                        <td class="">
+                            <?php
+                            $totalSeconds = $bill->number_of_units * 3600;
+                            $remainder = $totalSeconds % 60;
+                            if ($remainder !== 0) {
+                                if ($remainder < 30) {
+                                    $totalSeconds = $totalSeconds - $remainder;
+                                }
+                                else {
+                                    $totalSeconds = $totalSeconds + (60 - $remainder);
+                                }
+                            }
+                            ?>
+                            {{ time_in_hrminsec($totalSeconds) }}
+                        </td>
+                        <td class="">
+                            <div class="text-nowrap font-weight-bold text-secondary">{{ $bill->genericPro->displayName() }}</div>
+                            <div class="text-nowrap mt-1 screen-only">
+                                <span class="text-secondary">Paid: </span>
+                                <span>{{ $bill->has_generic_pro_been_paid ? 'Yes' : 'No' }}</span>
+                            </div>
+                            @if(!$bill->has_generic_pro_been_paid)
+                                <div class="text-nowrap mt-1 screen-only">
+                                    <span class="text-secondary">Expected: </span>
+                                    <span class="font-weight-bold">${{ $bill->total_expected }}</span>
+                                </div>
+                            @else
+                                <div class="text-nowrap mt-1 screen-only">
+                                    <span class="text-secondary">Amount: </span>
+                                    <span class="font-weight-bold">${{ $bill->total_paid }}</span>
+                                </div>
+                            @endif
+                        </td>
+                        <td class="pr-3 screen-only">
+                            @if($bill->has_generic_pro_been_paid)
+                                <span class="text-secondary">Paid. </span>
+                                <span class="font-weight-bold">${{ friendly_money($bill->total_paid) }}</span>
+                            @else
+                                <span class="text-secondary">Exp. </span>
+                                <span class="font-weight-bold">{{ $bill->total_expected ? '$' . friendly_money($bill->total_expected) : '-' }}</span>
+                            @endif
+                        </td>
+                        <td>
+                            @if(!$bill->is_cancelled)
+                                @if($bill->is_signed_by_generic_pro)
+                                    <div class="d-block text-secondary text-nowrap">
+                                        <i class="fa fa-check"></i>
+                                        Pro Signed
+                                    </div>
+                                @else
+                                    <div moe
+                                          class="d-block {{ $bill->generic_pro_id !== $pro->id ? 'moe-disabled' : '' }}"
+                                          title="{{ $bill->generic_pro_id !== $pro->id ? 'Only the bill\'s pro can sign' : '' }}">
+                                        <a class="" href="" show start>Sign As Pro</a>
+                                        <form url="/api/bill/signAsGenericPro">
+                                            <input type="hidden" name="uid" value="{{$bill->uid}}">
+                                            <p>Sign this bill as pro?</p>
+                                            <div class="mb-0">
+                                                <button class="btn btn-success btn-sm" submit>Sign</button>
+                                                <button class="btn btn-default border btn-sm" cancel>Cancel</button>
+                                            </div>
+                                        </form>
+                                    </div>
+                                @endif
+                            @endif
+                        </td>
+                        @if($pro->pro_type === 'ADMIN')
+                        <td> <!-- verification -->
+                            @if(!$bill->is_cancelled)
+                                @if(!$bill->is_verified)
+                                    <div class="text-warning-mellow font-weight-bold">Not Verified</div>
+                                    <div class="d-block mt-1" moe>
+                                        <a href="" show start>Mark Verified</a>
+                                        <form url="/api/bill/markAsVerified">
+                                            <input type="hidden" name="uid" value="{{$bill->uid}}">
+                                            <p>Mark As Verified?</p>
+                                            <div class="mb-0">
+                                                <button class="btn btn-success btn-sm" submit>Submit</button>
+                                                <button class="btn btn-default border btn-sm" cancel>Cancel</button>
+                                            </div>
+                                        </form>
+                                    </div>
+                                @else
+                                    <div class="text-success font-weight-bold"><i class="fa fa-check"></i> Verified</div>
+                                    <div class="d-block mt-1" moe>
+                                        <a class="" href="" show start>Undo</a>
+                                        <form url="/api/bill/undoMarkAsVerified">
+                                            <input type="hidden" name="uid" value="{{$bill->uid}}">
+                                            <p>Undo Mark As Verified?</p>
+                                            <div class="mb-0">
+                                                <button class="btn btn-success btn-sm" submit>Submit</button>
+                                                <button class="btn btn-default border btn-sm" cancel>Cancel</button>
+                                            </div>
+                                        </form>
+                                    </div>
+                                @endif
+                            @endif
+                        </td>
+                        <td>  <!-- cancellation -->
+                            @if($bill->is_cancelled)
+                                <div class="text-warning-mellow font-weight-bold">Cancelled</div>
+                                @if($bill->cancellation_memo)
+                                    <div class="text-dark text-sm font-italic my-1">{{$bill->cancellation_memo}}</div>
+                                @endif
+                                @if($bill->is_cancelled_by_administrator)
+                                    <div class="text-secondary text-sm">(by Administrator)</div>
+                                @endif
+                                <div moe class="mt-1">
+                                    <a class="" href="" show start>Update Memo</a>
+                                    <form url="/api/bill/updateCancellationMemo">
+                                        <input type="hidden" name="uid" value="{{$bill->uid}}">
+                                        <p>Update Cancellation Memo</p>
+                                        <div class="mb-2">
+                                            <textarea class="text form-control form-control-sm" name="cancellationMemo" placeholder="">{{$bill->cancellation_memo ? $bill->cancellation_memo : 'Insufficient documentation for billable service.'}}</textarea>
+                                        </div>
+                                        <div>
+                                            <button class="btn btn-success btn-sm" submit>Submit</button>
+                                            <button class="btn btn-default border btn-sm" cancel>Cancel</button>
+                                        </div>
+                                    </form>
+                                </div>
+                            @else
+                                <div class="d-block" moe relative="">
+                                    <a class="text-danger" href="" show start>Cancel</a>
+                                    <form url="/api/bill/markCancelled" right="">
+                                        <input type="hidden" name="uid" value="{{$bill->uid}}">
+                                        <p class="mb-2">Cancel this bill?</p>
+                                        <div class="mb-2">
+                                            <label class="mb-1 text-secondary">Cancellation Memo</label>
+                                            <textarea type="text" name="memo" placeholder="Memo" class="form-control form-control-sm">Insufficient documentation for billable service.</textarea>
+                                        </div>
+                                        <div class="mb-0">
+                                            <button class="btn btn-danger btn-sm" submit>Yes</button>
+                                            <button class="btn btn-default border btn-sm" cancel>No</button>
+                                        </div>
+                                    </form>
+                                </div>
+                            @endif
+
+                            @if($bill->is_cancelled && !$bill->is_cancellation_acknowledged)
+                                <div class="mt-2 text-secondary">
+                                    <i class="fa fa-exclamation-triangle"></i>
+                                    Not Acknowledged
+                                </div>
+                                <div class="d-block mt-1" moe>
+                                    <a class="" href="" show start>Ack. Cancellation</a>
+                                    <form url="/api/bill/acknowledgeCancellation">
+                                        <input type="hidden" name="uid" value="{{$bill->uid}}">
+                                        <p>Acknowledge Cancellation?</p>
+                                        <div class="mb-0">
+                                            {{--<input type="text" class="text form-control form-control-sm" name="cancellationMemo" value="{{$bill->cancellation_memo}}" placeholder=""><br>--}}
+                                            <button class="btn btn-primary btn-sm" submit>Submit</button>
+                                            <button class="btn btn-default border btn-sm" cancel>Cancel</button>
+                                        </div>
+                                    </form>
+                                </div>
+                            @endif
+
+                            @if($bill->is_cancellation_acknowledged && !$note->is_billing_marked_done)
+                                <div class="mt-2 text-secondary">
+                                    <i class="fa fa-check"></i>
+                                    Acknowledged
+                                </div>
+                                <div class="d-block mt-1" moe>
+                                    <a class="" href="" show start>Undo Cancellation Ack.</a>
+                                    <form url="/api/bill/undoAcknowledgeCancellation">
+                                        <input type="hidden" name="uid" value="{{$bill->uid}}">
+                                        <p>Undo Acknowledge Cancellation?</p>
+                                        <div class="mb-0">
+                                            <button class="btn btn-success btn-sm" submit>Submit</button>
+                                            <button class="btn btn-default border btn-sm" cancel>Cancel</button>
+                                        </div>
+                                    </form>
+                                </div>
+                            @endif
+
+                        </td>
+                        <td class="screen-only"> <!-- submit payment -->
+                            <div class="my-1">
+                                @if(!$bill->is_cancelled && !$bill->has_generic_pro_been_paid )
+                                    @if(+$bill->total_expected && $bill->is_signed_by_generic_pro)
+                                        <div class="d-block" moe relative="">
+                                            <a class="font-weight-bold" href="" show start>Submit Payment</a>
+                                            <form url="/api/bill/payGenericProAmount" right>
+                                                <input type="hidden" name="uid" value="{{$bill->uid}}">
+                                                <p>Submit Payment</p>
+                                                <div class="mb-0">
+                                                    <input type="text" class="text form-control form-control-sm" name="genericProPaymentAmount" value="{{$bill->total_expected}}" placeholder="amount"><br>
+                                                    <button class="btn btn-success btn-sm" submit>Submit</button>
+                                                    <button class="btn btn-default border btn-sm" cancel>Cancel</button>
+                                                </div>
+                                            </form>
+                                        </div>
+                                    @else
+                                        @if(!+$bill->total_expected)
+                                            <div class="mb-1 text-danger">
+                                                <i class="fa fa-exclamation-triangle"></i>
+                                                Pro expected amount is invalid
+                                            </div>
+                                        @endif
+                                        @if(!$bill->is_signed_by_generic_pro)
+                                            <div class="mb-1 text-danger">
+                                                <i class="fa fa-exclamation-triangle"></i>
+                                                Pro has not signed the bill
+                                            </div>
+                                        @endif
+                                    @endif
+                                @endif
+                            </div>
+                        </td>
+                        @endif
+                    </tr>
+                @endforeach
+                </tbody>
+            </table>
+    </div>
+@endif

+ 3 - 0
resources/views/app/patient/note/dashboard.blade.php

@@ -1990,6 +1990,9 @@
                 @endif
                 @endif
 
+                {{-- generic bills --}}
+                <?php $pro->pro_type = 1; ?>
+                @include('app.generic-bills.index', ['note' => $note, 'patient' => $patient])
 
                 <div class="border-top p-3 screen-only">
                     @if($note->addendums->count())