-
Notifications
You must be signed in to change notification settings - Fork 0
/
export_returns_pdf.php
65 lines (52 loc) · 1.79 KB
/
export_returns_pdf.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
// Include FPDF library
require('fpdf/fpdf.php');
// Start a new session
require('layouts/session.php');
$user_email = $_SESSION['email']; // User's email
// Database connection
include('conn.php');
// Establish the connection to the user's database
$conn = connectMainDB();
// Create instance of FPDF class
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial', 'B', 12);
// Add a title
$pdf->Cell(0, 10, 'Sales Returns List', 0, 1, 'C');
$pdf->Ln();
// Add timestamp
$pdf->SetFont('Arial', '', 10); // Set font for timestamp
$currentTimestamp = date('Y-m-d H:i:s'); // Format: YYYY-MM-DD HH:MM:SS
$pdf->Cell(0, 10, 'Generated on: ' . $currentTimestamp, 0, 1, 'C'); // Centered timestamp
$pdf->Ln(10); // Add a line break before table headers
// Table header
$pdf->SetFont('Arial', 'B', 10);
$pdf->Cell(35, 10, 'Customer', 1);
$pdf->Cell(30, 10, 'Reference', 1);
$pdf->Cell(30, 10, 'Status', 1);
$pdf->Cell(30, 10, 'Grand Total', 1);
$pdf->Cell(30, 10, 'Amount', 1);
$pdf->Cell(30, 10, 'Date', 1);
$pdf->Ln();
// Fetch sales return data
$query = "SELECT date, customer, reference, status, grand_total_returned, amount_returned
FROM sales_return
WHERE user_email = '$user_email'";
$result = $conn->query($query);
if ($result->num_rows > 0) {
// Fetch data and add it to the PDF
while ($row = $result->fetch_assoc()) {
$pdf->Cell(35, 10, $row['customer'], 1);
$pdf->Cell(30, 10, $row['reference'], 1);
$pdf->Cell(30, 10, $row['status'], 1);
$pdf->Cell(30, 10, $row['grand_total_returned'], 1);
$pdf->Cell(30, 10, $row['amount_returned'], 1);
$pdf->Cell(30, 10, $row['date'], 1);
$pdf->Ln();
}
} else {
$pdf->Cell(0, 10, 'No records found.', 0, 1, 'C');
}
// Output the PDF
$pdf->Output('I', 'sales_returns_report.pdf');