3 /* $Revision: 1.12 $ */
7 include('includes/session.inc');
9 $title = _('Search Outstanding Purchase Orders');
11 include('includes/header.inc');
14 if (isset($_GET['SelectedStockItem'])){
15 $SelectedStockItem=trim($_GET['SelectedStockItem']);
16 } elseif (isset($_POST['SelectedStockItem'])){
17 $SelectedStockItem=trim($_POST['SelectedStockItem']);
20 if (isset($_GET['OrderNumber'])){
21 $OrderNumber=trim($_GET['OrderNumber']);
22 } elseif (isset($_POST['OrderNumber'])){
23 $OrderNumber=trim($_POST['OrderNumber']);
26 if (isset($_GET['SelectedSupplier'])){
27 $SelectedSupplier=trim($_GET['SelectedSupplier']);
28 } elseif (isset($_POST['SelectedSupplier'])){
29 $SelectedSupplier=trim($_POST['SelectedSupplier']);
32 echo '<FORM ACTION="' . $_SERVER['PHP_SELF'] . '?' . SID
. '" METHOD=POST>';
35 If ($_POST['ResetPart']){
36 unset($SelectedStockItem);
39 If (isset($OrderNumber) && $OrderNumber!='') {
40 if (!is_numeric($OrderNumber)){
41 echo '<BR><B>' . _('The Order Number entered') . ' <U>' . _('MUST') . '</U> ' . _('be numeric') . '.</B><BR>';
44 echo _('Order Number') . ' - ' . $OrderNumber;
47 If ($SelectedSupplier) {
48 echo _('For supplier') . ': ' . $SelectedSupplier . ' ' . _('and') . ' ';
49 echo '<input type=hidden name="SelectedSupplier" value=' . $SelectedSupplier . '>';
51 If ($SelectedStockItem) {
52 echo _('for the part') . ': ' . $SelectedStockItem . ' ' . _('and') . ' <input type=hidden name="SelectedStockItem" value="' . $SelectedStockItem . '">';
56 if ($_POST['SearchParts']){
58 If ($_POST['Keywords'] AND $_POST['StockCode']) {
59 echo _('Stock description keywords have been used in preference to the Stock code extract entered') . '.';
61 If ($_POST['Keywords']) {
62 //insert wildcard characters in spaces
65 while (strpos($_POST['Keywords'], ' ', $i)) {
66 $wrdlen=strpos($_POST['Keywords'],' ',$i) - $i;
67 $SearchString=$SearchString . substr($_POST['Keywords'],$i,$wrdlen) . '%';
68 $i=strpos($_POST['Keywords'],' ',$i) +
1;
70 $SearchString = $SearchString. substr($_POST['Keywords'],$i).'%';
72 $SQL = "SELECT stockmaster.stockid,
73 stockmaster.description,
74 SUM(locstock.quantity) AS qoh,
76 SUM(purchorderdetails.quantityord-purchorderdetails.quantityrecd) AS qord
77 FROM stockmaster INNER JOIN locstock
78 ON stockmaster.stockid = locstock.stockid
79 INNER JOIN purchorderdetails
80 ON stockmaster.stockid=purchorderdetails.itemcode
81 WHERE purchorderdetails.completed=0
82 AND stockmaster.description " . LIKE
. " '$SearchString'
83 AND stockmaster.categoryid='" . $_POST['StockCat'] . "'
84 GROUP BY stockmaster.stockid,
85 stockmaster.description,
87 ORDER BY stockmaster.stockid";
90 } elseif ($_POST['StockCode']){
91 $SQL = "SELECT stockmaster.stockid,
92 stockmaster.description,
93 SUM(locstock.quantity) AS qoh,
94 SUM(purchorderdetails.quantityord-purchorderdetails.quantityrecd) AS qord,
96 FROM stockmaster INNER JOIN locstock
97 ON stockmaster.stockid = locstock.stockid
98 INNER JOIN purchorderdetails
99 ON stockmaster.stockid=purchorderdetails.itemcode
100 WHERE purchorderdetails.completed=0
101 AND stockmaster.stockid " . LIKE
. " '%" . $_POST['StockCode'] . "%'
102 AND stockmaster.categoryid='" . $_POST['StockCat'] . "'
103 GROUP BY stockmaster.stockid,
104 stockmaster.description,
106 ORDER BY stockmaster.stockid";
108 } elseif (!$_POST['StockCode'] AND !$_POST['Keywords']) {
109 $SQL = "SELECT stockmaster.stockid,
110 stockmaster.description,
111 SUM(locstock.quantity) AS qoh,
113 SUM(purchorderdetails.quantityord-purchorderdetails.quantityrecd) AS qord
114 FROM stockmaster INNER JOIN locstock
115 ON stockmaster.stockid = locstock.stockid
116 INNER JOIN purchorderdetails
117 ON stockmaster.stockid=purchorderdetails.itemcode
118 WHERE purchorderdetails.completed=0
119 AND stockmaster.categoryid='" . $_POST['StockCat'] . "'
120 GROUP BY stockmaster.stockid,
121 stockmaster.description,
123 ORDER BY stockmaster.stockid";
126 $ErrMsg = _('No stock items were returned by the SQL because');
127 $DbgMsg = _('The SQL used to retrieve the searched parts was');
128 $StockItemsResult = DB_query($SQL,$db, $ErrMsg, $DbgMsg);
132 /* Not appropriate really to restrict search by date since user may miss older ouststanding orders
133 $OrdersAfterDate = Date("d/m/Y",Mktime(0,0,0,Date("m")-2,Date("d"),Date("Y")));
136 if ($OrderNumber=='' OR !isset($OrderNumber)){
138 echo _('order number') . ': <INPUT type=text name="OrderNumber" MAXLENGTH =8 SIZE=9> ' . _('Into Stock Location') . ':<SELECT name="StockLocation"> ';
139 $sql = 'SELECT loccode, locationname FROM locations';
140 $resultStkLocs = DB_query($sql,$db);
141 while ($myrow=DB_fetch_array($resultStkLocs)){
142 if (isset($_POST['StockLocation'])){
143 if ($myrow['loccode'] == $_POST['StockLocation']){
144 echo '<OPTION SELECTED Value="' . $myrow['loccode'] . '">' . $myrow['locationname'];
146 echo '<OPTION Value="' . $myrow['loccode'] . '">' . $myrow['locationname'];
148 } elseif ($myrow['loccode']== $_SESSION['UserStockLocation']){
149 echo '<OPTION SELECTED Value="' . $myrow['loccode'] . '">' . $myrow['locationname'];
151 echo '<OPTION Value="' . $myrow['loccode'] . '">' . $myrow['locationname'];
155 echo '</SELECT> <INPUT TYPE=SUBMIT NAME="SearchOrders" VALUE="' . _('Search Purchase Orders') . '">';
156 echo ' <a href="' . $rootpath . '/PO_Header.php?' .SID
. '&NewOrder=Yes">' . _('Add Purchase Order') . '</a>';
159 $SQL='SELECT categoryid, categorydescription FROM stockcategory ORDER BY categorydescription';
160 $result1 = DB_query($SQL,$db);
165 <FONT SIZE
=1><?php
echo _('To search for purchase orders for a specific part use the part selection facilities below'); ?
> </FONT
>
166 <INPUT TYPE
=SUBMIT NAME
="SearchParts" VALUE
="<?php echo _('Search Parts Now'); ?>">
167 <INPUT TYPE
=SUBMIT NAME
="ResetPart" VALUE
="<?php echo _('Show All'); ?>">
170 <TD
><FONT SIZE
=1><?php
echo _('Select a stock category'); ?
>:</FONT
>
171 <SELECT NAME
="StockCat">
173 while ($myrow1 = DB_fetch_array($result1)) {
174 if ($myrow1['categoryid']==$_POST['StockCat']){
175 echo "<OPTION SELECTED VALUE='". $myrow1['categoryid'] . "'>" . $myrow1['categorydescription'];
177 echo "<OPTION VALUE='". $myrow1['categoryid'] . "'>" . $myrow1['categorydescription'];
182 <TD
><FONT SIZE
=1><?php
echo _('Enter text extracts in the'); ?
> <B
><?php
echo _('description'); ?
></B
>:</FONT
></TD
>
183 <TD
><INPUT TYPE
="Text" NAME
="Keywords" SIZE
=20 MAXLENGTH
=25></TD
></TR
>
185 <TD
><FONT SIZE
3><B
><?php
echo _('OR'); ?
> </B
></FONT
><FONT SIZE
=1><?php
echo _('Enter extract of the'); ?
> <B
><?php
echo _('Stock Code'); ?
></B
>:</FONT
></TD
>
186 <TD
><INPUT TYPE
="Text" NAME
="StockCode" SIZE
=15 MAXLENGTH
=18></TD
>
194 If ($StockItemsResult) {
196 echo '<TABLE CELLPADDING=2 COLSPAN=7 BORDER=2>';
197 $TableHeader = '<TR><TD class="tableheader">' . _('Code') . '</TD>
198 <TD class="tableheader">' . _('Description') . '</TD>
199 <TD class="tableheader">' . _('On Hand') . '</TD>
200 <TD class="tableheader">' . _('Orders') . '<BR>' . _('Outstanding') . '</TD>
201 <TD class="tableheader">' . _('Units') . '</TD>
205 $k=0; //row colour counter
207 while ($myrow=DB_fetch_array($StockItemsResult)) {
210 echo '<tr bgcolor="#CCCCCC">';
213 echo '<tr bgcolor="#EEEEEE">';
217 printf("<td><INPUT TYPE=SUBMIT NAME='SelectedStockItem' VALUE='%s'</td>
219 <td ALIGN=RIGHT>%s</td>
220 <td ALIGN=RIGHT>%s</td>
223 $myrow['description'],
233 //end of page full new headings if
240 //end if stock search results to show
243 //figure out the SQL required from the inputs available
245 if (isset($OrderNumber) && $OrderNumber !='') {
246 $SQL = 'SELECT purchorders.orderno,
249 purchorders.initiator,
250 purchorders.requisitionno,
251 purchorders.allowprint,
253 SUM(purchorderdetails.unitprice*purchorderdetails.quantityord) AS ordervalue
257 WHERE purchorders.orderno = purchorderdetails.orderno
258 AND purchorders.supplierno = suppliers.supplierid
259 AND purchorderdetails.completed=0
260 AND purchorders.orderno='. $OrderNumber .'
261 GROUP BY purchorders.orderno,
264 purchorders.initiator,
265 purchorders.requisitionno,
266 purchorders.allowprint,
270 /* $DateAfterCriteria = FormatDateforSQL($OrdersAfterDate); */
272 if (isset($SelectedSupplier)) {
274 if (isset($SelectedStockItem)) {
275 $SQL = "SELECT purchorders.orderno,
278 purchorders.initiator,
279 purchorders.requisitionno,
280 purchorders.allowprint,
282 SUM(purchorderdetails.unitprice*purchorderdetails.quantityord) AS ordervalue
286 WHERE purchorders.orderno = purchorderdetails.orderno
287 AND purchorders.supplierno = suppliers.supplierid
288 AND purchorderdetails.completed=0
289 AND purchorderdetails.itemcode='". $SelectedStockItem ."'
290 AND purchorders.supplierno='" . $SelectedSupplier ."'
291 AND purchorders.intostocklocation = '". $_POST['StockLocation'] . "'
292 GROUP BY purchorders.orderno,
295 purchorders.initiator,
296 purchorders.requisitionno,
297 purchorders.allowprint,
300 $SQL = "SELECT purchorders.orderno,
303 purchorders.initiator,
304 purchorders.requisitionno,
305 purchorders.allowprint,
307 SUM(purchorderdetails.unitprice*purchorderdetails.quantityord) AS ordervalue
311 WHERE purchorders.orderno = purchorderdetails.orderno
312 AND purchorders.supplierno = suppliers.supplierid
313 AND purchorderdetails.completed=0
314 AND purchorders.supplierno='" . $SelectedSupplier ."'
315 AND purchorders.intostocklocation = '". $_POST['StockLocation'] . "'
316 GROUP BY purchorders.orderno,
319 purchorders.initiator,
320 purchorders.requisitionno,
321 purchorders.allowprint,
324 } else { //no supplier selected
325 if (isset($SelectedStockItem)) {
326 $SQL = "SELECT purchorders.orderno,
329 purchorders.initiator,
330 purchorders.requisitionno,
331 purchorders.allowprint,
333 SUM(purchorderdetails.unitprice*purchorderdetails.quantityord) AS ordervalue
337 WHERE purchorders.orderno = purchorderdetails.orderno
338 AND purchorders.supplierno = suppliers.supplierid
339 AND purchorderdetails.completed=0
340 AND purchorderdetails.itemcode='". $SelectedStockItem ."'
341 AND purchorders.intostocklocation = '". $_POST['StockLocation'] . "'
342 GROUP BY purchorders.orderno,
345 purchorders.initiator,
346 purchorders.requisitionno,
347 purchorders.allowprint,
350 $SQL = "SELECT purchorders.orderno,
353 purchorders.initiator,
354 purchorders.requisitionno,
355 purchorders.allowprint,
357 SUM(purchorderdetails.unitprice*purchorderdetails.quantityord) AS ordervalue
361 WHERE purchorders.orderno = purchorderdetails.orderno
362 AND purchorders.supplierno = suppliers.supplierid
363 AND purchorderdetails.completed=0
364 AND purchorders.intostocklocation = '". $_POST['StockLocation'] . "'
365 GROUP BY purchorders.orderno,
368 purchorders.initiator,
369 purchorders.requisitionno,
370 purchorders.allowprint,
374 } //end selected supplier
375 } //end not order number selected
377 $ErrMsg = _('No orders were returned by the SQL because');
378 $PurchOrdersResult = DB_query($SQL,$db,$ErrMsg);
380 /*show a table of the orders returned by the SQL */
382 echo '<TABLE CELLPADDING=2 COLSPAN=7 WIDTH=100%>';
383 $TableHeader = '<TR><TD class="tableheader">' . _('Modify') .
384 '</TD><TD class="tableheader">' . _('Receive') .
385 '</TD><TD class="tableheader">' . _('Print') .
386 '</TD><TD class="tableheader">' . _('Supplier') .
387 '</TD><TD class="tableheader">' . _('Currency') .
388 '</TD><TD class="tableheader">' . _('Requisition') .
389 '</TD><TD class="tableheader">' . _('Order Date') .
390 '</TD><TD class="tableheader">' . _('Initiator') .
391 '</TD><TD class="tableheader">' . _('Order Total') .
395 $k=0; //row colour counter
396 while ($myrow=DB_fetch_array($PurchOrdersResult)) {
399 if ($k==1){ /*alternate bgcolour of row for highlighting */
400 echo '<tr bgcolor="#CCCCCC">';
403 echo '<tr bgcolor="#EEEEEE">';
407 $ModifyPage = $rootpath . "/PO_Header.php?" . SID
. "ModifyOrderNumber=" . $myrow["orderno"];
408 $ReceiveOrder = $rootpath . "/GoodsReceived.php?" . SID
. "PONumber=" . $myrow["orderno"];
409 if ($myrow["allowprint"]==1){
410 $PrintPurchOrder = '<A target="_blank" HREF="' . $rootpath . '/PO_PDFPurchOrder.php?' . SID
. 'OrderNo=' . $myrow['orderno'] . '">' . _('Print Now') . '</A>';
412 $PrintPurchOrder = '<FONT COLOR=GREY>' . _('Printed') . '</FONT>';
414 $FormatedOrderDate = ConvertSQLDate($myrow['orddate']);
415 $FormatedOrderValue = number_format($myrow['ordervalue'],2);
417 printf("<td><A HREF='%s'>%s</A></FONT></td>
418 <td><A HREF='%s'>" . _('Receive') . "</A></td>
425 <td ALIGN=RIGHT>%s</FONT></td>
433 $myrow['requisitionno'],
436 $FormatedOrderValue);
443 //end of page full new headings if
451 include('includes/footer.inc');