5 include($path_to_root . "/includes/session.inc");
7 page(_("Credit Status"));
9 include($path_to_root . "/sales/includes/db/credit_status_db.inc");
11 include($path_to_root . "/includes/ui.inc");
13 if (isset($_GET['selected_id']))
15 $selected_id = $_GET['selected_id'];
17 elseif (isset($_POST['selected_id']))
19 $selected_id = $_POST['selected_id'];
22 //-----------------------------------------------------------------------------------
24 function can_process()
27 if (strlen($_POST['reason_description']) == 0)
29 display_error(_("The credit status description cannot be empty."));
36 //-----------------------------------------------------------------------------------
38 if (isset($_POST['ADD_ITEM']) && can_process())
41 add_credit_status($_POST['reason_description'], $_POST['DisallowInvoices']);
42 meta_forward($_SERVER['PHP_SELF']);
45 //-----------------------------------------------------------------------------------
47 if (isset($_POST['UPDATE_ITEM']) && can_process())
50 update_credit_status($selected_id, $_POST['reason_description'], $_POST['DisallowInvoices']);
51 meta_forward($_SERVER['PHP_SELF']);
54 //-----------------------------------------------------------------------------------
56 function can_delete($selected_id)
58 $sql= "SELECT COUNT(*) FROM ".TB_PREF."debtors_master
59 WHERE credit_status=$selected_id";
60 $result = db_query($sql, "could not query customers");
61 $myrow = db_fetch_row($result);
64 display_error(_("Cannot delete this credit status because customer accounts have been created referring to it."));
72 //-----------------------------------------------------------------------------------
74 if (isset($_GET['delete']))
77 if (can_delete($selected_id))
79 delete_credit_status($selected_id);
80 meta_forward($_SERVER['PHP_SELF']);
84 //-----------------------------------------------------------------------------------
86 $result = get_all_credit_status();
88 start_table("$table_style width=40%");
89 $th = array(_("Description"), _("Dissallow Invoices"),'','');
93 while ($myrow = db_fetch($result))
96 alt_table_row_color($k);
98 if ($myrow["dissallow_invoices"] == 0)
100 $disallow_text = _("Invoice OK");
104 $disallow_text = "<b>" . _("NO INVOICING") . "</b>";
107 label_cell($myrow["reason_description"]);
108 label_cell($disallow_text);
109 edit_link_cell("selected_id=" . $myrow["id"]);
110 delete_link_cell("selected_id=" . $myrow["id"]. "&delete=1");
116 //-----------------------------------------------------------------------------------
118 hyperlink_no_params($_SERVER['PHP_SELF'], _("New Credit Status"));
122 start_table("$table_style2 width=40%");
124 if (isset($selected_id))
126 //editing an existing status code
128 $myrow = get_credit_status($selected_id);
130 $_POST['reason_description'] = $myrow["reason_description"];
131 $_POST['DisallowInvoices'] = $myrow["dissallow_invoices"];
133 hidden('selected_id', $selected_id);
136 text_row_ex(_("Description:"), 'reason_description', 50);
138 yesno_list_row(_("Dissallow invoicing ?"), 'DisallowInvoices', null);
142 submit_add_or_update_center(!isset($selected_id));
146 //------------------------------------------------------------------------------------