close #3199 Enhancement: Custom due date on receipt template

This commit is contained in:
Cüneyt Şentürk 2024-08-05 22:03:20 +03:00
parent c2ed4675f1
commit 8c7fd80d5a
9 changed files with 235 additions and 46 deletions

View File

@ -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',

View File

@ -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'
));
}
}

View File

@ -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());
}
}

View File

@ -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');
}
}

View File

@ -0,0 +1,42 @@
<?php
namespace App\View\Components\Form\Group;
use App\Abstracts\View\Components\Form;
class PaymentTerm extends Form
{
public $type = 'payment-term';
/**
* Get the view / contents that represent the component.
*
* @return \Illuminate\Contracts\View\View|string
*/
public function render()
{
$this->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');
}
}

View File

@ -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',

View File

@ -54,13 +54,11 @@
}
}
@endphp
<x-form.group.select
name="payment_terms"
<x-form.group.payment-term
label="{{ trans('invoices.payment_due') }}"
:options="$payment_terms"
:selected="(string) $payment_term"
visible-change="onChangeRecurringDate"
/>
/>
<x-form.input.hidden name="due_at" :value="old('due_at', $dueAt)" v-model="form.due_at" />
@else

View File

@ -0,0 +1,185 @@
@stack($name . '_input_start')
<div
@class([
'relative grid sm:grid-cols-6 gap-4 col-span-3',
$formGroupClass,
'required' => $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 . '")' }} }
]"
>
<akaunting-select
@class([
'relative',
'required' => $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))
<x-form.icon icon="{{ $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"
></akaunting-select>
<div class="col-span-3 grid sm:grid-cols-12 mt-6" v-show="form.{{ $name }} == 'custom'">
<x-form.group.text name="payment_terms" value="{{ !empty($value) ? $value : 0 }}" form-group-class="col-span-4" />
<div class="col-span-8 mt-3 ml-1">
{{ trans('settings.invoice.due_custom_day') }}
</div>
</div>
</div>
@stack($name . '_input_end')

View File

@ -18,7 +18,7 @@
<x-form.group.number name="number_next" label="{{ trans('settings.invoice.next') }}" value="{{ setting('invoice.number_next') }}" not-required />
<x-form.group.select name="payment_terms" label="{{ trans('settings.invoice.payment_terms') }}" :options="$payment_terms" :clearable="'false'" :selected="setting('invoice.payment_terms')" not-required />
<x-form.group.payment-term label="{{ trans('settings.invoice.payment_terms') }}" :clearable="'false'" :selected="setting('invoice.payment_terms')" not-required />
</x-slot>
</x-form.section>