-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathxalgo-notes
More file actions
90 lines (75 loc) · 9.53 KB
/
xalgo-notes
File metadata and controls
90 lines (75 loc) · 9.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
XXXXXXXXXXXXXXXXXXXXXX XALGO NOTES XXXXXXXXXXXXXXXXXXXXXX
THESE ARE OLD NOTES, BUT THEY MIGHT CONTAIN USEFUL ELEMENTS.
FIELD OR SOURCE DESCRIPTION VALUE
/* ABOUT THIS RULE */
RULE_name Quebec, Fuel Tax Act, Border Region Tax Reduction CA-QC_MJQ_RLRQ_T-1_r1_2R3(a)
RULE_id DOI 10.1010101010.0001 /* Adapted from template rule "XYZ". */
RULE_start IssueDate_IssueTime /* ISO 8601 */ >2017-01-01T00:00:00+00:01
RULE_end IssueDate_IssueTime /* ISO 8601 */ <2017-12-31T23:59:59+99:99
RULE_criticality TABLE:RuleCriticality 3
RULE_authorship_id: TABLE:EffectiveUsers /* SovrinID */ GTksmVZaSJVMWkP
RULE_responsibility_id TABLE:EffectiveUsers /* SovrinID */ 54JGpXKSaSOjQVN
/* THIS RULE REQUIRES THE FOLLOWING CONTEXT DATA FROM A UBL ORDER OR INVOICE (put each in a temporary parameter field to serve as a key) */
TRANSACTION_WHEN DocumentType =[Order OR Invoice] RETURN DocumentType /* This rule ONLY applies to these two types of documents in UBL ISO/IEC 19845:2015 */
TRANSACTION_WHEN IssueDate_IssueTime =[?] RETURN IssueDate_IssueTime /* ISO 8601 e.g. 2017-08-17T11:32:53+31:99 */
TRANSACTION_WHO SellerSupplierParty =[?] RETURN SellerSupplierParty /* Possibly not be a unique name, needs EffectiveUserID */
TABLE_LOOKUP /* to get WHERE */ TABLE:CA-QC_MJQ_RLRQ_T-1_r1_2R3(a)_DistanceRegister
USE field:SellerSupplierParty =[?] RETURN EffectiveUserID /* SovrinID e.g. earqiEh6gbxf1mM */
/* THIS RULE OBTAINS THE FOLLOWING ITEM DATA VIA AN ITEM TRAVERSAL OF THE UBL ORDER OR INVOICE (put each in a temporary parameter field to serve as a value) */
TRANSACTION_WHAT USE InvoiceLine OR OrderLine =[506505] RETURN ItemClassificationCode /* string, UNSPSC coder for "Gasoline and Petrol" */ This value is required for rule matching. The remaining in this section are required for calculation, not rule matching.
TRANSACTION_WHAT USE InvoiceLine OR OrderLine =[?] RETURN InvoicedQuantity AS "quantity" /* numeric e.g. 6 */
TRANSACTION_WHAT USE InvoiceLine OR OrderLine =[litres] RETURN BaseUnitMeasure AS "unit" /* string e.g. litres, gallons */ Need mechanism to convert, or needs to be part of calculation function - so if the value here is US gallon, need to multiply by 3.8. Or only allow a value of litres, in which case a different rule would match if the value here is gallons
/* REFERENCE TABLE RELATIONSHIPS (put in a temporary parameter field to serve as a value) */
TABLE_LOOKUP TABLE:CA-QC_MJQ_RLRQ_T-1_r1_2R3(a)_DistanceRegister
USE field:Seller_EffectiveUserID =[?] RETURN 2R3(a)_ Distance /* e.g. km */
EXPAND parameter field with a value for "distance"
TABLE_LOOKUP TABLE:CA-QC_MJQ_RLRQ_T-1_r1_2R3(a)_ReductionPerLitre
USE field:distance_2R3(a) =[?] RETURN _2R3(a)_ReductionPerLitre AS "variable" /* currency e.g. $0.04 */
EXPAND parameter field with a value for "variable"
/* ACTIONS */
COMPUTE Quebec, Fuel Tax Act, Border Region Tax Reduction Amount quantity*variable = "amount" /* currency e.g. $3.20 */
=[?] RETURN [RULE_name] amount is "amount"
XXXXXXXXXXXXXXXX DATA REFERENCE TABLES XXXXXXXXXXXXXXXXXXXXXX
Note: The first four tables below are needed by the Quebec, Fuel Tax Act, Border Region Tax Reduction
TABLE:RuleCriticality
RuleCriticalityID RuleCriticality RuleCriticalityMeaning
"1" imperative must always be active
"2" business must be active to uptime guaranteed tolerances
"3" experimental may be deactivated to support business and imperative requirements
TABLE:EffectiveUsers
EffectiveUserID EffectiveUserCommunicationsChannel EffectiveUserCommunicationsString
qJUgMVukff0YZfC sms 011-1-819-593-5983
t079WCDPL2Y4ACy email jpotvin@opman.ca
oF9TDiUzrponyhj twitter @jrpotvin
VJh82YU76Uyfceq [etc] [etc]
GTksmVZaSJVMWkP
us5uQgVJD5UFOQH
QRpOeZ7UXni9In5
54JGpXKSaSOjQVN
earqiEh6gbxf1mM
T9XxzFbpxvBEzRx
TABLE:CA-QC_MJQ_RLRQ_T-1_r1_2R3(a)_DistanceRegister
2R3(a)_Distance SellerSupplierParty (gas stations) EffectiveUserID
16.1 l'Essence Chez Bob us5uQgVJD5UFOQH
11.3 Ultramar #122 QRpOeZ7UXni9In5
2.7 Canadien Tire, Le Plateau 54JGpXKSaSOjQVN
5.3 Shell 392271 earqiEh6gbxf1mM
19.9 PetroCanada-Franchise31 T9XxzFbpxvBEzRx
3.3 Esso 428 Maloney, Gatineau XapDFDwg0w6taRQ
13.8 Depanneur Chelsea Y9Rrpsi9t4zaAEq
19.8 Pioneer 2688 St Joseph kUlkUY3JzpyHKEj
1.3 Hetco @ Gréber & Saint-Louis fScl51V5VE0ZBpE
16.6 Couche-Tard (Vanier & Allumettières) cuzXbCvmQruHaD4
/* Assume http://www.aquip-petrole.com/ hosts an app for managers of gas stations to register to have Lichen automate the gas tax reduction. Their registration app publishes the table to the Internet of Rules. */
Why would you want to have this table? Some sort of authorative source of truth? Otherwise, the proprieter could just supply a location code in the invoice... But, that doesn't answer why there's a table supplied by "someone" or "some agency". That might be considered "where the transaction" took place, not where the property IS...
The problem is, the legislation is not based on location per se, but on distance by a common route (I can't locate the detailed tax interpretation at this time). So it is too complex to be determined by the algorithm from knowing an OLC (Open Location Code) -- the rule could use the GoogleMaps API or similar GPS service, but for now I think that's too much work for "the rule author". Therefore the IoR must leave this matter in the hands of the rule owner and/or in the hands of the rule beneficiary to sort out. (Also, if the gas station owners listing their distance 'exaggerate', that can be deemed tax fraud. That's for them and the province to deal with, not the rule author or the IoR.) My working solution is to imagine gas stations registering for this tax reduction -- they probably have to anyways otherwise their numbers would look wrong to the tax authorities.
Who maintains the table? See http://www.aquip-petrole.com/ It could be them, as the industry association, or the Gov Quebec. Both approaches would make sense.
TABLE:CA-QC_MJQ_RLRQ_T-1_r1_2R3(a)_ReductionPerLitre
≥2R3(a)_ Distance 2R3(a)_ReductionPerLitre /* to populate "variable" parameter */
20 -0.00
15 -0.02
10 -0.04
5 -0.06
0 -0.08
/* Source: Ministry of Justice, Québec (MJQ), Consolidated Regulations of Québec (RLRQ), chapter T-1, r. 1
“Regulation respecting the application of the Fuel Tax Act”, Section 2R3(a), http://legisquebec.gouv.qc.ca/fr/ShowDoc/cr/T-1,%20r.%201 */