7 include ('includes/session.inc');
8 include('includes/SQL_CommonFunctions.inc');
12 if (isset($_POST['FromDate']) AND !Is_Date($_POST['FromDate'])){
13 $msg = _('The date from must be specified in the format') . ' ' . $_SESSION['DefaultDateFormat'];
15 unset($_POST['FromDate']);
17 if (isset($_POST['ToDate']) AND !Is_Date($_POST['ToDate'])){
18 $msg = _('The date to must be specified in the format') . ' ' . $_SESSION['DefaultDateFormat'];
20 unset($_POST['ToDate']);
23 if (!isset($_POST['FromDate']) OR !isset($_POST['ToDate'])){
25 $title = _('Order Status Report');
26 include ('includes/header.inc');
32 echo "<FORM METHOD='post' action='" . $_SERVER['PHP_SELF'] . '?' . SID
. "'>";
33 echo '<CENTER><TABLE><TR><TD>' . _('Enter the date from which orders are to be listed') . ":</TD><TD><INPUT TYPE=text NAME='FromDate' MAXLENGTH=10 SIZE=10 VALUE='" . Date($_SESSION['DefaultDateFormat'], Mktime(0,0,0,Date('m'),Date('d')-1,Date('y'))) . "'></TD></TR>";
34 echo '<TR><TD>' . _('Enter the date to which orders are to be listed') . ":</TD><TD><INPUT TYPE=text NAME='ToDate' MAXLENGTH=10 SIZE=10 VALUE='" . Date($_SESSION['DefaultDateFormat']) . "'></TD></TR>";
35 echo '<TR><TD>' . _('Inventory Category') . '</TD><TD>';
37 $sql = "SELECT categorydescription, categoryid FROM stockcategory WHERE stocktype<>'D' AND stocktype<>'L'";
38 $result = DB_query($sql,$db);
41 echo "<SELECT NAME='CategoryID'>";
42 echo "<OPTION SELECTED VALUE='All'>" . _('Over All Categories');
44 while ($myrow=DB_fetch_array($result)){
45 echo '<OPTION VALUE=' . $myrow['categoryid'] . '>' . $myrow['categorydescription'];
47 echo '</SELECT></TD></TR>';
49 echo '<TR><TD>' . _('Inventory Location') . ":</TD><TD><SELECT NAME='Location'>";
50 echo "<OPTION SELECTED VALUE='All'>" . _('All Locations');
52 $result= DB_query('SELECT loccode, locationname FROM locations',$db);
53 while ($myrow=DB_fetch_array($result)){
54 echo "<OPTION VALUE='" . $myrow['loccode'] . "'>" . $myrow['locationname'];
56 echo '</SELECT></TD></TR>';
58 echo '<TR><TD>' . _('Back Order Only') . ":</TD><TD><SELECT NAME='BackOrders'>";
59 echo "<OPTION SELECTED VALUE='Yes'>" . _('Only Show Back Orders');
60 echo "<OPTION VALUE='No'>" . _('Show All Orders');
61 echo "</SELECT></TD></TR></TABLE><INPUT TYPE=SUBMIT NAME='Go' VALUE='" . _('Create PDF') . "'></CENTER>";
63 include('includes/footer.inc');
66 include('includes/ConnectDB.inc');
67 include('includes/PDFStarter.php');
71 if ($_POST['CategoryID']=='All' AND $_POST['Location']=='All'){
72 $sql= "SELECT salesorders.orderno,
74 salesorders.branchcode,
75 salesorders.customerref,
77 salesorders.fromstkloc,
78 salesorders.printedpackingslip,
79 salesorders.datepackingslipprinted,
80 salesorderdetails.stkcode,
81 stockmaster.description,
83 stockmaster.decimalplaces,
84 salesorderdetails.quantity,
85 salesorderdetails.qtyinvoiced,
86 salesorderdetails.completed
88 INNER JOIN salesorderdetails
89 ON salesorders.orderno = salesorderdetails.orderno
90 INNER JOIN stockmaster
91 ON salesorderdetails.stkcode = stockmaster.stockid
92 WHERE salesorders.orddate >='" . FormatDateForSQL($_POST['FromDate']) . "'
93 AND salesorders.orddate <='" . FormatDateForSQL($_POST['ToDate']) . "'
94 AND salesorders.quotation=0";
96 } elseif ($_POST['CategoryID']!='All' AND $_POST['Location']=='All') {
97 $sql= "SELECT salesorders.orderno,
99 salesorders.branchcode,
100 salesorders.customerref,
102 salesorders.fromstkloc,
103 salesorders.printedpackingslip,
104 salesorders.datepackingslipprinted,
105 salesorderdetails.stkcode,
106 stockmaster.description,
108 stockmaster.decimalplaces,
109 salesorderdetails.quantity,
110 salesorderdetails.qtyinvoiced,
111 salesorderdetails.completed
113 INNER JOIN salesorderdetails
114 ON salesorders.orderno = salesorderdetails.orderno
115 INNER JOIN stockmaster
116 ON salesorderdetails.stkcode = stockmaster.stockid
117 WHERE stockmaster.categoryid ='" . $_POST['CategoryID'] . "'
118 AND orddate >='" . FormatDateForSQL($_POST['FromDate']) . "'
119 AND orddate <='" . FormatDateForSQL($_POST['ToDate']) . "'
120 AND salesorders.quotation=0";
123 } elseif ($_POST['CategoryID']=='All' AND $_POST['Location']!='All') {
124 $sql= "SELECT salesorders.orderno,
125 salesorders.debtorno,
126 salesorders.branchcode,
127 salesorders.customerref,
129 salesorders.fromstkloc,
130 salesorders.printedpackingslip,
131 salesorders.datepackingslipprinted,
132 salesorderdetails.stkcode,
133 stockmaster.description,
135 stockmaster.decimalplaces,
136 salesorderdetails.quantity,
137 salesorderdetails.qtyinvoiced,
138 salesorderdetails.completed
140 INNER JOIN salesorderdetails
141 ON salesorders.orderno = salesorderdetails.orderno
142 INNER JOIN stockmaster
143 ON salesorderdetails.stkcode = stockmaster.stockid
144 WHERE salesorders.fromstkloc ='" . $_POST['Location'] . "'
145 AND salesorders.orddate >='" . FormatDateForSQL($_POST['FromDate']) . "'
146 AND salesorders.orddate <='" . FormatDateForSQL($_POST['ToDate']) . "'
147 AND salesorders.quotation=0";
150 } elseif ($_POST['CategoryID']!='All' AND $_POST['location']!='All'){
152 $sql= "SELECT salesorders.orderno,
153 salesorders.debtorno,
154 salesorders.branchcode,
155 salesorders.customerref,
157 salesorders.fromstkloc,
158 salesorders.printedpackingslip,
159 salesorders.datepackingslipprinted,
160 salesorderdetails.stkcode,
161 stockmaster.description,
163 stockmaster.decimalplaces,
164 salesorderdetails.quantity,
165 salesorderdetails.qtyinvoiced,
166 salesorderdetails.completed
168 INNER JOIN salesorderdetails
169 ON salesorders.orderno = salesorderdetails.orderno
170 INNER JOIN stockmaster
171 ON salesorderdetails.stkcode = stockmaster.stockid
172 WHERE stockmaster.categoryid ='" . $_POST['CategoryID'] . "'
173 AND salesorders.fromstkloc ='" . $_POST['Location'] . "'
174 AND salesorders.orddate >='" . FormatDateForSQL($_POST['FromDate']) . "'
175 AND salesorders.orddate <='" . FormatDateForSQL($_POST['ToDate']) . "'
176 AND salesorders.quotation=0";
180 if ($_POST['BackOrders']=='Yes'){
181 $sql .= ' AND salesorderdetails.quantity-salesorderdetails.qtyinvoiced >0';
184 $sql .= ' ORDER BY salesorders.orderno';
186 $Result=DB_query($sql,$db,'','',false,false); //dont trap errors here
188 if (DB_error_no($db)!=0){
189 include('includes/header.inc');
190 echo '<BR>' . _('An error occurred getting the orders details');
192 echo '<BR>' . _('The SQL used to get the orders that failed was') . '<BR>' . $sql;
194 include ('includes/footer.inc');
196 } elseif (DB_num_rows($Result)==0){
197 $title=_('Order Status Report - No Data');
198 include('includes/header.inc');
199 prnMsg(_('There were no orders found in the database within the period from') . ' ' . $_POST['FromDate'] . ' ' . _('to') . ' '. $_POST['ToDate'] . '. ' . _('Please try again selecting a different date range'),'info');
200 include('includes/footer.inc');
205 /*PDFStarter.php has all the variables for page size and width set up depending on the users default preferences for paper size */
207 $pdf->addinfo('Title',_('Order Status Report'));
208 $pdf->addinfo('Subject',_('Orders from') . ' ' . $_POST['FromDate'] . ' ' . _('to') . ' ' . $_POST['ToDate']);
215 include ('includes/PDFOrderStatusPageHeader.inc');
217 $OrderNo =0; /*initialise */
219 while ($myrow=DB_fetch_array($Result)){
222 if ($YPos - (2 *$line_height) < $Bottom_Margin){
223 /*Then set up a new page */
225 include ('includes/PDFOrderStatusPageHeader.inc');
227 } /*end of new page header */
228 if($OrderNo!=0 AND $OrderNo != $myrow['orderno']){
229 $pdf->line($XPos, $YPos,$Page_Width-$Right_Margin, $YPos);
230 $YPos -= $line_height;
233 if ($myrow['orderno']!=$OrderNo ){
234 $LeftOvers = $pdf->addTextWrap($Left_Margin,$YPos,40,$FontSize,$myrow['orderno'], 'left');
235 $LeftOvers = $pdf->addTextWrap($Left_Margin+
40,$YPos,80,$FontSize,$myrow['debtorno'], 'left');
236 $LeftOvers = $pdf->addTextWrap($Left_Margin+
120,$YPos,80,$FontSize,$myrow['branchcode'], 'left');
238 $LeftOvers = $pdf->addTextWrap($Left_Margin+
200,$YPos,100,$FontSize,$myrow['customerref'], 'left');
239 $LeftOvers = $pdf->addTextWrap($Left_Margin+
300,$YPos,80,$FontSize,ConvertSQLDate($myrow['orddate']), 'left');
240 $LeftOvers = $pdf->addTextWrap($Left_Margin+
380,$YPos,20,$FontSize,$myrow['fromstkloc'], 'left');
242 if ($myrow['printedpackingslip']==1){
243 $PackingSlipPrinted = _('Printed') . ' ' . ConvertSQLDate($myrow['datepackingslipprinted']);
245 $PackingSlipPrinted =_('Not yet printed');
248 $LeftOvers = $pdf->addTextWrap($Left_Margin+
400,$YPos,100,$FontSize,$PackingSlipPrinted, 'left');
250 $YPos -= ($line_height);
252 /*Its not the first line */
253 $OrderNo = $myrow['orderno'];
254 $LeftOvers = $pdf->addTextWrap($Left_Margin,$YPos,60,$FontSize,_('Code'), 'center');
255 $LeftOvers = $pdf->addTextWrap($Left_Margin+
60,$YPos,120,$FontSize,_('Description'), 'center');
256 $LeftOvers = $pdf->addTextWrap($Left_Margin+
180,$YPos,60,$FontSize,_('Ordered'), 'center');
257 $LeftOvers = $pdf->addTextWrap($Left_Margin+
240,$YPos,60,$FontSize,_('Invoiced'), 'centre');
258 $LeftOvers = $pdf->addTextWrap($Left_Margin+
320,$YPos,60,$FontSize,_('Outstanding'), 'center');
259 $YPos -= ($line_height);
263 $LeftOvers = $pdf->addTextWrap($Left_Margin,$YPos,60,$FontSize,$myrow['stkcode'], 'left');
264 $LeftOvers = $pdf->addTextWrap($Left_Margin+
60,$YPos,120,$FontSize,$myrow['description'], 'left');
265 $LeftOvers = $pdf->addTextWrap($Left_Margin+
180,$YPos,60,$FontSize,number_format($myrow['quantity'],$myrow['decimalplaces']), 'right');
266 $LeftOvers = $pdf->addTextWrap($Left_Margin+
240,$YPos,60,$FontSize,number_format($myrow['qtyinvoiced'],$myrow['decimalplaces']), 'right');
268 if ($myrow['quantity']>$myrow['qtyinvoiced']){
269 $LeftOvers = $pdf->addTextWrap($Left_Margin+
320,$YPos,60,$FontSize,number_format($myrow['quantity']-$myrow['qtyinvoiced'],$myrow['decimalplaces']), 'right');
271 $LeftOvers = $pdf->addTextWrap($Left_Margin+
320,$YPos,60,$FontSize,_('Complete'), 'left');
274 $YPos -= ($line_height);
275 if ($YPos - (2 *$line_height) < $Bottom_Margin){
276 /*Then set up a new page */
278 include ('includes/PDFOrderStatusPageHeader.inc');
280 } /*end of new page header */
281 } /* end of while there are delivery differences to print */
283 $pdfcode = $pdf->output();
284 $len = strlen($pdfcode);
285 header('Content-type: application/pdf');
286 header('Content-Length: ' . $len);
287 header('Content-Disposition: inline; filename=OrderStatus.pdf');
288 header('Expires: 0');
289 header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
290 header('Pragma: public');