private function generatePaymentReport($startDate, $endDate, $isExport)
{
$columns = ['client', 'invoice_number', 'invoice_date', 'amount', 'payment_date', 'paid', 'method'];
$account = Auth::user()->account;
$displayData = [];
$reportTotals = [];
$payments = Payment::scope()->withArchived()->excludeFailed()->whereHas('client', function ($query) {
$query->where('is_deleted', '=', false);
})->whereHas('invoice', function ($query) {
$query->where('is_deleted', '=', false);
})->with('client.contacts', 'invoice', 'payment_type', 'account_gateway.gateway')->where('payment_date', '>=', $startDate)->where('payment_date', '<=', $endDate);
foreach ($payments->get() as $payment) {
$invoice = $payment->invoice;
$client = $payment->client;
$displayData[] = [$isExport ? $client->getDisplayName() : $client->present()->link, $isExport ? $invoice->invoice_number : $invoice->present()->link, $invoice->present()->invoice_date, $account->formatMoney($invoice->amount, $client), $payment->present()->payment_date, $account->formatMoney($payment->getCompletedAmount(), $client), $payment->present()->method];
$reportTotals = $this->addToTotals($reportTotals, $client->currency_id, 'amount', $invoice->amount);
$reportTotals = $this->addToTotals($reportTotals, $client->currency_id, 'paid', $payment->getCompletedAmount());
}
return ['columns' => $columns, 'displayData' => $displayData, 'reportTotals' => $reportTotals];
}