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_SALESMAN';
13 $path_to_root = "../..";
14 include($path_to_root . "/includes/session.inc");
16 page(_($help_context = "Sales Persons"));
18 include($path_to_root . "/includes/ui.inc");
20 simple_page_mode(true);
21 //------------------------------------------------------------------------------------------------
23 if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
26 //initialise no input errors assumed initially before we test
29 if (strlen($_POST['salesman_name']) == 0)
32 display_error(_("The sales person name cannot be empty."));
33 set_focus('salesman_name');
35 $pr1 = check_num('provision', 0,100);
36 if (!$pr1 || !check_num('provision2', 0, 100)) {
38 display_error( _("Salesman provision cannot be less than 0 or more than 100%."));
39 set_focus(!$pr1 ? 'provision' : 'provision2');
41 if (!check_num('break_pt', 0)) {
43 display_error( _("Salesman provision breakpoint must be numeric and not less than 0."));
44 set_focus('break_pt');
46 if ($input_error != 1)
48 if ($selected_id != -1)
50 /*selected_id could also exist if submit had not been clicked this code would not run in this case cos submit is false of course see the delete code below*/
51 update_salesman($selected_id, $_POST['salesman_name'], $_POST['salesman_phone'], $_POST['salesman_fax'],
52 $_POST['salesman_email'], input_num('provision'), input_num('break_pt'), input_num('provision2'));
56 /*Selected group is null cos no item selected on first time round so must be adding a record must be submitting new entries in the new Sales-person form */
57 add_salesman($_POST['salesman_name'], $_POST['salesman_phone'], $_POST['salesman_fax'],
58 $_POST['salesman_email'], input_num('provision'), input_num('break_pt'), input_num('provision2'));
61 if ($selected_id != -1)
62 display_notification(_('Selected sales person data have been updated'));
64 display_notification(_('New sales person data have been added'));
68 if ($Mode == 'Delete')
70 //the link to delete a selected record was clicked instead of the submit button
72 // PREVENT DELETES IF DEPENDENT RECORDS IN 'debtors_master'
74 if (key_in_foreign_table($selected_id, 'cust_branch', 'salesman'))
76 display_error(_("Cannot delete this sales-person because branches are set up referring to this sales-person - first alter the branches concerned."));
80 delete_salesman($selected_id);
81 display_notification(_('Selected sales person data have been deleted'));
89 $sav = get_post('show_inactive');
91 $_POST['show_inactive'] = $sav;
93 //------------------------------------------------------------------------------------------------
95 $result = get_salesmen(check_value('show_inactive'));
98 start_table(TABLESTYLE, "width='60%'");
99 $th = array(_("Name"), _("Phone"), _("Fax"), _("Email"), _("Provision"), _("Break Pt."), _("Provision")." 2", "", "");
100 inactive_control_column($th);
105 while ($myrow = db_fetch($result))
108 alt_table_row_color($k);
110 label_cell($myrow["salesman_name"]);
111 label_cell($myrow["salesman_phone"]);
112 label_cell($myrow["salesman_fax"]);
113 email_cell($myrow["salesman_email"]);
114 label_cell(percent_format($myrow["provision"])." %", "nowrap align=right");
115 amount_cell($myrow["break_pt"]);
116 label_cell(percent_format($myrow["provision2"])." %", "nowrap align=right");
117 inactive_control_cell($myrow["salesman_code"], $myrow["inactive"],
118 'salesman', 'salesman_code');
119 edit_button_cell("Edit".$myrow["salesman_code"], _("Edit"));
120 delete_button_cell("Delete".$myrow["salesman_code"], _("Delete"));
123 } //END WHILE LIST LOOP
125 inactive_control_row($th);
129 //------------------------------------------------------------------------------------------------
131 $_POST['salesman_email'] = "";
132 if ($selected_id != -1)
134 if ($Mode == 'Edit') {
135 //editing an existing Sales-person
136 $myrow = get_salesman($selected_id);
138 $_POST['salesman_name'] = $myrow["salesman_name"];
139 $_POST['salesman_phone'] = $myrow["salesman_phone"];
140 $_POST['salesman_fax'] = $myrow["salesman_fax"];
141 $_POST['salesman_email'] = $myrow["salesman_email"];
142 $_POST['provision'] = percent_format($myrow["provision"]);
143 $_POST['break_pt'] = price_format($myrow["break_pt"]);
144 $_POST['provision2'] = percent_format($myrow["provision2"]);
146 hidden('selected_id', $selected_id);
147 } elseif ($Mode != 'ADD_ITEM') {
148 $_POST['provision'] = percent_format(0);
149 $_POST['break_pt'] = price_format(0);
150 $_POST['provision2'] = percent_format(0);
153 start_table(TABLESTYLE2);
155 text_row_ex(_("Sales person name:"), 'salesman_name', 30);
156 text_row_ex(_("Telephone number:"), 'salesman_phone', 20);
157 text_row_ex(_("Fax number:"), 'salesman_fax', 20);
158 email_row_ex(_("E-mail:"), 'salesman_email', 40);
159 percent_row(_("Provision").':', 'provision');
160 amount_row(_("Break Pt.:"), 'break_pt');
161 percent_row(_("Provision")." 2:", 'provision2');
164 submit_add_or_update_center($selected_id == -1, '', 'both');