Fixed page title.
[fa-stable.git] / sales / manage / sales_points.php
1 <?php
2
3 $page_security = 15;
4 $path_to_root="../..";
5 include_once($path_to_root . "/includes/session.inc");
6
7 page(_("POS settings"));
8
9 include_once($path_to_root . "/includes/ui.inc");
10 include_once($path_to_root . "/sales/includes/db/sales_points_db.inc");
11
12 simple_page_mode(true);
13 //----------------------------------------------------------------------------------------------------
14
15 function can_process()
16 {
17         if (strlen($_POST['name']) == 0)
18         {
19                 display_error(_("The POS name cannot be empty."));
20                 set_focus('pos_name');
21                 return false;
22         }
23         if (!check_value('cash') && !check_value('credit'))
24         {
25                 display_error(_("You must allow cash or credit sale."));
26                 set_focus('credit');
27                 return false;
28         }
29
30         return true;
31 }
32
33 //----------------------------------------------------------------------------------------------------
34
35 if ($Mode=='ADD_ITEM' && can_process())
36 {
37         add_sales_point($_POST['name'], $_POST['location'], $_POST['account'],
38                 check_value('cash'), check_value('credit'));
39         display_notification(_('New point of sale has been added'));
40         $Mode = 'RESET';
41 }
42
43 //----------------------------------------------------------------------------------------------------
44
45 if ($Mode=='UPDATE_ITEM' && can_process())
46 {
47
48         update_sales_point($selected_id, $_POST['name'], $_POST['location'],
49                 $_POST['account'], check_value('cash'), check_value('credit'));
50         display_notification(_('Selected point of sale has been updated'));
51         $Mode = 'RESET';
52 }
53
54 //----------------------------------------------------------------------------------------------------
55
56 if ($Mode == 'Delete')
57 {
58         delete_sales_point($selected_id);
59         display_notification(_('Selected point of sale has been deleted'));
60         $Mode = 'RESET';
61 }
62
63 if ($Mode == 'RESET')
64 {
65         $selected_id = -1;
66         unset($_POST);
67 }
68 //----------------------------------------------------------------------------------------------------
69
70 $result = get_all_sales_points();
71
72 start_form();
73 start_table("$table_style");
74
75 $th = array (_('POS Name'), _('Credit sale'), _('Cash sale'), _('Location'), _('Default account'), 
76          '','');
77 table_header($th);
78 $k = 0;
79
80 while ($myrow = db_fetch($result))
81 {
82     alt_table_row_color($k);
83         label_cell($myrow["pos_name"], "nowrap");
84         label_cell($myrow['credit_sale'] ? _('Yes') : _('No'));
85         label_cell($myrow['cash_sale'] ? _('Yes') : _('No'));
86         label_cell($myrow["location_name"], "");
87         label_cell($myrow["bank_account_name"], "");
88         edit_button_cell("Edit".$myrow['id'], _("Edit"));
89         edit_button_cell("Delete".$myrow['id'], _("Delete"));
90         end_row();
91 }
92
93 end_table();
94 end_form();
95 echo '<br>';
96 //----------------------------------------------------------------------------------------------------
97
98 start_form();
99
100 start_table("$table_style2 width=30%");
101
102 if ($selected_id != -1)
103 {
104
105         if ($Mode == 'Edit') {
106                 $myrow = get_sales_point($selected_id);
107
108                 $_POST['name']  = $myrow["pos_name"];
109                 $_POST['location']  = $myrow["pos_location"];
110                 $_POST['account']  = $myrow["pos_account"];
111                 if ($myrow["credit_sale"]) $_POST['credit_sale']  = 1;
112                 if ($myrow["cash_sale"]) $_POST['cash_sale'] = 1;
113         }
114         hidden('selected_id', $selected_id);
115
116
117 text_row_ex(_("Point of Sale Name").':', 'name', 20, 30);
118 check_row(_('Allowed credit sale'), 'credit', check_value('credit_sale'));
119 check_row(_('Allowed cash sale'), 'cash',  check_value('cash_sale'));
120 locations_list_row(_("POS location").':', 'location');
121 cash_accounts_list_row(_("Default cash account").':', 'account');
122
123 end_table(1);
124
125 submit_add_or_update_center($selected_id == -1, '', true);
126
127 end_form();
128
129 end_page();
130
131 ?>