Feature 5388: Print Invoices (documents) list gets too long. Fixed by default 180...
[fa-stable.git] / admin / shipping_companies.php
1 <?php
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';
13 $path_to_root="..";
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");
18
19 simple_page_mode(true);
20 //----------------------------------------------------------------------------------------------
21
22 function can_process() 
23 {
24         if (strlen($_POST['shipper_name']) == 0) 
25         {
26                 display_error(_("The shipping company name cannot be empty."));
27                 set_focus('shipper_name');
28                 return false;
29         }
30         return true;
31 }
32
33 //----------------------------------------------------------------------------------------------
34 if ($Mode=='ADD_ITEM' && can_process()) 
35 {
36         add_shipper($_POST['shipper_name'], $_POST['contact'], $_POST['phone'], $_POST['phone2'], $_POST['address']);
37         display_notification(_('New shipping company has been added'));
38         $Mode = 'RESET';
39 }
40
41 //----------------------------------------------------------------------------------------------
42
43 if ($Mode=='UPDATE_ITEM' && can_process()) 
44 {
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'));
47         $Mode = 'RESET';
48 }
49
50 //----------------------------------------------------------------------------------------------
51
52 if ($Mode == 'Delete')
53 {
54 // PREVENT DELETES IF DEPENDENT RECORDS IN 'sales_orders'
55
56         if (key_in_foreign_table($selected_id, 'sales_orders', 'ship_via'))
57         {
58                 $cancel_delete = 1;
59                 display_error(_("Cannot delete this shipping company because sales orders have been created using this shipper."));
60         } 
61         else 
62         {
63                 // PREVENT DELETES IF DEPENDENT RECORDS IN 'debtor_trans'
64                 if (key_in_foreign_table($selected_id, 'debtor_trans', 'ship_via'))
65                 {
66                         $cancel_delete = 1;
67                         display_error(_("Cannot delete this shipping company because invoices have been created using this shipping company."));
68                 } 
69                 else 
70                 {
71                         delete_shipper($selected_id);
72                         display_notification(_('Selected shipping company has been deleted'));
73                 }
74         }
75         $Mode = 'RESET';
76 }
77
78 if ($Mode == 'RESET')
79 {
80         $selected_id = -1;
81         $sav = get_post('show_inactive');
82         unset($_POST);
83         $_POST['show_inactive'] = $sav;
84 }
85 //----------------------------------------------------------------------------------------------
86
87 $result = get_shippers(check_value('show_inactive'));
88
89 start_form();
90 start_table(TABLESTYLE);
91 $th = array(_("Name"), _("Contact Person"), _("Phone Number"), _("Secondary Phone"), _("Address"), "", "");
92 inactive_control_column($th);
93 table_header($th);
94
95 $k = 0; //row colour counter
96
97 while ($myrow = db_fetch($result)) 
98 {
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"));
108         end_row();
109 }
110
111 inactive_control_row($th);
112 end_table(1);
113
114 //----------------------------------------------------------------------------------------------
115
116 start_table(TABLESTYLE2);
117
118 if ($selected_id != -1) 
119 {
120         if ($Mode == 'Edit') {
121                 //editing an existing Shipper
122
123                 $myrow = get_shipper($selected_id);
124
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"];
130         }
131         hidden('selected_id', $selected_id);
132 }
133
134 text_row_ex(_("Name:"), 'shipper_name', 40);
135
136 text_row_ex(_("Contact Person:"), 'contact', 30);
137
138 text_row_ex(_("Phone Number:"), 'phone', 32, 30);
139
140 text_row_ex(_("Secondary Phone Number:"), 'phone2', 32, 30);
141
142 text_row_ex(_("Address:"), 'address', 50);
143
144 end_table(1);
145
146 submit_add_or_update_center($selected_id == -1, '', 'both');
147
148 end_form();
149 end_page();