1<?php 2 3include ('includes/DefineStockRequestClass.php'); 4 5include ('includes/session.php'); 6$Title = _('Create an Internal Materials Request'); 7$ViewTopic = 'Inventory'; 8$BookMark = 'CreateRequest'; 9include ('includes/header.php'); 10include ('includes/SQL_CommonFunctions.inc'); 11 12if (isset($_GET['New'])) { 13 unset($_SESSION['Transfer']); 14 $_SESSION['Request'] = new StockRequest(); 15} 16 17if (isset($_POST['Update'])) { 18 $InputError = 0; 19 if ($_POST['Department'] == '') { 20 prnMsg(_('You must select a Department for the request'), 'error'); 21 $InputError = 1; 22 } 23 if ($_POST['Location'] == '') { 24 prnMsg(_('You must select a Location to request the items from'), 'error'); 25 $InputError = 1; 26 } 27 if ($InputError == 0) { 28 $_SESSION['Request']->Department = $_POST['Department']; 29 $_SESSION['Request']->Location = $_POST['Location']; 30 $_SESSION['Request']->DispatchDate = $_POST['DispatchDate']; 31 $_SESSION['Request']->Narrative = $_POST['Narrative']; 32 } 33} 34 35if (isset($_POST['Edit'])) { 36 $_SESSION['Request']->LineItems[$_POST['LineNumber']]->Quantity = $_POST['Quantity']; 37} 38 39if (isset($_GET['Delete'])) { 40 unset($_SESSION['Request']->LineItems[$_GET['Delete']]); 41 echo '<br />'; 42 prnMsg(_('The line was successfully deleted'), 'success'); 43 echo '<br />'; 44} 45 46foreach ($_POST as $key => $value) { 47 if (mb_strstr($key, 'StockID')) { 48 $Index = mb_substr($key, 7); 49 if (filter_number_format($_POST['Quantity' . $Index]) > 0) { 50 $StockID = $value; 51 $ItemDescription = $_POST['ItemDescription' . $Index]; 52 $DecimalPlaces = $_POST['DecimalPlaces' . $Index]; 53 $NewItem_array[$StockID] = filter_number_format($_POST['Quantity' . $Index]); 54 $_POST['Units' . $StockID] = $_POST['Units' . $Index]; 55 $_SESSION['Request']->AddLine($StockID, $ItemDescription, $NewItem_array[$StockID], $_POST['Units' . $StockID], $DecimalPlaces); 56 } 57 } 58} 59 60if (isset($_POST['Submit']) and (!empty($_SESSION['Request']->LineItems))) { 61 62 DB_Txn_Begin(); 63 $InputError = 0; 64 if ($_SESSION['Request']->Department == '') { 65 prnMsg(_('You must select a Department for the request'), 'error'); 66 $InputError = 1; 67 } 68 if ($_SESSION['Request']->Location == '') { 69 prnMsg(_('You must select a Location to request the items from'), 'error'); 70 $InputError = 1; 71 } 72 if ($InputError == 0) { 73 $RequestNo = GetNextTransNo(38); 74 $HeaderSQL = "INSERT INTO stockrequest (dispatchid, 75 loccode, 76 departmentid, 77 despatchdate, 78 narrative, 79 initiator) 80 VALUES( 81 '" . $RequestNo . "', 82 '" . $_SESSION['Request']->Location . "', 83 '" . $_SESSION['Request']->Department . "', 84 '" . FormatDateForSQL($_SESSION['Request']->DispatchDate) . "', 85 '" . $_SESSION['Request']->Narrative . "', 86 '" . $_SESSION['UserID'] . "')"; 87 $ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The request header record could not be inserted because'); 88 $DbgMsg = _('The following SQL to insert the request header record was used'); 89 $Result = DB_query($HeaderSQL, $ErrMsg, $DbgMsg, true); 90 91 foreach ($_SESSION['Request']->LineItems as $LineItems) { 92 $LineSQL = "INSERT INTO stockrequestitems (dispatchitemsid, 93 dispatchid, 94 stockid, 95 quantity, 96 decimalplaces, 97 uom) 98 VALUES( 99 '" . $LineItems->LineNumber . "', 100 '" . $RequestNo . "', 101 '" . $LineItems->StockID . "', 102 '" . $LineItems->Quantity . "', 103 '" . $LineItems->DecimalPlaces . "', 104 '" . $LineItems->UOM . "')"; 105 $ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The request line record could not be inserted because'); 106 $DbgMsg = _('The following SQL to insert the request header record was used'); 107 $Result = DB_query($LineSQL, $ErrMsg, $DbgMsg, true); 108 } 109 110 $EmailSQL = "SELECT email 111 FROM www_users, departments 112 WHERE departments.authoriser = www_users.userid 113 AND departments.departmentid = '" . $_SESSION['Request']->Department . "'"; 114 $EmailResult = DB_query($EmailSQL); 115 if ($myEmail = DB_fetch_array($EmailResult)) { 116 $ConfirmationText = _('An internal stock request has been created and is waiting for your authoritation'); 117 $EmailSubject = _('Internal Stock Request needs your authoritation'); 118 if ($_SESSION['SmtpSetting'] == 0) { 119 mail($myEmail['email'], $EmailSubject, $ConfirmationText); 120 } else { 121 include ('includes/htmlMimeMail.php'); 122 $mail = new htmlMimeMail(); 123 $mail->setSubject($EmailSubject); 124 $mail->setText($ConfirmationText); 125 $Result = SendmailBySmtp($mail, array($myEmail['email'])); 126 } 127 } 128 } 129 DB_Txn_Commit(); 130 prnMsg(_('The internal stock request has been entered and now needs to be authorised'), 'success'); 131 echo '<br /><div class="centre"><a href="', htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8'), '?New=Yes">', _('Create another request'), '</a></div>'; 132 include ('includes/footer.php'); 133 unset($_SESSION['Request']); 134 exit; 135} elseif (isset($_POST['Submit'])) { 136 prnMsg(_('There are no items added to this request'), 'error'); 137} 138 139echo '<p class="page_title_text"><img src="', $RootPath, '/css/', $Theme, '/images/supplier.png" title="', _('Dispatch'), '" alt="" />', ' ', $Title, '</p>'; 140 141if (isset($_GET['Edit'])) { 142 echo '<form action="', htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8'), '" method="post">'; 143 echo '<div>'; 144 echo '<input type="hidden" name="FormID" value="', $_SESSION['FormID'], '" />'; 145 echo '<table class="selection">'; 146 echo '<tr> 147 <th colspan="2"><h4>', _('Edit the Request Line'), '</h4></th> 148 </tr>'; 149 echo '<tr> 150 <td>', _('Line number'), '</td> 151 <td>', $_SESSION['Request']->LineItems[$_GET['Edit']]->LineNumber, '</td> 152 </tr> 153 <tr> 154 <td>', _('Stock Code'), '</td> 155 <td>', $_SESSION['Request']->LineItems[$_GET['Edit']]->StockID, '</td> 156 </tr> 157 <tr> 158 <td>', _('Item Description'), '</td> 159 <td>', $_SESSION['Request']->LineItems[$_GET['Edit']]->ItemDescription, '</td> 160 </tr> 161 <tr> 162 <td>', _('Unit of Measure'), '</td> 163 <td>', $_SESSION['Request']->LineItems[$_GET['Edit']]->UOM, '</td> 164 </tr> 165 <tr> 166 <td>', _('Quantity Requested'), '</td> 167 <td><input type="text" class="number" name="Quantity" value="', locale_number_format($_SESSION['Request']->LineItems[$_GET['Edit']]->Quantity, $_SESSION['Request']->LineItems[$_GET['Edit']]->DecimalPlaces), '" /></td> 168 </tr>'; 169 echo '<input type="hidden" name="LineNumber" value="', $_SESSION['Request']->LineItems[$_GET['Edit']]->LineNumber, '" />'; 170 echo '</table> 171 <br />'; 172 echo '<div class="centre"> 173 <input type="submit" name="Edit" value="', _('Update Line'), '" /> 174 </div> 175 </div> 176 </form>'; 177 include ('includes/footer.php'); 178 exit; 179} 180 181echo '<form action="', htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8'), '" method="post"> 182 <div> 183 <input type="hidden" name="FormID" value="', $_SESSION['FormID'], '" /> 184 <table class="selection"> 185 <tr> 186 <th colspan="2"><h4>', _('Internal Stock Request Details'), '</h4></th> 187 </tr> 188 <tr> 189 <td>' . _('Department') . ':</td>'; 190if ($_SESSION['AllowedDepartment'] == 0) { 191 // any internal department allowed 192 $SQL = "SELECT departmentid, 193 description 194 FROM departments 195 ORDER BY description"; 196} else { 197 // just 1 internal department allowed 198 $SQL = "SELECT departmentid, 199 description 200 FROM departments 201 WHERE departmentid = '" . $_SESSION['AllowedDepartment'] . "' 202 ORDER BY description"; 203} 204$Result = DB_query($SQL); 205echo '<td><select name="Department">'; 206while ($MyRow = DB_fetch_array($Result)) { 207 if (isset($_SESSION['Request']->Department) and $_SESSION['Request']->Department == $MyRow['departmentid']) { 208 echo '<option selected value="', $MyRow['departmentid'], '">', htmlspecialchars($MyRow['description'], ENT_QUOTES, 'UTF-8'), '</option>'; 209 } else { 210 echo '<option value="', $MyRow['departmentid'], '">', htmlspecialchars($MyRow['description'], ENT_QUOTES, 'UTF-8'), '</option>'; 211 } 212} 213echo '</select></td> 214 </tr> 215 <tr> 216 <td>' . _('Location from which to request stock') . ':</td>'; 217$SQL = "SELECT locations.loccode, 218 locationname 219 FROM locations 220 INNER JOIN locationusers ON locationusers.loccode=locations.loccode AND locationusers.userid='" . $_SESSION['UserID'] . "' AND locationusers.canupd=1 221 WHERE internalrequest = 1 222 ORDER BY locationname"; 223 224$Result = DB_query($SQL); 225echo '<td><select name="Location"> 226 <option value="">', _('Select a Location'), '</option>'; 227while ($MyRow = DB_fetch_array($Result)) { 228 if (isset($_SESSION['Request']->Location) and $_SESSION['Request']->Location == $MyRow['loccode']) { 229 echo '<option selected value="', $MyRow['loccode'], '">', $MyRow['loccode'], ' - ', htmlspecialchars($MyRow['locationname'], ENT_QUOTES, 'UTF-8'), '</option>'; 230 } else { 231 echo '<option value="', $MyRow['loccode'], '">', $MyRow['loccode'], ' - ', htmlspecialchars($MyRow['locationname'], ENT_QUOTES, 'UTF-8'), '</option>'; 232 } 233} 234echo '</select></td> 235 </tr> 236 <tr> 237 <td>', _('Date when required'), ':</td> 238 <td><input type="text" class="date" name="DispatchDate" maxlength="10" size="11" value="', $_SESSION['Request']->DispatchDate, '" /></td> 239 </tr> 240 <tr> 241 <td>', _('Narrative'), ':</td> 242 <td><textarea name="Narrative" cols="30" rows="5">', $_SESSION['Request']->Narrative, '</textarea></td> 243 </tr> 244 </table> 245 <br /> 246 <div class="centre"> 247 <input type="submit" name="Update" value="', _('Update'), '" /> 248 </div> 249 </div> 250 </form>'; 251 252if (!isset($_SESSION['Request']->Location)) { 253 include ('includes/footer.php'); 254 exit; 255} 256 257echo '<form action="', htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8'), '" method="post"> 258 <div> 259 <input type="hidden" name="FormID" value="', $_SESSION['FormID'], '" /> 260 <br /> 261 <table class="selection"> 262 <thead> 263 <tr> 264 <th colspan="7"><h4>', _('Details of Items Requested'), '</h4></th> 265 </tr> 266 <tr> 267 <th>', _('Line Number'), '</th> 268 <th class="ascending">', _('Item Code'), '</th> 269 <th class="ascending">', _('Item Description'), '</th> 270 <th class="ascending">', _('Quantity Required'), '</th> 271 <th>', _('UOM'), '</th> 272 </tr> 273 </thead> 274 <tbody>'; 275 276if (isset($_SESSION['Request']->LineItems)) { 277 foreach ($_SESSION['Request']->LineItems as $LineItems) { 278 echo '<tr class="striped_row"> 279 <td>', $LineItems->LineNumber, '</td> 280 <td>', $LineItems->StockID, '</td> 281 <td>', $LineItems->ItemDescription, '</td> 282 <td class="number">', locale_number_format($LineItems->Quantity, $LineItems->DecimalPlaces), '</td> 283 <td>', $LineItems->UOM, '</td> 284 <td><a href="', htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8'), '?Edit=', urlencode($LineItems->LineNumber), '">', _('Edit'), '</a></td> 285 <td><a href="', htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8'), '?Delete=', urlencode($LineItems->LineNumber), '">', _('Delete'), '</a></td> 286 </tr>'; 287 } 288} 289 290echo '</tbody> 291 </table> 292 <br /> 293 <div class="centre"> 294 <input type="submit" name="Submit" value="', _('Submit'), '" /> 295 </div> 296 <br /> 297 </div> 298 </form>'; 299 300echo '<p class="page_title_text"> 301 <img src="', $RootPath, '/css/', $Theme, '/images/magnifier.png" title="', _('Search'), '" alt="" />', ' ', _('Search for Inventory Items'), '</p> 302 <form action="', htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8'), '" method="post"> 303 <div> 304 <input type="hidden" name="FormID" value="', $_SESSION['FormID'], '" />'; 305 306$SQL = "SELECT stockcategory.categoryid, 307 stockcategory.categorydescription 308 FROM stockcategory 309 INNER JOIN internalstockcatrole 310 ON stockcategory.categoryid = internalstockcatrole.categoryid 311 WHERE internalstockcatrole.secroleid= " . $_SESSION['AccessLevel'] . " 312 ORDER BY stockcategory.categorydescription"; 313 314$Result1 = DB_query($SQL); 315if (DB_num_rows($Result1) == 0) { 316 echo '<p class="bad">', _('Problem Report'), ':<br />', _('There are no stock categories currently defined please use the link below to set them up'), '</p> 317 <br /> 318 <a href="', $RootPath, '/StockCategories.php">', _('Define Stock Categories'), '</a>'; 319 exit; 320} 321 322echo '<table class="selection"> 323 <tr> 324 <td>' . _('In Stock Category') . ':<select name="StockCat">'; 325 326if (!isset($_POST['StockCat'])) { 327 $_POST['StockCat'] = 'All'; 328} 329 330if ($_POST['StockCat'] == 'All') { 331 echo '<option selected value="All">' . _('All Authorized') . '</option>'; 332} else { 333 echo '<option value="All">' . _('All Authorized') . '</option>'; 334} 335 336while ($MyRow1 = DB_fetch_array($Result1)) { 337 if ($MyRow1['categoryid'] == $_POST['StockCat']) { 338 echo '<option selected value="', $MyRow1['categoryid'], '">', $MyRow1['categorydescription'], '</option>'; 339 } else { 340 echo '<option value="', $MyRow1['categoryid'], '">', $MyRow1['categorydescription'], '</option>'; 341 } 342} 343 344echo '</select></td> 345 <td>', _('Enter partial'), '<b> ', _('Description'), '</b>:</td>'; 346 347if (isset($_POST['Keywords'])) { 348 echo '<td><input type="text" name="Keywords" value="', $_POST['Keywords'], '" size="20" maxlength="25" /></td>'; 349} else { 350 echo '<td><input type="text" name="Keywords" size="20" maxlength="25" /></td>'; 351} 352 353echo '</tr> 354 <tr> 355 <td></td> 356 <td><h3>', _('OR'), ' ', '</h3>', _('Enter partial'), ' <b>', _('Stock Code'), '</b>:</td>'; 357 358if (isset($_POST['StockCode'])) { 359 echo '<td><input type="text" autofocus="autofocus" name="StockCode" value="', $_POST['StockCode'], '" size="15" maxlength="18" /></td>'; 360} else { 361 echo '<td><input type="text" name="StockCode" size="15" maxlength="18" /></td>'; 362} 363 364echo '</tr> 365 </table> 366 <br /> 367 <div class="centre"> 368 <input type="submit" name="Search" value="', _('Search Now'), '" /> 369 </div> 370 <br /> 371 </div> 372 </form>'; 373 374if (isset($_POST['Search']) or isset($_POST['Next']) or isset($_POST['Previous'])) { 375 376 if ($_POST['Keywords'] != '' and $_POST['StockCode'] == '') { 377 prnMsg(_('Order Item description has been used in search'), 'warn'); 378 } elseif ($_POST['StockCode'] != '' and $_POST['Keywords'] == '') { 379 prnMsg(_('Stock Code has been used in search'), 'warn'); 380 } elseif ($_POST['Keywords'] == '' and $_POST['StockCode'] == '') { 381 prnMsg(_('Stock Category has been used in search'), 'warn'); 382 } 383 384 if (isset($_POST['Keywords']) and mb_strlen($_POST['Keywords']) > 0) { 385 //insert wildcard characters in spaces 386 $_POST['Keywords'] = mb_strtoupper($_POST['Keywords']); 387 $SearchString = '%' . str_replace(' ', '%', $_POST['Keywords']) . '%'; 388 389 if ($_POST['StockCat'] == 'All') { 390 $SQL = "SELECT stockmaster.stockid, 391 stockmaster.description, 392 stockmaster.units as stockunits, 393 stockmaster.decimalplaces 394 FROM stockmaster 395 INNER JOIN stockcategory 396 ON stockmaster.categoryid=stockcategory.categoryid 397 INNER JOIN internalstockcatrole 398 ON stockcategory.categoryid = internalstockcatrole.categoryid 399 WHERE stockmaster.mbflag <>'G' 400 AND stockmaster.discontinued=0 401 AND internalstockcatrole.secroleid= " . $_SESSION['AccessLevel'] . " 402 AND stockmaster.description " . LIKE . " '" . $SearchString . "' 403 ORDER BY stockmaster.stockid"; 404 } else { 405 $SQL = "SELECT stockmaster.stockid, 406 stockmaster.description, 407 stockmaster.units as stockunits, 408 stockmaster.decimalplaces 409 FROM stockmaster 410 INNER JOIN stockcategory 411 ON stockmaster.categoryid=stockcategory.categoryid 412 INNER JOIN internalstockcatrole 413 ON stockcategory.categoryid = internalstockcatrole.categoryid 414 WHERE stockmaster.mbflag <>'G' 415 AND stockmaster.discontinued=0 416 AND internalstockcatrole.secroleid= " . $_SESSION['AccessLevel'] . " 417 AND stockmaster.description " . LIKE . " '" . $SearchString . "' 418 AND stockmaster.categoryid='" . $_POST['StockCat'] . "' 419 ORDER BY stockmaster.stockid"; 420 } 421 422 } elseif (mb_strlen($_POST['StockCode']) > 0) { 423 424 $_POST['StockCode'] = mb_strtoupper($_POST['StockCode']); 425 $SearchString = '%' . $_POST['StockCode'] . '%'; 426 427 if ($_POST['StockCat'] == 'All') { 428 $SQL = "SELECT stockmaster.stockid, 429 stockmaster.description, 430 stockmaster.units as stockunits, 431 stockmaster.decimalplaces 432 FROM stockmaster 433 INNER JOIN stockcategory 434 ON stockmaster.categoryid=stockcategory.categoryid 435 INNER JOIN internalstockcatrole 436 ON stockcategory.categoryid = internalstockcatrole.categoryid 437 WHERE stockmaster.mbflag <>'G' 438 AND stockmaster.discontinued=0 439 AND internalstockcatrole.secroleid= " . $_SESSION['AccessLevel'] . " 440 AND stockmaster.stockid " . LIKE . " '" . $SearchString . "' 441 ORDER BY stockmaster.stockid"; 442 } else { 443 $SQL = "SELECT stockmaster.stockid, 444 stockmaster.description, 445 stockmaster.units as stockunits, 446 stockmaster.decimalplaces 447 FROM stockmaster 448 INNER JOIN stockcategory 449 ON stockmaster.categoryid=stockcategory.categoryid 450 INNER JOIN internalstockcatrole 451 ON stockcategory.categoryid = internalstockcatrole.categoryid 452 WHERE stockmaster.mbflag <>'G' 453 AND stockmaster.discontinued=0 454 AND internalstockcatrole.secroleid= " . $_SESSION['AccessLevel'] . " 455 AND stockmaster.stockid " . LIKE . " '" . $SearchString . "' 456 AND stockmaster.categoryid='" . $_POST['StockCat'] . "' 457 ORDER BY stockmaster.stockid"; 458 } 459 460 } else { 461 if ($_POST['StockCat'] == 'All') { 462 $SQL = "SELECT stockmaster.stockid, 463 stockmaster.description, 464 stockmaster.units as stockunits, 465 stockmaster.decimalplaces 466 FROM stockmaster 467 INNER JOIN stockcategory 468 ON stockmaster.categoryid=stockcategory.categoryid 469 INNER JOIN internalstockcatrole 470 ON stockcategory.categoryid = internalstockcatrole.categoryid 471 WHERE stockmaster.mbflag <>'G' 472 AND stockmaster.discontinued=0 473 AND internalstockcatrole.secroleid= " . $_SESSION['AccessLevel'] . " 474 ORDER BY stockmaster.stockid"; 475 } else { 476 $SQL = "SELECT stockmaster.stockid, 477 stockmaster.description, 478 stockmaster.units as stockunits, 479 stockmaster.decimalplaces 480 FROM stockmaster 481 INNER JOIN stockcategory 482 ON stockmaster.categoryid=stockcategory.categoryid 483 INNER JOIN internalstockcatrole 484 ON stockcategory.categoryid = internalstockcatrole.categoryid 485 WHERE stockmaster.mbflag <>'G' 486 AND stockmaster.discontinued=0 487 AND internalstockcatrole.secroleid= " . $_SESSION['AccessLevel'] . " 488 AND stockmaster.categoryid='" . $_POST['StockCat'] . "' 489 ORDER BY stockmaster.stockid"; 490 } 491 } 492 493 if (isset($_POST['Next'])) { 494 $Offset = $_POST['NextList']; 495 } 496 if (isset($_POST['Previous'])) { 497 $Offset = $_POST['PreviousList']; 498 } 499 if (!isset($Offset) or $Offset < 0) { 500 $Offset = 0; 501 } 502 $SQL = $SQL . ' LIMIT ' . $_SESSION['DisplayRecordsMax'] . ' OFFSET ' . ($_SESSION['DisplayRecordsMax'] * $Offset); 503 504 $ErrMsg = _('There is a problem selecting the part records to display because'); 505 $DbgMsg = _('The SQL used to get the part selection was'); 506 $SearchResult = DB_query($SQL, $ErrMsg, $DbgMsg); 507 508 if (DB_num_rows($SearchResult) == 0) { 509 prnMsg(_('There are no products available meeting the criteria specified'), 'info'); 510 } 511 if (DB_num_rows($SearchResult) < $_SESSION['DisplayRecordsMax']) { 512 $Offset = 0; 513 } 514 515} //end of if search 516if (isset($SearchResult)) { 517 $j = 1; 518 echo '<br /> 519 <div class="page_help_text">', _('Select an item by entering the quantity required. Click Order when ready.'), '</div> 520 <br /> 521 <form action="', htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8'), '" method="post" id="orderform"> 522 <div> 523 <input type="hidden" name="FormID" value="', $_SESSION['FormID'], '" /> 524 <table class="table1"> 525 <thead> 526 <tr> 527 <td> 528 <input type="hidden" name="PreviousList" value="', ($Offset - 1), '" /> 529 <input tabindex="', ($j + 8), '" type="submit" name="Previous" value="', _('Previous'), '" /></td> 530 <td class="centre" colspan="6"> 531 <input type="hidden" name="order_items" value="1" /> 532 <input tabindex="', ($j + 9), '" type="submit" value="', _('Add to Requisition'), '" /></td> 533 <td> 534 <input type="hidden" name="NextList" value="', ($Offset + 1), '" /> 535 <input tabindex="', ($j + 10), '" type="submit" name="Next" value="', _('Next'), '" /></td> 536 </tr> 537 <tr> 538 <th class="ascending">', _('Code'), '</th> 539 <th class="ascending">', _('Description'), '</th> 540 <th>', _('Units'), '</th> 541 <th class="ascending">', _('On Hand'), '</th> 542 <th class="ascending">', _('On Demand'), '</th> 543 <th class="ascending">', _('On Order'), '</th> 544 <th class="ascending">', _('Available'), '</th> 545 <th class="ascending">', _('Quantity'), '</th> 546 </tr> 547 </thead> 548 <tbody>'; 549 550 $ImageSource = _('No Image'); 551 552 $i = 0; 553 while ($MyRow = DB_fetch_array($SearchResult)) { 554 if ($MyRow['decimalplaces'] == '') { 555 /* This REALLY seems to be a redundant (unnecessary) re-query? 556 * The default on stockmaster is 0, so an empty string should never 557 * be true, as decimalplaces is in all queries from lines 382-482. 558 */ 559 $DecimalPlacesSQL = "SELECT decimalplaces 560 FROM stockmaster 561 WHERE stockid='" . $MyRow['stockid'] . "'"; 562 $DecimalPlacesResult = DB_query($DecimalPlacesSQL); 563 $DecimalPlacesRow = DB_fetch_array($DecimalPlacesResult); 564 $DecimalPlaces = $DecimalPlacesRow['decimalplaces']; 565 } else { 566 $DecimalPlaces = $MyRow['decimalplaces']; 567 } 568 569 $QOHSQL = "SELECT sum(locstock.quantity) AS qoh 570 FROM locstock 571 WHERE locstock.stockid='" . $MyRow['stockid'] . "' 572 AND loccode = '" . $_SESSION['Request']->Location . "'"; 573 $QOHResult = DB_query($QOHSQL); 574 $QOHRow = DB_fetch_array($QOHResult); 575 $QOH = $QOHRow['qoh']; 576 577 // Find the quantity on outstanding sales orders 578 $SQL = "SELECT SUM(salesorderdetails.quantity-salesorderdetails.qtyinvoiced) AS dem 579 FROM salesorderdetails 580 INNER JOIN salesorders 581 ON salesorders.orderno = salesorderdetails.orderno 582 WHERE salesorders.fromstkloc='" . $_SESSION['Request']->Location . "' 583 AND salesorderdetails.completed=0 584 AND salesorders.quotation=0 585 AND salesorderdetails.stkcode='" . $MyRow['stockid'] . "'"; 586 $ErrMsg = _('The demand for this product from') . ' ' . $_SESSION['Request']->Location . ' ' . _('cannot be retrieved because'); 587 $DemandResult = DB_query($SQL, $ErrMsg); 588 589 $DemandRow = DB_fetch_row($DemandResult); 590 if ($DemandRow[0] != null) { 591 $DemandQty = $DemandRow[0]; 592 } else { 593 $DemandQty = 0; 594 } 595 596 $PurchQty = GetQuantityOnOrderDueToPurchaseOrders($MyRow['stockid'], ''); 597 $WoQty = GetQuantityOnOrderDueToWorkOrders($MyRow['stockid'], ''); 598 599 $OnOrder = $PurchQty + $WoQty; 600 $Available = $QOH - $DemandQty + $OnOrder; 601 602 echo '<tr class="striped_row"> 603 <td>', $MyRow['stockid'], '</td> 604 <td>', $MyRow['description'], '</td> 605 <td>', $MyRow['stockunits'], '</td> 606 <td class="number">', locale_number_format($QOH, $DecimalPlaces), '</td> 607 <td class="number">', locale_number_format($DemandQty, $DecimalPlaces), '</td> 608 <td class="number">', locale_number_format($OnOrder, $DecimalPlaces), '</td> 609 <td class="number">', locale_number_format($Available, $DecimalPlaces), '</td> 610 <td><input class="number" ', ($i == 0 ? 'autofocus="autofocus"' : ''), ' tabindex="', ($j + 7), '" type="text" size="6" name="Quantity', $i, '" value="0" /> 611 <input type="hidden" name="StockID', $i, '" value="', $MyRow['stockid'], '" /> 612 </td> 613 </tr> 614 <input type="hidden" name="DecimalPlaces', $i, '" value="', $MyRow['decimalplaces'], '" /> 615 <input type="hidden" name="ItemDescription', $i, '" value="', $MyRow['description'], '" /> 616 <input type="hidden" name="Units', $i, '" value="', $MyRow['stockunits'], '" />'; 617 $i++; 618 } 619 #end of while loop 620 echo '</tbody> 621 <tfoot> 622 <tr> 623 <td><input type="hidden" name="PreviousList" value="', ($Offset - 1), '" /> 624 <input tabindex="', ($j + 7), '" type="submit" name="Previous" value="', _('Previous'), '" /></td> 625 <td class="centre" colspan="6"><input type="hidden" name="order_items" value="1" /> 626 <input tabindex="', ($j + 8), '" type="submit" value="', _('Add to Requisition'), '" /></td> 627 <td><input type="hidden" name="NextList" value="', ($Offset + 1), '" /> 628 <input tabindex="', ($j + 9), '" type="submit" name="Next" value="', _('Next'), '" /></td> 629 </tr> 630 </tfoot> 631 </table> 632 </div> 633 </form>'; 634} #end if SearchResults to show 635//********************************************************************************************************* 636include ('includes/footer.php'); 637?> 638