From 1e30bf4bdcdc52e4276922c533fcc2ba024d0575 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 15 Jun 2022 15:20:00 +1000 Subject: [PATCH] Accept a purchase order --- app/Exceptions/Handler.php | 3 + app/Http/Controllers/BaseController.php | 7 +- .../VendorPortal/PurchaseOrderController.php | 21 ++++ public/js/clients/purchase_orders/accept.js | 2 + .../purchase_orders/accept.js.LICENSE.txt | 9 ++ public/mix-manifest.json | 1 + .../js/clients/purchase_orders/accept.js | 103 ++++++++++++++++++ .../general/sidebar/vendor_header.blade.php | 2 +- .../includes/actions.blade.php | 40 +++++++ .../ninja2020/purchase_orders/show.blade.php | 52 ++------- routes/vendor.php | 8 +- webpack.mix.js | 4 + 12 files changed, 206 insertions(+), 46 deletions(-) create mode 100644 public/js/clients/purchase_orders/accept.js create mode 100644 public/js/clients/purchase_orders/accept.js.LICENSE.txt create mode 100644 resources/js/clients/purchase_orders/accept.js create mode 100644 resources/views/portal/ninja2020/purchase_orders/includes/actions.blade.php diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 1a859942f4e7..f9bc844a31da 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -222,6 +222,9 @@ class Handler extends ExceptionHandler case 'user': $login = 'login'; break; + case 'vendor': + $login = 'vendor.catchall'; + break; default: $login = 'default'; break; diff --git a/app/Http/Controllers/BaseController.php b/app/Http/Controllers/BaseController.php index e1bfbf1af4f5..90bdc3429ff7 100644 --- a/app/Http/Controllers/BaseController.php +++ b/app/Http/Controllers/BaseController.php @@ -172,7 +172,12 @@ class BaseController extends Controller */ public function notFoundClient() { - abort(404, 'Page not found in client portal.'); + abort(404, 'Page not found in the client portal.'); + } + + public function notFoundVendor() + { + abort(404, 'Page not found in the vendor portal.'); } /** diff --git a/app/Http/Controllers/VendorPortal/PurchaseOrderController.php b/app/Http/Controllers/VendorPortal/PurchaseOrderController.php index bbc03e8b7867..d285f455b988 100644 --- a/app/Http/Controllers/VendorPortal/PurchaseOrderController.php +++ b/app/Http/Controllers/VendorPortal/PurchaseOrderController.php @@ -118,17 +118,38 @@ class PurchaseOrderController extends Controller public function bulk(ProcessPurchaseOrdersInBulkRequest $request) { + $transformed_ids = $this->transformKeys($request->purchase_orders); if ($request->input('action') == 'download') { return $this->downloadInvoices((array) $transformed_ids); } + elseif ($request->input('action') == 'accept'){ + return $this->acceptPurchaseOrder($request->all()); + } return redirect() ->back() ->with('message', ctrans('texts.no_action_provided')); } + public function acceptPurchaseOrder($data) + { + $purchase_orders = PurchaseOrder::query() + ->whereIn('id', $this->transformKeys($data['purchase_orders'])) + ->where('company_id', auth()->guard('vendor')->user()->vendor->company_id) + ->whereIn('status_id', [PurchaseOrder::STATUS_DRAFT, PurchaseOrder::STATUS_SENT]); + + $purchase_orders->update(['status_id' => PurchaseOrder::STATUS_ACCEPTED]); + + if($purchase_orders->count() == 1) + return redirect()->route('vendor.purchase_order.show', ['purchase_order' => $purchase_orders->first()->hashed_id]); + else + return redirect()->route('vendor.purchase_orders.index'); + + + } + public function downloadInvoices($ids) { diff --git a/public/js/clients/purchase_orders/accept.js b/public/js/clients/purchase_orders/accept.js new file mode 100644 index 000000000000..46ec071e7531 --- /dev/null +++ b/public/js/clients/purchase_orders/accept.js @@ -0,0 +1,2 @@ +/*! For license information please see accept.js.LICENSE.txt */ +(()=>{function e(e,t){for(var n=0;n { + if (this.shouldDisplaySignature && this.shouldDisplayTerms) { + this.displaySignature(); + + document + .getElementById('signature-next-step') + .addEventListener('click', () => { + this.displayTerms(); + + document + .getElementById('accept-terms-button') + .addEventListener('click', () => { + document.querySelector( + 'input[name="signature"' + ).value = this.signaturePad.toDataURL(); + this.termsAccepted = true; + this.submitForm(); + }); + }); + } + + if (this.shouldDisplaySignature && !this.shouldDisplayTerms) { + this.displaySignature(); + + document + .getElementById('signature-next-step') + .addEventListener('click', () => { + document.querySelector( + 'input[name="signature"' + ).value = this.signaturePad.toDataURL(); + this.submitForm(); + }); + } + + if (!this.shouldDisplaySignature && this.shouldDisplayTerms) { + this.displayTerms(); + + document + .getElementById('accept-terms-button') + .addEventListener('click', () => { + this.termsAccepted = true; + this.submitForm(); + }); + } + + if (!this.shouldDisplaySignature && !this.shouldDisplayTerms) { + this.submitForm(); + } + }); + } +} + +const signature = document.querySelector('meta[name="require-purchase_order-signature"]') + .content; + +const terms = document.querySelector('meta[name="show-purchase_order-terms"]').content; + +new Accept(Boolean(+signature), Boolean(+terms)).handle(); diff --git a/resources/views/portal/ninja2020/components/general/sidebar/vendor_header.blade.php b/resources/views/portal/ninja2020/components/general/sidebar/vendor_header.blade.php index 662edf2290d5..9713ab52b757 100644 --- a/resources/views/portal/ninja2020/components/general/sidebar/vendor_header.blade.php +++ b/resources/views/portal/ninja2020/components/general/sidebar/vendor_header.blade.php @@ -30,7 +30,7 @@ {{ ctrans('texts.profile') }} - {{ ctrans('texts.logout') }} diff --git a/resources/views/portal/ninja2020/purchase_orders/includes/actions.blade.php b/resources/views/portal/ninja2020/purchase_orders/includes/actions.blade.php new file mode 100644 index 000000000000..53b35288b232 --- /dev/null +++ b/resources/views/portal/ninja2020/purchase_orders/includes/actions.blade.php @@ -0,0 +1,40 @@ +
+@csrf + + + + + + +
+
+
+
+ +

+ {{ ctrans('texts.approve') }} +

+ + + +
+ +
+ @yield('quote-not-approved-right-side') + +
+ +
+
+
+
+
+ +
diff --git a/resources/views/portal/ninja2020/purchase_orders/show.blade.php b/resources/views/portal/ninja2020/purchase_orders/show.blade.php index 337a7eea0ca1..bc2a91e97cd5 100644 --- a/resources/views/portal/ninja2020/purchase_orders/show.blade.php +++ b/resources/views/portal/ninja2020/purchase_orders/show.blade.php @@ -2,7 +2,8 @@ @section('meta_title', ctrans('texts.view_purchase_order')) @push('head') - + + @include('portal.ninja2020.components.no-cache') @@ -11,56 +12,24 @@ @section('body') - @if($purchase_order) -
- @csrf - - -
-
-
-
-

- {{ ctrans('texts.purchase_order_number_placeholder', ['purchase_order' => $purchase_order->number])}} - - {{ ctrans('texts.unpaid') }} -

- - @if($key) - - @endif - - -
-
-
- - - -
-
-
-
-
-
+ @if(in_array($purchase_order->status_id, [\App\Models\PurchaseOrder::STATUS_SENT, \App\Models\PurchaseOrder::STATUS_DRAFT])) +
+ @include('portal.ninja2020.purchase_orders.includes.actions', ['purchase_order' => $purchase_order]) +
@else

- {{ ctrans('texts.invoice_number_placeholder', ['invoice' => $purchase_order->number])}} + {{ ctrans('texts.purchase_order_number_placeholder', ['purchase_order' => $purchase_order->number])}} - {{ \App\Models\PurchaseOrder::stringStatus($purchase_order->status_id) }}

@if($key) -