diff --git a/docs/rule-decisions.md b/docs/rule-decisions.md index 60e83638..a7cdb331 100644 --- a/docs/rule-decisions.md +++ b/docs/rule-decisions.md @@ -190,6 +190,7 @@ A row that names a pull request is in the code of that branch until it merges. | A145 | 2026-11-27 | Form 8908 / Form 3800 | Form 8908 gives a homebuilder a credit for each new energy efficient home sold or leased; line 7 adds the same credit passed through on partnership and S corporation K-1s (code AM). With K-1s that show cents, is each K-1 rounded before the add, or only the total? | Form 1040 instructions: "include cents when adding the amounts and round off only the total" (`irs-1040-inst-2025::sec::rounding-off-to-whole::b01`). | Line 8 goes to Form 3800 line 1p (`irs-8908-face-2025::sec::face-page-2::b01`), whose Part V lists each pass-through entity's credit by its EIN, one whole-dollar amount each (`irs-3800-inst-2025::sec::part-v-3::b01`). | Text B, the same rule as row A96 (Form 8846 line 5) and Form 8826 line 7: each K-1 rounds first, so line 8 equals Form 3800 line 1p. | At most $1 for each K-1. | `federal/8908/resolveInfo.ts` | Silent: the statute sets no rounding. | | A146 | 2026-11-27 | Form 8908 | Items A to C ask, for each home the builder claims, whether the builder built it, had a basis in it and had it certified before the sale. One of several homes answers No. Is the credit lost for every home, or only for that one? | The items: "For each home for which you are claiming the credit, ..." (`irs-8908-inst-2025::sec::specific-instructions::b01`). | The form: "If you answered 'No' to question A, B, or C, STOP, you cannot claim the credit" (`irs-8908-face-2025::sec::face-page-1::b02`). | Text A: a home that answers No is not claimed, and the items show Yes for the homes that are. The form stops only when no home is left. The credit is "for each qualified new energy efficient home" (`irs-8908-inst-2025::sec::purpose-of-form::b01`), so one home that fails does not take the others' credit away. | Yes: in the made-up taxpayer `edelle`, a house that was not certified in time loses its $2,500, not the whole $20,000. | `federal/8908/resolveInfo.ts` | 45L(a)(1): supports. The credit is "the applicable amount for each qualified new energy efficient home". | | A147 | 2026-11-28 | FTB 3503 / Schedule P (540) | FTB 3503 gives a California credit of 55% of the value of land given with the Wildlife Conservation Board's approval. On Schedule P (540) it is one of the Section B2 credits that share the tax left, one after another. Where does it go in that order? | Section B2: "Generally, it is to your advantage to apply credits with limited carryovers before credits with no limitation on carryover. However, you may apply credits with no limitation on carryover first, if that is to your advantage" (`ca-540-sched-p-inst-2025::sec::section-b2-instructions::b01`). | FTB 3503: a credit from 2015 on carries over "15 years or until exhausted" (`ca-3503-form-2025::sec::f-carryover::b01`); the low-income housing credit is "required to be applied after any business credits are applied" (`ca-540-sched-p-inst-2025::sec::how-to-compute-the-limitation::b01`); the enterprise zone and TTA carryovers have 10 years (A90 to A92). | After the motion picture, enterprise zone and TTA credits, before the research, orphan drug and low-income housing credits: a limited carryover goes before an unlimited one, and the longer 15-year carryover after the 10-year ones. One order for every return. | None in the made-up taxpayer `kari` (one credit). Only when the tax left cannot cover all: with a $10,000 TTA carryover, $20,000 of this credit and $25,000 of tax, the TTA credit takes $10,000 and this credit $15,000 (the other order: $20,000 and $5,000). | `state/ca/3503/creditUsed.ts` | Silent on the order. R&TC 17053.30(d)(2) sets the 15-year carryover (`ca-rtc-2025::sec::s17053.30::d`). | +| A148 | 2026-11-28 | FTB 3547, Schedule P (540) | FTB 3547 gives a business that hauls donated food to a charity a California credit of half the transport costs (code 204); it offsets tax in Schedule P (540) Section A2, next to FTB 3541's motion picture credits and FTB 3807's LAMBRA credit. In what order are they used? | Section A2: "complete column (a) through column (d) for each credit in each section before going to the next section" (`ca-540-sched-p-inst-2025::sec::section-a2-instructions::b01`): no order inside the section. | Section B2's general rule, credits "with limited carryovers before credits with no limitation" (`::section-b2-instructions::b01`): this credit carries over "until exhausted" (`ca-3547-form-2025::sec::g-carryover::b01`), the film (A75) and LAMBRA (A82) credits for 9 and 10 years. | Text B: code 204 takes the line after the film and LAMBRA credits. One order for every return. | Only when the tax over TMT cannot cover every Section A2 credit; the part of code 204 not used carries over with no limit. In `padan` it is the only Section A2 credit. | `state/ca/3547/creditUsed.ts` | Not in the library: California law. R&TC 17053.12(d) (`ca-rtc-2025::sec::s17053.12::d`): the carryover runs "until the credit has been exhausted". | The last column names the subdivision read in the law library. Rows A33 to A57 were added after the check, so their last column is the author's note, not a read of the statute. On the day of the check the library held the statute only (the regulations were added after it): no regulations, no California law, and no statutory notes, so no effective date was checked. Row 12 was marked for research; section 55(b)(1)(A) settles it: the tentative minimum tax "shall be reduced by the alternative minimum tax foreign tax credit". diff --git a/engine/src/facts/index.ts b/engine/src/facts/index.ts index 89343626..59a25736 100644 --- a/engine/src/facts/index.ts +++ b/engine/src/facts/index.ts @@ -14,6 +14,7 @@ export * from "./kinds/blindness.js"; export * from "./kinds/business.js"; export * from "./kinds/businessLossLimit.js"; export * from "./kinds/businessPropertySale.js"; +export * from "./kinds/caAgTransport.js"; export * from "./kinds/caAmtCaliforniaAmounts.js"; export * from "./kinds/caCaliforniaAmounts.js"; export * from "./kinds/caChildUnearnedIncome.js"; diff --git a/engine/src/facts/kinds/caAgTransport.ts b/engine/src/facts/kinds/caAgTransport.ts new file mode 100644 index 00000000..a008dac1 --- /dev/null +++ b/engine/src/facts/kinds/caAgTransport.ts @@ -0,0 +1,103 @@ +/* + * FTB 3547, the donated agricultural products transportation credit: 50% of + * the costs of transporting agricultural products donated to a nonprofit + * charitable organization (ca-3547-form-2025::sec::b-description::b01), for a + * taxpayer "engaged in the business of processing, distributing, or selling + * agricultural products" (::c-qualifications::b01). The donee gives the + * taxpayer a certificate, which the taxpayer keeps (::c-qualifications::b01), + * so no document comes with it: the taxpayer states the costs from the trip + * records and the certificate. + * + * Three inputs: the taxpayer's own transportation costs (line 1), one fact per + * entity that passed a credit through on a Schedule K-1 (100S, 541, 565 or + * 568) (line 3), and last year's carryover (line 5). The California K-1 + * itself is not in the engine: the credit is stated as the K-1 prints it. + */ + +type FactRow = { key: string; value: unknown; category: string }; + +/* + * "You may determine eligible transportation costs in either of the following + * ways: $.14 (fourteen cents) per mile; The actual transportation expenses" + * (ca-3547-form-2025::sec::d-definitions::b01). + */ +export type CaAgTransportMethod = "mileage" | "actual"; + +/* + * Where the federal return deducted the same costs: "Any deduction allowed for + * these same costs must be reduced by the amount of credit figured" + * (ca-3547-form-2025::sec::d-definitions::b04). A business expense on + * Schedule C or Schedule F, or no deduction at all. + */ +export type CaAgTransportDeductedOn = "schedule_c" | "schedule_f" | "not_deducted"; + +/* Line 1 (ca-3547-form-2025::sec::line-1::b01). */ +export interface CaAgTransportCostsFactValue { + method: CaAgTransportMethod; + /* + * Mileage method: "the total miles connected with transporting the donated + * agricultural product" (::line-1::b01), the taxpayer's share when the trips + * were shared. 0 when none. + */ + miles?: number; + /* + * Actual method: the transportation costs paid or incurred, with parking + * fees and tolls, without depreciation and insurance (::d-definitions::b01); + * the taxpayer's share "in proportion to their respective share of the + * expenses paid or incurred" (::line-1::b01). + */ + actualCosts?: number; + deductedOn: CaAgTransportDeductedOn; + /* + * The costs were paid by a single member LLC that is disregarded for tax + * purposes. The credit's use is then limited to the tax on that LLC's income + * (::d-definitions::b03), which the engine does not figure. Absent: the + * taxpayer paid them directly. + */ + throughDisregardedSmllc?: boolean; +} + +/* Line 3: one entity's pass-through credit (ca-3547-form-2025::sec::line-3-pass-through-donated-agricultural-products-transportation::b01). */ +export interface CaAgTransportPassThroughFactValue { + /* The entity's name, for the schedule the line asks for. */ + entityName: string; + /* The entity's identification number. */ + entityId: string; + /* The credit as the Schedule K-1 (100S, 541, 565 or 568) reports it. */ + credit: number; +} + +export interface CaAgTransportPassThroughFact { + key: string; + value: CaAgTransportPassThroughFactValue; +} + +export const CA_AG_TRANSPORT_KEYS = { + /* Line 1: a CaAgTransportCostsFactValue. */ + costs: "ca_ag_transport.costs", + /* Line 5: the 2024 FTB 3547 line 8, "Credit carryover from a prior year" (the form). A number; 0 when none. */ + carryover: "prior_year.ca_ag_transport_credit_carryover", +} as const; + +const PASS_THROUGH_CATEGORY = "state_local_tax"; +const PASS_THROUGH_PREFIX = "ca_ag_transport_pass_through."; + +export function makeCaAgTransportPassThroughFactKey(entitySlug: string): string { + return `${PASS_THROUGH_PREFIX}${entitySlug}`; +} + +export function isCaAgTransportPassThroughFactKey(key: string): boolean { + const parts = key.split("."); + return parts.length === 2 && `${parts[0]}.` === PASS_THROUGH_PREFIX && parts[1] !== ""; +} + +/* Every pass-through credit fact, in the order recorded. */ +export function getCaAgTransportPassThroughFacts( + facts: ReadonlyArray, +): CaAgTransportPassThroughFact[] { + return facts + .filter( + (row) => row.category === PASS_THROUGH_CATEGORY && isCaAgTransportPassThroughFactKey(row.key), + ) + .map((row) => ({ key: row.key, value: row.value as CaAgTransportPassThroughFactValue })); +} diff --git a/engine/src/state/ca/3547/QUESTIONS.md b/engine/src/state/ca/3547/QUESTIONS.md new file mode 100644 index 00000000..1a00db2b --- /dev/null +++ b/engine/src/state/ca/3547/QUESTIONS.md @@ -0,0 +1,122 @@ +# FTB 3547 — open questions + +The 2025 form and its instructions (`ca-3547-form-2025`) have no example with +numbers, and no FTB publication has one. The rules were written from the form, +its instructions, Schedule P (540) (`ca-540-sched-p-inst-2025`) and R&TC +section 17053.12 (`ca-rtc-2025::sec::s17053.12`). The made-up taxpayers +`padan` (actual costs, a K-1 credit, a carryover, a credit limited by the tax, +Schedule CA lines 3 and 5) and `jori` (the mileage method, Schedule F, the +credit used in full, Schedule CA line 6, Schedule S line 2 net of the credit) +are the scenarios. + +## Two texts conflict + +Each is decided by the author, with a `DECISION` comment and a row in `docs/rule-decisions.md`. + +### 1. The order inside Schedule P (540) Section A2 + +- Text A: "complete column (a) through column (d) for each credit in each section before going to the next section" (`ca-540-sched-p-inst-2025::sec::section-a2-instructions::b01`): no order inside a section. +- Text B: "Generally, it is to your advantage to apply credits with limited carryovers before credits with no limitation on carryover" (`::section-b2-instructions::b01`). +- Done: code 204 takes the line after FTB 3541's original and new credits and FTB 3807's LAMBRA credit. This credit's carryover has no limit ("until exhausted", `ca-3547-form-2025::sec::g-carryover::b01`); theirs are limited to 9 and 10 years. The `DECISION` comment is above `agTransportScheduleLine` in `creditUsed.ts`. +- Dollars: only when the tax over TMT cannot cover every Section A2 credit; the part of code 204 not used then carries over with no limit. + +## Should we do this now + +Doubts with no conflicting text, the named gaps and the review's coverage +points. Each says "Done" or why not now. + +### 2. Which deduction line 2 and line 3 reduce + +- Source: "This credit is taken in lieu of any deduction otherwise allowable for the same eligible transportation costs. Any deduction allowed for these same costs must be reduced by the amount of credit figured for the current taxable year (the amount shown on line 4)" (`ca-3547-form-2025::sec::d-definitions::b04`). +- Done: federal law has no such credit, so the federal deduction stays whole and the California deduction is smaller: a Schedule CA (540) column C addition. Line 2 (the taxpayer's own costs) goes on line 3 when the costs were deducted on Schedule C, line 6 when on Schedule F, nowhere when they were not deducted (the costs fact says which). Line 3 (the K-1 credits) goes on line 5: the entity reduced its own deduction, and the engine reads the federal K-1 amounts, so the California difference is the partner's share of the credit. Together they are line 4, the amount the instructions name. +- Doubt: line 5 assumes the K-1 credit and the K-1 deduction are shared in the same proportion. A partnership with a special allocation could differ. The engine has no California K-1 amounts to check it. +- Doubt: the reduction never exceeds the deduction it reduces. The engine takes the stated deduction to be at least the credit; it does not compare the credit with the Schedule C or F line. With the mileage method the credit uses $.14 a mile while the deduction is the fuel or the standard mileage amount, so the two are not the same figure; the engine reduces by line 2 and does not cap it. +- Doubt: the amount. FTB Pub. 1001 says "Under California law, deductions are not allowed for the portion of expenses equal to the credit" (`ftb-pub-1001-2025::sec::alternative-depreciation::b15`), which agrees with line 4. Its "what to do" column says to enter "the portion of the deduction claimed on your federal return that was used to claim the California credit" (`ftb-pub-1001-2025::sec::enter-on-schedule-ca-540-part-i-or-7::b01`), which could be read as the whole deducted cost (for example $14,800 of costs instead of a $7,400 credit). The engine follows the form's own instructions (line 4); the publication's first sentence says the same. +- Doubt: the K-1 part. Another reading is that a California entity already reduced its own deduction on its California K-1, so line 5 column C takes nothing for line 3. The engine reads the federal K-1 amounts, so it adds line 3 on line 5. That reading would change line 5 column C to blank when a K-1 credit is present. +- Dollars: yes, the whole column C amount (padan: $8,550 of California AGI). + +### 3. The credit figured, or the credit used + +- Source: the instructions name "the amount of credit figured for the current taxable year (the amount shown on line 4)" (`::d-definitions::b04`). The statute: "any deduction otherwise allowed under this part for that amount of the cost paid or incurred by the taxpayer which is eligible for the credit that is claimed shall be reduced by the amount of the credit allowed" (`ca-rtc-2025::sec::s17053.12::b`). +- Done: line 4, the credit figured, as the instructions say. "Allowed" could be read as the credit used this year (line 7a), which is smaller when the tax limits the credit. +- Dollars: yes, when line 7a is less than line 4. In `padan` the reduction is $8,550; with the credit used it would be at most $5,372. +- For `docs/law-findings.md`: the instruction (`ca-3547-form-2025::sec::d-definitions::b04`) and R&TC 17053.12(b) (`ca-rtc-2025::sec::s17053.12::b`). + +### 4. Line 1: the taxpayer's share and the rounding + +- Source: "If two or more taxpayers share in the expenses eligible for the credit, each taxpayer shall be eligible to receive the tax credit in proportion to their respective share of the expenses paid or incurred" and "multiply the total miles ... by $.14" (`::line-1::b01`). +- Done: the costs fact holds the taxpayer's own share, as miles or as dollars. The mileage method rounds miles × $.14 to the nearest dollar; line 2 is half of the whole-dollar line 1, rounded (1,295 × 50% = $648 in `jori`). +- Dollars: at most $1. + +### 5. Line 7c and the $5,000,000 limit + +- Source: line 7c is the credit "that would have otherwise been available to reduce tax in this tax year but for the $5,000,000 credit limitation" (`::line-7c::b01`). +- Done: with Form 540 line 35 at $5,000,000 or less the credits cannot reduce the net tax by more than $5,000,000, so line 7c is 0. Above it the credit offered, line 7a, line 7c and line 8 are a gap: the limit runs across every business credit of Part III, and the engine does not figure it (FTB 3807 does the same). +- Dollars: none at or below the limit. + +### 6. Line 3 rounds once + +- Source: "add the amounts and enter the total" (`::line-3-pass-through-donated-agricultural-products-transportation::b01`). +- Done: the stated K-1 credits keep their cents while adding, and only the total is rounded (CLAUDE.md, document sums). Dollars: at most $1. + +### 7. Line 5 is the stated carryover + +- Source: the form, "Credit carryover from a prior year". +- Done: last year's line 8 as the taxpayer states it. The carryover has no time limit (`::g-carryover::b01`; R&TC 17053.12(d)), so the engine does not track its years. A carryover from the $5,000,000 limit is "extended by the number of taxable years the credit was not allowed" (`::credit-limitation::b02`); the engine does not track that either. + +### 8. Lines that print 0, and the header + +- Line 7b prints 0: "If you are not a corporation, enter -0-" (the form). Line 7c prints 0 (item 5). Line 8 prints 0 when the credit is used in full. Lines 3 and 5 print 0 with no K-1 credit or carryover. +- The name is the names on the return, the box is "SSN or ITIN", the number is the taxpayer's SSN. The Secretary of State file number is for an LLC or a corporation, so it is blank. + +### 9. The name on Form 540 line 43 and Schedule P (540) + +- The Credit Table's name for code 204 is "Donated Agricultural Products Transportation" (`ca-540-sched-p-inst-2025::sec::credit-table::b01`). It does not fit the printed box, so the engine prints "Donated Ag Transportation"; the code names the credit. + +### 10. Schedule S line 2 in a scenario (tax review, 2026-11-28) + +- Source: "Residents – Form 540, line 48 (without other state tax credit and PTE elective tax credit)" (`ca-540-sched-s-inst-2025::sec::part-ii-figure-your-other-state-tax-credit::b01`), so line 2 is Form 540 line 35 less this credit. +- Done: `jori` has Utah tax on her fruit stand. Schedule S line 2 is 6,619 − 648 = $5,971, and line 6 is $1,022; without the subtraction they would be $6,619 and $1,133. The golden locks both. + +### 11. Schedule P (540) Section A2 lines 7 and 8 in a scenario + +- Not now: code 204 takes line 7 or 8 only next to the LAMBRA or the film credits, a rare mix. The unit tests (`shemerin`, `lyrelle` with added costs) check both rows. + +### Named gaps + +Each is an `unsupported` reason. Not now: each needs a computation the engine does not have yet, named in the item. + +- A credit through a disregarded single member LLC: the limit is the regular tax with that LLC's income less the regular tax without it (`::d-definitions::b03`). Line 7a and line 8 are a gap: the engine has no second tax run without one business. +- Form 540NR: the credit limits of Form 540NR and Schedule P (540NR) are not figured for this credit. Line 7a is a gap, and Form 540NR lines 58 to 63 name FTB 3547 (`540nr/californiaForms.ts`). The model forms (FTB 3807, FTB 3809) do the same. +- Form 541, 100, 100S, 565, 568: entity returns are not in the engine (out of scope). +- Form 540 line 35 above $5,000,000 (item 5): the limit runs across every business credit, and no form figures it yet. +- A fourth Section A2 credit: FTB 3541's two Section A2 credits and the LAMBRA credit fill lines 6 to 8, and the engine does not fill line 9. Code 204 and the Section A2 rows are then a gap. Schedule P (540) has four Section A2 rows; a fifth credit needs an attached statement, which no form has yet. +- A K-1 credit on a return that files FTB 3801: Schedule CA line 5 column C goes through FTB 3801's Schedule E worksheet, which does not take it. +- A charitable deduction for the costs (Schedule A): the costs fact has no such choice. The credit is for a business "engaged in the business of processing, distributing, or selling agricultural products" (`::c-qualifications::b01`), whose costs are a Schedule C or F expense. Schedule CA Part II line 12 column B is a gap on every return already. +- Not a gap: a carryover with no current FTB 3547 is still FTB 3547 line 5. The credit is current, not a repealed credit of FTB 3540 (code 175 there is the former agricultural products credit of 1989 to 1991). + +## Pattern change + +None. The credit follows the FTB 3807 and FTB 3809 model: before, Form 540 lines 43 to 45 and Schedule S line 2 listed their credits; after, they list code 204 too, read from `3547/creditUsed.ts`. + +## Blind fill + +A preparer filled 13 cases by hand from the form and the instructions only (2026-11-28). Every dollar amount matched the engine: lines 1 to 8 and Schedule CA (540) lines 3, 5 and 6 column C. The 37 other differences are blank against 0 (lines 3 and 5 with no K-1 credit or carryover, line 7c, lines 1 and 2 with no costs). The preparer's doubts that change dollars are items 1, 2, 3, 4 and 6 above. + +## Second opinions + +- PolicyEngine-US 2.154.2 (commit c1fea42a38): its California variables and parameters (`variables/gov/states/ca`, `parameters/gov/states/ca`) have no donated agricultural products transportation credit and no FTB 3547 Schedule CA adjustment. Nothing to compare. +- The repository names no other reference implementation for California credit forms. IRS Direct File has no California return. + +## Confidence by field group + +| Fields | Confidence | +| --- | --- | +| Header | stated rule | +| Line 1 (mileage or actual) | stated rule | +| Lines 2 to 6 | stated rule (the form's arithmetic) | +| Line 7a | stated rule (Schedule P (540) Section A2 column (b)); the line order is the author's decision (item 1) | +| Line 7b | stated rule | +| Line 7c | stated rule up to $5,000,000; unsupported above | +| Line 8 | stated rule | +| Schedule CA lines 3, 5, 6 column C | own reading of a stated rule (items 2 and 3) | diff --git a/engine/src/state/ca/3547/bindings.ts b/engine/src/state/ca/3547/bindings.ts index 28d0e574..bf4b6060 100644 --- a/engine/src/state/ca/3547/bindings.ts +++ b/engine/src/state/ca/3547/bindings.ts @@ -1,9 +1,89 @@ -/* Drafted by the write-binding-rules skill. Mark hand edits with // MANUAL EDIT:. */ +/* + * FTB 3547, Donated Agricultural Products Transportation Credit. Lines 1 to 6 + * add the credit from the stated costs, the pass-through credits and last + * year's carryover (lines.ts). Line 7a is the credit Schedule P (540) Section + * A2 lets the return use (creditUsed.ts). Line 8 carries the rest forward, + * the part the tax could not use included. + */ -import { defineForm } from "../../../defineForm.js"; +import { defineForm, type BindingFn, type FormAccessor } from "../../../defineForm.js"; +import { namesOnReturn } from "../../../federal/returnNames.js"; +import type { Unsupported } from "../../../types.js"; +import { + agTransportCreditOffered, + agTransportCreditUsed, + agTransportLines, + passThroughCredits, + type Info, +} from "./creditUsed.js"; import type { Form3547FilingInfo } from "./filingInfo.js"; +import { ASSIGNED_CREDIT_OF_AN_INDIVIDUAL, line3, line8 } from "./lines.js"; import type { Form3547 } from "./types.js"; +type Form = FormAccessor; +type Bindings = Partial<{ [K in keyof Form3547]: BindingFn }>; + +const isGap = (value: unknown): value is Unsupported => + typeof value === "object" && value !== null && "unsupported" in value; + +const read = (form: Form) => (fieldId: string) => form[fieldId]; + +/* Line 7a, or its gap; undefined while it waits. */ +const claimed = (form: Form, info: Form3547FilingInfo) => + agTransportCreditUsed(read(form), info as Info); + +/* + * Line 7c: "enter the amount of credit that would have otherwise been + * available to reduce tax in this tax year but for the $5,000,000 credit + * limitation. Do not include credit limited by your tax" + * (ca-3547-form-2025::sec::line-7c::b01). With Form 540 line 35 at $5,000,000 + * or less the credits cannot reduce the net tax by more than $5,000,000, so + * the limit disallows nothing and the line is 0; above it the credit is a gap + * (creditUsed.ts). + */ +function refundable(form: Form, info: Form3547FilingInfo): number | Unsupported | undefined { + const offered = agTransportCreditOffered(read(form), info); + return typeof offered === "number" ? 0 : offered; +} + +const lines: Bindings = { + "0.line.1_eligible_transportation_costs": (_, info) => info.agTransportCosts, + "0.line.2_current_year_credit": (_, info) => agTransportLines(info)?.line2, + "0.line.3_pass_through_credit_k1": (_, info) => { + const credits = passThroughCredits(info); + return credits === undefined ? undefined : line3(credits); + }, + "0.line.4_total_current_year_credit": (_, info) => agTransportLines(info)?.line4, + "0.line.5_credit_carryover_prior_year": (_, info) => agTransportLines(info)?.line5, + "0.line.6_total_available_credit": (_, info) => agTransportLines(info)?.line6, + "0.line.7a_credit_claimed": (form, info) => claimed(form, info), + // "If you are not a corporation, enter -0-" (the form; ca-3547-form-2025::sec::line-7b::b01). + "0.line.7b_total_credit_assigned": () => ASSIGNED_CREDIT_OF_AN_INDIVIDUAL, + "0.line.7c_credit_elected_refundable": (form, info) => refundable(form, info), + // "Add lines 7a, 7b, and line 7c, subtract the result from line 6" (the form; lines.ts, line8). + "0.line.8_credit_carryover_future_years": (form, info) => { + const available = agTransportLines(info)?.line6; + const used = claimed(form, info); + const elected = refundable(form, info); + if (isGap(used)) return used; + if (isGap(elected)) return elected; + if (available === undefined || used === undefined || elected === undefined) return undefined; + return line8(available, used, ASSIGNED_CREDIT_OF_AN_INDIVIDUAL, elected); + }, +}; + +/* + * The header: the names on the return and the taxpayer's number. An + * individual files with an SSN or ITIN; the Secretary of State file number is + * for an LLC or a corporation, so it is blank. + */ +const header: Bindings = { + "0.header.id_number_type": () => "ssn_or_itin", + "0.header.id_number": (_, info) => info.taxpayerSSN, + "0.header.name_on_return": (_, info) => namesOnReturn(info), + "0.header.sos_file_number": () => undefined, +}; + export function register(): void { - defineForm("form-3547", { bindings: {} }); + defineForm("form-3547", { bindings: { ...header, ...lines } }); } diff --git a/engine/src/state/ca/3547/creditUsed.ts b/engine/src/state/ca/3547/creditUsed.ts new file mode 100644 index 00000000..bee40080 --- /dev/null +++ b/engine/src/state/ca/3547/creditUsed.ts @@ -0,0 +1,170 @@ +/* + * The donated agricultural products transportation credit the return takes: + * code 204, one line in Schedule P (540) Section A2 ("Offset Tax in Section: + * A2", ca-540-sched-p-inst-2025::sec::credit-table::b01). Schedule P (540), + * FTB 3547 line 7a, Form 540 lines 43 to 45 and Schedule S line 2 read it + * here. `read` takes a full field id. + */ + +import type { BaseFilingInfo } from "../../../filingInfo.js"; +import { numberOrBlank } from "../../../money.js"; +import { unsupported, type Unsupported } from "../../../types.js"; +import { filmCreditsAvailable, SECTION_A2_FILM_LINES } from "../3541/creditUsed.js"; +import type { Form3541FilingInfo } from "../3541/filingInfo.js"; +import { lambraCreditOffered, type Info as Form3807Info } from "../3807/figures.js"; +import type { Form3547FilingInfo } from "./filingInfo.js"; +import { BUSINESS_CREDIT_LIMIT, line2, line3, line4, line5, line6 } from "./lines.js"; + +export type ReadField = (fieldId: string) => unknown; +export type Info = Form3547FilingInfo & Form3541FilingInfo & Form3807Info; + +const FORM_540_LINE_35 = "form-540.line.35_total_tax_after_credits"; +/* The last Schedule P (540) Section A2 line the engine fills (schedule-p/sectionA2.ts). */ +const LAST_SECTION_A2_LINE = 8; + +const files = (info: BaseFilingInfo, formId: string) => info.mustFile?.[formId]?.value === true; +export const files3547 = (info: BaseFilingInfo) => files(info, "form-3547"); + +const NONRESIDENT_RETURN = unsupported( + "Line 7a on a Form 540NR return needs the credit limits of Form 540NR and Schedule P (540NR), which the engine does not figure for this credit.", +); +const NOT_FORM_540 = unsupported( + "Line 7a is figured only against Form 540; a fiduciary or entity return (Form 541, 100, 100S, 565, 568) is not in the engine.", +); +const DISREGARDED_SMLLC = unsupported( + "A credit from a disregarded single member LLC is limited to the regular tax with that LLC's income less the regular tax without it (ca-3547-form-2025::sec::d-definitions::b03), which needs the tax figured twice; the engine does not figure it.", +); +const OVER_BUSINESS_CREDIT_LIMIT = unsupported( + "Form 540 line 35 is over $5,000,000, so the business credit limitation and the FTB 3870 election (ca-3547-form-2025::sec::credit-limitation::b01, ::line-7c::b01) can apply; the engine does not figure the limit across every business credit.", +); +const NO_SCHEDULE_P = unsupported( + "The credit cannot reduce regular tax below tentative minimum tax (ca-3547-form-2025::sec::d-definitions::b04), which Schedule P (540) Section A2 figures; the decision says Schedule P (540) does not file, though a Section A2 credit attaches it (ca-540-sched-p-inst-2025::sec::b-who-must-file::b01).", +); +const NO_SECTION_A2_LINE = unsupported( + "FTB 3541's original and new credits and FTB 3807's LAMBRA credit fill Schedule P (540) Section A2 lines 6 to 8, so code 204 goes on line 9, which the engine does not fill.", +); + +const isGap = (value: unknown): value is Unsupported => + typeof value === "object" && value !== null && "unsupported" in value; + +/* A case of the whole return the engine does not handle, else undefined. */ +export function agTransportReturnGap(info: Form3547FilingInfo): Unsupported | undefined { + if (files(info, "form-540nr")) return NONRESIDENT_RETURN; + if (!files(info, "form-540")) return NOT_FORM_540; + if (info.agTransportThroughSmllc === true) return DISREGARDED_SMLLC; + return undefined; +} + +/* Every stated pass-through credit, or undefined while one waits. */ +export function passThroughCredits(info: Form3547FilingInfo): number[] | undefined { + const credits = (info.agTransportPassThroughRows ?? []).map((row) => row.credit); + return credits.every((credit) => credit !== undefined) ? (credits as number[]) : undefined; +} + +/* Lines 1 to 6 from the filing info; undefined while an amount waits. */ +export interface AgTransportLines { + line1: number; + line2: number; + line3: number; + line4: number; + line5: number; + line6: number; +} + +export function agTransportLines(info: Form3547FilingInfo): AgTransportLines | undefined { + const line1 = info.agTransportCosts; + const credits = passThroughCredits(info); + const carryover = info.agTransportCarryover; + if (line1 === undefined || credits === undefined || carryover === undefined) return undefined; + const own = line2(line1); + const passThrough = line3(credits); + const current = line4(own, passThrough); + const prior = line5(carryover); + return { + line1, + line2: own, + line3: passThrough, + line4: current, + line5: prior, + line6: line6(current, prior), + }; +} + +/* + * Schedule P (540) Section A2 column (a) for code 204: line 6. 0 with no FTB + * 3547 or a line 6 of 0. Above $5,000,000 of tax the business credit limit can + * bind, and the engine does not figure it. + */ +export function agTransportCreditOffered( + read: ReadField, + info: Form3547FilingInfo, +): number | Unsupported | undefined { + if (!files3547(info)) return 0; + const lines = agTransportLines(info); + if (lines === undefined) return undefined; + if (lines.line6 <= 0) return 0; + const gap = agTransportReturnGap(info); + if (gap !== undefined) return gap; + const tax = numberOrBlank(read(FORM_540_LINE_35)); + if (tax === undefined) return undefined; + if (tax > BUSINESS_CREDIT_LIMIT) return OVER_BUSINESS_CREDIT_LIMIT; + return lines.line6; +} + +/* + * DECISION (2026-11-28, by the author): in Schedule P (540) Section A2 the + * donated agricultural products transportation credit takes the line after + * FTB 3541's original and new motion picture credits and FTB 3807's LAMBRA + * credit. + * - Schedule P (540) Section A2: "Follow the Credit Table Instructions to find + * out in which section to claim your credit. Then complete column (a) + * through column (d) for each credit in each section before going to the + * next section" (ca-540-sched-p-inst-2025::sec::section-a2-instructions::b01): + * no order inside the section. + * - Section B2's rule for an order: "Generally, it is to your advantage to + * apply credits with limited carryovers before credits with no limitation on + * carryover" (::section-b2-instructions::b01). This credit's carryover has no + * limit ("until exhausted", ca-3547-form-2025::sec::g-carryover::b01), and + * the film (9 years) and LAMBRA (10 years) carryovers are limited, so they go + * first. + * The engine puts code 204 after them, the same order on every return. It + * changes dollars only when the tax over TMT cannot cover every Section A2 + * credit; the credit not used then carries over with no limit. + */ +export function agTransportScheduleLine( + read: ReadField, + info: Info, +): number | Unsupported | undefined { + const film = filmCreditsAvailable(info); + if (film === undefined || isGap(film)) return film; + const lambra = lambraCreditOffered(read, info); + if (lambra === undefined || isGap(lambra)) return lambra; + const filmA2 = film.filter((credit) => credit.program.section === "A2").length; + const line = SECTION_A2_FILM_LINES[0] + filmA2 + (lambra > 0 ? 1 : 0); + return line > LAST_SECTION_A2_LINE ? NO_SECTION_A2_LINE : line; +} + +/* + * The credit taken: Schedule P (540) column (b) of the code 204 line + * (ca-540-sched-p-inst-2025::sec::how-to-claim-your-credits::b01). 0 with no + * FTB 3547 or no credit offered. A gap passes through, so Form 540 never drops + * the credit in silence. Undefined while it waits. + */ +export function agTransportCreditUsed( + read: ReadField, + info: Info, +): number | Unsupported | undefined { + const offered = agTransportCreditOffered(read, info); + if (typeof offered !== "number") return offered; + if (offered <= 0) return 0; + if (!files(info, "schedule-p")) return NO_SCHEDULE_P; + const line = agTransportScheduleLine(read, info); + if (typeof line !== "number") return line; + return numberOrBlank(read(`schedule-p.2.part3.${line}_credit_used_col_b`)); +} + +/* The same for a reader typed with only the base filing info (Form 540, Schedule S). */ +export const agTransportCreditOnReturn = ( + read: ReadField, + info: BaseFilingInfo, +): number | Unsupported | undefined => agTransportCreditUsed(read, info as Info); diff --git a/engine/src/state/ca/3547/deductionReduction.ts b/engine/src/state/ca/3547/deductionReduction.ts new file mode 100644 index 00000000..11327bf1 --- /dev/null +++ b/engine/src/state/ca/3547/deductionReduction.ts @@ -0,0 +1,42 @@ +/* + * The deduction for the same costs. "This credit is taken in lieu of any + * deduction otherwise allowable for the same eligible transportation costs. + * Any deduction allowed for these same costs must be reduced by the amount of + * credit figured for the current taxable year (the amount shown on line 4)" + * (ca-3547-form-2025::sec::d-definitions::b04). Federal law has no such + * credit, so the federal deduction stays whole and California's is smaller: + * the difference is a Schedule CA (540) column C addition, on the line that + * holds the deduction. + * - Line 2, the credit on the taxpayer's own costs, reduces the deduction the + * taxpayer took: Schedule C goes to Schedule CA line 3, Schedule F to line 6 + * (ca-540-sched-ca-inst-2025::sec::line-3-business-income-or-loss::b04, + * ::line-6-farm-income-or-loss::b01: "special credits"). + * - Line 3, the credits passed through on a Schedule K-1, reduces the + * entity's deduction that reaches the taxpayer on the K-1: Schedule CA + * line 5, where the K-1 income is (QUESTIONS.md). + * Each is 0 with no FTB 3547 and undefined while the form's lines wait. + */ + +import type { BaseFilingInfo } from "../../../filingInfo.js"; +import { agTransportLines, files3547 } from "./creditUsed.js"; +import type { Form3547FilingInfo } from "./filingInfo.js"; + +/* The Schedule CA (540) line whose deduction the credit reduces. */ +export type ReducedLine = "line3" | "line5" | "line6"; + +const OWN_COSTS_LINE = { schedule_c: "line3", schedule_f: "line6" } as const; + +/* The column C amount the credit adds on one Schedule CA (540) line. */ +export function agTransportDeductionReduction( + info: BaseFilingInfo, + line: ReducedLine, +): number | undefined { + if (!files3547(info)) return 0; + const form = info as Form3547FilingInfo; + const lines = agTransportLines(form); + if (lines === undefined) return undefined; + if (line === "line5") return lines.line3; + const deductedOn = form.agTransportDeductedOn; + if (deductedOn === undefined) return undefined; + return deductedOn !== "not_deducted" && OWN_COSTS_LINE[deductedOn] === line ? lines.line2 : 0; +} diff --git a/engine/src/state/ca/3547/filingInfo.ts b/engine/src/state/ca/3547/filingInfo.ts index b37ecd28..616312c7 100644 --- a/engine/src/state/ca/3547/filingInfo.ts +++ b/engine/src/state/ca/3547/filingInfo.ts @@ -1,3 +1,30 @@ +import type { CaAgTransportDeductedOn } from "../../../facts/index.js"; import type { BaseFilingInfo } from "../../../filingInfo.js"; -export interface Form3547FilingInfo extends BaseFilingInfo {} +/* One line 3 entity. A field is undefined while its answer waits. */ +export interface AgTransportPassThroughRow { + factKey: string; + entityName?: string; + entityId?: string; + /* As stated, with cents. */ + credit?: number; +} + +/* + * FTB 3547 reads its inputs here, and Schedule P (540) through the form + * accessor. Schedule P (540) Section A2, Form 540 lines 43 to 45, Schedule S + * line 2 and Schedule CA (540) lines 3, 5 and 6 column C read them through + * creditUsed.ts and deductionReduction.ts. + */ +export interface Form3547FilingInfo extends BaseFilingInfo { + /* Line 1 in whole dollars; undefined while the costs wait or when the form does not file. */ + agTransportCosts?: number; + /* Where the federal return deducted the same costs; undefined while it waits. */ + agTransportDeductedOn?: CaAgTransportDeductedOn; + /* The costs were paid through a disregarded single member LLC. */ + agTransportThroughSmllc?: boolean; + /* Line 3, one entry per entity with a credit above 0 or not stated yet; empty when the form does not file. */ + agTransportPassThroughRows?: AgTransportPassThroughRow[]; + /* Line 5: the carryover from 2024; undefined while it waits. */ + agTransportCarryover?: number; +} diff --git a/engine/src/state/ca/3547/lines.ts b/engine/src/state/ca/3547/lines.ts new file mode 100644 index 00000000..69441ee7 --- /dev/null +++ b/engine/src/state/ca/3547/lines.ts @@ -0,0 +1,83 @@ +/* + * FTB 3547, Donated Agricultural Products Transportation Credit: the + * arithmetic, pure. Written by hand from ca-3547-form-2025; no published + * example with numbers exists (QUESTIONS.md). + */ + +import { atLeast, roundDollars, sum } from "../../../money.js"; + +/* + * "a credit of 50% of the eligible transportation costs" + * (ca-3547-form-2025::sec::b-description::b01); line 2: "Multiply line 1 by + * 50% (.50)" (the form). + */ +export const CREDIT_RATE = 0.5; + +/* "$.14 (fourteen cents) per mile" (ca-3547-form-2025::sec::d-definitions::b01, ::line-1::b01). */ +export const MILEAGE_RATE = 0.14; + +/* + * "The total of all business credits including the carryover of any business + * credit for the taxable year may not reduce the 'net tax' ... by more than + * $5,000,000" for taxable years 2024 to 2026 (ca-3547-form-2025::sec::credit-limitation::b01). + */ +export const BUSINESS_CREDIT_LIMIT = 5_000_000; + +/* "Use credit code 204 when you claim this credit" (ca-3547-form-2025::sec::line-7a::b01). */ +export const AG_TRANSPORT_CREDIT_CODE = "204"; + +/* + * The Credit Table's name for code 204 is "Donated Agricultural Products + * Transportation" (ca-540-sched-p-inst-2025::sec::credit-table::b01). It does + * not fit the printed name boxes of Form 540 lines 43 and 44 and Schedule P + * (540) Section A2, so the name is shortened; the code names the credit, as + * for "Prior Year AMT" (540/credits.ts). + */ +export const AG_TRANSPORT_CREDIT_NAME = "Donated Ag Transportation"; + +/* Line 7b: "If you are not a corporation, enter -0-" (the form). The engine figures individual returns only. */ +export const ASSIGNED_CREDIT_OF_AN_INDIVIDUAL = 0; + +/* + * Line 1 for the mileage method: "multiply the total miles connected with + * transporting the donated agricultural product by $.14 (fourteen cents)" + * (ca-3547-form-2025::sec::line-1::b01), in whole dollars. + */ +export const mileageCosts = (miles: number): number => + roundDollars(atLeast(0, miles) * MILEAGE_RATE); + +/* Line 1 for the actual method: "the actual transportation costs paid or incurred" (::line-1::b01), in whole dollars. */ +export const actualCosts = (costs: number): number => roundDollars(atLeast(0, costs)); + +/* Line 2: "Multiply line 1 by 50% (.50)" (the form), from the whole-dollar line 1. */ +export const line2 = (line1: number): number => roundDollars(line1 * CREDIT_RATE); + +/* + * Line 3: "If you received more than one pass-through credit ... add the + * amounts and enter the total" (ca-3547-form-2025::sec::line-3-pass-through-donated-agricultural-products-transportation::b01). + * The cents are kept while adding and only the total is rounded (CLAUDE.md, document sums). + */ +export const line3 = (credits: readonly number[]): number => roundDollars(sum(...credits)); + +/* Line 4: "Add line 2 and line 3" (the form). */ +export const line4 = (line2Amount: number, line3Amount: number): number => + line2Amount + line3Amount; + +/* Line 5: last year's line 8 in whole dollars ("Credit carryover from a prior year", the form). */ +export const line5 = (carryover: number): number => roundDollars(atLeast(0, carryover)); + +/* Line 6: "Add line 4 and line 5" (the form). */ +export const line6 = (line4Amount: number, line5Amount: number): number => + line4Amount + line5Amount; + +/* + * Line 8: "Add lines 7a, 7b, and line 7c, subtract the result from line 6" + * (the form). The credit the tax could not use stays in it: "If the available + * credit exceeds the current year tax liability, the unused credit may be + * carried over to succeeding years until exhausted" + * (ca-3547-form-2025::sec::g-carryover::b01), and "Credit limited by your tax + * liability ... can, however, be carried over for future years. Include any + * such amounts here" (::d-definitions::b04, the line 8 instruction). + */ +export const line8 = (line6Amount: number, claimed: number, assigned: number, refundable: number) => + atLeast(0, line6Amount - claimed - assigned - refundable); diff --git a/engine/src/state/ca/3547/resolveInfo.ts b/engine/src/state/ca/3547/resolveInfo.ts index 502ae28a..63e67910 100644 --- a/engine/src/state/ca/3547/resolveInfo.ts +++ b/engine/src/state/ca/3547/resolveInfo.ts @@ -1,20 +1,154 @@ -import { resolveMustFile, type ResolverInputs } from "../../../resolverInputs.js"; -import type { Form3547FilingInfo } from "./filingInfo.js"; +import { + CA_AG_TRANSPORT_KEYS, + getCaAgTransportPassThroughFacts, + type CaAgTransportCostsFactValue, + type CaAgTransportDeductedOn, + type CaAgTransportPassThroughFact, +} from "../../../facts/index.js"; +import { num, resolveMustFile, type ResolverInputs } from "../../../resolverInputs.js"; +import type { AgTransportPassThroughRow, Form3547FilingInfo } from "./filingInfo.js"; +import { actualCosts, mileageCosts } from "./lines.js"; + +const MUST_FILE_KEY = "decisions.scope.must_file_3547"; +const MUST_FILE_540_KEY = "decisions.scope.must_file_ca_540"; +const MUST_FILE_540NR_KEY = "decisions.scope.must_file_540nr"; + +const DEDUCTED_ON: ReadonlyArray = [ + "schedule_c", + "schedule_f", + "not_deducted", +]; + +const finite = (value: unknown) => + typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : undefined; +const filled = (value: unknown) => + typeof value === "string" && value.trim() !== "" ? value.trim() : undefined; + +function rowOf(fact: CaAgTransportPassThroughFact): AgTransportPassThroughRow { + const value = fact.value ?? ({} as Partial); + return { + factKey: fact.key, + entityName: filled(value.entityName), + entityId: filled(value.entityId), + credit: finite(value.credit), + }; +} + +const complete = (row: AgTransportPassThroughRow) => + row.entityName !== undefined && row.entityId !== undefined && row.credit !== undefined; + +/* The pass-through credits above 0, or not stated yet. A stated credit of 0 is no row. */ +const passThroughRowsOf = (inputs: ResolverInputs) => + getCaAgTransportPassThroughFacts(inputs.facts) + .map(rowOf) + .filter((row) => row.credit === undefined || row.credit > 0); + +/* Line 1 by the stated method (ca-3547-form-2025::sec::line-1::b01); undefined while it waits. */ +function line1Of(raw: Partial): number | undefined { + if (raw.method === "mileage") { + const miles = finite(raw.miles); + return miles === undefined ? undefined : mileageCosts(miles); + } + if (raw.method === "actual") { + const costs = finite(raw.actualCosts); + return costs === undefined ? undefined : actualCosts(costs); + } + return undefined; +} + +/* Line 1's fact: the costs and where they were deducted, each undefined while it waits. */ +function costsOf(inputs: ResolverInputs) { + const raw = inputs.factByKey.get(CA_AG_TRANSPORT_KEYS.costs) as + Partial | undefined; + const stated = raw !== undefined && typeof raw === "object" && raw !== null; + const value = stated ? raw : {}; + const deductedOn = DEDUCTED_ON.find((each) => each === value.deductedOn); + return { + stated, + line1: line1Of(value), + deductedOn, + throughSmllc: value.throughDisregardedSmllc === true, + }; +} + +/* + * The fact keys that put the credit on the return: costs above 0 (or a costs + * fact not complete), a pass-through credit row, or a 2024 carryover above 0. + * Schedule P (540) reads them: a Section A2 credit attaches it. + */ +export function agTransportCreditFactKeys(inputs: ResolverInputs): string[] { + const costs = costsOf(inputs); + const ownCosts = costs.stated && (costs.line1 === undefined || costs.line1 > 0); + const carryover = (num(inputs, CA_AG_TRANSPORT_KEYS.carryover) ?? 0) > 0; + return [ + ...(ownCosts ? [CA_AG_TRANSPORT_KEYS.costs] : []), + ...passThroughRowsOf(inputs).map((row) => row.factKey), + ...(carryover ? [CA_AG_TRANSPORT_KEYS.carryover] : []), + ]; +} + +/* + * Schedule P (540) attaches with "credits that are reported in Part III, + * Section A1, Section A2, or Section C" (ca-540-sched-p-inst-2025::sec::b-who-must-file::b01), + * and code 204 offsets tax in Section A2 (::credit-table::b01). + */ +export function agTransportSectionA2Fallback(inputs: ResolverInputs, files540: boolean) { + const keys = agTransportCreditFactKeys(inputs); + return { + rule: `fallback: Form 540 files (${files540}) with ${keys.length} donated agricultural products transportation credit input(s) (FTB 3547, Section A2)`, + value: files540 && keys.length > 0, + triggeredByFactKeys: keys, + triggeredByDecisionKeys: [MUST_FILE_540_KEY], + }; +} /* - * Who files: "Use form FTB 3547, Donated Agricultural Products Transportation Credit, to figure - * the amount of credit allowed for the transportation of agricultural products donated to - * nonprofit charitable organizations" (ca-3547-form-2025, "A Purpose"). - * The instructions are not in the corpus yet, so no block id is cited. - * The form has no rules yet, so no fact turns it on: only the decision does. + * Who files: a taxpayer in the business of processing, distributing or + * selling agricultural products who paid to transport donated products + * (ca-3547-form-2025::sec::a-purpose::b01, ::c-qualifications::b01), an owner + * who received the credit on a Schedule K-1 (::a-purpose::b01), and a taxpayer + * with a carryover from 2024 (line 5), attached to the California return (the + * form's heading). The form files with a California return that has one of + * these above 0 (one not stated yet counts, so it is asked). The explicit + * decision still wins. */ export function resolve3547Info(inputs: ResolverInputs): Form3547FilingInfo { + const filesCalifornia = + inputs.decisionByKey.get(MUST_FILE_540_KEY) === true || + inputs.decisionByKey.get(MUST_FILE_540NR_KEY) === true; + const keys = agTransportCreditFactKeys(inputs); + const resolution = resolveMustFile(inputs.decisionByKey, { + explicitKey: MUST_FILE_KEY, + fallbacks: [ + { + rule: `fallback: a California return (${filesCalifornia}) with ${keys.length} donated agricultural products transportation credit input(s) above 0`, + value: filesCalifornia && keys.length > 0, + triggeredByFactKeys: keys, + triggeredByDecisionKeys: [MUST_FILE_540_KEY, MUST_FILE_540NR_KEY], + }, + ], + }); + const files = resolution.value === true; + const costs = costsOf(inputs); + const rows = passThroughRowsOf(inputs); + const carryover = num(inputs, CA_AG_TRANSPORT_KEYS.carryover); + const costsWait = costs.line1 === undefined || costs.deductedOn === undefined; return { - mustFile: { - "form-3547": resolveMustFile(inputs.decisionByKey, { - explicitKey: "decisions.scope.must_file_3547", - fallbacks: [{ rule: "fallback: the form has no rules yet", value: false }], - }), + mustFile: { "form-3547": resolution }, + /* Line 1 with where it was deducted, and line 5, always; each row while an answer inside it is missing. */ + missingInputs: { + "form-3547": files + ? [ + ...(costsWait ? [CA_AG_TRANSPORT_KEYS.costs] : []), + ...rows.filter((row) => !complete(row)).map((row) => row.factKey), + ...(carryover === undefined ? [CA_AG_TRANSPORT_KEYS.carryover] : []), + ] + : [], }, + agTransportCosts: files ? costs.line1 : undefined, + agTransportDeductedOn: files ? costs.deductedOn : undefined, + agTransportThroughSmllc: files && costs.throughSmllc, + agTransportPassThroughRows: files ? rows : [], + agTransportCarryover: files && carryover !== undefined ? Math.max(0, carryover) : undefined, }; } diff --git a/engine/src/state/ca/540/credits.ts b/engine/src/state/ca/540/credits.ts index 493040eb..1a8c7522 100644 --- a/engine/src/state/ca/540/credits.ts +++ b/engine/src/state/ca/540/credits.ts @@ -4,7 +4,8 @@ * inmate labor credit (FTB 3507), the credit for prior year AMT (FTB 3510), the passive credits (FTB 3801-CR), * the enterprise zone credit (FTB 3805Z), the LAMBRA credit (FTB 3807), the * TTA credit carryovers (FTB 3809), the natural heritage preservation credit - * (FTB 3503), the other + * (FTB 3503), the donated agricultural products transportation credit + * (FTB 3547), the other * state tax credit (Schedule S) and the PTE elective tax credit (FTB 3804-CR). * They are unsupported when no such * form files. Line 46 stays unsupported in bindings.ts and reads as blank. @@ -22,6 +23,8 @@ import { files3507, prisonLaborCreditOnReturn } from "../3507/creditUsed.js"; import { PRISON_LABOR_CREDIT_CODE, PRISON_LABOR_CREDIT_NAME } from "../3507/lines.js"; import { files3510, priorYearAmtCreditUsed, priorYearAmtCreditWaits } from "../3510/creditUsed.js"; import { files3541, filmCreditsUsed } from "../3541/creditUsed.js"; +import { agTransportCreditOnReturn, files3547 } from "../3547/creditUsed.js"; +import { AG_TRANSPORT_CREDIT_CODE, AG_TRANSPORT_CREDIT_NAME } from "../3547/lines.js"; import { files3801Cr, passiveCreditsUsed } from "../3801-cr/creditUsed.js"; import { files3804Cr, pteCreditOnReturn } from "../3804-cr/creditUsed.js"; import { PTE_CREDIT_CODE, PTE_CREDIT_NAME } from "../3804-cr/lines.js"; @@ -96,9 +99,11 @@ function otherStateCreditUsed(form: Form540Form, info: Form540FilingInfo) { * completed (ca-540-sched-p-inst-2025::sec::how-to-claim-your-credits::b01), * in Part III order: line 4 (prison inmate labor, FTB 3507), lines 6 and 7 * (FTB 3541's original and new credits), the next Section A2 line (the LAMBRA - * credit, FTB 3807), line 10 (prior year AMT), lines 16 to 18 (FTB 3541's + * credit, FTB 3807), the line after it (FTB 3547's credit, code 204, the + * DECISION in 3547/creditUsed.ts), line 10 (prior year AMT), lines 16 to 18 (FTB 3541's * other film credits, FTB 3805Z's enterprise zone credit, FTB 3809's TTA - * credit, then FTB 3801-CR's passive credits), line 20 (other state tax), line + * credit, FTB 3503's natural heritage preservation credit, code 213, the + * DECISION in 3503/creditUsed.ts, then FTB 3801-CR's passive credits), line 20 (other state tax), line * 21 (PTE elective tax). The LAMBRA credit (198) offsets tax in Section A2 and * the enterprise zone credit (176) and the TTA credit (210) in Section B2 * (ca-540-sched-p-inst-2025::sec::credit-table::b06, ::b08), and "If your credits are @@ -132,6 +137,8 @@ function otherCredits( if (film === undefined || isGap(film)) return film; const lambra = lambraCreditOnReturn(read, info); if (typeof lambra !== "number") return lambra; + const agTransport = agTransportCreditOnReturn(read, info); + if (typeof agTransport !== "number") return agTransport; const enterpriseZone = enterpriseZoneCreditUsed(read, info); if (typeof enterpriseZone !== "number") return enterpriseZone; const tta = ttaCreditUsed(read, info); @@ -147,6 +154,7 @@ function otherCredits( { name: PRISON_LABOR_CREDIT_NAME, code: PRISON_LABOR_CREDIT_CODE, amount: prisonLabor }, ...filmIn("A2"), { name: LAMBRA_CREDIT_NAME, code: LAMBRA_CREDIT_CODE, amount: lambra }, + { name: AG_TRANSPORT_CREDIT_NAME, code: AG_TRANSPORT_CREDIT_CODE, amount: agTransport }, { name: PRIOR_YEAR_AMT_CREDIT_NAME, code: PRIOR_YEAR_AMT_CREDIT_CODE, amount: priorYearAmt }, ...filmIn("B2"), { @@ -177,7 +185,8 @@ const filesOtherCreditForm = (info: Form540FilingInfo) => files3805Z(info) || files3807(info) || files3809(info) || - files3503(info); + files3503(info) || + files3547(info); /* * "To claim only one or two credits, enter the credit name, code, and amount of diff --git a/engine/src/state/ca/540nr/californiaForms.ts b/engine/src/state/ca/540nr/californiaForms.ts index cc28d92c..f54c1abd 100644 --- a/engine/src/state/ca/540nr/californiaForms.ts +++ b/engine/src/state/ca/540nr/californiaForms.ts @@ -18,6 +18,7 @@ import { resolve3510Info } from "../3510/resolveInfo.js"; import { resolve3514Info } from "../3514/resolveInfo.js"; import { resolve3526Info } from "../3526/resolveInfo.js"; import { resolve3541Info } from "../3541/resolveInfo.js"; +import { resolve3547Info } from "../3547/resolveInfo.js"; import { resolve3800CaInfo } from "../3800-ca/resolveInfo.js"; import { resolve3801CRInfo } from "../3801-cr/resolveInfo.js"; import { resolve3801Info } from "../3801/resolveInfo.js"; @@ -51,6 +52,7 @@ export const FORMS_ONLY_WITH_540: ReadonlyArray = [ // Schedule P (540NR) Part III takes these two credits too (schedule-p-540nr/partIII.ts). { formId: "form-3507", name: "FTB 3507", resolve: resolve3507Info }, { formId: "form-3541", name: "FTB 3541", resolve: resolve3541Info }, + { formId: "form-3547", name: "FTB 3547", resolve: resolve3547Info }, { formId: "form-3800-ca", name: "FTB 3800", resolve: resolve3800CaInfo }, { formId: "form-3803", name: "FTB 3803", resolve: resolve3803Info }, { formId: "schedule-g-1", name: "Schedule G-1", resolve: resolveScheduleG1Info }, diff --git a/engine/src/state/ca/540nr/credits.ts b/engine/src/state/ca/540nr/credits.ts index d1cd11a7..c16a9d22 100644 --- a/engine/src/state/ca/540nr/credits.ts +++ b/engine/src/state/ca/540nr/credits.ts @@ -20,8 +20,8 @@ export const line50ChildDependentCareCredit: Form540NRLine< /* * Lines 58 to 60: the other special credits, by name and code, or Schedule P * (540NR) for more than two (ca-540nr-booklet-2025::sec::part-ii::b02). The - * credit forms the engine has (FTB 3507, FTB 3510, FTB 3541, FTB 3801-CR, FTB - * 3804-CR, Schedule S) file with Form 540 only; the others have no facts. As + * credit forms the engine has (FTB 3507, FTB 3510, FTB 3541, FTB 3547, FTB + * 3801-CR, FTB 3804-CR, Schedule S) file with Form 540 only; the others have no facts. As * on Form 540 lines 43 to 45, the lines are a gap: a blank could hide a * credit. Schedule P (540NR) has rules, but each of its credit rows takes one * of these forms (schedule-p-540nr/partIII.ts), so line 60 stays a gap. @@ -30,6 +30,7 @@ const OTHER_CREDIT_FORMS = [ "form-3507", "form-3510", "form-3541", + "form-3547", "form-3801-cr", "form-3804-cr", "schedule-s", diff --git a/engine/src/state/ca/formsWithNoRules.ts b/engine/src/state/ca/formsWithNoRules.ts index b11941bd..cdef92b9 100644 --- a/engine/src/state/ca/formsWithNoRules.ts +++ b/engine/src/state/ca/formsWithNoRules.ts @@ -16,8 +16,6 @@ import type { Form3531FilingInfo } from "./3531/filingInfo.js"; import { resolve3531Info } from "./3531/resolveInfo.js"; import type { Form3540FilingInfo } from "./3540/filingInfo.js"; import { resolve3540Info } from "./3540/resolveInfo.js"; -import type { Form3547FilingInfo } from "./3547/filingInfo.js"; -import { resolve3547Info } from "./3547/resolveInfo.js"; import type { Form3548FilingInfo } from "./3548/filingInfo.js"; import { resolve3548Info } from "./3548/resolveInfo.js"; import type { Form3554FilingInfo } from "./3554/filingInfo.js"; @@ -59,7 +57,6 @@ export type CaliforniaFormsWithNoRulesFilingInfo = ScheduleXFilingInfo & Form3523FilingInfo & Form3531FilingInfo & Form3540FilingInfo & - Form3547FilingInfo & Form3548FilingInfo & Form3554FilingInfo & Form3568FilingInfo & @@ -86,7 +83,6 @@ export const CALIFORNIA_FORMS_WITH_NO_RULES_RESOLVERS: ReadonlyArray< resolve3523Info, resolve3531Info, resolve3540Info, - resolve3547Info, resolve3548Info, resolve3554Info, resolve3568Info, diff --git a/engine/src/state/ca/laterForms.ts b/engine/src/state/ca/laterForms.ts index 40ce72d3..b0efc736 100644 --- a/engine/src/state/ca/laterForms.ts +++ b/engine/src/state/ca/laterForms.ts @@ -16,6 +16,8 @@ import type { Form3510FilingInfo } from "./3510/filingInfo.js"; import { resolve3510Info } from "./3510/resolveInfo.js"; import type { Form3541FilingInfo } from "./3541/filingInfo.js"; import { resolve3541Info } from "./3541/resolveInfo.js"; +import type { Form3547FilingInfo } from "./3547/filingInfo.js"; +import { resolve3547Info } from "./3547/resolveInfo.js"; import type { Form3800CaFilingInfo } from "./3800-ca/filingInfo.js"; import { resolve3800CaInfo } from "./3800-ca/resolveInfo.js"; import type { Form3801CRFilingInfo } from "./3801-cr/filingInfo.js"; @@ -87,6 +89,7 @@ export type LaterCaliforniaFormsFilingInfo = Form540NRFilingInfo & Form3807FilingInfo & Form3809FilingInfo & Form3503FilingInfo & + Form3547FilingInfo & ScheduleP540NRFilingInfo; export const LATER_CALIFORNIA_FORMS_RESOLVERS: ReadonlyArray< @@ -118,5 +121,6 @@ export const LATER_CALIFORNIA_FORMS_RESOLVERS: ReadonlyArray< resolve3807Info, resolve3809Info, resolve3503Info, + resolve3547Info, resolveScheduleP540NRInfo, ]; diff --git a/engine/src/state/ca/schedule-ca/answerLines.ts b/engine/src/state/ca/schedule-ca/answerLines.ts index 9c5dc355..d0763321 100644 --- a/engine/src/state/ca/schedule-ca/answerLines.ts +++ b/engine/src/state/ca/schedule-ca/answerLines.ts @@ -7,6 +7,7 @@ import type { FormSpec } from "../../../defineForm.js"; import { numberOrBlank, roundDollars, sum, sumOrBlank } from "../../../money.js"; import { unsupported } from "../../../types.js"; +import { agTransportDeductionReduction } from "../3547/deductionReduction.js"; import { isUnsupportedResult } from "../3801/context.js"; import { scheduleEAdjustment } from "../3801/worksheetBindings.js"; import type { DepreciationAdjustment } from "./activities.js"; @@ -71,16 +72,27 @@ function depreciationColumn( * (ca-3801-inst-2025::sec::individuals::b01; "Use form FTB 3801 to figure the * total adjustment for line 5", ca-540-sched-ca-inst-2025::sec::line-5-rental-real-estate-royalties-partnerships-s-corporations-trusts-etc::b01). * Otherwise FTB 3885A line 8a/14a in column B, 8b/14b in column C - * (ca-3885a-inst-2025::sec::line-8a-and-line-8b::b01). + * (ca-3885a-inst-2025::sec::line-8a-and-line-8b::b01). Column C also adds + * FTB 3547 line 3, the K-1 credits that reduce the entity's deduction + * (3547/deductionReduction.ts); with FTB 3801 filed that amount is a gap. */ +const AG_TRANSPORT_WITH_3801_GAP = + "FTB 3547 line 3 (a K-1 donated agricultural products transportation credit) reduces the entity's deduction for the same costs (ca-3547-form-2025::sec::d-definitions::b04), and with FTB 3801 filed the K-1's California difference goes through FTB 3801's Schedule E worksheet, which does not take it."; + export function line5Column( form: Record, info: ScheduleCaFilingInfo, side: "subtraction" | "addition", ) { + const agTransport = side === "addition" ? agTransportDeductionReduction(info, "line5") : 0; + if (agTransport === undefined) return undefined; if (info.mustFile?.["form-3801"]?.value !== true) { - return depreciationColumn(info.rentalDepreciationAdjustment, side); + const column = depreciationColumn(info.rentalDepreciationAdjustment, side); + if (agTransport === 0 || isUnsupportedResult(column)) return column; + if (info.rentalDepreciationAdjustment?.waits) return undefined; + return (column ?? 0) + agTransport; } + if (agTransport > 0) return unsupported(AG_TRANSPORT_WITH_3801_GAP); const adjustment = scheduleEAdjustment(form, info); if (adjustment === undefined || isUnsupportedResult(adjustment)) return adjustment; const amount = side === "subtraction" ? -adjustment : adjustment; @@ -152,10 +164,14 @@ export const CA_RESEARCH_GAP = /* * Line 3 column B or C: a California employee's profit or loss, plus the FTB * 3885A business difference, the Schedule D-1 Part IV difference and, in - * column B, the expenses the federal business credits took off. + * column B, the expenses the federal business credits took off. Column C also + * adds FTB 3547 line 2 when the costs it credits were deducted on Schedule C + * (3547/deductionReduction.ts). */ export function line3Column(info: ScheduleCaFilingInfo, side: "subtraction" | "addition") { if (info.caFederalResearchReduction !== undefined) return unsupported(CA_RESEARCH_GAP); + const agTransport = side === "addition" ? agTransportDeductionReduction(info, "line3") : 0; + if (agTransport === undefined) return undefined; const employee = side === "subtraction" ? info.caEmployeeAmounts?.netProfit : info.caEmployeeAmounts?.netLoss; const depreciation = depreciationColumn(info.businessDepreciationAdjustment, side); @@ -164,7 +180,11 @@ export function line3Column(info: ScheduleCaFilingInfo, side: "subtraction" | "a const recapture = recaptureColumn(info, side); if (recapture !== undefined && typeof recapture !== "number") return recapture; const total = - (employee ?? 0) + (depreciation ?? 0) + (recapture ?? 0) + businessCreditColumn(info, side); + (employee ?? 0) + + (depreciation ?? 0) + + (recapture ?? 0) + + businessCreditColumn(info, side) + + agTransport; return positive(total); } @@ -212,7 +232,10 @@ export function line6Column(info: ScheduleCaFilingInfo, side: "subtraction" | "a employmentCredits > (figured?.credit ?? 0) || farms.some((farm) => (farm.value.smallEmployerHealthCredit ?? 0) > 0); if (otherCredits) return unsupported(FARM_WAGE_CREDIT_GAP); - return side === "subtraction" ? positive(figured?.reduction) : undefined; + if (side === "subtraction") return positive(figured?.reduction); + // Column C: FTB 3547 line 2 when its costs were deducted on Schedule F (3547/deductionReduction.ts). + const agTransport = agTransportDeductionReduction(info, "line6"); + return agTransport === undefined ? undefined : positive(agTransport); } export function answerLines(): Bindings { diff --git a/engine/src/state/ca/schedule-p/partIII.ts b/engine/src/state/ca/schedule-p/partIII.ts index 8242d0ff..9bae5d4d 100644 --- a/engine/src/state/ca/schedule-p/partIII.ts +++ b/engine/src/state/ca/schedule-p/partIII.ts @@ -230,7 +230,8 @@ function codedCreditRow(page: 2 | 3, line: 6 | 7 | 8 | 9 | 16 | 17 | 18 | 19, se export const partIIICreditRows: Unsupported = Object.fromEntries([ /* * Line 4 holds FTB 3507's credit (prisonLaborRow.ts). Lines 6 to 8 hold - * FTB 3541's original and new credits, then FTB 3807's (sectionA2.ts). + * FTB 3541's original and new credits, then FTB 3807's, then FTB 3547's + * (sectionA2.ts). */ ...codedCreditRow(2, 9, "Section A2"), ...row( diff --git a/engine/src/state/ca/schedule-p/resolveInfo.ts b/engine/src/state/ca/schedule-p/resolveInfo.ts index 957957ed..e7487c1c 100644 --- a/engine/src/state/ca/schedule-p/resolveInfo.ts +++ b/engine/src/state/ca/schedule-p/resolveInfo.ts @@ -12,6 +12,7 @@ import { } from "../../../resolverInputs.js"; import { prisonLaborCreditFactKeys } from "../3507/resolveInfo.js"; import { claimsCaPriorYearAmtCredit } from "../3510/resolveInfo.js"; +import { agTransportSectionA2Fallback } from "../3547/resolveInfo.js"; import { lambraSectionA2Fallback } from "../3807/resolveInfo.js"; import { filmSectionA2Fallback, moreThanTwoCreditsFallback } from "./creditCount.js"; import type { SchedulePFilingInfo } from "./filingInfo.js"; @@ -79,6 +80,7 @@ export function resolveSchedulePInfo(inputs: ResolverInputs): SchedulePFilingInf moreThanTwoCreditsFallback(inputs, files540), filmSectionA2Fallback(inputs, files540), lambraSectionA2Fallback(inputs, files540), + agTransportSectionA2Fallback(inputs, files540), ], }); const files = resolution.value === true; diff --git a/engine/src/state/ca/schedule-p/sectionA2.ts b/engine/src/state/ca/schedule-p/sectionA2.ts index 0ac166be..39b9c942 100644 --- a/engine/src/state/ca/schedule-p/sectionA2.ts +++ b/engine/src/state/ca/schedule-p/sectionA2.ts @@ -1,7 +1,9 @@ /* * Schedule P (540) Part III, Section A2 lines 6 to 8: FTB 3541's original * (223) and new (237) motion picture credits, then FTB 3807's LAMBRA credit - * (198; the DECISION in 3807/creditUsed.ts). Each "cannot reduce regular tax + * (198; the DECISION in 3807/creditUsed.ts), then FTB 3547's donated + * agricultural products transportation credit (204; the DECISION in + * 3547/creditUsed.ts). Each "cannot reduce regular tax * below TMT" (ca-3541-inst-2025::sec::c-limitations::b01) and offsets tax in * Section A2 (ca-540-sched-p-inst-2025::sec::credit-table::b01, ::b02, ::b06). * Column (b) is the smaller of column (a) and the previous line's column (c): @@ -16,13 +18,16 @@ import { numberOrBlank } from "../../../money.js"; import { unsupported, type Unsupported } from "../../../types.js"; import { filmCreditsAvailable } from "../3541/creditUsed.js"; import type { Form3541FilingInfo } from "../3541/filingInfo.js"; +import { agTransportCreditOffered } from "../3547/creditUsed.js"; +import type { Form3547FilingInfo } from "../3547/filingInfo.js"; +import { AG_TRANSPORT_CREDIT_CODE, AG_TRANSPORT_CREDIT_NAME } from "../3547/lines.js"; import { scheduleCreditRow, type CreditRow } from "../3804-cr/lines.js"; import { lambraCreditOffered, type Info as Form3807Info } from "../3807/figures.js"; import { LAMBRA_CREDIT_CODE, LAMBRA_CREDIT_NAME } from "../3807/lines.js"; import type { SchedulePFilingInfo } from "./filingInfo.js"; import type { ScheduleP } from "./types.js"; -type Info = SchedulePFilingInfo & Form3541FilingInfo & Form3807Info; +type Info = SchedulePFilingInfo & Form3541FilingInfo & Form3807Info & Form3547FilingInfo; type Bindings = Partial<{ [K in keyof ScheduleP]: BindingFn }>; type Form = FormAccessor; @@ -41,6 +46,10 @@ interface A2Credit { const noCreditReason = (line: number) => `Section A2 line ${line}, a credit with carryover provisions chosen from the Credit Table — no credit facts.`; +/* Four Section A2 credits: the engine fills lines 6 to 8 only. */ +const MORE_CREDITS_THAN_LINES = + "The return has more Section A2 credits than lines 6 to 8 hold (FTB 3541's original and new credits, FTB 3807's and FTB 3547's); the engine does not fill line 9."; + const BALANCES_BEFORE_A2: Array = [ "1.part3.5_child_dependent_care_credit_col_c", "1.part3.4_prison_inmate_labor_credit_col_c", @@ -58,12 +67,14 @@ function balanceBeforeA2(form: Form): number | undefined { const isGap = (value: unknown): value is Unsupported => typeof value === "object" && value !== null && "unsupported" in value; -/* The film credits of Section A2, then the LAMBRA credit when above 0. */ +/* The film credits of Section A2, then the LAMBRA credit and FTB 3547's credit when above 0. */ function sectionA2Credits(form: Form, info: Info): A2Credit[] | Unsupported | undefined { const film = filmCreditsAvailable(info); if (film === undefined || isGap(film)) return film; const lambra = lambraCreditOffered((fieldId) => form[fieldId], info); if (lambra === undefined || isGap(lambra)) return lambra; + const agTransport = agTransportCreditOffered((fieldId) => form[fieldId], info); + if (agTransport === undefined || isGap(agTransport)) return agTransport; return [ ...film .filter((credit) => credit.program.section === "A2") @@ -75,6 +86,9 @@ function sectionA2Credits(form: Form, info: Info): A2Credit[] | Unsupported | un ...(lambra > 0 ? [{ code: LAMBRA_CREDIT_CODE, name: LAMBRA_CREDIT_NAME, available: lambra }] : []), + ...(agTransport > 0 + ? [{ code: AG_TRANSPORT_CREDIT_CODE, name: AG_TRANSPORT_CREDIT_NAME, available: agTransport }] + : []), ]; } @@ -94,6 +108,7 @@ const column = const index = SECTION_A2_LINES.indexOf(line); const credits = sectionA2Credits(form, info); if (credits === undefined || isGap(credits)) return credits; + if (credits.length > SECTION_A2_LINES.length) return unsupported(MORE_CREDITS_THAN_LINES); if (credits.length <= index) return unsupported(noCreditReason(line)); const rows = sectionA2Rows(form, credits); if (rows === undefined) return rows; diff --git a/engine/src/state/ca/schedule-s/returnAmounts.ts b/engine/src/state/ca/schedule-s/returnAmounts.ts index 1da23a88..a9e184a3 100644 --- a/engine/src/state/ca/schedule-s/returnAmounts.ts +++ b/engine/src/state/ca/schedule-s/returnAmounts.ts @@ -11,6 +11,7 @@ import { naturalHeritageCreditUsed } from "../3503/creditUsed.js"; import { prisonLaborCreditOnReturn } from "../3507/creditUsed.js"; import { PRIOR_YEAR_AMT_CREDIT_USED, priorYearAmtCreditWaits } from "../3510/creditUsed.js"; import { filmCreditsUsedTotal } from "../3541/creditUsed.js"; +import { agTransportCreditOnReturn } from "../3547/creditUsed.js"; import { passiveCreditsUsedTotal } from "../3801-cr/creditUsed.js"; import { enterpriseZoneCreditUsed } from "../3805z/creditUsed.js"; import { lambraCreditOnReturn } from "../3807/creditUsed.js"; @@ -70,25 +71,31 @@ export function californiaTaxLiability( // FTB 3541's credits are on lines 43 to 45 too; read from their source. const film = filmCreditsUsedTotal(read, info); if (typeof film !== "number") return film; - // FTB 3805Z's enterprise zone, FTB 3807's LAMBRA and FTB 3809's TTA credits are on lines 43 to 45 too. - const enterpriseZone = enterpriseZoneCreditUsed(read, info); - if (typeof enterpriseZone !== "number") return enterpriseZone; + /* + * On lines 43 to 45 too, in Schedule P (540) order: FTB 3807's LAMBRA credit + * and FTB 3547's credit (Section A2), then FTB 3805Z's enterprise zone, FTB + * 3809's TTA and FTB 3503's natural heritage preservation credits (Section B2). + */ const lambra = lambraCreditOnReturn(read, info); if (typeof lambra !== "number") return lambra; + const agTransport = agTransportCreditOnReturn(read, info); + if (typeof agTransport !== "number") return agTransport; + const enterpriseZone = enterpriseZoneCreditUsed(read, info); + if (typeof enterpriseZone !== "number") return enterpriseZone; const tta = ttaCreditUsed(read, info); if (typeof tta !== "number") return tta; - // FTB 3503's natural heritage preservation credit is on lines 43 to 45 too. const heritage = naturalHeritageCreditUsed(read, info); if (typeof heritage !== "number") return heritage; const otherCredits = sum( - heritage, ...OTHER_CREDIT_LINES.map(read), passive, prisonLabor, film, - enterpriseZone, lambra, + agTransport, + enterpriseZone, tta, + heritage, ); return atLeast(0, line35 - otherCredits); } diff --git a/engine/tests/integration/requiredInputs.test.ts b/engine/tests/integration/requiredInputs.test.ts index 196fdd56..ffeb6cbd 100644 --- a/engine/tests/integration/requiredInputs.test.ts +++ b/engine/tests/integration/requiredInputs.test.ts @@ -596,6 +596,18 @@ const OPTIONAL: Array<[RegExp, string]> = [ "line 3, one K-1); whether the taxpayer has one is Cade's question. FTB 3503 lists the " + "fact again while an answer inside it (name, number, credit) is missing", ], + [ + /^ca_ag_transport\.costs$/, + "the fact is the whole cost of the taxpayer's own trips with donated agricultural products " + + "(FTB 3547 line 1); whether the business hauled any is Cade's question. FTB 3547 lists " + + "the fact again while it files (a K-1 credit or a carryover) and the costs are not complete", + ], + [ + /^ca_ag_transport_pass_through\.[^.]+$/, + "each fact is a whole entity's pass-through donated agricultural products transportation " + + "credit (FTB 3547 line 3, one K-1); whether the taxpayer has one is Cade's question. FTB " + + "3547 lists the fact again while an answer inside it (name, number, credit) is missing", + ], [ /^ca_film_credit\.[^.]+$/, "each fact is one whole California Film Commission credit certificate (one FTB 3541); " + diff --git a/engine/tests/scenarios/synthetic/jori/README.md b/engine/tests/scenarios/synthetic/jori/README.md new file mode 100644 index 00000000..29be5b80 --- /dev/null +++ b/engine/tests/scenarios/synthetic/jori/README.md @@ -0,0 +1,62 @@ +# jori (synthetic, unverified) + +Jori Tessaly is a made-up taxpayer. No filed return, benchmark case or answer +key stands behind her values. The lines below were checked by hand against the +forms and their instructions, then the engine's output was locked. + +## Who she is + +- Single, a full-year California resident (near Visalia). +- She grows citrus (Schedule F, cash method): $240,000 of fruit sales and + $115,000 of expenses, no depreciation. Her $18,000 of fuel includes the fuel + for her runs to a food bank. +- She drove 9,250 miles hauling unsold fruit to the food bank, which gave her + a certificate. She figures FTB 3547 by the mileage method. +- No K-1 credit and no 2024 carryover. +- In winter she runs a fruit stand in St. George, Utah. $20,000 of her farm + profit is from it, and she filed a Utah nonresident return: Utah tax is $860. +- She paid $26,000 of federal and $8,000 of California estimated tax. + +## Documents + +None. The food bank's certificate stays with her, and the miles come from +her mileage log. The Utah return is not in the engine: its amounts are her +answers. + +## What it covers + +- FTB 3547 line 1 by the mileage method ($.14 a mile) and line 2 rounded to + the nearest dollar. The tax over TMT covers the whole credit: line 8 is 0. +- Schedule P (540) Section A2 line 6, code 204, with a balance in column (c). +- Schedule CA (540) line 6 column C: the Schedule F deduction for the same + costs, less line 2. +- Form 540 line 43: code 204. +- Schedule S line 2: Form 540 line 35 less the FTB 3547 credit ("Form 540, + line 48 (without other state tax credit and PTE elective tax credit)"), and + Form 540 line 44: the other state tax credit, code 187. +- `padan` covers the actual method, Schedule C, a K-1 credit, a carryover and + a credit limited by the tax. + +## Hand check + +| Line | Value | How | +| --- | --- | --- | +| Sch F line 34 | 125,000 | 240,000 − 115,000 | +| Sch SE lines 4a, 12, 13 | 115,438; 17,662; 8,831 | 125,000 × 92.35%; × 15.3%; half | +| 1040 line 11a | 116,169 | 125,000 − 8,831 | +| 3547 lines 1, 2 | 1,295; 648 | 9,250 × $.14; 1,295 × 50% = 647.50, rounded | +| 3547 lines 3 to 6 | 0; 648; 0; 648 | no K-1; 648 + 0; no carryover; 648 + 0 | +| Sch CA line 6 col C | 648 | 3547 line 2 | +| 540 lines 17, 19 | 116,817; 111,111 | 116,169 + 648; less 5,706 | +| 540 lines 31, 35 | 6,772; 6,619 | rate schedule; less 153 | +| Sch P lines 23, 24 | 24,068; 1,685 | 116,817 − 92,749; × 7% | +| Sch P Part III line 3 | 4,934 | 6,619 − 1,685 | +| Sch P line 6 (a), (b), (c), (d) | 648; 648; 4,286; 0 | 3547 line 6; smaller of 648 and 4,934; 4,934 − 648; 648 − 648 | +| 3547 lines 7a, 7b, 7c, 8 | 648; 0; 0; 0 | Sch P line 6 (b); not a corporation; line 35 under $5,000,000; 648 − 648 | +| Sch S lines 1, 2, 3, 4 | 20,000; 5,971; 20,000; 116,817 | the fruit stand; 6,619 − 648 (FTB 3547); line 1; 540 line 17 | +| Sch S lines 5, 6 | 0.1712; 1,022 | 20,000 / 116,817; 5,971 × 0.1712 | +| Sch S lines 7 to 12 | 860; 20,000; 20,000; 1.0000; 860; 860 | Utah tax; line 1; Utah AGI; 20,000 / 20,000; 860 × 1.0000; smaller of 1,022 and 860 | +| Sch P line 20 (a), (b), (c) | 860; 860; 5,111 | Sch S line 12; smaller of 860 and 5,971; 5,971 − 860 | +| 540 lines 43, 44 | 648; 860 | code 204; code 187 | +| 540 lines 47, 48 | 1,508; 5,111 | 648 + 860; 6,619 − 1,508 | +| 540 lines 72, 97, 115 | 8,000; 2,889; 2,889 | estimated tax; 8,000 − 5,111 | diff --git a/engine/tests/scenarios/synthetic/jori/decisions.ts b/engine/tests/scenarios/synthetic/jori/decisions.ts new file mode 100644 index 00000000..b08503f0 --- /dev/null +++ b/engine/tests/scenarios/synthetic/jori/decisions.ts @@ -0,0 +1,30 @@ +/* The made-up taxpayer's answers (README.md). */ + +import type { AIDecisionRow } from "../../../../src/facts/rows.js"; +import { decisionRow } from "../../../helpers/fixtureBuilders.js"; +import { JORI_TAX_YEAR, JORI_USER_ID } from "./facts.js"; + +const dec = (key: string, decision: unknown, rationale: string) => + decisionRow({ + userId: JORI_USER_ID, + taxYear: JORI_TAX_YEAR, + key, + decision, + rationale, + }); + +export const joriDecisions: AIDecisionRow[] = [ + dec("decisions.scope.must_file_federal", true, "Farm income is over the threshold."), + dec("decisions.scope.filing_status", "single", "Not married at the end of 2025."), + dec("decisions.scope.has_digital_assets", false, "No digital asset activity."), + dec("decisions.scope.has_reportable_sales", false, "No sales of stock or other property."), + dec("decisions.scope.has_foreign_financial_account", false, "No foreign accounts."), + dec("decisions.scope.has_foreign_trust", false, "No foreign trust."), + dec("decisions.itemize_vs_standard", "standard", "No itemized deductions."), + dec("decisions.scope.must_file_ca_540", true, "Full-year California resident."), + dec("decisions.scope.ca_residency", "full_year", "Lived near Visalia all of 2025."), + dec("decisions.scope.mailing_same_as_principal_residence", true, "Mailing address is the home."), + dec("decisions.scope.use_tax_zero_reason", "no_use_tax_owed", "No out-of-state purchases."), + dec("decisions.refund.refund_full_overpayment_federal", true, "Refund any overpayment."), + dec("decisions.refund.refund_full_overpayment_ca", true, "Refund any CA overpayment."), +]; diff --git a/engine/tests/scenarios/synthetic/jori/docs/Jori-1040-Golden.pdf b/engine/tests/scenarios/synthetic/jori/docs/Jori-1040-Golden.pdf new file mode 100644 index 00000000..1a553ae1 Binary files /dev/null and b/engine/tests/scenarios/synthetic/jori/docs/Jori-1040-Golden.pdf differ diff --git a/engine/tests/scenarios/synthetic/jori/docs/Jori-CA540-Golden.pdf b/engine/tests/scenarios/synthetic/jori/docs/Jori-CA540-Golden.pdf new file mode 100644 index 00000000..f3af316c Binary files /dev/null and b/engine/tests/scenarios/synthetic/jori/docs/Jori-CA540-Golden.pdf differ diff --git a/engine/tests/scenarios/synthetic/jori/docs/Jori-Form3547-Golden.pdf b/engine/tests/scenarios/synthetic/jori/docs/Jori-Form3547-Golden.pdf new file mode 100644 index 00000000..b581ef5b Binary files /dev/null and b/engine/tests/scenarios/synthetic/jori/docs/Jori-Form3547-Golden.pdf differ diff --git a/engine/tests/scenarios/synthetic/jori/docs/Jori-Form8995-Golden.pdf b/engine/tests/scenarios/synthetic/jori/docs/Jori-Form8995-Golden.pdf new file mode 100644 index 00000000..44723493 Binary files /dev/null and b/engine/tests/scenarios/synthetic/jori/docs/Jori-Form8995-Golden.pdf differ diff --git a/engine/tests/scenarios/synthetic/jori/docs/Jori-Schedule1-Golden.pdf b/engine/tests/scenarios/synthetic/jori/docs/Jori-Schedule1-Golden.pdf new file mode 100644 index 00000000..961d7e9d Binary files /dev/null and b/engine/tests/scenarios/synthetic/jori/docs/Jori-Schedule1-Golden.pdf differ diff --git a/engine/tests/scenarios/synthetic/jori/docs/Jori-Schedule2-Golden.pdf b/engine/tests/scenarios/synthetic/jori/docs/Jori-Schedule2-Golden.pdf new file mode 100644 index 00000000..af802df4 Binary files /dev/null and b/engine/tests/scenarios/synthetic/jori/docs/Jori-Schedule2-Golden.pdf differ diff --git a/engine/tests/scenarios/synthetic/jori/docs/Jori-ScheduleCA-Golden.pdf b/engine/tests/scenarios/synthetic/jori/docs/Jori-ScheduleCA-Golden.pdf new file mode 100644 index 00000000..10e29b76 Binary files /dev/null and b/engine/tests/scenarios/synthetic/jori/docs/Jori-ScheduleCA-Golden.pdf differ diff --git a/engine/tests/scenarios/synthetic/jori/docs/Jori-ScheduleF-Golden.pdf b/engine/tests/scenarios/synthetic/jori/docs/Jori-ScheduleF-Golden.pdf new file mode 100644 index 00000000..c3ab0f7f Binary files /dev/null and b/engine/tests/scenarios/synthetic/jori/docs/Jori-ScheduleF-Golden.pdf differ diff --git a/engine/tests/scenarios/synthetic/jori/docs/Jori-ScheduleP-Golden.pdf b/engine/tests/scenarios/synthetic/jori/docs/Jori-ScheduleP-Golden.pdf new file mode 100644 index 00000000..09f213c0 Binary files /dev/null and b/engine/tests/scenarios/synthetic/jori/docs/Jori-ScheduleP-Golden.pdf differ diff --git a/engine/tests/scenarios/synthetic/jori/docs/Jori-ScheduleS-Golden.pdf b/engine/tests/scenarios/synthetic/jori/docs/Jori-ScheduleS-Golden.pdf new file mode 100644 index 00000000..b2864dc7 Binary files /dev/null and b/engine/tests/scenarios/synthetic/jori/docs/Jori-ScheduleS-Golden.pdf differ diff --git a/engine/tests/scenarios/synthetic/jori/docs/Jori-ScheduleSe-Golden.pdf b/engine/tests/scenarios/synthetic/jori/docs/Jori-ScheduleSe-Golden.pdf new file mode 100644 index 00000000..727efaa7 Binary files /dev/null and b/engine/tests/scenarios/synthetic/jori/docs/Jori-ScheduleSe-Golden.pdf differ diff --git a/engine/tests/scenarios/synthetic/jori/expected.ts b/engine/tests/scenarios/synthetic/jori/expected.ts new file mode 100644 index 00000000..26cf8334 --- /dev/null +++ b/engine/tests/scenarios/synthetic/jori/expected.ts @@ -0,0 +1,343 @@ +/* + * jori — LOCKED expected values, drafted from the engine's + * output on 2026-11-28 (scripts/draftExpected.ts). + * + * UNVERIFIED: no CPA return or filed-return check stands behind these + * values. They are engine output, checked by hand, so a failure means + * "the engine changed", not "the engine is wrong". + * + * Edit by hand. Change a value only after you verify it against the form + * instructions or a filed return (scripts/compareFiled). + */ + +import type { ExpectedResults } from "../../../types.js"; + +const EXPECTED: Record> = { + "schedule-f": { + engineFields: { + // Line 2 — Sales of livestock, produce, grains, and other products you raised + "schedule-f.0.line.2_sales_products_raised": 240000, + // Line 9 — Gross income. Add amounts in the right column (lines 1c, 2, 3b, 4b, 5a, 5c, 6b, 6 + "schedule-f.0.line.9_gross_income": 240000, + // Line 11 — Chemicals + "schedule-f.0.line.11_chemicals": 12000, + // Line 25 — Repairs and maintenance + "schedule-f.0.line.25_repairs_maintenance": 8000, + // Line 28 — Supplies + "schedule-f.0.line.28_supplies": 4000, + // Line 29 — Taxes + "schedule-f.0.line.29_taxes": 3000, + // Line 30 — Utilities + "schedule-f.0.line.30_utilities": 6000, + // Line 17 — Fertilizers and lime + "schedule-f.0.line.17_fertilizers_lime": 14000, + // Line 19 — Gasoline, fuel, and oil + "schedule-f.0.line.19_gasoline_fuel_oil": 18000, + // Line 20 — Insurance (other than health) + "schedule-f.0.line.20_insurance_other_than_health": 5000, + // Line 22 — Labor hired (less employment credits) + "schedule-f.0.line.22_labor_hired": 45000, + // Line 33 — Total expenses. Add lines 10 through 32f + "schedule-f.0.line.33_total_expenses": 115000, + // Line 34 — Net farm profit or (loss). Subtract line 33 from line 9 + "schedule-f.0.line.34_net_farm_profit_loss": 125000, + }, + }, + "schedule-se": { + engineFields: { + // Line 1a — Net farm profit or (loss) from Schedule F, line 34, and farm partnerships, Sched + "schedule-se.0.line.1a": 125000, + // Line 3 — Combine lines 1a, 1b, and 2 + "schedule-se.0.line.3": 125000, + // Line 4a — If line 3 is more than zero, multiply line 3 by 92.35% (0.9235). Otherwise, ente + "schedule-se.0.line.4a": 115438, + // Line 4c — Combine lines 4a and 4b. If less than $400, stop; you don't owe self-employment + "schedule-se.0.line.4c": 115438, + // Line 6 — Add lines 4c and 5b + "schedule-se.0.line.6": 115438, + // Line 9 — Subtract line 8d from line 7. If zero or less, enter -0- + "schedule-se.0.line.9": 176100, + // Line 10 — Multiply the smaller of line 6 or line 9 by 12.4% (0.124) + "schedule-se.0.line.10": 14314, + // Line 11 — Multiply line 6 by 2.9% (0.029) + "schedule-se.0.line.11": 3348, + // Line 12 — Self-employment tax. Add lines 10 and 11 + "schedule-se.0.line.12": 17662, + // Line 13 — Deduction for one-half of self-employment tax. Multiply line 12 by 50% (0.50) + "schedule-se.0.line.13": 8831, + }, + }, + "schedule-1": { + engineFields: { + // Line 6 — Farm income or (loss). Attach Schedule F + "schedule-1.0.line.6": 125000, + // Line 10 — Combine lines 1 through 7 and 9. This is your additional income + "schedule-1.0.line.10": 125000, + // Line 15 — Deductible part of self-employment tax (attach Schedule SE) + "schedule-1.1.line.15": 8831, + // Line 26 — Adjustments to income. Add lines 11 through 23 and 25 + "schedule-1.1.line.26": 8831, + }, + }, + "schedule-2": { + engineFields: { + // Line 4 — Self-employment tax. Attach Schedule SE + "schedule-2.0.line.4_self_employment_tax": 17662, + // Line 21 — Add lines 4, 7 through 16, 18, and 19. Total other taxes. Enter here and on Form + "schedule-2.1.line.21_total_other_taxes": 17662, + }, + }, + "form-8995": { + engineFields: { + // Line 1i — (c) Qualified business income or (loss) + "form-8995.0.line.1i_c": 116169, + // Line 2 — Total qualified business income or (loss). Combine lines 1i through 1v, column (c + "form-8995.0.line.2": 116169, + // Line 4 — Total qualified business income. Combine lines 2 and 3. If zero or less, enter -0 + "form-8995.0.line.4": 116169, + // Line 5 — Qualified business income component. Multiply line 4 by 20% (0.20) + "form-8995.0.line.5": 23234, + // Line 10 — Qualified business income deduction before the income limitation. Add lines 5 an + "form-8995.0.line.10": 23234, + // Line 11 — Taxable income before qualified business income deduction + "form-8995.0.line.11": 100419, + // Line 13 — Subtract line 12 from line 11. If zero or less, enter -0- + "form-8995.0.line.13": 100419, + // Line 14 — Income limitation. Multiply line 13 by 20% (0.20) + "form-8995.0.line.14": 20084, + // Line 15 — Qualified business income deduction. Enter the smaller of line 10 or line 14 + "form-8995.0.line.15": 20084, + }, + }, + "form-1040": { + engineFields: { + // Line 8 — Additional income from Schedule 1, line 10 + "form-1040.line.8": 125000, + // Line 9 — Add lines 1z, 2b, 3b, 4b, 5b, 6b, 7a, and 8. This is your total income + "form-1040.line.9": 125000, + // Line 10 — Adjustments to income from Schedule 1, line 26 + "form-1040.line.10": 8831, + // Line 11a — Subtract line 10 from line 9. This is your adjusted gross income + "form-1040.line.11a": 116169, + // Line 11b — Amount from line 11a (adjusted gross income) + "form-1040.line.11b": 116169, + // Line 12e — Standard deduction or itemized deductions (from Schedule A) + "form-1040.line.12e": 15750, + // Line 13a — Qualified business income deduction from Form 8995 or Form 8995-A + "form-1040.line.13a": 20084, + // Line 14 — Add lines 12e, 13a, and 13b + "form-1040.line.14": 35834, + // Line 15 — Subtract line 14 from line 11b. Taxable income + "form-1040.line.15": 80335, + // Line 16 — Tax (see instructions) + "form-1040.line.16": 12586, + // Line 18 — Add lines 16 and 17 + "form-1040.line.18": 12586, + // Line 22 — Subtract line 21 from line 18. If zero or less, enter -0- + "form-1040.line.22": 12586, + // Line 23 — Other taxes, including self-employment tax, from Schedule 2, line 21 + "form-1040.line.23": 17662, + // Line 24 — Add lines 22 and 23. Total tax + "form-1040.line.24": 30248, + // Line 26 — 2025 estimated tax payments and amount applied from 2024 return + "form-1040.line.26": 26000, + // Line 33 — Add lines 25d, 26, and 32. Total payments + "form-1040.line.33": 26000, + // Line 37 — Amount you owe + "form-1040.line.37": 4248, + }, + }, + "schedule-ca": { + engineFields: { + // Line 6. Farm income or (loss). Column A. Federal Amounts. + "schedule-ca.0.line.b6_federal": 125000, + // Line 6. Column C. Additions. + "schedule-ca.0.line.b6_additions": 648, + // Line 10. Total. Add Section A, line 1z through line 7a, and Section B, line 1 through line + "schedule-ca.2.line.b10_federal": 125000, + // Line 10. Column C. Additions. + "schedule-ca.2.line.b10_additions": 648, + // Line 15. Deductible part of self-employment tax. See instructions. Column A. Federal Amoun + "schedule-ca.2.line.c15_federal": 8831, + // Line 26. Add line 11 through line 23 and line 25 in columns A, B, and C. See instructions. + "schedule-ca.3.line.c26_federal": 8831, + // Line 27. Total. Subtract line 26 from line 10 in columns A, B, and C. See instructions. Co + "schedule-ca.3.line.c27_federal": 116169, + // Line 27. Column C. Additions. + "schedule-ca.3.line.c27_additions": 648, + // Line 30. Enter the larger of the amount on line 29 or your standard deduction shown below: + "schedule-ca.5.page2.total_itemized_30_standard_or_itemized": 5706, + }, + }, + "schedule-p": { + engineFields: { + // Part 1 . Line 1 . If you itemized deductions, go to line 2 . If you did not itemize deduct + "schedule-p.0.line.1_standard_deduction": 5706, + // Line 14 . Total Adjustments and Preferences. Combine line 1 through line 13 . + "schedule-p.0.line.14_total_adjustments_preferences": 5706, + // Line 15 . Enter taxable income from Form 540, line 19 . See instructions. + "schedule-p.0.line.15_taxable_income": 111111, + // Line 19 . Combine line 14 through line 18 . + "schedule-p.1.line.19_combine_lines_14_through_18": 116817, + // Line 21 . Alternative Minimum Taxable Income. Subtract line 20 from line 19 (if married/Re + "schedule-p.1.line.21_alternative_minimum_taxable_income": 116817, + // Part 2 . Line 22 . Exemption Amount. (If this schedule is for a certain child under age 24 + "schedule-p.1.line.22_exemption_amount": 92749, + // Line 23 . Subtract line 22 from line 21 . If zero or less, enter 0 . See instructions. + "schedule-p.1.line.23_amti_less_exemption": 24068, + // Line 24 . Tentative Minimum Tax. Multiply line 23 by 7.0% (.07) + "schedule-p.1.line.24_tentative_minimum_tax": 1685, + // Line 25 . Regular tax before credits from Form 540, line 31 . + "schedule-p.1.line.25_regular_tax_before_credits": 6772, + // Part 3 . Line 1 . Enter the amount from Form 540, line 35 . + "schedule-p.1.part3.1_tax_from_form_540_line_35": 6619, + // Line 2 . Enter the tentative minimum tax from Part 2, line 24 . + "schedule-p.1.part3.2_tentative_minimum_tax": 1685, + // Section A. Line 3 . Subtract line 2 from line 1 . If zero or less enter 0 and see instruct + "schedule-p.1.part3.3_excess_tax_offset_by_credits_col_c": 4934, + // Line 6 . Column A. Credit amount. + "schedule-p.2.part3.6_credit_amount_col_a": 648, + // Line 6 . Column B*. Credit used this year. *If the taxpayer is subject to the business cre + "schedule-p.2.part3.6_credit_used_col_b": 648, + // Line 6 . Column C. Tax balance that may be offset by credits. + "schedule-p.2.part3.6_tax_balance_col_c": 4286, + // Column (d): the credit is used in full. + "schedule-p.2.part3.6_credit_carryover_col_d": 0, + // Section B. Line 11 . If Part 3, line 3 is zero, enter the amount from line 1 . If line 3 i + "schedule-p.2.part3.11_tax_balance_col_c": 5971, + // Line 20: the other state tax credit (Schedule S line 12), used in full. + "schedule-p.3.part3.20_other_state_tax_credit_amount_col_a": 860, + "schedule-p.3.part3.20_other_state_tax_credit_used_col_b": 860, + "schedule-p.3.part3.20_other_state_tax_tax_balance_col_c": 5111, + }, + }, + "schedule-s": { + engineFields: { + // Row 1 . Column (B). Double-taxed income taxable by California. + "schedule-s.0.part1.row1_taxable_by_california_col_b": 20000, + // Row 1 . Column (C). Double-taxed income taxable by other state. + "schedule-s.0.part1.row1_taxable_by_other_state_col_c": 20000, + // Line 1 . Total double-taxed income. Column (B). Double-taxed income taxable by California. + "schedule-s.0.line.1_total_double_taxed_income_col_b": 20000, + // Line 1 . Total double-taxed income. Column (C). Double-taxed income taxable by other state + "schedule-s.0.line.1_total_double_taxed_income_col_c": 20000, + // Part 2 . Line 2 . California tax liability: Form 540 line 35 less FTB 3547's credit. + "schedule-s.0.line.2_california_tax_liability": 5971, + // Line 3 . Double-taxed income taxable by California. Enter the amount from Part 1, line 1, + "schedule-s.0.line.3_double_taxed_income_california": 20000, + // Line 4 . California adjusted gross income. See instructions. + "schedule-s.0.line.4_california_adjusted_gross_income": 116817, + // Line 6 . Multiply line 2 by line 5 . + "schedule-s.0.line.6_california_tax_on_double_taxed_income": 1022, + // Line 7 . Income tax liability paid to other state. Enter amount. + "schedule-s.0.line.7_tax_paid_to_other_state": 860, + // Line 8 . Double-taxed income taxable by other state. Enter the amount from Part 1, line 1, + "schedule-s.0.line.8_double_taxed_income_other_state": 20000, + // Line 9 . Adjusted gross income taxable by other state. See instructions. + "schedule-s.0.line.9_other_state_adjusted_gross_income": 20000, + // Line 11 . Multiply line 7 by line 10 . + "schedule-s.0.line.11_other_state_tax_on_double_taxed_income": 860, + // Line 12 . Other state tax credit. Enter the smaller of line 6 or line 11 . Use Credit Code + "schedule-s.0.line.12_other_state_tax_credit": 860, + }, + renderedText: { + "schedule-s.0.part1.row1_income_item_description_col_a": + "Farm income, St. George fruit stand", + // Lines 5 and 10 are comb boxes with the point printed on the form: 0.1712 and 1.0000. + "schedule-s.0.line.5_california_income_ratio": "01712", + "schedule-s.0.line.7_other_state_abbreviation": "UT", + "schedule-s.0.line.10_other_state_income_ratio": "10000", + }, + }, + "form-3547": { + engineFields: { + // Line 1. Eligible transportation costs. See instructions. + "form-3547.0.line.1_eligible_transportation_costs": 1295, + // Line 2. Current year credit. Multiply line 1 by 50% (.50). + "form-3547.0.line.2_current_year_credit": 648, + // Line 4. Total current year Donated Agricultural Products Transportation Credit. Add line 2 + "form-3547.0.line.4_total_current_year_credit": 648, + // Line 6. Total available Donated Agricultural Products Transportation Credit. Add line 4 an + "form-3547.0.line.6_total_available_credit": 648, + // Line 7a. Credit claimed. Enter the amount of the credit claimed on the current year tax re + "form-3547.0.line.7a_credit_claimed": 648, + // Verified zeros: no K-1 credit or carryover, no corporation or $5,000,000 limit, all used. + "form-3547.0.line.3_pass_through_credit_k1": 0, + "form-3547.0.line.5_credit_carryover_prior_year": 0, + "form-3547.0.line.7b_total_credit_assigned": 0, + "form-3547.0.line.7c_credit_elected_refundable": 0, + "form-3547.0.line.8_credit_carryover_future_years": 0, + }, + }, + "form-540": { + engineFields: { + // Exemptions. For line 7, line 8, line 9, and line 10: Multiply the number you enter in the + "form-540.line.7_personal_exemption_count": 1, + // Multiply the number you put in the line 7 box by $153. Enter this number into this field. + "form-540.line.7_personal_exemption_amount": 153, + // Line 11. Exemption amount: Add line 7 through line 10. Transfer this amount to line 32. Wh + "form-540.line.11_total_exemption_amount": 153, + // Line 13. Enter federal adjusted gross income (A G I) from federal Form 1040 or 1040-SR, li + "form-540.line.13_federal_agi": 116169, + // Line 15. Subtract line 14 from line 13. If less than zero, enter the result in parentheses + "form-540.line.15_ca_agi_before_additions": 116169, + // Line 16. California adjustments – additions. Enter the amount from Schedule CA (540), Part + "form-540.line.16_ca_adjustments_additions": 648, + // Line 17. California adjusted gross income. Combine line 15 and line 16. + "form-540.line.17_ca_agi": 116817, + // Line 18. Enter the larger of your California itemized deductions from Schedule CA (540), P + "form-540.line.18_deductions": 5706, + // Line 19. Subtract line 18 from line 17. This is your taxable income. If less than zero, en + "form-540.line.19_taxable_income": 111111, + // Line 31. Tax amount. + "form-540.line.31_tax_amount": 6772, + // Line 32. Exemption credits. Enter the amount from line 11. If your federal adjusted gross + "form-540.line.32_exemption_credits": 153, + // Line 33. Subtract line 32 from line 31. If less than zero, enter 0. + "form-540.line.33_tax_after_exemption_credits": 6619, + // Line 35. Add line 33 and line 34. + "form-540.line.35_total_tax_after_credits": 6619, + // Line 43. Enter credit amount + "form-540.line.43_credit_amount": 648, + // Line 44. Enter credit amount: the other state tax credit (Schedule S line 12). + "form-540.line.44_credit_amount": 860, + // Line 47. Add line 40 through line 46. These are your total credits. + "form-540.line.47_total_credits": 1508, + // Line 48. Subtract line 47 from line 35. If less than zero, enter 0. + "form-540.line.48_tax_after_credits": 5111, + // Line 64. Add line 48, line 61, line 62, and line 63. This is your total tax. + "form-540.line.64_total_tax": 5111, + // Line 72. 2025 California estimated tax and other payments. See instructions. + "form-540.line.72_ca_estimated_tax_payments": 8000, + // Line 78. Add line 71 through line 77. These are your total payments. See instructions. + "form-540.line.78_total_payments": 8000, + // Overpaid Tax or Tax Due. Line 93 Payments balance. If line 78 is more than line 91, subtra + "form-540.line.93_payments_balance": 8000, + // Line 95. Payments after Individual Shared Responsibility penalty. If line 93 is more than + "form-540.line.95_payments_after_isr_penalty": 8000, + // Line 97. Overpaid tax. If line 95 is more than line 64, subtract line 64 from line 95. + "form-540.line.97_overpaid_tax": 2889, + // Line 99. Overpaid tax available this year. Subtract line 98 from line 97. + "form-540.line.99_overpaid_tax_available": 2889, + // Refund and Direct Deposit. Line 115. Refund or no amount due. Subtract the sum of line 110 + "form-540.line.115_refund_or_no_amount_due": 2889, + }, + renderedText: { + "form-540.line.43_credit_name": "Donated Ag Transportation", + "form-540.line.43_credit_code": "204", + "form-540.line.44_credit_name": "Other State Tax", + "form-540.line.44_credit_code": "187", + }, + renderedBlank: ["form-540.line.45_schedule_p_credits"], + }, +}; + +export function joriExpected(formId: string): ExpectedResults { + const expected = EXPECTED[formId] ?? {}; + return { + engineFields: expected.engineFields ?? {}, + renderedText: expected.renderedText ?? {}, + renderedBlank: expected.renderedBlank ?? [], + renderedChecked: expected.renderedChecked ?? [], + }; +} diff --git a/engine/tests/scenarios/synthetic/jori/facts.ts b/engine/tests/scenarios/synthetic/jori/facts.ts new file mode 100644 index 00000000..7ebff16d --- /dev/null +++ b/engine/tests/scenarios/synthetic/jori/facts.ts @@ -0,0 +1,172 @@ +/* + * A made-up taxpayer (README.md): every name, number and address is invented. + * Jori Tessaly grows citrus near Visalia and sells the fruit to packing + * houses. She trucks her own unsold fruit to a food bank and keeps its + * certificate. No input documents: the facts are the orchard's books, her + * mileage log, her 2024 return and her answers. + */ + +import { + CA_AG_TRANSPORT_KEYS, + CA_PAYMENT_KEYS, + ESTIMATED_TAX_KEYS, + PRIOR_YEAR_KEYS, + makeEstimatedTaxPaymentFactKey, + makeFarmFactKey, + makeOtherStateTaxFactKey, + type CaAgTransportCostsFactValue, + type FarmFactValue, + type OtherStateTaxFactValue, +} from "../../../../src/facts/index.js"; +import type { TaxFactRow } from "../../../../src/facts/rows.js"; +import { identityFact } from "../../../helpers/fixtureBuilders.js"; + +export const JORI_USER_ID = "jori-synthetic"; +export const JORI_TAX_YEAR = 2025; + +const CREATED_AT = "2026-11-28T00:00:00Z"; +const VERBAL = "Stated by Jori, 2026-11-28"; + +const fact = (category: string, key: string, value: unknown, sourceNote: string): TaxFactRow => ({ + id: `f-${key}`, + userId: JORI_USER_ID, + taxYear: JORI_TAX_YEAR, + category, + key, + value, + sourceNote, + createdAt: CREATED_AT, +}); + +const HOME = { street: "18420 Avenue 280", city: "Visalia", state: "CA", zip: "93292" }; + +/* + * Her citrus orchard, cash method, material participation, a profit. No + * depreciation: the trucks and the trees are fully depreciated. Line 19, + * gasoline, fuel and oil, includes the fuel for the food bank runs. + */ +const orchard: FarmFactValue = { + owner: "taxpayer", + activity: "Citrus", + code: "111310", + ein: "00-0003547", + accountingMethod: "cash", + materiallyParticipated: true, + paymentsRequire1099: true, + filedRequired1099: true, + productSales: 240000, + agriculturalProgramPayments: 0, + customHireIncome: 0, + expenses: { + chemicals: 12000, + fertilizersAndLime: 14000, + gasolineFuelAndOil: 18000, + insurance: 5000, + laborHired: 45000, + repairs: 8000, + supplies: 4000, + taxes: 3000, + utilities: 6000, + }, + newDepreciableProperty: false, + w2WagesPaid: 45000, + qualifiedPropertyUbia: 0, +}; + +/* + * Line 1 by the mileage method: 9,250 miles on the food bank runs, from her + * mileage log (ca-3547-form-2025::sec::line-1::b01). The fuel is deducted on + * Schedule F. + */ +const costs: CaAgTransportCostsFactValue = { + method: "mileage", + miles: 9250, + deductedOn: "schedule_f", +}; + +/* + * Utah nonresident return (TC-40 with TC-40B): $20,000 of her farm profit is + * from the winter fruit stand she runs in St. George, a business carried on in + * Utah. Schedule S line 2 is Form 540 line 35 less the FTB 3547 credit + * (ca-540-sched-s-inst-2025::sec::part-ii-figure-your-other-state-tax-credit::b01). + */ +const utah: OtherStateTaxFactValue = { + state: "UT", + items: [ + { + description: "Farm income, St. George fruit stand", + californiaAmount: 20000, + otherStateAmount: 20000, + }, + ], + taxPaid: 860, + otherStateAdjustedGrossIncome: 20000, +}; + +const PAYMENTS: Array<[string, { date: string; amount: number }]> = [ + ["2025-q1", { date: "2025-04-15", amount: 6500 }], + ["2025-q2", { date: "2025-06-16", amount: 6500 }], + ["2025-q3", { date: "2025-09-15", amount: 6500 }], + ["2025-q4", { date: "2026-01-15", amount: 6500 }], +]; + +const idFact = (suffix: string, value: string) => + identityFact({ userId: JORI_USER_ID, taxYear: JORI_TAX_YEAR, suffix, value }); + +export const joriFacts: TaxFactRow[] = [ + idFact("name.first", "Jori"), + idFact("name.last", "Tessaly"), + idFact("ssn", "400-00-0547"), + idFact("dob", "02/09/1969"), + idFact("address.street", HOME.street), + idFact("address.city", HOME.city), + idFact("address.state", HOME.state), + idFact("address.zip", HOME.zip), + idFact("address.county", "Tulare"), + idFact("occupation", "Citrus grower"), + idFact("phone", "559-555-0182"), + fact( + "self_employment", + makeFarmFactKey("avenue-280-citrus"), + orchard, + `${VERBAL}: the orchard's books.`, + ), + fact( + "self_employment", + CA_AG_TRANSPORT_KEYS.costs, + costs, + `${VERBAL}: her mileage log for the food bank runs and the food bank's certificate.`, + ), + fact("other", CA_AG_TRANSPORT_KEYS.carryover, 0, `${VERBAL}: no FTB 3547 in 2024.`), + fact( + "state_local_tax", + makeOtherStateTaxFactKey("ut"), + utah, + `${VERBAL}: from her 2025 Utah TC-40 and TC-40B.`, + ), + ...PAYMENTS.map(([slug, value]) => + fact( + "estimated_payments", + makeEstimatedTaxPaymentFactKey(slug), + value, + `${VERBAL}: IRS Direct Pay confirmation.`, + ), + ), + fact( + "estimated_payments", + ESTIMATED_TAX_KEYS.priorYearOverpaymentApplied, + 0, + `${VERBAL}: no 2024 overpayment applied.`, + ), + fact("estimated_payments", PRIOR_YEAR_KEYS.federalTax, 25000, `${VERBAL}: 2024 return.`), + fact("estimated_payments", PRIOR_YEAR_KEYS.federalAgi, 118000, `${VERBAL}: 2024 Form 1040.`), + fact("estimated_payments", PRIOR_YEAR_KEYS.filedJointReturn, false, `${VERBAL}: single in 2024.`), + fact( + "estimated_payments", + CA_PAYMENT_KEYS.estimatedTax, + 8000, + `${VERBAL}: FTB Web Pay confirmations.`, + ), + fact("health_coverage", "health_coverage.full_year_mec", true, `${VERBAL}: covered all year.`), + fact("use_tax", "use_tax.owed_amount", 0, `${VERBAL}: no out-of-state purchases.`), +]; diff --git a/engine/tests/scenarios/synthetic/jori/index.ts b/engine/tests/scenarios/synthetic/jori/index.ts new file mode 100644 index 00000000..90761da7 --- /dev/null +++ b/engine/tests/scenarios/synthetic/jori/index.ts @@ -0,0 +1,47 @@ +/* + * Made-up taxpayer (README.md): a single full-year California resident who + * grows citrus and trucks unsold fruit to a food bank. FTB 3547 figures her + * credit by the mileage method; Schedule P (540) Section A2 line 6 uses all + * of it. Schedule CA (540) line 6 column C takes the Schedule F deduction for + * the same costs back, and Form 540 line 43 takes the credit. Utah taxed the + * profit of her St. George fruit stand: Schedule S line 2 is Form 540 line 35 + * less the FTB 3547 credit, and line 44 takes the other state tax credit. No answer key: + * the expected values are hand-checked, locked engine output. + */ + +import { lockedGoldenPath } from "../../../helpers/scenarioPdfName.js"; +import type { Scenario } from "../../../types.js"; +import { joriDecisions } from "./decisions.js"; +import { joriExpected } from "./expected.js"; +import { JORI_TAX_YEAR, JORI_USER_ID, joriFacts } from "./facts.js"; + +/* Every form the engine files for these facts, upstreams first. */ +const FORM_IDS = [ + "schedule-f", + "schedule-se", + "schedule-1", + "schedule-2", + "form-8995", + "form-1040", + "schedule-ca", + "schedule-s", + "schedule-p", + "form-3547", + "form-540", +]; + +export const joriScenario: Scenario = { + name: "jori", + description: + "Single Visalia citrus grower with the donated agricultural products transportation credit by the mileage method: FTB 3547 used in full in Schedule P (540) Section A2, Schedule CA (540) line 6 column C, Form 540 line 43, and Schedule S line 2 net of the credit (Utah tax on a fruit stand).", + taxYear: JORI_TAX_YEAR, + userId: JORI_USER_ID, + verification: "unverified", + facts: joriFacts, + decisions: joriDecisions, + forms: FORM_IDS.map((formId) => ({ + formId, + expected: joriExpected(formId), + goldenPdfPath: lockedGoldenPath("jori", formId), + })), +}; diff --git a/engine/tests/scenarios/synthetic/padan/README.md b/engine/tests/scenarios/synthetic/padan/README.md new file mode 100644 index 00000000..7873c183 --- /dev/null +++ b/engine/tests/scenarios/synthetic/padan/README.md @@ -0,0 +1,58 @@ +# padan (synthetic, unverified) + +Padan Vellacourt is a made-up taxpayer. No filed return, benchmark case or +answer key stands behind her values. The lines below were checked by hand +against the forms and their instructions, then the engine's output was locked. + +## Who she is + +- Single, a full-year California resident (Fresno). +- She runs a fresh produce distribution business (Schedule C): $260,000 of + receipts and $123,000 of expenses. Her $31,000 of car and truck expenses + include $14,800 of actual costs for hauling donated produce to two food + banks. Each food bank gave her a certificate. +- She owns part of Kings River Packing LP. Its K-1 passes through a $1,150.40 + donated agricultural products transportation credit. +- Her 2024 FTB 3547 line 8 carried $2,300 to 2025. +- She paid $28,000 of federal and $5,000 of California estimated tax. + +## Documents + +None. The food banks' certificates stay with her (the instructions say to +keep them), and the costs come from her trip log. The K-1 and her 2024 return +are not in the engine: their amounts are her answers. The K-1 income is left +out on purpose: the engine has no California K-1, so this scenario tests the +credit alone (as `javindhra` does). + +## What it covers + +- FTB 3547 lines 1 to 8 by the actual method: her own credit, the K-1 credit + and the carryover. The tax over TMT limits the credit, so line 8 carries the + rest. +- Schedule P (540) Section A2 line 6, code 204 (a Section A2 credit attaches + the schedule). +- Schedule CA (540) line 3 column C (the Schedule C deduction for the same + costs, less line 2) and line 5 column C (the K-1 credit). +- Form 540 line 43: code 204. Lines 44 and 45 stay blank. +- The sister scenario `jori` covers the mileage method, Schedule F, Schedule + CA line 6 and a credit used in full. + +## Hand check + +| Line | Value | How | +| --- | --- | --- | +| Sch C line 31 | 137,000 | 260,000 − 123,000 | +| Sch SE lines 4a, 12, 13 | 126,520; 19,357; 9,679 | 137,000 × 92.35%; × 15.3%; half | +| 1040 line 11a | 127,321 | 137,000 − 9,679 | +| 3547 line 1, 2 | 14,800; 7,400 | actual costs; × 50% | +| 3547 lines 3, 4, 5, 6 | 1,150; 8,550; 2,300; 10,850 | 1,150.40 rounded; 7,400 + 1,150; 2024 line 8; 8,550 + 2,300 | +| Sch CA line 3 col C, line 5 col C | 7,400; 1,150 | 3547 line 2; 3547 line 3 | +| 540 lines 16, 17, 19 | 8,550; 135,871; 130,165 | 7,400 + 1,150; 127,321 + 8,550; less 5,706 | +| 540 lines 31, 33, 35 | 8,544; 8,391; 8,391 | rate schedule; less 153 | +| Sch P lines 21, 23, 24 | 135,871; 43,122; 3,019 | AMTI; less 92,749; × 7% | +| Sch P Part III line 3 | 5,372 | 8,391 − 3,019 | +| Sch P line 6 (a), (b), (c), (d) | 10,850; 5,372; 0; 5,478 | 3547 line 6; smaller of 10,850 and 5,372; 5,372 − 5,372; 10,850 − 5,372 | +| 3547 lines 7a, 7b, 7c, 8 | 5,372; 0; 0; 5,478 | Sch P line 6 (b); not a corporation; line 35 under $5,000,000; 10,850 − 5,372 | +| Sch P line 11 | 3,019 | 3,019 + 0 | +| 540 lines 43, 47, 48 | 5,372; 5,372; 3,019 | code 204; 8,391 − 5,372 | +| 540 lines 72, 97, 115 | 5,000; 1,981; 1,981 | estimated tax; 5,000 − 3,019 | diff --git a/engine/tests/scenarios/synthetic/padan/decisions.ts b/engine/tests/scenarios/synthetic/padan/decisions.ts new file mode 100644 index 00000000..7f0cc0ac --- /dev/null +++ b/engine/tests/scenarios/synthetic/padan/decisions.ts @@ -0,0 +1,30 @@ +/* The made-up taxpayer's answers (README.md). */ + +import type { AIDecisionRow } from "../../../../src/facts/rows.js"; +import { decisionRow } from "../../../helpers/fixtureBuilders.js"; +import { PADAN_TAX_YEAR, PADAN_USER_ID } from "./facts.js"; + +const dec = (key: string, decision: unknown, rationale: string) => + decisionRow({ + userId: PADAN_USER_ID, + taxYear: PADAN_TAX_YEAR, + key, + decision, + rationale, + }); + +export const padanDecisions: AIDecisionRow[] = [ + dec("decisions.scope.must_file_federal", true, "Self-employment income is over the threshold."), + dec("decisions.scope.filing_status", "single", "Not married at the end of 2025."), + dec("decisions.scope.has_digital_assets", false, "No digital asset activity."), + dec("decisions.scope.has_reportable_sales", false, "No sales of stock or other property."), + dec("decisions.scope.has_foreign_financial_account", false, "No foreign accounts."), + dec("decisions.scope.has_foreign_trust", false, "No foreign trust."), + dec("decisions.itemize_vs_standard", "standard", "No itemized deductions."), + dec("decisions.scope.must_file_ca_540", true, "Full-year California resident."), + dec("decisions.scope.ca_residency", "full_year", "Lived in Fresno all of 2025."), + dec("decisions.scope.mailing_same_as_principal_residence", true, "Mailing address is the home."), + dec("decisions.scope.use_tax_zero_reason", "no_use_tax_owed", "No out-of-state purchases."), + dec("decisions.refund.refund_full_overpayment_federal", true, "Refund any overpayment."), + dec("decisions.refund.refund_full_overpayment_ca", true, "Refund any CA overpayment."), +]; diff --git a/engine/tests/scenarios/synthetic/padan/docs/Padan-1040-Golden.pdf b/engine/tests/scenarios/synthetic/padan/docs/Padan-1040-Golden.pdf new file mode 100644 index 00000000..364979a2 Binary files /dev/null and b/engine/tests/scenarios/synthetic/padan/docs/Padan-1040-Golden.pdf differ diff --git a/engine/tests/scenarios/synthetic/padan/docs/Padan-CA540-Golden.pdf b/engine/tests/scenarios/synthetic/padan/docs/Padan-CA540-Golden.pdf new file mode 100644 index 00000000..621d6223 Binary files /dev/null and b/engine/tests/scenarios/synthetic/padan/docs/Padan-CA540-Golden.pdf differ diff --git a/engine/tests/scenarios/synthetic/padan/docs/Padan-Form3547-Golden.pdf b/engine/tests/scenarios/synthetic/padan/docs/Padan-Form3547-Golden.pdf new file mode 100644 index 00000000..a90b6c92 Binary files /dev/null and b/engine/tests/scenarios/synthetic/padan/docs/Padan-Form3547-Golden.pdf differ diff --git a/engine/tests/scenarios/synthetic/padan/docs/Padan-Form8995-Golden.pdf b/engine/tests/scenarios/synthetic/padan/docs/Padan-Form8995-Golden.pdf new file mode 100644 index 00000000..1dd184dd Binary files /dev/null and b/engine/tests/scenarios/synthetic/padan/docs/Padan-Form8995-Golden.pdf differ diff --git a/engine/tests/scenarios/synthetic/padan/docs/Padan-Schedule1-Golden.pdf b/engine/tests/scenarios/synthetic/padan/docs/Padan-Schedule1-Golden.pdf new file mode 100644 index 00000000..dad2bcad Binary files /dev/null and b/engine/tests/scenarios/synthetic/padan/docs/Padan-Schedule1-Golden.pdf differ diff --git a/engine/tests/scenarios/synthetic/padan/docs/Padan-Schedule2-Golden.pdf b/engine/tests/scenarios/synthetic/padan/docs/Padan-Schedule2-Golden.pdf new file mode 100644 index 00000000..0ca546c0 Binary files /dev/null and b/engine/tests/scenarios/synthetic/padan/docs/Padan-Schedule2-Golden.pdf differ diff --git a/engine/tests/scenarios/synthetic/padan/docs/Padan-ScheduleC-Golden.pdf b/engine/tests/scenarios/synthetic/padan/docs/Padan-ScheduleC-Golden.pdf new file mode 100644 index 00000000..62dfcd42 Binary files /dev/null and b/engine/tests/scenarios/synthetic/padan/docs/Padan-ScheduleC-Golden.pdf differ diff --git a/engine/tests/scenarios/synthetic/padan/docs/Padan-ScheduleCA-Golden.pdf b/engine/tests/scenarios/synthetic/padan/docs/Padan-ScheduleCA-Golden.pdf new file mode 100644 index 00000000..b6119100 Binary files /dev/null and b/engine/tests/scenarios/synthetic/padan/docs/Padan-ScheduleCA-Golden.pdf differ diff --git a/engine/tests/scenarios/synthetic/padan/docs/Padan-ScheduleP-Golden.pdf b/engine/tests/scenarios/synthetic/padan/docs/Padan-ScheduleP-Golden.pdf new file mode 100644 index 00000000..eab26e05 Binary files /dev/null and b/engine/tests/scenarios/synthetic/padan/docs/Padan-ScheduleP-Golden.pdf differ diff --git a/engine/tests/scenarios/synthetic/padan/docs/Padan-ScheduleSe-Golden.pdf b/engine/tests/scenarios/synthetic/padan/docs/Padan-ScheduleSe-Golden.pdf new file mode 100644 index 00000000..ae74afc2 Binary files /dev/null and b/engine/tests/scenarios/synthetic/padan/docs/Padan-ScheduleSe-Golden.pdf differ diff --git a/engine/tests/scenarios/synthetic/padan/expected.ts b/engine/tests/scenarios/synthetic/padan/expected.ts new file mode 100644 index 00000000..0ba9624b --- /dev/null +++ b/engine/tests/scenarios/synthetic/padan/expected.ts @@ -0,0 +1,313 @@ +/* + * padan — LOCKED expected values, drafted from the engine's + * output on 2026-11-28 (scripts/draftExpected.ts). + * + * UNVERIFIED: no CPA return or filed-return check stands behind these + * values. They are engine output, checked by hand, so a failure means + * "the engine changed", not "the engine is wrong". + * + * Edit by hand. Change a value only after you verify it against the form + * instructions or a filed return (scripts/compareFiled). + */ + +import type { ExpectedResults } from "../../../types.js"; + +const EXPECTED: Record> = { + "schedule-c": { + engineFields: { + // Line 1 — Gross receipts or sales + "schedule-c.0.line.1": 260000, + // Line 3 — Subtract line 2 from line 1 + "schedule-c.0.line.3": 260000, + // Line 5 — Gross profit. Subtract line 4 from line 3 + "schedule-c.0.line.5": 260000, + // Line 7 — Gross income. Add lines 5 and 6 + "schedule-c.0.line.7": 260000, + // Line 9 — Car and truck expenses + "schedule-c.0.line.9": 31000, + // Line 20b — Rent or lease: Other business property + "schedule-c.0.line.20b": 18000, + // Line 22 — Supplies (not included in Part III) + "schedule-c.0.line.22": 6000, + // Line 23 — Taxes and licenses + "schedule-c.0.line.23": 4000, + // Line 15 — Insurance (other than health) + "schedule-c.0.line.15": 7000, + // Line 25 — Utilities + "schedule-c.0.line.25": 5000, + // Line 26 — Wages (less employment credits) + "schedule-c.0.line.26": 52000, + // Line 28 — Total expenses before expenses for business use of home. Add lines 8 through 27b + "schedule-c.0.line.28": 123000, + // Line 29 — Tentative profit or (loss). Subtract line 28 from line 7 + "schedule-c.0.line.29": 137000, + // Line 31 — Net profit or (loss). Subtract line 30 from line 29 + "schedule-c.0.line.31": 137000, + }, + }, + "schedule-se": { + engineFields: { + // Line 2 — Net profit or (loss) from Schedule C, line 31; and Schedule K-1 (Form 1065), box + "schedule-se.0.line.2": 137000, + // Line 3 — Combine lines 1a, 1b, and 2 + "schedule-se.0.line.3": 137000, + // Line 4a — If line 3 is more than zero, multiply line 3 by 92.35% (0.9235). Otherwise, ente + "schedule-se.0.line.4a": 126520, + // Line 4c — Combine lines 4a and 4b. If less than $400, stop; you don't owe self-employment + "schedule-se.0.line.4c": 126520, + // Line 6 — Add lines 4c and 5b + "schedule-se.0.line.6": 126520, + // Line 9 — Subtract line 8d from line 7. If zero or less, enter -0- + "schedule-se.0.line.9": 176100, + // Line 10 — Multiply the smaller of line 6 or line 9 by 12.4% (0.124) + "schedule-se.0.line.10": 15688, + // Line 11 — Multiply line 6 by 2.9% (0.029) + "schedule-se.0.line.11": 3669, + // Line 12 — Self-employment tax. Add lines 10 and 11 + "schedule-se.0.line.12": 19357, + // Line 13 — Deduction for one-half of self-employment tax. Multiply line 12 by 50% (0.50) + "schedule-se.0.line.13": 9679, + }, + }, + "schedule-1": { + engineFields: { + // Line 3 — Business income or (loss). Attach Schedule C + "schedule-1.0.line.3": 137000, + // Line 10 — Combine lines 1 through 7 and 9. This is your additional income + "schedule-1.0.line.10": 137000, + // Line 15 — Deductible part of self-employment tax (attach Schedule SE) + "schedule-1.1.line.15": 9679, + // Line 26 — Adjustments to income. Add lines 11 through 23 and 25 + "schedule-1.1.line.26": 9679, + }, + }, + "schedule-2": { + engineFields: { + // Line 4 — Self-employment tax. Attach Schedule SE + "schedule-2.0.line.4_self_employment_tax": 19357, + // Line 21 — Add lines 4, 7 through 16, 18, and 19. Total other taxes. Enter here and on Form + "schedule-2.1.line.21_total_other_taxes": 19357, + }, + }, + "form-8995": { + engineFields: { + // Line 1i — (c) Qualified business income or (loss) + "form-8995.0.line.1i_c": 127321, + // Line 2 — Total qualified business income or (loss). Combine lines 1i through 1v, column (c + "form-8995.0.line.2": 127321, + // Line 4 — Total qualified business income. Combine lines 2 and 3. If zero or less, enter -0 + "form-8995.0.line.4": 127321, + // Line 5 — Qualified business income component. Multiply line 4 by 20% (0.20) + "form-8995.0.line.5": 25464, + // Line 10 — Qualified business income deduction before the income limitation. Add lines 5 an + "form-8995.0.line.10": 25464, + // Line 11 — Taxable income before qualified business income deduction + "form-8995.0.line.11": 111571, + // Line 13 — Subtract line 12 from line 11. If zero or less, enter -0- + "form-8995.0.line.13": 111571, + // Line 14 — Income limitation. Multiply line 13 by 20% (0.20) + "form-8995.0.line.14": 22314, + // Line 15 — Qualified business income deduction. Enter the smaller of line 10 or line 14 + "form-8995.0.line.15": 22314, + }, + }, + "form-1040": { + engineFields: { + // Line 8 — Additional income from Schedule 1, line 10 + "form-1040.line.8": 137000, + // Line 9 — Add lines 1z, 2b, 3b, 4b, 5b, 6b, 7a, and 8. This is your total income + "form-1040.line.9": 137000, + // Line 10 — Adjustments to income from Schedule 1, line 26 + "form-1040.line.10": 9679, + // Line 11a — Subtract line 10 from line 9. This is your adjusted gross income + "form-1040.line.11a": 127321, + // Line 11b — Amount from line 11a (adjusted gross income) + "form-1040.line.11b": 127321, + // Line 12e — Standard deduction or itemized deductions (from Schedule A) + "form-1040.line.12e": 15750, + // Line 13a — Qualified business income deduction from Form 8995 or Form 8995-A + "form-1040.line.13a": 22314, + // Line 14 — Add lines 12e, 13a, and 13b + "form-1040.line.14": 38064, + // Line 15 — Subtract line 14 from line 11b. Taxable income + "form-1040.line.15": 89257, + // Line 16 — Tax (see instructions) + "form-1040.line.16": 14555, + // Line 18 — Add lines 16 and 17 + "form-1040.line.18": 14555, + // Line 22 — Subtract line 21 from line 18. If zero or less, enter -0- + "form-1040.line.22": 14555, + // Line 23 — Other taxes, including self-employment tax, from Schedule 2, line 21 + "form-1040.line.23": 19357, + // Line 24 — Add lines 22 and 23. Total tax + "form-1040.line.24": 33912, + // Line 26 — 2025 estimated tax payments and amount applied from 2024 return + "form-1040.line.26": 28000, + // Line 33 — Add lines 25d, 26, and 32. Total payments + "form-1040.line.33": 28000, + // Line 37 — Amount you owe + "form-1040.line.37": 5912, + }, + }, + "schedule-ca": { + engineFields: { + // Line 3 . Business income or (loss). See instructions. Column A. Federal Amounts. + "schedule-ca.0.line.b3_federal": 137000, + // Line 3 . Column C. Additions. + "schedule-ca.0.line.b3_additions": 7400, + // Line 5. Column C. Additions. + "schedule-ca.0.line.b5_additions": 1150, + // Line 10. Total. Add Section A, line 1z through line 7a, and Section B, line 1 through line + "schedule-ca.2.line.b10_federal": 137000, + // Line 10. Column C. Additions. + "schedule-ca.2.line.b10_additions": 8550, + // Line 15. Deductible part of self-employment tax. See instructions. Column A. Federal Amoun + "schedule-ca.2.line.c15_federal": 9679, + // Line 26. Add line 11 through line 23 and line 25 in columns A, B, and C. See instructions. + "schedule-ca.3.line.c26_federal": 9679, + // Line 27. Total. Subtract line 26 from line 10 in columns A, B, and C. See instructions. Co + "schedule-ca.3.line.c27_federal": 127321, + // Line 27. Column C. Additions. + "schedule-ca.3.line.c27_additions": 8550, + // Line 30. Enter the larger of the amount on line 29 or your standard deduction shown below: + "schedule-ca.5.page2.total_itemized_30_standard_or_itemized": 5706, + }, + }, + "schedule-p": { + engineFields: { + // Part 1 . Line 1 . If you itemized deductions, go to line 2 . If you did not itemize deduct + "schedule-p.0.line.1_standard_deduction": 5706, + // Line 14 . Total Adjustments and Preferences. Combine line 1 through line 13 . + "schedule-p.0.line.14_total_adjustments_preferences": 5706, + // Line 15 . Enter taxable income from Form 540, line 19 . See instructions. + "schedule-p.0.line.15_taxable_income": 130165, + // Line 19 . Combine line 14 through line 18 . + "schedule-p.1.line.19_combine_lines_14_through_18": 135871, + // Line 21 . Alternative Minimum Taxable Income. Subtract line 20 from line 19 (if married/Re + "schedule-p.1.line.21_alternative_minimum_taxable_income": 135871, + // Part 2 . Line 22 . Exemption Amount. (If this schedule is for a certain child under age 24 + "schedule-p.1.line.22_exemption_amount": 92749, + // Line 23 . Subtract line 22 from line 21 . If zero or less, enter 0 . See instructions. + "schedule-p.1.line.23_amti_less_exemption": 43122, + // Line 24 . Tentative Minimum Tax. Multiply line 23 by 7.0% (.07) + "schedule-p.1.line.24_tentative_minimum_tax": 3019, + // Line 25 . Regular tax before credits from Form 540, line 31 . + "schedule-p.1.line.25_regular_tax_before_credits": 8544, + // Part 3 . Line 1 . Enter the amount from Form 540, line 35 . + "schedule-p.1.part3.1_tax_from_form_540_line_35": 8391, + // Line 2 . Enter the tentative minimum tax from Part 2, line 24 . + "schedule-p.1.part3.2_tentative_minimum_tax": 3019, + // Section A. Line 3 . Subtract line 2 from line 1 . If zero or less enter 0 and see instruct + "schedule-p.1.part3.3_excess_tax_offset_by_credits_col_c": 5372, + // Line 6 . Column A. Credit amount. + "schedule-p.2.part3.6_credit_amount_col_a": 10850, + // Line 6 . Column B*. Credit used this year. *If the taxpayer is subject to the business cre + "schedule-p.2.part3.6_credit_used_col_b": 5372, + // Line 6 . Column C: the credit uses all of line 3. + "schedule-p.2.part3.6_tax_balance_col_c": 0, + // Line 6 . Column D. Credit carryover. + "schedule-p.2.part3.6_credit_carryover_col_d": 5478, + // Section B. Line 11 . If Part 3, line 3 is zero, enter the amount from line 1 . If line 3 i + "schedule-p.2.part3.11_tax_balance_col_c": 3019, + }, + // Code 204 takes Section A2 line 6: no film or LAMBRA credit comes before it. + renderedText: { + "schedule-p.2.part3.6_credit_code": "204", + "schedule-p.2.part3.6_credit_name": "Donated Ag Transportation", + }, + }, + "form-3547": { + engineFields: { + // Line 1. Eligible transportation costs. See instructions. + "form-3547.0.line.1_eligible_transportation_costs": 14800, + // Line 2. Current year credit. Multiply line 1 by 50% (.50). + "form-3547.0.line.2_current_year_credit": 7400, + // Line 3. Pass-through Donated Agricultural Products Transportation Credit(s) from Schedule + "form-3547.0.line.3_pass_through_credit_k1": 1150, + // Line 4. Total current year Donated Agricultural Products Transportation Credit. Add line 2 + "form-3547.0.line.4_total_current_year_credit": 8550, + // Line 5. Credit carryover from a prior year. + "form-3547.0.line.5_credit_carryover_prior_year": 2300, + // Line 6. Total available Donated Agricultural Products Transportation Credit. Add line 4 an + "form-3547.0.line.6_total_available_credit": 10850, + // Line 7a. Credit claimed. Enter the amount of the credit claimed on the current year tax re + "form-3547.0.line.7a_credit_claimed": 5372, + // Line 7b: not a corporation; line 7c: line 35 is under $5,000,000, so the limit disallows nothing. + "form-3547.0.line.7b_total_credit_assigned": 0, + "form-3547.0.line.7c_credit_elected_refundable": 0, + // Line 8. Credit carryover available for future years. Add lines 7a, 7b, and line 7c, subtra + "form-3547.0.line.8_credit_carryover_future_years": 5478, + }, + renderedText: { + "form-3547.0.header.name_on_return": "Padan Vellacourt", + }, + }, + "form-540": { + engineFields: { + // Exemptions. For line 7, line 8, line 9, and line 10: Multiply the number you enter in the + "form-540.line.7_personal_exemption_count": 1, + // Multiply the number you put in the line 7 box by $153. Enter this number into this field. + "form-540.line.7_personal_exemption_amount": 153, + // Line 11. Exemption amount: Add line 7 through line 10. Transfer this amount to line 32. Wh + "form-540.line.11_total_exemption_amount": 153, + // Line 13. Enter federal adjusted gross income (A G I) from federal Form 1040 or 1040-SR, li + "form-540.line.13_federal_agi": 127321, + // Line 15. Subtract line 14 from line 13. If less than zero, enter the result in parentheses + "form-540.line.15_ca_agi_before_additions": 127321, + // Line 16. California adjustments – additions. Enter the amount from Schedule CA (540), Part + "form-540.line.16_ca_adjustments_additions": 8550, + // Line 17. California adjusted gross income. Combine line 15 and line 16. + "form-540.line.17_ca_agi": 135871, + // Line 18. Enter the larger of your California itemized deductions from Schedule CA (540), P + "form-540.line.18_deductions": 5706, + // Line 19. Subtract line 18 from line 17. This is your taxable income. If less than zero, en + "form-540.line.19_taxable_income": 130165, + // Line 31. Tax amount. + "form-540.line.31_tax_amount": 8544, + // Line 32. Exemption credits. Enter the amount from line 11. If your federal adjusted gross + "form-540.line.32_exemption_credits": 153, + // Line 33. Subtract line 32 from line 31. If less than zero, enter 0. + "form-540.line.33_tax_after_exemption_credits": 8391, + // Line 35. Add line 33 and line 34. + "form-540.line.35_total_tax_after_credits": 8391, + // Line 43. Enter credit amount + "form-540.line.43_credit_amount": 5372, + // Line 47. Add line 40 through line 46. These are your total credits. + "form-540.line.47_total_credits": 5372, + // Line 48. Subtract line 47 from line 35. If less than zero, enter 0. + "form-540.line.48_tax_after_credits": 3019, + // Line 64. Add line 48, line 61, line 62, and line 63. This is your total tax. + "form-540.line.64_total_tax": 3019, + // Line 72. 2025 California estimated tax and other payments. See instructions. + "form-540.line.72_ca_estimated_tax_payments": 5000, + // Line 78. Add line 71 through line 77. These are your total payments. See instructions. + "form-540.line.78_total_payments": 5000, + // Overpaid Tax or Tax Due. Line 93 Payments balance. If line 78 is more than line 91, subtra + "form-540.line.93_payments_balance": 5000, + // Line 95. Payments after Individual Shared Responsibility penalty. If line 93 is more than + "form-540.line.95_payments_after_isr_penalty": 5000, + // Line 97. Overpaid tax. If line 95 is more than line 64, subtract line 64 from line 95. + "form-540.line.97_overpaid_tax": 1981, + // Line 99. Overpaid tax available this year. Subtract line 98 from line 97. + "form-540.line.99_overpaid_tax_available": 1981, + // Refund and Direct Deposit. Line 115. Refund or no amount due. Subtract the sum of line 110 + "form-540.line.115_refund_or_no_amount_due": 1981, + }, + // One other credit: line 43 holds it by name and code; lines 44 and 45 stay blank. + renderedText: { + "form-540.line.43_credit_name": "Donated Ag Transportation", + "form-540.line.43_credit_code": "204", + }, + renderedBlank: ["form-540.line.44_credit_amount", "form-540.line.45_schedule_p_credits"], + }, +}; + +export function padanExpected(formId: string): ExpectedResults { + const expected = EXPECTED[formId] ?? {}; + return { + engineFields: expected.engineFields ?? {}, + renderedText: expected.renderedText ?? {}, + renderedBlank: expected.renderedBlank ?? [], + renderedChecked: expected.renderedChecked ?? [], + }; +} diff --git a/engine/tests/scenarios/synthetic/padan/facts.ts b/engine/tests/scenarios/synthetic/padan/facts.ts new file mode 100644 index 00000000..08774fa3 --- /dev/null +++ b/engine/tests/scenarios/synthetic/padan/facts.ts @@ -0,0 +1,170 @@ +/* + * A made-up taxpayer (README.md): every name, number and address is invented. + * Padan Vellacourt runs a fresh produce distribution business in Fresno. She + * hauls growers' surplus produce to two food banks and keeps each food bank's + * certificate. No input documents: the facts are her business's books and + * trip log, the K-1 statement as she reads it, her 2024 return and her + * answers. The K-1 partnership's income is left out: the engine has no + * California K-1, so this scenario tests the credit alone. + */ + +import { + CA_AG_TRANSPORT_KEYS, + CA_EMPLOYEE_CLASSIFICATION_KEYS, + CA_PAYMENT_KEYS, + ESTIMATED_TAX_KEYS, + PRIOR_YEAR_KEYS, + makeBusinessFactKey, + makeCaAgTransportPassThroughFactKey, + makeEstimatedTaxPaymentFactKey, + type BusinessFactValue, + type CaAgTransportCostsFactValue, + type CaAgTransportPassThroughFactValue, +} from "../../../../src/facts/index.js"; +import type { TaxFactRow } from "../../../../src/facts/rows.js"; +import { identityFact } from "../../../helpers/fixtureBuilders.js"; + +export const PADAN_USER_ID = "padan-synthetic"; +export const PADAN_TAX_YEAR = 2025; + +const CREATED_AT = "2026-11-28T00:00:00Z"; +const VERBAL = "Stated by Padan, 2026-11-28"; + +const fact = (category: string, key: string, value: unknown, sourceNote: string): TaxFactRow => ({ + id: `f-${key}`, + userId: PADAN_USER_ID, + taxYear: PADAN_TAX_YEAR, + category, + key, + value, + sourceNote, + createdAt: CREATED_AT, +}); + +const HOME = { street: "5318 North Teilman Avenue", city: "Fresno", state: "CA", zip: "93711" }; + +/* + * Her produce distribution business (Schedule C). She distributes growers' + * produce on commission, so she sells no goods of her own. Line 9 car and + * truck expenses include the $14,800 of trips to the food banks. + */ +const distribution: BusinessFactValue = { + owner: "taxpayer", + activity: "Fresh produce distribution", + code: "424480", + name: "Vellacourt Produce Distributors", + address: { street: "2210 East Olive Avenue", city: "Fresno", state: "CA", zip: "93701" }, + accountingMethod: "cash", + materiallyParticipated: true, + startedThisYear: false, + paymentsRequire1099: false, + sellsGoods: false, + grossReceipts: 260000, + expenses: { + carAndTruck: 31000, + wages: 52000, + rentOtherProperty: 18000, + supplies: 6000, + utilities: 5000, + insurance: 7000, + taxesAndLicenses: 4000, + }, + specifiedService: false, + w2WagesPaid: 52000, + qualifiedPropertyUbia: 0, +}; + +/* + * Line 1: the actual costs of the food bank trips (fuel, a hired driver's + * meals on the overnight runs, tolls), from her trip log. No depreciation or + * insurance (ca-3547-form-2025::sec::d-definitions::b01). She deducted them on + * Schedule C line 9. + */ +const costs: CaAgTransportCostsFactValue = { + method: "actual", + actualCosts: 14800, + deductedOn: "schedule_c", +}; + +/* Line 3: a packing partnership she owns part of also hauled donated produce and passed its credit through. */ +const passThrough: CaAgTransportPassThroughFactValue = { + entityName: "Kings River Packing LP", + entityId: "202110738214", + credit: 1150.4, +}; + +const PAYMENTS: Array<[string, { date: string; amount: number }]> = [ + ["2025-q1", { date: "2025-04-15", amount: 7000 }], + ["2025-q2", { date: "2025-06-16", amount: 7000 }], + ["2025-q3", { date: "2025-09-15", amount: 7000 }], + ["2025-q4", { date: "2026-01-15", amount: 7000 }], +]; + +const K1 = "Schedule K-1 (565) from Kings River Packing LP and its statement"; + +const idFact = (suffix: string, value: string) => + identityFact({ userId: PADAN_USER_ID, taxYear: PADAN_TAX_YEAR, suffix, value }); + +export const padanFacts: TaxFactRow[] = [ + idFact("name.first", "Padan"), + idFact("name.last", "Vellacourt"), + idFact("ssn", "400-00-3547"), + idFact("dob", "08/22/1976"), + idFact("address.street", HOME.street), + idFact("address.city", HOME.city), + idFact("address.state", HOME.state), + idFact("address.zip", HOME.zip), + idFact("address.county", "Fresno"), + idFact("occupation", "Produce distributor"), + idFact("phone", "559-555-0147"), + fact( + "self_employment", + makeBusinessFactKey("vellacourt-produce"), + distribution, + `${VERBAL}: her books for Vellacourt Produce Distributors.`, + ), + fact( + "self_employment", + CA_EMPLOYEE_CLASSIFICATION_KEYS.classifiedAsEmployee, + false, + `${VERBAL}: she owns the business; no one classifies her as an employee.`, + ), + fact( + "self_employment", + CA_AG_TRANSPORT_KEYS.costs, + costs, + `${VERBAL}: her trip log for the food bank runs and the two food banks' certificates.`, + ), + fact( + "state_local_tax", + makeCaAgTransportPassThroughFactKey("kings-river-packing"), + passThrough, + `${K1}.`, + ), + fact("other", CA_AG_TRANSPORT_KEYS.carryover, 2300, "Her filed 2024 FTB 3547, line 8."), + ...PAYMENTS.map(([slug, value]) => + fact( + "estimated_payments", + makeEstimatedTaxPaymentFactKey(slug), + value, + `${VERBAL}: IRS Direct Pay confirmation.`, + ), + ), + fact( + "estimated_payments", + ESTIMATED_TAX_KEYS.priorYearOverpaymentApplied, + 0, + `${VERBAL}: no 2024 overpayment applied.`, + ), + fact("estimated_payments", PRIOR_YEAR_KEYS.federalTax, 24000, `${VERBAL}: 2024 return.`), + fact("estimated_payments", PRIOR_YEAR_KEYS.federalAgi, 128000, `${VERBAL}: 2024 Form 1040.`), + fact("estimated_payments", PRIOR_YEAR_KEYS.filedJointReturn, false, `${VERBAL}: single in 2024.`), + fact( + "estimated_payments", + CA_PAYMENT_KEYS.estimatedTax, + 5000, + `${VERBAL}: FTB Web Pay confirmations.`, + ), + fact("health_coverage", "health_coverage.full_year_mec", true, `${VERBAL}: covered all year.`), + fact("use_tax", "use_tax.owed_amount", 0, `${VERBAL}: no out-of-state purchases.`), +]; diff --git a/engine/tests/scenarios/synthetic/padan/index.ts b/engine/tests/scenarios/synthetic/padan/index.ts new file mode 100644 index 00000000..1f8b85b5 --- /dev/null +++ b/engine/tests/scenarios/synthetic/padan/index.ts @@ -0,0 +1,45 @@ +/* + * Made-up taxpayer (README.md): a single full-year California resident who + * distributes fresh produce and hauls donated produce to food banks. FTB 3547 + * adds her own credit on the actual costs, a partnership's pass-through credit + * and a 2024 carryover; Schedule P (540) Section A2 line 6 uses part of it and + * line 8 carries the rest. Schedule CA (540) lines 3 and 5 column C take the + * deduction for the same costs back, and Form 540 line 43 takes the credit. No + * answer key: the expected values are hand-checked, locked engine output. + */ + +import { lockedGoldenPath } from "../../../helpers/scenarioPdfName.js"; +import type { Scenario } from "../../../types.js"; +import { padanDecisions } from "./decisions.js"; +import { padanExpected } from "./expected.js"; +import { PADAN_TAX_YEAR, PADAN_USER_ID, padanFacts } from "./facts.js"; + +/* Every form the engine files for these facts, upstreams first. */ +const FORM_IDS = [ + "schedule-c", + "schedule-se", + "schedule-1", + "schedule-2", + "form-8995", + "form-1040", + "schedule-ca", + "schedule-p", + "form-3547", + "form-540", +]; + +export const padanScenario: Scenario = { + name: "padan", + description: + "Single Fresno produce distributor with the donated agricultural products transportation credit (actual costs, a K-1 credit, a 2024 carryover): FTB 3547 line 7a from Schedule P (540) Section A2 line 6, a carryover on line 8, Schedule CA (540) lines 3 and 5 column C, Form 540 line 43.", + taxYear: PADAN_TAX_YEAR, + userId: PADAN_USER_ID, + verification: "unverified", + facts: padanFacts, + decisions: padanDecisions, + forms: FORM_IDS.map((formId) => ({ + formId, + expected: padanExpected(formId), + goldenPdfPath: lockedGoldenPath("padan", formId), + })), +}; diff --git a/engine/tests/unit/state/ca/3547/creditUsed.test.ts b/engine/tests/unit/state/ca/3547/creditUsed.test.ts new file mode 100644 index 00000000..3011289e --- /dev/null +++ b/engine/tests/unit/state/ca/3547/creditUsed.test.ts @@ -0,0 +1,109 @@ +/* + * FTB 3547's credit offered to Schedule P (540) (state/ca/3547/creditUsed.ts) + * and the Schedule CA (540) amounts (deductionReduction.ts), from a filing + * info built by hand: the return gaps and the $5,000,000 edge. + */ + +import { describe, expect, it } from "vitest"; +import { + agTransportCreditOffered, + agTransportReturnGap, +} from "../../../../../src/state/ca/3547/creditUsed.js"; +import { agTransportDeductionReduction } from "../../../../../src/state/ca/3547/deductionReduction.js"; +import type { Form3547FilingInfo } from "../../../../../src/state/ca/3547/filingInfo.js"; + +const ok = (value: boolean) => ({ ok: true as const, value, rule: "t", triggeredByFactKeys: [] }); + +function infoOf(overrides: Partial = {}, forms: string[] = ["form-540"]) { + const mustFile = Object.fromEntries( + ["form-3547", ...forms].map((formId) => [formId, ok(true)]), + ) as unknown as Form3547FilingInfo["mustFile"]; + return { + mustFile, + agTransportCosts: 14800, + agTransportDeductedOn: "schedule_c", + agTransportThroughSmllc: false, + agTransportPassThroughRows: [{ factKey: "k", entityName: "A", entityId: "1", credit: 1150.4 }], + agTransportCarryover: 2300, + ...overrides, + } as Form3547FilingInfo; +} + +const readTax = (line35: number | undefined) => (fieldId: string) => + fieldId === "form-540.line.35_total_tax_after_credits" ? line35 : undefined; + +const reasonOf = (result: unknown) => (result as { reason?: string } | undefined)?.reason ?? ""; + +describe("FTB 3547 credit offered to Schedule P (540)", () => { + it("is line 6 on a Form 540 return", () => { + expect(agTransportCreditOffered(readTax(8391), infoOf())).toBe(10850); + }); + + it("is 0 with no FTB 3547 or a line 6 of 0", () => { + const none = { mustFile: {} } as Form3547FilingInfo; + expect(agTransportCreditOffered(readTax(8391), none)).toBe(0); + const zero = infoOf({ + agTransportCosts: 0, + agTransportPassThroughRows: [], + agTransportCarryover: 0, + }); + expect(agTransportCreditOffered(readTax(8391), zero)).toBe(0); + }); + + it("waits while an amount or Form 540 line 35 waits", () => { + expect( + agTransportCreditOffered(readTax(8391), infoOf({ agTransportCarryover: undefined })), + ).toBeUndefined(); + expect(agTransportCreditOffered(readTax(undefined), infoOf())).toBeUndefined(); + }); + + it("is a gap above $5,000,000 of line 35, and not at it", () => { + expect(agTransportCreditOffered(readTax(5_000_000), infoOf())).toBe(10850); + expect(reasonOf(agTransportCreditOffered(readTax(5_000_001), infoOf()))).toContain( + "$5,000,000", + ); + }); + + it("is a gap on Form 540NR, without Form 540, and through a disregarded SMLLC", () => { + expect(reasonOf(agTransportReturnGap(infoOf({}, ["form-540nr"])))).toContain("Form 540NR"); + expect(reasonOf(agTransportReturnGap(infoOf({}, [])))).toContain("Form 541"); + expect(reasonOf(agTransportReturnGap(infoOf({ agTransportThroughSmllc: true })))).toContain( + "single member LLC", + ); + expect(agTransportReturnGap(infoOf())).toBeUndefined(); + }); +}); + +describe("FTB 3547 deduction reduction on Schedule CA (540) column C", () => { + it("puts line 2 on the line of the stated schedule and line 3 on line 5", () => { + const onC = infoOf(); + expect(agTransportDeductionReduction(onC, "line3")).toBe(7400); + expect(agTransportDeductionReduction(onC, "line6")).toBe(0); + expect(agTransportDeductionReduction(onC, "line5")).toBe(1150); + const onF = infoOf({ agTransportDeductedOn: "schedule_f" }); + expect(agTransportDeductionReduction(onF, "line3")).toBe(0); + expect(agTransportDeductionReduction(onF, "line6")).toBe(7400); + const none = infoOf({ agTransportDeductedOn: "not_deducted" }); + expect(agTransportDeductionReduction(none, "line3")).toBe(0); + expect(agTransportDeductionReduction(none, "line6")).toBe(0); + }); + + it("is 0 with no FTB 3547 and waits while the lines wait", () => { + expect(agTransportDeductionReduction({ mustFile: {} } as Form3547FilingInfo, "line3")).toBe(0); + expect( + agTransportDeductionReduction(infoOf({ agTransportCosts: undefined }), "line3"), + ).toBeUndefined(); + expect( + agTransportDeductionReduction(infoOf({ agTransportDeductedOn: undefined }), "line6"), + ).toBeUndefined(); + }); + + it("the two together equal line 4, the amount the instructions name", () => { + const info = infoOf(); + const total = + (agTransportDeductionReduction(info, "line3") ?? 0) + + (agTransportDeductionReduction(info, "line5") ?? 0) + + (agTransportDeductionReduction(info, "line6") ?? 0); + expect(total).toBe(8550); + }); +}); diff --git a/engine/tests/unit/state/ca/3547/form.test.ts b/engine/tests/unit/state/ca/3547/form.test.ts new file mode 100644 index 00000000..5bc6a3b0 --- /dev/null +++ b/engine/tests/unit/state/ca/3547/form.test.ts @@ -0,0 +1,331 @@ +/* + * FTB 3547 on a whole return: who files, what it asks, line 7a from Schedule + * P (540) Section A2, line 8, the gaps, the Schedule CA (540) column C + * amounts, Form 540 line 43 and Schedule S line 2, and "no facts, nothing + * changes". The synthetic padan scenario is the base; jori is the second. + */ + +import { describe, expect, it } from "vitest"; +import { + CA_AG_TRANSPORT_KEYS, + isCaAgTransportPassThroughFactKey, + makeCaAgTransportPassThroughFactKey, + type CaAgTransportCostsFactValue, + type CaAgTransportPassThroughFactValue, +} from "../../../../../src/facts/index.js"; +import type { AIDecisionRow, TaxFactRow } from "../../../../../src/facts/rows.js"; +import { evaluateScenario } from "../../../../../src/index.js"; +import { decisionRow } from "../../../../helpers/fixtureBuilders.js"; +import { domonScenario } from "../../../../scenarios/synthetic/domon/index.js"; +import { joriScenario } from "../../../../scenarios/synthetic/jori/index.js"; +import { kirunaScenario } from "../../../../scenarios/synthetic/kiruna/index.js"; +import { lyrelleScenario } from "../../../../scenarios/synthetic/lyrelle/index.js"; +import { padanScenario as base } from "../../../../scenarios/synthetic/padan/index.js"; +import { shemerinScenario } from "../../../../scenarios/synthetic/shemerin/index.js"; +import type { Scenario } from "../../../../types.js"; + +const decision = (scenario: Scenario, key: string, value: unknown): AIDecisionRow => + decisionRow({ + userId: scenario.userId, + taxYear: scenario.taxYear, + key, + decision: value, + rationale: "t", + }); + +const withDecision = (key: string, value: unknown, scenario: Scenario = base) => [ + ...scenario.decisions.filter((each) => each.decisionKey !== key), + decision(scenario, key, value), +]; + +const row = (scenario: Scenario, category: string, key: string, value: unknown): TaxFactRow => ({ + id: `f-${key}`, + userId: scenario.userId, + taxYear: scenario.taxYear, + category, + key, + value, + sourceNote: "test", + createdAt: "2026-11-28T00:00:00Z", +}); + +const isAgKey = (key: string) => + key === CA_AG_TRANSPORT_KEYS.costs || + key === CA_AG_TRANSPORT_KEYS.carryover || + isCaAgTransportPassThroughFactKey(key); +const withoutAg = (facts: TaxFactRow[]) => facts.filter((fact) => !isAgKey(fact.key)); + +const K1 = { entityName: "Tulare Basin Growers Co-op LP", entityId: "202210552817" }; + +/* The scenario's facts with FTB 3547's replaced; null leaves a key unstated. */ +function withAg(opts: { + scenario?: Scenario; + costs?: Partial | null; + carryover?: number | null; + rows?: Array<[string, Partial]>; +}): TaxFactRow[] { + const scenario = opts.scenario ?? base; + const facts = withoutAg(scenario.facts); + if (opts.costs !== null) { + const costs = opts.costs ?? { method: "actual", actualCosts: 0, deductedOn: "not_deducted" }; + facts.push(row(scenario, "self_employment", CA_AG_TRANSPORT_KEYS.costs, costs)); + } + for (const [slug, value] of opts.rows ?? []) { + const key = makeCaAgTransportPassThroughFactKey(slug); + facts.push(row(scenario, "state_local_tax", key, value)); + } + if (opts.carryover !== null) { + facts.push(row(scenario, "other", CA_AG_TRANSPORT_KEYS.carryover, opts.carryover ?? 0)); + } + return facts; +} + +function evaluate( + facts: TaxFactRow[], + decisions: AIDecisionRow[] = base.decisions, + scenario: Scenario = base, +) { + const result = evaluateScenario({ + filing: { id: "form-3547-test", taxYear: scenario.taxYear }, + facts, + decisions, + authEmail: null, + }); + const files = (formId: string) => { + const form = result.forms.get(formId); + return form?.mustFile.ok ? form.mustFile.value : undefined; + }; + const field = (formId: string, id: string) => + result.forms.get(formId)?.fields.find((each) => each.fieldId === `${formId}.${id}`)?.result; + const value = (formId: string, id: string) => { + const found = field(formId, id); + return found?.ok ? found.value : undefined; + }; + const line = (id: string) => value("form-3547", `0.line.${id}`); + const form540 = (id: string) => value("form-540", `line.${id}`); + const missing = result.forms.get("form-3547")?.missingInputs ?? []; + return { files, field, value, line, form540, missing }; +} + +const isGap = (result: unknown) => + (result as { unsupported?: boolean } | undefined)?.unsupported === true; +const reasonOf = (result: unknown) => (result as { reason?: string } | undefined)?.reason ?? ""; + +describe("FTB 3547 who files", () => { + it("files with padan's facts, attaches Schedule P (540) and asks nothing", () => { + const run = evaluate(base.facts); + expect(run.files("form-3547")).toBe(true); + expect(run.files("schedule-p")).toBe(true); + expect(run.missing).toEqual([]); + }); + + it("files with costs alone, a K-1 credit alone, or a carryover alone", () => { + const costs = evaluate( + withAg({ costs: { method: "mileage", miles: 1000, deductedOn: "not_deducted" } }), + ); + expect(costs.files("form-3547")).toBe(true); + expect([ + costs.line("1_eligible_transportation_costs"), + costs.line("2_current_year_credit"), + ]).toEqual([140, 70]); + const k1 = evaluate(withAg({ rows: [["co-op", { ...K1, credit: 300 }]] })); + expect(k1.files("form-3547")).toBe(true); + expect(k1.line("3_pass_through_credit_k1")).toBe(300); + const carry = evaluate(withAg({ carryover: 800 })); + expect(carry.files("form-3547")).toBe(true); + expect(carry.line("6_total_available_credit")).toBe(800); + }); + + it("does not file with costs of 0, a K-1 credit of 0 and no carryover", () => { + const run = evaluate(withAg({ rows: [["zero", { ...K1, credit: 0 }]] })); + expect(run.files("form-3547")).toBe(false); + expect(run.missing).toEqual([]); + }); + + it("does not file without a California return, or when the decision says no", () => { + const no540 = withDecision("decisions.scope.must_file_ca_540", false); + expect(evaluate(base.facts, no540).files("form-3547")).toBe(false); + const no = withDecision("decisions.scope.must_file_3547", false); + expect(evaluate(base.facts, no).files("form-3547")).toBe(false); + }); + + it("asks for the costs and the carryover when not stated, and for a row that is not complete", () => { + const run = evaluate( + withAg({ costs: null, carryover: null, rows: [["partial", { entityName: "Half Done LP" }]] }), + ); + expect(run.files("form-3547")).toBe(true); + expect(run.missing).toEqual([ + CA_AG_TRANSPORT_KEYS.costs, + makeCaAgTransportPassThroughFactKey("partial"), + CA_AG_TRANSPORT_KEYS.carryover, + ]); + expect(run.line("6_total_available_credit")).toBeUndefined(); + expect(run.line("7a_credit_claimed")).toBeUndefined(); + expect(run.line("8_credit_carryover_future_years")).toBeUndefined(); + }); + + it("asks for the costs while the method's amount or where they were deducted is missing", () => { + for (const costs of [ + { method: "mileage", deductedOn: "schedule_c" }, + { method: "actual", miles: 500, deductedOn: "schedule_c" }, + { method: "actual", actualCosts: 500 }, + ] as Array>) { + const run = evaluate(withAg({ costs, carryover: 100 })); + expect(run.files("form-3547")).toBe(true); + expect(run.missing).toContain(CA_AG_TRANSPORT_KEYS.costs); + } + }); +}); + +describe("FTB 3547 line 7a and Schedule P (540) Section A2", () => { + it("padan: the credit stops at the tax over TMT and the rest carries on line 8", () => { + const run = evaluate(base.facts); + expect(run.value("schedule-p", "1.part3.3_excess_tax_offset_by_credits_col_c")).toBe(5372); + expect(run.value("schedule-p", "2.part3.6_credit_code")).toBe("204"); + expect(run.value("schedule-p", "2.part3.6_credit_amount_col_a")).toBe(10850); + expect(run.value("schedule-p", "2.part3.6_credit_used_col_b")).toBe(5372); + expect(run.value("schedule-p", "2.part3.6_tax_balance_col_c")).toBe(0); + expect(run.value("schedule-p", "2.part3.6_credit_carryover_col_d")).toBe(5478); + expect(run.line("7a_credit_claimed")).toBe(5372); + expect(run.line("7b_total_credit_assigned")).toBe(0); + expect(run.line("7c_credit_elected_refundable")).toBe(0); + expect(run.line("8_credit_carryover_future_years")).toBe(5478); + expect(run.form540("43_credit_amount")).toBe(5372); + expect(run.form540("48_tax_after_credits")).toBe(3019); + }); + + it("jori: the whole credit is used and nothing carries", () => { + const run = evaluate(joriScenario.facts, joriScenario.decisions, joriScenario); + expect(run.line("6_total_available_credit")).toBe(648); + expect(run.line("7a_credit_claimed")).toBe(648); + expect(run.line("8_credit_carryover_future_years")).toBe(0); + expect(run.value("schedule-p", "2.part3.6_credit_carryover_col_d")).toBe(0); + }); + + it("a line 6 of 0 claims 0 and carries 0", () => { + const decisions = withDecision("decisions.scope.must_file_3547", true); + const run = evaluate(withAg({}), decisions); + expect(run.line("6_total_available_credit")).toBe(0); + expect(run.line("7a_credit_claimed")).toBe(0); + expect(run.line("8_credit_carryover_future_years")).toBe(0); + }); + + it("takes the Section A2 line after the LAMBRA credit (shemerin)", () => { + const costs = { method: "actual", actualCosts: 2000, deductedOn: "not_deducted" } as const; + const facts = withAg({ scenario: shemerinScenario, costs }); + const run = evaluate(facts, shemerinScenario.decisions, shemerinScenario); + expect(run.value("schedule-p", "2.part3.6_credit_code")).toBe("198"); + expect(run.value("schedule-p", "2.part3.7_credit_code")).toBe("204"); + expect(run.value("schedule-p", "2.part3.7_credit_amount_col_a")).toBe(1000); + expect(run.line("7a_credit_claimed")).toBe( + run.value("schedule-p", "2.part3.7_credit_used_col_b"), + ); + }); + + it("takes the Section A2 line after FTB 3541's two credits (lyrelle)", () => { + const costs = { method: "actual", actualCosts: 2000, deductedOn: "not_deducted" } as const; + const facts = withAg({ scenario: lyrelleScenario, costs }); + const run = evaluate(facts, lyrelleScenario.decisions, lyrelleScenario); + expect(run.value("schedule-p", "2.part3.8_credit_code")).toBe("204"); + expect(run.line("7a_credit_claimed")).toBe( + run.value("schedule-p", "2.part3.8_credit_used_col_b"), + ); + }); +}); + +describe("FTB 3547 gaps", () => { + it("a credit from a disregarded SMLLC is a gap on line 7a, line 8 and Form 540", () => { + const costs = { + method: "actual", + actualCosts: 14800, + deductedOn: "schedule_c", + throughDisregardedSmllc: true, + } as const; + const run = evaluate(withAg({ costs, carryover: 0 })); + expect(isGap(run.field("form-3547", "0.line.7a_credit_claimed"))).toBe(true); + expect(reasonOf(run.field("form-3547", "0.line.7a_credit_claimed"))).toContain( + "single member LLC", + ); + expect(isGap(run.field("form-3547", "0.line.8_credit_carryover_future_years"))).toBe(true); + expect(isGap(run.field("form-540", "line.47_total_credits"))).toBe(true); + expect(run.line("6_total_available_credit")).toBe(7400); + }); + + it("an explicit decision that Schedule P (540) does not file makes line 7a a gap", () => { + const decisions = withDecision("decisions.scope.must_file_schedule_p", false); + const run = evaluate(base.facts, decisions); + expect(reasonOf(run.field("form-3547", "0.line.7a_credit_claimed"))).toContain( + "Schedule P (540) does not file", + ); + }); +}); + +describe("Schedule CA (540) column C: the deduction for the same costs", () => { + it("padan: line 3 takes line 2 (Schedule C) and line 5 takes line 3 (the K-1)", () => { + const run = evaluate(base.facts); + expect(run.value("schedule-ca", "0.line.b3_additions")).toBe(7400); + expect(run.value("schedule-ca", "0.line.b5_additions")).toBe(1150); + expect(run.value("schedule-ca", "0.line.b6_additions")).toBeUndefined(); + expect(run.form540("16_ca_adjustments_additions")).toBe(8550); + }); + + it("jori: line 6 takes line 2 (Schedule F)", () => { + const run = evaluate(joriScenario.facts, joriScenario.decisions, joriScenario); + expect(run.value("schedule-ca", "0.line.b6_additions")).toBe(648); + expect(run.value("schedule-ca", "0.line.b3_additions")).toBeUndefined(); + }); + + it("costs that were not deducted change no Schedule CA line", () => { + const costs = { method: "actual", actualCosts: 14800, deductedOn: "not_deducted" } as const; + const run = evaluate(withAg({ costs, carryover: 0 })); + expect(run.line("2_current_year_credit")).toBe(7400); + expect(run.value("schedule-ca", "0.line.b3_additions")).toBeUndefined(); + expect(run.form540("16_ca_adjustments_additions")).toBe(0); + }); + + it("a K-1 credit on a return that files FTB 3801 makes line 5 column C a gap (kiruna)", () => { + const rows: Array<[string, Partial]> = [ + ["co-op", { ...K1, credit: 300 }], + ]; + const facts = withAg({ scenario: kirunaScenario, rows }); + const run = evaluate(facts, kirunaScenario.decisions, kirunaScenario); + expect(run.files("form-3801")).toBe(true); + expect(reasonOf(run.field("schedule-ca", "0.line.b5_additions"))).toContain("FTB 3801"); + }); +}); + +describe("Schedule S line 2 leaves the credit out (domon)", () => { + it("is Form 540 line 35 less the credit taken", () => { + const before = evaluate(domonScenario.facts, domonScenario.decisions, domonScenario); + const costs = { method: "actual", actualCosts: 2000, deductedOn: "not_deducted" } as const; + const facts = withAg({ scenario: domonScenario, costs }); + const after = evaluate(facts, domonScenario.decisions, domonScenario); + const used = after.line("7a_credit_claimed") as number; + expect(used).toBe(1000); + const line2 = (run: typeof before) => + run.value("schedule-s", "0.line.2_california_tax_liability") as number; + expect(line2(after)).toBe(line2(before) - used); + }); + + it("jori: line 2 is Form 540 line 35 less line 7a, and line 6 follows it", () => { + const run = evaluate(joriScenario.facts, joriScenario.decisions, joriScenario); + expect(run.form540("35_total_tax_after_credits")).toBe(6619); + expect(run.line("7a_credit_claimed")).toBe(648); + expect(run.value("schedule-s", "0.line.2_california_tax_liability")).toBe(5971); + expect(run.value("schedule-s", "0.line.6_california_tax_on_double_taxed_income")).toBe(1022); + expect(run.form540("44_credit_amount")).toBe(860); + }); +}); + +describe("FTB 3547: no facts, nothing changes", () => { + it("without FTB 3547's facts the form does not file and padan's return has no credit", () => { + const run = evaluate(withoutAg(base.facts)); + expect(run.files("form-3547")).toBe(false); + expect(run.value("schedule-ca", "0.line.b3_additions")).toBeUndefined(); + expect(run.value("schedule-ca", "0.line.b5_additions")).toBeUndefined(); + expect(run.form540("16_ca_adjustments_additions")).toBe(0); + expect(reasonOf(run.field("form-540", "line.43_credit_amount"))).toContain( + "No ingestion path for user-supplied special credits", + ); + }); +}); diff --git a/engine/tests/unit/state/ca/3547/lines.test.ts b/engine/tests/unit/state/ca/3547/lines.test.ts new file mode 100644 index 00000000..d6b5f640 --- /dev/null +++ b/engine/tests/unit/state/ca/3547/lines.test.ts @@ -0,0 +1,115 @@ +/* + * FTB 3547 arithmetic (state/ca/3547/lines.ts). The 2025 form and its + * instructions (ca-3547-form-2025) publish no example with numbers, so these + * are the form's own rules and their limits. + */ + +import { describe, expect, it } from "vitest"; +import { + actualCosts, + AG_TRANSPORT_CREDIT_CODE, + ASSIGNED_CREDIT_OF_AN_INDIVIDUAL, + BUSINESS_CREDIT_LIMIT, + CREDIT_RATE, + line2, + line3, + line4, + line5, + line6, + line8, + MILEAGE_RATE, + mileageCosts, +} from "../../../../../src/state/ca/3547/lines.js"; + +describe("FTB 3547 constants", () => { + it("are the form's: 50%, 14 cents a mile, $5,000,000, code 204, 0 for an individual", () => { + expect(CREDIT_RATE).toBe(0.5); + expect(MILEAGE_RATE).toBe(0.14); + expect(BUSINESS_CREDIT_LIMIT).toBe(5_000_000); + expect(AG_TRANSPORT_CREDIT_CODE).toBe("204"); + expect(ASSIGNED_CREDIT_OF_AN_INDIVIDUAL).toBe(0); + }); +}); + +describe("FTB 3547 line 1", () => { + it("multiplies the miles by $.14 and rounds to the nearest dollar", () => { + expect(mileageCosts(9250)).toBe(1295); + expect(mileageCosts(1000)).toBe(140); + // 1,003 × 0.14 = 140.42 → 140; 1,004 × 0.14 = 140.56 → 141. + expect(mileageCosts(1003)).toBe(140); + expect(mileageCosts(1004)).toBe(141); + expect(mileageCosts(0)).toBe(0); + }); + + it("takes the actual costs in whole dollars, never below 0", () => { + expect(actualCosts(14800)).toBe(14800); + expect(actualCosts(1234.5)).toBe(1235); + expect(actualCosts(1234.49)).toBe(1234); + expect(actualCosts(-50)).toBe(0); + }); +}); + +describe("FTB 3547 line 2", () => { + it("is half of line 1, to the nearest dollar", () => { + expect(line2(14800)).toBe(7400); + // 1,295 × 50% = 647.50 → 648. + expect(line2(1295)).toBe(648); + expect(line2(1)).toBe(1); + expect(line2(0)).toBe(0); + }); + + it("is never more than line 1", () => { + for (const costs of [0, 1, 3, 999, 1295, 14800]) + expect(line2(costs)).toBeLessThanOrEqual(costs); + }); +}); + +describe("FTB 3547 lines 3 to 6", () => { + it("line 3 adds the K-1 credits with their cents and rounds only the total", () => { + expect(line3([1150.4])).toBe(1150); + // 400.30 + 300.30 = 700.60 → 701; each rounded first would give 700. + expect(line3([400.3, 300.3])).toBe(701); + expect(line3([])).toBe(0); + }); + + it("line 4 is line 2 plus line 3, line 6 is line 4 plus line 5", () => { + expect(line4(7400, 1150)).toBe(8550); + expect(line6(8550, 2300)).toBe(10850); + expect(line6(line4(0, 0), 0)).toBe(0); + }); + + it("line 5 is last year's line 8 in whole dollars, never below 0", () => { + expect(line5(2300)).toBe(2300); + expect(line5(99.5)).toBe(100); + expect(line5(-10)).toBe(0); + }); +}); + +describe("FTB 3547 line 8", () => { + it("is line 6 less lines 7a, 7b and 7c: padan carries 5,478", () => { + expect(line8(10850, 5372, 0, 0)).toBe(5478); + }); + + it("is 0 when the credit is used in full, and never below 0", () => { + expect(line8(648, 648, 0, 0)).toBe(0); + expect(line8(100, 150, 0, 0)).toBe(0); + }); + + it("keeps the part the tax could not use, and leaves out the part elected refundable", () => { + // All of line 6 unused: the whole credit carries. + expect(line8(5000, 0, 0, 0)).toBe(5000); + expect(line8(6_000_000, 5_000_000, 0, 600_000)).toBe(400_000); + }); + + it("with lines 7a to 7c and line 8 always adding back to line 6", () => { + const cases: Array<[number, number, number]> = [ + [10850, 5372, 0], + [648, 648, 0], + [9000, 0, 0], + [6_000_000, 5_000_000, 1_000_000], + ]; + for (const [available, used, refundable] of cases) { + expect(used + refundable + line8(available, used, 0, refundable)).toBe(available); + } + }); +});