Skip to content

Commit

Permalink
PaulT: Remove $db parameter from BomMaterialCost(), GetTaxRate(), Get…
Browse files Browse the repository at this point in the history
…Taxes(), GetCreditAvailable(), ItemCostUpdateGL(), and UpdateCost() functions.
  • Loading branch information
TurboPT authored and timschofield committed Feb 27, 2018
1 parent 7a44c37 commit 2ebcfda
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 23 deletions.
6 changes: 3 additions & 3 deletions BOMs.php
Expand Up @@ -368,7 +368,7 @@ function DisplayBOMItems($UltimateParent, $Parent, $Component,$Level, $db) {
$result = DB_query($sql,$ErrMsg,$DbgMsg);
$msg = _('Details for') . ' - ' . $SelectedComponent . ' ' . _('have been updated') . '.';
if ($_SESSION['WeightedAverageCosting'] != 1) {
UpdateCost($db, $SelectedComponent);
UpdateCost($SelectedComponent);
}

} elseif ($InputError !=1 AND ! isset($SelectedComponent) AND isset($SelectedParent)) {
Expand Down Expand Up @@ -426,7 +426,7 @@ function DisplayBOMItems($UltimateParent, $Parent, $Component,$Level, $db) {
$result = DB_query($sql,$ErrMsg,$DbgMsg);

if ($_SESSION['WeightedAverageCosting'] != 1) {
UpdateCost($db, $_POST['Component']);
UpdateCost($_POST['Component']);
}
$msg = _('A new component part') . ' ' . $_POST['Component'] . ' ' . _('has been added to the bill of material for part') . ' - ' . $SelectedParent . '.';

Expand Down Expand Up @@ -466,7 +466,7 @@ function DisplayBOMItems($UltimateParent, $Parent, $Component,$Level, $db) {
$ComponentArray = DB_fetch_row($ComponentResult);

if ($_SESSION['WeightedAverageCosting'] != 1) {//only update the cost for standard cost
UpdateCost($db, $ComponentArray[0]);
UpdateCost($ComponentArray[0]);
}

prnMsg(_('The component part') . ' - ' . $SelectedComponent . ' - ' . _('has been deleted from this BOM'),'success');
Expand Down
2 changes: 1 addition & 1 deletion Contracts.php
Expand Up @@ -739,7 +739,7 @@
$_SESSION['Contract'.$identifier]->ExRate = $myrow['rate'];

if ($_SESSION['CheckCreditLimits'] > 0){ /*Check credit limits is 1 for warn and 2 for prohibit contracts */
$CreditAvailable = GetCreditAvailable($_SESSION['Contract'.$identifier]->DebtorNo,$db);
$CreditAvailable = GetCreditAvailable($_SESSION['Contract'.$identifier]->DebtorNo);
if ($_SESSION['CheckCreditLimits']==1 AND $CreditAvailable <=0){
prnMsg(_('The') . ' ' . $_SESSION['Contract'.$identifier]->CustomerName . ' ' . _('account is currently at or over their credit limit'),'warn');
} elseif ($_SESSION['CheckCreditLimits']==2 AND $CreditAvailable <=0){
Expand Down
2 changes: 1 addition & 1 deletion CopyBOM.php
Expand Up @@ -154,7 +154,7 @@

$result = DB_Txn_Commit();

UpdateCost($db, $NewStockID);
UpdateCost($NewStockID);

header('Location: BOMs.php?Select='.$NewStockID);
ob_end_flush();
Expand Down
2 changes: 1 addition & 1 deletion CounterSales.php
Expand Up @@ -191,7 +191,7 @@
}

if ($_SESSION['CheckCreditLimits'] > 0 AND $AlreadyWarnedAboutCredit==false) { /*Check credit limits is 1 for warn and 2 for prohibit sales */
$_SESSION['Items'.$identifier]->CreditAvailable = GetCreditAvailable($_SESSION['Items'.$identifier]->DebtorNo,$db);
$_SESSION['Items'.$identifier]->CreditAvailable = GetCreditAvailable($_SESSION['Items'.$identifier]->DebtorNo);

if ($_SESSION['CheckCreditLimits']==1 AND $_SESSION['Items'.$identifier]->CreditAvailable <=0){
prnMsg(_('The') . ' ' . $myrow['brname'] . ' ' . _('account is currently at or over their credit limit'),'warn');
Expand Down
4 changes: 2 additions & 2 deletions SelectOrderItems.php
Expand Up @@ -184,7 +184,7 @@
}
$_SESSION['Items'.$identifier]->OrderNo = $_GET['ModifyOrderNumber'];
$_SESSION['Items'.$identifier]->DebtorNo = $myrow['debtorno'];
$_SESSION['Items'.$identifier]->CreditAvailable = GetCreditAvailable($_SESSION['Items'.$identifier]->DebtorNo,$db);
$_SESSION['Items'.$identifier]->CreditAvailable = GetCreditAvailable($_SESSION['Items'.$identifier]->DebtorNo);
/*CustomerID defined in header.php */
$_SESSION['Items'.$identifier]->Branch = $myrow['branchcode'];
$_SESSION['Items'.$identifier]->CustomerName = $myrow['name'];
Expand Down Expand Up @@ -504,7 +504,7 @@
prnMsg($_SESSION['Items'.$identifier]->SpecialInstructions,'warn');

if ($_SESSION['CheckCreditLimits'] > 0){ /*Check credit limits is 1 for warn and 2 for prohibit sales */
$_SESSION['Items'.$identifier]->CreditAvailable = GetCreditAvailable($_SESSION['Items'.$identifier]->DebtorNo,$db);
$_SESSION['Items'.$identifier]->CreditAvailable = GetCreditAvailable($_SESSION['Items'.$identifier]->DebtorNo);

if ($_SESSION['CheckCreditLimits']==1 AND $_SESSION['Items'.$identifier]->CreditAvailable <=0){
prnMsg(_('The') . ' ' . htmlspecialchars($myrow[0], ENT_QUOTES, 'UTF-8', false) . ' ' . _('account is currently at or over their credit limit'),'warn');
Expand Down
4 changes: 2 additions & 2 deletions StockCostUpdate.php
Expand Up @@ -65,7 +65,7 @@
} elseif (abs($NewCost - $OldCost) > pow(10,-($_SESSION['StandardCostDecimalPlaces']+1))){

$Result = DB_Txn_Begin();
ItemCostUpdateGL($db, $StockID, $NewCost, $OldCost, $_POST['QOH']);
ItemCostUpdateGL($StockID, $NewCost, $OldCost, $_POST['QOH']);

$SQL = "UPDATE stockmaster SET materialcost='" . filter_number_format($_POST['MaterialCost']) . "',
labourcost='" . filter_number_format($_POST['LabourCost']) . "',
Expand All @@ -79,7 +79,7 @@
$Result = DB_query($SQL,$ErrMsg,$DbgMsg,true);

$Result = DB_Txn_Commit();
UpdateCost($db, $StockID); //Update any affected BOMs
UpdateCost($StockID); //Update any affected BOMs

}
}
Expand Down
2 changes: 1 addition & 1 deletion Z_BottomUpCosts.php
Expand Up @@ -28,7 +28,7 @@
$result = DB_query($sql,$ErrMsg,$DbgMsg);

while ($item = DB_fetch_array($result)) {
$inputerror=UpdateCost($db, $item['component']);
$inputerror=UpdateCost($item['component']);
if ($inputerror==0) {
prnMsg( _('Component') .' ' . $item['component'] . ' '. _('has been processed'),'success');
} else {
Expand Down
4 changes: 2 additions & 2 deletions Z_UpdateItemCosts.php
Expand Up @@ -80,7 +80,7 @@
AND $OldRow['mbflag']!='A'
AND $OldRow['mbflag']!='G'){

ItemCostUpdateGL($db, $StockID, $NewCost, $OldCost, $QOH);
ItemCostUpdateGL($StockID, $NewCost, $OldCost, $QOH);

$SQL = "UPDATE stockmaster SET materialcost='" . (double) $myrow[1] . "',
labourcost='" . (double) $myrow[2] . "',
Expand All @@ -93,7 +93,7 @@
$DbgMsg = _('The SQL that failed was');
$Result = DB_query($SQL,$ErrMsg,$DbgMsg,true);

UpdateCost($db, $StockID); //Update any affected BOMs
UpdateCost($StockID); //Update any affected BOMs

}

Expand Down
1 change: 1 addition & 0 deletions doc/Change.log
@@ -1,5 +1,6 @@
webERP Change Log

10/2/18 PaulT: Remove $db parameter from BomMaterialCost(), GetTaxRate(), GetTaxes(), GetCreditAvailable(), ItemCostUpdateGL(), and UpdateCost() functions.
10/2/18 PaulT: Remove $db parameter from all GetStockGLCode() functions.
10/2/18 PaulT: Remove variables left behind from 7944 commit.
9/2/18 PaulT: MRPReschedules.php, MRPShortages.php: Use DB_table_exists() from commit 7943 to replace table check query.
Expand Down
20 changes: 10 additions & 10 deletions includes/SQL_CommonFunctions.inc
Expand Up @@ -51,7 +51,7 @@ Function GetStockGLCode ($StockID){
return $myrow;
}

Function GetTaxRate ($TaxAuthority, $DispatchTaxProvince, $TaxCategory, &$db){
Function GetTaxRate ($TaxAuthority, $DispatchTaxProvince, $TaxCategory){

/*Gets the Tax rate applicable to an item from the TaxAuthority of the branch and TaxLevel of the item */

Expand All @@ -74,7 +74,7 @@ Function GetTaxRate ($TaxAuthority, $DispatchTaxProvince, $TaxCategory, &$db){

}

Function GetTaxes ($TaxGroup, $DispatchTaxProvince, $TaxCategory, &$db) {
Function GetTaxes ($TaxGroup, $DispatchTaxProvince, $TaxCategory) {

$SQL = "SELECT taxgrouptaxes.calculationorder,
taxauthorities.description,
Expand Down Expand Up @@ -105,7 +105,7 @@ Function GetTaxes ($TaxGroup, $DispatchTaxProvince, $TaxCategory, &$db) {



Function GetCreditAvailable($DebtorNo,&$db) {
Function GetCreditAvailable($DebtorNo) {

$sql = "SELECT debtorsmaster.debtorno,
debtorsmaster.creditlimit,
Expand Down Expand Up @@ -150,7 +150,7 @@ Function GetCreditAvailable($DebtorNo,&$db) {
return $CreditAvailable;
}

function ItemCostUpdateGL($db, $StockID, $NewCost, $OldCost, $QOH) {
function ItemCostUpdateGL($StockID, $NewCost, $OldCost, $QOH) {

if ($_SESSION['CompanyRecord']['gllink_stock']==1
AND $QOH!=0
Expand Down Expand Up @@ -203,7 +203,7 @@ function ItemCostUpdateGL($db, $StockID, $NewCost, $OldCost, $QOH) {
}

/* Calculates the material cost of a bill of materials, given parent code*/
function BomMaterialCost($Parent, $db) {
function BomMaterialCost($Parent) {
$SQL = "SELECT materialcost FROM stockmaster WHERE stockid='" . $Parent . "'";
$result1 = DB_query($SQL);
$MyRow1 = DB_fetch_row($result1);
Expand All @@ -222,26 +222,26 @@ function BomMaterialCost($Parent, $db) {
$MyRow = DB_fetch_row($result);
$MaterialCost = $MyRow[0];
if (abs($QOH*($MaterialCost-$OldCost))>0) {
ItemCostUpdateGL($db, $Parent, $MaterialCost, $OldCost, $QOH);
ItemCostUpdateGL($Parent, $MaterialCost, $OldCost, $QOH);
}
return $MaterialCost;
}

/*Iterates through the levels of the bom, recalculating each bom it meets*/
function UpdateCost($db, $Item) {
function UpdateCost($Item) {
//update the items cost itself first;
BomMaterialCost(strtoupper($Item),$db);
BomMaterialCost(strtoupper($Item));
$SQL = "SELECT parent FROM bom where component = '" . $Item . "'";
$Result = DB_query($SQL);
while ($MyRow=DB_fetch_array($Result)){
$NewParent = $MyRow['parent'];
$MaterialCost = BomMaterialCost($NewParent, $db);
$MaterialCost = BomMaterialCost($NewParent);
$SQL = "UPDATE stockmaster SET materialcost=" . $MaterialCost . " WHERE stockid='" . $NewParent . "'";
$result1 = DB_query($SQL);
if (DB_error_no()!=0) {
return 1;
}
UpdateCost($db, $NewParent);
UpdateCost($NewParent);
}
return 0;
}
Expand Down

0 comments on commit 2ebcfda

Please sign in to comment.