Cleanup: removed all closing tags in php files.
[fa-stable.git] / sales / manage / credit_status.php
1 <?php
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");
15
16 page(_($help_context = "Credit Status")); 
17
18 include($path_to_root . "/sales/includes/db/credit_status_db.inc");
19
20 include($path_to_root . "/includes/ui.inc");
21
22 simple_page_mode(true);
23 //-----------------------------------------------------------------------------------
24
25 function can_process() 
26 {
27         
28         if (strlen($_POST['reason_description']) == 0) 
29         {
30                 display_error(_("The credit status description cannot be empty."));
31                 set_focus('reason_description');
32                 return false;
33         }       
34         
35         return true;
36 }
37
38 //-----------------------------------------------------------------------------------
39
40 if ($Mode=='ADD_ITEM' && can_process()) 
41 {
42
43         add_credit_status($_POST['reason_description'], $_POST['DisallowInvoices']);
44         display_notification(_('New credit status has been added'));
45         $Mode = 'RESET';
46
47
48 //-----------------------------------------------------------------------------------
49
50 if ($Mode=='UPDATE_ITEM' && can_process()) 
51 {
52         display_notification(_('Selected credit status has been updated'));
53         update_credit_status($selected_id, $_POST['reason_description'], $_POST['DisallowInvoices']);
54         $Mode = 'RESET';
55 }
56
57 //-----------------------------------------------------------------------------------
58
59 function can_delete($selected_id)
60 {
61         if (key_in_foreign_table($selected_id, 'debtors_master', 'credit_status'))
62         {
63                 display_error(_("Cannot delete this credit status because customer accounts have been created referring to it."));
64                 return false;
65         }
66         
67         return true;
68 }
69
70
71 //-----------------------------------------------------------------------------------
72
73 if ($Mode == 'Delete')
74 {
75
76         if (can_delete($selected_id))
77         {
78                 delete_credit_status($selected_id);
79                 display_notification(_('Selected credit status has been deleted'));
80         }
81         $Mode = 'RESET';
82 }
83
84 if ($Mode == 'RESET')
85 {
86         $selected_id = -1;
87         $sav = get_post('show_inactive');
88         unset($_POST);
89         $_POST['show_inactive'] = $sav;
90 }
91 //-----------------------------------------------------------------------------------
92
93 $result = get_all_credit_status(check_value('show_inactive'));
94
95 start_form();
96 start_table(TABLESTYLE, "width=40%");
97 $th = array(_("Description"), _("Dissallow Invoices"),'','');
98 inactive_control_column($th);
99 table_header($th);
100
101 $k = 0;
102 while ($myrow = db_fetch($result)) 
103 {
104         
105         alt_table_row_color($k);        
106
107         if ($myrow["dissallow_invoices"] == 0) 
108         {
109                 $disallow_text = _("Invoice OK");
110         } 
111         else 
112         {
113                 $disallow_text = "<b>" . _("NO INVOICING") . "</b>";
114         }
115         
116         label_cell($myrow["reason_description"]);
117         label_cell($disallow_text);
118         inactive_control_cell($myrow["id"], $myrow["inactive"], 'credit_status', 'id');
119         edit_button_cell("Edit".$myrow['id'], _("Edit"));
120         delete_button_cell("Delete".$myrow['id'], _("Delete"));
121         end_row();
122 }
123
124 inactive_control_row($th);
125 end_table();
126 echo '<br>';
127
128 //-----------------------------------------------------------------------------------
129
130 start_table(TABLESTYLE2);
131
132 if ($selected_id != -1) 
133 {
134         if ($Mode == 'Edit') {
135                 //editing an existing status code
136
137                 $myrow = get_credit_status($selected_id);
138
139                 $_POST['reason_description']  = $myrow["reason_description"];
140                 $_POST['DisallowInvoices']  = $myrow["dissallow_invoices"];
141         }
142         hidden('selected_id', $selected_id);
143
144
145 text_row_ex(_("Description:"), 'reason_description', 50);
146
147 yesno_list_row(_("Dissallow invoicing ?"), 'DisallowInvoices', null); 
148
149 end_table(1);
150
151 submit_add_or_update_center($selected_id == -1, '', 'both');
152
153 end_form();
154
155 //------------------------------------------------------------------------------------
156
157 end_page();
158