Repository navigation
Expand file tree
/
Copy pathadmin_generate_pdf.php
More file actions
129 lines (103 loc) · 3.8 KB
/
Copy pathadmin_generate_pdf.php
File metadata and controls
129 lines (103 loc) · 3.8 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php
ob_start();
include 'admin.php';
include '../api/users/fetch_all.php';
include '../api/submission/fetch_all.php';
include '../api/task/fetch_all.php';
ob_end_clean();
require('fpdf.php');
class PDF extends FPDF {
function Header() {
$this->SetFont('Arial', 'B', 20);
$this->SetTextColor(34, 139, 34);
$this->Image('./assets/logo.png', 10, 10, 30);
$this->Cell(0, 10, 'EcoQuest Sustainability Report', 0, 1, 'C');
$this->SetFont('Arial', 'I', 10);
$this->SetTextColor(100);
$this->Cell(0, 10, 'Generated on: ' . date('Y-m-d H:i'), 0, 1, 'C');
$this->Ln(5);
$this->Line(10, 30, 200, 30);
$this->Ln(10);
}
function FancyTable($header, $data) {
$this->SetFillColor(232, 232, 232);
$this->SetFont('Arial', 'B', 12);
foreach($header as $col) $this->Cell(47, 7, $col, 1, 0, 'C', true);
$this->Ln();
$this->SetFont('Arial', '', 12);
foreach($data as $row) {
foreach($row as $col) $this->Cell(47, 6, $col, 1);
$this->Ln();
}
}
}
$pdf = new PDF();
$pdf->AddPage();
$pdf->SetFont('Arial', 'B', 14);
$pdf->Cell(0, 10, 'System Overview', 0, 1);
$pdf->SetFont('Arial', '', 12);
$pdf->Cell(95, 10, "Total Users: " . $totalUser['count'], 1, 0);
$pdf->Cell(95, 10, "Submission Success Rate: " . $successRate . "%", 1, 1);
$pdf->Cell(95, 10, "Total Submissions: " . $totalSubmission['count'], 1, 0);
$pdf->Cell(95, 10, "Tasks Completed: " . $completedTask['count'], 1, 1);
$pdf->Ln(10);
$pdf->SetFont('Arial', 'B', 14);
$pdf->Cell(0, 10, 'Reward Inventory Status', 0, 1);
$header = array('Metric', 'Value');
$rewardData = [
['Total Rewards', $totalResult['count']],
['Active Rewards', $activeResult['count']],
['Low Stock (<10)', $lowStockResult['count']],
['Claimed Rate', $claimedPercentage['count'] . '%']
];
foreach($rewardData as $row) {
$pdf->SetFont('Arial', 'B', 12);
$pdf->Cell(50, 8, $row[0], 1);
$pdf->SetFont('Arial', '', 12);
$pdf->Cell(40, 8, $row[1], 1, 1);
}
$pdf->Ln(10);
$pdf->SetX(10);
$pdf->SetFont('Arial', 'B', 14);
$pdf->Cell(0, 10, 'Impact by Goal Type (Approved Tasks)', 0, 1, 'L');
$availableWidth = $pdf->GetPageWidth() - 20;
$colWidth = $availableWidth / 4;
$pdf->SetFillColor(200, 255, 200);
$pdf->SetX(10);
$pdf->Cell($colWidth, 8, 'Plastic', 1, 0, 'C', true);
$pdf->Cell($colWidth, 8, 'Trash', 1, 0, 'C', true);
$pdf->Cell($colWidth, 8, 'Electric', 1, 0, 'C', true);
$pdf->Cell($colWidth, 8, 'Carbon', 1, 1, 'C', true);
$pdf->SetX(10);
$pdf->SetFont('Arial', '', 12);
$pdf->Cell($colWidth, 8, ($goalCounts['plastic'] ?? 0), 1, 0, 'C');
$pdf->Cell($colWidth, 8, ($goalCounts['trash'] ?? 0), 1, 0, 'C');
$pdf->Cell($colWidth, 8, ($goalCounts['electric'] ?? 0), 1, 0, 'C');
$pdf->Cell($colWidth, 8, ($goalCounts['carbon'] ?? 0), 1, 1, 'C');
$pdf->Ln(10);
$pdf->SetFont('Arial', 'B', 14);
$pdf->Cell(0, 10, 'Submission Status Breakdown', 0, 1, 'L');
$w = $pdf->GetPageWidth() - 20;
$colWidth = $w / 3;
$pdf->SetFillColor(232, 232, 232);
$pdf->SetFont('Arial', 'B', 12);
$pdf->SetX(10);
$pdf->Cell($colWidth, 8, 'Status', 1, 0, 'C', true);
$pdf->Cell($colWidth, 8, 'Total Count', 1, 0, 'C', true);
$pdf->Cell($colWidth, 8, 'Percentage', 1, 1, 'C', true);
$pdf->SetFont('Arial', '', 12);
$pdf->SetX(10);
$pdf->Cell($colWidth, 8, 'Approved', 1, 0, 'C');
$pdf->Cell($colWidth, 8, $appCount, 1, 0, 'C');
$pdf->Cell($colWidth, 8, round($pApp, 1) . '%', 1, 1, 'C');
$pdf->SetX(10);
$pdf->Cell($colWidth, 8, 'Pending', 1, 0, 'C');
$pdf->Cell($colWidth, 8, $penCount, 1, 0, 'C');
$pdf->Cell($colWidth, 8, round($pPen, 1) . '%', 1, 1, 'C');
$pdf->SetX(10);
$pdf->Cell($colWidth, 8, 'Rejected', 1, 0, 'C');
$pdf->Cell($colWidth, 8, $rejCount, 1, 0, 'C');
$pdf->Cell($colWidth, 8, round($pRej, 1) . '%', 1, 1, 'C');
$pdf->Ln(10);
$pdf->Output();
?>