diff --git a/app/Http/Controllers/ClientPortal/PaymentController.php b/app/Http/Controllers/ClientPortal/PaymentController.php index 55a6c2da65d6..1cac29ad5560 100644 --- a/app/Http/Controllers/ClientPortal/PaymentController.php +++ b/app/Http/Controllers/ClientPortal/PaymentController.php @@ -170,8 +170,8 @@ class PaymentController extends Controller }); - if ((bool) $request->signature) { - $invoices->each(function ($invoice) { + if (request()->has('signature') && !is_null(request()->signature) && !empty(request()->signature)) { + $invoices->each(function ($invoice) use ($request) { InjectSignature::dispatch($invoice, $request->signature); }); } diff --git a/app/Http/Controllers/ClientPortal/QuoteController.php b/app/Http/Controllers/ClientPortal/QuoteController.php index 3cf36cc6b93c..02d425a64455 100644 --- a/app/Http/Controllers/ClientPortal/QuoteController.php +++ b/app/Http/Controllers/ClientPortal/QuoteController.php @@ -6,6 +6,7 @@ use App\Events\Quote\QuoteWasApproved; use App\Http\Controllers\Controller; use App\Http\Requests\ClientPortal\ProcessQuotesInBulkRequest; use App\Http\Requests\ClientPortal\ShowQuoteRequest; +use App\Jobs\Invoice\InjectSignature; use App\Models\Company; use App\Models\Quote; use App\Utils\Ninja; @@ -111,6 +112,10 @@ class QuoteController extends Controller foreach ($quotes as $quote) { $quote->service()->approve(auth()->user())->save(); event(new QuoteWasApproved(auth('contact')->user(), $quote, $quote->company, Ninja::eventVars())); + + if (request()->has('signature') && !is_null(request()->signature) && !empty(request()->signature)) { + InjectSignature::dispatch($quote, request()->signature); + } } return redirect() diff --git a/app/Jobs/Invoice/InjectSignature.php b/app/Jobs/Invoice/InjectSignature.php index fe5dc5eb56b3..58c028c1c5b4 100644 --- a/app/Jobs/Invoice/InjectSignature.php +++ b/app/Jobs/Invoice/InjectSignature.php @@ -15,9 +15,9 @@ class InjectSignature implements ShouldQueue use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; /** - * @var App\Models\Invoice + * @var App\Models\Invoice|App\Models\Quote */ - public $invoice; + public $entity; /** * @var string @@ -27,12 +27,12 @@ class InjectSignature implements ShouldQueue /** * Create a new job instance. * - * @param Invoice $invoice + * @param $entity * @param string $signature */ - public function __construct(Invoice $invoice, string $signature) + public function __construct($entity, string $signature) { - $this->invoice = $invoice; + $this->entity = $entity; $this->signature = $signature; } @@ -44,7 +44,7 @@ class InjectSignature implements ShouldQueue */ public function handle() { - $invitation = $this->invoice->invitations->whereNotNull('signature_base64')->first(); + $invitation = $this->entity->invitations->whereNotNull('signature_base64')->first(); if (! $invitation) { return; diff --git a/public/js/clients/quotes/approve.js b/public/js/clients/quotes/approve.js index 2faaab5f8dca..9059c38633cd 100644 --- a/public/js/clients/quotes/approve.js +++ b/public/js/clients/quotes/approve.js @@ -1,2 +1,2 @@ /*! For license information please see approve.js.LICENSE.txt */ -!function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="/",n(n.s=10)}({10:function(e,t,n){e.exports=n("WuMn")},WuMn:function(e,t){function n(e,t){for(var n=0;n { - if (this.shouldDisplaySignature) { - this.displaySignature(); + document + .getElementById('approve-button') + .addEventListener('click', () => { + if (this.shouldDisplaySignature && this.shouldDisplayTerms) { + this.displaySignature(); - document.getElementById('signature-next-step').addEventListener('click', () => { + 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(); - }); - } - - if (!this.shouldDisplaySignature) this.submitForm(); - }) + } + }); } } -const signature = document.querySelector( - 'meta[name="require-quote-signature"]' -).content; - -new Approve(Boolean(+signature)).handle(); +const signature = document.querySelector('meta[name="require-quote-signature"]') + .content; +const terms = document.querySelector('meta[name="show-quote-terms"]').content; +new Approve(Boolean(+signature), Boolean(+terms)).handle(); diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index 0636c6169370..bcf7aff5f94f 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -3303,4 +3303,6 @@ return [ 'activity_65' => ':user emailed reminder 3 for invoice :invoice to :contact', 'activity_66' => ':user emailed reminder endless for invoice :invoice to :contact', + 'by_clicking_next_you_accept_terms' => 'By clicking "Next step" you accept terms.', + 'not_specified' => 'Not specified', ]; diff --git a/resources/views/portal/ninja2020/invoices/includes/signature.blade.php b/resources/views/portal/ninja2020/invoices/includes/signature.blade.php index 742772e3268d..e5e09aae48ce 100644 --- a/resources/views/portal/ninja2020/invoices/includes/signature.blade.php +++ b/resources/views/portal/ninja2020/invoices/includes/signature.blade.php @@ -1,24 +1,13 @@ -