diff --git a/app/Http/Controllers/ReportController.php b/app/Http/Controllers/ReportController.php index 1c4c033b9ed3..f1feb65b4bd9 100644 --- a/app/Http/Controllers/ReportController.php +++ b/app/Http/Controllers/ReportController.php @@ -354,8 +354,8 @@ class ReportController extends BaseController private function generateInvoiceReport($startDate, $endDate, $isExport) { - $columns = ['client', 'invoice_number', 'invoice_date', 'amount', 'paid', 'balance']; - + $columns = ['client', 'invoice_number', 'invoice_date', 'amount', 'payment_date', 'paid', 'method']; + $account = Auth::user()->account; $displayData = []; $reportTotals = []; @@ -379,19 +379,25 @@ class ReportController extends BaseController }]); foreach ($clients->get() as $client) { - $currencyId = $client->currency_id ?: Auth::user()->account->getCurrencyId(); + foreach ($client->invoices as $invoice) { + + $payments = count($invoice->payments) ? $invoice->payments : [false]; + foreach ($payments as $payment) { + $displayData[] = [ + $isExport ? $client->getDisplayName() : $client->present()->link, + $isExport ? $invoice->invoice_number : $invoice->present()->link, + $invoice->present()->invoice_date, + $account->formatMoney($invoice->amount, $client), + $payment ? $payment->present()->payment_date : '', + $payment ? $account->formatMoney($payment->amount, $client) : '', + $payment ? $payment->present()->method : '', + ]; + if ($payment) { + $reportTotals = $this->addToTotals($reportTotals, $client->currency_id, 'paid', $payment->amount); + } + } - foreach ($client->invoices as $invoice) { - $displayData[] = [ - $isExport ? $client->getDisplayName() : $client->present()->link, - $isExport ? $invoice->invoice_number : $invoice->present()->link, - $invoice->present()->invoice_date, - $account->formatMoney($invoice->amount, $client), - $account->formatMoney($invoice->getAmountPaid(), $client), - $account->formatMoney($invoice->balance, $client), - ]; $reportTotals = $this->addToTotals($reportTotals, $client->currency_id, 'amount', $invoice->amount); - $reportTotals = $this->addToTotals($reportTotals, $client->currency_id, 'paid', $invoice->getAmountPaid()); $reportTotals = $this->addToTotals($reportTotals, $client->currency_id, 'balance', $invoice->balance); } }