Cleanup in types.inc
[fa-stable.git] / includes / types.inc
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 //----------------------------------------------------------------------------------
13 //      FrontAccounting system transaction types
14 //
15 define('ST_JOURNAL', 0);
16
17 define('ST_BANKPAYMENT', 1);
18 define('ST_BANKDEPOSIT', 2);
19 define('ST_BANKTRANSFER', 4);
20
21 define('ST_SALESINVOICE', 10);
22 define('ST_CUSTCREDIT', 11);
23 define('ST_CUSTPAYMENT', 12);
24 define('ST_CUSTDELIVERY', 13);
25
26 define('ST_LOCTRANSFER', 16);
27 define('ST_INVADJUST', 17);
28
29 define('ST_PURCHORDER', 18);
30 define('ST_SUPPINVOICE', 20);
31 define('ST_SUPPCREDIT', 21);
32 define('ST_SUPPAYMENT', 22);
33 define('ST_SUPPRECEIVE', 25);
34
35 define('ST_WORKORDER', 26);
36 define('ST_MANUISSUE', 28);
37 define('ST_MANURECEIVE', 29);
38
39 define('ST_SALESORDER', 30);
40 define('ST_SALESQUOTE', 32);
41 define('ST_COSTUPDATE', 35);
42 define('ST_DIMENSION', 40);
43
44 // Don't include these defines in the $systypes_array.
45 // They are used as report subtypes only.
46 define ('ST_STATEMENT', 91);
47 define ('ST_CHEQUE', 92);
48
49 // document inheritance
50 $document_child_types = array(
51                 ST_SALESQUOTE => ST_SALESORDER,
52                 ST_SALESORDER => ST_CUSTDELIVERY,
53                 ST_CUSTDELIVERY => ST_SALESINVOICE,
54                 ST_SALESINVOICE => ST_CUSTCREDIT,
55
56                 ST_PURCHORDER => ST_SUPPRECEIVE,
57                 ST_SUPPRECEIVE => ST_SUPPINVOICE,
58                 ST_SUPPINVOICE => ST_SUPPCREDIT,
59 );
60
61 function get_child_type($type)
62 {
63         global $document_child_types;
64         return isset($document_child_types[$type]) ? $document_child_types[$type] : 0;
65 }
66
67 function get_parent_type($type)
68 {
69         global $document_child_types;
70         $child = array_search($type, $document_child_types);
71         return $child ? $child : 0;
72 }
73
74 //----------------------------------------------------------------------------------
75 //              Bank transaction types
76 //
77 define('BT_TRANSFER', 0);
78 define('BT_CHEQUE', 1);
79 define('BT_CREDIT', 2);
80 define('BT_CASH', 3);
81
82 include_once($path_to_root . "/manufacturing/includes/manufacturing_db.inc");
83 include_once($path_to_root . "/purchasing/includes/purchasing_db.inc");
84 include_once($path_to_root . "/sales/includes/sales_db.inc");
85 include_once($path_to_root . "/dimensions/includes/dimensions_db.inc");
86 //----------------------------------------------------------------------------------
87 //      Payment types
88 //
89 define('PT_MISC', 0);
90 define('PT_WORKORDER', 1);
91 define('PT_CUSTOMER', 2);
92 define('PT_SUPPLIER', 3);
93 define('PT_QUICKENTRY', 4);
94 define('PT_DIMESION', 5);
95
96 function payment_person_currency($type, $person_id)  {
97         switch ($type)
98         {
99                 case PT_MISC :
100                 case PT_QUICKENTRY :
101                 case PT_WORKORDER :
102                         return get_company_currency();
103
104                 case PT_CUSTOMER :
105                         return get_customer_currency($person_id);
106
107                 case PT_SUPPLIER :
108                         return get_supplier_currency($person_id);
109
110                 default :
111                         return get_company_currency();
112         }
113 }
114
115 function payment_person_name($type, $person_id, $full=true) {
116         global $payment_person_types;
117
118         switch ($type)
119         {
120                 case PT_MISC :
121                         return $person_id;
122                 case PT_QUICKENTRY :
123                         $qe = get_quick_entry($person_id);
124                         return ($full ? $payment_person_types[$type] . " ":"") . $qe["description"];
125                 case PT_WORKORDER :
126                         global $wo_cost_types;
127                         return get_trans_view_str(ST_WORKORDER, $person_id, _('Work Order').' '.$person_id);
128                 case PT_CUSTOMER :
129                         return ($full ?$payment_person_types[$type] . " ":"") . sprintf("[%05s] %s", $person_id, get_customer_name($person_id));
130                 case PT_SUPPLIER :
131                         return ($full ? $payment_person_types[$type] . " ":"") . sprintf("[%05s] %s", $person_id, get_supplier_name($person_id));
132                 default :
133                         return '';
134         }
135 }
136
137 function payment_person_has_items($type) {
138         switch ($type)
139         {
140                 case PT_MISC :
141                         return true;
142                 case PT_QUICKENTRY :
143                         return db_has_quick_entries();
144                 case PT_WORKORDER : // 070305 changed to open workorders JH
145                         return db_has_open_workorders();
146                 case PT_CUSTOMER :
147                         return db_has_customers();
148                 case PT_SUPPLIER :
149                         return db_has_suppliers();
150                 default :
151                         display_db_error("Invalid type sent to has_items", "");
152                         return false;
153         }
154 }
155 //----------------------------------------------------------------------------------
156 //      Payment terms categories
157 //
158 define('PM_ANY', 0);
159 define('PM_CASH', 1);
160 define('PM_CREDIT', 2);
161
162 //----------------------------------------------------------------------------------
163 //      Manufacturing types
164 //
165 define('WO_ASSEMBLY', 0);
166 define('WO_UNASSEMBLY', 1);
167 define('WO_ADVANCED', 2);
168
169 define('WO_LABOUR', 0);
170 define('WO_OVERHEAD', 1);
171 define('WO_MATERIALS', 2);
172
173 //----------------------------------------------------------------------------------
174 //      GL account classes
175 //
176 define('CL_NONE', 0); // for backward compatibility
177 define('CL_ASSETS', 1);
178 define('CL_LIABILITIES', 2);
179 define('CL_EQUITY', 3);
180 define('CL_INCOME', 4);
181 define('CL_COGS', 5);
182 define('CL_EXPENSE', 6);
183
184 function get_class_type_convert($ctype)
185 {
186         global $SysPrefs;
187
188         if (isset($SysPrefs->use_oldstyle_convert) && $SysPrefs->use_oldstyle_convert == 1)
189                 return (($ctype >= CL_INCOME || $ctype == CL_NONE) ? -1 : 1);
190         else    
191                 return ((($ctype >= CL_LIABILITIES && $ctype <= CL_INCOME) || $ctype == CL_NONE) ? -1 : 1);
192 }
193 //----------------------------------------------------------------------------------
194 //      Quick entry types
195 //
196 define('QE_PAYMENT', '1');
197 define('QE_DEPOSIT', '2');
198 define('QE_JOURNAL', '3');
199 define('QE_SUPPINV', '4');
200
201 //----------------------------------------------------------------------------------
202 //      Special option values for various list selectors.
203 //
204 define('ANY_TEXT', '');
205 define('ANY_NUMERIC', -1);
206 define('ALL_TEXT', '');
207 define('ALL_NUMERIC', -1);
208
209 //----------------------------------------------------------------------------------
210 // Special class values for tables (start_table())
211 define('TABLESTYLE',  1);
212 define('TABLESTYLE2', 2);
213 define('TABLESTYLE_NOBORDER', 3);
214
215 //----------------------------------------------------------------------------------
216
217 define('TAG_ACCOUNT',   1);
218 define('TAG_DIMENSION', 2);
219
220 //----------------------------------------------------------------------------------
221 // Payment term types
222
223 define('PTT_PREPAY', 1);
224 define('PTT_CASH', 2);
225 define('PTT_DAYS', 3);
226 define('PTT_FOLLOWING', 4);
227
228 //----------------------------------------------------------------------------------
229 // Tax calculation algorithms used in als and purchase (depends on supplier's invoicing software)
230
231 define('TCA_TOTALS', 1); // taxes are calculated from respective net totals for all lines
232 define('TCA_LINES', 2); // taxes calculated for every line, then summed
233 //
234 //      Bank account owner types
235 //
236 define('BO_UNKNOWN', 0);
237 define('BO_COMPANY', 1);
238 define('BO_CUSTBRANCH', 2);
239 define('BO_SUPPLIER', 3);
240
241 include_once($path_to_root . '/includes/sysnames.inc');
242
243 define('VC_NONE', -1);  // for tax adjustemnts
244 define('VC_OTHER', 0);
245 define('VC_MEDIA', 1);
246 define('VC_ASSETS', 2);
247 define('VC_NONDEDUCT', 3);
248 define('VC_SERVICES', 4);
249 define('VC_REVERSE', 5);
250 define('VC_PARTIAL', 6);
251
252 $vat_categories = array(
253         VC_OTHER => _('Other goods'),
254         VC_MEDIA => _('Continous services'),
255         VC_ASSETS => _('Fixed assets'),
256         VC_NONDEDUCT => _('No VAT deductible'),
257         VC_SERVICES => _('Other services'),
258         VC_PARTIAL => _('VAT partially deductible'),
259         VC_REVERSE => _('Reverse charge'),
260 );
261
262 //
263 // Tax area categories
264 //
265 define('TA_DOMESTIC', 0);
266 define('TA_EXPORT', 1);
267 define('TA_EU', 2);
268
269 $tax_area_types = array(
270         TA_DOMESTIC => _('Domestic'),
271         TA_EXPORT => _('Abroad'),
272         TA_EU => _('European Union'),
273 );
274
275
276 // tax register type
277 define('TR_OUTPUT', 0); // sales
278 define('TR_INPUT', 1);  // purchase
279
280 //
281 //      Depreciation period types
282 //
283 define('FA_MONTHLY', 0);
284 define('FA_YEARLY', 1);
285
286 //---------------------------------------------------------------------------------
287 // Constants optionally redefined locally
288 //
289 defined('ICON_EDIT') || define('ICON_EDIT', 'edit.gif');
290 defined('ICON_DELETE') || define('ICON_DELETE', 'delete.gif');
291 defined('ICON_ADD')     || define('ICON_ADD', 'ok.gif');
292 defined('ICON_UPDATE') || define('ICON_UPDATE', 'ok.gif');
293 defined('ICON_OK') || define('ICON_OK', 'ok.gif');
294 defined('ICON_CANCEL') || define('ICON_CANCEL', 'cancel.png');
295 defined('ICON_GL') || define('ICON_GL', 'gl.png');
296 defined('ICON_PRINT') || define('ICON_PRINT', 'print.png');
297 defined('ICON_PDF') || define('ICON_PDF', 'pdf.gif');
298 defined('ICON_DOC') || define('ICON_DOC', 'invoice.gif');
299 defined('ICON_CREDIT') || define('ICON_CREDIT', 'credit.gif');
300 defined('ICON_RECEIVE') || define('ICON_RECEIVE', 'receive.gif');
301 defined('ICON_DOWN') || define('ICON_DOWN', 'download.gif');
302 defined('ICON_MONEY') || define('ICON_MONEY', 'money.png');
303 defined('ICON_REMOVE') || define('ICON_REMOVE', 'remove.png');
304 defined('ICON_REPORT') || define('ICON_REPORT', 'report.png');
305 defined('ICON_VIEW') || define('ICON_VIEW', 'view.gif');
306 defined('ICON_SUBMIT') || define('ICON_SUBMIT', 'ok.gif');
307 defined('ICON_ESCAPE') || define('ICON_ESCAPE', 'escape.png');
308 defined('ICON_ALLOC') || define('ICON_ALLOC', 'alloc.png');
309 defined('ICON_CLOSED') || define('ICON_CLOSED', 'closed.png');
310