From: <dai...@us...> - 2011-06-23 09:44:12
|
Revision: 4604 http://web-erp.svn.sourceforge.net/web-erp/?rev=4604&view=rev Author: daintree Date: 2011-06-23 09:44:04 +0000 (Thu, 23 Jun 2011) Log Message: ----------- credit checks reinstated Modified Paths: -------------- trunk/AccountGroups.php trunk/PO_Items.php trunk/SelectOrderItems.php trunk/doc/Change.log trunk/includes/DefineCartClass.php trunk/includes/GetSalesTransGLCodes.inc trunk/includes/SelectOrderItems_IntoCart.inc Modified: trunk/AccountGroups.php =================================================================== --- trunk/AccountGroups.php 2011-06-21 09:28:57 UTC (rev 4603) +++ trunk/AccountGroups.php 2011-06-23 09:44:04 UTC (rev 4604) @@ -84,10 +84,10 @@ $i++; } else { $sql = "SELECT pandl, - sequenceintb, - sectioninaccounts - FROM accountgroups - WHERE groupname='" . $_POST['ParentGroupName'] . "'"; + sequenceintb, + sectioninaccounts + FROM accountgroups + WHERE groupname='" . $_POST['ParentGroupName'] . "'"; $DbgMsg = _('The SQL that was used to retrieve the information was'); $ErrMsg = _('Could not check whether the group is recursive because'); @@ -98,6 +98,7 @@ $_POST['SequenceInTB'] = $ParentGroupRow['sequenceintb']; $_POST['PandL'] = $ParentGroupRow['pandl']; $_POST['SectionInAccounts']= $ParentGroupRow['sectioninaccounts']; + prnMsg(_('Since this account group is a child group, the sequence in the trial balance, the section in the accounts and whether or not the account group appears in the balance sheet or profit and loss account are all properties inherited from the parent account group. Any changes made to these fields will have no effect.'),'warn'); } } if (!is_long((int) $_POST['SectionInAccounts'])) { Modified: trunk/PO_Items.php =================================================================== --- trunk/PO_Items.php 2011-06-21 09:28:57 UTC (rev 4603) +++ trunk/PO_Items.php 2011-06-23 09:44:04 UTC (rev 4604) @@ -515,7 +515,7 @@ foreach ($_SESSION['PO'.$identifier]->LineItems AS $OrderItem) { /* do a loop round the items on the order to see that the item is not already on this order */ - if (($OrderItem->StockID == $ItemCode) and ($OrderItem->Deleted==false)) { + if (($OrderItem->StockID == $ItemCode) AND ($OrderItem->Deleted==false)) { $AlreadyOnThisOrder = 1; prnMsg( _('The item') . ' ' . $ItemCode . ' ' . _('is already on this order') . '. ' . _('The system will not allow the same item on the order more than once') . '. ' . _('However you can change the quantity ordered of the existing line if necessary'),'error'); } @@ -524,12 +524,13 @@ } if ($AlreadyOnThisOrder!=1 AND $Quantity > 0){ $sql = "SELECT description, + longdescription, stockid, units, decimalplaces, stockact, accountname - FROM stockmaster INNER JOIN stockcategory + FROM stockmaster INNER JOIN stockcategory ON stockcategory.categoryid = stockmaster.categoryid INNER JOIN chartmaster ON chartmaster.accountcode = stockcategory.stockact @@ -548,16 +549,16 @@ suppliers_partno, leadtime, MAX(purchdata.effectivefrom) AS latesteffectivefrom - FROM purchdata - WHERE purchdata.supplierno = '" . $_SESSION['PO'.$identifier]->SupplierID . "' - AND purchdata.effectivefrom <='" . Date('Y-m-d') . "' - AND purchdata.stockid = '". $ItemCode . "' - GROUP BY purchdata.price, - purchdata.conversionfactor, - purchdata.supplierdescription, - purchdata.suppliersuom, - purchdata.suppliers_partno, - purchdata.leadtime"; + FROM purchdata + WHERE purchdata.supplierno = '" . $_SESSION['PO'.$identifier]->SupplierID . "' + AND purchdata.effectivefrom <='" . Date('Y-m-d') . "' + AND purchdata.stockid = '". $ItemCode . "' + GROUP BY purchdata.price, + purchdata.conversionfactor, + purchdata.supplierdescription, + purchdata.suppliersuom, + purchdata.suppliers_partno, + purchdata.leadtime"; $ErrMsg = _('The purchasing data for') . ' ' . $ItemCode . ' ' . _('could not be retrieved because'); $DbgMsg = _('The SQL used to retrieve the purchasing data but failed was'); Modified: trunk/SelectOrderItems.php =================================================================== --- trunk/SelectOrderItems.php 2011-06-21 09:28:57 UTC (rev 4603) +++ trunk/SelectOrderItems.php 2011-06-23 09:44:04 UTC (rev 4604) @@ -511,6 +511,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); if ($_SESSION['CheckCreditLimits']==1 AND $_SESSION['Items'.$identifier]->CreditAvailable <=0){ @@ -993,13 +994,13 @@ * and before that we need to add a disposal stock category - if not already created * first off get the details about the asset being disposed of */ $AssetDetailsResult = DB_query("SELECT fixedassets.description, - fixedassets.longdescription, - fixedassets.barcode, - fixedassetcategories.costact, - fixedassets.cost-fixedassets.accumdepn AS nbv - FROM fixedassetcategories INNER JOIN fixedassets - ON fixedassetcategories.categoryid=fixedassets.assetcategoryid - WHERE fixedassets.assetid='" . $_POST['AssetToDisposeOf'] . "'",$db); + fixedassets.longdescription, + fixedassets.barcode, + fixedassetcategories.costact, + fixedassets.cost-fixedassets.accumdepn AS nbv + FROM fixedassetcategories INNER JOIN fixedassets + ON fixedassetcategories.categoryid=fixedassets.assetcategoryid + WHERE fixedassets.assetid='" . $_POST['AssetToDisposeOf'] . "'",$db); $AssetRow = DB_fetch_array($AssetDetailsResult); /* Check that the stock category for disposal "ASSETS" is defined already */ @@ -1138,17 +1139,36 @@ OR $OrderLine->Narrative != $Narrative OR $OrderLine->ItemDue != $_POST['ItemDue_' . $OrderLine->LineNumber] OR $OrderLine->POLine != $_POST['POLine_' . $OrderLine->LineNumber]) { + + $WithinCreditLimit = true; + + if ($_SESSION['CheckCreditLimits'] > 0){ /*Check credit limits is 1 for warn + and 2 for prohibit sales */ + $DifferenceInOrderValue = ($Quantity*$Price*(1-$DiscountPercentage/100)) - ($OrderLine->Quantity*$OrderLine->Price*(1-$OrderLine->DiscountPercentage)); + + $_SESSION['Items'.$identifier]->CreditAvailable -= $DifferenceInOrderValue; - $_SESSION['Items'.$identifier]->update_cart_item($OrderLine->LineNumber, - $Quantity, - $Price, - ($DiscountPercentage/100), - $Narrative, - 'Yes', /*Update DB */ - $_POST['ItemDue_' . $OrderLine->LineNumber], - $_POST['POLine_' . $OrderLine->LineNumber], - $_POST['GPPercent_' . $OrderLine->LineNumber]); - } + if ($_SESSION['CheckCreditLimits']==1 AND $_SESSION['Items'.$identifier]->CreditAvailable <=0){ + prnMsg(_('The customer account will breach their credit limit'),'warn'); + } elseif ($_SESSION['CheckCreditLimits']==2 AND $_SESSION['Items'.$identifier]->CreditAvailable <=0){ + prnMsg(_('This change would put the customer over their credit limit and is prohibited'),'warn'); + $WithinCreditLimit = false; + $_SESSION['Items'.$identifier]->CreditAvailable += $DifferenceInOrderValue; + } + } + + if ($WithinCreditLimit){ + $_SESSION['Items'.$identifier]->update_cart_item($OrderLine->LineNumber, + $Quantity, + $Price, + ($DiscountPercentage/100), + $Narrative, + 'Yes', /*Update DB */ + $_POST['ItemDue_' . $OrderLine->LineNumber], + $_POST['POLine_' . $OrderLine->LineNumber], + $_POST['GPPercent_' . $OrderLine->LineNumber]); + } //within credit limit so make changes + } //there are changes to the order line to process } //page not called from itself - POST variables not set } } Modified: trunk/doc/Change.log =================================================================== --- trunk/doc/Change.log 2011-06-21 09:28:57 UTC (rev 4603) +++ trunk/doc/Change.log 2011-06-23 09:44:04 UTC (rev 4604) @@ -1,5 +1,7 @@ webERP Change Log +22/6/11 Phil: Added message to AccountGroups.php to show that child account groups cannot have changes to their account section, their profit and loss or balance sheet and sequence in TB as these properties belong only to parent account groups and are inherited by the kids +23/6/11 Phil: SelectOrderItems.php includes/DefineCartClass.php repaired credit checks 19/6/11 Phil: Credit_Invoice.php typos in quoting changes preventing posting credits on write offs also sql on gl account selection for write off 18/6/11 Phil: Made up a includes/LanguagesArray.php to contain a list of languages and the translated name of the language - updated WWW_Users.php and UserSettings.php and CustLoginSetup.php to use this array - so the selection of a language uses the language name rather than the locale codes 14/6/11 Phil: Added email to custcontacts and updated AddCustomerContacts.php SelectCustomer.php and Customers.php Modified: trunk/includes/DefineCartClass.php =================================================================== --- trunk/includes/DefineCartClass.php 2011-06-21 09:28:57 UTC (rev 4603) +++ trunk/includes/DefineCartClass.php 2011-06-23 09:44:04 UTC (rev 4604) @@ -148,21 +148,21 @@ global $db; $sql = "INSERT INTO salesorderdetails (orderlineno, - orderno, - stkcode, - quantity, - unitprice, - discountpercent, - itemdue, - poline) - VALUES(" . $this->LineCounter . ", - " . $_SESSION['ExistingOrder'] . ", - '" . trim(strtoupper($StockID)) ."', - " . $Qty . ", - " . $Price . ", - " . $Disc . ",' - " . $ItemDue . "', - " . $POLine . ")"; + orderno, + stkcode, + quantity, + unitprice, + discountpercent, + itemdue, + poline) + VALUES(" . $this->LineCounter . ", + " . $_SESSION['ExistingOrder'] . ", + '" . trim(strtoupper($StockID)) ."', + " . $Qty . ", + " . $Price . ", + " . $Disc . ",' + " . $ItemDue . "', + " . $POLine . ")"; $result = DB_query($sql, $db , _('The order line for') . ' ' . strtoupper($StockID) . ' ' ._('could not be inserted')); @@ -175,14 +175,14 @@ } function update_cart_item( $UpdateLineNumber, - $Qty, - $Price, - $Disc, - $Narrative, - $UpdateDB='No', - $ItemDue, - $POLine, - $GPPercent){ + $Qty, + $Price, + $Disc, + $Narrative, + $UpdateDB='No', + $ItemDue, + $POLine, + $GPPercent){ if ($Qty>0){ $this->LineItems[$UpdateLineNumber]->Quantity = $Qty; @@ -236,6 +236,7 @@ } } /* Since we need to check the LineItem above and might affect the DB, don't unset until after DB is updates occur */ + $this->CreditAvailable += ($this->LineItems[$LineNumber]->Quantity*$this->LineItems[$LineNumber]->Price*(1-$this->LineItems[$LineNumber]->DiscountPercent)); unset($this->LineItems[$LineNumber]); $this->ItemsOrdered--; Modified: trunk/includes/GetSalesTransGLCodes.inc =================================================================== --- trunk/includes/GetSalesTransGLCodes.inc 2011-06-21 09:28:57 UTC (rev 4603) +++ trunk/includes/GetSalesTransGLCodes.inc 2011-06-23 09:44:04 UTC (rev 4604) @@ -71,7 +71,7 @@ FROM cogsglpostings WHERE area = 'AN' AND salestype='AN' - AND stkcat = '$StockCategory'"; + AND stkcat = '" . $StockCategory . "'"; $Result = DB_query($SQL,$db,$ErrMsg,$DbgMsg); } @@ -81,7 +81,7 @@ DB_free_result($Result); $SQL = "SELECT glcode FROM cogsglpostings - WHERE area = '$Area' + WHERE area = '" . $Area . "' AND stkcat = 'ANY' AND salestype='AN'"; $Result = DB_query($SQL,$db,$ErrMsg,$DbgMsg); @@ -112,7 +112,7 @@ /*The default if all else fails */ /*Check GL account 1 exists */ prnMsg(_('Could not determine the correct general ledger account to use for posting the cost of this sale. Go to the setup menu and define appropriate COGS (Cost Of Goods Sold) accounts. To enable this invoice to be posted it has been posted to default sales and COGS - account number 1'),'warn'); - $SQL = 'SELECT accountcode FROM chartmaster WHERE accountcode=1'; + $SQL = "SELECT accountcode FROM chartmaster WHERE accountcode=1"; $Result = DB_query($SQL,$db); if (DB_num_rows($Result)==0){ /*It doesn't exist so create it */ $Result = DB_query("SELECT groupname FROM accountgroups WHERE groupname='Sales'",$db); @@ -177,12 +177,12 @@ if (DB_num_rows($Result)==0){ DB_free_result($Result); - $SQL = "SELECT salesglcode, - discountglcode - FROM salesglpostings - WHERE area = '" . $Area . "' - AND stkcat = '" . $StockCategory . "' - AND salestype = 'AN'"; + $SQL = "SELECT salesglcode, + discountglcode + FROM salesglpostings + WHERE area = '" . $Area . "' + AND stkcat = '" . $StockCategory . "' + AND salestype = 'AN'"; $Result = DB_query($SQL,$db,$ErrMsg,$DbgMsg); } @@ -190,11 +190,11 @@ if (DB_num_rows($Result)==0){ DB_free_result($Result); $SQL = "SELECT salesglcode, - discountglcode - FROM salesglpostings - WHERE area = '" . $Area . "' - AND stkcat = 'ANY' - AND salestype = '" . $SalesType . "'"; + discountglcode + FROM salesglpostings + WHERE area = '" . $Area . "' + AND stkcat = 'ANY' + AND salestype = '" . $SalesType . "'"; $Result = DB_query($SQL,$db,$ErrMsg,$DbgMsg); } @@ -202,11 +202,11 @@ if (DB_num_rows($Result)==0){ DB_free_result($Result); $SQL = "SELECT salesglcode, - discountglcode - FROM salesglpostings - WHERE area = 'AN' - AND salestype='AN' - AND stkcat = '$StockCategory'"; + discountglcode + FROM salesglpostings + WHERE area = 'AN' + AND salestype='AN' + AND stkcat = '" . $StockCategory . "'"; $Result = DB_query($SQL,$db,$ErrMsg,$DbgMsg); } @@ -214,11 +214,11 @@ if (DB_num_rows($Result)==0){ DB_free_result($Result); $SQL = "SELECT salesglcode, - discountglcode - FROM salesglpostings - WHERE area = '$Area' - AND stkcat = 'ANY' - AND salestype='AN'"; + discountglcode + FROM salesglpostings + WHERE area = '" . $Area . "' + AND stkcat = 'ANY' + AND salestype='AN'"; $Result = DB_query($SQL,$db,$ErrMsg,$DbgMsg); } @@ -226,11 +226,11 @@ if (DB_num_rows($Result)==0) { DB_free_result($Result); $SQL = "SELECT salesglcode, - discountglcode - FROM salesglpostings - WHERE area = 'AN' - AND stkcat = 'ANY' - AND salestype = '" . $SalesType . "'"; + discountglcode + FROM salesglpostings + WHERE area = 'AN' + AND stkcat = 'ANY' + AND salestype = '" . $SalesType . "'"; $Result = DB_query($SQL,$db,$ErrMsg,$DbgMsg); } @@ -238,11 +238,11 @@ DB_free_result($Result); $SQL = "SELECT salesglcode, - discountglcode - FROM salesglpostings - WHERE area = 'AN' - AND stkcat = 'ANY' - AND salestype='AN'"; + discountglcode + FROM salesglpostings + WHERE area = 'AN' + AND stkcat = 'ANY' + AND salestype='AN'"; $Result = DB_query($SQL,$db,$ErrMsg,$DbgMsg); } @@ -250,30 +250,30 @@ /*The default if all else fails */ prnMsg(_('Could not determine the correct general ledger account to use for posting this sale to. Go to the setup menu and define appropriate Sale GL Posting accounts. To enable this invoice to be posted it has been posted to default sales and COGS - account number 1'),'warn'); /*Check GL account 1 exists */ - $SQL = 'SELECT accountcode FROM chartmaster WHERE accountcode=1'; + $SQL = "SELECT accountcode FROM chartmaster WHERE accountcode=1"; $Result = DB_query($SQL,$db); if (DB_num_rows($Result)==0){ /*It doesn't exist so create it */ /*First check the account group sales exists */ $Result = DB_query("SELECT groupname FROM accountgroups WHERE groupname='Sales'",$db); if (DB_num_rows($Result)==0) { - $Result = DB_query("INSERT INTO accountgroups (groupname, - sectioninaccounts, - pandl, - sequenceintb) - VALUES ('Sales', - 1, - 1, - 5)", - $db); + $Result = DB_query("INSERT INTO accountgroups (groupname, + sectioninaccounts, + pandl, + sequenceintb) + VALUES ('Sales', + 1, + 1, + 5)", + $db); } $SQL = "INSERT INTO chartmaster VALUES (1, 'Default Sales and COGS', 'Sales')"; $Result = DB_query($SQL,$db); } - return array(salesglcode=>1, - discountglcode=>1); + return array('salesglcode'=>1, + 'discountglcode'=>1); } $myrow = DB_fetch_array($Result); - Return $myrow; + return $myrow; } ?> \ No newline at end of file Modified: trunk/includes/SelectOrderItems_IntoCart.inc =================================================================== --- trunk/includes/SelectOrderItems_IntoCart.inc 2011-06-21 09:28:57 UTC (rev 4603) +++ trunk/includes/SelectOrderItems_IntoCart.inc 2011-06-23 09:44:04 UTC (rev 4604) @@ -111,24 +111,22 @@ $WithinCreditLimit = true; - if (!isset($_SESSION['WarnOnce']) and $_SESSION['Items'.$identifier]->SpecialInstructions) { + if ($_SESSION['Items'.$identifier]->SpecialInstructions) { prnMsg($_SESSION['Items'.$identifier]->SpecialInstructions,'warn'); - $WarnOnce=1; } if ($_SESSION['CheckCreditLimits'] > 0){ /*Check credit limits is 1 for warn and 2 for prohibit sales */ $_SESSION['Items'.$identifier]->CreditAvailable -= round(($NewItemQty * $Price * (1- $Discount)),2); if ($_SESSION['CheckCreditLimits']==1 AND $_SESSION['Items'.$identifier]->CreditAvailable <=0){ - if (isset($_SESSION['WarnOnce']) and $_SESSION['WarnOnce'] < 2) prnMsg(_('The customer account will breach their credit limit'),'warn'); - $_SESSION['WarnOnce']=2; + prnMsg(_('The customer account will breach their credit limit'),'warn'); } elseif ($_SESSION['CheckCreditLimits']==2 AND $_SESSION['Items'.$identifier]->CreditAvailable <=0){ prnMsg(_('No more lines can be added to this order the customer account is currently at or over their credit limit'),'warn'); $WithinCreditLimit = false; } } - if ($WithinCreditLimit ==true){ + if ($WithinCreditLimit == true){ $_SESSION['Items'.$identifier]->add_to_cart ($NewItem, $NewItemQty, $myItemRow['description'], This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |