Bug fixes

This commit is contained in:
Hillel Coren 2014-06-01 16:35:19 +03:00
parent c9b7f79d7c
commit 3688669963
9 changed files with 63 additions and 53 deletions

View File

@ -86,7 +86,7 @@ class AccountController extends \BaseController {
'account' => Account::with('users')->findOrFail(Auth::user()->account_id),
'countries' => Country::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(),
'sizes' => Size::remember(DEFAULT_QUERY_CACHE)->orderBy('id')->get(),
'industries' => Industry::remember(DEFAULT_QUERY_CACHE)->orderBy('id')->get(),
'industries' => Industry::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(),
'timezones' => Timezone::remember(DEFAULT_QUERY_CACHE)->orderBy('location')->get(),
'dateFormats' => DateFormat::remember(DEFAULT_QUERY_CACHE)->get(),
'datetimeFormats' => DatetimeFormat::remember(DEFAULT_QUERY_CACHE)->get(),

View File

@ -154,7 +154,7 @@ class ClientController extends \BaseController {
return [
'sizes' => Size::remember(DEFAULT_QUERY_CACHE)->orderBy('id')->get(),
'paymentTerms' => PaymentTerm::remember(DEFAULT_QUERY_CACHE)->orderBy('num_days')->get(['name', 'num_days']),
'industries' => Industry::remember(DEFAULT_QUERY_CACHE)->orderBy('id')->get(),
'industries' => Industry::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(),
'currencies' => Currency::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(),
'countries' => Country::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(),
'customLabel1' => Auth::user()->account->custom_client_label1,

View File

@ -241,7 +241,7 @@ class InvoiceController extends \BaseController {
'currencies' => Currency::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(),
'sizes' => Size::remember(DEFAULT_QUERY_CACHE)->orderBy('id')->get(),
'paymentTerms' => PaymentTerm::remember(DEFAULT_QUERY_CACHE)->orderBy('num_days')->get(['name', 'num_days']),
'industries' => Industry::remember(DEFAULT_QUERY_CACHE)->orderBy('id')->get(),
'industries' => Industry::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(),
'invoiceDesigns' => InvoiceDesign::remember(DEFAULT_QUERY_CACHE)->orderBy('id')->get(),
'invoiceLabels' => Auth::user()->account->getInvoiceLabels(),
'frequencies' => array(

View File

@ -94,7 +94,7 @@ class QuoteController extends \BaseController {
'currencies' => Currency::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(),
'sizes' => Size::remember(DEFAULT_QUERY_CACHE)->orderBy('id')->get(),
'paymentTerms' => PaymentTerm::remember(DEFAULT_QUERY_CACHE)->orderBy('num_days')->get(['name', 'num_days']),
'industries' => Industry::remember(DEFAULT_QUERY_CACHE)->orderBy('id')->get(),
'industries' => Industry::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(),
'invoiceDesigns' => InvoiceDesign::remember(DEFAULT_QUERY_CACHE)->orderBy('id')->get(),
'invoiceLabels' => Auth::user()->account->getInvoiceLabels()
];

View File

@ -105,6 +105,7 @@ class ConstantsSeeder extends Seeder
Industry::create(array('name' => 'Transportation'));
Industry::create(array('name' => 'Travel & Luxury'));
Industry::create(array('name' => 'Other'));
Industry::create(array('name' => 'Photography'));
Size::create(array('name' => '1 - 3'));
Size::create(array('name' => '4 - 10'));
@ -119,6 +120,7 @@ class ConstantsSeeder extends Seeder
PaymentTerm::create(array('num_days' => 15, 'name' => 'Net 15'));
PaymentTerm::create(array('num_days' => 30, 'name' => 'Net 30'));
PaymentTerm::create(array('num_days' => 60, 'name' => 'Net 60'));
PaymentTerm::create(array('num_days' => 90, 'name' => 'Net 90'));
Currency::create(array('name' => 'US Dollar', 'code' => 'USD', 'symbol' => '$', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'));
Currency::create(array('name' => 'Pound Sterling', 'code' => 'GBP', 'symbol' => '£', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'));

View File

@ -251,7 +251,8 @@ class InvoiceRepository
}
$lineTotal = $invoiceItemCost * $invoiceItemQty;
$total += $lineTotal + ($lineTotal * $invoiceItemTaxRate / 100);
$total += round($lineTotal + ($lineTotal * $invoiceItemTaxRate / 100), 2);
}
if ($invoice->discount > 0)
@ -260,6 +261,7 @@ class InvoiceRepository
}
$total += $total * $invoice->tax_rate / 100;
$total = round($total, 2);
if ($publicId)
{

View File

@ -1095,7 +1095,7 @@
var total = 0;
for(var p=0; p < self.invoice_items().length; ++p) {
var item = self.invoice_items()[p];
total += item.totals.rawTotal();
total += item.totals.rawTotal();
}
return total;
});
@ -1106,7 +1106,7 @@
});
this.totals.rawDiscounted = ko.computed(function() {
return self.totals.rawSubtotal() * (self.discount()/100);
return roundToTwo(self.totals.rawSubtotal() * (self.discount()/100));
});
this.totals.discounted = ko.computed(function() {
@ -1118,12 +1118,12 @@
var discount = parseFloat(self.discount());
if (discount > 0) {
total = total * ((100 - discount)/100);
total = roundToTwo(total * ((100 - discount)/100));
}
var taxRate = parseFloat(self.tax_rate());
if (taxRate > 0) {
var tax = total * (taxRate/100);
var tax = roundToTwo(total * (taxRate/100));
return formatMoney(tax, self.client().currency_id());
} else {
return formatMoney(0);
@ -1140,29 +1140,29 @@
});
this.totals.total = ko.computed(function() {
var total = accounting.toFixed(self.totals.rawSubtotal(),2);
var total = accounting.toFixed(self.totals.rawSubtotal(),2);
var discount = parseFloat(self.discount());
if (discount > 0) {
total = total * ((100 - discount)/100);
}
var discount = parseFloat(self.discount());
if (discount > 0) {
total = roundToTwo(total * ((100 - discount)/100));
}
var taxRate = parseFloat(self.tax_rate());
if (taxRate > 0) {
total = NINJA.parseFloat(total) + (total * (taxRate/100));
}
total = NINJA.parseFloat(total) + roundToTwo((total * (taxRate/100)));
}
var paid = self.totals.rawPaidToDate();
if (paid > 0) {
total -= paid;
}
var paid = self.totals.rawPaidToDate();
if (paid > 0) {
total -= paid;
}
return total != 0 ? formatMoney(total, self.client().currency_id()) : '';
});
return total != 0 ? formatMoney(total, self.client().currency_id()) : '';
});
self.onDragged = function(item) {
refreshPDF();
}
self.onDragged = function(item) {
refreshPDF();
}
}
function ClientModel(data) {
@ -1392,12 +1392,12 @@
var cost = NINJA.parseFloat(self.cost());
var qty = NINJA.parseFloat(self.qty());
var taxRate = NINJA.parseFloat(self.tax_rate());
var value = cost * qty;
if (taxRate > 0) {
value += value * (taxRate/100);
}
return value ? value : '';
});
var value = cost * qty;
if (taxRate > 0) {
value += value * (taxRate/100);
}
return value ? roundToTwo(value) : '';
});
this.totals.total = ko.computed(function() {
var total = self.totals.rawTotal();
@ -1406,22 +1406,22 @@
} else {
return total ? formatMoney(total, 1) : '';
}
});
});
this.hideActions = function() {
this.actionsVisible(false);
}
this.hideActions = function() {
this.actionsVisible(false);
}
this.showActions = function() {
this.actionsVisible(true);
}
this.showActions = function() {
this.actionsVisible(true);
}
this.isEmpty = function() {
return !self.product_key() && !self.notes() && !self.cost() && !self.qty();
}
this.isEmpty = function() {
return !self.product_key() && !self.notes() && !self.cost() && !self.qty();
}
this.onSelect = function(){
}
this.onSelect = function(){
}
}
function onItemChange()

