@feedmepos/mf-inventory-portal 0.0.22-dev.7 → 0.0.22-dev.9

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 (60) hide show
  1. package/dist/{ApprovalView-B9s4exkr.js → ApprovalView-BPsScR5_.js} +4 -4
  2. package/dist/{BindingsDialog-uksEDFFX.js → BindingsDialog-GzX9Bo2g.js} +1 -1
  3. package/dist/{BindingsPicker-B2rQ9kJH.js → BindingsPicker-SbOetc0-.js} +19 -19
  4. package/dist/{BindingsTable-BLN_bAjO.js → BindingsTable-CAcE5y8U.js} +1 -1
  5. package/dist/{ClosingTemplateView-Bi06Gxzo.js → ClosingTemplateView-DECwEnlK.js} +91 -90
  6. package/dist/{FmInventoryTableToolbar.vue_vue_type_script_setup_true_lang-CeBoTYGq.js → FmInventoryTableToolbar.vue_vue_type_script_setup_true_lang-DnogYrRE.js} +1 -1
  7. package/dist/{IngredientsView-DY6yY-Fk.js → IngredientsView-8fT1Ljd5.js} +3 -3
  8. package/dist/{IntegrationView-C74CJ4PS.js → IntegrationView-CjGLRM78.js} +2 -2
  9. package/dist/{NumberPrecisionInput.vue_vue_type_script_setup_true_lang-BmsbeAvi.js → NumberPrecisionInput.vue_vue_type_script_setup_true_lang-1FCwvO8A.js} +1 -1
  10. package/dist/{PremiumBadge.vue_vue_type_script_setup_true_lang-RoZStI7P.js → PremiumBadge.vue_vue_type_script_setup_true_lang-DlhNc8Vk.js} +1 -1
  11. package/dist/{PurchaseOrderPrintPreview-Dn5CQDnd.js → PurchaseOrderPrintPreview-5HIWHR_f.js} +1 -1
  12. package/dist/{ReceiveRequestView-BC61WMFL.js → ReceiveRequestView-CXZv8g5U.js} +6 -6
  13. package/dist/{RecipeView-DYbuUEFK.js → RecipeView-sB0Lgmob.js} +3 -3
  14. package/dist/{StockView-D_ZzX7yp.js → StockView-CY2kNohB.js} +6 -6
  15. package/dist/{SupplierView-ChewCZKN.js → SupplierView-DTqeZPts.js} +37 -37
  16. package/dist/TransferDetails.vue_vue_type_script_setup_true_lang-BBby29tW.js +762 -0
  17. package/dist/TransferDialog.vue_vue_type_script_setup_true_lang-ByNQap9n.js +1498 -0
  18. package/dist/TransferTemplateView-DkRVfAox.js +1277 -0
  19. package/dist/{UnitView-Cx1xe3Wg.js → UnitView-BpU0Yk7X.js} +4 -4
  20. package/dist/{WarehouseView-CQQf0YFc.js → WarehouseView-DqxWgogc.js} +2 -2
  21. package/dist/api/inventory.d.ts +5 -7
  22. package/dist/api/netsuite.d.ts +40 -0
  23. package/dist/api/purchase-order-template.d.ts +0 -4
  24. package/dist/{app-emo4vLKK.js → app-BuyAj4kw.js} +11903 -11636
  25. package/dist/app.d.ts +6 -0
  26. package/dist/app.js +3 -3
  27. package/dist/{decimal-BO9I7LUt.js → decimal-DWbwRn_v.js} +1 -1
  28. package/dist/{defineDeepModel-D06lO_R2.js → defineDeepModel-DuVmbMwq.js} +4 -4
  29. package/dist/{format-time-from-id-HTOA-soi.js → format-time-from-id-BnmaRuab.js} +1 -1
  30. package/dist/{id-to-date-DAnKDcfC.js → id-to-date-CI5Vv0Ji.js} +1 -1
  31. package/dist/purchase-order-transaction-type-DrFJFvtK.js +676 -0
  32. package/dist/stores/api.d.ts +1 -0
  33. package/dist/stores/feature.d.ts +0 -1
  34. package/dist/stores/helper/core-store-proxy.d.ts +3 -0
  35. package/dist/stores/helper/generate-backend-urls.d.ts +1 -0
  36. package/dist/stores/location.d.ts +24 -42
  37. package/dist/stores/netsuite.d.ts +49 -0
  38. package/dist/stores/warehouse.d.ts +4 -7
  39. package/dist/style.css +1 -1
  40. package/dist/{supplier-CBf_J6D6.js → supplier-BQyK2eSZ.js} +1 -1
  41. package/dist/tsconfig.app.tsbuildinfo +1 -1
  42. package/dist/{use-template-enabled-locations-2-Bo3g55rA.js → use-template-enabled-locations-2-ClBq9FjN.js} +1 -1
  43. package/dist/views/closing-template/composables/use-closing-template-actions.d.ts +48 -84
  44. package/dist/views/closing-template/composables/use-closing-template-table.d.ts +48 -84
  45. package/dist/views/receive-request/components/transfer-form/TransferForm.vue.d.ts +14 -0
  46. package/dist/views/receive-request/composables/use-receive-request-form.d.ts +42 -0
  47. package/dist/views/receive-request/composables/use-receive-request-table.d.ts +42 -0
  48. package/dist/views/transfer-template/components/transfer-template-form/composables/use-template-enabled-locations.d.ts +4 -7
  49. package/dist/views/transfer-template/components/transfer-template-form/composables/use-transfer-locations.d.ts +2 -2
  50. package/dist/views/transfer-template/composables/use-transfer-template-actions.d.ts +132 -84
  51. package/dist/views/transfer-template/composables/use-transfer-template-table.d.ts +44 -1014
  52. package/dist/views/transfer-template/helpers/remove-deleted-skus.helper.d.ts +11 -7
  53. package/dist/views/warehouse/components/WarehouseForm.vue.d.ts +8 -14
  54. package/dist/{xlsx-DX8dk9eD.js → xlsx-DiOKvJ6l.js} +1 -1
  55. package/dist/{xlsx.util-BaeMOrlY.js → xlsx.util-CZ7zYxdP.js} +2 -2
  56. package/package.json +5 -5
  57. package/dist/TransferDetails.vue_vue_type_script_setup_true_lang-CXmk2PYd.js +0 -740
  58. package/dist/TransferDialog.vue_vue_type_script_setup_true_lang-D9XERa2u.js +0 -1409
  59. package/dist/TransferTemplateView-BIsn4jRY.js +0 -1238
  60. package/dist/purchase-order-transaction-type-73S8OLUt.js +0 -702
