From 962d678156c09990f978b0ede105328eb028eb98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=BCneyt=20=C5=9Eent=C3=BCrk?= Date: Mon, 19 Jun 2023 15:50:23 +0300 Subject: [PATCH] Fixed missing document totals relation then add payment button action.. --- app/Models/Document/Document.php | 34 +++++++++++++------ resources/lang/en-GB/invoices.php | 2 ++ .../documents/show/content.blade.php | 4 +++ .../documents/show/get-paid.blade.php | 26 +++++++++----- .../documents/show/make-payment.blade.php | 26 +++++++++----- 5 files changed, 63 insertions(+), 29 deletions(-) diff --git a/app/Models/Document/Document.php b/app/Models/Document/Document.php index 323956a38..edf79ae79 100644 --- a/app/Models/Document/Document.php +++ b/app/Models/Document/Document.php @@ -538,17 +538,29 @@ class Document extends Model if ($this->status != 'paid' && (empty($this->transactions->count()) || (! empty($this->transactions->count()) && $this->paid != $this->amount))) { try { - $actions[] = [ - 'type' => 'button', - 'title' => trans('invoices.add_payment'), - 'icon' => 'paid', - 'url' => route('modals.documents.document.transactions.create', $this->id), - 'permission' => 'read-' . $group . '-' . $permission_prefix, - 'attributes' => [ - 'id' => 'index-line-actions-payment-' . $this->type . '-' . $this->id, - '@click' => 'onAddPayment("' . route('modals.documents.document.transactions.create', $this->id) . '")', - ], - ]; + if ($this->totals->count()) { + $actions[] = [ + 'type' => 'button', + 'title' => trans('invoices.add_payment'), + 'icon' => 'paid', + 'url' => route('modals.documents.document.transactions.create', $this->id), + 'permission' => 'read-' . $group . '-' . $permission_prefix, + 'attributes' => [ + 'id' => 'index-line-actions-payment-' . $this->type . '-' . $this->id, + '@click' => 'onAddPayment("' . route('modals.documents.document.transactions.create', $this->id) . '")', + ], + ]; + } else { + $actions[] = [ + 'type' => 'button', + 'title' => trans('invoices.messages.totals_required', ['type' => $this->type]), + 'icon' => 'paid', + 'permission' => 'read-' . $group . '-' . $permission_prefix, + 'attributes' => [ + "disabled" => "disabled", + ], + ]; + } } catch (\Exception $e) {} } diff --git a/resources/lang/en-GB/invoices.php b/resources/lang/en-GB/invoices.php index 5186448b9..99040dc6a 100644 --- a/resources/lang/en-GB/invoices.php +++ b/resources/lang/en-GB/invoices.php @@ -50,6 +50,8 @@ return [ 'messages' => [ 'email_required' => 'No email address for this customer!', + 'totals_required' => 'Invoice totals are required Please edit the :type and save it again.', + 'draft' => 'This is a DRAFT invoice and will be reflected to charts after it gets sent.', 'status' => [ diff --git a/resources/views/components/documents/show/content.blade.php b/resources/views/components/documents/show/content.blade.php index 34ec22538..174cf979d 100644 --- a/resources/views/components/documents/show/content.blade.php +++ b/resources/views/components/documents/show/content.blade.php @@ -34,6 +34,10 @@ @if ($document->status == 'draft') @endif + + @if (! $document->totals->count()) + + @endif @endif @stack('status_message_end') diff --git a/resources/views/components/documents/show/get-paid.blade.php b/resources/views/components/documents/show/get-paid.blade.php index 73822a701..01a720103 100644 --- a/resources/views/components/documents/show/get-paid.blade.php +++ b/resources/views/components/documents/show/get-paid.blade.php @@ -11,15 +11,23 @@ @stack('timeline_get_paid_body_button_payment_start') @if (! $hideAddPayment) - @if ($document->status != 'paid' && (empty($document->transactions->count()) || (! empty($document->transactions->count()) && $document->paid != $document->amount))) - - {{ trans('invoices.add_payment') }} - + @if ($document->totals->count()) + @if ($document->status != 'paid' && (empty($document->transactions->count()) || (! empty($document->transactions->count()) && $document->paid != $document->amount))) + + {{ trans('invoices.add_payment') }} + + @endif + @else + + + {{ trans('invoices.add_payment') }} + + @endif @endif diff --git a/resources/views/components/documents/show/make-payment.blade.php b/resources/views/components/documents/show/make-payment.blade.php index c382bae9a..5b4dd39d5 100644 --- a/resources/views/components/documents/show/make-payment.blade.php +++ b/resources/views/components/documents/show/make-payment.blade.php @@ -11,15 +11,23 @@ @stack('timeline_get_paid_body_button_payment_start') @if (! $hideAddPayment) - @if ($document->status != 'paid' && (empty($document->transactions->count()) || (! empty($document->transactions->count()) && $document->paid != $document->amount)) ) - - {{ trans('invoices.add_payment') }} - + @if ($document->totals->count()) + @if ($document->status != 'paid' && (empty($document->transactions->count()) || (! empty($document->transactions->count()) && $document->paid != $document->amount)) ) + + {{ trans('invoices.add_payment') }} + + @endif + @else + + + {{ trans('invoices.add_payment') }} + + @endif @endif