2 /* $Revision: 1.10 $ */
5 include('includes/session.inc');
6 $title = _('Freight Costs Set Up');
7 include('includes/header.inc');
13 if (isset($_GET['LocationFrom'])){
14 $LocationFrom = $_GET['LocationFrom'];
15 } elseif (isset($_POST['LocationFrom'])){
16 $LocationFrom = $_POST['LocationFrom'];
18 if (isset($_GET['ShipperID'])){
19 $ShipperID = $_GET['ShipperID'];
20 } elseif (isset($_POST['ShipperID'])){
21 $ShipperID = $_POST['ShipperID'];
23 if (isset($_GET['SelectedFreightCost'])){
24 $SelectedFreightCost = $_GET['SelectedFreightCost'];
25 } elseif (isset($_POST['SelectedFreightCost'])){
26 $SelectedFreightCost = $_POST['SelectedFreightCost'];
31 if (!isset($LocationFrom) OR !isset($ShipperID)) {
33 echo "<FORM METHOD='post' action='" . $_SERVER['PHP_SELF'] . '?' . SID
. "'>";
34 $sql = 'SELECT shippername, shipper_id FROM shippers';
35 $ShipperResults = DB_query($sql,$db);
37 echo '<CENTER><TABLE BORDER=1>
39 <TD>' . _('Select A Freight Company to set up costs for') . "</TD>
40 <TD><SELECT name='ShipperID'>";
42 while ($myrow = DB_fetch_array($ShipperResults)){
43 echo '<OPTION VALUE=' . $myrow['shipper_id'] . '>' . $myrow['shippername'];
45 echo '</SELECT></TD></TR>
47 <TD>' . _('Select the warehouse') . ' (' . _('ship from location') . ")</TD>
48 <TD><SELECT name='LocationFrom'>";
50 $sql = 'SELECT loccode, locationname FROM locations';
51 $LocationResults = DB_query($sql,$db);
53 while ($myrow = DB_fetch_array($LocationResults)){
54 echo '<OPTION VALUE=' . $myrow['loccode'] . '>' . $myrow['locationname'];
57 echo "</SELECT></TD></TR></TABLE><INPUT TYPE=SUBMIT VALUE='" . _('Accept') . "' NAME='Accept'></FORM>";
61 $sql = "SELECT shippername FROM shippers WHERE shipper_id = $ShipperID";
62 $ShipperResults = DB_query($sql,$db);
63 $myrow = DB_fetch_row($ShipperResults);
64 $ShipperName = $myrow[0];
65 $sql = "SELECT locationname FROM locations WHERE loccode = '$LocationFrom'";
66 $LocationResults = DB_query($sql,$db);
67 $myrow = DB_fetch_row($LocationResults);
68 $LocationName = $myrow[0];
69 echo '<FONT SIZE=4 COLOR=BLUE>' . _('For Deliveries From') . ' ' . $LocationName . ' ' . _('using') . ' ' . $ShipperName . '</FONT><BR>';
74 if (isset($_POST['submit'])) {
76 //initialise no input errors assumed initially before we test
79 //first off validate inputs sensible
80 if (strlen($_POST['Destination'])<2){
82 prnMsg(_('The entry for the destination must be at least two characters long') . '. ' . _('These entries are matched against the town names entered for customer delivery addresses'),'warn');
86 if (trim($_POST['CubRate']) == '' ) {
87 $_POST['CubRate'] = 0;
89 if (trim($_POST['KGRate']) == '' ) {
92 if (trim($_POST['MAXKGs']) == '' ) {
95 if (trim($_POST['MAXCub']) == '' ) {
98 if (trim($_POST['FixedPrice']) == '' ){
99 $_POST['FixedPrice'] = 0;
101 if (trim($_POST['MinimumChg']) == '' ) {
102 $_POST['MinimumChg'] = 0;
105 if (!is_double((double) $_POST['CubRate']) OR !is_double((double) $_POST['KGRate']) OR !is_double((double) $_POST['MAXKGs']) OR !is_double((double) $_POST['MAXCub']) OR !is_double((double) $_POST['FixedPrice']) OR !is_double((double) $_POST['MinimumChg'])) {
107 prnMsg(_('The entries for Cubic Rate, KG Rate, Maxmimum Weight, Maximum Volume, Fixed Price and Minimum charge must be numeric'),'warn');
112 if (isset($SelectedFreightCost) AND $InputError !=1) {
114 $sql = "UPDATE freightcosts
116 locationfrom='$LocationFrom',
117 destination='" . $_POST['Destination'] . "',
118 shipperid=$ShipperID,
119 cubrate=" . $_POST['CubRate'] . ",
120 kgrate = " . $_POST['KGRate'] . ",
121 maxkgs = " . $_POST['MAXKGs'] . ",
122 maxcub= " . $_POST['MAXCub'] . ",
123 fixedprice = " . $_POST['FixedPrice'] . ",
124 minimumchg= " . $_POST['MinimumChg'] . "
125 WHERE shipcostfromid=" . $SelectedFreightCost;
127 $msg = _('Freight cost record updated');
129 } elseif ($InputError !=1) {
131 /*Selected freight cost is null cos no item selected on first time round so must be adding a record must be submitting new entries */
133 $sql = "INSERT INTO freightcosts (
145 '" . $_POST['Destination'] . "',
147 " . $_POST['CubRate'] . ",
148 " . $_POST['KGRate'] . ",
149 " . $_POST['MAXKGs'] . ",
150 " . $_POST['MAXCub'] . ",
151 " . $_POST['FixedPrice'] .",
152 " . $_POST['MinimumChg'] . "
155 $msg = _('Freight cost record inserted');
158 //run the SQL from either of the above possibilites
161 $ErrMsg = _('The freight cost record could not be updated because');
162 $result = DB_query($sql,$db,$ErrMsg);
164 prnMsg($msg,'success');
166 unset($SelectedFreightCost);
167 unset($_POST['CubRate']);
168 unset($_POST['KGRate']);
169 unset($_POST['MAXKGs']);
170 unset($_POST['MAXCub']);
171 unset($_POST['FixedPrice']);
172 unset($_POST['MinimumChg']);
174 } elseif (isset($_GET['delete'])) {
176 $sql = 'DELETE FROM freightcosts WHERE shipcostfromid=' . $SelectedFreightCost;
177 $result = DB_query($sql,$db);
178 prnMsg( _('Freight cost record deleted'),'success');
179 unset ($SelectedFreightCost);
180 unset($_GET['delete']);
183 if (!isset($SelectedFreightCost) AND isset($LocationFrom) AND isset($ShipperID)){
186 $sql = "SELECT shipcostfromid,
195 WHERE freightcosts.locationfrom = '$LocationFrom'
196 AND freightcosts.shipperid = $ShipperID
197 ORDER BY destination";
199 $result = DB_query($sql,$db);
201 echo '<table border=1>';
203 <td class='tableheader'>" . _('Destination') . "</td>
204 <td class='tableheader'>" . _('Cubic Rate') . "</td>
205 <td class='tableheader'>" . _('KG Rate') . "</td>
206 <td class='tableheader'>" . _('MAX KGs') . "</td>
207 <td class='tableheader'>" . _('MAX Volume') . "</td>
208 <td class='tableheader'>" . _('Fixed Price') . "</td>
209 <td class='tableheader'>" . _('Minimum Charge') . "</td>
214 $k = 0; //row counter to determine background colour
217 while ($myrow = DB_fetch_row($result)) {
219 if ($PageFullCounter==15){
225 echo "<tr bgcolor='#CCCCCC'>";
228 echo "<tr bgcolor='#EEEEEE'>";
234 <td ALIGN=RIGHT>%s</td>
235 <td ALIGN=RIGHT>%s</td>
236 <td ALIGN=RIGHT>%s</td>
237 <td ALIGN=RIGHT>%s</td>
238 <td ALIGN=RIGHT>%s</td>
239 <td ALIGN=RIGHT>%s</td>
240 <td><a href=\"%s&SelectedFreightCost=%s&LocationFrom=%s&ShipperID=%s\">" . _('Edit') . "</td>
241 <td><a href=\"%s&SelectedFreightCost=%s&LocationFrom=%s&ShipperID=%s&delete=yes\">" . _('Delete') . "</td></tr>",
249 $_SERVER['PHP_SELF'] . '?' . SID
,
253 $_SERVER['PHP_SELF'] . '?' . SID
,
260 //END WHILE LIST LOOP
264 //end of ifs and buts!
266 if (isset($SelectedFreightCost)) {
267 echo "<Center><a href='" . $_SERVER['PHP_SELF'] . "?" . SID
. '&LocationFrom=' . $LocationFrom . '&ShipperID=' . $ShipperID . "'>" . _('Show all freight costs for') . ' ' . $ShipperName . ' ' . _('from') . ' ' . $LocationName . '</a></Center>';
270 if (isset($LocationFrom) AND isset($ShipperID)) {
272 echo "<FORM METHOD='post' action='" . $_SERVER['PHP_SELF'] . '?' . SID
. "'>";
274 if ($SelectedFreightCost) {
275 //editing an existing freight cost item
277 $sql = "SELECT locationfrom,
287 WHERE shipcostfromid=$SelectedFreightCost";
289 $result = DB_query($sql, $db);
290 $myrow = DB_fetch_array($result);
292 $LocationFrom = $myrow['locationfrom'];
293 $_POST['Destination'] = $myrow['destination'];
294 $ShipperID = $myrow['shipperid'];
295 $_POST['CubRate'] = $myrow['cubrate'];
296 $_POST['KGRate'] = $myrow['kgrate'];
297 $_POST['MAXKGs'] = $myrow['maxkgs'];
298 $_POST['MAXCub'] = $myrow['maxcub'];
299 $_POST['FixedPrice'] = $myrow['fixedprice'];
300 $_POST['MinimumChg'] = $myrow['minimumchg'];
302 echo "<INPUT TYPE=HIDDEN NAME='SelectedFreightCost' VALUE=$SelectedFreightCost>";
305 $_POST['FixedPrice'] = 0;
306 $_POST['MinimumChg'] = 0;
309 echo "<input type=HIDDEN name='LocationFrom' value='$LocationFrom'>";
310 echo "<input type=HIDDEN name='ShipperID' value=$ShipperID>";
314 <TR><TD>' . _('Destination') . ":</TD>
315 <TD><input type='text' maxlength=20 size=20 name='Destination' VALUE='" . $_POST['Destination'] . "'></TD></TR>";
316 echo '<TR><TD>' . _('Rate per Cubic Metre') . ":</TD>
317 <TD><input type='Text' name='CubRate' SIZE=6 MAXLENGTH=5 value=" . $_POST['CubRate'] . "></TD></TR>";
318 echo '<TR><TD>' . _('Rate Per KG') . ":</TD>
319 <TD><input type='Text' name='KGRate' SIZE=6 MAXLENGTH=5 value=" . $_POST['KGRate'] . "></TD></TR>";
320 echo '<TR><TD>' . _('Maximum Weight Per Package (KGs)') . ":</a></TD>
321 <TD><input type='Text' name='MAXKGs' SIZE=8 MAXLENGTH=7 value=" . $_POST['MAXKGs'] . "></TD></TR>";
322 echo '<TR><TD>' . _('Maximum Volume Per Package (cubic metres)') . ":</a></TD>
323 <TD><input type='Text' name='MAXCub' SIZE=8 MAXLENGTH=7 value=" . $_POST['MAXCub'] . "></TD></TR>";
324 echo '<TR><TD>' . _('Fixed Price (zero if rate per KG or Cubic)') . ":</a></TD>
325 <TD><input type='Text' name='FixedPrice' SIZE=6 MAXLENGTH=5 value=" . $_POST['FixedPrice'] . "></TD></TR>";
326 echo '<TR><TD>' . _('Minimum Charge (0 is N/A)') . ":</a></TD>
327 <TD><input type='Text' name='MinimumChg' SIZE=6 MAXLENGTH=5 value=" . $_POST['MinimumChg'] . "></TD></TR>";
331 echo "<CENTER><input type='Submit' name='submit' value='" . _('Enter Information') . "'>";
335 } //end if record deleted no point displaying form to add record
337 include('includes/footer.inc');