mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Fixes for invoice sum calculations
This commit is contained in:
parent
d7c7289ca9
commit
25b48994d6
@ -52,10 +52,10 @@ class InvoiceItemSum
|
||||
|
||||
$this->invoice = $invoice;
|
||||
|
||||
if($this->invoice->vendor)
|
||||
$this->currency = $this->invoice->vendor->currency();
|
||||
else
|
||||
if($this->invoice->client)
|
||||
$this->currency = $this->invoice->client->currency();
|
||||
else
|
||||
$this->currency = $this->invoice->vendor->currency();
|
||||
|
||||
$this->line_items = [];
|
||||
}
|
||||
|
@ -46,7 +46,10 @@ class InvoiceItemSumInclusive
|
||||
|
||||
$this->invoice = $invoice;
|
||||
|
||||
if($this->invoice->client)
|
||||
$this->currency = $this->invoice->client->currency();
|
||||
else
|
||||
$this->currency = $this->invoice->vendor->currency();
|
||||
|
||||
$this->line_items = [];
|
||||
}
|
||||
|
@ -55,10 +55,10 @@ class InvoiceSum
|
||||
{
|
||||
$this->invoice = $invoice;
|
||||
|
||||
if($this->invoice->vendor)
|
||||
$this->precision = $this->invoice->vendor->currency()->precision;
|
||||
else
|
||||
if($this->invoice->client)
|
||||
$this->precision = $this->invoice->client->currency()->precision;
|
||||
else
|
||||
$this->precision = $this->invoice->vendor->currency()->precision;
|
||||
|
||||
$this->tax_map = new Collection;
|
||||
}
|
||||
|
@ -41,6 +41,7 @@ class InvoiceSumInclusive
|
||||
|
||||
private $sub_total;
|
||||
|
||||
private $precision;
|
||||
/**
|
||||
* Constructs the object with Invoice and Settings object.
|
||||
*
|
||||
@ -50,6 +51,11 @@ class InvoiceSumInclusive
|
||||
{
|
||||
$this->invoice = $invoice;
|
||||
|
||||
if($this->invoice->client)
|
||||
$this->precision = $this->invoice->client->currency()->precision;
|
||||
else
|
||||
$this->precision = $this->invoice->vendor->currency()->precision;
|
||||
|
||||
$this->tax_map = new Collection;
|
||||
}
|
||||
|
||||
@ -164,32 +170,15 @@ class InvoiceSumInclusive
|
||||
|
||||
private function calculateTotals()
|
||||
{
|
||||
//$this->total += $this->total_taxes;
|
||||
|
||||
// if (is_numeric($this->invoice->custom_value1)) {
|
||||
// $this->total += $this->invoice->custom_value1;
|
||||
// }
|
||||
|
||||
// if (is_numeric($this->invoice->custom_value2)) {
|
||||
// $this->total += $this->invoice->custom_value2;
|
||||
// }
|
||||
|
||||
// if (is_numeric($this->invoice->custom_value3)) {
|
||||
// $this->total += $this->invoice->custom_value3;
|
||||
// }
|
||||
|
||||
// if (is_numeric($this->invoice->custom_value4)) {
|
||||
// $this->total += $this->invoice->custom_value4;
|
||||
// }
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getRecurringInvoice()
|
||||
{
|
||||
$this->invoice->amount = $this->formatValue($this->getTotal(), $this->invoice->client->currency()->precision);
|
||||
$this->invoice->amount = $this->formatValue($this->getTotal(), $this->precision);
|
||||
$this->invoice->total_taxes = $this->getTotalTaxes();
|
||||
$this->invoice->balance = $this->formatValue($this->getTotal(), $this->invoice->client->currency()->precision);
|
||||
$this->invoice->balance = $this->formatValue($this->getTotal(), $this->precision);
|
||||
|
||||
$this->invoice->saveQuietly();
|
||||
|
||||
@ -249,14 +238,14 @@ class InvoiceSumInclusive
|
||||
if ($this->invoice->amount != $this->invoice->balance) {
|
||||
$paid_to_date = $this->invoice->amount - $this->invoice->balance;
|
||||
|
||||
$this->invoice->balance = $this->formatValue($this->getTotal(), $this->invoice->client->currency()->precision) - $paid_to_date;
|
||||
$this->invoice->balance = $this->formatValue($this->getTotal(), $this->precision) - $paid_to_date;
|
||||
} else {
|
||||
$this->invoice->balance = $this->formatValue($this->getTotal(), $this->invoice->client->currency()->precision);
|
||||
$this->invoice->balance = $this->formatValue($this->getTotal(), $this->precision);
|
||||
}
|
||||
}
|
||||
|
||||
/* Set new calculated total */
|
||||
$this->invoice->amount = $this->formatValue($this->getTotal(), $this->invoice->client->currency()->precision);
|
||||
$this->invoice->amount = $this->formatValue($this->getTotal(), $this->precision);
|
||||
|
||||
$this->invoice->total_taxes = $this->getTotalTaxes();
|
||||
|
||||
|
@ -107,6 +107,9 @@ class Vendor extends BaseModel
|
||||
if(!$currencies)
|
||||
$this->buildCache(true);
|
||||
|
||||
if(!$this->currency_id)
|
||||
$this->currency_id = 1;
|
||||
|
||||
return $currencies->filter(function ($item) {
|
||||
return $item->id == $this->currency_id;
|
||||
})->first();
|
||||
|
Loading…
x
Reference in New Issue
Block a user