forked from webERP-team/webERP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PDFTopItems.php
124 lines (120 loc) · 6.29 KB
/
PDFTopItems.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
<?php
include ('includes/session.php');
include ('includes/PDFStarter.php');
$FontSize = 10;
$pdf->addInfo('Title', _('Top Items Search Result'));
$PageNumber = 1;
$line_height = 12;
include ('includes/PDFTopItemsHeader.inc');
$FontSize = 10;
$FromDate = FormatDateForSQL(DateAdd(Date($_SESSION['DefaultDateFormat']),'d', -$_GET['NumberOfDays']));
//the situation if the location and customer type selected "All"
if (($_GET['Location'] == 'All') AND ($_GET['Customers'] == 'All')) {
$SQL = "SELECT salesorderdetails.stkcode,
SUM(salesorderdetails.qtyinvoiced) totalinvoiced,
SUM(salesorderdetails.qtyinvoiced * salesorderdetails.unitprice ) AS valuesales,
stockmaster.description,
stockmaster.units,
stockmaster.decimalplaces
FROM salesorderdetails, salesorders INNER JOIN locationusers ON locationusers.loccode=salesorders.fromstkloc AND locationusers.userid='" . $_SESSION['UserID'] . "' AND locationusers.canview=1,
debtorsmaster,stockmaster
WHERE salesorderdetails.orderno = salesorders.orderno
AND salesorderdetails.stkcode = stockmaster.stockid
AND salesorders.debtorno = debtorsmaster.debtorno
AND salesorderdetails.actualdispatchdate >='" . $FromDate . "'
GROUP BY salesorderdetails.stkcode
ORDER BY `" . $_GET['Sequence'] . "` DESC
LIMIT " . intval($_GET['NumberOfTopItems']) ;
} else { //the situation if only location type selected "All"
if ($_GET['Location'] == 'All') {
$SQL = "SELECT salesorderdetails.stkcode,
SUM(salesorderdetails.qtyinvoiced) totalinvoiced,
SUM(salesorderdetails.qtyinvoiced * salesorderdetails.unitprice ) AS valuesales,
stockmaster.description,
stockmaster.units
FROM salesorderdetails, salesorders INNER JOIN locationusers ON locationusers.loccode=salesorders.fromstkloc AND locationusers.userid='" . $_SESSION['UserID'] . "' AND locationusers.canview=1,
debtorsmaster,stockmaster
WHERE salesorderdetails.orderno = salesorders.orderno
AND salesorderdetails.stkcode = stockmaster.stockid
AND salesorders.debtorno = debtorsmaster.debtorno
AND debtorsmaster.typeid = '" . $_GET['Customers'] . "'
AND salesorderdetails.ActualDispatchDate >= '" . $FromDate . "'
GROUP BY salesorderdetails.stkcode
ORDER BY `" . $_GET['Sequence'] . "` DESC
LIMIT " . intval($_GET['NumberOfTopItems']);
} else {
//the situation if the customer type selected "All"
if ($_GET['Customers'] == 'All') {
$SQL = "SELECT salesorderdetails.stkcode,
SUM(salesorderdetails.qtyinvoiced) totalinvoiced,
SUM(salesorderdetails.qtyinvoiced * salesorderdetails.unitprice ) AS valuesales,
stockmaster.description,
stockmaster.units,
stockmaster.decimalplaces
FROM salesorderdetails, salesorders INNER JOIN locationusers ON locationusers.loccode=salesorders.fromstkloc AND locationusers.userid='" . $_SESSION['UserID'] . "' AND locationusers.canview=1,
debtorsmaster,stockmaster
WHERE salesorderdetails.orderno = salesorders.orderno
AND salesorderdetails.stkcode = stockmaster.stockid
AND salesorders.debtorno = debtorsmaster.debtorno
AND salesorders.fromstkloc = '" . $_GET['Location'] . "'
AND salesorderdetails.ActualDispatchDate >= '" . $FromDate . "'
GROUP BY salesorderdetails.stkcode
ORDER BY `" . $_GET['Sequence'] . "` DESC
LIMIT 0," . intval($_GET['NumberOfTopItems']);
} else {
//the situation if the location and customer type not selected "All"
$SQL = "SELECT salesorderdetails.stkcode,
SUM(salesorderdetails.qtyinvoiced) totalinvoiced,
SUM(salesorderdetails.qtyinvoiced * salesorderdetails.unitprice ) AS valuesales,
stockmaster.description,
stockmaster.units,
stockmaster.decimalplaces
FROM salesorderdetails, salesorders INNER JOIN locationusers ON locationusers.loccode=salesorders.fromstkloc AND locationusers.userid='" . $_SESSION['UserID'] . "' AND locationusers.canview=1,
debtorsmaster,stockmaster
WHERE salesorderdetails.orderno = salesorders.orderno
AND salesorderdetails.stkcode = stockmaster.stockid
AND salesorders.debtorno = debtorsmaster.debtorno
AND salesorders.fromstkloc = '" . $_GET['Location'] . "'
AND debtorsmaster.typeid = '" . $_GET['Customers'] . "'
AND salesorderdetails.actualdispatchdate >= '" . $FromDate . "'
GROUP BY salesorderdetails.stkcode
ORDER BY `" . $_GET['Sequence'] . "` DESC
LIMIT " . intval($_GET['NumberOfTopItems']);
}
}
}
$result = DB_query($SQL);
if (DB_num_rows($result)>0){
$YPos = $YPos - 6;
while ($myrow = DB_fetch_array($result)) {
//find the quantity onhand item
$sqloh = "SELECT sum(quantity)as qty
FROM locstock
INNER JOIN locationusers ON locationusers.loccode=locstock.loccode AND locationusers.userid='" . $_SESSION['UserID'] . "' AND locationusers.canview=1
WHERE stockid='" . DB_escape_string($myrow['stkcode']) . "'";
$oh = DB_query($sqloh);
$ohRow = DB_fetch_row($oh);
$LeftOvers = $pdf->addTextWrap($Left_Margin + 1, $YPos, 80, $FontSize, $myrow['stkcode']);
$LeftOvers = $pdf->addTextWrap($Left_Margin + 100, $YPos, 100, $FontSize, $myrow['description']);
$LeftOvers = $pdf->addTextWrap($Left_Margin + 330, $YPos, 30, $FontSize, locale_number_format($myrow['totalinvoiced'],$myrow['decimalplaces']), 'right');
$LeftOvers = $pdf->addTextWrap($Left_Margin + 370, $YPos, 300 - $Left_Margin, $FontSize, $myrow['units'], 'left');
$LeftOvers = $pdf->addTextWrap($Left_Margin + 400, $YPos, 70, $FontSize, locale_number_format($myrow['valuesales'], $_SESSION['CompanyRecord']['decimalplaces']), 'right');
$LeftOvers = $pdf->addTextWrap($Left_Margin + 490, $YPos, 30, $FontSize, locale_number_format($ohRow[0],$myrow['decimalplaces']), 'right');
if (mb_strlen($LeftOvers) > 1) {
$LeftOvers = $pdf->addTextWrap($Left_Margin + 1 + 94, $YPos - $line_height, 270, $FontSize, $LeftOvers, 'left');
$YPos-= $line_height;
}
if ($YPos - $line_height <= $Bottom_Margin) {
/* We reached the end of the page so finish off the page and start a newy */
$PageNumber++;
include ('includes/PDFTopItemsHeader.inc');
$FontSize = 10;
} //end if need a new page headed up
/*increment a line down for the next line item */
$YPos-= $line_height;
}
$pdf->OutputD($_SESSION['DatabaseName'] . '_TopItemsListing_' . date('Y-m-d').'.pdf');
$pdf->__destruct();
}
/*end of else not PrintPDF */
?>