diff --git a/app/Http/Controllers/InvoiceController.php b/app/Http/Controllers/InvoiceController.php index 5a14ea6244..260aaef3ba 100644 --- a/app/Http/Controllers/InvoiceController.php +++ b/app/Http/Controllers/InvoiceController.php @@ -324,11 +324,17 @@ class InvoiceController extends BaseController } } + // Tax rate options + $rates = TaxRate::scope()->orderBy('name')->get(); + foreach ($rates as $rate) { + $options[$rate->rate . ' ' . $rate->name] = $rate->name . ' ' . ($rate->rate+0) . '%'; + } + return [ 'data' => Input::old('data'), 'account' => Auth::user()->account->load('country'), 'products' => Product::scope()->with('default_tax_rate')->orderBy('product_key')->get(), - 'taxRates' => TaxRate::scope()->orderBy('name')->get(), + 'taxRates' => $options, 'currencies' => Cache::get('currencies'), 'languages' => Cache::get('languages'), 'sizes' => Cache::get('sizes'), diff --git a/database/migrations/2016_03_23_215049_support_multiple_tax_rates.php b/database/migrations/2016_03_23_215049_support_multiple_tax_rates.php new file mode 100644 index 0000000000..f9b9fd2218 --- /dev/null +++ b/database/migrations/2016_03_23_215049_support_multiple_tax_rates.php @@ -0,0 +1,38 @@ +decimal('tax_rate', 13, 3)->change(); + }); + + Schema::table('invoice_items', function($table) { + $table->decimal('tax_rate', 13, 3)->change(); + }); + } + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('invoices', function($table) { + $table->decimal('tax_rate', 13, 2)->change(); + }); + + Schema::table('invoice_items', function($table) { + $table->decimal('tax_rate', 13, 2)->change(); + }); + } +} \ No newline at end of file diff --git a/database/seeds/CurrenciesSeeder.php b/database/seeds/CurrenciesSeeder.php index 9a8304b181..b3da84dad0 100644 --- a/database/seeds/CurrenciesSeeder.php +++ b/database/seeds/CurrenciesSeeder.php @@ -55,6 +55,7 @@ class CurrenciesSeeder extends Seeder ['name' => 'Saudi Riyal', 'code' => 'SAR', 'symbol' => '', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Japanese Yen', 'code' => 'JPY', 'symbol' => '¥', 'precision' => '0', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Maldivian Rufiyaa', 'code' => 'MVR', 'symbol' => '', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], + ['name' => 'Costa Rican Colón', 'code' => 'CRC', 'symbol' => '', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ]; foreach ($currencies as $currency) { diff --git a/resources/views/invoices/edit.blade.php b/resources/views/invoices/edit.blade.php index a12ab9e1f9..505f0d332d 100644 --- a/resources/views/invoices/edit.blade.php +++ b/resources/views/invoices/edit.blade.php @@ -53,7 +53,7 @@
-
+
@@ -243,9 +243,12 @@ style="text-align: right" class="form-control invoice-item" name="quantity"/> - - - + {!! Former::select('') + ->options($taxRates) + ->data_bind('value: tax') + ->raw() !!} + +
@@ -351,9 +354,12 @@ {{ trans('texts.tax') }} @endif - - - + {!! Former::select('') + ->options($taxRates) + ->data_bind('value: tax') + ->raw() !!} + + @@ -712,11 +718,6 @@ // otherwise create blank model window.model = new ViewModel(); - // load the tax rates - @foreach ($taxRates as $taxRate) - model.addTaxRate({!! $taxRate !!}); - @endforeach - var invoice = {!! $invoice !!}; ko.mapping.fromJS(invoice, model.invoice().mapping, model.invoice); model.invoice().is_recurring({{ $invoice->is_recurring ? '1' : '0' }}); @@ -736,7 +737,7 @@ model.invoice().custom_taxes2({{ $account->custom_invoice_taxes2 ? 'true' : 'false' }}); // set the default account tax rate @if ($account->invoice_taxes && $account->default_tax_rate_id) - model.invoice().tax(model.getTaxRateById({{ $account->default_tax_rate ? $account->default_tax_rate->public_id : '' }})); + //model.invoice().tax(model.getTaxRateById({{ $account->default_tax_rate ? $account->default_tax_rate->public_id : '' }})); @endif @endif @@ -776,14 +777,7 @@ @endif @endif - - model.invoice().tax(model.getTaxRate(model.invoice().tax_name(), model.invoice().tax_rate())); - for (var i=0; i 1) { - return true; - } - if (self.invoice().tax_rate() > 0) { + if (self.invoice_taxes()) { return true; } return false; @@ -81,40 +71,6 @@ function ViewModel(data) { return false; }); - self.addTaxRate = function(data) { - var itemModel = new TaxRateModel(data); - self.tax_rates.push(itemModel); - applyComboboxListeners(); - } - - self.getTaxRateById = function(id) { - for (var i=0; iinvoice_item_taxes) if (datum.default_tax_rate) { - model.tax(self.model.getTaxRateById(datum.default_tax_rate.public_id)); + //model.tax(self.model.getTaxRateById(datum.default_tax_rate.public_id)); } @endif @endif