Bladeren bron

Invoice-center - cross linkage

Vijayakrishnan 3 jaren geleden
bovenliggende
commit
e06730ce18

+ 42 - 11
app/Http/Controllers/InvoiceController.php

@@ -43,6 +43,7 @@ use App\Models\ClientMeasurementDaysPerMonth;
 use App\Models\ClientBDTDevice;
 use App\Models\ClientMemo;
 use Carbon\Carbon;
+use Cassandra\Custom;
 use Illuminate\Pagination\LengthAwarePaginator;
 use Illuminate\Support\Facades\DB;
 use Illuminate\Support\Facades\Http;
@@ -64,23 +65,55 @@ class InvoiceController extends Controller
     }
 
     public function giftCards(Request $request) {
-        $records = GiftCard::orderBy('created_at', 'DESC')->paginate();
-        return view ('app.invoice-center.gift-cards', compact('records'));
+        $records = GiftCard::orderBy('created_at', 'DESC');
+        $company = null;
+        if($request->input('companyUid')) {
+            $company = Company::where('uid', $request->input('companyUid'))->first();
+            if($company) {
+                $records = $records->where('company_id', $company->id);
+            }
+        }
+        $records = $records->paginate();
+        return view ('app.invoice-center.gift-cards', compact('records', 'company'));
     }
 
     public function invoices(Request $request) {
-        $records = Invoice::orderBy('created_at', 'DESC')->paginate();
-        return view ('app.invoice-center.invoices', compact('records'));
+        $records = Invoice::orderBy('created_at', 'DESC');
+        $customer = null;
+        if($request->input('customerUid')) {
+            $customer = Customer::where('uid', $request->input('customerUid'))->first();
+            if($customer) {
+                $records = $records->where('customer_id', $customer->id);
+            }
+        }
+        $records = $records->paginate();
+        return view ('app.invoice-center.invoices', compact('records', 'customer'));
     }
 
     public function customerTransactions(Request $request) {
-        $records = CustomerTransaction::orderBy('created_at', 'DESC')->paginate();
-        return view ('app.invoice-center.customer-transactions', compact('records'));
+        $records = CustomerTransaction::orderBy('created_at', 'DESC');
+        $customer = null;
+        if($request->input('customerUid')) {
+            $customer = Customer::where('uid', $request->input('customerUid'))->first();
+            if($customer) {
+                $records = $records->where('customer_id', $customer->id);
+            }
+        }
+        $records = $records->paginate();
+        return view ('app.invoice-center.customer-transactions', compact('records', 'customer'));
     }
 
     public function invoiceTransactions(Request $request) {
-        $records = InvoiceTransaction::orderBy('created_at', 'DESC')->paginate();
-        return view ('app.invoice-center.invoice-transactions', compact('records'));
+        $records = InvoiceTransaction::orderBy('created_at', 'DESC');
+        $invoice = null;
+        if($request->input('invoiceUid')) {
+            $invoice = Invoice::where('uid', $request->input('invoiceUid'))->first();
+            if($invoice) {
+                $records = $records->where('invoice_id', $invoice->id);
+            }
+        }
+        $records = $records->paginate();
+        return view ('app.invoice-center.invoice-transactions', compact('records', 'invoice'));
     }
 
     public function companySuggestJSON(Request $request) {
@@ -183,9 +216,7 @@ ORDER BY client.name_first, client.name_last",
         foreach ($customer->invoices as $invoice) {
             $invoices[] = [
                 "uid" => $invoice->uid,
-                "text" => '$' . $invoice->amount .
-                    ($invoice->description ? ' | ' . substr($invoice->description, 0, 15) : '') .
-                    ' | ' . friendly_date_time($invoice->created_at)
+                "text" => $invoice->displayName()
             ];
         }
         return json_encode([

+ 6 - 0
app/Models/Invoice.php

@@ -8,6 +8,12 @@ class Invoice extends Model
 {
     protected $table = 'invoice';
 
+    public function displayName() {
+        return '$' . $this->amount .
+        ($this->description ? ' | ' . substr($this->description, 0, 15) : '') .
+        ' | ' . friendly_date_time($this->created_at);
+    }
+
     public function customer() {
         return $this->hasOne(Customer::class, 'id', 'customer_id');
     }

+ 8 - 4
resources/views/app/invoice-center/customer-transactions.blade.php

@@ -10,7 +10,7 @@
                 <p class="mb-2 text-secondary font-weight-bold text-nowrap">Add Manual Plus Transaction</p>
                 <div class="mb-2">
                     <label class="text-sm text-secondary mb-1">Customer</label>
-                    <input type="hidden" name="customerUid">
+                    <input type="hidden" name="customerUid" value="{{@$customer->uid}}">
                     <input type="text"
                            name="customerName"
                            target-key="uid"
@@ -19,6 +19,8 @@
                            class="form-control form-control-sm"
                            stag-suggest
                            stag-suggest-ep="/customer-suggest"
+                           value="{{@$customer && $customer->client ? @$customer->client->displayName() : ''}}"
+                           {{@$customer ? 'disabled readonly' : ''}}
                            required>
                 </div>
                 <div class="mb-2">
@@ -50,7 +52,7 @@
                 <p class="mb-2 text-secondary font-weight-bold text-nowrap">Add Manual Minus Transaction</p>
                 <div class="mb-2">
                     <label class="text-sm text-secondary mb-1">Customer</label>
-                    <input type="hidden" name="customerUid">
+                    <input type="hidden" name="customerUid" value="{{@$customer->uid}}">
                     <input type="text"
                            name="customerName"
                            target-key="uid"
@@ -59,6 +61,8 @@
                            class="form-control form-control-sm"
                            stag-suggest
                            stag-suggest-ep="/customer-suggest"
+                           value="{{@$customer && $customer->client ? @$customer->client->displayName() : ''}}"
+                           {{@$customer ? 'disabled readonly' : ''}}
                            required>
                 </div>
                 <div class="mb-2">
@@ -81,13 +85,13 @@
                     <button cancel class="btn btn-sm btn-default border">Cancel</button>
                 </div>
             </form>
-        </div>1
+        </div>
     </div>
     @if(count($records))
         <table class="table table-sm table-bordered table-striped">
             <thead>
             <tr>
-                <th class="border-bottom-0">Created</th>
+                <th class="border-bottom-0">Created <span class="font-weight-normal text-secondary text-sm">(newest first)</span></th>
                 <th class="border-bottom-0">Customer</th>
                 <th class="border-bottom-0">Plus / Minus</th>
                 <th class="border-bottom-0">Amount</th>

+ 41 - 27
resources/views/app/invoice-center/customers.blade.php

@@ -49,8 +49,8 @@
                 <th class="border-bottom-0">Customer</th>
                 <th class="border-bottom-0">Age/Gender</th>
                 <th class="border-bottom-0">Company</th>
-                <th class="border-bottom-0">Customer Balance</th>
-                <th class="border-bottom-0">Pending Invoices Balance</th>
+                <th class="border-bottom-0">Customer<br>Balance</th>
+                <th class="border-bottom-0">Pending Invoices<br>Balance</th>
                 <th class="border-bottom-0">Created</th>
                 <th class="border-bottom-0">Active?</th>
                 <th class="border-bottom-0"></th>
@@ -80,31 +80,45 @@
                     <td>{{ friendly_date($record->created_at) }}</td>
                     <td class="{{ !$record->is_active ? 'text-warning-dark' : ''}}">{{ $record->is_active ? 'Yes' : 'No' }}</td>
                     <td>
-                        @if($record->is_active)
-                            <div moe class="ml-3">
-                                <a href="" start show>Deactivate</a>
-                                <form url="/api/customer/deactivate" class="mcp-theme-1" right>
-                                    <p class="mb-2 text-nowrap">Deactivate this customer?</p>
-                                    <input type="hidden" name="uid" value="{{$record->uid}}">
-                                    <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>
-                        @else
-                            <div moe class="ml-3">
-                                <a href="" start show>Reactivate</a>
-                                <form url="/api/customer/reactivate" class="mcp-theme-1" right>
-                                    <p class="mb-2 text-nowrap">Reactivate this customer?</p>
-                                    <input type="hidden" name="uid" value="{{$record->uid}}">
-                                    <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
+                        <div class="d-flex flex-wrap">
+                            @if($record->is_active)
+                                <div moe class="mr-2">
+                                    <a href="" start show>Deactivate</a>
+                                    <form url="/api/customer/deactivate" class="mcp-theme-1" right>
+                                        <p class="mb-2 text-nowrap">Deactivate this customer?</p>
+                                        <input type="hidden" name="uid" value="{{$record->uid}}">
+                                        <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>
+                            @else
+                                <div moe class="mr-2">
+                                    <a href="" start show>Reactivate</a>
+                                    <form url="/api/customer/reactivate" class="mcp-theme-1" right>
+                                        <p class="mb-2 text-nowrap">Reactivate this customer?</p>
+                                        <input type="hidden" name="uid" value="{{$record->uid}}">
+                                        <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
+                            <a href="{{route('invoice-center.customerTransactions')}}?customerUid={{$record->uid}}"
+                               class="mr-2"
+                               open-in-stag-popup
+                               title="{{$record->client->displayName()}}: Customer Transactions"
+                               popup-style="stag-popup-med overflow-visible"
+                               mc-initer="invoice-center">Transactions</a>
+                            <a href="{{route('invoice-center.invoices')}}?customerUid={{$record->uid}}"
+                               class="mr-2"
+                               open-in-stag-popup
+                               title="{{$record->client->displayName()}}: Invoices"
+                               popup-style="stag-popup-med overflow-visible"
+                               mc-initer="invoice-center">Invoices</a>
+                        </div>
                     </td>
                 </tr>
             @endforeach

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

@@ -93,7 +93,7 @@
                         <button cancel class="btn btn-sm btn-default border">Cancel</button>
                     </div>
                 </form>
-            </div>1
+            </div>
         </div>
         @if(count($records))
             <table class="table table-sm table-bordered table-striped">

+ 37 - 27
resources/views/app/invoice-center/invoices.blade.php

@@ -10,7 +10,7 @@
                 <p class="mb-2 text-secondary font-weight-bold">Add Invoice</p>
                 <div class="mb-2">
                     <label class="text-sm text-secondary mb-1">Customer</label>
-                    <input type="hidden" name="customerUid">
+                    <input type="hidden" name="customerUid" value="{{@$customer->uid}}">
                     <input type="text"
                            name="customerName"
                            target-key="uid"
@@ -19,6 +19,8 @@
                            class="form-control form-control-sm"
                            stag-suggest
                            stag-suggest-ep="/customer-suggest"
+                           value="{{@$customer && $customer->client ? @$customer->client->displayName() : ''}}"
+                           {{@$customer ? 'disabled readonly' : ''}}
                            required>
                 </div>
                 <div class="mb-2">
@@ -116,37 +118,45 @@
                             </form>
                         </div>
                     </td>
-                    <td>{{$record->payment_link_slug}}</td>
+                    <td>{{substr($record->payment_link_slug, 0, 12) . '...'}}</td>
                     <td>${{ is_null($record->paid) ? 0 : $record->paid }}</td>
                     <td>${{ is_null($record->balance) ? 0 : $record->balance }}</td>
                     <td>{{ friendly_date($record->created_at) }}</td>
                     <td class="{{ !$record->is_active ? 'text-warning-dark' : ''}}">{{ $record->is_active ? 'Yes' : 'No' }}</td>
                     <td>
-                        @if($record->is_active)
-                            <div moe class="ml-3">
-                                <a href="" start show>Deactivate</a>
-                                <form url="/api/invoice/deactivate" class="mcp-theme-1" right>
-                                    <p class="mb-2 text-nowrap">Deactivate this invoice?</p>
-                                    <input type="hidden" name="uid" value="{{$record->uid}}">
-                                    <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>
-                        @else
-                            <div moe class="ml-3">
-                                <a href="" start show>Reactivate</a>
-                                <form url="/api/invoice/reactivate" class="mcp-theme-1" right>
-                                    <p class="mb-2 text-nowrap">Reactivate this invoice?</p>
-                                    <input type="hidden" name="uid" value="{{$record->uid}}">
-                                    <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
+                        <div class="d-flex flex-wrap">
+                            @if($record->is_active)
+                                <div moe class="mr-2">
+                                    <a href="" start show>Deactivate</a>
+                                    <form url="/api/invoice/deactivate" class="mcp-theme-1" right>
+                                        <p class="mb-2 text-nowrap">Deactivate this invoice?</p>
+                                        <input type="hidden" name="uid" value="{{$record->uid}}">
+                                        <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>
+                            @else
+                                <div moe class="mr-2">
+                                    <a href="" start show>Reactivate</a>
+                                    <form url="/api/invoice/reactivate" class="mcp-theme-1" right>
+                                        <p class="mb-2 text-nowrap">Reactivate this invoice?</p>
+                                        <input type="hidden" name="uid" value="{{$record->uid}}">
+                                        <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
+                            <a href="{{route('invoice-center.invoiceTransactions')}}?invoiceUid={{$record->uid}}"
+                               class="mr-2"
+                               open-in-stag-popup
+                               title="{{$record->displayName()}}: Invoice Transactions"
+                               popup-style="stag-popup-med overflow-visible"
+                               mc-initer="invoice-center">Transactions</a>
+                        </div>
                     </td>
                 </tr>
             @endforeach

+ 2 - 1
resources/views/layouts/invoice-center.blade.php

@@ -28,7 +28,8 @@ $routeName = request()->route()->getName();
 			</div>
 		</nav>
 		@endif
-		<main role="main" class="w-100 pt-3 mcp-theme-1">
+		<main role="main" class="w-100 mcp-theme-1">
+			<div class="pt-3 hide-inside-popup"></div>
 			@yield('inner-content')
 		</main>
 	</div>