Ver Fonte

Added new flow

Samson Mutunga há 3 meses atrás
pai
commit
53aec769ee

+ 29 - 0
app/Http/Controllers/PatientController.php

@@ -33,6 +33,7 @@ use App\Models\SectionTemplate;
 use App\Models\Shipment;
 use App\Models\SupplyOrder;
 use App\Models\Ticket;
+use App\Models\PatientRequest;
 use Illuminate\Http\Request;
 use Illuminate\Support\Facades\DB;
 use Illuminate\Support\Facades\File;
@@ -906,5 +907,33 @@ class PatientController extends Controller
         return $this->pass($records);
     }
 
+    public function patientRequests(Request $request, Client $patient)
+    {
+        $patientRequests = PatientRequest::where('client_id', $patient->id)->paginate(30);
+        $data = [
+            'patientRequests' => $patientRequests,
+            'patient' => $patient
+        ];
+        return view('app.patient.patient-requests', $data);
+    }
+
+    public function patientRequestCreateInvoice(Request $request, Client $client){
+        $params = $request->all();
+        $response = $this->callJavaApi('/invoice/create', $params);
+
+        if(!$response['success']){
+            return $this->fail(@$response['message']);
+        }
+
+        $invoiceUid = $response['data'];
+
+        $invoice = Invoice::where('uid', $invoiceUid)->first();
+        $patientRequest = PatientRequest::where('uid', $params['patientRequestUid'])->first();
+        $patientRequest->invoice_id = $invoice->id;
+        $patientRequest->save();
+
+        return $this->pass();
+    }
+
     
 }

+ 22 - 0
app/Models/PatientRequest.php

@@ -0,0 +1,22 @@
+<?php
+
+namespace App\Models;
+
+# use Illuminate\Database\Eloquent\Model;
+
+class PatientRequest extends Model
+{
+    protected $table = 'patient_request';
+
+    public function client() {
+        return $this->hasOne(Client::class, 'id', 'client_id');
+    }
+    public function customer() {
+        return $this->hasOne(Customer::class, 'id', 'customer_id');
+    }
+
+    public function invoice() {
+        return $this->hasOne(Invoice::class, 'id', 'invoice_id');
+    }
+
+}

+ 1 - 1
resources/views/app/invoice-center/ic-pay-invoice.blade.php

@@ -26,7 +26,7 @@
                 <tbody class="font-weight-normal">
                 <tr>
                     <td>{{friendly_date($invoice->created_at)}}</td>
-                    <td>{{$company->name}}</td>
+                    <td>{{@$company->name}}</td>
                     <td>{{$invoice->description}}</td>
                     <td class="font-weight-bold text-dark">${{!is_null($invoice->amount) ? $invoice->amount : 0}}</td>
                     <td class="font-weight-bold text-success">${{!is_null($invoice->paid) ? $invoice->paid : 0}}</td>

+ 1 - 1
resources/views/app/patient/company-client/partials/customer-invoices.blade.php

@@ -33,7 +33,7 @@ $invoices = $customer->invoices;
                 @foreach ($invoices as $record)
                     <tr>
                         <td>{{ $i++ }}</td>
-                        <td>{{ $record->customer->company->name }}</td>
+                        <td>{{ $record->customer->company ? $record->customer->company->name : '---' }}</td>
                         <td>{{ friendly_date($record->created_at) }}</td>
                         <td>${{ is_null($record->amount) ? 0 : $record->amount }}
                             <div moe relative class="ml-1">

+ 105 - 0
resources/views/app/patient/patient-requests.blade.php

