@things-factory/invoice 10.1.278 → 10.1.280

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/package.json +25 -9
  2. package/dist-client/bootstrap.js.map +0 -1
  3. package/dist-client/document/document-amount.js.map +0 -1
  4. package/dist-client/document/document-defaults.js.map +0 -1
  5. package/dist-client/document/document-form.js.map +0 -1
  6. package/dist-client/document/document-lines.js.map +0 -1
  7. package/dist-client/document/document-party.js.map +0 -1
  8. package/dist-client/document/document-preview.js.map +0 -1
  9. package/dist-client/document/document-print.js.map +0 -1
  10. package/dist-client/entity360/invoice-360.js.map +0 -1
  11. package/dist-client/index.js.map +0 -1
  12. package/dist-client/invoice-attach.js.map +0 -1
  13. package/dist-client/invoice-files.js.map +0 -1
  14. package/dist-client/invoice-preview.js.map +0 -1
  15. package/dist-client/pages/invoice-editor.js.map +0 -1
  16. package/dist-client/pages/invoice-list.js.map +0 -1
  17. package/dist-client/route.js.map +0 -1
  18. package/dist-client/tsconfig.tsbuildinfo +0 -1
  19. package/dist-client/viewparts/document-defaults-setting-let.js.map +0 -1
  20. package/dist-server/index.js.map +0 -1
  21. package/dist-server/role-tasks.js.map +0 -1
  22. package/dist-server/routes.js.map +0 -1
  23. package/dist-server/service/document-defaults/document-defaults-resolver.js.map +0 -1
  24. package/dist-server/service/document-defaults/document-defaults-rules.js.map +0 -1
  25. package/dist-server/service/document-defaults/index.js.map +0 -1
  26. package/dist-server/service/index.js.map +0 -1
  27. package/dist-server/service/invoice/commercial-document.js.map +0 -1
  28. package/dist-server/service/invoice/index.js.map +0 -1
  29. package/dist-server/service/invoice/invoice-document-file.js.map +0 -1
  30. package/dist-server/service/invoice/invoice-files.js.map +0 -1
  31. package/dist-server/service/invoice/invoice-mutation.js.map +0 -1
  32. package/dist-server/service/invoice/invoice-query.js.map +0 -1
  33. package/dist-server/service/invoice/invoice-read.js.map +0 -1
  34. package/dist-server/service/invoice/invoice-remaining.js.map +0 -1
  35. package/dist-server/service/invoice/invoice-rules.js.map +0 -1
  36. package/dist-server/service/invoice/invoice-service.js.map +0 -1
  37. package/dist-server/service/invoice/invoice-status.js.map +0 -1
  38. package/dist-server/service/invoice/invoice-subject.js.map +0 -1
  39. package/dist-server/service/invoice/invoice-type.js.map +0 -1
  40. package/dist-server/service/invoice/invoice.js.map +0 -1
  41. package/dist-server/service/invoice-event/index.js.map +0 -1
  42. package/dist-server/service/invoice-event/invoice-event-query.js.map +0 -1
  43. package/dist-server/service/invoice-event/invoice-event.js.map +0 -1
  44. package/dist-server/service/invoice-item/index.js.map +0 -1
  45. package/dist-server/service/invoice-item/invoice-item-query.js.map +0 -1
  46. package/dist-server/service/invoice-item/invoice-item.js.map +0 -1
  47. package/dist-server/tsconfig.tsbuildinfo +0 -1
  48. package/dist-server/work-doors.js.map +0 -1
  49. package/dist-shared/currency-digits.js.map +0 -1
  50. package/dist-shared/document-amounts.js.map +0 -1
  51. package/dist-shared/document-money.js.map +0 -1
  52. package/dist-shared/document-print.js.map +0 -1
  53. package/dist-shared/document-start.js.map +0 -1
  54. package/dist-shared/invoice-standing.js.map +0 -1
  55. package/dist-shared/screen-money.js.map +0 -1
  56. package/shared/currency-digits.ts +0 -18
  57. package/shared/document-amounts.ts +0 -226
  58. package/shared/document-money.ts +0 -33
  59. package/shared/document-print.ts +0 -131
  60. package/shared/document-start.ts +0 -46
  61. package/shared/invoice-standing.ts +0 -87
  62. package/shared/screen-money.ts +0 -26
  63. package/tsconfig.shared.json +0 -18
  64. package/tsconfig.shared.tsbuildinfo +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"file":"work-doors.js","sourceRoot":"","sources":["../server/work-doors.ts"],"names":[],"mappings":";;AAAA,yDAA6D;AAE7D;;;GAGG;AACH,IAAA,6BAAiB,EAAC;IAChB,EAAE,IAAI,EAAE,uBAAuB,EAAE,MAAM,EAAE,CAAC,eAAe,EAAE,eAAe,EAAE,cAAc,EAAE,aAAa,EAAE,oBAAoB,CAAC,EAAE;CACnI,CAAC,CAAA","sourcesContent":["import { registerWorkDoors } from '@things-factory/auth-base'\n\n/*\n * The work this module does through its doors that a report of one's week takes in by itself (ADR-0185 decision 6,\n * Q5): The invoices written, issued and voided. Each name is a translation key of this module.\n */\nregisterWorkDoors([\n { work: 'work.invoice.invoices', fields: ['createInvoice', 'updateInvoice', 'issueInvoice', 'voidInvoice', 'changeInvoiceFiles'] }\n])\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"currency-digits.js","sourceRoot":"","sources":["../shared/currency-digits.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;AAOH,wCAGC;AARD;;;;GAIG;AACH,SAAgB,cAAc,CAAC,QAAiB;IAC9C,IAAI,OAAO,QAAQ,KAAK,QAAQ,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,iBAAiB,CAAC,UAAU,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC;QAAE,OAAO,SAAS,CAAA;IAC5I,OAAO,IAAI,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,CAAC,CAAC,eAAe,EAAE,CAAC,qBAAqB,CAAA;AAC7G,CAAC","sourcesContent":["/*\n * How many decimal places each currency is written and reckoned with — the one place this is decided.\n *\n * No imports: the invoice server, its screens, accounting and the apps that write amounts all read this file, and a\n * screen's unit test must not pull in i18n or the framework to get one number. It builds to `dist-shared`\n * (`tsconfig.shared.json`), which a server rebuild does not empty, and is reached through the package's own name,\n * `@things-factory/invoice/dist-shared/currency-digits.js`.\n */\n\n/**\n * Decimal places of a currency — 0 for KRW and JPY, 2 for USD, 3 for KWD — as the platform's currency data has\n * them. Undefined for anything that is not a three-letter code the platform knows; the caller decides whether that\n * is a refusal or an amount written plainly.\n */\nexport function currencyDigits(currency: unknown): number | undefined {\n if (typeof currency !== 'string' || !/^[A-Z]{3}$/.test(currency) || !Intl.supportedValuesOf('currency').includes(currency)) return undefined\n return new Intl.NumberFormat('en', { style: 'currency', currency }).resolvedOptions().maximumFractionDigits\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"document-amounts.js","sourceRoot":"","sources":["../shared/document-amounts.ts"],"names":[],"mappings":";;;AA+EA,oCAUC;AAGD,wCAEC;AAqCD,0CA4EC;AA/MD,6DAAqD;AAsBxC,QAAA,SAAS,GAA2B,CAAC,SAAS,EAAE,YAAY,EAAE,QAAQ,CAAC,CAAA;AAoDpF;;;;GAIG;AACH,SAAgB,YAAY,CAAC,MAAW;IACtC,MAAM,KAAK,GAAG,CAAC,KAAc,EAAE,EAAE,CAAC,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,EAAE,CAAA;IACvF,OAAO,CACL,CAAC,MAAM,CAAC,MAAM,EAAE,WAAW,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE;QACzC,KAAK,CAAC,MAAM,EAAE,SAAS,CAAC;QACxB,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE;QAClC,KAAK,CAAC,MAAM,EAAE,iBAAiB,CAAC;QAChC,CAAC,KAAK,CAAC,MAAM,EAAE,QAAQ,CAAC,IAAI,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QAC1D,CAAC,KAAK,CAAC,MAAM,EAAE,QAAQ,CAAC,IAAI,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAC3D,CAAA;AACH,CAAC;AAED,uHAAuH;AACvH,SAAgB,cAAc,CAAC,OAAkC,EAAE,QAAQ,GAAG,EAAE;IAC9E,OAAO,OAAO,KAAK,YAAY,IAAI,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAA;AACxE,CAAC;AAED,MAAM,SAAS,GAAG,GAAG,IAAI,GA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CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IAC3M,KAAK,MAAM,EAAE,KAAK,EAAE,IAAI,WAAW,EAAE,CAAC;QACpC,IAAI,IAAI,IAAI,EAAE;YAAE,MAAK;QACrB,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,CAAA;QAClB,IAAI,IAAI,EAAE,CAAA;IACZ,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC","sourcesContent":["import { currencyDigits } from './currency-digits.js'\n\n/*\n * A commercial document's arithmetic - the one place it is decided, read by the invoice and quotation services when a\n * document is saved and by their screens while it is typed, so a line's supply and the totals on screen are the\n * ones the document will keep (ADR-0120 decision 4).\n *\n * - Lines carry supply and a tax kind and rate; the tax is reckoned once per (kind, rate) group: the group's supply\n * total × rate ÷ 100, rounded half-up to the currency's minor unit. The document tax is the sum of the groups.\n * - A discount of the whole document comes off the lines' supply before tax (ADR-0170 decision 8): it is spread over\n * the groups in proportion to each group's supply, in minor units, the remainder going one unit at a time to the\n * groups whose share was cut most (largest remainder), so the parts add up to the discount exactly. Each group's\n * tax is reckoned on its supply after its part.\n * - Everything is counted in integers: quantities, prices and rates to four decimals, money in minor units.\n * - A received document keeps the tax its sender printed on each line; nothing recomputes it.\n *\n * No imports but the currency's digits and no throwing: a line that cannot be reckoned says why (`problem`), and is\n * left out of the totals. The server refuses such a document; a screen shows the rest while the line is typed.\n */\n\nexport type TaxKindCode = 'TAXABLE' | 'ZERO_RATED' | 'EXEMPT'\n\nexport const TAX_KINDS: readonly TaxKindCode[] = ['TAXABLE', 'ZERO_RATED', 'EXEMPT']\n\nexport interface DocumentLine {\n description?: string | null\n quantity?: number | string | null\n unitPrice?: number | string | null\n discount?: number | string | null\n taxKind?: string | null\n taxRate?: number | string | null\n /** The tax the sender printed on the line - only on a received document. */\n receivedTaxAmount?: number | string | null\n}\n\n/** Why a line cannot be reckoned - the server's refusal codes, `invoice-<problem>`. */\nexport type LineProblem = 'item-description-required' | 'item-invalid' | 'discount-exceeds' | 'amount-too-large' | 'received-tax-required'\n\nexport interface ReckonedLine {\n /** The line's supply - quantity × unit price, less the discount - in the currency. Absent when the line has a problem. */\n supplyAmount?: number\n /** The tax the sender printed, on a received document. */\n receivedTaxAmount?: number | null\n problem?: LineProblem\n}\n\nexport interface TaxGroup {\n taxKind: string\n taxRate: number\n supplyAmount: number\n taxAmount: number\n}\n\n/** Why the discount of the whole document cannot be taken - the server's refusal code, `invoice-<problem>`. */\nexport type DiscountProblem = 'document-discount-invalid'\n\nexport interface DocumentAmounts {\n lines: ReckonedLine[]\n /** Each group's supply after its part of the document discount, and its tax. */\n taxGroups: TaxGroup[]\n /** The lines' supply before the document discount. */\n lineSupplyAmount: number\n /** The discount of the whole document taken off the lines' supply - none when it has a problem. */\n discountAmount: number\n /** A discount below zero, past the lines' supply or finer than the currency's minor unit; it is not taken. */\n discountProblem?: DiscountProblem\n /** The lines' supply less the document discount - the supply tax is reckoned on. */\n supplyAmount: number\n taxAmount: number\n totalAmount: number\n /** The totals pass the largest amount a document may carry. */\n tooLarge: boolean\n}\n\n/**\n * A row added and not typed into: no item, no price, unit or printed tax, and only what `settleLine` fills - a\n * quantity of one, no discount. Such a row is left out; a row typed into without its item is kept, and the save is\n * refused naming its row rather than the row vanishing from the document and its totals.\n */\nexport function untouchedRow(record: any): boolean {\n const blank = (value: unknown) => value === undefined || value === null || value === ''\n return (\n !String(record?.description ?? '').trim() &&\n blank(record?.unitPrice) &&\n !String(record?.unit ?? '').trim() &&\n blank(record?.receivedTaxAmount) &&\n (blank(record?.quantity) || Number(record.quantity) === 1) &&\n (blank(record?.discount) || Number(record.discount) === 0)\n )\n}\n\n/** The rate a tax kind takes unless the person writes another: the standard VAT for a taxable line, none otherwise. */\nexport function defaultTaxRate(taxKind: string | null | undefined, standard = 10): number {\n return taxKind === 'ZERO_RATED' || taxKind === 'EXEMPT' ? 0 : standard\n}\n\nconst MAX_MINOR = 10n ** 14n\nconst SCALE = 10_000n\n\nconst numberOf = (value: unknown): number => (typeof value === 'number' ? value : value === null || value === undefined || value === '' ? NaN : Number(value))\n\n/** A number with at most four decimals, as an integer of ten-thousandths; undefined when it has more. */\nfunction scaled(value: unknown): bigint | undefined {\n const number = numberOf(value)\n if (!Number.isFinite(number)) return undefined\n const whole = Math.round(number * 10_000)\n return Math.abs(number * 10_000 - whole) > 1e-6 ? undefined : BigInt(whole)\n}\n\nfunction minorOf(value: unknown, digits: number): bigint | undefined {\n const number = numberOf(value)\n if (!Number.isFinite(number)) return undefined\n const factor = 10 ** digits\n const whole = Math.round(number * factor)\n return Math.abs(number * factor - whole) > 1e-6 ? undefined : BigInt(whole)\n}\n\n/** numerator ÷ denominator, rounded half-up; both non-negative. */\nfunction divideHalfUp(numerator: bigint, denominator: bigint): bigint {\n return (numerator * 2n + denominator) / (denominator * 2n)\n}\n\nconst amountOf = (minor: bigint, digits: number) => Number(minor) / 10 ** digits\n\n/**\n * Each line's supply, the tax of each (kind, rate) group and the document totals, in the currency (whose digits must\n * be known - `currencyDigits`). `received` keeps the line tax the sender printed; otherwise the groups reckon it. A\n * blank discount is none; a blank quantity, price, kind or rate is a line not yet reckonable. `discountAmount` is the\n * discount of the whole document; a blank one is none. On a received document it lowers the supply, and the tax stays\n * as printed.\n */\nexport function documentAmounts(lines: readonly DocumentLine[], currency: string, received = false, discountAmount: unknown = 0): DocumentAmounts {\n const digits = currencyDigits(currency) ?? 0\n const factor = 10n ** BigInt(digits)\n const groups = new Map<string, { taxKind: string; rate: bigint; supply: bigint; tax: bigint }>()\n\n const reckoned = lines.map((line): ReckonedLine => {\n const quantity = scaled(line.quantity)\n const unitPrice = scaled(line.unitPrice)\n const rate = scaled(line.taxRate)\n const discount = line.discount === null || line.discount === undefined || line.discount === '' ? 0n : minorOf(line.discount, digits)\n const kind = String(line.taxKind ?? '')\n if (!String(line.description ?? '').trim()) return { problem: 'item-description-required' }\n if (\n quantity === undefined ||\n unitPrice === undefined ||\n rate === undefined ||\n discount === undefined ||\n quantity <= 0n ||\n unitPrice < 0n ||\n discount < 0n ||\n rate < 0n ||\n rate > 100n * SCALE ||\n !TAX_KINDS.includes(kind as TaxKindCode) ||\n (kind !== 'TAXABLE' && rate !== 0n)\n ) {\n return { problem: 'item-invalid' }\n }\n\n const gross = divideHalfUp(quantity * unitPrice * factor, SCALE * SCALE)\n if (discount > gross) return { problem: 'discount-exceeds' }\n const supply = gross - discount\n if (supply > MAX_MINOR) return { problem: 'amount-too-large' }\n\n let printed: bigint | undefined\n if (received) {\n printed = line.receivedTaxAmount === null || line.receivedTaxAmount === undefined || line.receivedTaxAmount === '' ? undefined : minorOf(line.receivedTaxAmount, digits)\n if (printed === undefined || printed < 0n) return { supplyAmount: amountOf(supply, digits), problem: 'received-tax-required' }\n }\n\n const key = `${kind}:${rate}`\n const group = groups.get(key) ?? { taxKind: kind, rate, supply: 0n, tax: 0n }\n group.supply += supply\n if (printed !== undefined) group.tax += printed\n groups.set(key, group)\n\n return { supplyAmount: amountOf(supply, digits), receivedTaxAmount: printed === undefined ? null : amountOf(printed, digits) }\n })\n\n const kept = [...groups.values()]\n const lineSupply = kept.reduce((sum, group) => sum + group.supply, 0n)\n const asked = discountAmount === null || discountAmount === undefined || discountAmount === '' ? 0n : minorOf(discountAmount, digits)\n const discountProblem: DiscountProblem | undefined = asked === undefined || asked < 0n || asked > lineSupply ? 'document-discount-invalid' : undefined\n const discount = discountProblem ? 0n : asked!\n const parts = shares(discount, kept.map(group => group.supply))\n\n let supply = 0n\n let tax = 0n\n const taxGroups = kept.map((group, index) => {\n group.supply -= parts[index]\n if (!received) group.tax = divideHalfUp(group.supply * group.rate, 100n * SCALE)\n supply += group.supply\n tax += group.tax\n return { taxKind: group.taxKind, taxRate: Number(group.rate) / 10_000, supplyAmount: amountOf(group.supply, digits), taxAmount: amountOf(group.tax, digits) }\n })\n\n return {\n lines: reckoned,\n taxGroups,\n lineSupplyAmount: amountOf(lineSupply, digits),\n discountAmount: amountOf(discount, digits),\n ...(discountProblem ? { discountProblem } : {}),\n supplyAmount: amountOf(supply, digits),\n taxAmount: amountOf(tax, digits),\n totalAmount: amountOf(supply + tax, digits),\n tooLarge: lineSupply > MAX_MINOR || supply + tax > MAX_MINOR\n }\n}\n\n/**\n * `total` split in proportion to `weights`, in whole units: each its share cut down, then the units left over one\n * at a time to the largest cut-off remainders (the first of equal ones first), so the parts add up to `total`.\n */\nfunction shares(total: bigint, weights: readonly bigint[]): bigint[] {\n const whole = weights.reduce((sum, weight) => sum + weight, 0n)\n if (!total || !whole) return weights.map(() => 0n)\n const parts = weights.map(weight => (total * weight) / whole)\n let left = total - parts.reduce((sum, part) => sum + part, 0n)\n const byRemainder = weights.map((weight, index) => ({ index, remainder: (total * weight) % whole })).sort((a, b) => (a.remainder === b.remainder ? a.index - b.index : a.remainder > b.remainder ? -1 : 1))\n for (const { index } of byRemainder) {\n if (left <= 0n) break\n parts[index] += 1n\n left -= 1n\n }\n return parts\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"document-money.js","sourceRoot":"","sources":["../shared/document-money.ts"],"names":[],"mappings":";;AAgBA,wCAMC;AAMD,wCAIC;AAhCD,6DAAqD;AAErD;;;;GAIG;AAEH,MAAM,KAAK,GAAG,CAAC,KAAc,EAAE,EAAE,CAAC,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAA;AAE1H;;;;;GAKG;AACH,SAAgB,cAAc,CAAC,KAAyC,EAAE,QAAgB,EAAE,GAAW;IACrG,IAAI,KAAK,CAAC,KAAK,CAAC;QAAE,OAAO,EAAE,CAAA;IAC3B,MAAM,MAAM,GAAG,IAAA,mCAAc,EAAC,QAAQ,CAAC,CAAA;IACvC,IAAI,MAAM,KAAK,SAAS;QAAE,OAAO,GAAG,QAAQ,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE,CAAA;IACnF,IAAI,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,IAAI,QAAQ,KAAK,KAAK;QAAE,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,cAAc,CAAC,IAAI,EAAE,EAAE,qBAAqB,EAAE,MAAM,EAAE,qBAAqB,EAAE,MAAM,EAAE,CAAC,GAAG,CAAA;IACvK,OAAO,IAAI,IAAI,CAAC,YAAY,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,qBAAqB,EAAE,MAAM,EAAE,qBAAqB,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAA;AACxJ,CAAC;AAED;;;GAGG;AACH,SAAgB,cAAc,CAAC,KAAyC,EAAE,QAAgB,EAAE,GAAW,EAAE,KAAK,GAAG,KAAK;IACpH,IAAI,KAAK,CAAC,KAAK,CAAC;QAAE,OAAO,EAAE,CAAA;IAC3B,MAAM,MAAM,GAAG,IAAA,mCAAc,EAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;IAC5C,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,cAAc,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,qBAAqB,EAAE,MAAM,EAAE,qBAAqB,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,qBAAqB,EAAE,CAAC,EAAE,qBAAqB,EAAE,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,EAAE,CAAC,CAAA;AAC/L,CAAC","sourcesContent":["import { currencyDigits } from './currency-digits.js'\n\n/*\n * How a commercial document writes money - the one place it is decided, read by the screens (in the screen's\n * language, client/document/document-amount.ts) and by the print the server makes (in the print's language,\n * document-print.ts). No i18n: the language comes in as a parameter.\n */\n\nconst unset = (value: unknown) => value === null || value === undefined || value === '' || !Number.isFinite(Number(value))\n\n/**\n * An amount in its currency as the language writes money (2026-10-28, the user: 「한글인 경우에는 KRW보다는 '원'이 더 좋을\n * 것 같다」): won in Korean reads 「5,000,000원」; every other pair takes the language's own currency form - 「₩5,000,000」\n * and 「$12,000.00」 in English, 「US$12,000.00」 in Korean - with exactly the currency's decimal places. A code the\n * platform does not know is written plainly.\n */\nexport function documentAmount(value: number | string | null | undefined, currency: string, lng: string): string {\n if (unset(value)) return ''\n const digits = currencyDigits(currency)\n if (digits === undefined) return `${currency} ${Number(value).toLocaleString(lng)}`\n if (lng.split('-')[0] === 'ko' && currency === 'KRW') return `${Number(value).toLocaleString('ko', { minimumFractionDigits: digits, maximumFractionDigits: digits })}원`\n return new Intl.NumberFormat(lng, { style: 'currency', currency, minimumFractionDigits: digits, maximumFractionDigits: digits }).format(Number(value))\n}\n\n/**\n * A number without the currency - a price or a discount in a table of lines: as typed (up to four decimals), or with\n * exactly the currency's decimal places when `exact` (a printed amount).\n */\nexport function documentNumber(value: number | string | null | undefined, currency: string, lng: string, exact = false): string {\n if (unset(value)) return ''\n const digits = currencyDigits(currency) ?? 0\n return Number(value).toLocaleString(lng, exact ? { minimumFractionDigits: digits, maximumFractionDigits: digits } : { minimumFractionDigits: 0, maximumFractionDigits: Math.max(digits, 4) })\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"document-print.js","sourceRoot":"","sources":["../shared/document-print.ts"],"names":[],"mappings":";;;AAeA,0CAEC;AAmDD,oCA6CC;AAMD,oCAKC;AAGD,4CAGC;AAlID,2DAAoE;AAUpE,mHAAmH;AACtG,QAAA,eAAe,GAAG,CAAC,IAAI,EAAE,IAAI,CAAU,CAAA;AAGpD,uGAAuG;AACvG,SAAgB,eAAe,CAAC,QAAiB;IAC/C,OAAQ,uBAAsC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAE,QAA0B,CAAC,CAAC,CAAC,SAAS,CAAA;AAC7G,CAAC;AAeD,MAAM,MAAM,GAAG,CAAC,IAAa,EAAE,E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AAK,CAAC,QAAQ,CAAC,WAAW,CAAC;IACtC,CAAC,cAAc,EAAE,aAAa,EAAE,OAAO,CAAC;SACvC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;SAC5B,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,mBAAmB,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC;SAC1D,IAAI,CAAC,EAAE,CAAC;SACJ,CAAA;AACT,CAAC;AAED;;;GAGG;AACH,SAAgB,YAAY,CAAC,QAAyB,EAAE,OAAqB;IAC3E,OAAO,8BAA8B,OAAO,CAAC,QAAQ,wCAAwC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,kBAAkB,oBAAY,GAAG,2BAAmB,wBAAwB,YAAY,CAC1M,QAAQ,EACR,OAAO,CACR,gBAAgB,CAAA;AACnB,CAAC;AAED,mGAAmG;AACnG,SAAgB,gBAAgB,CAAC,IAAY,EAAE,MAAc,EAAE,SAAyB;IACtF,MAAM,IAAI,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,kBAAkB,EAAE,GAAG,CAAC,CAAA;IACzF,OAAO,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,SAAS,EAAE,CAAA;AAC/E,CAAC","sourcesContent":["import { documentAmount, documentNumber } from './document-money.js'\n\n/*\n * A commercial document as the buyer reads it - the one layout every print of an invoice or a quotation is, made by\n * the server from the stored document (ADR-0170 decision 10): the preview's page, the PDF to download and what the\n * browser prints are this page. Pure - no i18next: the words come in as a translator of the print's language.\n */\n\nexport type PrintedDocument = Record<string, any>\n\n/** The languages the print has words for - this package's and sales' print words in each (ADR-0170 decision 9). */\nexport const PRINT_LANGUAGES = ['ko', 'en'] as const\nexport type PrintLanguage = (typeof PRINT_LANGUAGES)[number]\n\n/** The language as one the print has words for, or undefined - the caller refuses it or falls back. */\nexport function printLanguageOf(language: unknown): PrintLanguage | undefined {\n return (PRINT_LANGUAGES as readonly unknown[]).includes(language) ? (language as PrintLanguage) : undefined\n}\n\nexport type PrintOptions = {\n /** The language of the print - its words and how it writes money. */\n language: PrintLanguage\n /** The words of the print, in `language`. */\n t: (key: string) => string\n /** The kind's title - 「청구서」, 「견적서」. */\n title: string\n /** The kind's own terms beside the number - the due date; the version and the last day of an offer. */\n terms: { label: string; value?: string | null }[]\n /** How the kind names its number. */\n numberLabel?: string\n}\n\nconst escape = (text: unknown) => String(text ?? '').replace(/[&<>\"']/g, c => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '\"': '&quot;', \"'\": '&#39;' })[c]!)\n\n/** The look of the printed page - A4 with its margins. */\nexport const DOCUMENT_CSS = `\n @page{size:A4;margin:18mm}\n body{font:13px/1.5 system-ui,sans-serif;color:#000}\n h1{font-size:26px;margin:0}\n h2{font-size:13px;color:#555;margin:0 0 4px}\n header,.parties{display:flex;justify-content:space-between;gap:32px}\n .parties section{flex:1}\n table{width:100%;border-collapse:collapse;margin:24px 0}\n th,td{padding:8px;border-bottom:1px solid #999;text-align:right;font-variant-numeric:tabular-nums}\n th:first-child,td:first-child{text-align:left}\n .text{white-space:pre-wrap}\n .totals{width:50%;margin-left:auto}\n .grand td{font-weight:600;font-size:15px}\n tr{break-inside:avoid}\n`\n\n/**\n * On a screen, the page as a sheet of A4 on a grey desk with the print's margins - the preview reads as the PDF will.\n * Printing and the PDF read the print media, where none of this applies.\n */\nexport const DOCUMENT_SCREEN_CSS = `\n@media screen {\n html{background:#e9edf1}\n body{margin:0;padding:24px 0}\n .sheet{box-sizing:border-box;width:210mm;min-height:297mm;margin:0 auto;padding:18mm;background:#fff;\n box-shadow:0 1px 3px rgba(23,36,44,.12),0 8px 24px rgba(23,36,44,.08)}\n}\n@media screen and (max-width:210mm) {\n .sheet{width:auto;min-height:0;margin:0 8px;padding:8mm}\n}\n`\n\n/** The document's sheet - the head, the parties, the lines, the totals and the terms - without a page around it. */\nexport function documentBody(document: PrintedDocument, { language, t: word, title, terms, numberLabel = 'field.invoice-number' }: PrintOptions): string {\n const t = (key: string) => escape(word(key))\n /* A table's cells carry numbers; the total carries its currency, as the print's language writes money. */\n const amount = (value: number) => escape(documentNumber(value ?? 0, document.currency, language, true))\n const money = (value: number) => escape(documentAmount(value ?? 0, document.currency, language))\n const kind = (taxKind: string) =>\n taxKind === 'ZERO_RATED' ? t('text.tax-kind-zero-rated') : taxKind === 'EXEMPT' ? t('text.tax-kind-exempt') : t('text.tax-kind-taxable')\n const party = (label: string, name: string, address: string, number: string) =>\n `<section><h2>${label}</h2><strong>${escape(name)}</strong><p class=\"text\">${escape(address)}</p><p>${escape(number)}</p></section>`\n\n return `<div class=\"sheet\">\n <header><h1>${escape(title)}</h1><div><p>${t(numberLabel)}: ${escape(document.number)}</p><p>${t('field.invoice-issue-date')}: ${escape(document.issueDate)}</p>${terms\n .map(one => `<p>${escape(one.label)}: ${escape(one.value)}</p>`)\n .join('')}</div></header>\n <div class=\"parties\">${party(t('field.invoice-supplier-name'), document.supplierName, document.supplierAddress, document.supplierRegistrationNumber)}${party(\n t('field.invoice-buyer-name'),\n document.buyerName,\n document.buyerAddress,\n document.buyerRegistrationNumber\n )}</div>\n ${document.purchaseOrder ? `<p>${t('field.invoice-purchase-order')}: ${escape(document.purchaseOrder)}</p>` : ''}\n <table><thead><tr><th>${t('field.invoice-line-description')}</th><th>${t('field.invoice-quantity')}</th><th>${t('field.invoice-unit')}</th><th>${t('field.invoice-unit-price')}</th><th>${t(\n 'field.invoice-discount'\n )}</th><th>${t('field.invoice-tax-kind')}</th><th>${t('field.invoice-supply-amount')}</th></tr></thead><tbody>${(document.items ?? [])\n .map(\n (item: any) =>\n `<tr><td>${escape(item.description)}</td><td>${escape(item.quantity)}</td><td>${escape(item.unit)}</td><td>${amount(item.unitPrice)}</td><td>${amount(item.discount)}</td><td>${kind(item.taxKind)} ${escape(\n item.taxRate\n )}%</td><td>${amount(item.supplyAmount)}</td></tr>`\n )\n .join('')}</tbody></table>\n <table class=\"totals\"><tbody>${\n Number(document.discountAmount) > 0\n ? `<tr><td>${t('field.invoice-line-sum')}</td><td>${amount(document.lineSupplyAmount)}</td><td></td></tr><tr><td>${t('field.invoice-discount')}</td><td>− ${amount(document.discountAmount)}</td><td></td></tr>`\n : ''\n }${(document.taxGroups ?? [])\n .map((group: any) => `<tr><td>${kind(group.taxKind)} ${escape(group.taxRate)}%</td><td>${amount(group.supplyAmount)}</td><td>${amount(group.taxAmount)}</td></tr>`)\n .join('')}<tr><td>${t('field.invoice-sum')}</td><td>${amount(document.supplyAmount)}</td><td>${amount(document.taxAmount)}</td></tr><tr class=\"grand\"><td colspan=\"2\">${t(\n 'field.invoice-total-amount'\n )}</td><td>${money(document.totalAmount)}</td></tr></tbody></table>\n ${['paymentTerms', 'bankDetails', 'notes']\n .filter(key => document[key])\n .map(key => `<p class=\"text\">${escape(document[key])}</p>`)\n .join('')}\n </div>`\n}\n\n/**\n * The document as one HTML page - what the preview shows and the browser prints. Only escaped business data enters\n * the page.\n */\nexport function documentHtml(document: PrintedDocument, options: PrintOptions): string {\n return `<!doctype html><html lang=\"${options.language}\"><head><meta charset=\"utf-8\"><title>${escape(document.number)}</title><style>${DOCUMENT_CSS}${DOCUMENT_SCREEN_CSS}</style></head><body>${documentBody(\n document,\n options\n )}</body></html>`\n}\n\n/** 「견적서-Q2026-001.pdf」 - the kind's word and the number, without what a file name may not hold. */\nexport function documentFileName(word: string, number: string, extension: 'html' | 'pdf'): string {\n const safe = (text: string) => String(text ?? '').trim().replace(/[\\\\/:*?\"<>|\\s]+/g, '-')\n return `${[safe(word), safe(number)].filter(Boolean).join('-')}.${extension}`\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"document-start.js","sourceRoot":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I,CAAC,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,EAAE,CAAC;QACzD,MAAM,EAAE,GAAG,KAAK,CAAC,KAAM,CAAA;QACvB,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,EAAE,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,EAAE,CAAA;IACxE,CAAC;IACD,OAAO,GAAG,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,CAAA;AAC7C,CAAC;AAED,mFAAmF;AACnF,SAAgB,QAAQ,CAAC,CAAU,EAAE,CAAU;IAC7C,MAAM,KAAK,GAAG,CAAC,IAAa,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,WAAW,EAAE,CAAA;IACrF,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC,CAAC,CAAA;AAC5C,CAAC;AAED,iHAAiH;AACjH,SAAgB,UAAU,CAAqC,IAAa,EAAE,OAAqB;IACjG,MAAM,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAA;IAC7D,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;AAClD,CAAC","sourcesContent":["/*\n * What a new commercial document starts with, so a person writes only what is new (ADR-0170 decisions 5 · 11) - the\n * next number, the day a term ends, the counterparty its party's name is. Pure: the screens ask the server for what\n * these read and test them without a browser.\n */\n\n/** The day `days` after `day` (YYYY-MM-DD), counted in calendar days. */\nexport function daysAfter(day: string, days: number): string {\n const at = new Date(`${day}T00:00:00Z`)\n if (Number.isNaN(at.getTime())) return ''\n at.setUTCDate(at.getUTCDate() + days)\n return at.toISOString().slice(0, 10)\n}\n\n/**\n * The number after `last`, the domain's most recent invoice number: its trailing digits one up, keeping their width\n * and what comes before them - 「INV-2026-007」 → 「INV-2026-008」, 「A99」 → 「A100」. A year of four digits standing\n * apart in it that is not `year` becomes `year` and the count starts again at one - 「INV-2025-017」 →\n * 「INV-2026-001」. With nothing to follow - no number, or none ending in digits - 「INV-<year>-001」.\n */\nexport function nextInvoiceNumber(last: string | null | undefined, year: number): string {\n const match = /^(.*?)(\\d+)$/.exec(String(last ?? '').trim())\n if (!match) return `INV-${year}-001`\n const [, prefix, count] = match\n const pad = (n: number) => String(n).padStart(count.length, '0')\n /* A year apart from other digits - not the count itself, not part of a longer number. */\n const years = [...prefix.matchAll(/(?<!\\d)((?:19|20)\\d{2})(?!\\d)/g)]\n const stale = years.find(one => Number(one[1]) !== year)\n if (stale && !years.some(one => Number(one[1]) === year)) {\n const at = stale.index!\n return `${prefix.slice(0, at)}${year}${prefix.slice(at + 4)}${pad(1)}`\n }\n return `${prefix}${pad(Number(count) + 1)}`\n}\n\n/** Two names as the same name - case and spaces aside: 「(주) 하티오랩」 is 「(주)하티오랩」. */\nexport function sameName(a: unknown, b: unknown): boolean {\n const plain = (text: unknown) => String(text ?? '').replace(/\\s+/g, '').toLowerCase()\n return !!plain(a) && plain(a) === plain(b)\n}\n\n/** The one choice named `name`; none when no choice or more than one is - a guess would link the wrong party. */\nexport function partyNamed<T extends { name?: string | null }>(name: unknown, choices: readonly T[]): T | undefined {\n const named = choices.filter(one => sameName(one.name, name))\n return named.length === 1 ? named[0] : undefined\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"invoice-standing.js","sourceRoot":"","sources":["../shared/invoice-standing.ts"],"names":[],"mappings":";;;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GAAG,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,CAAC,QAAQ,EAAE,KAAK,EAAE,GAAG,CAAC,KAAK,EAAE,CAAC,CAAA;IACvE,CAAC,CAAC,CAAA;AACJ,CAAC;AAED;;;;GAIG;AACU,QAAA,cAAc,GAAG,KAAK,CAAA;AAEnC;;;GAGG;AACH,SAAgB,SAAS,CAAC,KAAa,EAAE,KAAa,EAAE,QAAgB,EAAE,QAAQ,GAAG,KAAK;IACxF,MAAM,KAAK,GAAG,EAAE,IAAI,CAAC,IAAA,mCAAc,EAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAA;IACnD,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,KAAK,CAAC,CAAA;IACtE,IAAI,KAAK,IAAI,CAAC,IAAI,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,KAAK,GAAG,sBAAc,CAAC;QAAE,OAAO,CAAC,CAAA;IACxF,OAAO,KAAK,GAAG,KAAK,CAAA;AACtB,CAAC","sourcesContent":["import { currencyDigits } from './currency-digits.js'\n\n/*\n * How the invoice list reads its rows (ADR-0170 decision 11). Pure.\n */\n\ntype Row = { status?: string | null; dueDate?: string | null; direction?: string | null; currency?: string | null; totalAmount?: number | string | null; remainingAmount?: number | null }\n\n/**\n * Whether an invoice is past its due date: issued, due before `today`, and still owing. What it owes is the\n * application's to say (`registerInvoiceRemaining` - Office reads the bank lines on it); where none says, a paid\n * invoice past its day reads overdue too.\n */\nexport function overdue(row: Row, today: string): boolean {\n const settled = typeof row.remainingAmount === 'number' && row.remainingAmount <= 0\n return row.status === 'ISSUED' && !!row.dueDate && row.dueDate < today && !settled\n}\n\n/**\n * The total of the rows by direction and currency - the sales and the purchases apart, each currency apart, voided\n * invoices left out: an invoice cancelled bills nothing. Counted in the currency's minor unit.\n */\nexport function totalsOf(rows: readonly Row[]): { direction: string; currency: string; amount: number }[] {\n const sums = new Map<string, { direction: string; currency: string; minor: number; digits: number }>()\n for (const row of rows) {\n if (row.status === 'VOID') continue\n const currency = row.currency || 'KRW'\n const direction = row.direction === 'PURCHASE' ? 'PURCHASE' : 'SALES'\n const digits = currencyDigits(currency) ?? 0\n const key = `${direction}:${currency}`\n const sum = sums.get(key) ?? { direction, currency, minor: 0, digits }\n sum.minor += Math.round(Number(row.totalAmount ?? 0) * 10 ** digits)\n sums.set(key, sum)\n }\n return [...sums.values()]\n .sort((a, b) => a.direction.localeCompare(b.direction, 'en') * -1 || a.currency.localeCompare(b.currency, 'en'))\n .map(({ direction, currency, minor, digits }) => ({ direction, currency, amount: minor / 10 ** digits }))\n}\n\n/** The first and last day (YYYY-MM-DD) of a period the list is narrowed to, around `day`; undefined for every period. */\nexport function issuePeriodOf(period: string, day: string): [string, string] | undefined {\n const [year, month] = day.split('-').map(Number)\n const pad = (n: number) => String(n).padStart(2, '0')\n const monthOf = (y: number, m: number): [string, string] => [`${y}-${pad(m)}-01`, `${y}-${pad(m)}-${pad(new Date(Date.UTC(y, m, 0)).getUTCDate())}`]\n if (period === 'this-month') return monthOf(year, month)\n if (period === 'last-month') return month === 1 ? monthOf(year - 1, 12) : monthOf(year, month - 1)\n if (period === 'this-year') return [`${year}-01-01`, `${year}-12-31`]\n if (period === 'last-year') return [`${year - 1}-01-01`, `${year - 1}-12-31`]\n return undefined\n}\n\n/**\n * The invoice list's grid filters as the server reads them (FOOTER-BUTTON-REVIEW G09). The caller passes the\n * conditions only (data-grist `isFilterCondition`); each one passes on as it is unless it is one of these: status OVERDUE is issued, due before `today` and still owing - what an invoice owes is the application's that ties\n * its payments (`registerInvoiceRemaining`), so the server picks them; the issue date's choice is a period around\n * `today`, read as the days between.\n */\nexport function invoiceListFilters(filters: readonly { name: string; operator: string; value?: any }[], today: string): { name: string; operator: string; value: any }[] {\n return filters.flatMap(one => {\n /* Only the chosen 기한 지남 becomes the server's own overdue condition; any other status condition passes as it is. */\n if (one.name === 'status' && one.operator === 'eq' && one.value === 'OVERDUE') return [{ name: 'overdue', operator: 'eq', value: today }]\n /* Only a chosen period (`this-month` …) becomes its days; a day itself or another operator passes as it is. */\n if (one.name === 'issueDate' && one.operator === 'eq' && typeof one.value === 'string') {\n const period = issuePeriodOf(one.value, today)\n if (period) return [{ name: 'issueDate', operator: 'between', value: period }]\n }\n return [{ name: one.name, operator: one.operator, value: one.value }]\n })\n}\n\n/**\n * The share of a bill the banks on the way may keep and the bill still be settled - an overseas transfer arrives a few\n * dollars short of what the payer sent. A shortfall within it is taken by default for their fee (지급수수료); a person may\n * leave the bill partly paid instead. Above it a shortfall is the payer's, and stays owing.\n */\nexport const BANK_FEE_SHARE = 0.005\n\n/**\n * What of a shortfall reads as the banks' fee: what a bill of `total` still `owing` lacks once `arriving` comes, when it\n * is within `BANK_FEE_SHARE` of the bill - else nothing. Counted in the currency's minor unit.\n */\nexport function bankFeeOf(total: number, owing: number, arriving: number, currency = 'KRW'): number {\n const scale = 10 ** (currencyDigits(currency) ?? 0)\n const short = Math.round(owing * scale) - Math.round(arriving * scale)\n if (short <= 0 || short > Math.floor(Math.abs(total) * scale * BANK_FEE_SHARE)) return 0\n return short / scale\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"screen-money.js","sourceRoot":"","sources":["../shared/screen-money.ts"],"names":[],"mappings":";;AASA,kBAGC;AAOD,sBAMC;AAzBD,6DAAqD;AAErD;;;;GAIG;AAEH,iDAAiD;AACjD,SAAgB,GAAG,CAAC,KAAgC;IAClD,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAA;IAC9C,OAAO,GAAG,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,IAAI,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,cAAc,CAAC,OAAO,CAAC,EAAE,CAAA;AACjF,CAAC;AAED;;;;GAIG;AACH,SAAgB,KAAK,CAAC,KAAgC,EAAE,QAAwB;IAC9E,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,EAAE,CAAA;IACpD,IAAI,CAAC,QAAQ,IAAI,QAAQ,KAAK,KAAK;QAAE,OAAO,GAAG,CAAC,KAAK,CAAC,CAAA;IACtD,MAAM,MAAM,GAAG,IAAA,mCAAc,EAAC,QAAQ,CAAC,CAAA;IACvC,IAAI,MAAM,KAAK,SAAS;QAAE,OAAO,GAAG,QAAQ,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,cAAc,CAAC,OAAO,CAAC,EAAE,CAAA;IACvF,OAAO,GAAG,QAAQ,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,cAAc,CAAC,OAAO,EAAE,EAAE,qBAAqB,EAAE,MAAM,EAAE,qBAAqB,EAAE,MAAM,EAAE,CAAC,EAAE,CAAA;AACjI,CAAC","sourcesContent":["import { currencyDigits } from './currency-digits.js'\n\n/*\n * Format amounts consistently in screens and approval descriptions through screen-money. Printed commercial\n * documents use documentAmount. Keep imports limited to numeric formatting so unit tests can load this\n * module independently.\n */\n\n/** Won with every won - `₩45,000`, `−₩1,235`. */\nexport function won(value: number | null | undefined): string {\n const rounded = Math.round(Number(value) || 0)\n return `${rounded < 0 ? '−' : ''}₩${Math.abs(rounded).toLocaleString('en-US')}`\n}\n\n/**\n * An amount in its own currency: won as `won`, any other by its code with exactly the currency's decimal places -\n * `USD 73,209.00` - so the amounts of a column line up. A code the platform does not know is written beside the\n * plain amount.\n */\nexport function money(value: number | null | undefined, currency?: string | null): string {\n if (value === null || value === undefined) return ''\n if (!currency || currency === 'KRW') return won(value)\n const digits = currencyDigits(currency)\n if (digits === undefined) return `${currency} ${Number(value).toLocaleString('en-US')}`\n return `${currency} ${Number(value).toLocaleString('en-US', { minimumFractionDigits: digits, maximumFractionDigits: digits })}`\n}\n"]}
@@ -1,18 +0,0 @@
1
- /*
2
- * How many decimal places each currency is written and reckoned with — the one place this is decided.
3
- *
4
- * No imports: the invoice server, its screens, accounting and the apps that write amounts all read this file, and a
5
- * screen's unit test must not pull in i18n or the framework to get one number. It builds to `dist-shared`
6
- * (`tsconfig.shared.json`), which a server rebuild does not empty, and is reached through the package's own name,
7
- * `@things-factory/invoice/dist-shared/currency-digits.js`.
8
- */
9
-
10
- /**
11
- * Decimal places of a currency — 0 for KRW and JPY, 2 for USD, 3 for KWD — as the platform's currency data has
12
- * them. Undefined for anything that is not a three-letter code the platform knows; the caller decides whether that
13
- * is a refusal or an amount written plainly.
14
- */
15
- export function currencyDigits(currency: unknown): number | undefined {
16
- if (typeof currency !== 'string' || !/^[A-Z]{3}$/.test(currency) || !Intl.supportedValuesOf('currency').includes(currency)) return undefined
17
- return new Intl.NumberFormat('en', { style: 'currency', currency }).resolvedOptions().maximumFractionDigits
18
- }
@@ -1,226 +0,0 @@
1
- import { currencyDigits } from './currency-digits.js'
2
-
3
- /*
4
- * A commercial document's arithmetic - the one place it is decided, read by the invoice and quotation services when a
5
- * document is saved and by their screens while it is typed, so a line's supply and the totals on screen are the
6
- * ones the document will keep (ADR-0120 decision 4).
7
- *
8
- * - Lines carry supply and a tax kind and rate; the tax is reckoned once per (kind, rate) group: the group's supply
9
- * total × rate ÷ 100, rounded half-up to the currency's minor unit. The document tax is the sum of the groups.
10
- * - A discount of the whole document comes off the lines' supply before tax (ADR-0170 decision 8): it is spread over
11
- * the groups in proportion to each group's supply, in minor units, the remainder going one unit at a time to the
12
- * groups whose share was cut most (largest remainder), so the parts add up to the discount exactly. Each group's
13
- * tax is reckoned on its supply after its part.
14
- * - Everything is counted in integers: quantities, prices and rates to four decimals, money in minor units.
15
- * - A received document keeps the tax its sender printed on each line; nothing recomputes it.
16
- *
17
- * No imports but the currency's digits and no throwing: a line that cannot be reckoned says why (`problem`), and is
18
- * left out of the totals. The server refuses such a document; a screen shows the rest while the line is typed.
19
- */
20
-
21
- export type TaxKindCode = 'TAXABLE' | 'ZERO_RATED' | 'EXEMPT'
22
-
23
- export const TAX_KINDS: readonly TaxKindCode[] = ['TAXABLE', 'ZERO_RATED', 'EXEMPT']
24
-
25
- export interface DocumentLine {
26
- description?: string | null
27
- quantity?: number | string | null
28
- unitPrice?: number | string | null
29
- discount?: number | string | null
30
- taxKind?: string | null
31
- taxRate?: number | string | null
32
- /** The tax the sender printed on the line - only on a received document. */
33
- receivedTaxAmount?: number | string | null
34
- }
35
-
36
- /** Why a line cannot be reckoned - the server's refusal codes, `invoice-<problem>`. */
37
- export type LineProblem = 'item-description-required' | 'item-invalid' | 'discount-exceeds' | 'amount-too-large' | 'received-tax-required'
38
-
39
- export interface ReckonedLine {
40
- /** The line's supply - quantity × unit price, less the discount - in the currency. Absent when the line has a problem. */
41
- supplyAmount?: number
42
- /** The tax the sender printed, on a received document. */
43
- receivedTaxAmount?: number | null
44
- problem?: LineProblem
45
- }
46
-
47
- export interface TaxGroup {
48
- taxKind: string
49
- taxRate: number
50
- supplyAmount: number
51
- taxAmount: number
52
- }
53
-
54
- /** Why the discount of the whole document cannot be taken - the server's refusal code, `invoice-<problem>`. */
55
- export type DiscountProblem = 'document-discount-invalid'
56
-
57
- export interface DocumentAmounts {
58
- lines: ReckonedLine[]
59
- /** Each group's supply after its part of the document discount, and its tax. */
60
- taxGroups: TaxGroup[]
61
- /** The lines' supply before the document discount. */
62
- lineSupplyAmount: number
63
- /** The discount of the whole document taken off the lines' supply - none when it has a problem. */
64
- discountAmount: number
65
- /** A discount below zero, past the lines' supply or finer than the currency's minor unit; it is not taken. */
66
- discountProblem?: DiscountProblem
67
- /** The lines' supply less the document discount - the supply tax is reckoned on. */
68
- supplyAmount: number
69
- taxAmount: number
70
- totalAmount: number
71
- /** The totals pass the largest amount a document may carry. */
72
- tooLarge: boolean
73
- }
74
-
75
- /**
76
- * A row added and not typed into: no item, no price, unit or printed tax, and only what `settleLine` fills - a
77
- * quantity of one, no discount. Such a row is left out; a row typed into without its item is kept, and the save is
78
- * refused naming its row rather than the row vanishing from the document and its totals.
79
- */
80
- export function untouchedRow(record: any): boolean {
81
- const blank = (value: unknown) => value === undefined || value === null || value === ''
82
- return (
83
- !String(record?.description ?? '').trim() &&
84
- blank(record?.unitPrice) &&
85
- !String(record?.unit ?? '').trim() &&
86
- blank(record?.receivedTaxAmount) &&
87
- (blank(record?.quantity) || Number(record.quantity) === 1) &&
88
- (blank(record?.discount) || Number(record.discount) === 0)
89
- )
90
- }
91
-
92
- /** The rate a tax kind takes unless the person writes another: the standard VAT for a taxable line, none otherwise. */
93
- export function defaultTaxRate(taxKind: string | null | undefined, standard = 10): number {
94
- return taxKind === 'ZERO_RATED' || taxKind === 'EXEMPT' ? 0 : standard
95
- }
96
-
97
- const MAX_MINOR = 10n ** 14n
98
- const SCALE = 10_000n
99
-
100
- const numberOf = (value: unknown): number => (typeof value === 'number' ? value : value === null || value === undefined || value === '' ? NaN : Number(value))
101
-
102
- /** A number with at most four decimals, as an integer of ten-thousandths; undefined when it has more. */
103
- function scaled(value: unknown): bigint | undefined {
104
- const number = numberOf(value)
105
- if (!Number.isFinite(number)) return undefined
106
- const whole = Math.round(number * 10_000)
107
- return Math.abs(number * 10_000 - whole) > 1e-6 ? undefined : BigInt(whole)
108
- }
109
-
110
- function minorOf(value: unknown, digits: number): bigint | undefined {
111
- const number = numberOf(value)
112
- if (!Number.isFinite(number)) return undefined
113
- const factor = 10 ** digits
114
- const whole = Math.round(number * factor)
115
- return Math.abs(number * factor - whole) > 1e-6 ? undefined : BigInt(whole)
116
- }
117
-
118
- /** numerator ÷ denominator, rounded half-up; both non-negative. */
119
- function divideHalfUp(numerator: bigint, denominator: bigint): bigint {
120
- return (numerator * 2n + denominator) / (denominator * 2n)
121
- }
122
-
123
- const amountOf = (minor: bigint, digits: number) => Number(minor) / 10 ** digits
124
-
125
- /**
126
- * Each line's supply, the tax of each (kind, rate) group and the document totals, in the currency (whose digits must
127
- * be known - `currencyDigits`). `received` keeps the line tax the sender printed; otherwise the groups reckon it. A
128
- * blank discount is none; a blank quantity, price, kind or rate is a line not yet reckonable. `discountAmount` is the
129
- * discount of the whole document; a blank one is none. On a received document it lowers the supply, and the tax stays
130
- * as printed.
131
- */
132
- export function documentAmounts(lines: readonly DocumentLine[], currency: string, received = false, discountAmount: unknown = 0): DocumentAmounts {
133
- const digits = currencyDigits(currency) ?? 0
134
- const factor = 10n ** BigInt(digits)
135
- const groups = new Map<string, { taxKind: string; rate: bigint; supply: bigint; tax: bigint }>()
136
-
137
- const reckoned = lines.map((line): ReckonedLine => {
138
- const quantity = scaled(line.quantity)
139
- const unitPrice = scaled(line.unitPrice)
140
- const rate = scaled(line.taxRate)
141
- const discount = line.discount === null || line.discount === undefined || line.discount === '' ? 0n : minorOf(line.discount, digits)
142
- const kind = String(line.taxKind ?? '')
143
- if (!String(line.description ?? '').trim()) return { problem: 'item-description-required' }
144
- if (
145
- quantity === undefined ||
146
- unitPrice === undefined ||
147
- rate === undefined ||
148
- discount === undefined ||
149
- quantity <= 0n ||
150
- unitPrice < 0n ||
151
- discount < 0n ||
152
- rate < 0n ||
153
- rate > 100n * SCALE ||
154
- !TAX_KINDS.includes(kind as TaxKindCode) ||
155
- (kind !== 'TAXABLE' && rate !== 0n)
156
- ) {
157
- return { problem: 'item-invalid' }
158
- }
159
-
160
- const gross = divideHalfUp(quantity * unitPrice * factor, SCALE * SCALE)
161
- if (discount > gross) return { problem: 'discount-exceeds' }
162
- const supply = gross - discount
163
- if (supply > MAX_MINOR) return { problem: 'amount-too-large' }
164
-
165
- let printed: bigint | undefined
166
- if (received) {
167
- printed = line.receivedTaxAmount === null || line.receivedTaxAmount === undefined || line.receivedTaxAmount === '' ? undefined : minorOf(line.receivedTaxAmount, digits)
168
- if (printed === undefined || printed < 0n) return { supplyAmount: amountOf(supply, digits), problem: 'received-tax-required' }
169
- }
170
-
171
- const key = `${kind}:${rate}`
172
- const group = groups.get(key) ?? { taxKind: kind, rate, supply: 0n, tax: 0n }
173
- group.supply += supply
174
- if (printed !== undefined) group.tax += printed
175
- groups.set(key, group)
176
-
177
- return { supplyAmount: amountOf(supply, digits), receivedTaxAmount: printed === undefined ? null : amountOf(printed, digits) }
178
- })
179
-
180
- const kept = [...groups.values()]
181
- const lineSupply = kept.reduce((sum, group) => sum + group.supply, 0n)
182
- const asked = discountAmount === null || discountAmount === undefined || discountAmount === '' ? 0n : minorOf(discountAmount, digits)
183
- const discountProblem: DiscountProblem | undefined = asked === undefined || asked < 0n || asked > lineSupply ? 'document-discount-invalid' : undefined
184
- const discount = discountProblem ? 0n : asked!
185
- const parts = shares(discount, kept.map(group => group.supply))
186
-
187
- let supply = 0n
188
- let tax = 0n
189
- const taxGroups = kept.map((group, index) => {
190
- group.supply -= parts[index]
191
- if (!received) group.tax = divideHalfUp(group.supply * group.rate, 100n * SCALE)
192
- supply += group.supply
193
- tax += group.tax
194
- return { taxKind: group.taxKind, taxRate: Number(group.rate) / 10_000, supplyAmount: amountOf(group.supply, digits), taxAmount: amountOf(group.tax, digits) }
195
- })
196
-
197
- return {
198
- lines: reckoned,
199
- taxGroups,
200
- lineSupplyAmount: amountOf(lineSupply, digits),
201
- discountAmount: amountOf(discount, digits),
202
- ...(discountProblem ? { discountProblem } : {}),
203
- supplyAmount: amountOf(supply, digits),
204
- taxAmount: amountOf(tax, digits),
205
- totalAmount: amountOf(supply + tax, digits),
206
- tooLarge: lineSupply > MAX_MINOR || supply + tax > MAX_MINOR
207
- }
208
- }
209
-
210
- /**
211
- * `total` split in proportion to `weights`, in whole units: each its share cut down, then the units left over one
212
- * at a time to the largest cut-off remainders (the first of equal ones first), so the parts add up to `total`.
213
- */
214
- function shares(total: bigint, weights: readonly bigint[]): bigint[] {
215
- const whole = weights.reduce((sum, weight) => sum + weight, 0n)
216
- if (!total || !whole) return weights.map(() => 0n)
217
- const parts = weights.map(weight => (total * weight) / whole)
218
- let left = total - parts.reduce((sum, part) => sum + part, 0n)
219
- const byRemainder = weights.map((weight, index) => ({ index, remainder: (total * weight) % whole })).sort((a, b) => (a.remainder === b.remainder ? a.index - b.index : a.remainder > b.remainder ? -1 : 1))
220
- for (const { index } of byRemainder) {
221
- if (left <= 0n) break
222
- parts[index] += 1n
223
- left -= 1n
224
- }
225
- return parts
226
- }
@@ -1,33 +0,0 @@
1
- import { currencyDigits } from './currency-digits.js'
2
-
3
- /*
4
- * How a commercial document writes money - the one place it is decided, read by the screens (in the screen's
5
- * language, client/document/document-amount.ts) and by the print the server makes (in the print's language,
6
- * document-print.ts). No i18n: the language comes in as a parameter.
7
- */
8
-
9
- const unset = (value: unknown) => value === null || value === undefined || value === '' || !Number.isFinite(Number(value))
10
-
11
- /**
12
- * An amount in its currency as the language writes money (2026-10-28, the user: 「한글인 경우에는 KRW보다는 '원'이 더 좋을
13
- * 것 같다」): won in Korean reads 「5,000,000원」; every other pair takes the language's own currency form - 「₩5,000,000」
14
- * and 「$12,000.00」 in English, 「US$12,000.00」 in Korean - with exactly the currency's decimal places. A code the
15
- * platform does not know is written plainly.
16
- */
17
- export function documentAmount(value: number | string | null | undefined, currency: string, lng: string): string {
18
- if (unset(value)) return ''
19
- const digits = currencyDigits(currency)
20
- if (digits === undefined) return `${currency} ${Number(value).toLocaleString(lng)}`
21
- if (lng.split('-')[0] === 'ko' && currency === 'KRW') return `${Number(value).toLocaleString('ko', { minimumFractionDigits: digits, maximumFractionDigits: digits })}원`
22
- return new Intl.NumberFormat(lng, { style: 'currency', currency, minimumFractionDigits: digits, maximumFractionDigits: digits }).format(Number(value))
23
- }
24
-
25
- /**
26
- * A number without the currency - a price or a discount in a table of lines: as typed (up to four decimals), or with
27
- * exactly the currency's decimal places when `exact` (a printed amount).
28
- */
29
- export function documentNumber(value: number | string | null | undefined, currency: string, lng: string, exact = false): string {
30
- if (unset(value)) return ''
31
- const digits = currencyDigits(currency) ?? 0
32
- return Number(value).toLocaleString(lng, exact ? { minimumFractionDigits: digits, maximumFractionDigits: digits } : { minimumFractionDigits: 0, maximumFractionDigits: Math.max(digits, 4) })
33
- }
@@ -1,131 +0,0 @@
1
- import { documentAmount, documentNumber } from './document-money.js'
2
-
3
- /*
4
- * A commercial document as the buyer reads it - the one layout every print of an invoice or a quotation is, made by
5
- * the server from the stored document (ADR-0170 decision 10): the preview's page, the PDF to download and what the
6
- * browser prints are this page. Pure - no i18next: the words come in as a translator of the print's language.
7
- */
8
-
9
- export type PrintedDocument = Record<string, any>
10
-
11
- /** The languages the print has words for - this package's and sales' print words in each (ADR-0170 decision 9). */
12
- export const PRINT_LANGUAGES = ['ko', 'en'] as const
13
- export type PrintLanguage = (typeof PRINT_LANGUAGES)[number]
14
-
15
- /** The language as one the print has words for, or undefined - the caller refuses it or falls back. */
16
- export function printLanguageOf(language: unknown): PrintLanguage | undefined {
17
- return (PRINT_LANGUAGES as readonly unknown[]).includes(language) ? (language as PrintLanguage) : undefined
18
- }
19
-
20
- export type PrintOptions = {
21
- /** The language of the print - its words and how it writes money. */
22
- language: PrintLanguage
23
- /** The words of the print, in `language`. */
24
- t: (key: string) => string
25
- /** The kind's title - 「청구서」, 「견적서」. */
26
- title: string
27
- /** The kind's own terms beside the number - the due date; the version and the last day of an offer. */
28
- terms: { label: string; value?: string | null }[]
29
- /** How the kind names its number. */
30
- numberLabel?: string
31
- }
32
-
33
- const escape = (text: unknown) => String(text ?? '').replace(/[&<>"']/g, c => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' })[c]!)
34
-
35
- /** The look of the printed page - A4 with its margins. */
36
- export const DOCUMENT_CSS = `
37
- @page{size:A4;margin:18mm}
38
- body{font:13px/1.5 system-ui,sans-serif;color:#000}
39
- h1{font-size:26px;margin:0}
40
- h2{font-size:13px;color:#555;margin:0 0 4px}
41
- header,.parties{display:flex;justify-content:space-between;gap:32px}
42
- .parties section{flex:1}
43
- table{width:100%;border-collapse:collapse;margin:24px 0}
44
- th,td{padding:8px;border-bottom:1px solid #999;text-align:right;font-variant-numeric:tabular-nums}
45
- th:first-child,td:first-child{text-align:left}
46
- .text{white-space:pre-wrap}
47
- .totals{width:50%;margin-left:auto}
48
- .grand td{font-weight:600;font-size:15px}
49
- tr{break-inside:avoid}
50
- `
51
-
52
- /**
53
- * On a screen, the page as a sheet of A4 on a grey desk with the print's margins - the preview reads as the PDF will.
54
- * Printing and the PDF read the print media, where none of this applies.
55
- */
56
- export const DOCUMENT_SCREEN_CSS = `
57
- @media screen {
58
- html{background:#e9edf1}
59
- body{margin:0;padding:24px 0}
60
- .sheet{box-sizing:border-box;width:210mm;min-height:297mm;margin:0 auto;padding:18mm;background:#fff;
61
- box-shadow:0 1px 3px rgba(23,36,44,.12),0 8px 24px rgba(23,36,44,.08)}
62
- }
63
- @media screen and (max-width:210mm) {
64
- .sheet{width:auto;min-height:0;margin:0 8px;padding:8mm}
65
- }
66
- `
67
-
68
- /** The document's sheet - the head, the parties, the lines, the totals and the terms - without a page around it. */
69
- export function documentBody(document: PrintedDocument, { language, t: word, title, terms, numberLabel = 'field.invoice-number' }: PrintOptions): string {
70
- const t = (key: string) => escape(word(key))
71
- /* A table's cells carry numbers; the total carries its currency, as the print's language writes money. */
72
- const amount = (value: number) => escape(documentNumber(value ?? 0, document.currency, language, true))
73
- const money = (value: number) => escape(documentAmount(value ?? 0, document.currency, language))
74
- const kind = (taxKind: string) =>
75
- taxKind === 'ZERO_RATED' ? t('text.tax-kind-zero-rated') : taxKind === 'EXEMPT' ? t('text.tax-kind-exempt') : t('text.tax-kind-taxable')
76
- const party = (label: string, name: string, address: string, number: string) =>
77
- `<section><h2>${label}</h2><strong>${escape(name)}</strong><p class="text">${escape(address)}</p><p>${escape(number)}</p></section>`
78
-
79
- return `<div class="sheet">
80
- <header><h1>${escape(title)}</h1><div><p>${t(numberLabel)}: ${escape(document.number)}</p><p>${t('field.invoice-issue-date')}: ${escape(document.issueDate)}</p>${terms
81
- .map(one => `<p>${escape(one.label)}: ${escape(one.value)}</p>`)
82
- .join('')}</div></header>
83
- <div class="parties">${party(t('field.invoice-supplier-name'), document.supplierName, document.supplierAddress, document.supplierRegistrationNumber)}${party(
84
- t('field.invoice-buyer-name'),
85
- document.buyerName,
86
- document.buyerAddress,
87
- document.buyerRegistrationNumber
88
- )}</div>
89
- ${document.purchaseOrder ? `<p>${t('field.invoice-purchase-order')}: ${escape(document.purchaseOrder)}</p>` : ''}
90
- <table><thead><tr><th>${t('field.invoice-line-description')}</th><th>${t('field.invoice-quantity')}</th><th>${t('field.invoice-unit')}</th><th>${t('field.invoice-unit-price')}</th><th>${t(
91
- 'field.invoice-discount'
92
- )}</th><th>${t('field.invoice-tax-kind')}</th><th>${t('field.invoice-supply-amount')}</th></tr></thead><tbody>${(document.items ?? [])
93
- .map(
94
- (item: any) =>
95
- `<tr><td>${escape(item.description)}</td><td>${escape(item.quantity)}</td><td>${escape(item.unit)}</td><td>${amount(item.unitPrice)}</td><td>${amount(item.discount)}</td><td>${kind(item.taxKind)} ${escape(
96
- item.taxRate
97
- )}%</td><td>${amount(item.supplyAmount)}</td></tr>`
98
- )
99
- .join('')}</tbody></table>
100
- <table class="totals"><tbody>${
101
- Number(document.discountAmount) > 0
102
- ? `<tr><td>${t('field.invoice-line-sum')}</td><td>${amount(document.lineSupplyAmount)}</td><td></td></tr><tr><td>${t('field.invoice-discount')}</td><td>− ${amount(document.discountAmount)}</td><td></td></tr>`
103
- : ''
104
- }${(document.taxGroups ?? [])
105
- .map((group: any) => `<tr><td>${kind(group.taxKind)} ${escape(group.taxRate)}%</td><td>${amount(group.supplyAmount)}</td><td>${amount(group.taxAmount)}</td></tr>`)
106
- .join('')}<tr><td>${t('field.invoice-sum')}</td><td>${amount(document.supplyAmount)}</td><td>${amount(document.taxAmount)}</td></tr><tr class="grand"><td colspan="2">${t(
107
- 'field.invoice-total-amount'
108
- )}</td><td>${money(document.totalAmount)}</td></tr></tbody></table>
109
- ${['paymentTerms', 'bankDetails', 'notes']
110
- .filter(key => document[key])
111
- .map(key => `<p class="text">${escape(document[key])}</p>`)
112
- .join('')}
113
- </div>`
114
- }
115
-
116
- /**
117
- * The document as one HTML page - what the preview shows and the browser prints. Only escaped business data enters
118
- * the page.
119
- */
120
- export function documentHtml(document: PrintedDocument, options: PrintOptions): string {
121
- return `<!doctype html><html lang="${options.language}"><head><meta charset="utf-8"><title>${escape(document.number)}</title><style>${DOCUMENT_CSS}${DOCUMENT_SCREEN_CSS}</style></head><body>${documentBody(
122
- document,
123
- options
124
- )}</body></html>`
125
- }
126
-
127
- /** 「견적서-Q2026-001.pdf」 - the kind's word and the number, without what a file name may not hold. */
128
- export function documentFileName(word: string, number: string, extension: 'html' | 'pdf'): string {
129
- const safe = (text: string) => String(text ?? '').trim().replace(/[\\/:*?"<>|\s]+/g, '-')
130
- return `${[safe(word), safe(number)].filter(Boolean).join('-')}.${extension}`
131
- }
@@ -1,46 +0,0 @@
1
- /*
2
- * What a new commercial document starts with, so a person writes only what is new (ADR-0170 decisions 5 · 11) - the
3
- * next number, the day a term ends, the counterparty its party's name is. Pure: the screens ask the server for what
4
- * these read and test them without a browser.
5
- */
6
-
7
- /** The day `days` after `day` (YYYY-MM-DD), counted in calendar days. */
8
- export function daysAfter(day: string, days: number): string {
9
- const at = new Date(`${day}T00:00:00Z`)
10
- if (Number.isNaN(at.getTime())) return ''
11
- at.setUTCDate(at.getUTCDate() + days)
12
- return at.toISOString().slice(0, 10)
13
- }
14
-
15
- /**
16
- * The number after `last`, the domain's most recent invoice number: its trailing digits one up, keeping their width
17
- * and what comes before them - 「INV-2026-007」 → 「INV-2026-008」, 「A99」 → 「A100」. A year of four digits standing
18
- * apart in it that is not `year` becomes `year` and the count starts again at one - 「INV-2025-017」 →
19
- * 「INV-2026-001」. With nothing to follow - no number, or none ending in digits - 「INV-<year>-001」.
20
- */
21
- export function nextInvoiceNumber(last: string | null | undefined, year: number): string {
22
- const match = /^(.*?)(\d+)$/.exec(String(last ?? '').trim())
23
- if (!match) return `INV-${year}-001`
24
- const [, prefix, count] = match
25
- const pad = (n: number) => String(n).padStart(count.length, '0')
26
- /* A year apart from other digits - not the count itself, not part of a longer number. */
27
- const years = [...prefix.matchAll(/(?<!\d)((?:19|20)\d{2})(?!\d)/g)]
28
- const stale = years.find(one => Number(one[1]) !== year)
29
- if (stale && !years.some(one => Number(one[1]) === year)) {
30
- const at = stale.index!
31
- return `${prefix.slice(0, at)}${year}${prefix.slice(at + 4)}${pad(1)}`
32
- }
33
- return `${prefix}${pad(Number(count) + 1)}`
34
- }
35
-
36
- /** Two names as the same name - case and spaces aside: 「(주) 하티오랩」 is 「(주)하티오랩」. */
37
- export function sameName(a: unknown, b: unknown): boolean {
38
- const plain = (text: unknown) => String(text ?? '').replace(/\s+/g, '').toLowerCase()
39
- return !!plain(a) && plain(a) === plain(b)
40
- }
41
-
42
- /** The one choice named `name`; none when no choice or more than one is - a guess would link the wrong party. */
43
- export function partyNamed<T extends { name?: string | null }>(name: unknown, choices: readonly T[]): T | undefined {
44
- const named = choices.filter(one => sameName(one.name, name))
45
- return named.length === 1 ? named[0] : undefined
46
- }