From: <te...@us...> - 2015-11-17 00:38:08
|
Revision: 7393 http://sourceforge.net/p/web-erp/reponame/7393 Author: tehonu Date: 2015-11-17 00:38:05 +0000 (Tue, 17 Nov 2015) Log Message: ----------- Improve comparation of OldCost and NewCost to avoid useless GL transactions Modified Paths: -------------- trunk/StockCostUpdate.php trunk/Z_UpdateItemCosts.php trunk/includes/SQL_CommonFunctions.inc Modified: trunk/StockCostUpdate.php =================================================================== --- trunk/StockCostUpdate.php 2015-11-16 09:15:24 UTC (rev 7392) +++ trunk/StockCostUpdate.php 2015-11-17 00:38:05 UTC (rev 7393) @@ -62,7 +62,7 @@ $myrow = DB_fetch_row($result); if (DB_num_rows($result)==0) { prnMsg (_('The entered item code does not exist'),'error',_('Non-existent Item')); - } elseif ($OldCost != $NewCost){ + } elseif (abs($NewCost - $OldCost) > pow(1,-($_SESSION['StandardCostDecimalPlaces']+1))){ $Result = DB_Txn_Begin(); ItemCostUpdateGL($db, $StockID, $NewCost, $OldCost, $_POST['QOH']); Modified: trunk/Z_UpdateItemCosts.php =================================================================== --- trunk/Z_UpdateItemCosts.php 2015-11-16 09:15:24 UTC (rev 7392) +++ trunk/Z_UpdateItemCosts.php 2015-11-17 00:38:05 UTC (rev 7393) @@ -75,7 +75,10 @@ $OldCost = $OldRow['materialcost'] + $OldRow['labourcost'] + $OldRow['overheadcost']; //dont update costs for assembly or kit-sets or ghost items!! - if ($OldCost != $NewCost AND $OldRow['mbflag']!='K' AND $OldRow['mbflag']!='A' AND $OldRow['mbflag']!='G'){ + if ((abs($NewCost - $OldCost) > pow(1,-($_SESSION['StandardCostDecimalPlaces']+1))) + AND $OldRow['mbflag']!='K' + AND $OldRow['mbflag']!='A' + AND $OldRow['mbflag']!='G'){ ItemCostUpdateGL($db, $StockID, $NewCost, $OldCost, $QOH); Modified: trunk/includes/SQL_CommonFunctions.inc =================================================================== --- trunk/includes/SQL_CommonFunctions.inc 2015-11-16 09:15:24 UTC (rev 7392) +++ trunk/includes/SQL_CommonFunctions.inc 2015-11-17 00:38:05 UTC (rev 7393) @@ -158,53 +158,54 @@ } function ItemCostUpdateGL($db, $StockID, $NewCost, $OldCost, $QOH) { + if ($_SESSION['CompanyRecord']['gllink_stock']==1 + AND $QOH!=0 + AND (abs($NewCost - $OldCost) > pow(1,-($_SESSION['StandardCostDecimalPlaces']+1)))){ - if ($_SESSION['CompanyRecord']['gllink_stock']==1 AND $QOH!=0){ + $CostUpdateNo = GetNextTransNo(35, $db); + $PeriodNo = GetPeriod(date($_SESSION['DefaultDateFormat']), $db); + $StockGLCode = GetStockGLCode($StockID,$db); - $CostUpdateNo = GetNextTransNo(35, $db); - $PeriodNo = GetPeriod(date($_SESSION['DefaultDateFormat']), $db); - $StockGLCode = GetStockGLCode($StockID,$db); + $ValueOfChange = $QOH * ($NewCost - $OldCost); - $ValueOfChange = $QOH * ($NewCost - $OldCost); + $SQL = "INSERT INTO gltrans (type, + typeno, + trandate, + periodno, + account, + narrative, + amount) + VALUES ('35', + '" . $CostUpdateNo . "', + '" . Date('Y-m-d') . "', + '" . $PeriodNo . "', + '" . $StockGLCode['adjglact'] . "', + '" . $StockID . ' ' . _('cost was') . ' ' . $OldCost . ' ' . _('changed to') . ' ' . $NewCost . ' x ' . _('Quantity on hand of') . ' ' . $QOH . "', + '" . -$ValueOfChange . "')"; - $SQL = "INSERT INTO gltrans (type, - typeno, - trandate, - periodno, - account, - narrative, - amount) - VALUES ('35', - '" . $CostUpdateNo . "', - '" . Date('Y-m-d') . "', - '" . $PeriodNo . "', - '" . $StockGLCode['adjglact'] . "', - '" . $StockID . ' ' . _('cost was') . ' ' . $OldCost . ' ' . _('changed to') . ' ' . $NewCost . ' x ' . _('Quantity on hand of') . ' ' . $QOH . "', - '" . -$ValueOfChange . "')"; + $ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The GL credit for the stock cost adjustment posting could not be inserted because'); + $DbgMsg = _('The following SQL to insert the GLTrans record was used'); + $Result = DB_query($SQL,$ErrMsg,$DbgMsg,true); - $ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The GL credit for the stock cost adjustment posting could not be inserted because'); - $DbgMsg = _('The following SQL to insert the GLTrans record was used'); - $Result = DB_query($SQL,$ErrMsg,$DbgMsg,true); + $SQL = "INSERT INTO gltrans (type, + typeno, + trandate, + periodno, + account, + narrative, + amount) + VALUES ('35', + '" . $CostUpdateNo . "', + '" . Date('Y-m-d') . "', + '" . $PeriodNo . "', + '" . $StockGLCode['stockact'] . "', + '" . $StockID . ' ' . _('cost was') . ' ' . $OldCost . ' ' . _('changed to') .' ' . $NewCost . ' x ' . _('Quantity on hand of') . ' ' . $QOH . "', + '" . $ValueOfChange . "')"; - $SQL = "INSERT INTO gltrans (type, - typeno, - trandate, - periodno, - account, - narrative, - amount) - VALUES ('35', - '" . $CostUpdateNo . "', - '" . Date('Y-m-d') . "', - '" . $PeriodNo . "', - '" . $StockGLCode['stockact'] . "', - '" . $StockID . ' ' . _('cost was') . ' ' . $OldCost . ' ' . _('changed to') .' ' . $NewCost . ' x ' . _('Quantity on hand of') . ' ' . $QOH . "', - '" . $ValueOfChange . "')"; - - $ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The GL debit for stock cost adjustment posting could not be inserted because'); - $DbgMsg = _('The following SQL to insert the GLTrans record was used'); - $Result = DB_query($SQL,$ErrMsg,$DbgMsg,true); - } + $ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The GL debit for stock cost adjustment posting could not be inserted because'); + $DbgMsg = _('The following SQL to insert the GLTrans record was used'); + $Result = DB_query($SQL,$ErrMsg,$DbgMsg,true); + } } /* Calculates the material cost of a bill of materials, given parent code*/ |