1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-09 12:42:36 +01:00
This commit is contained in:
Hillel Coren 2017-01-30 14:35:04 +02:00
parent ac705a8739
commit cc2a64acac
5 changed files with 36 additions and 12 deletions

View File

@ -1726,11 +1726,26 @@ class Account extends Eloquent
return $this->enable_email_markup;
}
public function defaultDueDate()
public function defaultDaysDue($client = false)
{
$numDays = $this->payment_terms == -1 ? 0 : $this->payment_terms;
if ($client && $client->payment_terms != 0) {
return $client->defaultDaysDue();
}
return Carbon::now($this->getTimezone())->addDays($numDays)->format('Y-m-d');
return $this->payment_terms == -1 ? 0 : $this->payment_terms;
}
public function defaultDueDate($client = false)
{
if ($client && $client->payment_terms != 0) {
$numDays = $client->defaultDaysDue();
} elseif ($this->payment_terms != 0) {
$numDays = $this->defaultDaysDue();
} else {
return null;
}
return Carbon::now()->addDays($numDays)->format('Y-m-d');
}
public function hasMultipleAccounts()

View File

@ -531,6 +531,11 @@ class Client extends EntityModel
public function hasAutoBillConfigurableInvoices(){
return $this->invoices()->whereIn('auto_bill', [AUTO_BILL_OPT_IN, AUTO_BILL_OPT_OUT])->count() > 0;
}
public function defaultDaysDue()
{
return $this->payment_terms == -1 ? 0 : $this->payment_terms;
}
}
Client::creating(function ($client) {

View File

@ -1031,13 +1031,12 @@ class Invoice extends EntityModel implements BalanceAffecting
if($dueDate) {
return date('Y-m-d', $dueDate);// SQL format
}
}
else if ($this->client->payment_terms != 0) {
} else if ($this->client->payment_terms != 0) {
// No custom due date set for this invoice; use the client's payment terms
$days = $this->client->payment_terms;
if ($days == -1) {
$days = 0;
}
$days = $this->client->defaultDaysDue();
return date('Y-m-d', strtotime('+'.$days.' day', $now));
} else if ($this->account->payment_terms != 0) {
$days = $this->account->defaultDaysDue();
return date('Y-m-d', strtotime('+'.$days.' day', $now));
}
}

View File

@ -5,6 +5,7 @@ use DB;
use Utils;
use Auth;
use Carbon;
use App\Models\Client;
use App\Models\Invoice;
use App\Models\InvoiceItem;
use App\Models\Invitation;
@ -308,8 +309,11 @@ class InvoiceRepository extends BaseRepository
if (isset($data['has_expenses']) && filter_var($data['has_expenses'], FILTER_VALIDATE_BOOLEAN)) {
$invoice->has_expenses = true;
}
if ($account->payment_terms != 0) {
$invoice->due_date = $account->defaultDueDate();
// set the default due date
if ($entityType == ENTITY_INVOICE) {
$client = Client::scope()->whereId($data['client_id'])->first();
$invoice->due_date = $account->defaultDueDate($client);
}
} else {
$invoice = Invoice::scope($publicId)->firstOrFail();
@ -667,6 +671,7 @@ class InvoiceRepository extends BaseRepository
}
$clone->invoice_number = $invoiceNumber ?: $account->getNextNumber($clone);
$clone->invoice_date = Utils::today(false)->format('Y-m-d');
$clone->due_date = $account->defaultDueDate($invoice->client);
foreach ([
'client_id',

View File

@ -149,7 +149,7 @@
{!! Former::text('invoice_date')->data_bind("datePicker: invoice_date, valueUpdate: 'afterkeydown'")->label(trans("texts.{$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(trans("texts.{$entityType}_due_date"))
->placeholder($invoice->exists ? ' ' : $account->present()->dueDatePlaceholder())
->placeholder($invoice->exists || $invoice->isQuote() ? ' ' : $account->present()->dueDatePlaceholder())
->data_date_format(Session::get(SESSION_DATE_PICKER_FORMAT, DEFAULT_DATE_PICKER_FORMAT))->appendIcon('calendar')->addGroupClass('due_date') !!}
{!! Former::text('partial')->data_bind("value: partial, valueUpdate: 'afterkeydown'")->onkeyup('onPartialChange()')