From: <dai...@us...> - 2010-08-08 07:43:20
|
Revision: 3687 http://web-erp.svn.sourceforge.net/web-erp/?rev=3687&view=rev Author: daintree Date: 2010-08-08 07:43:13 +0000 (Sun, 08 Aug 2010) Log Message: ----------- work on contracts Modified Paths: -------------- trunk/Contracts.php trunk/CounterSales.php trunk/DeliveryDetails.php trunk/SelectContract.php trunk/Stocks.php trunk/doc/Change.log.html trunk/doc/Manual/ManualCurrencies.html trunk/includes/DefineContractClass.php trunk/includes/MiscFunctions.php trunk/sql/mysql/weberp-demo.sql Modified: trunk/Contracts.php =================================================================== --- trunk/Contracts.php 2010-08-07 16:27:37 UTC (rev 3686) +++ trunk/Contracts.php 2010-08-08 07:43:13 UTC (rev 3687) @@ -52,7 +52,6 @@ $_POST['SelectedCustomer'] = $_GET['SelectedCustomer']; - $_SESSION['Contract'.$identifier]->Status =0; /*The customer is checked for credit and the Contract Object populated * using the usual logic of when a customer is selected * */ @@ -155,8 +154,8 @@ /*read in all the guff from the selected contract into the contract Class variable */ $ContractHeaderSQL = "SELECT contractdescription, - debtorno, - branchcode, + contracts.debtorno, + contracts.branchcode, status, categoryid, orderno, @@ -164,8 +163,16 @@ wo, requireddate, drawing, - exrate - FROM contracts + exrate, + debtorsmaster.name, + custbranch.brname, + debtorsmaster.currcode + FROM contracts INNER JOIN debtorsmaster + ON contracts.debtorno=debtorsmaster.debtorno + INNER JOIN currencies + ON debtorsmaster.currcode=currencies.currabrev + INNER JOIN custbranch + ON debtorsmaster.debtorno=custbranch.debtorno WHERE contractref= '" . $_GET['ModifyContractRef'] . "'"; $ErrMsg = _('The contract cannot be retrieved because'); @@ -187,6 +194,11 @@ $_SESSION['Contract'.$identifier]->RequiredDate = ConvertSQLDate($myrow['requireddate']); $_SESSION['Contract'.$identifier]->Drawing = $myrow['drawing']; $_SESSION['Contract'.$identifier]->ExRate = $myrow['exrate']; + $_SESSION['Contract'.$identifier]->BranchName = $myrow['brname']; + $_SESSION['RequireCustomerSelection'] = 0; + $_SESSION['Contract'.$identifier]->CustomerName = $myrow['name']; + $_SESSION['Contract'.$identifier]->CurrCode = $myrow['currcode']; + /*now populate the contract BOM array with the items required for the contract */ @@ -241,33 +253,36 @@ if (isset($_POST['CancelContract'])) { /*The cancel button on the header screen - to delete the contract */ - $OK_to_delete = 1; //assume this in the first instance + $OK_to_delete = true; //assume this in the first instance if(!isset($_SESSION['ExistingContract']) OR $_SESSION['ExistingContract']!=0) { - /* need to check that not already ordered by the customer - status = 0 */ - if($_SESSION['Contract'.$identifier]->Status==1){ - $result = DB_query('SELECT orderno FROM salesorders WHERE orderno=' . $_SESSION['Contract'.$identifier]->OrderNo,$db); - if (DB_num_rows($result)==1){ - $OK_to_delete =0; - prnMsg( _('The contract has already been ordered by the customer the order must also be deleted first before the contract can be deleted'),'warn'); - } + /* need to check that not already ordered by the customer - status = 100 */ + if($_SESSION['Contract'.$identifier]->Status==2){ + $OK_to_delete = false; + prnMsg( _('The contract has already been ordered by the customer the order must also be deleted first before the contract can be deleted'),'warn'); } } - if ($OK_to_delete==1){ - if($_SESSION['ExistingContract']!=0){ - - $sql = "DELETE FROM contractbom WHERE contractref='" . $_SESSION['Contract'.$identifier]->ContractRef . "'"; - $ErrMsg = _('The contract bill of materials could not be deleted because'); + + if ($OK_to_delete==true){ + $sql = "DELETE FROM contractbom WHERE contractref='" . $_SESSION['Contract'.$identifier]->ContractRef . "'"; + $ErrMsg = _('The contract bill of materials could not be deleted because'); + $DelResult=DB_query($sql,$db,$ErrMsg); + $sql = "DELETE FROM contractreqts WHERE contractref='" . $_SESSION['Contract'.$identifier]->ContractRef . "'"; + $ErrMsg = _('The contract requirements could not be deleted because'); + $DelResult=DB_query($sql,$db,$ErrMsg); + $sql= "DELETE FROM contracts WHERE contractref='" . $_SESSION['Contract'.$identifier]->ContractRef . "'"; + $ErrMsg = _('The contract could not be deleted because'); + $DelResult=DB_query($sql,$db,$ErrMsg); + + if ($_SESSION['Contract'.$identifier]->Status==1){ + $sql = "DELETE FROM salesorderdetails WHERE orderno='" . $_SESSION['Contract'.$identifier]->OrderNo . "'"; + $ErrMsg = _('The quotation line for the contract could not be deleted because'); $DelResult=DB_query($sql,$db,$ErrMsg); - $sql = "DELETE FROM contractreqts WHERE contractref='" . $_SESSION['Contract'.$identifier]->ContractRef . "'"; - $ErrMsg = _('The contract requirements could not be deleted because'); + $sql = "DELETE FROM salesorders WHERE orderno='" . $_SESSION['Contract'.$identifier]->OrderNo . "'"; + $ErrMsg = _('The quotation for the contract could not be deleted because'); $DelResult=DB_query($sql,$db,$ErrMsg); - $sql= "DELETE FROM contracts WHERE contractref='" . $_SESSION['Contract'.$identifier]->ContractRef . "'"; - $ErrMsg = _('The contract could not be deleted because'); - $DelResult=DB_query($sql,$db,$ErrMsg); - - prnMsg( _('Contract').' '.$_SESSION['Contract'.$identifier]->ContractRef.' '._('has been cancelled'), 'success'); - unset($_SESSION['ExistingContract']); } + prnMsg( _('Contract').' '.$_SESSION['Contract'.$identifier]->ContractRef.' '._('has been cancelled'), 'success'); + unset($_SESSION['ExistingContract']); unset($_SESSION['Contract'.$identifier]->ContractBOM); unset($_SESSION['Contract'.$identifier]->ContractReqts); unset($_SESSION['Contract'.$identifier]); @@ -283,10 +298,9 @@ $_SESSION['ExistingContract']= 0; $_SESSION['Contract'.$identifier] = new Contract; - - $_SESSION['Contract'.$identifier]->Status = 0; //new contracts are just quotes ... - - if ($_SESSION['Contract'.$identifier]->DebtorNo=='' OR !isset($_SESSION['Contract'.$identifier]->DebtorNo)){ + + if ($_SESSION['Contract'.$identifier]->DebtorNo=='' + OR !isset($_SESSION['Contract'.$identifier]->DebtorNo)){ /* a session variable will have to maintain if a supplier * has been selected for the order or not the session @@ -298,7 +312,7 @@ } } -if (isset($_POST['CommitContract'])){ +if (isset($_POST['CommitContract']) OR isset($_POST['CreateQuotation'])){ /*This is the bit where the contract object is commited to the database after a bit of error checking */ //First update the session['Contract'.$identifier] variable with all inputs from the form @@ -308,9 +322,14 @@ prnMsg(_('The contract reference is expected to be more than 2 characters long. Please alter the contract reference before proceeding.'),'error'); $InputError = true; } + if(ContainsIllegalCharacters($_POST['ContractRef'])){ + prnMsg(_('The contract reference cannot contain any spaces, slashes, or inverted commas. Please alter the contract reference before proceeding.'),'error'); + $InputError = true; + } + //The contractRef cannot be the same as an existing stockid or contractref $result = DB_query("SELECT stockid FROM stockmaster WHERE stockid='" . $_POST['ContractRef'] . "'",$db); - if (DB_num_rows($result)==1){ + if (DB_num_rows($result)==1 AND $_SESSION['Contract'.$identifier]->Status ==0){ prnMsg(_('The contract reference cannot be the same as a previously created stock item. Please modify the contract reference before continuing'),'error'); $InputError=true; } @@ -361,8 +380,6 @@ requireddate, margin, customerref, - quantityreqd, - units, exrate, status FROM contracts @@ -420,9 +437,37 @@ } if ($ExistingContract['status']==1 AND ! $InputError){ //then the quotation will need to be updated with the revised contract cost if necessary + $ContractBOMCost =0; + foreach ($_SESSION['Contract'.$identifier]->ContractBOM as $Component) { + $ContractBOMCost += ($Component->ItemCost * $Component->Quantity); + } + $ContractReqtsCost=0; + foreach ($_SESSION['Contract'.$identifier]->ContractReqts as $Requirement) { + $ContractReqtsCost += ($Requirement->CostPerUnit * $Requirement->Quantity); + } + $ContractCost = $ContractReqtsCost+$ContractBOMCost; + $ContractPrice = ($ContractBOMCost+$ContractReqtsCost)/((100-$_SESSION['Contract'.$identifier]->Margin)/100); + + $sql = "UPDATE stockmaster SET description='" . $_SESSION['Contract'.$identifier]->ContractDescription . "', + longdescription='" . $_SESSION['Contract'.$identifier]->ContractDescription . "', + categoryid = '" . $_SESSION['Contract'.$identifier]->CategoryID . "', + materialcost= '" . $ContractCost . "' + WHERE stockid ='" . $_SESSION['Contract'.$identifier]->ContractRef."'"; + $ErrMsg = _('The contract item could not be updated because'); + $DbgMsg = _('The SQL that was used to update the contract item failed was'); + $InsertNewItemResult = DB_query($sql,$db, $ErrMsg, $DbgMsg); + + //update the quotation + $sql = "UPDATE salesorderdetails + SET unitprice = '" . $ContractPrice* $_SESSION['Contract'.$identifier]->ExRate . "' + WHERE stkcode='" . $_SESSION['Contract'.$identifier]->ContractRef . "' + AND orderno='" . $_SESSION['Contract'.$identifier]->OrderNo . "'"; + $ErrMsg = _('The contract quotation could not be updated because'); + $DbgMsg = _('The SQL that failed to update the quotation was'); + $UpdQuoteResult = DB_query($sql,$db,$ErrMsg,$DbgMsg); + pnMsg(_('The contract quotation has been updated based on the new contract cost and margin'),'success'); + echo '<br><a href="' .$rootpath . '/SelectSalesOrder.php?OrderNumber=' . $_SESSION['Contract'.$identifier]->OrderNo . '&Quotations=Quotes_Only">' . _('Go to Quotation') . ' ' . $_SESSION['Contract'.$identifier]->OrderNo . '</a>'; - - } if ($ExistingContract['status'] == 0 AND $_POST['Status']==1){ /*we are updating the status on the contract to a quotation so we need to @@ -434,11 +479,6 @@ } } elseif (!$InputError) { /*Its a new contract - so insert */ - if ($_POST['Status'] !=0){ - //a new contract being created with a status of not a quotation - create it anyway but with status=0 - prnMsg(_('A contract can only be created with a status of costing initially'),'warn'); - } - $sql = "INSERT INTO contracts ( contractref, debtorno, branchcode, @@ -488,20 +528,168 @@ $result = DB_query($sql,$db,$ErrMsg); } prnMsg(_('The new contract has been added to the database'),'success'); - unset($_SESSION['Contract'.$identifier]->ContractBOM); - unset($_SESSION['Contract'.$identifier]->ContractReqts); - unset($_SESSION['Contract' . $identifier]); - unset($_POST['ContractRef']); - unset($_POST['Description']); - unset($_POST['CategoryID']); - unset($_POST['RequiredDate']); - unset($_POST['Margin']); - unset($_POST['CustomerRef']); - unset($_POST['ExRate']); - + } //end of adding a new contract }//end of commital to database +if(isset($_POST['CreateQuotation']) AND !$InputError){ +//Create a quotation for the contract as entered +//First need to create the item in stockmaster + +//calculate the item's contract cost + $ContractBOMCost =0; + foreach ($_SESSION['Contract'.$identifier]->ContractBOM as $Component) { + $ContractBOMCost += ($Component->ItemCost * $Component->Quantity); + } + $ContractReqtsCost=0; + foreach ($_SESSION['Contract'.$identifier]->ContractReqts as $Requirement) { + $ContractReqtsCost += ($Requirement->CostPerUnit * $Requirement->Quantity); + } + $ContractCost = $ContractReqtsCost+$ContractBOMCost; + $ContractPrice = ($ContractBOMCost+$ContractReqtsCost)/((100-$_SESSION['Contract'.$identifier]->Margin)/100); + +//Check if the item exists already + $sql = "SELECT * FROM stockmaster WHERE stockid='" . $_SESSION['Contract'.$identifier]->ContractRef."'"; + $ErrMsg = _('The item could not be retrieved because'); + $DbgMsg = _('The SQL that was used to find the item failed was'); + $result = DB_query($sql,$db, $ErrMsg, $DbgMsg); + if (DB_num_rows($result)==0) { //then the item doesn't currently exist so add it + + $sql = "INSERT INTO stockmaster (stockid, + description, + longdescription, + categoryid, + mbflag, + taxcatid, + materialcost) + VALUES ('" . $_SESSION['Contract'.$identifier]->ContractRef."', + '" . $_SESSION['Contract'.$identifier]->ContractDescription . "', + '" . $_SESSION['Contract'.$identifier]->ContractDescription . "', + '" . $_SESSION['Contract'.$identifier]->CategoryID . "', + 'M', + '" . $_SESSION['DefaultTaxCategory'] . "', + '" . $ContractCost . "')"; + $ErrMsg = _('The new contract item could not be added because'); + $DbgMsg = _('The SQL that was used to insert the contract item failed was'); + $InsertNewItemResult = DB_query($sql,$db, $ErrMsg, $DbgMsg); + $sql = "INSERT INTO locstock (loccode, + stockid) + SELECT locations.loccode, + '" . $_SESSION['Contract'.$identifier]->ContractRef . "' + FROM locations"; + + $ErrMsg = _('The locations for the item') . ' ' . $_SESSION['Contract'.$identifier]->ContractRef . ' ' . _('could not be added because'); + $DbgMsg = _('NB Locations records can be added by opening the utility page') . ' <i>Z_MakeStockLocns.php</i> ' . _('The SQL that was used to add the location records that failed was'); + $InsLocnsResult = DB_query($sql,$db,$ErrMsg,$DbgMsg); + } + //now add the quotation for the item + + //first need to get some more details from the customer/branch record + $sql = "SELECT debtorsmaster.salestype, + custbranch.defaultshipvia, + custbranch.brname, + custbranch.braddress1, + custbranch.braddress2, + custbranch.braddress3, + custbranch.braddress4, + custbranch.braddress5, + custbranch.braddress6, + custbranch.phoneno, + custbranch.email, + custbranch.defaultlocation + FROM debtorsmaster INNER JOIN custbranch + ON debtorsmaster.debtorno=custbranch.debtorno + WHERE debtorsmaster.debtorno='" . $_SESSION['Contract'.$identifier]->DebtorNo . "' + AND custbranch.branchcode='" . $_SESSION['Contract'.$identifier]->BranchCode . "'"; + $ErrMsg = _('The customer and branch details could not be retrieved because'); + $DbgMsg = _('The SQL that was used to find the customer and branch details failed was'); + $CustomerDetailsResult = DB_query($sql,$db, $ErrMsg, $DbgMsg); + + $CustomerDetailsRow = DB_fetch_array($CustomerDetailsResult); + + //start a DB transaction + $Result = DB_Txn_Begin($db); + $OrderNo = GetNextTransNo(30, $db); + $HeaderSQL = "INSERT INTO salesorders ( + orderno, + debtorno, + branchcode, + customerref, + orddate, + ordertype, + shipvia, + deliverto, + deladd1, + deladd2, + deladd3, + deladd4, + deladd5, + deladd6, + contactphone, + contactemail, + fromstkloc, + deliverydate, + quotedate, + quotation) + VALUES ( + '". $OrderNo . "', + '" . DB_escape_string($_SESSION['Contract'.$identifier]->DebtorNo) . "', + '" . DB_escape_string($_SESSION['Contract'.$identifier]->BranchCode) . "', + '". DB_escape_string($_SESSION['Contract'.$identifier]->CustomerRef) ."', + '" . DB_escape_string(Date('Y-m-d H:i')) . "', + '" . DB_escape_string($CustomerDetailsRow['salestype']) . "', + '" . DB_escape_string($CustomerDetailsRow['defaultshipvia']) ."', + '". DB_escape_string($CustomerDetailsRow['brname']) . "', + '" . DB_escape_string($CustomerDetailsRow['braddress1']) . "', + '" . DB_escape_string($CustomerDetailsRow['braddress2']) . "', + '" . DB_escape_string($CustomerDetailsRow['braddress3']) . "', + '" . DB_escape_string($CustomerDetailsRow['braddress4']) . "', + '" . DB_escape_string($CustomerDetailsRow['braddress5']) . "', + '" . DB_escape_string($CustomerDetailsRow['braddress6']) . "', + '" . DB_escape_string($CustomerDetailsRow['phoneno']) . "', + '" . DB_escape_string($CustomerDetailsRow['email']) . "', + '" . DB_escape_string($CustomerDetailsRow['defaultlocation']) ."', + '" . FormatDateForSQL($_SESSION['Contract'.$identifier]->RequiredDate) . "', + '" . Date('Y-m-d') . "', + '1' )"; + + $ErrMsg = _('The quotation cannot be added because'); + $InsertQryResult = DB_query($HeaderSQL,$db,$ErrMsg,true); + $LineItemSQL = "INSERT INTO salesorderdetails ( orderlineno, + orderno, + stkcode, + unitprice, + quantity, + poline, + itemdue) + VALUES ('0', + '" . $OrderNo . "', + '" . DB_escape_string($_SESSION['Contract'.$identifier]->ContractRef) . "', + '" . ($ContractPrice * $_SESSION['Contract'.$identifier]->ExRate) . "', + '1', + '" . DB_escape_string($_SESSION['Contract'.$identifier]->CustomerRef) . "', + '" . FormatDateForSQL($_SESSION['Contract'.$identifier]->RequiredDate) . "')"; + $DbgMsg = _('The SQL that failed was'); + $ErrMsg = _('Unable to add the quotation line'); + $Ins_LineItemResult = DB_query($LineItemSQL,$db,$ErrMsg,$DbgMsg,true); + //end of adding the quotation to salesorders/details + + //make the status of the contract 1 - to indicate that it is now quoted + $sql = "UPDATE contracts SET orderno='" . $OrderNo . "', + status='" . 1 . "' + WHERE contractref='" . DB_escape_string($_SESSION['Contract'.$identifier]->ContractRef) . "'"; + $ErrMsg = _('Unable to update the contract status and order number because'); + $UpdContractResult = DB_query($sql,$db,$ErrMsg,$DbgMsg,true); + $Result = DB_Txn_Commit($db); + $_SESSION['Contract'.$identifier]->Status=1; + $_SESSION['Contract'.$identifier]->OrderNo=$OrderNo; + prnMsg(_('The contract has been made into quotation number') . ' ' . $OrderNo,'info'); + echo '<br><a href="' . $rootpath . '/SelectSalesOrder.php?OrderNumber=' . $OrderNo . '&Quotations=Quotes_Only">' . _('Go to quotation number:') . ' ' . $OrderNo . '</a>'; + +} //end of if making a quotation + + + if (isset($_POST['SearchCustomers'])){ if (($_POST['CustKeywords']!='') AND (($_POST['CustCode']!='') OR ($_POST['CustPhone']!=''))) { @@ -723,7 +911,7 @@ echo '<table>'; echo '<tr><td>' . _('Contract Reference') . ':</td><td>'; - if ($_SESSION['Contract'.$identifier]->Status==100) { + if ($_SESSION['Contract'.$identifier]->Status==0) { /*Then the contract has not become an order yet and we can allow changes to the ContractRef */ echo '<input type="text" name="ContractRef" size=21 maxlength=20 value="' . $_SESSION['Contract'.$identifier]->ContractRef . '">'; } else { @@ -749,19 +937,6 @@ echo '</select><a target="_blank" href="'. $rootpath . '/StockCategories.php?' . SID . '">' . _('Add or Modify Contract Categories') . '</a></td></tr>'; - echo '<tr><td>' . _('Units of Measure') . ':</td><td><select name="Units">'; - $sql = 'SELECT unitname FROM unitsofmeasure ORDER by unitname'; - $UOMResult = DB_query($sql,$db); - - while( $UOMrow = DB_fetch_array($UOMResult) ) { - if (isset($_SESSION['Contract'.$identifier]->Units) AND $_SESSION['Contract'.$identifier]->Units==$UOMrow['unitname']){ - echo '<option selected value="' . $UOMrow['unitname'] . '">' . $UOMrow['unitname'] . '</option>'; - } else { - echo '<option value="' . $UOMrow['unitname'] . '">' . $UOMrow['unitname'] . '</option>'; - } - } - echo '</select></td></tr>'; - echo '<tr><td>' . _('Contract Description'); echo ':</td><td><textarea name="ContractDescription" style="width:100%" rows=5>' . $_SESSION['Contract'.$identifier]->ContractDescription . '</textarea></td></tr>'; @@ -795,15 +970,15 @@ if ($_SESSION['Contract'.$identifier]->Status == 0){ echo _('Contract Setup'); } elseif ($_SESSION['Contract'.$identifier]->Status == 1){ - echo _('Customer Already Quoted'); + echo _('Customer Quoted'); } elseif ($_SESSION['Contract'.$identifier]->Status == 2){ echo _('Order Placed'); } echo '</select></td></tr>'; - if ($_SESSION['Contract'.$identifier]->Status>=1) { - echo '<tr><td>' . _('Quotation Reference/Sales Order No') . ':</td><td>' . $_SESSION['Contract'.$identifier]->OrderNo . '</td></tr>'; + if ($_SESSION['Contract'.$identifier]->Status >=1) { + echo '<tr><td>' . _('Quotation Reference/Sales Order No') . ':</td><td><a href="' . $rootpath . '/SelectSalesOrder.php?OrderNumber=' . $_SESSION['Contract'.$identifier]->OrderNo . '&Quotations=Quotes_Only">' . $_SESSION['Contract'.$identifier]->OrderNo . '</a></td></tr>'; } - if ($_SESSION['Contract'.$identifier]->Status!=0) { + if ($_SESSION['Contract'.$identifier]->Status!=2) { echo '<tr><td>' . _('Contract Work Order Ref') . ':</td><td>' . $_SESSION['Contract'.$identifier]->WorkOrder . '</td></tr>'; } echo '</table><hr>'; @@ -858,10 +1033,18 @@ echo'<table><tr><th>' . _('Total Contract Cost') . '</th><th class="number">' . number_format(($ContractBOMCost+$ContractReqtsCost),2) . '</th><th>' . _('Contract Price') . '</th><th class="number">' . number_format(($ContractBOMCost+$ContractReqtsCost)/((100-$_SESSION['Contract'.$identifier]->Margin)/100),2) . '</th></tr></table>'; echo'<p></p>'; - echo '<div class="centre"><input type="submit" name="EnterContractBOM" value="' . _('Enter Items Required') . '"> - <input type=submit name="EnterContractRequirements" value="' . _('Enter Other Requirements') .'"> - <input type=submit name="CommitContract" value="' . _('Commit Changes') .'"></div>'; + <input type=submit name="EnterContractRequirements" value="' . _('Enter Other Requirements') .'">'; + if($_SESSION['Contract'.$identifier]->Status==0){ // not yet quoted + echo '<input type=submit name="CommitContract" value="' . _('Commit Changes') .'">'; + } elseif($_SESSION['Contract'.$identifier]->Status==1){ //quoted but not yet ordered + echo '<input type=submit name="CommitContract" value="' . _('Update Quotation') .'">'; + } + if($_SESSION['Contract'.$identifier]->Status==0){ //not yet quoted + echo ' <input type=submit name="CreateQuotation" value="' . _('Create Quotation') .'"></div>'; + } else { + echo '</div>'; + } if ($_SESSION['Contract'.$identifier]->Status!=2) { echo '<p><div class="centre"><input type="submit" name="CancelContract" value="' . _('Cancel and Delete Contract') . '"></div></p>'; } Modified: trunk/CounterSales.php =================================================================== --- trunk/CounterSales.php 2010-08-07 16:27:37 UTC (rev 3686) +++ trunk/CounterSales.php 2010-08-08 07:43:13 UTC (rev 3687) @@ -1601,10 +1601,10 @@ VALUES ( 10, " . $InvoiceNo . ", '" . $DefaultDispatchDate . "', - " . $PeriodNo . ", - " . GetCOGSGLAccount($Area, $OrderLine->StockID, $_SESSION['Items'.$identifier]->DefaultSalesType, $db) . ", + '" . $PeriodNo . "', + '" . GetCOGSGLAccount($Area, $OrderLine->StockID, $_SESSION['Items'.$identifier]->DefaultSalesType, $db) . "', '" . $_SESSION['Items'.$identifier]->DebtorNo . " - " . $OrderLine->StockID . " x " . $OrderLine->Quantity . " @ " . $OrderLine->StandardCost . "', - " . $OrderLine->StandardCost * $OrderLine->Quantity . ")"; + '" . $OrderLine->StandardCost * $OrderLine->Quantity . "')"; $ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The cost of sales GL posting could not be inserted because'); $DbgMsg = _('The following SQL to insert the GLTrans record was used'); @@ -1623,10 +1623,10 @@ VALUES ( 10, " . $InvoiceNo . ", '" . $DefaultDispatchDate . "', - " . $PeriodNo . ", - " . $StockGLCode['stockact'] . ", + '" . $PeriodNo . "', + '" . $StockGLCode['stockact'] . "', '" . $_SESSION['Items'.$identifier]->DebtorNo . " - " . $OrderLine->StockID . " x " . $OrderLine->Quantity . " @ " . $OrderLine->StandardCost . "', - " . (-$OrderLine->StandardCost * $OrderLine->Quantity) . ")"; + '" . (-$OrderLine->StandardCost * $OrderLine->Quantity) . "')"; $ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The stock side of the cost of sales GL posting could not be inserted because'); $DbgMsg = _('The following SQL to insert the GLTrans record was used'); @@ -1649,10 +1649,10 @@ VALUES ( 10, " . $InvoiceNo . ", '" . $DefaultDispatchDate . "', - " . $PeriodNo . ", - " . $SalesGLAccounts['salesglcode'] . ", + '" . $PeriodNo . "', + '" . $SalesGLAccounts['salesglcode'] . "', '" . $_SESSION['Items'.$identifier]->DebtorNo . " - " . $OrderLine->StockID . " x " . $OrderLine->Quantity . " @ " . $OrderLine->Price . "', - " . (-$OrderLine->Price * $OrderLine->Quantity/$ExRate) . ")"; + '" . (-$OrderLine->Price * $OrderLine->Quantity/$ExRate) . "')"; $ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The sales GL posting could not be inserted because'); $DbgMsg = '<br>' ._('The following SQL to insert the GLTrans record was used'); @@ -1671,10 +1671,10 @@ VALUES ( 10, " . $InvoiceNo . ", '" . $DefaultDispatchDate . "', - " . $PeriodNo . ", - " . $SalesGLAccounts['discountglcode'] . ", + '" . $PeriodNo . "', + '" . $SalesGLAccounts['discountglcode'] . "', '" . $_SESSION['Items'.$identifier]->DebtorNo . " - " . $OrderLine->StockID . " @ " . ($OrderLine->DiscountPercent * 100) . "%', - " . ($OrderLine->Price * $OrderLine->Quantity * $OrderLine->DiscountPercent/$ExRate) . ")"; + '" . ($OrderLine->Price * $OrderLine->Quantity * $OrderLine->DiscountPercent/$ExRate) . "')"; $ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The sales discount GL posting could not be inserted because'); $DbgMsg = _('The following SQL to insert the GLTrans record was used'); @@ -1697,10 +1697,10 @@ VALUES ( 10, " . $InvoiceNo . ", '" . $DefaultDispatchDate . "', - " . $PeriodNo . ", - " . $_SESSION['CompanyRecord']['debtorsact'] . ", + '" . $PeriodNo . "', + '" . $_SESSION['CompanyRecord']['debtorsact'] . "', '" . $_SESSION['Items'.$identifier]->DebtorNo . "', - " . (($_SESSION['Items'.$identifier]->total + $TaxTotal)/$ExRate) . ")"; + '" . (($_SESSION['Items'.$identifier]->total + $TaxTotal)/$ExRate) . "')"; $ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The total debtor GL posting could not be inserted because'); $DbgMsg = _('The following SQL to insert the total debtors control GLTrans record was used'); @@ -1720,10 +1720,10 @@ VALUES ( 10, " . $InvoiceNo . ", '" . $DefaultDispatchDate . "', - " . $PeriodNo . ", - " . $TaxGLCodes[$TaxAuthID] . ", + '" . $PeriodNo . "', + '" . $TaxGLCodes[$TaxAuthID] . "', '" . $_SESSION['Items'.$identifier]->DebtorNo . "', - " . (-$TaxAmount/$ExRate) . ")"; + '" . (-$TaxAmount/$ExRate) . "')"; $ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The tax GL posting could not be inserted because'); $DbgMsg = _('The following SQL to insert the GLTrans record was used'); @@ -1745,10 +1745,10 @@ VALUES (12, ' . $ReceiptNumber . ", '" . $DefaultDispatchDate . "', - " . $PeriodNo . ", + '" . $PeriodNo . "', '" . $_POST['BankAccount'] . "', '" . $_SESSION['Items'.$identifier]->LocationName . ' ' . _('Counter Sale') . ' ' . $InvoiceNo . "', - " . ($_POST['AmountPaid']/$ExRate) . ')'; + '" . ($_POST['AmountPaid']/$ExRate) . "')"; $DbgMsg = _('The SQL that failed to insert the GL transaction for the bank account debit was'); $ErrMsg = _('Cannot insert a GL transaction for the bank account debit'); $result = DB_query($SQL,$db,$ErrMsg,$DbgMsg,true); @@ -1764,11 +1764,10 @@ VALUES (12, ' . $ReceiptNumber . ", '" . $DefaultDispatchDate . "', - " . $PeriodNo . ', - ' . $_SESSION['CompanyRecord']['debtorsact'] . ", - '" . $_SESSION['Items'.$identifier]->LocationName . ' ' . _('Counter Sale') . ' ' . $InvoiceNo . "', - " . -($_POST['AmountPaid']/$ExRate) . ' - )'; + '" . $PeriodNo . "', + '" . $_SESSION['CompanyRecord']['debtorsact'] . "', + '" . $_SESSION['Items'.$identifier]->LocationName . ' ' . _('Counter Sale') . ' ' . $InvoiceNo . "', + '" . -($_POST['AmountPaid']/$ExRate) . "')"; $DbgMsg = _('The SQL that failed to insert the GL transaction for the debtors account credit was'); $ErrMsg = _('Cannot insert a GL transaction for the debtors account credit'); $result = DB_query($SQL,$db,$ErrMsg,$DbgMsg,true); @@ -1800,7 +1799,7 @@ //insert the banktrans record in the currency of the bank account - $SQL='INSERT INTO banktrans (type, + $SQL="INSERT INTO banktrans (type, transno, bankact, ref, @@ -1811,14 +1810,14 @@ amount, currcode) VALUES (12, - ' . $ReceiptNumber . ', - ' . $_POST['BankAccount'] . ", + '" . $ReceiptNumber . "', + '" . $_POST['BankAccount'] . "', '" . $_SESSION['Items'.$identifier]->LocationName . ' ' . _('Counter Sale') . ' ' . $InvoiceNo . "', - " . $ExRate . ", - " . $BankAccountExRate . ", + '" . $ExRate . "', + '" . $BankAccountExRate . "', '" . $DefaultDispatchDate . "', '" . $_POST['PaymentMethod'] . "', - " . ($_POST['AmountPaid'] * $BankAccountExRate) . ", + '" . ($_POST['AmountPaid'] * $BankAccountExRate) . "', '" . $_SESSION['Items'.$identifier]->DefaultCurrency . "')"; $DbgMsg = _('The SQL that failed to insert the bank account transaction was'); @@ -1843,11 +1842,11 @@ '" . $_SESSION['Items'.$identifier]->DebtorNo . "', '" . $DefaultDispatchDate . "', '" . date('Y-m-d H-i-s') . "', - " . $PeriodNo . ", - " . $InvoiceNo . ", - " . $ExRate . ", - " . -$_POST['AmountPaid'] . ", - " . -$_POST['AmountPaid'] . ", + '" . $PeriodNo . "', + '" . $InvoiceNo . "', + '" . $ExRate . "', + '" . -$_POST['AmountPaid'] . "', + '" . -$_POST['AmountPaid'] . "', '" . $_SESSION['Items'.$identifier]->LocationName . ' ' . _('Counter Sale') ."')"; $DbgMsg = _('The SQL that failed to insert the customer receipt transaction was'); @@ -1857,7 +1856,7 @@ $ReceiptDebtorTransID = DB_Last_Insert_ID($db,'debtortrans','id'); $SQL = "UPDATE debtorsmaster SET lastpaiddate = '" . $DefaultDispatchDate . "', - lastpaid=" . $_POST['AmountPaid'] ." + lastpaid='" . $_POST['AmountPaid'] . "' WHERE debtorsmaster.debtorno='" . $_SESSION['Items'.$identifier]->DebtorNo . "'"; $DbgMsg = _('The SQL that failed to update the date of the last payment received was'); @@ -1872,8 +1871,8 @@ transid_allocto ) VALUES (' . $_POST['AmountPaid'] . ", '" . $DefaultDispatchDate . "', - " . $ReceiptDebtorTransID . ", - " . $DebtorTransID . ')'; + '" . $ReceiptDebtorTransID . "', + '" . $DebtorTransID . "')"; $DbgMsg = _('The SQL that failed to insert the allocation of the receipt to the invoice was'); $ErrMsg = _('Cannot insert the customer allocation of the receipt to the invoice because'); $result = DB_query($SQL,$db,$ErrMsg,$DbgMsg,true); Modified: trunk/DeliveryDetails.php =================================================================== --- trunk/DeliveryDetails.php 2010-08-07 16:27:37 UTC (rev 3686) +++ trunk/DeliveryDetails.php 2010-08-08 07:43:13 UTC (rev 3687) @@ -601,9 +601,89 @@ $DelDate = FormatDateforSQL($_SESSION['Items'.$identifier]->DeliveryDate); $QuotDate = FormatDateforSQL($_SESSION['Items'.$identifier]->QuoteDate); $ConfDate = FormatDateforSQL($_SESSION['Items'.$identifier]->ConfirmedDate); - + $Result = DB_Txn_Begin($db); + /*see if this is a contract quotation being changed to an order? */ + if ($_SESSION['Items'.$identifier]->Quotation==0) { //now its being changed? to an order + $ContractResult = DB_query("SELECT contractref, + requireddate + FROM contracts WHERE orderno='" . $_SESSION['ExistingOrder'] ."' + AND status=1",$db); + if (DB_num_rows($ContractResult)==1){ //then it is a contract quotation being changed to an order + $ContractRow = DB_fetch_array($ContractResult); + $WONo = GetNextTransNo(40,$db); + $ErrMsg = _('Could not update the contract status'); + $DbgMsg = _('The SQL that failed to update the contract status was'); + $UpdContractResult=DB_query("UPDATE contracts SET status=2, + wo='" . $WONo . "' + WHERE orderno='" .$_SESSION['ExistingOrder'] . "'", $db,$ErrMsg,$DbgMsg,true); + $ErrMsg = _('Could not insert the contract bill of materials'); + $InsContractBOM = DB_query("INSERT INTO bom (parent, + component, + workcentreadded, + location, + effectiveafter, + effectiveto) + SELECT contractref, + stockid, + workcentreadded, + '" . $_SESSION['Items'.$identifier]->Location ."', + '" . Date('Y-m-d') . "', + '2037-12-31' + FROM contractbom + WHERE contractref='" . $ContractRow['contractref'] . "'",$db,$ErrMsg,$DbgMsg); + + $ErrMsg = _('Unable to insert a new work order for the sales order item'); + $InsWOResult = DB_query("INSERT INTO workorders (wo, + loccode, + requiredby, + startdate) + VALUES ('" . $WONo . "', + '" . $_SESSION['Items'.$identifier]->Location ."', + '" . $ContractRow['requireddate'] . "', + '" . Date('Y-m-d'). "')", + $db,$ErrMsg,$DbgMsg); + //Need to get the latest BOM to roll up cost but also add the contract other requirements + $CostResult = DB_query("SELECT SUM((materialcost+labourcost+overheadcost)*bom.quantity) AS cost + FROM stockmaster INNER JOIN contractbom + ON stockmaster.stockid=contractbom.stockid + WHERE contractbom.contractref='" . $ContractRow['contractref'] . "'", + $db); + $CostRow = DB_fetch_row($CostResult); + if (is_null($CostRow[0]) OR $CostRow[0]==0){ + $Cost =0; + prnMsg(_('In automatically creating a work order for') . ' ' . $ContractRow['contractref'] . ' ' . _('an item on this sales order, the cost of this item as accumulated from the sum of the component costs is nil. This could be because there is no bill of material set up ... you may wish to double check this'),'warn'); + } else { + $Cost = $CostRow[0]; //cost of contract BOM + } + $CostResult = DB_query("SELECT SUM(costperunit*quantity) AS cost + FROM contractreqts + WHERE contractreqts.contractref='" . $ContractRow['contractref'] . "'", + $db); + $CostRow = DB_fetch_row($CostResult); + //add other requirements cost to cost of contract BOM + $Cost += $CostRow[0]; + + // insert parent item info + $sql = "INSERT INTO woitems (wo, + stockid, + qtyreqd, + stdcost) + VALUES ( '" . $WONo . "', + '" . $ContractRow['contractref'] . "', + '1', + '" . $Cost . "')"; + $ErrMsg = _('The work order item could not be added'); + $result = DB_query($sql,$db,$ErrMsg,$DbgMsg,true); + + //Recursively insert real component requirements - see includes/SQL_CommonFunctions.in for function WoRealRequirements + WoRealRequirements($db, $WONo, $_SESSION['Items'.$identifier]->Location, $ContractRow['contractref']); + + } //end processing if the order was a contract quotation being changed to an order + } //end test to see if the order was a contract quotation being changed to an order + + $HeaderSQL = "UPDATE salesorders SET debtorno = '" . $_SESSION['Items'.$identifier]->DebtorNo . "', branchcode = '" . $_SESSION['Items'.$identifier]->Branch . "', @@ -625,9 +705,6 @@ contactemail = '" . $_SESSION['Items'.$identifier]->Email . "', freightcost = '" . $_SESSION['Items'.$identifier]->FreightCost ."', fromstkloc = '" . $_SESSION['Items'.$identifier]->Location ."', - deliverydate = '" . $DelDate . "', - quotedate = '" . $QuotDate . "', - confirmeddate = '" . $ConfDate . "', printedpackingslip = '" . $_POST['ReprintPackingSlip'] . "', quotation = '" . $_SESSION['Items'.$identifier]->Quotation . "', deliverblind = '" . $_SESSION['Items'.$identifier]->DeliverBlind . "' Modified: trunk/SelectContract.php =================================================================== --- trunk/SelectContract.php 2010-08-07 16:27:37 UTC (rev 3686) +++ trunk/SelectContract.php 2010-08-08 07:43:13 UTC (rev 3687) @@ -162,11 +162,11 @@ } $ModifyPage = $rootpath . '/Contracts.php?' . SID . '&ModifyContractRef=' . $myrow['contractref']; - $OrderModifyPage = $rootpath . '/SelectOrderItems.php?' . SID . '&ModifyOrderNo=' . $myrow['orderno']; + $OrderModifyPage = $rootpath . '/SelectOrderItems.php?' . SID . '&ModifyOrderNumber=' . $myrow['orderno']; $IssueToWOPage = $rootpath . '/WOIssue.php?' . SID . '&WO=' . $myrow['wo']; $FormatedRequiredDate = ConvertSQLDate($myrow['requireddate']); - if ($myrow['status']==0){ //still setting up the contract + if ($myrow['status']==0 OR $myrow['status']==1){ //still setting up the contract echo '<td><a href="' . $ModifyPage . '">' . _('Modify') . '</a></td>'; } else { echo '<td>' . _('n/a') . '</td>'; Modified: trunk/Stocks.php =================================================================== --- trunk/Stocks.php 2010-08-07 16:27:37 UTC (rev 3686) +++ trunk/Stocks.php 2010-08-08 07:43:13 UTC (rev 3687) @@ -102,7 +102,7 @@ $Errors[$i] = 'StockID'; $i++; } - if (strstr($StockID,' ') OR strstr($StockID,"'") OR strstr($StockID,'+') OR strstr($StockID,"\\") OR strstr($StockID,"\"") OR strstr($StockID,'&') OR strstr($StockID,'.') OR strstr($StockID,'"')) { + if (ContainsIllegalCharacters($StockID)) { $InputError = 1; prnMsg(_('The stock item code cannot contain any of the following characters') . " - ' & + \" \\ " . _('or a space'),'error'); $Errors[$i] = 'StockID'; Modified: trunk/doc/Change.log.html =================================================================== --- trunk/doc/Change.log.html 2010-08-07 16:27:37 UTC (rev 3686) +++ trunk/doc/Change.log.html 2010-08-08 07:43:13 UTC (rev 3687) @@ -1,5 +1,6 @@ <p><font SIZE=4 COLOR=BLUE><b>webERP Change Log</b></font></p> <p></p> +<p>08/08/10 Phil: Contracts.php SelectContracts.php DeliveryDetails.php - more work to convert Contracts to quotations and on conversion of contract quotations to orders to create contract work order to issue materials to <p>07/08/10 Tim: PDFLowGP.php - Sql quoting correction, layout changes, and assorted minor bug corrections</p> <p>07/08/10 Tim: PO_Items.php - Sql quoting correction, layout changes, and assorted minor bug corrections</p> <p>07/08/10 Tim: SelectCustomer.php - Unset $result variable once used as it was causing search errors later in the script</p> Modified: trunk/doc/Manual/ManualCurrencies.html =================================================================== --- trunk/doc/Manual/ManualCurrencies.html 2010-08-07 16:27:37 UTC (rev 3686) +++ trunk/doc/Manual/ManualCurrencies.html 2010-08-08 07:43:13 UTC (rev 3687) @@ -21,4 +21,4 @@ <br><br> For all credit ratings set up, this field indicates whether or not the rating is serious enough to prohibit future invoicing to customers set up with this credit rating. -<!-- Help End: CreditStatus --> +<!-- Help End: Currencies --> Modified: trunk/includes/DefineContractClass.php =================================================================== --- trunk/includes/DefineContractClass.php 2010-08-07 16:27:37 UTC (rev 3686) +++ trunk/includes/DefineContractClass.php 2010-08-08 07:43:13 UTC (rev 3687) @@ -11,7 +11,7 @@ var $CustomerName; var $BranchCode; var $BranchName; - var $Status; /* 0 = initiated - 1=quoted - 2=completed */ + var $Status; /* 100 = initiated - 1=quoted - 2=completed */ var $CategoryID; /* the category where the contract will be when converted to an item for quotation*/ var $OrderNo; /* the order number created when the contract is quoted */ var $CustomerRef; @@ -33,7 +33,7 @@ $this->ContractReqts = array(); $this->BOMComponentCounter=0; $this->RequirementsCounter=0; - $this->Status =100; + $this->Status = 0; } function Add_To_ContractBOM($StockID, Modified: trunk/includes/MiscFunctions.php =================================================================== --- trunk/includes/MiscFunctions.php 2010-08-07 16:27:37 UTC (rev 3686) +++ trunk/includes/MiscFunctions.php 2010-08-08 07:43:13 UTC (rev 3687) @@ -110,15 +110,15 @@ } +function ContainsIllegalCharacters ($CheckVariable) { -Function ContainsIllegalCharacters ($CheckVariable) { - if (strstr($CheckVariable,"'") OR strstr($CheckVariable,'+') OR strstr($CheckVariable,"\"") OR strstr($CheckVariable,'&') OR strstr($CheckVariable,"\\") - OR strstr($CheckVariable,'"')){ + OR strstr($CheckVariable,'"') + OR strstr($CheckVariable,' ')){ return true; } else { Modified: trunk/sql/mysql/weberp-demo.sql =================================================================== --- trunk/sql/mysql/weberp-demo.sql 2010-08-07 16:27:37 UTC (rev 3686) +++ trunk/sql/mysql/weberp-demo.sql 2010-08-08 07:43:13 UTC (rev 3687) @@ -10,7 +10,8 @@ /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; - +CREATE DATABASE weberpdemo; +USE weberpdemo; -- -- Table structure for table `accountgroups` -- This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |