diff --git a/Stocks.php b/Stocks.php
index c136a2c8e..459e15a20 100644
--- a/Stocks.php
+++ b/Stocks.php
@@ -1,127 +1,123 @@
'" . $StockID . "' ORDER BY stockid ASC LIMIT 1");
// Only change the StockID if we find a row.
// If not, the StockID is 'clobbered' with null and causes form havoc.
- if ( DB_num_rows( $Result ) > 0 ) {
- $NextItemRow = DB_fetch_row($Result);
- $StockID = $NextItemRow[0];
- }
- else {
+ if (DB_num_rows($Result) > 0) {
+ $NextItemRow = DB_fetch_row($Result);
+ $StockID = $NextItemRow[0];
+ } else {
$hasNext = false;
}
foreach ($ItemDescriptionLanguagesArray as $LanguageId) {
- unset($_POST['Description_' . str_replace('.','_',$LanguageId)]);
+ unset($_POST['Description_' . str_replace('.', '_', $LanguageId) ]);
}
}
-if (isset($_POST['PreviousItem'])){
+if (isset($_POST['PreviousItem'])) {
$Result = DB_query("SELECT stockid FROM stockmaster WHERE stockid<'" . $StockID . "' ORDER BY stockid DESC LIMIT 1");
// Only change the StockID if we find a row.
// If not, the StockID is 'clobbered' with null and causes form havoc.
- if ( DB_num_rows( $Result ) > 0 ) {
- $PreviousItemRow = DB_fetch_row($Result);
- $StockID = $PreviousItemRow[0];
- }
- else {
+ if (DB_num_rows($Result) > 0) {
+ $PreviousItemRow = DB_fetch_row($Result);
+ $StockID = $PreviousItemRow[0];
+ } else {
$hasPrev = false;
}
foreach ($ItemDescriptionLanguagesArray as $LanguageId) {
- unset($_POST['Description_' . str_replace('.','_',$LanguageId)]);
+ unset($_POST['Description_' . str_replace('.', '_', $LanguageId) ]);
}
}
-if (isset($StockID) AND !isset($_POST['UpdateCategories'])) {
- $sql = "SELECT COUNT(stockid)
+if (isset($StockID) and !isset($_POST['UpdateCategories'])) {
+ $SQL = "SELECT COUNT(stockid)
FROM stockmaster
- WHERE stockid='".$StockID."'
+ WHERE stockid='" . $StockID . "'
GROUP BY stockid";
- $result = DB_query($sql);
- $myrow = DB_fetch_row($result);
- if ($myrow[0]==0) {
- $New=1;
+ $Result = DB_query($SQL);
+ $MyRow = DB_fetch_row($Result);
+ if ($MyRow[0] == 0) {
+ $New = 1;
} else {
- $New=0;
+ $New = 0;
}
}
if (isset($_POST['New'])) {
- $New=$_POST['New'];
+ $New = $_POST['New'];
}
echo '' . _('Back to Items') . '
-
',
- '
', // Icon title. - $Title, '
';// Page title. +', // Icon title. +$Title, '
'; // Page title. +$SupportedImgExt = array('png', 'jpg', 'jpeg'); -$SupportedImgExt = array('png','jpg','jpeg'); - -if (isset($_FILES['ItemPicture']) AND $_FILES['ItemPicture']['name'] !='') { +if (isset($_FILES['ItemPicture']) and $_FILES['ItemPicture']['name'] != '') { $ImgExt = pathinfo($_FILES['ItemPicture']['name'], PATHINFO_EXTENSION); - $result = $_FILES['ItemPicture']['error']; - $UploadTheFile = 'Yes'; //Assume all is well to start off with + $Result = $_FILES['ItemPicture']['error']; + $UploadTheFile = 'Yes'; //Assume all is well to start off with $filename = $_SESSION['part_pics_dir'] . '/' . $StockID . '.' . $ImgExt; - //But check for the worst - if (!in_array ($ImgExt, $SupportedImgExt)) { - prnMsg(_('Only ' . implode(", ", $SupportedImgExt) . ' files are supported - a file extension of ' . implode(", ", $SupportedImgExt) . ' is expected'),'warn'); - $UploadTheFile ='No'; - } elseif ( $_FILES['ItemPicture']['size'] > ($_SESSION['MaxImageSize']*1024)) { //File Size Check - prnMsg(_('The file size is over the maximum allowed. The maximum size allowed in KB is') . ' ' . $_SESSION['MaxImageSize'],'warn'); - $UploadTheFile ='No'; - } elseif ( $_FILES['ItemPicture']['type'] == 'text/plain' ) { //File Type Check - prnMsg( _('Only graphics files can be uploaded'),'warn'); - $UploadTheFile ='No'; - } elseif ( $_FILES['ItemPicture']['error'] == 6 ) { //upload temp directory check - prnMsg( _('No tmp directory set. You must have a tmp directory set in your PHP for upload of files. '),'warn'); - $UploadTheFile ='No'; + //But check for the worst + if (!in_array($ImgExt, $SupportedImgExt)) { + prnMsg(_('Only ' . implode(", ", $SupportedImgExt) . ' files are supported - a file extension of ' . implode(", ", $SupportedImgExt) . ' is expected'), 'warn'); + $UploadTheFile = 'No'; + } elseif ($_FILES['ItemPicture']['size'] > ($_SESSION['MaxImageSize'] * 1024)) { //File Size Check + prnMsg(_('The file size is over the maximum allowed. The maximum size allowed in KB is') . ' ' . $_SESSION['MaxImageSize'], 'warn'); + $UploadTheFile = 'No'; + } elseif ($_FILES['ItemPicture']['type'] == 'text/plain') { //File Type Check + prnMsg(_('Only graphics files can be uploaded'), 'warn'); + $UploadTheFile = 'No'; + } elseif ($_FILES['ItemPicture']['error'] == 6) { //upload temp directory check + prnMsg(_('No tmp directory set. You must have a tmp directory set in your PHP for upload of files. '), 'warn'); + $UploadTheFile = 'No'; + } elseif (!is_writable($_SESSION['part_pics_dir'])) { + prnMsg(_('The web server user does not have permission to upload files. Please speak to your system administrator'), 'warn'); + $UploadTheFile = 'No'; } foreach ($SupportedImgExt as $ext) { $file = $_SESSION['part_pics_dir'] . '/' . $StockID . '.' . $ext; - if (file_exists ($file) ) { - $result = unlink($file); - if (!$result){ - prnMsg(_('The existing image could not be removed'),'error'); - $UploadTheFile ='No'; + if (file_exists($file)) { + $Result = unlink($file); + if (!$Result) { + prnMsg(_('The existing image could not be removed'), 'error'); + $UploadTheFile = 'No'; } } } - if ($UploadTheFile=='Yes'){ - $result = move_uploaded_file($_FILES['ItemPicture']['tmp_name'], $filename); - $message = ($result)?_('File url') . '' . $filename . '' : _('Something is wrong with uploading a file'); + if ($UploadTheFile == 'Yes') { + $Result = move_uploaded_file($_FILES['ItemPicture']['tmp_name'], $filename); + $message = ($Result) ? _('File url') . '' . $filename . '' : _('Something is wrong with uploading a file'); } } @@ -134,157 +130,151 @@ if (isset($_POST['submit'])) { //initialise no input errors assumed initially before we test - /* actions to take once the user has clicked the submit button - ie the page has called itself with some user input */ + ie the page has called itself with some user input */ //first off validate inputs sensible - $i=1; - + $i = 1; - if (!isset($_POST['Description']) OR mb_strlen($_POST['Description']) > 50 OR mb_strlen($_POST['Description'])==0) { + if (!isset($_POST['Description']) or mb_strlen($_POST['Description']) > 50 or mb_strlen($_POST['Description']) == 0) { $InputError = 1; - prnMsg (_('The stock item description must be entered and be fifty characters or less long') . '. ' . _('It cannot be a zero length string either') . ' - ' . _('a description is required'),'error'); + prnMsg(_('The stock item description must be entered and be fifty characters or less long') . '. ' . _('It cannot be a zero length string either') . ' - ' . _('a description is required'), 'error'); $Errors[$i] = 'Description'; $i++; } - if (mb_strlen($_POST['LongDescription'])==0) { + if (mb_strlen($_POST['LongDescription']) == 0) { $InputError = 1; - prnMsg (_('The stock item description cannot be a zero length string') . ' - ' . _('a long description is required'),'error'); + prnMsg(_('The stock item description cannot be a zero length string') . ' - ' . _('a long description is required'), 'error'); $Errors[$i] = 'LongDescription'; $i++; } - if (mb_strlen($StockID) ==0) { + if (mb_strlen($StockID) == 0) { $InputError = 1; - prnMsg (_('The Stock Item code cannot be empty'),'error'); + prnMsg(_('The Stock Item code cannot be empty'), 'error'); $Errors[$i] = 'StockID'; $i++; } - if (ContainsIllegalCharacters($StockID) OR mb_strpos($StockID,' ')) { + if (ContainsIllegalCharacters($StockID) or mb_strpos($StockID, ' ')) { $InputError = 1; - prnMsg(_('The stock item code cannot contain any of the following characters') . " - ' & + \" \\ ." . _('or a space'),'error'); + prnMsg(_('The stock item code cannot contain any of the following characters') . " - ' & + \" \\ ." . _('or a space'), 'error'); $Errors[$i] = 'StockID'; $i++; - $StockID=''; + $StockID = ''; } - if (mb_strlen($_POST['Units']) >20) { + if (mb_strlen($_POST['Units']) > 20) { $InputError = 1; - prnMsg(_('The unit of measure must be 20 characters or less long'),'error'); + prnMsg(_('The unit of measure must be 20 characters or less long'), 'error'); $Errors[$i] = 'Units'; $i++; } - if (mb_strlen($_POST['BarCode']) >20) { + if (mb_strlen($_POST['BarCode']) > 20) { $InputError = 1; - prnMsg(_('The barcode must be 20 characters or less long'),'error'); + prnMsg(_('The barcode must be 20 characters or less long'), 'error'); $Errors[$i] = 'BarCode'; $i++; } if (!is_numeric(filter_number_format($_POST['Volume']))) { $InputError = 1; - prnMsg (_('The volume of the packaged item in cubic metres must be numeric') ,'error'); + prnMsg(_('The volume of the packaged item in cubic metres must be numeric'), 'error'); $Errors[$i] = 'Volume'; $i++; } - if (filter_number_format($_POST['Volume']) <0) { + if (filter_number_format($_POST['Volume']) < 0) { $InputError = 1; - prnMsg(_('The volume of the packaged item must be a positive number'),'error'); + prnMsg(_('The volume of the packaged item must be a positive number'), 'error'); $Errors[$i] = 'Volume'; $i++; } if (!is_numeric(filter_number_format($_POST['GrossWeight']))) { $InputError = 1; - prnMsg(_('The weight of the packaged item in Gross Weight must be numeric'),'error'); + prnMsg(_('The weight of the packaged item in Gross Weight must be numeric'), 'error'); $Errors[$i] = 'GrossWeight'; $i++; } - if (filter_number_format($_POST['GrossWeight'])<0) { + if (filter_number_format($_POST['GrossWeight']) < 0) { $InputError = 1; - prnMsg(_('The weight of the packaged item must be a positive number'),'error'); + prnMsg(_('The weight of the packaged item must be a positive number'), 'error'); $Errors[$i] = 'GrossWeight'; $i++; } if (!is_numeric(filter_number_format($_POST['NetWeight']))) { $InputError = 1; - prnMsg(_('The net weight of the item in Net Weight must be numeric'),'error'); + prnMsg(_('The net weight of the item in Net Weight must be numeric'), 'error'); $Errors[$i] = 'NetWeight'; $i++; } - if (filter_number_format($_POST['NetWeight'])<0) { + if (filter_number_format($_POST['NetWeight']) < 0) { $InputError = 1; - prnMsg(_('The net weight of the item must be a positive number'),'error'); + prnMsg(_('The net weight of the item must be a positive number'), 'error'); $Errors[$i] = 'NetWeight'; $i++; } if (!is_numeric(filter_number_format($_POST['EOQ']))) { $InputError = 1; - prnMsg(_('The economic order quantity must be numeric'),'error'); + prnMsg(_('The economic order quantity must be numeric'), 'error'); $Errors[$i] = 'EOQ'; $i++; } - if (filter_number_format($_POST['EOQ']) <0) { + if (filter_number_format($_POST['EOQ']) < 0) { $InputError = 1; - prnMsg (_('The economic order quantity must be a positive number'),'error'); + prnMsg(_('The economic order quantity must be a positive number'), 'error'); $Errors[$i] = 'EOQ'; $i++; } - if ($_POST['Controlled']==0 AND $_POST['Serialised']==1){ + if ($_POST['Controlled'] == 0 and $_POST['Serialised'] == 1) { $InputError = 1; - prnMsg(_('The item can only be serialised if there is lot control enabled already') . '. ' . _('Batch control') . ' - ' . _('with any number of items in a lot/bundle/roll is enabled when controlled is enabled') . '. ' . _('Serialised control requires that only one item is in the batch') . '. ' . _('For serialised control') . ', ' . _('both controlled and serialised must be enabled'),'error'); + prnMsg(_('The item can only be serialised if there is lot control enabled already') . '. ' . _('Batch control') . ' - ' . _('with any number of items in a lot/bundle/roll is enabled when controlled is enabled') . '. ' . _('Serialised control requires that only one item is in the batch') . '. ' . _('For serialised control') . ', ' . _('both controlled and serialised must be enabled'), 'error'); $Errors[$i] = 'Serialised'; $i++; } - if ($_POST['NextSerialNo']!=0 AND $_POST['Serialised']==0){ + if ($_POST['NextSerialNo'] != 0 and $_POST['Serialised'] == 0) { $InputError = 1; - prnMsg(_('The item can only have automatically generated serial numbers if it is a serialised item'),'error'); + prnMsg(_('The item can only have automatically generated serial numbers if it is a serialised item'), 'error'); $Errors[$i] = 'NextSerialNo'; $i++; } - if ($_POST['NextSerialNo']!=0 AND $_POST['MBFlag']!='M'){ + if ($_POST['NextSerialNo'] != 0 and $_POST['MBFlag'] != 'M') { $InputError = 1; - prnMsg(_('The item can only have automatically generated serial numbers if it is a manufactured item'),'error'); + prnMsg(_('The item can only have automatically generated serial numbers if it is a manufactured item'), 'error'); $Errors[$i] = 'NextSerialNo'; $i++; } - if (($_POST['MBFlag']=='A' - OR $_POST['MBFlag']=='K' - OR $_POST['MBFlag']=='D' - OR $_POST['MBFlag']=='G') - AND $_POST['Controlled']==1){ + if (($_POST['MBFlag'] == 'A' or $_POST['MBFlag'] == 'K' or $_POST['MBFlag'] == 'D' or $_POST['MBFlag'] == 'G') and $_POST['Controlled'] == 1) { $InputError = 1; - prnMsg(_('Assembly/Kitset/Phantom/Service/Labour items cannot also be controlled items') . '. ' . _('Assemblies/Dummies/Phantom and Kitsets are not physical items and batch/serial control is therefore not appropriate'),'error'); + prnMsg(_('Assembly/Kitset/Phantom/Service/Labour items cannot also be controlled items') . '. ' . _('Assemblies/Dummies/Phantom and Kitsets are not physical items and batch/serial control is therefore not appropriate'), 'error'); $Errors[$i] = 'Controlled'; $i++; } - if (trim($_POST['CategoryID'])==''){ + if (trim($_POST['CategoryID']) == '') { $InputError = 1; - prnMsg(_('There are no inventory categories defined. All inventory items must belong to a valid inventory category,'),'error'); + prnMsg(_('There are no inventory categories defined. All inventory items must belong to a valid inventory category,'), 'error'); $Errors[$i] = 'CategoryID'; $i++; } if (!is_numeric(filter_number_format($_POST['Pansize']))) { $InputError = 1; - prnMsg(_('Pansize quantity must be numeric'),'error'); + prnMsg(_('Pansize quantity must be numeric'), 'error'); $Errors[$i] = 'Pansize'; $i++; } if (!is_numeric(filter_number_format($_POST['ShrinkFactor']))) { $InputError = 1; - prnMsg(_('Shrinkage factor quantity must be numeric'),'error'); + prnMsg(_('Shrinkage factor quantity must be numeric'), 'error'); $Errors[$i] = 'ShrinkFactor'; $i++; } - if ($InputError !=1){ - if ($_POST['Serialised']==1){ /*Not appropriate to have several dp on serial items */ - $_POST['DecimalPlaces']=0; + if ($InputError != 1) { + if ($_POST['Serialised'] == 1) { /*Not appropriate to have several dp on serial items */ + $_POST['DecimalPlaces'] = 0; } - if ($New==0) { /*so its an existing one */ + if ($New == 0) { /*so its an existing one */ /*first check on the changes being made we must disallow: - changes from manufactured or purchased to Service, Assembly or Kitset if there is stock - changes from manufactured, kitset or assembly where a BOM exists */ - $sql = "SELECT mbflag, + $SQL = "SELECT mbflag, controlled, serialised, materialcost+labourcost+overheadcost AS itemcost, @@ -295,144 +285,143 @@ FROM stockmaster INNER JOIN stockcategory ON stockmaster.categoryid=stockcategory.categoryid - WHERE stockid = '".$StockID."'"; - $MBFlagResult = DB_query($sql); - $myrow = DB_fetch_row($MBFlagResult); - $OldMBFlag = $myrow[0]; - $OldControlled = $myrow[1]; - $OldSerialised = $myrow[2]; - $UnitCost = $myrow[3]; - $OldStockAccount = $myrow[4]; - $OldWIPAccount = $myrow[5]; - $OldDescription = $myrow[6]; - $OldLongDescription = $myrow[7]; - - - $sql = "SELECT SUM(locstock.quantity) + WHERE stockid = '" . $StockID . "'"; + $MBFlagResult = DB_query($SQL); + $MyRow = DB_fetch_row($MBFlagResult); + $OldMBFlag = $MyRow[0]; + $OldControlled = $MyRow[1]; + $OldSerialised = $MyRow[2]; + $UnitCost = $MyRow[3]; + $OldStockAccount = $MyRow[4]; + $OldWIPAccount = $MyRow[5]; + $OldDescription = $MyRow[6]; + $OldLongDescription = $MyRow[7]; + + $SQL = "SELECT SUM(locstock.quantity) FROM locstock - WHERE stockid='".$StockID."' + WHERE stockid='" . $StockID . "' GROUP BY stockid"; - $result = DB_query($sql); - $StockQtyRow = DB_fetch_row($result); + $Result = DB_query($SQL); + $StockQtyRow = DB_fetch_row($Result); /*Now check the GL account of the new category to see if it is different to the old stock gl account */ - $result = DB_query("SELECT stockact, + $Result = DB_query("SELECT stockact, wipact FROM stockcategory WHERE categoryid='" . $_POST['CategoryID'] . "'"); - $NewStockActRow = DB_fetch_array($result); + $NewStockActRow = DB_fetch_array($Result); $NewStockAct = $NewStockActRow['stockact']; $NewWIPAct = $NewStockActRow['wipact']; - if ($OldMBFlag != $_POST['MBFlag']){ - if (($OldMBFlag == 'M' OR $OldMBFlag=='B') AND ($_POST['MBFlag']=='A' OR $_POST['MBFlag']=='K' OR $_POST['MBFlag']=='D' OR $_POST['MBFlag']=='G')){ /*then need to check that there is no stock holding first */ + if ($OldMBFlag != $_POST['MBFlag']) { + if (($OldMBFlag == 'M' or $OldMBFlag == 'B') and ($_POST['MBFlag'] == 'A' or $_POST['MBFlag'] == 'K' or $_POST['MBFlag'] == 'D' or $_POST['MBFlag'] == 'G')) { /*then need to check that there is no stock holding first */ /* stock holding OK for phantom (ghost) items */ - if ($StockQtyRow[0]!=0 AND $OldMBFlag!='G'){ - $InputError=1; - prnMsg( _('The make or buy flag cannot be changed from') . ' ' . $OldMBFlag . ' ' . _('to') . ' ' . $_POST['MBFlag'] . ' ' . _('where there is a quantity of stock on hand at any location') . '. ' . _('Currently there are') . ' ' . $StockQtyRow[0] . ' ' . _('on hand') , 'errror'); + if ($StockQtyRow[0] != 0 and $OldMBFlag != 'G') { + $InputError = 1; + prnMsg(_('The make or buy flag cannot be changed from') . ' ' . $OldMBFlag . ' ' . _('to') . ' ' . $_POST['MBFlag'] . ' ' . _('where there is a quantity of stock on hand at any location') . '. ' . _('Currently there are') . ' ' . $StockQtyRow[0] . ' ' . _('on hand'), 'errror'); } /* don't allow controlled/serialized */ - if ($_POST['Controlled']==1){ - $InputError=1; - prnMsg( _('The make or buy flag cannot be changed from') . ' ' . $OldMBFlag . ' ' . _('to') . ' ' . $_POST['MBFlag'] . ' ' . _('where the item is to be lot controlled') . '. ' . _('Kitset, phantom, dummy and assembly items cannot be lot controlled'), 'error'); + if ($_POST['Controlled'] == 1) { + $InputError = 1; + prnMsg(_('The make or buy flag cannot be changed from') . ' ' . $OldMBFlag . ' ' . _('to') . ' ' . $_POST['MBFlag'] . ' ' . _('where the item is to be lot controlled') . '. ' . _('Kitset, phantom, dummy and assembly items cannot be lot controlled'), 'error'); } } /*now check that if the item is being changed to a kitset, there are no items on sales orders or purchase orders*/ - if ($_POST['MBFlag']=='K') { - $sql = "SELECT quantity-qtyinvoiced + if ($_POST['MBFlag'] == 'K') { + $SQL = "SELECT quantity-qtyinvoiced FROM salesorderdetails - WHERE stkcode = '".$StockID."' + WHERE stkcode = '" . $StockID . "' AND completed=0"; - $result = DB_query($sql); - $ChkSalesOrds = DB_fetch_row($result); - if ($ChkSalesOrds[0]!=0){ + $Result = DB_query($SQL); + $ChkSalesOrds = DB_fetch_row($Result); + if ($ChkSalesOrds[0] != 0) { $InputError = 1; - prnMsg( _('The make or buy flag cannot be changed to a kitset where there is a quantity outstanding to be delivered on sales orders') . '. ' . _('Currently there are') .' ' . $ChkSalesOrds[0] . ' '. _('outstanding'), 'error'); + prnMsg(_('The make or buy flag cannot be changed to a kitset where there is a quantity outstanding to be delivered on sales orders') . '. ' . _('Currently there are') . ' ' . $ChkSalesOrds[0] . ' ' . _('outstanding'), 'error'); } } /*now check that if it is to be a kitset or assembly or dummy there is no quantity on purchase orders outstanding*/ - if ($_POST['MBFlag']=='K' OR $_POST['MBFlag']=='A' OR $_POST['MBFlag']=='D') { + if ($_POST['MBFlag'] == 'K' or $_POST['MBFlag'] == 'A' or $_POST['MBFlag'] == 'D') { - $sql = "SELECT quantityord-quantityrecd + $SQL = "SELECT quantityord-quantityrecd FROM purchorderdetails INNER JOIN purchorders ON purchorders.orderno=purchorderdetails.orderno - WHERE itemcode = '".$StockID."' + WHERE itemcode = '" . $StockID . "' AND purchorderdetails.completed=0 AND purchorders.status<>'Cancelled' AND purchorders.status<>'Completed' AND purchorders.status<>'Rejected'"; - $result = DB_query($sql); - $ChkPurchOrds = DB_fetch_row($result); - if ($ChkPurchOrds[0]!=0){ + $Result = DB_query($SQL); + $ChkPurchOrds = DB_fetch_row($Result); + if ($ChkPurchOrds[0] != 0) { $InputError = 1; - prnMsg( _('The make or buy flag cannot be changed to'). ' ' . $_POST['MBFlag'] . ' '. _('where there is a quantity outstanding to be received on purchase orders') . '. ' . _('Currently there are'). ' ' . $ChkPurchOrds[0] . ' '. _('yet to be received'). 'error'); + prnMsg(_('The make or buy flag cannot be changed to') . ' ' . $_POST['MBFlag'] . ' ' . _('where there is a quantity outstanding to be received on purchase orders') . '. ' . _('Currently there are') . ' ' . $ChkPurchOrds[0] . ' ' . _('yet to be received') . 'error'); } } /*now check that if it was a Manufactured, Kitset, Phantom or Assembly and is being changed to a purchased or dummy - that no BOM exists */ - if (($OldMBFlag=='M' OR $OldMBFlag =='K' OR $OldMBFlag=='A' OR $OldMBFlag=='G') AND ($_POST['MBFlag']=='B' OR $_POST['MBFlag']=='D')) { - $sql = "SELECT COUNT(*) + if (($OldMBFlag == 'M' or $OldMBFlag == 'K' or $OldMBFlag == 'A' or $OldMBFlag == 'G') and ($_POST['MBFlag'] == 'B' or $_POST['MBFlag'] == 'D')) { + $SQL = "SELECT COUNT(*) FROM bom - WHERE parent = '".$StockID."' + WHERE parent = '" . $StockID . "' GROUP BY parent"; - $result = DB_query($sql); - $ChkBOM = DB_fetch_row($result); - if ($ChkBOM[0]!=0){ + $Result = DB_query($SQL); + $ChkBOM = DB_fetch_row($Result); + if ($ChkBOM[0] != 0) { $InputError = 1; - prnMsg( _('The make or buy flag cannot be changed from manufactured, kitset or assembly to'). ' ' . $_POST['MBFlag'] . ' '. _('where there is a bill of material set up for the item') . '. ' . _('Bills of material are not appropriate for purchased or dummy items'), 'error'); + prnMsg(_('The make or buy flag cannot be changed from manufactured, kitset or assembly to') . ' ' . $_POST['MBFlag'] . ' ' . _('where there is a bill of material set up for the item') . '. ' . _('Bills of material are not appropriate for purchased or dummy items'), 'error'); } } /*now check that if it was Manufac, Phantom or Purchased and is being changed to assembly or kitset, it is not a component on an existing BOM */ - if (($OldMBFlag=='M' OR $OldMBFlag =='B' OR $OldMBFlag=='D' OR $OldMBFlag=='G') AND ($_POST['MBFlag']=='A' OR $_POST['MBFlag']=='K')) { - $sql = "SELECT COUNT(*) + if (($OldMBFlag == 'M' or $OldMBFlag == 'B' or $OldMBFlag == 'D' or $OldMBFlag == 'G') and ($_POST['MBFlag'] == 'A' or $_POST['MBFlag'] == 'K')) { + $SQL = "SELECT COUNT(*) FROM bom - WHERE component = '".$StockID."' + WHERE component = '" . $StockID . "' GROUP BY component"; - $result = DB_query($sql); - $ChkBOM = DB_fetch_row($result); - if ($ChkBOM[0]!=0){ + $Result = DB_query($SQL); + $ChkBOM = DB_fetch_row($Result); + if ($ChkBOM[0] != 0) { $InputError = 1; - prnMsg( _('The make or buy flag cannot be changed from manufactured, purchased or dummy to a kitset or assembly where the item is a component in a bill of material') . '. ' . _('Assembly and kitset items are not appropriate as components in a bill of materials'), 'error'); + prnMsg(_('The make or buy flag cannot be changed from manufactured, purchased or dummy to a kitset or assembly where the item is a component in a bill of material') . '. ' . _('Assembly and kitset items are not appropriate as components in a bill of materials'), 'error'); } } } /* Do some checks for changes in the Serial & Controlled setups */ - if ($OldControlled != $_POST['Controlled'] AND $StockQtyRow[0]!=0){ - $InputError=1; - prnMsg( _('You can not change a Non-Controlled Item to Controlled (or back from Controlled to non-controlled when there is currently stock on hand for the item') , 'error'); + if ($OldControlled != $_POST['Controlled'] and $StockQtyRow[0] != 0) { + $InputError = 1; + prnMsg(_('You can not change a Non-Controlled Item to Controlled (or back from Controlled to non-controlled when there is currently stock on hand for the item'), 'error'); } - if ($OldSerialised != $_POST['Serialised'] AND $StockQtyRow[0]!=0){ - $InputError=1; - prnMsg( _('You can not change a Serialised Item to Non-Serialised (or vice-versa) when there is a quantity on hand for the item') , 'error'); + if ($OldSerialised != $_POST['Serialised'] and $StockQtyRow[0] != 0) { + $InputError = 1; + prnMsg(_('You can not change a Serialised Item to Non-Serialised (or vice-versa) when there is a quantity on hand for the item'), 'error'); } /* Do some check for property input */ - for ($i=0;$i<$_POST['PropertyCounter'];$i++){ - if ($_POST['PropNumeric' .$i]==1){ - if ( filter_number_format($_POST['PropValue' . $i]) < $_POST['PropMin' . $i] OR filter_number_format($_POST['PropValue' . $i]) > $_POST['PropMax' . $i]){ - $InputError = 1; - prnMsg(_('The property value should between') . ' '.$_POST['PropMin' . $i] . ' ' . _('and') . $_POST['PropMax' . $i],'error'); + for ($i = 0;$i < $_POST['PropertyCounter'];$i++) { + if ($_POST['PropNumeric' . $i] == 1) { + if (filter_number_format($_POST['PropValue' . $i]) < $_POST['PropMin' . $i] or filter_number_format($_POST['PropValue' . $i]) > $_POST['PropMax' . $i]) { + $InputError = 1; + prnMsg(_('The property value should between') . ' ' . $_POST['PropMin' . $i] . ' ' . _('and') . $_POST['PropMax' . $i], 'error'); } } } - if ($InputError == 0){ + if ($InputError == 0) { DB_Txn_Begin(); - $sql = "UPDATE stockmaster + $SQL = "UPDATE stockmaster SET longdescription='" . $_POST['LongDescription'] . "', description='" . $_POST['Description'] . "', discontinued='" . $_POST['Discontinued'] . "', controlled='" . $_POST['Controlled'] . "', - serialised='" . $_POST['Serialised']."', - perishable='" . $_POST['Perishable']."', + serialised='" . $_POST['Serialised'] . "', + perishable='" . $_POST['Perishable'] . "', categoryid='" . $_POST['CategoryID'] . "', units='" . $_POST['Units'] . "', mbflag='" . $_POST['MBFlag'] . "', @@ -447,83 +436,76 @@ shrinkfactor='" . filter_number_format($_POST['ShrinkFactor']) . "', pansize='" . filter_number_format($_POST['Pansize']) . "', nextserialno='" . $_POST['NextSerialNo'] . "' - WHERE stockid='".$StockID."'"; + WHERE stockid='" . $StockID . "'"; $ErrMsg = _('The stock item could not be updated because'); $DbgMsg = _('The SQL that was used to update the stock item and failed was'); - $result = DB_query($sql,$ErrMsg,$DbgMsg,true); + $Result = DB_query($SQL, $ErrMsg, $DbgMsg, true); $ErrMsg = _('Could not update the language description because'); $DbgMsg = _('The SQL that was used to update the language description and failed was'); - if (count($ItemDescriptionLanguagesArray)>0){ + if (count($ItemDescriptionLanguagesArray) > 0) { foreach ($ItemDescriptionLanguagesArray as $LanguageId) { - if ($LanguageId != ''){ - $result = DB_query("DELETE FROM stockdescriptiontranslations WHERE stockid='" . $StockID . "' AND language_id='" . $LanguageId . "'", $ErrMsg, $DbgMsg, true); - $result = DB_query("INSERT INTO stockdescriptiontranslations (stockid, + if ($LanguageId != '') { + $Result = DB_query("DELETE FROM stockdescriptiontranslations WHERE stockid='" . $StockID . "' AND language_id='" . $LanguageId . "'", $ErrMsg, $DbgMsg, true); + $Result = DB_query("INSERT INTO stockdescriptiontranslations (stockid, language_id, descriptiontranslation, longdescriptiontranslation) - VALUES('" . $StockID . "','" . - $LanguageId . "', '" . - $_POST['Description_' . str_replace('.','_',$LanguageId)] . "', '" . - $_POST['LongDescription_' . str_replace('.','_',$LanguageId)]. - "')",$ErrMsg,$DbgMsg,true); + VALUES('" . $StockID . "','" . $LanguageId . "', '" . $_POST['Description_' . str_replace('.', '_', $LanguageId) ] . "', '" . $_POST['LongDescription_' . str_replace('.', '_', $LanguageId) ] . "')", $ErrMsg, $DbgMsg, true); } } /* foreach ($ItemDescriptionLanguagesArray as $LanguageId) { $DescriptionTranslation = $_POST['Description_' . str_replace('.', '_', $LanguageId)]; //WARNING: It DOES NOT update if database row DOES NOT exist. - $sql = "UPDATE stockdescriptiontranslations " . + $SQL = "UPDATE stockdescriptiontranslations " . "SET descriptiontranslation='" . $DescriptionTranslation . "' " . "WHERE stockid='" . $StockID . "' AND (language_id='" . $LanguageId. "')"; - $result = DB_query($sql, $ErrMsg, $DbgMsg, true); + $Result = DB_query($SQL, $ErrMsg, $DbgMsg, true); } */ } /* Activate the needs revision flag for translations for modified descriptions */ - if ($OldDescription != $_POST['Description'] OR $OldLongDescription != $_POST['LongDescription']){ - $sql = "UPDATE stockdescriptiontranslations + if ($OldDescription != $_POST['Description'] or $OldLongDescription != $_POST['LongDescription']) { + $SQL = "UPDATE stockdescriptiontranslations SET needsrevision = '0' - WHERE stockid='".$StockID."'"; + WHERE stockid='" . $StockID . "'"; $ErrMsg = _('The stock description translations could not be updated because'); $DbgMsg = _('The SQL that was used to set the flag for translation revision failed was'); - $result = DB_query($sql,$ErrMsg,$DbgMsg,true); + $Result = DB_query($SQL, $ErrMsg, $DbgMsg, true); } - //delete any properties for the item no longer relevant with the change of category - $result = DB_query("DELETE FROM stockitemproperties WHERE stockid ='" . $StockID . "'",$ErrMsg, $DbgMsg, true); + $Result = DB_query("DELETE FROM stockitemproperties WHERE stockid ='" . $StockID . "'", $ErrMsg, $DbgMsg, true); //now insert any item properties - for ($i=0;$i<$_POST['PropertyCounter'];$i++){ + for ($i = 0;$i < $_POST['PropertyCounter'];$i++) { - if ($_POST['PropType' . $i] ==2){ - if ($_POST['PropValue' . $i]=='on'){ - $_POST['PropValue' . $i]=1; + if ($_POST['PropType' . $i] == 2) { + if ($_POST['PropValue' . $i] == 'on') { + $_POST['PropValue' . $i] = 1; } else { - $_POST['PropValue' . $i]=0; + $_POST['PropValue' . $i] = 0; } } - if ($_POST['PropNumeric' .$i]==1){ - $_POST['PropValue' . $i]=filter_number_format($_POST['PropValue' . $i]); + if ($_POST['PropNumeric' . $i] == 1) { + $_POST['PropValue' . $i] = filter_number_format($_POST['PropValue' . $i]); } else { - $_POST['PropValue' . $i]=$_POST['PropValue' . $i]; + $_POST['PropValue' . $i] = $_POST['PropValue' . $i]; } - $result = DB_query("INSERT INTO stockitemproperties (stockid, + $Result = DB_query("INSERT INTO stockitemproperties (stockid, stkcatpropid, value) VALUES ('" . $StockID . "', '" . $_POST['PropID' . $i] . "', - '" . $_POST['PropValue' . $i] . "')", - $ErrMsg,$DbgMsg,true); + '" . $_POST['PropValue' . $i] . "')", $ErrMsg, $DbgMsg, true); } //end of loop around properties defined for the category - - if ($OldStockAccount != $NewStockAct AND $_SESSION['CompanyRecord']['gllink_stock']==1) { - /*Then we need to make a journal to transfer the cost to the new stock account */ + if ($OldStockAccount != $NewStockAct and $_SESSION['CompanyRecord']['gllink_stock'] == 1) { + /*Then we need to make a journal to transfer the cost to the new stock account */ $JournalNo = GetNextTransNo(0); //enter as a journal $SQL = "INSERT INTO gltrans (type, typeno, @@ -538,10 +520,10 @@ '" . GetPeriod(Date($_SESSION['DefaultDateFormat'])) . "', '" . $NewStockAct . "', '" . $StockID . ' ' . _('Change stock category') . "', - '" . ($UnitCost* $StockQtyRow[0]) . "')"; - $ErrMsg = _('The stock cost journal could not be inserted because'); + '" . ($UnitCost * $StockQtyRow[0]) . "')"; + $ErrMsg = _('The stock cost journal could not be inserted because'); $DbgMsg = _('The SQL that was used to create the stock cost journal and failed was'); - $result = DB_query($SQL, $ErrMsg, $DbgMsg,true); + $Result = DB_query($SQL, $ErrMsg, $DbgMsg, true); $SQL = "INSERT INTO gltrans (type, typeno, trandate, @@ -555,13 +537,13 @@ '" . GetPeriod(Date($_SESSION['DefaultDateFormat'])) . "', '" . $OldStockAccount . "', '" . $StockID . ' ' . _('Change stock category') . "', - '" . (-$UnitCost* $StockQtyRow[0]) . "')"; - $result = DB_query($SQL, $ErrMsg, $DbgMsg,true); + '" . (-$UnitCost * $StockQtyRow[0]) . "')"; + $Result = DB_query($SQL, $ErrMsg, $DbgMsg, true); } /* end if the stock category changed and forced a change in stock cost account */ - if ($OldWIPAccount != $NewWIPAct AND $_SESSION['CompanyRecord']['gllink_stock']==1) { - /*Then we need to make a journal to transfer the cost of WIP to the new WIP account */ - /*First get the total cost of WIP for this category */ + if ($OldWIPAccount != $NewWIPAct and $_SESSION['CompanyRecord']['gllink_stock'] == 1) { + /*Then we need to make a journal to transfer the cost of WIP to the new WIP account */ + /*First get the total cost of WIP for this category */ $WOCostsResult = DB_query("SELECT workorders.costissued, SUM(woitems.qtyreqd * woitems.stdcost) AS costrecd @@ -569,15 +551,14 @@ ON woitems.wo = workorders.wo INNER JOIN stockmaster ON woitems.stockid=stockmaster.stockid - WHERE stockmaster.stockid='". $StockID . "' + WHERE stockmaster.stockid='" . $StockID . "' AND workorders.closed=0 - GROUP BY workorders.costissued", - _('Error retrieving value of finished goods received and cost issued against work orders for this item')); + GROUP BY workorders.costissued", _('Error retrieving value of finished goods received and cost issued against work orders for this item')); $WIPValue = 0; - while ($WIPRow=DB_fetch_array($WOCostsResult)){ - $WIPValue += ($WIPRow['costissued']-$WIPRow['costrecd']); + while ($WIPRow = DB_fetch_array($WOCostsResult)) { + $WIPValue+= ($WIPRow['costissued'] - $WIPRow['costrecd']); } - if ($WIPValue !=0){ + if ($WIPValue != 0) { $JournalNo = GetNextTransNo(0); //enter as a journal $SQL = "INSERT INTO gltrans (type, typeno, @@ -593,9 +574,9 @@ '" . $NewWIPAct . "', '" . $StockID . ' ' . _('Change stock category') . "', '" . $WIPValue . "')"; - $ErrMsg = _('The WIP cost journal could not be inserted because'); + $ErrMsg = _('The WIP cost journal could not be inserted because'); $DbgMsg = _('The SQL that was used to create the WIP cost journal and failed was'); - $result = DB_query($SQL, $ErrMsg, $DbgMsg,true); + $Result = DB_query($SQL, $ErrMsg, $DbgMsg, true); $SQL = "INSERT INTO gltrans (type, typeno, trandate, @@ -610,28 +591,28 @@ '" . $OldWIPAccount . "', '" . $StockID . ' ' . _('Change stock category') . "', '" . (-$WIPValue) . "')"; - $result = DB_query($SQL, $ErrMsg, $DbgMsg,true); + $Result = DB_query($SQL, $ErrMsg, $DbgMsg, true); } } /* end if the stock category changed and forced a change in WIP account */ DB_Txn_Commit(); - prnMsg( _('Stock Item') . ' ' . $StockID . ' ' . _('has been updated'), 'success'); + prnMsg(_('Stock Item') . ' ' . $StockID . ' ' . _('has been updated'), 'success'); echo '