3 /* $Revision: 1.37 $ */
7 include('includes/session.inc');
8 $title = _('Item Maintenance');
9 include('includes/header.inc');
13 <script type
="text/javascript">
14 function ReloadForm ()
16 document
.getElementById("submit").value
= "TEST"
17 var stockid
=document
.getElementById("StockID").value
18 if (stockid
.length
> 1)
20 document
.getElementById("submit").value
= "TEST"
21 document
.getElementById("ItemForm").submit()
28 echo "<A HREF='" . $rootpath . '/SelectProduct.php?' . SID
. "'>" . _('Back to Items') . '</A><BR>';
31 /*If this form is called with the StockID then it is assumed that the stock item is to be modified */
33 if (isset($_GET['StockID'])){
34 $StockID =trim(strtoupper($_GET['StockID']));
35 } elseif (isset($_POST['StockID'])){
36 $StockID =trim(strtoupper($_POST['StockID']));
39 if (isset($_FILES['ItemPicture']) AND $_FILES['ItemPicture']['name'] !='') {
41 $result = $_FILES['ItemPicture']['error'];
42 $UploadTheFile = 'Yes'; //Assume all is well to start off with
43 $filename = $_SESSION['part_pics_dir'] . '/' . $StockID . '.jpg';
45 //But check for the worst
46 if (strtoupper(substr(trim($_FILES['ItemPicture']['name']),strlen($_FILES['ItemPicture']['name'])-3))!='JPG'){
47 prnMsg(_('Only jpg files are supported - a file extension of .jpg is expected'),'warn');
49 } elseif ( $_FILES['ItemPicture']['size'] > ($_SESSION['MaxImageSize']*1024)) { //File Size Check
50 prnMsg(_('The file size is over the maximum allowed. The maximum size allowed in KB is') . ' ' . $_SESSION['MaxImageSize'],'warn');
52 } elseif ( $_FILES['ItemPicture']['type'] == "text/plain" ) { //File Type Check
53 prnMsg( _('Only graphics files can be uploaded'),'warn');
55 } elseif (file_exists($filename)){
56 prnMsg(_('Attempting to overwrite an existing item image'),'warn');
57 $result = unlink($filename);
59 prnMsg(_('The existing image could not be removed'),'error');
64 if ($UploadTheFile=='Yes'){
65 $result = move_uploaded_file($_FILES['ItemPicture']['tmp_name'], $filename);
66 $message = ($result)?
_('File url') ."<a href='". $filename ."'>" . $filename . '</a>' : _('Something is wrong with uploading a file');
68 /* EOR Add Image upload for New Item - by Ori */
72 if (isset($_POST['submit'])) {
74 //initialise no input errors assumed initially before we test
77 /* actions to take once the user has clicked the submit button
78 ie the page has called itself with some user input */
80 //first off validate inputs sensible
82 if (strlen($_POST['Description']) > 50 OR strlen($_POST['Description'])==0) {
84 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');
85 } elseif (strlen($_POST['LongDescription'])==0) {
87 prnMsg (_('The stock item description cannot be a zero length string') . ' - ' . _('a long description is required'),'error');
88 } elseif (strlen($StockID) ==0) {
90 prnMsg (_('The Stock Item code cannot be empty'),'error');
91 }elseif (strstr($StockID,' ') OR strstr($StockID,"'") OR strstr($StockID,'+') OR strstr($StockID,"\\") OR strstr($StockID,"\"") OR strstr($StockID,'&') OR strstr($StockID,'.') OR strstr($StockID,'"')) {
93 prnMsg(_('The stock item code cannot contain any of the following characters') . " - ' & + \" \\ " . _('or a space'),'error');
95 } elseif (strlen($_POST['Units']) >20) {
97 prnMsg(_('The unit of measure must be 20 characters or less long'),'error');
98 } elseif (strlen($_POST['BarCode']) >20) {
100 prnMsg(_('The barcode must be 20 characters or less long'),'error');
101 } elseif (!is_numeric($_POST['Volume'])) {
103 prnMsg (_('The volume of the packaged item in cubic metres must be numeric') ,'error');
104 } elseif ($_POST['Volume'] <0) {
106 prnMsg(_('The volume of the packaged item must be a positive number'),'error');
107 } elseif (!is_numeric($_POST['KGS'])) {
109 prnMsg(_('The weight of the packaged item in KGs must be numeric'),'error');
110 } elseif ($_POST['KGS'] <0) {
112 prnMsg(_('The weight of the packaged item must be a positive number'),'error');
113 } elseif (!is_numeric($_POST['EOQ'])) {
115 prnMsg(_('The economic order quantity must be numeric'),'error');
116 } elseif ($_POST['EOQ'] <0) {
118 prnMsg (_('The economic order quantity must be a positive number'),'error');
119 }elseif ($_POST['Controlled']==0 AND $_POST['Serialised']==1){
121 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');
122 } elseif (($_POST['MBFlag']=='A' OR $_POST['MBFlag']=='K' OR $_POST['MBFlag']=='D') AND $_POST['Controlled']==1){
124 prnMsg(_('Assembly/Kitset/Service items cannot also be controlled items') . '. ' . _('Assemblies/Dummies and Kitsets are not physical items and batch/serial control is therefore not appropriate'),'error');
125 } elseif (trim($_POST['CategoryID'])==''){
127 prnMsg(_('There are no inventory categories defined. All inventory items must belong to a valid inventory category,'),'error');
130 if ($InputError !=1){
131 if ($_POST['Serialised']==1){ /*Not appropriate to have several dp on serial items */
132 $_POST['DecimalPlaces']=0;
134 if (!isset($_POST['New'])) { /*so its an existing one */
136 /*first check on the changes being made we must disallow:
137 - changes from manufactured or purchased to Service, Assembly or Kitset if there is stock - changes from manufactured, kitset or assembly where a BOM exists
140 $sql = "SELECT mbflag,
143 FROM stockmaster WHERE stockid = '$StockID'";
144 $MBFlagResult = DB_query($sql,$db);
145 $myrow = DB_fetch_row($MBFlagResult);
146 $OldMBFlag = $myrow[0];
147 $OldControlled = $myrow[1];
148 $OldSerialised = $myrow[2];
150 $sql = "SELECT SUM(locstock.quantity) FROM locstock WHERE stockid='$StockID'";
151 $result = DB_query($sql,$db);
152 $stkqtychk = DB_fetch_row($result);
154 if ($OldMBFlag != $_POST['MBFlag']){
155 if (($OldMBFlag == 'M' OR $OldMBFlag=='B') AND ($_POST['MBFlag']=='A' OR $_POST['MBFlag']=='K' OR $_POST['MBFlag']=='D')){ /*then need to check that there is no stock holding first */
156 if ($stkqtychk[0]!=0){
158 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');
161 if ($_POST['Controlled']==1){
163 prnMsg( _('The make or buy flag cannot be changed from') . ' ' . $OldMBFlag . ' ' . _('to') . ' ' . $_POST['MBFlag'] . ' ' . _('where the item is to be lot controlled') . '. ' . _('Kitset, dummy and assembly items cannot be lot controlled'), 'error');
166 /*now check that if the item is being changed to a kitset, there are no items on order sales or purchase orders*/
167 if ($_POST['MBFlag']=='K') {
168 $sql = "SELECT quantity-qtyinvoiced
169 FROM salesorderdetails
170 WHERE stkcode = '$StockID'
173 $result = DB_query($sql,$db);
174 $ChkSalesOrds = DB_fetch_row($result);
175 if ($ChkSalesOrds[0]!=0){
177 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');
180 /*now check that if it is to be a kitset or assembly or dummy there is no quantity on purchase orders outstanding*/
181 if ($_POST['MBFlag']=='K' OR $_POST['MBFlag']=='A' OR $_POST['MBFlag']=='D') {
183 $sql = "SELECT quantityord-quantityrecd
184 FROM purchorderdetails
185 WHERE itemcode = '$StockID'
188 $result = DB_query($sql,$db);
189 $ChkPurchOrds = DB_fetch_row($result);
190 if ($ChkPurchOrds[0]!=0){
192 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');
195 /*now check that if it is was a Manufactured, Kitset or Assembly and is being changed to a purchased or dummy - that no BOM exists */
197 if (($OldMBFlag=='M' OR $OldMBFlag =='K' OR $OldMBFlag=='A') AND ($_POST['MBFlag']=='B' OR $_POST['MBFlag']=='D')) {
198 $sql = "SELECT COUNT(*) FROM bom WHERE parent = '$StockID'";
199 $result = DB_query($sql,$db);
200 $ChkBOM = DB_fetch_row($result);
203 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');
207 /*now check that if it was Manufac or Purchased and is being changed to assembly or kitset, it is not a component on an existing BOM */
208 if (($OldMBFlag=='M' OR $OldMBFlag =='B' OR $OldMBFlag=='D') AND ($_POST['MBFlag']=='A' OR $_POST['MBFlag']=='K')) {
209 $sql = "SELECT COUNT(*) FROM bom WHERE component = '$StockID'";
210 $result = DB_query($sql,$db);
211 $ChkBOM = DB_fetch_row($result);
214 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 componennts in a bill of materials'), 'error');
219 /* Do some checks for changes in the Serial & Controlled setups */
221 if ($OldControlled != $_POST['Controlled'] AND $stkqtychk[0]!=0){
223 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');
226 if ($OldSerialised != $_POST['Serialised'] AND $stkqtychk[0]!=0){
228 prnMsg( _('You can not change a Serialised Item to Non-Serialised (or visa-versa) when there is a quantity on hand for the item') , 'error');
232 if ($InputError == 0){
233 $sql = "UPDATE stockmaster
234 SET longdescription='" . DB_escape_string($_POST['LongDescription']) . "',
235 description='" . DB_escape_string($_POST['Description']) . "',
236 discontinued=" . $_POST['Discontinued'] . ",
237 controlled=" . $_POST['Controlled'] . ",
238 serialised=" . $_POST['Serialised'].",
239 categoryid='" . $_POST['CategoryID'] . "',
240 units='" . DB_escape_string($_POST['Units']) . "',
241 mbflag='" . $_POST['MBFlag'] . "',
242 eoq=" . $_POST['EOQ'] . ",
243 volume=" . $_POST['Volume'] . ",
244 kgs=" . $_POST['KGS'] . ",
245 barcode='" . $_POST['BarCode'] . "',
246 discountcategory='" . $_POST['DiscountCategory'] . "',
247 taxcatid=" . $_POST['TaxCat'] . ",
248 decimalplaces=" . $_POST['DecimalPlaces'] . "
249 WHERE stockid='$StockID'";
252 $ErrMsg = _('The stock item could not be updated because');
253 $DbgMsg = _('The SQL that was used to update the stock item and failed was');
254 $result = DB_query($sql,$db,$ErrMsg,$DbgMsg);
256 //delete any properties for the item no longer relevant with the change of category
257 $result = DB_query("DELETE FROM stockitemproperties
258 WHERE stockid ='" . $StockID . "'",
261 //now insert any item properties
262 for ($i=0;$i<$_POST['PropertyCounter'];$i++
){
264 if ($_POST['PropType' . $i] ==2){
265 if ($_POST['PropValue' . $i]=='on'){
266 $_POST['PropValue' . $i]=1;
268 $_POST['PropValue' . $i]=0;
271 $result = DB_query("INSERT INTO stockitemproperties (stockid,
274 VALUES ('" . $StockID . "',
275 " . $_POST['PropID' . $i] . ",
276 '" . $_POST['PropValue' . $i] . "')",
278 } //end of loop around properties defined for the category
279 prnMsg( _('Stock Item') . ' ' . $StockID . ' ' . _('has been updated'), 'success');
282 } else { //it is a NEW part
284 //but lets be really sure here
285 $result = DB_query("SELECT stockid FROM stockmaster WHERE stockid='" . $StockID ."'",$db);
286 if (DB_num_rows($result)==1){
287 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');
290 $sql = "INSERT INTO stockmaster (
308 '" . DB_escape_string($_POST['Description']) . "',
309 '" . DB_escape_string($_POST['LongDescription']) . "',
310 '" . $_POST['CategoryID'] . "',
311 '" . DB_escape_string($_POST['Units']) . "',
312 '" . $_POST['MBFlag'] . "',
313 " . $_POST['EOQ'] . ",
314 " . $_POST['Discontinued'] . ",
315 " . $_POST['Controlled'] . ",
316 " . $_POST['Serialised']. ",
317 " . $_POST['Volume'] . ",
318 " . $_POST['KGS'] . ",
319 '" . $_POST['BarCode'] . "',
320 '" . $_POST['DiscountCategory'] . "',
321 " . $_POST['TaxCat'] . ",
322 " . $_POST['DecimalPlaces']. "
325 $ErrMsg = _('The item could not be added because');
326 $DbgMsg = _('The SQL that was used to add the item failed was');
327 $result = DB_query($sql,$db, $ErrMsg, $DbgMsg);
328 if (DB_error_no($db) ==0) {
330 $sql = "INSERT INTO locstock (loccode,
332 SELECT locations.loccode,
336 $ErrMsg = _('The locations for the item') . ' ' . $myrow[0] . ' ' . _('could not be added because');
337 $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');
338 $InsResult = DB_query($sql,$db,$ErrMsg,$DbgMsg);
340 if (DB_error_no($db) ==0) {
341 prnMsg( _('New Item') .' ' . $StockID . ' '. _('has been added to the database'),'success');
342 unset($_POST['LongDescription']);
343 unset($_POST['Description']);
344 unset($_POST['EOQ']);
345 unset($_POST['CategoryID']);
346 unset($_POST['Units']);
347 unset($_POST['MBFlag']);
348 unset($_POST['Discontinued']);
349 unset($_POST['Controlled']);
350 unset($_POST['Serialised']);
351 unset($_POST['Volume']);
352 unset($_POST['KGS']);
353 unset($_POST['BarCode']);
354 unset($_POST['ReorderLevel']);
355 unset($_POST['DiscountCategory']);
356 unset($_POST['DecimalPlaces']);
358 }//ALL WORKED SO RESET THE FORM VARIABLES
359 }//THE INSERT OF THE NEW CODE WORKED SO BANG IN THE STOCK LOCATION RECORDS TOO
360 }//END CHECK FOR ALREADY EXISTING ITEM OF THE SAME CODE
365 prnMsg( _('Validation failed, no updates or deletes took place'), 'error');
368 } elseif (isset($_POST['delete']) AND strlen($_POST['delete']) >1 ) {
369 //the button to delete a selected record was clicked instead of the submit button
373 // PREVENT DELETES IF DEPENDENT RECORDS IN 'StockMoves'
375 $sql= "SELECT COUNT(*) FROM stockmoves WHERE stockid='$StockID'";
376 $result = DB_query($sql,$db);
377 $myrow = DB_fetch_row($result);
380 prnMsg( _('Cannot delete this stock item because there are stock movements that refer to this item'),'warn');
381 echo '<BR>' . _('There are') . ' ' . $myrow[0] . ' ' . _('stock movements that refer to this item');
384 $sql= "SELECT COUNT(*) FROM bom WHERE component='$StockID'";
385 $result = DB_query($sql,$db);
386 $myrow = DB_fetch_row($result);
389 prnMsg( _('Cannot delete this item record because there are bills of material that require this part as a component'),'warn');
390 echo '<br>' . _('There are') . ' ' . $myrow[0] . ' ' . _('bills of material that require this part as a component');
392 $sql= "SELECT COUNT(*) FROM salesorderdetails WHERE stkcode='$StockID'";
393 $result = DB_query($sql,$db);
394 $myrow = DB_fetch_row($result);
397 prnMsg( _('Cannot delete this item record because there are existing sales orders for this part'),'warn');
398 echo '<BR>' . _('There are') . ' ' . $myrow[0] . ' ' . _('sales order items against this part');
400 $sql= "SELECT COUNT(*) FROM salesanalysis WHERE stockid='$StockID'";
401 $result = DB_query($sql,$db);
402 $myrow = DB_fetch_row($result);
405 prnMsg(_('Cannot delete this item because sales analysis records exist for it'),'warn');
406 echo '<BR>' . _('There are') . ' ' . $myrow[0] . ' ' . _('sales analysis records against this part');
408 $sql= "SELECT COUNT(*) FROM purchorderdetails WHERE itemcode='$StockID'";
409 $result = DB_query($sql,$db);
410 $myrow = DB_fetch_row($result);
413 prnMsg(_('Cannot delete this item because there are existing purchase order items for it'),'warn');
414 echo '<BR>' . _('There are') . ' ' . $myrow[0] . ' ' . _('purchase order item record relating to this part');
416 $sql = "SELECT SUM(quantity) AS qoh FROM locstock WHERE stockid='$StockID'";
417 $result = DB_query($sql,$db);
418 $myrow = DB_fetch_row($result);
421 prnMsg( _('Cannot delete this item because there is currently some stock on hand'),'warn');
422 echo '<BR>' . _('There are') . ' ' . $myrow[0] . ' ' . _('on hand for this part');
430 if ($CancelDelete==0) {
431 $result = DB_query('BEGIN', $db);
433 /*Deletes LocStock records*/
434 $sql ="DELETE FROM locstock WHERE stockid='$StockID'";
435 $result=DB_query($sql,$db,_('Could not delete the location stock records because'),'',true);
436 /*Deletes Price records*/
437 $sql ="DELETE FROM prices WHERE stockid='$StockID'";
438 $result=DB_query($sql,$db,_('Could not delete the prices for this stock record because'),'',true);
439 /*and cascade deletes in PurchData */
440 $sql ="DELETE FROM purchdata WHERE stockid='$StockID'";
441 $result=DB_query($sql,$db,_('Could not delete the purchasing data because'),'',true);
442 /*and cascade delete the bill of material if any */
443 $sql = "DELETE FROM bom WHERE parent='$StockID'";
444 $result=DB_query($sql,$db,_('Could not delete the bill of material because'),'',true);
445 $sql="DELETE FROM stockmaster WHERE stockid='$StockID'";
446 $result=DB_query($sql,$db, _('Could not delete the item record'),'',true);
448 $result = DB_query('COMMIT', $db);
450 prnMsg(_('Deleted the stock master record for') . ' ' . $StockID . '....' .
451 '<BR>. . ' . _('and all the location stock records set up for the part') .
452 '<BR>. . .' . _('and any bill of material that may have been set up for the part') .
453 '<BR> . . . .' . _('and any purchasing data that may have been set up for the part') .
454 '<BR> . . . . .' . _('and any prices that may have been set up for the part'),'success');
455 unset($_POST['LongDescription']);
456 unset($_POST['Description']);
457 unset($_POST['EOQ']);
458 unset($_POST['CategoryID']);
459 unset($_POST['Units']);
460 unset($_POST['MBFlag']);
461 unset($_POST['Discontinued']);
462 unset($_POST['Controlled']);
463 unset($_POST['Serialised']);
464 unset($_POST['Volume']);
465 unset($_POST['KGS']);
466 unset($_POST['BarCode']);
467 unset($_POST['ReorderLevel']);
468 unset($_POST['DiscountCategory']);
469 unset($_POST['TaxCat']);
470 unset($_POST['DecimalPlaces']);
472 unset($_SESSION['SelectedStockItem']);
473 //echo "<META HTTP-EQUIV='Refresh' CONTENT='0; URL=" . $rootpath . '/SelectProduct.php?' . SID ."'>";
476 } //end if Delete Part
480 echo '<form name="ItemForm" enctype="multipart/form-data" method="post" action="' . $_SERVER['PHP_SELF'] . '?' .SID
.'"><center><table>
481 <tr><td><table>'; //Nested table
483 if (!isset($StockID)) {
485 /*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*/
488 echo '<input type="hidden" name="New" value="1">';
490 echo '<TR><TD>'. _('Item Code'). ':</TD><TD><INPUT TYPE="TEXT" NAME="StockID" SIZE=21 MAXLENGTH=20></TD></TR>';
492 } elseif (!isset($_POST['submit'])) { // Must be modifying an existing item and no changes made yet
494 $sql = "SELECT stockid,
511 WHERE stockid = '$StockID'";
513 $result = DB_query($sql, $db);
514 $myrow = DB_fetch_array($result);
516 $_POST['LongDescription'] = $myrow['longdescription'];
517 $_POST['Description'] = $myrow['description'];
518 $_POST['EOQ'] = $myrow['eoq'];
519 $_POST['CategoryID'] = $myrow['categoryid'];
520 $_POST['Units'] = $myrow['units'];
521 $_POST['MBFlag'] = $myrow['mbflag'];
522 $_POST['Discontinued'] = $myrow['discontinued'];
523 $_POST['Controlled'] = $myrow['controlled'];
524 $_POST['Serialised'] = $myrow['serialised'];
525 $_POST['Volume'] = $myrow['volume'];
526 $_POST['KGS'] = $myrow['kgs'];
527 $_POST['BarCode'] = $myrow['barcode'];
528 $_POST['DiscountCategory'] = $myrow['discountcategory'];
529 $_POST['TaxCat'] = $myrow['taxcatid'];
530 $_POST['DecimalPlaces'] = $myrow['decimalplaces'];
532 echo '<TR><TD>' . _('Item Code') . ':</TD><TD>'.$StockID.'</TD></TR>';
533 echo "<input type='Hidden' name='StockID' value='$StockID'>";
535 } else { // some changes were made to the data so don't re-set form variables to DB ie the code above
536 echo '<TR><TD>' . _('Item Code') . ':</TD><TD>'.$StockID.'</TD></TR>';
537 echo "<input type='Hidden' name='StockID' value='$StockID'>";
541 echo '<TR><TD>' . _('Part Description') . ' (' . _('short') . '):</TD><TD><input type="Text" name="Description" SIZE=52 MAXLENGTH=50 value="' . htmlentities($_POST['Description'],ENT_QUOTES
,_('ISO-8859-1')) . '"></TD></TR>';
543 echo '<TR><TD>' . _('Part Description') . ' (' . _('long') . '):</TD><TD><textarea name="LongDescription" cols=40 rows=4>' . htmlentities($_POST['LongDescription'],ENT_QUOTES
,_('ISO-8859-1')) . '</textarea></TD></TR>';
545 // Add image upload for New Item - by Ori
546 echo '<tr><td>'. _('Image File (.jpg)') . ':</td><td><input type="file" id="ItemPicture" name="ItemPicture"></td></tr>';
547 // EOR Add Image upload for New Item - by Ori
549 echo '<tr><td>' . _('Category') . ':</td><td><select name="CategoryID" onChange="ReloadForm();">';
551 $sql = "SELECT categoryid, categorydescription FROM stockcategory";
552 $ErrMsg = _('The stock categories could not be retrieved because');
553 $DbgMsg = _('The SQL used to retrieve stock categories and failed was');
554 $result = DB_query($sql,$db,$ErrMsg,$DbgMsg);
556 while ($myrow=DB_fetch_array($result)){
557 if ($myrow['categoryid']==$_POST['CategoryID']){
558 echo '<OPTION SELECTED VALUE="'. $myrow['categoryid'] . '">' . $myrow['categorydescription'];
560 echo '<OPTION VALUE="'. $myrow['categoryid'] . '">' . $myrow['categorydescription'];
564 echo '</select><a target="_blank" href="'. $rootpath . '/StockCategories.php?' . SID
. '">' . _('Add or Modify Stock Categories') . '</a></td></tr>';
567 if ($_POST['EOQ']=='' or !isset($_POST['EOQ'])){
571 if ($_POST['Volume']=='' OR !isset($_POST['Volume'])){
574 if ($_POST['KGS']=='' OR !isset($_POST['KGS'])){
577 if ($_POST['Controlled']=='' OR !isset($_POST['Controlled'])){
578 $_POST['Controlled']=0;
580 if ($_POST['Serialised']=='' OR !isset($_POST['Serialised']) ||
$_POST['Controlled']==0){
581 $_POST['Serialised']=0;
583 if ($_POST['DecimalPlaces']=='' OR !isset($_POST['DecimalPlaces'])){
584 $_POST['DecimalPlaces']=0;
586 if ($_POST['Discontinued']=='' OR !isset($_POST['Discontinued'])){
587 $_POST['Discontinued']=0;
591 echo '<TR><TD>' . _('Economic Order Quantity') . ':</TD><TD><input type="Text" name="EOQ" SIZE=12 MAXLENGTH=10 Value="' . $_POST['EOQ'] . '"></TD></TR>';
593 echo '<TR><TD>' . _('Packaged Volume (metres cubed)') . ':</TD><TD><input type="Text" name="Volume" SIZE=12 MAXLENGTH=10 value="' . $_POST['Volume'] . '"></TD></TR>';
595 echo '<TR><TD>' . _('Packaged Weight (KGs)') . ':</TD><TD><input type="Text" name="KGS" SIZE=12 MAXLENGTH=10 value="' . $_POST['KGS'] . '"></TD></TR>';
597 echo '<TR><TD>' . _('Units of Measure') . ':</TD><TD><SELECT name="Units">';
600 $sql = 'SELECT unitname FROM unitsofmeasure ORDER by unitname';
601 $UOMResult = DB_query($sql,$db);
603 while( $UOMrow = DB_fetch_array($UOMResult) ) {
604 if ($_POST['Units']==$UOMrow['unitname']){
605 echo "<OPTION SELECTED Value='" . $UOMrow['unitname'] . "'>" . $UOMrow['unitname'];
607 echo "<OPTION Value='" . $UOMrow['unitname'] . "'>" . $UOMrow['unitname'];
611 echo '</SELECT></TD></TR>';
613 echo '<TR><TD>' . _('Make, Buy, Kit, Assembly or Service Part') . ':</TD><TD><SELECT name="MBFlag">';
614 if ($_POST['MBFlag']=='A'){
615 echo '<OPTION SELECTED VALUE="A">' . _('Assembly');
617 echo '<OPTION VALUE="A">' . _('Assembly');
619 if ($_POST['MBFlag']=='K'){
620 echo '<OPTION SELECTED VALUE="K">' . _('Kit');
622 echo '<OPTION VALUE="K">' . _('Kit');
624 if ($_POST['MBFlag']=='M'){
625 echo '<OPTION SELECTED VALUE="M">' . _('Manufactured');
627 echo '<OPTION VALUE="M">' . _('Manufactured');
629 if ($_POST['MBFlag']=='B' OR !isset($_POST['MBFlag']) OR $_POST['MBFlag']==''){
630 echo '<OPTION SELECTED VALUE="B">' . _('Purchased');
632 echo '<OPTION VALUE="B">' . _('Purchased');
635 if ($_POST['MBFlag']=='D'){
636 echo '<OPTION SELECTED VALUE="D">' . _('Service');
638 echo '<OPTION VALUE="D">' . _('Service');
641 echo '</SELECT></TD></TR>';
643 echo '<TR><TD>' . _('Current or Obsolete') . ':</TD><TD><SELECT name="Discontinued">';
644 if ($_POST['Discontinued']==0){
645 echo '<OPTION SELECTED VALUE=0>' . _('Current');
647 echo '<OPTION VALUE=0>' . _('Current');
649 if ($_POST['Discontinued']==1){
650 echo '<OPTION SELECTED VALUE=1>' . _('Obsolete');
652 echo '<OPTION VALUE=1>' . _('Obsolete');
654 echo '</SELECT></TD></TR>';
656 echo '<TR><TD>' . _('Batch, Serial or Lot Control') . ':</TD><TD><SELECT name="Controlled">';
658 if ($_POST['Controlled']==0){
659 echo '<OPTION SELECTED VALUE=0>' . _('No Control');
661 echo '<OPTION VALUE=0>' . _('No Control');
663 if ($_POST['Controlled']==1){
664 echo '<OPTION SELECTED VALUE=1>' . _('Controlled');
666 echo "<OPTION VALUE=1>" . _('Controlled');
668 echo '</SELECT></TD></TR>';
670 echo '<TR><TD>' . _('Serialised') . ':</TD><TD><SELECT name="Serialised">';
672 if ($_POST['Serialised']==0){
673 echo '<OPTION SELECTED VALUE=0>' . _('No');
675 echo '<OPTION VALUE=0>' . _('No');
677 if ($_POST['Serialised']==1){
678 echo '<OPTION SELECTED VALUE=1>' . _('Yes');
680 echo '<OPTION VALUE=1>' . _('Yes');
682 echo '</SELECT><i>' . _('Note') . ', ' . _('this has no effect if the item is not Controlled') . '</i></TD></TR>';
684 echo '<TR><TD>' . _('Decimal Places to Display') . ':</TD><TD><input type="Text" name="DecimalPlaces" SIZE=1 MAXLENGTH=1 value="' . $_POST['DecimalPlaces'] . '"><TD></TR>';
686 echo '<TR><TD>' . _('Bar Code') . ':</TD><TD><input type="Text" name="BarCode" SIZE=22 MAXLENGTH=20 value="' . $_POST['BarCode'] . '"></TD></TR>';
688 echo '<TR><TD>' . _('Discount Category') . ':</TD><TD><input type="Text" name="DiscountCategory" SIZE=2 MAXLENGTH=2 value="' . $_POST['DiscountCategory'] . '"></TD></TR>';
690 echo '<TR><TD>' . _('Tax Category') . ':</TD><TD><SELECT NAME="TaxCat">';
691 $sql = 'SELECT taxcatid, taxcatname FROM taxcategories ORDER BY taxcatname';
692 $result = DB_query($sql, $db);
694 if (!isset($_POST['TaxCat'])){
695 $_POST['TaxCat'] = $_SESSION['DefaultTaxCategory'];
698 while ($myrow = DB_fetch_array($result)) {
699 if ($_POST['TaxCat'] == $myrow['taxcatid']){
700 echo '<OPTION SELECTED VALUE=' . $myrow['taxcatid'] . '>' . $myrow['taxcatname'];
702 echo '<OPTION VALUE=' . $myrow['taxcatid'] . '>' . $myrow['taxcatname'];
706 echo '</SELECT></TD></TR>';
708 if (function_exists('imagecreatefrompng')){
709 $StockImgLink = '<img src="GetStockImage.php?SID&automake=1&textcolor=FFFFFF&bgcolor=CCCCCC'.
710 '&StockID='.urlencode($StockID).
716 if( file_exists($_SESSION['part_pics_dir'] . '/' .$StockID.'.jpg') ) {
717 $StockImgLink = '<img src="' . $_SESSION['part_pics_dir'] . '/' .$StockID.'.jpg" >';
719 $StockImgLink = _('No Image');
723 echo '</table></td><td><center>' . _('Image') . '<br>'.$StockImgLink . '</center></td></tr></table><center>';
727 echo '<input type="Submit" name="submit" value="' . _('Insert New Item') . '">';
731 // Now the form to enter the item properties
732 echo '<table><tr><td class="tableheader" colspan="2">' . _('Item Category Properties') . '</td></tr>';
733 $sql = "SELECT stkcatpropid,
737 FROM stockcatproperties
738 WHERE categoryid ='" . DB_escape_string($_POST['CategoryID']) . "'
739 AND reqatsalesorder =0
740 ORDER BY stkcatpropid";
742 $PropertiesResult = DB_query($sql,$db);
743 $PropertyCounter = 0;
744 $PropertyWidth = array();
746 while ($PropertyRow=DB_fetch_array($PropertiesResult)){
748 $PropValResult = DB_query("SELECT value FROM
750 WHERE stockid='" . $StockID . "'
751 AND stkcatpropid =" . $PropertyRow['stkcatpropid'],
753 $PropValRow = DB_fetch_row($PropValResult);
754 $PropertyValue = $PropValRow[0];
756 echo '<input type="hidden" name="PropID' . $PropertyCounter . '" value=' .$PropertyRow['stkcatpropid'] .'>';
758 echo '<tr><td>' . $PropertyRow['label'] . '</td>
760 switch ($PropertyRow['controltype']) {
762 echo '<input type="textbox" name="PropValue' . $PropertyCounter . '" size="20" maxlength="100" value="' . $PropertyValue . '">';
765 $OptionValues = explode(',',$PropertyRow['defaultvalue']);
766 echo '<select name="PropValue' . $PropertyCounter . '">';
767 foreach ($OptionValues as $PropertyOptionValue){
768 if ($PropertyOptionValue == $PropertyValue){
769 echo '<option selected value="' . $PropertyOptionValue . '">' . $PropertyOptionValue . '</option>';
771 echo '<option value="' . $PropertyOptionValue . '">' . $PropertyOptionValue . '</option>';
777 echo '<input type="checkbox" name="PropValue' . $PropertyCounter . '"';
778 if ($PropertyValue==1){
784 echo '<input type="hidden" name="PropType' . $PropertyCounter .'" value=' . $PropertyRow['controltype'] . '>';
787 } //end loop round properties for the item category
789 echo '<input type="hidden" name="PropertyCounter" value=' . $PropertyCounter . '>';
791 echo '<input type="submit" name="submit" value="' . _('Update') . '">';
793 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'));
794 echo '<P><input type="Submit" name="delete" value="' . _('Delete This Item') . '" onclick="return confirm(\'' . _('Are You Sure?') . '\');">';
797 echo '</FORM></CENTER>';
798 include('includes/footer.inc');