Extended email entries.
[fa-stable.git] / inventory / manage / locations.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_INVENTORYLOCATION';
13 $path_to_root = "../..";
14 include($path_to_root . "/includes/session.inc");
15
16 page(_($help_context = "Inventory Locations"));
17
18 include_once($path_to_root . "/includes/ui.inc");
19
20 include_once($path_to_root . "/inventory/includes/inventory_db.inc");
21
22 simple_page_mode(true);
23
24 if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM') 
25 {
26
27         //initialise no input errors assumed initially before we test
28         $input_error = 0;
29
30         /* actions to take once the user has clicked the submit button
31         ie the page has called itself with some user input */
32
33         //first off validate inputs sensible
34         $_POST['loc_code'] = strtoupper($_POST['loc_code']);
35
36         if ((strlen(db_escape($_POST['loc_code'])) > 7) || empty($_POST['loc_code'])) //check length after conversion
37         {
38                 $input_error = 1;
39                 display_error( _("The location code must be five characters or less long (including converted special chars)."));
40                 set_focus('loc_code');
41         } 
42         elseif (strlen($_POST['location_name']) == 0) 
43         {
44                 $input_error = 1;
45                 display_error( _("The location name must be entered."));                
46                 set_focus('location_name');
47         }
48
49         if ($input_error != 1) 
50         {
51         if ($selected_id != -1) 
52         {
53     
54                 update_item_location($selected_id, $_POST['location_name'], $_POST['delivery_address'],
55                         $_POST['phone'], $_POST['phone2'], $_POST['fax'], $_POST['email'], $_POST['contact']);  
56                         display_notification(_('Selected location has been updated'));
57         } 
58         else 
59         {
60     
61         /*selected_id is null cos no item selected on first time round so must be adding a      record must be submitting new entries in the new Location form */
62         
63                 add_item_location($_POST['loc_code'], $_POST['location_name'], $_POST['delivery_address'], 
64                         $_POST['phone'], $_POST['phone2'], $_POST['fax'], $_POST['email'], $_POST['contact']);
65                         display_notification(_('New location has been added'));
66         }
67                 
68                 $Mode = 'RESET';
69         }
70
71
72 function can_delete($selected_id)
73 {
74         if (key_in_foreign_table($selected_id, 'stock_moves', 'loc_code'))
75         {
76                 display_error(_("Cannot delete this location because item movements have been created using this location."));
77                 return false;
78         }
79
80         if (key_in_foreign_table($selected_id, 'workorders', 'loc_code'))
81         {
82                 display_error(_("Cannot delete this location because it is used by some work orders records."));
83                 return false;
84         }
85
86         if (key_in_foreign_table($selected_id, 'cust_branch', 'default_location'))
87         {
88                 display_error(_("Cannot delete this location because it is used by some branch records as the default location to deliver from."));
89                 return false;
90         }
91         
92         if (key_in_foreign_table($selected_id, 'bom', 'loc_code'))
93         {
94                 display_error(_("Cannot delete this location because it is used by some related records in other tables."));
95                 return false;
96         }
97         
98         if (key_in_foreign_table($selected_id, 'grn_batch', 'loc_code'))
99         {
100                 display_error(_("Cannot delete this location because it is used by some related records in other tables."));
101                 return false;
102         }
103         if (key_in_foreign_table($selected_id, 'purch_orders', 'into_stock_location'))
104         {
105                 display_error(_("Cannot delete this location because it is used by some related records in other tables."));
106                 return false;
107         }
108         if (key_in_foreign_table($selected_id, 'sales_orders', 'from_stk_loc'))
109         {
110                 display_error(_("Cannot delete this location because it is used by some related records in other tables."));
111                 return false;
112         }
113         if (key_in_foreign_table($selected_id, 'sales_pos', 'pos_location'))
114         {
115                 display_error(_("Cannot delete this location because it is used by some related records in other tables."));
116                 return false;
117         }
118         return true;
119 }
120
121 //----------------------------------------------------------------------------------
122
123 if ($Mode == 'Delete')
124 {
125
126         if (can_delete($selected_id)) 
127         {
128                 delete_item_location($selected_id);
129                 display_notification(_('Selected location has been deleted'));
130         } //end if Delete Location
131         $Mode = 'RESET';
132 }
133
134 if ($Mode == 'RESET')
135 {
136         $selected_id = -1;
137         $sav = get_post('show_inactive');
138         unset($_POST);
139         $_POST['show_inactive'] = $sav;
140 }
141
142 $result = get_item_locations(check_value('show_inactive'));
143
144 start_form();
145 start_table(TABLESTYLE);
146 $th = array(_("Location Code"), _("Location Name"), _("Address"), _("Phone"), _("Secondary Phone"), "", "");
147 inactive_control_column($th);
148 table_header($th);
149 $k = 0; //row colour counter
150 while ($myrow = db_fetch($result)) 
151 {
152
153         alt_table_row_color($k);
154         
155         label_cell($myrow["loc_code"]);
156         label_cell($myrow["location_name"]);
157         label_cell($myrow["delivery_address"]);
158         label_cell($myrow["phone"]);
159         label_cell($myrow["phone2"]);
160         inactive_control_cell($myrow["loc_code"], $myrow["inactive"], 'locations', 'loc_code');
161         edit_button_cell("Edit".$myrow["loc_code"], _("Edit"));
162         delete_button_cell("Delete".$myrow["loc_code"], _("Delete"));
163         end_row();
164 }
165         //END WHILE LIST LOOP
166 inactive_control_row($th);
167 end_table();
168
169 echo '<br>';
170
171 start_table(TABLESTYLE2);
172
173 $_POST['email'] = "";
174 if ($selected_id != -1) 
175 {
176         //editing an existing Location
177
178         if ($Mode == 'Edit') {
179                 $myrow = get_item_location($selected_id);
180
181                 $_POST['loc_code'] = $myrow["loc_code"];
182                 $_POST['location_name']  = $myrow["location_name"];
183                 $_POST['delivery_address'] = $myrow["delivery_address"];
184                 $_POST['contact'] = $myrow["contact"];
185                 $_POST['phone'] = $myrow["phone"];
186                 $_POST['phone2'] = $myrow["phone2"];
187                 $_POST['fax'] = $myrow["fax"];
188                 $_POST['email'] = $myrow["email"];
189         }
190         hidden("selected_id", $selected_id);
191         hidden("loc_code");
192         label_row(_("Location Code:"), $_POST['loc_code']);
193
194 else 
195 { //end of if $selected_id only do the else when a new record is being entered
196         text_row(_("Location Code:"), 'loc_code', null, 5, 5);
197 }
198
199 text_row_ex(_("Location Name:"), 'location_name', 50, 50);
200 text_row_ex(_("Contact for deliveries:"), 'contact', 30, 30);
201
202 textarea_row(_("Address:"), 'delivery_address', null, 34, 5);   
203
204 text_row_ex(_("Telephone No:"), 'phone', 32, 30);
205 text_row_ex(_("Secondary Phone Number:"), 'phone2', 32, 30);
206 text_row_ex(_("Facsimile No:"), 'fax', 32, 30);
207 email_row_ex(_("E-mail:"), 'email', 50);
208
209 end_table(1);
210 submit_add_or_update_center($selected_id == -1, '', 'both');
211
212 end_form();
213
214 end_page();
215
216 ?>