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