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");
17 include($path_to_root . "/admin/db/shipping_db.inc");
19 simple_page_mode(true);
20 //----------------------------------------------------------------------------------------------
22 function can_process()
24 if (strlen($_POST['shipper_name']) == 0)
26 display_error(_("The shipping company name cannot be empty."));
27 set_focus('shipper_name');
33 //----------------------------------------------------------------------------------------------
34 if ($Mode=='ADD_ITEM' && can_process())
36 add_shipper($_POST['shipper_name'], $_POST['contact'], $_POST['phone'], $_POST['phone2'], $_POST['address']);
37 display_notification(_('New shipping company has been added'));
41 //----------------------------------------------------------------------------------------------
43 if ($Mode=='UPDATE_ITEM' && can_process())
45 update_shipper($selected_id, $_POST['shipper_name'], $_POST['contact'], $_POST['phone'], $_POST['phone2'], $_POST['address']);
46 display_notification(_('Selected shipping company has been updated'));
50 //----------------------------------------------------------------------------------------------
52 if ($Mode == 'Delete')
54 // PREVENT DELETES IF DEPENDENT RECORDS IN 'sales_orders'
56 if (key_in_foreign_table($selected_id, 'sales_orders', 'ship_via'))
59 display_error(_("Cannot delete this shipping company because sales orders have been created using this shipper."));
63 // PREVENT DELETES IF DEPENDENT RECORDS IN 'debtor_trans'
64 if (key_in_foreign_table($selected_id, 'debtor_trans', 'ship_via'))
67 display_error(_("Cannot delete this shipping company because invoices have been created using this shipping company."));
71 delete_shipper($selected_id);
72 display_notification(_('Selected shipping company has been deleted'));
81 $sav = get_post('show_inactive');
83 $_POST['show_inactive'] = $sav;
85 //----------------------------------------------------------------------------------------------
87 $result = get_shippers(check_value('show_inactive'));
90 start_table(TABLESTYLE);
91 $th = array(_("Name"), _("Contact Person"), _("Phone Number"), _("Secondary Phone"), _("Address"), "", "");
92 inactive_control_column($th);
95 $k = 0; //row colour counter
97 while ($myrow = db_fetch($result))
99 alt_table_row_color($k);
100 label_cell($myrow["shipper_name"]);
101 label_cell($myrow["contact"]);
102 label_cell($myrow["phone"]);
103 label_cell($myrow["phone2"]);
104 label_cell($myrow["address"]);
105 inactive_control_cell($myrow["shipper_id"], $myrow["inactive"], 'shippers', 'shipper_id');
106 edit_button_cell("Edit".$myrow["shipper_id"], _("Edit"));
107 delete_button_cell("Delete".$myrow["shipper_id"], _("Delete"));
111 inactive_control_row($th);
114 //----------------------------------------------------------------------------------------------
116 start_table(TABLESTYLE2);
118 if ($selected_id != -1)
120 if ($Mode == 'Edit') {
121 //editing an existing Shipper
123 $myrow = get_shipper($selected_id);
125 $_POST['shipper_name'] = $myrow["shipper_name"];
126 $_POST['contact'] = $myrow["contact"];
127 $_POST['phone'] = $myrow["phone"];
128 $_POST['phone2'] = $myrow["phone2"];
129 $_POST['address'] = $myrow["address"];
131 hidden('selected_id', $selected_id);
134 text_row_ex(_("Name:"), 'shipper_name', 40);
136 text_row_ex(_("Contact Person:"), 'contact', 30);
138 text_row_ex(_("Phone Number:"), 'phone', 32, 30);
140 text_row_ex(_("Secondary Phone Number:"), 'phone2', 32, 30);
142 text_row_ex(_("Address:"), 'address', 50);
146 submit_add_or_update_center($selected_id == -1, '', 'both');