request = $request; } public function headings(): array { return [ 'Date', 'Description', 'Incoming', 'Outgoing', 'Balance', ]; } /** * @return \Illuminate\Support\Collection|mixed */ public function query() { $company = Company::where('reference', $this->request->route('marking'))->first(); $transactions = $company->wallets()->first()->transactions()->whereIn('transactions.status', [2, 3])->orderBy('id'); // dd($transactions->get()->toArray()); return $transactions; } /** * @param Transaction $transaction * * @return array */ public function map($transaction): array { // dd($transaction); $decimals = $this->request->route('is_precise') == 'true' ? 5 : 2; $description = ''; switch ((int) $transaction->type) { case 5: $description = (float) $transaction->amount . ' Credit Top up'; break; case 9: $description = 'Credit Voucher for ' . $transaction->payment_reference; break; case 1: $booking = Transaction::where('payment_reference', $transaction->bill_no)->first()->owner; if (!$booking) { $description = 'Payment for unknown booking, please contact tech support.'; break; } $marking = $booking->marking; $description = 'Payment For booking refs' . $marking; break; case 11: $description = 'Debit Voucher for ' . $transaction->payment_reference; break; } $incoming = $outgoing = ''; if (in_array($transaction->type, [TransactionType::TOP_UP, TransactionType::CREDIT_NOTE])) { $incoming = number_format($transaction->amount, $decimals, '.', ','); $this->runningBalance += $transaction->amount; } if (in_array($transaction->type, [TransactionType::PAYMENT, TransactionType::DEBIT_NOTE])) { $outgoing = number_format($transaction->amount, $decimals, '.', ','); $this->runningBalance -= $transaction->amount; } return [ Carbon::parse($transaction->created_at)->format('d-m-Y h:i:s A'), $description, $incoming, $outgoing, number_format($this->runningBalance, $decimals, '.', ',') ]; } }