Use paid attribute of model
This commit is contained in:
@ -78,8 +78,6 @@ class Invoices extends Controller
|
||||
|
||||
$date_format = $this->getCompanyDateFormat();
|
||||
|
||||
$paid = $this->getPaidAmount($invoice);
|
||||
|
||||
// Get Invoice Totals
|
||||
foreach ($invoice->totals as $invoice_total) {
|
||||
$invoice->{$invoice_total->code} = $invoice_total->amount;
|
||||
@ -89,8 +87,8 @@ class Invoices extends Controller
|
||||
|
||||
$invoice->grand_total = money($total, $currency->code)->getAmount();
|
||||
|
||||
if (!empty($paid)) {
|
||||
$invoice->grand_total = round($invoice->total - $paid, $currency->precision);
|
||||
if (!empty($invoice->paid)) {
|
||||
$invoice->grand_total = round($invoice->total - $invoice->paid, $currency->precision);
|
||||
}
|
||||
|
||||
return view('sales.invoices.show', compact('invoice', 'accounts', 'currencies', 'currency', 'account_currency_code', 'customers', 'categories', 'payment_methods', 'signed_url', 'date_format'));
|
||||
@ -464,44 +462,4 @@ class Invoices extends Controller
|
||||
|
||||
return $invoice;
|
||||
}
|
||||
|
||||
protected function getPaidAmount($invoice)
|
||||
{
|
||||
$paid = 0;
|
||||
|
||||
// Get invoice transactions
|
||||
if (!$invoice->transactions->count()) {
|
||||
return $paid;
|
||||
}
|
||||
|
||||
$currencies = Currency::enabled()->pluck('rate', 'code')->toArray();
|
||||
|
||||
foreach ($invoice->transactions as $item) {
|
||||
$default_amount = $item->amount;
|
||||
|
||||
if ($invoice->currency_code == $item->currency_code) {
|
||||
$amount = (double) $default_amount;
|
||||
} else {
|
||||
$default_amount_model = new Transaction();
|
||||
$default_amount_model->default_currency_code = $invoice->currency_code;
|
||||
$default_amount_model->amount = $default_amount;
|
||||
$default_amount_model->currency_code = $item->currency_code;
|
||||
$default_amount_model->currency_rate = $currencies[$item->currency_code];
|
||||
|
||||
$default_amount = (double) $default_amount_model->getDivideConvertedAmount();
|
||||
|
||||
$convert_amount_model = new Transaction();
|
||||
$convert_amount_model->default_currency_code = $item->currency_code;
|
||||
$convert_amount_model->amount = $default_amount;
|
||||
$convert_amount_model->currency_code = $invoice->currency_code;
|
||||
$convert_amount_model->currency_rate = $currencies[$invoice->currency_code];
|
||||
|
||||
$amount = (double) $convert_amount_model->getAmountConvertedFromCustomDefault();
|
||||
}
|
||||
|
||||
$paid += $amount;
|
||||
}
|
||||
|
||||
return $paid;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user