:- module(payg,[]). en("the target language is: prolog. the templates are: the varied amount payable for *a quarter* by *an entity* is calculated as *an amount*. the estimated tax for *a year* for *an entity* is *an amount*. the year-to-date fraction for *a quarter* is *a fraction*. the year-to-date instalment adjustment for *an entity* at *a quarter* is calculated as *an amount*. the new varied rate for *an entity* for *a year* is *an amount*. the PAYG instalment income for *an entity* for *a year* is *an amount*. the instalment income for *an entity* for *a quarter* of *a year* is *an amount*. applicable tax rate for *an entity* is *a percentage*. *an amount* was reported as an instalment on *a quarter* of the income year. *a value* was reported as a variation on *a quarter* of the income year. *an amount* is a type of business or investment income for *an entity* for *a quarter*. *an amount* is a type of excluded income for *an entity* for *a quarter*. tax was withheld from *an amount* because of no TFN or ABN for *an entity* for *a quarter*. *a thing* is gross rent for *an entity* for *a quarter*. *a thing* is dividends for *an entity* for *a quarter*. *a thing* is royalties for *an entity* for *a quarter*. *a thing* is foreign pensions for *an entity* for *a quarter*. *a thing* is partnership income for *an entity* for *a quarter*. *a thing* is trust income for *an entity* for *a quarter*. *a thing* is foreign income for *an entity* for *a quarter*. *a thing* is interest for *an entity* for *a quarter*. *a thing* is gross sales for *an entity* for *a quarter*. *a thing* is gross fees for services for *an entity* for *a quarter*. *a thing* is withdrawals from farm management deposits for *an entity* for *a quarter*. *a thing* is fuel tax credits for *an entity* for *a quarter*. *a thing* is JobKeeper payments for *an entity* for *a quarter*. *an amount* is a capital gain for *an entity* for *a quarter*. *a thing* is a type of excluded income for *an entity* for *a quarter*. *a thing* is GST for *an entity* for *a quarter*. *a thing* is wine equalisation tax for *an entity* for *a quarter*. *a thing* is luxury car tax for *an entity* for *a quarter*. *a thing* is a type of excluded income for *an entity* for *a quarter*. *a thing* is salary and wages for *an entity* for *a quarter*. an amount was withheld from *a thing* under the PAYG withholding system. *a thing* is a type of excluded income for *an entity* for *a quarter*. *a thing* is a franking credit for *an entity* for *a quarter*. *a thing* is a deemed dividend for *an entity* for *a quarter*. *a thing* is an exempt income for *an entity* for *a quarter*. *a thing* is a payment under the National Rental Affordability Scheme for *an entity* for *a quarter*. *a thing* is a grant under the energy grants credits scheme for *an entity* for *a quarter*. *a thing* is a type of excluded income for *an entity* for *a quarter*. *a thing* is a capital gain for *an entity* for *a quarter*. *a year* is a year under consideration. *an amount* is an ordinary income for *an entity* for *a quarter*. *an amount* is specially included as instalment income for *an entity* for *a quarter*. *a quarter* is previous or equal to *a quarter*. *a quarter* is previous to *a quarter*. *an entity* is the taxpayer. the ontology is: quarter 1 is a quarter. quarter 2 is a quarter. quarter 3 is a quarter. quarter 4 is a quarter. Q1 is a quarter 1. Q2 is a quarter 2. Q3 is a quarter 3. Q4 is a quarter 4. a quarter X is previous or equal to a quarter Y if X is previous to Y or X is equal to Y. quarter 1 is previous to quarter 2. quarter 2 is previous to quarter 3. quarter 3 is previous to quarter 4. Q1 is previous to Q2. Q2 is previous to Q3. Q3 is previous to Q4. the knowledge base payg includes: the varied amount payable for a quarter Q by an entity E is calculated as a value VA if the estimated tax for a year for E is an amount ET and the year-to-date fraction for Q is an fraction F and the year-to-date instalment adjustment for E at Q is calculated as an amount Y and VA = ET * F - Y. the year-to-date fraction for a quarter Q is a fraction F if Q is quarter 1 and F is 0.25 or Q is quarter 2 and F is 0.5 or Q is quarter 3 and F is 0.75 or Q is quarter 4 and F is 1.0. the year-to-date instalment adjustment for an entity E at a quarter Q is calculated as a value V if E is the taxpayer and a value IR is the sum of each amount such that the amount was reported as an instalment on a quarter X of the income year and X is previous or equal to Q and a value IVC is the sum of each value such that the value was reported as a variation on a quarter Y of the income year and Y is previous or equal to Q and V = IR - IVC. the new varied rate for an entity for a year is an amount VR if the estimated tax for the year for the entity is a value ET and the PAYG instalment income for the entity for the year is a value I and I>0 and VR = (ET/I)*100. % instalment income % https://www.ato.gov.au/businesses-and-organisations/income-deductions-and-concessions/payg-instalments/calculate-your-payg-instalments/instalment-income the PAYG instalment income for an entity for a year is a total amount if the entity is the taxpayer and the year is a year under consideration and the total amount is the sum of each partial such that partial is an ordinary income for the entity for a quarter. % --- General Rule --- (as sketched by Gemini and Andrew) % The primary rule states that business/investment income is included, unless it's specifically excluded. an amount is an ordinary income for an entity for a quarter if the amount is a type of business or investment income for the entity for the quarter and it is not the case that the amount is a type of excluded income for the entity for the quarter or the amount is specially included as instalment income for the entity for the quarter. % An exception for income where tax was withheld due to no TFN/ABN. This is always included. an amount is specially included as instalment income for an entity for a quarter if tax was withheld from the amount because of no TFN or ABN for the entity for the quarter. a thing is a type of business or investment income for an entity for a quarter if the thing is gross rent for the entity for the quarter or the thing is dividends for the entity for the quarter or the thing is royalties for the entity for the quarter or the thing is foreign pensions for the entity for the quarter or the thing is partnership income for the entity for the quarter or the thing is trust income for the entity for the quarter or the thing is foreign income for the entity for the quarter or the thing is interest for the entity for the quarter or the thing is gross sales for the entity for the quarter or the thing is gross fees for services for the entity for the quarter or the thing is withdrawals from farm management deposits for the entity for the quarter or the thing is fuel tax credits for the entity for the quarter or the thing is JobKeeper payments for the entity for the quarter. % Capital gains are a special case, only included for super funds. an income is specially included as instalment income for an entity for a quarter if the income is a capital gain for the entity for the quarter and the entity is a super fund. % % --- Specific Exclusions (Types of Excluded Income) --- a thing is a type of excluded income for an entity for a quarter if the thing is GST for the entity for the quarter or the thing is wine equalisation tax for the entity for the quarter or the thing is luxury car tax for the entity for the quarter. a thing is a type of excluded income for an entity for a quarter if the thing is salary and wages for the entity for the quarter and an amount was withheld from the thing under the PAYG withholding system. a thing is a type of excluded income for an entity for a quarter if the thing is a franking credit for the entity for the quarter or the thing is a deemed dividend for the entity for the quarter or the thing is an exempt income for the entity for the quarter or the thing is a payment under the National Rental Affordability Scheme for the entity for the quarter or the thing is a grant under the energy grants credits scheme for the entity for the quarter. % General capital gains are excluded (the super fund rule above is the exception). a thing is a type of excluded income for an entity for a quarter if the thing is a capital gain for the entity for the quarter and it is not the case that the entity is a super fund. scenario test is: 2025 is a year under consideration. Australian entity is the taxpayer. the estimated tax for a year for Australian entity is 8000. applicable tax rate for Australian entity is 0.25. 1000 was reported as an instalment on quarter 4 of the income year. 2000 was reported as a variation on quarter 4 of the income year. scenario harmander is: Harmander is the taxpayer. the estimated tax for 2025 for Harmander is 10125. ordinary income for Harmander for 2025 is 82480. % https://www.ato.gov.au/businesses-and-organisations/income-deductions-and-concessions/payg-instalments/starting-payg-instalments scenario example1 is: Rob is the taxpayer. 2025 is a year under consideration. the estimated tax for 2025 for Rob is 7544. the PAYG instalment income for Rob for 2025 is 49500. scenario example2 is: Danielle is the taxpayer. 2025 is a year under consideration. the estimated tax for 2025 for Danielle is 20437. the PAYG instalment income for Danielle for 2025 is 90000. scenario mine is: me is the taxpayer. 2025 is a year under consideration. the estimated tax for 2025 for me is 16388. the PAYG instalment income for me for 2025 is 80000. scenario alex is: Alex is the taxpayer. 2025 is a year under consideration. 15000 is gross sales for Alex for quarter 1. 5000 is salary and wages for Alex for quarter 1. an amount was withheld from 5000 under the PAYG withholding system. 200 is interest for Alex for quarter 1. 1500 is GST for Alex for quarter 1. 1000 is royalties for Alex for quarter 2. scenario overpaying_test is: overpayer is the taxpayer. 2025 is a year under consideration. the estimated tax for 2025 for overpayer is 10000. 120000 is gross sales for overpayer for quarter 1. 150000 is gross sales for overpayer for quarter 2. the PAYG instalment income for overpayer for 2025 is 100000. 5000 was reported as an instalment on quarter 1 of the income year. 5000 was reported as an instalment on quarter 2 of the income year. scenario underpaying_test is: underpayer is the taxpayer. 2025 is a year under consideration. the estimated tax for 2025 for underpayer is 15000. 180000 is gross sales for underpayer for quarter 1. 200000 is gross sales for underpayer for quarter 2. the PAYG instalment income for underpayer for 2025 is 250000. 2500 was reported as an instalment on quarter 1 of the income year. 2500 was reported as an instalment on quarter 2 of the income year. scenario on_track_test is: on_tracker is the taxpayer. 2025 is a year under consideration. the estimated tax for 2025 for on_tracker is 10000. the PAYG instalment income for on_tracker for 2025 is 200000. 5000 was reported as an instalment on quarter 1 of the income year. 5000 was reported as an instalment on quarter 2 of the income year. query normal is: the varied amount payable for quarter 4 by which entity is calculated as which amount. query rate is: the new varied rate for which entity for 2025 is which amount. query payg is: the PAYG instalment income for which entity for which year is which amount. "). /** ?- show prolog. ?- answer("normal with test"). ?- answer("rate with test"). ?- answer(normal, with(test), le(E), R). ?- answer(rate, with(test), le(E), R). ?- answer(rate, with(example1), le(E), R). ?- answer(rate, with(example2), le(E), R). ?- answer(rate, with(mine), le(E), R). ?- answer(payg, with(alex), le(E), R). ?- answer(payg, with(alex)). ?- answer(rate, with(overpaying_test), le(E), R). ?- answer(normal, with(overpaying_test), le(E), R). */