[Weberp-svn] SF.net SVN: weberp:[8376] trunk
Brought to you by:
sotandeka,
tim_schofield
From: <tim...@us...> - 2011-12-24 22:42:54
|
Revision: 8376 http://weberp.svn.sourceforge.net/weberp/?rev=8376&view=rev Author: tim_schofield Date: 2011-12-24 22:42:48 +0000 (Sat, 24 Dec 2011) Log Message: ----------- Fix for multiple orders some inserted and some updated at the same time Modified Paths: -------------- trunk/DeliveryDetails.php trunk/SelectOrderItems.php trunk/includes/DefineCartClass.php trunk/includes/SelectOrderItems_IntoCart.inc Modified: trunk/DeliveryDetails.php =================================================================== --- trunk/DeliveryDetails.php 2011-12-24 22:42:31 UTC (rev 8375) +++ trunk/DeliveryDetails.php 2011-12-24 22:42:48 UTC (rev 8376) @@ -313,7 +313,7 @@ } #end if else freight charge not altered } #end if process order -if (isset($OK_to_PROCESS) and $OK_to_PROCESS == 1 and $_SESSION['ExistingOrder']==0){ +if (isset($OK_to_PROCESS) and $OK_to_PROCESS == 1 and $_SESSION['ExistingOrder'.$identifier]==0){ /* finally write the order header to the database and then the order line details */ @@ -648,7 +648,7 @@ include('includes/footer.inc'); exit; -} elseif (isset($OK_to_PROCESS) and $OK_to_PROCESS == 1 and $_SESSION['ExistingOrder']!=0){ +} elseif (isset($OK_to_PROCESS) and $OK_to_PROCESS == 1 and $_SESSION['ExistingOrder'.$identifier]!=0){ /* update the order header then update the old order line details and insert the new lines */ @@ -662,7 +662,7 @@ 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'] ."' + FROM contracts WHERE orderno='" . $_SESSION['ExistingOrder'.$identifier] ."' 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); @@ -671,7 +671,7 @@ $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); + WHERE orderno='" .$_SESSION['ExistingOrder'.$identifier] . "'", $db,$ErrMsg,$DbgMsg,true); $ErrMsg = _('Could not insert the contract bill of materials'); $InsContractBOM = DB_query("INSERT INTO bom (parent, component, @@ -763,7 +763,7 @@ printedpackingslip = '" . $_POST['ReprintPackingSlip'] . "', quotation = '" . $_SESSION['Items'.$identifier]->Quotation . "', deliverblind = '" . $_SESSION['Items'.$identifier]->DeliverBlind . "' - WHERE salesorders.orderno='" . $_SESSION['ExistingOrder'] ."'"; + WHERE salesorders.orderno='" . $_SESSION['ExistingOrder'.$identifier] ."'"; $DbgMsg = _('The SQL that was used to update the order and failed was'); $ErrMsg = _('The order cannot be updated because'); @@ -786,7 +786,7 @@ completed='" . $Completed . "', poline='" . $StockItem->POLine . "', itemdue='" . FormatDateForSQL($StockItem->ItemDue) . "' - WHERE salesorderdetails.orderno='" . $_SESSION['ExistingOrder'] . "' + WHERE salesorderdetails.orderno='" . $_SESSION['ExistingOrder'.$identifier] . "' AND salesorderdetails.orderlineno='" . $StockItem->LineNumber . "'"; $DbgMsg = _('The SQL that was used to modify the order line and failed was'); @@ -810,11 +810,11 @@ unset($_SESSION['Items'.$identifier]->LineItems); unset($_SESSION['Items'.$identifier]); - prnMsg(_('Order Number') .' ' . $_SESSION['ExistingOrder'] . ' ' . _('has been updated'),'success'); + prnMsg(_('Order Number') .' ' . $_SESSION['ExistingOrder'.$identifier] . ' ' . _('has been updated'),'success'); - echo '<br /><table class="selection"><tr><td><img src="'.$rootpath.'/css/'.$theme.'/images/printer.png" title="' . _('Print') . '" alt="" /></td><td><a href="' . $rootpath . '/PrintCustOrder.php?identifier='.$identifier . '&TransNo=' . $_SESSION['ExistingOrder'] . '">'. _('Print packing slip - pre-printed stationery') .'</a></td></tr>'; - echo '<tr><td><img src="'.$rootpath.'/css/'.$theme.'/images/printer.png" title="' . _('Print') . '" alt="" /></td><td><a target="_blank" href="' . $rootpath . '/PrintCustOrder_generic.php?identifier='.$identifier . '&TransNo=' . $_SESSION['ExistingOrder'] . '">'. _('Print packing slip') . ' (' . _('Laser') . ')' .'</a></td></tr>'; - echo '<tr><td><img src="'.$rootpath.'/css/'.$theme.'/images/reports.png" title="' . _('Invoice') . '" alt="" /></td><td><a href="' . $rootpath .'/ConfirmDispatch_Invoice.php?identifier='.$identifier . '&OrderNumber=' . $_SESSION['ExistingOrder'] . '">'. _('Confirm Order Delivery Quantities and Produce Invoice') .'</a></td></tr>'; + echo '<br /><table class="selection"><tr><td><img src="'.$rootpath.'/css/'.$theme.'/images/printer.png" title="' . _('Print') . '" alt="" /></td><td><a href="' . $rootpath . '/PrintCustOrder.php?identifier='.$identifier . '&TransNo=' . $_SESSION['ExistingOrder'.$identifier] . '">'. _('Print packing slip - pre-printed stationery') .'</a></td></tr>'; + echo '<tr><td><img src="'.$rootpath.'/css/'.$theme.'/images/printer.png" title="' . _('Print') . '" alt="" /></td><td><a target="_blank" href="' . $rootpath . '/PrintCustOrder_generic.php?identifier='.$identifier . '&TransNo=' . $_SESSION['ExistingOrder'.$identifier] . '">'. _('Print packing slip') . ' (' . _('Laser') . ')' .'</a></td></tr>'; + echo '<tr><td><img src="'.$rootpath.'/css/'.$theme.'/images/reports.png" title="' . _('Invoice') . '" alt="" /></td><td><a href="' . $rootpath .'/ConfirmDispatch_Invoice.php?identifier='.$identifier . '&OrderNumber=' . $_SESSION['ExistingOrder'.$identifier] . '">'. _('Confirm Order Delivery Quantities and Produce Invoice') .'</a></td></tr>'; echo '<tr><td><img src="'.$rootpath.'/css/'.$theme.'/images/sales.png" title="' . _('Order') . '" alt="" /></td><td><a href="' . $rootpath .'/SelectSalesOrder.php?identifier='.$identifier . '">'. _('Select A Different Order') .'</a></td></tr></table>'; include('includes/footer.inc'); exit; @@ -1152,7 +1152,7 @@ echo '<br /><div class="centre"><input type="submit" name="BackToLineDetails" value="' . _('Modify Order Lines') . '" /><br />'; -if ($_SESSION['ExistingOrder']==0){ +if ($_SESSION['ExistingOrder'.$identifier]==0){ echo '<br /><br /><input type="submit" name="ProcessOrder" value="' . _('Place Order') . '" />'; echo '<br /><br /><input type="submit" name="MakeRecurringOrder" value="' . _('Create Recurring Order') . '" />'; } else { Modified: trunk/SelectOrderItems.php =================================================================== --- trunk/SelectOrderItems.php 2011-12-24 22:42:31 UTC (rev 8375) +++ trunk/SelectOrderItems.php 2011-12-24 22:42:48 UTC (rev 8376) @@ -58,7 +58,7 @@ unset ($_SESSION['Items'.$identifier]); } - $_SESSION['ExistingOrder']=0; + $_SESSION['ExistingOrder'.$identifier]=0; $_SESSION['Items'.$identifier] = new cart; if (count($_SESSION['AllowedPageSecurityTokens'])==1){ //its a customer logon @@ -80,7 +80,7 @@ unset ($_SESSION['Items'.$identifier]->LineItems); unset ($_SESSION['Items'.$identifier]); } - $_SESSION['ExistingOrder']=$_GET['ModifyOrderNumber']; + $_SESSION['ExistingOrder'.$identifier]=$_GET['ModifyOrderNumber']; $_SESSION['RequireCustomerSelection'] = 0; $_SESSION['Items'.$identifier] = new cart; @@ -292,7 +292,7 @@ set to 1. The delivery check screen is where the details of the order are either updated or inserted depending on the value of ExistingOrder */ - $_SESSION['ExistingOrder']=0; + $_SESSION['ExistingOrder'.$identifier]=0; $_SESSION['Items'.$identifier] = new cart; $_SESSION['PrintedPackingSlip'] =0; /*Of course cos the order aint even started !!*/ @@ -717,11 +717,11 @@ if (isset($_POST['CancelOrder'])) { $OK_to_delete=1; //assume this in the first instance - if($_SESSION['ExistingOrder']!=0) { //need to check that not already dispatched + if($_SESSION['ExistingOrder'.$identifier]!=0) { //need to check that not already dispatched $sql = "SELECT qtyinvoiced FROM salesorderdetails - WHERE orderno='" . $_SESSION['ExistingOrder'] . "' + WHERE orderno='" . $_SESSION['ExistingOrder'.$identifier] . "' AND qtyinvoiced>0"; $InvQties = DB_query($sql,$db); @@ -735,17 +735,17 @@ } if ($OK_to_delete==1){ - if($_SESSION['ExistingOrder']!=0){ + if($_SESSION['ExistingOrder'.$identifier]!=0){ - $SQL = "DELETE FROM salesorderdetails WHERE salesorderdetails.orderno ='" . $_SESSION['ExistingOrder'] . "'"; + $SQL = "DELETE FROM salesorderdetails WHERE salesorderdetails.orderno ='" . $_SESSION['ExistingOrder'.$identifier] . "'"; $ErrMsg =_('The order detail lines could not be deleted because'); $DelResult=DB_query($SQL,$db,$ErrMsg); - $SQL = "DELETE FROM salesorders WHERE salesorders.orderno='" . $_SESSION['ExistingOrder'] . "'"; + $SQL = "DELETE FROM salesorders WHERE salesorders.orderno='" . $_SESSION['ExistingOrder'.$identifier] . "'"; $ErrMsg = _('The order header could not be deleted because'); $DelResult=DB_query($SQL,$db,$ErrMsg); - $_SESSION['ExistingOrder']=0; + $_SESSION['ExistingOrder'.$identifier]=0; } unset($_SESSION['Items'.$identifier]->LineItems); @@ -1156,6 +1156,11 @@ //Attempt to default the due date to something sensible? $_POST['ItemDue_' . $OrderLine->LineNumber] = DateAdd (Date($_SESSION['DefaultDateFormat']),'d', $_SESSION['Items'.$identifier]->DeliveryDays); } + if (isset($_POST['OverrideDiscount_' . $OrderLine->LineNumber])) { + $_POST['OverrideDiscount_' . $OrderLine->LineNumber]= 1; + } else { + $_POST['OverrideDiscount_' . $OrderLine->LineNumber]= 0; + } if ($Quantity<0 OR $Price <0 OR $DiscountPercentage >100 OR $DiscountPercentage <0){ prnMsg(_('The item could not be updated because you are attempting to set the quantity ordered to less than 0 or the price less than 0 or the discount more than 100% or less than 0%'),'warn'); } elseif($_SESSION['Items'.$identifier]->Some_Already_Delivered($OrderLine->LineNumber)!=0 AND $_SESSION['Items'.$identifier]->LineItems[$OrderLine->LineNumber]->Price != $Price) { @@ -1172,6 +1177,7 @@ OR $OrderLine->Narrative != $Narrative OR $OrderLine->ItemDue != $_POST['ItemDue_' . $OrderLine->LineNumber] OR $OrderLine->POLine != $_POST['POLine_' . $OrderLine->LineNumber] + OR $OrderLine->OverrideDiscount != $_POST['OverrideDiscount_' . $OrderLine->LineNumber] OR isset($PropertiesArray)) { $_SESSION['Items'.$identifier]->update_cart_item($OrderLine->LineNumber, $Quantity, @@ -1179,6 +1185,7 @@ $_POST['Units_' . $OrderLine->LineNumber], $_POST['ConversionFactor_' . $OrderLine->LineNumber], ($DiscountPercentage/100), + $_POST['OverrideDiscount_' . $OrderLine->LineNumber], $Narrative, 'Yes', /*Update DB */ $_POST['ItemDue_' . $OrderLine->LineNumber], @@ -1314,12 +1321,15 @@ AND discountcategory ='" . $OrderLine->DiscCat . "' AND quantitybreak <" . $QuantityOfDiscCat,$db); $myrow = DB_fetch_row($result); - if ($myrow[0]!=0){ /* need to update the lines affected */ - foreach ($_SESSION['Items'.$identifier]->LineItems as $StkItems_2) { - /* add up total quantity of all lines of this DiscCat */ - if ($StkItems_2->DiscCat==$OrderLine->DiscCat AND $StkItems_2->DiscountPercent == 0){ - $_SESSION['Items'.$identifier]->LineItems[$StkItems_2->LineNumber]->DiscountPercent = $myrow[0]; - } + if ($myrow[0] == NULL){ + $DiscountMatrixRate = 0; + } else { + $DiscountMatrixRate = $myrow[0]; + } + foreach ($_SESSION['Items'.$identifier]->LineItems as $StkItems_2) { + /* add up total quantity of all lines of this DiscCat */ + if ($StkItems_2->DiscCat==$OrderLine->DiscCat){ + $_SESSION['Items'.$identifier]->LineItems[$StkItems_2->LineNumber]->DiscountPercent = $myrow[0]; } } } @@ -1344,7 +1354,7 @@ <th>' . _('Price') . '</th>'; if (in_array(2,$_SESSION['AllowedPageSecurityTokens'])){ - echo '<th>' . _('Discount') . '</th> + echo '<th colspan="1">' . _('Discount') . '</th> <th>' . _('GP %') . '</th>'; } echo '<th>' . _('Total') . '</th> @@ -1396,8 +1406,13 @@ if (in_array(2,$_SESSION['AllowedPageSecurityTokens'])){ /*OK to display with discount if it is an internal user with appropriate permissions */ echo '<td><input class="number" type="text" name="Price_' . $OrderLine->LineNumber . '" size="16" maxlength="16" value="' . locale_money_format($OrderLine->Price, $_SESSION['Items'.$identifier]->DefaultCurrency) . '" /></td> - <td><input class="number" type="text" name="Discount_' . $OrderLine->LineNumber . '" size="5" maxlength="4" value="' . locale_number_format($OrderLine->DiscountPercent * 100, 2) . '" />%</td> - <td><input class="number" type="text" name="GPPercent_' . $OrderLine->LineNumber . '" size="8" maxlength="40" value="' . locale_number_format($OrderLine->GPPercent,2) . '" /></td>'; + <td><input class="number" type="text" name="Discount_' . $OrderLine->LineNumber . '" size="7" maxlength="6" value="' . locale_number_format($OrderLine->DiscountPercent * 100, 2) . '" />%'; + if ( $OrderLine->OverrideDiscount==1) { + echo '<input type="checkbox" checked="True" name="OverrideDiscount_' . $OrderLine->LineNumber . '" />'._('Override').'</td>'; + } else { + echo '<input type="checkbox" name="OverrideDiscount_' . $OrderLine->LineNumber . '" />'._('Override').'</td>'; + } + echo '<td><input class="number" type="text" name="GPPercent_' . $OrderLine->LineNumber . '" size="8" maxlength="40" value="' . locale_number_format($OrderLine->GPPercent,2) . '" /></td>'; } else { echo '<td class="number">' . $OrderLine->Price . '</td><td></td>'; echo '<input type="hidden" name="Price_' . $OrderLine->LineNumber . '" value="' . $OrderLine->Price . '" />'; Modified: trunk/includes/DefineCartClass.php =================================================================== --- trunk/includes/DefineCartClass.php 2011-12-24 22:42:31 UTC (rev 8375) +++ trunk/includes/DefineCartClass.php 2011-12-24 22:42:48 UTC (rev 8376) @@ -83,6 +83,7 @@ $ActDispatchDate=NULL, $QtyInvoiced=0, $DiscCat='', + $DiscOverride=0, $Controlled=0, $Serialised=0, $DecimalPlaces=0, @@ -116,6 +117,7 @@ $Qty, $Price, $Disc, + $DiscOverride, $Units, $ConversionFactor, $Volume, @@ -161,7 +163,7 @@ itemdue, poline) VALUES('" . $this->LineCounter . "', - '" . $_SESSION['ExistingOrder'] . "', + '" . $_SESSION['ExistingOrder'.$identifier] . "', '" . trim(mb_strtoupper($StockID)) ."', '" . $Qty . "', '" . $Price . "', @@ -187,13 +189,14 @@ $Units, $ConversionFactor=1, $Disc, + $DiscOverride, $Narrative, $UpdateDB='No', $ItemDue, $POLine, $GPPercent, $ItemProperties=array()){ - +echo $DiscOverride.'xxx'; if ($Qty>0){ $this->LineItems[$UpdateLineNumber]->Quantity = $Qty; } @@ -201,6 +204,7 @@ $this->LineItems[$UpdateLineNumber]->Units = $Units; $this->LineItems[$UpdateLineNumber]->ConversionFactor = $ConversionFactor; $this->LineItems[$UpdateLineNumber]->DiscountPercent = $Disc; + $this->LineItems[$UpdateLineNumber]->OverrideDiscount = $DiscOverride; $this->LineItems[$UpdateLineNumber]->Narrative = $Narrative; $this->LineItems[$UpdateLineNumber]->ItemDue = $ItemDue; $this->LineItems[$UpdateLineNumber]->POLine = $POLine; @@ -216,7 +220,7 @@ narrative ='" . DB_escape_string($Narrative) . "', itemdue = '" . FormatDateForSQL($ItemDue) . "', poline = '" . DB_escape_string($POLine) . "' - WHERE orderno='" . $_SESSION['ExistingOrder'] . "' + WHERE orderno='" . $_SESSION['ExistingOrder'.$identifier] . "' AND orderlineno='" . $UpdateLineNumber . "'" , $db , _('The order line number') . ' ' . $UpdateLineNumber . ' ' . _('could not be updated')); @@ -234,20 +238,20 @@ if ($this->Some_Already_Delivered($LineNumber)==0){ /* nothing has been delivered, delete it. */ $result = DB_query("DELETE FROM salesorderdetails - WHERE orderno='" . $_SESSION['ExistingOrder'] . "' + WHERE orderno='" . $_SESSION['ExistingOrder'.$identifier] . "' AND orderlineno='" . $LineNumber . "'", $db, _('The order line could not be deleted because') ); - prnMsg( _('Deleted Line Number'). ' ' . $LineNumber . ' ' . _('from existing Order Number').' ' . $_SESSION['ExistingOrder'], 'success'); + prnMsg( _('Deleted Line Number'). ' ' . $LineNumber . ' ' . _('from existing Order Number').' ' . $_SESSION['ExistingOrder'.$identifier], 'success'); } else { /* something has been delivered. Clear the remaining Qty and Mark Completed */ $result = DB_query("UPDATE salesorderdetails SET quantity=qtyinvoiced, completed=1 - WHERE orderno='".$_SESSION['ExistingOrder']."' AND orderlineno='" . $LineNumber . "'" , + WHERE orderno='".$_SESSION['ExistingOrder'.$identifier]."' AND orderlineno='" . $LineNumber . "'" , $db, _('The order line could not be updated as completed because') ); - prnMsg(_('Removed Remaining Quantity and set Line Number '). ' ' . $LineNumber . ' ' . _('as Completed for existing Order Number').' ' . $_SESSION['ExistingOrder'], 'success'); + prnMsg(_('Removed Remaining Quantity and set Line Number '). ' ' . $LineNumber . ' ' . _('as Completed for existing Order Number').' ' . $_SESSION['ExistingOrder'.$identifier], 'success'); } } /* Since we need to check the LineItem above and might affect the DB, don't unset until after DB is updates occur */ @@ -429,6 +433,7 @@ var $Quantity; var $Price; var $DiscountPercent; + var $OverrideDiscount; var $Units; var $ConversionFactor; var $Volume; @@ -462,6 +467,7 @@ $Qty, $Prc, $DiscPercent, + $DiscOverride, $Units, $ConversionFactor, $Volume, @@ -491,6 +497,7 @@ $this->Quantity = $Qty; $this->Price = $Prc; $this->DiscountPercent = $DiscPercent; + $this->DiscountOverride = $DiscOverride; $this->Units = $Units; $this->ConversionFactor = $ConversionFactor; $this->Volume = $Volume; Modified: trunk/includes/SelectOrderItems_IntoCart.inc =================================================================== --- trunk/includes/SelectOrderItems_IntoCart.inc 2011-12-24 22:42:31 UTC (rev 8375) +++ trunk/includes/SelectOrderItems_IntoCart.inc 2011-12-24 22:42:48 UTC (rev 8376) @@ -77,9 +77,9 @@ /*these checks above ensure that the item has a cost if the config.php variable AllowSalesOfZeroCostItems is set to false */ - if ($_SESSION['ExistingOrder']!=0){ + if ($_SESSION['ExistingOrder'.$identifier]!=0){ $UpdateDB = 'Yes'; - $result = DB_query("SELECT MAX(orderlineno) AS newlineno FROM salesorderdetails WHERE orderno='" . $_SESSION['ExistingOrder'] . "'",$db); + $result = DB_query("SELECT MAX(orderlineno) AS newlineno FROM salesorderdetails WHERE orderno='" . $_SESSION['ExistingOrder'.$identifier] . "'",$db); $MaxNumRow = DB_fetch_row($result); if ($MaxNumRow[0] != "" and $MaxNumRow[0] > 0) { $NewLineNo = $MaxNumRow[0]+1; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |