2 /**********************************************************************
3 Copyright (C) FrontAccounting, LLC.
4 Released under the terms of the GNU General Public License, GPL,
5 as published by the Free Software Foundation, either version 3
6 of the License, or (at your option) any later version.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
14 include($path_to_root . "/includes/session.inc");
15 page(_("Shipping Company"));
16 include($path_to_root . "/includes/ui.inc");
18 simple_page_mode(true);
19 //----------------------------------------------------------------------------------------------
21 function can_process()
23 if (strlen($_POST['shipper_name']) == 0)
25 display_error(_("The shipping company name cannot be empty."));
26 set_focus('shipper_name');
32 //----------------------------------------------------------------------------------------------
33 if ($Mode=='ADD_ITEM' && can_process())
36 $sql = "INSERT INTO ".TB_PREF."shippers (shipper_name, contact, phone, address)
37 VALUES (" . db_escape($_POST['shipper_name']) . ", " .
38 db_escape($_POST['contact']). ", " .
39 db_escape($_POST['phone']). ", " .
40 db_escape($_POST['address']) . ")";
42 db_query($sql,"The Shipping Company could not be added");
43 display_notification(_('New shipping company has been added'));
47 //----------------------------------------------------------------------------------------------
49 if ($Mode=='UPDATE_ITEM' && can_process())
52 $sql = "UPDATE ".TB_PREF."shippers SET shipper_name=" . db_escape($_POST['shipper_name']). " ,
53 contact =" . db_escape($_POST['contact']). " ,
54 phone =" . db_escape($_POST['phone']). " ,
55 address =" . db_escape($_POST['address']). "
56 WHERE shipper_id = $selected_id";
58 db_query($sql,"The shipping company could not be updated");
59 display_notification(_('Selected shipping company has been updated'));
63 //----------------------------------------------------------------------------------------------
65 if ($Mode == 'Delete')
67 // PREVENT DELETES IF DEPENDENT RECORDS IN 'sales_orders'
69 $sql= "SELECT COUNT(*) FROM ".TB_PREF."sales_orders WHERE ship_via='$selected_id'";
70 $result = db_query($sql,"check failed");
71 $myrow = db_fetch_row($result);
75 display_error(_("Cannot delete this shipping company because sales orders have been created using this shipper."));
79 // PREVENT DELETES IF DEPENDENT RECORDS IN 'debtor_trans'
81 $sql= "SELECT COUNT(*) FROM ".TB_PREF."debtor_trans WHERE ship_via='$selected_id'";
82 $result = db_query($sql,"check failed");
83 $myrow = db_fetch_row($result);
87 display_error(_("Cannot delete this shipping company because invoices have been created using this shipping company."));
91 $sql="DELETE FROM ".TB_PREF."shippers WHERE shipper_id=$selected_id";
92 db_query($sql,"could not delete shipper");
93 display_notification(_('Selected shipping company has been deleted'));
104 //----------------------------------------------------------------------------------------------
106 $sql = "SELECT * FROM ".TB_PREF."shippers ORDER BY shipper_id";
107 $result = db_query($sql,"could not get shippers");
110 start_table($table_style);
111 $th = array(_("Name"), _("Contact Person"), _("Phone Number"), _("Address"), "", "");
114 $k = 0; //row colour counter
116 while ($myrow = db_fetch($result))
118 alt_table_row_color($k);
119 label_cell($myrow["shipper_name"]);
120 label_cell($myrow["contact"]);
121 label_cell($myrow["phone"]);
122 label_cell($myrow["address"]);
123 edit_button_cell("Edit".$myrow[0], _("Edit"));
124 delete_button_cell("Delete".$myrow[0], _("Delete"));
132 //----------------------------------------------------------------------------------------------
136 start_table($table_style2);
138 if ($selected_id != -1)
140 if ($Mode == 'Edit') {
141 //editing an existing Shipper
143 $sql = "SELECT * FROM ".TB_PREF."shippers WHERE shipper_id=$selected_id";
145 $result = db_query($sql, "could not get shipper");
146 $myrow = db_fetch($result);
148 $_POST['shipper_name'] = $myrow["shipper_name"];
149 $_POST['contact'] = $myrow["contact"];
150 $_POST['phone'] = $myrow["phone"];
151 $_POST['address'] = $myrow["address"];
153 hidden('selected_id', $selected_id);
156 text_row_ex(_("Name:"), 'shipper_name', 40);
158 text_row_ex(_("Contact Person:"), 'contact', 30);
160 text_row_ex(_("Phone Number:"), 'phone', 20);
162 text_row_ex(_("Address:"), 'address', 50);
166 submit_add_or_update_center($selected_id == -1, '', true);