Browse Source

Invoice-center - cross linkage + companies page

Vijayakrishnan 3 years ago
parent
commit
2687cd025c

+ 25 - 10
app/Http/Controllers/InvoiceController.php

@@ -59,9 +59,24 @@ use App\Models\VisitTemplateAccess;
 class InvoiceController extends Controller
 {
 
+    private static $PAGE_SIZE = 25;
+
+    public function companies(Request $request) {
+        $records = Company::orderBy('name', 'ASC')->where('is_active', true)->paginate(InvoiceController::$PAGE_SIZE);
+        return view ('app.invoice-center.companies', compact('records'));
+    }
+
     public function customers(Request $request) {
-        $records = Customer::orderBy('created_at', 'DESC')->paginate();
-        return view ('app.invoice-center.customers', compact('records'));
+        $records = Customer::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(InvoiceController::$PAGE_SIZE);
+        return view ('app.invoice-center.customers', compact('records', 'company'));
     }
 
     public function giftCards(Request $request) {
@@ -73,7 +88,7 @@ class InvoiceController extends Controller
                 $records = $records->where('company_id', $company->id);
             }
         }
-        $records = $records->paginate();
+        $records = $records->paginate(InvoiceController::$PAGE_SIZE);
         return view ('app.invoice-center.gift-cards', compact('records', 'company'));
     }
 
@@ -86,7 +101,7 @@ class InvoiceController extends Controller
                 $records = $records->where('customer_id', $customer->id);
             }
         }
-        $records = $records->paginate();
+        $records = $records->paginate(InvoiceController::$PAGE_SIZE);
         return view ('app.invoice-center.invoices', compact('records', 'customer'));
     }
 
@@ -99,7 +114,7 @@ class InvoiceController extends Controller
                 $records = $records->where('customer_id', $customer->id);
             }
         }
-        $records = $records->paginate();
+        $records = $records->paginate(InvoiceController::$PAGE_SIZE);
         return view ('app.invoice-center.customer-transactions', compact('records', 'customer'));
     }
 
@@ -112,7 +127,7 @@ class InvoiceController extends Controller
                 $records = $records->where('invoice_id', $invoice->id);
             }
         }
-        $records = $records->paginate();
+        $records = $records->paginate(InvoiceController::$PAGE_SIZE);
         return view ('app.invoice-center.invoice-transactions', compact('records', 'invoice'));
     }
 
