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 (sales_orders_has_shipper($selected_id))
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'
65 if (debtor_trans_has_shipper($selected_id))
68 display_error(_("Cannot delete this shipping company because invoices have been created using this shipping company."));
72 delete_shipper($selected_id);
73 display_notification(_('Selected shipping company has been deleted'));
82 $sav = get_post('show_inactive');
84 $_POST['show_inactive'] = $sav;
86 //----------------------------------------------------------------------------------------------
88 $result = get_shippers(check_value('show_inactive'));
91 start_table($table_style);
92 $th = array(_("Name"), _("Contact Person"), _("Phone Number"), _("Secondary Phone"), _("Address"), "", "");
93 inactive_control_column($th);
96 $k = 0; //row colour counter
98 while ($myrow = db_fetch($result))
100 alt_table_row_color($k);
101 label_cell($myrow["shipper_name"]);
102 label_cell($myrow["contact"]);
103 label_cell($myrow["phone"]);
104 label_cell($myrow["phone2"]);
105 label_cell($myrow["address"]);
106 inactive_control_cell($myrow["shipper_id"], $myrow["inactive"], 'shippers', 'shipper_id');
107 edit_button_cell("Edit".$myrow["shipper_id"], _("Edit"));
108 delete_button_cell("Delete".$myrow["shipper_id"], _("Delete"));
112 inactive_control_row($th);
115 //----------------------------------------------------------------------------------------------
117 start_table($table_style2);
119 if ($selected_id != -1)
121 if ($Mode == 'Edit') {
122 //editing an existing Shipper
124 $myrow = get_shipper($selected_id);
126 $_POST['shipper_name'] = $myrow["shipper_name"];
127 $_POST['contact'] = $myrow["contact"];
128 $_POST['phone'] = $myrow["phone"];
129 $_POST['phone2'] = $myrow["phone2"];
130 $_POST['address'] = $myrow["address"];
132 hidden('selected_id', $selected_id);
135 text_row_ex(_("Name:"), 'shipper_name', 40);
137 text_row_ex(_("Contact Person:"), 'contact', 30);
139 text_row_ex(_("Phone Number:"), 'phone', 32, 30);
141 text_row_ex(_("Secondary Phone Number:"), 'phone2', 32, 30);
143 text_row_ex(_("Address:"), 'address', 50);
147 submit_add_or_update_center($selected_id == -1, '', 'both');