import { ExternalRef } from "@classytic/primitives/reference"; //#region src/input-credit.d.ts /** The host document an entry came from — so a refused one can be opened and fixed. */ interface PurchaseDocumentRef { readonly sourceModel: string; readonly sourceId: string; } /** One purchase document, per tax rate, as the register projects it. */ interface PurchaseRegisterEntry { readonly source: PurchaseDocumentRef; /** * The document LINE this entry is (with `source`, its identity). Rate, base and tax are facts ON the * line, so correcting a rate changes the entry rather than creating a second one. A document derived * from another (a bill raised from a purchase order) carries the ORIGINAL line's source and key, so * both share one claim balance. Absent: the entry is the document's rate bucket. */ readonly lineKey?: string | undefined; /** The document's own date — its tax period is where the credit originates. */ readonly documentDate: Date; /** The evidence held: the pack names the kinds (tax invoice, customs declaration, …). */ readonly document: { readonly kind: string; readonly number?: string | undefined; }; readonly supplier: { readonly name?: string | undefined; readonly address?: string | undefined; readonly taxId?: string | undefined; /** The supplier's own record — where a refusal it causes is fixed. */ readonly ref?: ExternalRef | undefined; /** The supplier's tax standing in the pack's vocabulary; `unknown` when not stated. */ readonly standing: string; /** A reseller of imported goods: the customs declaration its invoice must cite, if any. */ readonly importer?: { readonly declarationNumber?: string | undefined; } | undefined; }; readonly origin: 'local' | 'import'; /** The recorded tax base. Absent when the document did not record it — never reconstructed. */ readonly taxableValue?: number | undefined; /** The creditable tax on the document at `ratePercent` (supplementary or excise duties excluded). */ readonly tax: number; readonly ratePercent: number; /** What the filer uses the input for, in the pack's vocabulary; `unknown` when not stated. */ readonly use: string; /** A pack category the law excludes (vehicles, entertainment, …). */ readonly category?: string | undefined; } /** * Where a blocker is fixed: the purchase `document`, the `supplier`'s record, the `filer`'s own * registration details, or `none` — a bar the law imposes that no correction lifts. */ type InputCreditFixOn = 'document' | 'supplier' | 'filer' | 'none'; /** A named reason a document gives no credit. `clause` is the citation; `fixOn` says where it is fixed. */ interface InputCreditBlocker { readonly code: string; readonly clause: string; readonly detail: string; readonly fixOn: InputCreditFixOn; } type InputCreditVerdict = { readonly outcome: 'claimable'; readonly credit: number; } | { readonly outcome: 'blocked'; readonly credit: 0; readonly blockers: readonly InputCreditBlocker[]; }; /** The jurisdiction's rules, applied to one entry claimed in `claimPeriod` (`YYYY-MM`). */ interface InputCreditJudge { judge(entry: PurchaseRegisterEntry, claimPeriod: string): InputCreditVerdict; } /** The stable identity of a register entry — one document line. */ declare function registerEntryKey(entry: Pick): string; /** One entry's credit as this return would claim it. */ interface ClaimableEntry { readonly entryKey: string; readonly source: PurchaseDocumentRef; readonly ratePercent: number; /** What the law allows on the entry now. */ readonly eligible: number; /** What THIS return claims — `eligible` less what other returns already claimed or hold. */ readonly credit: number; /** The tax period the document belongs to (`YYYY-MM`). */ readonly originPeriod: string; /** The tax period the claim is attributed to (`YYYY-MM`). */ readonly claimPeriod: string; } interface RegisterCredit { /** Claimable tax per rate, highest rate first. */ readonly byRate: ReadonlyArray<{ readonly ratePercent: number; readonly tax: number; }>; readonly claimed: number; /** The worklist: every refused document with its blockers. */ readonly blocked: ReadonlyArray<{ readonly source: PurchaseDocumentRef; /** The supplier's record, when the register knows it — where a `fixOn: 'supplier'` blocker is fixed. */ readonly supplier?: ExternalRef | undefined; readonly tax: number; readonly blockers: readonly InputCreditBlocker[]; }>; /** Every entry this return claims, with its identity, origin and claim month — what a claim reserves. */ readonly claimable: readonly ClaimableEntry[]; /** Entries whose whole credit another return already claimed or holds. */ readonly alreadyClaimed: ReadonlyArray<{ readonly entryKey: string; readonly source: PurchaseDocumentRef; readonly eligible: number; }>; } interface CreditFromRegisterOptions { /** The claim month for an entry — e.g. the latest month of a quarterly return still inside its window. */ readonly claimPeriodOf?: ((entry: PurchaseRegisterEntry) => string) | undefined; /** The document's own tax period (`YYYY-MM`), to report origin months. */ readonly periodOf: (date: Date) => string; /** Credit still available to THIS return per entry key (claim balances). Absent: everything is available. */ readonly available?: ((entryKey: string) => number) | undefined; } /** * Judge every entry; claim what is eligible AND still available (a partial claim is legal); sum by rate; * list refused documents with their reasons and fully-claimed ones separately. */ /** * Entries sharing one identity are ONE credit (two bills raised from one purchase order): their tax adds, * their base adds only when every part recorded one. The first entry's facts stand for the rest. */ declare function mergeRegisterEntries(entries: readonly PurchaseRegisterEntry[]): PurchaseRegisterEntry[]; declare function creditFromRegister(entries: readonly PurchaseRegisterEntry[], judge: InputCreditJudge, claimPeriod: string, options?: CreditFromRegisterOptions): RegisterCredit; /** One purchase line's input tax as posting values it. */ interface InputTaxCreditQuery { /** The rate the supplier charged, percent (15 = 15%). */ readonly ratePercent: number; /** The document's date — the pack's rules are effective-dated. */ readonly asOf: Date; /** The account the purchase is booked to, when known — a pack may bar credit by what was bought. */ readonly bookedTo?: string | undefined; } /** * The share of a purchase's input tax the pack CREDITS to an input-tax head; the rest is capitalised into * what was bought. `1` — fully creditable; `0` — none (a sales tax, a barred input); between — partial * recovery. Every posting of one purchase (receipt accrual, bill, return, credit note) asks the same port. * A rate the pack cannot place THROWS — a guessed share posts a plausible, wrong cost. */ interface InputTaxCreditability { creditableShare(query: InputTaxCreditQuery): number; } /** A jurisdiction with no input credit (a sales tax, Malaysia SST): every input tax is cost. */ declare const NO_INPUT_CREDIT: InputTaxCreditability; /** The creditable minor units of `taxMinor` at `share`, rounded once. Refuses a share outside [0, 1]. */ declare function creditableInputTax(taxMinor: number, share: number): number; /** The minor units of `taxMinor` that are NOT creditable at `share` — what joins the cost. */ declare function nonCreditableInputTax(taxMinor: number, share: number): number; /** * What a claim OPERATION does to an entry's balance. `reduce` (the document shrank) and `disallow` (a * statutory adjustment) never release credit for reuse; `release` returns a draft's reservation. */ type ClaimOperationKind = 'reserve' | 'release' | 'commit' | 'supersede' | 'reduce' | 'disallow'; /** One entry's claim balance. Invariant: `reserved + committed <= eligible - disallowed - reduced`. */ interface CreditClaimBalance { readonly entryKey: string; readonly eligible: number; readonly reserved: number; readonly committed: number; readonly disallowed: number; readonly reduced: number; } /** The deterministic id of an operation: one per (filing version, entry, kind) — a retry is the same op. */ declare function claimOperationId(filingKey: string, entryKey: string, kind: ClaimOperationKind): string; /** Credit an entry still offers a return that already holds `ownHeld` of it (its reservation or earlier commitment). */ declare function availableCredit(balance: CreditClaimBalance, ownHeld?: number): number; //#endregion export { ClaimOperationKind, ClaimableEntry, CreditClaimBalance, CreditFromRegisterOptions, InputCreditBlocker, InputCreditFixOn, InputCreditJudge, InputCreditVerdict, InputTaxCreditQuery, InputTaxCreditability, NO_INPUT_CREDIT, PurchaseDocumentRef, PurchaseRegisterEntry, RegisterCredit, availableCredit, claimOperationId, creditFromRegister, creditableInputTax, mergeRegisterEntries, nonCreditableInputTax, registerEntryKey };