@@ -187,8 +202,8 @@ ORDER BY client.name_first, client.name_last",
         if(!empty($term2)) {
             $matches = DB::select("
 SELECT customer.uid,
-       (client.name_first || ' ' || client.name_last) as text
-FROM client join customer on client.id = customer.client_id
+       (client.name_first || ' ' || client.name_last || ' (' || company.name || ')') as text
+FROM client join customer on client.id = customer.client_id join company on customer.company_id = company.id
 WHERE (client.name_first ILIKE :term OR client.name_last ILIKE :term OR client.name_first ILIKE :term2 OR client.name_last ILIKE :term2)
 ORDER BY client.name_first, client.name_last",
                 ['term' => $term . '%', 'term2' => $term2 . '%']
@@ -197,8 +212,8 @@ ORDER BY client.name_first, client.name_last",
         else {
             $matches = DB::select("
 SELECT customer.uid,
-       (client.name_first || ' ' || client.name_last) as text
-FROM client join customer on client.id = customer.client_id
+       (client.name_first || ' ' || client.name_last || ' (' || company.name || ')') as text
+FROM client join customer on client.id = customer.client_id join company on customer.company_id = company.id
 WHERE (client.name_first ILIKE :term OR client.name_last ILIKE :term)
 ORDER BY client.name_first, client.name_last",
                 ['term' => $term . '%']

+ 9 - 0
app/Models/Company.php

@@ -2,6 +2,7 @@
 
 namespace App\Models;
 
+use Cassandra\Custom;
 use Illuminate\Database\Eloquent\Model;
 
 class Company extends Model
@@ -13,4 +14,12 @@ class Company extends Model
         return $this->hasMany(CompanyLocation::class, 'company_id', 'id')->orderBy('line1', 'ASC');
     }
 
+    public function customers(){
+        return $this->hasMany(Customer::class, 'company_id', 'id')->orderBy('created_at', 'DESC');
+    }
+
+    public function giftCards(){
+        return $this->hasMany(GiftCard::class, 'company_id', 'id')->orderBy('created_at', 'DESC');
+    }
+
 }

+ 60 - 0
resources/views/app/invoice-center/companies.blade.php

@@ -0,0 +1,60 @@
+@extends('layouts.invoice-center')
+@section('inner-content')
+    <div class="d-flex mb-2 pb-2 align-items-center border-bottom">
+        <div class="font-size-14 font-weight-bold">Companies</div>
+    </div>
+    @if(count($records))
+        <table class="table table-sm table-bordered table-striped">
+            <thead>
+            <tr>
+                <th class="border-bottom-0"></th>
+                <th class="border-bottom-0 width-300px">Name</th>
+                <th class="border-bottom-0">State</th>
+                <th class="border-bottom-0">Customers</th>
+                <th class="border-bottom-0">Gift Cards</th>
+                <th class="border-bottom-0">Created</th>
+            </tr>
+            </thead>
+            <tbody>
+            <?php $i = 1; ?>
+            @foreach($records as $record)
+                <tr>
+                    <td>{{ $i++ }}</td>
+                    <td>{{ $record->name }}</td>
+                    <td>{{ $record->state }}</td>
+                    <td>
+                        @if(count($record->customers))
+                            <a href="{{route('invoice-center.customers')}}?companyUid={{$record->uid}}"
+                               class="mr-2"
+                               open-in-stag-popup
+                               update-parent
+                               title="{{$record->name}}: Customers"
+                               popup-style="stag-popup-med overflow-visible"
+                               mc-initer="invoice-center">{{count($record->customers)}} customer{{count($record->customers) === 1 ? '' : 's'}}</a>
+                        @else
+                            -
+                        @endif
+                    </td>
+                    <td>
+                        @if(count($record->giftCards))
+                            <a href="{{route('invoice-center.giftCards')}}?companyUid={{$record->uid}}"
+                               class="mr-2"
+                               open-in-stag-popup
+                               update-parent
+                               title="{{$record->name}}: Gift Cards"
+                               popup-style="stag-popup-med overflow-visible"
+                               mc-initer="invoice-center">{{count($record->giftCards)}} gift card{{count($record->giftCards) === 1 ? '' : 's'}}</a>
+                        @else
+                            -
+                        @endif
+                    </td>
+                    <td>{{ friendly_date($record->created_at) }}</td>
+                </tr>
+            @endforeach
+            </tbody>
+        </table>
+        {{$records->withQueryString()->links()}}
+    @else
+        <div class="text-secondary">No companies yet!</div>
+    @endif
+@endsection

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

@@ -124,6 +124,7 @@
             @endforeach
             </tbody>
         </table>
+        {{$records->withQueryString()->links()}}
     @else
         <div class="text-secondary">No customer transactions yet!</div>
     @endif

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

@@ -10,7 +10,7 @@
                 <p class="mb-2 text-secondary font-weight-bold">Add Customer</p>
                 <div class="mb-2">
                     <label class="text-sm text-secondary mb-1">Company</label>
-                    <input type="hidden" name="companyUid">
+                    <input type="hidden" name="companyUid" value="{{@$company->uid}}">
                     <input type="text"
                            name="companyName"
                            target-key="uid"
@@ -19,6 +19,8 @@
                            class="form-control form-control-sm"
                            stag-suggest
                            stag-suggest-ep="/company-suggest"
+                           value="{{@$company ? @$company->name : ''}}"
+                           {{@$company ? 'disabled readonly' : ''}}
                            required>
                 </div>
                 <div class="mb-2">
@@ -109,12 +111,14 @@
                             <a href="{{route('invoice-center.customerTransactions')}}?customerUid={{$record->uid}}"
                                class="mr-2"
                                open-in-stag-popup
+                               update-parent
                                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
+                               update-parent
                                title="{{$record->client->displayName()}}: Invoices"
                                popup-style="stag-popup-med overflow-visible"
                                mc-initer="invoice-center">Invoices</a>
@@ -124,6 +128,7 @@
             @endforeach
             </tbody>
         </table>
+        {{$records->withQueryString()->links()}}
     @else
         <div class="text-secondary">No customers yet!</div>
     @endif

+ 4 - 1
resources/views/app/invoice-center/gift-cards.blade.php

@@ -10,7 +10,7 @@
                 <p class="mb-2 text-secondary font-weight-bold">Add Gift Card</p>
                 <div class="mb-2">
                     <label class="text-sm text-secondary mb-1">Company</label>
-                    <input type="hidden" name="companyUid">
+                    <input type="hidden" name="companyUid" value="{{@$company->uid}}">
                     <input type="text"
                            name="companyName"
                            target-key="uid"
@@ -19,6 +19,8 @@
                            class="form-control form-control-sm"
                            stag-suggest
                            stag-suggest-ep="/company-suggest"
+                           value="{{@$company ? @$company->name : ''}}"
+                           {{@$company ? 'disabled readonly' : ''}}
                            required>
                 </div>
                 <div class="mb-2">
@@ -100,6 +102,7 @@
             @endforeach
             </tbody>
         </table>
+        {{$records->withQueryString()->links()}}
     @else
         <div class="text-secondary">No gift cards yet!</div>
     @endif

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

@@ -130,6 +130,7 @@
                 @endforeach
                 </tbody>
             </table>
+            {{$records->withQueryString()->links()}}
         @else
             <div class="text-secondary">No customer transactions yet!</div>
         @endif
@@ -137,6 +138,7 @@
     <script>
         (function () {
             function init() {
+                initStagSuggest();
                 let parentSegment = $('#invoice-transactions');
                 parentSegment.find('input.customer-select')
                     .off('stag-suggest-selected')
@@ -156,7 +158,7 @@
                         });
                     });
             }
