diff --git a/resources/views/invoices/edit.blade.php b/resources/views/invoices/edit.blade.php index 9d9bfb4cdc..31afd457d2 100644 --- a/resources/views/invoices/edit.blade.php +++ b/resources/views/invoices/edit.blade.php @@ -228,8 +228,11 @@ {!! Former::text('po_number')->label($account->getLabel('po_number', 'po_number_short'))->data_bind("value: po_number, valueUpdate: 'afterkeydown'") !!} {!! Former::text('discount')->data_bind("value: discount, valueUpdate: 'afterkeydown'") ->addGroupClass('discount-group')->type('number')->min('0')->step('any')->append( - Former::select('is_amount_discount')->addOption(trans('texts.discount_percent'), '0') - ->addOption(trans('texts.discount_amount'), '1')->data_bind("value: is_amount_discount")->raw() + Former::select('is_amount_discount') + ->addOption(trans('texts.discount_percent'), '0') + ->addOption(trans('texts.discount_amount'), '1') + ->data_bind("value: is_amount_discount, event:{ change: isAmountDiscountChanged}") + ->raw() ) !!} @if ($account->showCustomField('custom_invoice_text_label2', $invoice)) @@ -869,6 +872,15 @@ model.invoice().tax_name2("{{ $account->tax_name2 }}"); @endif @endif + + // load previous isAmountDiscount setting + if (isStorageSupported()) { + var lastIsAmountDiscount = parseInt(localStorage.getItem('last:is_amount_discount')); + console.log('lastIsAmountDiscount: ' + lastIsAmountDiscount); + if (lastIsAmountDiscount) { + model.invoice().is_amount_discount(lastIsAmountDiscount); + } + } @endif @if (isset($tasks) && $tasks) diff --git a/resources/views/invoices/knockout.blade.php b/resources/views/invoices/knockout.blade.php index f8f26d8b00..37003463b5 100644 --- a/resources/views/invoices/knockout.blade.php +++ b/resources/views/invoices/knockout.blade.php @@ -592,6 +592,18 @@ function InvoiceModel(data) { } self.applyInclusivTax(taxRate); } + + self.isAmountDiscountChanged = function(obj, event) { + console.log('onIsAmountDiscountChange... ' + event.originalEvent); + if (event.originalEvent) { + return; + } + if (! isStorageSupported()) { + return; + } + var isAmountDiscount = $('#is_amount_discount').val(); + localStorage.setItem('last:is_amount_discount', isAmountDiscount); + } } function ClientModel(data) {