- modules/fotolab updated imagej to current version & some cod fixes to make it work
[care2x.git] / Care2007 / modules / weberp / Stocks.php
bloba6946e9b0d19a395902b2c8673a8ad957fe9d2cd
1 <?php
3 /* $Revision: 1.37 $ */
5 $PageSecurity = 11;
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()
24 </script>
26 <?php
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');
48 $UploadTheFile ='No';
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');
51 $UploadTheFile ='No';
52 } elseif ( $_FILES['ItemPicture']['type'] == "text/plain" ) { //File Type Check
53 prnMsg( _('Only graphics files can be uploaded'),'warn');
54 $UploadTheFile ='No';
55 } elseif (file_exists($filename)){
56 prnMsg(_('Attempting to overwrite an existing item image'),'warn');
57 $result = unlink($filename);
58 if (!$result){
59 prnMsg(_('The existing image could not be removed'),'error');
60 $UploadTheFile ='No';
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
75 $InputError = 0;
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) {
83 $InputError = 1;
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) {
86 $InputError = 1;
87 prnMsg (_('The stock item description cannot be a zero length string') . ' - ' . _('a long description is required'),'error');
88 } elseif (strlen($StockID) ==0) {
89 $InputError = 1;
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,'"')) {
92 $InputError = 1;
93 prnMsg(_('The stock item code cannot contain any of the following characters') . " - ' & + \" \\ " . _('or a space'),'error');
95 } elseif (strlen($_POST['Units']) >20) {
96 $InputError = 1;
97 prnMsg(_('The unit of measure must be 20 characters or less long'),'error');
98 } elseif (strlen($_POST['BarCode']) >20) {
99 $InputError = 1;
100 prnMsg(_('The barcode must be 20 characters or less long'),'error');
101 } elseif (!is_numeric($_POST['Volume'])) {
102 $InputError = 1;
103 prnMsg (_('The volume of the packaged item in cubic metres must be numeric') ,'error');
104 } elseif ($_POST['Volume'] <0) {
105 $InputError = 1;
106 prnMsg(_('The volume of the packaged item must be a positive number'),'error');
107 } elseif (!is_numeric($_POST['KGS'])) {
108 $InputError = 1;
109 prnMsg(_('The weight of the packaged item in KGs must be numeric'),'error');
110 } elseif ($_POST['KGS'] <0) {
111 $InputError = 1;
112 prnMsg(_('The weight of the packaged item must be a positive number'),'error');
113 } elseif (!is_numeric($_POST['EOQ'])) {
114 $InputError = 1;
115 prnMsg(_('The economic order quantity must be numeric'),'error');
116 } elseif ($_POST['EOQ'] <0) {
117 $InputError = 1;
118 prnMsg (_('The economic order quantity must be a positive number'),'error');
119 }elseif ($_POST['Controlled']==0 AND $_POST['Serialised']==1){
120 $InputError = 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){
123 $InputError = 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'])==''){
126 $InputError = 1;
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,
141 controlled,
142 serialised
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){
157 $InputError=1;
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){
162 $InputError=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'
171 AND completed=0";
173 $result = DB_query($sql,$db);
174 $ChkSalesOrds = DB_fetch_row($result);
175 if ($ChkSalesOrds[0]!=0){
176 $InputError = 1;
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'
186 AND completed=0";
188 $result = DB_query($sql,$db);
189 $ChkPurchOrds = DB_fetch_row($result);
190 if ($ChkPurchOrds[0]!=0){
191 $InputError = 1;
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);
201 if ($ChkBOM[0]!=0){
202 $InputError = 1;
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);
212 if ($ChkBOM[0]!=0){
213 $InputError = 1;
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){
222 $InputError=1;
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){
227 $InputError=1;
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 . "'",
259 $db);
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;
267 } else {
268 $_POST['PropValue' . $i]=0;
271 $result = DB_query("INSERT INTO stockitemproperties (stockid,
272 stkcatpropid,
273 value)
274 VALUES ('" . $StockID . "',
275 " . $_POST['PropID' . $i] . ",
276 '" . $_POST['PropValue' . $i] . "')",
277 $db);
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');
288 exit;
289 } else {
290 $sql = "INSERT INTO stockmaster (
291 stockid,
292 description,
293 longdescription,
294 categoryid,
295 units,
296 mbflag,
297 eoq,
298 discontinued,
299 controlled,
300 serialised,
301 volume,
302 kgs,
303 barcode,
304 discountcategory,
305 taxcatid,
306 decimalplaces)
307 VALUES ('$StockID',
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,
331 stockid)
332 SELECT locations.loccode,
333 '" . $StockID . "'
334 FROM locations";
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']);
357 unset($StockID);
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
363 } else {
364 echo '<BR>';
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
371 $CancelDelete = 0;
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);
378 if ($myrow[0]>0) {
379 $CancelDelete = 1;
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');
383 } else {
384 $sql= "SELECT COUNT(*) FROM bom WHERE component='$StockID'";
385 $result = DB_query($sql,$db);
386 $myrow = DB_fetch_row($result);
387 if ($myrow[0]>0) {
388 $CancelDelete = 1;
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');
391 } else {
392 $sql= "SELECT COUNT(*) FROM salesorderdetails WHERE stkcode='$StockID'";
393 $result = DB_query($sql,$db);
394 $myrow = DB_fetch_row($result);
395 if ($myrow[0]>0) {
396 $CancelDelete = 1;
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');
399 } else {
400 $sql= "SELECT COUNT(*) FROM salesanalysis WHERE stockid='$StockID'";
401 $result = DB_query($sql,$db);
402 $myrow = DB_fetch_row($result);
403 if ($myrow[0]>0) {
404 $CancelDelete = 1;
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');
407 } else {
408 $sql= "SELECT COUNT(*) FROM purchorderdetails WHERE itemcode='$StockID'";
409 $result = DB_query($sql,$db);
410 $myrow = DB_fetch_row($result);
411 if ($myrow[0]>0) {
412 $CancelDelete = 1;
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');
415 } else {
416 $sql = "SELECT SUM(quantity) AS qoh FROM locstock WHERE stockid='$StockID'";
417 $result = DB_query($sql,$db);
418 $myrow = DB_fetch_row($result);
419 if ($myrow[0]!=0) {
420 $CancelDelete = 1;
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']);
471 unset($StockID);
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*/
487 $New = true;
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,
495 description,
496 longdescription,
497 categoryid,
498 units,
499 mbflag,
500 discontinued,
501 controlled,
502 serialised,
503 eoq,
504 volume,
505 kgs,
506 barcode,
507 discountcategory,
508 taxcatid,
509 decimalplaces
510 FROM stockmaster
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'];
559 } else {
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'])){
568 $_POST['EOQ']=0;
571 if ($_POST['Volume']=='' OR !isset($_POST['Volume'])){
572 $_POST['Volume']=0;
574 if ($_POST['KGS']=='' OR !isset($_POST['KGS'])){
575 $_POST['KGS']=0;
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'];
606 } else {
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');
616 } else {
617 echo '<OPTION VALUE="A">' . _('Assembly');
619 if ($_POST['MBFlag']=='K'){
620 echo '<OPTION SELECTED VALUE="K">' . _('Kit');
621 } else {
622 echo '<OPTION VALUE="K">' . _('Kit');
624 if ($_POST['MBFlag']=='M'){
625 echo '<OPTION SELECTED VALUE="M">' . _('Manufactured');
626 } else {
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');
631 } else {
632 echo '<OPTION VALUE="B">' . _('Purchased');
635 if ($_POST['MBFlag']=='D'){
636 echo '<OPTION SELECTED VALUE="D">' . _('Service');
637 } else {
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');
646 } else {
647 echo '<OPTION VALUE=0>' . _('Current');
649 if ($_POST['Discontinued']==1){
650 echo '<OPTION SELECTED VALUE=1>' . _('Obsolete');
651 } else {
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');
660 } else {
661 echo '<OPTION VALUE=0>' . _('No Control');
663 if ($_POST['Controlled']==1){
664 echo '<OPTION SELECTED VALUE=1>' . _('Controlled');
665 } else {
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');
674 } else {
675 echo '<OPTION VALUE=0>' . _('No');
677 if ($_POST['Serialised']==1){
678 echo '<OPTION SELECTED VALUE=1>' . _('Yes');
679 } else {
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'];
701 } else {
702 echo '<OPTION VALUE=' . $myrow['taxcatid'] . '>' . $myrow['taxcatname'];
704 } //end while loop
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).
711 '&text='.
712 '&width=64'.
713 '&height=64'.
714 '" >';
715 } else {
716 if( file_exists($_SESSION['part_pics_dir'] . '/' .$StockID.'.jpg') ) {
717 $StockImgLink = '<img src="' . $_SESSION['part_pics_dir'] . '/' .$StockID.'.jpg" >';
718 } else {
719 $StockImgLink = _('No Image');
723 echo '</table></td><td><center>' . _('Image') . '<br>'.$StockImgLink . '</center></td></tr></table><center>';
726 if ($New) {
727 echo '<input type="Submit" name="submit" value="' . _('Insert New Item') . '">';
729 } else {
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,
734 label,
735 controltype,
736 defaultvalue
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
749 stockitemproperties
750 WHERE stockid='" . $StockID . "'
751 AND stkcatpropid =" . $PropertyRow['stkcatpropid'],
752 $db);
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>
759 <td>';
760 switch ($PropertyRow['controltype']) {
761 case 0; //textbox
762 echo '<input type="textbox" name="PropValue' . $PropertyCounter . '" size="20" maxlength="100" value="' . $PropertyValue . '">';
763 break;
764 case 1; //select box
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>';
770 } else {
771 echo '<option value="' . $PropertyOptionValue . '">' . $PropertyOptionValue . '</option>';
774 echo '</select>';
775 break;
776 case 2; //checkbox
777 echo '<input type="checkbox" name="PropValue' . $PropertyCounter . '"';
778 if ($PropertyValue==1){
779 echo '"checked"';
781 echo '>';
782 break;
783 } //end switch
784 echo '<input type="hidden" name="PropType' . $PropertyCounter .'" value=' . $PropertyRow['controltype'] . '>';
785 echo '</td></tr>';
786 $PropertyCounter++;
787 } //end loop round properties for the item category
788 echo '</table>';
789 echo '<input type="hidden" name="PropertyCounter" value=' . $PropertyCounter . '>';
791 echo '<input type="submit" name="submit" value="' . _('Update') . '">';
792 echo '<P>';
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');