@things-factory/sales 10.1.176 → 10.1.178

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 (32) hide show
  1. package/dist-client/opportunity-attach.js.map +1 -1
  2. package/dist-client/pages/opportunity-editor.d.ts +2 -0
  3. package/dist-client/pages/opportunity-editor.js +50 -4
  4. package/dist-client/pages/opportunity-editor.js.map +1 -1
  5. package/dist-client/pages/quotation-editor.d.ts +10 -0
  6. package/dist-client/pages/quotation-editor.js +50 -6
  7. package/dist-client/pages/quotation-editor.js.map +1 -1
  8. package/dist-client/tsconfig.tsbuildinfo +1 -1
  9. package/dist-server/service/index.d.ts +1 -1
  10. package/dist-server/service/opportunity/opportunity-query.d.ts +2 -0
  11. package/dist-server/service/opportunity/opportunity-query.js +12 -0
  12. package/dist-server/service/opportunity/opportunity-query.js.map +1 -1
  13. package/dist-server/service/quotation/quotation-query.d.ts +2 -0
  14. package/dist-server/service/quotation/quotation-query.js +11 -0
  15. package/dist-server/service/quotation/quotation-query.js.map +1 -1
  16. package/dist-server/service/quotation/quotation-service.d.ts +2 -0
  17. package/dist-server/service/quotation/quotation-service.js +16 -4
  18. package/dist-server/service/quotation/quotation-service.js.map +1 -1
  19. package/dist-server/service/quotation/quotation-type.d.ts +1 -0
  20. package/dist-server/service/quotation/quotation-type.js +4 -0
  21. package/dist-server/service/quotation/quotation-type.js.map +1 -1
  22. package/dist-server/service/quotation/quotation.d.ts +3 -0
  23. package/dist-server/service/quotation/quotation.js +12 -0
  24. package/dist-server/service/quotation/quotation.js.map +1 -1
  25. package/dist-server/tsconfig.tsbuildinfo +1 -1
  26. package/package.json +6 -6
  27. package/translations/en.json +5 -1
  28. package/translations/es.json +5 -1
  29. package/translations/ja.json +5 -1
  30. package/translations/ko.json +5 -1
  31. package/translations/ms.json +5 -1
  32. package/translations/zh.json +5 -1
