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 ***********************************************************************/
13 FA tax rules basic reimplementation. Final version would involve changes in database scheme,
14 and/or tax system class selection according to site requirements.
17 . changes in Sales module
18 . change all tax related methods in supp_trans to use split_item_price instead of other functions like get_taxes_for_item
19 . all tax types selections in tax group table (beside domestic group) are currently ignored (see FIXME in split_item_price())
21 define('TAX_NONE', 0); // none option
22 define('TQ_NONE', 0); // none option
24 // implemented taxation options
26 define('TAX_PAYABLE', 1);
27 define('TAX_DEDUCTIBLE', 2);
28 define('TAX_CHARGED', 4);
29 // category depenedent:
30 define('TAX_DUEDATE', 8);
31 define('TAX_PARTIAL', 16);
33 // quirks dependent on vat_categories
34 define('TQ_NONDEDUCT', 1); // never deductible
35 define('TQ_PARTIAL', 2); // partially deductible (using global factor)
36 define('TQ_DUEDATE', 4); // taxable on due date instead of transaction date
37 define('TQ_REVERSE', 8); // tax is reverse charged
38 define('TQ_IMPDEDUCTIBLE', 16); // import tax is deductible
42 //-------------------------- entity taxation rules ----------------------------
43 // general rules: who and when pays taxes
45 // FIXME: credit notes
49 var $ts_category_quirks;
51 function __construct()
53 $this->ts_basic_rules = array(
55 ST_SALESQUOTE => TAX_CHARGED,
56 ST_SALESORDER => TAX_CHARGED,
57 ST_CUSTDELIVERY => TAX_CHARGED,
58 ST_SALESINVOICE => TAX_PAYABLE | TAX_CHARGED,
59 ST_CUSTCREDIT => TAX_PAYABLE | TAX_CHARGED,
60 ST_PURCHORDER => TAX_CHARGED,
61 ST_SUPPRECEIVE => TAX_CHARGED,
62 ST_SUPPINVOICE => TAX_DEDUCTIBLE | TAX_CHARGED,
63 ST_SUPPCREDIT => TAX_DEDUCTIBLE | TAX_CHARGED,
66 ST_SALESQUOTE => TAX_NONE,
67 ST_SALESORDER => TAX_NONE,
68 ST_CUSTDELIVERY => TAX_NONE,
69 ST_SALESINVOICE => TAX_NONE,
70 ST_CUSTCREDIT => TAX_NONE,
71 ST_PURCHORDER => TAX_NONE,
72 ST_SUPPRECEIVE => TAX_NONE,
73 ST_SUPPINVOICE => TAX_NONE,
74 ST_SUPPCREDIT => TAX_NONE,
77 ST_SALESQUOTE => TAX_NONE,
78 ST_SALESORDER => TAX_NONE,
79 ST_CUSTDELIVERY => TAX_NONE,
80 ST_SALESINVOICE => TAX_NONE,
81 ST_CUSTCREDIT => TAX_NONE,
82 ST_PURCHORDER => TAX_NONE,
83 ST_SUPPRECEIVE => TAX_NONE,
84 ST_SUPPINVOICE => TAX_DEDUCTIBLE | TAX_PAYABLE,
85 ST_SUPPCREDIT => TAX_DEDUCTIBLE | TAX_PAYABLE,
89 //-------------------------- special goods dependent rules ----------------------------
91 $this->ts_category_quirks = array(
93 VC_MEDIA => TQ_DUEDATE, // is no longer used ?
94 VC_ASSETS => TQ_NONE, // just separate category in tax reg
95 VC_NONDEDUCT => TQ_NONDEDUCT,
96 VC_SERVICES => TQ_IMPDEDUCTIBLE,
97 VC_PARTIAL => TQ_PARTIAL,
98 VC_REVERSE => TQ_REVERSE,
102 Returns tax options applicable for the arguments set
104 $allow_reverse - decides whether reverse charging option is honoured for sales invoice
105 (this depends on 'continue transaction' value as defined by law, so have to be set by case).
107 function options($trans_type, $tax_area, $vat_category, $allow_reverse=true)
109 if (!isset($vat_category)) // exempt goods has really no category
112 $options = $this->ts_basic_rules[$tax_area][$trans_type];
114 // per vat category quirks
115 $quirks = $this->ts_category_quirks[$vat_category];
117 if ($quirks & TQ_DUEDATE)
118 $options |= TAX_DUEDATE;
120 if ($quirks & TQ_NONDEDUCT)
121 $options &= ~TAX_DEDUCTIBLE;
123 if ($quirks & TQ_PARTIAL)
124 if ($options & TAX_DEDUCTIBLE)
125 $options |= TAX_PARTIAL;
127 if ($quirks & TQ_IMPDEDUCTIBLE)
128 if ($tax_area == TA_EXPORT && in_array($trans_type, array(ST_SUPPINVOICE, ST_SUPPCREDIT)))
130 $options |= TAX_DEDUCTIBLE | TAX_PAYABLE;
133 if (($quirks & TQ_REVERSE) && (!in_array($trans_type,array(ST_SALESINVOICE, ST_CUSTCREDIT)) || $allow_reverse))
134 if ($tax_area == TA_DOMESTIC)
136 $options ^= TAX_PAYABLE;
137 $options &= ~TAX_CHARGED;
144 function dbg_tax($options)
147 TAX_PAYABLE => 'payable',
148 TAX_DEDUCTIBLE => 'deductible',
149 TAX_CHARGED => 'charged',
150 TAX_DUEDATE => 'due_date',
151 TAX_PARTIAL => 'partial'
155 foreach($dbg_rules as $key => $name)
159 _vd(implode($opts, ','));