Skip to content

Commit

Permalink
Fixed missing document totals relation then add payment button action..
Browse files Browse the repository at this point in the history
  • Loading branch information
cuneytsenturk committed Jun 19, 2023
1 parent 1d7b140 commit 962d678
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 29 deletions.
34 changes: 23 additions & 11 deletions app/Models/Document/Document.php
Expand Up @@ -538,17 +538,29 @@ public function getLineActionsAttribute()

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) {}
}

Expand Down
2 changes: 2 additions & 0 deletions resources/lang/en-GB/invoices.php
Expand Up @@ -50,6 +50,8 @@

'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 <b>DRAFT</b> invoice and will be reflected to charts after it gets sent.',

'status' => [
Expand Down
4 changes: 4 additions & 0 deletions resources/views/components/documents/show/content.blade.php
Expand Up @@ -34,6 +34,10 @@
@if ($document->status == 'draft')
<x-documents.show.message type="status" background-color="bg-red-100" text-color="text-red-600" message="{!! trans($textStatusMessage) !!}" />
@endif

@if (! $document->totals->count())
<x-documents.show.message type="status" background-color="bg-red-100" text-color="text-red-600" message="{!! trans('invoices.messages.totals_required', ['type' => $type]) !!}" />
@endif
@endif

@stack('status_message_end')
Expand Down
26 changes: 17 additions & 9 deletions resources/views/components/documents/show/get-paid.blade.php
Expand Up @@ -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)))
<x-button
@click="onAddPayment('{{ route('modals.documents.document.transactions.create', $document->id) }}')"
id="show-slider-actions-payment-{{ $document->type }}"
class="px-3 py-1.5 mb-3 sm:mb-0 rounded-lg text-xs font-medium leading-6 bg-green hover:bg-green-700 text-white disabled:bg-green-100"
override="class"
>
{{ trans('invoices.add_payment') }}
</x-button>
@if ($document->totals->count())
@if ($document->status != 'paid' && (empty($document->transactions->count()) || (! empty($document->transactions->count()) && $document->paid != $document->amount)))
<x-button
@click="onAddPayment('{{ route('modals.documents.document.transactions.create', $document->id) }}')"
id="show-slider-actions-payment-{{ $document->type }}"
class="px-3 py-1.5 mb-3 sm:mb-0 rounded-lg text-xs font-medium leading-6 bg-green hover:bg-green-700 text-white disabled:bg-green-100"
override="class"
>
{{ trans('invoices.add_payment') }}
</x-button>
@endif
@else
<x-tooltip message="{{ trans('invoices.messages.totals_required', ['type' => $type]) }}" placement="top">
<x-dropdown.button disabled="disabled">
{{ trans('invoices.add_payment') }}
</x-dropdown.button>
</x-tooltip>
@endif
@endif

Expand Down
26 changes: 17 additions & 9 deletions resources/views/components/documents/show/make-payment.blade.php
Expand Up @@ -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)) )
<x-button
@click="onAddPayment('{{ route('modals.documents.document.transactions.create', $document->id) }}')"
id="show-slider-actions-payment-{{ $document->type }}"
class="px-3 py-1.5 mb-3 sm:mb-0 rounded-lg text-xs font-medium leading-6 bg-green hover:bg-green-700 text-white disabled:bg-green-100"
override="class"
>
{{ trans('invoices.add_payment') }}
</x-button>
@if ($document->totals->count())
@if ($document->status != 'paid' && (empty($document->transactions->count()) || (! empty($document->transactions->count()) && $document->paid != $document->amount)) )
<x-button
@click="onAddPayment('{{ route('modals.documents.document.transactions.create', $document->id) }}')"
id="show-slider-actions-payment-{{ $document->type }}"
class="px-3 py-1.5 mb-3 sm:mb-0 rounded-lg text-xs font-medium leading-6 bg-green hover:bg-green-700 text-white disabled:bg-green-100"
override="class"
>
{{ trans('invoices.add_payment') }}
</x-button>
@endif
@else
<x-tooltip message="{{ trans('invoices.messages.totals_required', ['type' => $type]) }}" placement="top">
<x-button disabled="disabled">
{{ trans('invoices.add_payment') }}
</x-button>
</x-tooltip>
@endif
@endif

Expand Down

0 comments on commit 962d678

Please sign in to comment.