mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Refactor tax rate code
This commit is contained in:
parent
dd23b86a3f
commit
e01b61cef5
@ -219,6 +219,8 @@ class InvoiceController extends BaseController
|
|||||||
|
|
||||||
private static function getViewModel($invoice)
|
private static function getViewModel($invoice)
|
||||||
{
|
{
|
||||||
|
$account = Auth::user()->account;
|
||||||
|
|
||||||
$recurringHelp = '';
|
$recurringHelp = '';
|
||||||
$recurringDueDateHelp = '';
|
$recurringDueDateHelp = '';
|
||||||
$recurringDueDates = [];
|
$recurringDueDates = [];
|
||||||
@ -282,25 +284,6 @@ class InvoiceController extends BaseController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tax rate $options
|
|
||||||
$account = Auth::user()->account;
|
|
||||||
$rates = TaxRate::scope()->orderBy('name')->get();
|
|
||||||
$options = [];
|
|
||||||
$defaultTax = false;
|
|
||||||
|
|
||||||
foreach ($rates as $rate) {
|
|
||||||
$name = $rate->name . ' ' . ($rate->rate + 0) . '%';
|
|
||||||
if ($rate->is_inclusive) {
|
|
||||||
$name .= ' - ' . trans('texts.inclusive');
|
|
||||||
}
|
|
||||||
$options[($rate->is_inclusive ? '1 ' : '0 ') . $rate->rate . ' ' . $rate->name] = $name;
|
|
||||||
|
|
||||||
// load default invoice tax
|
|
||||||
if ($rate->id == $account->default_tax_rate_id) {
|
|
||||||
$defaultTax = $rate;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for any taxes which have been deleted
|
// Check for any taxes which have been deleted
|
||||||
if ($invoice->exists) {
|
if ($invoice->exists) {
|
||||||
foreach ($invoice->getTaxes() as $key => $rate) {
|
foreach ($invoice->getTaxes() as $key => $rate) {
|
||||||
@ -315,8 +298,8 @@ class InvoiceController extends BaseController
|
|||||||
'data' => Input::old('data'),
|
'data' => Input::old('data'),
|
||||||
'account' => Auth::user()->account->load('country'),
|
'account' => Auth::user()->account->load('country'),
|
||||||
'products' => Product::scope()->with('default_tax_rate')->orderBy('product_key')->get(),
|
'products' => Product::scope()->with('default_tax_rate')->orderBy('product_key')->get(),
|
||||||
'taxRateOptions' => $options,
|
'taxRateOptions' => $account->present()->taxRateOptions,
|
||||||
'defaultTax' => $defaultTax,
|
'defaultTax' => $account->default_tax_rate,
|
||||||
'currencies' => Cache::get('currencies'),
|
'currencies' => Cache::get('currencies'),
|
||||||
'sizes' => Cache::get('sizes'),
|
'sizes' => Cache::get('sizes'),
|
||||||
'paymentTerms' => Cache::get('paymentTerms'),
|
'paymentTerms' => Cache::get('paymentTerms'),
|
||||||
|
@ -93,31 +93,14 @@ class QuoteController extends BaseController
|
|||||||
|
|
||||||
private static function getViewModel()
|
private static function getViewModel()
|
||||||
{
|
{
|
||||||
// Tax rate $options
|
|
||||||
$account = Auth::user()->account;
|
$account = Auth::user()->account;
|
||||||
$rates = TaxRate::scope()->orderBy('name')->get();
|
|
||||||
$options = [];
|
|
||||||
$defaultTax = false;
|
|
||||||
|
|
||||||
foreach ($rates as $rate) {
|
|
||||||
$name = $rate->name . ' ' . ($rate->rate + 0) . '%';
|
|
||||||
if ($rate->is_inclusive) {
|
|
||||||
$name .= ' - ' . trans('texts.inclusive');
|
|
||||||
}
|
|
||||||
$options[($rate->is_inclusive ? '1 ' : '0 ') . $rate->rate . ' ' . $rate->name] = $name;
|
|
||||||
|
|
||||||
// load default invoice tax
|
|
||||||
if ($rate->id == $account->default_tax_rate_id) {
|
|
||||||
$defaultTax = $rate;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'entityType' => ENTITY_QUOTE,
|
'entityType' => ENTITY_QUOTE,
|
||||||
'account' => Auth::user()->account,
|
'account' => $account,
|
||||||
'products' => Product::scope()->orderBy('id')->get(['product_key', 'notes', 'cost', 'qty']),
|
'products' => Product::scope()->orderBy('id')->get(['product_key', 'notes', 'cost', 'qty']),
|
||||||
'taxRateOptions' => $options,
|
'taxRateOptions' => $account->present()->taxRateOptions,
|
||||||
'defaultTax' => $defaultTax,
|
'defaultTax' => $account->default_tax_rate,
|
||||||
'countries' => Cache::get('countries'),
|
'countries' => Cache::get('countries'),
|
||||||
'clients' => Client::scope()->with('contacts', 'country')->orderBy('name')->get(),
|
'clients' => Client::scope()->with('contacts', 'country')->orderBy('name')->get(),
|
||||||
'taxRates' => TaxRate::scope()->orderBy('name')->get(),
|
'taxRates' => TaxRate::scope()->orderBy('name')->get(),
|
||||||
|
@ -4,6 +4,7 @@ namespace App\Ninja\Presenters;
|
|||||||
|
|
||||||
use Carbon;
|
use Carbon;
|
||||||
use Domain;
|
use Domain;
|
||||||
|
use App\Models\TaxRate;
|
||||||
use Laracasts\Presenter\Presenter;
|
use Laracasts\Presenter\Presenter;
|
||||||
use stdClass;
|
use stdClass;
|
||||||
use Utils;
|
use Utils;
|
||||||
@ -132,4 +133,20 @@ class AccountPresenter extends Presenter
|
|||||||
|
|
||||||
return $str;
|
return $str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function taxRateOptions()
|
||||||
|
{
|
||||||
|
$rates = TaxRate::scope()->orderBy('name')->get();
|
||||||
|
$options = [];
|
||||||
|
|
||||||
|
foreach ($rates as $rate) {
|
||||||
|
$name = $rate->name . ' ' . ($rate->rate + 0) . '%';
|
||||||
|
if ($rate->is_inclusive) {
|
||||||
|
$name .= ' - ' . trans('texts.inclusive');
|
||||||
|
}
|
||||||
|
$options[($rate->is_inclusive ? '1 ' : '0 ') . $rate->rate . ' ' . $rate->name] = $name;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $options;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user