View File

@ -39195,7 +39195,7 @@ function calculateAmounts(invoice) {
var lineTotal = NINJA.parseFloat(item.cost) * NINJA.parseFloat(item.qty);
if (tax) {
lineTotal += lineTotal * tax / 100;
lineTotal += roundToTwo(lineTotal * tax / 100);
}
if (lineTotal) {
total += lineTotal;
@ -39210,7 +39210,7 @@ function calculateAmounts(invoice) {
if (invoice.discount > 0) {
var discount = total * (invoice.discount/100);
var discount = roundToTwo(total * (invoice.discount/100));
total -= discount;
}
@ -39219,14 +39219,14 @@ function calculateAmounts(invoice) {
tax = parseFloat(invoice.tax.rate);
} else if (invoice.tax_rate && parseFloat(invoice.tax_rate)) {
tax = parseFloat(invoice.tax_rate);
}
}
if (tax) {
var tax = total * (tax/100);
var tax = roundToTwo(total * (tax/100));
total = parseFloat(total) + parseFloat(tax);
}
invoice.balance_amount = accounting.toFixed(total,2) - (accounting.toFixed(invoice.amount,2) - accounting.toFixed(invoice.balance,2));
invoice.balance_amount = roundToTwo(total) - roundToTwo(invoice.amount) - roundToTwo(invoice.balance);
invoice.tax_amount = tax;
invoice.discount_amount = discount;
invoice.has_taxes = hasTaxes;
@ -39463,3 +39463,6 @@ function toggleDatePicker(field) {
$('#'+field).datepicker('show');
}
function roundToTwo(num) {
return +(Math.round(num + "e+2") + "e-2");
}

View File

@ -1479,7 +1479,7 @@ function calculateAmounts(invoice) {
var lineTotal = NINJA.parseFloat(item.cost) * NINJA.parseFloat(item.qty);
if (tax) {
lineTotal += lineTotal * tax / 100;
lineTotal += roundToTwo(lineTotal * tax / 100);
}
if (lineTotal) {
total += lineTotal;
@ -1494,7 +1494,7 @@ function calculateAmounts(invoice) {
if (invoice.discount > 0) {
var discount = total * (invoice.discount/100);
var discount = roundToTwo(total * (invoice.discount/100));
total -= discount;
}
@ -1503,14 +1503,14 @@ function calculateAmounts(invoice) {
tax = parseFloat(invoice.tax.rate);
} else if (invoice.tax_rate && parseFloat(invoice.tax_rate)) {
tax = parseFloat(invoice.tax_rate);
}
}
if (tax) {
var tax = total * (tax/100);
var tax = roundToTwo(total * (tax/100));
total = parseFloat(total) + parseFloat(tax);
}
invoice.balance_amount = accounting.toFixed(total,2) - (accounting.toFixed(invoice.amount,2) - accounting.toFixed(invoice.balance,2));
invoice.balance_amount = roundToTwo(total) - roundToTwo(invoice.amount) - roundToTwo(invoice.balance);
invoice.tax_amount = tax;
invoice.discount_amount = discount;
invoice.has_taxes = hasTaxes;
@ -1747,3 +1747,6 @@ function toggleDatePicker(field) {
$('#'+field).datepicker('show');
}
function roundToTwo(num) {
return +(Math.round(num + "e+2") + "e-2");
}