@feedmepos/mf-inventory-portal 0.0.22-dev.2 → 0.0.22-dev.21

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 (81) hide show
  1. package/dist/App.vue.d.ts +2 -0
  2. package/dist/{ApprovalView-D7WEr35k.js → ApprovalView-CCYykhrK.js} +14 -14
  3. package/dist/{BindingsDialog-C-3uO6pD.js → BindingsDialog-33VV_AST.js} +1 -1
  4. package/dist/{BindingsPicker-B3tGisCE.js → BindingsPicker-BKu4vN8J.js} +8 -8
  5. package/dist/{BindingsTable-CPtiH3vj.js → BindingsTable-Dd0h5gDf.js} +1 -1
  6. package/dist/ClosingTemplateView-BhevjTLl.js +1067 -0
  7. package/dist/{FmInventoryTableToolbar.vue_vue_type_script_setup_true_lang-ohHZLOuR.js → FmInventoryTableToolbar.vue_vue_type_script_setup_true_lang-3gp56NNJ.js} +14 -16
  8. package/dist/{IngredientsView-D-EKGLq9.js → IngredientsView-DckIH9eR.js} +5 -6
  9. package/dist/{IntegrationView-BVAO_vch.js → IntegrationView-BqQ4jRIp.js} +2 -2
  10. package/dist/{NumberPrecisionInput.vue_vue_type_script_setup_true_lang-CJYmB7Ct.js → NumberPrecisionInput.vue_vue_type_script_setup_true_lang-Vi0q_bDz.js} +1 -1
  11. package/dist/{PremiumBadge.vue_vue_type_script_setup_true_lang-BxkM-SOw.js → PremiumBadge.vue_vue_type_script_setup_true_lang-BIL8LWRz.js} +1 -1
  12. package/dist/{PurchaseOrderPrintPreview-CP-mK62z.js → PurchaseOrderPrintPreview-Ct7daTTa.js} +1 -1
  13. package/dist/{ReceiveRequestView-x8WTvuDk.js → ReceiveRequestView-B4wHTogG.js} +25 -26
  14. package/dist/RecipeView-DuE4cXLz.js +590 -0
  15. package/dist/Standalone.vue.d.ts +2 -0
  16. package/dist/{StockView-SyWxT4Ee.js → StockView-Bn9v2Ix8.js} +602 -585
  17. package/dist/{SupplierView-a0HAZJau.js → SupplierView-C8rqHSOV.js} +37 -37
  18. package/dist/TransferDetails.vue_vue_type_script_setup_true_lang-CStnY5Zh.js +851 -0
  19. package/dist/TransferDialog.vue_vue_type_script_setup_true_lang-DRKiv_t8.js +1511 -0
  20. package/dist/TransferTemplateView-RM6Y-WL4.js +1209 -0
  21. package/dist/{UnitView-B3c7W5lw.js → UnitView-BXISVrop.js} +4 -4
  22. package/dist/{WarehouseView-DDV-yslF.js → WarehouseView-B055eB90.js} +18 -18
  23. package/dist/api/closing-template.d.ts +14 -0
  24. package/dist/api/inventory.d.ts +5 -7
  25. package/dist/api/netsuite.d.ts +46 -0
  26. package/dist/api/purchase-order-template.d.ts +0 -4
  27. package/dist/{app-DURkcZal.js → app-9algzyce.js} +16045 -15403
  28. package/dist/app.d.ts +6 -0
  29. package/dist/app.js +2 -2
  30. package/dist/components/FmMinMaxInputRules.d.ts +2 -0
  31. package/dist/components/FmUnitInputRules.d.ts +2 -0
  32. package/dist/{decimal-BGJlFDm8.js → decimal-CMuMGm4y.js} +1 -1
  33. package/dist/{defineDeepModel-pATZSiCT.js → defineDeepModel-CjPowyho.js} +1 -1
  34. package/dist/extensions/promises.d.ts +14 -0
  35. package/dist/{format-time-from-id-BCAuJEq2.js → format-time-from-id-DNKcbBFm.js} +1 -1
  36. package/dist/helper/date2.d.ts +1 -0
  37. package/dist/helper/rules.d.ts +7 -0
  38. package/dist/helper/rules.spec.d.ts +1 -0
  39. package/dist/{id-to-date-CVHmTOJk.js → id-to-date-C6W4aVdr.js} +1 -1
  40. package/dist/purchase-order-transaction-type-CscRvNAR.js +680 -0
  41. package/dist/stores/api.d.ts +1 -0
  42. package/dist/stores/feature.d.ts +0 -1
  43. package/dist/stores/helper/core-store-proxy.d.ts +3 -0
  44. package/dist/stores/helper/generate-backend-urls.d.ts +1 -0
  45. package/dist/stores/inventory.d.ts +7 -0
  46. package/dist/stores/location.d.ts +24 -42
  47. package/dist/stores/netsuite.d.ts +56 -0
  48. package/dist/stores/route.d.ts +0 -5
  49. package/dist/stores/warehouse.d.ts +4 -7
  50. package/dist/style.css +1 -1
  51. package/dist/{supplier-DmBbGAwf.js → supplier-BiCX3dpL.js} +1 -1
  52. package/dist/tsconfig.app.tsbuildinfo +1 -1
  53. package/dist/use-template-enabled-locations-2-Dtg2qOTm.js +85 -0
  54. package/dist/views/closing-template/components/closing-template-publish/ClosingTemplatePublish.vue.d.ts +6 -0
  55. package/dist/views/closing-template/composables/use-closing-template-actions.d.ts +276 -84
  56. package/dist/views/closing-template/composables/use-closing-template-table.d.ts +341 -85
  57. package/dist/views/receive-request/components/transfer-details/TransferDetailsProps.d.ts +1 -0
  58. package/dist/views/receive-request/components/transfer-form/TransferForm.vue.d.ts +916 -0
  59. package/dist/views/receive-request/components/transfer-form/TransferFormProps.d.ts +1 -0
  60. package/dist/views/receive-request/composables/use-receive-request-form.d.ts +788 -152
  61. package/dist/views/receive-request/composables/use-receive-request-table.d.ts +800 -164
  62. package/dist/views/transfer-template/components/transfer-template-form/composables/use-template-enabled-locations-2.d.ts +13 -0
  63. package/dist/views/transfer-template/components/transfer-template-form/composables/use-template-enabled-locations.d.ts +4 -7
  64. package/dist/views/transfer-template/components/transfer-template-form/composables/use-transfer-locations.d.ts +2 -2
  65. package/dist/views/transfer-template/composables/use-transfer-template-actions.d.ts +1285 -109
  66. package/dist/views/transfer-template/composables/use-transfer-template-table.d.ts +399 -993
  67. package/dist/views/transfer-template/helpers/remove-deleted-skus.helper.d.ts +345 -0
  68. package/dist/views/warehouse/components/WarehouseForm.vue.d.ts +8 -14
  69. package/dist/{xlsx-1DLm6bBD.js → xlsx-fKJqx2Qc.js} +1 -1
  70. package/dist/{xlsx.util-DLtch7r5.js → xlsx.util-LOnzE3KS.js} +2 -2
  71. package/package.json +5 -5
  72. package/dist/ClosingTemplateView-Df0lgpjS.js +0 -928
  73. package/dist/RecipeView-BysIWI1W.js +0 -581
  74. package/dist/TransferDetails.vue_vue_type_script_setup_true_lang-ckp8gcT_.js +0 -740
  75. package/dist/TransferDialog.vue_vue_type_script_setup_true_lang-BSvpuWY9.js +0 -1409
  76. package/dist/TransferTemplateView-BGi6zd6d.js +0 -1350
  77. package/dist/array-ClJzD_Lt.js +0 -30
  78. package/dist/layout/InventoryLayout.vue.d.ts +0 -2
  79. package/dist/layout/layout-routes.d.ts +0 -6
  80. package/dist/purchase-order-transaction-type-DvSpCSXr.js +0 -712
  81. package/dist/use-template-enabled-locations-BiuOdu1M.js +0 -57
