7521182af1569eb15bfe6250205a280dab6bdba6
[fa-stable.git] / sales / manage / sales_groups.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_SALESGROUP';
13 $path_to_root = "../..";
14 include($path_to_root . "/includes/session.inc");
15
16 page(_($help_context = "Sales Groups"));
17
18 include($path_to_root . "/includes/ui.inc");
19
20 simple_page_mode(true);
21
22 if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM') 
23 {
24
25         $input_error = 0;
26
27         if (strlen($_POST['description']) == 0) 
28         {
29                 $input_error = 1;
30                 display_error(_("The area description cannot be empty."));
31                 set_focus('description');
32         }
33
34         if ($input_error != 1)
35         {
36         if ($selected_id != -1) 
37         {
38                 update_sales_group($selected_id, $_POST['description']);
39                         $note = _('Selected sales group has been updated');
40         } 
41         else 
42         {
43                 add_sales_group($_POST['description']);
44                         $note = _('New sales group has been added');
45         }
46     
47                 display_notification($note);            
48                 $Mode = 'RESET';
49         }
50
51
52 if ($Mode == 'Delete')
53 {
54
55         $cancel_delete = 0;
56
57         // PREVENT DELETES IF DEPENDENT RECORDS IN 'debtors_master'
58
59         if (key_in_foreign_table($selected_id, 'cust_branch', 'group_no'))
60         {
61                 $cancel_delete = 1;
62                 display_error(_("Cannot delete this group because customers have been created using this group."));
63         } 
64         if ($cancel_delete == 0) 
65         {
66                 delete_sales_group($selected_id);
67                 display_notification(_('Selected sales group has been deleted'));
68         } //end if Delete area
69         $Mode = 'RESET';
70
71
72 if ($Mode == 'RESET')
73 {
74         $selected_id = -1;
75         $sav = get_post('show_inactive');
76         unset($_POST);
77         if ($sav) $_POST['show_inactive'] = 1;
78 }
79 //-------------------------------------------------------------------------------------------------
80
81 $result = get_sales_groups(check_value('show_inactive'));
82
83 start_form();
84 start_table("$table_style width=30%");
85 $th = array(_("Group Name"), "", "");
86 inactive_control_column($th);
87
88 table_header($th);
89 $k = 0; 
90
91 while ($myrow = db_fetch($result)) 
92 {
93         
94         alt_table_row_color($k);
95                 
96         label_cell($myrow["description"]);
97         inactive_control_cell($myrow["id"], $myrow["inactive"], 'groups', 'id');
98         edit_button_cell("Edit".$myrow["id"], _("Edit"));
99         delete_button_cell("Delete".$myrow["id"], _("Delete"));
100         end_row();
101 }
102
103 inactive_control_row($th);
104 end_table(1);
105
106 //-------------------------------------------------------------------------------------------------
107
108 start_table($table_style2);
109
110 if ($selected_id != -1) 
111 {
112         if ($Mode == 'Edit') {
113                 //editing an existing area
114                 $myrow = get_sales_group($selected_id);
115
116                 $_POST['description']  = $myrow["description"];
117         }
118         hidden("selected_id", $selected_id);
119
120
121 text_row_ex(_("Group Name:"), 'description', 30); 
122
123 end_table(1);
124
125 submit_add_or_update_center($selected_id == -1, '', 'both');
126
127 end_form();
128
129 end_page();
130 ?>