From 748c1d38fb353011b7c040c6c4765e5268f2698a Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Sun, 15 Apr 2018 13:25:28 +0300 Subject: [PATCH] Don't apply payment terms to quotes --- app/Ninja/Repositories/InvoiceRepository.php | 2 +- resources/views/invoices/edit.blade.php | 2 +- resources/views/invoices/knockout.blade.php | 22 +++++++++++--------- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/app/Ninja/Repositories/InvoiceRepository.php b/app/Ninja/Repositories/InvoiceRepository.php index 9d405d1c1ce3..e6efdbca600a 100644 --- a/app/Ninja/Repositories/InvoiceRepository.php +++ b/app/Ninja/Repositories/InvoiceRepository.php @@ -392,7 +392,7 @@ class InvoiceRepository extends BaseRepository $invoice->custom_taxes2 = $account->custom_invoice_taxes2 ?: false; // set the default due date - if (empty($data['partial_due_date'])) { + if ($entityType == ENTITY_INVOICE && empty($data['partial_due_date'])) { $client = Client::scope()->whereId($data['client_id'])->first(); $invoice->due_date = $account->defaultDueDate($client); } diff --git a/resources/views/invoices/edit.blade.php b/resources/views/invoices/edit.blade.php index cda7db829bee..595fd120a8b3 100644 --- a/resources/views/invoices/edit.blade.php +++ b/resources/views/invoices/edit.blade.php @@ -190,7 +190,7 @@ {!! Former::text('invoice_date')->data_bind("datePicker: invoice_date, valueUpdate: 'afterkeydown'")->label($account->getLabel("{$entityType}_date")) ->data_date_format(Session::get(SESSION_DATE_PICKER_FORMAT, DEFAULT_DATE_PICKER_FORMAT))->appendIcon('calendar')->addGroupClass('invoice_date') !!} {!! Former::text('due_date')->data_bind("datePicker: due_date, valueUpdate: 'afterkeydown'")->label($account->getLabel($invoice->getDueDateLabel())) - ->placeholder($invoice->id ? ' ' : $account->present()->dueDatePlaceholder()) + ->placeholder($invoice->id || $invoice->isQuote() ? ' ' : $account->present()->dueDatePlaceholder()) ->data_date_format(Session::get(SESSION_DATE_PICKER_FORMAT, DEFAULT_DATE_PICKER_FORMAT))->appendIcon('calendar')->addGroupClass('due_date') !!}
diff --git a/resources/views/invoices/knockout.blade.php b/resources/views/invoices/knockout.blade.php index 0a6c532febe4..3d359354d9d7 100644 --- a/resources/views/invoices/knockout.blade.php +++ b/resources/views/invoices/knockout.blade.php @@ -25,16 +25,18 @@ function ViewModel(data) { } self.setDueDate = function() { - var paymentTerms = parseInt(self.invoice().client().payment_terms()); - if (paymentTerms && paymentTerms != 0 && !self.invoice().due_date()) { - if (paymentTerms == -1) paymentTerms = 0; - var dueDate = $('#invoice_date').datepicker('getDate'); - dueDate.setDate(dueDate.getDate() + paymentTerms); - dueDate = moment(dueDate).format("{{ $account->getMomentDateFormat() }}"); - $('#due_date').attr('placeholder', dueDate); - } else { - $('#due_date').attr('placeholder', "{{ $invoice->id ? ' ' : $account->present()->dueDatePlaceholder() }}"); - } + @if ($entityType == ENTITY_INVOICE) + var paymentTerms = parseInt(self.invoice().client().payment_terms()); + if (paymentTerms && paymentTerms != 0 && !self.invoice().due_date()) { + if (paymentTerms == -1) paymentTerms = 0; + var dueDate = $('#invoice_date').datepicker('getDate'); + dueDate.setDate(dueDate.getDate() + paymentTerms); + dueDate = moment(dueDate).format("{{ $account->getMomentDateFormat() }}"); + $('#due_date').attr('placeholder', dueDate); + } else { + $('#due_date').attr('placeholder', "{{ $invoice->id ? ' ' : $account->present()->dueDatePlaceholder() }}"); + } + @endif } self.clearBlankContacts = function() {