1<?php 2/* Entry of point to point stock location transfers of a single part. */ 3 4include('includes/DefineSerialItems.php'); 5include('includes/DefineStockTransfers.php'); 6 7include('includes/session.php'); 8$Title = _('Stock Transfers');// Screen identification. 9$ViewTopic = "Inventory";// Filename's id in ManualContents.php's TOC. 10$BookMark = "LocationTransfers";// Anchor's id in the manual's html document. 11include('includes/header.php'); 12 13include('includes/SQL_CommonFunctions.inc'); 14 15if(isset($_GET['New'])) { 16 unset($_SESSION['Transfer']); 17} 18 19if(isset($_GET['From'])) { 20 $_POST['StockLocationFrom']=$_GET['From']; 21 $_POST['StockLocationTo']=$_GET['To']; 22 $_POST['Quantity']=$_GET['Quantity']; 23} 24 25if(isset($_POST['CheckCode'])) { 26 27 echo '<p class="page_title_text"><img alt="" src="', $RootPath, '/css/', $Theme, 28 '/images/magnifier.png" title="',// Icon image. 29 _('Dispatch'), '" /> ',// Icon title. 30 _('Select Item to Transfer'), '</p>';// Page title. 31 32 if(mb_strlen($_POST['StockText'])>0) { 33 $sql="SELECT stockid, 34 description 35 FROM stockmaster 36 WHERE description " . LIKE . " '%" . $_POST['StockText'] . "%'"; 37 } else { 38 $sql="SELECT stockid, 39 description 40 FROM stockmaster 41 WHERE stockid " . LIKE . " '%" . $_POST['StockCode']."%'"; 42 } 43 $ErrMsg=_('The stock information cannot be retrieved because'); 44 $DbgMsg=_('The SQL to get the stock description was'); 45 $result = DB_query($sql,$ErrMsg,$DbgMsg); 46 echo '<table class="selection"> 47 <thead> 48 <tr> 49 <th class="ascending">' . _('Stock Code') . '</th> 50 <th class="ascending">' . _('Stock Description') . '</th> 51 </tr> 52 </thead> 53 <tbody>'; 54 while($myrow = DB_fetch_array($result)) { 55 echo '<tr> 56 <td>' . $myrow['stockid'] . '</td> 57 <td>' . $myrow['description'] . '</td> 58 <td><a href="' . $RootPath . '/StockTransfers.php?StockID='.$myrow['stockid'].'&Description='.$myrow['description'].'&NewTransfer=Yes&Quantity='. filter_number_format($_POST['Quantity']).'&From='.$_POST['StockLocationFrom'].'&To='.$_POST['StockLocationTo'].'">' 59 ._('Transfer') . '</a></td> 60 </tr>'; 61 62 } 63 echo '</tbody></table>'; 64 include('includes/footer.php'); 65 exit; 66} 67 68$NewTransfer = false; /*initialise this first then determine from form inputs */ 69 70if(isset($_GET['NewTransfer'])) { 71 unset($_SESSION['Transfer']); 72 unset($_SESSION['TransferItem']); /*this is defined in bulk transfers but needs to be unset for individual transfers */ 73 $NewTransfer=$_GET['NewTransfer']; 74} 75 76 77if(isset($_GET['StockID'])) { /*carry the stockid through to the form for additional inputs */ 78 $_POST['StockID'] = trim(mb_strtoupper($_GET['StockID'])); 79} elseif(isset($_POST['StockID'])) { /* initiate a new transfer only if the StockID is different to the previous entry */ 80 if(isset($_SESSION['Transfer']->TransferItem[0])) { 81 if($_POST['StockID'] != $_SESSION['Transfer']->TransferItem[0]->StockID) { 82 unset($_SESSION['Transfer']); 83 $NewTransfer = true; 84 } 85 } else { /* _SESSION['Transfer']->TransferItem[0] is not set so */ 86 $NewTransfer = true; 87 } 88} 89 90if($NewTransfer) { 91 92 if(!isset($_POST['StockLocationFrom'])) { 93 $_POST['StockLocationFrom']=''; 94 $StockLocationFromAccount = ''; 95 } 96 else 97 { 98 $SQL = "SELECT glaccountcode 99 FROM locations 100 INNER JOIN locationusers 101 ON locationusers.loccode=locations.loccode AND locationusers.userid='" . $_SESSION['UserID'] . "' AND locationusers.canupd=1 102 WHERE locations.loccode = '" . $_POST['StockLocationFrom'] . "'"; 103 $Result = DB_query($SQL); 104 $myrow = DB_fetch_array($Result); 105 { 106 $StockLocationFromAccount = $myrow['glaccountcode']; 107 } 108 } 109 if(!isset($_POST['StockLocationTo'])) { 110 $_POST['StockLocationTo']=''; 111 $StockLocationToAccount = ''; 112 } 113 else 114 { 115 $SQL = "SELECT glaccountcode 116 FROM locations 117 INNER JOIN locationusers 118 ON locationusers.loccode=locations.loccode AND locationusers.userid='" . $_SESSION['UserID'] . "' AND locationusers.canupd=1 119 WHERE locations.loccode = '" . $_POST['StockLocationTo'] . "'"; 120 $Result = DB_query($SQL); 121 $myrow = DB_fetch_array($Result); 122 { 123 $StockLocationToAccount = $myrow['glaccountcode']; 124 } 125 126 $_SESSION['Transfer']->StockLocationTo = $_POST['StockLocationTo']; 127 } 128 129 $_SESSION['Transfer']= new StockTransfer(0, 130 $_POST['StockLocationFrom'], 131 '', 132 $StockLocationFromAccount, 133 $_POST['StockLocationTo'], 134 '', 135 $StockLocationToAccount, 136 Date($_SESSION['DefaultDateFormat']) 137 ); 138 $result = DB_query("SELECT description, 139 units, 140 mbflag, 141 materialcost+labourcost+overheadcost as standardcost, 142 controlled, 143 serialised, 144 perishable, 145 decimalplaces 146 FROM stockmaster 147 WHERE stockid='" . trim(mb_strtoupper($_POST['StockID'])) . "'"); 148 149 if(DB_num_rows($result) == 0) { 150 prnMsg( _('Unable to locate Stock Code').' '.mb_strtoupper($_POST['StockID']), 'error' ); 151 } elseif(DB_num_rows($result)>0) { 152 $myrow = DB_fetch_array($result); 153 $_SESSION['Transfer']->TransferItem[0] = new LineItem( trim(mb_strtoupper($_POST['StockID'])), 154 $myrow['description'], 155 filter_number_format($_POST['Quantity']), 156 $myrow['units'], 157 $myrow['controlled'], 158 $myrow['serialised'], 159 $myrow['perishable'], 160 $myrow['decimalplaces']); 161 162 163 $_SESSION['Transfer']->TransferItem[0]->StandardCost = $myrow['standardcost']; 164 165 if($myrow['mbflag']=='D' OR $myrow['mbflag']=='A' OR $myrow['mbflag']=='K') { 166 prnMsg(_('The part entered is either or a dummy part or an assembly or a kit-set part') . '. ' . _('These parts are not physical parts and no stock holding is maintained for them') . '. ' . _('Stock Transfers are therefore not possible'),'warn'); 167 echo '.<hr />'; 168 echo '<a href="' . $RootPath . '/StockTransfers.php?NewTransfer=Yes">' . _('Enter another Transfer') . '</a>'; 169 unset($_SESSION['Transfer']); 170 include('includes/footer.php'); 171 exit; 172 } 173 } 174} 175 176if(isset($_POST['Quantity']) 177 AND isset($_SESSION['Transfer']->TransferItem[0]->Controlled) 178 AND $_SESSION['Transfer']->TransferItem[0]->Controlled==0) { 179 180 $_SESSION['Transfer']->TransferItem[0]->Quantity = filter_number_format($_POST['Quantity']); 181 182} 183 184if(isset($_POST['StockLocationFrom']) 185 AND $_POST['StockLocationFrom'] != $_SESSION['Transfer']->StockLocationFrom ) { 186 187 $SQL = "SELECT glaccountcode 188 FROM locations 189 INNER JOIN locationusers 190 ON locationusers.loccode=locations.loccode AND locationusers.userid='" . $_SESSION['UserID'] . "' AND locationusers.canupd=1 191 WHERE locations.loccode = '" . $_POST['StockLocationFrom'] . "'"; 192 $Result = DB_query($SQL); 193 $myrow = DB_fetch_array($Result); 194 { 195 $_SESSION['Transfer']->StockLocationFromAccount = $myrow['glaccountcode']; 196 } 197 198 $_SESSION['Transfer']->StockLocationFrom = $_POST['StockLocationFrom']; 199 $_SESSION['Transfer']->StockLocationTo = $_POST['StockLocationTo']; 200 $_SESSION['Transfer']->TransferItem[0]->Quantity=filter_number_format($_POST['Quantity']); 201 $_SESSION['Transfer']->TransferItem[0]->SerialItems=array(); 202} 203 204if(isset($_POST['StockLocationTo']) 205 AND $_POST['StockLocationTo'] != $_SESSION['Transfer']->StockLocationTo) { 206 207 $SQL = "SELECT glaccountcode 208 FROM locations 209 INNER JOIN locationusers 210 ON locationusers.loccode=locations.loccode AND locationusers.userid='" . $_SESSION['UserID'] . "' AND locationusers.canupd=1 211 WHERE locations.loccode = '" . $_POST['StockLocationTo'] . "'"; 212 $Result = DB_query($SQL); 213 $myrow = DB_fetch_array($Result); 214 { 215 $_SESSION['Transfer']->StockLocationToAccount = $myrow['glaccountcode']; 216 } 217 218 $_SESSION['Transfer']->StockLocationTo = $_POST['StockLocationTo']; 219} 220 221if(isset($_POST['EnterTransfer']) ) { 222 223 $result = DB_query("SELECT * FROM stockmaster WHERE stockid='" . $_SESSION['Transfer']->TransferItem[0]->StockID ."'"); 224 $myrow = DB_fetch_row($result); 225 $InputError = false; 226 if(DB_num_rows($result)==0) { 227 echo '<br />'; 228 prnMsg(_('The entered item code does not exist'), 'error'); 229 $InputError = true; 230 } elseif(!is_numeric($_SESSION['Transfer']->TransferItem[0]->Quantity)) { 231 echo '<br />'; 232 prnMsg( _('The quantity entered must be numeric'), 'error' ); 233 $InputError = true; 234 } elseif($_SESSION['Transfer']->TransferItem[0]->Quantity <= 0) { 235 echo '<br />'; 236 prnMsg( _('The quantity entered must be a positive number greater than zero'), 'error'); 237 $InputError = true; 238 } 239 if($_SESSION['Transfer']->StockLocationFrom==$_SESSION['Transfer']->StockLocationTo) { 240 echo '<br />'; 241 prnMsg( _('The locations to transfer from and to must be different'), 'error'); 242 $InputError = true; 243 } 244 245 if($InputError==False) { 246/*All inputs must be sensible so make the stock movement records and update the locations stocks */ 247 248 $TransferNumber = GetNextTransNo(16); 249 $PeriodNo = GetPeriod(Date($_SESSION['DefaultDateFormat'])); 250 $SQLTransferDate = FormatDateForSQL(Date($_SESSION['DefaultDateFormat'])); 251 252 $Result = DB_Txn_Begin(); 253 254 // Need to get the current location quantity will need it later for the stock movement 255 $SQL="SELECT locstock.quantity 256 FROM locstock 257 WHERE locstock.stockid='" . $_SESSION['Transfer']->TransferItem[0]->StockID . "' 258 AND loccode= '" . $_SESSION['Transfer']->StockLocationFrom . "'"; 259 260 $ErrMsg = _('Could not retrieve the QOH at the sending location because'); 261 $DbgMsg = _('The SQL that failed was'); 262 $Result = DB_query($SQL, $ErrMsg, $DbgMsg, true); 263 264 if(DB_num_rows($Result)==1) { 265 $LocQtyRow = DB_fetch_row($Result); 266 $QtyOnHandPrior = $LocQtyRow[0]; 267 } else { 268 // There must actually be some error this should never happen 269 $QtyOnHandPrior = 0; 270 } 271 if($_SESSION['ProhibitNegativeStock']==1 272 AND $QtyOnHandPrior<$_SESSION['Transfer']->TransferItem[0]->Quantity) { 273 prnMsg( _('There is insufficient stock to make this transfer and webERP is setup to prevent negative stock'), 'warn'); 274 include('includes/footer.php'); 275 exit; 276 } 277 // Insert outgoing inventory GL transaction if any of the locations has a GL account code: 278 if(($_SESSION['Transfer']->StockLocationFromAccount !='' OR $_SESSION['Transfer']->StockLocationToAccount !='') AND 279 ($_SESSION['Transfer']->StockLocationFromAccount != $_SESSION['Transfer']->StockLocationToAccount)) { 280 // Get the account code: 281 if($_SESSION['Transfer']->StockLocationFromAccount !='') { 282 $AccountCode = $_SESSION['Transfer']->StockLocationFromAccount; 283 } else { 284 $StockGLCode = GetStockGLCode($_SESSION['Transfer']->TransferItem[0]->StockID);// Get Category's account codes. 285 $AccountCode = $StockGLCode['stockact'];// Select account code for stock. 286 } 287 // Get the item cost: 288 $SQLstandardcost = "SELECT stockmaster.materialcost + stockmaster.labourcost + stockmaster.overheadcost AS standardcost 289 FROM stockmaster 290 WHERE stockmaster.stockid ='" . $_SESSION['Transfer']->TransferItem[0]->StockID . "'"; 291 $ErrMsg = _('The standard cost of the item cannot be retrieved because'); 292 $DbgMsg = _('The SQL that failed was'); 293 $ResultStandardCost = DB_query($SQLstandardcost,$ErrMsg,$DbgMsg); 294 $myrow = DB_fetch_array($ResultStandardCost); 295 $StandardCost = $myrow['standardcost'];// QUESTION: Standard cost for: Assembly (value="A") and Manufactured (value="M") items ? 296 // Insert record: 297 $SQL = "INSERT INTO gltrans ( 298 periodno, 299 trandate, 300 type, 301 typeno, 302 account, 303 narrative, 304 amount) 305 VALUES ('" . 306 $PeriodNo . "','" . 307 $SQLTransferDate . "', 308 16,'" . 309 $TransferNumber . "','" . 310 $AccountCode . "','" . 311 $_SESSION['Transfer']->StockLocationFrom.' - '.$_SESSION['Transfer']->TransferItem[0]->StockID.' x '.$_SESSION['Transfer']->TransferItem[0]->Quantity.' @ '. $StandardCost . "','" . 312 -$_SESSION['Transfer']->TransferItem[0]->Quantity * $StandardCost . "')"; 313 $ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The outgoing inventory GL transacction record could not be inserted because'); 314 $DbgMsg = _('The following SQL to insert records was used'); 315 $Result = DB_query($SQL, $ErrMsg, $DbgMsg, true); 316 } 317 // Insert the stock movement for the stock going out of the from location 318 $SQL = "INSERT INTO stockmoves(stockid, 319 type, 320 transno, 321 loccode, 322 trandate, 323 userid, 324 prd, 325 reference, 326 qty, 327 newqoh) 328 VALUES ( 329 '" . $_SESSION['Transfer']->TransferItem[0]->StockID . "', 330 16, 331 '" . $TransferNumber . "', 332 '" . $_SESSION['Transfer']->StockLocationFrom . "', 333 '" . $SQLTransferDate . "', 334 '" . $_SESSION['UserID'] . "', 335 '" . $PeriodNo . "', 336 'To " . $_SESSION['Transfer']->StockLocationTo ."', 337 '" . round(-$_SESSION['Transfer']->TransferItem[0]->Quantity,$_SESSION['Transfer']->TransferItem[0]->DecimalPlaces) . "', 338 '" . ($QtyOnHandPrior - round($_SESSION['Transfer']->TransferItem[0]->Quantity,$_SESSION['Transfer']->TransferItem[0]->DecimalPlaces)) . "' 339 )"; 340 341 $ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The stock movement record cannot be inserted because'); 342 $DbgMsg = _('The following SQL to insert the stock movement record was used'); 343 $Result = DB_query($SQL,$ErrMsg,$DbgMsg,true); 344 345 /*Get the ID of the StockMove... */ 346 $StkMoveNo = DB_Last_Insert_ID('stockmoves','stkmoveno'); 347 348/*Insert the StockSerialMovements and update the StockSerialItems for controlled items*/ 349 350 if($_SESSION['Transfer']->TransferItem[0]->Controlled ==1) { 351 foreach($_SESSION['Transfer']->TransferItem[0]->SerialItems as $Item) { 352 /*We need to add or update the StockSerialItem record and 353 The StockSerialMoves as well */ 354 355 /*First need to check if the serial items already exists or not in the location from */ 356 $SQL = "SELECT COUNT(*) 357 FROM stockserialitems 358 WHERE 359 stockid='" . $_SESSION['Transfer']->TransferItem[0]->StockID . "' 360 AND loccode='" . $_SESSION['Transfer']->StockLocationFrom . "' 361 AND serialno='" . $Item->BundleRef . "'"; 362 363 $ErrMsg = _('The entered item code does not exist'); 364 $Result = DB_query($SQL,$ErrMsg); 365 $SerialItemExistsRow = DB_fetch_row($Result); 366 367 if($SerialItemExistsRow[0]==1) { 368 369 $SQL = "UPDATE stockserialitems 370 SET quantity= quantity - '" . $Item->BundleQty . "', 371 expirationdate='" . FormatDateForSQL($Item->ExpiryDate) . "' 372 WHERE stockid='" . $_SESSION['Transfer']->TransferItem[0]->StockID . "' 373 AND loccode='" . $_SESSION['Transfer']->StockLocationFrom . "' 374 AND serialno='" . $Item->BundleRef . "'"; 375 376 $ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The serial stock item record could not be updated because'); 377 $DbgMsg = _('The following SQL to update the serial stock item record was used'); 378 $Result = DB_query($SQL, $ErrMsg, $DbgMsg, true); 379 } else { 380 /*Need to insert a new serial item record */ 381 $SQL = "INSERT INTO stockserialitems (stockid, 382 loccode, 383 serialno, 384 expirationdate, 385 quantity) 386 VALUES ('" . $_SESSION['Transfer']->TransferItem[0]->StockID . "', 387 '" . $_SESSION['Transfer']->StockLocationFrom . "', 388 '" . $Item->BundleRef . "', 389 '" . FormatDateForSQL($Item->ExpiryDate) . "', 390 '" . -$Item->BundleQty . "')"; 391 392 $ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The serial stock item record could not be added because'); 393 $DbgMsg = _('The following SQL to insert the serial stock item record was used'); 394 $Result = DB_query($SQL, $ErrMsg, $DbgMsg, true); 395 } 396 397 398 /* now insert the serial stock movement */ 399 400 $SQL = "INSERT INTO stockserialmoves ( 401 stockmoveno, 402 stockid, 403 serialno, 404 moveqty) 405 VALUES ( 406 '" . $StkMoveNo . "', 407 '" . $_SESSION['Transfer']->TransferItem[0]->StockID . "', 408 '" . $Item->BundleRef . "', 409 '" . $Item->BundleQty . "' 410 )"; 411 412 $ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The serial stock movement record could not be inserted because'); 413 $DbgMsg = _('The following SQL to insert the serial stock movement records was used'); 414 $Result = DB_query($SQL, $ErrMsg, $DbgMsg, true); 415 416 }/* foreach controlled item in the serialitems array */ 417 } /*end if the transferred item is a controlled item */ 418 419 420 // Need to get the current location quantity will need it later for the stock movement 421 $SQL="SELECT locstock.quantity 422 FROM locstock 423 WHERE locstock.stockid='" . $_SESSION['Transfer']->TransferItem[0]->StockID . "' 424 AND loccode= '" . $_SESSION['Transfer']->StockLocationTo . "'"; 425 $ErrMsg = _('Could not retrieve QOH at the destination because'); 426 $Result = DB_query($SQL, $ErrMsg, $DbgMsg,true); 427 if(DB_num_rows($Result)==1) { 428 $LocQtyRow = DB_fetch_row($Result); 429 $QtyOnHandPrior = $LocQtyRow[0]; 430 } else { 431 // There must actually be some error this should never happen 432 $QtyOnHandPrior = 0; 433 } 434 // Insert incoming inventory GL transaction if any of the locations has a GL account code: 435 if(($_SESSION['Transfer']->StockLocationFromAccount !='' OR $_SESSION['Transfer']->StockLocationToAccount !='') AND 436 ($_SESSION['Transfer']->StockLocationFromAccount != $_SESSION['Transfer']->StockLocationToAccount)) { 437 // Get the account code: 438 if($_SESSION['Transfer']->StockLocationToAccount !='') { 439 $AccountCode = $_SESSION['Transfer']->StockLocationToAccount; 440 } else { 441 $StockGLCode = GetStockGLCode($_SESSION['Transfer']->TransferItem[0]->StockID);// Get Category's account codes. 442 $AccountCode = $StockGLCode['stockact'];// Select account code for stock. 443 } 444 // Get the item cost: 445 $SQLstandardcost = "SELECT stockmaster.materialcost + stockmaster.labourcost + stockmaster.overheadcost AS standardcost 446 FROM stockmaster 447 WHERE stockmaster.stockid ='" . $_SESSION['Transfer']->TransferItem[0]->StockID . "'"; 448 $ErrMsg = _('The standard cost of the item cannot be retrieved because'); 449 $DbgMsg = _('The SQL that failed was'); 450 $ResultStandardCost = DB_query($SQLstandardcost,$ErrMsg,$DbgMsg); 451 $myrow = DB_fetch_array($ResultStandardCost); 452 $StandardCost = $myrow['standardcost'];// QUESTION: Standard cost for: Assembly (value="A") and Manufactured (value="M") items ? 453 // Insert record: 454 $SQL = "INSERT INTO gltrans ( 455 periodno, 456 trandate, 457 type, 458 typeno, 459 account, 460 narrative, 461 amount) 462 VALUES ('" . 463 $PeriodNo . "','" . 464 $SQLTransferDate . "', 465 16,'" . 466 $TransferNumber . "','" . 467 $AccountCode . "','" . 468 $_SESSION['Transfer']->StockLocationTo.' - '.$_SESSION['Transfer']->TransferItem[0]->StockID.' x '.$_SESSION['Transfer']->TransferItem[0]->Quantity.' @ '. $StandardCost . "','" . 469 $_SESSION['Transfer']->TransferItem[0]->Quantity * $StandardCost . "')"; 470 $ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The incoming inventory GL transacction record could not be inserted because'); 471 $DbgMsg = _('The following SQL to insert records was used'); 472 $Result = DB_query($SQL, $ErrMsg, $DbgMsg, true); 473 } 474 // Insert the stock movement for the stock coming into the to location 475 $SQL = "INSERT INTO stockmoves (stockid, 476 type, 477 transno, 478 loccode, 479 trandate, 480 userid, 481 prd, 482 reference, 483 qty, 484 newqoh) 485 VALUES ('" . $_SESSION['Transfer']->TransferItem[0]->StockID . "', 486 16, 487 '" . $TransferNumber . "', 488 '" . $_SESSION['Transfer']->StockLocationTo . "', 489 '" . $SQLTransferDate . "', 490 '" . $_SESSION['UserID'] . "', 491 '" . $PeriodNo . "', 492 '" . _('From') . " " . $_SESSION['Transfer']->StockLocationFrom . "', 493 '" . $_SESSION['Transfer']->TransferItem[0]->Quantity . "', 494 '" . round($QtyOnHandPrior + $_SESSION['Transfer']->TransferItem[0]->Quantity,$_SESSION['Transfer']->TransferItem[0]->DecimalPlaces) . "')"; 495 496 $ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The stock movement record cannot be inserted because'); 497 $DbgMsg = _('The following SQL to insert the stock movement record was used'); 498 $Result = DB_query($SQL,$ErrMsg,$DbgMsg,true); 499 500 /*Get the ID of the StockMove... */ 501 $StkMoveNo = DB_Last_Insert_ID('stockmoves','stkmoveno'); 502 503/*Insert the StockSerialMovements and update the StockSerialItems for controlled items*/ 504 505 if($_SESSION['Transfer']->TransferItem[0]->Controlled ==1) { 506 foreach($_SESSION['Transfer']->TransferItem[0]->SerialItems as $Item) { 507 /*We need to add or update the StockSerialItem record and 508 The StockSerialMoves as well */ 509 510 /*First need to check if the serial items already exists or not in the location from */ 511 $SQL = "SELECT COUNT(*) 512 FROM stockserialitems 513 WHERE stockid='" . $_SESSION['Transfer']->TransferItem[0]->StockID . "' 514 AND loccode='" . $_SESSION['Transfer']->StockLocationTo . "' 515 AND serialno='" . $Item->BundleRef . "'"; 516 517 $ErrMsg = _('Could not determine if the serial item exists in the transfer to location'); 518 $Result = DB_query($SQL,$ErrMsg); 519 $SerialItemExistsRow = DB_fetch_row($Result); 520 521 if($SerialItemExistsRow[0]==1) { 522 523 $SQL = "UPDATE stockserialitems 524 SET quantity= quantity + '" . $Item->BundleQty . "', 525 expirationdate='" . FormatDateForSQL($Item->ExpiryDate) . "' 526 WHERE stockid='" . $_SESSION['Transfer']->TransferItem[0]->StockID . "' 527 AND loccode='" . $_SESSION['Transfer']->StockLocationTo . "' 528 AND serialno='" . $Item->BundleRef . "'"; 529 530 $ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The serial stock item record could not be updated because'); 531 $DbgMsg = _('The following SQL to update the serial stock item record was used'); 532 $Result = DB_query($SQL, $ErrMsg, $DbgMsg, true); 533 } else { 534 /*Need to insert a new serial item record */ 535 $SQL = "INSERT INTO stockserialitems (stockid, 536 loccode, 537 serialno, 538 expirationdate, 539 quantity, 540 qualitytext) 541 VALUES ('" . $_SESSION['Transfer']->TransferItem[0]->StockID . "', 542 '" . $_SESSION['Transfer']->StockLocationTo . "', 543 '" . $Item->BundleRef . "', 544 '" . FormatDateForSQL($Item->ExpiryDate) . "', 545 '" . $Item->BundleQty . "', 546 '')"; 547 548 $ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The serial stock item record could not be added because'); 549 $DbgMsg = _('The following SQL to insert the serial stock item record was used:'); 550 $Result = DB_query($SQL, $ErrMsg, $DbgMsg, true); 551 } 552 553 554 /* now insert the serial stock movement */ 555 556 $SQL = "INSERT INTO stockserialmoves (stockmoveno, 557 stockid, 558 serialno, 559 moveqty) 560 VALUES ('" . $StkMoveNo . "', 561 '" . $_SESSION['Transfer']->TransferItem[0]->StockID . "', 562 '" . $Item->BundleRef . "', 563 '" . $Item->BundleQty . "')"; 564 $ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The serial stock movement record could not be inserted because'); 565 $DbgMsg = _('The following SQL to insert the serial stock movement records was used'); 566 $Result = DB_query($SQL, $ErrMsg, $DbgMsg, true); 567 568 }/* foreach controlled item in the serialitems array */ 569 } /*end if the transfer item is a controlled item */ 570 571 572 $SQL = "UPDATE locstock SET quantity = quantity - '" . round($_SESSION['Transfer']->TransferItem[0]->Quantity,$_SESSION['Transfer']->TransferItem[0]->DecimalPlaces) . "' 573 WHERE stockid='" . $_SESSION['Transfer']->TransferItem[0]->StockID . "' 574 AND loccode='" . $_SESSION['Transfer']->StockLocationFrom . "'"; 575 576 $ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The location stock record could not be updated because'); 577 $DbgMsg = _('The following SQL to update the location stock record was used'); 578 $Result = DB_query($SQL,$ErrMsg,$DbgMsg,true); 579 580 $SQL = "UPDATE locstock 581 SET quantity = quantity + '" . round($_SESSION['Transfer']->TransferItem[0]->Quantity,$_SESSION['Transfer']->TransferItem[0]->DecimalPlaces) . "' 582 WHERE stockid='" . $_SESSION['Transfer']->TransferItem[0]->StockID . "' 583 AND loccode='" . $_SESSION['Transfer']->StockLocationTo . "'"; 584 585 $ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The location stock record could not be updated because'); 586 $DbgMsg = _('The following SQL to update the location stock record was used'); 587 $Result = DB_query($SQL,$ErrMsg, $DbgMsg, true); 588 589 $Result = DB_Txn_Commit(); 590 591 prnMsg(_('An inventory transfer of').' ' . $_SESSION['Transfer']->TransferItem[0]->StockID . ' - ' . $_SESSION['Transfer']->TransferItem[0]->ItemDescription . ' '. _('has been created from').' ' . $_SESSION['Transfer']->StockLocationFrom . ' '. _('to') . ' ' . $_SESSION['Transfer']->StockLocationTo . ' '._('for a quantity of').' ' . $_SESSION['Transfer']->TransferItem[0]->Quantity,'success'); 592 echo '<br /><a href="PDFStockTransfer.php?TransferNo='.$TransferNumber.'">' . _('Print Transfer Note') . '</a>'; 593 unset($_SESSION['Transfer']); 594 include('includes/footer.php'); 595 exit; 596 } 597 598} 599 600echo '<p class="page_title_text"> 601 <img src="'.$RootPath.'/css/'.$Theme.'/images/supplier.png" title="' . _('Dispatch') . '" alt="" />' . ' ' . $Title . ' 602 </p>'; 603 604echo '<form action="'. htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '" method="post">'; 605echo '<div>'; 606echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />'; 607 608if(!isset($_GET['Description'])) { 609 $_GET['Description']=''; 610} 611echo '<table class="selection"> 612 <tr> 613 <td>' . _('Stock Code'). ':</td> 614 <td>'; 615if(!isset($_POST['StockID'])) { 616 $_POST['StockID'] = ''; 617} 618 echo '<input type="text" title="'._('The stock ID should not be blank or contains illegal characters, you can choose left this blank and only keyin')._('Partial Stock Code')._('or')._('Partial Description')._('then push')._('Check Part').'" name="StockID" size="21" value="' . $_POST['StockID'] . '" maxlength="20" /></td></tr>'; 619 620echo '<tr><td>' . _('Partial Description'). ':</td> 621 <td><input type="text" name="StockText" title="'._('You can key in part of stock description or left this and ')._('Partial Stock Code')._('blank and click ')._('Check Part').' '._('to view the whole stock list').'" size="21" value="' . $_GET['Description'] .'" /></td> 622 <td>' . _('Partial Stock Code'). ':</td><td>'; 623if(isset($_POST['StockID'])) { 624 echo '<input type="text" title="'._('You can key in partial of the stock code or just left this blank to click').' '._('Check Part').'" name="StockCode" size="21" value="' . $_POST['StockID'] .'" maxlength="20" />'; 625} else { 626 echo '<input type="text" title="'._('You can key in partial of the stock code or just left this blank to click').' '._('Check Part').'" name="StockCode" size="21" value="" maxlength="20" />'; 627} 628echo '</td><td><input type="submit" name="CheckCode" value="'._('Check Part').'" /></td></tr>'; 629 630if(isset($_SESSION['Transfer']->TransferItem[0]->ItemDescription) 631 AND mb_strlen($_SESSION['Transfer']->TransferItem[0]->ItemDescription)>1) { 632 633 echo '<tr> 634 <td colspan="3"><font color="blue" size="3">' . $_SESSION['Transfer']->TransferItem[0]->ItemDescription . ' ('._('In Units of').' ' . $_SESSION['Transfer']->TransferItem[0]->PartUnit . ' )</font></td> 635 </tr>'; 636} 637 638echo '<tr> 639 <td>' . _('From Stock Location').':</td> 640 <td><select name="StockLocationFrom">'; 641 642$sql = "SELECT locations.loccode, locationname FROM locations INNER JOIN locationusers ON locationusers.loccode=locations.loccode AND locationusers.userid='" . $_SESSION['UserID'] . "' AND locationusers.canupd=1"; 643$resultStkLocs = DB_query($sql); 644while($myrow=DB_fetch_array($resultStkLocs)) { 645 if(isset($_SESSION['Transfer']->StockLocationFrom)) { 646 if($myrow['loccode'] == $_SESSION['Transfer']->StockLocationFrom) { 647 echo '<option selected="selected" value="' . $myrow['loccode'] . '">' . $myrow['locationname'] . '</option>'; 648 } else { 649 echo '<option value="' . $myrow['loccode'] . '">' . $myrow['locationname'] . '</option>'; 650 } 651 } elseif($myrow['loccode']==$_SESSION['UserStockLocation']) { 652 echo '<option selected="selected" value="' . $myrow['loccode'] . '">' . $myrow['locationname'] . '</option>'; 653 if(isset($_SESSION['Transfer'])) 654 $_SESSION['Transfer']->StockLocationFrom=$myrow['loccode']; 655 } else { 656 echo '<option value="' . $myrow['loccode'] . '">' . $myrow['locationname'] . '</option>'; 657 } 658} 659 660echo '</select></td> 661 </tr>'; 662 663echo '<tr> 664 <td>' . _('To Stock Location').': </td> 665 <td><select name="StockLocationTo"> '; 666 667DB_data_seek($resultStkLocs,0); 668 669while($myrow=DB_fetch_array($resultStkLocs)) { 670 if(isset($_SESSION['Transfer']) AND isset($_SESSION['Transfer']->StockLocationTo)) { 671 if($myrow['loccode'] == $_SESSION['Transfer']->StockLocationTo) { 672 echo '<option selected="selected" value="' . $myrow['loccode'] . '">' . $myrow['locationname'] . '</option>'; 673 } else { 674 echo '<option value="' . $myrow['loccode'] . '">' . $myrow['locationname'] . '</option>'; 675 } 676 } elseif($myrow['loccode']==$_SESSION['UserStockLocation'] AND isset($_SESSION['Transfer'])) { 677 echo '<option selected="selected" value="' . $myrow['loccode'] . '">' . $myrow['locationname'] . '</option>'; 678 if(isset($_SESSION['Transfer'])) 679 $_SESSION['Transfer']->StockLocationTo=$myrow['loccode']; 680 } else { 681 echo '<option value="' . $myrow['loccode'] . '">' . $myrow['locationname'] . '</option>'; 682 } 683} 684 685echo '</select></td></tr>'; 686 687echo '<tr> 688 <td>' . _('Transfer Quantity').':</td>'; 689 690if(isset($_SESSION['Transfer']->TransferItem[0]->Controlled) 691 AND $_SESSION['Transfer']->TransferItem[0]->Controlled==1) { 692 693 echo '<td class="number"><input type="hidden" name="Quantity" value="' . locale_number_format($_SESSION['Transfer']->TransferItem[0]->Quantity) . '" /><a href="' . $RootPath .'/StockTransferControlled.php?StockLocationFrom='.$_SESSION['Transfer']->StockLocationFrom.'">' . $_SESSION['Transfer']->TransferItem[0]->Quantity . '</a></td></tr>'; 694} elseif(isset($_SESSION['Transfer']->TransferItem[0]->Controlled)) { 695 echo '<td><input type="text" class="number" name="Quantity" title="'._('The transfer quantity cannot be zero').'" size="12" maxlength="12" value="' . locale_number_format($_SESSION['Transfer']->TransferItem[0]->Quantity) . '" /></td></tr>'; 696} else { 697 echo '<td><input type="text" class="number" title="'._('The transfer quantity cannot be zer0').'" name="Quantity" size="12" maxlength="12" value="0" /></td> 698 </tr>'; 699} 700 701echo '</table> 702 <div class="centre"> 703 <br /> 704 <input type="submit" name="EnterTransfer" value="' . _('Enter Stock Transfer') . '" /> 705 <br />'; 706 707if(empty($_SESSION['Transfer']->TransferItem[0]->StockID) and isset($_POST['StockID'])) { 708 $StockID=$_POST['StockID']; 709} elseif(isset($_SESSION['Transfer']->TransferItem[0]->StockID)) { 710 $StockID=$_SESSION['Transfer']->TransferItem[0]->StockID; 711} else { 712 $StockID=''; 713} 714if(isset($_SESSION['Transfer'])) { 715 echo '<br /> 716 <a href="'.$RootPath.'/StockStatus.php?StockID=' . $StockID . '">' . _('Show Stock Status') . '</a>'; 717 echo '<br /> 718 <a href="'.$RootPath.'/StockMovements.php?StockID=' . $StockID . '">' . _('Show Movements') . '</a>'; 719 echo '<br /> 720 <a href="'.$RootPath.'/StockUsage.php?StockID=' . $StockID . '&StockLocation=' . $_SESSION['Transfer']->StockLocationFrom . '">' . _('Show Stock Usage') . '</a>'; 721 echo '<br /> 722 <a href="'.$RootPath.'/SelectSalesOrder.php?SelectedStockItem=' . $StockID . '&StockLocation=' . $_SESSION['Transfer']->StockLocationFrom . '">' . _('Search Outstanding Sales Orders') . '</a>'; 723 echo '<br /> 724 <a href="'.$RootPath.'/SelectCompletedOrder.php?SelectedStockItem=' . $StockID . '">' . _('Search Completed Sales Orders') . '</a>'; 725} 726echo '</div> 727 </div> 728 </form>'; 729include('includes/footer.php'); 730?>