6 include('includes/session.inc');
7 $title=_('Update Pricing');
8 include('includes/header.inc');
11 echo '<BR>' . _('This page updates already existing prices for a specified sales type (price list)') . '. ' . _('Choose between updating only customer special prices where the customer is set up under the price list selected, or all prices under the sales type or just specific prices for a customer for the stock category selected');
13 echo "<FORM METHOD='POST' ACTION='" . $_SERVER['PHP_SELF'] . '?' . SID
. "'>";
15 $SQL = 'SELECT sales_type, typeabbrev FROM salestypes';
17 $result = DB_query($SQL,$db);
19 echo '<P><CENTER><TABLE>
21 <TD>' . _('Select the Price List to update the costs for') .":</TD>
22 <TD><SELECT NAME='PriceList'>";
24 if (!isset($_POST['PriceList'])){
25 echo '<OPTION SELECTED VALUE=0>' . _('No Price List Selected');
28 while ($PriceLists=DB_fetch_array($result)){
29 echo "<OPTION VALUE='" . $PriceLists['typeabbrev'] . "'>" . $PriceLists['sales_type'];
32 echo '</SELECT></TD></TR>';
34 echo '<TR><TD>' . _('Category') . ":</TD>
35 <TD><SELECT name='StkCat'>";
37 $sql = 'SELECT categoryid, categorydescription FROM stockcategory';
39 $ErrMsg = _('The stock categories could not be retrieved because');
40 $DbgMsg = _('The SQL used to retrieve stock categories and failed was');
41 $result = DB_query($sql,$db,$ErrMsg,$DbgMsg);
43 while ($myrow=DB_fetch_array($result)){
44 if ($myrow['categoryid']==$_POST['StkCat']){
45 echo "<OPTION SELECTED VALUE='". $myrow['categoryid'] . "'>" . $myrow['categorydescription'];
47 echo "<OPTION VALUE='". $myrow['categoryid'] . "'>" . $myrow['categorydescription'];
50 echo '</SELECT></TD></TR>';
52 echo '<TR><TD>' . _('Which Prices to update') . ":</TD>
53 <TD><SELECT NAME='WhichPrices'>";
54 echo "<OPTION VALUE='Only Non-customer special prices'>" . _('Only Non-customer special prices');
55 echo "<OPTION VALUE='Only customer special prices'>" . _('Only customer special prices');
56 echo "<OPTION VALUE='Both customer special prices and non-customer special prices'>" . _('Both customer special prices and non-customer special prices');
57 echo "<OPTION VALUE='Selected customer special prices only'>" . $_SESSION['CustomerID'] . ' ' . _('customer special prices only');
58 echo '</SELECT></TD></TR>';
60 if (!isset($_POST['IncreasePercent'])){
61 $_POST['IncreasePercent']=0;
64 echo '<TR><TD>' . _('Percentage Increase (positive) or decrease (negative)') . "</TD>
65 <TD><INPUT name='IncreasePercent' SIZE=4 MAXLENGTH=4 VALUE=" . $_POST['IncreasePercent'] . "></TD></TR></TABLE>";
68 echo "<P><INPUT TYPE=SUBMIT NAME='UpdatePrices' VALUE='" . _('Update Prices') . '\' onclick="return confirm(\'' . _('Are you sure you wish to update all the prices according to the criteria selected?') . '\');"></CENTER>';
72 if (isset($_POST['UpdatePrices']) AND isset($_POST['StkCat'])){
74 echo '<BR>' . _('So we are using a price list/sales type of') .' : ' . $_POST['PriceList'];
75 echo '<BR>' . _('and a stock category code of') . ' : ' . $_POST['StkCat'];
76 echo '<BR>' . _('and a increase percent of') . ' : ' . $_POST['IncreasePercent'];
78 if ($_POST['PriceList']=='0'){
79 echo '<BR>' . _('The price list/sales type to be updated must be selected first');
80 include ('includes/footer.inc');
84 if (ABS($_POST['IncreasePercent']) < 0.5 OR ABS($_POST['IncreasePercent'])>40 OR !is_numeric($_POST['IncreasePercent'])){
86 echo '<BR>' . _('The increase or decrease to be applied is expected to be an integer between 1 and 40 it is not necessary to enter the % sign') . ' - ' . _('the amount is assumed to be a percentage');
87 include ('includes/footer.inc');
91 echo '<P>' . _('Price list') . ' ' . $_POST['PriceList'] . ' ' . _('prices for') . ' ' . $_POST['WhichPrices'] . ' ' . _('for the stock category') . ' ' . $_POST['StkCat'] . ' ' . _('will been incremented by') . ' ' . $_POST['IncreasePercent'] . ' ' . _('percent');
93 $sql = "SELECT stockid FROM stockmaster WHERE categoryid='" . $_POST['StkCat'] . "'";
94 $PartsResult = DB_query($sql,$db);
96 $IncrementPercentage = $_POST['IncreasePercent']/100;
98 while ($myrow=DB_fetch_array($PartsResult)){
100 if ($_POST['WhichPrices'] == 'Only Non-customer special prices'){
102 $sql = 'UPDATE prices SET price=price*(1+' . $IncrementPercentage . ")
103 WHERE typeabbrev='" . $_POST['PriceList'] . "'
104 AND stockid='" . $myrow['stockid'] . "'
105 AND typeabbrev='" . $_POST['PriceList'] . "'
108 }else if ($_POST['WhichPrices'] == 'Only customer special prices'){
110 $sql = "UPDATE prices SET price=price*(1+" . $IncrementPercentage . ")
111 WHERE typeabbrev='" . $_POST['PriceList'] . "'
112 AND stockid='" . $myrow['stockid'] . "'
113 AND typeabbrev='" . $_POST['PriceList'] . "'
116 } else if ($_POST['WhichPrices'] == 'Both customer special prices and non-customer special prices'){
118 $sql = "UPDATE prices SET price=price*(1+" . $IncrementPercentage . ")
119 WHERE typeabbrev='" . $_POST['PriceList'] . "'
120 AND stockd='" . $myrow['stockid'] . "'
121 AND typeabbrev='" . $_POST['PriceList'] . "'";
123 } else if ($_POST['WhichPrices'] == 'Selected customer special prices only'){
125 $sql = 'UPDATE prices SET price=price*(1+' . $IncrementPercentage . ")
126 WHERE typeabbrev='" . $_POST['PriceList'] . "'
127 AND stockid='" . $myrow['stockid'] . "'
128 AND typeabbrev='" . $_POST['PriceList'] . "'
129 AND debtorno='" . $_SESSION['CustomerID'] . "'";
133 $result = DB_query($sql,$db);
134 $ErrMsg =_('Error updating prices for') . ' ' . $myrow['stockid'] . ' ' . _('because');
135 prnMsg(_('Updating prices for') . ' ' . $myrow['stockid'],'info');
139 include('includes/footer.inc');