From: <dai...@us...> - 2010-05-08 08:39:33
|
Revision: 3456 http://web-erp.svn.sourceforge.net/web-erp/?rev=3456&view=rev Author: daintree Date: 2010-05-08 08:39:26 +0000 (Sat, 08 May 2010) Log Message: ----------- Price effectivity dates changes - found a bug in DateFunctions that prevented Date1GreaterThanDate2 function working for DefaultDateFormat=d/m/Y Changes in Prices.php and Prices_Customer.php to allow entry of start date and end date and update/deletions of prices. Also update to includes/GetPrice.inc to use the new startdate and enddate prices based on todays date Modified Paths: -------------- trunk/Prices.php trunk/Prices_Customer.php trunk/doc/Change.log.html trunk/includes/DateFunctions.inc trunk/includes/GetPrice.inc trunk/includes/session.inc trunk/sql/mysql/upgrade3.11.1-3.12.sql Modified: trunk/Prices.php =================================================================== --- trunk/Prices.php 2010-05-07 23:22:18 UTC (rev 3455) +++ trunk/Prices.php 2010-05-08 08:39:26 UTC (rev 3456) @@ -29,9 +29,6 @@ $_POST['CurrAbrev'] = $_SESSION['CompanyRecord']['currencydefault']; } -if (!isset($_POST['StartDate'])){ - $_POST['StartDate'] = Date($_SESSION['DefaultDateFormat']); -} echo "<a href='" . $rootpath . '/SelectProduct.php?' . SID . "'>" . _('Back to Items') . '</a><br>'; @@ -72,51 +69,50 @@ if (!is_double((double) trim($_POST['Price'])) OR $_POST['Price']=="") { $InputError = 1; - $msg = _('The price entered must be numeric'); + prnMsg( _('The price entered must be numeric'),'error'); } if (! Is_Date($_POST['StartDate'])){ $InputError =1; - $msg = _('The date this price is to take effect from must be entered in the format') . ' ' . $_SESSION['DefaultDateFormat']; + prnMsg (_('The date this price is to take effect from must be entered in the format') . ' ' . $_SESSION['DefaultDateFormat'],'error'); } if (! Is_Date($_POST['EndDate'])){ $InputError =1; - $msg = _('The date this price is be in effect to must be entered in the format') . ' ' . $_SESSION['DefaultDateFormat']; + prnMsg (_('The date this price is be in effect to must be entered in the format') . ' ' . $_SESSION['DefaultDateFormat'],'error'); } if (Date1GreaterThanDate2($_POST['StartDate'],$_POST['EndDate'])){ $InputError =1; - $msg = _('The end date is expected to be after the start date, enter an end date after the start date for this price'); + prnMsg (_('The end date is expected to be after the start date, enter an end date after the start date for this price'),'error'); } - + if (Date1GreaterThanDate2(Date($_SESSION['DefaultDateFormat']),$_POST['EndDate'])){ + $InputError =1; + prnMsg(_('The end date is expected to be after today. There is no point entering a new price where the effective date is before today!'),'error'); + } if (isset($_POST['OldTypeAbbrev']) AND isset($_POST['OldCurrAbrev']) AND strlen($Item)>1 AND $InputError !=1) { + /* Need to see if there is also a price entered that has an end date after the start date of this price and if so we will need to update it so there is no ambiguity as to which price will be used*/ + //editing an existing price $sql = "UPDATE prices SET - typeabbrev='" . $_POST['TypeAbbrev'] . "', - currabrev='" . $_POST['CurrAbrev'] . "', - price=" . $_POST['Price'] . ", - startdate='" . FormatDateForSQL($_POST['StartDate']) . "', - enddate='" . FormatDateForSQL($_POST['EndDate']) . "' - WHERE prices.stockid='$Item' - AND prices.typeabbrev='" . $_POST['OldTypeAbbrev'] . "' - AND prices.currabrev='" . $_POST['OldCurrAbrev'] . "' - AND prices.debtorno=''"; + typeabbrev='" . $_POST['TypeAbbrev'] . "', + currabrev='" . $_POST['CurrAbrev'] . "', + price=" . $_POST['Price'] . ", + startdate='" . FormatDateForSQL($_POST['StartDate']) . "', + enddate='" . FormatDateForSQL($_POST['EndDate']) . "' + WHERE prices.stockid='$Item' + AND startdate='" .$_POST['OldStartDate'] . "' + AND enddate ='" . $_POST['OldEndDate'] . "' + AND prices.typeabbrev='" . $_POST['OldTypeAbbrev'] . "' + AND prices.currabrev='" . $_POST['OldCurrAbrev'] . "' + AND prices.debtorno=''"; - /* Need to see if there is also a price entered that has an end date after the start date of this price and if so we will need to update it so there is no ambiguity as to which price will be used*/ - $SQLEndDate = + $ErrMsg = _('Could not be update the existing prices'); + $result = DB_query($sql,$db,$ErrMsg); - $UpdateEndDateOfExistingPricesSQL = "UPDATE prices SET enddate = '" . - WHERE enddate >= '" . FormatDateForSQL($_POST['StartDate']) . "' - AND typeabbrev='" . $_POST['TypeAbbrev'] . "', - AND currabrev='" . $_POST['CurrAbrev'] . "', - - FROM prices - WHERE - + ReSequenceEffectiveDates ($Item, $_POST['TypeAbbrev'], $_POST['CurrAbrev'], $db) ; + prnMsg(_('The price has been updated'),'success'); - - $msg = _('This price has been updated') . '.'; } elseif ($InputError !=1) { /*Selected price is null cos no item selected on first time round so must be adding a record must be submitting new entries in the new price form */ @@ -124,50 +120,39 @@ $sql = "INSERT INTO prices (stockid, typeabbrev, currabrev, - debtorno, startdate, enddate, price) VALUES ('$Item', '" . $_POST['TypeAbbrev'] . "', '" . $_POST['CurrAbrev'] . "', - '', '" . FormatDateForSQL($_POST['StartDate']) . "', '" . FormatDateForSQL($_POST['EndDate']). "', " . $_POST['Price'] . ")"; - - $msg = _('The new price has been added') . '.'; + $ErrMsg = _('The new price could not be added'); + $result = DB_query($sql,$db,$ErrMsg); + + ReSequenceEffectiveDates ($Item, $_POST['TypeAbbrev'], $_POST['CurrAbrev'], $db) ; + prnMsg(_('The new price has been inserted'),'success'); } - //run the SQL from either of the above possibilites only if there were no input errors - if ($InputError !=1){ - $result = DB_query($sql,$db,'','',false,false); - if (DB_error_no($db)!=0){ - If ($msg== _('This price has been updated')){ - $msg = _('The price could not be updated because') . ' - ' . DB_error_msg($db); - } else { - $msg = _('The price could not be added because') . ' - ' . DB_error_msg($db); - } - if ($debug==1){ - prnMsg(_('The SQL that caused the problem was') . ':<br>' . $sql,'error'); - } - } else { - unset($_POST['Price']); - } - } - prnMsg($msg); + unset($_POST['Price']); + unset($_POST['StartDate']); + unset($_POST['EndDate']); } elseif (isset($_GET['delete'])) { //the link to delete a selected record was clicked instead of the submit button $sql="DELETE FROM prices - WHERE prices.stockid = '". $Item ."' - AND prices.typeabbrev='". $_GET['TypeAbbrev'] ."' - AND prices.currabrev ='". $_GET['CurrAbrev'] ."' - AND prices.debtorno=''"; + WHERE prices.stockid = '". $Item ."' + AND prices.typeabbrev='". $_GET['TypeAbbrev'] ."' + AND prices.currabrev ='". $_GET['CurrAbrev'] ."' + AND prices.startdate = '" .$_GET['StartDate'] . "' + AND prices.enddate = '" . $_GET['EndDate'] . "' + AND prices.debtorno=''"; + $ErrMsg = _('Could not delete this price'); + $result = DB_query($sql,$db,$ErrMsg); + prnMsg( _('The selected price has been deleted'),'success'); - $result = DB_query($sql,$db); - prnMsg( _('The selected price has been deleted') . '!','success'); - } //Always do this stuff @@ -188,7 +173,8 @@ AND prices.stockid='$Item' AND prices.debtorno='' ORDER BY prices.currabrev, - prices.typeabbrev"; + prices.typeabbrev, + prices.startdate"; $result = DB_query($sql,$db); @@ -218,8 +204,8 @@ <td class=number>%0.2f</td> <td>%s</td> <td>%s</td> - <td><a href='%s?%s&Item=%s&TypeAbbrev=%s&CurrAbrev=%s&Price=%s&Edit=1'>" . _('Edit') . "</td> - <td><a href='%s?%s&Item=%s&TypeAbbrev=%s&CurrAbrev=%s&delete=yes' onclick=\"return confirm('" . _('Are you sure you wish to delete this price?') . "');\">" . _('Delete') . '</td></tr>', + <td><a href='%s?%s&Item=%s&TypeAbbrev=%s&CurrAbrev=%s&Price=%s&StartDate=%s&EndDate=%s&Edit=1'>" . _('Edit') . "</td> + <td><a href='%s?%s&Item=%s&TypeAbbrev=%s&CurrAbrev=%s&StartDate=%s&EndDate=%s&delete=yes' onclick=\"return confirm('" . _('Are you sure you wish to delete this price?') . "');\">" . _('Delete') . '</td></tr>', $myrow['currency'], $myrow['sales_type'], $myrow['price'], @@ -231,11 +217,15 @@ $myrow['typeabbrev'], $myrow['currabrev'], $myrow['price'], + $myrow['startdate'], + $myrow['enddate'], $_SERVER['PHP_SELF'], SID, $myrow['stockid'], $myrow['typeabbrev'], - $myrow['currabrev']); + $myrow['currabrev'], + $myrow['startdate'], + $myrow['enddate']); } else { printf("<td>%s</td> <td>%s</td> @@ -261,9 +251,13 @@ if (isset($_GET['Edit'])){ echo '<input type=hidden name="OldTypeAbbrev" VALUE="' . $_GET['TypeAbbrev'] .'">'; echo '<input type=hidden name="OldCurrAbrev" VALUE="' . $_GET['CurrAbrev'] . '">'; + echo '<input type=hidden name="OldStartDate" VALUE="' . $_GET['StartDate'] . '">'; + echo '<input type=hidden name="OldEndDate" VALUE="' . $_GET['EndDate'] . '">'; $_POST['CurrAbrev'] = $_GET['CurrAbrev']; $_POST['TypeAbbrev'] = $_GET['TypeAbbrev']; $_POST['Price'] = $_GET['Price']; + $_POST['StartDate'] = ConvertSQLDate($_GET['StartDate']); + $_POST['EndDate'] = ConvertSQLDate($_GET['EndDate']); } $SQL = "SELECT currabrev, currency FROM currencies"; @@ -283,7 +277,7 @@ echo '</select> </td></tr><tr><td>' . _('Sales Type Price List') . ':</td><td><select name="TypeAbbrev">'; - $SQL = "SELECT typeabbrev, sales_type FROM salestypes"; + $SQL = 'SELECT typeabbrev, sales_type FROM salestypes'; $result = DB_query($SQL,$db); while ($myrow = DB_fetch_array($result)) { @@ -298,10 +292,17 @@ DB_free_result($result); + if (!isset($_POST['StartDate'])){ + $_POST['StartDate'] = Date($_SESSION['DefaultDateFormat']); + } + + if (!isset($_POST['EndDate'])){ + $_POST['EndDate'] = Date($_SESSION['DefaultDateFormat'],Mktime(0,0,0,12,31,(Date('y')+20))); + } echo '<tr><td>' . _('Price Effective From Date') . ':</td> - <td><input type=text name="StartDate" value="' . Date($_SESSION['DefaultDateFormat']) . '"></td></tr>'; + <td><input type=text name="StartDate" value="' . $_POST['StartDate'] . '"></td></tr>'; echo '<tr><td>' . _('Price Effective To Date') . ':</td> - <td><input type=text name="EndDate" value="' . Date($_SESSION['DefaultDateFormat'],Mktime(0,0,0,12,31,(Date('y')+20))) . '">'; + <td><input type=text name="EndDate" value="' . $_POST['EndDate'] . '">'; ?> @@ -325,4 +326,48 @@ echo '</form>'; include('includes/footer.inc'); + + +function ReSequenceEffectiveDates ($Item, $PriceList, $CurrAbbrev, $db) { + + $SQL = "SELECT price, + startdate, + enddate + FROM prices + WHERE debtorno='' + AND stockid='" . $Item . "' + AND currabrev='" . $CurrAbbrev . "' + AND typeabbrev='" . $PriceList . "' + ORDER BY startdate, enddate"; + $result = DB_query($SQL,$db); + $NextStartDate = Date($_SESSION['DefaultDateFormat']); + unset($EndDate); + unset($NextStartDate); + while ($myrow = DB_fetch_array($result)){ + + if (isset($NextStartDate)){ + if (Date1GreaterThanDate2(ConvertSQLDate($myrow['startdate']),$NextStartDate)){ + $NextStartDate = ConvertSQLDate($myrow['startdate']); + if (isset($EndDate)) { + /*Need to make the end date the new start date less 1 day */ + $SQL = "UPDATE prices SET enddate = '" . FormatDateForSQL(DateAdd($NextStartDate,'d',-1)) . "' + WHERE stockid ='" .$Item . "' + AND currabrev='" . $CurrAbbrev . "' + AND typeabbrev='" . $PriceList . "' + AND startdate ='" . $StartDate . "' + AND enddate = '" . $EndDate . "' + AND debtorno =''"; + $UpdateResult = DB_query($SQL,$db); + } + } //end of if startdate after NextStartDate - we have a new NextStartDate + } //end of if set NextStartDate + else { + $NextStartDate = ConvertSQLDate($myrow['startdate']); + } + $StartDate = $myrow['startdate']; + $EndDate = $myrow['enddate']; + $Price = $myrow['price']; + } +} + ?> \ No newline at end of file Modified: trunk/Prices_Customer.php =================================================================== --- trunk/Prices_Customer.php 2010-05-07 23:22:18 UTC (rev 3455) +++ trunk/Prices_Customer.php 2010-05-08 08:39:26 UTC (rev 3456) @@ -25,12 +25,12 @@ } $result = DB_query("SELECT debtorsmaster.name, - debtorsmaster.currcode, - debtorsmaster.salestype - FROM - debtorsmaster - WHERE - debtorsmaster.debtorno='" . $_SESSION['CustomerID'] . "'",$db); + debtorsmaster.currcode, + debtorsmaster.salestype + FROM + debtorsmaster + WHERE + debtorsmaster.debtorno='" . $_SESSION['CustomerID'] . "'",$db); $myrow = DB_fetch_row($result); echo '<font color=BLUE><b>' . $myrow[0] . ' ' . _('in') . ' ' . $myrow[1] . '<br>' . ' ' . _('for') . ' '; @@ -38,8 +38,8 @@ $SalesType = $myrow[2]; $result = DB_query("SELECT stockmaster.description - FROM stockmaster - WHERE stockmaster.stockid='" . $Item . "'",$db); + FROM stockmaster + WHERE stockmaster.stockid='" . $Item . "'",$db); $myrow = DB_fetch_row($result); @@ -62,9 +62,9 @@ if ($_POST['Branch'] !=''){ $sql = "SELECT custbranch.branchcode - FROM custbranch - WHERE custbranch.debtorno='" . $_SESSION['CustomerID'] . "' - AND custbranch.branchcode='" . $_POST['Branch'] . "'"; + FROM custbranch + WHERE custbranch.debtorno='" . $_SESSION['CustomerID'] . "' + AND custbranch.branchcode='" . $_POST['Branch'] . "'"; $result = DB_query($sql,$db); if (DB_num_rows($result) ==0){ @@ -85,7 +85,11 @@ $InputError =1; $msg = _('The end date is expected to be after the start date, enter an end date after the start date for this price'); } - + if (Date1GreaterThanDate2(Date($_SESSION['DefaultDateFormat']),$_POST['EndDate'])){ + $InputError =1; + $msg = _('The end date is expected to be after today. There is no point entering a new price where the effective date is before today!'); + } + if ((isset($_POST['Editing']) and $_POST['Editing']=='Yes') AND strlen($Item)>1 AND $InputError !=1) { //editing an existing price @@ -99,8 +103,8 @@ WHERE prices.stockid='" . $Item . "' AND prices.typeabbrev='" . $SalesType . "' AND prices.currabrev='" . $CurrCode . "' - AND prices.startdate='" . FormatDateForSQL($_POST['StartDate']) . "' - AND prices.enddate='" . FormatDateForSQL($_POST['EndDate']) . "' + AND prices.startdate='" . $_POST['OldStartDate'] . "' + AND prices.enddate='" . $_POST['OldEndDate'] . "' AND prices.debtorno='" . $_SESSION['CustomerID'] . "'"; $msg = _('Price Updated'); @@ -136,6 +140,9 @@ $msg = _('The price could not be added because') . ' - ' . DB_error_msg($db); } }else { + ReSequenceEffectiveDates ($Item, $SalesType, $CurrCode, $_SESSION['CustomerID'], $db); + unset($_POST['EndDate']); + unset($_POST['StartDate']); unset($_POST['Price']); } } @@ -163,13 +170,18 @@ //Show the normal prices in the currency of this customer $sql = "SELECT prices.price, - prices.typeabbrev + prices.currabrev, + prices.typeabbrev, + prices.startdate, + prices.enddate FROM prices - WHERE prices.typeabbrev = '" . $SalesType . "' - AND prices.stockid='" . $Item . "' + WHERE prices.stockid='" . $Item . "' + AND prices.typeabbrev='". $SalesType ."' + AND prices.currabrev ='". $CurrCode ."' AND prices.debtorno='' - AND prices.currabrev='" . $CurrCode . "' - ORDER BY typeabbrev"; + ORDER BY currabrev, + typeabbrev, + startdate"; $ErrMsg = _('Could not retrieve the normal prices set up because'); $DbgMsg = _('The SQL used to retrieve these records was'); @@ -183,7 +195,13 @@ } else { echo '<tr><th>' . _('Normal Price') . '</th></tr>'; while ($myrow = DB_fetch_array($result)) { - printf('<tr class="EvenTableRows"><td class=number>%0.2f</td></tr>', $myrow['price']); + printf('<tr class="EvenTableRows"> + <td class=number>%0.2f</td> + <td class=date>%s</td> + <td class=date>%s</td></tr>', + $myrow['price'], + ConvertSQLDate($myrow['startdate']), + ConvertSQLDate($myrow['enddate'])); } } @@ -202,7 +220,9 @@ AND prices.debtorno='" . $_SESSION['CustomerID'] . "' AND prices.currabrev='$CurrCode' AND (custbranch.debtorno='" . $_SESSION['CustomerID'] . "' OR - custbranch.debtorno IS NULL)"; + custbranch.debtorno IS NULL) + ORDER BY prices.branchcode, + prices.startdate"; $ErrMsg = _('Could not retrieve the special prices set up because'); $DbgMsg = _('The SQL used to retrieve these records was'); @@ -263,6 +283,8 @@ if (isset($_GET['Edit']) and $_GET['Edit']==1){ echo '<input type=hidden name="Editing" VALUE="Yes">'; + echo '<input type=hidden name="OldStartDate" VALUE="' . $_GET['StartDate'] .'">'; + echo '<input type=hidden name="OldEndDate" VALUE="' . $_GET['EndDate'] . '">'; $_POST['Price']=$_GET['Price']; $_POST['Branch']=$_GET['Branch']; $_POST['StartDate'] = ConvertSQLDate($_GET['StartDate']); @@ -301,4 +323,52 @@ echo '</form>'; include('includes/footer.inc'); + + function ReSequenceEffectiveDates ($Item, $PriceList, $CurrAbbrev, $CustomerID, $db) { + + $SQL = "SELECT branchcode, + startdate, + enddate + FROM prices + WHERE debtorno='" . $CustomerID . "' + AND stockid='" . $Item . "' + AND currabrev='" . $CurrAbbrev . "' + AND typeabbrev='" . $PriceList . "' + ORDER BY branchcode, + startdate, + enddate"; + $result = DB_query($SQL,$db); + + unset($BranchCode); + + while ($myrow = DB_fetch_array($result)){ + if ($BranchCode != $myrow['branchcode']){ + unset($NextStartDate); + unset($EndDate); + unset($StartDate); + $BranchCode = $myrow['branchcode']; + } + if (isset($NextStartDate)){ + if (Date1GreaterThanDate2(ConvertSQLDate($myrow['startdate']),$NextStartDate)){ + $NextStartDate = ConvertSQLDate($myrow['startdate']); + if (isset($EndDate)) { + /*Need to make the end date the new start date less 1 day */ + $SQL = "UPDATE prices SET enddate = '" . FormatDateForSQL(DateAdd($NextStartDate,'d',-1)) . "' + WHERE stockid ='" .$Item . "' + AND currabrev='" . $CurrAbbrev . "' + AND typeabbrev='" . $PriceList . "' + AND startdate ='" . $StartDate . "' + AND enddate = '" . $EndDate . "' + AND debtorno ='" . $CustomerID . "'"; + $UpdateResult = DB_query($SQL,$db); + } + } //end of if startdate after NextStartDate - we have a new NextStartDate + } //end of if set NextStartDate + else { + $NextStartDate = ConvertSQLDate($myrow['startdate']); + } + $StartDate = $myrow['startdate']; + $EndDate = $myrow['enddate']; + } +} ?> \ No newline at end of file Modified: trunk/doc/Change.log.html =================================================================== --- trunk/doc/Change.log.html 2010-05-07 23:22:18 UTC (rev 3455) +++ trunk/doc/Change.log.html 2010-05-08 08:39:26 UTC (rev 3456) @@ -1,6 +1,8 @@ <p><font SIZE=4 COLOR=BLUE><b>webERP Change Log</b></font></p> <p></p> -<p>06/05/10 Lindsay: Tracker 2929564: dates mangled via QuicK Entry format +<p>08/05/10 Phil: GetPrices.inc now uses the new price startdate and enddate to return the price which falls within the date range base on the current date. Changes to Prices.php and Prices_Customer.php to allow entry of effective from and effective to dates and updating/deleting of prices with appropriate error trapping and rescheduling of enddates where start and end dates would otherwise overlap.</p> +<p>08/05/10 Phil: Found a bug in Date1GreaterThanDate2 function (in includes/DateFunction.inc) with SESSION['DefaultDateFormat'] = 'd/m/Y' this function had been broken </p> +<p>06/05/10 Lindsay: Tracker 2929564: dates mangled via QuicK Entry format</p> <p>05/05/10 Tim: Fix javascript errors in date picker</p> <p>05/05/10 SiteMe: Update to allow RecurringSalesOrdersProcess.php to run via cron</p> <p>05/05/10 SiteMe: Correct statements layout problems caused by the newer version of tcpdf</p> Modified: trunk/includes/DateFunctions.inc =================================================================== --- trunk/includes/DateFunctions.inc 2010-05-07 23:22:18 UTC (rev 3455) +++ trunk/includes/DateFunctions.inc 2010-05-08 08:39:26 UTC (rev 3456) @@ -439,9 +439,12 @@ $Date2 = trim($Date2); /* Get date elements */ - if ($_SESSION['DefaultDateFormat']=='d.m.Y' or $_SESSION['DefaultDateFormat'] =='d/m/Y'){ + if ($_SESSION['DefaultDateFormat']=='d.m.Y' ) { list($Day1,$Month1,$Year1) = explode('.', $Date1); list($Day2,$Month2,$Year2) = explode('.', $Date2); + } elseif ($_SESSION['DefaultDateFormat'] =='d/m/Y'){ + list($Day1,$Month1,$Year1) = explode('/', $Date1); + list($Day2,$Month2,$Year2) = explode('/', $Date2); } elseif ($_SESSION['DefaultDateFormat'] =='m/d/Y'){ list($Month1,$Day1,$Year1) = explode('/', $Date1); list($Month2,$Day2,$Year2) = explode('/', $Date2); @@ -454,6 +457,7 @@ * 2 characters and the other >2 then then make them both 4 characters long. Assume * a date >50 to be 1900's and less than to be 2000's */ + if (strlen($Year1)>2 AND strlen($Year2)==2){ if ($Year2>50) { $Year2=1900+$Year2; Modified: trunk/includes/GetPrice.inc =================================================================== --- trunk/includes/GetPrice.inc 2010-05-07 23:22:18 UTC (rev 3455) +++ trunk/includes/GetPrice.inc 2010-05-08 08:39:26 UTC (rev 3456) @@ -14,7 +14,9 @@ AND prices.stockid = '" . $StockID . "' AND prices.currabrev = debtorsmaster.currcode AND prices.debtorno=debtorsmaster.debtorno - AND prices.branchcode='" . $BranchCode . "'"; + AND prices.branchcode='" . $BranchCode . "' + AND prices.startdate <='" . Date('Y-m-d') . "' + AND prices.enddate >='" . Date('Y-m-d') . "'"; $ErrMsg = _('There is a problem in retrieving the pricing information for part') . ' ' . $StockID . ' ' . _('and for Customer') . ' ' . $DebtorNo . ' ' . _('the error message returned by the SQL server was'); $result = DB_query($sql, $db,$ErrMsg); @@ -22,7 +24,7 @@ if (DB_num_rows($result)==0){ - /* No result from go for customer and branch search try for just a customer match */ + /* No result returned for customer and branch search try for just a customer match */ $sql = "SELECT prices.price, prices.debtorno, prices.branchcode @@ -33,7 +35,9 @@ AND prices.stockid = '" . $StockID . "' AND prices.currabrev = debtorsmaster.currcode AND prices.debtorno=debtorsmaster.debtorno - AND prices.branchcode=''"; + AND prices.branchcode='' + AND prices.startdate <='" . Date('Y-m-d') . "' + AND prices.enddate >='" . Date('Y-m-d') . "'";; $result = DB_query($sql,$db,$ErrMsg); @@ -50,7 +54,10 @@ AND debtorsmaster.debtorno='" . $DebtorNo . "' AND prices.stockid = '" . $StockID . "' AND prices.debtorno='' - AND prices.currabrev = debtorsmaster.currcode"; + AND prices.currabrev = debtorsmaster.currcode + AND prices.startdate <='" . Date('Y-m-d') . "' + AND prices.enddate >='" . Date('Y-m-d') . "'"; + $result = DB_query($sql,$db,$ErrMsg); if (DB_num_rows($result)==0){ @@ -63,7 +70,9 @@ AND prices.currabrev = debtorsmaster.currcode AND debtorsmaster.debtorno='" . $DebtorNo . "' AND prices.typeabbrev='" . $_SESSION['DefaultPriceList'] . "' - AND prices.debtorno=''"; + AND prices.debtorno='' + AND prices.startdate <='" . Date('Y-m-d') . "' + AND prices.enddate >='" . Date('Y-m-d') . "'";; $result = DB_query($sql, $db,$ErrMsg); Modified: trunk/includes/session.inc =================================================================== --- trunk/includes/session.inc 2010-05-07 23:22:18 UTC (rev 3455) +++ trunk/includes/session.inc 2010-05-08 08:39:26 UTC (rev 3456) @@ -138,12 +138,14 @@ $CurrenciesResult = DB_query('SELECT currabrev FROM currencies',$db); while ($CurrencyRow = DB_fetch_row($CurrenciesResult)){ if ($CurrencyRow[0]!=$_SESSION['CompanyRecord']['currencydefault']){ - $UpdateCurrRateResult = DB_query('UPDATE currencies SET - rate=' . GetCurrencyRate ($CurrencyRow[0],$CurrencyRates) . " - WHERE currabrev='" . $CurrencyRow[0] . "'",$db); + + $UpdateCurrRateResult = DB_query('UPDATE currencies SET rate=' . GetCurrencyRate ($CurrencyRow[0],$CurrencyRates) . " WHERE currabrev='" . $CurrencyRow[0] . "'",$db); } } $_SESSION['UpdateCurrencyRatesDaily'] = Date('Y-m-d'); + + + $UpdateConfigResult = DB_query("UPDATE config SET confvalue = '" . Date('Y-m-d') . "' WHERE confname='UpdateCurrencyRatesDaily'",$db); } } Modified: trunk/sql/mysql/upgrade3.11.1-3.12.sql =================================================================== --- trunk/sql/mysql/upgrade3.11.1-3.12.sql 2010-05-07 23:22:18 UTC (rev 3455) +++ trunk/sql/mysql/upgrade3.11.1-3.12.sql 2010-05-08 08:39:26 UTC (rev 3456) @@ -156,3 +156,4 @@ ALTER TABLE `prices` ADD `startdate` DATE NOT NULL , ADD `enddate` DATE NOT NULL DEFAULT '9999-12-31'; ALTER TABLE prices DROP PRIMARY KEY , ADD PRIMARY KEY ( `stockid` , `typeabbrev` , `currabrev` , `debtorno` , `startdate` , `enddate` ) ; +UPDATE prices SET startdate='1999-01-01', enddate='9999-12-31'; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |