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(_("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*/
52 $sql = "UPDATE ".TB_PREF."salesman SET salesman_name=".db_escape($_POST['salesman_name']) . ",
53 salesman_phone=".db_escape($_POST['salesman_phone']) . ",
54 salesman_fax=".db_escape($_POST['salesman_fax']) . ",
55 salesman_email=".db_escape($_POST['salesman_email']) . ",
56 provision=".input_num('provision').",
57 break_pt=".input_num('break_pt').",
58 provision2=".input_num('provision2')."
59 WHERE salesman_code = ".db_escape($selected_id);
63 /*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 */
64 $sql = "INSERT INTO ".TB_PREF."salesman (salesman_name, salesman_phone, salesman_fax, salesman_email,
65 provision, break_pt, provision2)
66 VALUES (".db_escape($_POST['salesman_name']) . ", "
67 .db_escape($_POST['salesman_phone']) . ", "
68 .db_escape($_POST['salesman_fax']) . ", "
69 .db_escape($_POST['salesman_email']) . ", ".
70 input_num('provision').", ".input_num('break_pt').", "
71 .input_num('provision2').")";
74 //run the sql from either of the above possibilites
75 db_query($sql,"The insert or update of the sales person failed");
76 if ($selected_id != -1)
77 display_notification(_('Selected sales person data have been updated'));
79 display_notification(_('New sales person data have been added'));
83 if ($Mode == 'Delete')
85 //the link to delete a selected record was clicked instead of the submit button
87 // PREVENT DELETES IF DEPENDENT RECORDS IN 'debtors_master'
89 $sql= "SELECT COUNT(*) FROM ".TB_PREF."cust_branch WHERE salesman=".db_escape($selected_id);
90 $result = db_query($sql,"check failed");
91 $myrow = db_fetch_row($result);
94 display_error("Cannot delete this sales-person because branches are set up referring to this sales-person - first alter the branches concerned.");
98 $sql="DELETE FROM ".TB_PREF."salesman WHERE salesman_code=".db_escape($selected_id);
99 db_query($sql,"The sales-person could not be deleted");
100 display_notification(_('Selected sales person data have been deleted'));
105 if ($Mode == 'RESET')
108 $sav = get_post('show_inactive');
110 $_POST['show_inactive'] = $sav;
112 //------------------------------------------------------------------------------------------------
114 $sql = "SELECT * FROM ".TB_PREF."salesman";
115 if (!check_value('show_inactive')) $sql .= " WHERE !inactive";
116 $result = db_query($sql,"could not get sales persons");
119 start_table("$table_style width=60%");
120 $th = array(_("Name"), _("Phone"), _("Fax"), _("Email"), _("Provision"), _("Break Pt."), _("Provision")." 2", "", "");
121 inactive_control_column($th);
126 while ($myrow = db_fetch($result))
129 alt_table_row_color($k);
131 label_cell($myrow["salesman_name"]);
132 label_cell($myrow["salesman_phone"]);
133 label_cell($myrow["salesman_fax"]);
134 email_cell($myrow["salesman_email"]);
135 label_cell(percent_format($myrow["provision"])." %", "nowrap align=right");
136 amount_cell($myrow["break_pt"]);
137 label_cell(percent_format($myrow["provision2"])." %", "nowrap align=right");
138 inactive_control_cell($myrow["salesman_code"], $myrow["inactive"],
139 'salesman', 'salesman_code');
140 edit_button_cell("Edit".$myrow["salesman_code"], _("Edit"));
141 delete_button_cell("Delete".$myrow["salesman_code"], _("Delete"));
144 } //END WHILE LIST LOOP
146 inactive_control_row($th);
150 //------------------------------------------------------------------------------------------------
152 $_POST['salesman_email'] = "";
153 if ($selected_id != -1)
155 if ($Mode == 'Edit') {
156 //editing an existing Sales-person
157 $sql = "SELECT * FROM ".TB_PREF."salesman WHERE salesman_code=".db_escape($selected_id);
159 $result = db_query($sql,"could not get sales person");
160 $myrow = db_fetch($result);
162 $_POST['salesman_name'] = $myrow["salesman_name"];
163 $_POST['salesman_phone'] = $myrow["salesman_phone"];
164 $_POST['salesman_fax'] = $myrow["salesman_fax"];
165 $_POST['salesman_email'] = $myrow["salesman_email"];
166 $_POST['provision'] = percent_format($myrow["provision"]);
167 $_POST['break_pt'] = price_format($myrow["break_pt"]);
168 $_POST['provision2'] = percent_format($myrow["provision2"]);
170 hidden('selected_id', $selected_id);
171 } elseif ($Mode != 'ADD_ITEM') {
172 $_POST['provision'] = percent_format(0);
173 $_POST['break_pt'] = price_format(0);
174 $_POST['provision2'] = percent_format(0);
177 start_table($table_style2);
179 text_row_ex(_("Sales person name:"), 'salesman_name', 30);
180 text_row_ex(_("Telephone number:"), 'salesman_phone', 20);
181 text_row_ex(_("Fax number:"), 'salesman_fax', 20);
182 email_row_ex(_("E-mail:"), 'salesman_email', 40);
183 percent_row(_("Provision").':', 'provision');
184 amount_row(_("Break Pt.:"), 'break_pt');
185 percent_row(_("Provision")." 2:", 'provision2');
188 submit_add_or_update_center($selected_id == -1, '', 'both');