Преглед на файлове

Invoice-center - invoices

Vijayakrishnan преди 3 години
родител
ревизия
baea559623
променени са 4 файла, в които са добавени 198 реда и са изтрити 1 реда
  1. 39 0
      app/Http/Controllers/InvoiceController.php
  2. 3 0
      app/Models/Invoice.php
  3. 155 1
      resources/views/app/invoice-center/invoices.blade.php
  4. 1 0
      routes/web.php

+ 39 - 0
app/Http/Controllers/InvoiceController.php

@@ -138,5 +138,44 @@ ORDER BY client.name_first, client.name_last",
             "data" => $matches
         ]);
     }
+
+    public function customerSuggestJSON(Request $request) {
+        $term = $request->input('term') ? trim($request->input('term')) : '';
+        if (empty($term)) return '';
+
+        // if multiple words in query, check for all (max 2)
+        $term2 = '';
+        if(strpos($term, ' ') !== FALSE) {
+            $terms = explode(' ', $term);
+            $term = trim($terms[0]);
+            $term2 = trim($terms[1]);
+        }
+
+        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
+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 . '%']
+            );
+        }
+        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
+WHERE (client.name_first ILIKE :term OR client.name_last ILIKE :term)
+ORDER BY client.name_first, client.name_last",
+                ['term' => $term . '%']
+            );
+        }
+
+        return json_encode([
+            "success" => true,
+            "data" => $matches
+        ]);
+    }
    
 }

+ 3 - 0
app/Models/Invoice.php

@@ -8,4 +8,7 @@ class Invoice extends Model
 {
     protected $table = 'invoice';
 
+    public function customer() {
+        return $this->hasOne(Customer::class, 'id', 'customer_id');
+    }
 }

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

@@ -1,4 +1,158 @@
 @extends('layouts.invoice-center')
 @section('inner-content')
-    Invoices
+    <div class="d-flex mb-2 pb-2 align-items-center border-bottom">
+        <div class="font-size-14 font-weight-bold">Invoices</div>
+        <div moe class="ml-3">
+            <a href="" start show class="btn btn-sm btn-primary font-weight-normal text-white">
+                + Add Invoice
+            </a>
+            <form url="/api/invoice/create" class="mcp-theme-1">
+                <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="text"
+                           name="customerName"
+                           target-key="uid"
+                           target-field="customerUid"
+                           autocomplete="off"
+                           class="form-control form-control-sm"
+                           stag-suggest
+                           stag-suggest-ep="/customer-suggest"
+                           required>
+                </div>
+                <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"
+                           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"></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>
+    </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">Customer</th>
+                <th class="border-bottom-0">Amount</th>
+                <th class="border-bottom-0">Description</th>
+                <th class="border-bottom-0">Pay Link</th>
+                <th class="border-bottom-0">Paid</th>
+                <th class="border-bottom-0">Balance</th>
+                <th class="border-bottom-0">Created</th>
+                <th class="border-bottom-0">Active?</th>
+                <th class="border-bottom-0"></th>
+            </tr>
+            </thead>
+            <tbody>
+            <?php $i = 1; ?>
+            @foreach($records as $record)
+                <tr>
+                    <td>{{ $i++ }}</td>
+                    <td>
+                        @if($record->customer && $record->customer->client)
+                            <a href="{{route('patients.view.dashboard', $record->customer->client)}}">
+                                {{$record->customer->client->displayName()}}
+                            </a>
+                        @else
+                            -
+                        @endif
+                        @if(!$record->is_active)
+                            <span class="text-sm font-weight-bold text-secondary ml-2">[INACTIVE]</span>
+                        @endif
+                    </td>
+                    <td>${{ is_null($record->amount) ? 0 : $record->amount }}
+                        <div moe relative class="ml-1">
+                            <a href="#" start show><i class="fa fa-edit on-hover-opaque"></i></a>
+                            <form url="/api/invoice/changeAmount">
+                                <input type="hidden" name="invoiceUid" 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>
+                                    <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>
+                    </td>
+                    <td>{{ $record->description ?: '' }}
+                        <div moe relative class="ml-1">
+                            <a href="#" start show><i class="fa fa-edit on-hover-opaque"></i></a>
+                            <form url="/api/invoice/changeDescription">
+                                <input type="hidden" name="invoiceUid" value="{{$record->uid}}">
+                                <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">{{$record->description}}</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>
+                    </td>
+                    <td>{{$record->payment_link_slug}}</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
+                    </td>
+                </tr>
+            @endforeach
+            </tbody>
+        </table>
+    @else
+        <div class="text-secondary">No invoices yet!</div>
+    @endif
 @endsection

+ 1 - 0
routes/web.php

@@ -648,6 +648,7 @@ Route::middleware('pro.auth')->group(function () {
     // Company/client suggest
     Route::get('/company-suggest', 'InvoiceController@companySuggestJSON')->name('company-suggest-json');
     Route::get('/client-suggest', 'InvoiceController@clientSuggestJSON')->name('client-suggest-json');
+    Route::get('/customer-suggest', 'InvoiceController@customerSuggestJSON')->name('customer-suggest-json');
 
     // Pro suggest
     Route::get('/pro-suggest', 'HomeController@proSuggest');