-            addMCInitializer('invoice-transactions', init, )
+            addMCInitializer('invoice-transactions', init, '#invoice-transactions')
         }).call(window);
     </script>
 @endsection

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

@@ -153,15 +153,17 @@
                             <a href="{{route('invoice-center.invoiceTransactions')}}?invoiceUid={{$record->uid}}"
                                class="mr-2"
                                open-in-stag-popup
+                               update-parent
                                title="{{$record->displayName()}}: Invoice Transactions"
                                popup-style="stag-popup-med overflow-visible"
-                               mc-initer="invoice-center">Transactions</a>
+                               mc-initer="invoice-transactions">Transactions</a>
                         </div>
                     </td>
                 </tr>
             @endforeach
             </tbody>
         </table>
+        {{$records->withQueryString()->links()}}
     @else
         <div class="text-secondary">No invoices yet!</div>
     @endif

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

@@ -9,6 +9,9 @@ $routeName = request()->route()->getName();
 		<nav id="sidebarMenu" class="d-block bg-light sidebar collapse px-0">
 			<div class="sidebar-sticky pt-3">
 				<ul class="nav flex-column mcp-theme-1">
+					<li class="nav-item">
+						<a class="nav-link {{ strpos($routeName, 'invoice-center.companies') === 0 ? 'active' : '' }}" href="{{ route('invoice-center.companies') }}">Companies</a>
+					</li>
 					<li class="nav-item">
 						<a class="nav-link {{ strpos($routeName, 'invoice-center.customers') === 0 ? 'active' : '' }}" href="{{ route('invoice-center.customers') }}">Customers</a>
 					</li>
@@ -37,7 +40,8 @@ $routeName = request()->route()->getName();
 <script>
 	(function () {
 		function init() {
-			let parentSegment = $('#invoice-center');
+			initStagSuggest();
+			let parentSegment = $('body');
 			parentSegment.find('input[stag-suggest][target-key][target-field]')
 					.off('stag-suggest-selected')
 					.on('stag-suggest-selected', (_e, _input, _data) => {
@@ -45,7 +49,7 @@ $routeName = request()->route()->getName();
 						_input.closest('form').find('input[name="' + _input.attr('target-field') + '"]').val(_data[_input.attr('target-key')]);
 					});
 		}
-		addMCInitializer('invoice-center', init, '#invoice-center')
+		addMCInitializer('invoice-center', init)
 	}).call(window);
 </script>
 @endsection

+ 1 - 0
routes/web.php

@@ -226,6 +226,7 @@ Route::middleware('pro.auth')->group(function () {
 
     Route::name('invoice-center.')->prefix('invoice-center')->group(function () {
         Route::middleware('pro.auth.admin')->group(function () {
+            Route::get('companies', 'InvoiceController@companies')->name('companies');
             Route::get('customers', 'InvoiceController@customers')->name('customers');
             Route::get('gift-cards', 'InvoiceController@giftCards')->name('giftCards');
             Route::get('invoices', 'InvoiceController@invoices')->name('invoices');