@@ -0,0 +1,105 @@
+@extends ('layouts.patient')
+<?php
+// include the Diff class
+?>
+
+@section('inner-content')
+    <div id="patient-requests">
+        <h4 class="font-weight-bold m-0 mb-3">Patient Requests</h4>
+
+        <table class="table table-sm table-striped">
+            <thead>
+                <tr>
+                    <th>Treatment</th>
+                    <th>Amount</th>
+                    <th>Paid</th>
+                    <th>Balance</th>
+                    <th>Status</th>
+                    <th>Invoice</th>
+                    <th>Actions</th>
+                </tr>
+            </thead>
+            <tbody>
+                @foreach ($patientRequests as $patientRequest)
+                    <tr>
+                        <td>{{ $patientRequest->title }}</td>
+                        <td>${{ $patientRequest->amount }}</td>
+                        <td>${{ $patientRequest->invoice ? $patientRequest->invoice->paid : '--' }}</td>
+                        <td>${{ $patientRequest->invoice ? $patientRequest->invoice->balance : '--' }}</td>
+                        <td>{{ $patientRequest->status }}</td>
+                        <td>
+                            @if ($patientRequest->invoice)
+                                <a href="#" data-invoice-uid="{{ $patientRequest->invoice->uid }}" data-uid="{{ $patientRequest->invoice->customer->uid }}"
+                        class="generate-and-copy-ic-pay-url" native target="_blank">Copy Pay Link</a>
+                            @else
+                                <div moe>
+                                    <a href="" start show>
+                                        + Create Invoice
+                                    </a>
+
+                                    <form url="{{ route('patient-request-create-invoice') }}" class="mcp-theme-1">
+                                        @csrf
+                                        <input type="hidden" name="customerUid"
+                                            value="{{ $patientRequest->customer->uid }}" />
+                                        <input type="hidden" name="patientRequestUid" value="{{ $patientRequest->uid }}" />
+                                        <p class="mb-2 text-secondary font-weight-bold">Add Invoice</p>
+                                        <div class="mb-2">
+                                            <label class="text-sm text-secondary mb-1">Amount</label>
+                                            <input type="text" name="amount" value="{{ $patientRequest->amount }}"
+                                                autocomplete="off" class="form-control form-control-sm" required>
+                                        </div>
+                                        <div class="mb-2">
+                                            <label class="text-sm text-secondary mb-1">Description</label>
+                                            <textarea rows="2" name="description" autocomplete="off" class="form-control form-control-sm" required></textarea>
+                                        </div>
+                                        <div>
+                                            <button submit class="btn btn-sm btn-primary mr-2">Submit</button>
+                                            <button cancel class="btn btn-sm btn-default border">Cancel</button>
+                                        </div>
+                                    </form>
+                                </div>
+                            @endif
+                        </td>
+                        <td>
+
+                        </td>
+                    </tr>
+                @endforeach
+            </tbody>
+        </table>
+    </div>
+
+    <script>
+    (function($) {
+        var patientRequestsComponent = {
+            init: function() {
+                let parentSegment = $('body');
+                parentSegment.find('.copy-target')
+                    .off('click.copy-target')
+                    .on('click.copy-target', function() {
+                        copyTextToClipboard($(this).attr('data-target'));
+                        return false;
+                    });
+
+                parentSegment.find('.generate-and-copy-ic-pay-url')
+                    .off('click.generate-and-copy-ic-pay-url')
+                    .on('click.generate-and-copy-ic-pay-url', function() {
+                        $.post('/api/session/proLogInAsCustomer', {
+                            customerUid: $(this).attr('data-uid')
+                        }, _data => {
+                            if (!hasResponseError(_data)) {
+                                copyTextToClipboard('{{ config('app.url') }}/ic/pay/' + $(this)
+                                    .attr(
+                                        'data-invoice-uid') + '/' + _data.data);
+                                return false;
+                            }
+                        });
+                        return false;
+                    });
+            }
+        };
+        patientRequestsComponent.init();
+    })(jQuery);
+</script>
+
+@endsection

+ 3 - 0
resources/views/layouts/patient.blade.php

@@ -242,6 +242,9 @@ $patientCompanyClients = $patient->companyClients;
 								<li class="nav-item">
 									<a class="nav-link {{ strpos($routeName, 'patients.view.claims-resolver') === 0 ? 'active' : '' }}" href="{{ route('patients.view.claims-resolver', $patient) }}">Claims Resolver</a>
 								</li>
+								<li class="nav-item">
+									<a class="nav-link {{ strpos($routeName, 'patients.view.patient-requests') === 0 ? 'active' : '' }}" href="{{ route('patients.view.patient-requests', $patient) }}">Patient Requests</a>
+								</li>
 							</ul>
 						</li>
 					@endif

+ 4 - 0
routes/web.php

@@ -679,6 +679,8 @@ Route::middleware('pro.auth')->group(function () {
             // CLAIMS RESOLVER
             Route::get('claims-resolver', 'PatientController@claimsResolver')->name('claims-resolver');
 
+            Route::get('patient-requests', 'PatientController@patientRequests')->name('patient-requests');
+
             Route::get('accounts', 'PatientController@accounts')->name('accounts');
 
             Route::get('companies', 'PatientController@companies')->name('companies');
@@ -856,6 +858,8 @@ Route::middleware('pro.auth')->group(function () {
 
     Route::get('check-if-cpt-code-is-submitted', 'PatientController@checkIfCptCodeIsSubmitted')->name('check-if-cpt-code-is-submitted');
 
+    Route::post('patient-request-create-invoice', 'PatientController@patientRequestCreateInvoice')->name('patient-request-create-invoice');
+
 });
 
 Route::get("/get-default-section-data/{patientID}/{sectionTemplateID}", 'NoteController@getDefaultValueForSection')->name('get_default_section_data');