New files from unstable branch
[fa-stable.git] / sales / manage / sales_points.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_POSSETUP';
13 $path_to_root = "../..";
14 include_once($path_to_root . "/includes/session.inc");
15
16 page(_($help_context = "POS settings"));
17
18 include_once($path_to_root . "/includes/ui.inc");
19 include_once($path_to_root . "/sales/includes/db/sales_points_db.inc");
20
21 simple_page_mode(true);
22 //----------------------------------------------------------------------------------------------------
23
24 function can_process()
25 {
26         if (strlen($_POST['name']) == 0)
27         {
28                 display_error(_("The POS name cannot be empty."));
29                 set_focus('pos_name');
30                 return false;
31         }
32         return true;
33 }
34
35 //----------------------------------------------------------------------------------------------------
36
37 if ($Mode=='ADD_ITEM' && can_process())
38 {
39         add_sales_point($_POST['name'], $_POST['location'], $_POST['account'],
40                 check_value('cash'), check_value('credit'));
41         display_notification(_('New point of sale has been added'));
42         $Mode = 'RESET';
43 }
44
45 //----------------------------------------------------------------------------------------------------
46
47 if ($Mode=='UPDATE_ITEM' && can_process())
48 {
49
50         update_sales_point($selected_id, $_POST['name'], $_POST['location'],
51                 $_POST['account'], check_value('cash'), check_value('credit'));
52         display_notification(_('Selected point of sale has been updated'));
53         $Mode = 'RESET';
54 }
55
56 //----------------------------------------------------------------------------------------------------
57
58 if ($Mode == 'Delete')
59 {
60         if (key_in_foreign_table($selected_id, 'users', 'pos'))
61         {
62                 display_error(_("Cannot delete this POS because it is used in users setup."));
63         } else {
64                 delete_sales_point($selected_id);
65                 display_notification(_('Selected point of sale has been deleted'));
66                 $Mode = 'RESET';
67         }
68 }
69
70 if ($Mode == 'RESET')
71 {
72         $selected_id = -1;
73         $sav = get_post('show_inactive');
74         unset($_POST);
75         $_POST['show_inactive'] = $sav;
76 }
77 //----------------------------------------------------------------------------------------------------
78
79 $result = get_all_sales_points(check_value('show_inactive'));
80
81 start_form();
82 start_table(TABLESTYLE);
83
84 $th = array (_('POS Name'), _('Credit sale'), _('Cash sale'), _('Location'), _('Default account'), 
85          '','');
86 inactive_control_column($th);
87 table_header($th);
88 $k = 0;
89
90 while ($myrow = db_fetch($result))
91 {
92     alt_table_row_color($k);
93         label_cell($myrow["pos_name"], "nowrap");
94         label_cell($myrow['credit_sale'] ? _('Yes') : _('No'));
95         label_cell($myrow['cash_sale'] ? _('Yes') : _('No'));
96         label_cell($myrow["location_name"], "");
97         label_cell($myrow["bank_account_name"], "");
98         inactive_control_cell($myrow["id"], $myrow["inactive"], "sales_pos", 'id');
99         edit_button_cell("Edit".$myrow['id'], _("Edit"));
100         delete_button_cell("Delete".$myrow['id'], _("Delete"));
101         end_row();
102 }
103
104 inactive_control_row($th);
105 end_table(1);
106 //----------------------------------------------------------------------------------------------------
107
108 $cash = db_has_cash_accounts();
109
110 if (!$cash) display_note(_("To have cash POS first define at least one cash bank account."));
111
112 start_table(TABLESTYLE2);
113
114 if ($selected_id != -1)
115 {
116
117         if ($Mode == 'Edit') {
118                 $myrow = get_sales_point($selected_id);
119
120                 $_POST['name']  = $myrow["pos_name"];
121                 $_POST['location']  = $myrow["pos_location"];
122                 $_POST['account']  = $myrow["pos_account"];
123                 if ($myrow["credit_sale"]) $_POST['credit_sale']  = 1;
124                 if ($myrow["cash_sale"]) $_POST['cash_sale'] = 1;
125         }
126         hidden('selected_id', $selected_id);
127
128
129 text_row_ex(_("Point of Sale Name").':', 'name', 20, 30);
130 if($cash) {
131         check_row(_('Allowed credit sale terms selection:'), 'credit', check_value('credit_sale'));
132         check_row(_('Allowed cash sale terms selection:'), 'cash',  check_value('cash_sale'));
133         cash_accounts_list_row(_("Default cash account").':', 'account');
134 } else {
135         hidden('credit', 1);
136         hidden('account', 0);
137 }
138
139 locations_list_row(_("POS location").':', 'location');
140 end_table(1);
141
142 submit_add_or_update_center($selected_id == -1, '', 'both');
143
144 end_form();
145
146 end_page();
147
148 ?>