From 2baebffc32e12765d2726b9c6b5a5646a73b67b9 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 9 Aug 2024 14:44:39 +1000 Subject: [PATCH] Updates for multi invoice payment flow --- app/DataMapper/CompanySettings.php | 3 +- .../ClientPortal/InvoiceController.php | 10 ++- app/Livewire/Flow2/InvoicePay.php | 7 +- app/Livewire/Flow2/InvoiceSummary.php | 12 ++-- app/Livewire/Flow2/Terms.php | 2 +- .../ClientPortal/LivewireInstantPayment.php | 2 + .../ninja2020/flow2/invoice-summary.blade.php | 67 ----------------- .../flow2/invoices-summary.blade.php | 71 +++++++++++++++++++ .../ninja2020/invoices/show_smooth.blade.php | 4 +- .../invoices/show_smooth_multi.blade.php | 17 +++++ 10 files changed, 114 insertions(+), 81 deletions(-) delete mode 100644 resources/views/portal/ninja2020/flow2/invoice-summary.blade.php create mode 100644 resources/views/portal/ninja2020/flow2/invoices-summary.blade.php create mode 100644 resources/views/portal/ninja2020/invoices/show_smooth_multi.blade.php diff --git a/app/DataMapper/CompanySettings.php b/app/DataMapper/CompanySettings.php index f373153173..bbe92d1e7b 100644 --- a/app/DataMapper/CompanySettings.php +++ b/app/DataMapper/CompanySettings.php @@ -516,9 +516,10 @@ class CompanySettings extends BaseSettings public $quote_late_fee_amount1 = 0; public $quote_late_fee_percent1 = 0; - + public string $payment_flow = 'default'; //smooth public static $casts = [ + 'payment_flow' => 'string', 'enable_quote_reminder1' => 'bool', 'quote_num_days_reminder1' => 'int', 'quote_schedule_reminder1' => 'string', diff --git a/app/Http/Controllers/ClientPortal/InvoiceController.php b/app/Http/Controllers/ClientPortal/InvoiceController.php index ca2f7fee31..2a22627d84 100644 --- a/app/Http/Controllers/ClientPortal/InvoiceController.php +++ b/app/Http/Controllers/ClientPortal/InvoiceController.php @@ -79,13 +79,16 @@ class InvoiceController extends Controller 'hash' => $hash, 'variables' => $variables, 'invoices' => [$invoice->hashed_id], + 'db' => $invoice->company->db, ]; if ($request->query('mode') === 'fullscreen') { return render('invoices.show-fullscreen', $data); } - return $this->render('invoices.show_smooth', $data); + return auth()->guard('contact')->user()->client->getSetting('payment_flow') == 'default' ? $this->render('invoices.show', $data) : $this->render('invoices.show_smooth', $data); + + // return $this->render('invoices.show_smooth', $data); } public function showBlob($hash) @@ -237,9 +240,12 @@ class InvoiceController extends Controller 'hashed_ids' => $invoices->pluck('hashed_id'), 'total' => $total, 'variables' => $variables, + 'invitation' => $invitation, + 'db' => $invitation->company->db, ]; - return $this->render('invoices.payment', $data); + // return $this->render('invoices.payment', $data); + return auth()->guard('contact')->user()->client->getSetting('payment_flow') === 'default' ? $this->render('invoices.payment', $data) : $this->render('invoices.show_smooth_multi', $data); } /** diff --git a/app/Livewire/Flow2/InvoicePay.php b/app/Livewire/Flow2/InvoicePay.php index a7154a7eac..6a71c98d6e 100644 --- a/app/Livewire/Flow2/InvoicePay.php +++ b/app/Livewire/Flow2/InvoicePay.php @@ -238,9 +238,12 @@ class InvoicePay extends Component $this->setContext('settings', $settings); // $this->context['settings'] = $settings; $this->setContext('db', $this->db); // $this->context['db'] = $this->db; - $invoices = Invoice::find($this->transformKeys($this->invoices)); + nlog($this->invoices); + + if(is_array($this->invoices)) + $this->invoices = Invoice::find($this->transformKeys($this->invoices)); - $invoices = $invoices->filter(function ($i) { + $invoices = $this->invoices->filter(function ($i) { $i = $i->service() ->markSent() ->removeUnpaidGatewayFees() diff --git a/app/Livewire/Flow2/InvoiceSummary.php b/app/Livewire/Flow2/InvoiceSummary.php index cf0f346d90..51681737b2 100644 --- a/app/Livewire/Flow2/InvoiceSummary.php +++ b/app/Livewire/Flow2/InvoiceSummary.php @@ -20,12 +20,12 @@ class InvoiceSummary extends Component { use WithSecureContext; - public $invoice; + public $invoices; public function mount() { //@TODO for a single invoice - show all details, for multi-invoices, only show the summaries - $this->invoice = $this->getContext()['invitation']->invoice; // $this->context['invitation']->invoice; + $this->invoices = $this->getContext()['invoices']; // $this->context['invitation']->invoice; } #[On(self::CONTEXT_UPDATE)] @@ -33,13 +33,15 @@ class InvoiceSummary extends Component { // refactor logic for updating the price for eg if it changes with under/over pay - $this->invoice = $this->getContext()['invitation']->invoice; + $this->invoices = $this->getContext()['invoices']; } public function render(): \Illuminate\Contracts\View\Factory|\Illuminate\View\View { - return render('flow2.invoice-summary', [ - 'invoice' => $this->invoice + return render('flow2.invoices-summary', [ + 'invoice' => $this->invoices, + 'client' => $this->invoices->first()->client, ]); + } } diff --git a/app/Livewire/Flow2/Terms.php b/app/Livewire/Flow2/Terms.php index 8aedbb4ec9..95de13bd3a 100644 --- a/app/Livewire/Flow2/Terms.php +++ b/app/Livewire/Flow2/Terms.php @@ -25,7 +25,7 @@ class Terms extends Component public function mount() { - $this->invoice = $this->getContext()['invoice']; + $this->invoice = $this->getContext()['invoices']->first(); $this->variables = $this->getContext()['variables']; } diff --git a/app/Services/ClientPortal/LivewireInstantPayment.php b/app/Services/ClientPortal/LivewireInstantPayment.php index 43bd6d2bdc..91cf490d26 100644 --- a/app/Services/ClientPortal/LivewireInstantPayment.php +++ b/app/Services/ClientPortal/LivewireInstantPayment.php @@ -89,6 +89,8 @@ class LivewireInstantPayment public function run() { + nlog($this->data); + $company_gateway = CompanyGateway::query()->find($this->data['company_gateway_id']); if ($this->data['company_gateway_id'] == CompanyGateway::GATEWAY_CREDIT) { diff --git a/resources/views/portal/ninja2020/flow2/invoice-summary.blade.php b/resources/views/portal/ninja2020/flow2/invoice-summary.blade.php deleted file mode 100644 index 005637a57f..0000000000 --- a/resources/views/portal/ninja2020/flow2/invoice-summary.blade.php +++ /dev/null @@ -1,67 +0,0 @@ -
-
-
-
-

