@feedmepos/mf-inventory-portal 0.0.23-dev.28 → 0.0.23-dev.3

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 (114) hide show
  1. package/dist/{App-DRBjtrVV.js → App-BREfwtck.js} +73 -85
  2. package/dist/{ApprovalView-OzaufzMA.js → ApprovalView-DCzLx24G.js} +27 -24
  3. package/dist/{BindingsDialog-DQwWNg1N.js → BindingsDialog-CUcC8lue.js} +4 -4
  4. package/dist/{BindingsPicker-DSYOkBTy.js → BindingsPicker-3VOdZBWI.js} +9 -8
  5. package/dist/{BindingsTable-BB39IdFU.js → BindingsTable-D5Lt6GOO.js} +22 -18
  6. package/dist/{ClosingTemplateView-Dk5TTe31.js → ClosingTemplateView-CukthwOo.js} +286 -272
  7. package/dist/FmDroppableField-8RzKjEdL.js +154 -0
  8. package/dist/FmFilterableMenuOptions.vue_vue_type_script_setup_true_lang-Dwb3eBLo.js +267 -0
  9. package/dist/FmInventoryTableToolbar.vue_vue_type_script_setup_true_lang-CvtvzIt1.js +436 -0
  10. package/dist/FmMultiselectDialog-CKBcMDGC.js +415 -0
  11. package/dist/{FmUnitInput.vue_vue_type_script_setup_true_lang-qqudhwEN.js → FmUnitInput.vue_vue_type_script_setup_true_lang-DigsIOB0.js} +114 -116
  12. package/dist/{IngredientBindedItem.vue_vue_type_script_setup_true_lang-g1RpNK-0.js → IngredientBindedItem.vue_vue_type_script_setup_true_lang-DweLQVwq.js} +5 -5
  13. package/dist/{IngredientGroupView-CREz-Vh2.js → IngredientGroupView-CkD8x2CP.js} +69 -63
  14. package/dist/IngredientsView-DuK4YSD6.js +1613 -0
  15. package/dist/{IntegrationView-3cA_x_gB.js → IntegrationView-BfeV07OO.js} +95 -92
  16. package/dist/{InventoryBindingForm-DDS19Q0p.js → InventoryBindingForm-BsSmth0U.js} +1 -1
  17. package/dist/{InventoryBindingForm.vue_vue_type_script_setup_true_lang-5elMjhnH.js → InventoryBindingForm.vue_vue_type_script_setup_true_lang-CMV5e99K.js} +27 -25
  18. package/dist/{InventoryBindingSummary-HSClvlZ5.js → InventoryBindingSummary-BHloDawE.js} +1 -1
  19. package/dist/{NumberPrecisionInput.vue_vue_type_script_setup_true_lang-ni8Q5uWj.js → NumberPrecisionInput.vue_vue_type_script_setup_true_lang-BjddpTCS.js} +1 -1
  20. package/dist/{PremiumBadge.vue_vue_type_script_setup_true_lang-ClmXXhpb.js → PremiumBadge.vue_vue_type_script_setup_true_lang-BZBa_99i.js} +24 -23
  21. package/dist/{PurchaseOrderPrintPreview-wKM6u0Ci.js → PurchaseOrderPrintPreview-CTdd-RuH.js} +14 -13
  22. package/dist/ReceiveRequestView-CgWNaYs1.js +4104 -0
  23. package/dist/{RecipeView-DJzDyKB5.js → RecipeView-CrmDQdc5.js} +85 -79
  24. package/dist/{StockView-DO4ys9XN.js → StockView-Xb3fQaiD.js} +1446 -1338
  25. package/dist/{SupplierView-BIJkWdt4.js → SupplierView-CrtIiaz0.js} +787 -2325
  26. package/dist/TableActionableRow.vue_vue_type_script_setup_true_lang-DlNJ6kRg.js +135 -0
  27. package/dist/TransferDetails.vue_vue_type_script_setup_true_lang-C9H41eg7.js +1189 -0
  28. package/dist/TransferTemplateView-Cc7VRbZ7.js +1262 -0
  29. package/dist/{UnitView-DJoSWs6g.js → UnitView-C6BgrZ1G.js} +44 -40
  30. package/dist/{WarehouseView-C8YZTOZd.js → WarehouseView-Hhd76ybU.js} +100 -94
  31. package/dist/_plugin-vue_export-helper-CHgC5LLL.js +9 -0
  32. package/dist/api/bill.d.ts +2 -2
  33. package/dist/api/closing.d.ts +0 -1
  34. package/dist/api/netsuite.d.ts +1 -1
  35. package/dist/app-CwUHqg7h.js +33462 -0
  36. package/dist/app.d.ts +0 -56
  37. package/dist/app.js +2 -2
  38. package/dist/components/FmMinMaxInputRules.d.ts +1 -4
  39. package/dist/components/FmMultiselectDialogProps.d.ts +0 -1
  40. package/dist/components/row-action.enum.d.ts +0 -1
  41. package/dist/composable/defineDeepModel.d.ts +1 -1
  42. package/dist/date2-CHNm4ELK.js +117 -0
  43. package/dist/dayjs.min-FE3dpxHU.js +282 -0
  44. package/dist/{decimal-0QwuGxcA.js → decimal-rPKr5T-H.js} +1 -1
  45. package/dist/defineDeepModel-Dc1zZzOi.js +13 -0
  46. package/dist/{feature-Q0gPMHLe.js → feature-z95vJnA1.js} +9 -23
  47. package/dist/format-time-from-id-CaPj8EHN.js +15 -0
  48. package/dist/format-unit-display-Bkz5kW6p.js +1198 -0
  49. package/dist/fuzzy-DXqhGaFi.js +41 -0
  50. package/dist/index-BMJHz32O.js +22277 -0
  51. package/dist/index-Be5vGZdr.js +45 -0
  52. package/dist/index-D2juQPg6.js +10545 -0
  53. package/dist/netsuite-P0as0Moa.js +194 -0
  54. package/dist/normalizeArguments-DP7Hrren.js +1552 -0
  55. package/dist/router/name.d.ts +0 -2
  56. package/dist/row-action.enum-PMKMRrZR.js +50 -0
  57. package/dist/rules-BQz4NGht.js +198 -0
  58. package/dist/stores/feature.d.ts +0 -2
  59. package/dist/stores/integration/netsuite.d.ts +1 -69
  60. package/dist/stores/inventory.d.ts +4 -1
  61. package/dist/style.css +1 -1
  62. package/dist/{supplier-xeNz-LFV.js → supplier-BixmjZyl.js} +15 -15
  63. package/dist/tsconfig.app.tsbuildinfo +1 -1
  64. package/dist/{use-inventory-binding-dialog-WCVWoWcc.js → use-inventory-binding-dialog-BRygbm1p.js} +11 -10
  65. package/dist/use-template-enabled-locations-2-Dd15d-ng.js +86 -0
  66. package/dist/views/closing-template/composables/use-closing-template-actions.d.ts +192 -24
  67. package/dist/views/closing-template/composables/use-closing-template-table.d.ts +193 -25
  68. package/dist/views/receive-request/components/transfer-form/TransferForm.vue.d.ts +34 -34
  69. package/dist/views/receive-request/components/transfer-form/composables/use-transfer-items.d.ts +0 -1
  70. package/dist/views/receive-request/composables/use-receive-request-form.d.ts +54 -54
  71. package/dist/views/receive-request/composables/use-receive-request-table.d.ts +54 -54
  72. package/dist/views/stock/components/StockRecordCard.vue.d.ts +1 -1
  73. package/dist/views/stock/components/dialog/AdjustedItemForm.vue.d.ts +2 -2
  74. package/dist/views/stock/helper/compute-summary-total.d.ts +2 -2
  75. package/dist/views/transfer-template/components/transfer-template-form/composables/use-transfer-template-items.d.ts +8 -8
  76. package/dist/views/transfer-template/composables/use-transfer-template-actions.d.ts +96 -96
  77. package/dist/views/transfer-template/composables/use-transfer-template-table.d.ts +96 -96
  78. package/dist/xlsx-k2Rf0NcF.js +24004 -0
  79. package/dist/xlsx.util-CJxPf7XZ.js +78 -0
  80. package/package.json +2 -2
  81. package/dist/ClosingDraftView-CF3wn51T.js +0 -1190
  82. package/dist/FmFilterableMenuOptions.vue_vue_type_script_setup_true_lang-vvfsYTGA.js +0 -282
  83. package/dist/IngredientsView-DzI9vr-u.js +0 -1657
  84. package/dist/ReceiveRequestView-CTk9r1bA.js +0 -4188
  85. package/dist/TransferDetails.vue_vue_type_script_setup_true_lang-KSBV1U_z.js +0 -1227
  86. package/dist/TransferTemplateView-CDUNWRLQ.js +0 -1264
  87. package/dist/api/adjustment-template.d.ts +0 -23
  88. package/dist/api/closing-draft.d.ts +0 -6
  89. package/dist/app-CYk4J4VK.js +0 -84180
  90. package/dist/format-unit-display-BIMHakYl.js +0 -1207
  91. package/dist/index-BQjj0Tdx.js +0 -12087
  92. package/dist/stock-ahRK16Qq.js +0 -110
  93. package/dist/views/adjustment-template/import/AdjustmentTemplateImport.vue.d.ts +0 -2
  94. package/dist/views/adjustment-template/import/AdjustmentTemplateImportItem.vue.d.ts +0 -18
  95. package/dist/views/adjustment-template/import/export.d.ts +0 -60
  96. package/dist/views/adjustment-template/wastage-template/WastageTemplateDetails.vue.d.ts +0 -2
  97. package/dist/views/adjustment-template/wastage-template/WastageTemplateDialog.vue.d.ts +0 -22
  98. package/dist/views/adjustment-template/wastage-template/WastageTemplatePublish.vue.d.ts +0 -6
  99. package/dist/views/adjustment-template/wastage-template/WastageTemplateView.vue.d.ts +0 -2
  100. package/dist/views/adjustment-template/wastage-template/actions.d.ts +0 -1295
  101. package/dist/views/adjustment-template/wastage-template/form/WastageTemplateForm.vue.d.ts +0 -16
  102. package/dist/views/adjustment-template/wastage-template/form/WastageTemplateItemTable.vue.d.ts +0 -35
  103. package/dist/views/adjustment-template/wastage-template/form/useAdjustmentTemplateItems.d.ts +0 -20
  104. package/dist/views/adjustment-template/wastage-template/props.d.ts +0 -29
  105. package/dist/views/adjustment-template/wastage-template/table.d.ts +0 -1273
  106. package/dist/views/closing-draft/ClosingDraftView.vue.d.ts +0 -2
  107. package/dist/views/closing-draft/components/closing-draft-action/ClosingDraftAction.vue.d.ts +0 -22
  108. package/dist/views/closing-draft/components/closing-draft-dialog/ClosingDraftDialog.vue.d.ts +0 -621
  109. package/dist/views/closing-draft/composables/use-closing-draft-actions.d.ts +0 -25
  110. package/dist/views/closing-draft/composables/use-closing-draft-table.d.ts +0 -3621
  111. package/dist/views/closing-draft/helpers/draft-status-to-class-name.helper.d.ts +0 -1
  112. package/dist/views/closing-draft/helpers/export-draft.helper.d.ts +0 -19
  113. package/dist/views/closing-draft/helpers/get-calculated-total.helper.d.ts +0 -4
  114. package/dist/views/receive-request/helper/check-netsuite-subsidiary.helper.d.ts +0 -1
