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