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 ***********************************************************************/
12 $page_security = 'SA_SHIPPING';
14 include($path_to_root . "/includes/session.inc");
15 page(_($help_context = "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, phone2, address)
37 VALUES (" . db_escape($_POST['shipper_name']) . ", " .
38 db_escape($_POST['contact']). ", " .
39 db_escape($_POST['phone']). ", " .
40 db_escape($_POST['phone2']). ", " .
41 db_escape($_POST['address']) . ")";
43 db_query($sql,"The Shipping Company could not be added");
44 display_notification(_('New shipping company has been added'));
48 //----------------------------------------------------------------------------------------------
50 if ($Mode=='UPDATE_ITEM' && can_process())
53 $sql = "UPDATE ".TB_PREF."shippers SET shipper_name=" . db_escape($_POST['shipper_name']). " ,
54 contact =" . db_escape($_POST['contact']). " ,
55 phone =" . db_escape($_POST['phone']). " ,
56 phone2 =" . db_escape($_POST['phone2']). " ,
57 address =" . db_escape($_POST['address']). "
58 WHERE shipper_id = ".db_escape($selected_id);
60 db_query($sql,"The shipping company could not be updated");
61 display_notification(_('Selected shipping company has been updated'));
65 //----------------------------------------------------------------------------------------------
67 if ($Mode == 'Delete')
69 // PREVENT DELETES IF DEPENDENT RECORDS IN 'sales_orders'
71 $sql= "SELECT COUNT(*) FROM ".TB_PREF."sales_orders WHERE ship_via=".db_escape($selected_id);
72 $result = db_query($sql,"check failed");
73 $myrow = db_fetch_row($result);
77 display_error(_("Cannot delete this shipping company because sales orders have been created using this shipper."));
81 // PREVENT DELETES IF DEPENDENT RECORDS IN 'debtor_trans'
83 $sql= "SELECT COUNT(*) FROM ".TB_PREF."debtor_trans WHERE ship_via=".db_escape($selected_id);
84 $result = db_query($sql,"check failed");
85 $myrow = db_fetch_row($result);
89 display_error(_("Cannot delete this shipping company because invoices have been created using this shipping company."));
93 $sql="DELETE FROM ".TB_PREF."shippers WHERE shipper_id=".db_escape($selected_id);
94 db_query($sql,"could not delete shipper");
95 display_notification(_('Selected shipping company has been deleted'));
101 if ($Mode == 'RESET')
104 $sav = get_post('show_inactive');
106 $_POST['show_inactive'] = $sav;
108 //----------------------------------------------------------------------------------------------
110 $sql = "SELECT * FROM ".TB_PREF."shippers";
111 if (!check_value('show_inactive')) $sql .= " WHERE !inactive";
112 $sql .= " ORDER BY shipper_id";
113 $result = db_query($sql,"could not get shippers");
116 start_table($table_style);
117 $th = array(_("Name"), _("Contact Person"), _("Phone Number"), _("Secondary Phone"), _("Address"), "", "");
118 inactive_control_column($th);
121 $k = 0; //row colour counter
123 while ($myrow = db_fetch($result))
125 alt_table_row_color($k);
126 label_cell($myrow["shipper_name"]);
127 label_cell($myrow["contact"]);
128 label_cell($myrow["phone"]);
129 label_cell($myrow["phone2"]);
130 label_cell($myrow["address"]);
131 inactive_control_cell($myrow["shipper_id"], $myrow["inactive"], 'shippers', 'shipper_id');
132 edit_button_cell("Edit".$myrow["shipper_id"], _("Edit"));
133 delete_button_cell("Delete".$myrow["shipper_id"], _("Delete"));
137 inactive_control_row($th);
140 //----------------------------------------------------------------------------------------------
142 start_table($table_style2);
144 if ($selected_id != -1)
146 if ($Mode == 'Edit') {
147 //editing an existing Shipper
149 $sql = "SELECT * FROM ".TB_PREF."shippers WHERE shipper_id=".db_escape($selected_id);
151 $result = db_query($sql, "could not get shipper");
152 $myrow = db_fetch($result);
154 $_POST['shipper_name'] = $myrow["shipper_name"];
155 $_POST['contact'] = $myrow["contact"];
156 $_POST['phone'] = $myrow["phone"];
157 $_POST['phone2'] = $myrow["phone2"];
158 $_POST['address'] = $myrow["address"];
160 hidden('selected_id', $selected_id);
163 text_row_ex(_("Name:"), 'shipper_name', 40);
165 text_row_ex(_("Contact Person:"), 'contact', 30);
167 text_row_ex(_("Phone Number:"), 'phone', 32, 30);
169 text_row_ex(_("Secondary Phone Number:"), 'phone2', 32, 30);
171 text_row_ex(_("Address:"), 'address', 50);
175 submit_add_or_update_center($selected_id == -1, '', 'both');