@things-factory/sales 0.0.0-stage → 10.1.177

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 (131) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/assets/images/hatiolab-logo.png +0 -0
  3. package/dist-client/bootstrap.d.ts +1 -0
  4. package/dist-client/bootstrap.js +5 -0
  5. package/dist-client/bootstrap.js.map +1 -0
  6. package/dist-client/entity360/opportunity-360.d.ts +12 -0
  7. package/dist-client/entity360/opportunity-360.js +114 -0
  8. package/dist-client/entity360/opportunity-360.js.map +1 -0
  9. package/dist-client/index.d.ts +4 -0
  10. package/dist-client/index.js +5 -0
  11. package/dist-client/index.js.map +1 -0
  12. package/dist-client/opportunity-attach.d.ts +17 -0
  13. package/dist-client/opportunity-attach.js +8 -0
  14. package/dist-client/opportunity-attach.js.map +1 -0
  15. package/dist-client/opportunity-words.d.ts +1 -0
  16. package/dist-client/opportunity-words.js +13 -0
  17. package/dist-client/opportunity-words.js.map +1 -0
  18. package/dist-client/pages/opportunity-editor.d.ts +83 -0
  19. package/dist-client/pages/opportunity-editor.js +528 -0
  20. package/dist-client/pages/opportunity-editor.js.map +1 -0
  21. package/dist-client/pages/opportunity-list.d.ts +40 -0
  22. package/dist-client/pages/opportunity-list.js +134 -0
  23. package/dist-client/pages/opportunity-list.js.map +1 -0
  24. package/dist-client/pages/quotation-editor.d.ts +54 -0
  25. package/dist-client/pages/quotation-editor.js +359 -0
  26. package/dist-client/pages/quotation-editor.js.map +1 -0
  27. package/dist-client/pages/quotation-list.d.ts +36 -0
  28. package/dist-client/pages/quotation-list.js +113 -0
  29. package/dist-client/pages/quotation-list.js.map +1 -0
  30. package/dist-client/quotation-attach.d.ts +16 -0
  31. package/dist-client/quotation-attach.js +8 -0
  32. package/dist-client/quotation-attach.js.map +1 -0
  33. package/dist-client/quotation-words.d.ts +1 -0
  34. package/dist-client/quotation-words.js +13 -0
  35. package/dist-client/quotation-words.js.map +1 -0
  36. package/dist-client/route.d.ts +1 -0
  37. package/dist-client/route.js +17 -0
  38. package/dist-client/route.js.map +1 -0
  39. package/dist-client/tsconfig.tsbuildinfo +1 -0
  40. package/dist-server/controllers/index.d.ts +0 -0
  41. package/dist-server/controllers/index.js +1 -0
  42. package/dist-server/controllers/index.js.map +1 -0
  43. package/dist-server/index.d.ts +4 -0
  44. package/dist-server/index.js +8 -0
  45. package/dist-server/index.js.map +1 -0
  46. package/dist-server/middlewares/index.d.ts +2 -0
  47. package/dist-server/middlewares/index.js +7 -0
  48. package/dist-server/middlewares/index.js.map +1 -0
  49. package/dist-server/migrations/index.d.ts +1 -0
  50. package/dist-server/migrations/index.js +12 -0
  51. package/dist-server/migrations/index.js.map +1 -0
  52. package/dist-server/routes.d.ts +0 -0
  53. package/dist-server/routes.js +24 -0
  54. package/dist-server/routes.js.map +1 -0
  55. package/dist-server/service/index.d.ts +16 -0
  56. package/dist-server/service/index.js +21 -0
  57. package/dist-server/service/index.js.map +1 -0
  58. package/dist-server/service/opportunity/index.d.ts +8 -0
  59. package/dist-server/service/opportunity/index.js +12 -0
  60. package/dist-server/service/opportunity/index.js.map +1 -0
  61. package/dist-server/service/opportunity/opportunity-event-query.d.ts +9 -0
  62. package/dist-server/service/opportunity/opportunity-event-query.js +55 -0
  63. package/dist-server/service/opportunity/opportunity-event-query.js.map +1 -0
  64. package/dist-server/service/opportunity/opportunity-event.d.ts +27 -0
  65. package/dist-server/service/opportunity/opportunity-event.js +115 -0
  66. package/dist-server/service/opportunity/opportunity-event.js.map +1 -0
  67. package/dist-server/service/opportunity/opportunity-mutation.d.ts +7 -0
  68. package/dist-server/service/opportunity/opportunity-mutation.js +64 -0
  69. package/dist-server/service/opportunity/opportunity-mutation.js.map +1 -0
  70. package/dist-server/service/opportunity/opportunity-query.d.ts +21 -0
  71. package/dist-server/service/opportunity/opportunity-query.js +156 -0
  72. package/dist-server/service/opportunity/opportunity-query.js.map +1 -0
  73. package/dist-server/service/opportunity/opportunity-rules.d.ts +22 -0
  74. package/dist-server/service/opportunity/opportunity-rules.js +59 -0
  75. package/dist-server/service/opportunity/opportunity-rules.js.map +1 -0
  76. package/dist-server/service/opportunity/opportunity-service.d.ts +19 -0
  77. package/dist-server/service/opportunity/opportunity-service.js +107 -0
  78. package/dist-server/service/opportunity/opportunity-service.js.map +1 -0
  79. package/dist-server/service/opportunity/opportunity-type.d.ts +23 -0
  80. package/dist-server/service/opportunity/opportunity-type.js +86 -0
  81. package/dist-server/service/opportunity/opportunity-type.js.map +1 -0
  82. package/dist-server/service/opportunity/opportunity.d.ts +35 -0
  83. package/dist-server/service/opportunity/opportunity.js +147 -0
  84. package/dist-server/service/opportunity/opportunity.js.map +1 -0
  85. package/dist-server/service/quotation/index.d.ts +10 -0
  86. package/dist-server/service/quotation/index.js +14 -0
  87. package/dist-server/service/quotation/index.js.map +1 -0
  88. package/dist-server/service/quotation/quotation-event-query.d.ts +9 -0
  89. package/dist-server/service/quotation/quotation-event-query.js +55 -0
  90. package/dist-server/service/quotation/quotation-event-query.js.map +1 -0
  91. package/dist-server/service/quotation/quotation-event.d.ts +22 -0
  92. package/dist-server/service/quotation/quotation-event.js +98 -0
  93. package/dist-server/service/quotation/quotation-event.js.map +1 -0
  94. package/dist-server/service/quotation/quotation-item-query.d.ts +8 -0
  95. package/dist-server/service/quotation/quotation-item-query.js +45 -0
  96. package/dist-server/service/quotation/quotation-item-query.js.map +1 -0
  97. package/dist-server/service/quotation/quotation-item.d.ts +18 -0
  98. package/dist-server/service/quotation/quotation-item.js +75 -0
  99. package/dist-server/service/quotation/quotation-item.js.map +1 -0
  100. package/dist-server/service/quotation/quotation-mutation.d.ts +11 -0
  101. package/dist-server/service/quotation/quotation-mutation.js +117 -0
  102. package/dist-server/service/quotation/quotation-mutation.js.map +1 -0
  103. package/dist-server/service/quotation/quotation-query.d.ts +19 -0
  104. package/dist-server/service/quotation/quotation-query.js +136 -0
  105. package/dist-server/service/quotation/quotation-query.js.map +1 -0
  106. package/dist-server/service/quotation/quotation-rules.d.ts +6 -0
  107. package/dist-server/service/quotation/quotation-rules.js +22 -0
  108. package/dist-server/service/quotation/quotation-rules.js.map +1 -0
  109. package/dist-server/service/quotation/quotation-service.d.ts +25 -0
  110. package/dist-server/service/quotation/quotation-service.js +127 -0
  111. package/dist-server/service/quotation/quotation-service.js.map +1 -0
  112. package/dist-server/service/quotation/quotation-type.d.ts +10 -0
  113. package/dist-server/service/quotation/quotation-type.js +36 -0
  114. package/dist-server/service/quotation/quotation-type.js.map +1 -0
  115. package/dist-server/service/quotation/quotation.d.ts +36 -0
  116. package/dist-server/service/quotation/quotation.js +121 -0
  117. package/dist-server/service/quotation/quotation.js.map +1 -0
  118. package/dist-server/service/sales-event.d.ts +15 -0
  119. package/dist-server/service/sales-event.js +12 -0
  120. package/dist-server/service/sales-event.js.map +1 -0
  121. package/dist-server/tsconfig.tsbuildinfo +1 -0
  122. package/helps/quotation/quotation.md +160 -0
  123. package/package.json +46 -4
  124. package/things-factory.config.js +13 -0
  125. package/translations/en.json +102 -0
  126. package/translations/es.json +102 -0
  127. package/translations/ja.json +102 -0
  128. package/translations/ko.json +102 -0
  129. package/translations/ms.json +102 -0
  130. package/translations/zh.json +102 -0
  131. package/README.md +0 -3
