6b0ee02d608b233911389da2433b201ff0708edf
[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                 set_focus('reason_description');
23                 return false;
24         }       
25         
26         return true;
27 }
28
29 //-----------------------------------------------------------------------------------
30
31 if ($Mode=='ADD_ITEM' && can_process()) 
32 {
33
34         add_credit_status($_POST['reason_description'], $_POST['DisallowInvoices']);
35         display_notification(_('New credit status has been added'));
36         $Mode = 'RESET';
37
38
39 //-----------------------------------------------------------------------------------
40
41 if ($Mode=='UPDATE_ITEM' && can_process()) 
42 {
43         display_notification(_('Selected credit status has been updated'));
44         update_credit_status($selected_id, $_POST['reason_description'], $_POST['DisallowInvoices']);
45         $Mode = 'RESET';
46 }
47
48 //-----------------------------------------------------------------------------------
49
50 function can_delete($selected_id)
51 {
52         $sql= "SELECT COUNT(*) FROM ".TB_PREF."debtors_master 
53                 WHERE credit_status=$selected_id";
54         $result = db_query($sql, "could not query customers");
55         $myrow = db_fetch_row($result);
56         if ($myrow[0] > 0) 
57         {
58                 display_error(_("Cannot delete this credit status because customer accounts have been created referring to it."));
59                 return false;
60         }
61         
62         return true;
63 }
64
65
66 //-----------------------------------------------------------------------------------
67
68 if ($Mode == 'Delete')
69 {
70
71         if (can_delete($selected_id))
72         {
73                 delete_credit_status($selected_id);
74                 display_notification(_('Selected credit status has been deleted'));
75         }
76         $Mode = 'RESET';
77 }
78
79 if ($Mode == 'RESET')
80 {
81         $selected_id = -1;
82         unset($_POST);
83 }
84 //-----------------------------------------------------------------------------------
85
86 $result = get_all_credit_status();
87
88 start_form();
89 start_table("$table_style width=40%");
90 $th = array(_("Description"), _("Dissallow Invoices"),'','');
91 table_header($th);
92
93 $k = 0;
94 while ($myrow = db_fetch($result)) 
95 {
96         
97         alt_table_row_color($k);        
98
99         if ($myrow["dissallow_invoices"] == 0) 
100         {
101                 $disallow_text = _("Invoice OK");
102         } 
103         else 
104         {
105                 $disallow_text = "<b>" . _("NO INVOICING") . "</b>";
106         }
107         
108         label_cell($myrow["reason_description"]);
109         label_cell($disallow_text);
110         edit_button_cell("Edit".$myrow['id'], _("Edit"));
111         edit_button_cell("Delete".$myrow['id'], _("Delete"));
112         end_row();
113 }
114
115 end_table();
116 end_form();
117 echo '<br>';
118
119 //-----------------------------------------------------------------------------------
120
121 start_form();
122
123 start_table("$table_style2 width=40%");
124
125 if ($selected_id != -1) 
126 {
127         if ($Mode == 'Edit') {
128                 //editing an existing status code
129
130                 $myrow = get_credit_status($selected_id);
131
132                 $_POST['reason_description']  = $myrow["reason_description"];
133                 $_POST['DisallowInvoices']  = $myrow["dissallow_invoices"];
134         }
135         hidden('selected_id', $selected_id);
136
137
138 text_row_ex(_("Description:"), 'reason_description', 50);
139
140 yesno_list_row(_("Dissallow invoicing ?"), 'DisallowInvoices', null); 
141
142 end_table(1);
143
144 submit_add_or_update_center($selected_id == -1, '', true);
145
146 end_form();
147
148 //------------------------------------------------------------------------------------
149
150 end_page();
151
152 ?>