@feedmepos/mf-inventory-portal 0.0.22-dev.5 → 0.0.22-dev.50

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