@@ -1 +1 @@
1
- {"version":3,"file":"opportunity-attach.js","sourceRoot":"","sources":["../client/opportunity-attach.ts"],"names":[],"mappings":"AAcA,IAAI,OAAuC,CAAA;AAE3C,MAAM,UAAU,2BAA2B,CAAC,GAAuB;IACjE,OAAO,GAAG,GAAG,CAAA;AACf,CAAC;AAED,MAAM,UAAU,kBAAkB;IAChC,OAAO,OAAO,CAAA;AAChB,CAAC","sourcesContent":["import { type TemplateResult } from 'lit'\n\n/*\n * Where an application attaches its own work to an opportunity — Office ties it to the contract it became and to the\n * classification its pivot judgement reads (ADR-0138 decision 8). The sales module knows no application words.\n */\n\nexport type OpportunitySection = {\n /** The section's heading, already in the reader's words. */\n heading: () => string\n /** The section's body for one saved opportunity; it reads and writes through the application's own API. */\n render: (opportunity: { id: string; name: string; stage: string; counterpartyId: string; currency: string; amount: number; expectedCloseMonth: string }) => TemplateResult\n}\n\nlet section: OpportunitySection | undefined\n\nexport function configureOpportunitySection(one: OpportunitySection): void {\n section = one\n}\n\nexport function opportunitySection(): OpportunitySection | undefined {\n return section\n}\n"]}
1
+ {"version":3,"file":"opportunity-attach.js","sourceRoot":"","sources":["../client/opportunity-attach.ts"],"names":[],"mappings":"AAeA,IAAI,OAAuC,CAAA;AAE3C,MAAM,UAAU,2BAA2B,CAAC,GAAuB;IACjE,OAAO,GAAG,GAAG,CAAA;AACf,CAAC;AAED,MAAM,UAAU,kBAAkB;IAChC,OAAO,OAAO,CAAA;AAChB,CAAC","sourcesContent":["import { type TemplateResult } from 'lit'\n\n/*\n * Where an application attaches its own work to an opportunity — Office ties it to the contract it became and to the\n * classification its pivot judgement reads (ADR-0138 decision 8). The sales module knows no application words. A\n * section that changed the opportunity (closed it as won) dispatches `opportunity-changed`; the editor reads it again.\n */\n\nexport type OpportunitySection = {\n /** The section's heading, already in the reader's words. */\n heading: () => string\n /** The section's body for one saved opportunity; it reads and writes through the application's own API. */\n render: (opportunity: { id: string; name: string; stage: string; counterpartyId: string; currency: string; amount: number; expectedCloseMonth: string }) => TemplateResult\n}\n\nlet section: OpportunitySection | undefined\n\nexport function configureOpportunitySection(one: OpportunitySection): void {\n section = one\n}\n\nexport function opportunitySection(): OpportunitySection | undefined {\n return section\n}\n"]}
@@ -64,6 +64,8 @@ export declare class OpportunityEditor extends OpportunityEditor_base {
64
64
  /** A counterparty of the domain, found by name or business number. */
65
65
  private renderParty;
66
66
  private renderLose;
67
+ /** The quotations that answer this opportunity; a new one is written from here and answers it. */
68
+ private renderQuotations;
67
69
  private renderEvents;
68
70
  private setPicker;
69
71
  private chooseParty;
@@ -8,12 +8,14 @@ import { i18next, localize } from '@operato/i18n';
8
8
  import { notify } from '@operato/layout';
9
9
  import { navigate, PageView } from '@operato/shell';
10
10
  import { ButtonStyles, DocumentPageStyles, FormFieldStyles } from '@operato/styles';
11
- import { currencyChoices } from '@things-factory/invoice/dist-client';
11
+ import { currencyChoices, documentAmount, DocumentFormStyles } from '@things-factory/invoice/dist-client';
12
12
  import { opportunitySection } from '../opportunity-attach';
13
13
  import { opportunityStageWord } from '../opportunity-words';
14
+ import { quotationStatusWord } from '../quotation-words';
14
15
  const FIELDS = `
15
16
  id name stage probability amount currency expectedCloseMonth closedOn lostReason description
16
17
  counterpartyId endCustomerId ownerId counterparty { id name } endCustomer { id name } owner { id name }
18
+ quotations { id number version status issueDate validUntil totalAmount currency }
17
19
  `;
18
20
  const thisMonth = () => new Date().toLocaleDateString('en-CA').slice(0, 7);
19
21
  /**
@@ -41,6 +43,7 @@ let OpportunityEditor = class OpportunityEditor extends localize(i18next)(PageVi
41
43
  FormFieldStyles,
42
44
  ButtonStyles,
43
45
  DocumentPageStyles,
46
+ DocumentFormStyles,
44
47
  css `
45
48
  .party {
46
49
  display: flex;
@@ -59,11 +62,17 @@ let OpportunityEditor = class OpportunityEditor extends localize(i18next)(PageVi
59
62
  td {
60
63
  text-align: left;
61
64
  padding: var(--spacing-small);
62
- border-bottom: 1px solid var(--ui-border, rgba(0, 0, 0, 0.1));
65
+ border-bottom: 1px solid var(--ui-line-soft);
66
+ font-size: var(--ui-t-body);
63
67
  }
68
+ th.number,
64
69
  td.number {
65
70
  text-align: right;
66
71
  }
72
+ td a {
73
+ color: inherit;
74
+ text-decoration: underline;
75
+ }
67
76
  `
68
77
  ]; }
69
78
  isOpen(stage) {
@@ -170,8 +179,9 @@ let OpportunityEditor = class OpportunityEditor extends localize(i18next)(PageVi
170
179
  <p>${this.opportunity.lostReason}</p>
171
180
  </section>`
172
181
  : nothing}
182
+ ${this.opportunity ? this.renderQuotations() : nothing}
173
183
  ${attached && this.opportunity
174
- ? html `<section class="page-section">
184
+ ? html `<section class="page-section" @opportunity-changed=${() => this.load(this.opportunity.id)}>
175
185
  <header class="page-section-header"><h3>${attached.heading()}</h3></header>
176
186
  ${attached.render(this.opportunity)}
177
187
  </section>`
@@ -221,6 +231,42 @@ let OpportunityEditor = class OpportunityEditor extends localize(i18next)(PageVi
221
231
  </div>
222
232
  </section>`;
223
233
  }
234
+ /** The quotations that answer this opportunity; a new one is written from here and answers it. */
235
+ renderQuotations() {
236
+ const quotations = this.opportunity.quotations ?? [];
237
+ return html `<section class="page-section">
238
+ <header class="page-section-header">
239
+ <h3>${i18next.t('text.opportunity-section-quotations')}</h3>
240
+ <div class="page-section-actions">
241
+ <button ?disabled=${this.busy || this.opportunity.stage === 'WON' || this.opportunity.stage === 'LOST'} @click=${() => navigate(`quotation-editor?opportunity=${this.opportunity.id}`)}>
242
+ ${i18next.t('button.opportunity-new-quotation')}
243
+ </button>
244
+ </div>
245
+ </header>
246
+ ${quotations.length
247
+ ? html `<table>
248
+ <thead>
249
+ <tr>
250
+ <th>${i18next.t('field.quotation-number')}</th>
251
+ <th>${i18next.t('field.quotation-version')}</th>
252
+ <th>${i18next.t('field.quotation-status')}</th>
253
+ <th>${i18next.t('field.quotation-issue-date')}</th>
254
+ <th class="number">${i18next.t('field.quotation-total-amount')}</th>
255
+ </tr>
256
+ </thead>
257
+ <tbody>
258
+ ${quotations.map(one => html `<tr>
259
+ <td><a href=${`quotation-editor?id=${one.id}`}>${one.number}</a></td>
260
+ <td>v${one.version}</td>
261
+ <td>${quotationStatusWord(one.status)}</td>
262
+ <td>${one.issueDate ?? ''}</td>
263
+ <td class="number">${documentAmount(one.totalAmount, one.currency || 'KRW')}</td>
264
+ </tr>`)}
265
+ </tbody>
266
+ </table>`
267
+ : nothing}
268
+ </section>`;
269
+ }
224
270
  renderEvents() {
225
271
  return html `<section class="page-section">
226
272
  <header class="page-section-header"><h3>${i18next.t('text.opportunity-section-history')}</h3></header>
@@ -231,7 +277,7 @@ let OpportunityEditor = class OpportunityEditor extends localize(i18next)(PageVi
231
277
  <th>${i18next.t('field.opportunity-event-actor')}</th>
232
278
  <th>${i18next.t('field.opportunity-event-action')}</th>
233
279
  <th>${i18next.t('field.opportunity-stage')}</th>
234
- <th>${i18next.t('field.opportunity-probability')}</th>
280
+ <th class="number">${i18next.t('field.opportunity-probability')}</th>
235
281
  </tr>
236
282
  </thead>
237
283
  <tbody>
@@ -1 +1 @@
1
- {"version":3,"file":"opportunity-editor.js","sourceRoot":"","sources":["../../client/pages/opportunity-editor.ts"],"names":[],"mappings":";AAAA,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,MAAM,mBAAmB,CAAA;AAExD,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AACzC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACjD,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AACxC,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACnD,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACnF,OAAO,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAA;AAErE,OAAO,EAAE,kBAAkB,EAA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,+BAA+B,CAAC;QAC5C,CAAC,CAAC,MAAM,KAAK,KAAK;YAChB,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,4BAA4B,CAAC;YACzC,CAAC,CAAC,MAAM,KAAK,MAAM;gBACjB,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,6BAA6B,CAAC;gBAC1C,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,gCAAgC,CAAC,CAAA;AAEvD,SAAS,KAAK,CAAC,SAAmD,EAAE;IAClE,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,KAAK,KAAK,MAAM,CAAC,CAAA;IACrD,OAAO;QACL,IAAI,EAAE,EAAE;QACR,YAAY,EAAE,IAAI;QAClB,WAAW,EAAE,IAAI;QACjB,MAAM,EAAE,GAAG;QACX,QAAQ,EAAE,KAAK;QACf,kBAAkB,EAAE,SAAS,EAAE;QAC/B,KAAK,EAAE,MAAM;QACb,WAAW,EAAE,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,EAAE;QACjD,OAAO,EAAE,EAAE;QACX,WAAW,EAAE,EAAE;KAChB,CAAA;AACH,CAAC","sourcesContent":["import '@operato/list-state/ox-page-state.js'\n\nimport gql from 'graphql-tag'\nimport { css, html, nothing } from 'lit'\nimport { customElement, state } from 'lit/decorators.js'\n\nimport { client } from '@operato/graphql'\nimport { i18next, localize } from '@operato/i18n'\nimport { notify } from '@operato/layout'\nimport { navigate, PageView } from '@operato/shell'\nimport { ButtonStyles, DocumentPageStyles, FormFieldStyles } from '@operato/styles'\nimport { currencyChoices } from '@things-factory/invoice/dist-client'\n\nimport { opportunitySection } from '../opportunity-attach'\nimport { opportunityStageWord } from '../opportunity-words'\n\nconst FIELDS = `\n id name stage probability amount currency expectedCloseMonth closedOn lostReason description\n counterpartyId endCustomerId ownerId counterparty { id name } endCustomer { id name } owner { id name }\n`\n\ntype Party = { id: string; name: string; businessNumber?: string }\ntype Picker = { search: string; found: Party[] }\ntype Form = {\n name: string\n counterparty: Party | null\n endCustomer: Party | null\n amount: string\n currency: string\n expectedCloseMonth: string\n stage: string\n probability: string\n ownerId: string\n description: string\n}\n\nconst thisMonth = () => new Date().toLocaleDateString('en-CA').slice(0, 7)\n\n/**\n * 영업 기회 편집 — with whom, for how much, by when and how likely.\n *\n * A person moves an open opportunity through the stages; changing the stage puts that stage's probability in, and the\n * person may change it. An open one is closed as lost with the reason; a lost one is opened again by choosing an open\n * stage. Winning is the application's: it closes the opportunity when the opportunity becomes its contract.\n */\n@customElement('opportunity-editor')\nexport class OpportunityEditor extends localize(i18next)(PageView) {\n static styles = [\n FormFieldStyles,\n ButtonStyles,\n DocumentPageStyles,\n css`\n .party {\n display: flex;\n gap: var(--spacing-small);\n align-items: center;\n }\n .party input {\n flex: 1;\n }\n table {\n width: 100%;\n border-collapse: collapse;\n font-variant-numeric: tabular-nums;\n }\n th,\n td {\n text-align: left;\n padding: var(--spacing-small);\n border-bottom: 1px solid var(--ui-border, rgba(0, 0, 0, 0.1));\n }\n td.number {\n text-align: right;\n }\n `\n ]\n\n @state() opportunity: any = null\n @state() form: Form = blank()\n @state() pickers: Record<'counterparty' | 'endCustomer', Picker> = { counterparty: { search: '', found: [] }, endCustomer: { search: '', found: [] } }\n @state() stages: { stage: string; probability: number; open: boolean }[] = []\n @state() owners: { id: string; name: string; email?: string }[] = []\n @state() events: any[] = []\n @state() reason = ''\n @state() loading = false\n @state() error: unknown = null\n @state() busy = false\n\n private isOpen(stage: string) {\n return this.stages.some(one => one.stage === stage && one.open)\n }\n\n /** Won is final; a lost one is changed only by being opened again. */\n get editable() {\n return !this.busy && this.opportunity?.stage !== 'WON' && this.isOpen(this.form.stage)\n }\n\n get context() {\n const actions: any[] = []\n if (this.editable) actions.push({ title: i18next.t('button.save'), icon: 'save', emphasis: { raised: true }, action: () => this.save() })\n return {\n title: this.opportunity ? `${i18next.t('title.opportunity')} ${this.opportunity.name}` : i18next.t('title.opportunity-new'),\n ...(this.opportunity ? { description: opportunityStageWord(this.opportunity.stage) } : {}),\n frame: 'document',\n /* Opened from the opportunity list; the menu marks it. */\n menu: 'opportunity-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 if (!this.stages.length) await this.readChoices()\n const id = lifecycle?.params?.id\n if (!id) {\n this.opportunity = null\n this.form = blank(this.stages)\n this.events = []\n this.updateContext()\n return\n }\n if (id !== this.opportunity?.id) await this.load(id)\n }\n\n render() {\n const attached = this.opportunity ? opportunitySection() : undefined\n const editable = this.editable\n const set = (patch: Partial<Form>) => (this.form = { ...this.form, ...patch })\n const stageChoices = this.stages.filter(one => one.open || one.stage === this.opportunity?.stage)\n return html`<ox-page-state .loading=${this.loading} .error=${this.error} @retry=${() => this.opportunity && this.load(this.opportunity.id)}>\n <div class=\"page\">\n <section class=\"page-section\">\n <header class=\"page-section-header\"><h3>${i18next.t('text.opportunity-section-head')}</h3></header>\n <div class=\"form\">\n <label class=\"wide\"\n >${i18next.t('field.opportunity-name')}\n <input .value=${this.form.name} ?disabled=${!editable} @input=${(e: any) => set({ name: e.target.value })}\n /></label>\n ${this.renderParty('counterparty', i18next.t('field.opportunity-counterparty'), editable)}\n ${this.renderParty('endCustomer', i18next.t('field.opportunity-end-customer'), editable)}\n <label\n >${i18next.t('field.opportunity-amount')}\n <input type=\"number\" min=\"0\" .value=${this.form.amount} ?disabled=${!editable} @input=${(e: any) => set({ amount: e.target.value })}\n /></label>\n <label\n >${i18next.t('field.opportunity-currency')}\n <select .value=${this.form.currency} ?disabled=${!editable} @change=${(e: any) => set({ currency: e.target.value })}>\n ${currencyChoices().map((code: string) => html`<option value=${code} ?selected=${code === this.form.currency}>${code}</option>`)}\n </select>\n </label>\n <label\n >${i18next.t('field.opportunity-expected-close-month')}\n <input type=\"month\" .value=${this.form.expectedCloseMonth} ?disabled=${!editable} @input=${(e: any) => set({ expectedCloseMonth: e.target.value })}\n /></label>\n <label\n >${i18next.t('field.opportunity-owner')}\n <select .value=${this.form.ownerId} ?disabled=${!editable} @change=${(e: any) => set({ ownerId: e.target.value })}>\n ${this.form.ownerId ? nothing : html`<option value=\"\" selected>${i18next.t('text.opportunity-owner-me')}</option>`}\n ${this.owners.map(one => html`<option value=${one.id} ?selected=${one.id === this.form.ownerId}>${one.name}</option>`)}\n </select>\n </label>\n <label class=\"wide\"\n >${i18next.t('field.opportunity-description')}\n <textarea .value=${this.form.description} ?disabled=${!editable} @input=${(e: any) => set({ description: e.target.value })}></textarea>\n </label>\n </div>\n </section>\n <section class=\"page-section\">\n <header class=\"page-section-header\"><h3>${i18next.t('text.opportunity-section-stage')}</h3></header>\n <div class=\"form\">\n <label\n >${i18next.t('field.opportunity-stage')}\n <select .value=${this.form.stage} ?disabled=${this.busy || this.opportunity?.stage === 'WON'} @change=${(e: any) => this.chooseStage(e.target.value)}>\n ${stageChoices.map(one => html`<option value=${one.stage} ?selected=${one.stage === this.form.stage} ?disabled=${!one.open}>${opportunityStageWord(one.stage)}</option>`)}\n </select>\n </label>\n <label\n >${i18next.t('field.opportunity-probability')}\n <input type=\"number\" min=\"0\" max=\"100\" step=\"1\" .value=${this.form.probability} ?disabled=${!editable} @input=${(e: any) => set({ probability: e.target.value })}\n /></label>\n ${this.opportunity?.closedOn\n ? html`<label>${i18next.t('field.opportunity-closed-on')} <strong>${this.opportunity.closedOn}</strong></label>`\n : nothing}\n </div>\n </section>\n ${this.opportunity && this.isOpen(this.opportunity.stage) ? this.renderLose() : nothing}\n ${this.opportunity?.lostReason\n ? html`<section class=\"page-section\">\n <header class=\"page-section-header\"><h3>${i18next.t('field.opportunity-lost-reason')}</h3></header>\n <p>${this.opportunity.lostReason}</p>\n </section>`\n : nothing}\n ${attached && this.opportunity\n ? html`<section class=\"page-section\">\n <header class=\"page-section-header\"><h3>${attached.heading()}</h3></header>\n ${attached.render(this.opportunity)}\n </section>`\n : nothing}\n ${this.events.length ? this.renderEvents() : nothing}\n </div>\n </ox-page-state>`\n }\n\n /** A counterparty of the domain, found by name or business number. */\n private renderParty(which: 'counterparty' | 'endCustomer', label: string, editable: boolean) {\n const picker = this.pickers[which]\n const chosen = this.form[which]\n return html`<label\n >${label}\n <span class=\"party\">\n <input\n .value=${picker.search}\n placeholder=${chosen?.name ?? i18next.t('text.opportunity-counterparty-search')}\n ?disabled=${!editable}\n @input=${(e: any) => this.setPicker(which, { search: e.target.value })}\n @keydown=${(e: KeyboardEvent) => e.key === 'Enter' && this.findParties(which)}\n />\n <button ?disabled=${!editable} @click=${() => this.findParties(which)}>${i18next.t('button.search')}</button>\n ${which === 'endCustomer' && chosen ? html`<button ?disabled=${!editable} @click=${() => (this.form = { ...this.form, endCustomer: null })}>${i18next.t('button.opportunity-clear')}</button>` : nothing}\n </span>\n ${picker.found.length\n ? html`<select ?disabled=${!editable} @change=${(e: any) => this.chooseParty(which, picker.found.find(one => one.id === e.target.value) ?? null)}>\n <option value=\"\">${chosen?.name ?? ''}</option>\n ${picker.found.map(one => html`<option value=${one.id}>${one.name}${one.businessNumber ? ` (${one.businessNumber})` : ''}</option>`)}\n </select>`\n : nothing}\n </label>`\n }\n\n private renderLose() {\n return html`<section class=\"page-section\">\n <header class=\"page-section-header\">\n <h3>${i18next.t('text.opportunity-section-lose')}</h3>\n <div class=\"page-section-actions\">\n <button ?disabled=${this.busy || !this.reason.trim()} @click=${() => this.lose()}>${i18next.t('button.opportunity-lose')}</button>\n </div>\n </header>\n <div class=\"form\">\n <label class=\"wide\"\n >${i18next.t('field.opportunity-lost-reason')}\n <input .value=${this.reason} ?disabled=${this.busy} @input=${(e: any) => (this.reason = e.target.value)}\n /></label>\n </div>\n </section>`\n }\n\n private renderEvents() {\n return html`<section class=\"page-section\">\n <header class=\"page-section-header\"><h3>${i18next.t('text.opportunity-section-history')}</h3></header>\n <table>\n <thead>\n <tr>\n <th>${i18next.t('field.opportunity-event-at')}</th>\n <th>${i18next.t('field.opportunity-event-actor')}</th>\n <th>${i18next.t('field.opportunity-event-action')}</th>\n <th>${i18next.t('field.opportunity-stage')}</th>\n <th>${i18next.t('field.opportunity-probability')}</th>\n </tr>\n </thead>\n <tbody>\n ${this.events.map(\n one => html`<tr>\n <td>${one.createdAt ? new Date(one.createdAt).toLocaleString() : ''}</td>\n <td>${one.actor?.name ?? ''}</td>\n <td>${eventWord(one.action)}${one.reason ? ` · ${one.reason}` : ''}</td>\n <td>${one.fromStage ? `${opportunityStageWord(one.fromStage)} → ` : ''}${opportunityStageWord(one.stage)}</td>\n <td class=\"number\">${one.probability}%</td>\n </tr>`\n )}\n </tbody>\n </table>\n </section>`\n }\n\n private setPicker(which: 'counterparty' | 'endCustomer', patch: Partial<Picker>) {\n this.pickers = { ...this.pickers, [which]: { ...this.pickers[which], ...patch } }\n }\n\n private chooseParty(which: 'counterparty' | 'endCustomer', party: Party | null) {\n if (!party) return\n this.form = { ...this.form, [which]: party }\n this.setPicker(which, { search: '', found: [] })\n }\n\n /** The stage's own probability comes in with it; the person may change it afterwards. */\n private chooseStage(stage: string) {\n const given = this.stages.find(one => one.stage === stage)\n this.form = { ...this.form, stage, probability: given ? String(given.probability) : this.form.probability }\n }\n\n private async readChoices() {\n try {\n const response = await client.query({\n query: gql`\n query {\n opportunityStages { stage probability open }\n opportunityOwners { id name email }\n }\n `,\n fetchPolicy: 'no-cache'\n })\n if (response.errors?.length) throw response\n this.stages = response.data.opportunityStages\n this.owners = response.data.opportunityOwners\n } catch (error) {\n this.error = error\n }\n }\n\n private async findParties(which: 'counterparty' | 'endCustomer') {\n await this.run(async () => {\n const response = await client.query({\n query: gql`\n query ($search: String, $pagination: Pagination) {\n counterparties(search: $search, pagination: $pagination) {\n items { id name businessNumber }\n }\n }\n `,\n variables: { search: this.pickers[which].search.trim() || undefined, pagination: { page: 1, limit: 30 } },\n fetchPolicy: 'no-cache'\n })\n if (response.errors?.length) throw response\n const found: Party[] = response.data.counterparties.items ?? []\n if (found.length === 1) this.chooseParty(which, found[0])\n else this.setPicker(which, { found })\n })\n }\n\n private async load(id: string) {\n this.loading = true\n this.error = null\n try {\n const response = await client.query({\n query: gql(`query ($id: String!) { opportunity(id: $id) { ${FIELDS} } opportunityEvents(opportunityId: $id) { id action fromStage stage probability reason createdAt actor { id name } } }`),\n variables: { id },\n fetchPolicy: 'no-cache'\n })\n if (response.errors?.length) throw response\n if (!response.data.opportunity) throw new Error(i18next.t('text.opportunity-not-found'))\n this.show(response.data.opportunity, response.data.opportunityEvents)\n } catch (error) {\n this.error = error\n } finally {\n this.loading = false\n this.updateContext()\n }\n }\n\n private show(opportunity: any, events: any[]) {\n this.opportunity = opportunity\n this.events = events\n this.form = {\n name: opportunity.name,\n counterparty: opportunity.counterparty,\n endCustomer: opportunity.endCustomer,\n amount: String(opportunity.amount ?? 0),\n currency: opportunity.currency,\n expectedCloseMonth: opportunity.expectedCloseMonth,\n stage: opportunity.stage,\n probability: String(opportunity.probability),\n ownerId: opportunity.ownerId ?? '',\n description: opportunity.description ?? ''\n }\n this.reason = ''\n }\n\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 { name, counterparty, endCustomer, amount, currency, expectedCloseMonth, stage, probability, ownerId, description } = this.form\n return {\n name,\n counterpartyId: counterparty?.id ?? '',\n endCustomerId: endCustomer?.id ?? null,\n amount: Number(amount || 0),\n currency,\n expectedCloseMonth,\n stage,\n probability: probability === '' ? null : Number(probability),\n ownerId: ownerId || null,\n description\n }\n }\n\n private async save() {\n const id = this.opportunity?.id\n const saved = await this.run(async () => {\n const response = await client.mutate({\n mutation: gql(\n id\n ? `mutation ($id: String!, $opportunity: NewOpportunity!) { opportunity: updateOpportunity(id: $id, opportunity: $opportunity) { id } }`\n : `mutation ($opportunity: NewOpportunity!) { opportunity: createOpportunity(opportunity: $opportunity) { id } }`\n ),\n variables: { ...(id ? { id } : {}), opportunity: this.input() }\n })\n if (response.errors?.length) throw response\n return response.data.opportunity as { id: string }\n })\n if (!saved) return\n if (!id) navigate(`opportunity-editor?id=${saved.id}`)\n else await this.load(id)\n }\n\n private async lose() {\n const id = this.opportunity!.id\n const lost = await this.run(async () => {\n const response = await client.mutate({\n mutation: gql`\n mutation ($id: String!, $reason: String!) {\n loseOpportunity(id: $id, reason: $reason) { id }\n }\n `,\n variables: { id, reason: this.reason.trim() }\n })\n if (response.errors?.length) throw response\n return response.data.loseOpportunity\n })\n if (lost) await this.load(id)\n }\n}\n\nconst eventWord = (action?: string) =>\n action === 'CREATED'\n ? i18next.t('text.opportunity-event-created')\n : action === 'STAGED'\n ? i18next.t('text.opportunity-event-staged')\n : action === 'WON'\n ? i18next.t('text.opportunity-event-won')\n : action === 'LOST'\n ? i18next.t('text.opportunity-event-lost')\n : i18next.t('text.opportunity-event-updated')\n\nfunction blank(stages: { stage: string; probability: number }[] = []): Form {\n const lead = stages.find(one => one.stage === 'LEAD')\n return {\n name: '',\n counterparty: null,\n endCustomer: null,\n amount: '0',\n currency: 'KRW',\n expectedCloseMonth: thisMonth(),\n stage: 'LEAD',\n probability: lead ? String(lead.probability) : '',\n ownerId: '',\n description: ''\n }\n}\n"]}
1
+ {"version":3,"file":"opportunity-editor.js","sourceRoot":"","sources":["../../client/pages/opportunity-editor.ts"],"names":[],"mappings":";AAAA,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,MAAM,mBAAmB,CAAA;AAExD,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AACzC,OAAO,EAAE,OAAO,EAAE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,CAAC","sourcesContent":["import '@operato/list-state/ox-page-state.js'\n\nimport gql from 'graphql-tag'\nimport { css, html, nothing } from 'lit'\nimport { customElement, state } from 'lit/decorators.js'\n\nimport { client } from '@operato/graphql'\nimport { i18next, localize } from '@operato/i18n'\nimport { notify } from '@operato/layout'\nimport { navigate, PageView } from '@operato/shell'\nimport { ButtonStyles, DocumentPageStyles, FormFieldStyles } from '@operato/styles'\nimport { currencyChoices, documentAmount, DocumentFormStyles } from '@things-factory/invoice/dist-client'\n\nimport { opportunitySection } from '../opportunity-attach'\nimport { opportunityStageWord } from '../opportunity-words'\nimport { quotationStatusWord } from '../quotation-words'\n\nconst FIELDS = `\n id name stage probability amount currency expectedCloseMonth closedOn lostReason description\n counterpartyId endCustomerId ownerId counterparty { id name } endCustomer { id name } owner { id name }\n quotations { id number version status issueDate validUntil totalAmount currency }\n`\n\ntype Party = { id: string; name: string; businessNumber?: string }\ntype Picker = { search: string; found: Party[] }\ntype Form = {\n name: string\n counterparty: Party | null\n endCustomer: Party | null\n amount: string\n currency: string\n expectedCloseMonth: string\n stage: string\n probability: string\n ownerId: string\n description: string\n}\n\nconst thisMonth = () => new Date().toLocaleDateString('en-CA').slice(0, 7)\n\n/**\n * 영업 기회 편집 — with whom, for how much, by when and how likely.\n *\n * A person moves an open opportunity through the stages; changing the stage puts that stage's probability in, and the\n * person may change it. An open one is closed as lost with the reason; a lost one is opened again by choosing an open\n * stage. Winning is the application's: it closes the opportunity when the opportunity becomes its contract.\n */\n@customElement('opportunity-editor')\nexport class OpportunityEditor extends localize(i18next)(PageView) {\n static styles = [\n FormFieldStyles,\n ButtonStyles,\n DocumentPageStyles,\n DocumentFormStyles,\n css`\n .party {\n display: flex;\n gap: var(--spacing-small);\n align-items: center;\n }\n .party input {\n flex: 1;\n }\n table {\n width: 100%;\n border-collapse: collapse;\n font-variant-numeric: tabular-nums;\n }\n th,\n td {\n text-align: left;\n padding: var(--spacing-small);\n border-bottom: 1px solid var(--ui-line-soft);\n font-size: var(--ui-t-body);\n }\n th.number,\n td.number {\n text-align: right;\n }\n td a {\n color: inherit;\n text-decoration: underline;\n }\n `\n ]\n\n @state() opportunity: any = null\n @state() form: Form = blank()\n @state() pickers: Record<'counterparty' | 'endCustomer', Picker> = { counterparty: { search: '', found: [] }, endCustomer: { search: '', found: [] } }\n @state() stages: { stage: string; probability: number; open: boolean }[] = []\n @state() owners: { id: string; name: string; email?: string }[] = []\n @state() events: any[] = []\n @state() reason = ''\n @state() loading = false\n @state() error: unknown = null\n @state() busy = false\n\n private isOpen(stage: string) {\n return this.stages.some(one => one.stage === stage && one.open)\n }\n\n /** Won is final; a lost one is changed only by being opened again. */\n get editable() {\n return !this.busy && this.opportunity?.stage !== 'WON' && this.isOpen(this.form.stage)\n }\n\n get context() {\n const actions: any[] = []\n if (this.editable) actions.push({ title: i18next.t('button.save'), icon: 'save', emphasis: { raised: true }, action: () => this.save() })\n return {\n title: this.opportunity ? `${i18next.t('title.opportunity')} ${this.opportunity.name}` : i18next.t('title.opportunity-new'),\n ...(this.opportunity ? { description: opportunityStageWord(this.opportunity.stage) } : {}),\n frame: 'document',\n /* Opened from the opportunity list; the menu marks it. */\n menu: 'opportunity-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 if (!this.stages.length) await this.readChoices()\n const id = lifecycle?.params?.id\n if (!id) {\n this.opportunity = null\n this.form = blank(this.stages)\n this.events = []\n this.updateContext()\n return\n }\n if (id !== this.opportunity?.id) await this.load(id)\n }\n\n render() {\n const attached = this.opportunity ? opportunitySection() : undefined\n const editable = this.editable\n const set = (patch: Partial<Form>) => (this.form = { ...this.form, ...patch })\n const stageChoices = this.stages.filter(one => one.open || one.stage === this.opportunity?.stage)\n return html`<ox-page-state .loading=${this.loading} .error=${this.error} @retry=${() => this.opportunity && this.load(this.opportunity.id)}>\n <div class=\"page\">\n <section class=\"page-section\">\n <header class=\"page-section-header\"><h3>${i18next.t('text.opportunity-section-head')}</h3></header>\n <div class=\"form\">\n <label class=\"wide\"\n >${i18next.t('field.opportunity-name')}\n <input .value=${this.form.name} ?disabled=${!editable} @input=${(e: any) => set({ name: e.target.value })}\n /></label>\n ${this.renderParty('counterparty', i18next.t('field.opportunity-counterparty'), editable)}\n ${this.renderParty('endCustomer', i18next.t('field.opportunity-end-customer'), editable)}\n <label\n >${i18next.t('field.opportunity-amount')}\n <input type=\"number\" min=\"0\" .value=${this.form.amount} ?disabled=${!editable} @input=${(e: any) => set({ amount: e.target.value })}\n /></label>\n <label\n >${i18next.t('field.opportunity-currency')}\n <select .value=${this.form.currency} ?disabled=${!editable} @change=${(e: any) => set({ currency: e.target.value })}>\n ${currencyChoices().map((code: string) => html`<option value=${code} ?selected=${code === this.form.currency}>${code}</option>`)}\n </select>\n </label>\n <label\n >${i18next.t('field.opportunity-expected-close-month')}\n <input type=\"month\" .value=${this.form.expectedCloseMonth} ?disabled=${!editable} @input=${(e: any) => set({ expectedCloseMonth: e.target.value })}\n /></label>\n <label\n >${i18next.t('field.opportunity-owner')}\n <select .value=${this.form.ownerId} ?disabled=${!editable} @change=${(e: any) => set({ ownerId: e.target.value })}>\n ${this.form.ownerId ? nothing : html`<option value=\"\" selected>${i18next.t('text.opportunity-owner-me')}</option>`}\n ${this.owners.map(one => html`<option value=${one.id} ?selected=${one.id === this.form.ownerId}>${one.name}</option>`)}\n </select>\n </label>\n <label class=\"wide\"\n >${i18next.t('field.opportunity-description')}\n <textarea .value=${this.form.description} ?disabled=${!editable} @input=${(e: any) => set({ description: e.target.value })}></textarea>\n </label>\n </div>\n </section>\n <section class=\"page-section\">\n <header class=\"page-section-header\"><h3>${i18next.t('text.opportunity-section-stage')}</h3></header>\n <div class=\"form\">\n <label\n >${i18next.t('field.opportunity-stage')}\n <select .value=${this.form.stage} ?disabled=${this.busy || this.opportunity?.stage === 'WON'} @change=${(e: any) => this.chooseStage(e.target.value)}>\n ${stageChoices.map(one => html`<option value=${one.stage} ?selected=${one.stage === this.form.stage} ?disabled=${!one.open}>${opportunityStageWord(one.stage)}</option>`)}\n </select>\n </label>\n <label\n >${i18next.t('field.opportunity-probability')}\n <input type=\"number\" min=\"0\" max=\"100\" step=\"1\" .value=${this.form.probability} ?disabled=${!editable} @input=${(e: any) => set({ probability: e.target.value })}\n /></label>\n ${this.opportunity?.closedOn\n ? html`<label>${i18next.t('field.opportunity-closed-on')} <strong>${this.opportunity.closedOn}</strong></label>`\n : nothing}\n </div>\n </section>\n ${this.opportunity && this.isOpen(this.opportunity.stage) ? this.renderLose() : nothing}\n ${this.opportunity?.lostReason\n ? html`<section class=\"page-section\">\n <header class=\"page-section-header\"><h3>${i18next.t('field.opportunity-lost-reason')}</h3></header>\n <p>${this.opportunity.lostReason}</p>\n </section>`\n : nothing}\n ${this.opportunity ? this.renderQuotations() : nothing}\n ${attached && this.opportunity\n ? html`<section class=\"page-section\" @opportunity-changed=${() => this.load(this.opportunity.id)}>\n <header class=\"page-section-header\"><h3>${attached.heading()}</h3></header>\n ${attached.render(this.opportunity)}\n </section>`\n : nothing}\n ${this.events.length ? this.renderEvents() : nothing}\n </div>\n </ox-page-state>`\n }\n\n /** A counterparty of the domain, found by name or business number. */\n private renderParty(which: 'counterparty' | 'endCustomer', label: string, editable: boolean) {\n const picker = this.pickers[which]\n const chosen = this.form[which]\n return html`<label\n >${label}\n <span class=\"party\">\n <input\n .value=${picker.search}\n placeholder=${chosen?.name ?? i18next.t('text.opportunity-counterparty-search')}\n ?disabled=${!editable}\n @input=${(e: any) => this.setPicker(which, { search: e.target.value })}\n @keydown=${(e: KeyboardEvent) => e.key === 'Enter' && this.findParties(which)}\n />\n <button ?disabled=${!editable} @click=${() => this.findParties(which)}>${i18next.t('button.search')}</button>\n ${which === 'endCustomer' && chosen ? html`<button ?disabled=${!editable} @click=${() => (this.form = { ...this.form, endCustomer: null })}>${i18next.t('button.opportunity-clear')}</button>` : nothing}\n </span>\n ${picker.found.length\n ? html`<select ?disabled=${!editable} @change=${(e: any) => this.chooseParty(which, picker.found.find(one => one.id === e.target.value) ?? null)}>\n <option value=\"\">${chosen?.name ?? ''}</option>\n ${picker.found.map(one => html`<option value=${one.id}>${one.name}${one.businessNumber ? ` (${one.businessNumber})` : ''}</option>`)}\n </select>`\n : nothing}\n </label>`\n }\n\n private renderLose() {\n return html`<section class=\"page-section\">\n <header class=\"page-section-header\">\n <h3>${i18next.t('text.opportunity-section-lose')}</h3>\n <div class=\"page-section-actions\">\n <button ?disabled=${this.busy || !this.reason.trim()} @click=${() => this.lose()}>${i18next.t('button.opportunity-lose')}</button>\n </div>\n </header>\n <div class=\"form\">\n <label class=\"wide\"\n >${i18next.t('field.opportunity-lost-reason')}\n <input .value=${this.reason} ?disabled=${this.busy} @input=${(e: any) => (this.reason = e.target.value)}\n /></label>\n </div>\n </section>`\n }\n\n /** The quotations that answer this opportunity; a new one is written from here and answers it. */\n private renderQuotations() {\n const quotations: any[] = this.opportunity.quotations ?? []\n return html`<section class=\"page-section\">\n <header class=\"page-section-header\">\n <h3>${i18next.t('text.opportunity-section-quotations')}</h3>\n <div class=\"page-section-actions\">\n <button ?disabled=${this.busy || this.opportunity.stage === 'WON' || this.opportunity.stage === 'LOST'} @click=${() => navigate(`quotation-editor?opportunity=${this.opportunity.id}`)}>\n ${i18next.t('button.opportunity-new-quotation')}\n </button>\n </div>\n </header>\n ${quotations.length\n ? html`<table>\n <thead>\n <tr>\n <th>${i18next.t('field.quotation-number')}</th>\n <th>${i18next.t('field.quotation-version')}</th>\n <th>${i18next.t('field.quotation-status')}</th>\n <th>${i18next.t('field.quotation-issue-date')}</th>\n <th class=\"number\">${i18next.t('field.quotation-total-amount')}</th>\n </tr>\n </thead>\n <tbody>\n ${quotations.map(\n one => html`<tr>\n <td><a href=${`quotation-editor?id=${one.id}`}>${one.number}</a></td>\n <td>v${one.version}</td>\n <td>${quotationStatusWord(one.status)}</td>\n <td>${one.issueDate ?? ''}</td>\n <td class=\"number\">${documentAmount(one.totalAmount, one.currency || 'KRW')}</td>\n </tr>`\n )}\n </tbody>\n </table>`\n : nothing}\n </section>`\n }\n\n private renderEvents() {\n return html`<section class=\"page-section\">\n <header class=\"page-section-header\"><h3>${i18next.t('text.opportunity-section-history')}</h3></header>\n <table>\n <thead>\n <tr>\n <th>${i18next.t('field.opportunity-event-at')}</th>\n <th>${i18next.t('field.opportunity-event-actor')}</th>\n <th>${i18next.t('field.opportunity-event-action')}</th>\n <th>${i18next.t('field.opportunity-stage')}</th>\n <th class=\"number\">${i18next.t('field.opportunity-probability')}</th>\n </tr>\n </thead>\n <tbody>\n ${this.events.map(\n one => html`<tr>\n <td>${one.createdAt ? new Date(one.createdAt).toLocaleString() : ''}</td>\n <td>${one.actor?.name ?? ''}</td>\n <td>${eventWord(one.action)}${one.reason ? ` · ${one.reason}` : ''}</td>\n <td>${one.fromStage ? `${opportunityStageWord(one.fromStage)} → ` : ''}${opportunityStageWord(one.stage)}</td>\n <td class=\"number\">${one.probability}%</td>\n </tr>`\n )}\n </tbody>\n </table>\n </section>`\n }\n\n private setPicker(which: 'counterparty' | 'endCustomer', patch: Partial<Picker>) {\n this.pickers = { ...this.pickers, [which]: { ...this.pickers[which], ...patch } }\n }\n\n private chooseParty(which: 'counterparty' | 'endCustomer', party: Party | null) {\n if (!party) return\n this.form = { ...this.form, [which]: party }\n this.setPicker(which, { search: '', found: [] })\n }\n\n /** The stage's own probability comes in with it; the person may change it afterwards. */\n private chooseStage(stage: string) {\n const given = this.stages.find(one => one.stage === stage)\n this.form = { ...this.form, stage, probability: given ? String(given.probability) : this.form.probability }\n }\n\n private async readChoices() {\n try {\n const response = await client.query({\n query: gql`\n query {\n opportunityStages { stage probability open }\n opportunityOwners { id name email }\n }\n `,\n fetchPolicy: 'no-cache'\n })\n if (response.errors?.length) throw response\n this.stages = response.data.opportunityStages\n this.owners = response.data.opportunityOwners\n } catch (error) {\n this.error = error\n }\n }\n\n private async findParties(which: 'counterparty' | 'endCustomer') {\n await this.run(async () => {\n const response = await client.query({\n query: gql`\n query ($search: String, $pagination: Pagination) {\n counterparties(search: $search, pagination: $pagination) {\n items { id name businessNumber }\n }\n }\n `,\n variables: { search: this.pickers[which].search.trim() || undefined, pagination: { page: 1, limit: 30 } },\n fetchPolicy: 'no-cache'\n })\n if (response.errors?.length) throw response\n const found: Party[] = response.data.counterparties.items ?? []\n if (found.length === 1) this.chooseParty(which, found[0])\n else this.setPicker(which, { found })\n })\n }\n\n private async load(id: string) {\n this.loading = true\n this.error = null\n try {\n const response = await client.query({\n query: gql(`query ($id: String!) { opportunity(id: $id) { ${FIELDS} } opportunityEvents(opportunityId: $id) { id action fromStage stage probability reason createdAt actor { id name } } }`),\n variables: { id },\n fetchPolicy: 'no-cache'\n })\n if (response.errors?.length) throw response\n if (!response.data.opportunity) throw new Error(i18next.t('text.opportunity-not-found'))\n this.show(response.data.opportunity, response.data.opportunityEvents)\n } catch (error) {\n this.error = error\n } finally {\n this.loading = false\n this.updateContext()\n }\n }\n\n private show(opportunity: any, events: any[]) {\n this.opportunity = opportunity\n this.events = events\n this.form = {\n name: opportunity.name,\n counterparty: opportunity.counterparty,\n endCustomer: opportunity.endCustomer,\n amount: String(opportunity.amount ?? 0),\n currency: opportunity.currency,\n expectedCloseMonth: opportunity.expectedCloseMonth,\n stage: opportunity.stage,\n probability: String(opportunity.probability),\n ownerId: opportunity.ownerId ?? '',\n description: opportunity.description ?? ''\n }\n this.reason = ''\n }\n\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 { name, counterparty, endCustomer, amount, currency, expectedCloseMonth, stage, probability, ownerId, description } = this.form\n return {\n name,\n counterpartyId: counterparty?.id ?? '',\n endCustomerId: endCustomer?.id ?? null,\n amount: Number(amount || 0),\n currency,\n expectedCloseMonth,\n stage,\n probability: probability === '' ? null : Number(probability),\n ownerId: ownerId || null,\n description\n }\n }\n\n private async save() {\n const id = this.opportunity?.id\n const saved = await this.run(async () => {\n const response = await client.mutate({\n mutation: gql(\n id\n ? `mutation ($id: String!, $opportunity: NewOpportunity!) { opportunity: updateOpportunity(id: $id, opportunity: $opportunity) { id } }`\n : `mutation ($opportunity: NewOpportunity!) { opportunity: createOpportunity(opportunity: $opportunity) { id } }`\n ),\n variables: { ...(id ? { id } : {}), opportunity: this.input() }\n })\n if (response.errors?.length) throw response\n return response.data.opportunity as { id: string }\n })\n if (!saved) return\n if (!id) navigate(`opportunity-editor?id=${saved.id}`)\n else await this.load(id)\n }\n\n private async lose() {\n const id = this.opportunity!.id\n const lost = await this.run(async () => {\n const response = await client.mutate({\n mutation: gql`\n mutation ($id: String!, $reason: String!) {\n loseOpportunity(id: $id, reason: $reason) { id }\n }\n `,\n variables: { id, reason: this.reason.trim() }\n })\n if (response.errors?.length) throw response\n return response.data.loseOpportunity\n })\n if (lost) await this.load(id)\n }\n}\n\nconst eventWord = (action?: string) =>\n action === 'CREATED'\n ? i18next.t('text.opportunity-event-created')\n : action === 'STAGED'\n ? i18next.t('text.opportunity-event-staged')\n : action === 'WON'\n ? i18next.t('text.opportunity-event-won')\n : action === 'LOST'\n ? i18next.t('text.opportunity-event-lost')\n : i18next.t('text.opportunity-event-updated')\n\nfunction blank(stages: { stage: string; probability: number }[] = []): Form {\n const lead = stages.find(one => one.stage === 'LEAD')\n return {\n name: '',\n counterparty: null,\n endCustomer: null,\n amount: '0',\n currency: 'KRW',\n expectedCloseMonth: thisMonth(),\n stage: 'LEAD',\n probability: lead ? String(lead.probability) : '',\n ownerId: '',\n description: ''\n }\n}\n"]}
@@ -18,6 +18,14 @@ export declare class QuotationEditor extends QuotationEditor_base {
18
18
  busy: boolean;
19
19
  reason: string;
20
20
  gristConfig: any;
21
+ /** The open opportunities a draft may answer, and the one it answers when that one is closed. */
22
+ opportunities: {
23
+ id: string;
24
+ name: string;
25
+ counterparty?: {
26
+ name: string;
27
+ };
28
+ }[];
21
29
  private grist?;
22
30
  get editable(): boolean;
23
31
  get context(): {
@@ -30,6 +38,8 @@ export declare class QuotationEditor extends QuotationEditor_base {
30
38
  pageUpdated(changes: any, lifecycle: any): Promise<void>;
31
39
  render(): import("lit-html").TemplateResult<1>;
32
40
  private renderDecline;
41
+ private opportunityChoices;
42
+ private readOpportunities;
33
43
  private configure;
34
44
  private load;
35
45
  private show;
@@ -14,7 +14,7 @@ import { documentHtml, DocumentFormStyles, documentLinesConfig, linesOf, printDo
14
14
  import { quotationSection } from '../quotation-attach';
15
15
  import { quotationStatusWord } from '../quotation-words';
16
16
  const FIELDS = `
17
- id number version status validUntil outcomeReason direction currency language supplierName supplierAddress supplierRegistrationNumber
17
+ id number version status validUntil outcomeReason opportunityId opportunity { id name } direction currency language supplierName supplierAddress supplierRegistrationNumber
18
18
  buyerName buyerAddress buyerRegistrationNumber issueDate purchaseOrder paymentTerms bankDetails notes sourceReference
19
19
  supplyAmount taxAmount totalAmount taxRounding currencyDigits
20
20
  items { position description quantity unitPrice discount taxKind taxRate supplyAmount }
@@ -37,7 +37,8 @@ const HEAD = [
37
37
  'bankDetails',
38
38
  'notes',
39
39
  'sourceReference',
40
- 'validUntil'
40
+ 'validUntil',
41
+ 'opportunityId'
41
42
  ];
42
43
  const today = () => new Date().toLocaleDateString('en-CA');
43
44
  /**
@@ -55,6 +56,8 @@ let QuotationEditor = class QuotationEditor extends localize(i18next)(PageView)
55
56
  this.error = null;
56
57
  this.busy = false;
57
58
  this.reason = '';
59
+ /** The open opportunities a draft may answer, and the one it answers when that one is closed. */
60
+ this.opportunities = [];
58
61
  }
59
62
  static { this.styles = [
60
63
  FormFieldStyles,
@@ -102,9 +105,12 @@ let QuotationEditor = class QuotationEditor extends localize(i18next)(PageView)
102
105
  if (!this.active || !(changes.active || changes.params))
103
106
  return;
104
107
  const id = lifecycle?.params?.id;
108
+ if (!this.opportunities.length)
109
+ await this.readOpportunities();
105
110
  if (!id) {
106
111
  this.quotation = null;
107
- this.form = blank();
112
+ /* Written from an opportunity, the draft answers it. */
113
+ this.form = { ...blank(), opportunityId: lifecycle?.params?.opportunity ?? '' };
108
114
  this.configure();
109
115
  this.updateContext();
110
116
  return;
@@ -120,9 +126,16 @@ let QuotationEditor = class QuotationEditor extends localize(i18next)(PageView)
120
126
  <section class="page-section">
121
127
  <header class="page-section-header"><h3>${i18next.t('text.quotation-section-head')}</h3></header>
122
128
  ${renderDocumentHead(this.form, editable, patch => (this.form = { ...this.form, ...patch }), html `<label
123
- >${i18next.t('field.quotation-valid-until')}
124
- <input type="date" .value=${this.form.validUntil ?? ''} ?disabled=${!editable} @input=${(e) => (this.form = { ...this.form, validUntil: e.target.value })}
125
- /></label>`)}
129
+ >${i18next.t('field.quotation-valid-until')}
130
+ <input type="date" .value=${this.form.validUntil ?? ''} ?disabled=${!editable} @input=${(e) => (this.form = { ...this.form, validUntil: e.target.value })}
131
+ /></label>
132
+ <label
133
+ >${i18next.t('field.quotation-opportunity')}
134
+ <select .value=${this.form.opportunityId ?? ''} ?disabled=${!editable} @change=${(e) => (this.form = { ...this.form, opportunityId: e.target.value })}>
135
+ <option value=""></option>
136
+ ${this.opportunityChoices().map(one => html `<option value=${one.id} ?selected=${one.id === this.form.opportunityId}>${one.name}${one.counterparty?.name ? ` · ${one.counterparty.name}` : ''}</option>`)}
137
+ </select>
138
+ </label>`)}
126
139
  </section>
127
140
  <section class="page-section">
128
141
  <header class="page-section-header"><h3>${i18next.t('text.quotation-section-lines')}</h3></header>
@@ -166,6 +179,33 @@ let QuotationEditor = class QuotationEditor extends localize(i18next)(PageView)
166
179
  </div>
167
180
  </section>`;
168
181
  }
182
+ opportunityChoices() {
183
+ const answered = this.quotation?.opportunity;
184
+ return answered && !this.opportunities.some(one => one.id === answered.id) ? [answered, ...this.opportunities] : this.opportunities;
185
+ }
186
+ async readOpportunities() {
187
+ try {
188
+ const response = await client.query({
189
+ query: gql `
190
+ query ($filters: [Filter!], $pagination: Pagination, $sortings: [Sorting!]) {
191
+ opportunities(filters: $filters, pagination: $pagination, sortings: $sortings) {
192
+ items { id name counterparty { name } }
193
+ }
194
+ }
195
+ `,
196
+ variables: {
197
+ filters: [{ name: 'stage', operator: 'in', value: ['LEAD', 'PROPOSAL', 'QUOTED', 'NEGOTIATION'] }],
198
+ pagination: { page: 1, limit: 500 },
199
+ sortings: [{ name: 'name' }]
200
+ },
201
+ fetchPolicy: 'no-cache'
202
+ });
203
+ this.opportunities = response.data?.opportunities?.items ?? [];
204
+ }
205
+ catch (error) {
206
+ notify({ level: 'error', message: error?.graphQLErrors?.[0]?.message ?? error?.message ?? String(error) });
207
+ }
208
+ }
169
209
  configure() {
170
210
  this.gristConfig = documentLinesConfig({ editable: this.editable, currency: this.form.currency || 'KRW' });
171
211
  }
@@ -301,6 +341,10 @@ __decorate([
301
341
  state(),
302
342
  __metadata("design:type", Object)
303
343
  ], QuotationEditor.prototype, "gristConfig", void 0);
344
+ __decorate([
345
+ state(),
346
+ __metadata("design:type", Array)
347
+ ], QuotationEditor.prototype, "opportunities", void 0);
304
348
  __decorate([
305
349
  query('ox-grist'),
306
350
  __metadata("design:type", DataGrist)
@@ -1 +1 @@
1
- {"version":3,"file":"quotation-editor.js","sourceRoot":"","sources":["../../client/pages/quotation-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;AAE/D,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AACzC,OAAO,EAAE,OAAO,EAAE,Q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ato/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 { navigate, PageView } from '@operato/shell'\nimport { ButtonStyles, CommonGristStyles, DocumentPageStyles, FormFieldStyles, ScrollbarStyles } from '@operato/styles'\nimport {\n documentHtml,\n DocumentFormStyles,\n documentLinesConfig,\n linesOf,\n printDocument,\n renderDocumentHead,\n renderDocumentTotals,\n type DocumentValue\n} from '@things-factory/invoice/dist-client'\n\nimport { quotationSection } from '../quotation-attach'\nimport { quotationStatusWord } from '../quotation-words'\n\nconst FIELDS = `\n id number version status validUntil outcomeReason direction currency language supplierName supplierAddress supplierRegistrationNumber\n buyerName buyerAddress buyerRegistrationNumber issueDate purchaseOrder paymentTerms bankDetails notes sourceReference\n supplyAmount taxAmount totalAmount taxRounding currencyDigits\n items { position description quantity unitPrice discount taxKind taxRate supplyAmount }\n taxGroups { taxKind taxRate supplyAmount taxAmount }\n`\n\nconst HEAD = [\n 'number',\n 'direction',\n 'currency',\n 'language',\n 'supplierName',\n 'supplierAddress',\n 'supplierRegistrationNumber',\n 'buyerName',\n 'buyerAddress',\n 'buyerRegistrationNumber',\n 'issueDate',\n 'purchaseOrder',\n 'paymentTerms',\n 'bankDetails',\n 'notes',\n 'sourceReference',\n 'validUntil'\n]\n\nconst today = () => new Date().toLocaleDateString('en-CA')\n\n/**\n * 견적 편집 — the same head, lines and totals as an invoice, valid until a day.\n *\n * A draft is saved and sent; once sent its amounts are fixed, and the buyer's answer is recorded — accepted, or\n * declined with a reason. To change a sent quotation, revise it: the next version keeps the number.\n */\n@customElement('quotation-editor')\nexport class QuotationEditor 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() quotation: DocumentValue | null = null\n @state() form: DocumentValue = blank()\n @state() loading = false\n @state() error: unknown = null\n @state() busy = false\n @state() reason = ''\n @state() gristConfig: any\n\n @query('ox-grist') private grist?: DataGrist\n\n get editable() {\n return !this.quotation || this.quotation.status === 'DRAFT'\n }\n\n get context() {\n const status = this.quotation?.status\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.quotation-send'), icon: 'send', emphasis: { raised: true }, action: () => this.send() })\n }\n if (status === 'SENT') {\n if (this.quotation!.validUntil < today()) actions.push({ title: i18next.t('button.quotation-expire'), action: () => this.change('expireQuotation') })\n else actions.push({ title: i18next.t('button.quotation-accept'), emphasis: { raised: true }, action: () => this.change('acceptQuotation') })\n }\n if (['SENT', 'REJECTED', 'EXPIRED'].includes(status)) actions.push({ title: i18next.t('button.quotation-revise'), icon: 'edit_document', action: () => this.change('reviseQuotation') })\n if (this.quotation) actions.push({ title: i18next.t('button.quotation-print'), icon: 'print', action: () => this.print() })\n return {\n title: this.quotation ? `${i18next.t('title.quotation')} ${this.quotation.number} · v${this.quotation.version}` : i18next.t('title.quotation-new'),\n ...(this.quotation ? { description: quotationStatusWord(status) } : {}),\n frame: 'document',\n /* Opened from the quotation list; the menu marks it. */\n menu: 'quotation-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 (!id) {\n this.quotation = null\n this.form = blank()\n this.configure()\n this.updateContext()\n return\n }\n if (id !== this.quotation?.id) await this.load(id)\n }\n\n render() {\n const attached = this.quotation ? quotationSection() : undefined\n const editable = this.editable && !this.busy\n return html`<ox-page-state .loading=${this.loading} .error=${this.error} @retry=${() => this.quotation && this.load(this.quotation.id)}>\n <div class=\"page\">\n <section class=\"page-section\">\n <header class=\"page-section-header\"><h3>${i18next.t('text.quotation-section-head')}</h3></header>\n ${renderDocumentHead(\n this.form,\n editable,\n patch => (this.form = { ...this.form, ...patch }),\n html`<label\n >${i18next.t('field.quotation-valid-until')}\n <input type=\"date\" .value=${this.form.validUntil ?? ''} ?disabled=${!editable} @input=${(e: any) => (this.form = { ...this.form, validUntil: e.target.value })}\n /></label>`\n )}\n </section>\n <section class=\"page-section\">\n <header class=\"page-section-header\"><h3>${i18next.t('text.quotation-section-lines')}</h3></header>\n <ox-grist mode=\"GRID\" .config=${this.gristConfig} .fetchHandler=${() => ({ total: this.form.items.length, records: this.form.items })}></ox-grist>\n </section>\n ${this.quotation\n ? html`<section class=\"page-section\">\n <header class=\"page-section-header\"><h3>${i18next.t('text.quotation-section-totals')}</h3></header>\n ${renderDocumentTotals(this.quotation)}\n </section>`\n : nothing}\n ${this.quotation?.status === 'SENT' ? this.renderDecline() : nothing}\n ${this.quotation?.outcomeReason\n ? html`<section class=\"page-section\">\n <header class=\"page-section-header\"><h3>${i18next.t('field.quotation-outcome-reason')}</h3></header>\n <p>${this.quotation.outcomeReason}</p>\n </section>`\n : nothing}\n ${attached && this.quotation\n ? html`<section class=\"page-section\">\n <header class=\"page-section-header\"><h3>${attached.heading()}</h3></header>\n ${attached.render(this.quotation as any)}\n </section>`\n : nothing}\n </div>\n </ox-page-state>`\n }\n\n private renderDecline() {\n return html`<section class=\"page-section\">\n <header class=\"page-section-header\">\n <h3>${i18next.t('text.quotation-section-decline')}</h3>\n <div class=\"page-section-actions\">\n <button ?disabled=${this.busy || !this.reason.trim()} @click=${() => this.change('rejectQuotation', this.reason.trim())}>${i18next.t('button.quotation-reject')}</button>\n </div>\n </header>\n <div class=\"form\">\n <label class=\"wide\"\n >${i18next.t('field.quotation-outcome-reason')}\n <input .value=${this.reason} ?disabled=${this.busy} @input=${(e: any) => (this.reason = e.target.value)}\n /></label>\n </div>\n </section>`\n }\n\n private configure() {\n this.gristConfig = documentLinesConfig({ editable: this.editable, 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!) { quotation(id: $id) { ${FIELDS} } }`), variables: { id }, fetchPolicy: 'no-cache' })\n if (response.errors?.length) throw response\n if (!response.data.quotation) throw new Error(i18next.t('text.quotation-not-found'))\n this.show(response.data.quotation)\n } catch (error) {\n this.error = error\n } finally {\n this.loading = false\n this.updateContext()\n }\n }\n\n private show(quotation: DocumentValue) {\n this.quotation = quotation\n this.form = { ...quotation, items: quotation.items.map((item: any) => ({ ...item })) }\n this.reason = ''\n this.configure()\n this.grist?.fetch()\n }\n\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.items = linesOf(this.grist).map(({ receivedTaxAmount, ...line }: any) => line)\n return input\n }\n\n private async save(): Promise<DocumentValue | undefined> {\n const id = this.quotation?.id\n const saved = await this.run(async () => {\n const response = await client.mutate({\n mutation: gql(\n id\n ? `mutation ($id: String!, $quotation: NewQuotation!) { quotation: updateQuotation(id: $id, quotation: $quotation) { ${FIELDS} } }`\n : `mutation ($quotation: NewQuotation!) { quotation: createQuotation(quotation: $quotation) { ${FIELDS} } }`\n ),\n variables: { ...(id ? { id } : {}), quotation: this.input() }\n })\n if (response.errors?.length) throw response\n return response.data.quotation as DocumentValue\n })\n if (!saved) return undefined\n this.show(saved)\n this.updateContext()\n if (!id) navigate(`quotation-editor?id=${saved.id}`)\n return saved\n }\n\n /** Save what is on screen, then send it — its amounts are fixed from here on. */\n private async send() {\n const saved = await this.save()\n if (saved) await this.change('sendQuotation')\n }\n\n private async change(mutation: string, reason?: string) {\n const changed = await this.run(async () => {\n const response = await client.mutate({\n mutation: gql(\n reason === undefined\n ? `mutation ($id: String!) { quotation: ${mutation}(id: $id) { ${FIELDS} } }`\n : `mutation ($id: String!, $reason: String!) { quotation: ${mutation}(id: $id, reason: $reason) { ${FIELDS} } }`\n ),\n variables: { id: this.quotation!.id, ...(reason === undefined ? {} : { reason }) }\n })\n if (response.errors?.length) throw response\n return response.data.quotation as DocumentValue\n })\n if (!changed) return\n if (changed.id !== this.quotation?.id) navigate(`quotation-editor?id=${changed.id}`)\n this.show(changed)\n this.updateContext()\n }\n\n private print() {\n const quotation = this.quotation!\n const lng = quotation.language === 'en' ? 'en' : 'ko'\n printDocument(\n documentHtml(quotation, {\n title: i18next.t('title.quotation-print', { lng }),\n terms: [\n { label: i18next.t('field.quotation-version', { lng }), value: `v${quotation.version}` },\n { label: i18next.t('field.quotation-valid-until', { lng }), value: quotation.validUntil }\n ]\n })\n )\n }\n}\n\nfunction blank(): DocumentValue {\n return { number: '', direction: 'SALES', currency: 'KRW', language: 'ko', supplierName: '', buyerName: '', issueDate: today(), validUntil: '', items: [] }\n}\n"]}
1
+ {"version":3,"file":"quotation-editor.js","sourceRoot":"","sources":["../../client/pages/quotation-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;AAE/D,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AACzC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACjD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AC,6BAA6B,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,SAAS,CAAC,UAAU,EAAE;aAC1F;SACF,CAAC,CACH,CAAA;IACH,CAAC;;AAjQQ;IAAR,KAAK,EAAE;;kDAAuC;AACtC;IAAR,KAAK,EAAE;;6CAA8B;AAC7B;IAAR,KAAK,EAAE;;gDAAgB;AACf;IAAR,KAAK,EAAE;;8CAAsB;AACrB;IAAR,KAAK,EAAE;;6CAAa;AACZ;IAAR,KAAK,EAAE;;+CAAY;AACX;IAAR,KAAK,EAAE;;oDAAiB;AAEhB;IAAR,KAAK,EAAE;;sDAAoF;AAEjE;IAA1B,KAAK,CAAC,UAAU,CAAC;8BAAiB,SAAS;8CAAA;AAzBjC,eAAe;IAD3B,aAAa,CAAC,kBAAkB,CAAC;GACrB,eAAe,CAiR3B;;AAED,SAAS,KAAK;IACZ,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,EAAE,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE,UAAU,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,CAAA;AAC5J,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 { navigate, PageView } from '@operato/shell'\nimport { ButtonStyles, CommonGristStyles, DocumentPageStyles, FormFieldStyles, ScrollbarStyles } from '@operato/styles'\nimport {\n documentHtml,\n DocumentFormStyles,\n documentLinesConfig,\n linesOf,\n printDocument,\n renderDocumentHead,\n renderDocumentTotals,\n type DocumentValue\n} from '@things-factory/invoice/dist-client'\n\nimport { quotationSection } from '../quotation-attach'\nimport { quotationStatusWord } from '../quotation-words'\n\nconst FIELDS = `\n id number version status validUntil outcomeReason opportunityId opportunity { id name } direction currency language supplierName supplierAddress supplierRegistrationNumber\n buyerName buyerAddress buyerRegistrationNumber issueDate purchaseOrder paymentTerms bankDetails notes sourceReference\n supplyAmount taxAmount totalAmount taxRounding currencyDigits\n items { position description quantity unitPrice discount taxKind taxRate supplyAmount }\n taxGroups { taxKind taxRate supplyAmount taxAmount }\n`\n\nconst HEAD = [\n 'number',\n 'direction',\n 'currency',\n 'language',\n 'supplierName',\n 'supplierAddress',\n 'supplierRegistrationNumber',\n 'buyerName',\n 'buyerAddress',\n 'buyerRegistrationNumber',\n 'issueDate',\n 'purchaseOrder',\n 'paymentTerms',\n 'bankDetails',\n 'notes',\n 'sourceReference',\n 'validUntil',\n 'opportunityId'\n]\n\nconst today = () => new Date().toLocaleDateString('en-CA')\n\n/**\n * 견적 편집 — the same head, lines and totals as an invoice, valid until a day.\n *\n * A draft is saved and sent; once sent its amounts are fixed, and the buyer's answer is recorded — accepted, or\n * declined with a reason. To change a sent quotation, revise it: the next version keeps the number.\n */\n@customElement('quotation-editor')\nexport class QuotationEditor 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() quotation: DocumentValue | null = null\n @state() form: DocumentValue = blank()\n @state() loading = false\n @state() error: unknown = null\n @state() busy = false\n @state() reason = ''\n @state() gristConfig: any\n /** The open opportunities a draft may answer, and the one it answers when that one is closed. */\n @state() opportunities: { id: string; name: string; counterparty?: { name: string } }[] = []\n\n @query('ox-grist') private grist?: DataGrist\n\n get editable() {\n return !this.quotation || this.quotation.status === 'DRAFT'\n }\n\n get context() {\n const status = this.quotation?.status\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.quotation-send'), icon: 'send', emphasis: { raised: true }, action: () => this.send() })\n }\n if (status === 'SENT') {\n if (this.quotation!.validUntil < today()) actions.push({ title: i18next.t('button.quotation-expire'), action: () => this.change('expireQuotation') })\n else actions.push({ title: i18next.t('button.quotation-accept'), emphasis: { raised: true }, action: () => this.change('acceptQuotation') })\n }\n if (['SENT', 'REJECTED', 'EXPIRED'].includes(status)) actions.push({ title: i18next.t('button.quotation-revise'), icon: 'edit_document', action: () => this.change('reviseQuotation') })\n if (this.quotation) actions.push({ title: i18next.t('button.quotation-print'), icon: 'print', action: () => this.print() })\n return {\n title: this.quotation ? `${i18next.t('title.quotation')} ${this.quotation.number} · v${this.quotation.version}` : i18next.t('title.quotation-new'),\n ...(this.quotation ? { description: quotationStatusWord(status) } : {}),\n frame: 'document',\n /* Opened from the quotation list; the menu marks it. */\n menu: 'quotation-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.opportunities.length) await this.readOpportunities()\n if (!id) {\n this.quotation = null\n /* Written from an opportunity, the draft answers it. */\n this.form = { ...blank(), opportunityId: lifecycle?.params?.opportunity ?? '' }\n this.configure()\n this.updateContext()\n return\n }\n if (id !== this.quotation?.id) await this.load(id)\n }\n\n render() {\n const attached = this.quotation ? quotationSection() : undefined\n const editable = this.editable && !this.busy\n return html`<ox-page-state .loading=${this.loading} .error=${this.error} @retry=${() => this.quotation && this.load(this.quotation.id)}>\n <div class=\"page\">\n <section class=\"page-section\">\n <header class=\"page-section-header\"><h3>${i18next.t('text.quotation-section-head')}</h3></header>\n ${renderDocumentHead(\n this.form,\n editable,\n patch => (this.form = { ...this.form, ...patch }),\n html`<label\n >${i18next.t('field.quotation-valid-until')}\n <input type=\"date\" .value=${this.form.validUntil ?? ''} ?disabled=${!editable} @input=${(e: any) => (this.form = { ...this.form, validUntil: e.target.value })}\n /></label>\n <label\n >${i18next.t('field.quotation-opportunity')}\n <select .value=${this.form.opportunityId ?? ''} ?disabled=${!editable} @change=${(e: any) => (this.form = { ...this.form, opportunityId: e.target.value })}>\n <option value=\"\"></option>\n ${this.opportunityChoices().map(\n one => html`<option value=${one.id} ?selected=${one.id === this.form.opportunityId}>${one.name}${one.counterparty?.name ? ` · ${one.counterparty.name}` : ''}</option>`\n )}\n </select>\n </label>`\n )}\n </section>\n <section class=\"page-section\">\n <header class=\"page-section-header\"><h3>${i18next.t('text.quotation-section-lines')}</h3></header>\n <ox-grist mode=\"GRID\" .config=${this.gristConfig} .fetchHandler=${() => ({ total: this.form.items.length, records: this.form.items })}></ox-grist>\n </section>\n ${this.quotation\n ? html`<section class=\"page-section\">\n <header class=\"page-section-header\"><h3>${i18next.t('text.quotation-section-totals')}</h3></header>\n ${renderDocumentTotals(this.quotation)}\n </section>`\n : nothing}\n ${this.quotation?.status === 'SENT' ? this.renderDecline() : nothing}\n ${this.quotation?.outcomeReason\n ? html`<section class=\"page-section\">\n <header class=\"page-section-header\"><h3>${i18next.t('field.quotation-outcome-reason')}</h3></header>\n <p>${this.quotation.outcomeReason}</p>\n </section>`\n : nothing}\n ${attached && this.quotation\n ? html`<section class=\"page-section\">\n <header class=\"page-section-header\"><h3>${attached.heading()}</h3></header>\n ${attached.render(this.quotation as any)}\n </section>`\n : nothing}\n </div>\n </ox-page-state>`\n }\n\n private renderDecline() {\n return html`<section class=\"page-section\">\n <header class=\"page-section-header\">\n <h3>${i18next.t('text.quotation-section-decline')}</h3>\n <div class=\"page-section-actions\">\n <button ?disabled=${this.busy || !this.reason.trim()} @click=${() => this.change('rejectQuotation', this.reason.trim())}>${i18next.t('button.quotation-reject')}</button>\n </div>\n </header>\n <div class=\"form\">\n <label class=\"wide\"\n >${i18next.t('field.quotation-outcome-reason')}\n <input .value=${this.reason} ?disabled=${this.busy} @input=${(e: any) => (this.reason = e.target.value)}\n /></label>\n </div>\n </section>`\n }\n\n private opportunityChoices() {\n const answered = this.quotation?.opportunity\n return answered && !this.opportunities.some(one => one.id === answered.id) ? [answered, ...this.opportunities] : this.opportunities\n }\n\n private async readOpportunities() {\n try {\n const response = await client.query({\n query: gql`\n query ($filters: [Filter!], $pagination: Pagination, $sortings: [Sorting!]) {\n opportunities(filters: $filters, pagination: $pagination, sortings: $sortings) {\n items { id name counterparty { name } }\n }\n }\n `,\n variables: {\n filters: [{ name: 'stage', operator: 'in', value: ['LEAD', 'PROPOSAL', 'QUOTED', 'NEGOTIATION'] }],\n pagination: { page: 1, limit: 500 },\n sortings: [{ name: 'name' }]\n },\n fetchPolicy: 'no-cache'\n })\n this.opportunities = response.data?.opportunities?.items ?? []\n } catch (error: any) {\n notify({ level: 'error', message: error?.graphQLErrors?.[0]?.message ?? error?.message ?? String(error) })\n }\n }\n\n private configure() {\n this.gristConfig = documentLinesConfig({ editable: this.editable, 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!) { quotation(id: $id) { ${FIELDS} } }`), variables: { id }, fetchPolicy: 'no-cache' })\n if (response.errors?.length) throw response\n if (!response.data.quotation) throw new Error(i18next.t('text.quotation-not-found'))\n this.show(response.data.quotation)\n } catch (error) {\n this.error = error\n } finally {\n this.loading = false\n this.updateContext()\n }\n }\n\n private show(quotation: DocumentValue) {\n this.quotation = quotation\n this.form = { ...quotation, items: quotation.items.map((item: any) => ({ ...item })) }\n this.reason = ''\n this.configure()\n this.grist?.fetch()\n }\n\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.items = linesOf(this.grist).map(({ receivedTaxAmount, ...line }: any) => line)\n return input\n }\n\n private async save(): Promise<DocumentValue | undefined> {\n const id = this.quotation?.id\n const saved = await this.run(async () => {\n const response = await client.mutate({\n mutation: gql(\n id\n ? `mutation ($id: String!, $quotation: NewQuotation!) { quotation: updateQuotation(id: $id, quotation: $quotation) { ${FIELDS} } }`\n : `mutation ($quotation: NewQuotation!) { quotation: createQuotation(quotation: $quotation) { ${FIELDS} } }`\n ),\n variables: { ...(id ? { id } : {}), quotation: this.input() }\n })\n if (response.errors?.length) throw response\n return response.data.quotation as DocumentValue\n })\n if (!saved) return undefined\n this.show(saved)\n this.updateContext()\n if (!id) navigate(`quotation-editor?id=${saved.id}`)\n return saved\n }\n\n /** Save what is on screen, then send it — its amounts are fixed from here on. */\n private async send() {\n const saved = await this.save()\n if (saved) await this.change('sendQuotation')\n }\n\n private async change(mutation: string, reason?: string) {\n const changed = await this.run(async () => {\n const response = await client.mutate({\n mutation: gql(\n reason === undefined\n ? `mutation ($id: String!) { quotation: ${mutation}(id: $id) { ${FIELDS} } }`\n : `mutation ($id: String!, $reason: String!) { quotation: ${mutation}(id: $id, reason: $reason) { ${FIELDS} } }`\n ),\n variables: { id: this.quotation!.id, ...(reason === undefined ? {} : { reason }) }\n })\n if (response.errors?.length) throw response\n return response.data.quotation as DocumentValue\n })\n if (!changed) return\n if (changed.id !== this.quotation?.id) navigate(`quotation-editor?id=${changed.id}`)\n this.show(changed)\n this.updateContext()\n }\n\n private print() {\n const quotation = this.quotation!\n const lng = quotation.language === 'en' ? 'en' : 'ko'\n printDocument(\n documentHtml(quotation, {\n title: i18next.t('title.quotation-print', { lng }),\n terms: [\n { label: i18next.t('field.quotation-version', { lng }), value: `v${quotation.version}` },\n { label: i18next.t('field.quotation-valid-until', { lng }), value: quotation.validUntil }\n ]\n })\n )\n }\n}\n\nfunction blank(): DocumentValue {\n return { number: '', direction: 'SALES', currency: 'KRW', language: 'ko', supplierName: '', buyerName: '', issueDate: today(), validUntil: '', items: [] }\n}\n"]}