f4608d088e3c10d2cef45fc934d287af768868ab
[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 simple_page_mode(true);
14 //-----------------------------------------------------------------------------------
15
16 function can_process() 
17 {
18         
19         if (strlen($_POST['reason_description']) == 0) 
20         {
21                 display_error(_("The credit status description cannot be empty."));
22                 return false;
23         }       
24         
25         return true;
26 }
27
28 //-----------------------------------------------------------------------------------
29
30 if ($Mode=='ADD_ITEM' && can_process()) 
31 {
32
33         add_credit_status($_POST['reason_description'], $_POST['DisallowInvoices']);
34         display_notification(_('New credit status has been added'));
35         $Mode = 'RESET';
36
37
38 //-----------------------------------------------------------------------------------
39
40 if ($Mode=='UPDATE_ITEM' && can_process()) 
41 {
42         display_notification(_('Selected credit status has been updated'));
43         update_credit_status($selected_id, $_POST['reason_description'], $_POST['DisallowInvoices']);
44         $Mode = 'RESET';
45 }
46
47 //-----------------------------------------------------------------------------------
48
49 function can_delete($selected_id)
50 {
51         $sql= "SELECT COUNT(*) FROM ".TB_PREF."debtors_master 
52                 WHERE credit_status=$selected_id";
53         $result = db_query($sql, "could not query customers");
54         $myrow = db_fetch_row($result);
55         if ($myrow[0] > 0) 
56         {
57                 display_error(_("Cannot delete this credit status because customer accounts have been created referring to it."));
58                 return false;
59         }
60         
61         return true;
62 }
63
64
65 //-----------------------------------------------------------------------------------
66
67 if ($Mode == 'Delete')
68 {
69
70         if (can_delete($selected_id))
71         {
72                 delete_credit_status($selected_id);
73                 display_notification(_('Selected credit status has been deleted'));
74                 $Mode = 'RESET';
75         }
76 }
77
78 if ($Mode == 'RESET')
79 {
80         $selected_id = -1;
81         unset($_POST);
82 }
83 //-----------------------------------------------------------------------------------
84
85 $result = get_all_credit_status();
86
87 start_form();
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_button_cell("Edit".$myrow['id'], _("Edit"));
110         edit_button_cell("Delete".$myrow['id'], _("Delete"));
111         end_row();
112 }
113
114 end_table();
115 end_form();
116 echo '<br>';
117
118 //-----------------------------------------------------------------------------------
119
120 start_form();
121
122 start_table("$table_style2 width=40%");
123
124 if ($selected_id != -1) 
125 {
126         if ($Mode == 'Edit') {
127                 //editing an existing status code
128
129                 $myrow = get_credit_status($selected_id);
130
131                 $_POST['reason_description']  = $myrow["reason_description"];
132                 $_POST['DisallowInvoices']  = $myrow["dissallow_invoices"];
133         }
134         hidden('selected_id', $selected_id);
135
136
137 text_row_ex(_("Description:"), 'reason_description', 50);
138
139 yesno_list_row(_("Dissallow invoicing ?"), 'DisallowInvoices', null); 
140
141 end_table(1);
142
143 submit_add_or_update_center($selected_id == -1, '', true);
144
145 end_form();
146
147 //------------------------------------------------------------------------------------
148
149 end_page();
150
151 ?>