mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-17 08:32:51 +01:00
Enable setting default payment terms
This commit is contained in:
parent
b954a9af8b
commit
7263e87db2
@ -89,6 +89,7 @@ class Account extends Eloquent
|
||||
'email_design_id',
|
||||
'enable_email_markup',
|
||||
'domain_id',
|
||||
'payment_terms',
|
||||
];
|
||||
|
||||
/**
|
||||
@ -1724,6 +1725,13 @@ class Account extends Eloquent
|
||||
|
||||
return $this->enable_email_markup;
|
||||
}
|
||||
|
||||
public function defaultDueDate()
|
||||
{
|
||||
$numDays = $this->payment_terms == -1 ? 0 : $this->payment_terms;
|
||||
|
||||
return Carbon::now($this->getTimezone())->addDays($numDays)->format('Y-m-d');
|
||||
}
|
||||
}
|
||||
|
||||
Account::updated(function ($account)
|
||||
|
@ -52,6 +52,17 @@ class AccountPresenter extends Presenter
|
||||
return $this->entity->size ? $this->entity->size->name : '';
|
||||
}
|
||||
|
||||
public function dueDatePlaceholder()
|
||||
{
|
||||
if ($this->entity->payment_terms == 0) {
|
||||
return ' ';
|
||||
}
|
||||
|
||||
$date = $this->entity->defaultDueDate();
|
||||
|
||||
return $date ? Utils::fromSqlDate($date) : ' ';
|
||||
}
|
||||
|
||||
private function createRBit($type, $source, $properties)
|
||||
{
|
||||
$data = new stdClass();
|
||||
|
@ -4,6 +4,7 @@ use App\Models\Account;
|
||||
use DB;
|
||||
use Utils;
|
||||
use Auth;
|
||||
use Carbon;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\InvoiceItem;
|
||||
use App\Models\Invitation;
|
||||
@ -305,6 +306,9 @@ 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();
|
||||
}
|
||||
} else {
|
||||
$invoice = Invoice::scope($publicId)->firstOrFail();
|
||||
if (Utils::isNinjaDev()) {
|
||||
@ -380,7 +384,7 @@ class InvoiceRepository extends BaseRepository
|
||||
$invoice->due_date = $data['due_date'];
|
||||
}
|
||||
} else {
|
||||
if (isset($data['due_date']) || isset($data['due_date_sql'])) {
|
||||
if (!empty($data['due_date']) || !empty($data['due_date_sql'])) {
|
||||
$invoice->due_date = isset($data['due_date_sql']) ? $data['due_date_sql'] : Utils::toSqlDate($data['due_date']);
|
||||
}
|
||||
$invoice->frequency_id = 0;
|
||||
|
@ -34,7 +34,7 @@ class AddInclusiveTaxes extends Migration
|
||||
$table->integer('client_number_counter')->default(0)->nullable();
|
||||
$table->text('client_number_pattern')->nullable();
|
||||
$table->tinyInteger('domain_id')->default(1)->nullable()->unsigned();
|
||||
$table->tinyInteger('payment_terms')->nullable()->unsigned();
|
||||
$table->tinyInteger('payment_terms')->nullable();
|
||||
});
|
||||
|
||||
Schema::table('activities', function ($table)
|
||||
|
@ -59,6 +59,11 @@
|
||||
</div>
|
||||
@endif
|
||||
|
||||
{!! Former::select('payment_terms')
|
||||
->addOption('','')
|
||||
->fromQuery(Cache::get('paymentTerms'), 'name', 'num_days')
|
||||
->help(trans('texts.payment_terms_help')) !!}
|
||||
|
||||
{!! Former::select('size_id')
|
||||
->addOption('','')
|
||||
->fromQuery($sizes, 'name', 'id') !!}
|
||||
|
@ -149,6 +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())
|
||||
->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()')
|
||||
|
Loading…
Reference in New Issue
Block a user