From: <tim...@us...> - 2009-11-03 15:47:33
|
Revision: 2684 http://web-erp.svn.sourceforge.net/web-erp/?rev=2684&view=rev Author: tim_schofield Date: 2009-11-03 15:47:26 +0000 (Tue, 03 Nov 2009) Log Message: ----------- New fixed asset files from Tim Schofield Added Paths: ----------- trunk/FixedAssetCategories.php trunk/FixedAssetItems.php trunk/FixedAssetJournal.php trunk/FixedAssetLocations.php trunk/FixedAssetRegister.php trunk/FixedAssetTransfer.php Added: trunk/FixedAssetCategories.php =================================================================== --- trunk/FixedAssetCategories.php (rev 0) +++ trunk/FixedAssetCategories.php 2009-11-03 15:47:26 UTC (rev 2684) @@ -0,0 +1,466 @@ +<?php +/* $Revision: 1.2 $ */ + +$PageSecurity = 11; + +include('includes/session.inc'); + +$title = _('Fixed Asset Category Maintenance'); + +include('includes/header.inc'); + +if (isset($_GET['SelectedCategory'])){ + $SelectedCategory = strtoupper($_GET['SelectedCategory']); +} else if (isset($_POST['SelectedCategory'])){ + $SelectedCategory = strtoupper($_POST['SelectedCategory']); +} + +if (isset($_GET['DeleteProperty'])){ + + $ErrMsg = _('Could not delete the property') . ' ' . $_GET['DeleteProperty'] . ' ' . _('because'); + $sql = "DELETE FROM stockitemproperties WHERE stkcatpropid=" . $_GET['DeleteProperty']; + $result = DB_query($sql,$db,$ErrMsg); + $sql = "DELETE FROM stockcatproperties WHERE stkcatpropid=" . $_GET['DeleteProperty']; + $result = DB_query($sql,$db,$ErrMsg); + prnMsg(_('Deleted the property') . ' ' . $_GET['DeleteProperty'],'success'); +} + +if (isset($_POST['submit'])) { + + //initialise no input errors assumed initially before we test + $InputError = 0; + + /* actions to take once the user has clicked the submit button + ie the page has called itself with some user input */ + + //first off validate inputs sensible + + $_POST['CategoryID'] = strtoupper($_POST['CategoryID']); + + if (strlen($_POST['CategoryID']) > 6) { + $InputError = 1; + prnMsg(_('The Fixed Asset Category code must be six characters or less long'),'error'); + } elseif (strlen($_POST['CategoryID'])==0) { + $InputError = 1; + prnMsg(_('The Fixed Asset Category code must be at least 1 character but less than six characters long'),'error'); + } elseif (strlen($_POST['CategoryDescription']) >20) { + $InputError = 1; + prnMsg(_('The Fixed Asset Category description must be twenty characters or less long'),'error'); + } + + if ($SelectedCategory AND $InputError !=1) { + + /*SelectedCategory could also exist if submit had not been clicked this code + would not run in this case cos submit is false of course see the + delete code below*/ + + $sql = "UPDATE stockcategory SET + stocktype = '" . $_POST['StockType'] . "', + categorydescription = '" . $_POST['CategoryDescription'] . "', + stockact = " . $_POST['StockAct'] . ", + adjglact = " . $_POST['AdjGLAct'] . ", + materialuseagevarac = " . $_POST['MaterialUseageVarAc'] . ", + wipact = " . $_POST['WIPAct'] . " + WHERE + categoryid = '$SelectedCategory'"; + $ErrMsg = _('Could not update the fixed asset category') . $_POST['CategoryDescription'] . _('because'); + $result = DB_query($sql,$db,$ErrMsg); + +/* for ($i=0;$i<=$_POST['PropertyCounter'];$i++){ + + if (isset($_POST['PropReqSO' .$i]) and $_POST['PropReqSO' .$i] == true){ + $_POST['PropReqSO' .$i] =1; + } else { + $_POST['PropReqSO' .$i] =0; + } + if ($_POST['PropID' .$i] =='NewProperty' AND strlen($_POST['PropLabel'.$i])>0){ + $sql = "INSERT INTO stockcatproperties (categoryid, + label, + controltype, + defaultvalue, + reqatsalesorder) + VALUES ('" . $SelectedCategory . "', + '" . $_POST['PropLabel' . $i] . "', + " . $_POST['PropControlType' . $i] . ", + '" . $_POST['PropDefault' .$i] . "', + " . $_POST['PropReqSO' .$i] . ')'; + $ErrMsg = _('Could not insert a new category property for') . $_POST['PropLabel' . $i]; + $result = DB_query($sql,$db,$ErrMsg); + } elseif ($_POST['PropID' .$i] !='NewProperty') { //we could be amending existing properties + $sql = "UPDATE stockcatproperties SET label ='" . $_POST['PropLabel' . $i] . "', + controltype = " . $_POST['PropControlType' . $i] . ", + defaultvalue = '" . $_POST['PropDefault' .$i] . "', + reqatsalesorder = " . $_POST['PropReqSO' .$i] . " + WHERE stkcatpropid =" . $_POST['PropID' .$i]; + $ErrMsg = _('Updated the asset category property for') . ' ' . $_POST['PropLabel' . $i]; + $result = DB_query($sql,$db,$ErrMsg); + } + + } //end of loop round properties +*/ + prnMsg(_('Updated the fixed asset category record for') . ' ' . $_POST['CategoryDescription'],'success'); + + } elseif ($InputError !=1) { + + /*Selected category is null cos no item selected on first time round so must be adding a record must be submitting new entries in the new asset category form */ + + $sql = "INSERT INTO stockcategory (categoryid, + stocktype, + categorydescription, + stockact, + adjglact, + materialuseagevarac, + wipact) + VALUES ( + '" . $_POST['CategoryID'] . "', + '" . $_POST['StockType'] . "', + '" . $_POST['CategoryDescription'] . "', + " . $_POST['StockAct'] . ", + " . $_POST['AdjGLAct'] . ", + " . $_POST['MaterialUseageVarAc'] . ", + " . $_POST['WIPAct'] . ")"; + $ErrMsg = _('Could not insert the new asset category') . $_POST['CategoryDescription'] . _('because'); + $result = DB_query($sql,$db,$ErrMsg); + prnMsg(_('A new asset category record has been added for') . ' ' . $_POST['CategoryDescription'],'success'); + $sql="INSERT INTO stockcatproperties + VALUES( + NULL, + '".$_POST['CategoryID']."', + '"._('Depreciation Type')."', + '1', + '"._('Straight Line').","._('Reducing Balance')."', + '0')"; + $result=DB_query($sql,$db); + $sql="INSERT INTO stockcatproperties + VALUES( + NULL, + '".$_POST['CategoryID']."', + '"._('Annual Depreciation Percentage')."', + '0', + '5', + '0')"; + $result=DB_query($sql,$db); + $sql="INSERT INTO stockcatproperties + VALUES( + NULL, + '".$_POST['CategoryID']."', + '"._('Annual Internal Depreciation Percentage')."', + '0', + '5', + '0')"; + $result=DB_query($sql,$db); + } + //run the SQL from either of the above possibilites + + unset($_POST['StockType']); + unset($_POST['CategoryDescription']); + unset($_POST['StockAct']); + unset($_POST['AdjGLAct']); + unset($_POST['PurchPriceVarAct']); + unset($_POST['MaterialUseageVarAc']); + unset($_POST['WIPAct']); + + +} elseif (isset($_GET['delete'])) { +//the link to delete a selected record was clicked instead of the submit button + +// PREVENT DELETES IF DEPENDENT RECORDS IN 'StockMaster' + + $sql= "SELECT COUNT(*) FROM stockmaster WHERE stockmaster.categoryid='$SelectedCategory'"; + $result = DB_query($sql,$db); + $myrow = DB_fetch_row($result); + if ($myrow[0]>0) { + prnMsg(_('Cannot delete this asset category because stock items have been created using this asset category') . + '<br> ' . _('There are') . ' ' . $myrow[0] . ' ' . _('items referring to this asset category code'),'warn'); + + } else { + $sql = "SELECT COUNT(*) FROM salesglpostings WHERE stkcat='$SelectedCategory'"; + $result = DB_query($sql,$db); + $myrow = DB_fetch_row($result); + if ($myrow[0]>0) { + prnMsg(_('Cannot delete this asset category because it is used by the sales') . ' - ' . _('GL posting interface') . '. ' . _('Delete any records in the Sales GL Interface set up using this asset category first'),'warn'); + } else { + $sql = "SELECT COUNT(*) FROM cogsglpostings WHERE stkcat='$SelectedCategory'"; + $result = DB_query($sql,$db); + $myrow = DB_fetch_row($result); + if ($myrow[0]>0) { + prnMsg(_('Cannot delete this asset category because it is used by the cost of sales') . ' - ' . _('GL posting interface') . '. ' . _('Delete any records in the Cost of Sales GL Interface set up using this asset category first'),'warn'); + } else { + $sql="DELETE FROM stockcategory WHERE categoryid='$SelectedCategory'"; + $result = DB_query($sql,$db); + prnMsg(_('The asset category') . ' ' . $SelectedCategory . ' ' . _('has been deleted') . ' !','success'); + unset ($SelectedCategory); + } + } + } //end if asset category used in debtor transactions +} + +if (!isset($SelectedCategory)) { + +/* It could still be the second time the page has been run and a record has been selected for modification - SelectedCategory will exist because it was sent with the new call. If its the first time the page has been displayed with no parameters +then none of the above are true and the list of asset categorys will be displayed with +links to delete or edit each. These will call the same page again and allow update/input +or deletion of the records*/ + + $sql = "SELECT * FROM stockcategory WHERE stocktype='".'A'."'"; + $result = DB_query($sql,$db); + + echo "<br><table border=1>\n"; + echo '<tr><th>' . _('Cat Code') . '</th> + <th>' . _('Description') . '</th> + <th>' . _('Type') . '</th> + <th>' . _('Asset GL') . '</th> + <th>' . _('P & L Depn GL') . '</th> + <th>' . _('Sale of Asset account') . '</th> + <th>' . _('BS Depn GL') . '</th></tr>'; + + $k=0; //row colour counter + + while ($myrow = DB_fetch_row($result)) { + if ($k==1){ + echo '<tr class="EvenTableRows">'; + $k=0; + } else { + echo '<tr class="OddTableRows">'; + $k=1; + } + printf("<td>%s</td> + <td>%s</td> + <td>%s</td> + <td align=right>%s</td> + <td align=right>%s</td> + <td align=right>%s</td> + <td align=right>%s</td> + <td><a href=\"%sSelectedCategory=%s\">" . _('Edit') . "</td> + <td><a href=\"%sSelectedCategory=%s&delete=yes\" onclick=\"return confirm('" . _('Are you sure you wish to delete this asset category? Additional checks will be performed before actual deletion to ensure data integrity is not compromised.') . "');\">" . _('Delete') . "</td> + </tr>", + $myrow[0], + $myrow[1], + $myrow[2], + $myrow[3], + $myrow[4], +// $myrow[5], + $myrow[6], + $myrow[7], + $_SERVER['PHP_SELF'] . '?' . SID, + $myrow[0], + $_SERVER['PHP_SELF'] . '?' . SID, + $myrow[0]); + } + //END WHILE LIST LOOP + echo '</table>'; +} + +//end of ifs and buts! + +?> + +<p> +<?php +if (isset($SelectedCategory)) { ?> + <div class='centre'><a href="<?php echo $_SERVER['PHP_SELF'] . '?' . SID;?>"><?php echo _('Show All Stock Categories'); ?></a></div> +<?php } ?> + +<p> + +<?php + +if (! isset($_GET['delete'])) { + + echo '<form name="CategoryForm" method="post" action="' . $_SERVER['PHP_SELF'] . '?' . SID . '">'; + + if (isset($SelectedCategory)) { + //editing an existing asset category + if (!isset($_POST['UpdateTypes'])) { + $sql = "SELECT categoryid, + stocktype, + categorydescription, + stockact, + adjglact, + purchpricevaract, + materialuseagevarac, + wipact + FROM stockcategory + WHERE categoryid='" . $SelectedCategory . "'"; + + $result = DB_query($sql, $db); + $myrow = DB_fetch_array($result); + + $_POST['CategoryID'] = $myrow['categoryid']; + $_POST['StockType'] = $myrow['stocktype']; + $_POST['CategoryDescription'] = $myrow['categorydescription']; + $_POST['StockAct'] = $myrow['stockact']; + $_POST['AdjGLAct'] = $myrow['adjglact']; + $_POST['PurchPriceVarAct'] = $myrow['purchpricevaract']; + $_POST['MaterialUseageVarAc'] = $myrow['materialuseagevarac']; + $_POST['WIPAct'] = $myrow['wipact']; + } + echo '<input type=hidden name="SelectedCategory" value="' . $SelectedCategory . '">'; + echo '<input type=hidden name="CategoryID" value="' . $_POST['CategoryID'] . '">'; + echo '<table><tr><td>' . _('Asset Category Code') . ':</td><td>' . $_POST['CategoryID'] . '</td></tr>'; + + } else { //end of if $SelectedCategory only do the else when a new record is being entered + if (!isset($_POST['CategoryID'])) { + $_POST['CategoryID'] = ''; + } + echo '<table><tr><td>' . _('Asset Category Code') . ':</td> + <td><input type="Text" name="CategoryID" size=7 maxlength=6 value="' . $_POST['CategoryID'] . '"></td></tr>'; + } + + //SQL to poulate account selection boxes + $sql = "SELECT accountcode, + accountname + FROM chartmaster, + accountgroups + WHERE chartmaster.group_=accountgroups.groupname and + accountgroups.pandl=0 + ORDER BY accountcode"; + + $BSAccountsResult = DB_query($sql,$db); + + $sql = "SELECT accountcode, + accountname + FROM chartmaster, + accountgroups + WHERE chartmaster.group_=accountgroups.groupname and + accountgroups.pandl!=0 + ORDER BY accountcode"; + + $PnLAccountsResult = DB_query($sql,$db); + + if (!isset($_POST['CategoryDescription'])) { + $_POST['CategoryDescription'] = ''; + } + + echo '<tr><td>' . _('Category Description') . ':</td> + <td><input type="Text" name="CategoryDescription" size=22 maxlength=20 value="' . $_POST['CategoryDescription'] . '"></td></tr>'; + + +/* echo '<tr><td>' . _('Stock Type') . ':</td> + <td><select name="StockType" onChange="ReloadForm(CategoryForm.UpdateTypes)" >'; + if (isset($_POST['StockType']) and $_POST['StockType']=='F') { + echo '<option selected value="F">' . _('Finished Goods'); + } else { + echo '<option value="F">' . _('Finished Goods'); + } + if (isset($_POST['StockType']) and $_POST['StockType']=='M') { + echo '<option selected value="M">' . _('Raw Materials'); + } else { + echo '<option value="M">' . _('Raw Materials'); + } + if (isset($_POST['StockType']) and $_POST['StockType']=='D') { + echo '<option selected value="D">' . _('Dummy Item - (No Movements)'); + } else { + echo '<option value="D">' . _('Dummy Item - (No Movements)'); + } + if (isset($_POST['StockType']) and $_POST['StockType']=='L') { + echo '<option selected value="L">' . _('Labour'); + } else { + echo '<option value="L">' . _('Labour'); + } + + echo '</select></td></tr>'; +*/ + echo '<input type=hidden name="StockType" value="A">'; + echo '<input type="submit" name="UpdateTypes" style="visibility:hidden;width:1px" value="Not Seen">'; + echo '<tr><td>' . _('Fixed Asset GL Code'); + + echo ':</td><td><select name="StockAct">'; + + while ($myrow = DB_fetch_array($BSAccountsResult)){ + + if (isset($_POST['StockAct']) and $myrow['accountcode']==$_POST['StockAct']) { + echo '<option selected value='; + } else { + echo '<option value='; + } + echo $myrow['accountcode'] . '>' . $myrow['accountname'] . ' ('.$myrow['accountcode'].')'; + } //end while loop + DB_data_seek($PnLAccountsResult,0); + DB_data_seek($BSAccountsResult,0); + echo '</select></td></tr>'; + + echo '<tr><td>' . _('Balance Sheet Depreciation GL Code') . ':</td><td><select name="WIPAct">'; + + while ($myrow = DB_fetch_array($BSAccountsResult)) { + + if (isset($_POST['WIPAct']) and $myrow['accountcode']==$_POST['WIPAct']) { + echo '<option selected value='; + } else { + echo '<option value='; + } + echo $myrow['accountcode'] . '>' . $myrow['accountname'] . ' ('.$myrow['accountcode'].')'; + + } //end while loop + echo '</select></td></tr>'; + DB_data_seek($BSAccountsResult,0); + + echo '<tr><td>' . _('Profit and Loss Depreciation GL Code') . ':</td> + <td><select name="AdjGLAct">'; + + while ($myrow = DB_fetch_array($PnLAccountsResult)) { + if (isset($_POST['AdjGLAct']) and $myrow['accountcode']==$_POST['AdjGLAct']) { + echo '<option selected value='; + } else { + echo '<option value='; + } + echo $myrow['accountcode'] . '>' . $myrow['accountname'] . ' ('.$myrow['accountcode'].')'; + + } //end while loop + DB_data_seek($PnLAccountsResult,0); + echo '</select></td></tr>'; + +/* echo '<tr><td>' . _('Price Variance GL Code') . ':</td> + <td><select name="PurchPriceVarAct">'; + + while ($myrow = DB_fetch_array($PnLAccountsResult)) { + if (isset($_POST['PurchPriceVarAct']) and $myrow['accountcode']==$_POST['PurchPriceVarAct']) { + echo '<option selected value='; + } else { + echo '<option value='; + } + echo $myrow['accountcode'] . '>' . $myrow['accountname'] . ' ('.$myrow['accountcode'].')'; + + } //end while loop + DB_data_seek($PnLAccountsResult,0); + + echo '</select></td></tr><tr><td>'; */ + echo '<tr><td>'; + if (isset($_POST['StockType']) and $_POST['StockType']=='L') { + echo _('Other Capitalized Goods P/L Code'); + } else { + echo _('Sale of Asset account'); + } + echo ':</td><td><select name="MaterialUseageVarAc">'; + + while ($myrow = DB_fetch_array($PnLAccountsResult)) { + if (isset($_POST['MaterialUseageVarAc']) and $myrow['accountcode']==$_POST['MaterialUseageVarAc']) { + echo '<option selected value='; + } else { + echo '<option value='; + } + echo $myrow['accountcode'] . '>' . $myrow['accountname'] . ' ('.$myrow['accountcode'].')'; + + } //end while loop + DB_free_result($PnLAccountsResult); + echo '</select></td></tr></table><br>'; + + $sql='SELECT COUNT(categoryid) + FROM stockcatproperties + WHERE categoryid="dpntyp"'; + $result=DB_query($sql,$db); + $row=DB_fetch_array($result); + if ($row['categoryid']==0) { + } + echo '<table>'; + + + echo '<div class="centre"><input type="Submit" name="submit" value="' . _('Enter Information') . '"></div>'; + + echo '</form>'; + +} //end if record deleted no point displaying form to add record + + +include('includes/footer.inc'); +?> Added: trunk/FixedAssetItems.php =================================================================== --- trunk/FixedAssetItems.php (rev 0) +++ trunk/FixedAssetItems.php 2009-11-03 15:47:26 UTC (rev 2684) @@ -0,0 +1,926 @@ +<?php + +/* $Revision: 1.2 $ */ + +$PageSecurity = 11; + +include('includes/session.inc'); +$title = _('Fixed Asset Maintenance'); +include('includes/header.inc'); + +/*If this form is called with the StockID then it is assumed that the stock item is to be modified */ + +if (isset($_GET['StockID'])){ + $StockID =trim(strtoupper($_GET['StockID'])); +} elseif (isset($_POST['StockID'])){ + $StockID =trim(strtoupper($_POST['StockID'])); +} else { + $StockID = ''; +} + +if (isset($StockID)) { + $sql = "SELECT COUNT(stockid) FROM assetmanager WHERE stockid='".$StockID."'"; + $result = DB_query($sql,$db); + $myrow = DB_fetch_row($result); + if ($myrow[0]==0) { + $New=1; + } +} + +echo '<a href="' . $rootpath . '/SelectProduct.php?' . SID . '">' . _('Back to Items') . '</a><br>' . "\n"; + + +if (isset($_FILES['ItemPicture']) AND $_FILES['ItemPicture']['name'] !='') { + + $result = $_FILES['ItemPicture']['error']; + $UploadTheFile = 'Yes'; //Assume all is well to start off with + $filename = $_SESSION['part_pics_dir'] . '/' . $StockID . '.jpg'; + + //But check for the worst + if (strtoupper(substr(trim($_FILES['ItemPicture']['name']),strlen($_FILES['ItemPicture']['name'])-3))!='JPG'){ + prnMsg(_('Only jpg files are supported - a file extension of .jpg 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 (file_exists($filename)){ + prnMsg(_('Attempting to overwrite an existing item image'),'warn'); + $result = unlink($filename); + 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') ."<a href='". $filename ."'>" . $filename . '</a>' : _('Something is wrong with uploading a file'); + } + /* EOR Add Image upload for New Item - by Ori */ +} + +if (isset($Errors)) { + unset($Errors); +} +$Errors = array(); +$InputError = 0; + +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 */ + + //first off validate inputs sensible + $i=1; + + + if (!isset($_POST['Description']) or strlen($_POST['Description']) > 50 OR 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'); + $Errors[$i] = 'Description'; + $i++; + } + if (strlen($_POST['LongDescription'])==0) { + $InputError = 1; + prnMsg (_('The stock item description cannot be a zero length string') . ' - ' . _('a long description is required'),'error'); + $Errors[$i] = 'LongDescription'; + $i++; + } + if (strlen($StockID) ==0) { + $InputError = 1; + prnMsg (_('The Stock Item code cannot be empty'),'error'); + $Errors[$i] = 'StockID'; + $i++; + } + if (strstr($StockID,' ') OR strstr($StockID,"'") OR strstr($StockID,'+') OR strstr($StockID,"\\") OR strstr($StockID,"\"") OR strstr($StockID,'&') OR strstr($StockID,'.') OR strstr($StockID,'"')) { + $InputError = 1; + prnMsg(_('The stock item code cannot contain any of the following characters') . " - ' & + \" \\ " . _('or a space'),'error'); + $Errors[$i] = 'StockID'; + $i++; + $StockID=''; + } + if (strlen($_POST['Units']) >20) { + $InputError = 1; + prnMsg(_('The unit of measure must be 20 characters or less long'),'error'); + $Errors[$i] = 'Units'; + $i++; + } + if (strlen($_POST['BarCode']) >20) { + $InputError = 1; + prnMsg(_('The barcode must be 20 characters or less long'),'error'); + $Errors[$i] = 'BarCode'; + $i++; + } + if (!is_numeric($_POST['Volume'])) { + $InputError = 1; + prnMsg (_('The volume of the packaged item in cubic metres must be numeric') ,'error'); + $Errors[$i] = 'Volume'; + $i++; + } + if ($_POST['Volume'] <0) { + $InputError = 1; + prnMsg(_('The volume of the packaged item must be a positive number'),'error'); + $Errors[$i] = 'Volume'; + $i++; + } + if (!is_numeric($_POST['KGS'])) { + $InputError = 1; + prnMsg(_('The weight of the packaged item in KGs must be numeric'),'error'); + $Errors[$i] = 'KGS'; + $i++; + } + if ($_POST['KGS']<0) { + $InputError = 1; + prnMsg(_('The weight of the packaged item must be a positive number'),'error'); + $Errors[$i] = 'KGS'; + $i++; + } + if (!is_numeric($_POST['EOQ'])) { + $InputError = 1; + prnMsg(_('The economic order quantity must be numeric'),'error'); + $Errors[$i] = 'EOQ'; + $i++; + } + if ($_POST['EOQ'] <0) { + $InputError = 1; + prnMsg (_('The economic order quantity must be a positive number'),'error'); + $Errors[$i] = 'EOQ'; + $i++; + } + 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'); + $Errors[$i] = 'Serialised'; + $i++; + } + 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'); + $Errors[$i] = 'NextSerialNo'; + $i++; + } + 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'); + $Errors[$i] = 'NextSerialNo'; + $i++; + } + 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'); + $Errors[$i] = 'Controlled'; + $i++; + } + if (trim($_POST['CategoryID'])==''){ + $InputError = 1; + 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($_POST['Pansize'])) { + $InputError = 1; + prnMsg(_('Pansize quantity must be numeric'),'error'); + $Errors[$i] = 'Pansize'; + $i++; + } + if (!is_numeric($_POST['ShrinkFactor'])) { + $InputError = 1; + 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 (!isset($_POST['New']) and !isset($New)) { /*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, + controlled, + serialised + FROM stockmaster WHERE stockid = '$StockID'"; + $MBFlagResult = DB_query($sql,$db); + $myrow = DB_fetch_row($MBFlagResult); + $OldMBFlag = $myrow[0]; + $OldControlled = $myrow[1]; + $OldSerialised = $myrow[2]; + + $sql = "SELECT SUM(locstock.quantity) FROM locstock WHERE stockid='$StockID'"; + $result = DB_query($sql,$db); + $stkqtychk = DB_fetch_row($result); + + 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 ($stkqtychk[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') . ' ' . $stkqtychk[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'); + } + } + /*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 + FROM salesorderdetails + WHERE stkcode = '$StockID' + AND completed=0"; + + $result = DB_query($sql,$db); + $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'); + } + } + /*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') { + + $sql = "SELECT quantityord-quantityrecd + FROM purchorderdetails + WHERE itemcode = '$StockID' + AND completed=0"; + + $result = DB_query($sql,$db); + $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'); + } + } + + /*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(*) FROM bom WHERE parent = '$StockID'"; + $result = DB_query($sql,$db); + $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'); + } + } + + /*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(*) FROM bom WHERE component = '$StockID'"; + $result = DB_query($sql,$db); + $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'); + } + } + } + + /* Do some checks for changes in the Serial & Controlled setups */ + if ($OldControlled != $_POST['Controlled'] AND $stkqtychk[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 $stkqtychk[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 ($InputError == 0){ + $sql = "UPDATE stockmaster + SET longdescription='" . $_POST['LongDescription'] . "', + description='" . $_POST['Description'] . "', + discontinued=" . $_POST['Discontinued'] . ", + controlled=" . $_POST['Controlled'] . ", + serialised=" . $_POST['Serialised'].", + perishable=" . $_POST['Perishable'].", + categoryid='" . $_POST['CategoryID'] . "', + units='" . $_POST['Units'] . "', + mbflag='" . $_POST['MBFlag'] . "', + eoq=" . $_POST['EOQ'] . ", + volume=" . $_POST['Volume'] . ", + kgs=" . $_POST['KGS'] . ", + barcode='" . $_POST['BarCode'] . "', + discountcategory='" . $_POST['DiscountCategory'] . "', + taxcatid=" . $_POST['TaxCat'] . ", + decimalplaces=" . $_POST['DecimalPlaces'] . ", + appendfile='" . $_POST['ItemPDF'] . "', + shrinkfactor=" . $_POST['ShrinkFactor'] . ", + pansize=" . $_POST['Pansize'] . ", + nextserialno=" . $_POST['NextSerialNo'] . " + 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,$db,$ErrMsg,$DbgMsg); + + //delete any properties for the item no longer relevant with the change of category + $result = DB_query("DELETE FROM stockitemproperties + WHERE stockid ='" . $StockID . "'", + $db); + + //now insert any item properties + for ($i=0;$i<=$_POST['PropertyCounter'];$i++){ + + if ($_POST['PropType' . $i] ==2){ + if ($_POST['PropValue' . $i]=='on'){ + $_POST['PropValue' . $i]=1; + } else { + $_POST['PropValue' . $i]=0; + } + } + $result = DB_query("INSERT INTO stockitemproperties (stockid, + stkcatpropid, + value) + VALUES ('" . $StockID . "', + " . $_POST['PropID' . $i] . ", + '" . $_POST['PropValue' . $i] . "')", + $db); + } //end of loop around properties defined for the category + prnMsg( _('Stock Item') . ' ' . $StockID . ' ' . _('has been updated'), 'success'); + } + + } else { //it is a NEW part + //but lets be really sure here + $result = DB_query("SELECT stockid FROM stockmaster WHERE stockid='" . $StockID ."'",$db); + if (DB_num_rows($result)==1){ + prnMsg(_('The stock code entered is actually already in the database - duplicate stock codes are prohibited by the system. Try choosing an alternative stock code'),'error'); + exit; + } else { + $sql = "INSERT INTO stockmaster ( + stockid, + description, + longdescription, + categoryid, + units, + mbflag, + eoq, + discontinued, + controlled, + serialised, + perishable, + volume, + kgs, + barcode, + discountcategory, + taxcatid, + decimalplaces, + appendfile, + shrinkfactor, + pansize) + VALUES ('$StockID', + '" . $_POST['Description'] . "', + '" . $_POST['LongDescription'] . "', + '" . $_POST['CategoryID'] . "', + '" . $_POST['Units'] . "', + '" . $_POST['MBFlag'] . "', + " . $_POST['EOQ'] . ", + " . $_POST['Discontinued'] . ", + " . $_POST['Controlled'] . ", + " . $_POST['Serialised']. ", + " . $_POST['Perishable']. ", + " . $_POST['Volume'] . ", + " . $_POST['KGS'] . ", + '" . $_POST['BarCode'] . "', + '" . $_POST['DiscountCategory'] . "', + " . $_POST['TaxCat'] . ", + " . $_POST['DecimalPlaces']. ", + '" . $_POST['ItemPDF']. "', + " . $_POST['ShrinkFactor'] . ", + " . $_POST['Pansize'] . " + )"; + + $ErrMsg = _('The item could not be added because'); + $DbgMsg = _('The SQL that was used to add the item failed was'); + $result = DB_query($sql,$db, $ErrMsg, $DbgMsg); + //now insert any item properties + for ($i=0;$i<=$_POST['PropertyCounter'];$i++){ + + if ($_POST['PropType' . $i] ==2){ + if ($_POST['PropValue' . $i]=='on'){ + $_POST['PropValue' . $i]=1; + } else { + $_POST['PropValue' . $i]=0; + } + } + $sql="INSERT INTO stockitemproperties (stockid, + stkcatpropid, + value) + VALUES ('" . $StockID . "', + " . $_POST['PropID' . $i] . ", + '" . $_POST['PropValue' . $i] . "')"; + $result = DB_query($sql,$db); + } //end of loop around properties defined for the category + if (DB_error_no($db) ==0) { + + $sql = "INSERT INTO locstock (loccode, + stockid) + SELECT locations.loccode, + '" . $StockID . "' + FROM locations"; + + $ErrMsg = _('The locations for the item') . ' ' . $StockID . ' ' . _('could not be added because'); + $DbgMsg = _('NB Locations records can be added by opening the utility page') . ' <i>Z_MakeStockLocns.php</i> ' . _('The SQL that was used to add the location records that failed was'); + $InsResult = DB_query($sql,$db,$ErrMsg,$DbgMsg); + + if (DB_error_no($db) ==0) { + prnMsg( _('New Item') .' ' . "<a + href='SelectProduct.php?StockID=$StockID'>$StockID</a>" . ' '. _('has been added to the database'),'success'); unset($_POST['LongDescription']); + unset($_POST['Description']); + unset($_POST['EOQ']); +// Leave Category ID set for ease of batch entry +// unset($_POST['CategoryID']); + unset($_POST['Units']); + unset($_POST['MBFlag']); + unset($_POST['Discontinued']); + unset($_POST['Controlled']); + unset($_POST['Serialised']); + unset($_POST['Perishable']); + unset($_POST['Volume']); + unset($_POST['KGS']); + unset($_POST['BarCode']); + unset($_POST['ReorderLevel']); + unset($_POST['DiscountCategory']); + unset($_POST['DecimalPlaces']); + unset($_POST['ItemPDF']); + unset($_POST['ShrinkFactor']); + unset($_POST['Pansize']); + unset($StockID); + }//ALL WORKED SO RESET THE FORM VARIABLES + }//THE INSERT OF THE NEW CODE WORKED SO BANG IN THE STOCK LOCATION RECORDS TOO + }//END CHECK FOR ALREADY EXISTING ITEM OF THE SAME CODE + } + + } else { + echo '<br>'. "\n"; + prnMsg( _('Validation failed, no updates or deletes took place'), 'error'); + } + +} elseif (isset($_POST['delete']) AND strlen($_POST['delete']) >1 ) { +//the button to delete a selected record was clicked instead of the submit button + + $CancelDelete = 0; + +// PREVENT DELETES IF DEPENDENT RECORDS IN 'StockMoves' + + $sql= "SELECT COUNT(*) FROM stockmoves WHERE stockid='$StockID'"; + $result = DB_query($sql,$db); + $myrow = DB_fetch_row($result); + if ($myrow[0]>0) { + $CancelDelete = 1; + prnMsg( _('Cannot delete this stock item because there are stock movements that refer to this item'),'warn'); + echo '<br>' . _('There are') . ' ' . $myrow[0] . ' ' . _('stock movements that refer to this item'); + + } else { + $sql= "SELECT COUNT(*) FROM bom WHERE component='$StockID'"; + $result = DB_query($sql,$db); + $myrow = DB_fetch_row($result); + if ($myrow[0]>0) { + $CancelDelete = 1; + prnMsg( _('Cannot delete this item record because there are bills of material that require this part as a component'),'warn'); + echo '<br>' . _('There are') . ' ' . $myrow[0] . ' ' . _('bills of material that require this part as a component'); + } else { + $sql= "SELECT COUNT(*) FROM salesorderdetails WHERE stkcode='$StockID'"; + $result = DB_query($sql,$db); + $myrow = DB_fetch_row($result); + if ($myrow[0]>0) { + $CancelDelete = 1; + prnMsg( _('Cannot delete this item record because there are existing sales orders for this part'),'warn'); + echo '<br>' . _('There are') . ' ' . $myrow[0] . ' ' . _('sales order items against this part'); + } else { + $sql= "SELECT COUNT(*) FROM salesanalysis WHERE stockid='$StockID'"; + $result = DB_query($sql,$db); + $myrow = DB_fetch_row($result); + if ($myrow[0]>0) { + $CancelDelete = 1; + prnMsg(_('Cannot delete this item because sales analysis records exist for it'),'warn'); + echo '<br>' . _('There are') . ' ' . $myrow[0] . ' ' . _('sales analysis records against this part'); + } else { + $sql= "SELECT COUNT(*) FROM purchorderdetails WHERE itemcode='$StockID'"; + $result = DB_query($sql,$db); + $myrow = DB_fetch_row($result); + if ($myrow[0]>0) { + $CancelDelete = 1; + prnMsg(_('Cannot delete this item because there are existing purchase order items for it'),'warn'); + echo '<br>' . _('There are') . ' ' . $myrow[0] . ' ' . _('purchase order item record relating to this part'); + } else { + $sql = "SELECT SUM(quantity) AS qoh FROM locstock WHERE stockid='$StockID'"; + $result = DB_query($sql,$db); + $myrow = DB_fetch_row($result); + if ($myrow[0]!=0) { + $CancelDelete = 1; + prnMsg( _('Cannot delete this item because there is currently some stock on hand'),'warn'); + echo '<br>' . _('There are') . ' ' . $myrow[0] . ' ' . _('on hand for this part'); + } + } + } + } + } + + } + if ($CancelDelete==0) { + $result = DB_Txn_Begin($db); + + /*Deletes LocStock records*/ + $sql ="DELETE FROM locstock WHERE stockid='$StockID'"; + $result=DB_query($sql,$db,_('Could not delete the location stock records because'),'',true); + /*Deletes Price records*/ + $sql ="DELETE FROM prices WHERE stockid='$StockID'"; + $result=DB_query($sql,$db,_('Could not delete the prices for this stock record because'),'',true); + /*and cascade deletes in PurchData */ + $sql ="DELETE FROM purchdata WHERE stockid='$StockID'"; + $result=DB_query($sql,$db,_('Could not delete the purchasing data because'),'',true); + /*and cascade delete the bill of material if any */ + $sql = "DELETE FROM bom WHERE parent='$StockID'"; + $result=DB_query($sql,$db,_('Could not delete the bill of material because'),'',true); + $sql="DELETE FROM stockmaster WHERE stockid='$StockID'"; + $result=DB_query($sql,$db, _('Could not delete the item record'),'',true); + + $result = DB_Txn_Commit($db); + + prnMsg(_('Deleted the stock master record for') . ' ' . $StockID . '....' . + '<br>. . ' . _('and all the location stock records set up for the part') . + '<br>. . .' . _('and any bill of material that may have been set up for the part') . + '<br> . . . .' . _('and any purchasing data that may have been set up for the part') . + '<br> . . . . .' . _('and any prices that may have been set up for the part'),'success'); + unset($_POST['LongDescription']); + unset($_POST['Description']); + unset($_POST['EOQ']); + unset($_POST['CategoryID']); + unset($_POST['Units']); + unset($_POST['MBFlag']); + unset($_POST['Discontinued']); + unset($_POST['Controlled']); + unset($_POST['Serialised']); + unset($_POST['Perishable']); + unset($_POST['Volume']); + unset($_POST['KGS']); + unset($_POST['BarCode']); + unset($_POST['ReorderLevel']); + unset($_POST['DiscountCategory']); + unset($_POST['TaxCat']); + unset($_POST['DecimalPlaces']); + unset($_POST['ItemPDF']); + unset($StockID); + unset($_SESSION['SelectedStockItem']); + //echo "<meta http-equiv='Refresh' content='0; url=" . $rootpath . '/SelectProduct.php?' . SID ."'>"; + + + } //end if Delete Part +} + + +echo '<form name="ItemForm" enctype="multipart/form-data" method="post" action="' . $_SERVER['PHP_SELF'] . '?' .SID .'"><table> + <tr><td><table>'. "\n"; // Nested table + +if (!isset($StockID) or $StockID=='') { + +/*If the page was called without $StockID passed to page then assume a new stock item is to be entered show a form with a part Code field other wise the form showing the fields with the existing entries against the part will show for editing with only a hidden StockID field. New is set to flag that the page may have called itself and still be entering a new part, in which case the page needs to know not to go looking up details for an existing part*/ + + $New = true; + echo '<input type="hidden" name="New" value="1">'. "\n"; + + echo '<tr><td>'. _('Asset Code'). ':</td><td><input ' . (in_array('StockID',$Errors) ? 'class="inputerror"' : '' ) .' type="text" name="StockID" size=21 maxlength=20></td></tr>'. "\n"; + +} elseif (!isset($_POST['UpdateCategories']) and $InputError!=1) { // Must be modifying an existing item and no changes made yet + + $sql = "SELECT stockid, + description, + longdescription, + categoryid, + units, + mbflag, + discontinued, + controlled, + serialised, + perishable, + eoq, + volume, + kgs, + barcode, + discountcategory, + taxcatid, + decimalplaces, + appendfile, + nextserialno + FROM stockmaster + WHERE stockid = '$StockID'"; + + $result = DB_query($sql, $db); + $myrow = DB_fetch_array($result); + + $_POST['LongDescription'] = $myrow['longdescription']; + $_POST['Description'] = $myrow['description']; + $_POST['EOQ'] = $myrow['eoq']; + $_POST['CategoryID'] = $myrow['categoryid']; + $_POST['Units'] = $myrow['units']; + $_POST['MBFlag'] = $myrow['mbflag']; + $_POST['Discontinued'] = $myrow['discontinued']; + $_POST['Controlled'] = $myrow['controlled']; + $_POST['Serialised'] = $myrow['serialised']; + $_POST['Perishable'] = $myrow['perishable']; + $_POST['Volume'] = $myrow['volume']; + $_POST['KGS'] = $myrow['kgs']; + $_POST['BarCode'] = $myrow['barcode']; + $_POST['DiscountCategory'] = $myrow['discountcategory']; + $_POST['TaxCat'] = $myrow['taxcatid']; + $_POST['DecimalPlaces'] = $myrow['decimalplaces']; + $_POST['ItemPDF'] = $myrow['appendfile']; + $_POST['NextSerialNo'] = $myrow['nextserialno']; + + echo '<tr><td>' . _('Asset Code') . ':</td><td>'.$StockID.'</td></tr>'. "\n"; + echo '<input type="Hidden" name="StockID" value='.$StockID.'>'. "\n"; + +} else { // some changes were made to the data so don't re-set form variables to DB ie the code above + echo '<tr><td>' . _('Asset Code') . ':</td><td>'.$StockID.'</td></tr>'; + echo "<input type='Hidden' name='StockID' value='$StockID'>"; +} + +if (isset($_POST['Description'])) { + $Description = $_POST['Description']; +} else { + $Description =''; +} +echo '<tr><td>' . _('Asset Description') . ' (' . _('short') . '):</td><td><input ' . (in_array('Description',$Errors) ? 'class="inputerror"' : '' ) .' type="Text" name="Description" size=52 maxlength=50 value="' . htmlentities($Description,ENT_QUOTES,_('ISO-8859-1')) . '"></td></tr>'."\n"; + +if (isset($_POST['LongDescription'])) { + $LongDescription = AddCarriageReturns($_POST['LongDescription']); +} else { + $LongDescription =''; +} +echo '<tr><td>' . _('Asset Description') . ' (' . _('long') . '):</td><td><textarea ' . (in_array('LongDescription',$Errors) ? 'class="texterror"' : '' ) .' name="LongDescription" cols=40 rows=4>' . stripslashes($LongDescription) . '</textarea></td></tr>'."\n"; + +// Generate selection drop down from pdf_append directory - by emdx, +// developed with examples from http://au2.php.net/manual/en/function.opendir.php +function select_files($dir, $label = '', $select_name = 'ItemPDF', $curr_val = '', $char_length = 60) { + $teller = 0; + if (!file_exists($dir)) { + mkdir($dir); + chmod($dir, 0777); + } + if ($handle = opendir($dir)) { + $mydir = "<select name=".$select_name.">\n"; + $mydir .= '<option VALUE=0>none'; + if (isset($_POST['ItemPDF'])) { + $curr_val = $_POST['ItemPDF']; + } else { + $curr_val .= 'none'; + } + while (false !== ($file = readdir($handle))) + { + $files[] = $file; + } + closedir($handle); + sort($files); + foreach ($files as $val) { + if (is_file($dir.$val)) { + $mydir .= '<option VALUE='.$val; + $mydir .= ($val == $curr_val) ? ' selected>' : '>'; + $mydir .= $val."\n"; + $teller++; + } + } + $mydir .= ""; + } + return $mydir; +} +if (!isset($_POST['ItemPDF'])) { + $_POST['ItemPDF'] = ''; +} +echo '<tr><td>' . _('PDF attachment (.pdf)') . ':' . "\n</td><td>" . select_files('companies/' . $_SESSION['DatabaseName'] .'/pdf_append//','' , 'ItemPDF', $_POST['ItemPDF'], '60') . '</td></tr>'. "\n"; + +// Add image upload for New Item - by Ori +echo '<tr><td>'. _('Image File (.jpg)') . ':</td><td><input type="file" id="ItemPicture" name="ItemPicture"></td></tr>'; +// EOR Add Image upload for New Item - by Ori + + echo '<tr><td>' . _('Category') . ':</td><td><select name="CategoryID" onChange="ReloadForm(ItemForm.UpdateCategories)">'; + +$sql = 'SELECT categoryid, categorydescription FROM stockcategory WHERE stocktype="A"'; +$ErrMsg = _('The stock categories could not be retrieved because'); +$DbgMsg = _('The SQL used to retrieve stock categories and failed was'); +$result = DB_query($sql,$db,$ErrMsg,$DbgMsg); + +while ($myrow=DB_fetch_array($result)){ + if (!isset($_POST['CategoryID']) or $myrow['categoryid']==$_POST['CategoryID']){ + echo '<option selected VALUE="'. $myrow['categoryid'] . '">' . $myrow['categorydescription']; + } else { + echo '<option VALUE="'. $myrow['categoryid'] . '">' . $myrow['categorydescription']; + } + $category=$myrow['categoryid']; +} +echo '</select><a target="_blank" href="'. $rootpath . '/FixedAssetCategories.php?' . SID . '">'.' ' . _('Add or Modify Asset Categories') . '</a></td></tr>'; +if (!isset($_POST['CategoryID'])) { + $_POST['CategoryID']=$category; +} + +if (!isset($_POST['EOQ']) or $_POST['EOQ']==''){ + $_POST['EOQ']=0; +} + +if (!isset($_POST['Volume']) or $_POST['Volume']==''){ + $_POST['Volume']=0; +} +if (!isset($_POST['KGS']) or $_POST['KGS']==''){ + $_POST['KGS']=0; +} +if (!isset($_POST['Controlled']) or $_POST['Controlled']==''){ + $_POST['Controlled']=0; +} +if (!isset($_POST['Serialised']) or $_POST['Serialised']=='' || $_POST['Controlled']==0){ + $_POST['Serialised']=0; +} +if (!isset($_POST['DecimalPlaces']) or $_POST['DecimalPlaces']==''){ + $_POST['DecimalPlaces']=0; +} +if (!isset($_POST['Discontinued']) or $_POST['Discontinued']==''){ + $_POST['Discontinued']=0; +} +if (!isset($_POST['Pansize'])) { + $_POST['Pansize']=0; +} +if (!isset($_POST['ShrinkFactor'])) { + $_POST['ShrinkFactor']=0; +} +if (!isset($_POST['NextSerialNo'])) { + $_POST['NextSerialNo']=0; +} + + +echo '<input type="hidden" class="number" name="EOQ" size=12 maxlength=10 value="0">'; + +echo '<tr><td>' . _('Packaged Volume (metres cubed)') . ':</td><td><input ' . (in_array('Volume',$Errors) ? 'class="inputerror"' : '' ) .' type="Text" class="number" name="Volume" size=12 maxlength=10 value="' . $_POST['Volume'] . '"></td></tr>'; + +echo '<tr><td>' . _('Packaged Weight (KGs)') . ':</td><td><input ' . (in_array('KGS',$Errors) ? 'class="inputerror"' : '' ) .' type="Text" class="number" name="KGS" size=12 maxlength=10 value="' . $_POST['KGS'] . '"></td></tr>'; + +if (!isset($_POST['Units'])) { + $UOMrow['unitname']=_('each'); +} + +echo '<input type=hidden name=Units value="each">'; + +echo '<tr><td>' . _('Manufactured or Purchased') . ':</td><td><select name="MBFlag">'; +if (!isset($_POST['MBFlag']) or $_POST['MBFlag']=='M'){ + echo '<option selected value="M">' . _('Manufactured') . '</option>'; +} else { + echo '<option value="M">' . _('Manufactured') . '</option>'; +} +if (!isset($_POST['MBFlag']) or $_POST['MBFlag']=='B' OR !isset($_POST['MBFlag']) OR $_POST['MBFlag']==''){ + echo '<option selected value="B">' . _('Purchased') . '</option>'; +} else { + echo '<option value="B">' . _('Purchased') . '</option>'; +} + +echo '</select></td></tr>'; + +echo '<input type=hidden name=Discontinued value="0">'; +echo '<input type=hidden name=Controlled value="1">'; +echo '<input type=hidden name=Serialised value="1">'; + + +echo '<input type=hidden name=Perishable value="0">'; + +echo '<input type="hidden" class="number" name="DecimalPlaces" size=1 maxlength=1 value="0">'; + +if (isset($_POST['BarCode'])) { + $BarCode = $_POST['BarCode']; +} else { + $BarCode=''; +} +echo '<tr><td>' . _('Bar Code') . ':</td><td><input ' . (in_array('BarCode',$Errors) ? 'class="inputerror"' : '' ) .' type="Text" name="BarCode" size=22 maxlength=20 value="' . $BarCode . '"></td></tr>'; + +if (isset($_POST['DiscountCategory'])) { + $DiscountCategory = $_POST['DiscountCategory']; +} else { + $DiscountCategory=''; +} +echo '<input type="hidden" name="DiscountCategory" size=2 maxlength=2 value="' . $DiscountCategory . '">'; + +echo '<tr><td>' . _('Tax Category') . ':</td><td><select name="TaxCat">'; +$sql = 'SELECT taxcatid, taxcatname FROM taxcategories ORDER BY taxcatname'; +$result = DB_query($sql, $db); + +if (!isset($_POST['TaxCat'])){ + $_POST['TaxCat'] = $_SESSION['DefaultTaxCategory']; +} + +while ($myrow = DB_fetch_array($result)) { + if ($_POST['TaxCat'] == $myrow['taxcatid']){ + echo '<option selected value=' . $myrow['taxcatid'] . '>' . $myrow['taxcatname'] . '</option>'; + } else { + echo '<option value=' . $myrow['taxcatid'] . '>' . $myrow['taxcatname'] . '</option>'; + } +} //end while loop + +echo '</select></td></tr>'; + +echo '<input type="hidden" class="number" name="Pansize" size="6" maxlength="6" value=' . $_POST['Pansize'] . '>'; +echo '<input type="hidden" class="number" name="ShrinkFactor" size="6" maxlength="6" value=' . $_POST['ShrinkFactor'] . '>'; + + + if (function_exists('imagecreatefrompng')){ + $StockImgLink = '<img src="GetStockImage.php?SID&automake=1&textcolor=FFFFFF&bgcolor=CCCCCC'. + '&StockID='.urlencode($StockID). + '&text='. + '&width=64'. + '&height=64'. + '" >'; +} else { + if( isset($StockID) and file_exists($_SESSION['part_pics_dir'] . '/' .$StockID.'.jpg') ) { + $StockImgLink = '<img src="' . $_SESSION['part_pics_dir'] . '/' .$StockID.'.jpg" >'; + } else { + $StockImgLink = _('No Image'); + } +} + +echo '</table></td><td>' . _('Image') . '<br>'.$StockImgLink . '</td></tr></table><div class="centre">'; + +if (!isset($_POST['CategoryID'])) { + $_POST['CategoryID'] = ''; +} +echo '<table><tr><th colspan="2">' . _('Asset Category Properties') . '</th></tr>'; +$sql = "SELECT stkcatpropid, + label, + controltype, + defaultvalue + FROM stockcatproperties + WHERE categoryid ='" . $_POST['CategoryID'] . "' + AND reqatsalesorder =0 + ORDER BY stkcatpropid"; + +$PropertiesResult = DB_query($sql,$db); +$PropertyCounter = 0; +$PropertyWidth = array(); + +while ($PropertyRow=DB_fetch_array($PropertiesResult)){ + + $PropValResult = DB_query("SELECT value FROM + stockitemproperties + WHERE stockid='" . $StockID . "' + AND stkcatpropid =" . $PropertyRow['stkcatpropid'], + $db); + $PropValRow = DB_fetch_row($PropValResult); + $PropertyValue = $PropValRow[0]; + + echo '<input type="hidden" name="PropID' . $PropertyCounter . '" value=' .$PropertyRow['stkcatpropid'] .'>'; + + echo '<tr><td>' . $PropertyRow['label'] . '</td> + <td>'; + switch ($PropertyRow['controltype']) { + case 0; //textbox + echo '<input type="textbox" name="PropValue' . $PropertyCounter . '" size="20" maxlength="100" value="' . $PropertyValue . '">'; + break; + case 1; //select box + $OptionValues = explode(',',$PropertyRow['defaultvalue']); + echo '<select name="PropValue' . $PropertyCounter . '">'; + foreach ($OptionValues as $PropertyOptionValue){ + if ($PropertyOptionValue == $PropertyValue){ + echo '<option selected value="' . $PropertyOptionValue . '">' . $PropertyOptionValue . '</option>'; + } else { + echo '<option value="' . $PropertyOptionValue . '">' . $PropertyOptionValue . '</option>'; + } + } + echo '</select>'; + break; + case 2; //checkbox + echo '<input type="checkbox" name="PropValue' . $PropertyCounter . '"'; + if ($PropertyValue==1){ + echo '"checked"'; + } + echo '>'; + break; + } //end switch + echo '<input type="hidden" name="PropType' . $PropertyCounter .'" value=' . $PropertyRow['controltype'] . '>'; + echo '</td></tr>'; + $PropertyCounter++; +} //end loop round properties for the item category +echo '</table>'; +echo '<input type="hidden" name="PropertyCounter" value=2>'; + +if (isset($New)) { + echo '<input type="Submit" name="submit" value="' . _('Insert New Item') . '">'; + echo '<input type="submit" name="UpdateCategories" style="visibility:hidden;width:1px" value="' . _('Categories') . '">'; + +} else { + + // Now the form to enter the item properties + + echo '<input type="submit" name="submit" value="' . _('Update') . '">'; + echo '<input type="submit" name="UpdateCategories" style="visibility:hidden;width:1px" value="' . _('Categories') . '">'; + echo '<p>'; + prnMsg( _('Only click the Delete button if you are sure you wish to delete the item!') . _('Checks will be made to ensure that there are no stock movements, sales analysis records, sales order items or purchase order items for the item') . '. ' . _('No deletions will be allowed if they exist'), 'warn', _('WARNING')); + echo '<p><input type="Submit" name="delete" value="' . _('Delete This Item') . '" onclick="return confirm(\'' . _('Are You Sure?') . '\');">'; +} + +echo '</form></div>'; +include('includes/footer.inc'); +?> Added: trunk/FixedAssetJournal.php =================================================================== --- trunk/FixedAssetJournal.php (rev 0) +++ trunk/FixedAssetJournal.php 2009-11-03 15:47:26 UTC (rev 2684) @@ -0,0 +1,426 @@ +<?php + +/* $Revision: 1.2 $ */ + +include('includes/DefineJournalClass.php'); + +$PageSecurity = 10; +include('includes/session.inc'); +$title = _('Depreciation Journal Entry'); + +include('includes/header.inc'); +include('includes/SQL_CommonFunctions.inc'); + +if (isset($_GET['NewJournal']) and $_GET['NewJournal'] == 'Yes' AND isset($_SESSION['JournalDetail'])){ + unset($_SESSION['JournalDetail']->GLEntries); + unset($_SESSION['JournalDetail']); +} + +if (!isset($_SESSION['JournalDetail']) or isset($_POST['update'])){ + $_SESSION['JournalDetail'] = new Journal; + + /* Make an array of the defined bank accounts - better to make it now than do it each time a line is added + Journals cannot be entered against bank accounts GL postings involving bank accounts must be done using + a receipt or a payment transaction to ensure a bank trans is available for matching off vs statements */ + + $SQL = 'SELECT accountcode FROM bankaccounts'; + $result = DB_query($SQL,$db); + $i=0; + while ($Act = DB_fetch_row($result)){ + $_SESSION['JournalDetail']->BankAccounts[$i]= $Act[0]; + $i++; + } + + /* Get list of assets for journal */ + $sql='SELECT assetmanager.*, + stockcategory.stockact as bsdepn, + stockcategory.adjglact as pldepn, + fixedassetlocations.locationdescription + FROM assetmanager + LEFT JOIN stockmaster + ON assetmanager.stockid=stockmaster.stockid + LEFT JOIN stockcategory + ON stockmaster.categoryid=stockcategory.categoryid + LEFT JOIN fixedassetlocations + ON fixedassetlocations.locationid=assetmanager.location'; + $result=DB_query($sql, $db); + $i=0; + while ($myrow=DB_fetch_array($result)) { + $assetarray[$i]=$myrow; + // Find depreciation type + $typesql='SELECT stockitemproperties.value + FROM stockitemproperties + LEFT JOIN stockcatproperties + ON stockcatproperties.stkcatpropid=stockitemproperties.stkcatpropid + WHERE stockitemproperties.stockid="'.$myrow['stockid'].'" + AND stockcatproperties.label="'._('Depreciation Type').'"'; + $typeresult=DB_query($typesql,$db); + $typerow=DB_fetch_array($typeresult); + $assetarray[$i]['DepreciationType']=$typerow['value']; + + // Find the depreciation rate + $ratesql='SELECT stockitemproperties.value + FROM stockitemproperties + LEFT JOIN stockcatproperties + ON stockcatproperties.stkcatpropid=stockitemproperties.stkcatpropid + WHERE stockitemproperties.stockid="'.$myrow['stockid'].'" + AND stockcatproperties.label="'._('Annual Depreciation Percentage').'"'; + $rateresult=DB_query($ratesql, $db); + $raterow=DB_fetch_array($rateresult); + $assetarray[$i]['DepreciationRate']=$raterow['value']; + + $bsnamesql='SELECT accountname FROM chartmaster WHERE accountcode='.$assetarray[$i]['bsdepn']; + $bsnameresult=DB_query($bsnamesql, $db); + $bsnamerow=DB_fetch_array($bsnameresult); + $assetarray[$i]['bsdepnaccount']=$bsnamerow['accountname']; + + $plnamesql='SELECT accountname FROM chartmaster WHERE accountcode='.$assetarray[$i]['pldepn']; + $plnameresult=DB_query($plnamesql, $db); + $plnamerow=DB_fetch_array($plnameresult); + $assetarray[$i]['pldepnaccount']=$plnamerow['accountname']; + + /* Need a method to correctly enter the journal date, + * and for it to be available to the depn calculation - Tim + */ + + if (isset($_POST['JournalProcessDate'])) { + $_SESSION['JournalDetail']->JnlDate=$_POST['JournalProcessDate']; + } + if (!Is_Date($_SESSION['JournalDetail']->JnlDate)){ + // Default the date to the last day of the previous month + $_SESSION['JournalDetail']->JnlDate = Date($_SESSION['DefaultDateFormat'],mktime(0,0,0,date('m'),0,date('Y'))); + } + + $NoOfMonths=DateDiff($_SESSION['JournalDetail']->JnlDate,FormatDateForSQL($assetarray[$i]['datepurchased']), 'm'); + if ($assetarray[$i]['DepreciationType']==_('Straight Line')) { + ... [truncated message content] |