*** empty log message ***
[fa-stable.git] / sales / manage / credit_status.php
1 <?php
2
3 $page_security = 3;
4 $path_to_root="../..";
5 include($path_to_root . "/includes/session.inc");
6
7 page(_("Credit Status")); 
8
9 include($path_to_root . "/sales/includes/db/credit_status_db.inc");
10
11 include($path_to_root . "/includes/ui.inc");
12
13 if (isset($_GET['selected_id']))
14 {
15         $selected_id = $_GET['selected_id'];
16
17 elseif (isset($_POST['selected_id']))
18 {
19         $selected_id = $_POST['selected_id'];
20 }
21
22 //-----------------------------------------------------------------------------------
23
24 function can_process() 
25 {
26         
27         if (strlen($_POST['reason_description']) == 0) 
28         {
29                 display_error(_("The credit status description cannot be empty."));
30                 return false;
31         }       
32         
33         return true;
34 }
35
36 //-----------------------------------------------------------------------------------
37
38 if (isset($_POST['ADD_ITEM']) && can_process()) 
39 {
40
41         add_credit_status($_POST['reason_description'], $_POST['DisallowInvoices']);
42         meta_forward($_SERVER['PHP_SELF']);     
43
44
45 //-----------------------------------------------------------------------------------
46
47 if (isset($_POST['UPDATE_ITEM']) && can_process()) 
48 {
49
50         update_credit_status($selected_id, $_POST['reason_description'], $_POST['DisallowInvoices']);
51         meta_forward($_SERVER['PHP_SELF']);     
52 }
53
54 //-----------------------------------------------------------------------------------
55
56 function can_delete($selected_id)
57 {
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);
62         if ($myrow[0] > 0) 
63         {
64                 display_error(_("Cannot delete this credit status because customer accounts have been created referring to it."));
65                 return false;
66         }
67         
68         return true;
69 }
70
71
72 //-----------------------------------------------------------------------------------
73
74 if (isset($_GET['delete'])) 
75 {
76
77         if (can_delete($selected_id))
78         {
79                 delete_credit_status($selected_id);
80                 meta_forward($_SERVER['PHP_SELF']);             
81         }
82 }
83
84 //-----------------------------------------------------------------------------------
85
86 $result = get_all_credit_status();
87
88 start_table("$table_style width=40%");
89 $th = array(_("Description"), _("Dissallow Invoices"));
90 table_header($th);
91
92 $k = 0;
93 while ($myrow = db_fetch($result)) 
94 {
95         
96         alt_table_row_color($k);        
97
98         if ($myrow["dissallow_invoices"] == 0) 
99         {
100                 $disallow_text = _("Invoice OK");
101         } 
102         else 
103         {
104                 $disallow_text = "<b>" . _("NO INVOICING") . "</b>";
105         }
106         
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");
111         end_row();
112 }
113
114 end_table();
115
116 //-----------------------------------------------------------------------------------
117
118 hyperlink_no_params($_SERVER['PHP_SELF'], _("New Credit Status"));
119
120 start_form();
121
122 start_table("$table_style2 width=40%");
123
124 if (isset($selected_id)) 
125 {
126         //editing an existing status code
127
128         $myrow = get_credit_status($selected_id);
129
130         $_POST['reason_description']  = $myrow["reason_description"];
131         $_POST['DisallowInvoices']  = $myrow["dissallow_invoices"];
132
133         hidden('selected_id', $selected_id);
134
135
136 text_row_ex(_("Description:"), 'reason_description', 50);
137
138 yesno_list_row(_("Dissallow invoicing ?"), 'DisallowInvoices', null); 
139
140 end_table(1);
141
142 submit_add_or_update_center(!isset($selected_id));
143
144 end_form();
145
146 //------------------------------------------------------------------------------------
147
148 end_page();
149
150 ?>