From: <tim...@us...> - 2010-04-25 09:47:52
|
Revision: 3430 http://web-erp.svn.sourceforge.net/web-erp/?rev=3430&view=rev Author: tim_schofield Date: 2010-04-25 09:47:46 +0000 (Sun, 25 Apr 2010) Log Message: ----------- Matt Taylor: Z_BottomUpCost.php : Add script for batch updating BOM costs, and improvements to DateFunctions.php Modified Paths: -------------- trunk/Z_index.php trunk/doc/Change.log.html trunk/includes/DateFunctions.inc trunk/includes/SQL_CommonFunctions.inc trunk/javascripts/MiscFunctions.js Added Paths: ----------- trunk/Z_BottomUpCosts.php Added: trunk/Z_BottomUpCosts.php =================================================================== --- trunk/Z_BottomUpCosts.php (rev 0) +++ trunk/Z_BottomUpCosts.php 2010-04-25 09:47:46 UTC (rev 3430) @@ -0,0 +1,56 @@ +<?php +/* $Id$*/ +/* Script to update costs for all BOM items, from the bottom up */ + +$PageSecurity = 15; +include('includes/session.inc'); +$title = _('Recalculate BOM costs'); +include('includes/header.inc'); +include('includes/SQL_CommonFunctions.inc'); + +if (isset($_GET['Run'])){ + $Run = $_GET['Run']; +} elseif (isset($_POST['Run'])){ + $Run = $_POST['Run']; +} + +if (isset($Run)) { //start bom processing + + // Get all bottom level components + $sql = "SELECT DISTINCT b1.component + FROM bom as b1 + left join bom as b2 on b2.parent=b1.component + WHERE b2.parent is null;" ; + + $ErrMsg = _('An error occurred selecting all bottom level components'); + $DbgMsg = _('The SQL that was used to select bottom level components and failed in the process was'); + + $result = DB_query($sql,$db,$ErrMsg,$DbgMsg); + + while ($item = DB_fetch_array($result)) { + $inputerror=UpdateCost($db, $item['component']); + if ($inputerror==0) { + prnMsg( _('Component') .' ' . $item['component'] . ' '. _('has been processed'),'success'); + } else { + break; + } + } + + if ($inputerror == 1) { //exited loop with errors so rollback + prnMsg(_('Failed on item '. $item['component']. '. Cost update has been rolled back.'),'error'); + DB_Txn_Rollback($db); + } else { //all good so commit data transaction + DB_Txn_Commit($db); + prnMsg( _('All cost updates committed to the database.'),'success'); + } + +} else { //show file upload form + + echo "<form action=" . $_SERVER['PHP_SELF'] . '?' . sid . " method=post name='form'>"; + echo '<p class="page_title_text"><img src="'.$rootpath.'/css/'.$theme.'/images/sales.png" title="' . _('Search') . '" alt="">' . ' ' . _('Update costs for all items listed in a bill of materials').'<br></p>'; + echo "<div class=centre><input type='submit' name='Run' value='" . _('Run') . "'></div></form>"; + +} + +include('includes/footer.inc'); +?> \ No newline at end of file Property changes on: trunk/Z_BottomUpCosts.php ___________________________________________________________________ Added: svn:keywords + Id Modified: trunk/Z_index.php =================================================================== --- trunk/Z_index.php 2010-04-23 07:45:28 UTC (rev 3429) +++ trunk/Z_index.php 2010-04-25 09:47:46 UTC (rev 3430) @@ -14,6 +14,7 @@ echo "<p><a href='$rootpath/Z_ChangeBranchCode.php?" . SID . "'>" . _('Change A Customer Branch Code') . '</a>'; echo "<p><a href='$rootpath/Z_ChangeStockCode.php?" . SID . "'>" . _('Change An Inventory Item Code') . '</a>'; echo "<p><a href='$rootpath/Z_PriceChanges.php?" . SID . "'>" . _('Bulk Change Customer Pricing') . '</a>'; + echo "<p><a href='$rootpath/Z_BottomUpCosts.php?" . SID . "'>" . _('Update costs for all BOM items, from the bottom up') . '</a>'; echo "<p><a href='$rootpath/Z_CurrencyDebtorsBalances.php?" . SID . "'>" . _('Show Local Currency Total Debtor Balances') . '</a>'; echo "<p><a href='$rootpath/Z_CurrencySuppliersBalances.php?" . SID . "'>" . _('Show Local Currency Total Suppliers Balances') . '</a>'; Modified: trunk/doc/Change.log.html =================================================================== --- trunk/doc/Change.log.html 2010-04-23 07:45:28 UTC (rev 3429) +++ trunk/doc/Change.log.html 2010-04-25 09:47:46 UTC (rev 3430) @@ -1,5 +1,8 @@ <p><font SIZE=4 COLOR=BLUE><b>webERP Change Log</b></font></p> <p></p> +<p>23/04/10 Matt Taylor: MiscFunctions.js : Fix IsDate() function for Y/m/d format.</p> +<p>23/04/10 Matt Taylor: DateFunctions.inc : Fix Date1GreaterThanDate2() function for Y/m/d format.</p> +<p>23/04/10 Matt Taylor: Z_BottomUpCost.php : Add script for batch updating BOM costs.</p> <p>22/04/10 Zhiguo: SelectProduct.php - Add a link to StockStatus.php direct from the selection page.</p> <p>22/04/10 Lindsay: add missing ; to second last line of upgrade3.11.1-3.12.sql</p> <p>22/04/10 Zhiguo: index.php - Change SID to sid, so as to solve the locale issue of Turkish I(ı) & İ(i)</p> Modified: trunk/includes/DateFunctions.inc =================================================================== --- trunk/includes/DateFunctions.inc 2010-04-23 07:45:28 UTC (rev 3429) +++ trunk/includes/DateFunctions.inc 2010-04-25 09:47:46 UTC (rev 3430) @@ -16,7 +16,7 @@ */ -function Is_Date($DateEntry) { +function is_date($DateEntry) { $DateEntry =Trim($DateEntry); @@ -397,7 +397,7 @@ } if ($_SESSION['DefaultDateFormat']=='Y/m/d') { - return $Date_Array[0].'/'.$Date_Array[1].'/'.$Date_Array[2]; + return $Date_Array[0].'-'.$Date_Array[1].'-'.$Date_Array[2]; } //to modify assumption in 2030 @@ -412,13 +412,13 @@ } if (($_SESSION['DefaultDateFormat']=='d/m/Y')){ /* echo '<BR>The date returned is ' . $Date_Array[2].'/'.$Date_Array[1].'/'.$Date_Array[0]; */ - return $Date_Array[2].'/'.$Date_Array[1].'/'.$Date_Array[0]; + return $Date_Array[2].'-'.$Date_Array[1].'-'.$Date_Array[0]; } elseif ($_SESSION['DefaultDateFormat']=='d.m.Y') { - return $Date_Array[2].'.'.$Date_Array[1].'.'.$Date_Array[0]; + return $Date_Array[2].'-'.$Date_Array[1].'-'.$Date_Array[0]; } elseif ($_SESSION['DefaultDateFormat']=='m/d/Y') { - return $Date_Array[2].'/'.$Date_Array[0].'/'.$Date_Array[1]; + return $Date_Array[2].'-'.$Date_Array[0].'-'.$Date_Array[1]; } elseif ($_SESSION['DefaultDateFormat']=='Y/m/d') { - return $Date_Array[0].'/'.$Date_Array[1].'/'.$Date_Array[2]; + return $Date_Array[0].'-'.$Date_Array[1].'-'.$Date_Array[2]; } }// end of function @@ -433,59 +433,66 @@ function Date1GreaterThanDate2 ($Date1, $Date2) { -/* returns 1 true if Date1 is greater than Date 2 */ +/* returns true (1) if Date1 is greater than Date2 */ $Date1 = trim($Date1); $Date2 = trim($Date2); - $Date1_array = explode('/', $Date1); - $Date2_array = explode('/', $Date2); + /* Get date elements */ + if ($_SESSION['DefaultDateFormat']=='d.m.Y' or $_SESSION['DefaultDateFormat'] =='d/m/Y'){ + list($Day1,$Month1,$Year1) = explode('.', $Date1); + list($Day2,$Month2,$Year2) = explode('.', $Date2); + } elseif ($_SESSION['DefaultDateFormat'] =='m/d/Y'){ + list($Month1,$Day1,$Year1) = explode('/', $Date1); + list($Month2,$Day2,$Year2) = explode('/', $Date2); + } elseif ($_SESSION['DefaultDateFormat'] =='Y/m/d'){ + list($Year1,$Month1,$Day1) = explode('/', $Date1); + list($Year2,$Month2,$Day2) = explode('/', $Date2); + } + /*Try to make the year of each date comparable - if one date is specified as just - 2 characters and the other >2 then take the last 2 characters of the other date only */ - if (strlen($Date1_array[2])>2 AND strlen($Date2_array[2])==2){ - $Date1_array[2] = substr($Date1_array[2], strlen($Date1_array[2])-2); + * 2 characters and the other >2 then then make them both 4 characters long. Assume + * a date >50 to be 1900's and less than to be 2000's + */ + if (strlen($Year1)>2 AND strlen($Year2)==2){ + if ($Year2>50) { + $Year2=1900+$Year2; + } else { + $Year2=2000+$Year2; + } } - if (strlen($Date2_array[2])>2 AND strlen($Date1_array[2])==2){ - $Date2_array[2] = substr($Date2_array[2], strlen($Date2_array[2])-2); + if (strlen($Year2)>2 AND strlen($Year1)==2){ + if ($Year1>50) { + $Year1=1900+$Year1; + } else { + $Year1=2000+$Year1; + } } - /*The 2 element of the array will be the year in either d/m/Y or m/d/Y formats */ + /* Compare years */ + if ($Year1>$Year2){ + return 1; + } elseif ($Year2>$Year1){ + return 0; + } - if (($Date1_array[2] - $Date2_array[2]) >0){ + /* Compare months. Years are equal*/ + if ($Month1>$Month2){ return 1; - } elseif (($Date1_array[2] - $Date2_array[2]) ==0){ + } elseif ($Month2>$Month1){ + return 0; + } - /*The 0 and 1 elements of the array are switched depending on the format used */ + /* Compare days. Years and months are equal */ + if ($Day1>$Day2){ + return 1; + } elseif ($Day2>$Day1){ + return 0; + } - if (($_SESSION['DefaultDateFormat']=='d/m/Y') OR ($_SESSION['DefaultDateFormat']=='d.m.Y')){ - if ( ($Date1_array[1] - $Date2_array[1]) >0){ - return 1; - } elseif (($Date1_array[1] - $Date2_array[1])==0){ - if (($Date1_array[0] - $Date2_array[0])>0){ - return 1; - } - } + /* The dates are equal, so return an error state */ + return 1; - } elseif ($_SESSION['DefaultDateFormat'] =='m/d/Y'){ - If (($Date1_array[0] - $Date2_array[0])>0){ - Return 1; - } elseif (($Date1_array[0] - $Date2_array[0])==0){ - If (($Date1_array[1] - $Date2_array[1])>0){ - Return 1; - } - } - } elseif ($_SESSION['DefaultDateFormat'] =='Y/m/d'){ - if (($Date1_array[2] - $Date2_array[2])>0){ - return 1; - } elseif (($Date1_array[2] - $Date2_array[2])==0){ - if (($Date1_array[1] - $Date2_array[1])>0){ - return 1; - } - } - } - } - - return 0; } function CalcDueDate($TranDate, $DayInFollowingMonth, $DaysBeforeDue){ Modified: trunk/includes/SQL_CommonFunctions.inc =================================================================== --- trunk/includes/SQL_CommonFunctions.inc 2010-04-23 07:45:28 UTC (rev 3429) +++ trunk/includes/SQL_CommonFunctions.inc 2010-04-25 09:47:46 UTC (rev 3430) @@ -239,8 +239,12 @@ $MaterialCost = BomMaterialCost($NewParent, $db); $SQL = 'UPDATE stockmaster SET materialcost=' . $MaterialCost . " WHERE stockid='" . $NewParent . "'"; $result1 = DB_query($SQL,$db); + if (DB_error_no($db)!=0) { + return 1; + } UpdateCost($db, $NewParent); } + return 0; } /* Accepts work order information and iterates through the bom, inserting real components (dissolving phantom assemblies) */ @@ -303,8 +307,8 @@ WHERE wo = " . $WO . " AND parentstockid = '". $ParentID . "' ) - ) AS g ON g.wo=worequirements.wo - AND g.parentstockid=worequirements.parentstockid + ) AS g ON g.wo=worequirements.wo + AND g.parentstockid=worequirements.parentstockid AND g.stockid=worequirements.stockid SET worequirements.qtypu=worequirements.qtypu+g.qtypu"; $result = DB_query($sql, $db); Modified: trunk/javascripts/MiscFunctions.js =================================================================== --- trunk/javascripts/MiscFunctions.js 2010-04-23 07:45:28 UTC (rev 3429) +++ trunk/javascripts/MiscFunctions.js 2010-04-25 09:47:46 UTC (rev 3430) @@ -23,7 +23,12 @@ return false; } function isDate(dS,dF){ -var mA=dS.match(/^(\d{1,2})(\/|-|.)(\d{1,2})(\/|-|.)(\d{4})$/); +var mA; +if (dF == "Y/m/d"){ +mA=dS.match(/^(\d{4})(\/|-|.)(\d{1,2})(\/|-|.)(\d{1,2})$/); +}else{ +mA=dS.match(/^(\d{1,2})(\/|-|.)(\d{1,2})(\/|-|.)(\d{4})$/); +} if (mA==null){ alert("Please enter the date in the format "+dF); return false; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |