Skip to content

Commit

Permalink
fixed #695
Browse files Browse the repository at this point in the history
  • Loading branch information
denisdulici committed Dec 22, 2018
1 parent 44fe707 commit ca0b21b
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 10 deletions.
4 changes: 2 additions & 2 deletions app/Http/Controllers/Reports/ProfitLoss.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public function index()
private function setAmount(&$totals, &$compares, $items, $type, $date_field)
{
foreach ($items as $item) {
if ($item['table'] == 'bill_payments' || $item['table'] == 'invoice_payments') {
if (($item['table'] == 'bill_payments') || ($item['table'] == 'invoice_payments')) {
$type_item = $item->$type;

$item->category_id = $type_item->category_id;
Expand All @@ -170,7 +170,7 @@ private function setAmount(&$totals, &$compares, $items, $type, $date_field)
continue;
}

$amount = $item->getConvertedAmount();
$amount = $item->getConvertedAmount(false, false);

// Forecasting
if ((($type == 'invoice') || ($type == 'bill')) && ($date_field == 'due_at')) {
Expand Down
18 changes: 17 additions & 1 deletion app/Models/Expense/Bill.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Bill extends Model
*
* @var array
*/
protected $appends = ['attachment', 'discount', 'paid'];
protected $appends = ['attachment', 'amount_without_tax', 'discount', 'paid'];

protected $dates = ['deleted_at', 'billed_at', 'due_at'];

Expand Down Expand Up @@ -201,6 +201,22 @@ public function getDiscountAttribute()
return $percent;
}

/**
* Get the amount without tax.
*
* @return string
*/
public function getAmountWithoutTaxAttribute()
{
$amount = $this->amount;

$this->totals()->where('code', 'tax')->each(function ($tax) use(&$amount) {
$amount -= $tax->amount;
});

return $amount;
}

/**
* Get the paid amount.
*
Expand Down
18 changes: 17 additions & 1 deletion app/Models/Income/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Invoice extends Model
*
* @var array
*/
protected $appends = ['attachment', 'discount', 'paid'];
protected $appends = ['attachment', 'amount_without_tax', 'discount', 'paid'];

protected $dates = ['deleted_at', 'invoiced_at', 'due_at'];

Expand Down Expand Up @@ -205,6 +205,22 @@ public function getDiscountAttribute()
return $percent;
}

/**
* Get the amount without tax.
*
* @return string
*/
public function getAmountWithoutTaxAttribute()
{
$amount = $this->amount;

$this->totals()->where('code', 'tax')->each(function ($tax) use(&$amount) {
$amount -= $tax->amount;
});

return $amount;
}

/**
* Get the paid amount.
*
Expand Down
18 changes: 12 additions & 6 deletions app/Traits/Currencies.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,24 @@ public function dynamicConvert($default, $amount, $code, $rate, $format = false)
return $money;
}

public function getConvertedAmount($format = false)
public function getConvertedAmount($format = false, $with_tax = true)
{
return $this->convert($this->amount, $this->currency_code, $this->currency_rate, $format);
$amount = $with_tax ? $this->amount : isset($this->amount_without_tax) ? $this->amount_without_tax : $this->amount;

return $this->convert($amount, $this->currency_code, $this->currency_rate, $format);
}

public function getReverseConvertedAmount($format = false)
public function getReverseConvertedAmount($format = false, $with_tax = true)
{
return $this->reverseConvert($this->amount, $this->currency_code, $this->currency_rate, $format);
$amount = $with_tax ? $this->amount : isset($this->amount_without_tax) ? $this->amount_without_tax : $this->amount;

return $this->reverseConvert($amount, $this->currency_code, $this->currency_rate, $format);
}

public function getDynamicConvertedAmount($format = false)
public function getDynamicConvertedAmount($format = false, $with_tax = true)
{
return $this->dynamicConvert($this->default_currency_code, $this->amount, $this->currency_code, $this->currency_rate, $format);
$amount = $with_tax ? $this->amount : isset($this->amount_without_tax) ? $this->amount_without_tax : $this->amount;

return $this->dynamicConvert($this->default_currency_code, $amount, $this->currency_code, $this->currency_rate, $format);
}
}

0 comments on commit ca0b21b

Please sign in to comment.