@@ -0,0 +1,1198 @@
1
+ import { F as ee, D as V, R as I } from "./row-action.enum-PMKMRrZR.js";
2
+ import { c as be } from "./TableActionableRow.vue_vue_type_script_setup_true_lang-DlNJ6kRg.js";
3
+ import { j as Te, a as M, u as j, i as Se, x as te, s as _e, c as W, R as re } from "./app-CwUHqg7h.js";
4
+ import { f as $e } from "./format-time-from-id-CaPj8EHN.js";
5
+ import { useCoreStore as Y, useI18n as G } from "@feedmepos/mf-common";
6
+ import { useDialogChild as we, useSnackbar as le, useDialog as ke, FmButtonVariant as ne, components as oe } from "@feedmepos/ui-library";
7
+ import { defineStore as me } from "pinia";
8
+ import { defineComponent as ce, resolveComponent as P, openBlock as _, createElementBlock as w, createElementVNode as $, normalizeClass as U, createTextVNode as Re, toDisplayString as C, unref as E, createCommentVNode as B, createVNode as N, withCtx as K, Fragment as F, renderList as q, ref as k, onMounted as Ee, computed as ae, watch as Ce, createSlots as Ae, createBlock as Q, h as z } from "vue";
9
+ import { useRouter as Ie } from "vue-router";
10
+ import { F as Ne } from "./FmMultiselectDialog-CKBcMDGC.js";
11
+ import { a as D, b as ue, d as pe, s as de, r as Fe } from "./xlsx.util-CJxPf7XZ.js";
12
+ import { F as De } from "./FmDroppableField-8RzKjEdL.js";
13
+ import { a as O, t as L, g as H, m as Oe, B as Pe } from "./rules-BQz4NGht.js";
14
+ import { f as Ue } from "./date2-CHNm4ELK.js";
15
+ import { u as J } from "./supplier-BixmjZyl.js";
16
+ const fe = Te((t, r) => {
17
+ function a() {
18
+ var n;
19
+ return `business_${((n = Y().currentBusiness.value) == null ? void 0 : n._id) ?? ""}`;
20
+ }
21
+ return {
22
+ async getTemplate(c) {
23
+ const o = a(), n = `${t.inventoryBackendUrl}/${o}/purchase-order-template/${c}`;
24
+ return r.get(n);
25
+ },
26
+ async readTemplates() {
27
+ const c = a(), o = `${t.inventoryBackendUrl}/${c}/purchase-order-template`;
28
+ return r.get(o);
29
+ },
30
+ async createTemplate(c) {
31
+ const o = a(), n = `${t.inventoryBackendUrl}/${o}/purchase-order-template`;
32
+ return r.post(n, c);
33
+ },
34
+ async updateTemplate(c) {
35
+ const o = a(), n = `${t.inventoryBackendUrl}/${o}/purchase-order-template`;
36
+ return r.put(n, c);
37
+ },
38
+ async deleteTemplate(c) {
39
+ const o = a(), n = `${t.inventoryBackendUrl}/${o}/purchase-order-template`;
40
+ return r.delete(n, { _id: c._id, _rev: c._rev });
41
+ },
42
+ async importTemplates(c) {
43
+ const o = a(), n = `${t.inventoryBackendUrl}/${o}/purchase-order-template/import`;
44
+ return r.post(n, c);
45
+ }
46
+ };
47
+ });
48
+ function ye(t) {
49
+ const r = M(), a = t.sku, c = r.skuById[a._id];
50
+ if (c.unit._id !== a.unit._id) return !0;
51
+ const o = t.measurement;
52
+ return o ? !r.unitById[c.unit._id].measurements.find((l) => l.id === o.id) : !1;
53
+ }
54
+ var R = /* @__PURE__ */ ((t) => (t.PURCHASE = "PURCHASE", t.TRANSFER = "TRANSFER", t))(R || {}), X = /* @__PURE__ */ ((t) => (t.Source = "Source", t.Destination = "Destination", t.Ingredient = "Ingredient", t))(X || {});
55
+ function he(t) {
56
+ var c;
57
+ const r = t.sku;
58
+ return {
59
+ code: r.code,
60
+ name: r.name,
61
+ unit: ((c = r.unit.measurements.find((o) => o.id === r.trackingMeasurement)) == null ? void 0 : c.abbrev) ?? r.unit.abbrev,
62
+ defaultQuantity: +O(t.quantity),
63
+ minimumQuantity: +O(t.minimumQuantity),
64
+ maximumQuantity: +O(t.maximumQuantity),
65
+ quantityStep: +O(t.quantityStep)
66
+ };
67
+ }
68
+ function ve() {
69
+ return [
70
+ {
71
+ id: "code",
72
+ name: "Code"
73
+ },
74
+ {
75
+ id: "name",
76
+ name: "Name"
77
+ },
78
+ {
79
+ id: "unit",
80
+ name: "Unit"
81
+ },
82
+ {
83
+ id: "defaultQuantity",
84
+ name: "Default Quantity"
85
+ },
86
+ {
87
+ id: "minimumQuantity",
88
+ name: "Minimum Quantity"
89
+ },
90
+ {
91
+ id: "maximumQuantity",
92
+ name: "Maximum Quantity"
93
+ },
94
+ {
95
+ id: "quantityStep",
96
+ name: "Quantity Step"
97
+ }
98
+ ];
99
+ }
100
+ function Be(t) {
101
+ var l;
102
+ const a = Y().currentBusiness.value, o = (l = t.map((u) => {
103
+ var f;
104
+ const m = u.purchaseOrder.items.map(he), h = ve(), g = [
105
+ ["Template ID", u._id],
106
+ ["Template name", u.name],
107
+ ["Business name", a == null ? void 0 : a.name],
108
+ ["Business ID", a == null ? void 0 : a._id],
109
+ ["Menu version", a == null ? void 0 : a.menuVersion],
110
+ [
111
+ "Purchase/Transfer",
112
+ typeof u.purchaseOrder.supplier.internal == "string" ? R.TRANSFER : R.PURCHASE
113
+ ],
114
+ [
115
+ "Transfer from",
116
+ `${u.purchaseOrder.supplier.name} (${[
117
+ u.purchaseOrder.supplier.internal,
118
+ u.purchaseOrder.supplier._id
119
+ ].filter((e) => e).join("_")})`
120
+ ],
121
+ ["Location codes", ...((f = u.locations) == null ? void 0 : f.map((e) => `${e.name} (${e.dbName})`)) ?? ["All"]],
122
+ ["Reference", u.purchaseOrder.ref ?? ""],
123
+ ["Remark", u.purchaseOrder.remark ?? ""],
124
+ [],
125
+ h.map((e) => e.name),
126
+ ...m.map((e) => h.map((T) => e[T.id]))
127
+ ], x = h.map((e) => `system:${e.id}`), y = D(g, x);
128
+ return { name: u.name, sheet: y };
129
+ }).reduce(
130
+ (u, m) => {
131
+ var g;
132
+ const h = m.name.slice(0, 12);
133
+ return (g = u.sheetOccurence)[h] ?? (g[h] = 0), u.sheetOccurence[h] += 1, u.sheets[`${h} (${u.sheetOccurence[h]})`] = m.sheet, u;
134
+ },
135
+ {
136
+ sheets: {},
137
+ sheetOccurence: {}
138
+ }
139
+ )) == null ? void 0 : l.sheets, n = `${a == null ? void 0 : a.name} transfer templates (${Ue(/* @__PURE__ */ new Date())}).xlsx`, i = ue(o);
140
+ return pe(i, n), n;
141
+ }
142
+ function Me() {
143
+ const t = Y(), r = J(), a = j(), c = M(), o = t.currentBusiness.value, n = he({
144
+ sku: {
145
+ unit: {
146
+ _id: "",
147
+ name: "Unit",
148
+ abbrev: "Unit",
149
+ precision: 0,
150
+ measurements: []
151
+ },
152
+ code: "ING001",
153
+ _id: "",
154
+ name: "Sugar"
155
+ },
156
+ code: "ING001",
157
+ name: "Sugar",
158
+ quantity: {
159
+ amount: 1,
160
+ precision: 0
161
+ },
162
+ quantityStep: {
163
+ amount: 1,
164
+ precision: 0
165
+ },
166
+ minimumQuantity: {
167
+ amount: 1,
168
+ precision: 0
169
+ },
170
+ maximumQuantity: {
171
+ amount: 1,
172
+ precision: 0
173
+ }
174
+ }), i = ve(), l = [
175
+ ["Template ID (leave empty to create new)"],
176
+ ["Template Name", "New template"],
177
+ ["Business name", o == null ? void 0 : o.name],
178
+ ["Business ID", o == null ? void 0 : o._id],
179
+ ["Menu version", o == null ? void 0 : o.menuVersion],
180
+ ["Purchase/Transfer", "Purchase"],
181
+ [
182
+ "Transfer from",
183
+ "Example supplier (supplier_xxx)",
184
+ "Refer to sources list & copy whole cell."
185
+ ],
186
+ [
187
+ "Location codes (leave empty to enable all)",
188
+ "Example outlet (restaurant_xxx)",
189
+ "Example outlet 2 (restaurant_xxx)"
190
+ ],
191
+ ["Reference"],
192
+ ["Remark"],
193
+ [],
194
+ i.map((e) => e.name),
195
+ i.map((e) => n[e.id])
196
+ ], u = i.map((e) => `system:${e.id}`), m = D(l, u), h = D(
197
+ [
198
+ ...r.businessSuppliers.map((e) => [
199
+ `${e.name} (${e._id})`,
200
+ "Purchase",
201
+ e.address.line1,
202
+ e.address.line2,
203
+ e.address.city,
204
+ e.address.postcode,
205
+ e.address.state,
206
+ e.address.country
207
+ ]),
208
+ ...a.locations.map((e) => {
209
+ var T, d, v, s, p, S;
210
+ return [
211
+ `${e.name} (${e.dbName})`,
212
+ "Transfer",
213
+ (T = e.doc.profile.address) == null ? void 0 : T.line1,
214
+ (d = e.doc.profile.address) == null ? void 0 : d.line2,
215
+ (v = e.doc.profile.address) == null ? void 0 : v.city,
216
+ (s = e.doc.profile.address) == null ? void 0 : s.postcode,
217
+ (p = e.doc.profile.address) == null ? void 0 : p.state,
218
+ (S = e.doc.profile.address) == null ? void 0 : S.country
219
+ ];
220
+ })
221
+ ],
222
+ ["Name", "Type", "Line 1", "Line 2", "City", "Postal", "State", "Country"]
223
+ ), g = D(
224
+ a.locations.map((e) => {
225
+ var T, d, v, s, p, S;
226
+ return [
227
+ `${e.name} (${e.dbName})`,
228
+ (T = e.doc.profile.address) == null ? void 0 : T.line1,
229
+ (d = e.doc.profile.address) == null ? void 0 : d.line2,
230
+ (v = e.doc.profile.address) == null ? void 0 : v.city,
231
+ (s = e.doc.profile.address) == null ? void 0 : s.postcode,
232
+ (p = e.doc.profile.address) == null ? void 0 : p.state,
233
+ (S = e.doc.profile.address) == null ? void 0 : S.country
234
+ ];
235
+ }),
236
+ ["Name", "Line 1", "Line 2", "City", "Postal", "State", "Country"]
237
+ ), x = D(
238
+ c.skus.map((e) => [
239
+ e.code,
240
+ e.name,
241
+ e.unit.abbrev,
242
+ ...e.unit.measurements.map((T) => T.abbrev)
243
+ ]),
244
+ ["Code", "Name", "Base unit", "Measurements"]
245
+ ), y = ue({
246
+ Template: m,
247
+ Source: h,
248
+ Destination: g,
249
+ Ingredient: x
250
+ }), f = `${o == null ? void 0 : o.name} transfer templates import.xlsx`;
251
+ return pe(y, f), f;
252
+ }
253
+ function Qe(t, r) {
254
+ const a = new Array(), c = /(.*) \(((supplier_|warehouse_|restaurant_).{24,})\)/, n = j().locationByDbName, l = J().supplierById, u = t.trim(), m = c.exec(u);
255
+ if (!m)
256
+ return a.push(`Transfer from location value of ${u} cannot be read.`), {
257
+ errors: a
258
+ };
259
+ const h = m[1], g = m[2];
260
+ let x;
261
+ if (g.startsWith("supplier"))
262
+ x = l[g], r !== R.PURCHASE && a.push(`Expected transfer type Purchase but found ${r} instead.`);
263
+ else {
264
+ const y = n[g];
265
+ if (!y)
266
+ return a.push(`Location (${h}) of id ${g} is not found.`), {
267
+ errors: a
268
+ };
269
+ h !== y.name && a.push(
270
+ `Location id ${g} has non-matching name. Found ${h} but expected ${y.name}`
271
+ ), x = {
272
+ _id: y.doc._id,
273
+ name: y.name,
274
+ address: y.doc.profile.address ?? {
275
+ line1: "",
276
+ state: "",
277
+ country: "",
278
+ city: "",
279
+ postcode: "",
280
+ coordinates: [0, 0]
281
+ },
282
+ internal: g.split("_")[0] === "restaurant" ? te.enum.restaurant : te.enum.warehouse,
283
+ phoneNumber: y.doc.profile.phoneNo ?? "",
284
+ email: y.doc.profile.email ?? "",
285
+ _rev: "",
286
+ contactName: y.doc.profile.name ?? "",
287
+ registrationNumber: y.doc.profile.regNo ?? ""
288
+ };
289
+ }
290
+ return {
291
+ from: x,
292
+ errors: a
293
+ };
294
+ }
295
+ function Le(t) {
296
+ if (!t.length || `${t[0]}`.toLocaleLowerCase() === "all")
297
+ return [];
298
+ const r = /(.*) \(((warehouse_|restaurant_).{24,})\)/, c = j().locationByDbName;
299
+ return t.map((o) => {
300
+ const n = new Array(), i = o.trim(), l = r.exec(i);
301
+ if (!l)
302
+ return n.push(`Enabled location value of ${i} cannot be read.`), {
303
+ errors: n
304
+ };
305
+ const u = l[1], m = l[2], h = c[m];
306
+ return h ? (u !== h.name && n.push(
307
+ `Location id ${m} has non-matching name. Found ${u} but expected ${h.name}`
308
+ ), {
309
+ errors: n,
310
+ location: h
311
+ }) : (n.push(`Location (${u}) of id ${m} is not found.`), {
312
+ errors: n
313
+ });
314
+ });
315
+ }
316
+ function He(t) {
317
+ const [
318
+ r,
319
+ a,
320
+ c,
321
+ o,
322
+ n,
323
+ i,
324
+ l,
325
+ u,
326
+ m,
327
+ h,
328
+ g
329
+ ] = de(t);
330
+ return {
331
+ id: `${a[1] ?? ""}`.trim(),
332
+ name: `${c[1] ?? ""}`.trim(),
333
+ type: `${l[1] ?? ""}`.trim().toLocaleLowerCase() === "transfer" ? R.TRANSFER : R.PURCHASE,
334
+ transferFrom: `${u[1] ?? ""}`.trim(),
335
+ locations: m.slice(1).map((x) => `${x}`.trim()).filter((x) => x),
336
+ reference: `${h[1] ?? ""}`.trim(),
337
+ remark: `${g[1] ?? ""}`.trim()
338
+ };
339
+ }
340
+ function qe(t) {
341
+ const [
342
+ r,
343
+ a,
344
+ c,
345
+ o,
346
+ n,
347
+ i,
348
+ l,
349
+ u,
350
+ m,
351
+ h,
352
+ g,
353
+ x,
354
+ y,
355
+ ...f
356
+ ] = de(t);
357
+ if (!r || !r.length || r.some((s) => s.length && !s.startsWith("system:")))
358
+ throw new Error("Missing meta header. Excel file does not come from the template.");
359
+ const e = r.map((s) => s.split(":")[1]), d = [
360
+ "code",
361
+ "name",
362
+ "unit",
363
+ "defaultQuantity",
364
+ "minimumQuantity",
365
+ "maximumQuantity",
366
+ "quantityStep"
367
+ ].filter((s) => !e.includes(s));
368
+ if (d.length)
369
+ throw new Error(
370
+ `Missing meta headers (${d.join()}). Excel file does not come from the template.`
371
+ );
372
+ return f.map((s, p) => {
373
+ const S = {};
374
+ for (const b in e) {
375
+ const A = e[b];
376
+ Object.assign(S, { [A]: s[b] });
377
+ }
378
+ return {
379
+ index: p,
380
+ data: S
381
+ };
382
+ });
383
+ }
384
+ function je(t, r, a) {
385
+ const o = M().skuByCode[t.code], n = new Array();
386
+ if (!o)
387
+ return n.push(`Cannot find ingredient with code (${t.code}) ${t.name}.`), {
388
+ index: r,
389
+ errors: n
390
+ };
391
+ if (a.filter((s) => s.data.code === t.code).length > 1)
392
+ return n.push(`Ingredient ${t.code} is defined twice.`), {
393
+ index: r,
394
+ errors: n
395
+ };
396
+ const i = o.unit, l = i == null ? void 0 : i.measurements.find((s) => s.abbrev === t.unit);
397
+ if (i.abbrev !== t.unit && !l) {
398
+ const s = `Cannot find unit measurement of symbol ${t.unit || "[empty]"} for ingredient (${t.code}) ${t.name}.`;
399
+ n.push(s);
400
+ const p = {
401
+ sku: o,
402
+ code: o.code,
403
+ name: o.name,
404
+ measurement: l,
405
+ quantity: { amount: 0, precision: 0 },
406
+ quantityStep: { amount: 0, precision: 0 },
407
+ minimumQuantity: { amount: 0, precision: 0 },
408
+ maximumQuantity: { amount: 0, precision: 0 }
409
+ };
410
+ return {
411
+ index: r,
412
+ errors: n,
413
+ templateItem: p
414
+ };
415
+ }
416
+ const u = L(
417
+ t.quantityStep,
418
+ H(i, l)
419
+ );
420
+ (Number.isNaN(Number(t.quantityStep)) || Number(t.quantityStep) <= 0) && n.push("Amount step must be more than 0");
421
+ const m = Oe(u), h = L(
422
+ t.minimumQuantity,
423
+ H(i, l)
424
+ ), g = m(h);
425
+ typeof g == "string" && n.push(`Minimum amount: ${g}`);
426
+ const x = L(
427
+ t.maximumQuantity,
428
+ H(i, l)
429
+ ), y = m(x);
430
+ typeof y == "string" && n.push(`Maximum amount: ${y}`), +t.minimumQuantity > +t.maximumQuantity && n.push("Minimum amount must be less than or equal to maximum amount");
431
+ const f = Pe(+t.minimumQuantity, +t.maximumQuantity), e = L(
432
+ t.defaultQuantity,
433
+ H(i, l)
434
+ ), T = m(e), d = f(`${t.defaultQuantity}`);
435
+ typeof T == "string" && n.push(`Default amount: ${T}`), typeof d == "string" && n.push(`Default amount: ${d}`);
436
+ const v = {
437
+ sku: o,
438
+ code: o.code,
439
+ name: o.name,
440
+ measurement: l,
441
+ quantity: e,
442
+ quantityStep: u,
443
+ minimumQuantity: h,
444
+ maximumQuantity: x
445
+ };
446
+ return {
447
+ index: r,
448
+ errors: n,
449
+ templateItem: v
450
+ };
451
+ }
452
+ function Ve(t) {
453
+ const r = t.SheetNames.filter(
454
+ (n) => !Object.values(X).map(String).includes(n)
455
+ ), c = xe().templates, o = Se(c, "_id");
456
+ try {
457
+ return r.reduce(
458
+ (n, i) => {
459
+ var s;
460
+ const l = new Array(), u = t.Sheets[i], m = He(u), h = Qe(m.transferFrom, m.type);
461
+ l.push(...h.errors);
462
+ const g = h.from, x = Le(m.locations), y = x.filter((p) => p.location).map((p) => p.location);
463
+ l.push(...x.flatMap((p) => p.errors));
464
+ const f = qe(u).filter((p) => p.data.code), e = f.map(
465
+ (p, S) => je(p.data, S, f)
466
+ );
467
+ l.push(
468
+ ...e.flatMap(
469
+ (p) => p.errors.map((S) => `(Excel row ${p.index + 14}) ${S}`)
470
+ )
471
+ );
472
+ const T = e.filter((p) => p.templateItem).map((p) => p.templateItem);
473
+ if (m.id) {
474
+ const p = o[m.id];
475
+ if (!p) {
476
+ const b = {
477
+ _id: m.id,
478
+ _rev: "",
479
+ name: m.name || `(unnamed from sheet ${i || "<unnamed sheet>"})`,
480
+ purchaseOrder: ze()
481
+ };
482
+ return l.push(`Template ID ${m.id} is not found.`), n.importUpdateResult.push({
483
+ type: "update",
484
+ original: b,
485
+ template: b,
486
+ excelSheetName: i,
487
+ errors: l
488
+ }), n;
489
+ }
490
+ const S = {
491
+ type: "update",
492
+ original: p,
493
+ template: {
494
+ ...p,
495
+ name: m.name,
496
+ locations: y.length ? y : null,
497
+ purchaseOrder: {
498
+ ...p.purchaseOrder,
499
+ supplier: g ?? ((s = p.purchaseOrder) == null ? void 0 : s.supplier),
500
+ ref: m.reference,
501
+ remark: m.remark,
502
+ items: T
503
+ }
504
+ },
505
+ excelSheetName: i,
506
+ errors: l
507
+ };
508
+ return n.importUpdateResult.push(S), n;
509
+ }
510
+ const v = {
511
+ type: "create",
512
+ template: {
513
+ name: m.id,
514
+ locations: y,
515
+ purchaseOrder: {
516
+ supplier: g ?? ge(),
517
+ ref: m.reference,
518
+ remark: m.remark,
519
+ items: T
520
+ }
521
+ },
522
+ excelSheetName: i,
523
+ errors: l
524
+ };
525
+ return n.importCreateResult.push(v), n;
526
+ },
527
+ {
528
+ invalidExcel: !1,
529
+ importCreateResult: new Array(),
530
+ importUpdateResult: new Array()
531
+ }
532
+ );
533
+ } catch (n) {
534
+ return {
535
+ invalidExcel: !0,
536
+ invalidExcelMessage: (n == null ? void 0 : n.message) ?? "Invalid excel",
537
+ importCreateResult: [],
538
+ importUpdateResult: []
539
+ };
540
+ }
541
+ }
542
+ function ge() {
543
+ return {
544
+ _id: "",
545
+ name: "",
546
+ address: {
547
+ line2: void 0,
548
+ line1: "",
549
+ state: "",
550
+ city: "",
551
+ postcode: "",
552
+ country: ""
553
+ }
554
+ };
555
+ }
556
+ function ze() {
557
+ return {
558
+ remark: void 0,
559
+ ref: void 0,
560
+ items: [],
561
+ supplier: ge()
562
+ };
563
+ }
564
+ const Ke = { class: "flex items-center gap-12 pl-8" }, We = { class: "flex flex-col" }, Ye = { class: "fm-typo-en-body-md-400 text-fm-color-typo-primary flex items-center gap-4" }, Ge = { class: "text-fm-color-typo-secondary fm-typo-en-body-md-400" }, Je = {
565
+ key: 0,
566
+ class: "text-fm-color-typo-secondary fm-typo-en-body-sm-400"
567
+ }, Xe = { key: 0 }, se = /* @__PURE__ */ ce({
568
+ __name: "TransferTemplateImportItem",
569
+ props: {
570
+ type: {},
571
+ name: {},
572
+ transferType: {},
573
+ locations: {},
574
+ items: {},
575
+ errors: {}
576
+ },
577
+ setup(t) {
578
+ return (r, a) => {
579
+ var n, i, l;
580
+ const c = P("FmIcon"), o = P("FmTooltip");
581
+ return _(), w("div", Ke, [
582
+ a[0] || (a[0] = $("div", null, "•", -1)),
583
+ $("div", We, [
584
+ $("div", Ye, [
585
+ $("div", {
586
+ class: U({
587
+ "text-fm-color-system-error-300": r.errors.length
588
+ })
589
+ }, [
590
+ Re(C(r.name) + " ", 1),
591
+ $("span", Ge, " (" + C(E(_e)(`${r.transferType}`)) + ") ", 1),
592
+ r.type === "create" ? (_(), w("span", Je, "(new)")) : B("", !0)
593
+ ], 2),
594
+ r.errors.length ? (_(), w("div", Xe, [
595
+ N(o, { "z-index": 50 }, {
596
+ content: K(() => [
597
+ $("ol", null, [
598
+ (_(!0), w(F, null, q(r.errors, (u, m) => (_(), w("li", { key: m }, C(u), 1))), 128))
599
+ ])
600
+ ]),
601
+ default: K(() => [
602
+ N(c, {
603
+ name: "error",
604
+ size: "sm",
605
+ color: "system-error-300"
606
+ })
607
+ ]),
608
+ _: 1
609
+ })
610
+ ])) : B("", !0)
611
+ ]),
612
+ $("div", {
613
+ class: U([
614
+ "fm-typo-en-body-sm-400",
615
+ {
616
+ "text-fm-color-system-error-200": r.errors.length,
617
+ "text-fm-color-typo-secondary": !r.errors.length
618
+ }
619
+ ])
620
+ }, C((n = r.locations) != null && n.length ? `${(i = r.locations) == null ? void 0 : i.length} locations` : "All locations") + ", " + C(`${(l = r.items) == null ? void 0 : l.length} items`), 3)
621
+ ])
622
+ ]);
623
+ };
624
+ }
625
+ }), Ze = { class: "flex flex-col gap-24" }, et = {
626
+ key: 0,
627
+ class: "flex items-center gap-8"
628
+ }, tt = { class: "flex flex-col gap-8" }, rt = { class: "line-clamp-2 text-ellipsis break-all" }, nt = {
629
+ key: 2,
630
+ class: "shrink-0"
631
+ }, ot = {
632
+ key: 0,
633
+ class: "flex flex-col"
634
+ }, at = { class: "text-fm-color-system-error-300 fm-typo-en-body-sm-400" }, st = {
635
+ key: 0,
636
+ class: "max-h-[200px] overflow-y-auto flex flex-col gap-8"
637
+ }, it = { class: "fm-typo-en-body-lg-600" }, lt = /* @__PURE__ */ ce({
638
+ __name: "TransferTemplateImport",
639
+ setup(t) {
640
+ const r = k(null), a = we(), c = le(), o = k(!1), n = k(!1), i = J();
641
+ Ee(async () => {
642
+ n.value = !0;
643
+ try {
644
+ await i.readSuppliers().delayed(1e3);
645
+ } catch {
646
+ c.open({
647
+ title: "Something went wrong.",
648
+ message: "Error at reading suppliers list. Please try again.",
649
+ type: "error"
650
+ });
651
+ } finally {
652
+ n.value = !1;
653
+ }
654
+ });
655
+ const l = k(new Array()), u = k([]), m = k([]), h = ae(
656
+ () => !!l.value.length || u.value.some((f) => f.errors.length) || m.value.some((f) => f.errors.length)
657
+ ), g = ae(
658
+ () => !!u.value.length || !!m.value.length
659
+ ), { t: x } = G();
660
+ async function y(f) {
661
+ l.value = [], u.value = [], m.value = [];
662
+ try {
663
+ o.value = !0;
664
+ const [e] = await Promise.all([
665
+ Fe(f),
666
+ // fake buffer
667
+ new Promise((s) => setTimeout(s, 1e3))
668
+ ]);
669
+ if (!e.SheetNames.filter(
670
+ (s) => !Object.values(X).map(String).includes(s)
671
+ ).find((s) => s)) {
672
+ l.value.push(x("inventory.ingredient.import.fileError.noSheet"));
673
+ return;
674
+ }
675
+ const v = Ve(e);
676
+ if (v.invalidExcel) {
677
+ l.value.push(
678
+ v.invalidExcelMessage ?? x("inventory.ingredient.import.fileError.invalidExcel")
679
+ );
680
+ return;
681
+ }
682
+ if (u.value = v.importCreateResult, m.value = v.importUpdateResult, !u.value.length && !m.value.length) {
683
+ l.value.push(x("inventory.ingredient.import.fileError.noData"));
684
+ return;
685
+ }
686
+ a.emitData(v);
687
+ } catch (e) {
688
+ c.open({
689
+ title: x("inventory.ingredient.import.fileError.unableToRead"),
690
+ message: e == null ? void 0 : e.message,
691
+ type: "error"
692
+ }), console.error("Error in reading file", e);
693
+ } finally {
694
+ l.value.length && c.open({
695
+ title: x("inventory.ingredient.import.fileError.invalidExcel"),
696
+ type: "error"
697
+ }), o.value = !1;
698
+ }
699
+ }
700
+ return Ce(r, (f) => {
701
+ f && y(f);
702
+ }), (f, e) => {
703
+ const T = P("FmCircularProgress"), d = P("FmIcon"), v = P("FmButton");
704
+ return _(), w("div", Ze, [
705
+ e[2] || (e[2] = $("div", { class: "fm-typo-en-body-md-400" }, "Import transfer templates from excel sheets.", -1)),
706
+ n.value ? (_(), w("div", et, [
707
+ $("div", null, [
708
+ N(T, {
709
+ size: "md",
710
+ color: "neutral-gray-200"
711
+ })
712
+ ]),
713
+ e[1] || (e[1] = $("div", { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, "Loading...", -1))
714
+ ])) : (_(), w(F, { key: 1 }, [
715
+ N(De, {
716
+ class: U({
717
+ "w-full": !0,
718
+ "h-[200px]": !r.value
719
+ }),
720
+ accept: ".xlsx",
721
+ onFileUpload: e[0] || (e[0] = (s) => r.value = s),
722
+ label: E(x)("inventory.ingredient.import.uploadTemplate"),
723
+ "button-label": E(x)("inventory.ingredient.import.selectFile")
724
+ }, Ae({ _: 2 }, [
725
+ r.value ? {
726
+ name: "default",
727
+ fn: K(({ openFileDialog: s }) => [
728
+ $("div", tt, [
729
+ $("div", {
730
+ class: U([
731
+ "fm-corner-radius-md p-16 flex items-center gap-16",
732
+ {
733
+ "border border-fm-color-neutral-gray-100": o.value,
734
+ "border border-fm-color-neutral-gray-200": !o.value && !h.value,
735
+ "border border-fm-color-system-error-200": h.value
736
+ }
737
+ ])
738
+ }, [
739
+ o.value ? (_(), Q(T, {
740
+ key: 0,
741
+ size: "md",
742
+ color: "neutral-gray-200"
743
+ })) : (_(), Q(d, {
744
+ key: 1,
745
+ name: h.value ? "error" : "attach_file",
746
+ outline: "",
747
+ color: h.value ? "system-error-300" : void 0
748
+ }, null, 8, ["name", "color"])),
749
+ $("div", {
750
+ class: U([
751
+ "fm-typo-en-body-md-400 flex-1 h-[36px] flex items-center",
752
+ {
753
+ "text-fm-color-typo-disabled": o.value,
754
+ "text-fm-color-typo-primary": !o.value
755
+ }
756
+ ])
757
+ }, [
758
+ $("div", rt, C(r.value.name), 1)
759
+ ], 2),
760
+ o.value ? B("", !0) : (_(), w("div", nt, [
761
+ N(v, {
762
+ label: E(x)("inventory.ingredient.import.replaceFile"),
763
+ variant: h.value ? "destructive" : "secondary",
764
+ "prepend-icon": h.value ? void 0 : "autorenew",
765
+ onClick: s
766
+ }, null, 8, ["label", "variant", "prepend-icon", "onClick"])
767
+ ]))
768
+ ], 2),
769
+ l.value.length ? (_(), w("div", ot, [
770
+ (_(!0), w(F, null, q(l.value, (p, S) => (_(), w("div", {
771
+ key: S,
772
+ class: "flex gap-8 items-center"
773
+ }, [
774
+ N(d, {
775
+ name: "error",
776
+ size: "sm",
777
+ color: "system-error-300"
778
+ }),
779
+ $("div", at, C(p), 1)
780
+ ]))), 128))
781
+ ])) : B("", !0)
782
+ ])
783
+ ]),
784
+ key: "0"
785
+ } : void 0
786
+ ]), 1032, ["class", "label", "button-label"]),
787
+ g.value ? (_(), w("div", st, [
788
+ $("div", it, C(E(x)("inventory.ingredient.import.summary")), 1),
789
+ (_(!0), w(F, null, q(u.value, (s, p) => (_(), Q(se, {
790
+ key: p,
791
+ name: s.template.name,
792
+ "transfer-type": typeof s.template.purchaseOrder.supplier.internal == "string" ? E(R).TRANSFER : E(R).PURCHASE,
793
+ locations: s.template.locations,
794
+ items: s.template.purchaseOrder.items,
795
+ errors: s.errors,
796
+ type: "create"
797
+ }, null, 8, ["name", "transfer-type", "locations", "items", "errors"]))), 128)),
798
+ (_(!0), w(F, null, q(m.value, (s) => (_(), Q(se, {
799
+ key: s.template._id,
800
+ name: s.template.name,
801
+ "transfer-type": typeof s.template.purchaseOrder.supplier.internal == "string" ? E(R).TRANSFER : E(R).PURCHASE,
802
+ locations: s.template.locations,
803
+ items: s.template.purchaseOrder.items,
804
+ errors: s.errors,
805
+ type: "update"
806
+ }, null, 8, ["name", "transfer-type", "locations", "items", "errors"]))), 128))
807
+ ])) : B("", !0)
808
+ ], 64))
809
+ ]);
810
+ };
811
+ }
812
+ }), mt = me("transferTemplateActions", () => {
813
+ const t = ke(), r = le(), a = j(), c = xe(), o = fe(), n = Ie(), { t: i } = G(), l = k({});
814
+ function u() {
815
+ l.value = {
816
+ mode: ee.CREATE,
817
+ show: !0,
818
+ "onUpdate:show"(d) {
819
+ l.value.show = d;
820
+ }
821
+ };
822
+ }
823
+ function m(d) {
824
+ l.value = {
825
+ mode: ee.UPDATE,
826
+ modelValue: d,
827
+ show: !0,
828
+ "onUpdate:show"(v) {
829
+ l.value.show = v;
830
+ }
831
+ };
832
+ }
833
+ function h(d, v, s) {
834
+ t.open({
835
+ title: `Confirm deleting template ${d.name}?`,
836
+ message: "Deleted template can no longer be retrieved",
837
+ primaryActions: {
838
+ text: "Delete",
839
+ variant: ne.Destructive,
840
+ close: !0
841
+ },
842
+ secondaryActions: {
843
+ text: "Cancel",
844
+ variant: ne.Plain,
845
+ close: !0
846
+ }
847
+ }).onPrimary(async () => {
848
+ r.open({
849
+ title: `Deleting ${d.name}`,
850
+ type: "info"
851
+ });
852
+ try {
853
+ v.value = !0;
854
+ const [p] = await Promise.allSettled([
855
+ o.deleteTemplate(d),
856
+ new Promise((S) => setTimeout(S, 1e3))
857
+ ]);
858
+ if (p.status === "rejected") throw p.reason;
859
+ r.open({
860
+ title: `Deleted ${d.name}`,
861
+ type: "success"
862
+ });
863
+ } catch (p) {
864
+ r.open({
865
+ title: `Unable to delete ${d.name}`,
866
+ message: `See error from server: ${p}`,
867
+ type: "error"
868
+ }), console.error("error on deleting purchase order template", p);
869
+ } finally {
870
+ v.value = !1, s();
871
+ }
872
+ });
873
+ }
874
+ const g = k({});
875
+ function x(d) {
876
+ g.value = {
877
+ template: d,
878
+ show: !0,
879
+ "onUpdate:show"(v) {
880
+ g.value.show = v;
881
+ },
882
+ "onAction:edit"() {
883
+ g.value.show = !1, m(W(d));
884
+ }
885
+ };
886
+ }
887
+ function y() {
888
+ const { promise: d, resolve: v } = Promise.withResolvers(), s = (b) => {
889
+ v(b);
890
+ }, p = c.templates.filter(
891
+ (b) => {
892
+ var A;
893
+ return (!b.locations || b.locations.find((Z) => Z.doc._id === a.currentLocation.doc._id)) && ((A = b.purchaseOrder.supplier) == null ? void 0 : A._id) !== a.currentLocation.doc._id;
894
+ }
895
+ );
896
+ if (!p.length)
897
+ return t.open({
898
+ title: "Select one template",
899
+ message: "There is no available template in your business. Configure a new template?",
900
+ primaryActions: {
901
+ text: "Close",
902
+ close: !0
903
+ },
904
+ secondaryActions: {
905
+ text: "Close",
906
+ close: !0
907
+ }
908
+ }).onPrimary(() => {
909
+ n.push({ name: re.TRANSFER_TEMPLATE }), s(void 0);
910
+ }).onSecondary(() => s(void 0)).onClose(() => s(void 0)), d;
911
+ const S = p.map((b) => {
912
+ const A = !b.purchaseOrder.items.length || b.purchaseOrder.items.some(ye);
913
+ return {
914
+ label: b.name,
915
+ value: b._id,
916
+ disabled: A,
917
+ sublabel: A ? "This template is invalid. Update this template." : void 0
918
+ };
919
+ });
920
+ return t.open({
921
+ title: "Select one template",
922
+ contentComponent: Ne,
923
+ contentComponentProps: {
924
+ items: S,
925
+ singleSelect: !0
926
+ },
927
+ primaryActions: {
928
+ text: "Confirm",
929
+ close: !0
930
+ },
931
+ secondaryActions: {
932
+ text: "Close",
933
+ close: !0
934
+ },
935
+ tertiaryActions: {
936
+ text: "Templates",
937
+ close: !0
938
+ }
939
+ }).onPrimary((b) => Array.isArray(b) ? s(b[0]) : null).onSecondary(() => s(void 0)).onTertiary(() => {
940
+ n.push({ name: re.TRANSFER_TEMPLATE }), s(void 0);
941
+ }).onClose(() => s(void 0)), d;
942
+ }
943
+ function f() {
944
+ t.open({
945
+ title: i("inventory.ingredient.import.title"),
946
+ contentComponent: lt,
947
+ overlay: !0,
948
+ closeButton: !0,
949
+ primaryActions: {
950
+ text: i("common.import"),
951
+ close: !1
952
+ },
953
+ secondaryActions: {
954
+ text: i("common.close"),
955
+ close: !0
956
+ },
957
+ tertiaryActions: {
958
+ text: i("inventory.ingredient.import.actions.downloadTemplate"),
959
+ close: !1,
960
+ variant: "plain"
961
+ }
962
+ }).onPrimary((d) => {
963
+ if (!d) {
964
+ r.open({
965
+ title: i("inventory.ingredient.import.error.noData"),
966
+ type: "error"
967
+ });
968
+ return;
969
+ }
970
+ if (!d.importCreateResult.length && !d.importUpdateResult.length) {
971
+ r.open({
972
+ title: i("inventory.ingredient.import.error.invalidContent"),
973
+ message: i("inventory.ingredient.import.error.noImportData"),
974
+ type: "error"
975
+ });
976
+ return;
977
+ }
978
+ if (d.importCreateResult.some((v) => v.errors.length) || d.importUpdateResult.some((v) => v.errors.length)) {
979
+ r.open({
980
+ title: i("inventory.ingredient.import.error.invalidContent"),
981
+ message: i("inventory.ingredient.import.error.hasErrors"),
982
+ type: "error"
983
+ });
984
+ return;
985
+ }
986
+ t.close(), e(d);
987
+ }).onTertiary(Me);
988
+ }
989
+ async function e(d) {
990
+ try {
991
+ const v = [
992
+ ...d.importCreateResult.map(
993
+ (b) => b.template
994
+ ),
995
+ ...d.importUpdateResult.map(
996
+ (b) => b.template
997
+ )
998
+ ], s = 100;
999
+ let p = 0;
1000
+ const S = () => {
1001
+ p += s, r.open({
1002
+ title: i("inventory.ingredient.import.progress", [
1003
+ Math.min(p, v.length),
1004
+ v.length
1005
+ ])
1006
+ });
1007
+ };
1008
+ for (const b of v.chunk(100))
1009
+ S(), await o.importTemplates(b);
1010
+ r.open({
1011
+ title: i("inventory.ingredient.import.success"),
1012
+ type: "success"
1013
+ });
1014
+ } catch (v) {
1015
+ r.open({
1016
+ title: i("inventory.ingredient.import.error.failed"),
1017
+ message: i("inventory.ingredient.import.error.systemMessage", [v == null ? void 0 : v.message]),
1018
+ type: "error"
1019
+ }), console.error("Error in importing skus", d, v);
1020
+ } finally {
1021
+ c.fetchTemplates();
1022
+ }
1023
+ }
1024
+ function T() {
1025
+ const d = Be(c.templates);
1026
+ r.open({
1027
+ title: i("inventory.ingredient.export.success"),
1028
+ message: i("inventory.ingredient.export.filename", [d]),
1029
+ type: "success"
1030
+ });
1031
+ }
1032
+ return {
1033
+ createTemplate: u,
1034
+ viewTemplate: x,
1035
+ updateTemplate: m,
1036
+ deleteTemplate: h,
1037
+ getTemplateId: y,
1038
+ importTemplates: f,
1039
+ exportTemplates: T,
1040
+ templateDialogProps: l,
1041
+ templateDetailsProps: g
1042
+ };
1043
+ });
1044
+ function ie(t) {
1045
+ const { skuById: r } = M(), a = W(t);
1046
+ return a.purchaseOrder.items = t.purchaseOrder.items.filter((c) => r[c.sku._id]), a;
1047
+ }
1048
+ const xe = me(
1049
+ "transferTemplateTable",
1050
+ function() {
1051
+ const { t: r } = G(), { viewTemplate: a, updateTemplate: c, deleteTemplate: o } = mt(), n = k(!1), i = k(new Array()), l = fe(), u = M();
1052
+ async function m() {
1053
+ i.value = [], n.value = !0;
1054
+ try {
1055
+ const [y] = await Promise.all([
1056
+ l.readTemplates(),
1057
+ u.readInventory()
1058
+ ]).delayed(1e3);
1059
+ i.value = y.map(ie);
1060
+ } catch (y) {
1061
+ console.log("Something went wrong when fetching templates:", y);
1062
+ } finally {
1063
+ n.value = !1;
1064
+ }
1065
+ }
1066
+ async function h(y) {
1067
+ if (!i.value.find((f) => f._id)) {
1068
+ n.value = !0;
1069
+ try {
1070
+ i.value = [
1071
+ await l.getTemplate(y).then(ie).delayed(1e3)
1072
+ ];
1073
+ } catch (f) {
1074
+ console.log("Something went wrong when fetching templates:", f);
1075
+ } finally {
1076
+ n.value = !1;
1077
+ }
1078
+ }
1079
+ }
1080
+ function g(y, f) {
1081
+ switch (f = W(f), y) {
1082
+ case I.Details:
1083
+ return a(f);
1084
+ case I.Edit:
1085
+ return c(f);
1086
+ case I.Delete:
1087
+ return o(f, n, m);
1088
+ }
1089
+ }
1090
+ return {
1091
+ columnDefs: [
1092
+ {
1093
+ id: "_id",
1094
+ accessorKey: "_id",
1095
+ header: () => r("inventory.transfer.table.createdAt"),
1096
+ cell(y) {
1097
+ return $e(`${y.getValue()}`);
1098
+ },
1099
+ enableSorting: !0
1100
+ },
1101
+ {
1102
+ id: "name",
1103
+ accessorKey: "name",
1104
+ header: () => r("inventory.transfer.table.name"),
1105
+ enableSorting: !0,
1106
+ size: 200
1107
+ },
1108
+ {
1109
+ id: "noOfItems",
1110
+ accessorKey: "purchaseOrder.items.length",
1111
+ header: () => r("inventory.transfer.table.noOfItems"),
1112
+ enableSorting: !1,
1113
+ meta: {
1114
+ width: "10rem",
1115
+ textAlign: "right"
1116
+ },
1117
+ cell(y) {
1118
+ const f = Number(y.getValue()) || 0, e = y.row.original.purchaseOrder.items.some(ye);
1119
+ return f === 0 || e ? z("div", { class: "flex justify-end gap-4 items-center" }, [
1120
+ z(
1121
+ oe.FmTooltip,
1122
+ {},
1123
+ {
1124
+ content() {
1125
+ return e ? "The template is invalid due to invalid unit on some of the items. Please update this template." : "The template is invalid due to deleted ingredients. Please update this template.";
1126
+ },
1127
+ default() {
1128
+ return z(oe.FmIcon, {
1129
+ name: "error",
1130
+ color: "system-error-300",
1131
+ size: "sm"
1132
+ });
1133
+ }
1134
+ }
1135
+ ),
1136
+ f
1137
+ ]) : f;
1138
+ }
1139
+ },
1140
+ {
1141
+ id: "enabledLocations",
1142
+ accessorKey: "purchaseOrder.locations.length",
1143
+ header: () => "Enabled outlets",
1144
+ cell(y) {
1145
+ var e;
1146
+ const f = (e = y.row.original.locations) == null ? void 0 : e.length;
1147
+ return f ? `${f}` : "All";
1148
+ },
1149
+ enableSorting: !1,
1150
+ meta: {
1151
+ width: "10rem",
1152
+ textAlign: "right"
1153
+ }
1154
+ },
1155
+ {
1156
+ id: "ref",
1157
+ accessorKey: "purchaseOrder.ref",
1158
+ header: () => r("inventory.transfer.table.reference"),
1159
+ enableSorting: !1,
1160
+ size: "auto"
1161
+ },
1162
+ {
1163
+ id: "action",
1164
+ cell(y) {
1165
+ const f = y.row.original, e = [
1166
+ V[I.Details],
1167
+ V[I.Edit],
1168
+ V[I.Delete]
1169
+ ];
1170
+ return be(e, (T) => g(T, f));
1171
+ },
1172
+ enableSorting: !1,
1173
+ size: 40,
1174
+ meta: {
1175
+ cellClass: "",
1176
+ headerClass: ""
1177
+ }
1178
+ }
1179
+ ],
1180
+ templates: i,
1181
+ loading: n,
1182
+ fetchTemplates: m,
1183
+ loadTemplate: h
1184
+ };
1185
+ }
1186
+ );
1187
+ function wt(t, r, a) {
1188
+ const c = (a == null ? void 0 : a.abbrev) ?? r.abbrev;
1189
+ return `${O(t, !1)} ${c}`;
1190
+ }
1191
+ export {
1192
+ R as P,
1193
+ fe as a,
1194
+ mt as b,
1195
+ wt as f,
1196
+ ye as t,
1197
+ xe as u
1198
+ };