1use time::weeks_in_year;
18
19#[allow(clippy::too_many_arguments)]
20pub fn annual_taxable_income(p: isize, i: isize, f: isize, f2: isize, f5a: isize, u1: isize, hd: isize, f1: isize) -> isize {
21 (p * (i - f - f2 - f5a - u1)) - hd - f1
22}
23
24#[allow(clippy::too_many_arguments)]
25pub fn annual_taxable_income_commission(i1: isize, f: isize, f2: isize, f5a: isize, u1: isize, hd: isize, f1: isize, e: isize) -> isize {
26 i1 - f - f2 - f5a - u1 - hd - f1 - e
27}
28
29pub fn pay_periods(period: &str, custom: Option<u16>) -> u16 {
30 const YEAR: i32 = 2024;
31 match period {
32 "Weekly"=>weeks_in_year(YEAR) as u16,
33 "Biweekly"=>(weeks_in_year(YEAR) as f32 / 2.0).round() as u16,
34 "Semi-monthly"=>24,
35 "Monthly"=>12,
36 _=> custom.unwrap_or(1)
37 }
38}
39
40pub fn glossary(factor: &str) -> &str {
42 match factor {
43 "A"=> "Annual taxable income",
44 "B"=> "Gross bonus, retroactive pay increase, vacation pay when vacation is not taken, accumulated overtime payment or other non-periodic payment",
45 "B1"=> "Gross bonuses, retroactive pay increases, vacation pay when vacation is not taken, accumulated overtime payments or other non-periodic payments year-to-date (before the pay period)",
46 "BPAF"=> "Federal Basic Personal Amount",
47 "BPANS"=> "Basic Personal Amount for Nova Scotia",
48 "BPAYT"=> "Basic Personal Amount for Yukon",
49 "C"=> "Canada (or Quebec) Pension Plan contributions for the pay period",
50 "C2"=> "Second additional Canada (or Quebec) Pension Plan contributions for the pay period",
51 "CEA"=> "Canada Employment Amount, a non-refundable tax credit used in the calculation for K4 and K4P",
52 "D"=> "Employee’s year-to-date (before the pay period) Canada Pension Plan contribution with the employer",
53 "DQ"=> "Employee’s year-to-date (before the pay period) Quebec Pension Plan contribution with the employer",
54 "D1"=> "Employee’s year-to-date (before the pay period) employment insurance premium with the employer",
55 "D2"=> "Employee’s year-to-date (before the pay period) second additional Canada Pension Plan contribution with the employer",
56 "D2Q"=> "Employee’s year-to-date (before the pay period) second additional Quebec Pension Plan contribution with the employer ",
57 "E"=> "Total commission expenses deductions reported on Form TD1X",
58 "EI"=> "Employment insurance premiums for the pay period",
59 "F"=> "Payroll deductions for the pay period for employee contributions to a registered pension plan (RPP) for current and past services, a registered retirement savings plan (RRSP), to a pooled registered pension plan (PRPP), or a retirement compensation arrangement (RCA). For tax deduction purposes, employers can deduct amounts contributed to an RPP, RRSP, PRPP, or RCA by or on behalf of an employee to determine the employee's taxable income",
60 "F1"=> "Annual deductions such as child care expenses and support payments requested by an employee or pensioner and authorized by a tax services office or tax centre",
61 "F2"=> "Alimony or maintenance payments required by a legal document dated before May 1, 1997, to be payroll-deducted authorized by a tax services office or tax centre",
62 "F3"=> "Employee registered pension plan or registered retirement savings plan contributions deducted from the current non-periodic payment. You can also use this field or design another to apply other tax-deductible amounts to the non-periodic payment, such as union dues",
63 "F4"=> "Employee registered pension plan or registered retirement savings plan contributions deducted from the year-to-date non-periodic payments. You can also use this field or design another to apply other tax-deductible amounts to the non-periodic payment, such as union dues",
64 "F5"=> "Deductions for Canada Pension Plan additional contributions for the pay period",
65 "F5A"=> "Deductions for Canada (or Quebec) Pension Plan additional contributions for the pay period deducted from the periodic income",
66 "F5B"=> "Deductions for Canada (or Quebec) Pension Plan additional contributions for the pay period deducted from the non-periodic payment",
67 "F5Q"=> "Deductions for Quebec Pension Plan additional contributions for the pay period",
68 "G"=> "Gross commission amount including gross salary at the time of payment, plus any taxable benefits for commission-remunerated employees who have filled out Form TD1X. When an employee has not filed Form TD1X, tax is calculated the regular way",
69 "HD"=> "Annual deduction for living in a prescribed zone, as shown on Form TD1",
70 "I"=> "Gross remuneration for the pay period. This includes overtime earned and paid in the same pay period, pension income, qualified pension income, and taxable benefits, but does not include bonuses, retroactive pay increases, or other non-periodic payments",
71 "I1"=> "Total remuneration for the year reported on Form TD1X. This includes commission payments, salary (where applicable), non-periodic payments, and taxable benefits",
72 "IE"=> "Insurable earnings for the pay period including insurable taxable benefits, bonuses, and retroactive pay increases",
73 "K"=> "Federal constant. The constant is the tax overcharged when applying the 20.5%, 26%, 29%, and 33% rates to the annual taxable income A",
74 "KP"=> "Provincial or territorial constant",
75 "K1"=> "Federal non-refundable personal tax credit (the lowest federal tax rate is used to calculate this credit)",
76 "K1P"=> "Provincial or territorial non-refundable personal tax credit (the lowest tax rate of the province or territory is used to calculate this credit)",
77 "K2"=> "Base Canada Pension Plan contributions and employment insurance premiums federal tax credits for the year (the lowest federal tax rate is used to calculate this credit). Note: If an employee has already contributed the maximum CPP and EI, for the year with the employer, use the maximum base CPP contribution and the maximum EI premium to calculate the credit for the rest of the year. If, during the pay period in which the employee reaches the maximum, the CPP and EI, when annualized, is less than the annual maximum, use the maximum base CPP contribution and the maximum EI premium in that pay period",
78 "K2P"=> "Provincial or territorial base Canada Pension Plan contributions and employment insurance premiums tax credits for the year (the lowest provincial or territorial tax rate is used to calculate this credit). If an employee reaches the maximum CPP or EI for the year with an employer, the instructions in the note for the K2 factor also apply to the K2P factor. For employees paid by commission, use the federal K2 formula for commissions and replace the lowest federal rate in the K2 formula with the lowest provincial or territorial tax rate",
79 "K2Q"=> "Base Quebec Pension Plan contributions, employment insurance premiums, and Quebec Parental Insurance Plan premiums federal tax credits for the year (the lowest federal tax rate is used to calculate this credit)",
80 "K2R"=> "Base Canada Pension Plan contributions and employment insurance premiums tax credits for the year (the lowest federal tax rate is used to calculate this credit), for employees that are transferred from Quebec to a location outside Quebec. The term “location outside Quebec” refers to a province or territory outside Quebec",
81 "K2RQ"=> "Base Quebec Pension Plan contributions, employment insurance premiums, and Quebec Parental Insurance Plan premiums federal tax credits for the year (the lowest federal tax rate is used to calculate this credit), for employees that are transferred to Quebec from a location outside Quebec. The term “location outside Quebec” refers to a province or territory outside Quebec",
82 "K3"=> "Other federal non-refundable tax credits (such as medical expenses and charitable donations) authorized by a tax services office or tax centre",
83 "K3P"=> " Other provincial or territorial non-refundable tax credits (such as medical expenses and charitable donations) authorized by a tax services office or tax centre",
84 "K4"=> " Federal non-refundable tax credit calculated using the Canada employment amount (the lowest federal tax rate is used to calculate this credit)",
85 "K4P"=> "Territorial non-refundable tax credit calculated using the provincial or territorial Canada employment amount (the lowest territorial tax rate is used to calculate this credit)",
86 "L"=> "Additional tax deductions for the pay period requested by the employee or pensioner as shown on Form TD1",
87 "LCF"=> "Federal labour-sponsored funds tax credit",
88 "LCP"=> "Provincial or territorial labour-sponsored funds tax credit",
89 "M"=> "Accumulated federal and provincial or territorial tax deductions (if any) to the end of the last pay period",
90 "M1"=> "Year-to-date tax deducted on all payments included in B1",
91 "N"=> "The number of days in the current year since the last payment. The minimum basic exemption amount of $67.30 is included in the formula in line with CPP legislation",
92 "NI"=> "Net income for the year from the employer",
93 "P"=> "The number of pay periods in the year",
94 "PI"=> "Pensionable earnings for the pay period, or the gross income plus any taxable benefits for the pay period, including bonuses and retroactive pay increases where applicable",
95 "PM"=> "The total number of months during which CPP and/or QPP contributions are required to be deducted (used in the proration of maximum contribution). For detailed information and examples, refer to T4001 Employers’ Guide – Payroll Deductions and Remittances.",
96 "PR"=> "The number of pay periods left in the year (including the current pay period)",
97 "R"=> "Federal tax rate that applies to the annual taxable income A",
98 "S"=> "Provincial tax reduction (only applies to Ontario and British Columbia)",
99 "S1"=> "Annualizing factor",
100 "S2"=> "Basic amount used in the calculation of Factor S (only applies to Ontario and British Columbia)",
101 "T"=> "Estimated federal and provincial or territorial tax deductions for the pay period",
102 "T1"=> "Annual federal tax deduction",
103 "T2"=> "Annual provincial or territorial tax deduction (except Quebec)",
104 "T3"=> "Annual basic federal tax",
105 "T4"=> "Annual basic provincial or territorial tax",
106 "TB"=> "Tax deductions, i.e., bonuses or retroactive pay increases, payable now",
107 "TC"=> "\"Total claim amount,\" reported on federal Form TD1. If Form TD1 is not filed by the employee or pensioner, calculate TC using BPAF formula, and for non-resident individuals, TC is $0. If the claim code is E, T = $0. If the province is Ontario, even if the claim code is E, the Ontario Health Premium is payable on annual income over $20,000",
108 "TCP"=> "\"Total claim amount,\" reported on the provincial or territorial Form TD1. If this form is not filed, TCP is the provincial or territorial basic personal amount, refer to Table 8.2. For Nova Scotia and Yukon, use BPANS and BPAYT formulas respectively.",
109 "U1"=> "Union dues for the pay period paid to a trade union, an association of public servants, or dues required under the law of a province to a parity or advisory committee or similar body",
110 "V"=> "Provincial or territorial tax rate for the year (does not apply to Quebec, outside Canada, or in Canada beyond the limits of any province or territory)",
111 "V1"=> "Provincial surtax calculated on the basic provincial tax (only applies to Ontario)",
112 "V2"=> "Additional tax calculated on taxable income (only applies to the Ontario Health Premium)",
113 "W"=> "The greater of year-to-date (before the pay period) pensionable earnings (PIYTD or GYTD) and employee’s Year’s Maximum Pensionable Earnings (YMPE). This is used to calculate Factor C2",
114 "Y"=> "Additional provincial tax reduction amount based on the number of eligible dependents used in the calculation of Factor S (only applies to Ontario)",
115 "YAMPE"=> "Year’s Additional Maximum Pensionable Earnings",
116 "YMPE"=> "Year’s Maximum Pensionable Earnings",
117 "YTD"=> "Year-to-date, not including current pay period",
118 _=> "Invalid factor provided. See https://www.canada.ca/en/revenue-agency/services/forms-publications/payroll/t4127-payroll-deductions-formulas/t4127-jan/t4127-jan-payroll-deductions-formulas-computer-programs.html#toc30 for more details."
119 }
120}