@things-factory/invoice 10.1.255 → 10.1.257
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.
- package/dist-client/document/document-defaults.d.ts +11 -2
- package/dist-client/document/document-defaults.js +7 -15
- package/dist-client/document/document-defaults.js.map +1 -1
- package/dist-client/document/document-party.d.ts +5 -2
- package/dist-client/document/document-party.js +21 -21
- package/dist-client/document/document-party.js.map +1 -1
- package/dist-client/entity360/invoice-360.d.ts +3 -4
- package/dist-client/entity360/invoice-360.js +17 -38
- package/dist-client/entity360/invoice-360.js.map +1 -1
- package/dist-client/index.d.ts +1 -1
- package/dist-client/index.js +1 -1
- package/dist-client/index.js.map +1 -1
- package/dist-client/invoice-files.d.ts +4 -10
- package/dist-client/invoice-files.js +19 -58
- package/dist-client/invoice-files.js.map +1 -1
- package/dist-client/pages/invoice-editor.d.ts +42 -19
- package/dist-client/pages/invoice-editor.js +150 -179
- package/dist-client/pages/invoice-editor.js.map +1 -1
- package/dist-client/tsconfig.tsbuildinfo +1 -1
- package/dist-client/viewparts/document-defaults-setting-let.d.ts +7 -2
- package/dist-client/viewparts/document-defaults-setting-let.js +30 -35
- package/dist-client/viewparts/document-defaults-setting-let.js.map +1 -1
- package/dist-server/index.d.ts +1 -0
- package/dist-server/index.js +1 -0
- package/dist-server/index.js.map +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/dist-server/work-doors.d.ts +1 -0
- package/dist-server/work-doors.js +11 -0
- package/dist-server/work-doors.js.map +1 -0
- package/package.json +12 -12
- package/translations/en.json +2 -1
- package/translations/es.json +2 -1
- package/translations/ja.json +2 -1
- package/translations/ko.json +2 -1
- package/translations/ms.json +2 -1
- package/translations/zh.json +2 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"invoice-editor.js","sourceRoot":"","sources":["../../client/pages/invoice-editor.ts"],"names":[],"mappings":";AAAA,OAAO,iCAAiC,CAAA;AACxC,OAAO,sCAAs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QACX,QAAQ,EAAE,YAAY;QACtB,cAAc,EAAE,CAAC;QACjB,KAAK,EAAE,EAAE;KACV,CAAA;AACH,CAAC","sourcesContent":["import '@operato/data-grist/ox-grist.js'\nimport '@operato/list-state/ox-page-state.js'\n\nimport gql from 'graphql-tag'\nimport { css, html, nothing } from 'lit'\nimport { customElement, query, state } from 'lit/decorators.js'\n\nimport { DataGrist } from '@operato/data-grist'\nimport { client } from '@operato/graphql'\nimport { i18next, localize } from '@operato/i18n'\nimport { notify } from '@operato/layout'\nimport { OxPrompt } from '@operato/popup/ox-prompt.js'\nimport { navigate, PageView } from '@operato/shell'\nimport { ButtonStyles, CommonGristStyles, DocumentPageStyles, FormFieldStyles, ScrollbarStyles } from '@operato/styles'\n\nimport { daysAfter, nextInvoiceNumber } from '@things-factory/invoice/dist-shared/document-start.js'\n\nimport { documentAmount } from '../document/document-amount'\nimport { DocumentFormStyles, renderDocumentHead, renderDocumentTotals, type DocumentValue } from '../document/document-form'\nimport { documentLinesConfig, linesOf, onLineChange, reckonLines } from '../document/document-lines'\nimport { partyOfName, type DocumentParty } from '../document/document-party'\nimport { documentDefaults, headFromDefaults, OUR_SIDE_FIELDS, oursFromLast, type DocumentDefaults } from '../document/document-defaults'\nimport { openDocumentPreview, type DocumentFileFormat } from '../document/document-preview'\nimport { invoiceStatusWord } from '../entity360/invoice-360'\nimport { invoiceLinkSection } from '../invoice-attach'\nimport '../invoice-files'\n\nconst FIELDS = `\n id number status direction currency language counterpartyId counterparty { id name } supplierName supplierAddress supplierRegistrationNumber buyerName buyerAddress\n buyerRegistrationNumber issueDate dueDate purchaseOrder paymentTerms bankDetails notes sourceReference taxBasis voidReason\n discountAmount lineSupplyAmount supplyAmount taxAmount totalAmount taxRounding currencyDigits\n items { position description quantity unit unitPrice discount taxKind taxRate supplyAmount receivedTaxAmount }\n taxGroups { taxKind taxRate supplyAmount taxAmount }\n`\n\nconst HEAD = [\n 'number',\n 'counterpartyId',\n 'direction',\n 'currency',\n 'language',\n 'supplierName',\n 'supplierAddress',\n 'supplierRegistrationNumber',\n 'buyerName',\n 'buyerAddress',\n 'buyerRegistrationNumber',\n 'issueDate',\n 'dueDate',\n 'purchaseOrder',\n 'paymentTerms',\n 'bankDetails',\n 'notes',\n 'sourceReference',\n 'taxBasis',\n 'discountAmount'\n]\n\nconst today = () => new Date().toLocaleDateString('en-CA')\n\n/** Days an invoice is due after its issue unless the company says otherwise (ADR-0170 decision 11). */\nconst PAYMENT_DAYS = 30\n\ntype Party = DocumentParty\n\n/**\n * 청구서 편집 — the head, the lines, the totals by tax kind and rate, and what an application links it to.\n *\n * A draft is written and saved; 「발행」 saves what is on screen and issues it, after which its amounts never change.\n * An issued invoice is voided with a reason, in its own section. While a request runs only the inputs wait.\n */\n@customElement('invoice-editor')\nexport class InvoiceEditor extends localize(i18next)(PageView) {\n static styles = [\n FormFieldStyles,\n ButtonStyles,\n DocumentPageStyles,\n CommonGristStyles,\n ScrollbarStyles,\n DocumentFormStyles,\n css`\n ox-grist {\n height: calc(var(--form-element-height-medium) * 10);\n }\n `\n ]\n\n @state() invoice: DocumentValue | null = null\n @state() form: DocumentValue = blank()\n @state() loading = false\n @state() error: unknown = null\n @state() busy = false\n @state() voidReason = ''\n @state() gristConfig: any\n /** The totals of the lines as typed - reckoned as the invoice will keep them, shown before it is saved. */\n @state() amounts: Partial<DocumentValue> = {}\n /** The company's words a new invoice starts with, and the payment terms it offers (ADR-0170). */\n @state() defaults: DocumentDefaults | null = null\n /** The number a new invoice was offered - it follows the direction while the person leaves it. */\n @state() suggestedNumber = ''\n\n @query('ox-grist') private grist?: DataGrist\n\n private get received() {\n return this.form.taxBasis === 'RECEIVED'\n }\n\n get editable() {\n return !this.invoice || this.invoice.status === 'DRAFT'\n }\n\n get context() {\n const actions: any[] = []\n if (this.editable) {\n actions.push({ title: i18next.t('button.save'), icon: 'save', action: () => this.save() })\n actions.push({ title: i18next.t('button.invoice-issue'), icon: 'send', emphasis: { raised: true }, action: () => this.issue() })\n }\n if (this.invoice) actions.push({ title: i18next.t('button.preview'), icon: 'preview', action: () => this.preview() })\n return {\n title: this.invoice ? `${i18next.t('title.invoice')} ${this.invoice.number}` : i18next.t('title.invoice-new'),\n ...(this.invoice ? { description: invoiceStatusWord(this.invoice.status) } : {}),\n frame: 'document',\n /* Opened from the invoice list; the menu marks it. */\n menu: 'invoice-list',\n actions: this.error ? [] : actions\n }\n }\n\n async pageUpdated(changes: any, lifecycle: any) {\n if (!this.active || !(changes.active || changes.params)) return\n const id = lifecycle?.params?.id\n if (!this.defaults) this.defaults = await documentDefaults()\n if (!id) {\n this.invoice = null\n this.form = blank()\n this.amounts = {}\n this.configure()\n this.updateContext()\n /* Started, not waited for - the page's title stands meanwhile. */\n this.prefill()\n return\n }\n if (id !== this.invoice?.id) await this.load(id)\n }\n\n render() {\n const links = this.invoice ? invoiceLinkSection() : undefined\n return html`<ox-page-state .loading=${this.loading} .error=${this.error} @retry=${() => this.invoice && this.load(this.invoice.id)}>\n <div class=\"page\">\n <section class=\"page-section\">\n <header class=\"page-section-header\"><h3>${i18next.t('text.invoice-section-head')}</h3></header>\n ${renderDocumentHead(this.form, this.editable && !this.busy, patch => this.edit(patch), this.renderTerms(), 'field.invoice-number', {\n terms: this.defaults?.paymentTerms,\n party: this.renderParty(this.editable && !this.busy)\n })}\n </section>\n <section class=\"page-section\">\n <header class=\"page-section-header\"><h3>${i18next.t('text.invoice-section-lines')}</h3></header>\n <ox-grist\n mode=\"GRID\"\n .config=${this.gristConfig}\n .fetchHandler=${() => ({ total: this.form.items.length, records: this.form.items })}\n @record-change=${(e: CustomEvent) => (this.amounts = onLineChange(this.grist, e, this.form.currency, this.received, this.form.discountAmount))}\n ></ox-grist>\n </section>\n <section class=\"page-section\">\n <header class=\"page-section-header\"><h3>${i18next.t('text.invoice-section-totals')}</h3></header>\n ${renderDocumentTotals(\n { ...this.amounts, currency: this.form.currency },\n { value: this.form.discountAmount, editable: this.editable && !this.busy, change: value => this.discount(value) }\n )}\n </section>\n ${this.invoice\n ? html`<section class=\"page-section\">\n <header class=\"page-section-header\"><h3>${i18next.t('text.invoice-section-files')}</h3></header>\n <invoice-files .invoiceId=${this.invoice.id}></invoice-files>\n </section>`\n : nothing}\n ${links && this.invoice\n ? html`<section class=\"page-section\">\n <header class=\"page-section-header\"><h3>${links.heading()}</h3></header>\n ${links.render(this.invoice as any)}\n </section>`\n : nothing}\n ${this.invoice?.status === 'ISSUED' ? this.renderVoid() : nothing}\n </div>\n </ox-page-state>`\n }\n\n private renderTerms() {\n const editable = this.editable && !this.busy\n return html`<label\n >${i18next.t('field.invoice-due-date')}\n <input type=\"date\" .value=${this.form.dueDate ?? ''} ?disabled=${!editable} @input=${(e: any) => (this.form = { ...this.form, dueDate: e.target.value })}\n /></label>\n ${this.form.direction === 'PURCHASE'\n ? html`<label\n >${i18next.t('field.invoice-tax-basis')}\n <select ?disabled=${!editable} @change=${(e: any) => this.changeTaxBasis(e.target.value)}>\n <option value=\"CALCULATED\" ?selected=${this.form.taxBasis !== 'RECEIVED'}>${i18next.t('text.invoice-tax-basis-calculated')}</option>\n <option value=\"RECEIVED\" ?selected=${this.form.taxBasis === 'RECEIVED'}>${i18next.t('text.invoice-tax-basis-received')}</option>\n </select></label\n >`\n : nothing}`\n }\n\n /**\n * Who the other party is among the domain's counterparties - the buyer of a sale, the supplier of a purchase. Found by\n * name or business number; choosing one writes its name and number onto the printed side, which stays editable. A\n * saved invoice whose party is none of them says so under the picker (ADR-0170 decision 11).\n */\n private renderParty(editable: boolean) {\n const name = this.form.direction === 'PURCHASE' ? this.form.supplierName : this.form.buyerName\n return html`<label\n >${i18next.t('field.counterparty')}\n <document-party-select .party=${this.form.counterparty ?? null} ?disabled=${!editable} @party=${(e: CustomEvent) => this.chooseParty(e.detail)}></document-party-select>\n ${this.invoice && !this.form.counterpartyId && String(name ?? '').trim() ? html`<span class=\"quiet\">${i18next.t('text.invoice-counterparty-unlinked')}</span>` : nothing}\n </label>`\n }\n\n /**\n * A party typed by name and not picked is the counterparty of that name when exactly one is - case and spaces aside;\n * otherwise it stays unlinked and the editor says so.\n */\n private async linkByName() {\n if (this.form.counterpartyId) return\n const party = await partyOfName(this.form.direction === 'PURCHASE' ? this.form.supplierName : this.form.buyerName)\n if (party) this.form = { ...this.form, counterpartyId: party.id, counterparty: party }\n }\n\n /**\n * What a new invoice starts with, so a person writes only what is new: the number after the last sales invoice's, the\n * due date the company's days after the issue, the company's own words (ADR-0170 decision 6), and what they leave\n * blank of our side as the last sales invoice wrote it.\n */\n private async prefill() {\n let last: DocumentValue | undefined\n try {\n const response = await client.query({\n query: gql`\n query ($filters: [Filter!], $pagination: Pagination, $sortings: [Sorting!]) {\n invoices(filters: $filters, pagination: $pagination, sortings: $sortings) { items { number ${OUR_SIDE_FIELDS.join(' ')} } }\n }\n `,\n variables: { filters: [{ name: 'direction', operator: 'eq', value: 'SALES' }], pagination: { page: 1, limit: 1 }, sortings: [{ name: 'createdAt', desc: true }] },\n fetchPolicy: 'no-cache'\n })\n last = response.data?.invoices?.items?.[0]\n } catch {\n /* Nothing to follow - the first number of the year, and our side from the company's words alone. */\n }\n /* An invoice opened meanwhile is not a new one. */\n if (this.invoice) return\n this.suggestedNumber = nextInvoiceNumber(last?.number, Number(this.form.issueDate.slice(0, 4)))\n this.form = { ...this.form, ...headFromDefaults(this.form, this.defaults) }\n this.form = {\n ...this.form,\n ...oursFromLast(this.form, last),\n number: this.form.number || this.suggestedNumber,\n dueDate: this.form.dueDate || daysAfter(this.form.issueDate, this.paymentDays)\n }\n }\n\n /** Days an invoice is due - the company's, or thirty. */\n private get paymentDays() {\n return this.defaults?.paymentDays ?? PAYMENT_DAYS\n }\n\n private chooseParty(party: Party | null) {\n const side = this.form.direction === 'PURCHASE' ? 'supplier' : 'buyer'\n this.form = {\n ...this.form,\n counterpartyId: party?.id ?? null,\n counterparty: party,\n ...(party ? { [`${side}Name`]: party.name, [`${side}RegistrationNumber`]: party.businessNumber ?? this.form[`${side}RegistrationNumber`] } : {})\n }\n }\n\n private renderVoid() {\n return html`<section class=\"page-section\">\n <header class=\"page-section-header\">\n <h3>${i18next.t('text.invoice-section-void')}</h3>\n <div class=\"page-section-actions\">\n <button danger ?disabled=${this.busy || !this.voidReason.trim()} @click=${() => this.void()}>${i18next.t('button.invoice-void')}</button>\n </div>\n </header>\n <div class=\"form\">\n <label class=\"wide\"\n >${i18next.t('field.invoice-void-reason')}\n <input .value=${this.voidReason} ?disabled=${this.busy} @input=${(e: any) => (this.voidReason = e.target.value)}\n /></label>\n </div>\n </section>`\n }\n\n private changeTaxBasis(taxBasis: string) {\n this.form = { ...this.form, items: linesOf(this.grist), taxBasis }\n this.configure()\n this.updateComplete.then(() => (this.amounts = reckonLines(this.grist, this.form.currency, this.received, this.form.discountAmount)))\n }\n\n /** The discount of the whole invoice as typed, and the totals after it. */\n private discount(value: string) {\n this.form = { ...this.form, discountAmount: value }\n this.amounts = reckonLines(this.grist, this.form.currency, this.received, value)\n }\n\n /**\n * A change of the head; a new currency reckons the lines in its minor unit; the due date follows a moved issue date\n * while it is the one offered. A new invoice's offered number is ours - a purchase carries its sender's, so it goes\n * while the person leaves it, and comes back with a sale.\n */\n private edit(patch: DocumentValue) {\n const currency = this.form.currency\n const following = patch.issueDate && this.form.dueDate === daysAfter(this.form.issueDate, this.paymentDays)\n const number =\n this.invoice || !patch.direction\n ? {}\n : patch.direction === 'PURCHASE' && this.form.number === this.suggestedNumber\n ? { number: '' }\n : patch.direction === 'SALES' && !String(this.form.number ?? '').trim()\n ? { number: this.suggestedNumber }\n : {}\n this.form = { ...this.form, ...patch, ...number, ...(following ? { dueDate: daysAfter(patch.issueDate, this.paymentDays) } : {}) }\n if (patch.currency && patch.currency !== currency) {\n this.configure()\n this.amounts = reckonLines(this.grist, this.form.currency, this.received, this.form.discountAmount)\n }\n }\n\n private configure() {\n this.gristConfig = documentLinesConfig({ editable: this.editable, received: this.form.taxBasis === 'RECEIVED', currency: this.form.currency || 'KRW' })\n }\n\n private async load(id: string) {\n this.loading = true\n this.error = null\n try {\n const response = await client.query({ query: gql(`query ($id: String!) { invoice(id: $id) { ${FIELDS} } }`), variables: { id }, fetchPolicy: 'no-cache' })\n if (response.errors?.length) throw response\n if (!response.data.invoice) throw new Error(i18next.t('text.invoice-not-found'))\n this.show(response.data.invoice)\n } catch (error) {\n this.error = error\n } finally {\n this.loading = false\n this.updateContext()\n }\n }\n\n private show(invoice: DocumentValue) {\n this.invoice = invoice\n this.form = { ...invoice, items: invoice.items.map((item: any) => ({ ...item })) }\n this.amounts = invoice\n this.voidReason = ''\n this.configure()\n this.grist?.fetch()\n }\n\n /** Runs one request at a time; a refusal is said in the server's words. */\n private async run<T>(work: () => Promise<T>): Promise<T | undefined> {\n if (this.busy) return undefined\n this.busy = true\n try {\n return await work()\n } catch (error: any) {\n notify({ level: 'error', message: error?.graphQLErrors?.[0]?.message ?? error?.errors?.[0]?.message ?? error?.message ?? String(error) })\n return undefined\n } finally {\n this.busy = false\n }\n }\n\n private input() {\n const input: DocumentValue = Object.fromEntries(HEAD.map(key => [key, this.form[key] === '' ? null : this.form[key] ?? null]))\n input.taxBasis = input.direction === 'PURCHASE' ? input.taxBasis || 'CALCULATED' : 'CALCULATED'\n input.items = linesOf(this.grist)\n input.discountAmount = input.discountAmount === null ? 0 : Number(input.discountAmount)\n return input\n }\n\n private async save(): Promise<DocumentValue | undefined> {\n const id = this.invoice?.id\n if (this.busy) return undefined\n await this.linkByName()\n const saved = await this.run(async () => {\n const response = await client.mutate({\n mutation: gql(\n id\n ? `mutation ($id: String!, $invoice: NewInvoice!) { invoice: updateInvoice(id: $id, invoice: $invoice) { ${FIELDS} } }`\n : `mutation ($invoice: NewInvoice!) { invoice: createInvoice(invoice: $invoice) { ${FIELDS} } }`\n ),\n variables: { ...(id ? { id } : {}), invoice: this.input() }\n })\n if (response.errors?.length) throw response\n return response.data.invoice as DocumentValue\n })\n if (!saved) return undefined\n this.show(saved)\n this.updateContext()\n if (!id) navigate(`invoice-editor?id=${saved.id}`)\n return saved\n }\n\n /** Asked first - to whom and how much, fixed after - then save what is on screen and issue it. */\n private async issue() {\n const purchase = this.form.direction === 'PURCHASE'\n const words = {\n party: (purchase ? this.form.supplierName : this.form.buyerName) || '—',\n total: documentAmount(this.amounts.totalAmount ?? 0, this.form.currency || 'KRW')\n }\n const confirmed = await OxPrompt.open({\n title: i18next.t('button.invoice-issue'),\n text: purchase ? i18next.t('text.invoice-issue-confirm-purchase', words) : i18next.t('text.invoice-issue-confirm', words),\n confirmButton: { text: i18next.t('button.invoice-issue') },\n cancelButton: { text: i18next.t('button.cancel') }\n })\n if (!confirmed) return\n const saved = await this.save()\n if (!saved) return\n const issued = await this.mutate(`mutation ($id: String!) { invoice: issueInvoice(id: $id) { ${FIELDS} } }`, { id: saved.id })\n if (issued) notify({ level: 'info', message: i18next.t('text.invoice-issued') })\n }\n\n private async void() {\n const confirmed = await OxPrompt.open({\n title: i18next.t('button.invoice-void'),\n text: i18next.t('text.invoice-void-confirm'),\n confirmButton: { text: i18next.t('button.invoice-void'), destructive: true },\n cancelButton: { text: i18next.t('button.cancel') }\n })\n if (!confirmed) return\n await this.mutate(`mutation ($id: String!, $reason: String!) { invoice: voidInvoice(id: $id, reason: $reason) { ${FIELDS} } }`, {\n id: this.invoice!.id,\n reason: this.voidReason.trim()\n })\n }\n\n private async mutate(mutation: string, variables: any) {\n const changed = await this.run(async () => {\n const response = await client.mutate({ mutation: gql(mutation), variables })\n if (response.errors?.length) throw response\n return response.data.invoice as DocumentValue\n })\n if (changed) {\n this.show(changed)\n this.updateContext()\n }\n return changed\n }\n\n /**\n * The saved invoice as it goes out (ADR-0170 decision 10) - the server's page in the language chosen there, the\n * invoice's own first, to download as PDF or print. What is on screen and not saved is not in it.\n */\n private preview() {\n const { id, number, language } = this.invoice!\n openDocumentPreview(\n async (format: DocumentFileFormat, lng: string) => {\n const response = await client.query({\n query: gql`\n query ($id: String!, $format: DocumentFileFormat!, $language: String) {\n invoiceDocumentFile(id: $id, format: $format, language: $language) { fileName mimeType content }\n }\n `,\n variables: { id, format, language: lng },\n fetchPolicy: 'no-cache'\n })\n if (!response.data?.invoiceDocumentFile) throw response.errors?.[0] ?? new Error(i18next.t('text.invoice-not-found'))\n return response.data.invoiceDocumentFile\n },\n language,\n `${i18next.t('title.preview')} · ${number}`\n )\n }\n}\n\nfunction blank(): DocumentValue {\n return {\n number: '',\n direction: 'SALES',\n currency: 'KRW',\n language: 'ko',\n supplierName: '',\n buyerName: '',\n issueDate: today(),\n dueDate: '',\n taxBasis: 'CALCULATED',\n discountAmount: 0,\n items: []\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"invoice-editor.js","sourceRoot":"","sources":["../../client/pages/invoice-editor.ts"],"names":[],"mappings":";AAAA,OAAO,iCAAiC,CAAA;AACxC,OAAO,sCAAsC,CAAA;AAE7C,OAAO,GAAG,MAAM,aAAa,CAAA;AAC7B,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,KAAK,CAAA;AACxC,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAG/D,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAC/C,OAAO,EAAE,MAAM,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAC9E,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACjD,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAA;AACtD,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AACpE,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACvH,OAAO,EAAE,YAAY,EAAE,MAAM,uCAAuC,CAAA;AAEpE,OAAO,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d,YAAY,EAAE,EAAE;QAChB,SAAS,EAAE,EAAE;QACb,SAAS,EAAE,KAAK,EAAE;QAClB,OAAO,EAAE,EAAE;QACX,QAAQ,EAAE,YAAY;QACtB,cAAc,EAAE,CAAC;QACjB,KAAK,EAAE,EAAE;KACV,CAAA;AACH,CAAC","sourcesContent":["import '@operato/data-grist/ox-grist.js'\nimport '@operato/list-state/ox-page-state.js'\n\nimport gql from 'graphql-tag'\nimport { css, html, nothing } from 'lit'\nimport { customElement, query, state } from 'lit/decorators.js'\nimport type { PropertyValues } from 'lit'\n\nimport { DataGrist } from '@operato/data-grist'\nimport { client, MutationController, QueryController } from '@operato/graphql'\nimport { i18next, localize } from '@operato/i18n'\nimport { notify } from '@operato/layout'\nimport { OxPrompt } from '@operato/popup/ox-prompt.js'\nimport { navigate, PageView, DraftController } from '@operato/shell'\nimport { ButtonStyles, CommonGristStyles, DocumentPageStyles, FormFieldStyles, ScrollbarStyles } from '@operato/styles'\nimport { hasPrivilege } from '@things-factory/auth-base/dist-client'\n\nimport { daysAfter, nextInvoiceNumber } from '@things-factory/invoice/dist-shared/document-start.js'\n\nimport { documentAmount } from '../document/document-amount'\nimport { DocumentFormStyles, renderDocumentHead, renderDocumentTotals, type DocumentValue } from '../document/document-form'\nimport { documentLinesConfig, linesOf, onLineChange, reckonLines } from '../document/document-lines'\nimport { partyOfName, type DocumentParty } from '../document/document-party'\nimport { DOCUMENT_DEFAULTS, DOCUMENT_DEFAULTS_READER, headFromDefaults, OUR_SIDE_FIELDS, oursFromLast, type DocumentDefaults } from '../document/document-defaults'\nimport { openDocumentPreview, type DocumentFileFormat } from '../document/document-preview'\nimport { invoiceStatusWord } from '../entity360/invoice-360'\nimport { invoiceLinkSection } from '../invoice-attach'\nimport '../invoice-files'\n\nconst FIELDS = `\n id number status direction currency language counterpartyId counterparty { id name } supplierName supplierAddress supplierRegistrationNumber buyerName buyerAddress\n buyerRegistrationNumber issueDate dueDate purchaseOrder paymentTerms bankDetails notes sourceReference taxBasis voidReason\n discountAmount lineSupplyAmount supplyAmount taxAmount totalAmount taxRounding currencyDigits\n items { position description quantity unit unitPrice discount taxKind taxRate supplyAmount receivedTaxAmount }\n taxGroups { taxKind taxRate supplyAmount taxAmount }\n`\n\nconst HEAD = [\n 'number',\n 'counterpartyId',\n 'direction',\n 'currency',\n 'language',\n 'supplierName',\n 'supplierAddress',\n 'supplierRegistrationNumber',\n 'buyerName',\n 'buyerAddress',\n 'buyerRegistrationNumber',\n 'issueDate',\n 'dueDate',\n 'purchaseOrder',\n 'paymentTerms',\n 'bankDetails',\n 'notes',\n 'sourceReference',\n 'taxBasis',\n 'discountAmount'\n]\n\nconst today = () => new Date().toLocaleDateString('en-CA')\n\n/** Days an invoice is due after its issue unless the company says otherwise (ADR-0170 decision 11). */\nconst PAYMENT_DAYS = 30\n\ntype Party = DocumentParty\n\n/**\n * 청구서 편집 — the head, the lines, the totals by tax kind and rate, and what an application links it to.\n *\n * A draft is written and saved; 「발행」 saves what is on screen and issues it, after which its amounts never change.\n * An issued invoice is voided with a reason, in its own section. While a request runs only the inputs wait.\n */\n@customElement('invoice-editor')\nexport class InvoiceEditor extends localize(i18next)(PageView) {\n static styles = [\n FormFieldStyles,\n ButtonStyles,\n DocumentPageStyles,\n CommonGristStyles,\n ScrollbarStyles,\n DocumentFormStyles,\n css`\n ox-grist {\n height: calc(var(--form-element-height-medium) * 10);\n }\n `\n ]\n\n /** What the address opens: an invoice by id, or a new one. */\n @state() private address?: { id?: string }\n @state() gristConfig: any\n /** The totals of the lines as typed - reckoned as the invoice will keep them, shown before it is saved. */\n @state() private typedAmounts: Partial<DocumentValue> | null = null\n /** Whether this person may read the company's words - unknown, and nothing read, until asked. */\n @state() private defaultsReadable = false\n\n /* The company's words, the invoice the address names, and the last sales invoice a new one follows (ADR-0190). */\n private companyDefaults = new QueryController(this, DOCUMENT_DEFAULTS, { variables: () => (this.defaultsReadable ? {} : undefined) })\n private record = new QueryController(this, gql(`query ($id: String!) { invoice(id: $id) { ${FIELDS} } }`), {\n variables: () => (this.invoiceId ? { id: this.invoiceId } : undefined)\n })\n private last = new QueryController(\n this,\n gql`\n query ($filters: [Filter!], $pagination: Pagination, $sortings: [Sorting!]) {\n invoices(filters: $filters, pagination: $pagination, sortings: $sortings) { items { number ${OUR_SIDE_FIELDS.join(' ')} } }\n }\n `,\n {\n variables: () =>\n this.address && !this.address.id\n ? { filters: [{ name: 'direction', operator: 'eq', value: 'SALES' }], pagination: { page: 1, limit: 1 }, sortings: [{ name: 'createdAt', desc: true }] }\n : undefined\n }\n )\n\n /* What is typed over the invoice read, or over what a new one starts with; the lines are the grid's. */\n private draft = new DraftController<DocumentValue>(this, { read: () => this.formRead, key: () => this.address })\n /* The reason an issued one is voided with. */\n private voiding = new DraftController<{ reason: string }>(this, { read: () => ({ reason: '' }), key: () => this.address })\n\n /* Every change of the invoice reads it again once it is done. */\n private saves = {\n create: new MutationController(this, gql`mutation ($invoice: NewInvoice!) { invoice: createInvoice(invoice: $invoice) { id } }`),\n update: this.saving(gql`mutation ($id: String!, $invoice: NewInvoice!) { invoice: updateInvoice(id: $id, invoice: $invoice) { id } }`),\n issue: this.saving(gql`mutation ($id: String!) { invoice: issueInvoice(id: $id) { id } }`),\n void: this.saving(gql`mutation ($id: String!, $reason: String!) { invoice: voidInvoice(id: $id, reason: $reason) { id } }`)\n }\n\n private saving(mutation: any) {\n return new MutationController(this, mutation, { refetch: () => [this.record] })\n }\n\n private get invoiceId() {\n return this.address?.id ?? ''\n }\n\n /** The company's words a new invoice starts with, and the payment terms it offers (ADR-0170) - none until read. */\n get defaults(): DocumentDefaults | null {\n return this.companyDefaults.data?.documentDefaults ?? null\n }\n\n get invoice(): DocumentValue | null {\n return (this.invoiceId && this.record.data?.invoice) || null\n }\n\n /** What the form shows unedited: the invoice read, or what a new one starts with. */\n private get formRead(): DocumentValue | undefined {\n if (!this.address) return undefined\n return this.address.id ? (this.invoice ?? undefined) : this.start\n }\n\n /** The form as it shows: each field's edit, else what was read. */\n get form(): DocumentValue {\n return { ...blank(), ...this.formRead, ...this.draft.edits }\n }\n\n /** The totals of the lines as typed, else as the invoice keeps them. */\n get amounts(): Partial<DocumentValue> {\n return this.typedAmounts ?? this.invoice ?? {}\n }\n\n get voidReason() {\n return this.voiding.value('reason') ?? ''\n }\n\n /** A failed read, or an invoice the address names that is not there. */\n get error(): unknown {\n if (this.record.error) return this.record.error\n return this.invoiceId && this.record.data && !this.record.data.invoice ? new Error(i18next.t('text.invoice-not-found')) : null\n }\n\n get loading() {\n return this.record.loading\n }\n\n /** Runs one request at a time. */\n get busy() {\n return Object.values(this.saves).some(save => save.pending)\n }\n\n @query('ox-grist') private grist?: DataGrist\n\n private get received() {\n return this.form.taxBasis === 'RECEIVED'\n }\n\n get editable() {\n return !this.invoice || this.invoice.status === 'DRAFT'\n }\n\n get context() {\n const actions: any[] = []\n if (this.editable) {\n actions.push({ title: i18next.t('button.save'), icon: 'save', action: () => this.save() })\n actions.push({ title: i18next.t('button.invoice-issue'), icon: 'send', emphasis: { raised: true }, action: () => this.issue() })\n }\n if (this.invoice) actions.push({ title: i18next.t('button.preview'), icon: 'preview', action: () => this.preview() })\n return {\n title: this.invoice ? `${i18next.t('title.invoice')} ${this.invoice.number}` : i18next.t('title.invoice-new'),\n ...(this.invoice ? { description: invoiceStatusWord(this.invoice.status) } : {}),\n frame: 'document',\n /* Opened from the invoice list; the menu marks it. */\n menu: 'invoice-list',\n actions: this.error ? [] : actions\n }\n }\n\n pageUpdated(changes: any, lifecycle: any) {\n if (!this.active || !(changes.active || changes.params)) return\n const id = lifecycle?.params?.id\n if (!this.defaultsReadable) hasPrivilege(DOCUMENT_DEFAULTS_READER).then(may => (this.defaultsReadable = !!may))\n this.address = id ? { id } : {}\n }\n\n /* The lines and their totals are the grid's: a new answer, or another invoice, puts the lines read in it again. */\n private lined?: unknown\n private relined = false\n\n willUpdate(changes: PropertyValues) {\n super.willUpdate(changes)\n const source = this.invoiceId ? this.invoice : JSON.stringify(this.address ?? null)\n if (source === this.lined) return\n this.lined = source\n this.typedAmounts = null\n this.configure()\n this.relined = true\n }\n\n updated(changes: PropertyValues) {\n super.updated(changes)\n if (!this.relined) return\n this.relined = false\n this.grist?.fetch()\n }\n\n render() {\n const links = this.invoice ? invoiceLinkSection() : undefined\n return html`<ox-page-state .loading=${this.loading} .error=${this.error} @retry=${() => this.record.refetch()}>\n <div class=\"page\">\n <section class=\"page-section\">\n <header class=\"page-section-header\"><h3>${i18next.t('text.invoice-section-head')}</h3></header>\n ${renderDocumentHead(this.form, this.editable && !this.busy, patch => this.edit(patch), this.renderTerms(), 'field.invoice-number', {\n terms: this.defaults?.paymentTerms,\n party: this.renderParty(this.editable && !this.busy)\n })}\n </section>\n <section class=\"page-section\">\n <header class=\"page-section-header\"><h3>${i18next.t('text.invoice-section-lines')}</h3></header>\n <ox-grist\n mode=\"GRID\"\n .config=${this.gristConfig}\n .fetchHandler=${() => ({ total: (this.form.items ?? []).length, records: (this.form.items ?? []).map((item: any) => ({ ...item })) })}\n @record-change=${(e: CustomEvent) => (this.typedAmounts = onLineChange(this.grist, e, this.form.currency, this.received, this.form.discountAmount))}\n ></ox-grist>\n </section>\n <section class=\"page-section\">\n <header class=\"page-section-header\"><h3>${i18next.t('text.invoice-section-totals')}</h3></header>\n ${renderDocumentTotals(\n { ...this.amounts, currency: this.form.currency },\n { value: this.form.discountAmount, editable: this.editable && !this.busy, change: value => this.discount(value) }\n )}\n </section>\n ${this.invoice\n ? html`<section class=\"page-section\">\n <header class=\"page-section-header\"><h3>${i18next.t('text.invoice-section-files')}</h3></header>\n <invoice-files .invoiceId=${this.invoice.id}></invoice-files>\n </section>`\n : nothing}\n ${links && this.invoice\n ? html`<section class=\"page-section\">\n <header class=\"page-section-header\"><h3>${links.heading()}</h3></header>\n ${links.render(this.invoice as any)}\n </section>`\n : nothing}\n ${this.invoice?.status === 'ISSUED' ? this.renderVoid() : nothing}\n </div>\n </ox-page-state>`\n }\n\n private renderTerms() {\n const editable = this.editable && !this.busy\n return html`<label\n >${i18next.t('field.invoice-due-date')}\n <input type=\"date\" .value=${this.form.dueDate ?? ''} ?disabled=${!editable} @input=${(e: any) => this.put({ dueDate: e.target.value })}\n /></label>\n ${this.form.direction === 'PURCHASE'\n ? html`<label\n >${i18next.t('field.invoice-tax-basis')}\n <select ?disabled=${!editable} @change=${(e: any) => this.changeTaxBasis(e.target.value)}>\n <option value=\"CALCULATED\" ?selected=${this.form.taxBasis !== 'RECEIVED'}>${i18next.t('text.invoice-tax-basis-calculated')}</option>\n <option value=\"RECEIVED\" ?selected=${this.form.taxBasis === 'RECEIVED'}>${i18next.t('text.invoice-tax-basis-received')}</option>\n </select></label\n >`\n : nothing}`\n }\n\n /**\n * Who the other party is among the domain's counterparties - the buyer of a sale, the supplier of a purchase. Found by\n * name or business number; choosing one writes its name and number onto the printed side, which stays editable. A\n * saved invoice whose party is none of them says so under the picker (ADR-0170 decision 11).\n */\n private renderParty(editable: boolean) {\n const name = this.form.direction === 'PURCHASE' ? this.form.supplierName : this.form.buyerName\n return html`<label\n >${i18next.t('field.counterparty')}\n <document-party-select .party=${this.form.counterparty ?? null} ?disabled=${!editable} @party=${(e: CustomEvent) => this.chooseParty(e.detail)}></document-party-select>\n ${this.invoice && !this.form.counterpartyId && String(name ?? '').trim() ? html`<span class=\"quiet\">${i18next.t('text.invoice-counterparty-unlinked')}</span>` : nothing}\n </label>`\n }\n\n /**\n * A party typed by name and not picked is the counterparty of that name when exactly one is - case and spaces aside;\n * otherwise it stays unlinked and the editor says so. Looked up for the save and shown nowhere: the invoice read after\n * it shows the link.\n */\n private async linkByName(): Promise<Party | null> {\n if (this.form.counterpartyId) return null\n return partyOfName(this.form.direction === 'PURCHASE' ? this.form.supplierName : this.form.buyerName)\n }\n\n /**\n * What a new invoice starts with, so a person writes only what is new: the number after the last sales invoice's, the\n * due date the company's days after the issue, the company's own words (ADR-0170 decision 6), and what they leave\n * blank of our side as the last sales invoice wrote it.\n */\n private get start(): DocumentValue {\n const form = blank()\n const head = { ...form, ...headFromDefaults(form, this.defaults) }\n return {\n ...head,\n ...oursFromLast(head, this.last.data?.invoices?.items?.[0]),\n number: this.suggestedNumber,\n dueDate: daysAfter(form.issueDate, this.paymentDays)\n }\n }\n\n /** The number a new invoice is offered once the last one is read - it follows the direction while the person leaves it. */\n private get suggestedNumber() {\n if (!this.last.answeredAt && !this.last.error) return ''\n const last = this.last.data?.invoices?.items?.[0]\n return nextInvoiceNumber(last?.number, Number(today().slice(0, 4)))\n }\n\n /** Days an invoice is due - the company's, or thirty. */\n private get paymentDays() {\n return this.defaults?.paymentDays ?? PAYMENT_DAYS\n }\n\n private chooseParty(party: Party | null) {\n const side = this.form.direction === 'PURCHASE' ? 'supplier' : 'buyer'\n this.put({\n counterpartyId: party?.id ?? null,\n counterparty: party,\n ...(party ? { [`${side}Name`]: party.name, [`${side}RegistrationNumber`]: party.businessNumber ?? this.form[`${side}RegistrationNumber`] } : {})\n })\n }\n\n /** Edits of several fields at once. */\n private put(patch: DocumentValue) {\n for (const [name, value] of Object.entries(patch)) this.draft.set(name, value)\n }\n\n private renderVoid() {\n return html`<section class=\"page-section\">\n <header class=\"page-section-header\">\n <h3>${i18next.t('text.invoice-section-void')}</h3>\n <div class=\"page-section-actions\">\n <button danger ?disabled=${this.busy || !this.voidReason.trim()} @click=${() => this.void()}>${i18next.t('button.invoice-void')}</button>\n </div>\n </header>\n <div class=\"form\">\n <label class=\"wide\"\n >${i18next.t('field.invoice-void-reason')}\n <input .value=${this.voidReason} ?disabled=${this.busy} @input=${(e: any) => this.voiding.set('reason', e.target.value)}\n /></label>\n </div>\n </section>`\n }\n\n private changeTaxBasis(taxBasis: string) {\n this.put({ items: linesOf(this.grist), taxBasis })\n this.configure()\n this.updateComplete.then(() => (this.typedAmounts = reckonLines(this.grist, this.form.currency, this.received, this.form.discountAmount)))\n }\n\n /** The discount of the whole invoice as typed, and the totals after it. */\n private discount(value: string) {\n this.put({ discountAmount: value })\n this.typedAmounts = reckonLines(this.grist, this.form.currency, this.received, value)\n }\n\n /**\n * A change of the head; a new currency reckons the lines in its minor unit; the due date follows a moved issue date\n * while it is the one offered. A new invoice's offered number is ours - a purchase carries its sender's, so it goes\n * while the person leaves it, and comes back with a sale.\n */\n private edit(patch: DocumentValue) {\n const currency = this.form.currency\n const following = patch.issueDate && this.form.dueDate === daysAfter(this.form.issueDate, this.paymentDays)\n const number =\n this.invoice || !patch.direction\n ? {}\n : patch.direction === 'PURCHASE' && this.form.number === this.suggestedNumber\n ? { number: '' }\n : patch.direction === 'SALES' && !String(this.form.number ?? '').trim()\n ? { number: this.suggestedNumber }\n : {}\n this.put({ ...patch, ...number, ...(following ? { dueDate: daysAfter(patch.issueDate, this.paymentDays) } : {}) })\n if (patch.currency && patch.currency !== currency) {\n this.configure()\n this.typedAmounts = reckonLines(this.grist, this.form.currency, this.received, this.form.discountAmount)\n }\n }\n\n private configure() {\n this.gristConfig = documentLinesConfig({ editable: this.editable, received: this.form.taxBasis === 'RECEIVED', currency: this.form.currency || 'KRW' })\n }\n\n private input() {\n const input: DocumentValue = Object.fromEntries(HEAD.map(key => [key, this.form[key] === '' ? null : this.form[key] ?? null]))\n input.taxBasis = input.direction === 'PURCHASE' ? input.taxBasis || 'CALCULATED' : 'CALCULATED'\n input.items = linesOf(this.grist)\n input.discountAmount = input.discountAmount === null ? 0 : Number(input.discountAmount)\n return input\n }\n\n /** A new one is opened once it is made; the edits sent are cleared once the save answered. Answers the invoice's id. */\n private async save(): Promise<string | undefined> {\n if (this.busy) return undefined\n const id = this.invoiceId\n const linked = await this.linkByName()\n const saved = await this.draft.submit(() => {\n const invoice = { ...this.input(), ...(linked ? { counterpartyId: linked.id } : {}) }\n return id ? this.saves.update.run({ id, invoice }) : this.saves.create.run({ invoice })\n })\n if (!saved) return undefined\n if (!id) {\n /* The lines went with it: the grid keeps them as saved while the new invoice opens. */\n this.grist?.commit()\n navigate(`invoice-editor?id=${saved.invoice.id}`)\n }\n return saved.invoice.id\n }\n\n /** Asked first - to whom and how much, fixed after - then save what is on screen and issue it. */\n private async issue() {\n const purchase = this.form.direction === 'PURCHASE'\n const words = {\n party: (purchase ? this.form.supplierName : this.form.buyerName) || '—',\n total: documentAmount(this.amounts.totalAmount ?? 0, this.form.currency || 'KRW')\n }\n const confirmed = await OxPrompt.open({\n title: i18next.t('button.invoice-issue'),\n text: purchase ? i18next.t('text.invoice-issue-confirm-purchase', words) : i18next.t('text.invoice-issue-confirm', words),\n confirmButton: { text: i18next.t('button.invoice-issue') },\n cancelButton: { text: i18next.t('button.cancel') }\n })\n if (!confirmed) return\n const saved = await this.save()\n if (!saved) return\n const issued = await this.saves.issue.run({ id: saved })\n if (issued) notify({ level: 'info', message: i18next.t('text.invoice-issued') })\n }\n\n private async void() {\n const confirmed = await OxPrompt.open({\n title: i18next.t('button.invoice-void'),\n text: i18next.t('text.invoice-void-confirm'),\n confirmButton: { text: i18next.t('button.invoice-void'), destructive: true },\n cancelButton: { text: i18next.t('button.cancel') }\n })\n if (!confirmed) return\n await this.voiding.submit(sent => this.saves.void.run({ id: this.invoiceId, reason: (sent.reason ?? '').trim() }))\n }\n\n /**\n * The saved invoice as it goes out (ADR-0170 decision 10) - the server's page in the language chosen there, the\n * invoice's own first, to download as PDF or print. What is on screen and not saved is not in it.\n */\n private preview() {\n const { id, number, language } = this.invoice!\n openDocumentPreview(\n async (format: DocumentFileFormat, lng: string) => {\n const response = await client.query({\n query: gql`\n query ($id: String!, $format: DocumentFileFormat!, $language: String) {\n invoiceDocumentFile(id: $id, format: $format, language: $language) { fileName mimeType content }\n }\n `,\n variables: { id, format, language: lng },\n fetchPolicy: 'no-cache'\n })\n if (!response.data?.invoiceDocumentFile) throw response.errors?.[0] ?? new Error(i18next.t('text.invoice-not-found'))\n return response.data.invoiceDocumentFile\n },\n language,\n `${i18next.t('title.preview')} · ${number}`\n )\n }\n}\n\nfunction blank(): DocumentValue {\n return {\n number: '',\n direction: 'SALES',\n currency: 'KRW',\n language: 'ko',\n supplierName: '',\n buyerName: '',\n issueDate: today(),\n dueDate: '',\n taxBasis: 'CALCULATED',\n discountAmount: 0,\n items: []\n }\n}\n"]}
|