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

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