- {{ ctrans('texts.invoice') }} {{ $invoice->number }} - -

-

{{ ctrans('texts.date') }}: {{ $invoice->translateDate($invoice->date, $invoice->client->date_format(), $invoice->client->locale()) }}

-
- -
-
-
-
{{ ctrans('texts.invoice_details') }}
-
    - @foreach($invoice->line_items as $item) -
  • {{ $item->notes }} {{ App\Utils\Number::formatMoney($item->line_total, $invoice->client) }}
  • - @endforeach -
-
-
    - @if($invoice->total_taxes > 0) -
  • {{ ctrans('texts.tax')}}{{App\Utils\Number::formatMoney($invoice->total_taxes, $invoice->client) }}
  • - @endif -
  • {{ ctrans('texts.total') }}{{ App\Utils\Number::formatMoney($invoice->amount, $invoice->client) }}
  • -
-
-
-
-
-
-
-
-
-
-
{{ ctrans('texts.client_information') }}
-
-
-
{{ ctrans('texts.client') }}
-
{{ $invoice->client->present()->name() }}
-
-
-
{{ ctrans('texts.email') }}
-
{{ $invoice->client->present()->email() }}
-
-
-
{{ ctrans('texts.phone') }}
-
{{ $invoice->client->present()->phone() }}
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/resources/views/portal/ninja2020/flow2/invoices-summary.blade.php b/resources/views/portal/ninja2020/flow2/invoices-summary.blade.php new file mode 100644 index 0000000000..d5c9cde79a --- /dev/null +++ b/resources/views/portal/ninja2020/flow2/invoices-summary.blade.php @@ -0,0 +1,71 @@ +
+
+
+
+

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

