diff --git a/app/Http/Controllers/Settings/Localisation.php b/app/Http/Controllers/Settings/Localisation.php index ea95628ba..fc7200491 100644 --- a/app/Http/Controllers/Settings/Localisation.php +++ b/app/Http/Controllers/Settings/Localisation.php @@ -41,12 +41,20 @@ class Localisation extends Controller 'after' => trans('settings.localisation.percent.after'), ]; + $discount_locations = [ + 'no' => trans('general.disabled'), + 'item' => trans('settings.localisation.discount_location.item'), + 'total' => trans('settings.localisation.discount_location.total'), + 'both' => trans('settings.localisation.discount_location.both'), + ]; + return view('settings.localisation.edit', compact( 'setting', 'timezones', 'date_formats', 'date_separators', - 'percent_positions' + 'percent_positions', + 'discount_locations' )); } } diff --git a/app/Models/Purchase/BillItem.php b/app/Models/Purchase/BillItem.php index 942454b40..34e5710c8 100644 --- a/app/Models/Purchase/BillItem.php +++ b/app/Models/Purchase/BillItem.php @@ -13,6 +13,13 @@ class BillItem extends Model protected $table = 'bill_items'; + /** + * The accessors to append to the model's array form. + * + * @var array + */ + protected $appends = ['discount']; + /** * Attributes that should be mass-assignable. * @@ -100,12 +107,12 @@ class BillItem extends Model * * @return string */ - public function getDiscountRateAttribute($value) + public function getDiscountAttribute() { if (setting('localisation.percent_position', 'after') === 'after') { - $text = ($this->discount_type === 'normal') ? $value . '%' : $value; + $text = ($this->discount_type === 'normal') ? $this->discount_rate . '%' : $this->discount_rate; } else { - $text = ($this->discount_type === 'normal') ? '%' . $value : $value; + $text = ($this->discount_type === 'normal') ? '%' . $this->discount_rate : $this->discount_rate; } return $text; diff --git a/app/Models/Sale/InvoiceItem.php b/app/Models/Sale/InvoiceItem.php index e55577291..10c3ddab1 100644 --- a/app/Models/Sale/InvoiceItem.php +++ b/app/Models/Sale/InvoiceItem.php @@ -12,6 +12,13 @@ class InvoiceItem extends Model protected $table = 'invoice_items'; + /** + * The accessors to append to the model's array form. + * + * @var array + */ + protected $appends = ['discount']; + /** * Attributes that should be mass-assignable. * @@ -99,12 +106,12 @@ class InvoiceItem extends Model * * @return string */ - public function getDiscountRateAttribute($value) + public function getDiscountAttribute() { if (setting('localisation.percent_position', 'after') === 'after') { - $text = ($this->discount_type === 'normal') ? $value . '%' : $value; + $text = ($this->discount_type === 'normal') ? $this->discount_rate . '%' : $this->discount_rate; } else { - $text = ($this->discount_type === 'normal') ? '%' . $value : $value; + $text = ($this->discount_type === 'normal') ? '%' . $this->discount_rate : $this->discount_rate; } return $text; diff --git a/resources/lang/en-GB/bills.php b/resources/lang/en-GB/bills.php index 5914cf59b..6c2831b9e 100644 --- a/resources/lang/en-GB/bills.php +++ b/resources/lang/en-GB/bills.php @@ -13,7 +13,7 @@ return [ 'price' => 'Price', 'sub_total' => 'Subtotal', 'discount' => 'Discount', - 'item_discount' => 'Item Discount', + 'item_discount' => 'Line Discount', 'tax_total' => 'Tax Total', 'total' => 'Total', diff --git a/resources/lang/en-GB/invoices.php b/resources/lang/en-GB/invoices.php index e06ce9a68..a2719ca16 100644 --- a/resources/lang/en-GB/invoices.php +++ b/resources/lang/en-GB/invoices.php @@ -13,7 +13,7 @@ return [ 'price' => 'Price', 'sub_total' => 'Subtotal', 'discount' => 'Discount', - 'item_discount' => 'Item Discount', + 'item_discount' => 'Line Discount', 'tax_total' => 'Tax Total', 'total' => 'Total', diff --git a/resources/lang/en-GB/settings.php b/resources/lang/en-GB/settings.php index 044061471..394c2910d 100644 --- a/resources/lang/en-GB/settings.php +++ b/resources/lang/en-GB/settings.php @@ -29,6 +29,12 @@ return [ 'before' => 'Before Number', 'after' => 'After Number', ], + 'discount_location' => [ + 'name' => 'Discount Location', + 'item' => 'At line', + 'total' => 'At total', + 'both' => 'Both line and total', + ], ], 'invoice' => [ diff --git a/resources/views/purchases/bills/create.blade.php b/resources/views/purchases/bills/create.blade.php index f344556cb..3840b6274 100644 --- a/resources/views/purchases/bills/create.blade.php +++ b/resources/views/purchases/bills/create.blade.php @@ -30,6 +30,7 @@ {{ Form::textGroup('order_number', trans('bills.order_number'), 'shopping-cart',[]) }}
+ @php $item_colspan = in_array(setting('localisation.discount_location', 'total'), ['item', 'both']) ? '6' : '5' @endphp {!! Form::label('items', trans_choice('general.items', 2), ['class' => 'form-control-label']) !!}
@@ -51,9 +52,11 @@ @stack('price_th_end') - @stack('discount_th_start') - - @stack('discount_th_end') + @if (in_array(setting('localisation.discount_location', 'total'), ['item', 'both'])) + @stack('discount_th_start') + + @stack('discount_th_end') + @endif @stack('taxes_th_start') @@ -73,13 +76,13 @@ - + @stack('add_item_td_end') @stack('sub_total_td_start') - @stack('sub_total_td_end') - @stack('item_discount_td_start') - - - - - @stack('item_discount_td_end') - - @stack('add_discount_td_start') - - + - - @stack('add_discount_td_end') + @stack('item_discount_td_end') + @endif + + @if (in_array(setting('localisation.discount_location', 'total'), ['total', 'both'])) + @stack('add_discount_td_start') + + + + + @stack('add_discount_td_end') + @endif @stack('tax_total_td_start') - -
{{ trans('bills.price') }}{{ trans('bills.discount') }}{{ trans('bills.discount') }}{{ trans_choice('general.taxes', 1) }}
+ {{ trans('bills.sub_total') }} @@ -90,74 +93,78 @@
- {{ trans('bills.item_discount') }} - - {{ Form::moneyGroup('item_discount', '', '', ['disabled' => true, 'required' => 'required', 'v-model' => 'totals.item_discount', 'currency' => $currency, 'masked' => 'true'], 0.00, 'text-right d-none') }} - - @money(0, $currency->code, true) -
- -
-
-
-
-
-
- - - -
- {!! Form::number('pre_discount', null, ['id' => 'pre-discount', 'class' => 'form-control']) !!} -
-
-
-
- {{ trans('invoices.discount_desc') }} -
-
-
-
- -
- {{ trans('invoices.add_discount') }} - -
+ @if (in_array(setting('localisation.discount_location', 'total'), ['item', 'both'])) + @stack('item_discount_td_start') +
+ {{ trans('bills.item_discount') }} - {{ Form::moneyGroup('discount_total', '', '', ['disabled' => true, 'required' => 'required', 'v-model' => 'totals.discount', 'currency' => $currency, 'masked' => 'true'], 0.00, 'text-right d-none') }} - + + {{ Form::moneyGroup('item_discount', '', '', ['disabled' => true, 'required' => 'required', 'v-model' => 'totals.item_discount', 'currency' => $currency, 'masked' => 'true'], 0.00, 'text-right d-none') }} + @money(0, $currency->code, true) - {!! Form::hidden('discount', null, ['id' => 'discount', 'class' => 'form-control text-right', 'v-model' => 'form.discount']) !!}
+ +
+
+
+
+
+
+ + + +
+ {!! Form::number('pre_discount', null, ['id' => 'pre-discount', 'class' => 'form-control']) !!} +
+
+
+
+ {{ trans('invoices.discount_desc') }} +
+
+
+
+ +
+ {{ trans('invoices.add_discount') }} + +
+
+ {{ Form::moneyGroup('discount_total', '', '', ['disabled' => true, 'required' => 'required', 'v-model' => 'totals.discount', 'currency' => $currency, 'masked' => 'true'], 0.00, 'text-right d-none') }} + + @money(0, $currency->code, true) + {!! Form::hidden('discount', null, ['id' => 'discount', 'class' => 'form-control text-right', 'v-model' => 'form.discount']) !!} +
+ {{ trans_choice('general.taxes', 1) }} @@ -170,7 +177,7 @@ @stack('grand_total_td_start')
+ {{ trans('bills.total') }} diff --git a/resources/views/purchases/bills/edit.blade.php b/resources/views/purchases/bills/edit.blade.php index 56c29f50a..8be122eb6 100644 --- a/resources/views/purchases/bills/edit.blade.php +++ b/resources/views/purchases/bills/edit.blade.php @@ -31,6 +31,7 @@ {{ Form::textGroup('order_number', trans('bills.order_number'), 'shopping-cart',[]) }}
+ @php $item_colspan = in_array(setting('localisation.discount_location', 'total'), ['item', 'both']) ? '6' : '5' @endphp {!! Form::label('items', trans_choice('general.items', 2), ['class' => 'control-label']) !!}
@@ -52,9 +53,11 @@ @stack('price_th_end') - @stack('discount_th_start') - - @stack('discount_th_end') + @if (in_array(setting('localisation.discount_location', 'total'), ['item', 'both'])) + @stack('discount_th_start') + + @stack('discount_th_end') + @endif @stack('taxes_th_start') @@ -74,13 +77,13 @@ - + @stack('add_item_td_end') @stack('sub_total_td_start') - @stack('sub_total_td_end') - @stack('add_discount_td_start') - - + + + + @stack('item_discount_td_end') + @endif + + @if (in_array(setting('localisation.discount_location', 'total'), ['total', 'both'])) + @stack('add_discount_td_start') + + - - - @stack('add_discount_td_end') + {{ trans('bills.add_discount') }} + + + + + + @stack('add_discount_td_end') + @endif @stack('tax_total_td_start') - - @stack('price_td_end') - @stack('discount_td_start') - - @stack('discount_td_end') + @stack('discount_input_end') + + @stack('discount_td_end') + @endif @stack('taxes_td_start') - @stack('discount_th_end') + @if (in_array(setting('localisation.discount_location', 'total'), ['item', 'both'])) + @stack('discount_th_start') + + @stack('discount_th_end') + @endif @stack('total_th_start') @@ -366,9 +368,11 @@ @stack('price_td_end') - @stack('discount_td_start') - - @stack('discount_td_end') + @if (in_array(setting('localisation.discount_location', 'total'), ['item', 'both'])) + @stack('discount_td_start') + + @stack('discount_td_end') + @endif @stack('total_td_start') diff --git a/resources/views/sales/invoices/create.blade.php b/resources/views/sales/invoices/create.blade.php index c35745c1b..5d3212b6e 100644 --- a/resources/views/sales/invoices/create.blade.php +++ b/resources/views/sales/invoices/create.blade.php @@ -30,6 +30,7 @@ {{ Form::textGroup('order_number', trans('invoices.order_number'), 'shopping-cart', []) }}
+ @php $item_colspan = in_array(setting('localisation.discount_location', 'total'), ['item', 'both']) ? '6' : '5' @endphp {!! Form::label('items', trans_choice($text_override['items'], 2), ['class' => 'form-control-label']) !!}
{{ trans('bills.price') }}{{ trans('bills.discount') }}{{ trans('bills.discount') }}{{ trans_choice('general.taxes', 1) }}
+ {{ trans('bills.sub_total') }} @@ -91,61 +94,78 @@
- -
-
-
-
-
-
- - - + @if (in_array(setting('localisation.discount_location', 'total'), ['item', 'both'])) + @stack('item_discount_td_start') +
+ {{ trans('bills.item_discount') }} + + {{ Form::moneyGroup('item_discount', '', '', ['disabled' => true, 'required' => 'required', 'v-model' => 'totals.item_discount', 'currency' => $currency, 'masked' => 'true'], 0.00, 'text-right d-none') }} + + @money(0, $currency->code, true) +
+ +
+
+
+
+
+
+ + + +
+ {!! Form::number('pre_discount', null, ['id' => 'pre-discount', 'class' => 'form-control']) !!} +
+
+
+
+ {{ trans('bills.discount_desc') }}
- {!! Form::number('pre_discount', null, ['id' => 'pre-discount', 'class' => 'form-control']) !!}
-
-
- {{ trans('invoices.discount_desc') }} +
+
- -
- {{ trans('invoices.add_discount') }} - - -
- {{ Form::moneyGroup('discount_total', '', '', ['disabled' => true, 'required' => 'required', 'v-model' => 'totals.discount', 'currency' => $currency, 'masked' => 'true'], 0.00, 'text-right d-none') }} - - @money(0, $currency->code, true) - {!! Form::hidden('discount', null, ['id' => 'discount', 'class' => 'form-control text-right', 'v-model' => 'form.discount']) !!} -
+ {{ Form::moneyGroup('discount_total', '', '', ['disabled' => true, 'required' => 'required', 'v-model' => 'totals.discount', 'currency' => $currency, 'masked' => 'true'], 0.00, 'text-right d-none') }} + + @money(0, $currency->code, true) + {!! Form::hidden('discount', null, ['id' => 'discount', 'class' => 'form-control text-right', 'v-model' => 'form.discount']) !!} +
+ {{ trans_choice('general.taxes', 1) }} @@ -158,7 +178,7 @@ @stack('grand_total_td_start')
+ {{ trans('bills.total') }} diff --git a/resources/views/purchases/bills/item.blade.php b/resources/views/purchases/bills/item.blade.php index 17413efb0..f53a15264 100644 --- a/resources/views/purchases/bills/item.blade.php +++ b/resources/views/purchases/bills/item.blade.php @@ -98,36 +98,38 @@ - @stack('discount_input_start') -
-
- - - -
- + @if (in_array(setting('localisation.discount_location', 'total'), ['item', 'both'])) + @stack('discount_td_start') +
+ @stack('discount_input_start') +
+
+ + + +
+ -
+
+
-
- @stack('discount_input_end') -
{{ trans('bills.price') }} @stack('price_th_end') - @stack('discount_th_start') - {{ trans('bills.discount') }}{{ trans('bills.discount') }}{{ trans('bills.total') }}@money($bill_item->price, $bill->currency_code, true){{ $bill_item->discount_rate }}{{ $bill_item->discount }}@money($bill_item->total, $bill->currency_code, true)
@@ -51,9 +52,11 @@ @stack('price_th_end') - @stack('discount_th_start') - - @stack('discount_th_end') + @if (in_array(setting('localisation.discount_location', 'total'), ['item', 'both'])) + @stack('discount_th_start') + + @stack('discount_th_end') + @endif @stack('taxes_th_start') @@ -73,13 +76,13 @@ - + @stack('add_item_td_end') @stack('sub_total_td_start') - @stack('sub_total_td_end') - @stack('item_discount_td_start') - - - - - @stack('item_discount_td_end') + @if (in_array(setting('localisation.discount_location', 'total'), ['item', 'both'])) + @stack('item_discount_td_start') + + + + + @stack('item_discount_td_end') + @endif - @stack('add_discount_td_start') - - + - - - @stack('add_discount_td_end') + {{ trans('invoices.add_discount') }} + + + + + + @stack('add_discount_td_end') + @endif @stack('tax_total_td_start') - -
{{ trans($text_override['price']) }}{{ trans('invoices.discount') }}{{ trans('invoices.discount') }}{{ trans_choice('general.taxes', 1) }}
+ {{ trans('invoices.sub_total') }} @@ -90,74 +93,78 @@
- {{ trans('invoices.item_discount') }} - - {{ Form::moneyGroup('item_discount', '', '', ['disabled' => true, 'required' => 'required', 'v-model' => 'totals.item_discount', 'currency' => $currency, 'masked' => 'true'], 0.00, 'text-right d-none') }} - - @money(0, $currency->code, true) -
+ {{ trans('invoices.item_discount') }} + + {{ Form::moneyGroup('item_discount', '', '', ['disabled' => true, 'required' => 'required', 'v-model' => 'totals.item_discount', 'currency' => $currency, 'masked' => 'true'], 0.00, 'text-right d-none') }} + + @money(0, $currency->code, true) +
- -
-
-
-
-
-
- - - + @if (in_array(setting('localisation.discount_location', 'total'), ['total', 'both'])) + @stack('add_discount_td_start') +
+ +
+
+
+
+
+
+ + + +
+ {!! Form::number('pre_discount', null, ['id' => 'pre-discount', 'class' => 'form-control']) !!} +
+
+
+
+ {{ trans('invoices.discount_desc') }}
- {!! Form::number('pre_discount', null, ['id' => 'pre-discount', 'class' => 'form-control']) !!}
-
-
- {{ trans('invoices.discount_desc') }} +
+
- -
- {{ trans('invoices.add_discount') }} - - -
- {{ Form::moneyGroup('discount_total', '', '', ['disabled' => true, 'required' => 'required', 'v-model' => 'totals.discount', 'currency' => $currency, 'masked' => 'true'], 0.00, 'text-right d-none') }} - - @money(0, $currency->code, true) - {!! Form::hidden('discount', null, ['id' => 'discount', 'class' => 'form-control text-right', 'v-model' => 'form.discount']) !!} -
+ {{ Form::moneyGroup('discount_total', '', '', ['disabled' => true, 'required' => 'required', 'v-model' => 'totals.discount', 'currency' => $currency, 'masked' => 'true'], 0.00, 'text-right d-none') }} + + @money(0, $currency->code, true) + {!! Form::hidden('discount', null, ['id' => 'discount', 'class' => 'form-control text-right', 'v-model' => 'form.discount']) !!} +
+ {{ trans_choice('general.taxes', 1) }} @@ -170,7 +177,7 @@ @stack('grand_total_td_start')
+ {{ trans('invoices.total') }} diff --git a/resources/views/sales/invoices/edit.blade.php b/resources/views/sales/invoices/edit.blade.php index 2af8841d9..793a6dd33 100644 --- a/resources/views/sales/invoices/edit.blade.php +++ b/resources/views/sales/invoices/edit.blade.php @@ -31,6 +31,7 @@ {{ Form::textGroup('order_number', trans('invoices.order_number'), 'shopping-cart',[]) }}
+ @php $item_colspan = in_array(setting('localisation.discount_location', 'total'), ['item', 'both']) ? '6' : '5' @endphp {!! Form::label('items', trans_choice($text_override['items'], 2), ['class' => 'control-label']) !!}
@@ -52,9 +53,11 @@ @stack('price_th_end') - @stack('discount_th_start') - - @stack('discount_th_end') + @if (in_array(setting('localisation.discount_location', 'total'), ['item', 'both'])) + @stack('discount_th_start') + + @stack('discount_th_end') + @endif @stack('taxes_th_start') @@ -74,13 +77,13 @@ - + @stack('add_item_td_end') @stack('sub_total_td_start') - @stack('sub_total_td_end') - @stack('add_discount_td_start') - - + + + + @stack('item_discount_td_end') + @endif + + @if (in_array(setting('localisation.discount_location', 'total'), ['total', 'both'])) + @stack('add_discount_td_start') + + - - - @stack('add_discount_td_end') + {{ trans('invoices.add_discount') }} + + + + + + @stack('add_discount_td_end') + @endif @stack('tax_total_td_start') - - @stack('price_td_end') - @stack('discount_td_start') - - @stack('discount_td_end') + @stack('discount_input_end') + + @stack('discount_td_end') + @endif @stack('taxes_td_start') - @stack('discount_th_end') + @if (in_array(setting('localisation.discount_location', 'total'), ['item', 'both'])) + @stack('discount_th_start') + + @stack('discount_th_end') + @endif @stack('total_th_start') @@ -383,9 +385,11 @@ @stack('price_td_end') - @stack('discount_td_start') - - @stack('discount_td_end') + @if (in_array(setting('localisation.discount_location', 'total'), ['item', 'both'])) + @stack('discount_td_start') + + @stack('discount_td_end') + @endif @stack('total_td_start') diff --git a/resources/views/settings/localisation/edit.blade.php b/resources/views/settings/localisation/edit.blade.php index 055205843..1d259817f 100644 --- a/resources/views/settings/localisation/edit.blade.php +++ b/resources/views/settings/localisation/edit.blade.php @@ -27,6 +27,8 @@ {{ Form::selectGroup('date_separator', trans('settings.localisation.date.separator'), 'minus', $date_separators, $setting['date_separator'], []) }} {{ Form::selectGroup('percent_position', trans('settings.localisation.percent.title'), 'percent', $percent_positions, $setting['percent_position'], []) }} + + {{ Form::selectGroup('discount_location', trans('settings.localisation.discount_location.name'), 'percent', $discount_locations, !empty($setting['discount_location']) ? $setting['discount_location'] : 'total', []) }}
{{ trans($text_override['price']) }}{{ trans('invoices.discount') }}{{ trans('invoices.discount') }}{{ trans_choice('general.taxes', 1) }}
+ {{ trans('invoices.sub_total') }} @@ -91,61 +94,78 @@
- -
-
-
-
-
-
- - - + @if (in_array(setting('localisation.discount_location', 'total'), ['item', 'both'])) + @stack('item_discount_td_start') +
+ {{ trans('invoices.item_discount') }} + + {{ Form::moneyGroup('item_discount', '', '', ['disabled' => true, 'required' => 'required', 'v-model' => 'totals.item_discount', 'currency' => $currency, 'masked' => 'true'], 0.00, 'text-right d-none') }} + + @money(0, $currency->code, true) +
+ +
+
+
+
+
+
+ + + +
+ {!! Form::number('pre_discount', null, ['id' => 'pre-discount', 'class' => 'form-control']) !!} +
+
+
+
+ {{ trans('invoices.discount_desc') }}
- {!! Form::number('pre_discount', null, ['id' => 'pre-discount', 'class' => 'form-control']) !!}
-
-
- {{ trans('invoices.discount_desc') }} +
+
- -
- {{ trans('invoices.add_discount') }} - - -
- {{ Form::moneyGroup('discount_total', '', '', ['disabled' => true, 'required' => 'required', 'v-model' => 'totals.discount', 'currency' => $currency, 'masked' => 'true'], 0.00, 'text-right d-none') }} - - @money(0, $currency->code, true) - {!! Form::hidden('discount', null, ['id' => 'discount', 'class' => 'form-control text-right', 'v-model' => 'form.discount']) !!} -
+ {{ Form::moneyGroup('discount_total', '', '', ['disabled' => true, 'required' => 'required', 'v-model' => 'totals.discount', 'currency' => $currency, 'masked' => 'true'], 0.00, 'text-right d-none') }} + + @money(0, $currency->code, true) + {!! Form::hidden('discount', null, ['id' => 'discount', 'class' => 'form-control text-right', 'v-model' => 'form.discount']) !!} +
+ {{ trans_choice('general.taxes', 1) }} @@ -158,7 +178,7 @@ @stack('grand_total_td_start')
+ {{ trans('invoices.total') }} diff --git a/resources/views/sales/invoices/item.blade.php b/resources/views/sales/invoices/item.blade.php index ea085c498..1083bf0c4 100644 --- a/resources/views/sales/invoices/item.blade.php +++ b/resources/views/sales/invoices/item.blade.php @@ -98,36 +98,38 @@ - @stack('discount_input_start') -
-
- - - -
- + @if (in_array(setting('localisation.discount_location', 'total'), ['item', 'both'])) + @stack('discount_td_start') +
+ @stack('discount_input_start') +
+
+ + + +
+ -
+
+
-
- @stack('discount_input_end') -
{{ trans($text_override['price']) }} @stack('price_th_end') - @stack('discount_th_start') - {{ trans('invoices.discount') }}{{ trans('invoices.discount') }}{{ trans('invoices.total') }}@money($invoice_item->price, $invoice->currency_code, true){{ $invoice_item->discount_rate }}{{ $invoice_item->discount }}@money($invoice_item->total, $invoice->currency_code, true)