@@ -1,712 +0,0 @@
1
- import { n as W, j as A, ah as P, c as O, S as re, y as ae, a7 as oe, J as ne, K as se, ai as ce, ad as le, w as ie, b as ue, a as de } from "./app-DURkcZal.js";
2
- import { ref as w, computed as L, defineComponent as me, onMounted as pe, resolveComponent as q, openBlock as E, createElementBlock as K, createElementVNode as N, createVNode as I, createCommentVNode as fe, createBlock as H } from "vue";
3
- import { i as ve } from "./FmInventoryTableToolbar.vue_vue_type_script_setup_true_lang-ohHZLOuR.js";
4
- import { F as x, D as M, R as C } from "./row-action.enum-PMKMRrZR.js";
5
- import { useDialog as G, useSnackbar as J, FmButtonVariant as z } from "@feedmepos/ui-library";
6
- import { f as he, p as ge } from "./format-time-from-id-BCAuJEq2.js";
7
- import { c as ye } from "./TableActionableRow.vue_vue_type_script_setup_true_lang-DlNJ6kRg.js";
8
- import { useCoreStore as V, useI18n as be } from "@feedmepos/mf-common";
9
- import { defineStore as we } from "pinia";
10
- import { useRouter as Te } from "vue-router";
11
- const Se = W((a, n) => {
12
- const s = A();
13
- return {
14
- async readRequests(e) {
15
- const t = e ?? s.currentLocationDBName, r = `${a.inventoryBackendUrl}/${t}/purchase-request`;
16
- return await n.get(r);
17
- },
18
- async getPurchaseOrders({
19
- start: e,
20
- end: t
21
- }) {
22
- const r = s.currentLocationDBName, l = `${a.inventoryBackendUrl}/${r}/purchase-order`;
23
- return await n.get(`${l}?start=${e}&end=${t}`);
24
- },
25
- async getPurchaseOrderById(e) {
26
- const t = s.currentLocationDBName, r = `${a.inventoryBackendUrl}/${t}/purchase-order`;
27
- return await n.get(`${r}/${e}`);
28
- },
29
- async processPurchaseOrder(e, t) {
30
- const r = s.currentLocationDBName, l = t || r, i = `${a.inventoryBackendUrl}/${l}/purchase-order/run-operation`;
31
- return await n.put(i, e);
32
- },
33
- async createPurchaseOrder(e) {
34
- const t = s.currentLocationDBName, r = `${a.inventoryBackendUrl}/${t}/purchase-order`;
35
- return await n.post(r, e);
36
- },
37
- async updatePurchaseOrder(e) {
38
- const t = s.currentLocationDBName, r = `${a.inventoryBackendUrl}/${t}/purchase-order`;
39
- return await n.put(r, e);
40
- }
41
- };
42
- }), Pe = {
43
- [P.enum.confirmDraft]: {
44
- primaryActions: {
45
- text: "Confirm draft",
46
- close: !0
47
- },
48
- title: "Confirm draft?",
49
- message: "Purchase order cannot be changed after confirm draft.",
50
- successMessage: "Purchase order draft has been confirmed"
51
- },
52
- [P.enum.cancelDraft]: {
53
- primaryActions: {
54
- text: "Cancel draft",
55
- close: !0,
56
- variant: "destructive"
57
- },
58
- title: "Cancel draft?",
59
- message: "Purchase order cannot be changed after cancelled draft.",
60
- successMessage: "Purchase order draft has been cancelled"
61
- },
62
- [P.enum.submitRequest]: {
63
- primaryActions: {
64
- text: "Submit request",
65
- close: !0
66
- },
67
- title: "Confirm draft?",
68
- message: "Purchase order cannot be changed after confirm draft.",
69
- successMessage: "Purchase order draft has been submitted"
70
- },
71
- [P.enum.completeReceive]: {
72
- primaryActions: {
73
- text: "Mark received",
74
- close: !0
75
- },
76
- title: "Mark as received",
77
- message: "Purchase order cannot be changed after it has complete receiving.",
78
- successMessage: "Purchase order has been marked as received"
79
- },
80
- [P.enum.approveRequest]: {
81
- primaryActions: {
82
- text: "Approve request",
83
- close: !0
84
- },
85
- title: "Approve request?",
86
- message: "Purchase order will be approved.",
87
- successMessage: "Purchase order has been approved"
88
- },
89
- [P.enum.rejectRequest]: {
90
- primaryActions: {
91
- text: "Reject request",
92
- close: !0,
93
- variant: "destructive"
94
- },
95
- title: "Reject request?",
96
- message: "Purchase order will be rejected.",
97
- successMessage: "Purchase order has been rejected"
98
- }
99
- }, Q = W((a, n) => {
100
- function s() {
101
- var p;
102
- const e = V(), t = A(), r = t.businessLevel, l = `business_${((p = e.currentBusiness.value) == null ? void 0 : p._id) ?? ""}`, i = t.currentLocation.dbName;
103
- return r ? l : i;
104
- }
105
- return {
106
- async getTemplate(e) {
107
- const t = s(), r = `${a.inventoryBackendUrl}/${t}/purchase-order-template/${e}`;
108
- return n.get(r);
109
- },
110
- async getLocationTemplate(e) {
111
- const r = A().currentLocation.dbName, l = `${a.inventoryBackendUrl}/${r}/purchase-order-template/${e}`;
112
- return n.get(l);
113
- },
114
- async getBusinessTemplate(e) {
115
- var i;
116
- const r = `business_${((i = V().currentBusiness.value) == null ? void 0 : i._id) ?? ""}`, l = `${a.inventoryBackendUrl}/${r}/purchase-order-template/${e}`;
117
- return n.get(l);
118
- },
119
- async readTemplates() {
120
- const e = s(), t = `${a.inventoryBackendUrl}/${e}/purchase-order-template`;
121
- return n.get(t);
122
- },
123
- async readLocationTemplates() {
124
- const t = A().currentLocation.dbName, r = `${a.inventoryBackendUrl}/${t}/purchase-order-template`;
125
- return n.get(r);
126
- },
127
- async readBusinessTemplates() {
128
- var l;
129
- const t = `business_${((l = V().currentBusiness.value) == null ? void 0 : l._id) ?? ""}`, r = `${a.inventoryBackendUrl}/${t}/purchase-order-template`;
130
- return n.get(r);
131
- },
132
- async createTemplate(e) {
133
- const t = s(), r = `${a.inventoryBackendUrl}/${t}/purchase-order-template`;
134
- return n.post(r, e);
135
- },
136
- async updateTemplate(e) {
137
- const t = s(), r = `${a.inventoryBackendUrl}/${t}/purchase-order-template`;
138
- return n.put(r, e);
139
- },
140
- async deleteTemplate(e) {
141
- const t = s(), r = `${a.inventoryBackendUrl}/${t}/purchase-order-template`;
142
- return n.delete(r, { _id: e._id, _rev: e._rev });
143
- }
144
- };
145
- }), Ae = we("transferTemplateActions", () => {
146
- const a = ke("receive/request"), n = G(), s = J(), e = Q(), t = w({});
147
- function r() {
148
- t.value = {
149
- mode: x.CREATE,
150
- show: !0,
151
- "onUpdate:show"(d) {
152
- t.value.show = d;
153
- }
154
- };
155
- }
156
- function l(d) {
157
- t.value = {
158
- mode: x.UPDATE,
159
- modelValue: d,
160
- show: !0,
161
- "onUpdate:show"(y) {
162
- t.value.show = y;
163
- }
164
- };
165
- }
166
- function i(d, y, v) {
167
- n.open({
168
- title: `Confirm deleting template ${d.name}?`,
169
- message: "Deleted template can no longer be retrieved",
170
- primaryActions: {
171
- text: "Delete",
172
- variant: z.Destructive,
173
- close: !0
174
- },
175
- secondaryActions: {
176
- text: "Cancel",
177
- variant: z.Plain,
178
- close: !0
179
- }
180
- }).onPrimary(async () => {
181
- s.open({
182
- title: `Deleting ${d.name}`,
183
- type: "info"
184
- });
185
- try {
186
- y.value = !0;
187
- const [f] = await Promise.allSettled([
188
- e.deleteTemplate(d),
189
- new Promise((m) => setTimeout(m, 1e3))
190
- ]);
191
- if (f.status === "rejected") throw f.reason;
192
- s.open({
193
- title: `Deleted ${d.name}`,
194
- type: "success"
195
- });
196
- } catch (f) {
197
- s.open({
198
- title: `Unable to delete ${d.name}`,
199
- message: `See error from server: ${f}`,
200
- type: "error"
201
- }), console.error("error on deleting purchase order template", f);
202
- } finally {
203
- y.value = !1, v();
204
- }
205
- });
206
- }
207
- const p = w({});
208
- function T(d) {
209
- p.value = {
210
- template: d,
211
- show: !0,
212
- "onUpdate:show"(y) {
213
- p.value.show = y;
214
- },
215
- "onAction:edit"() {
216
- p.value.show = !1, l(O(d));
217
- },
218
- "onAction:use"(y) {
219
- const v = A(), f = v.locations.find((m) => m.doc._id === y);
220
- v.selectLocation(f), p.value.show = !1, S(O(d));
221
- }
222
- };
223
- }
224
- function S(d) {
225
- a.promptCreateTransferDialog({
226
- ...d.purchaseOrder,
227
- template: d._id
228
- });
229
- }
230
- return {
231
- createTemplate: r,
232
- viewTemplate: T,
233
- updateTemplate: l,
234
- deleteTemplate: i,
235
- useTemplate: S,
236
- templateDialogProps: t,
237
- templateDetailsProps: p,
238
- transferFormDialogProps: a.transferDialogProps
239
- };
240
- }), $e = "use";
241
- function De() {
242
- const { t: a } = be(), { viewTemplate: n, updateTemplate: s, deleteTemplate: e, useTemplate: t } = Ae(), r = w(new Array()), l = w(new Array()), i = w(!1), p = A(), T = Q();
243
- async function S() {
244
- if (r.value = [], l.value = [], !!p._currentLocation) {
245
- i.value = !0;
246
- try {
247
- const [m, u] = await Promise.all([
248
- T.readLocationTemplates(),
249
- T.readBusinessTemplates(),
250
- new Promise((b) => setTimeout(b, 1e3))
251
- ]);
252
- r.value = m, l.value = u;
253
- } catch (m) {
254
- console.log("Something went wrong when fetching templates:", m);
255
- } finally {
256
- i.value = !1;
257
- }
258
- }
259
- }
260
- async function d(m) {
261
- if (!r.value.find((u) => u._id) && p._currentLocation) {
262
- i.value = !0;
263
- try {
264
- const [u] = await Promise.all([
265
- T.getTemplate(m).catch((b) => {
266
- if (b instanceof re && b.errorResponse.statusCode === 404)
267
- return T.getBusinessTemplate(m);
268
- throw b;
269
- }),
270
- new Promise((b) => setTimeout(b, 1e3))
271
- ]);
272
- r.value = [u];
273
- } catch (u) {
274
- console.log("Something went wrong when fetching templates:", u);
275
- } finally {
276
- i.value = !1;
277
- }
278
- }
279
- }
280
- function y(m, u) {
281
- switch (u = O(u), m) {
282
- case $e:
283
- return t(u);
284
- case C.Details:
285
- return n(u);
286
- case C.Edit:
287
- return s(u);
288
- case C.Delete:
289
- return e(u, i, S);
290
- }
291
- }
292
- const v = [
293
- {
294
- id: "_id",
295
- accessorKey: "_id",
296
- header: () => a("inventory.transfer.table.createdAt"),
297
- cell(m) {
298
- return he(`${m.getValue()}`);
299
- },
300
- enableSorting: !0
301
- },
302
- {
303
- id: "name",
304
- accessorKey: "name",
305
- header: () => a("inventory.transfer.table.name"),
306
- enableSorting: !0,
307
- size: 200
308
- },
309
- // {
310
- // id: 'supplier',
311
- // accessorKey: 'purchaseOrder.supplier.name',
312
- // header: () => t('inventory.transfer.table.transferFrom'),
313
- // enableSorting: true,
314
- // size: 200
315
- // },
316
- // {
317
- // id: 'type',
318
- // header: () => t('inventory.transfer.receiveRequest.details.type.title'),
319
- // enableSorting: true,
320
- // sortingFn(rowA, rowB) {
321
- // const typeA = getTransferType(rowA.original.purchaseOrder)
322
- // const typeB = getTransferType(rowB.original.purchaseOrder)
323
- // return typeA.localeCompare(typeB)
324
- // },
325
- // size: 200,
326
- // cell(props) {
327
- // const type = getTransferType(props.row.original.purchaseOrder)
328
- // const label = t(
329
- // `inventory.transfer.receiveRequest.details.type.${type.toLocaleLowerCase()}`
330
- // )
331
- // return h(components.FmChip, {
332
- // label: label,
333
- // class: 'fm-chip-transfer-info',
334
- // compact: true
335
- // })
336
- // }
337
- // },
338
- {
339
- id: "noOfItems",
340
- accessorKey: "purchaseOrder.items.length",
341
- header: () => a("inventory.transfer.table.noOfItems"),
342
- enableSorting: !1,
343
- meta: {
344
- width: "10rem",
345
- textAlign: "right"
346
- }
347
- },
348
- {
349
- id: "enabledLocations",
350
- accessorKey: "purchaseOrder.locations.length",
351
- header: () => "Enabled outlets",
352
- cell(m) {
353
- var b;
354
- const u = (b = m.row.original.locations) == null ? void 0 : b.length;
355
- return u ? `${u}` : "All";
356
- },
357
- enableSorting: !1,
358
- meta: {
359
- width: "10rem",
360
- textAlign: "right"
361
- }
362
- },
363
- {
364
- id: "ref",
365
- accessorKey: "purchaseOrder.ref",
366
- header: () => a("inventory.transfer.table.reference"),
367
- enableSorting: !1,
368
- size: "auto"
369
- },
370
- {
371
- id: "action",
372
- cell(m) {
373
- const u = m.row.original, b = [
374
- // {
375
- // translationKey: 'inventory.transfer.template.use',
376
- // value: useAction,
377
- // color: 'text-fm-color-typo-primary'
378
- // },
379
- M[C.Details],
380
- M[C.Edit],
381
- M[C.Delete]
382
- ];
383
- return ye(b, (F) => y(F, u));
384
- },
385
- enableSorting: !1,
386
- size: 40,
387
- meta: {
388
- cellClass: "",
389
- headerClass: ""
390
- }
391
- }
392
- ], f = L(() => [...r.value, ...l.value]);
393
- return {
394
- columnDefs: v,
395
- locationTemplates: r,
396
- businessTemplates: l,
397
- templates: f,
398
- loading: i,
399
- fetchTemplates: S,
400
- loadTemplate: d
401
- };
402
- }
403
- const _e = { class: "flex flex-col bg-white p-16 fm-corner-radius-lg gap-16" }, Ce = {
404
- key: 0,
405
- class: "flex gap-8 fm-typo-en-body-md-400 text-fm-color-typo-warning"
406
- }, Ne = { class: "flex gap-12" }, Be = /* @__PURE__ */ me({
407
- __name: "SelectTemplateDialog",
408
- emits: ["close", "update:modelValue"],
409
- setup(a, { emit: n }) {
410
- const s = n, e = w(), t = De(), r = Te(), l = A();
411
- pe(() => {
412
- t.fetchTemplates();
413
- });
414
- const i = L(() => t.loading.value), p = L(
415
- () => t.templates.value.filter(
416
- (v) => !v.locations || v.locations.find((f) => f.doc._id === l.currentLocation.doc._id)
417
- ).map((v) => ({
418
- label: v.name,
419
- value: v._id
420
- }))
421
- );
422
- function T() {
423
- s("close"), r.push({ name: oe.TRANSFER_TEMPLATE });
424
- }
425
- function S() {
426
- s("close");
427
- }
428
- function d([v]) {
429
- e.value = v;
430
- }
431
- function y() {
432
- s("update:modelValue", e.value), S();
433
- }
434
- return (v, f) => {
435
- const m = q("FmIcon"), u = q("FmButton");
436
- return E(), K("div", _e, [
437
- f[2] || (f[2] = N("div", { class: "h-32 text-fm-color-typo-primary fm-typo-en-title-md-600" }, "Select one template", -1)),
438
- I(ae, {
439
- "model-value": [e.value],
440
- "onUpdate:modelValue": d,
441
- items: p.value,
442
- loading: i.value,
443
- "no-shadow": "",
444
- "single-select": ""
445
- }, null, 8, ["model-value", "items", "loading"]),
446
- !i.value && !p.value.length ? (E(), K("div", Ce, [
447
- N("div", null, [
448
- I(m, {
449
- name: "warning",
450
- size: "sm"
451
- })
452
- ]),
453
- f[0] || (f[0] = N("div", null, "You have not configured any templates", -1))
454
- ])) : fe("", !0),
455
- N("div", Ne, [
456
- f[1] || (f[1] = N("div", { class: "flex-1" }, null, -1)),
457
- !i.value && !p.value.length ? (E(), H(u, {
458
- key: 0,
459
- label: "Create template",
460
- "prepend-icon": "add",
461
- onClick: T
462
- })) : (E(), H(u, {
463
- key: 1,
464
- loading: i.value,
465
- disabled: !e.value,
466
- label: "Use template",
467
- onClick: y
468
- }, null, 8, ["loading", "disabled"])),
469
- I(u, {
470
- label: "Close",
471
- variant: "tertiary",
472
- onClick: S
473
- })
474
- ])
475
- ]);
476
- };
477
- }
478
- });
479
- function Ue() {
480
- let a = () => {
481
- }, n = (e) => Promise.reject(e);
482
- const s = new Promise((e, t) => {
483
- a = e, n = t;
484
- });
485
- return Object.defineProperty(s, "resolve", {
486
- get() {
487
- return a;
488
- }
489
- }), Object.defineProperty(s, "reject", {
490
- get() {
491
- return n;
492
- }
493
- }), s;
494
- }
495
- const B = w();
496
- function ke(a, n) {
497
- const s = G(), e = A(), t = ue(), r = w(!1), l = J(), i = Se(), p = w(new Array()), T = w(
498
- n != null && n.startDate && (n != null && n.endDate) ? n : ve()
499
- ), S = L(() => {
500
- const c = new Date(T.value.startDate), o = new Date(T.value.endDate);
501
- return {
502
- start: ne(c).toISOString(),
503
- end: se(o).toISOString()
504
- };
505
- }), d = w(new Array()), y = ce(), v = w(null);
506
- function f() {
507
- const c = Ue();
508
- let o;
509
- return s.open({
510
- title: "Select one template",
511
- dialogComponent: Be,
512
- dialogComponentProps: {
513
- onClose() {
514
- s.close(), c.resolve(o);
515
- },
516
- "onUpdate:modelValue"(h) {
517
- o = h;
518
- }
519
- }
520
- }), c;
521
- }
522
- async function m(c) {
523
- let o;
524
- if (t.mustUsePoTemplate && !(c != null && c.template) && (o = await f(), !o))
525
- return;
526
- const h = {
527
- mode: x.CREATE,
528
- modelValue: c || void 0,
529
- show: !0,
530
- "onUpdate:show"(g) {
531
- B.value.show = g;
532
- },
533
- templateId: o,
534
- lastClosingDate: v.value
535
- };
536
- B.value = h;
537
- }
538
- function u(c) {
539
- const o = {
540
- mode: x.UPDATE,
541
- modelValue: O(c),
542
- show: !0,
543
- "onUpdate:show"(h) {
544
- B.value.show = h;
545
- },
546
- lastClosingDate: v.value
547
- };
548
- B.value = o;
549
- }
550
- async function b() {
551
- p.value = [], r.value = !0;
552
- try {
553
- p.value = await i.getPurchaseOrders(S.value).then((h) => h.sort((g, $) => $._id.localeCompare(g._id)));
554
- const c = await y.readLastClosing(!0), o = c == null ? void 0 : c._id;
555
- o && (v.value = ge(o));
556
- } catch {
557
- l.open({
558
- title: "Something went wrong",
559
- message: "Error at fetching purchase orders",
560
- type: "error"
561
- });
562
- } finally {
563
- r.value = !1;
564
- }
565
- }
566
- async function F() {
567
- d.value = [], r.value = !0;
568
- try {
569
- d.value = await i.readRequests();
570
- } catch {
571
- l.open({
572
- title: "Something went wrong",
573
- message: "Error at fetching purchase requests",
574
- type: "error"
575
- });
576
- } finally {
577
- r.value = !1;
578
- }
579
- }
580
- function U() {
581
- switch (a) {
582
- case "receive/request":
583
- return b();
584
- case "approval":
585
- return F();
586
- }
587
- }
588
- function Y(c, o) {
589
- T.value = {
590
- startDate: c,
591
- endDate: o
592
- }, U();
593
- }
594
- e.watchLocation(async (c) => {
595
- if (!c) {
596
- p.value = [];
597
- return;
598
- }
599
- await U();
600
- });
601
- const _ = w(), j = w(Math.random().toString());
602
- async function X(c, o) {
603
- var D, k;
604
- const h = Math.random().toString();
605
- j.value = h;
606
- const g = a === "receive/request" ? e.currentLocation : o == null ? void 0 : o.to, $ = {
607
- purchaseOrder: c,
608
- transferTo: g == null ? void 0 : g.name,
609
- transferToDbName: g == null ? void 0 : g.dbName,
610
- show: !0,
611
- canResubmit: !1,
612
- canApprove: a === "approval",
613
- "onUpdate:show"(R) {
614
- _.value.show = R;
615
- }
616
- };
617
- if (_.value = $, !(o || c.status !== le.enum.REQUESTING)) {
618
- try {
619
- o = (await i.readRequests(
620
- `${c.supplier.internal}_${c.supplier._id}`
621
- )).find((te) => te.purchaseOrderId === c._id);
622
- } catch {
623
- console.error("Error at fetching po request to check");
624
- }
625
- h === j.value && (_.value.canResubmit = !o, _.value.transferTo = (D = o == null ? void 0 : o.to) == null ? void 0 : D.name, _.value.transferToDbName = (k = o == null ? void 0 : o.to) == null ? void 0 : k.dbName);
626
- }
627
- }
628
- async function Z(c, o, h, g) {
629
- r.value = !0;
630
- try {
631
- await i.processPurchaseOrder(
632
- {
633
- operation: o,
634
- doc: c,
635
- options: (
636
- // auto receive for supplier to warehouse
637
- (o === P.enum.confirmDraft || // auto receive for warehouse to warehouse
638
- o === P.enum.completeReceive) && t.autoReceiveWarehouse ? {
639
- autoReceive: !0
640
- } : void 0
641
- )
642
- },
643
- g
644
- ), await new Promise((k) => setTimeout(k, 1e3));
645
- const D = A().currentLocationDBName.startsWith("restaurant_");
646
- o === P.enum.confirmDraft && c.effectiveAt && D ? l.open({
647
- title: "Success",
648
- message: `${h}. The backdate will be reflected once your POS has received this change.`,
649
- type: "success"
650
- }) : l.open({
651
- title: "Success",
652
- message: h,
653
- type: "success"
654
- });
655
- } catch ($) {
656
- l.open({
657
- title: "Something went wrong",
658
- message: "Please try again.",
659
- type: "error"
660
- }), console.error("Error when submitting PO operation", o, c, $);
661
- } finally {
662
- r.value = !1, U();
663
- }
664
- }
665
- async function ee(c, o, h) {
666
- const g = Pe[o];
667
- if (!g) {
668
- l.open({
669
- title: "Something went wrong",
670
- message: `Cannot process order: ${ie(o)}`,
671
- type: "error"
672
- });
673
- return;
674
- }
675
- const { successMessage: $, ...D } = g;
676
- s.open({
677
- title: D.title,
678
- message: D.message,
679
- primaryActions: D.primaryActions
680
- }).onPrimary(() => {
681
- Z(c, o, $, h);
682
- });
683
- }
684
- return {
685
- purchaseOrders: p,
686
- purchaseRequests: d,
687
- updateDateRange: Y,
688
- fetchData: U,
689
- loading: r,
690
- transferDialogProps: B,
691
- promptCreateTransferDialog: m,
692
- promptUpdateTransferDialog: u,
693
- transferDetailsProps: _,
694
- promptShowTransferDetails: X,
695
- submitAction: ee
696
- };
697
- }
698
- function Ke(a, n, s) {
699
- const e = (s == null ? void 0 : s.abbrev) ?? n.abbrev;
700
- return `${de(a, !1)} ${e}`;
701
- }
702
- var Ee = /* @__PURE__ */ ((a) => (a.PURCHASE = "PURCHASE", a.TRANSFER = "TRANSFER", a))(Ee || {});
703
- export {
704
- Ee as P,
705
- Q as a,
706
- Ae as b,
707
- De as c,
708
- Se as d,
709
- Pe as e,
710
- Ke as f,
711
- ke as u
712
- };