-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchangeover_pdf.php
212 lines (156 loc) · 6.79 KB
/
changeover_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
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<?php
require_once('vendor/autoload.php');
use TCPDF;
include 'db.php';
$db = get_db_connection();
ob_end_clean();
// Fetch all trucks
$trucks = $db->query('SELECT * FROM trucks')->fetchAll(PDO::FETCH_ASSOC);
// Check if a truck has been selected
$selected_truck_id = isset($_GET['truck_id']) ? $_GET['truck_id'] : null;
if ($selected_truck_id) {
// Fetch lockers for the selected truck
$query = $db->prepare('SELECT * FROM lockers WHERE truck_id = :truck_id');
$query->execute(['truck_id' => $selected_truck_id]);
$lockers = $query->fetchAll(PDO::FETCH_ASSOC);
$selected_locker_id = isset($_GET['locker_id']) ? $_GET['locker_id'] : null;
}
// Set document information
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, 'A4', true, 'UTF-8', false);
$pdf->setPrintHeader(false);
//$pdf->SetMargins(7.375, 26, 7.375);
$pdf->SetAutoPageBreak(TRUE, 26);
// Set header and footer fonts
//$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
//$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
// Set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
// Set margins
$pdf->SetMargins(5,5,5,true);
//$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
//$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
// Set auto page breaks
$pdf->SetAutoPageBreak(TRUE, 5);
// Set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
// Add a page
$pdf->AddPage();
// Set font
$pdf->SetFont('helvetica', '', 12);
// Fetch and display data
$html = '';
if ($selected_truck_id) {
$html .= '<table style="width: 100%;">';
$html .= ' <TR>';
$html .= ' <TD style="width: 25%;" >';
$html .= ' <h1>Truck Change Over</h1>';
$html .= ' Date:________________';
$html .= ' </TD>';
$html .= ' <TD style="width: 5%;" ></TD>';
$html .= ' <TD style="width: 70%;border=1;" >';
$html .= ' <h2>Notes:</h2>';
$html .= ' <p>1. Officer keys.</p>';
$html .= ' <p>2. Station Remotes - keys.</p>';
$html .= ' </TD>';
$html .= ' </TR>';
$html .= '</table>';
$truck_id = $selected_truck_id;
$query = $db->prepare("
SELECT
t.name AS truck_name,
l.name AS locker_name,
i.name AS item_name
FROM
trucks t
JOIN
lockers l ON t.id = l.truck_id
JOIN
items i ON l.id = i.locker_id
WHERE
t.id = :truck_id
ORDER BY
l.name, i.name
");
$query->execute(['truck_id' => $truck_id]);
$results = $query->fetchAll(PDO::FETCH_ASSOC);
$locker_count = 1;
$cellbgcolour = "#f0f0f0";
$locker_total = 0;
$prev_locker = "";
$rowcount = 1;
$pagecount =1;
$html .= '<table border="1" cellpadding="5" cellspacing="0" style="width: 100%;">';
$html .= "<tbody>";
foreach ($results as $row) {
if ($prev_locker != $row['locker_name']) {
$locker_total++;
if ($locker_count == 2 && $locker_total > 1) {
$html .= '<td style="background-color: ' . $cellbgcolour . '"' . "></td>";
$html .= '<td style="background-color: ' . $cellbgcolour . '"' . "></td>";
$html .= '<td style="background-color: ' . $cellbgcolour . '"' . "></td>";
$html .= "</tr>";
$locker_count = 1;
}
$rowcount++;
// chuck in a couple of blank rows
if ($rowcount > 30) {
$html .= '<tr><td style="background-color: ' . $cellbgcolour . '"' . "></td>";
$html .= '<td style="background-color: ' . $cellbgcolour . '"' . "></td>";
$html .= '<td style="background-color: ' . $cellbgcolour . '"' . "></td>";
$html .= '<td style="background-color: ' . $cellbgcolour . '"' . "></td>";
$html .= '<td style="background-color: ' . $cellbgcolour . '"' . "></td>";
$html .= '<td style="background-color: ' . $cellbgcolour . '"' . "></td></tr>";
$rowcount = 1;
}
$html .= '<tr style="background-color: #A9A9A9">' ;
$html .= '<td style="width:30%">';
$html .= htmlspecialchars($row['locker_name']);
$html .= "</td>";
$html .= '<td style="width:10%">';
$html .= "Relief</td>";
$html .= '<td style="width:10%">';
$html .= htmlspecialchars($row['truck_name']) ;
$html .= '</td><td style="width:30%">';
$html .= htmlspecialchars($row['locker_name']);
$html .= "</td>";
$html .= '<td style="width:10%">';
$html .= "Relief</td>";
$html .= '<td style="width:10%">';
$html .= htmlspecialchars($row['truck_name']) ;
$html .= '</td></tr>';
if ($locker_total % 2 == 0) {
$cellbgcolour = "#ffffff";
} else {
$cellbgcolour = "#f0f0f0";
}
}
if ($locker_count == 1) {
$html .= '<tr>';
$rowcount++;
}
$html .= '<td style="background-color: ' . $cellbgcolour . '">' . htmlspecialchars($row['item_name']) . "</td>";
$html .= '<td style="text-align: center; background-color: ' . $cellbgcolour . '"' . "> </td>";
$html .= '<td style="text-align: center; background-color: ' . $cellbgcolour . '"' . "> </td>";
if ($locker_count == 2) {
$html .= "</tr>";
$locker_count = 0;
}
$prev_locker = $row['locker_name'];
$locker_count++;
}
if ($locker_count == 2 && $locker_total > 1) {
$html .= '<td style="background-color: ' . $cellbgcolour . '"' . "></td>";
$html .= '<td style="background-color: ' . $cellbgcolour . '"' . "></td>";
$html .= '<td style="background-color: ' . $cellbgcolour . '"' . "></td>";
$html .= "</tr>";
$locker_count = 1;
}
$html .= "</tbody></table>";
} else {
$html .= '<p>Please select a truck to view its lockers and items.</p>';
}
// Output the HTML content
$pdf->writeHTML($html, true, false, false, false, '');
// Close and output PDF document
$pdf->Output('truck_changeover.pdf', 'I');
?>