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

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