From: <dai...@us...> - 2011-09-10 04:39:26
|
Revision: 4683 http://web-erp.svn.sourceforge.net/web-erp/?rev=4683&view=rev Author: daintree Date: 2011-09-10 04:39:18 +0000 (Sat, 10 Sep 2011) Log Message: ----------- number formatting Modified Paths: -------------- trunk/DeliveryDetails.php trunk/SelectOrderItems.php trunk/includes/DefineCartClass.php trunk/includes/LanguageSetup.php trunk/includes/MiscFunctions.php Modified: trunk/DeliveryDetails.php =================================================================== --- trunk/DeliveryDetails.php 2011-09-09 03:39:04 UTC (rev 4682) +++ trunk/DeliveryDetails.php 2011-09-10 04:39:18 UTC (rev 4683) @@ -358,7 +358,7 @@ '". DB_escape_string($_SESSION['Items'.$identifier]->Comments) ."', '" . Date('Y-m-d H:i') . "', '" . $_SESSION['Items'.$identifier]->DefaultSalesType . "', - '" . $_POST['ShipVia'] ."', + '" . DB_escape_string($_POST['ShipVia']) ."', '". DB_escape_string($_SESSION['Items'.$identifier]->DeliverTo) . "', '" . DB_escape_string($_SESSION['Items'.$identifier]->BuyerName) . "', '" . DB_escape_string($_SESSION['Items'.$identifier]->DelAdd1) . "', @@ -367,9 +367,9 @@ '" . DB_escape_string($_SESSION['Items'.$identifier]->DelAdd4) . "', '" . DB_escape_string($_SESSION['Items'.$identifier]->DelAdd5) . "', '" . DB_escape_string($_SESSION['Items'.$identifier]->DelAdd6) . "', - '" . $_SESSION['Items'.$identifier]->PhoneNo . "', - '" . $_SESSION['Items'.$identifier]->Email . "', - '" . $_SESSION['Items'.$identifier]->FreightCost ."', + '" . DB_escape_string($_SESSION['Items'.$identifier]->PhoneNo) . "', + '" . DB_escape_string($_SESSION['Items'.$identifier]->Email) . "', + '" . filter_number_format($_SESSION['Items'.$identifier]->FreightCost) ."', '" . $_SESSION['Items'.$identifier]->Location ."', '" . $DelDate . "', '" . $QuotDate . "', @@ -400,9 +400,9 @@ '" . $StockItem->LineNumber . "', '" . $OrderNo . "', '" . $StockItem->StockID . "', - '" . $StockItem->Price . "', - '" . $StockItem->Quantity . "', - '" . floatval($StockItem->DiscountPercent) . "', + '" . filter_number_format($StockItem->Price) . "', + '" . filter_number_format($StockItem->Quantity) . "', + '" . filter_number_format(floatval($StockItem->DiscountPercent)) . "', '" . DB_escape_string($StockItem->Narrative) . "', '" . $StockItem->POLine . "', '" . FormatDateForSQL($StockItem->ItemDue) . "' @@ -511,8 +511,8 @@ stdcost) VALUES ( '" . $WONo . "', '" . $StockItem->StockID . "', - '" . $WOQuantity . "', - '" . $Cost . "')"; + '" . filter_number_format($WOQuantity) . "', + '" . filter_number_format($Cost) . "')"; $ErrMsg = _('The work order item could not be added'); $result = DB_query($sql,$db,$ErrMsg,$DbgMsg,true); @@ -699,7 +699,7 @@ VALUES ( '" . $WONo . "', '" . $ContractRow['contractref'] . "', '1', - '" . $Cost . "')"; + '" . filter_number_format($Cost) . "')"; $ErrMsg = _('The work order item could not be added'); $result = DB_query($sql,$db,$ErrMsg,$DbgMsg,true); @@ -727,9 +727,9 @@ deladd4 = '" . DB_escape_string($_SESSION['Items'.$identifier]->DelAdd4) . "', deladd5 = '" . DB_escape_string($_SESSION['Items'.$identifier]->DelAdd5) . "', deladd6 = '" . DB_escape_string($_SESSION['Items'.$identifier]->DelAdd6) . "', - contactphone = '" . $_SESSION['Items'.$identifier]->PhoneNo . "', - contactemail = '" . $_SESSION['Items'.$identifier]->Email . "', - freightcost = '" . $_SESSION['Items'.$identifier]->FreightCost ."', + contactphone = '" . DB_escape_string($_SESSION['Items'.$identifier]->PhoneNo) . "', + contactemail = '" . DB_escape_string($_SESSION['Items'.$identifier]->Email) . "', + freightcost = '" . filter_number_format($_SESSION['Items'.$identifier]->FreightCost) ."', fromstkloc = '" . $_SESSION['Items'.$identifier]->Location ."', printedpackingslip = '" . $_POST['ReprintPackingSlip'] . "', quotation = '" . $_SESSION['Items'.$identifier]->Quotation . "', @@ -751,9 +751,9 @@ $Completed = 0; } - $LineItemsSQL = "UPDATE salesorderdetails SET unitprice='" . $StockItem->Price . "', - quantity='" . $StockItem->Quantity . "', - discountpercent='" . floatval($StockItem->DiscountPercent) . "', + $LineItemsSQL = "UPDATE salesorderdetails SET unitprice='" . filter_number_format($StockItem->Price) . "', + quantity='" . filter_number_format($StockItem->Quantity) . "', + discountpercent='" . filter_number_format(floatval($StockItem->DiscountPercent)) . "', completed='" . $Completed . "', poline='" . $StockItem->POLine . "', itemdue='" . FormatDateForSQL($StockItem->ItemDue) . "' @@ -837,8 +837,8 @@ foreach ($_SESSION['Items'.$identifier]->LineItems as $StockItem) { $LineTotal = $StockItem->Quantity * $StockItem->Price * (1 - $StockItem->DiscountPercent); - $DisplayLineTotal = locale_number_format($LineTotal,$_SESSION['Items'.$identifier]->CurrDecimalPlaces); - $DisplayPrice = locale_number_format($StockItem->Price,$_SESSION['Items'.$identifier]->CurrDecimalPlaces); + $DisplayLineTotal = locale_money_format($LineTotal,$_SESSION['Items'.$identifier]->CurrDecimalPlaces); + $DisplayPrice = locale_money_format($StockItem->Price,$_SESSION['Items'.$identifier]->CurrDecimalPlaces); $DisplayQuantity = locale_number_format($StockItem->Quantity,$StockItem->DecimalPlaces); $DisplayDiscount = locale_number_format(($StockItem->DiscountPercent * 100),2); @@ -865,7 +865,7 @@ $_SESSION['Items'.$identifier]->totalWeight = $_SESSION['Items'.$identifier]->totalWeight + ($StockItem->Quantity * $StockItem->Weight); } - $DisplayTotal = locale_number_format($_SESSION['Items'.$identifier]->total,2); + $DisplayTotal = locale_money_format($_SESSION['Items'.$identifier]->total,2); echo '<tr class="EvenTableRows"> <td colspan=6 class=number><b>'. _('TOTAL Excl Tax/Freight') .'</b></td> <td class=number>'.$DisplayTotal.'</td> @@ -901,8 +901,8 @@ foreach ($_SESSION['Items'.$identifier]->LineItems as $StockItem) { $LineTotal = $StockItem->Quantity * $StockItem->Price * (1 - $StockItem->DiscountPercent); - $DisplayLineTotal = locale_number_format($LineTotal,$_SESSION['Items'.$identifier]->CurrDecimalPlaces); - $DisplayPrice = locale_number_format($StockItem->Price,$_SESSION['Items'.$identifier]->CurrDecimalPlaces); + $DisplayLineTotal = locale_money_format($LineTotal,$_SESSION['Items'.$identifier]->CurrDecimalPlaces); + $DisplayPrice = locale_money_format($StockItem->Price,$_SESSION['Items'.$identifier]->CurrDecimalPlaces); $DisplayQuantity = locale_number_format($StockItem->Quantity,$StockItem->DecimalPlaces); if ($k==1){ @@ -925,7 +925,7 @@ } - $DisplayTotal = locale_number_format($_SESSION['Items'.$identifier]->total,$_SESSION['Items'.$identifier]->CurrDecimalPlaces); + $DisplayTotal = locale_money_format($_SESSION['Items'.$identifier]->total,$_SESSION['Items'.$identifier]->CurrDecimalPlaces); echo '<table class="selection"> <tr> <td>'. _('Total Weight') .':</td> Modified: trunk/SelectOrderItems.php =================================================================== --- trunk/SelectOrderItems.php 2011-09-09 03:39:04 UTC (rev 4682) +++ trunk/SelectOrderItems.php 2011-09-10 04:39:18 UTC (rev 4683) @@ -25,13 +25,13 @@ if (isset($_POST['SelectingOrderItems'])){ foreach ($_POST as $FormVariable => $Quantity) { if (mb_strpos($FormVariable,'OrderQty')!==false) { - $NewItem_array[$_POST['StockID' . mb_substr($FormVariable,8)]] = trim($Quantity); + $NewItem_array[$_POST['StockID' . mb_substr($FormVariable,8)]] = filter_number_format(trim($Quantity)); } } } if (isset($_GET['NewItem'])){ - $NewItem = trim($_GET['NewItem']); + $NewItem = filter_number_format(trim($_GET['NewItem'])); } @@ -124,7 +124,7 @@ ON locations.loccode=salesorders.fromstkloc INNER JOIN currencies ON debtorsmaster.currcode=currencies.currabrev - WHERE salesorders.orderno = '" . $_GET['ModifyOrderNumber'] . "'"; + WHERE salesorders.orderno = '" . filter_number_format($_GET['ModifyOrderNumber']) . "'"; $ErrMsg = _('The order cannot be retrieved because'); $GetOrdHdrResult = DB_query($OrderHeaderSQL,$db,$ErrMsg); @@ -294,80 +294,34 @@ //Customer logins are not allowed to select other customers henc in_array(2,$_SESSION['AllowedPageSecurityTokens']) if (isset($_POST['SearchCust']) AND $_SESSION['RequireCustomerSelection']==1 AND in_array(2,$_SESSION['AllowedPageSecurityTokens'])){ - if (($_POST['CustKeywords']!='') AND (($_POST['CustCode']!='') OR ($_POST['CustPhone']!=''))) { - prnMsg( _('Customer Branch Name keywords have been used in preference to the Customer Branch Code or Branch Phone Number entered'), 'warn'); - } - if (($_POST['CustCode']!='') AND ($_POST['CustPhone']!='')) { - prnMsg(_('Customer Branch Code has been used in preference to the Customer Branch Phone Number entered'), 'warn'); - } if (($_POST['CustKeywords']=='') AND ($_POST['CustCode']=='') AND ($_POST['CustPhone']=='')) { prnMsg(_('At least one Customer Branch Name keyword OR an extract of a Customer Branch Code or Branch Phone Number must be entered for the search'), 'warn'); } else { - if (mb_strlen($_POST['CustKeywords'])>0) { //insert wildcard characters in spaces - $_POST['CustKeywords'] = mb_strtoupper(trim($_POST['CustKeywords'])); - $SearchString = '%' . str_replace(' ', '%', $_POST['CustKeywords']) . '%'; + $_POST['CustKeywords'] = mb_strtoupper(trim($_POST['CustKeywords'])); + $SearchString = str_replace(' ', '%', $_POST['CustKeywords']) ; + + $SQL = "SELECT custbranch.brname, + custbranch.contactname, + custbranch.phoneno, + custbranch.faxno, + custbranch.branchcode, + custbranch.debtorno, + debtorsmaster.name + FROM custbranch + LEFT JOIN debtorsmaster + ON custbranch.debtorno=debtorsmaster.debtorno + WHERE custbranch.brname " . LIKE . " '%" . $SearchString . "%' + AND custbranch.debtorno " . LIKE . " '%" . mb_strtoupper(trim($_POST['CustCode'])) . "%' + AND custbranch.branchcode " . LIKE . " '%" . mb_strtoupper(trim($_POST['CustCode'])) . "%' + AND custbranch.phoneno " . LIKE . " '%" . trim($_POST['CustPhone']) . "%'"; - $SQL = "SELECT custbranch.brname, - custbranch.contactname, - custbranch.phoneno, - custbranch.faxno, - custbranch.branchcode, - custbranch.debtorno, - debtorsmaster.name - FROM custbranch - LEFT JOIN debtorsmaster - ON custbranch.debtorno=debtorsmaster.debtorno - WHERE custbranch.brname " . LIKE . " '$SearchString'"; - if ($_SESSION['SalesmanLogin']!=''){ $SQL .= " AND custbranch.salesman='" . $_SESSION['SalesmanLogin'] . "'"; } $SQL .= " AND custbranch.disabletrans=0 ORDER BY custbranch.debtorno, custbranch.branchcode"; - } elseif (mb_strlen($_POST['CustCode'])>0){ - - $_POST['CustCode'] = mb_strtoupper(trim($_POST['CustCode'])); - - $SQL = "SELECT custbranch.brname, - custbranch.contactname, - custbranch.phoneno, - custbranch.faxno, - custbranch.branchcode, - custbranch.debtorno, - debtorsmaster.name - FROM custbranch - LEFT JOIN debtorsmaster - ON custbranch.debtorno=debtorsmaster.debtorno - WHERE custbranch.debtorno " . LIKE . " '%" . $_POST['CustCode'] . "%' OR custbranch.branchcode " . LIKE . " '%" . $_POST['CustCode'] . "%'"; - - if ($_SESSION['SalesmanLogin']!=''){ - $SQL .= " AND custbranch.salesman='" . $_SESSION['SalesmanLogin'] . "'"; - } - $SQL .= " AND custbranch.disabletrans=0 - ORDER BY custbranch.debtorno"; - } elseif (mb_strlen($_POST['CustPhone'])>0){ - $SQL = "SELECT custbranch.brname, - custbranch.contactname, - custbranch.phoneno, - custbranch.faxno, - custbranch.branchcode, - custbranch.debtorno, - debtorsmaster.name - FROM custbranch - INNER JOIN debtorsmaster - ON custbranch.debtorno=debtorsmaster.debtorno - WHERE custbranch.phoneno " . LIKE . " '%" . $_POST['CustPhone'] . "%'"; - - if ($_SESSION['SalesmanLogin']!=''){ - $SQL .= " AND custbranch.salesman='" . $_SESSION['SalesmanLogin'] . "'"; - } - - $SQL .= " AND custbranch.disabletrans=0 - ORDER BY custbranch.debtorno"; - } - $ErrMsg = _('The searched customer records requested cannot be retrieved because'); $result_CustSelect = DB_query($SQL,$db,$ErrMsg); @@ -399,7 +353,7 @@ record returned from a search so parse the $SelectCustomer string into customer code and branch code */ if (isset($SelectedCustomer)) { - $_SESSION['Items'.$identifier]->DebtorNo = trim($SelectedCustomer); + $_SESSION['Items'.$identifier]->DebtorNo = trim($SelectedCustomer); $_SESSION['Items'.$identifier]->Branch = trim($SelectedBranch); // Now check to ensure this account is not on hold */ @@ -922,7 +876,7 @@ $NewItem = mb_strtoupper($_POST[$QuickEntryCode]); } if (isset($_POST[$QuickEntryQty])) { - $NewItemQty = $_POST[$QuickEntryQty]; + $NewItemQty = filter_number_format($_POST[$QuickEntryQty]); } if (isset($_POST[$QuickEntryItemDue])) { $NewItemDue = $_POST[$QuickEntryItemDue]; @@ -941,7 +895,7 @@ } if(!Is_Date($NewItemDue)) { - prnMsg(_('An invalid date entry was made for ') . ' ' . $NewItem . ' ' . _('The date entry') . ' ' . $NewItemDue . ' ' . _('must be in the format') . ' ' . $_SESSION['DefaultDateFormat'],'warn'); + prnMsg(_('An invalid date entry was made for ') . ' ' . $NewItem . ' ' . _('The date entry') . ' ' . $NewItemDue . ' ' . _('must be in the format') . ' ' . $_SESSION['DefaultDateFormat'],'warn'); //Attempt to default the due date to something sensible? $NewItemDue = DateAdd (Date($_SESSION['DefaultDateFormat']),'d', $_SESSION['Items'.$identifier]->DeliveryDays); } @@ -1054,8 +1008,8 @@ taxcatid, materialcost) VALUES ('" . $AssetStockID . "', - '" . $AssetRow['description'] . "', - '" . $AssetRow['longdescription'] . "', + '" . DB_escape_string($AssetRow['description']) . "', + '" . DB_escape_string($AssetRow['longdescription']) . "', 'ASSETS', 'D', '0', @@ -1099,18 +1053,18 @@ if (isset($_POST['Quantity_' . $OrderLine->LineNumber])){ - $Quantity = $_POST['Quantity_' . $OrderLine->LineNumber]; + $Quantity = filter_number_format($_POST['Quantity_' . $OrderLine->LineNumber]); if (ABS($OrderLine->Price - $_POST['Price_' . $OrderLine->LineNumber])>0.01){ - $Price = $_POST['Price_' . $OrderLine->LineNumber]; - $_POST['GPPercent_' . $OrderLine->LineNumber] = (($Price*(1-($_POST['Discount_' . $OrderLine->LineNumber]/100))) - $OrderLine->StandardCost*$ExRate)/($Price *(1-$_POST['Discount_' . $OrderLine->LineNumber])/100); - } elseif (ABS($OrderLine->GPPercent - $_POST['GPPercent_' . $OrderLine->LineNumber])>=0.001) { + $Price = filter_number_format($_POST['Price_' . $OrderLine->LineNumber]); + $_POST['GPPercent_' . $OrderLine->LineNumber] = (($Price*(1-(filter_number_format($_POST['Discount_' . $OrderLine->LineNumber])/100))) - $OrderLine->StandardCost*$ExRate)/($Price *(1-filter_number_format($_POST['Discount_' . $OrderLine->LineNumber]))/100); + } elseif (ABS($OrderLine->GPPercent - filter_number_format($_POST['GPPercent_' . $OrderLine->LineNumber]))>=0.001) { //then do a recalculation of the price at this new GP Percentage - $Price = ($OrderLine->StandardCost*$ExRate)/(1 -(($_POST['GPPercent_' . $OrderLine->LineNumber] + $_POST['Discount_' . $OrderLine->LineNumber])/100)); + $Price = ($OrderLine->StandardCost*$ExRate)/(1 -((filter_number_format($_POST['GPPercent_' . $OrderLine->LineNumber]) + filter_number_format($_POST['Discount_' . $OrderLine->LineNumber]))/100)); } else { - $Price = $_POST['Price_' . $OrderLine->LineNumber]; + $Price = filter_number_format($_POST['Price_' . $OrderLine->LineNumber]); } - $DiscountPercentage = $_POST['Discount_' . $OrderLine->LineNumber]; + $DiscountPercentage = filter_number_format($_POST['Discount_' . $OrderLine->LineNumber]); if ($_SESSION['AllowOrderLineItemNarrative'] == 1) { $Narrative = $_POST['Narrative_' . $OrderLine->LineNumber]; } else { @@ -1171,7 +1125,7 @@ 'Yes', /*Update DB */ $_POST['ItemDue_' . $OrderLine->LineNumber], $_POST['POLine_' . $OrderLine->LineNumber], - $_POST['GPPercent_' . $OrderLine->LineNumber]); + filter_number_format($_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 @@ -1382,7 +1336,7 @@ foreach ($_SESSION['Items'.$identifier]->LineItems as $OrderLine) { $LineTotal = $OrderLine->Quantity * $OrderLine->Price * (1 - $OrderLine->DiscountPercent); - $DisplayLineTotal = locale_number_format($LineTotal,$_SESSION['Items'.$identifier]->CurrDecimalPlaces); + $DisplayLineTotal = locale_money_format($LineTotal,$_SESSION['Items'.$identifier]->CurrDecimalPlaces); $DisplayDiscount = locale_number_format(($OrderLine->DiscountPercent * 100),2); $QtyOrdered = $OrderLine->Quantity; $QtyRemain = $QtyOrdered - $OrderLine->QtyInv; @@ -1454,7 +1408,7 @@ } /* end of loop around items */ - $DisplayTotal = locale_number_format($_SESSION['Items'.$identifier]->total,$_SESSION['Items'.$identifier]->CurrDecimalPlaces); + $DisplayTotal = locale_money_format($_SESSION['Items'.$identifier]->total,$_SESSION['Items'.$identifier]->CurrDecimalPlaces); if (in_array(2,$_SESSION['AllowedPageSecurityTokens'])){ $ColSpanNumber = 2; } else { Modified: trunk/includes/DefineCartClass.php =================================================================== --- trunk/includes/DefineCartClass.php 2011-09-09 03:39:04 UTC (rev 4682) +++ trunk/includes/DefineCartClass.php 2011-09-10 04:39:18 UTC (rev 4683) @@ -159,9 +159,9 @@ VALUES(" . $this->LineCounter . ", " . $_SESSION['ExistingOrder'] . ", '" . trim(mb_strtoupper($StockID)) ."', - " . $Qty . ", - " . $Price . ", - " . $Disc . ",' + " . filter_number_format($Qty) . ", + " . filter_number_format($Price) . ", + " . filter_number_format($Disc) . ",' " . $ItemDue . "', " . $POLine . ")"; $result = DB_query($sql, @@ -196,9 +196,9 @@ $this->LineItems[$UpdateLineNumber]->GPPercent = $GPPercent; if ($UpdateDB=='Yes'){ global $db; - $result = DB_query("UPDATE salesorderdetails SET quantity=" . $Qty . ", - unitprice=" . $Price . ", - discountpercent=" . $Disc . ", + $result = DB_query("UPDATE salesorderdetails SET quantity=" . filter_number_format($Qty) . ", + unitprice=" . filter_number_format($Price) . ", + discountpercent=" . filter_number_format($Disc) . ", narrative ='" . DB_escape_string($Narrative) . "', itemdue = '" . FormatDateForSQL($ItemDue) . "', poline = '" . DB_escape_string($POLine) . "' Modified: trunk/includes/LanguageSetup.php =================================================================== --- trunk/includes/LanguageSetup.php 2011-09-09 03:39:04 UTC (rev 4682) +++ trunk/includes/LanguageSetup.php 2011-09-10 04:39:18 UTC (rev 4683) @@ -24,22 +24,21 @@ $Language = $_SESSION['Language']; } +$Locale = setlocale (LC_ALL, $_SESSION['Language']); +$LocaleInfo = localeconv(); +if (defined('LC_MESSAGES')){ + $Locale = setlocale (LC_MESSAGES, $_SESSION['Language']); +} +//Turkish seems to be a special case +if ($_SESSION['Language']=='tr_TR.utf8') { + $Locale = setlocale(LC_CTYPE, 'C'); +} + +//$Locale = setlocale (LC_NUMERIC, 'en_US'); //currently need decimal points to be '.' + if (function_exists('gettext')){ - $Locale = setlocale (LC_ALL, $_SESSION['Language']); - $LocaleInfo = localeconv(); - if (defined('LC_MESSAGES')){ - $Locale = setlocale (LC_MESSAGES, $_SESSION['Language']); - } - - //Turkish seems to be a special case - if ($_SESSION['Language']=='tr_TR.utf8') { - $Locale = setlocale(LC_CTYPE, 'C'); - } - - //$Locale = setlocale (LC_NUMERIC, 'en_US'); //currently need decimal points to be '.' - // possibly even if locale fails the language will still switch by using Language instead of locale variable putenv('LANG=' . $_SESSION['Language']); putenv('LANGUAGE=' . $_SESSION['Language']); Modified: trunk/includes/MiscFunctions.php =================================================================== --- trunk/includes/MiscFunctions.php 2011-09-09 03:39:04 UTC (rev 4682) +++ trunk/includes/MiscFunctions.php 2011-09-10 04:39:18 UTC (rev 4683) @@ -315,6 +315,11 @@ /*Functions to display numbers in locale of the user */ function locale_number_format($Number, $DecimalPlaces) { + global $LocaleInfo; + return number_format($Number,$DecimalPlaces,$LocaleInfo['decimal_point'],$LocaleInfo['thousands_sep']); +} + +function locale_money_format($Number, $DecimalPlaces) { return money_format('%!.' . $DecimalPlaces . 'n',$Number); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |