1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-21 08:51:34 +02:00

Fix for suming amounts payable

This commit is contained in:
David Bomba 2021-01-08 14:25:54 +11:00
parent bb8f628bb2
commit a5290e067e

View File

@ -88,17 +88,30 @@ class InvoiceController extends Controller
->whereClientId(auth()->user()->client->id) ->whereClientId(auth()->user()->client->id)
->get(); ->get();
$total = $invoices->sum('balance'); //filter invoices which are payable
$invoices = $invoices->filter(function ($invoice) { $invoices = $invoices->filter(function ($invoice) {
return $invoice->isPayable() && $invoice->balance > 0; return $invoice->isPayable() && $invoice->balance > 0;
}); });
//return early if no invoices.
if ($invoices->count() == 0) { if ($invoices->count() == 0) {
return back() return back()
->with('message', ctrans('texts.no_payable_invoices_selected')); ->with('message', ctrans('texts.no_payable_invoices_selected'));
} }
//iterate and sum the payable amounts either partial or balance
$total = 0;
foreach($invoices as $invoice)
{
if($invoice->partial > 0)
$total += $invoice->partial;
else
$total += $invoice->balance;
}
//format data
$invoices->map(function ($invoice) { $invoices->map(function ($invoice) {
$invoice->service()->removeUnpaidGatewayFees()->save(); $invoice->service()->removeUnpaidGatewayFees()->save();
$invoice->balance = Number::formatValue($invoice->balance, $invoice->client->currency()); $invoice->balance = Number::formatValue($invoice->balance, $invoice->client->currency());
@ -107,6 +120,7 @@ class InvoiceController extends Controller
return $invoice; return $invoice;
}); });
//format totals
$formatted_total = Number::formatMoney($total, auth()->user()->client); $formatted_total = Number::formatMoney($total, auth()->user()->client);
$payment_methods = auth()->user()->client->getPaymentMethods($total); $payment_methods = auth()->user()->client->getPaymentMethods($total);