5 include('includes/session.inc');
6 $title = _('Discount Matrix Maintenance');
7 include('includes/header.inc');
9 if (isset($_POST['submit'])) {
11 //initialise no input errors assumed initially before we test
14 if (!is_numeric($_POST['QuantityBreak'])){
15 prnMsg( _('The quantity break must be entered as a positive number'),'error');
19 if ($_POST['QuantityBreak']<=0){
20 prnMsg( _('The quantity of all items on an order in the discount category') . ' ' . $_POST['DiscountCategory'] . ' ' . _('at which the discount will apply is 0 or less than 0') . '. ' . _('Positive numbers are expected for this entry'),'warn');
23 if (!is_numeric($_POST['DiscountRate'])){
24 prnMsg( _('The discount rate must be entered as a positive number'),'warn');
27 if ($_POST['DiscountRate']<=0 OR $_POST['DiscountRate']>=70){
28 prnMsg( _('The discount rate applicable for this record is either less than 0% or greater than 70%') . '. ' . _('Numbers between 1 and 69 are expected'),'warn');
32 /* actions to take once the user has clicked the submit button
33 ie the page has called itself with some user input */
35 if ($InputError !=1) {
37 $sql = "INSERT INTO discountmatrix (salestype,
41 VALUES('" . $_POST['SalesType'] . "',
42 '" . $_POST['DiscountCategory'] . "',
43 " . $_POST['QuantityBreak'] . ",
44 " . ($_POST['DiscountRate']/100) . ')';
46 $result = DB_query($sql,$db);
47 prnMsg( _('The discount matrix record has been added'),'success');
48 unset($_POST['DiscountCategory']);
49 unset($_POST['SalesType']);
50 unset($_POST['QuantityBreak']);
51 unset($_POST['DiscountRate']);
53 } elseif ($_GET['Delete']=='yes') {
54 /*the link to delete a selected record was clicked instead of the submit button */
56 $sql="DELETE FROM discountmatrix
57 WHERE discountcategory='" .$_GET['DiscountCategory'] . "'
58 AND salestype='" . $_GET['SalesType'] . "'
59 AND quantitybreak=" . $_GET['QuantityBreak'];
61 $result = DB_query($sql,$db);
62 prnMsg( _('The discount matrix record has been deleted'),'success');
65 $sql = 'SELECT sales_type,
70 FROM discountmatrix INNER JOIN salestypes
71 ON discountmatrix.salestype=salestypes.typeabbrev
76 $result = DB_query($sql,$db);
78 echo '<CENTER><table>';
79 echo "<tr><td class='tableheader'>" . _('Sales Type') . "</td>
80 <td class='tableheader'>" . _('Discount Category') . "</td>
81 <td class='tableheader'>" . _('Quantity Break') . "</td>
82 <td class='tableheader'>" . _('Discount Rate') . ' %' . "</td></TR>";
84 $k=0; //row colour counter
86 while ($myrow = DB_fetch_array($result)) {
88 echo "<tr bgcolor='#CCCCCC'>";
91 echo "<tr bgcolor='#EEEEEE'>";
94 $DeleteURL = $_SERVER['PHP_SELF'] . '?' . SID
. '&Delete=yes&SalesType=' . $myrow['salestype'] . '&DiscountCategory=' . $myrow['discountcategory'] . '&QuantityBreak=' . $myrow['quantitybreak'];
100 <td><a href='%s'>" . _('Delete') . '</td>
102 $myrow['sales_type'],
103 $myrow['discountcategory'],
104 $myrow['quantitybreak'],
105 number_format($myrow['discountrate']*100,2) ,
112 echo "<FORM METHOD='post' action=" . $_SERVER['PHP_SELF'] . '?' . SID
. '>';
117 $sql = 'SELECT typeabbrev,
121 $result = DB_query($sql, $db);
123 echo '<TR><TD>' . _('Customer Price List') . ' (' . _('Sales Type') . '):</TD><TD>';
125 echo "<SELECT NAME='SalesType'>";
127 while ($myrow = DB_fetch_array($result)){
128 if ($myrow['typeabbrev']==$_POST['SalesType']){
129 echo "<OPTION SELECTED VALUE='" . $myrow['typeabbrev'] . "'>" . $myrow['sales_type'];
131 echo "<OPTION VALUE='" . $myrow['typeabbrev'] . "'>" . $myrow['sales_type'];
138 echo '<TR><TD>' . _('Discount Category Code') . ':</TD><TD>';
140 echo "<INPUT TYPE='Text' NAME='DiscountCategory' MAXLENGTH=2 SIZE=2 VALUE='" . $_POST['DiscCat'] . "'></TD></TR>";
142 echo '<TR><TD>' . _('Quantity Break') . ":</TD><TD><input type='Text' name='QuantityBreak' SIZE=10 MAXLENGTH=10></TD></TR>";
144 echo '<TR><TD>' . _('Discount Rate') . " (%):</TD><TD><input type='Text' name='DiscountRate' SIZE=4 MAXLENGTH=4></TD></TR>";
147 echo "<CENTER><input type='Submit' name='submit' value='" . _('Enter Information') . "'></CENTER>";
151 include('includes/footer.inc');