@@ -1,702 +0,0 @@
1
- import { n as Q, j as D, ai as A, c as E, u as Y, S as se, y as ce, a8 as le, J as ie, K as ue, aj as de, ae as me, w as pe, b as fe, a as ve } from "./app-emo4vLKK.js";
2
- import { ref as w, computed as x, h as R, defineComponent as he, onMounted as ge, resolveComponent as K, openBlock as L, createElementBlock as z, createElementVNode as U, createVNode as M, createCommentVNode as ye, createBlock as H } from "vue";
3
- import { i as be } from "./FmInventoryTableToolbar.vue_vue_type_script_setup_true_lang-CeBoTYGq.js";
4
- import { F, D as j, R as B } from "./row-action.enum-PMKMRrZR.js";
5
- import { useDialog as X, useSnackbar as Z, FmButtonVariant as W, components as G } from "@feedmepos/ui-library";
6
- import { f as we, p as Te } from "./format-time-from-id-HTOA-soi.js";
7
- import { c as Se } from "./TableActionableRow.vue_vue_type_script_setup_true_lang-DlNJ6kRg.js";
8
- import { useCoreStore as V, useI18n as Pe } from "@feedmepos/mf-common";
9
- import { defineStore as Ae } from "pinia";
10
- import { useRouter as De } from "vue-router";
11
- const $e = Q((a, n) => {
12
- const s = D();
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
- }), _e = {
43
- [A.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
- [A.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
- [A.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
- [A.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
- [A.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
- [A.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
- }, ee = Q((a, n) => {
100
- function s() {
101
- var p;
102
- const e = V(), t = D(), 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 = D().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 = D().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
- }), Ce = Ae("transferTemplateActions", () => {
146
- const a = xe("receive/request"), n = X(), s = Z(), e = ee(), t = w({});
147
- function r() {
148
- t.value = {
149
- mode: F.CREATE,
150
- show: !0,
151
- "onUpdate:show"(u) {
152
- t.value.show = u;
153
- }
154
- };
155
- }
156
- function l(u) {
157
- t.value = {
158
- mode: F.UPDATE,
159
- modelValue: u,
160
- show: !0,
161
- "onUpdate:show"(y) {
162
- t.value.show = y;
163
- }
164
- };
165
- }
166
- function i(u, y, v) {
167
- n.open({
168
- title: `Confirm deleting template ${u.name}?`,
169
- message: "Deleted template can no longer be retrieved",
170
- primaryActions: {
171
- text: "Delete",
172
- variant: W.Destructive,
173
- close: !0
174
- },
175
- secondaryActions: {
176
- text: "Cancel",
177
- variant: W.Plain,
178
- close: !0
179
- }
180
- }).onPrimary(async () => {
181
- s.open({
182
- title: `Deleting ${u.name}`,
183
- type: "info"
184
- });
185
- try {
186
- y.value = !0;
187
- const [f] = await Promise.allSettled([
188
- e.deleteTemplate(u),
189
- new Promise((P) => setTimeout(P, 1e3))
190
- ]);
191
- if (f.status === "rejected") throw f.reason;
192
- s.open({
193
- title: `Deleted ${u.name}`,
194
- type: "success"
195
- });
196
- } catch (f) {
197
- s.open({
198
- title: `Unable to delete ${u.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(u) {
209
- p.value = {
210
- template: u,
211
- show: !0,
212
- "onUpdate:show"(y) {
213
- p.value.show = y;
214
- },
215
- "onAction:edit"() {
216
- p.value.show = !1, l(E(u));
217
- },
218
- "onAction:use"(y) {
219
- const v = D(), f = v.locations.find((P) => P.doc._id === y);
220
- v.selectLocation(f), p.value.show = !1, S(E(u));
221
- }
222
- };
223
- }
224
- function S(u) {
225
- a.promptCreateTransferDialog({
226
- ...u.purchaseOrder,
227
- template: u._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
- });
241
- function J(a) {
242
- const { skuById: n } = Y(), s = E(a);
243
- return s.purchaseOrder.items = a.purchaseOrder.items.filter((e) => n[e.sku._id]), s;
244
- }
245
- const Ne = "use";
246
- function Be() {
247
- const { t: a } = Pe(), { viewTemplate: n, updateTemplate: s, deleteTemplate: e, useTemplate: t } = Ce(), r = w(new Array()), l = w(new Array()), i = w(!1), p = D(), T = ee(), S = Y();
248
- async function u() {
249
- if (r.value = [], l.value = [], !!p._currentLocation) {
250
- i.value = !0;
251
- try {
252
- const [m, d] = await Promise.all([
253
- T.readLocationTemplates(),
254
- T.readBusinessTemplates(),
255
- S.readInventory(),
256
- new Promise((b) => setTimeout(b, 1e3))
257
- ]);
258
- r.value = m.map(J), l.value = d.map(J);
259
- } catch (m) {
260
- console.log("Something went wrong when fetching templates:", m);
261
- } finally {
262
- i.value = !1;
263
- }
264
- }
265
- }
266
- async function y(m) {
267
- if (!r.value.find((d) => d._id) && p._currentLocation) {
268
- i.value = !0;
269
- try {
270
- const [d] = await Promise.all([
271
- T.getTemplate(m).catch((b) => {
272
- if (b instanceof se && b.errorResponse.statusCode === 404)
273
- return T.getBusinessTemplate(m);
274
- throw b;
275
- }),
276
- new Promise((b) => setTimeout(b, 1e3))
277
- ]);
278
- r.value = [d];
279
- } catch (d) {
280
- console.log("Something went wrong when fetching templates:", d);
281
- } finally {
282
- i.value = !1;
283
- }
284
- }
285
- }
286
- function v(m, d) {
287
- switch (d = E(d), m) {
288
- case Ne:
289
- return t(d);
290
- case B.Details:
291
- return n(d);
292
- case B.Edit:
293
- return s(d);
294
- case B.Delete:
295
- return e(d, i, u);
296
- }
297
- }
298
- const f = [
299
- {
300
- id: "_id",
301
- accessorKey: "_id",
302
- header: () => a("inventory.transfer.table.createdAt"),
303
- cell(m) {
304
- return we(`${m.getValue()}`);
305
- },
306
- enableSorting: !0
307
- },
308
- {
309
- id: "name",
310
- accessorKey: "name",
311
- header: () => a("inventory.transfer.table.name"),
312
- enableSorting: !0,
313
- size: 200
314
- },
315
- {
316
- id: "noOfItems",
317
- accessorKey: "purchaseOrder.items.length",
318
- header: () => a("inventory.transfer.table.noOfItems"),
319
- enableSorting: !1,
320
- meta: {
321
- width: "10rem",
322
- textAlign: "right"
323
- },
324
- cell(m) {
325
- const d = Number(m.getValue()) || 0;
326
- return d === 0 ? R("div", { class: "flex justify-end gap-4 items-center" }, [
327
- R(
328
- G.FmTooltip,
329
- {},
330
- {
331
- content() {
332
- return "The template is invalid due to deleted ingredients. Please update this template.";
333
- },
334
- default() {
335
- return R(G.FmIcon, { name: "error", color: "system-error-300", size: "sm" });
336
- }
337
- }
338
- ),
339
- d
340
- ]) : d;
341
- }
342
- },
343
- {
344
- id: "enabledLocations",
345
- accessorKey: "purchaseOrder.locations.length",
346
- header: () => "Enabled outlets",
347
- cell(m) {
348
- var b;
349
- const d = (b = m.row.original.locations) == null ? void 0 : b.length;
350
- return d ? `${d}` : "All";
351
- },
352
- enableSorting: !1,
353
- meta: {
354
- width: "10rem",
355
- textAlign: "right"
356
- }
357
- },
358
- {
359
- id: "ref",
360
- accessorKey: "purchaseOrder.ref",
361
- header: () => a("inventory.transfer.table.reference"),
362
- enableSorting: !1,
363
- size: "auto"
364
- },
365
- {
366
- id: "action",
367
- cell(m) {
368
- const d = m.row.original, b = [
369
- j[B.Details],
370
- j[B.Edit],
371
- j[B.Delete]
372
- ];
373
- return Se(b, (C) => v(C, d));
374
- },
375
- enableSorting: !1,
376
- size: 40,
377
- meta: {
378
- cellClass: "",
379
- headerClass: ""
380
- }
381
- }
382
- ], P = x(() => [...r.value, ...l.value]);
383
- return {
384
- columnDefs: f,
385
- locationTemplates: r,
386
- businessTemplates: l,
387
- templates: P,
388
- loading: i,
389
- fetchTemplates: u,
390
- loadTemplate: y
391
- };
392
- }
393
- const Ue = { class: "flex flex-col bg-white p-16 fm-corner-radius-lg gap-16" }, ke = {
394
- key: 0,
395
- class: "flex gap-8 fm-typo-en-body-md-400 text-fm-color-typo-warning"
396
- }, Ee = { class: "flex gap-12" }, Oe = /* @__PURE__ */ he({
397
- __name: "SelectTemplateDialog",
398
- emits: ["close", "update:modelValue"],
399
- setup(a, { emit: n }) {
400
- const s = n, e = w(), t = Be(), r = De(), l = D();
401
- ge(() => {
402
- t.fetchTemplates();
403
- });
404
- const i = x(() => t.loading.value), p = x(
405
- () => t.templates.value.filter(
406
- (v) => !v.locations || v.locations.find((f) => f.doc._id === l.currentLocation.doc._id)
407
- ).map((v) => ({
408
- label: v.name,
409
- value: v._id
410
- }))
411
- );
412
- function T() {
413
- s("close"), r.push({ name: le.TRANSFER_TEMPLATE });
414
- }
415
- function S() {
416
- s("close");
417
- }
418
- function u([v]) {
419
- e.value = v;
420
- }
421
- function y() {
422
- s("update:modelValue", e.value), S();
423
- }
424
- return (v, f) => {
425
- const P = K("FmIcon"), m = K("FmButton");
426
- return L(), z("div", Ue, [
427
- f[2] || (f[2] = U("div", { class: "h-32 text-fm-color-typo-primary fm-typo-en-title-md-600" }, "Select one template", -1)),
428
- M(ce, {
429
- "model-value": [e.value],
430
- "onUpdate:modelValue": u,
431
- items: p.value,
432
- loading: i.value,
433
- "no-shadow": "",
434
- "single-select": ""
435
- }, null, 8, ["model-value", "items", "loading"]),
436
- !i.value && !p.value.length ? (L(), z("div", ke, [
437
- U("div", null, [
438
- M(P, {
439
- name: "warning",
440
- size: "sm"
441
- })
442
- ]),
443
- f[0] || (f[0] = U("div", null, "You have not configured any templates", -1))
444
- ])) : ye("", !0),
445
- U("div", Ee, [
446
- f[1] || (f[1] = U("div", { class: "flex-1" }, null, -1)),
447
- !i.value && !p.value.length ? (L(), H(m, {
448
- key: 0,
449
- label: "Create template",
450
- "prepend-icon": "add",
451
- onClick: T
452
- })) : (L(), H(m, {
453
- key: 1,
454
- loading: i.value,
455
- disabled: !e.value,
456
- label: "Use template",
457
- onClick: y
458
- }, null, 8, ["loading", "disabled"])),
459
- M(m, {
460
- label: "Close",
461
- variant: "tertiary",
462
- onClick: S
463
- })
464
- ])
465
- ]);
466
- };
467
- }
468
- });
469
- function Le() {
470
- let a = () => {
471
- }, n = (e) => Promise.reject(e);
472
- const s = new Promise((e, t) => {
473
- a = e, n = t;
474
- });
475
- return Object.defineProperty(s, "resolve", {
476
- get() {
477
- return a;
478
- }
479
- }), Object.defineProperty(s, "reject", {
480
- get() {
481
- return n;
482
- }
483
- }), s;
484
- }
485
- const k = w();
486
- function xe(a, n) {
487
- const s = X(), e = D(), t = fe(), r = w(!1), l = Z(), i = $e(), p = w(new Array()), T = w(
488
- n != null && n.startDate && (n != null && n.endDate) ? n : be()
489
- ), S = x(() => {
490
- const c = new Date(T.value.startDate), o = new Date(T.value.endDate);
491
- return {
492
- start: ie(c).toISOString(),
493
- end: ue(o).toISOString()
494
- };
495
- }), u = w(new Array()), y = de(), v = w(null);
496
- function f() {
497
- const c = Le();
498
- let o;
499
- return s.open({
500
- title: "Select one template",
501
- dialogComponent: Oe,
502
- dialogComponentProps: {
503
- onClose() {
504
- s.close(), c.resolve(o);
505
- },
506
- "onUpdate:modelValue"(h) {
507
- o = h;
508
- }
509
- }
510
- }), c;
511
- }
512
- async function P(c) {
513
- let o;
514
- if (t.mustUsePoTemplate && !(c != null && c.template) && (o = await f(), !o))
515
- return;
516
- const h = {
517
- mode: F.CREATE,
518
- modelValue: c || void 0,
519
- show: !0,
520
- "onUpdate:show"(g) {
521
- k.value.show = g;
522
- },
523
- templateId: o,
524
- lastClosingDate: v.value
525
- };
526
- k.value = h;
527
- }
528
- function m(c) {
529
- const o = {
530
- mode: F.UPDATE,
531
- modelValue: E(c),
532
- show: !0,
533
- "onUpdate:show"(h) {
534
- k.value.show = h;
535
- },
536
- lastClosingDate: v.value
537
- };
538
- k.value = o;
539
- }
540
- async function d() {
541
- p.value = [], r.value = !0;
542
- try {
543
- p.value = await i.getPurchaseOrders(S.value).then((h) => h.sort((g, $) => $._id.localeCompare(g._id)));
544
- const c = await y.readLastClosing(!0), o = c == null ? void 0 : c._id;
545
- o && (v.value = Te(o));
546
- } catch {
547
- l.open({
548
- title: "Something went wrong",
549
- message: "Error at fetching purchase orders",
550
- type: "error"
551
- });
552
- } finally {
553
- r.value = !1;
554
- }
555
- }
556
- async function b() {
557
- u.value = [], r.value = !0;
558
- try {
559
- u.value = await i.readRequests();
560
- } catch {
561
- l.open({
562
- title: "Something went wrong",
563
- message: "Error at fetching purchase requests",
564
- type: "error"
565
- });
566
- } finally {
567
- r.value = !1;
568
- }
569
- }
570
- function C() {
571
- switch (a) {
572
- case "receive/request":
573
- return d();
574
- case "approval":
575
- return b();
576
- }
577
- }
578
- function te(c, o) {
579
- T.value = {
580
- startDate: c,
581
- endDate: o
582
- }, C();
583
- }
584
- e.watchLocation(async (c) => {
585
- if (!c) {
586
- p.value = [];
587
- return;
588
- }
589
- await C();
590
- });
591
- const N = w(), q = w(Math.random().toString());
592
- async function re(c, o) {
593
- var _, O;
594
- const h = Math.random().toString();
595
- q.value = h;
596
- const g = a === "receive/request" ? e.currentLocation : o == null ? void 0 : o.to, $ = {
597
- purchaseOrder: c,
598
- transferTo: g == null ? void 0 : g.name,
599
- transferToDbName: g == null ? void 0 : g.dbName,
600
- show: !0,
601
- canResubmit: !1,
602
- canApprove: a === "approval",
603
- "onUpdate:show"(I) {
604
- N.value.show = I;
605
- }
606
- };
607
- if (N.value = $, !(o || c.status !== me.enum.REQUESTING)) {
608
- try {
609
- o = (await i.readRequests(
610
- `${c.supplier.internal}_${c.supplier._id}`
611
- )).find((ne) => ne.purchaseOrderId === c._id);
612
- } catch {
613
- console.error("Error at fetching po request to check");
614
- }
615
- h === q.value && (N.value.canResubmit = !o, N.value.transferTo = (_ = o == null ? void 0 : o.to) == null ? void 0 : _.name, N.value.transferToDbName = (O = o == null ? void 0 : o.to) == null ? void 0 : O.dbName);
616
- }
617
- }
618
- async function ae(c, o, h, g) {
619
- r.value = !0;
620
- try {
621
- await i.processPurchaseOrder(
622
- {
623
- operation: o,
624
- doc: c,
625
- options: (
626
- // auto receive for supplier to warehouse
627
- (o === A.enum.confirmDraft || // auto receive for warehouse to warehouse
628
- o === A.enum.completeReceive) && t.autoReceiveWarehouse ? {
629
- autoReceive: !0
630
- } : void 0
631
- )
632
- },
633
- g
634
- ), await new Promise((O) => setTimeout(O, 1e3));
635
- const _ = D().currentLocationDBName.startsWith("restaurant_");
636
- o === A.enum.confirmDraft && c.effectiveAt && _ ? l.open({
637
- title: "Success",
638
- message: `${h}. The backdate will be reflected once your POS has received this change.`,
639
- type: "success"
640
- }) : l.open({
641
- title: "Success",
642
- message: h,
643
- type: "success"
644
- });
645
- } catch ($) {
646
- l.open({
647
- title: "Something went wrong",
648
- message: "Please try again.",
649
- type: "error"
650
- }), console.error("Error when submitting PO operation", o, c, $);
651
- } finally {
652
- r.value = !1, C();
653
- }
654
- }
655
- async function oe(c, o, h) {
656
- const g = _e[o];
657
- if (!g) {
658
- l.open({
659
- title: "Something went wrong",
660
- message: `Cannot process order: ${pe(o)}`,
661
- type: "error"
662
- });
663
- return;
664
- }
665
- const { successMessage: $, ..._ } = g;
666
- s.open({
667
- title: _.title,
668
- message: _.message,
669
- primaryActions: _.primaryActions
670
- }).onPrimary(() => {
671
- ae(c, o, $, h);
672
- });
673
- }
674
- return {
675
- purchaseOrders: p,
676
- purchaseRequests: u,
677
- updateDateRange: te,
678
- fetchData: C,
679
- loading: r,
680
- transferDialogProps: k,
681
- promptCreateTransferDialog: P,
682
- promptUpdateTransferDialog: m,
683
- transferDetailsProps: N,
684
- promptShowTransferDetails: re,
685
- submitAction: oe
686
- };
687
- }
688
- function Ge(a, n, s) {
689
- const e = (s == null ? void 0 : s.abbrev) ?? n.abbrev;
690
- return `${ve(a, !1)} ${e}`;
691
- }
692
- var Fe = /* @__PURE__ */ ((a) => (a.PURCHASE = "PURCHASE", a.TRANSFER = "TRANSFER", a))(Fe || {});
693
- export {
694
- Fe as P,
695
- ee as a,
696
- Ce as b,
697
- Be as c,
698
- $e as d,
699
- _e as e,
700
- Ge as f,
701
- xe as u
702
- };