-
Notifications
You must be signed in to change notification settings - Fork 0
/
pdf_sales_report.php
214 lines (158 loc) · 6.18 KB
/
pdf_sales_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
<?php
require('fpdf.php');
class PeoplePDF extends FPDF {
//Page header
function Header() {
$num = 0;
$fill = 0;
include('dao/connect.php');
$result = $db->query("select * from institution_details");
while ($de = $result->fetch_assoc()) {
$name = $de['institution_name'];
$name2 = $de['name_part2'];
$address = $de['box'] . " , " . $de['place'] . " Tel: " . $de['telphone'];
//$logref=$de['logref'];
$phone = $de['telphone'];
$headoffice = $de['head_office'];
$email = $de['email'];
$web = $de['website'];
}
$logo = "images/logo.png";
$date = date("Y-m-d H:i:s");
$y = date("Y");
$m = date("m");
$d = date("d");
$hr = date("H");
$min = date("i");
$sec = date("s");
$hcodes = $y . $m . $d . $hr;
$mins = $min . $sec;
$hcode = $hcodes . $mins;
$barcode = "images/barcode.PNG";
$this->SetFont('times', '', 8);
$this->Image($logo, 15, 10, 20, 20);
$this->Image($barcode, 165, 10, 0, 0);
$this->Text(175, 25, $hcode);
$this->SetFont('times', '', 8);
//$this->Image($barcode,150,10,0,0);
//$this->Text(151, 25, $hcode);
$this->SetFont('times', 'B', 28);
$this->Cell(195, 7, $name, 0, 0, "C", 0);
$this->Ln();
$this->SetFont('times', 'B', 14);
$this->Cell(195, 6, $name2, 0, 0, "C", 0);
$this->Ln();
$this->SetFont('times', '', 12);
$this->Ln();
if(isset($_GET['from'])){
//echo $mydate;
$start = date("d-m-Y",strtotime($_GET['from']));
$end = date("d-m-Y",strtotime($_GET['to']));
}else{
$start = date("d-m-Y");
$end = date("d-m-Y", strtotime("-5 days", strtotime($to)));
}
$this->SetFont('times', 'B', 11);
$this->Cell(195, 6, "SALES REPORT FOR THE PERIOD BETWEEN ".$start." AND ".$end , 0, 0, "C", 0);
$this->Line(10, 36, 200, 36);
$this->Ln();
$this->Ln(20);
}
//Page footer
function Footer() {
//Position at 1.5 cm from bottom
$this->SetY(-15);
//Arial italic 8
$this->SetFont('Arial', 'I', 9);
//Page number
$this->Cell(0, 10, 'Page ' . $this->PageNo() . '/{nb}', 0, 0, 'C');
}
}
$pdf = new FPDF();
$pdf = new PeoplePDF();
$pdf->AliasNbPages(); //for page numbers
//$pdf->open();
$pdf->addPage();
$pdf->SetAutoPageBreak(false);
$pdf->SetFillColor(0, 0, 0); //black
$pdf->SetDrawColor(0, 0, 0); //black
//table header
$pdf->SetFillColor(128, 128, 128); //gray
$pdf->setFont("times", "", "11");
$pdf->setXY(10, 40);
$pdf->Cell(10, 7, "#", 1, 0, "L", 1);
$pdf->Cell(35, 7, "Category", 1, 0, "C", 1);
$pdf->Cell(30, 7, "Product", 1, 0, "C", 1);
$pdf->Cell(20, 7, "Sale Price", 1, 0, "C", 1);
$pdf->Cell(25, 7, "Price Type", 1, 0, "C", 1);
$pdf->Cell(30, 7, "Date", 1, 0, "C", 1);
$pdf->Cell(15, 7, "Qty", 1, 0, "C", 1);
$pdf->Cell(25, 7, "Total", 1, 0, "C", 1);
$pdf->Ln();
//gegevens van database
$y = $pdf->GetY();
$x = 10;
$pdf->setXY($x, $y);
if(isset($_GET['from'])){
//echo $mydate;
$from = date("Y-m-d",strtotime($_GET['from']));
$to = date("Y-m-d",strtotime($_GET['to']));
}else{
$to = date("Y-m-d");
$from = date("Y-m-d", strtotime("-5 days", strtotime($to)));
}
$statement = "SELECT `category`,`product_value`,`price`,pricetype, SUM(`items_sold`.`qnty`) AS totalunits ,
SUM(`price` *`items_sold`.`qnty`) AS totalamount , DATE_FORMAT(`sales_date`,\"%d-%m-%Y\")
AS salesdate FROM sales
JOIN `items_sold` ON SALES.`sales_id` = items_sold.`sale_id`
JOIN `products` ON `items_sold`.`product_id` = `products`.`product_id`
JOIN `product_category` ON `products`.`product_category` = `product_category`.`category_id`
WHERE sales_date >= '$from' AND sales_date <= '$to'
GROUP BY category, product_value, pricetype, statuss,sales_date
ORDER BY `sales_date` DESC, category DESC, product_value DESC";
include('dao/connect.php');
$result = $db->query($statement);
$num = 0;
$fill = 0;
$totalSale = 0;
$totalPaid = 0;
$totalUnits = 0;
while ($row = $result->fetch_assoc()) {
$num++;
$totalSale += $row['totalamount'];
$totalUnits += $row['totalunits'];
$pdf->SetFillColor(224, 235, 255);
$pdf->setFont("times", "", "11");
$pdf->Cell(10, 7, $num, 1, 0, "L", $fill);
$pdf->Cell(35, 7, $row['category'], 1, 0, "L", $fill);
$pdf->Cell(30, 7, $row['product_value'], 1, 0, "L", $fill);
$pdf->Cell(20, 7, $row['price'], 1, 0, "R", $fill);
$pdf->Cell(25, 7, $row['pricetype'], 1, 0, "L", $fill);
$pdf->Cell(30, 7, $row['salesdate'], 1, 0, "R", $fill);
$pdf->Cell(15, 7, $row['totalunits'], 1, 0, "C", $fill);
$pdf->Cell(25, 7, $row['totalamount'], 1, 0, "R", $fill);
$y += 7;
$fill = !$fill;
if ($y > 275) {
$pdf->AddPage();
$pdf->SetFillColor(128, 128, 128); //gray
$pdf->setFont("times", "", "11");
$pdf->setXY(20, 40);
$pdf->Cell(10, 7, "#", 1, 0, "L", 1);
$pdf->Cell(35, 7, "Category", 1, 0, "C", 1);
$pdf->Cell(30, 7, "Product", 1, 0, "C", 1);
$pdf->Cell(20, 7, "Sale Price", 1, 0, "C", 1);
$pdf->Cell(25, 7, "Price Type", 1, 0, "C", 1);
$pdf->Cell(30, 7, "Date", 1, 0, "C", 1);
$pdf->Cell(15, 7, "Qty", 1, 0, "C", 1);
$pdf->Cell(25, 7, "Total", 1, 0, "C", 1);
$pdf->Ln();
$y = 45;
}
$pdf->setXY($x, $y);
}
$pdf->Cell(150, 7, "Totals", 1, 0, "C", 1);
$pdf->Cell(15, 7, $totalUnits, 1, 0, "C", 1);
$pdf->Cell(25, 7, "Ksh. ".number_format($totalSale,2), 1, 0, "R", 1);
$pdf->Output();
?>