-
Notifications
You must be signed in to change notification settings - Fork 2
/
generate-pdf.php
110 lines (93 loc) · 2.93 KB
/
generate-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
<?php
require_once("session.php");
require_once("vendor/autoload.php" );
require_once("user_class.php");
use Dompdf\Dompdf;
$user = new User();
$dompdf = new Dompdf();
$content = '
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<style>
html {
font-family: DejaVu Sans;
text-align: center;
}
table {
border-collapse: collapse;
width: 100%;
font-size: 18px;
}
td, th {
border: 1px solid #bfbfbf;
text-align: left;
padding: 8px;
}
td:first-child {
width: 10%;
text-align: center;
}
td:last-child {
width: 20%;
}
tr:first-child th{
background-color: #333333;
color: white;
border-color: #b3b3b3;
}
tr:nth-child(even) {
background-color: #dddddd;
}
tr:last-child td {
background-color: #333333;
color: white;
border-color: #333333;
}
img {
max-width: 80px;
height: auto;
}
</style>
<h1>Kosztorys</h1>
<table>
<tr>
<th></th>
<th>Nazwa produktu</th>
<th>Cena</th>
<th>Ilość</th>
<th>Wartość</th>
</tr>';
if (isset($_SESSION['user_session'])) {
try {
$stmt = $user->runQuery("SELECT id, prod_img, prod_name, prod_price, quantity
FROM clipboard
INNER JOIN products ON clipboard.prod_id = products.prod_id
WHERE clipboard.user_id = :id");
$stmt->bindParam(":id", $_SESSION['user_session']);
$stmt->execute();
$total = 0;
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$content .=
'<tr>
<td><img src="'.$row['prod_img'].'"</td>
<td>'.$row['prod_name'].'</td>
<td>'.$row['prod_price'].' zł</td>
<td>'.$row['quantity'].'</td>
<td>'.number_format((float)$row['prod_price']*$row['quantity'], 2, '.', '').' zł</td>
</tr>';
$total += $row['prod_price']*$row['quantity'];
}
$content .= '
<tr>
<td></td><td></td><td></td><td></td>
<td>Łącznie: <strong>'.$total.' zł</strong></td>
</tr>
</table>';
} catch (PDOException $e) {
$e->getMessage();
}
}
$dompdf->loadHtml($content);
$dompdf->setPaper('A4', 'landscape');
$dompdf->render();
$dompdf->stream("1", array("Attachment"=>0));
?>