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_CRSTATUS';
13 $path_to_root = "../..";
14 include($path_to_root . "/includes/session.inc");
16 page(_("Credit Status"));
18 include($path_to_root . "/sales/includes/db/credit_status_db.inc");
20 include($path_to_root . "/includes/ui.inc");
22 simple_page_mode(true);
23 //-----------------------------------------------------------------------------------
25 function can_process()
28 if (strlen($_POST['reason_description']) == 0)
30 display_error(_("The credit status description cannot be empty."));
31 set_focus('reason_description');
38 //-----------------------------------------------------------------------------------
40 if ($Mode=='ADD_ITEM' && can_process())
43 add_credit_status($_POST['reason_description'], $_POST['DisallowInvoices']);
44 display_notification(_('New credit status has been added'));
48 //-----------------------------------------------------------------------------------
50 if ($Mode=='UPDATE_ITEM' && can_process())
52 display_notification(_('Selected credit status has been updated'));
53 update_credit_status($selected_id, $_POST['reason_description'], $_POST['DisallowInvoices']);
57 //-----------------------------------------------------------------------------------
59 function can_delete($selected_id)
61 $sql= "SELECT COUNT(*) FROM ".TB_PREF."debtors_master
62 WHERE credit_status=".db_escape($selected_id);
63 $result = db_query($sql, "could not query customers");
64 $myrow = db_fetch_row($result);
67 display_error(_("Cannot delete this credit status because customer accounts have been created referring to it."));
75 //-----------------------------------------------------------------------------------
77 if ($Mode == 'Delete')
80 if (can_delete($selected_id))
82 delete_credit_status($selected_id);
83 display_notification(_('Selected credit status has been deleted'));
91 $sav = get_post('show_inactive');
93 $_POST['show_inactive'] = $sav;
95 //-----------------------------------------------------------------------------------
97 $result = get_all_credit_status(check_value('show_inactive'));
100 start_table("$table_style width=40%");
101 $th = array(_("Description"), _("Dissallow Invoices"),'','');
102 inactive_control_column($th);
106 while ($myrow = db_fetch($result))
109 alt_table_row_color($k);
111 if ($myrow["dissallow_invoices"] == 0)
113 $disallow_text = _("Invoice OK");
117 $disallow_text = "<b>" . _("NO INVOICING") . "</b>";
120 label_cell($myrow["reason_description"]);
121 label_cell($disallow_text);
122 inactive_control_cell($myrow["id"], $myrow["inactive"], 'credit_status', 'id');
123 edit_button_cell("Edit".$myrow['id'], _("Edit"));
124 delete_button_cell("Delete".$myrow['id'], _("Delete"));
128 inactive_control_row($th);
132 //-----------------------------------------------------------------------------------
134 start_table($table_style2);
136 if ($selected_id != -1)
138 if ($Mode == 'Edit') {
139 //editing an existing status code
141 $myrow = get_credit_status($selected_id);
143 $_POST['reason_description'] = $myrow["reason_description"];
144 $_POST['DisallowInvoices'] = $myrow["dissallow_invoices"];
146 hidden('selected_id', $selected_id);
149 text_row_ex(_("Description:"), 'reason_description', 50);
151 yesno_list_row(_("Dissallow invoicing ?"), 'DisallowInvoices', null);
155 submit_add_or_update_center($selected_id == -1, '', 'both');
159 //------------------------------------------------------------------------------------