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 ***********************************************************************/
15 define('TAX_NONE', 0); // none option
16 define('TQ_NONE', 0); // none option
18 // implemented taxation options
20 define('TAX_PAYABLE', 1);
21 define('TAX_DEDUCTIBLE', 2);
22 define('TAX_CHARGED', 4);
23 // category depenedent:
24 define('TAX_DUEDATE', 8);
25 define('TAX_PARTIAL', 16);
27 // quirks dependent on vat_categories
28 define('TQ_NONDEDUCT', 1); // never deductible
29 define('TQ_PARTIAL', 2); // partially deductible (using global factor)
30 define('TQ_DUEDATE', 4); // taxable on due date instead of transaction date
31 define('TQ_REVERSE', 8); // tax is reverse charged
32 define('TQ_IMPDEDUCTIBLE', 16); // import tax is deductible
36 //-------------------------- entity taxation rules ----------------------------
37 // general rules: who and when pays taxes
39 // FIXME: credit notes
43 var $ts_category_quirks;
45 function __construct()
47 $this->ts_basic_rules = array(
49 ST_SALESQUOTE => TAX_CHARGED,
50 ST_SALESORDER => TAX_CHARGED,
51 ST_CUSTDELIVERY => TAX_CHARGED,
52 ST_SALESINVOICE => TAX_PAYABLE | TAX_CHARGED,
53 ST_CUSTCREDIT => TAX_PAYABLE | TAX_CHARGED,
54 ST_PURCHORDER => TAX_CHARGED,
55 ST_SUPPRECEIVE => TAX_CHARGED,
56 ST_SUPPINVOICE => TAX_DEDUCTIBLE | TAX_CHARGED,
57 ST_SUPPCREDIT => TAX_DEDUCTIBLE | TAX_CHARGED,
60 ST_SALESQUOTE => TAX_NONE,
61 ST_SALESORDER => TAX_NONE,
62 ST_CUSTDELIVERY => TAX_NONE,
63 ST_SALESINVOICE => TAX_NONE,
64 ST_CUSTCREDIT => TAX_NONE,
65 ST_PURCHORDER => TAX_NONE,
66 ST_SUPPRECEIVE => TAX_NONE,
67 ST_SUPPINVOICE => TAX_NONE,
68 ST_SUPPCREDIT => TAX_NONE,
71 ST_SALESQUOTE => TAX_NONE,
72 ST_SALESORDER => TAX_NONE,
73 ST_CUSTDELIVERY => TAX_NONE,
74 ST_SALESINVOICE => TAX_NONE,
75 ST_CUSTCREDIT => TAX_NONE,
76 ST_PURCHORDER => TAX_NONE,
77 ST_SUPPRECEIVE => TAX_NONE,
78 ST_SUPPINVOICE => TAX_DEDUCTIBLE | TAX_PAYABLE,
79 ST_SUPPCREDIT => TAX_DEDUCTIBLE | TAX_PAYABLE,
83 //-------------------------- special goods dependent rules ----------------------------
85 $this->ts_category_quirks = array(
87 VC_MEDIA => TQ_DUEDATE, // is no longer used ?
88 VC_ASSETS => TQ_NONE, // just separate category in tax reg
89 VC_NONDEDUCT => TQ_NONDEDUCT,
90 VC_SERVICES => TQ_IMPDEDUCTIBLE,
91 VC_PARTIAL => TQ_PARTIAL,
92 VC_REVERSE => TQ_REVERSE,
96 Returns tax options applicable for the arguments set
98 $allow_reverse - decides whether reverse charging option is honoured for sales invoice
99 (this depends on 'continue transaction' value as defined by law, so have to be set by case).
101 function options($trans_type, $tax_area, $vat_category, $allow_reverse=true)
103 if (!isset($vat_category)) // exempt goods has really no category
106 $options = $this->ts_basic_rules[$tax_area][$trans_type];
108 // per vat category quirks
109 $quirks = $this->ts_category_quirks[$vat_category];
111 if ($quirks & TQ_DUEDATE)
112 $options |= TAX_DUEDATE;
114 if ($quirks & TQ_NONDEDUCT)
115 $options &= ~TAX_DEDUCTIBLE;
117 if ($quirks & TQ_PARTIAL)
118 if ($options & TAX_DEDUCTIBLE)
119 $options |= TAX_PARTIAL;
121 if ($quirks & TQ_IMPDEDUCTIBLE)
122 if ($tax_area == TA_EXPORT && in_array($trans_type, array(ST_SUPPINVOICE, ST_SUPPCREDIT)))
124 $options |= TAX_DEDUCTIBLE | TAX_PAYABLE;
127 if (($quirks & TQ_REVERSE) && (!in_array($trans_type,array(ST_SALESINVOICE, ST_CUSTCREDIT)) || $allow_reverse))
128 if ($tax_area == TA_DOMESTIC)
130 $options ^= TAX_PAYABLE;
131 $options &= ~TAX_CHARGED;
138 function dbg_tax($options)
141 TAX_PAYABLE => 'payable',
142 TAX_DEDUCTIBLE => 'deductible',
143 TAX_CHARGED => 'charged',
144 TAX_DUEDATE => 'due_date',
145 TAX_PARTIAL => 'partial'
149 foreach($dbg_rules as $key => $name)
153 _vd(implode($opts, ','));