Просмотр исходного кода

Customer financial transactions

Samson Mutunga 1 год назад
Родитель
Сommit
bfb5e77abf

+ 5 - 0
app/Http/Controllers/CustomerController.php

@@ -16,6 +16,11 @@ class CustomerController extends Controller
         return view('app.patient.company-client.customers', compact('patient', 'customers'));
     }
 
+    public function customersList(Request $request, Client $patient){
+        $customers = Customer::where('client_id', $patient->id)->paginate(25);
+         return view('app.patient.company-client.customers', compact('patient', 'customers'));
+     }
+
     public function customer(Request $request, Client $patient, $slug){
         $customer = Customer::where('slug', $slug)->first();
          return view('app.patient.company-client.customer', compact('patient', 'customer'));

+ 5 - 1
app/Models/Customer.php

@@ -23,7 +23,11 @@ class Customer extends Model
     }
 
     public function customerTransactions() {
-        return $this->hasMany(CustomerTransaction::class, 'customer_id', 'id')->orderBy('created_at', 'ASC');
+        return $this->hasMany(CustomerTransaction::class, 'customer_id', 'id')->orderBy('created_at', 'DESC');
+    }
+
+    public function customerFinancialTransactions() {
+        return $this->hasMany(FinancialTransaction::class, 'customer_id', 'id')->orderBy('created_at', 'DESC');
     }
 
     public function paymentMethods() {

+ 14 - 0
app/Models/FinancialTransaction.php

@@ -0,0 +1,14 @@
+<?php
+
+namespace App\Models;
+
+# use Illuminate\Database\Eloquent\Model;
+
+class FinancialTransaction extends Model
+{
+    protected $table = 'financial_transaction';
+
+    public function customer() {
+        return $this->hasOne(Customer::class, 'id', 'customer_id');
+    }
+}

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

@@ -2,7 +2,7 @@
 @section('content')
 <div class="container mcp-theme-1">
     <div class="d-flex align-items-baseline mt-3 mb-2">
-        <h3 class="font-size-16 font-weight-bold text-dark">{{$customer->client->displayName()}} / {{$company->name}}</h3>
+        <h3 class="font-size-16 font-weight-bold text-dark">{{$customer->client->displayName()}} / {{isset($company) ? $company->name : '(No compamy)'}}</h3>
         <a href="{{config('app.stagfe6_url')}}" class="ml-auto text-nowrap">
             <i class="fa fa-power-off"></i>
             Exit

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

@@ -10,7 +10,7 @@
     <div moe id="gift-card-moe" style="display: none">
         <form url="/api/giftCard/redeem" show>
             <input type="hidden" name="customerUid" value="{{$customer->uid}}">
-            <p class="mb-2">If you have a voucher from {{$company->name}}, please enter its code below:</p>
+            <p class="mb-2">If you have a voucher from {{isset($company) ? $company->name: '(no company)'}}, please enter its code below:</p>
             <div class="mb-2">
                 <input type="text" name="code" placeholder="Code" class="form-control form-control-sm">
             </div>

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

@@ -10,7 +10,7 @@
             <div>
                 <div class="d-flex align-items-end pb-3">
                     <h4 class="font-weight-bold m-0">
-                        Customer: {{ $customer->company->name }}
+                        Customer: {{ $customer->company ? $customer->company->name : '(No linked company)' }}
                     </h4>
                 </div>
             </div>
@@ -22,6 +22,9 @@
 <div class="row">
     <div class="col-md-8">
         @include('app.patient.company-client.partials.customer-invoices')
+        <div class="mt-4">
+            @include('app.patient.company-client.partials.customer-financial-transactions')
+        </div>        
     </div>
     <div class="col-md-4">
         @include('app.patient.company-client.partials.customer-payment-methods')

+ 1 - 1
resources/views/app/patient/company-client/customers.blade.php

@@ -35,7 +35,7 @@
             <tbody>
                 @foreach($customers as $customer)
                     <tr>
-                        <td>{{ $customer->company->name }}</td>
+                        <td>{{ $customer->company ? $customer->company->name : '--' }}</td>
                         <td>${{ friendly_money($customer->customer_balance) }}</td>
                         <td>${{ friendly_money($customer->pending_invoices_balance_total) }}</td>
                         <td>{{ friendly_date($customer->created_at) }}</td>

+ 76 - 0
resources/views/app/patient/company-client/partials/customer-financial-transactions.blade.php

@@ -0,0 +1,76 @@
+<?php
+$customerFinancialTransactions = $customer->customerFinancialTransactions;
+?>
+<div id="generic-customer-invoices" class="">
+    <div class="d-flex align-items-end pb-1">
+        <h4 class="font-weight-bold m-0">
+            Customer Financial Transactions
+        </h4>
+    </div>
+    @if (!count($customerFinancialTransactions))
+    <div class="border p-2">This customer does not have any financial transactions yet.</div>
+    @else
+    <table class="table table-sm table-bordered table-striped m-0">
+        <thead>
+            <tr>
+                <th class="border-bottom-0">Created At</th>
+                <th class="border-bottom-0">Amount</th>
+                <th class="border-bottom-0">Is Captured?</th>
+                <th class="border-bottom-0"></th>
+            </tr>
+        </thead>
+        <tbody>
+            @foreach ($customerFinancialTransactions as $record)
+            <tr>
+                <td>{{ friendly_date($record->created_at) }}</td>
+                <td>${{ friendly_money($record->amount) }}</td>
+                <td>{{ $record->is_captured ? 'YES':'NO' }}</td>
+                <td>
+                    @if($record->was_refunded)
+                    <?php
+                        $refundDetails = json_decode($record->refund_detail_json);
+                        $refundedAmount = floatval($refundDetails->amount)/100;
+                    ?>
+                    <div class="d-flex flex-column">
+                        <span><b>Refunded:</b> ${{ friendly_money($refundedAmount) }}</span>
+                        <span><b>Reason:</b> {{ $refundDetails->reason }}</span>
+                    </div>
+                    @elseif($record->is_captured)
+                    <div moe class="mr-2">
+                        <a href="" start show>Refund</a>
+                        <form url="/api/financialTransaction/refund" class="mcp-theme-1" right>
+                            <input type="hidden" name="uid" value="{{ $record->uid }}">
+                            <div class="mb-2">
+                                <label class="text-sm text-secondary mb-1">Amount</label>
+                                <input type="text" name="amount" autocomplete="off" class="form-control form-control-sm" value="{{ $record->amount }}" 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">Refund</button>
+                                <button cancel class="btn btn-sm btn-default border">Cancel</button>
+                            </div>
+                        </form>
+                    </div>
+                    @else
+                    <div moe class="mr-2">
+                        <a href="" start show>Capture</a>
+                        <form url="/api/financialTransaction/captureAuthorizedTransaction" class="mcp-theme-1" right>
+                            <p class="mb-2 text-nowrap">Are you sure?</p>
+                            <input type="hidden" name="uid" value="{{ $record->uid }}">
+                            <div>
+                                <button submit class="btn btn-sm btn-primary mr-2">Capture</button>
+                                <button cancel class="btn btn-sm btn-default border">Cancel</button>
+                            </div>
+                        </form>
+                    </div>
+                    @endif
+                </td>
+            </tr>
+            @endforeach
+        </tbody>
+    </table>
+    @endif
+</div>

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

@@ -1,8 +1,8 @@
 <?php
 $invoices = $customer->invoices;
 ?>
-<div id="generic-customer-invoices" class="">
-    <div class="d-flex align-items-end pb-3">
+<div id="generic-customer-invoices" class="mt-3">
+    <div class="d-flex align-items-end pb-1">
         <h4 class="font-weight-bold m-0">
             Invoices
         </h4>

+ 1 - 1
routes/web.php

@@ -588,7 +588,7 @@ Route::middleware('pro.auth')->group(function () {
             Route::get('show-set-company-client', [CompanyClientController::class, 'showSetCompanyClient'])->name('show-set-company-client');
             Route::get('show-set-default-company-client', [CompanyClientController::class, 'showSetDefaultCompanyClient'])->name('show-set-default-company-client');
             Route::post('set-default-company-client', [CompanyClientController::class, 'setDefaultCompanyClient'])->name('set-default-company-client');
-            Route::middleware(['client.has-company-client'])->group(function () {
+            Route::middleware([])->group(function () {
                 Route::get('customers', [CustomerController::class, 'customers'])->name('customers');
                 Route::get('customers/view/{slug}', [CustomerController::class, 'customer'])->name('customer');
                 Route::middleware(['client.has-default-company-client'])->group(function () {