forked from cedrickjames/helpdesk-production
-
Notifications
You must be signed in to change notification settings - Fork 1
/
PDF Summary Report.php
384 lines (291 loc) · 12.9 KB
/
PDF Summary Report.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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
<?php
include("includes/connect.php");
require 'dompdf/vendor/autoload.php';
use Dompdf\Dompdf;
session_start();
$month = $_SESSION['month'];
$year = $_SESSION['year'];
$wholename = $_SESSION['name'];
$section = $_SESSION['level'];
$request_type = $_SESSION['request_type'];
$monthNumber1 = date('m', strtotime($month));
// Create DateTime object
$currentDate = DateTime::createFromFormat('m-d-Y', $monthNumber1 . '-01-' . $year);
$lastMonth = $currentDate->modify('-1 month');
// Get the year and month of the last month
$lastMonthYear = $lastMonth->format('Y');
$lastMonthMonth = $lastMonth->format('m');
$currentDate = $currentDate->format('m-d-y');
$monthNumber = date('m', strtotime($month));
// Calculate the previous month
if ($monthNumber == 1) {
// If the current month is January (1), set the previous month to December (12) of the previous year
$previousMonthNumber = 12;
$previousYear = date('Y') - 1;
} else {
// For all other months, subtract 1 from the current month to get the previous month
$previousMonthNumber = $monthNumber - 1;
$previousYear = date('Y');
}
$previousMonthName = date('F', mktime(0, 0, 0, $previousMonthNumber, 1));
$previousMonthNumber = str_pad($previousMonthNumber, 2, '0', STR_PAD_LEFT);
if ($section == "admin") {
$section = $_SESSION['adminsection'];
}
$firstdate = date('d', strtotime("first day of $year-$month"));
$lastDateOfMonth = date('d', strtotime("last day of $year-$month"));
$monthNumber = date('m', strtotime("$month"));
$sql = "SELECT ROUND (((SELECT COUNT('id') FROM request WHERE request_to = '$section' AND (status2 = 'Done' OR status2 = 'rated' )AND late != true AND admin_approved_date BETWEEN '$lastMonthYear-$previousMonthNumber-28' AND '$year-$monthNumber-$lastDateOfMonth')) / ((SELECT ((SELECT COUNT('id') FROM request WHERE request_to = '$section' AND (status2 = 'Done' OR status2 = 'rated') AND admin_approved_date BETWEEN '$lastMonthYear-$previousMonthNumber-28' AND '$year-$monthNumber-$lastDateOfMonth')) + (SELECT COUNT('id') FROM request WHERE request_to = '$section' AND status2 = 'inprogress' AND admin_approved_date BETWEEN '$lastMonthYear-$previousMonthNumber-28' AND '$year-$monthNumber-$lastDateOfMonth' ))) * 100, 2) AS percentage;";
// $sql="SELECT ROUND (((SELECT COUNT('id') FROM request WHERE request_to = '$section' AND (status2 = 'Done' OR status2 = 'rated') AND admin_approved_date BETWEEN '$year-$monthNumber-$firstdate' AND '$year-$monthNumber-$lastDateOfMonth')) / ((SELECT ((SELECT COUNT('id') FROM request WHERE request_to = '$section' AND (status2 = 'Done' OR status2 = 'rated') AND admin_approved_date BETWEEN '$year-$monthNumber-$firstdate' AND '$year-$monthNumber-$lastDateOfMonth')) + (SELECT COUNT('id') FROM request WHERE request_to = '$section' AND status2 = 'inprogress' AND admin_approved_date BETWEEN '$year-$monthNumber-$firstdate' AND '$year-$monthNumber-$lastDateOfMonth' AND reqfinish_date BETWEEN '$year-$monthNumber-$firstdate' AND '$year-$monthNumber-$lastDateOfMonth'))) * 100, 2) AS percentage;";
$result = mysqli_query($con, $sql);
// $sql = "SELECT ROUND (((SELECT COUNT('id') FROM request WHERE request_to = '$section' AND (status2 = 'Done' OR status2 = 'rated') AND admin_approved_date BETWEEN '$year-$monthNumber-$firstdate' AND '$year-$monthNumber-$lastDateOfMonth')) / ((SELECT ((SELECT COUNT('id') FROM request WHERE request_to = '$section' AND (status2 = 'Done' OR status2 = 'rated') AND admin_approved_date BETWEEN '$year-$monthNumber-$firstdate' AND '$year-$monthNumber-$lastDateOfMonth')) + (SELECT COUNT('id') FROM request WHERE request_to = '$section' AND status2 = 'inprogress' AND admin_approved_date BETWEEN '$year-$monthNumber-$firstdate' AND '$year-$monthNumber-$lastDateOfMonth' AND reqfinish_date BETWEEN '$year-$monthNumber-$firstdate' AND '$year-$monthNumber-$lastDateOfMonth'))) * 100, 2) AS percentage;";
$resultPercentage = "";
while ($row = mysqli_fetch_assoc($result)) {
$resultPercentage = $row['percentage'];
}
$dateNow = new DateTime();
$dateNow = $dateNow->format('F d, Y');
$html = '<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Monthly Report</title>
<style>
@page { margin: 15px; }
body{
font-family: "Calibri", sans-serif;
}
.header{
display: flex;
justify-content: center;
}
.logo{
height: 100px; width: 100px; background-color: blue
}
.label{
font-weight: bold;
font-size:11px;
}
.child{
font-size:11px;
}
p{
margin: 5px
}
.category{
font-weight: bold;
text-decoration: underline;
font-size:11px;
}
table {
border-collapse: collapse;
border-color: inherit;
text-indent: 0;
margin-top: 10px;
border: 2px;
font-size: 9px;
width: 100%;
}
#finishedTable td {
border-width: .5px; border-style: solid;
padding-left: 5px; border-color: gray
}
#latefinishedTable td {
border-width: .5px; border-style: solid;
padding-left: 5px; border-color: gray
}
#pendingTable td {
border-width: .5px; border-style: solid;
padding-left: 5px; border-color: gray
}
.first{
width: 25%;
}
.second{
width: 40%;
}
.third{
width: 15%;
}
.fourth{
width: 25%;
}
</style>
<script src="../cdn_tailwindcss.js"></script>
</head>
<body style="margin: 0px; padding: 0px; ">
<div style="text-align: center">
<p style="font-size: 11px; margin: 0; font-weight: bold">Helpdesk Monthly Report</p>
</div>
<table>
<tr>
<td class="first"><span class="label">Date</span><span style="align-text: right">:</span></td>
<td class="second"> <span class="child">' . $dateNow . '</span></td>
</tr>
<tr>
<td class="first"><span class="label">Section</span><span style="align-text: right">:</span></td>
<td class="second"> <span style="text-transform: uppercase;" class="child">' . $section . '</span></td>
<td><span class="label">Month of: </span></td>
<td class="fourth"><span class="child">' . $month . ' ' . $year . ' </span></td>
</tr>
</tr>';
if ($section == "fem") {
$html .= '<tr>
<td class="first"><span class="label">Target: </span></td>
<td class="second"> <span class="child">97% Completion of Job Orders from Approved Schedule</span></td>
<td><span class="label">Result: </span></td>
<td class="fourth"><span class="child">' . $resultPercentage . '%</span></td>
</tr>';
} else {
$html .= '<tr> </tr>';
}
$html .= '<tr>
</tr>
</table>
<h5 style="margin-bottom: 0">Finished Job Order</h5>
<table id="finishedTable" >
<tr>
<td>No.</td>
<td>Request Number</td>
<td>Requestor</td>
<td>Details</td>
<td>Personnel</td>
<td>Approved Date</td>
<td>Due Date</td>
<td>Date Finish</td>
</tr>
';
$a = 1;
$sql = "select * from `request` WHERE `request_to` = '$section' and (`status2` = 'Done' or `status2` = 'rated') AND late != true AND `admin_approved_date` BETWEEN '$lastMonthYear-$previousMonthNumber-28' AND '$year-$monthNumber-$lastDateOfMonth' order by assignedPersonnelName asc ";
$result = mysqli_query($con, $sql);
while ($row = mysqli_fetch_assoc($result)) {
$date = new DateTime($row['date_filled']);
$date = $date->format('ym');
$dateApproved = new DateTime($row['admin_approved_date']);
$dateApproved = $dateApproved->format('F d, Y');
$dateFinished = new DateTime($row['actual_finish_date']);
$dateFinished = $dateFinished->format('F d, Y');
$expected = new DateTime($row['expectedFinishDate']);
$expected = $expected->format('F d, Y');
$html .= ' <tr>
<td>' . $a . '</td>
<td>' . $date . '-' . $row['id'] . '</td>
<td>' . $row['requestor'] . '</td>
<td>' . $row['request_details'] . '</td>
<td>' . $row['assignedPersonnelName'] . '</td>
<td>' . $dateApproved . '</td>
<td>' . $expected . '</td>
<td>' . $dateFinished . '</td>
</tr>';
$a++;
}
$html .= ' </table>
<br>
<br>
<br>
<br>
<br>
<h5 style="margin-bottom: 0">Late Finished Job Order</h5>
<table id="latefinishedTable" >
<tr>
<td>No.</td>
<td>Request Number</td>
<td>Requestor</td>
<td>Details</td>
<td>Personnel</td>
<td>Date Started</td>
<td>Expected Finished Date </td>
<td>Date Finished</td>
</tr>
';
$a = 1;
$sql = "select * from `request` WHERE `request_to` = '$section' and (`status2` = 'Done' or `status2` = 'rated') AND late != false AND `admin_approved_date` BETWEEN '$lastMonthYear-$previousMonthNumber-28' AND '$year-$monthNumber-$lastDateOfMonth' order by id asc ";
$result = mysqli_query($con, $sql);
while ($row = mysqli_fetch_assoc($result)) {
$date = new DateTime($row['date_filled']);
$date = $date->format('ym');
$dateApproved = new DateTime($row['admin_approved_date']);
$dateApproved = $dateApproved->format('F d, Y');
$dateFinished = new DateTime($row['actual_finish_date']);
$dateFinished = $dateFinished->format('F d, Y');
$expected = new DateTime($row['expectedFinishDate']);
$expected = $expected->format('F d, Y');
$html .= ' <tr>
<td>' . $a . '</td>
<td>' . $date . '-' . $row['id'] . '</td>
<td>' . $row['requestor'] . '</td>
<td>' . $row['request_details'] . '</td>
<td>' . $row['assignedPersonnelName'] . '</td>
<td>' . $dateApproved . '</td>
<td>' . $expected . '</td>
<td>' . $dateFinished . '</td>
</tr>';
$a++;
}
$html .= ' </table>
<h5 style="margin-bottom: 0">Pending Job Order</h5>
<table id="pendingTable" >
<tr>
<td>No.</td>
<td>Request Number</td>
<td>Requestor</td>
<td>Details</td>
<td>Personnel</td>
<td>Date Started</td>
<td>Expected Finished Date</td>
</tr>
';
$a = 1;
$sql = "select * from `request` WHERE `request_to` = '$section' and `status2` = 'inprogress'AND admin_approved_date BETWEEN '$lastMonthYear-$previousMonthNumber-28' AND '$year-$monthNumber-$lastDateOfMonth' order by id asc ";
$result = mysqli_query($con, $sql);
while ($row = mysqli_fetch_assoc($result)) {
$date = new DateTime($row['date_filled']);
$date = $date->format('ym');
$dateApproved = new DateTime($row['admin_approved_date']);
$dateApproved = $dateApproved->format('F d, Y');
$expectedDate = new DateTime($row['expectedFinishDate']);
$expectedDate = $expectedDate->format('F d, Y');
$html .= ' <tr>
<td>' . $a . '</td>
<td>' . $date . '-' . $row['id'] . '</td>
<td>' . $row['requestor'] . '</td>
<td>' . $row['request_details'] . '</td>
<td>' . $row['assignedPersonnelName'] . '</td>
<td>' . $dateApproved . '</td>
<td>' . $expectedDate . '</td>
</tr>';
$a++;
}
$html .= ' </table>';
$html .= '
<table style="bottom: 75px; position: absolute;">
<tr>
<td class="first" style="text-align: center"><span class="label">Prepared by: </span></td>
<td class="second"> <span class="child"></span></td>
<td class="third" style="text-align: center"><span class="label">Checked by: </span></td>
</tr>
<tr style="margin-bottom: 50px">
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<br>
<br>
<tr>
<td class="first" style="text-align: center"><span class="label">' . $_SESSION['name'] . '</span></td>
<td class="second"> <span class="child"></span></td>
<td class="third" style="text-align: center"><span class="label">Jonathan Nemedez</span></td>
</tr>
</table>
</body>
</html>';
$dompdf = new Dompdf();
$dompdf->loadHtml($html);
$dompdf->setPaper('A4', 'portrait');
$dompdf->render();
$dompdf->stream('Monthly Report.pdf', ['Attachment' => 0]);