From: <dai...@us...> - 2012-04-24 09:46:09
|
Revision: 5277 http://web-erp.svn.sourceforge.net/web-erp/?rev=5277&view=rev Author: daintree Date: 2012-04-24 09:45:59 +0000 (Tue, 24 Apr 2012) Log Message: ----------- insert of blank item code fixed Modified Paths: -------------- trunk/CopyBOM.php trunk/Labels.php trunk/companies/weberpdemo/reportwriter/labels.xml trunk/doc/Change.log Modified: trunk/CopyBOM.php =================================================================== --- trunk/CopyBOM.php 2012-04-23 03:06:00 UTC (rev 5276) +++ trunk/CopyBOM.php 2012-04-24 09:45:59 UTC (rev 5277) @@ -15,135 +15,142 @@ include('includes/SQL_CommonFunctions.inc'); if(isset($_POST['Submit'])) { - $stkid = $_POST['stkid']; - $type = $_POST['type']; - $newstkid = ''; - - if($type == 'N') { - $newstkid = $_POST['tostkid']; + $StockID = $_POST['StockID']; + $NewOrExisting = $_POST['NewOrExisting']; + $NewStockID = ''; + $InputError = 0; //assume the best + + if($NewOrExisting == 'N') { + $NewStockID = $_POST['ToStockID']; + if (mb_strlen($NewStockID)==0 OR $NewStockID==''){ + $InputError = 1; + prnMsg(_('The new item code cannot be blank. Enter a new code for the item to copy the BOM to'),'error'); + } } else { - $newstkid = $_POST['exstkid']; + $NewStockID = $_POST['ExStockID']; } + if ($InputError==0){ + $result = DB_Txn_Begin($db); - $result = DB_query("begin", $db); - - if($type == 'N') { - /* duplicate rows into stockmaster */ - $sql = "INSERT INTO stockmaster( stockid, - categoryid, - description, - longdescription, - units, - mbflag, - actualcost, - lastcost, - materialcost, - labourcost, - overheadcost, - lowestlevel, - discontinued, - controlled, - eoq, - volume, - kgs, - barcode, - discountcategory, - taxcatid, - serialised, - appendfile, - perishable, - decimalplaces, - nextserialno, - pansize, - shrinkfactor, - netweight ) - SELECT '".$newstkid."' AS stockid, - categoryid, - description, - longdescription, - units, - mbflag, - actualcost, - lastcost, - materialcost, - labourcost, - overheadcost, - lowestlevel, - discontinued, - controlled, - eoq, - volume, - kgs, - barcode, - discountcategory, - taxcatid, - serialised, - appendfile, - perishable, - decimalplaces, - nextserialno, - pansize, - shrinkfactor, - netweight + if($NewOrExisting == 'N') { + /* duplicate rows into stockmaster */ + $sql = "INSERT INTO stockmaster( stockid, + categoryid, + description, + longdescription, + units, + mbflag, + actualcost, + lastcost, + materialcost, + labourcost, + overheadcost, + lowestlevel, + discontinued, + controlled, + eoq, + volume, + kgs, + barcode, + discountcategory, + taxcatid, + serialised, + appendfile, + perishable, + decimalplaces, + nextserialno, + pansize, + shrinkfactor, + netweight ) + SELECT '".$NewStockID."' AS stockid, + categoryid, + description, + longdescription, + units, + mbflag, + actualcost, + lastcost, + materialcost, + labourcost, + overheadcost, + lowestlevel, + discontinued, + controlled, + eoq, + volume, + kgs, + barcode, + discountcategory, + taxcatid, + serialised, + appendfile, + perishable, + decimalplaces, + nextserialno, + pansize, + shrinkfactor, + netweight + FROM stockmaster + WHERE stockid='".$StockID."';"; + $result = DB_query($sql, $db); + } else { + $sql = "SELECT lastcostupdate, + actualcost, + lastcost, + materialcost, + labourcost, + overheadcost, + lowestlevel FROM stockmaster - WHERE stockid='".$stkid."';"; + WHERE stockid='".$StockID."';"; + $result = DB_query($sql, $db); + + $myrow = DB_fetch_row($result); + + $sql = "UPDATE stockmaster set + lastcostupdate = " . $myrow[0] . ", + actualcost = " . $myrow[1] . ", + lastcost = " . $myrow[2] . ", + materialcost = " . $myrow[3] . ", + labourcost = " . $myrow[4] . ", + overheadcost = " . $myrow[5] . ", + lowestlevel = " . $myrow[6] . " + WHERE stockid='".$NewStockID."';"; + $result = DB_query($sql, $db); + } + + $sql = "INSERT INTO bom + SELECT '".$NewStockID."' AS parent, + component, + workcentreadded, + loccode, + effectiveafter, + effectiveto, + quantity, + autoissue + FROM bom + WHERE parent='".$StockID."';"; $result = DB_query($sql, $db); - } else { - $sql = "SELECT lastcurcostdate, - actualcost, - lastcost, - materialcost, - labourcost, - overheadcost, - lowestlevel - FROM stockmaster - WHERE stockid='".$stkid."';"; - $result = DB_query($sql, $db); - - $row = DB_fetch_row($result); - - $sql = "UPDATE stockmaster set - lastcurcostdate = '".$row[0]."', - actualcost = ".$row[1].", - lastcost = ".$row[2].", - materialcost = ".$row[3].", - labourcost = ".$row[4].", - overheadcost = ".$row[5].", - lowestlevel = ".$row[6]." - WHERE stockid='".$newstkid."';"; - $result = DB_query($sql, $db); - } - - $sql = "INSERT INTO bom - SELECT '".$newstkid."' AS parent, - component, - workcentreadded, - loccode, - effectiveafter, - effectiveto, - quantity, - autoissue - FROM bom - WHERE parent='".$stkid."';"; - $result = DB_query($sql, $db); - - if($type == 'N') { - $sql = "INSERT INTO locstock - SELECT loccode, - '".$newstkid."' AS stockid, - 0 AS quantity, - reorderlevel - FROM locstock - WHERE stockid='".$stkid."';"; - $result = DB_query($sql, $db); - } - - $result = DB_query('commit', $db); - - UpdateCost($db, $newstkid); - - header('Location: BOMs.php?Select='.$newstkid); - ob_end_flush(); + + if($NewOrExisting == 'N') { + $sql = "INSERT INTO locstock + SELECT loccode, + '".$NewStockID."' AS stockid, + 0 AS quantity, + reorderlevel + FROM locstock + WHERE stockid='".$StockID."'"; + + $result = DB_query($sql, $db); + } + + $result = DB_Txn_Commit($db); + + UpdateCost($db, $NewStockID); + + header('Location: BOMs.php?Select='.$NewStockID); + ob_end_flush(); + } //end if there is no input error } else { echo '<p class="page_title_text"><img src="'.$rootpath.'/css/'.$theme.'/images/inventory.png" title="' . _('Contract') . '" alt="" />' . ' ' . $title . '</p>'; @@ -156,35 +163,35 @@ description FROM stockmaster WHERE stockid IN (SELECT DISTINCT parent FROM bom) - AND mbflag IN ('M', 'A', 'K');"; + AND mbflag IN ('M', 'A', 'K', 'G');"; $result = DB_query($sql, $db); echo '<table class="selection"> <tr> <td>' . _('From Stock ID') . '</td>'; - echo '<td><select name="stkid">'; - while($row = DB_fetch_row($result)) { - echo '<option value="'.$row[0].'">'.$row[0].' -- '.$row[1].'</option>'; + echo '<td><select name="StockID">'; + while($myrow = DB_fetch_row($result)) { + echo '<option value="'.$myrow[0].'">'.$myrow[0].' -- '.$myrow[1].'</option>'; } echo '</select></td> </tr>'; echo '<tr> - <td><input type="radio" name="type" value="N" />' . _(' To New Stock ID') . '</td>'; - echo '<td><input type="text" maxlength="20" name="tostkid" /></td></tr>'; + <td><input type="radio" name="NewOrExisting" value="N" />' . _(' To New Stock ID') . '</td>'; + echo '<td><input type="text" maxlength="20" name="ToStockID" /></td></tr>'; $sql = "SELECT stockid, description FROM stockmaster WHERE stockid NOT IN (SELECT DISTINCT parent FROM bom) - AND mbflag IN ('M', 'A', 'K');"; + AND mbflag IN ('M', 'A', 'K', 'G');"; $result = DB_query($sql, $db); if (DB_num_rows($result) > 0) { echo '<tr> - <td><input type="radio" name="type" value="E" />'._('To Existing Stock ID') . '</td><td>'; - echo '<select name="exstkid">'; - while($row = DB_fetch_row($result)) { - echo '<option value="'.$row[0].'">'.$row[0].' -- '.$row[1].'</option>'; + <td><input type="radio" name="NewOrExisting" value="E" />'._('To Existing Stock ID') . '</td><td>'; + echo '<select name="ExStockID">'; + while($myrow = DB_fetch_row($result)) { + echo '<option value="'.$myrow[0].'">'.$myrow[0].' -- '.$myrow[1].'</option>'; } echo '</select></td></tr>'; } Modified: trunk/Labels.php =================================================================== --- trunk/Labels.php 2012-04-23 03:06:00 UTC (rev 5276) +++ trunk/Labels.php 2012-04-24 09:45:59 UTC (rev 5277) @@ -7,12 +7,22 @@ * @version 1.1 * Last changes: 2010-08-31 * + * + * Phil's notes: + * This is an example of clever code that works but IMHO is very hard to decipher and modify - sorry Marcos! + * It is in webERP because it fulfills a useful function on its own but don't expect to be able to modify it!! + * I would prefer this code was re-written in a manner consistent with the rest of webERP + * There are many meaningless variable names + * unecessary abrastaction at every turn + * No class is necessary for this script IMHO + * Data held in an xml file instead of the database + * Variable naming uses a lower case first character + * $debug is used - but is a webERP global to trap SQL errors for sysadmins + * **/ $Version_adds= 1.1; -/** Error reporting */ - include('includes/session.inc'); $title=_('Label Templates Maintainance'); include('includes/header.inc'); @@ -20,8 +30,11 @@ $debug=false; include('includes/DefineLabelClass.php'); + +//Phil why xml? Why not use the database like every other part of webERP for storing data + $allLabels = //!< The variable $allLabels is the global variable that contains the list - getXMLFile(LABELS_FILE); //!< of all the label objects defined until now. In case of a fresh + getXMLFile($_SESSION['reports_dir'] . '/labels.xml'); //!< of all the label objects defined until now. In case of a fresh //!< installation or an empty XML labels file it holds a NULL value. if ($debug) { @@ -41,6 +54,7 @@ */ if (isset($_POST['Update'])) { // Get the data from the user input & validate it (not new) + //getData function $Label=getData($_POST, false, $ok); // If all OK try to update the requested label if (!$ok OR !updateLabel($Label)) { @@ -138,17 +152,20 @@ // Check the heading data $errors=array(); if ($new) { - if (empty($data['id'])) + if (empty($data['id'])) { $errors[]=_('Id required'); - elseif ($allLabels!=null AND $allLabels->findLabel($data['id'])!==false) + } elseif ($allLabels!=null AND $allLabels->findLabel($data['id'])!==false){ $errors[]=_('This id exists in previous list'); + } } if (empty($data['description'])) $errors=_('the description is required'); // Check the dimensions data foreach ($DimensionTags as $iTag=>$tag) { - if ($tag['type']=='s') continue; // select type does not require validation + if ($tag['type']=='s') { + continue; // select type does not require validation + } $dd = trim($data[$iTag]); $desc=$tag['desc']; switch ($tag['type']) { @@ -286,7 +303,8 @@ </tr> </tbody> </table> - <br /><input type="submit" name="'.$name.'" value="'.$value.'" /> + <br /> + <input type="submit" name="'.$name.'" value="'.$value.'" /> <input type="submit" name="Cancel" value="'.$vCancel.'" /> </div> </div> @@ -295,7 +313,7 @@ function setTableGD($Label, $ReadOnly) { global $GlobalTags, $DimensionTags; - $html='<table border="0" cellspacing="1" class="selection">'; + $html='<table class="selection">'; $html .= setDataFields($GlobalTags, 0, $Label, $specialTag='id', $ReadOnly); $html .= setDataFields($DimensionTags, 1, $Label->dimensions); $html .= ' @@ -345,13 +363,11 @@ function setTableLines($lineArray) { global $DataTags; - $html=' - <table border="0" cellspacing="1" class="selection">'; + $html='<table class="selection">'; $html .= setTableHeader($DataTags); $iCount=MAX_LINES_PER_LABEL; foreach ($lineArray as $i=>$data) { - $iCount--; $html .= setLineFields($DataTags, $data); } @@ -406,8 +422,7 @@ * @return Nothing */ function showLabelsList($list) { - $txt= //*< - array(_('Label id'),_('Description'), _('Label array'), + $txt= array(_('Label id'),_('Description'), _('Label array'), _('New'), _('Edit'), _('Copy'), _('Delete'), _('Do you really want to erase the label') ); @@ -425,7 +440,7 @@ } } </script> - <form action="'.htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8').'" method="post" id="form1"> + <form action="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '" method="post" id="form1"> <div> <input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" /> <input type="hidden" name="action" id="action" value="" /> Modified: trunk/companies/weberpdemo/reportwriter/labels.xml =================================================================== --- trunk/companies/weberpdemo/reportwriter/labels.xml 2012-04-23 03:06:00 UTC (rev 5276) +++ trunk/companies/weberpdemo/reportwriter/labels.xml 2012-04-24 09:45:59 UTC (rev 5277) @@ -1,2 +1,2 @@ <?xml version="1.0"?> -<labels><label><id>111-price</id><description>111-CodePrice</description><dimensions><Unit>mm</Unit><Rows>12</Rows><Cols>10</Cols><Sh>162</Sh><Sw>196</Sw><He>12</He><Wi>18</Wi><Tm>3</Tm><Lm>3</Lm><Rh>12.5</Rh><Cw>18.5</Cw></dimensions><data><line><row>7</row><pos>1</pos><max>15</max><font>2</font><dat>code</dat></line><line><row>2</row><pos>1</pos><max>15</max><font>2</font><dat>bcode</dat></line></data></label><label><id>130-price</id><description>130-CodePrice</description><dimensions><Unit>mm</Unit><Rows>8</Rows><Cols>6</Cols><Sh>170</Sh><Sw>205</Sw><He>18</He><Wi>31</Wi><Tm>3</Tm><Lm>2</Lm><Rh>20.5</Rh><Cw>33.5</Cw></dimensions><data><line><row>13</row><pos>2</pos><max>27</max><font>4</font><dat>code</dat></line><line><row>5</row><pos>2</pos><max>27</max><font>4</font><dat>price</dat></line></data></label></labels> +<labels><label><id>111-price</id><description>111-CodePrice</description><dimensions><Unit>mm</Unit><Rows>12</Rows><Cols>10</Cols><Sh>162</Sh><Sw>196</Sw><He>12</He><Wi>18</Wi><Tm>3</Tm><Lm>3</Lm><Rh>12.5</Rh><Cw>18.5</Cw></dimensions><data><line><row>7</row><pos>1</pos><max>15</max><font>2</font><dat>code</dat></line><line><row>2</row><pos>1</pos><max>15</max><font>2</font><dat>bcode</dat></line></data></label><label><id>130-price</id><description>130-CodePrice</description><dimensions><Unit>mm</Unit><Rows>8</Rows><Cols>6</Cols><Sh>170</Sh><Sw>205</Sw><He>18</He><Wi>31</Wi><Tm>3</Tm><Lm>2</Lm><Rh>20.5</Rh><Cw>33.5</Cw></dimensions><data><line><row>13</row><pos>2</pos><max>27</max><font>4</font><dat>code</dat></line><line><row>5</row><pos>2</pos><max>27</max><font>4</font><dat>price</dat></line></data></label><label><id>PriceLabel</id><description>Price Label</description><dimensions><Unit>mm</Unit><Rows>10</Rows><Cols>4</Cols><Sh>297</Sh><Sw>210</Sw><He>25.4</He><Wi>45.7</Wi><Tm>5</Tm><Lm>10</Lm><Rh>25.4</Rh><Cw>48</Cw></dimensions><data><line><row>20</row><pos>5</pos><max>20</max><font>3</font><dat>code</dat></line><line><row>12</row><pos>10</pos><max>15</max><font>5</font><dat>price</dat></line><line><row>5</row><pos>2</pos><max>40</max><font>2</font><dat>name1</dat></line></data></label></labels> Modified: trunk/doc/Change.log =================================================================== --- trunk/doc/Change.log 2012-04-23 03:06:00 UTC (rev 5276) +++ trunk/doc/Change.log 2012-04-24 09:45:59 UTC (rev 5277) @@ -1,4 +1,6 @@ webERP Change Log + +24/4/2012 Phil: fix CopyBOM.php that was insering a blank stockid into stockmaster as reported by Ricard 21/04/2012 Vitaly: Editable item description in PO. 16/04/2012 Vitaly: Added option to display only items that are currently on purchase order in StockLocStatus.php 16/04/2012 Vitaly: Fixed Days textbox where it did not remember entered value. @@ -65,10 +67,6 @@ 17/2/12 Phil: SuppCreditGRNs.php SuppInvGRNs.php DefineSuppTransClass.php SupplierInvoice.php stock movement was not being updated correctly with cost on purchase invoice entry as was using GRNNo not GRNBatchNo - which is used as the GRN transaction number in stock movements. 16/2/12 Tim: Modified index.php to use arrays of links rather than hard code all menus 16/2/12 Exson: Fixed StockAdjustments.php was not producing gltrans entries when stock code entered directly - - -Release 4.07 - 11/2/12 Phil: Fix Prices.php for end dates when a new price with no end date is inserted with a start date in the future. 11/2/12 Ahmed.Fawzy: Repairs to Prices_Customer.php option to have prices for a single customer and all branches had been compromised by having the branch selection box with no "All Branches" option. Also selected branch was not showing as it should have when editing a specific branch price 7/2/12 Ricard: Made new system parameter for StandardCostDecimalPlaces - reworked SelectProduct.php and StockCostUpdate.php to use the new parameter. Modified SystemParameters.php to allow the parameter to be a number between 0 and 4 inclusive. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |