@feedmepos/mf-inventory-portal 0.0.23-dev.4 → 0.0.23-dev.41

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