+
+
+ +
+ @foreach($invoices as $invoice) +
+
{{ ctrans('texts.invoice') }} {{ $invoice->number }}
+
+
+
{{ ctrans('texts.invoice_date') }}
+
{{ $invoice->translateDate($invoice->date, $invoice->client->date_format(), $invoice->client->locale()) }}
+
+ @if($invoice->due_date) +
+
{{ ctrans('texts.due_date') }}
+
{{ $invoice->translateDate($invoice->due_date, $invoice->client->date_format(), $invoice->client->locale()) }}
+
+ @endif +
+
{{ ctrans('texts.amount_due') }}
+
+ {{ $invoice->client->currency()->code }} ({{ $invoice->client->currency()->symbol }}) + {{ $invoice->partial > 0 ? $invoice->partial : $invoice->balance }} +
+
+
+
+ @endforeach + +
+
+
{{ ctrans('texts.client_information') }}
+
+
+
{{ ctrans('texts.client') }}
+
{{ $client->present()->name() }}
+
+
+
{{ ctrans('texts.email') }}
+
{{ $client->present()->email() }}
+
+ @if($client->present()->phone()) +
+
{{ ctrans('texts.phone') }}
+
{{ $client->present()->phone() }}
+
+ @endif +
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file diff --git a/resources/views/portal/ninja2020/invoices/show_smooth.blade.php b/resources/views/portal/ninja2020/invoices/show_smooth.blade.php index ba319142c7..f7add35dd0 100644 --- a/resources/views/portal/ninja2020/invoices/show_smooth.blade.php +++ b/resources/views/portal/ninja2020/invoices/show_smooth.blade.php @@ -17,11 +17,9 @@ @endif @if($invoice->isPayable()) - @livewire('flow2.invoice-pay', ['invoices' => $invoices, 'invitation_id' => $invitation->id, 'db' => $invoice->company->db, 'variables' => $variables]) + @livewire('flow2.invoice-pay', ['invoices' => $invoices, 'invitation_id' => $invitation->id, 'db' => $db, 'variables' => $variables]) @endif - @include('portal.ninja2020.components.entity-documents', ['entity' => $invoice]) - @endsection @section('footer') diff --git a/resources/views/portal/ninja2020/invoices/show_smooth_multi.blade.php b/resources/views/portal/ninja2020/invoices/show_smooth_multi.blade.php new file mode 100644 index 0000000000..9975396baa --- /dev/null +++ b/resources/views/portal/ninja2020/invoices/show_smooth_multi.blade.php @@ -0,0 +1,17 @@ +@extends('portal.ninja2020.layout.app') +@section('meta_title', ctrans('texts.view_invoice')) + +@push('head') +@endpush + +@section('body') + + @livewire('flow2.invoice-pay', ['invoices' => $invoices, 'invitation_id' => $invitation->id, 'db' => $db, 'variables' => $variables]) + +@endsection + +@section('footer') +@endsection + +@push('head') +@endpush