diff --git a/app/Http/Controllers/ClientController.php b/app/Http/Controllers/ClientController.php index 54a9d5a817..8a6beffcc8 100644 --- a/app/Http/Controllers/ClientController.php +++ b/app/Http/Controllers/ClientController.php @@ -188,7 +188,6 @@ class ClientController extends BaseController 'data' => Input::old('data'), 'account' => Auth::user()->account, 'sizes' => Cache::get('sizes'), - 'paymentTerms' => Cache::get('paymentTerms'), 'currencies' => Cache::get('currencies'), 'customLabel1' => Auth::user()->account->custom_client_label1, 'customLabel2' => Auth::user()->account->custom_client_label2, diff --git a/app/Http/Controllers/InvoiceController.php b/app/Http/Controllers/InvoiceController.php index 54cc53da1d..04bc692b87 100644 --- a/app/Http/Controllers/InvoiceController.php +++ b/app/Http/Controllers/InvoiceController.php @@ -303,7 +303,6 @@ class InvoiceController extends BaseController 'defaultTax' => $account->default_tax_rate, 'currencies' => Cache::get('currencies'), 'sizes' => Cache::get('sizes'), - 'paymentTerms' => Cache::get('paymentTerms'), 'invoiceDesigns' => InvoiceDesign::getDesigns(), 'invoiceFonts' => Cache::get('fonts'), 'frequencies' => \App\Models\Frequency::selectOptions(), diff --git a/app/Http/Controllers/PaymentTermController.php b/app/Http/Controllers/PaymentTermController.php index ee215b1b64..e92e530356 100644 --- a/app/Http/Controllers/PaymentTermController.php +++ b/app/Http/Controllers/PaymentTermController.php @@ -112,8 +112,8 @@ class PaymentTermController extends BaseController $paymentTerm = PaymentTerm::createNew(); } - $paymentTerm->name = trim(Input::get('name')); $paymentTerm->num_days = Utils::parseInt(Input::get('num_days')); + $paymentTerm->name = 'Net ' . $paymentTerm->num_days; $paymentTerm->save(); $message = $publicId ? trans('texts.updated_payment_term') : trans('texts.created_payment_term'); diff --git a/app/Models/PaymentTerm.php b/app/Models/PaymentTerm.php index 814ad3d9f2..899d239e29 100644 --- a/app/Models/PaymentTerm.php +++ b/app/Models/PaymentTerm.php @@ -2,6 +2,7 @@ namespace App\Models; +use Cache; use Illuminate\Database\Eloquent\SoftDeletes; /** @@ -9,7 +10,7 @@ use Illuminate\Database\Eloquent\SoftDeletes; */ class PaymentTerm extends EntityModel { - //use SoftDeletes; + use SoftDeletes; /** * @var bool @@ -27,4 +28,15 @@ class PaymentTerm extends EntityModel { return ENTITY_PAYMENT_TERM; } + + public static function getSelectOptions() + { + $terms = Cache::get('paymentTerms'); + + foreach (PaymentTerm::scope()->get() as $term) { + $terms->push($term); + } + + return $terms->sortBy('num_days'); + } } diff --git a/resources/views/accounts/details.blade.php b/resources/views/accounts/details.blade.php index 8c9c719d29..4ca72a5629 100644 --- a/resources/views/accounts/details.blade.php +++ b/resources/views/accounts/details.blade.php @@ -96,7 +96,7 @@ {!! Former::select('payment_terms') ->addOption('','') - ->fromQuery(Cache::get('paymentTerms'), 'name', 'num_days') + ->fromQuery(\App\Models\PaymentTerm::getSelectOptions(), 'name', 'num_days') ->help(trans('texts.payment_terms_help') . ' | ' . link_to('/settings/payment_terms', trans('texts.customize_options'))) !!} diff --git a/resources/views/clients/edit.blade.php b/resources/views/clients/edit.blade.php index 8b3b931d51..1abf8912ce 100644 --- a/resources/views/clients/edit.blade.php +++ b/resources/views/clients/edit.blade.php @@ -126,7 +126,7 @@ ->placeholder($account->language ? trans('texts.lang_'.$account->language->name) : '') ->fromQuery($languages, 'name', 'id') !!} {!! Former::select('payment_terms')->addOption('','') - ->fromQuery($paymentTerms, 'name', 'num_days') + ->fromQuery(\App\Models\PaymentTerm::getSelectOptions(), 'name', 'num_days') ->placeholder($account->present()->paymentTerms) ->help(trans('texts.payment_terms_help')) !!} {!! Former::select('size_id')->addOption('','') diff --git a/resources/views/invoices/edit.blade.php b/resources/views/invoices/edit.blade.php index 1abac66ae5..9799f54a67 100644 --- a/resources/views/invoices/edit.blade.php +++ b/resources/views/invoices/edit.blade.php @@ -729,7 +729,7 @@ ->data_bind('value: language_id') ->fromQuery($languages, 'name', 'id') !!} {!! Former::select('client[payment_terms]')->addOption('','')->data_bind('value: payment_terms') - ->fromQuery($paymentTerms, 'name', 'num_days') + ->fromQuery(\App\Models\PaymentTerm::getSelectOptions(), 'name', 'num_days') ->label(trans('texts.payment_terms')) ->help(trans('texts.payment_terms_help')) !!} {!! Former::select('client[size_id]')->addOption('','')->data_bind('value: size_id')