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(_("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'));
102 $sav = get_post('show_inactive');
104 $_POST['show_inactive'] = $sav;
106 //----------------------------------------------------------------------------------------------
108 $sql = "SELECT * FROM ".TB_PREF."shippers";
109 if (!check_value('show_inactive')) $sql .= " WHERE !inactive";
110 $sql .= " ORDER BY shipper_id";
111 $result = db_query($sql,"could not get shippers");
114 start_table($table_style);
115 $th = array(_("Name"), _("Contact Person"), _("Phone Number"), _("Address"), "", "");
116 inactive_control_column($th);
119 $k = 0; //row colour counter
121 while ($myrow = db_fetch($result))
123 alt_table_row_color($k);
124 label_cell($myrow["shipper_name"]);
125 label_cell($myrow["contact"]);
126 label_cell($myrow["phone"]);
127 label_cell($myrow["address"]);
128 inactive_control_cell($myrow["shipper_id"], $myrow["inactive"], 'shippers', 'shipper_id');
129 edit_button_cell("Edit".$myrow["shipper_id"], _("Edit"));
130 delete_button_cell("Delete".$myrow["shipper_id"], _("Delete"));
134 inactive_control_row($th);
137 //----------------------------------------------------------------------------------------------
139 start_table($table_style2);
141 if ($selected_id != -1)
143 if ($Mode == 'Edit') {
144 //editing an existing Shipper
146 $sql = "SELECT * FROM ".TB_PREF."shippers WHERE shipper_id=$selected_id";
148 $result = db_query($sql, "could not get shipper");
149 $myrow = db_fetch($result);
151 $_POST['shipper_name'] = $myrow["shipper_name"];
152 $_POST['contact'] = $myrow["contact"];
153 $_POST['phone'] = $myrow["phone"];
154 $_POST['address'] = $myrow["address"];
156 hidden('selected_id', $selected_id);
159 text_row_ex(_("Name:"), 'shipper_name', 40);
161 text_row_ex(_("Contact Person:"), 'contact', 30);
163 text_row_ex(_("Phone Number:"), 'phone', 20);
165 text_row_ex(_("Address:"), 'address', 50);
169 submit_add_or_update_center($selected_id == -1, '', 'both');