function generatePDF($accountId) { $transactions = selectTransactionsByAccountId($accountId); $userId = selectAccountById($accountId)->USER; $user = selectUser($userId); require 'FPDF/fpdf.php'; $pdf = new FPDF(); // Column headings $header = array("Sender Name", "Sender Account", "Recipient Name", "Recipient Account", "Amount", "Description", "Status", "Created On", "TAN", "Approved By", "Approved On"); // Column widths $w = array(25, 23, 25, 23, 20, 35, 15, 20, 35, 27, 20); $pdf->AddPage("L"); $pdf->SetFont('Arial', 'B', 12); $pdf->Cell(0, 10, "Transaction Summary: " . $user->FIRST_NAME . " " . $user->LAST_NAME); $pdf->Ln(); $pdf->SetFont('Arial', '', 8); for ($i = 0; $i < count($header); $i++) { $pdf->Cell($w[$i], 7, $header[$i], 1, 0, 'C'); } $pdf->Ln(); // Data foreach ($transactions as $row) { $status = "Pending"; if ($row->STATUS === "A") { $status = "Approved"; } else { if ($row->STATUS === "D") { $status = "Declined"; } } $pdf->Cell($w[0], 6, $row->SENDER_NAME, 'LR'); $pdf->Cell($w[1], 6, $row->SENDER_ACCOUNT_NUM, 'LR'); $pdf->Cell($w[2], 6, $row->RECIPIENT_NAME, 'LR'); $pdf->Cell($w[3], 6, $row->RECIPIENT_ACCOUNT_NUM, 'LR'); $pdf->Cell($w[4], 6, number_format($row->AMOUNT), 'LR', 0, 'R'); $pdf->Cell($w[5], 6, $row->DESCRIPTION, 'LR'); $pdf->Cell($w[6], 6, $status, 'LR'); $pdf->Cell($w[7], 6, $row->DATE_CREATED, 'LR'); $pdf->Cell($w[8], 6, $row->TAN_NUMBER, 'LR'); $pdf->Cell($w[9], 6, $row->APPROVED_BY_NAME, 'LR'); $pdf->Cell($w[10], 6, $row->DATE_APPROVED, 'LR'); $pdf->Ln(); } // Closing line $pdf->Cell(array_sum($w), 0, '', 'T'); $doc = $pdf->Output('transactions.pdf', 'D'); //Save the pdf file return $doc; }
function updateBalance($sender, $recipient, $amount) { $senderBalance = selectAccountById($sender)->BALANCE; $recipientBalance = selectAccountById($recipient)->BALANCE; $newSenderBalance = $senderBalance - $amount; $newRecipientbalance = $recipientBalance + $amount; $connection = openDb(); //Using prepared statements and parameterized queries: $sql = "UPDATE accounts SET BALANCE = ? WHERE ID = ?"; $stmt = $connection->stmt_init(); if (!$stmt->prepare($sql)) { return false; } $stmt->bind_param("di", $newSenderBalance, $sender); if (!executeNonQuery($stmt, $connection)) { return false; } $connection = openDb(); //Using prepared statements and parameterized queries: $sql = "UPDATE accounts SET BALANCE = ? WHERE ID = ?"; $stmt = $connection->stmt_init(); if (!$stmt->prepare($sql)) { return false; } $stmt->bind_param("ss", $newRecipientbalance, $recipient); return executeNonQuery($stmt, $connection); }