From 8c7fd80d5ae6df1edb5dc65a32f142a3d5d61efa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=BCneyt=20=C5=9Eent=C3=BCrk?= Date: Mon, 5 Aug 2024 22:03:20 +0300 Subject: [PATCH] close #3199 Enhancement: Custom due date on receipt template --- .../Modals/DocumentItemColumns.php | 10 - app/Http/Controllers/Settings/Invoice.php | 12 +- app/Http/ViewComposers/DocumentRecurring.php | 11 +- .../Documents/Form/RecurringMetadata.php | 11 +- .../Components/Form/Group/PaymentTerm.php | 42 ++++ resources/lang/en-GB/settings.php | 2 + .../form/recurring_metadata.blade.php | 6 +- .../form/group/payment_term.blade.php | 185 ++++++++++++++++++ .../views/settings/invoice/edit.blade.php | 2 +- 9 files changed, 235 insertions(+), 46 deletions(-) create mode 100644 app/View/Components/Form/Group/PaymentTerm.php create mode 100644 resources/views/components/form/group/payment_term.blade.php diff --git a/app/Http/Controllers/Modals/DocumentItemColumns.php b/app/Http/Controllers/Modals/DocumentItemColumns.php index 941434b3c..db5be4a91 100644 --- a/app/Http/Controllers/Modals/DocumentItemColumns.php +++ b/app/Http/Controllers/Modals/DocumentItemColumns.php @@ -51,15 +51,6 @@ class DocumentItemColumns extends Controller 'custom' => trans('settings.invoice.custom'), ]; - $payment_terms = [ - '0' => trans('settings.invoice.due_receipt'), - '15' => trans('settings.invoice.due_days', ['days' => 15]), - '30' => trans('settings.invoice.due_days', ['days' => 30]), - '45' => trans('settings.invoice.due_days', ['days' => 45]), - '60' => trans('settings.invoice.due_days', ['days' => 60]), - '90' => trans('settings.invoice.due_days', ['days' => 90]), - ]; - $item_name = setting($this->getDocumentSettingKey($type, 'item_name')); $item_name_input = setting($this->getDocumentSettingKey($type, 'item_name_input')); $price_name = setting($this->getDocumentSettingKey($type, 'price_name')); @@ -77,7 +68,6 @@ class DocumentItemColumns extends Controller 'item_names', 'price_names', 'quantity_names', - 'payment_terms', 'item_name', 'item_name_input', 'price_name', diff --git a/app/Http/Controllers/Settings/Invoice.php b/app/Http/Controllers/Settings/Invoice.php index 723b42660..effbbc85c 100644 --- a/app/Http/Controllers/Settings/Invoice.php +++ b/app/Http/Controllers/Settings/Invoice.php @@ -29,20 +29,10 @@ class Invoice extends SettingController 'custom' => trans('settings.invoice.custom'), ]; - $payment_terms = [ - '0' => trans('settings.invoice.due_receipt'), - '15' => trans('settings.invoice.due_days', ['days' => 15]), - '30' => trans('settings.invoice.due_days', ['days' => 30]), - '45' => trans('settings.invoice.due_days', ['days' => 45]), - '60' => trans('settings.invoice.due_days', ['days' => 60]), - '90' => trans('settings.invoice.due_days', ['days' => 90]), - ]; - return view('settings.invoice.edit', compact( 'item_names', 'price_names', - 'quantity_names', - 'payment_terms' + 'quantity_names' )); } } diff --git a/app/Http/ViewComposers/DocumentRecurring.php b/app/Http/ViewComposers/DocumentRecurring.php index 289767058..31f932ba8 100644 --- a/app/Http/ViewComposers/DocumentRecurring.php +++ b/app/Http/ViewComposers/DocumentRecurring.php @@ -30,21 +30,12 @@ class DocumentRecurring return; } - $payment_terms = [ - '0' => trans('settings.invoice.due_receipt'), - '15' => trans('settings.invoice.due_days', ['days' => 15]), - '30' => trans('settings.invoice.due_days', ['days' => 30]), - '45' => trans('settings.invoice.due_days', ['days' => 45]), - '60' => trans('settings.invoice.due_days', ['days' => 60]), - '90' => trans('settings.invoice.due_days', ['days' => 90]), - ]; - $view->with([ 'type' => $type, 'payment_terms' => $payment_terms, ]); // Override the whole file - $view->setPath(view('components.documents.form.recurring_metadata', compact('type', 'payment_terms'))->getPath()); + $view->setPath(view('components.documents.form.recurring_metadata', compact('type'))->getPath()); } } diff --git a/app/View/Components/Documents/Form/RecurringMetadata.php b/app/View/Components/Documents/Form/RecurringMetadata.php index 0ac39f825..acad9ccc9 100644 --- a/app/View/Components/Documents/Form/RecurringMetadata.php +++ b/app/View/Components/Documents/Form/RecurringMetadata.php @@ -13,15 +13,6 @@ class RecurringMetadata extends Component */ public function render() { - $payment_terms = [ - '0' => trans('settings.invoice.due_receipt'), - '15' => trans('settings.invoice.due_days', ['days' => 15]), - '30' => trans('settings.invoice.due_days', ['days' => 30]), - '45' => trans('settings.invoice.due_days', ['days' => 45]), - '60' => trans('settings.invoice.due_days', ['days' => 60]), - '90' => trans('settings.invoice.due_days', ['days' => 90]), - ]; - - return view('components.documents.form.recurring_metadata', compact('payment_terms')); + return view('components.documents.form.recurring_metadata'); } } diff --git a/app/View/Components/Form/Group/PaymentTerm.php b/app/View/Components/Form/Group/PaymentTerm.php new file mode 100644 index 000000000..4629a8b6c --- /dev/null +++ b/app/View/Components/Form/Group/PaymentTerm.php @@ -0,0 +1,42 @@ +name = 'temp_payment_term'; + + $payment_terms = [ + '0' => trans('settings.invoice.due_receipt'), + '7' => trans('settings.invoice.due_days', ['days' => 7]), + '15' => trans('settings.invoice.due_days', ['days' => 15]), + '30' => trans('settings.invoice.due_days', ['days' => 30]), + '45' => trans('settings.invoice.due_days', ['days' => 45]), + '60' => trans('settings.invoice.due_days', ['days' => 60]), + '90' => trans('settings.invoice.due_days', ['days' => 90]), + 'custom' => trans('settings.invoice.due_custom'), + ]; + + if (empty($this->options)) { + $this->options = $this->getOptions($payment_terms); + } + + if (! array_key_exists($this->selected, $payment_terms)) { + $this->value = $this->selected; + $this->selected = 'custom'; + } + + return view('components.form.group.payment_term'); + } +} diff --git a/resources/lang/en-GB/settings.php b/resources/lang/en-GB/settings.php index af82d038f..b9d3ff0a7 100644 --- a/resources/lang/en-GB/settings.php +++ b/resources/lang/en-GB/settings.php @@ -79,6 +79,8 @@ return [ 'subheading' => 'Subheading', 'due_receipt' => 'Due upon receipt', 'due_days' => 'Due within :days days', + 'due_custom' => 'Custom day(s)', + 'due_custom_day' => 'after day', 'choose_template' => 'Choose invoice template', 'default' => 'Default', 'classic' => 'Classic', diff --git a/resources/views/components/documents/form/recurring_metadata.blade.php b/resources/views/components/documents/form/recurring_metadata.blade.php index 482612636..3688c6992 100644 --- a/resources/views/components/documents/form/recurring_metadata.blade.php +++ b/resources/views/components/documents/form/recurring_metadata.blade.php @@ -54,13 +54,11 @@ } } @endphp - + /> @else diff --git a/resources/views/components/form/group/payment_term.blade.php b/resources/views/components/form/group/payment_term.blade.php new file mode 100644 index 000000000..4d0da36ab --- /dev/null +++ b/resources/views/components/form/group/payment_term.blade.php @@ -0,0 +1,185 @@ +@stack($name . '_input_start') +
$required, + 'readonly' => $readonly, + 'disabled' => $disabled, + ]) + + @if (isset($attributes['v-show'])) + v-if="{{ $attributes['v-show'] }}" + @endif + + :class="[ + {'has-error': {{ isset($attributes['v-error']) ? $attributes['v-error'] : 'form.errors.get("' . $name . '")' }} } + ]" +> + $required, + 'readonly' => $readonly, + 'disabled' => $disabled, + ]) + + ref="{{ $name }}" + + id="form-invoice-{{ $name }}" + + @if (isset($attributes['v-show'])) + v-if="{{ $attributes['v-show'] }}" + @endif + + @if (!empty($attributes['v-error'])) + :form-classes="[ + {'has-error': {{ $attributes['v-error'] }} }, + {'col-span-3': form.{{ $name }} == 'custom'}, + {'col-span-6': form.{{ $name }} != 'custom'} + ]" + @else + :form-classes="[ + {'has-error': form.errors.has('{{ $name }}') }, + {'col-span-3': form.{{ $name }} == 'custom'}, + {'col-span-6': form.{{ $name }} != 'custom'} + ]" + @endif + + @if (! $attributes->has('icon') && ! empty($icon->contents)) + {!! $icon ?? '' !!} + @elseif (! empty($icon)) + + @endif + + title="{!! $label !!}" + + @if (isset($attributes['placeholder'])) + placeholder="{{ $attributes['placeholder'] }}" + @else + placeholder="{{ trans('general.form.select.field', ['field' => $label]) }}" + @endif + + name="{{ $name }}" + + :options="{{ json_encode($options) }}" + + @if (isset($attributes['disabledOptions'])) + :disabled-options="{{ json_encode($attributes['disabledOptions']) }}" + @endif + + @if (isset($attributes['dynamicOptions'])) + :dynamic-options="{{ $attributes['dynamicOptions'] }}" + @endif + + @if (empty($multiple)) + @if (isset($selected) || old($name)) + value="{{ old($name, $selected) }}" + @endif + @else + @if (isset($selected) || old($name)) + :value="{{ json_encode(old($name, $selected)) }}" + @endif + + multiple + + @if (! empty($attributes['collapse'])) + collapse + @endif + @endif + + @if (! empty($attributes['model'])) + :model="{{ $attributes['model'] }}" + @endif + + @if (! empty($addNew)) + :add-new="{{ json_encode([ + 'status' => true, + 'text' => trans('general.add_new'), + 'path' => isset($attributes['path']) ? $attributes['path']: false, + 'type' => isset($attributes['type']) ? $attributes['type'] : 'modal', + 'field' => [ + 'key' => isset($attributes['field']['key']) ? $attributes['field']['key'] : 'id', + 'value' => isset($attributes['field']['value']) ? $attributes['field']['value'] : 'name' + ], + 'new_text' => trans('modules.new'), + 'buttons' => [ + 'cancel' => [ + 'text' => trans('general.cancel'), + 'class' => 'btn-outline-secondary' + ], + 'confirm' => [ + 'text' => trans('general.save'), + 'class' => 'disabled:bg-green-100' + ] + ] + ])}}" + @endif + + @if (! empty($group)) + group + @endif + + @if (! empty($attributes['v-model'])) + @interface="form.errors.clear('{{ $attributes['v-model'] }}'); ($event != 'custom') ? form.payment_terms = $event : form.payment_terms = {{ !empty($value) ? $value : 0 }}; {{ $attributes['v-model'] . ' = $event' }}" + @elseif (! empty($attributes['data-field'])) + @interface="form.errors.clear('{{ 'form.' . $attributes['data-field'] . '.' . $name }}'); ($event != 'custom') ? form.payment_terms = $event : form.payment_terms = {{ !empty($value) ? $value : 0 }}; {{ 'form.' . $attributes['data-field'] . '.' . $name . ' = $event' }}" + @else + @interface="form.errors.clear('{{ $name }}'); ($event != 'custom') ? form.payment_terms = $event : form.payment_terms = {{ !empty($value) ? $value : 0 }}; form.{{ $name }} = $event;" + @endif + + @if (! empty($attributes['change'])) + @change="{{ $attributes['change'] }}($event)" + @endif + + @if (! empty($attributes['visible-change'])) + @visible-change="{{ $attributes['visible-change'] }}" + @endif + + @if (isset($attributes['readonly'])) + :readonly="{{ $attributes['readonly'] }}" + @endif + + @if (isset($attributes['clearable'])) + :clearable="{{ $attributes['clearable'] }}" + @else + clearable + @endif + + @if (isset($attributes['v-disabled'])) + :disabled="{{ $attributes['v-disabled'] }}" + @endif + + @if (!$required) + :not-required={{ $required ? 'false' : 'true' }} + @endif + + @if (isset($attributes['v-error-message'])) + :form-error="{{ $attributes['v-error-message'] }}" + @else + :form-error="form.errors.get('{{ $name }}')" + @endif + + @if (! empty($remote)) + remote-action="{{ $attributes['remote_action'] }}" + + @if (! empty($attributes['currency_code'])) + currency-code="{{ $attributes['currency_code'] }}" + @endif + @endif + + loading-text="{{ trans('general.loading') }}" + no-data-text="{{ trans('general.no_data') }}" + no-matching-data-text="{{ trans('general.no_matching_data') }}" + + :sort-options="false" + > + +
+ +
+ {{ trans('settings.invoice.due_custom_day') }} +
+
+
+@stack($name . '_input_end') \ No newline at end of file diff --git a/resources/views/settings/invoice/edit.blade.php b/resources/views/settings/invoice/edit.blade.php index ba867fda5..2bff0a363 100644 --- a/resources/views/settings/invoice/edit.blade.php +++ b/resources/views/settings/invoice/edit.blade.php @@ -18,7 +18,7 @@ - +