@@ -0,0 +1,134 @@
1
+ import { __decorate, __metadata } from "tslib";
2
+ import '@operato/data-grist/ox-grist.js';
3
+ import '@operato/data-grist/ox-filters-form.js';
4
+ import gql from 'graphql-tag';
5
+ import { html } from 'lit';
6
+ import { customElement, query, state } from 'lit/decorators.js';
7
+ import { DataGrist } from '@operato/data-grist';
8
+ import { client } from '@operato/graphql';
9
+ import { i18next, localize } from '@operato/i18n';
10
+ import { entity360Name } from '@operato/layout';
11
+ import { navigate, PageView } from '@operato/shell';
12
+ import { CommonGristStyles, CommonHeaderStyles, ScrollbarStyles, WorkSurfacePageStyles } from '@operato/styles';
13
+ import { isMobileDevice } from '@operato/utils';
14
+ import { documentAmount } from '@things-factory/invoice/dist-client';
15
+ import { opportunityStageWord } from '../opportunity-words';
16
+ const STAGES = ['LEAD', 'PROPOSAL', 'QUOTED', 'NEGOTIATION', 'WON', 'LOST'];
17
+ /** 영업 기회 — every opportunity of the domain, narrowed by stage. The name opens its 360; the edit gutter its editor. */
18
+ let OpportunityList = class OpportunityList extends localize(i18next)(PageView) {
19
+ static { this.styles = [WorkSurfacePageStyles, CommonGristStyles, CommonHeaderStyles, ScrollbarStyles]; }
20
+ get context() {
21
+ return {
22
+ title: i18next.t('title.opportunity-list'),
23
+ search: {
24
+ handler: (search) => {
25
+ this.grist.searchText = search;
26
+ },
27
+ value: this.grist?.searchText || ''
28
+ },
29
+ /* Narrowing by stage stays in the headroom, and this folds it. */
30
+ filter: {
31
+ handler: () => {
32
+ this.grist.toggleHeadroom();
33
+ }
34
+ },
35
+ actions: [{ title: i18next.t('button.opportunity-new'), icon: 'add', emphasis: { raised: true }, action: () => navigate('opportunity-editor') }],
36
+ exportable: { name: i18next.t('title.opportunity-list'), data: () => this.grist.exportRecords() }
37
+ };
38
+ }
39
+ render() {
40
+ return html `<ox-grist
41
+ class="page-fill"
42
+ search-mode="term"
43
+ .mode=${isMobileDevice() ? 'CARD' : 'GRID'}
44
+ .config=${this.gristConfig}
45
+ .fetchHandler=${this.fetchHandler.bind(this)}
46
+ >
47
+ <div slot="headroom" class="header">
48
+ <div class="filters">
49
+ <ox-filters-form without-search autofocus></ox-filters-form>
50
+ </div>
51
+ </div>
52
+ </ox-grist>`;
53
+ }
54
+ async pageInitialized() {
55
+ const open = (record) => record?.id && navigate(`opportunity-editor?id=${record.id}`);
56
+ const party = (value) => (value ? entity360Name({ __typename: 'Counterparty', ...value }, value.name) : '');
57
+ const readonly = (type, name, header, width, extra = {}) => ({
58
+ type,
59
+ name,
60
+ header,
61
+ width,
62
+ sortable: true,
63
+ ...extra,
64
+ record: { editable: false, ...extra.record }
65
+ });
66
+ this.gristConfig = {
67
+ rows: { appendable: false, selectable: false },
68
+ pagination: { limit: 50, pages: [50, 100, 500] },
69
+ emptyNote: { title: i18next.t('text.opportunity-empty'), description: i18next.t('text.opportunity-empty-description') },
70
+ list: { fields: ['name', 'counterparty'], details: ['stage', 'expectedCloseMonth', 'amount'] },
71
+ columns: [
72
+ { type: 'gutter', gutterName: 'sequence' },
73
+ { type: 'gutter', gutterName: 'button', icon: 'edit_note', handlers: { click: (_c, _d, _col, record) => open(record) } },
74
+ readonly('string', 'name', i18next.t('field.opportunity-name'), 220, {
75
+ record: { renderer: (_v, _c, record) => (record?.id ? entity360Name({ __typename: 'Opportunity', ...record }, record.name) : '') }
76
+ }),
77
+ readonly('string', 'counterparty', i18next.t('field.opportunity-counterparty'), 180, { sortable: false, record: { renderer: (value) => party(value) } }),
78
+ readonly('string', 'endCustomer', i18next.t('field.opportunity-end-customer'), 160, { sortable: false, record: { renderer: (value) => party(value) } }),
79
+ readonly('string', 'stage', i18next.t('field.opportunity-stage'), 90, {
80
+ record: { renderer: (value) => opportunityStageWord(value) },
81
+ filter: { type: 'select', operator: 'eq', options: [{ display: '', value: '' }, ...STAGES.map(stage => ({ display: opportunityStageWord(stage), value: stage }))] }
82
+ }),
83
+ readonly('integer', 'probability', i18next.t('field.opportunity-probability'), 70, { record: { align: 'right', renderer: (value) => `${value ?? 0}%` } }),
84
+ readonly('float', 'amount', i18next.t('field.opportunity-amount'), 150, {
85
+ record: { align: 'right', renderer: (value, _c, record) => documentAmount(value, record?.currency || 'KRW') }
86
+ }),
87
+ readonly('string', 'expectedCloseMonth', i18next.t('field.opportunity-expected-close-month'), 100),
88
+ readonly('string', 'owner', i18next.t('field.opportunity-owner'), 110, { sortable: false, record: { renderer: (value) => value?.name ?? '' } })
89
+ ],
90
+ sorters: [{ name: 'expectedCloseMonth' }]
91
+ };
92
+ }
93
+ async fetchHandler({ page = 1, limit = 50, sortings = [], filters = [], search }) {
94
+ const response = await client.query({
95
+ query: gql `
96
+ query ($filters: [Filter!], $pagination: Pagination, $sortings: [Sorting!], $search: String) {
97
+ responses: opportunities(filters: $filters, pagination: $pagination, sortings: $sortings, search: $search) {
98
+ items {
99
+ id
100
+ name
101
+ stage
102
+ probability
103
+ amount
104
+ currency
105
+ expectedCloseMonth
106
+ counterparty { id name }
107
+ endCustomer { id name }
108
+ owner { id name }
109
+ }
110
+ total
111
+ }
112
+ }
113
+ `,
114
+ variables: { filters, pagination: { page, limit }, sortings, search: search?.trim() || undefined },
115
+ fetchPolicy: 'network-only'
116
+ });
117
+ if (response.errors?.length)
118
+ throw response;
119
+ return { total: response.data.responses.total, records: response.data.responses.items };
120
+ }
121
+ };
122
+ __decorate([
123
+ state(),
124
+ __metadata("design:type", Object)
125
+ ], OpportunityList.prototype, "gristConfig", void 0);
126
+ __decorate([
127
+ query('ox-grist'),
128
+ __metadata("design:type", DataGrist)
129
+ ], OpportunityList.prototype, "grist", void 0);
130
+ OpportunityList = __decorate([
131
+ customElement('opportunity-list')
132
+ ], OpportunityList);
133
+ export { OpportunityList };
134
+ //# sourceMappingURL=opportunity-list.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"opportunity-list.js","sourceRoot":"","sources":["../../client/pages/opportunity-list.ts"],"names":[],"mappings":";AAAA,OAAO,iCAAiC,CAAA;AACxC,OAAO,wCAAwC,CAAA;AAE/C,OAAO,GAAG,MAAM,aAAa,CAAA;AAC7B,OAAO,EAAE,IAAI,EAAE,MAAM,KAAK,CAAA;AAC1B,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAE/D,OAAO,EAAE,SAAS,EAAe,MAAM,qBAAqB,CAAA;AAC5D,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AACzC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACnD,OAAO,EAAE,iBAAiB,EA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AA;AAJjC,eAAe;IAD3B,aAAa,CAAC,kBAAkB,CAAC;GACrB,eAAe,CA6G3B","sourcesContent":["import '@operato/data-grist/ox-grist.js'\nimport '@operato/data-grist/ox-filters-form.js'\n\nimport gql from 'graphql-tag'\nimport { html } from 'lit'\nimport { customElement, query, state } from 'lit/decorators.js'\n\nimport { DataGrist, FetchOption } from '@operato/data-grist'\nimport { client } from '@operato/graphql'\nimport { i18next, localize } from '@operato/i18n'\nimport { entity360Name } from '@operato/layout'\nimport { navigate, PageView } from '@operato/shell'\nimport { CommonGristStyles, CommonHeaderStyles, ScrollbarStyles, WorkSurfacePageStyles } from '@operato/styles'\nimport { isMobileDevice } from '@operato/utils'\nimport { documentAmount } from '@things-factory/invoice/dist-client'\n\nimport { opportunityStageWord } from '../opportunity-words'\n\nconst STAGES = ['LEAD', 'PROPOSAL', 'QUOTED', 'NEGOTIATION', 'WON', 'LOST']\n\n/** 영업 기회 — every opportunity of the domain, narrowed by stage. The name opens its 360; the edit gutter its editor. */\n@customElement('opportunity-list')\nexport class OpportunityList extends localize(i18next)(PageView) {\n static styles = [WorkSurfacePageStyles, CommonGristStyles, CommonHeaderStyles, ScrollbarStyles]\n\n @state() gristConfig: any\n @query('ox-grist') private grist!: DataGrist\n\n get context() {\n return {\n title: i18next.t('title.opportunity-list'),\n search: {\n handler: (search: string) => {\n this.grist.searchText = search\n },\n value: this.grist?.searchText || ''\n },\n /* Narrowing by stage stays in the headroom, and this folds it. */\n filter: {\n handler: () => {\n this.grist.toggleHeadroom()\n }\n },\n actions: [{ title: i18next.t('button.opportunity-new'), icon: 'add', emphasis: { raised: true }, action: () => navigate('opportunity-editor') }],\n exportable: { name: i18next.t('title.opportunity-list'), data: () => this.grist.exportRecords() }\n }\n }\n\n render() {\n return html`<ox-grist\n class=\"page-fill\"\n search-mode=\"term\"\n .mode=${isMobileDevice() ? 'CARD' : 'GRID'}\n .config=${this.gristConfig}\n .fetchHandler=${this.fetchHandler.bind(this)}\n >\n <div slot=\"headroom\" class=\"header\">\n <div class=\"filters\">\n <ox-filters-form without-search autofocus></ox-filters-form>\n </div>\n </div>\n </ox-grist>`\n }\n\n async pageInitialized() {\n const open = (record: any) => record?.id && navigate(`opportunity-editor?id=${record.id}`)\n const party = (value?: { id: string; name: string }) => (value ? entity360Name({ __typename: 'Counterparty', ...value }, value.name) : '')\n const readonly = (type: string, name: string, header: string, width: number, extra: any = {}) => ({\n type,\n name,\n header,\n width,\n sortable: true,\n ...extra,\n record: { editable: false, ...extra.record }\n })\n this.gristConfig = {\n rows: { appendable: false, selectable: false },\n pagination: { limit: 50, pages: [50, 100, 500] },\n emptyNote: { title: i18next.t('text.opportunity-empty'), description: i18next.t('text.opportunity-empty-description') },\n list: { fields: ['name', 'counterparty'], details: ['stage', 'expectedCloseMonth', 'amount'] },\n columns: [\n { type: 'gutter', gutterName: 'sequence' },\n { type: 'gutter', gutterName: 'button', icon: 'edit_note', handlers: { click: (_c: any, _d: any, _col: any, record: any) => open(record) } },\n readonly('string', 'name', i18next.t('field.opportunity-name'), 220, {\n record: { renderer: (_v: any, _c: any, record: any) => (record?.id ? entity360Name({ __typename: 'Opportunity', ...record }, record.name) : '') }\n }),\n readonly('string', 'counterparty', i18next.t('field.opportunity-counterparty'), 180, { sortable: false, record: { renderer: (value: any) => party(value) } }),\n readonly('string', 'endCustomer', i18next.t('field.opportunity-end-customer'), 160, { sortable: false, record: { renderer: (value: any) => party(value) } }),\n readonly('string', 'stage', i18next.t('field.opportunity-stage'), 90, {\n record: { renderer: (value: string) => opportunityStageWord(value) },\n filter: { type: 'select', operator: 'eq', options: [{ display: '', value: '' }, ...STAGES.map(stage => ({ display: opportunityStageWord(stage), value: stage }))] }\n }),\n readonly('integer', 'probability', i18next.t('field.opportunity-probability'), 70, { record: { align: 'right', renderer: (value: number) => `${value ?? 0}%` } }),\n readonly('float', 'amount', i18next.t('field.opportunity-amount'), 150, {\n record: { align: 'right', renderer: (value: number, _c: any, record: any) => documentAmount(value, record?.currency || 'KRW') }\n }),\n readonly('string', 'expectedCloseMonth', i18next.t('field.opportunity-expected-close-month'), 100),\n readonly('string', 'owner', i18next.t('field.opportunity-owner'), 110, { sortable: false, record: { renderer: (value: any) => value?.name ?? '' } })\n ],\n sorters: [{ name: 'expectedCloseMonth' }]\n }\n }\n\n async fetchHandler({ page = 1, limit = 50, sortings = [], filters = [], search }: FetchOption) {\n const response = await client.query({\n query: gql`\n query ($filters: [Filter!], $pagination: Pagination, $sortings: [Sorting!], $search: String) {\n responses: opportunities(filters: $filters, pagination: $pagination, sortings: $sortings, search: $search) {\n items {\n id\n name\n stage\n probability\n amount\n currency\n expectedCloseMonth\n counterparty { id name }\n endCustomer { id name }\n owner { id name }\n }\n total\n }\n }\n `,\n variables: { filters, pagination: { page, limit }, sortings, search: search?.trim() || undefined },\n fetchPolicy: 'network-only'\n })\n if (response.errors?.length) throw response\n return { total: response.data.responses.total, records: response.data.responses.items }\n }\n}\n"]}
@@ -0,0 +1,54 @@
1
+ import '@operato/data-grist/ox-grist.js';
2
+ import '@operato/list-state/ox-page-state.js';
3
+ import { PageView } from '@operato/shell';
4
+ import { type DocumentValue } from '@things-factory/invoice/dist-client';
5
+ declare const QuotationEditor_base: (new (...args: any[]) => import("lit").LitElement) & typeof PageView;
6
+ /**
7
+ * 견적 편집 — the same head, lines and totals as an invoice, valid until a day.
8
+ *
9
+ * A draft is saved and sent; once sent its amounts are fixed, and the buyer's answer is recorded — accepted, or
10
+ * declined with a reason. To change a sent quotation, revise it: the next version keeps the number.
11
+ */
12
+ export declare class QuotationEditor extends QuotationEditor_base {
13
+ static styles: import("lit").CSSResult[];
14
+ quotation: DocumentValue | null;
15
+ form: DocumentValue;
16
+ loading: boolean;
17
+ error: unknown;
18
+ busy: boolean;
19
+ reason: string;
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
+ }[];
29
+ private grist?;
30
+ get editable(): boolean;
31
+ get context(): {
32
+ frame: string;
33
+ menu: string;
34
+ actions: any[];
35
+ description?: string | undefined;
36
+ title: string;
37
+ };
38
+ pageUpdated(changes: any, lifecycle: any): Promise<void>;
39
+ render(): import("lit-html").TemplateResult<1>;
40
+ private renderDecline;
41
+ private opportunityChoices;
42
+ private readOpportunities;
43
+ private configure;
44
+ private load;
45
+ private show;
46
+ private run;
47
+ private input;
48
+ private save;
49
+ /** Save what is on screen, then send it — its amounts are fixed from here on. */
50
+ private send;
51
+ private change;
52
+ private print;
53
+ }
54
+ export {};
@@ -0,0 +1,359 @@
1
+ import { __decorate, __metadata } from "tslib";
2
+ import '@operato/data-grist/ox-grist.js';
3
+ import '@operato/list-state/ox-page-state.js';
4
+ import gql from 'graphql-tag';
5
+ import { css, html, nothing } from 'lit';
6
+ import { customElement, query, state } from 'lit/decorators.js';
7
+ import { DataGrist } from '@operato/data-grist';
8
+ import { client } from '@operato/graphql';
9
+ import { i18next, localize } from '@operato/i18n';
10
+ import { notify } from '@operato/layout';
11
+ import { navigate, PageView } from '@operato/shell';
12
+ import { ButtonStyles, CommonGristStyles, DocumentPageStyles, FormFieldStyles, ScrollbarStyles } from '@operato/styles';
13
+ import { documentHtml, DocumentFormStyles, documentLinesConfig, linesOf, printDocument, renderDocumentHead, renderDocumentTotals } from '@things-factory/invoice/dist-client';
14
+ import { quotationSection } from '../quotation-attach';
15
+ import { quotationStatusWord } from '../quotation-words';
16
+ const FIELDS = `
17
+ id number version status validUntil outcomeReason opportunityId opportunity { id name } direction currency language supplierName supplierAddress supplierRegistrationNumber
18
+ buyerName buyerAddress buyerRegistrationNumber issueDate purchaseOrder paymentTerms bankDetails notes sourceReference
19
+ supplyAmount taxAmount totalAmount taxRounding currencyDigits
20
+ items { position description quantity unitPrice discount taxKind taxRate supplyAmount }
21
+ taxGroups { taxKind taxRate supplyAmount taxAmount }
22
+ `;
23
+ const HEAD = [
24
+ 'number',
25
+ 'direction',
26
+ 'currency',
27
+ 'language',
28
+ 'supplierName',
29
+ 'supplierAddress',
30
+ 'supplierRegistrationNumber',
31
+ 'buyerName',
32
+ 'buyerAddress',
33
+ 'buyerRegistrationNumber',
34
+ 'issueDate',
35
+ 'purchaseOrder',
36
+ 'paymentTerms',
37
+ 'bankDetails',
38
+ 'notes',
39
+ 'sourceReference',
40
+ 'validUntil',
41
+ 'opportunityId'
42
+ ];
43
+ const today = () => new Date().toLocaleDateString('en-CA');
44
+ /**
45
+ * 견적 편집 — the same head, lines and totals as an invoice, valid until a day.
46
+ *
47
+ * A draft is saved and sent; once sent its amounts are fixed, and the buyer's answer is recorded — accepted, or
48
+ * declined with a reason. To change a sent quotation, revise it: the next version keeps the number.
49
+ */
50
+ let QuotationEditor = class QuotationEditor extends localize(i18next)(PageView) {
51
+ constructor() {
52
+ super(...arguments);
53
+ this.quotation = null;
54
+ this.form = blank();
55
+ this.loading = false;
56
+ this.error = null;
57
+ this.busy = false;
58
+ this.reason = '';
59
+ /** The open opportunities a draft may answer, and the one it answers when that one is closed. */
60
+ this.opportunities = [];
61
+ }
62
+ static { this.styles = [
63
+ FormFieldStyles,
64
+ ButtonStyles,
65
+ DocumentPageStyles,
66
+ CommonGristStyles,
67
+ ScrollbarStyles,
68
+ DocumentFormStyles,
69
+ css `
70
+ ox-grist {
71
+ height: calc(var(--form-element-height-medium) * 10);
72
+ }
73
+ `
74
+ ]; }
75
+ get editable() {
76
+ return !this.quotation || this.quotation.status === 'DRAFT';
77
+ }
78
+ get context() {
79
+ const status = this.quotation?.status;
80
+ const actions = [];
81
+ if (this.editable) {
82
+ actions.push({ title: i18next.t('button.save'), icon: 'save', action: () => this.save() });
83
+ actions.push({ title: i18next.t('button.quotation-send'), icon: 'send', emphasis: { raised: true }, action: () => this.send() });
84
+ }
85
+ if (status === 'SENT') {
86
+ if (this.quotation.validUntil < today())
87
+ actions.push({ title: i18next.t('button.quotation-expire'), action: () => this.change('expireQuotation') });
88
+ else
89
+ actions.push({ title: i18next.t('button.quotation-accept'), emphasis: { raised: true }, action: () => this.change('acceptQuotation') });
90
+ }
91
+ if (['SENT', 'REJECTED', 'EXPIRED'].includes(status))
92
+ actions.push({ title: i18next.t('button.quotation-revise'), icon: 'edit_document', action: () => this.change('reviseQuotation') });
93
+ if (this.quotation)
94
+ actions.push({ title: i18next.t('button.quotation-print'), icon: 'print', action: () => this.print() });
95
+ return {
96
+ title: this.quotation ? `${i18next.t('title.quotation')} ${this.quotation.number} · v${this.quotation.version}` : i18next.t('title.quotation-new'),
97
+ ...(this.quotation ? { description: quotationStatusWord(status) } : {}),
98
+ frame: 'document',
99
+ /* Opened from the quotation list; the menu marks it. */
100
+ menu: 'quotation-list',
101
+ actions: this.error ? [] : actions
102
+ };
103
+ }
104
+ async pageUpdated(changes, lifecycle) {
105
+ if (!this.active || !(changes.active || changes.params))
106
+ return;
107
+ const id = lifecycle?.params?.id;
108
+ if (!this.opportunities.length)
109
+ await this.readOpportunities();
110
+ if (!id) {
111
+ this.quotation = null;
112
+ /* Written from an opportunity, the draft answers it. */
113
+ this.form = { ...blank(), opportunityId: lifecycle?.params?.opportunity ?? '' };
114
+ this.configure();
115
+ this.updateContext();
116
+ return;
117
+ }
118
+ if (id !== this.quotation?.id)
119
+ await this.load(id);
120
+ }
121
+ render() {
122
+ const attached = this.quotation ? quotationSection() : undefined;
123
+ const editable = this.editable && !this.busy;
124
+ return html `<ox-page-state .loading=${this.loading} .error=${this.error} @retry=${() => this.quotation && this.load(this.quotation.id)}>
125
+ <div class="page">
126
+ <section class="page-section">
127
+ <header class="page-section-header"><h3>${i18next.t('text.quotation-section-head')}</h3></header>
128
+ ${renderDocumentHead(this.form, editable, patch => (this.form = { ...this.form, ...patch }), html `<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>`)}
139
+ </section>
140
+ <section class="page-section">
141
+ <header class="page-section-header"><h3>${i18next.t('text.quotation-section-lines')}</h3></header>
142
+ <ox-grist mode="GRID" .config=${this.gristConfig} .fetchHandler=${() => ({ total: this.form.items.length, records: this.form.items })}></ox-grist>
143
+ </section>
144
+ ${this.quotation
145
+ ? html `<section class="page-section">
146
+ <header class="page-section-header"><h3>${i18next.t('text.quotation-section-totals')}</h3></header>
147
+ ${renderDocumentTotals(this.quotation)}
148
+ </section>`
149
+ : nothing}
150
+ ${this.quotation?.status === 'SENT' ? this.renderDecline() : nothing}
151
+ ${this.quotation?.outcomeReason
152
+ ? html `<section class="page-section">
153
+ <header class="page-section-header"><h3>${i18next.t('field.quotation-outcome-reason')}</h3></header>
154
+ <p>${this.quotation.outcomeReason}</p>
155
+ </section>`
156
+ : nothing}
157
+ ${attached && this.quotation
158
+ ? html `<section class="page-section">
159
+ <header class="page-section-header"><h3>${attached.heading()}</h3></header>
160
+ ${attached.render(this.quotation)}
161
+ </section>`
162
+ : nothing}
163
+ </div>
164
+ </ox-page-state>`;
165
+ }
166
+ renderDecline() {
167
+ return html `<section class="page-section">
168
+ <header class="page-section-header">
169
+ <h3>${i18next.t('text.quotation-section-decline')}</h3>
170
+ <div class="page-section-actions">
171
+ <button ?disabled=${this.busy || !this.reason.trim()} @click=${() => this.change('rejectQuotation', this.reason.trim())}>${i18next.t('button.quotation-reject')}</button>
172
+ </div>
173
+ </header>
174
+ <div class="form">
175
+ <label class="wide"
176
+ >${i18next.t('field.quotation-outcome-reason')}
177
+ <input .value=${this.reason} ?disabled=${this.busy} @input=${(e) => (this.reason = e.target.value)}
178
+ /></label>
179
+ </div>
180
+ </section>`;
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
+ }
209
+ configure() {
210
+ this.gristConfig = documentLinesConfig({ editable: this.editable, currency: this.form.currency || 'KRW' });
211
+ }
212
+ async load(id) {
213
+ this.loading = true;
214
+ this.error = null;
215
+ try {
216
+ const response = await client.query({ query: gql(`query ($id: String!) { quotation(id: $id) { ${FIELDS} } }`), variables: { id }, fetchPolicy: 'no-cache' });
217
+ if (response.errors?.length)
218
+ throw response;
219
+ if (!response.data.quotation)
220
+ throw new Error(i18next.t('text.quotation-not-found'));
221
+ this.show(response.data.quotation);
222
+ }
223
+ catch (error) {
224
+ this.error = error;
225
+ }
226
+ finally {
227
+ this.loading = false;
228
+ this.updateContext();
229
+ }
230
+ }
231
+ show(quotation) {
232
+ this.quotation = quotation;
233
+ this.form = { ...quotation, items: quotation.items.map((item) => ({ ...item })) };
234
+ this.reason = '';
235
+ this.configure();
236
+ this.grist?.fetch();
237
+ }
238
+ async run(work) {
239
+ if (this.busy)
240
+ return undefined;
241
+ this.busy = true;
242
+ try {
243
+ return await work();
244
+ }
245
+ catch (error) {
246
+ notify({ level: 'error', message: error?.graphQLErrors?.[0]?.message ?? error?.errors?.[0]?.message ?? error?.message ?? String(error) });
247
+ return undefined;
248
+ }
249
+ finally {
250
+ this.busy = false;
251
+ }
252
+ }
253
+ input() {
254
+ const input = Object.fromEntries(HEAD.map(key => [key, this.form[key] === '' ? null : this.form[key] ?? null]));
255
+ input.items = linesOf(this.grist).map(({ receivedTaxAmount, ...line }) => line);
256
+ return input;
257
+ }
258
+ async save() {
259
+ const id = this.quotation?.id;
260
+ const saved = await this.run(async () => {
261
+ const response = await client.mutate({
262
+ mutation: gql(id
263
+ ? `mutation ($id: String!, $quotation: NewQuotation!) { quotation: updateQuotation(id: $id, quotation: $quotation) { ${FIELDS} } }`
264
+ : `mutation ($quotation: NewQuotation!) { quotation: createQuotation(quotation: $quotation) { ${FIELDS} } }`),
265
+ variables: { ...(id ? { id } : {}), quotation: this.input() }
266
+ });
267
+ if (response.errors?.length)
268
+ throw response;
269
+ return response.data.quotation;
270
+ });
271
+ if (!saved)
272
+ return undefined;
273
+ this.show(saved);
274
+ this.updateContext();
275
+ if (!id)
276
+ navigate(`quotation-editor?id=${saved.id}`);
277
+ return saved;
278
+ }
279
+ /** Save what is on screen, then send it — its amounts are fixed from here on. */
280
+ async send() {
281
+ const saved = await this.save();
282
+ if (saved)
283
+ await this.change('sendQuotation');
284
+ }
285
+ async change(mutation, reason) {
286
+ const changed = await this.run(async () => {
287
+ const response = await client.mutate({
288
+ mutation: gql(reason === undefined
289
+ ? `mutation ($id: String!) { quotation: ${mutation}(id: $id) { ${FIELDS} } }`
290
+ : `mutation ($id: String!, $reason: String!) { quotation: ${mutation}(id: $id, reason: $reason) { ${FIELDS} } }`),
291
+ variables: { id: this.quotation.id, ...(reason === undefined ? {} : { reason }) }
292
+ });
293
+ if (response.errors?.length)
294
+ throw response;
295
+ return response.data.quotation;
296
+ });
297
+ if (!changed)
298
+ return;
299
+ if (changed.id !== this.quotation?.id)
300
+ navigate(`quotation-editor?id=${changed.id}`);
301
+ this.show(changed);
302
+ this.updateContext();
303
+ }
304
+ print() {
305
+ const quotation = this.quotation;
306
+ const lng = quotation.language === 'en' ? 'en' : 'ko';
307
+ printDocument(documentHtml(quotation, {
308
+ title: i18next.t('title.quotation-print', { lng }),
309
+ terms: [
310
+ { label: i18next.t('field.quotation-version', { lng }), value: `v${quotation.version}` },
311
+ { label: i18next.t('field.quotation-valid-until', { lng }), value: quotation.validUntil }
312
+ ]
313
+ }));
314
+ }
315
+ };
316
+ __decorate([
317
+ state(),
318
+ __metadata("design:type", Object)
319
+ ], QuotationEditor.prototype, "quotation", void 0);
320
+ __decorate([
321
+ state(),
322
+ __metadata("design:type", Object)
323
+ ], QuotationEditor.prototype, "form", void 0);
324
+ __decorate([
325
+ state(),
326
+ __metadata("design:type", Object)
327
+ ], QuotationEditor.prototype, "loading", void 0);
328
+ __decorate([
329
+ state(),
330
+ __metadata("design:type", Object)
331
+ ], QuotationEditor.prototype, "error", void 0);
332
+ __decorate([
333
+ state(),
334
+ __metadata("design:type", Object)
335
+ ], QuotationEditor.prototype, "busy", void 0);
336
+ __decorate([
337
+ state(),
338
+ __metadata("design:type", Object)
339
+ ], QuotationEditor.prototype, "reason", void 0);
340
+ __decorate([
341
+ state(),
342
+ __metadata("design:type", Object)
343
+ ], QuotationEditor.prototype, "gristConfig", void 0);
344
+ __decorate([
345
+ state(),
346
+ __metadata("design:type", Array)
347
+ ], QuotationEditor.prototype, "opportunities", void 0);
348
+ __decorate([
349
+ query('ox-grist'),
350
+ __metadata("design:type", DataGrist)
351
+ ], QuotationEditor.prototype, "grist", void 0);
352
+ QuotationEditor = __decorate([
353
+ customElement('quotation-editor')
354
+ ], QuotationEditor);
355
+ export { QuotationEditor };
356
+ function blank() {
357
+ return { number: '', direction: 'SALES', currency: 'KRW', language: 'ko', supplierName: '', buyerName: '', issueDate: today(), validUntil: '', items: [] };
358
+ }
359
+ //# sourceMappingURL=quotation-editor.js.map
@@ -0,0 +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,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,iBAAiB,EAAE,kBAAkB,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACvH,OAAO,EACL,YAAY,EACZ,kBAAkB,EAClB,mBAAmB,EACnB,OAAO,EACP,aAAa,EACb,kBAAkB,EAClB,oBAAoB,EAErB,MAAM,qCAAqC,CAAA;AAE5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAA;AACtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AAExD,MAAM,MAAM,GAAG;;;;;;CAMd,CAAA;AAED,MAAM,IAAI,GAAG;IACX,QAAQ;IACR,WAAW;IACX,UAAU;IACV,UAAU;IACV,cAAc;IACd,iBAAiB;IACjB,4BAA4B;IAC5B,WAAW;IACX,cAAc;IACd,yBAAyB;IACzB,WAAW;IACX,eAAe;IACf,cAAc;IACd,aAAa;IACb,OAAO;IACP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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"]}