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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (248) hide show
  1. package/dist/App-BxpqrT2x.js +1445 -0
  2. package/dist/{ApprovalView-RaXuWWSu.js → ApprovalView-DZBM9n1Y.js} +26 -25
  3. package/dist/{BindingsDialog-DomvXijP.js → BindingsDialog-jjHrmqY_.js} +2 -2
  4. package/dist/{BindingsPicker-DGnzxEs7.js → BindingsPicker-Dv1KwHIQ.js} +2 -2
  5. package/dist/{BindingsTable-DfG9kWrv.js → BindingsTable-Ch_TlrZu.js} +10 -10
  6. package/dist/BulkReceiveRequestPage-BVB3PNxF.js +2839 -0
  7. package/dist/{ChangeLocationComponent.vue_vue_type_script_setup_true_lang-CVekIoiN.js → ChangeLocationComponent.vue_vue_type_script_setup_true_lang-DpHYhOmI.js} +1 -1
  8. package/dist/{ClosingDraftView-C3n66bbh.js → ClosingDraftView-DQQkWYOh.js} +748 -746
  9. package/dist/ClosingHistoryView-CXXd0Csp.js +769 -0
  10. package/dist/{ClosingTemplateView-DwGloYxn.js → ClosingTemplateView-Bf5Ivxjw.js} +22 -21
  11. package/dist/{CustomPrintTemplatePreview.vue_vue_type_script_setup_true_lang-9eY_r8LF.js → CustomPrintTemplatePreview.vue_vue_type_script_setup_true_lang-C3Y_rwNE.js} +1 -1
  12. package/dist/{DefaultView-JC_e4xgC.js → DefaultView-Bt8ZFV10.js} +2 -2
  13. package/dist/{DeliveryOrderPrintPreview-BBCvI67S.js → DeliveryOrderPrintPreview-BS5ZKe1f.js} +15 -15
  14. package/dist/{EmailDialog.vue_vue_type_script_setup_true_lang-H4FWc9ga.js → EmailDialog.vue_vue_type_script_setup_true_lang-BvDFKrFF.js} +10077 -9950
  15. package/dist/FeatureCapabilityBadge.vue_vue_type_script_setup_true_lang-B389iY-f.js +48 -0
  16. package/dist/FeatureCapabilityGate-BAOroN-j.js +82 -0
  17. package/dist/FeaturePageGate.vue_vue_type_script_setup_true_lang-Xapa8xyy.js +189 -0
  18. package/dist/{FmDateRangePickerChip.vue_vue_type_script_setup_true_lang-Q8Mptiv3.js → FmDateRangePickerChip.vue_vue_type_script_setup_true_lang-CgbvPK8u.js} +1 -1
  19. package/dist/{FmFilterableMenuOptions.vue_vue_type_script_setup_true_lang-CE1_yyHe.js → FmFilterableMenuOptions.vue_vue_type_script_setup_true_lang-DnCj1qv6.js} +2 -2
  20. package/dist/{FmInventoryTableToolbar.vue_vue_type_script_setup_true_lang-CGJi3f86.js → FmInventoryTableToolbar.vue_vue_type_script_setup_true_lang-CUb4VGOc.js} +2 -2
  21. package/dist/{FmMultiselectDialog-DCaRlBIy.js → FmMultiselectDialog-Bz8bNuK2.js} +2 -2
  22. package/dist/FmMultiselectDialog-CosTDuNE.js +123 -0
  23. package/dist/{FmUnitInput.vue_vue_type_script_setup_true_lang-ClaLVtpK.js → FmUnitInput.vue_vue_type_script_setup_true_lang-3OrHiybe.js} +105 -99
  24. package/dist/ImportView-BoTmcCyn.js +1540 -0
  25. package/dist/{IngredientsView-DPj9lBTK.js → IngredientsView-VED94pGW.js} +691 -689
  26. package/dist/{IntegrationExplorerView-CO2wpUR_.js → IntegrationExplorerView-B9ZY9hG1.js} +1537 -1620
  27. package/dist/IntegrationPlatformView-Bar1zj3R.js +13385 -0
  28. package/dist/{IntegrationView-DIeZoey0.js → IntegrationView-BvzBDBGp.js} +2604 -2565
  29. package/dist/{InventoryBindingForm-Cj4_Chue.js → InventoryBindingForm-DWhXHIaL.js} +1 -1
  30. package/dist/InventoryBindingForm.vue_vue_type_script_setup_true_lang-mZRrPywY.js +472 -0
  31. package/dist/{InventoryBindingSummary-yzGzd7jJ.js → InventoryBindingSummary-Imo2J8O2.js} +1 -1
  32. package/dist/JsonViewer.vue_vue_type_script_setup_true_lang-C_hg75l0.js +25 -0
  33. package/dist/NumberPrecisionInput.vue_vue_type_script_setup_true_lang-CChCnKxa.js +79 -0
  34. package/dist/PlanTierBadge.vue_vue_type_script_setup_true_lang-CM3gtYZo.js +19 -0
  35. package/dist/PlanUpgradeDialog.vue_vue_type_script_setup_true_lang-0F-yOcPC.js +79 -0
  36. package/dist/PremiumUpgradePage.vue_vue_type_script_setup_true_lang-DGAxPOEh.js +58 -0
  37. package/dist/ProductionRunDetailPage-KFKeWhhY.js +2317 -0
  38. package/dist/{ProductionRunLifecycleDialogs.vue_vue_type_script_setup_true_lang-BYyiiAWb.js → ProductionRunLifecycleDialogs.vue_vue_type_script_setup_true_lang-CobaPkUr.js} +3053 -3163
  39. package/dist/ProductionRunPage-BrXsPo-A.js +954 -0
  40. package/dist/{PublishView-CPK9NeVF.js → PublishView-_k3N44Pl.js} +3 -3
  41. package/dist/{PurchaseOrderPrintPreview-DosqWQeN.js → PurchaseOrderPrintPreview-DXVEhy-G.js} +17 -17
  42. package/dist/{ReceiveRequestView-BxSkpK2t.js → ReceiveRequestView-ByWddqiL.js} +17 -16
  43. package/dist/RecipeView-C29uNZxj.js +3272 -0
  44. package/dist/SettingsView-CyE6ZM8x.js +1005 -0
  45. package/dist/StockView-BBR404Ie.js +3003 -0
  46. package/dist/{SubsidiaryTreeDialog.vue_vue_type_script_setup_true_lang-GdGJCuc0.js → SubsidiaryTreeDialog.vue_vue_type_script_setup_true_lang-Cmnk66T9.js} +1 -1
  47. package/dist/{SupplierView-BKxKoi_0.js → SupplierView-CIB5GCwp.js} +304 -301
  48. package/dist/{SurchargeView-Db4cwhZv.js → SurchargeView-DNtEbO7I.js} +7 -7
  49. package/dist/{SystemTrailDialog.vue_vue_type_script_setup_true_lang-CpkF77Ow.js → SystemTrailDialog.vue_vue_type_script_setup_true_lang-ClCi5rLI.js} +2 -2
  50. package/dist/TableActionableRow.vue_vue_type_script_setup_true_lang-gJQQKKAC.js +71 -0
  51. package/dist/TemplatePublishDialog.vue_vue_type_script_setup_true_lang-C19KOLrQ.js +332 -0
  52. package/dist/TransferDetails.vue_vue_type_script_setup_true_lang-DD5nMsrn.js +4953 -0
  53. package/dist/TransferTemplateView-BftwH1_W.js +2347 -0
  54. package/dist/{UnitCostHistoryView-CqcyjCCd.js → UnitCostHistoryView-CE-1joTV.js} +4 -4
  55. package/dist/{UnitDisplayControl.vue_vue_type_script_setup_true_lang-DO80_8SZ.js → UnitDisplayControl.vue_vue_type_script_setup_true_lang-reJFavQF.js} +4 -4
  56. package/dist/{UnitView-BqdK1AM_.js → UnitView-T-Vo8IpV.js} +111 -106
  57. package/dist/{WarehouseView-COJM9IXM.js → WarehouseView-CzQcj5VY.js} +12 -11
  58. package/dist/{WastageTemplateView-DW3viTHN.js → WastageTemplateView-Cm5_V2zN.js} +19 -18
  59. package/dist/api/bill.d.ts +4 -2
  60. package/dist/api/bill.spec.d.ts +1 -0
  61. package/dist/api/closing.d.ts +1 -0
  62. package/dist/api/feature-flags.d.ts +4 -0
  63. package/dist/api/integration-sync-log.d.ts +0 -13
  64. package/dist/api/license.d.ts +0 -2
  65. package/dist/api/netsuite-explorer.d.ts +1 -0
  66. package/dist/api/stock.d.ts +1 -1
  67. package/dist/{app-yvK__CBL.js → app-DnOtng5V.js} +10177 -10126
  68. package/dist/app.d.ts +151 -164
  69. package/dist/app.js +1 -1
  70. package/dist/bulk-edit-simulation.helper-BZRyNbpM.js +178 -0
  71. package/dist/{closing-template-DezidSM0.js → closing-template-BiJRchG9.js} +4 -4
  72. package/dist/components/FeatureCapabilityBadge.vue.d.ts +4 -0
  73. package/dist/components/FeatureCapabilityGate.spec.d.ts +1 -0
  74. package/dist/components/FeatureCapabilityGate.vue.d.ts +5 -0
  75. package/dist/components/FeatureGateLayout.vue.d.ts +11 -0
  76. package/dist/components/FeaturePageGate.spec.d.ts +1 -0
  77. package/dist/components/FeaturePageGate.vue.d.ts +34 -0
  78. package/dist/components/FmAdminCollapsiblePanel.vue.d.ts +1 -1
  79. package/dist/components/FmDroppableField.vue.d.ts +1 -1
  80. package/dist/components/FmInventoryTableToolbar.vue.d.ts +2 -2
  81. package/dist/components/FmUnitInputProps.d.ts +1 -0
  82. package/dist/components/FmUnitInputRules.d.ts +1 -1
  83. package/dist/components/HrmPermissionGuard.vue.d.ts +1 -1
  84. package/dist/components/NumberPrecisionInput.spec.d.ts +1 -0
  85. package/dist/{views/ingredient-group/IngredientGroupView.vue.d.ts → components/PremiumUpgradePage.vue.d.ts} +0 -1
  86. package/dist/components/TemplatePublishDialog.d.ts +2 -0
  87. package/dist/components/TemplatePublishDialog.spec.d.ts +1 -0
  88. package/dist/composable/defineApi.d.ts +1 -1
  89. package/dist/{date2-2XjepIqc.js → date2-Bzlk0lSj.js} +1 -1
  90. package/dist/{dayjs.min-CNp5DLBB.js → dayjs.min-B8gqMYa7.js} +1 -1
  91. package/dist/{decimal-Z7oJdGk8.js → decimal-utE08Cjv.js} +2 -2
  92. package/dist/{defineDeepModel-CMxJn_H2.js → defineDeepModel-D_tKNP-n.js} +5 -5
  93. package/dist/{duplicate-template-BetV5oy_.js → duplicate-template-lCi99jVD.js} +1 -1
  94. package/dist/{feature-CkWaZ-5K.js → feature-Zeyz4pJe.js} +2089 -2854
  95. package/dist/feature-flags/core.d.ts +4 -2
  96. package/dist/feature-flags/portal-feature-catalog.d.ts +1 -6
  97. package/dist/feature-flags/portal-feature-catalog.spec.d.ts +1 -0
  98. package/dist/feature-flags/vue.d.ts +24 -1
  99. package/dist/feature-flags/vue.spec.d.ts +1 -0
  100. package/dist/{format-time-from-id-DatSI9uD.js → format-time-from-id-v_KvI4jM.js} +1 -1
  101. package/dist/{format-unit-display-DM5We5cx.js → format-unit-display-C8oexlpM.js} +209 -208
  102. package/dist/helper/country.spec.d.ts +1 -0
  103. package/dist/helper/menu-usage-module.d.ts +2 -1
  104. package/dist/helper/number.d.ts +5 -1
  105. package/dist/helper/rules.d.ts +1 -1
  106. package/dist/{id-to-date-Dxw2jKhy.js → id-to-date-Doi1vn9Q.js} +1 -1
  107. package/dist/{import-export.helper-BOmADwUw.js → import-export.helper-DyRPa4wa.js} +17 -17
  108. package/dist/{index-CIH9NCvs.js → index-B-SVjo8N.js} +1 -1
  109. package/dist/{index-ClYgfwW7.js → index-Bl8qrC1m.js} +2234 -2163
  110. package/dist/{JsonViewer.vue_vue_type_script_setup_true_lang-ig2zSXAB.js → index-C25C1Dg7.js} +1074 -1066
  111. package/dist/{index-7fz5sGDO.js → index-DZ9i-1uy.js} +3 -3
  112. package/dist/index-eGvSlWMU.js +1892 -0
  113. package/dist/layout/SingleColumnLayout.vue.d.ts +1 -1
  114. package/dist/{lz-string-CCsc2X7t.js → lz-string-pPNhTzCj.js} +1 -1
  115. package/dist/menu-usage-module-Bq_KLsO4.js +74 -0
  116. package/dist/{netsuite-COumFXC2.js → netsuite-C5s0JXRA.js} +254 -263
  117. package/dist/netsuite-explorer-BF-bujxD.js +79 -0
  118. package/dist/{predefined-templates-Bw9A9LNA.js → predefined-templates-C6hmqqhm.js} +1 -1
  119. package/dist/production-run-list-DR1WsaBR.js +61 -0
  120. package/dist/{purchase-order-template-BaZjdGq8.js → purchase-order-template-C0XlITpK.js} +1 -1
  121. package/dist/{recalculationUtils-t32wAurN.js → recalculationUtils-CnzCEyIJ.js} +1 -1
  122. package/dist/router/name.d.ts +2 -2
  123. package/dist/{row-action.enum-BDeudY4d.js → row-action.enum-Ci5mHFdS.js} +1 -1
  124. package/dist/rules-rAD4INHX.js +243 -0
  125. package/dist/{stock-B59sfN28.js → stock-CukGlv0u.js} +1 -1
  126. package/dist/stock-DUQYl3xe.js +78 -0
  127. package/dist/stores/feature.d.ts +41 -11
  128. package/dist/stores/feature.load-state.spec.d.ts +1 -0
  129. package/dist/stores/inventory.d.ts +0 -47
  130. package/dist/stores/inventory.no-location.spec.d.ts +1 -0
  131. package/dist/stores/supplier.d.ts +1 -1
  132. package/dist/stores/warehouse.d.ts +1 -1
  133. package/dist/style.css +1 -1
  134. package/dist/{supplier-DnbLJ_cS.js → supplier-CDPdi2B5.js} +2 -2
  135. package/dist/{surcharge-C1uE3uQa.js → surcharge-XABFccMt.js} +1 -1
  136. package/dist/tsconfig.app.tsbuildinfo +1 -1
  137. package/dist/{uom-rules-DjfyrFHJ.js → uom-rules-BbNTM-Xw.js} +1 -1
  138. package/dist/{use-ingredient-select-dialog-7A7fWyEH.js → use-ingredient-select-dialog-CxrFXfoM.js} +2 -2
  139. package/dist/use-inventory-binding-dialog-BZpguHE1.js +113 -0
  140. package/dist/{use-template-enabled-locations-C-Hqqgzt.js → use-template-enabled-locations-B9n-uc36.js} +2 -2
  141. package/dist/{use-transfer-locations-CqsXvOI2.js → use-transfer-locations-z78M6XgR.js} +14 -14
  142. package/dist/{useHrmPermission-BzwD3Ctc.js → useHrmPermission-CfMWeFGZ.js} +1 -1
  143. package/dist/{useNavigationMenu-PrZg9HS7.js → useNavigationMenu-B6dCSflb.js} +111 -117
  144. package/dist/{useSseClient-FCyLWq8k.js → useSseClient-ICUObHUB.js} +1 -1
  145. package/dist/views/changelog/composables/use-snapshot-diff.d.ts +2 -2
  146. package/dist/views/closing-draft/composables/use-closing-draft-table.d.ts +1 -1
  147. package/dist/views/closing-draft/helpers/draft-status-to-class-name.helper.d.ts +1 -1
  148. package/dist/views/import/helper/submit-rows.d.ts +1 -1
  149. package/dist/views/ingredients/components/inventory-binding/InventoryBindingForm.vue.d.ts +0 -1
  150. package/dist/views/ingredients/components/inventory-binding/composables/use-inventory-binding-dialog.d.ts +0 -1
  151. package/dist/views/ingredients/components/inventory-binding/recipe-amount-validation.spec.d.ts +1 -0
  152. package/dist/views/ingredients/components/inventory-binding/v2/InventoryBindingFormV2.vue.d.ts +0 -1
  153. package/dist/views/ingredients/components/inventory-binding/v2/composables/use-inventory-binding-dialog.d.ts +0 -1
  154. package/dist/views/ingredients/helper/is-linked-ingredient-error.d.ts +3 -1
  155. package/dist/views/{ingredient-group/components/ingredient-group-rule-field/IngredientGroupRuleField.vue.d.ts → integration/IntegrationPlatformView.vue.d.ts} +11 -24
  156. package/dist/views/integration/components/Synergy/importFn.spec.d.ts +1 -0
  157. package/dist/views/integration/components/Xilnex/importFn.spec.d.ts +1 -0
  158. package/dist/views/integration/helper/opening-balance.d.ts +22 -0
  159. package/dist/views/integration/helper/opening-balance.spec.d.ts +1 -0
  160. package/dist/views/production-run/ProductionRunDetailPage.spec.d.ts +1 -0
  161. package/dist/views/{integration/components/IntegrationSyncLogTab.vue.d.ts → production-run/ProductionRunDetailPage.vue.d.ts} +2 -2
  162. package/dist/views/production-run/ProductionRunPage.vue.d.ts +2 -0
  163. package/dist/views/production-run/features/detail/ProductionRunItemsTable.vue.d.ts +2 -2
  164. package/dist/views/production-run/features/detail/ProductionRunOverviewTab.vue.d.ts +4 -4
  165. package/dist/views/production-run/features/detail/use-production-run-detail.d.ts +19 -9
  166. package/dist/views/production-run/features/lifecycle/CancelRunDialog.vue.d.ts +4 -4
  167. package/dist/views/production-run/features/lifecycle/CloseRunDialog.vue.d.ts +4 -4
  168. package/dist/views/production-run/features/lifecycle/ProductionRunLifecycleDialogs.vue.d.ts +14 -14
  169. package/dist/views/production-run/features/lifecycle/TargetReachedDialog.vue.d.ts +4 -4
  170. package/dist/views/production-run/features/planning/ProductionRunFormDialog.vue.d.ts +4 -4
  171. package/dist/views/production-run/features/planning/ProductionRunPlanner.vue.d.ts +1 -1
  172. package/dist/views/production-run/features/planning/use-production-run-duplicate-sources.d.ts +6 -6
  173. package/dist/views/production-run/shared/helpers/production-run-navigation.d.ts +0 -1
  174. package/dist/views/production-run/shared/model/production-run-list.d.ts +1 -1
  175. package/dist/views/production-run/shared/ui/ProductionRunInfoBadge.vue.d.ts +1 -1
  176. package/dist/views/production-run/shared/ui/ProductionRunInfoText.vue.d.ts +1 -1
  177. package/dist/views/production-run/shared/ui/ProductionRunScrollHint.vue.d.ts +2 -2
  178. package/dist/views/production-run/shared/ui/ProductionRunTextarea.vue.d.ts +3 -3
  179. package/dist/views/receive-request/composables/netsuite-order-label.d.ts +11 -0
  180. package/dist/views/receive-request/composables/netsuite-order-label.spec.d.ts +1 -0
  181. package/dist/views/receive-request/composables/use-process-purchase-order.d.ts +1 -1
  182. package/dist/views/receive-request/composables/use-receive-request-form.d.ts +9 -9
  183. package/dist/views/receive-request/composables/use-receive-request-form.spec.d.ts +1 -0
  184. package/dist/views/receive-request/composables/use-receive-request-table.d.ts +7 -7
  185. package/dist/views/receive-request/import/export.spec.d.ts +1 -0
  186. package/dist/views/receive-request-bulk/BulkReceiveRequestPage.vue.d.ts +2 -0
  187. package/dist/views/receive-request-bulk/components/CreateTransferWizard.spec.d.ts +1 -0
  188. package/dist/views/receive-request-bulk/composables/use-bulk-receive-request-form.d.ts +20 -20
  189. package/dist/views/receive-request-bulk/composables/use-bulk-receive-request-form.readiness.spec.d.ts +1 -0
  190. package/dist/views/receive-request-bulk/composables/use-bulk-receive-request-table.d.ts +2 -2
  191. package/dist/views/recipe/components/recipe-bulk-editor/components/ModificationCard.spec.d.ts +1 -0
  192. package/dist/views/recipe/helper/bulk-edit-simulation.helper.d.ts +0 -1
  193. package/dist/views/recipe/helper/import-recipe.d.ts +32 -2
  194. package/dist/views/recipe/helper/import-recipe.spec.d.ts +1 -0
  195. package/dist/views/settings/PlanLicenseDisplay.spec.d.ts +1 -0
  196. package/dist/views/settings/PlanLicenseDisplay.vue.d.ts +2 -0
  197. package/dist/views/stock/components/StockRecordCard.spec.d.ts +1 -0
  198. package/dist/views/stock/components/StockRecordCard.vue.d.ts +19 -865
  199. package/dist/views/stock/components/dialog/AmendAdjustmentForm.spec.d.ts +1 -0
  200. package/dist/views/stock/components/dialog/BillInventoryInfoDialog.spec.d.ts +1 -0
  201. package/dist/views/stock/components/dialog/BillInventoryInfoDialog.vue.d.ts +36 -0
  202. package/dist/views/stock/components/dialog/ConvertSkuDialog.spec.d.ts +1 -0
  203. package/dist/views/stock/composables/use-last-closing-summary.d.ts +4 -0
  204. package/dist/views/stock/composables/use-last-closing-summary.spec.d.ts +1 -0
  205. package/dist/views/transfer-template/components/transfer-template-form/composables/use-transfer-template-items.spec.d.ts +1 -0
  206. package/dist/views/transfer-template/helpers/template-item.error.helper.spec.d.ts +1 -0
  207. package/dist/views/unit/composables/use-unit-form.spec.d.ts +1 -0
  208. package/dist/views/warehouse/components/WarehouseForm.vue.d.ts +2 -2
  209. package/dist/vue-DBxqzbt5.js +295 -0
  210. package/dist/{vue-i18n-C34f-Tph.js → vue-i18n-CdbY8MsR.js} +539 -539
  211. package/dist/{xlsx.util-X4amwe_k.js → xlsx.util-CD5NablT.js} +2 -2
  212. package/package.json +71 -66
  213. package/dist/App-DVHgBTHP.js +0 -1499
  214. package/dist/BulkReceiveRequestView-DxHWrfbi.js +0 -2656
  215. package/dist/ClosingHistoryView-kdpYGy1Y.js +0 -761
  216. package/dist/DeprecateSoonWarningDialog.vue_vue_type_script_setup_true_lang-5Cc08Svt.js +0 -58
  217. package/dist/FeatureCapabilityBadge.vue_vue_type_script_setup_true_lang-C1C8aDA6.js +0 -61
  218. package/dist/FmMultiselectDialog-yVPY5aBV.js +0 -77
  219. package/dist/ImportView-DQrVMzxN.js +0 -1302
  220. package/dist/IngredientBindedItem.vue_vue_type_script_setup_true_lang-7lT5UZc8.js +0 -51
  221. package/dist/IngredientGroupView-BMUnEaY7.js +0 -1000
  222. package/dist/InventoryBindingForm.vue_vue_type_script_setup_true_lang-CaBOK7NC.js +0 -563
  223. package/dist/NumberPrecisionInput.vue_vue_type_script_setup_true_lang-DzzTPdyF.js +0 -72
  224. package/dist/ProductionRunDetailView-Cw-ecaey.js +0 -2312
  225. package/dist/ProductionRunView-C11eseXQ.js +0 -930
  226. package/dist/RecipeView-oHDWsT0P.js +0 -3624
  227. package/dist/SettingsView-QlUNwFhM.js +0 -983
  228. package/dist/StockView-a8LbVZ_7.js +0 -2614
  229. package/dist/TableActionableRow.vue_vue_type_script_setup_true_lang-DAMpuZ1X.js +0 -84
  230. package/dist/TemplatePublishDialog.vue_vue_type_script_setup_true_lang-CCCj4WVF.js +0 -299
  231. package/dist/TransferDetails.vue_vue_type_script_setup_true_lang-CFNPXqt5.js +0 -4796
  232. package/dist/TransferTemplateView-CzwxOBMQ.js +0 -2326
  233. package/dist/menu-usage-module-BdjYEk3s.js +0 -57
  234. package/dist/number-gSLvxNqA.js +0 -138
  235. package/dist/portal-feature-catalog-yGIESKTc.js +0 -246
  236. package/dist/random-CSbEbElR.js +0 -10
  237. package/dist/rules-C1btu0Md.js +0 -98
  238. package/dist/stock-BF86TMW0.js +0 -75
  239. package/dist/use-inventory-binding-dialog-Cc1tjTfV.js +0 -152
  240. package/dist/usePromise-CbVUCxhj.js +0 -29
  241. package/dist/views/ingredient-group/components/ingredient-group-dialog/IngredientGroupDialog.vue.d.ts +0 -31
  242. package/dist/views/ingredient-group/components/ingredient-group-dialog/IngredientGroupDialogProps.d.ts +0 -10
  243. package/dist/views/ingredient-group/components/ingredient-group-form/IngredientGroupForm.vue.d.ts +0 -21
  244. package/dist/views/ingredient-group/components/ingredient-group-form/IngredientGroupFormProps.d.ts +0 -12
  245. package/dist/views/ingredient-group/composables/use-ingredient-group-actions.d.ts +0 -24
  246. package/dist/views/ingredient-group/composables/use-ingredient-group-rule-item.d.ts +0 -31
  247. package/dist/views/ingredient-group/composables/use-ingredient-group-table.d.ts +0 -77
  248. package/dist/views/integration/composables/use-integration-sync-log.d.ts +0 -45
@@ -0,0 +1,3003 @@
1
+ import { defineComponent as ye, createElementBlock as E, openBlock as p, createElementVNode as e, createVNode as b, toDisplayString as r, unref as o, ref as z, h as Fe, computed as N, watch as ge, resolveComponent as P, createBlock as ee, isRef as Ne, withCtx as U, Fragment as ae, renderList as fe, createCommentVNode as Q, normalizeClass as he, reactive as _t, normalizeStyle as Qe, createTextVNode as ve, mergeModels as st, useModel as Ct, onMounted as Ze, nextTick as Bt, watchEffect as Vt, renderSlot as at, onUnmounted as Dt, Teleport as It, normalizeProps as lt, mergeProps as We } from "vue";
2
+ import { u as Mt, _ as Tt } from "./SingleColumnLayout.vue_vue_type_script_setup_true_lang-DpwneGOV.js";
3
+ import { u as Ce, c as Oe, a as Le, F as rt, v as Ht, s as K, E as ue, t as Et, G as Ut, d as Rt, B as Pt, h as Nt, e as it, M as je, O as Ee } from "./app-DnOtng5V.js";
4
+ import { u as ze } from "./stock-DUQYl3xe.js";
5
+ import { c as Ot } from "./component-BmLAdDiY.js";
6
+ import { _ as kt, o as Lt } from "./UnitDisplayControl.vue_vue_type_script_setup_true_lang-reJFavQF.js";
7
+ import { _ as Je, S as Ke, g as bt, a as zt } from "./SubsidiaryTreeDialog.vue_vue_type_script_setup_true_lang-Cmnk66T9.js";
8
+ import { _ as Yt } from "./FeatureCapabilityBadge.vue_vue_type_script_setup_true_lang-B389iY-f.js";
9
+ import { useI18n as _e, useCoreStore as et } from "@feedmepos/mf-common";
10
+ import { u as ht, i as De } from "./id-to-date-Doi1vn9Q.js";
11
+ import { useSnackbar as xe, useDialog as Ye, useProxiedModel as qe, components as qt, useBreakpoints as Gt } from "@feedmepos/ui-library";
12
+ import { defineStore as Wt } from "pinia";
13
+ import { F as Ge } from "./FmAdminBadge-DlplQOHb.js";
14
+ import { g as Ie, a as $e, h as Kt, t as Me, I as ut, f as tt, A as Xt, M as Jt, i as Qt, j as ct, k as gt, l as ot, R as Zt, d as Re, m as eo } from "./rules-rAD4INHX.js";
15
+ import { u as Be } from "./stock-CukGlv0u.js";
16
+ import { u as to } from "./use-inventory-binding-dialog-BZpguHE1.js";
17
+ import { a as xt } from "./FmMultiselectDialog-Bz8bNuK2.js";
18
+ import { d as we } from "./dayjs.min-B8gqMYa7.js";
19
+ import { _ as oo } from "./NumberPrecisionInput.vue_vue_type_script_setup_true_lang-CChCnKxa.js";
20
+ import { g as no } from "./decimal-utE08Cjv.js";
21
+ import { c as St, f as nt, b as so, d as ao, t as dt, a as mt, p as lo, n as ro } from "./date2-Bzlk0lSj.js";
22
+ import { i as io } from "./FmDateRangePickerChip.vue_vue_type_script_setup_true_lang-CgbvPK8u.js";
23
+ import { _ as uo } from "./empty-placeholder-B0QU467o.js";
24
+ import { F as wt } from "./FeatureCapabilityGate-BAOroN-j.js";
25
+ import "./feature-Zeyz4pJe.js";
26
+ import { u as $t } from "./useHrmPermission-CfMWeFGZ.js";
27
+ import { F as ft } from "./index-eGvSlWMU.js";
28
+ import { _ as co } from "./TableActionableRow.vue_vue_type_script_setup_true_lang-gJQQKKAC.js";
29
+ import { _ as mo } from "./FmInventoryTableToolbar.vue_vue_type_script_setup_true_lang-CUb4VGOc.js";
30
+ import { u as fo } from "./useSseClient-ICUObHUB.js";
31
+ import { u as vo } from "./netsuite-C5s0JXRA.js";
32
+ import { P as po, J as yo } from "./app-C39bYJmq.js";
33
+ var Pe = /* @__PURE__ */ ((j) => (j.History = "History", j.Convert = "Convert", j.Adjust = "Adjust", j))(Pe || {});
34
+ const _o = [
35
+ {
36
+ translationKey: "inventory.stock.action.history",
37
+ color: "text-neutral-700",
38
+ value: "History"
39
+ /* History */
40
+ }
41
+ ], ko = [
42
+ {
43
+ translationKey: "inventory.stock.action.history",
44
+ color: "text-neutral-700",
45
+ value: "History"
46
+ /* History */
47
+ },
48
+ {
49
+ translationKey: "inventory.stock.action.convert",
50
+ color: "text-neutral-700",
51
+ value: "Convert"
52
+ /* Convert */
53
+ },
54
+ {
55
+ translationKey: "inventory.stock.action.adjust",
56
+ color: "text-neutral-700",
57
+ value: "Adjust"
58
+ /* Adjust */
59
+ }
60
+ ], bo = { class: "flex items-center gap-8" }, ho = { class: "whitespace-nowrap" }, go = /* @__PURE__ */ ye({
61
+ __name: "StockHeaderPreview",
62
+ setup(j) {
63
+ const { t: f } = _e();
64
+ return (h, v) => (p(), E("div", bo, [
65
+ e("div", ho, r(o(f)("inventory.stock.prediction.daysRemaining")), 1),
66
+ b(Yt, {
67
+ tier: "standard",
68
+ category: "beta"
69
+ })
70
+ ]));
71
+ }
72
+ }), At = Wt("stockActions", () => {
73
+ const j = z(!1), f = Ce(), h = ze(), v = ht(), F = xe(), $ = Ye(), { t: u } = _e();
74
+ async function i() {
75
+ if (f._currentLocation) {
76
+ j.value = !0;
77
+ try {
78
+ await h.readStockBalance(), await v.readStockEstimateBalance();
79
+ } catch {
80
+ F.open({
81
+ title: u("inventory.stock.error.title"),
82
+ message: u("inventory.stock.error.message"),
83
+ type: "error"
84
+ });
85
+ } finally {
86
+ j.value = !1;
87
+ }
88
+ }
89
+ }
90
+ const _ = z();
91
+ async function L(x) {
92
+ var c, s, T;
93
+ if (!!!((s = (c = x.convert) == null ? void 0 : c.inventoryBindings) != null && s.length)) {
94
+ $.open({
95
+ title: u("inventory.stock.error.convert.title"),
96
+ message: u("inventory.stock.error.convert.message")
97
+ });
98
+ return;
99
+ }
100
+ try {
101
+ await h.readProductBalance();
102
+ } catch (H) {
103
+ F.open({
104
+ title: u("inventory.stock.error.title"),
105
+ message: u("inventory.stock.error.message"),
106
+ type: "error"
107
+ }), console.error("error on compute convert balance", H);
108
+ return;
109
+ }
110
+ const n = {
111
+ maxCount: ((T = h.productBalance.find(({ id: H }) => H === x._id)) == null ? void 0 : T.count) || 0,
112
+ sku: x,
113
+ show: !0,
114
+ "onUpdate:show"(H) {
115
+ _.value.show = H;
116
+ },
117
+ onSubmitted() {
118
+ i();
119
+ }
120
+ };
121
+ _.value = n;
122
+ }
123
+ const D = z();
124
+ async function k(x) {
125
+ const l = {
126
+ stock: x,
127
+ show: !0,
128
+ "onUpdate:show"(t) {
129
+ D.value.show = t;
130
+ },
131
+ onSubmitted() {
132
+ i();
133
+ }
134
+ };
135
+ D.value = l;
136
+ }
137
+ const d = z();
138
+ async function C(x) {
139
+ const l = {
140
+ sku: x,
141
+ show: !0,
142
+ "onUpdate:show"(t) {
143
+ d.value.show = t;
144
+ }
145
+ };
146
+ d.value = l;
147
+ }
148
+ function a(x, l) {
149
+ const t = Oe(l);
150
+ switch (x) {
151
+ case Pe.History:
152
+ C(t);
153
+ return;
154
+ case Pe.Convert:
155
+ L(t);
156
+ return;
157
+ case Pe.Adjust:
158
+ k(t);
159
+ return;
160
+ }
161
+ }
162
+ return {
163
+ fetchStockBalance: i,
164
+ onActionMenu: a,
165
+ stockHistoryProps: d,
166
+ showSkuHistory: C,
167
+ convertSkuDialogProps: _,
168
+ adjustSkuDialogProps: D
169
+ };
170
+ });
171
+ function xo() {
172
+ var $;
173
+ const j = Ce(), f = At(), h = et(), { t: v } = _e();
174
+ return {
175
+ columnDefs: [
176
+ {
177
+ accessorKey: "code",
178
+ header: () => v("inventory.stock.code"),
179
+ enableSorting: !0,
180
+ size: 300
181
+ },
182
+ {
183
+ accessorKey: "name",
184
+ header: () => v("inventory.stock.product"),
185
+ enableSorting: !0,
186
+ size: "auto"
187
+ },
188
+ {
189
+ id: "UOM",
190
+ header: () => v("inventory.stock.balance"),
191
+ cell(u) {
192
+ const i = u.row.original, _ = {
193
+ unit: i.unit,
194
+ sku: i,
195
+ amount: i.balance,
196
+ defaultTrackingMeasurement: i.trackingMeasurement ?? void 0
197
+ };
198
+ return Fe(kt, _);
199
+ },
200
+ size: 180
201
+ },
202
+ ...($ = h.sessionUser.value) != null && $.role.isAdmin ? [
203
+ {
204
+ accessorKey: "isInactive",
205
+ header: () => Fe(Ge, {}, () => `${v("inventory.ingredient.status.title")}`),
206
+ cell(u) {
207
+ const i = u.row.original.isInactive;
208
+ return Fe(
209
+ "span",
210
+ {
211
+ class: [
212
+ "inline-block px-3 py-1 rounded-full text-xs font-semibold",
213
+ i ? "bg-red-100 text-red-700" : "bg-green-100 text-green-700"
214
+ ].join(" ")
215
+ },
216
+ v(i ? "inventory.ingredient.status.inactive" : "inventory.ingredient.status.active")
217
+ );
218
+ },
219
+ enableSorting: !0
220
+ }
221
+ ] : [],
222
+ {
223
+ accessorKey: "day",
224
+ id: "expireDate",
225
+ header: () => Fe(go),
226
+ enableSorting: !0,
227
+ sortUndefined: "last",
228
+ cell(u) {
229
+ var C, a;
230
+ const i = u.row.original.day, _ = u.row.original.operator, L = (C = u.row.original.thresholds) == null ? void 0 : C.low, D = (a = u.row.original.thresholds) == null ? void 0 : a.mid;
231
+ if (typeof i != "number" || typeof L != "number" || typeof D != "number")
232
+ return Fe(Je, {
233
+ days: i,
234
+ operator: _
235
+ });
236
+ const k = i <= L ? Ke.low : i <= D ? Ke.mid : Ke.high;
237
+ return Fe(Je, {
238
+ days: i,
239
+ level: k
240
+ });
241
+ },
242
+ size: 200
243
+ },
244
+ {
245
+ id: "action",
246
+ cell(u) {
247
+ var i;
248
+ return Ot(
249
+ ((i = j._currentLocation) == null ? void 0 : i.type) === "restaurant" ? _o : ko,
250
+ (_) => f.onActionMenu(_, u.row.original)
251
+ );
252
+ },
253
+ enableSorting: !1,
254
+ size: 40,
255
+ meta: {
256
+ cellClass: "",
257
+ headerClass: ""
258
+ }
259
+ }
260
+ ]
261
+ };
262
+ }
263
+ const So = {
264
+ context: null,
265
+ error: null,
266
+ isRequired(j = "This field is required") {
267
+ return `${this.context ?? ""}`.length === 0 && (this.error = j), this;
268
+ },
269
+ isString(j = "Must be a valid string") {
270
+ return this.error ? this : (typeof this.context != "string" && (this.error ?? (this.error = j)), this);
271
+ },
272
+ toInt() {
273
+ return this.error ? this : (this.context = +this.context, this);
274
+ },
275
+ isInteger(j = "Must be an integer") {
276
+ return this.error ? this : (this.toInt(), isNaN(this.context) && (this.error = j), this);
277
+ },
278
+ min(j, f) {
279
+ if (this.error) return this;
280
+ try {
281
+ typeof this.context == "number" ? +this.context < j && (this.error = f ?? `Must be at least ${j}`) : Object.prototype.hasOwnProperty.call(this.context, "length") ? +this.context.length < j && (this.error = f ?? `Must be at least ${j}`) : this.error = "Length cannot be determined";
282
+ } catch {
283
+ this.error = "Length cannot be determined";
284
+ }
285
+ return this;
286
+ },
287
+ max(j, f) {
288
+ if (this.error) return this;
289
+ try {
290
+ typeof this.context == "number" ? +this.context > j && (this.error = f ?? `Must be at most ${j}`) : "length" in this.context ? +this.context.length > j && (this.error = f ?? `Must be at most ${j}`) : this.error = "Length cannot be determined";
291
+ } catch {
292
+ this.error = "Length cannot be determined";
293
+ }
294
+ return this;
295
+ }
296
+ };
297
+ function vt(j) {
298
+ return { ...So, context: j };
299
+ }
300
+ const wo = { class: "flex items-center" }, $o = { class: "fm-typo-en-title-md-800" }, Ao = { class: "flex flex-col gap-24 w-full" }, Fo = { class: "flex flex-col gap-8" }, jo = { class: "fm-typo-en-body-lg-600" }, Co = { class: "fm-typo-en-body-lg-400 text-fm-color-typo-secondary flex-grow" }, Bo = { class: "fm-typo-en-body-lg-600 text-fm-color-typo-error" }, Vo = { class: "flex flex-col p-16 gap-8" }, Do = { class: "flex flex-col gap-4" }, Io = { class: "fm-typo-en-body-md-600 text-fm-color-typo-secondary bg-fm-color-neutral-gray-100 border-b py-12 px-16" }, Mo = { class: "grid grid-cols-[auto_100px_100px_48px] xs:grid-cols-[auto_80px_120px_48px] gap-8 px-8 items-center" }, To = { class: "xs:col-span-3" }, Ho = { class: "flex gap-8" }, Eo = /* @__PURE__ */ ye({
301
+ __name: "ConvertSkuDialog",
302
+ props: {
303
+ sku: {},
304
+ maxCount: {},
305
+ show: { type: Boolean }
306
+ },
307
+ emits: ["update:show", "submitted"],
308
+ setup(j, { expose: f, emit: h }) {
309
+ const v = j, F = h, $ = to(), u = Le(), i = Be(), _ = xe(), { t: L } = _e(), D = z(0), k = z(null), d = N(() => u.skus), C = N(
310
+ () => {
311
+ var w, g;
312
+ return (((g = (w = v.sku) == null ? void 0 : w.convert) == null ? void 0 : g.inventoryBindings) ?? []).filter(
313
+ (G) => G.type === rt.enum.SKU
314
+ );
315
+ }
316
+ ), a = N({
317
+ get() {
318
+ return !!k.value;
319
+ },
320
+ set(w) {
321
+ w ? k.value = Oe(C.value) : (k.value = null, l.value = {}, D.value = Math.min(D.value, v.maxCount ?? 0));
322
+ }
323
+ }), x = z(!1);
324
+ ge([() => v.show], ([w]) => {
325
+ w && (D.value = 0);
326
+ });
327
+ const l = z({});
328
+ function t(w) {
329
+ return String(w ?? "").trim().length === 0;
330
+ }
331
+ function n(w) {
332
+ if (t(w)) return "Required";
333
+ const g = ut()(String(w));
334
+ return g !== !0 ? g : Number(w) >= 0 || "Must be zero or greater";
335
+ }
336
+ function c(w) {
337
+ const g = { ...l.value };
338
+ delete g[w], l.value = g;
339
+ }
340
+ function s() {
341
+ if (k.value && (Object.keys(l.value).length > 0 || k.value.some((w) => w.amount.amount < 0))) {
342
+ _.open({
343
+ title: "Invalid amount",
344
+ message: "Please correct the highlighted ingredient amounts.",
345
+ type: "error"
346
+ });
347
+ return;
348
+ }
349
+ Y(v.sku, Me(D.value), k.value);
350
+ }
351
+ function T(w) {
352
+ if (k.value)
353
+ return !0;
354
+ const g = vt(w).isInteger().max(v.maxCount ?? 0).error ?? "";
355
+ return g || !0;
356
+ }
357
+ function H(w) {
358
+ var R;
359
+ const g = (R = v.sku.convert) != null && R.measurement ? v.sku.unit.measurements.find((te) => {
360
+ var le;
361
+ return te.id === ((le = v.sku.convert) == null ? void 0 : le.measurement);
362
+ }) ?? null : null, G = Ie(v.sku.unit, g), q = Qt(+w);
363
+ return vt(q).isInteger().max(G).error ? "Precision cannot be more than " + G : !0;
364
+ }
365
+ const V = N(
366
+ () => {
367
+ var w, g;
368
+ return (w = v.sku.convert) != null && w.measurement ? (g = v.sku.unit.measurements.find((G) => {
369
+ var q;
370
+ return G.id === ((q = v.sku.convert) == null ? void 0 : q.measurement);
371
+ })) == null ? void 0 : g.abbrev : v.sku.unit.abbrev;
372
+ }
373
+ ), J = N(() => {
374
+ var q, M;
375
+ const g = Ht({
376
+ bindings: ((q = v.sku.convert) == null ? void 0 : q.inventoryBindings) ?? [],
377
+ skus: u.skus,
378
+ skuGroups: [],
379
+ recipes: u.recipes
380
+ }).inventoryBindings.filter((R) => "success" in R && R.success).map((R) => R).map((R) => R.binding);
381
+ return (M = k.value ?? g) == null ? void 0 : M.map((R) => {
382
+ var B, O, X, se, ne;
383
+ const te = u.skus.find((ie) => ie._id === R.id), le = ((B = R.measurement) == null ? void 0 : B.abbrev) ?? ((O = te == null ? void 0 : te.unit) == null ? void 0 : O.abbrev), re = (X = v.sku.convert) != null && X.measurement ? v.sku.unit.measurements.find((ie) => {
384
+ var de;
385
+ return ie.id === ((de = v.sku.convert) == null ? void 0 : de.measurement);
386
+ }) ?? null : null, A = Ie(v.sku.unit, re), m = H(`${D.value}`) === !0 ? $e(
387
+ Kt(
388
+ R.amount,
389
+ Me(+D.value, A)
390
+ ),
391
+ !1
392
+ ) : "0", S = (ne = (se = k.value) == null ? void 0 : se.find((ie) => ie.id === (te == null ? void 0 : te._id))) == null ? void 0 : ne.amount, y = S ? $e(S, !1) : null;
393
+ return {
394
+ sku: te,
395
+ convertAmount: y ?? m,
396
+ abbrev: le
397
+ };
398
+ });
399
+ }), I = z();
400
+ f({
401
+ validateInputs: () => {
402
+ var w, g;
403
+ (g = (w = I.value) == null ? void 0 : w.validateInputs) == null || g.call(w);
404
+ },
405
+ resetInputsValidation: () => {
406
+ var w, g;
407
+ (g = (w = I.value) == null ? void 0 : w.resetInputsValidation) == null || g.call(w);
408
+ },
409
+ resetInputs: () => {
410
+ var w, g;
411
+ (g = (w = I.value) == null ? void 0 : w.resetInputs) == null || g.call(w);
412
+ }
413
+ });
414
+ const W = qe(v, "show");
415
+ async function Y(w, g, G) {
416
+ x.value = !0;
417
+ try {
418
+ await i.convertSku({
419
+ conversions: [
420
+ {
421
+ doc: w,
422
+ amount: g,
423
+ overrides: G == null ? void 0 : G.map((q) => ({
424
+ ...q,
425
+ amount: {
426
+ ...q.amount,
427
+ amount: -1 * Math.abs(q.amount.amount)
428
+ // ensure truly negative
429
+ }
430
+ }))
431
+ }
432
+ ]
433
+ }), F("update:show", !1), F("submitted");
434
+ } catch (q) {
435
+ _.open({
436
+ title: "Something went wrong",
437
+ message: `Cannot convert ${w.name}. Please try again.`,
438
+ type: "error"
439
+ }), console.error("error at converting stock amount", w, g, q);
440
+ } finally {
441
+ x.value = !1;
442
+ }
443
+ }
444
+ function Z(w, g, G) {
445
+ if (n(g) !== !0) {
446
+ l.value = { ...l.value, [w]: g };
447
+ return;
448
+ }
449
+ c(w);
450
+ const q = +g;
451
+ k.value = G.map((M) => (M.id !== w || (M.amount = K.fromNumber(q)), M));
452
+ }
453
+ function oe(w) {
454
+ const g = d.value.find((G) => G._id === w);
455
+ return g ? bt(g.unit, !0) : [];
456
+ }
457
+ function ce(w, g) {
458
+ const G = oe(w), q = G.find((M) => M.value === g) ?? G.find((M) => M.value === null);
459
+ return q ? {
460
+ ...q,
461
+ label: q.abbrev
462
+ } : null;
463
+ }
464
+ function pe(w, g, G) {
465
+ let q;
466
+ if (g === null)
467
+ q = G.map((M) => (M.id !== w || (M.measurement = null), M)) ?? [];
468
+ else {
469
+ const M = d.value.find((R) => R._id === w);
470
+ q = G.map((R) => {
471
+ var te, le;
472
+ return R.id !== w || (R.measurement = (le = (te = M == null ? void 0 : M.unit) == null ? void 0 : te.measurements) == null ? void 0 : le.find((re) => re.id === g)), R;
473
+ }) ?? [];
474
+ }
475
+ k.value = q;
476
+ }
477
+ function ke(w, g) {
478
+ const G = g.filter((q) => q.id !== w);
479
+ c(w), k.value = G;
480
+ }
481
+ function be() {
482
+ const w = (k.value ?? []).map((g) => ({
483
+ ...g,
484
+ type: rt.enum.SKU
485
+ }));
486
+ $.promptIngredientsBinding(
487
+ w,
488
+ (g) => k.value = g,
489
+ v.sku._id
490
+ );
491
+ }
492
+ return ge(
493
+ () => v.show,
494
+ (w) => {
495
+ w || (k.value = null, l.value = {}, D.value = 0);
496
+ }
497
+ ), (w, g) => {
498
+ const G = P("FmTextField"), q = P("FmForm"), M = P("FmCard"), R = P("FmSwitch"), te = P("FmFormGroup"), le = P("FmSelect"), re = P("FmButton"), A = P("FmSideSheet");
499
+ return p(), ee(A, {
500
+ "dismiss-away": "",
501
+ modelValue: o(W),
502
+ "onUpdate:modelValue": g[3] || (g[3] = (m) => Ne(W) ? W.value = m : null),
503
+ "max-width": 500
504
+ }, {
505
+ "side-sheet-header": U(() => [
506
+ e("div", wo, [
507
+ e("div", $o, r(o(L)("inventory.stock.convert.title", { name: w.sku.name })), 1)
508
+ ])
509
+ ]),
510
+ default: U(() => [
511
+ e("div", Ao, [
512
+ b(q, {
513
+ ref_key: "formRef",
514
+ ref: I,
515
+ onValidationSuccess: s
516
+ }, {
517
+ default: U(() => [
518
+ b(G, {
519
+ disabled: x.value,
520
+ "model-value": D.value,
521
+ "onUpdate:modelValue": g[0] || (g[0] = (m) => D.value = m),
522
+ label: o(L)("inventory.stock.convert.amount"),
523
+ rules: [o(ut)(), T, H, o(tt)(0)],
524
+ "append-text": V.value,
525
+ "helper-text": k.value ? void 0 : `Max ${w.maxCount} ${V.value}`
526
+ }, null, 8, ["disabled", "model-value", "label", "rules", "append-text", "helper-text"])
527
+ ]),
528
+ _: 1
529
+ }, 512),
530
+ b(M, {
531
+ variant: "outlined",
532
+ class: "p-16"
533
+ }, {
534
+ default: U(() => [
535
+ e("div", Fo, [
536
+ e("div", jo, r(o(L)("inventory.stock.convert.deductionSummary")), 1),
537
+ (p(!0), E(ae, null, fe(J.value, (m) => {
538
+ var S, y;
539
+ return p(), E("div", {
540
+ key: (S = m.sku) == null ? void 0 : S._id,
541
+ class: "flex items-center"
542
+ }, [
543
+ e("div", Co, r((y = m.sku) == null ? void 0 : y.name), 1),
544
+ e("div", Bo, " -" + r(m.convertAmount) + " " + r(m.abbrev), 1)
545
+ ]);
546
+ }), 128))
547
+ ])
548
+ ]),
549
+ _: 1
550
+ }),
551
+ b(M, { variant: "outlined" }, {
552
+ default: U(() => [
553
+ e("div", Vo, [
554
+ b(R, {
555
+ value: "",
556
+ modelValue: a.value,
557
+ "onUpdate:modelValue": g[1] || (g[1] = (m) => a.value = m),
558
+ label: o(L)("inventory.stock.convert.overrideDeduction"),
559
+ "label-placement": "right"
560
+ }, null, 8, ["modelValue", "label"]),
561
+ a.value ? (p(), E(ae, { key: 0 }, [
562
+ b(te, {
563
+ modelValue: k.value,
564
+ rules: [o(Xt)(1, "Must have at least one ingredient binding")]
565
+ }, null, 8, ["modelValue", "rules"]),
566
+ e("div", Do, [
567
+ e("div", Io, r(o(L)("inventory.stock.convert.ingredients")), 1),
568
+ (p(!0), E(ae, null, fe(k.value, (m) => (p(), ee(te, {
569
+ key: m.id,
570
+ disabled: x.value,
571
+ modelValue: l.value[m.id] ?? +o($e)(m.amount ?? { amount: 1, precision: 0 }),
572
+ rules: [
573
+ n,
574
+ o(Jt)(
575
+ d.value.find((S) => S._id === m.id).unit,
576
+ m.measurement
577
+ )
578
+ ]
579
+ }, {
580
+ default: U(({ invalid: S }) => {
581
+ var y, B, O;
582
+ return [
583
+ e("div", Mo, [
584
+ e("div", To, r((y = d.value.find((X) => X._id === m.id)) == null ? void 0 : y.name), 1),
585
+ b(G, {
586
+ class: "xs:col-span-2",
587
+ disabled: x.value,
588
+ modelValue: l.value[m.id] ?? +o($e)(
589
+ m.amount ?? { amount: 1, precision: 0 }
590
+ ),
591
+ "onUpdate:modelValue": (X) => Z(m.id, X, k.value ?? []),
592
+ invalid: S
593
+ }, null, 8, ["disabled", "modelValue", "onUpdate:modelValue", "invalid"]),
594
+ b(le, {
595
+ disabled: x.value,
596
+ class: "translate-y-[2px]",
597
+ items: oe(m.id),
598
+ "model-value": (O = ce(m.id, (B = m.measurement) == null ? void 0 : B.id)) == null ? void 0 : O.value,
599
+ "onUpdate:modelValue": (X) => pe(m.id, X, k.value ?? []),
600
+ invalid: S
601
+ }, {
602
+ "helper-text": U(() => g[4] || (g[4] = [])),
603
+ _: 2
604
+ }, 1032, ["disabled", "items", "model-value", "onUpdate:modelValue", "invalid"]),
605
+ b(re, {
606
+ disabled: x.value,
607
+ type: "button",
608
+ variant: "tertiary",
609
+ icon: "delete",
610
+ onClick: (X) => ke(m.id, k.value ?? [])
611
+ }, null, 8, ["disabled", "onClick"])
612
+ ])
613
+ ];
614
+ }),
615
+ _: 2
616
+ }, 1032, ["disabled", "modelValue", "rules"]))), 128))
617
+ ]),
618
+ e("div", null, [
619
+ b(re, {
620
+ icon: "link",
621
+ label: o(L)("inventory.stock.convert.linkIngredient"),
622
+ variant: "plain",
623
+ onClick: be
624
+ }, null, 8, ["label"])
625
+ ])
626
+ ], 64)) : Q("", !0)
627
+ ])
628
+ ]),
629
+ _: 1
630
+ })
631
+ ])
632
+ ]),
633
+ "side-sheet-footer": U(() => [
634
+ e("div", Ho, [
635
+ b(re, {
636
+ loading: x.value,
637
+ label: o(L)("inventory.stock.convert.convertButton"),
638
+ onClick: g[2] || (g[2] = (m) => {
639
+ var S, y;
640
+ return (y = (S = I.value) == null ? void 0 : S.validateInputs) == null ? void 0 : y.call(S);
641
+ })
642
+ }, null, 8, ["loading", "label"])
643
+ ])
644
+ ]),
645
+ _: 1
646
+ }, 8, ["modelValue"]);
647
+ };
648
+ }
649
+ });
650
+ function Ue(j, f) {
651
+ const h = Me(j, f);
652
+ return { ...h, amount: -h.amount };
653
+ }
654
+ function pt(j, f) {
655
+ return Me(Math.abs(j), f);
656
+ }
657
+ const Xe = {
658
+ [ue.enum.DAMAGE]: {
659
+ label: "Damage",
660
+ toAdjustmentAmount: Ue
661
+ },
662
+ [ue.enum.WASTAGE]: {
663
+ label: "Wastage",
664
+ toAdjustmentAmount: Ue
665
+ },
666
+ [ue.enum.THEFT]: {
667
+ label: "Theft",
668
+ toAdjustmentAmount: Ue
669
+ },
670
+ [ue.enum.LOSE]: {
671
+ label: "Lose",
672
+ toAdjustmentAmount: Ue
673
+ },
674
+ [ue.enum.EXTRA]: {
675
+ label: "Extra",
676
+ toAdjustmentAmount: pt
677
+ },
678
+ [ue.enum.PURCHASE]: {
679
+ label: "Purchase",
680
+ toAdjustmentAmount: pt
681
+ }
682
+ }, Uo = { class: "col-span-2 flex" }, Ro = { class: "flex-1" }, Po = { class: "fm-typo-en-body-lg-600" }, No = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, Oo = { class: "col-span-2 flex flex-col gap-4" }, Lo = { class: "flex gap-4 text-fm-color-typo-primary fm-typo-en-body-lg-600" }, zo = {
683
+ key: 0,
684
+ class: "fm-typo-en-body-md-400 text-fm-color-typo-warning"
685
+ }, Ft = /* @__PURE__ */ ye({
686
+ __name: "AdjustedItemForm",
687
+ props: {
688
+ modelValue: {},
689
+ disabled: { type: Boolean },
690
+ isBackdate: { type: Boolean }
691
+ },
692
+ emits: ["update:modelValue", "click:delete"],
693
+ setup(j, { emit: f }) {
694
+ const h = j, v = f, { t: F } = _e(), $ = ze(), u = N(
695
+ () => Object.keys(Xe).map((t) => ({
696
+ label: Et(t),
697
+ value: t
698
+ }))
699
+ ), i = N(() => bt(h.modelValue.doc.unit, !0)), _ = N({
700
+ get() {
701
+ return h.modelValue.type ?? ue.enum.PURCHASE;
702
+ },
703
+ set(t) {
704
+ const n = {
705
+ ...h.modelValue
706
+ };
707
+ n.type = t;
708
+ const c = ct(h.modelValue.amount);
709
+ n.amount = Xe[n.type].toAdjustmentAmount(
710
+ +$e(c),
711
+ c.precision
712
+ ), v("update:modelValue", n);
713
+ }
714
+ }), L = N({
715
+ get() {
716
+ const t = ct(h.modelValue.amount);
717
+ return +$e(t);
718
+ },
719
+ set(t) {
720
+ const n = {
721
+ ...h.modelValue
722
+ }, c = K.fromNumber(t);
723
+ n.amount = Xe[_.value].toAdjustmentAmount(
724
+ t,
725
+ c.precision
726
+ ), v("update:modelValue", n);
727
+ }
728
+ }), D = N({
729
+ get() {
730
+ var t;
731
+ return ((t = h.modelValue.measurement) == null ? void 0 : t.id) ?? null;
732
+ },
733
+ set(t) {
734
+ var c, s;
735
+ const n = {
736
+ ...h.modelValue
737
+ };
738
+ n.measurement = ((s = (c = h.modelValue.doc.unit) == null ? void 0 : c.measurements) == null ? void 0 : s.find((T) => T.id === t)) ?? null, v("update:modelValue", n);
739
+ }
740
+ }), k = N({
741
+ get() {
742
+ return h.modelValue.remark ?? "";
743
+ },
744
+ set(t) {
745
+ const n = {
746
+ ...h.modelValue
747
+ };
748
+ n.remark = t, v("update:modelValue", n);
749
+ }
750
+ }), d = N(() => {
751
+ var n;
752
+ const t = (n = $.stockBalance.skus) == null ? void 0 : n.find((c) => c.id === h.modelValue.doc._id);
753
+ return (t == null ? void 0 : t.balance) ?? { amount: 0, precision: 0 };
754
+ }), C = N(() => {
755
+ const t = h.modelValue.amount, n = h.modelValue.measurement;
756
+ return n ? gt(t, n.conversion) : t;
757
+ }), a = N(
758
+ () => h.isBackdate ? d.value : ot(d.value, C.value)
759
+ ), x = N(
760
+ () => no(a.value, h.modelValue.doc.unit)
761
+ ), l = N(
762
+ () => !h.isBackdate && C.value.amount < 0
763
+ );
764
+ return (t, n) => {
765
+ const c = P("FmButton"), s = P("FmSelect"), T = P("FmTextarea"), H = P("FmCard");
766
+ return p(), ee(H, {
767
+ variant: "outlined",
768
+ class: "grid grid-cols-2 gap-8 p-16"
769
+ }, {
770
+ default: U(() => [
771
+ e("div", Uo, [
772
+ e("div", Ro, [
773
+ e("div", Po, r(t.modelValue.doc.name), 1),
774
+ e("div", No, r(t.modelValue.doc.code), 1)
775
+ ]),
776
+ b(c, {
777
+ variant: "tertiary",
778
+ "prepend-icon": "delete",
779
+ onClick: n[0] || (n[0] = (V) => v("click:delete"))
780
+ })
781
+ ]),
782
+ b(s, {
783
+ disabled: t.disabled,
784
+ class: "col-span-2",
785
+ label: "Type",
786
+ items: u.value,
787
+ modelValue: _.value,
788
+ "onUpdate:modelValue": n[1] || (n[1] = (V) => _.value = V),
789
+ rules: [o(Zt)()],
790
+ "label-mark": "required"
791
+ }, null, 8, ["disabled", "items", "modelValue", "rules"]),
792
+ b(oo, {
793
+ disabled: t.disabled,
794
+ label: "Amount",
795
+ step: +o($e)({
796
+ amount: 1,
797
+ precision: o(Ie)(t.modelValue.doc.unit, t.modelValue.measurement)
798
+ }),
799
+ modelValue: L.value,
800
+ "onUpdate:modelValue": n[2] || (n[2] = (V) => L.value = V),
801
+ rules: [o(tt)(0)]
802
+ }, null, 8, ["disabled", "step", "modelValue", "rules"]),
803
+ b(s, {
804
+ disabled: t.disabled,
805
+ label: "Unit",
806
+ items: i.value,
807
+ modelValue: D.value,
808
+ "onUpdate:modelValue": n[3] || (n[3] = (V) => D.value = V)
809
+ }, null, 8, ["disabled", "items", "modelValue"]),
810
+ b(T, {
811
+ class: "col-span-2",
812
+ disabled: t.disabled,
813
+ label: "Remark",
814
+ modelValue: k.value,
815
+ "onUpdate:modelValue": n[4] || (n[4] = (V) => k.value = V),
816
+ "label-mark": "optional"
817
+ }, null, 8, ["disabled", "modelValue"]),
818
+ e("div", Oo, [
819
+ e("div", Lo, r(o(F)("inventory.stock.stock_adjustment.stockAfter")), 1),
820
+ e("div", {
821
+ class: he(["fm-typo-en-body-lg-600", l.value ? "text-red-700" : "text-green-700"])
822
+ }, r(x.value), 3),
823
+ t.isBackdate ? (p(), E("div", zo, r(o(F)("inventory.stock.stock_adjustment.backdatePreviewWarning")), 1)) : Q("", !0)
824
+ ])
825
+ ]),
826
+ _: 1
827
+ });
828
+ };
829
+ }
830
+ }), Yo = { class: "flex items-center" }, qo = { class: "fm-typo-en-title-md-800" }, Go = { class: "flex items-center" }, Wo = { class: "fm-typo-en-title-sm-800 flex-1" }, Ko = { class: "flex gap-8" }, Xo = /* @__PURE__ */ ye({
831
+ __name: "AdjustSkuDialog",
832
+ props: {
833
+ stock: {},
834
+ show: { type: Boolean }
835
+ },
836
+ emits: ["update:show", "submitted"],
837
+ setup(j, { expose: f, emit: h }) {
838
+ const v = j, F = h, $ = Le(), u = Ye(), i = Be(), _ = xe(), L = z(!1), { t: D } = _e();
839
+ function k() {
840
+ x(Oe(a));
841
+ }
842
+ const d = z();
843
+ f({
844
+ validateInputs: () => {
845
+ var n, c;
846
+ (c = (n = d.value) == null ? void 0 : n.validateInputs) == null || c.call(n);
847
+ },
848
+ resetInputsValidation: () => {
849
+ var n, c;
850
+ (c = (n = d.value) == null ? void 0 : n.resetInputsValidation) == null || c.call(n);
851
+ },
852
+ resetInputs: () => {
853
+ var n, c;
854
+ (c = (n = d.value) == null ? void 0 : n.resetInputs) == null || c.call(n);
855
+ }
856
+ });
857
+ const C = qe(v, "show"), a = _t({
858
+ remark: "",
859
+ adjustments: [
860
+ {
861
+ id: `sku_${(/* @__PURE__ */ new Date()).toISOString()}_${Math.random().toString(16).slice(2, 8)}`,
862
+ type: ue.enum.PURCHASE,
863
+ doc: v.stock,
864
+ measurement: null,
865
+ remark: "",
866
+ amount: K.fromNumber(1)
867
+ }
868
+ ]
869
+ });
870
+ ge([() => v.show], ([n]) => {
871
+ n && (a.remark = "", a.adjustments = [
872
+ {
873
+ id: `sku_${(/* @__PURE__ */ new Date()).toISOString()}_${Math.random().toString(16).slice(2, 8)}`,
874
+ type: ue.enum.PURCHASE,
875
+ doc: v.stock,
876
+ measurement: null,
877
+ remark: "",
878
+ amount: K.fromNumber(1)
879
+ }
880
+ ]);
881
+ });
882
+ async function x(n) {
883
+ L.value = !0;
884
+ try {
885
+ await i.adjustSku({
886
+ remark: n.remark,
887
+ adjustments: n.adjustments.map(({ doc: c, remark: s, type: T, amount: H, measurement: V }) => ({
888
+ id: c._id,
889
+ amount: H,
890
+ measurement: V,
891
+ remark: s,
892
+ doc: c,
893
+ type: T
894
+ }))
895
+ }), F("update:show", !1), F("submitted");
896
+ } catch (c) {
897
+ _.open({
898
+ title: D("inventory.stock.adjust.error.title"),
899
+ message: D("inventory.stock.adjust.error.message"),
900
+ type: "error"
901
+ }), console.log("error on adjust ingredients", n, c);
902
+ } finally {
903
+ L.value = !1;
904
+ }
905
+ }
906
+ function l() {
907
+ const n = $.skus.map((s) => ({
908
+ label: s.name,
909
+ sublabel: s.code,
910
+ value: s._id
911
+ })), c = n.filter((s) => a.adjustments.find((T) => T.doc._id === s.value)).map((s) => s.value);
912
+ u.open({
913
+ title: "Select ingredients",
914
+ contentComponent: xt,
915
+ contentComponentProps: {
916
+ items: n,
917
+ modelValue: c
918
+ },
919
+ overlay: !0,
920
+ closeButton: !0,
921
+ dismissAway: !0,
922
+ primaryActions: {
923
+ text: "Confirm",
924
+ close: !0
925
+ },
926
+ secondaryActions: {
927
+ text: "Close",
928
+ close: !0,
929
+ variant: "tertiary"
930
+ }
931
+ }).onPrimary((s) => {
932
+ a.adjustments = s.map(
933
+ (T) => a.adjustments.find((H) => H.doc._id === T) ?? {
934
+ id: `sku_${(/* @__PURE__ */ new Date()).toISOString()}_${Math.random().toString(16).slice(2, 8)}`,
935
+ type: ue.enum.PURCHASE,
936
+ doc: $.skus.find((H) => H._id === T),
937
+ measurement: null,
938
+ remark: "",
939
+ amount: K.fromNumber(1)
940
+ }
941
+ );
942
+ });
943
+ }
944
+ function t(n) {
945
+ a.adjustments.splice(n, 1);
946
+ }
947
+ return (n, c) => {
948
+ const s = P("FmTextarea"), T = P("FmButton"), H = P("FmForm"), V = P("FmSideSheet");
949
+ return p(), ee(V, {
950
+ modelValue: o(C),
951
+ "onUpdate:modelValue": c[2] || (c[2] = (J) => Ne(C) ? C.value = J : null),
952
+ "dismiss-away": "",
953
+ "max-width": 500
954
+ }, {
955
+ "side-sheet-header": U(() => [
956
+ e("div", Yo, [
957
+ e("div", qo, r(o(D)("inventory.stock.adjust.title")), 1)
958
+ ])
959
+ ]),
960
+ default: U(() => [
961
+ b(H, {
962
+ class: "w-full flex flex-col gap-12",
963
+ ref_key: "formRef",
964
+ ref: d,
965
+ onValidationSuccess: k
966
+ }, {
967
+ default: U(() => [
968
+ b(s, {
969
+ label: o(D)("inventory.stock.adjust.remark"),
970
+ modelValue: a.remark,
971
+ "onUpdate:modelValue": c[0] || (c[0] = (J) => a.remark = J)
972
+ }, null, 8, ["label", "modelValue"]),
973
+ e("div", Go, [
974
+ e("div", Wo, r(o(D)("inventory.stock.adjust.adjustedItems")), 1),
975
+ b(T, {
976
+ "prepend-icon": "add",
977
+ variant: "tertiary",
978
+ size: "md",
979
+ onClick: l
980
+ })
981
+ ]),
982
+ (p(!0), E(ae, null, fe(a.adjustments, (J, I) => (p(), ee(Ft, {
983
+ key: J.id,
984
+ modelValue: a.adjustments[I],
985
+ "onUpdate:modelValue": (W) => a.adjustments[I] = W,
986
+ "onClick:delete": (W) => t(I)
987
+ }, null, 8, ["modelValue", "onUpdate:modelValue", "onClick:delete"]))), 128))
988
+ ]),
989
+ _: 1
990
+ }, 512)
991
+ ]),
992
+ "side-sheet-footer": U(() => [
993
+ e("div", Ko, [
994
+ b(T, {
995
+ label: o(D)("inventory.stock.adjust.adjustButton"),
996
+ loading: L.value,
997
+ onClick: c[1] || (c[1] = (J) => {
998
+ var I, W;
999
+ return (W = (I = d.value) == null ? void 0 : I.validateInputs) == null ? void 0 : W.call(I);
1000
+ })
1001
+ }, null, 8, ["label", "loading"])
1002
+ ])
1003
+ ]),
1004
+ _: 1
1005
+ }, 8, ["modelValue"]);
1006
+ };
1007
+ }
1008
+ }), Jo = { class: "flex items-center w-full gap-8" }, Qo = { class: "fm-typo-en-title-md-800 flex-1" }, Zo = {
1009
+ key: 0,
1010
+ class: "flex flex-col gap-4"
1011
+ }, en = { class: "fm-typo-en-body-md-600" }, tn = { class: "flex gap-8 items-start" }, on = { class: "flex-1 min-w-0" }, nn = { class: "flex-1 min-w-0" }, sn = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, an = { class: "flex items-center" }, ln = { class: "fm-typo-en-title-sm-800 flex-1" }, rn = { class: "flex gap-8" }, yt = 14, un = /* @__PURE__ */ ye({
1012
+ __name: "StockAdjustmentSideSheet",
1013
+ props: {
1014
+ show: { type: Boolean }
1015
+ },
1016
+ emits: ["update:show", "submitted"],
1017
+ setup(j, { emit: f }) {
1018
+ const h = j, v = f, { t: F } = _e(), $ = Le(), u = Be(), i = Ye(), _ = xe(), L = qe(h, "show"), D = z(!1), k = _t({
1019
+ remark: "",
1020
+ effectiveAt: /* @__PURE__ */ new Date(),
1021
+ adjustments: []
1022
+ }), d = z(!1), C = z(we().format("YYYY-MM-DD")), a = z(we().format("HH:mm")), x = z();
1023
+ ge([C, a], () => {
1024
+ if (C.value && a.value) {
1025
+ const W = we(`${C.value} ${a.value}`, "YYYY-MM-DD HH:mm");
1026
+ W.isValid() && (k.effectiveAt = W.toDate());
1027
+ }
1028
+ });
1029
+ const l = N(() => `${C.value} ${a.value}`);
1030
+ function t() {
1031
+ if (!d.value) return !0;
1032
+ const W = we(`${C.value} ${a.value}`, "YYYY-MM-DD HH:mm");
1033
+ if (!W.isValid()) return F("inventory.stock.stock_adjustment.invalidDateTime");
1034
+ const Y = we();
1035
+ if (W.isAfter(Y))
1036
+ return F("inventory.stock.stock_adjustment.futureDateNotAllowed");
1037
+ const Z = Y.subtract(yt, "day");
1038
+ return W.isBefore(Z) ? F("inventory.stock.stock_adjustment.backdateLimitError", { days: yt }) : !0;
1039
+ }
1040
+ const n = N(() => [() => t()]), c = N(() => k.adjustments.length === 0 || t() !== !0);
1041
+ function s() {
1042
+ k.remark = "", k.effectiveAt = /* @__PURE__ */ new Date(), k.adjustments = [], d.value = !1, C.value = we(k.effectiveAt).format("YYYY-MM-DD"), a.value = we(k.effectiveAt).format("HH:mm");
1043
+ }
1044
+ function T() {
1045
+ s();
1046
+ }
1047
+ const H = N(() => {
1048
+ const W = {};
1049
+ return $.skus.forEach((Y) => {
1050
+ W[Y._id] = Y;
1051
+ }), W;
1052
+ });
1053
+ function V() {
1054
+ const W = $.skus.map((Z) => ({
1055
+ label: Z.name,
1056
+ sublabel: Z.code,
1057
+ value: Z._id
1058
+ })), Y = k.adjustments.map((Z) => Z.doc._id);
1059
+ i.open({
1060
+ title: F("inventory.stock.adjust.selectIngredients"),
1061
+ contentComponent: xt,
1062
+ contentComponentProps: {
1063
+ items: W,
1064
+ modelValue: Y,
1065
+ virtualScroll: !0
1066
+ },
1067
+ overlay: !0,
1068
+ closeButton: !0,
1069
+ dismissAway: !0,
1070
+ primaryActions: {
1071
+ text: F("common.confirm"),
1072
+ close: !0
1073
+ },
1074
+ secondaryActions: {
1075
+ text: F("common.close"),
1076
+ close: !0,
1077
+ variant: "tertiary"
1078
+ }
1079
+ }).onPrimary((Z) => {
1080
+ k.adjustments = Z.map(
1081
+ (oe) => k.adjustments.find((ce) => ce.doc._id === oe) ?? {
1082
+ id: "",
1083
+ type: ue.enum.PURCHASE,
1084
+ doc: H.value[oe],
1085
+ measurement: null,
1086
+ remark: "",
1087
+ amount: K.fromNumber(1)
1088
+ }
1089
+ );
1090
+ });
1091
+ }
1092
+ function J(W) {
1093
+ k.adjustments.splice(W, 1);
1094
+ }
1095
+ async function I() {
1096
+ if (k.adjustments.length === 0) {
1097
+ _.open({
1098
+ title: F("inventory.stock.error.title"),
1099
+ message: F("inventory.stock.stock_adjustment.noAdjustments"),
1100
+ type: "warning"
1101
+ });
1102
+ return;
1103
+ }
1104
+ D.value = !0;
1105
+ try {
1106
+ const W = k.adjustments.map(
1107
+ ({ doc: Z, remark: oe, type: ce, amount: pe, measurement: ke }) => ({
1108
+ id: Z._id,
1109
+ amount: pe,
1110
+ measurement: ke,
1111
+ remark: oe,
1112
+ doc: Z,
1113
+ type: ce
1114
+ })
1115
+ ), Y = {
1116
+ remark: k.remark,
1117
+ adjustments: W,
1118
+ ...d.value ? { effectiveAt: k.effectiveAt.toISOString() } : {}
1119
+ };
1120
+ await u.adjustSku(Oe(Y)), v("submitted"), v("update:show", !1);
1121
+ } catch (W) {
1122
+ _.open({
1123
+ title: F("inventory.stock.adjust.error.title"),
1124
+ message: F("inventory.stock.adjust.error.message"),
1125
+ type: "error"
1126
+ }), console.error("error on stock adjustment", W);
1127
+ } finally {
1128
+ D.value = !1;
1129
+ }
1130
+ }
1131
+ return (W, Y) => {
1132
+ const Z = P("FmTextarea"), oe = P("FmSwitch"), ce = P("FmDatePicker"), pe = P("FmTimePicker"), ke = P("FmFormGroup"), be = P("FmButton"), w = P("FmForm"), g = P("FmSideSheet");
1133
+ return p(), ee(g, {
1134
+ modelValue: o(L),
1135
+ "onUpdate:modelValue": Y[6] || (Y[6] = (G) => Ne(L) ? L.value = G : null),
1136
+ "dismiss-away": "",
1137
+ "max-width": 560,
1138
+ onAfterEnter: T
1139
+ }, {
1140
+ "side-sheet-header": U(() => [
1141
+ e("div", Jo, [
1142
+ e("div", Qo, r(o(F)("inventory.stock.stock_adjustment.title")), 1)
1143
+ ])
1144
+ ]),
1145
+ default: U(() => [
1146
+ b(w, {
1147
+ class: "flex flex-col gap-16",
1148
+ ref_key: "formRef",
1149
+ ref: x,
1150
+ onValidationSuccess: I
1151
+ }, {
1152
+ default: U(() => [
1153
+ b(Z, {
1154
+ label: o(F)("inventory.stock.adjust.remark"),
1155
+ modelValue: k.remark,
1156
+ "onUpdate:modelValue": Y[0] || (Y[0] = (G) => k.remark = G),
1157
+ "label-mark": "optional"
1158
+ }, null, 8, ["label", "modelValue"]),
1159
+ b(oe, {
1160
+ value: "",
1161
+ "model-value": d.value,
1162
+ "onUpdate:modelValue": Y[1] || (Y[1] = (G) => d.value = G),
1163
+ label: o(F)("inventory.stock.stock_adjustment.backdateLabel"),
1164
+ sublabel: o(F)("inventory.stock.stock_adjustment.backdateSublabel"),
1165
+ labelPlacement: "right"
1166
+ }, null, 8, ["model-value", "label", "sublabel"]),
1167
+ d.value ? (p(), E("div", Zo, [
1168
+ e("label", en, r(o(F)("inventory.stock.stock_adjustment.effectiveAt")), 1),
1169
+ e("div", tn, [
1170
+ e("div", on, [
1171
+ b(ce, {
1172
+ class: "w-full",
1173
+ modelValue: C.value,
1174
+ "onUpdate:modelValue": Y[2] || (Y[2] = (G) => C.value = G),
1175
+ clearable: !1
1176
+ }, null, 8, ["modelValue"])
1177
+ ]),
1178
+ e("div", nn, [
1179
+ b(pe, {
1180
+ class: "w-full",
1181
+ modelValue: a.value,
1182
+ "onUpdate:modelValue": Y[3] || (Y[3] = (G) => a.value = G),
1183
+ format: "HH:mm"
1184
+ }, null, 8, ["modelValue"])
1185
+ ])
1186
+ ]),
1187
+ b(ke, {
1188
+ "model-value": l.value,
1189
+ rules: n.value
1190
+ }, null, 8, ["model-value", "rules"]),
1191
+ e("div", sn, r(o(F)("inventory.stock.stock_adjustment.immediateHint")), 1)
1192
+ ])) : Q("", !0),
1193
+ e("div", an, [
1194
+ e("div", ln, r(o(F)("inventory.stock.adjust.adjustedItems")), 1),
1195
+ b(be, {
1196
+ "prepend-icon": "add",
1197
+ variant: "tertiary",
1198
+ size: "md",
1199
+ onClick: V
1200
+ })
1201
+ ]),
1202
+ (p(!0), E(ae, null, fe(k.adjustments, (G, q) => (p(), ee(Ft, {
1203
+ key: G.doc._id,
1204
+ modelValue: k.adjustments[q],
1205
+ "onUpdate:modelValue": (M) => k.adjustments[q] = M,
1206
+ "is-backdate": d.value,
1207
+ "onClick:delete": (M) => J(q)
1208
+ }, null, 8, ["modelValue", "onUpdate:modelValue", "is-backdate", "onClick:delete"]))), 128))
1209
+ ]),
1210
+ _: 1
1211
+ }, 512)
1212
+ ]),
1213
+ "side-sheet-footer": U(() => [
1214
+ e("div", rn, [
1215
+ b(be, {
1216
+ label: o(F)("common.confirm"),
1217
+ loading: D.value,
1218
+ disabled: c.value,
1219
+ onClick: Y[4] || (Y[4] = (G) => {
1220
+ var q, M;
1221
+ return (M = (q = x.value) == null ? void 0 : q.validateInputs) == null ? void 0 : M.call(q);
1222
+ })
1223
+ }, null, 8, ["label", "loading", "disabled"]),
1224
+ b(be, {
1225
+ label: o(F)("common.close"),
1226
+ variant: "tertiary",
1227
+ onClick: Y[5] || (Y[5] = (G) => v("update:show", !1))
1228
+ }, null, 8, ["label"])
1229
+ ])
1230
+ ]),
1231
+ _: 1
1232
+ }, 8, ["modelValue"]);
1233
+ };
1234
+ }
1235
+ });
1236
+ function cn(j, f) {
1237
+ const h = Ut(), v = xe(), F = z(null), $ = z(null);
1238
+ ge(
1239
+ [j, () => f()._id],
1240
+ async ([_], L, D) => {
1241
+ let k = !0;
1242
+ D(() => {
1243
+ k = !1;
1244
+ }), F.value = null, $.value = null;
1245
+ try {
1246
+ const d = await h.readLastClosing(_, !1);
1247
+ if (!k || (F.value = d, !(d != null && d._id))) return;
1248
+ const C = await h.readClosingAdjustment(_, d._id);
1249
+ k && ($.value = C);
1250
+ } catch (d) {
1251
+ console.error("Failed to fetch last closing balance:", d), k && v.open({
1252
+ title: "Something went wrong",
1253
+ message: "Cannot fetch last closing balance. Please try again.",
1254
+ type: "error"
1255
+ });
1256
+ }
1257
+ },
1258
+ { immediate: !0 }
1259
+ );
1260
+ const u = N(() => {
1261
+ const _ = F.value;
1262
+ if (!_) return "";
1263
+ const L = _.effectiveAt ?? (_._id ? De(_._id) : null);
1264
+ return L ? St(new Date(L)) : "";
1265
+ });
1266
+ return { lastClosingBalance: N(() => {
1267
+ var D, k, d;
1268
+ const _ = f(), L = (d = (k = (D = $.value) == null ? void 0 : D.skus) == null ? void 0 : k.find(
1269
+ (C) => C.sku._id === _._id
1270
+ )) == null ? void 0 : d.toBalance;
1271
+ return L ? `${K.toFormatString({ value: L, precision: 4 })} ${_.unit.abbrev}` : "—";
1272
+ }), lastClosingDate: u };
1273
+ }
1274
+ const dn = Rt((j, f) => ({
1275
+ // TODO: remove once latest inventory backend has been push
1276
+ async findBillsByBusinessId(h, v, F) {
1277
+ const $ = `${j.businessesBackendUrl}/${h}/reports/find-many`, u = {
1278
+ // type: TYPE.bill,
1279
+ type: "bill",
1280
+ restaurantIds: v,
1281
+ ids: F
1282
+ };
1283
+ return await f.post($, u);
1284
+ },
1285
+ async findBillsById(h, v) {
1286
+ const $ = Ce().currentLocationDBName, u = v ? `?${new URLSearchParams({ fields: v.join(",") })}` : "", i = `${j.inventoryBackendUrl}/${$}/bill/search${u}`, _ = {
1287
+ ids: h
1288
+ };
1289
+ return await f.post(i, _);
1290
+ }
1291
+ })), mn = { class: "fm-typo-en-heading-lg-600" }, fn = {
1292
+ key: 0,
1293
+ class: "py-16"
1294
+ }, vn = {
1295
+ key: 1,
1296
+ class: "flex flex-col gap-8 py-8 max-h-[60vh] overflow-auto"
1297
+ }, pn = {
1298
+ key: 0,
1299
+ class: "rounded-md border border-blue-100 bg-blue-50 px-12 py-8",
1300
+ "data-selected-adjustment": ""
1301
+ }, yn = { class: "text-xs text-fm-color-typo-secondary" }, _n = { class: "text-sm" }, kn = { class: "text-xs text-fm-color-typo-secondary mt-4 flex flex-wrap gap-8" }, bn = { key: 0 }, hn = { key: 1 }, gn = { class: "border border-fm-color-neutral-gray-100 rounded-md" }, xn = { class: "px-12 py-8 text-xs font-mono text-fm-color-neutral-gray-300 break-all" }, Sn = { class: "px-12 pb-12" }, wn = { class: "font-bold text-sm mb-4" }, $n = {
1302
+ key: 0,
1303
+ role: "note",
1304
+ "data-adjustment-scope-warning": "",
1305
+ class: "flex items-start gap-8 rounded-md border border-amber-200 bg-amber-50 px-12 py-8 mb-8 text-xs text-amber-800"
1306
+ }, An = {
1307
+ class: "text-xs flex flex-col gap-4",
1308
+ "data-bill-receipt": ""
1309
+ }, Fn = { class: "flex justify-between gap-8 text-fm-color-neutral-gray-300 mb-4" }, jn = ["data-item-key"], Cn = { class: "w-[24px] shrink-0 text-right" }, Bn = { class: "grow min-w-0 break-words" }, Vn = { key: 0 }, Dn = {
1310
+ key: 1,
1311
+ class: "text-fm-color-neutral-gray-300"
1312
+ }, In = { key: 2 }, Mn = { class: "shrink-0 text-right" }, Tn = { class: "flex items-start gap-8 min-w-0" }, Hn = { class: "break-words font-medium" }, En = { class: "shrink-0 text-right" }, Un = /* @__PURE__ */ ye({
1313
+ __name: "BillInventoryInfoDialog",
1314
+ props: {
1315
+ show: { type: Boolean },
1316
+ bill: {},
1317
+ billId: {},
1318
+ sku: {},
1319
+ amounts: {},
1320
+ itemRef: {},
1321
+ adjustmentContext: {}
1322
+ },
1323
+ emits: ["update:show"],
1324
+ setup(j, { emit: f }) {
1325
+ const { FmDialog: h, FmButton: v, FmSpacer: F, FmIcon: $ } = qt, { t: u } = _e(), i = j, _ = f, L = N(() => {
1326
+ var a;
1327
+ if (!i.bill) return [];
1328
+ const d = [];
1329
+ function C(x, l, t) {
1330
+ l.forEach((n, c) => {
1331
+ var V, J;
1332
+ const s = `${x}|${c}`, T = (V = n.variantSelected) == null ? void 0 : V.name.join(", "), H = T ? `${n.name} (${T})` : n.name;
1333
+ d.push({ key: s, name: H, code: (J = n.product) == null ? void 0 : J.code, quantity: n.quantity, depth: t }), C(s, n.subItems, t + 1);
1334
+ });
1335
+ }
1336
+ for (const [x, l] of Object.entries(i.bill.items)) {
1337
+ const t = (a = l.variantSelected) == null ? void 0 : a.name.join(", "), n = t ? `${l.product.name} (${t})` : l.product.name;
1338
+ d.push({ key: x, name: n, code: l.product.code, quantity: l.quantity, depth: 0 }), C(x, l.subItems, 1);
1339
+ }
1340
+ return d.map((x) => ({
1341
+ ...x,
1342
+ amounts: i.amounts.filter((l) => l.ref === x.key)
1343
+ }));
1344
+ }), D = N(
1345
+ () => i.amounts.filter((d) => !L.value.some((C) => C.key === d.ref))
1346
+ );
1347
+ function k(d) {
1348
+ var C;
1349
+ return `${K.toFormatString({ value: d.amount, precision: 4 })} ${((C = d.measurement) == null ? void 0 : C.abbrev) ?? i.sku.unit.abbrev}`;
1350
+ }
1351
+ return (d, C) => (p(), ee(o(h), {
1352
+ "model-value": d.show,
1353
+ overlay: !0,
1354
+ "max-width": "720px",
1355
+ "z-index": 60,
1356
+ "onUpdate:modelValue": C[1] || (C[1] = (a) => _("update:show", a))
1357
+ }, {
1358
+ "dialog-header": U(() => {
1359
+ var a;
1360
+ return [
1361
+ e("div", mn, r(o(u)("inventory.stock.record.bill", [((a = d.bill) == null ? void 0 : a.seqNumber) ?? d.billId])), 1)
1362
+ ];
1363
+ }),
1364
+ "dialog-footer": U(() => [
1365
+ b(o(F), { class: "sm:hidden xs:hidden" }),
1366
+ b(o(v), {
1367
+ label: o(u)("inventory.stock.record.closeBill"),
1368
+ size: "md",
1369
+ onClick: C[0] || (C[0] = (a) => _("update:show", !1))
1370
+ }, null, 8, ["label"])
1371
+ ]),
1372
+ default: U(() => [
1373
+ d.bill ? (p(), E("div", vn, [
1374
+ d.adjustmentContext ? (p(), E("div", pn, [
1375
+ e("div", yn, r(o(u)("inventory.stock.record.selectedAdjustment")), 1),
1376
+ (p(!0), E(ae, null, fe(d.amounts, (a, x) => (p(), E("div", {
1377
+ key: x,
1378
+ class: "flex items-center justify-between gap-8 mt-4"
1379
+ }, [
1380
+ e("span", _n, r(o(u)(`inventory.inventoryAdjustment.type.${a.type}`)), 1),
1381
+ e("span", {
1382
+ class: he([
1383
+ "font-bold text-sm",
1384
+ a.amount.amount < 0 ? "text-fm-color-typo-error" : "text-fm-color-typo-success"
1385
+ ])
1386
+ }, r(k(a)), 3)
1387
+ ]))), 128)),
1388
+ e("div", kn, [
1389
+ d.adjustmentContext.timestamp ? (p(), E("span", bn, r(o(nt)(new Date(d.adjustmentContext.timestamp))), 1)) : Q("", !0),
1390
+ d.adjustmentContext.actor ? (p(), E("span", hn, r(d.adjustmentContext.actor), 1)) : Q("", !0)
1391
+ ])
1392
+ ])) : Q("", !0),
1393
+ e("div", gn, [
1394
+ e("div", xn, r(d.bill._id), 1),
1395
+ e("div", Sn, [
1396
+ e("div", wn, r(d.sku.name) + " (" + r(d.sku.unit.abbrev) + ")", 1),
1397
+ d.adjustmentContext ? (p(), E("div", $n, [
1398
+ b(o($), {
1399
+ name: "warning",
1400
+ size: "sm",
1401
+ class: "shrink-0"
1402
+ }),
1403
+ e("span", null, r(o(u)("inventory.stock.record.selectedAdjustmentHint")), 1)
1404
+ ])) : Q("", !0),
1405
+ e("div", An, [
1406
+ e("div", Fn, [
1407
+ e("span", null, r(o(u)("inventory.stock.record.billItem")), 1),
1408
+ e("span", null, r(o(u)("inventory.stock.record.billStockChange")), 1)
1409
+ ]),
1410
+ (p(!0), E(ae, null, fe(L.value, (a) => (p(), E("div", {
1411
+ key: a.key,
1412
+ "data-item-key": a.key,
1413
+ class: he(["flex items-start gap-8", { "bg-blue-50 font-bold rounded": a.key === d.itemRef }]),
1414
+ style: Qe({ paddingLeft: `${a.depth * 16}px` })
1415
+ }, [
1416
+ e("div", Cn, r(a.depth === 0 ? a.quantity : ""), 1),
1417
+ e("div", Bn, [
1418
+ a.depth > 1 ? (p(), E("span", Vn, "- ")) : Q("", !0),
1419
+ a.code ? (p(), E("span", Dn, r(a.code), 1)) : Q("", !0),
1420
+ ve(" " + r(a.name) + " ", 1),
1421
+ a.depth > 0 && a.quantity !== 1 ? (p(), E("span", In, " ×" + r(a.quantity), 1)) : Q("", !0)
1422
+ ]),
1423
+ e("div", Mn, [
1424
+ (p(!0), E(ae, null, fe(a.amounts, (x, l) => (p(), E("div", { key: l }, r(k(x)), 1))), 128))
1425
+ ])
1426
+ ], 14, jn))), 128)),
1427
+ (p(!0), E(ae, null, fe(D.value, (a, x) => (p(), E("div", {
1428
+ key: x,
1429
+ role: "alert",
1430
+ class: "flex items-start justify-between gap-8 rounded-md border border-red-200 bg-red-50 px-12 py-8 mt-4 text-red-700"
1431
+ }, [
1432
+ e("div", Tn, [
1433
+ b(o($), {
1434
+ name: "error",
1435
+ size: "sm",
1436
+ class: "shrink-0"
1437
+ }),
1438
+ e("span", Hn, r(o(u)("inventory.stock.record.billItemNoLongerExists")), 1)
1439
+ ]),
1440
+ e("div", En, r(k(a)), 1)
1441
+ ]))), 128))
1442
+ ])
1443
+ ])
1444
+ ])
1445
+ ])) : (p(), E("div", fn, r(o(u)("inventory.stock.record.billNotFound")), 1))
1446
+ ]),
1447
+ _: 1
1448
+ }, 8, ["model-value"]));
1449
+ }
1450
+ }), Rn = {
1451
+ key: 0,
1452
+ class: "flex justify-center items-center h-32"
1453
+ }, Pn = { class: "mb-3" }, Nn = { class: "flex flex-col gap-8" }, On = { class: "flex flex-col text-fm-color-typo-primary mb-3 text-center" }, Ln = { class: "text-fm-color-neutral-gray-400 fm-typo-en-body-sm-600" }, zn = { class: "flex flex-col gap-4 text-fm-color-typo-primary mb-3" }, Yn = { class: "flex flex-col gap-4 text-fm-color-typo-primary mb-3" }, qn = { class: "flex flex-col gap-4 text-fm-color-typo-primary mb-3" }, Gn = { class: "flex flex-col w-full px-2" }, Wn = { class: "flex gap-2" }, Kn = /* @__PURE__ */ ye({
1454
+ __name: "AmendAdjustmentForm",
1455
+ props: /* @__PURE__ */ st({
1456
+ adjustmentId: {}
1457
+ }, {
1458
+ modelValue: {},
1459
+ modelModifiers: {}
1460
+ }),
1461
+ emits: /* @__PURE__ */ st(["refreshHistory"], ["update:modelValue"]),
1462
+ setup(j, { emit: f }) {
1463
+ const h = j, v = f, F = Be(), $ = Ct(j, "modelValue"), u = z(!1), i = z(!1), _ = z(!1), L = z({
1464
+ _id: `inventoryAdjustment_${(/* @__PURE__ */ new Date()).toISOString()}_XXXXX`,
1465
+ skus: []
1466
+ }), D = z();
1467
+ Ze(async () => {
1468
+ u.value = !0;
1469
+ const l = await F.readSingleAdjustment(h.adjustmentId);
1470
+ if (!l) throw new Error("Adjustment not found");
1471
+ L.value = l, u.value = !1;
1472
+ });
1473
+ async function k() {
1474
+ var t, n;
1475
+ if ((n = (t = D == null ? void 0 : D.value) == null ? void 0 : t.validateInputs) == null || n.call(t), !i.value) return;
1476
+ const l = {};
1477
+ Object.keys($.value || {}).forEach((c) => {
1478
+ var s;
1479
+ Object.keys(((s = $.value) == null ? void 0 : s[c]) || {}).forEach((T) => {
1480
+ var V, J;
1481
+ const H = (J = (V = $.value) == null ? void 0 : V[c]) == null ? void 0 : J[Number(T)];
1482
+ H && C(H.amount) > 0 && (l[c] || (l[c] = []), l[c].push(H));
1483
+ });
1484
+ }), await F.revertWastageAdjustment({
1485
+ targetWastageAdjustmentId: h.adjustmentId,
1486
+ amountsGoingToAdjust: l
1487
+ }), v("refreshHistory"), _.value = !1, $.value = {};
1488
+ }
1489
+ function d(l) {
1490
+ const { skuId: t, idx: n, unit: c, measurement: s } = l;
1491
+ return N({
1492
+ get: () => {
1493
+ var V, J, I;
1494
+ const T = (I = (J = (V = $.value) == null ? void 0 : V[t]) == null ? void 0 : J[n]) == null ? void 0 : I.amount;
1495
+ return T ? Number(K.toFormatString({ value: T })) : 0;
1496
+ },
1497
+ set: (T) => {
1498
+ const H = T ?? 0;
1499
+ $.value || ($.value = {});
1500
+ const V = { ...$.value };
1501
+ V[t] || (V[t] = {});
1502
+ const J = Ie(c);
1503
+ let I;
1504
+ try {
1505
+ I = K.fromNumber(H);
1506
+ } catch (W) {
1507
+ if (!Number.isFinite(H)) throw W;
1508
+ const Y = Me(H, J, !0);
1509
+ I = K.fromNumber(Y.amount / 10 ** J);
1510
+ }
1511
+ V[t][n] = {
1512
+ amount: K.convertPrecision({
1513
+ value: I,
1514
+ precision: J
1515
+ }),
1516
+ type: ue.Enum.WASTAGE,
1517
+ measurement: s
1518
+ }, $.value = V;
1519
+ }
1520
+ });
1521
+ }
1522
+ function C(l, t = !0) {
1523
+ const n = Number(K.toFormatString({ value: l }));
1524
+ return t ? Math.abs(n) : n;
1525
+ }
1526
+ function a(l, t) {
1527
+ return t.measurement ? t.measurement.abbrev : l.sku.unit.abbrev;
1528
+ }
1529
+ function x(l, t) {
1530
+ if (t.amount === 0) return "N/A";
1531
+ const n = K.add([l, t]);
1532
+ return n ? K.toFormatString({ value: n }) : "N/A";
1533
+ }
1534
+ return (l, t) => {
1535
+ const n = P("FmIcon"), c = P("FmStepperField"), s = P("FmCard"), T = P("FmForm"), H = P("FmSpacer"), V = P("FmButton"), J = P("FmDialog");
1536
+ return p(), ee(J, {
1537
+ modelValue: _.value,
1538
+ "onUpdate:modelValue": t[4] || (t[4] = (I) => _.value = I),
1539
+ overlay: !0
1540
+ }, {
1541
+ "dialog-button": U(() => [
1542
+ b(Ge, null, {
1543
+ default: U(() => [
1544
+ e("button", {
1545
+ onClick: t[0] || (t[0] = (I) => _.value = !0),
1546
+ class: "rounded-md hover:bg-gray-100 transition-colors"
1547
+ }, [
1548
+ b(n, {
1549
+ name: "edit",
1550
+ size: "sm"
1551
+ })
1552
+ ])
1553
+ ]),
1554
+ _: 1
1555
+ })
1556
+ ]),
1557
+ "dialog-header": U(() => t[5] || (t[5] = [
1558
+ e("div", null, "Amend Adjustment", -1)
1559
+ ])),
1560
+ "dialog-footer": U(() => [
1561
+ e("div", Gn, [
1562
+ t[13] || (t[13] = e("span", { class: "text-fm-color-system-warning-400 fm-typo-en-body-sm-400" }, "1. New adjustment EXTRA will be created for each reversal", -1)),
1563
+ e("div", Wn, [
1564
+ b(H),
1565
+ b(V, {
1566
+ class: "sm:w-full xs:w-full",
1567
+ label: "Close",
1568
+ size: "md",
1569
+ variant: "tertiary",
1570
+ onClick: t[3] || (t[3] = (I) => _.value = !1)
1571
+ }),
1572
+ b(V, {
1573
+ class: "sm:w-full xs:w-full",
1574
+ label: "Submit",
1575
+ size: "md",
1576
+ variant: "primary",
1577
+ onClick: k
1578
+ })
1579
+ ])
1580
+ ])
1581
+ ]),
1582
+ default: U(() => [
1583
+ u.value ? (p(), E("div", Rn)) : (p(), ee(T, {
1584
+ key: 1,
1585
+ ref_key: "formRef",
1586
+ ref: D,
1587
+ onValidationFailed: t[1] || (t[1] = () => {
1588
+ i.value = !1;
1589
+ }),
1590
+ onValidationSuccess: t[2] || (t[2] = () => {
1591
+ i.value = !0;
1592
+ }),
1593
+ blameFormChildOnValidationFailed: ""
1594
+ }, {
1595
+ default: U(() => [
1596
+ e("p", Pn, [
1597
+ t[6] || (t[6] = e("b", null, "Date:", -1)),
1598
+ t[7] || (t[7] = e("br", null, null, -1)),
1599
+ ve(" " + r(o(so)(o(Pt)(L.value._id))), 1)
1600
+ ]),
1601
+ e("div", Nn, [
1602
+ (p(!0), E(ae, null, fe(L.value.skus, (I, W) => (p(), E(ae, { key: W }, [
1603
+ (p(!0), E(ae, null, fe(I.amounts, (Y, Z) => (p(), ee(s, {
1604
+ key: Z,
1605
+ variant: "outlined",
1606
+ class: "p-2"
1607
+ }, {
1608
+ default: U(() => [
1609
+ e("div", On, [
1610
+ e("span", Ln, r(I.sku.code), 1),
1611
+ e("span", null, r(I.sku.name), 1)
1612
+ ]),
1613
+ t[12] || (t[12] = e("hr", { class: "m-2" }, null, -1)),
1614
+ e("div", zn, [
1615
+ t[8] || (t[8] = e("span", { class: "fm-typo-en-body-lg-600" }, "Adjustment type:", -1)),
1616
+ e("span", null, r(Y.type), 1)
1617
+ ]),
1618
+ e("div", Yn, [
1619
+ t[9] || (t[9] = e("span", { class: "fm-typo-en-body-lg-600" }, "Current amount:", -1)),
1620
+ e("span", null, r(o(K).toFormatString({ value: Y.amount })) + " " + r(a(I, Y)), 1)
1621
+ ]),
1622
+ b(c, {
1623
+ "max-fraction-digits": o(Ie)(I.sku.unit),
1624
+ "model-value": d({
1625
+ skuId: I.sku._id,
1626
+ idx: Z,
1627
+ unit: I.sku.unit
1628
+ }).value,
1629
+ "onUpdate:modelValue": (oe) => d({
1630
+ skuId: I.sku._id,
1631
+ idx: Z,
1632
+ unit: I.sku.unit
1633
+ }).value = oe,
1634
+ class: "mb-3",
1635
+ label: "Adjust Amount (Leave 0 to skip)",
1636
+ "helper-text": `Max: ${C(Y.amount)}`,
1637
+ "append-text": a(I, Y),
1638
+ rules: [
1639
+ (oe) => oe <= C(Y.amount) || `Cannot be more than ${C(Y.amount)}`,
1640
+ (oe) => o(tt)(-1)(oe ?? 0)
1641
+ ]
1642
+ }, null, 8, ["max-fraction-digits", "model-value", "onUpdate:modelValue", "helper-text", "append-text", "rules"]),
1643
+ e("div", qn, [
1644
+ t[10] || (t[10] = e("span", { class: "fm-typo-en-body-lg-600" }, "Amount after amend:", -1)),
1645
+ t[11] || (t[11] = e("span", { class: "text-fm-color-system-warning-400 fm-typo-en-body-sm-400" }, "* It's an estimate for your reference, as it didn't include all the reversals related to this adjustment", -1)),
1646
+ ve(" " + r(x(
1647
+ Y.amount,
1648
+ o(K).fromNumber(
1649
+ d({
1650
+ skuId: I.sku._id,
1651
+ idx: Z,
1652
+ unit: I.sku.unit
1653
+ }).value
1654
+ )
1655
+ )) + " " + r(a(I, Y)), 1)
1656
+ ])
1657
+ ]),
1658
+ _: 2
1659
+ }, 1024))), 128))
1660
+ ], 64))), 128))
1661
+ ])
1662
+ ]),
1663
+ _: 1
1664
+ }, 512))
1665
+ ]),
1666
+ _: 1
1667
+ }, 8, ["modelValue"]);
1668
+ };
1669
+ }
1670
+ }), Xn = { class: "p-16" }, Jn = { class: "fm-typo-en-body-md-600 flex-grow" }, Qn = ["onClick"], Zn = { class: "flex-grow text-fm-color-typo-secondary" }, es = {
1671
+ key: 0,
1672
+ class: "my-5"
1673
+ }, ts = { class: "shrink-0 whitespace-nowrap text-neutral-400" }, os = { class: "flex-grow min-w-0" }, ns = { class: "flex gap-1" }, ss = { class: "flex flex-wrap items-center gap-x-1 min-w-0 break-words" }, as = { class: "flex flex-col gap-1" }, ls = ["onClick"], rs = {
1674
+ key: 2,
1675
+ class: "text-xs text-gray-400"
1676
+ }, is = { key: 3 }, us = { key: 4 }, cs = { class: "inline-flex items-center gap-0.5 text-fm-color-typo-secondary" }, ds = {
1677
+ key: 6,
1678
+ class: "inline-flex items-center rounded-md bg-yellow-400/10 px-2 text-xs font-medium text-yellow-500 inset-ring inset-ring-yellow-400/20"
1679
+ }, ms = { class: "shrink-0 whitespace-nowrap text-fm-color-typo-secondary" }, fs = ["onClick"], vs = /* @__PURE__ */ ye({
1680
+ __name: "StockRecordCard",
1681
+ props: {
1682
+ record: {},
1683
+ sku: {},
1684
+ bills: { default: () => [] },
1685
+ unitCostHistory: { default: () => [] },
1686
+ costMechanism: { default: "adjustment" },
1687
+ typeFilter: { default: null },
1688
+ debug: { type: Boolean, default: !1 }
1689
+ },
1690
+ emits: ["refreshHistory", "toggleType"],
1691
+ setup(j) {
1692
+ const f = j;
1693
+ function h(a, x) {
1694
+ if (f.costMechanism === "adjustment")
1695
+ return null;
1696
+ const l = f.unitCostHistory.filter(
1697
+ (c) => c.mechanism === f.costMechanism && c.skuId === f.sku._id
1698
+ );
1699
+ if (l.length === 0) return null;
1700
+ const t = l.find((c) => {
1701
+ const s = c.meta;
1702
+ return (s == null ? void 0 : s.adjustmentId) === a;
1703
+ });
1704
+ if (t) return t.cost;
1705
+ const n = [...l].filter((c) => new Date(c.snapshotAt) <= new Date(x)).sort((c, s) => new Date(s.snapshotAt).getTime() - new Date(c.snapshotAt).getTime());
1706
+ return n.length > 0 ? n[0].cost : null;
1707
+ }
1708
+ const v = z(null), F = N(
1709
+ () => f.bills.find((a) => {
1710
+ var x;
1711
+ return a._id === ((x = v.value) == null ? void 0 : x.billId);
1712
+ }) ?? null
1713
+ ), $ = z(!1), u = z(), i = z(null), _ = N(() => i.value === null ? "unset" : $.value ? `${i.value}px` : "0px");
1714
+ Ze(() => {
1715
+ var a;
1716
+ i.value = ((a = u.value) == null ? void 0 : a.scrollHeight) || 0;
1717
+ });
1718
+ const L = N(() => {
1719
+ var c;
1720
+ const a = f.record.adjustments, x = f.sku, l = {}, n = a.flatMap((s) => {
1721
+ var T;
1722
+ return ((T = s.skus) == null ? void 0 : T.filter((H) => H.sku._id === x._id)) ?? [];
1723
+ }).flatMap((s) => s.amounts);
1724
+ for (const s of n) {
1725
+ const T = s.measurement ? gt(s.measurement.conversion, s.amount) : s.amount;
1726
+ l[c = s.type] ?? (l[c] = { amount: 0, precision: 0 }), l[s.type] = ot(T, l[s.type]);
1727
+ }
1728
+ return Object.entries(l).reduce(
1729
+ (s, [T, H]) => (s[T] = /// comment, because without it formatter makes code uglier
1730
+ `${K.toFormatString({
1731
+ value: H,
1732
+ precision: 4
1733
+ })} ${x.unit.abbrev}`, s),
1734
+ {}
1735
+ );
1736
+ }), { t: D } = _e(), k = xe();
1737
+ async function d(a) {
1738
+ await navigator.clipboard.writeText(a), k.open({ message: `Copied ${a}`, type: "success" });
1739
+ }
1740
+ const C = N(() => f.record.adjustmentsByTime.map(({ date: x, adjustments: l }) => ({
1741
+ time: ao(new Date(x)),
1742
+ adjustments: l.flatMap(
1743
+ (t) => {
1744
+ var n, c;
1745
+ return ((c = (n = t.skus) == null ? void 0 : n.map) == null ? void 0 : c.call(n, (s) => {
1746
+ var T, H;
1747
+ return {
1748
+ ...s,
1749
+ ref: t.ref,
1750
+ reason: t.reason,
1751
+ adjustmentRemark: t.remark,
1752
+ backdateFrom: t.effectiveAt != null ? De(t._id) : null,
1753
+ toBalance: (H = (T = t.skus) == null ? void 0 : T[0]) == null ? void 0 : H.toBalance,
1754
+ adjustmentId: t._id,
1755
+ adjustmentTime: t.effectiveAt ?? De(t._id),
1756
+ createdBy: t.createdBy
1757
+ };
1758
+ })) ?? [];
1759
+ }
1760
+ ).flatMap((t) => {
1761
+ var H;
1762
+ const n = (H = f.bills.find((V) => V._id === t.ref)) == null ? void 0 : H.seqNumber, c = n ? D("inventory.stock.record.bill", [n]) : "", s = t.adjustmentTime ?? (/* @__PURE__ */ new Date()).toISOString(), T = h(t.adjustmentId, s);
1763
+ return (t.amounts || []).filter((V) => V != null).filter((V) => !f.typeFilter || V.type === f.typeFilter).map((V) => {
1764
+ var W, Y;
1765
+ let J = V.cost;
1766
+ if (T) {
1767
+ const Z = K.fromDinero(T), oe = V.amount, ce = V.measurement ? K.multiply([oe, V.measurement.conversion]) : oe;
1768
+ J = {
1769
+ ...K.multiply([
1770
+ Z,
1771
+ ce
1772
+ ]),
1773
+ currency: T.currency
1774
+ };
1775
+ }
1776
+ let I = "";
1777
+ return c ? I = V.remark || "" : I = [t.adjustmentRemark, V.remark].filter((oe) => oe).join("/"), {
1778
+ amount: `${K.toFormatString({ value: V.amount, precision: 4 })} ${((W = V.measurement) == null ? void 0 : W.abbrev) ?? t.sku.unit.abbrev}`,
1779
+ backdateFrom: t.backdateFrom,
1780
+ name: V.type,
1781
+ billRemark: c,
1782
+ billId: (Y = t.ref) != null && Y.startsWith("bill_") ? t.ref : null,
1783
+ itemRef: V.ref,
1784
+ billAmount: V,
1785
+ adjustmentTimestamp: t.adjustmentTime,
1786
+ billSku: t.sku,
1787
+ remark: I,
1788
+ reason: t.reason || "",
1789
+ cost: J,
1790
+ toBalance: K.toFormatString({
1791
+ value: t.toBalance ?? K.fromNumber(0),
1792
+ precision: 4
1793
+ }),
1794
+ baseUnit: t.sku.unit.abbrev,
1795
+ adjustmentId: t.adjustmentId,
1796
+ createdBy: t.createdBy
1797
+ };
1798
+ });
1799
+ })
1800
+ })).filter((x) => x.adjustments.length > 0));
1801
+ return ge(
1802
+ () => f.typeFilter,
1803
+ (a) => {
1804
+ a && ($.value = !0);
1805
+ },
1806
+ { immediate: !0 }
1807
+ ), ge([C, () => f.debug], async () => {
1808
+ var a;
1809
+ await Bt(), i.value = ((a = u.value) == null ? void 0 : a.scrollHeight) || 0;
1810
+ }), (a, x) => {
1811
+ const l = P("FmIcon"), t = P("FmTooltip"), n = P("FmCard");
1812
+ return p(), ee(n, {
1813
+ variant: "outlined",
1814
+ style: { overflow: "clip" }
1815
+ }, {
1816
+ default: U(() => [
1817
+ e("div", Xn, [
1818
+ e("div", {
1819
+ class: "sticky top-0 z-10 bg-white flex items-center cursor-pointer py-4 mb-1",
1820
+ onClick: x[0] || (x[0] = (c) => $.value = !$.value)
1821
+ }, [
1822
+ e("div", Jn, r(a.record.date), 1),
1823
+ b(l, {
1824
+ name: $.value ? "expand_more" : "expand_less",
1825
+ color: "#777777",
1826
+ size: "md"
1827
+ }, null, 8, ["name"])
1828
+ ]),
1829
+ (p(!0), E(ae, null, fe(L.value, (c, s) => (p(), E("div", {
1830
+ key: s,
1831
+ class: he(["flex flex-row py-1 px-8 -mx-8 rounded-md cursor-pointer select-none transition-colors hover:bg-gray-100", {
1832
+ "opacity-40": a.typeFilter && a.typeFilter !== s,
1833
+ "font-bold bg-gray-100": a.typeFilter === s
1834
+ }]),
1835
+ style: { "font-size": "0.8rem" },
1836
+ onClick: (T) => a.$emit("toggleType", s)
1837
+ }, [
1838
+ e("div", Zn, r(o(D)(`inventory.inventoryAdjustment.type.${s}`)), 1),
1839
+ e("div", {
1840
+ class: he({
1841
+ "text-fm-color-typo-error": c.startsWith("-"),
1842
+ "text-fm-color-typo-success": !c.startsWith("-"),
1843
+ "ml-auto": !0
1844
+ })
1845
+ }, r(c), 3)
1846
+ ], 10, Qn))), 128)),
1847
+ e("div", {
1848
+ ref_key: "detailRef",
1849
+ ref: u,
1850
+ style: Qe({
1851
+ fontSize: "0.8rem",
1852
+ maxHeight: _.value,
1853
+ overflow: "hidden",
1854
+ transition: "max-height 0.2s ease-out"
1855
+ })
1856
+ }, [
1857
+ C.value.length ? (p(), E("hr", es)) : Q("", !0),
1858
+ (p(!0), E(ae, null, fe(C.value, (c) => (p(), E("div", {
1859
+ key: c.time,
1860
+ class: "flex gap-1 w-full"
1861
+ }, [
1862
+ e("div", ts, r(c.time), 1),
1863
+ e("div", os, [
1864
+ (p(!0), E(ae, null, fe(c.adjustments, (s) => {
1865
+ var T;
1866
+ return p(), E("div", {
1867
+ key: s.name
1868
+ }, [
1869
+ e("div", ns, [
1870
+ e("div", ss, [
1871
+ e("span", null, r(o(D)(`inventory.inventoryAdjustment.type.${s.name}`)), 1),
1872
+ s.backdateFrom ? (p(), ee(t, {
1873
+ key: 0,
1874
+ variant: "plain",
1875
+ placement: "top",
1876
+ "z-index": 50
1877
+ }, {
1878
+ content: U(() => [
1879
+ e("div", as, r(o(D)("inventory.stock.record.backdate", [
1880
+ o(nt)(new Date(s.backdateFrom))
1881
+ ])), 1)
1882
+ ]),
1883
+ default: U(() => [
1884
+ b(l, {
1885
+ name: "info",
1886
+ size: "sm",
1887
+ color: "primary"
1888
+ })
1889
+ ]),
1890
+ _: 2
1891
+ }, 1024)) : Q("", !0),
1892
+ s.billId ? (p(), E("button", {
1893
+ key: 1,
1894
+ class: "t-system text-fsecondary hover:underline text-left",
1895
+ onClick: (H) => {
1896
+ var V;
1897
+ return v.value = {
1898
+ billId: s.billId,
1899
+ itemRef: s.itemRef,
1900
+ amounts: [s.billAmount],
1901
+ sku: s.billSku,
1902
+ context: {
1903
+ timestamp: s.adjustmentTimestamp,
1904
+ actor: (V = s.createdBy) == null ? void 0 : V.name
1905
+ }
1906
+ };
1907
+ }
1908
+ }, " # " + r(s.billRemark || o(D)("inventory.stock.record.bill", [s.billId])), 9, ls)) : Q("", !0),
1909
+ s.billRemark && s.remark ? (p(), E("span", rs, " (" + r(s.remark) + ") ", 1)) : Q("", !0),
1910
+ !s.billRemark && s.reason ? (p(), E("span", is, " (" + r(s.reason) + ") ", 1)) : Q("", !0),
1911
+ !s.billRemark && s.remark ? (p(), E("span", us, " # " + r(s.remark), 1)) : Q("", !0),
1912
+ (T = s.createdBy) != null && T.name ? (p(), ee(t, {
1913
+ key: 5,
1914
+ variant: "plain",
1915
+ placement: "top",
1916
+ "z-index": 50
1917
+ }, {
1918
+ content: U(() => [
1919
+ ve(r(o(D)("inventory.stock.record.createdBy", [s.createdBy.name])), 1)
1920
+ ]),
1921
+ default: U(() => [
1922
+ e("span", cs, [
1923
+ b(l, {
1924
+ name: "person",
1925
+ size: "sm",
1926
+ color: "primary"
1927
+ }),
1928
+ ve(" " + r(s.createdBy.name), 1)
1929
+ ])
1930
+ ]),
1931
+ _: 2
1932
+ }, 1024)) : Q("", !0),
1933
+ s.name === o(ue).Enum.CLOSING ? (p(), E("span", ds, " Actual Balance: " + r(s.toBalance) + " " + r(s.baseUnit), 1)) : Q("", !0)
1934
+ ]),
1935
+ e("div", {
1936
+ class: he({
1937
+ "text-fm-color-typo-error": s.amount.startsWith("-"),
1938
+ "text-fm-color-typo-success": !s.amount.startsWith("-"),
1939
+ "ml-auto shrink-0 whitespace-nowrap": !0
1940
+ })
1941
+ }, r(s.amount), 3),
1942
+ s.name === o(ue).Enum.WASTAGE ? (p(), ee(Kn, {
1943
+ key: 0,
1944
+ adjustmentId: s.adjustmentId,
1945
+ onRefreshHistory: x[1] || (x[1] = (H) => a.$emit("refreshHistory"))
1946
+ }, null, 8, ["adjustmentId"])) : Q("", !0),
1947
+ s.cost ? (p(), ee(wt, {
1948
+ key: 1,
1949
+ "feature-key": "total-cost",
1950
+ compact: ""
1951
+ }, {
1952
+ default: U(() => [
1953
+ e("div", ms, " (" + r(o(Re)(s.cost, !1, s.cost.precision)) + ") ", 1)
1954
+ ]),
1955
+ _: 2
1956
+ }, 1024)) : Q("", !0)
1957
+ ]),
1958
+ a.debug ? (p(), E("button", {
1959
+ key: 0,
1960
+ class: "flex items-center gap-1 mb-2 font-mono text-[11px] text-neutral-400 hover:text-neutral-600",
1961
+ onClick: (H) => d(s.adjustmentId)
1962
+ }, [
1963
+ ve(r(s.adjustmentId) + " ", 1),
1964
+ b(l, {
1965
+ name: "content_copy",
1966
+ size: "sm"
1967
+ })
1968
+ ], 8, fs)) : Q("", !0)
1969
+ ]);
1970
+ }), 128))
1971
+ ])
1972
+ ]))), 128))
1973
+ ], 4)
1974
+ ]),
1975
+ v.value ? (p(), ee(Un, {
1976
+ key: 0,
1977
+ show: !0,
1978
+ bill: F.value,
1979
+ "bill-id": v.value.billId,
1980
+ sku: v.value.sku,
1981
+ amounts: v.value.amounts,
1982
+ "item-ref": v.value.itemRef,
1983
+ "adjustment-context": v.value.context,
1984
+ "onUpdate:show": x[2] || (x[2] = (c) => {
1985
+ c || (v.value = null);
1986
+ })
1987
+ }, null, 8, ["bill", "bill-id", "sku", "amounts", "item-ref", "adjustment-context"])) : Q("", !0)
1988
+ ]),
1989
+ _: 1
1990
+ });
1991
+ };
1992
+ }
1993
+ });
1994
+ function ps(j, f) {
1995
+ var $;
1996
+ const h = Object.keys(ue.enum).reduce(
1997
+ (u, i) => (u[i] = { amount: 0, precision: 0 }, u),
1998
+ {}
1999
+ );
2000
+ if (!f)
2001
+ return Object.entries(h).reduce(
2002
+ (u, [i]) => (u[i] = K.fromNumber(0), u),
2003
+ {}
2004
+ );
2005
+ const F = j.flatMap((u) => {
2006
+ var i;
2007
+ return ((i = u.skus) == null ? void 0 : i.filter((_) => _.sku._id === f._id)) ?? [];
2008
+ }).flatMap((u) => u.amounts);
2009
+ for (const u of F) {
2010
+ const i = u.measurement ? K.multiply([u.measurement.conversion, u.amount]) : u.amount;
2011
+ h[$ = u.type] ?? (h[$] = { amount: 0, precision: 0 }), h[u.type] = K.add([i, h[u.type]]);
2012
+ }
2013
+ return Object.entries(h).reduce(
2014
+ (u, [i, _]) => {
2015
+ const L = {
2016
+ ..._,
2017
+ amount: Math.abs(_.amount)
2018
+ };
2019
+ return u[i] = /// comment, because without it formatter makes code uglier
2020
+ `${K.toFormatString({
2021
+ value: L,
2022
+ precision: 4
2023
+ })} ${f.unit.abbrev}`, u;
2024
+ },
2025
+ {}
2026
+ );
2027
+ }
2028
+ function ys(j, f) {
2029
+ if (!f)
2030
+ return null;
2031
+ let h = null;
2032
+ const F = j.flatMap(($) => {
2033
+ var u;
2034
+ return ((u = $.skus) == null ? void 0 : u.filter((i) => i.sku._id === f._id)) ?? [];
2035
+ }).flatMap(($) => {
2036
+ var u;
2037
+ return !$.history || ((u = $.history) == null ? void 0 : u.length) === 0 ? [] : $.history[0];
2038
+ });
2039
+ for (const $ of F) {
2040
+ const u = $.amounts;
2041
+ for (const i of u) {
2042
+ if (i.type !== ue.Enum.SALES)
2043
+ continue;
2044
+ const _ = i.measurement ? K.multiply([i.measurement.conversion, i.amount]) : i.amount;
2045
+ h ?? (h = K.fromNumber(0)), h = K.add([h, _]);
2046
+ }
2047
+ }
2048
+ return h != null ? (h.amount = Math.abs(h.amount), `${K.toFormatString({
2049
+ value: h,
2050
+ precision: 4
2051
+ })} ${f.unit.abbrev}`) : null;
2052
+ }
2053
+ const _s = { class: "flex items-center w-full fm-typo-en-title-md-800" }, ks = { class: "flex-1 line-clamp-2" }, bs = { class: "flex flex-col gap-32 w-full h-full" }, hs = { class: "flex flex-col gap-16" }, gs = { class: "flex items-center relative gap-4" }, xs = { class: "flex-1" }, Ss = { class: "flex items-center gap-8" }, ws = { class: "flex items-center gap-8" }, $s = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, As = { class: "fm-typo-cn-body-lg-600 flex-grow" }, Fs = {
2054
+ key: 0,
2055
+ class: "grid gap-12 fm-typo-en-body-md-400",
2056
+ style: { "grid-template-columns": "auto auto auto", "grid-auto-rows": "1fr" }
2057
+ }, js = { class: "flex flex-col gap-1" }, Cs = { class: "text-fm-color-typo-secondary" }, Bs = { class: "font-bold" }, Vs = { class: "flex flex-col gap-1" }, Ds = { class: "text-fm-color-typo-secondary flex" }, Is = { class: "font-bold" }, Ms = { class: "flex flex-col gap-1" }, Ts = { class: "text-fm-color-typo-secondary" }, Hs = { class: "font-bold" }, Es = { class: "flex flex-col gap-1" }, Us = { class: "text-fm-color-typo-secondary" }, Rs = { class: "font-bold" }, Ps = { class: "flex flex-col gap-1" }, Ns = { class: "text-fm-color-typo-secondary" }, Os = { class: "font-bold" }, Ls = { class: "flex flex-col gap-1" }, zs = { class: "text-fm-color-typo-secondary" }, Ys = { class: "font-bold" }, qs = { class: "flex flex-col gap-1" }, Gs = { class: "text-fm-color-typo-secondary" }, Ws = { class: "font-bold" }, Ks = { class: "flex flex-col gap-1" }, Xs = { class: "text-fm-color-typo-secondary" }, Js = { class: "font-bold" }, Qs = { class: "flex flex-col gap-1" }, Zs = { class: "text-fm-color-typo-secondary" }, ea = { class: "font-bold" }, ta = { class: "flex flex-col gap-1" }, oa = { class: "text-fm-color-typo-secondary" }, na = { key: 0 }, sa = { class: "font-bold" }, aa = { class: "flex flex-col gap-8" }, la = { class: "flex" }, ra = { class: "flex-1 flex flex-col gap-1" }, ia = { class: "flex items-center gap-8" }, ua = { class: "flex gap-1 items-center text-fm-color-typo-secondary" }, ca = { class: "font-bold" }, da = { class: "flex-1 flex flex-col gap-1" }, ma = { class: "flex items-center gap-8" }, fa = { class: "flex gap-1 items-center text-fm-color-typo-secondary" }, va = { class: "flex flex-col gap-1" }, pa = { class: "font-bold" }, ya = {
2058
+ key: 0,
2059
+ class: "flex-1 flex flex-col items-center gap-16"
2060
+ }, _a = { class: "fm-typo-en-body-lg-400 translate-x-4" }, ka = {
2061
+ key: 1,
2062
+ class: "flex flex-col gap-12"
2063
+ }, ba = {
2064
+ key: 2,
2065
+ class: "flex-1 flex flex-col items-center gap-8"
2066
+ }, ha = ["src"], ga = { class: "font-bold text-lg" }, xa = { class: "text-xs text-neutral-400 text-center" }, Sa = /* @__PURE__ */ ye({
2067
+ __name: "StockHistory",
2068
+ props: {
2069
+ sku: {},
2070
+ show: { type: Boolean }
2071
+ },
2072
+ emits: ["update:show"],
2073
+ setup(j) {
2074
+ const f = et(), h = ze(), v = Be(), F = dn(), $ = Ce(), u = N(() => Nt(f.currentCountry.value)), { t: i } = _e(), _ = j, { lastClosingBalance: L, lastClosingDate: D } = cn(
2075
+ () => $.currentLocationDBName,
2076
+ () => _.sku
2077
+ ), k = z(!1), d = xe(), C = z("adjustment"), a = z([
2078
+ { label: "Adjustment (Default)", value: "adjustment" }
2079
+ ]), x = z([]), l = z(io(0));
2080
+ async function t() {
2081
+ k.value = !0;
2082
+ try {
2083
+ await V(), await h.readStockBalance();
2084
+ } catch (A) {
2085
+ d.open({
2086
+ title: "Something went wrong",
2087
+ message: "Cannot fetch stock history. Please try again.",
2088
+ type: "error"
2089
+ }), console.log("failed at fetching item adjustment history", _.sku, l, A);
2090
+ } finally {
2091
+ k.value = !1;
2092
+ }
2093
+ }
2094
+ Ze(() => {
2095
+ t();
2096
+ }), ge([() => l.value, () => _.sku], () => {
2097
+ t();
2098
+ });
2099
+ const n = z([]), c = z([]), s = z(new Array());
2100
+ function T(A, m) {
2101
+ return m === "day" ? St(A) : nt(A);
2102
+ }
2103
+ function H(A, m) {
2104
+ const S = A.reduce(
2105
+ (y, B) => {
2106
+ const O = B.effectiveAt ?? De(B._id);
2107
+ if (!O)
2108
+ return y;
2109
+ const X = T(new Date(O), m);
2110
+ return y[X] ?? (y[X] = []), y[X].push(B), y;
2111
+ },
2112
+ {}
2113
+ );
2114
+ return Object.keys(S).map((y) => ({
2115
+ date: y,
2116
+ adjustments: S[y]
2117
+ }));
2118
+ }
2119
+ async function V() {
2120
+ let A = await v.readStockAdjustment(
2121
+ _.sku._id,
2122
+ dt(new Date(l.value.startDate)).toISOString(),
2123
+ mt(new Date(l.value.endDate)).toISOString()
2124
+ );
2125
+ n.value = A;
2126
+ const m = [
2127
+ ...new Set(
2128
+ A.filter(({ ref: S }) => S == null ? void 0 : S.startsWith("bill_")).map(({ ref: S }) => S)
2129
+ )
2130
+ ];
2131
+ await J(m), c.value = H(A, "day").map(({ date: S, adjustments: y }) => ({
2132
+ date: S,
2133
+ adjustments: y,
2134
+ adjustmentsByTime: H(y, "minute")
2135
+ }));
2136
+ try {
2137
+ const S = await v.readUnitCostHistory(
2138
+ _.sku._id,
2139
+ dt(new Date(l.value.startDate)).toISOString(),
2140
+ mt(new Date(l.value.endDate)).toISOString()
2141
+ );
2142
+ x.value = S;
2143
+ const y = /* @__PURE__ */ new Set();
2144
+ S.forEach((O) => {
2145
+ y.add(O.mechanism);
2146
+ });
2147
+ const B = [{ label: "Default", value: "adjustment" }];
2148
+ y.has(je.Enum.weightedAverage) && B.push({
2149
+ label: "Weighted Average (Beta)",
2150
+ value: je.Enum.weightedAverage
2151
+ }), y.has(je.Enum.netsuite) && B.push({ label: "NetSuite (Beta)", value: je.Enum.netsuite }), y.has(je.Enum["netsuite-average"]) && B.push({
2152
+ label: "NetSuite Average (Beta)",
2153
+ value: je.Enum["netsuite-average"]
2154
+ }), a.value = B, !y.has(C.value) && C.value !== "adjustment" && (C.value = "adjustment");
2155
+ } catch (S) {
2156
+ console.error("Failed to fetch unit cost history:", S);
2157
+ }
2158
+ }
2159
+ async function J(A) {
2160
+ if (!A.length) {
2161
+ s.value = [];
2162
+ return;
2163
+ }
2164
+ s.value = await F.findBillsById(A, ["_id", "seqNumber", "items"]).catch((m) => {
2165
+ var B;
2166
+ console.error("Error on using latest bill API, retrying using legacy api", m);
2167
+ const S = ((B = f.currentBusiness.value) == null ? void 0 : B._id) ?? "", y = $.currentLocation.doc._id;
2168
+ return F.findBillsByBusinessId(S, [y], A);
2169
+ });
2170
+ }
2171
+ const I = N(() => {
2172
+ const A = n.value, m = _.sku;
2173
+ return ps(A, m);
2174
+ }), W = N(() => {
2175
+ const A = n.value, m = _.sku;
2176
+ return ys(A, m);
2177
+ }), Y = N(() => {
2178
+ const A = [...n.value].computeFirst((S) => {
2179
+ var B, O;
2180
+ const y = (O = (B = S.skus) == null ? void 0 : B.find) == null ? void 0 : O.call(B, (X) => X.sku._id === _.sku._id);
2181
+ return y == null ? void 0 : y.fromBalance;
2182
+ }) ?? {
2183
+ amount: 0,
2184
+ precision: 0
2185
+ }, m = _.sku;
2186
+ return m ? `${K.toFormatString({
2187
+ value: A,
2188
+ precision: 4
2189
+ })} ${m.unit.abbrev}` : "";
2190
+ }), Z = N(() => {
2191
+ const A = [...n.value].reverse().computeFirst((S) => {
2192
+ var B, O;
2193
+ const y = (O = (B = S.skus) == null ? void 0 : B.find) == null ? void 0 : O.call(B, (X) => X.sku._id === _.sku._id);
2194
+ return y == null ? void 0 : y.toBalance;
2195
+ }) ?? {
2196
+ amount: 0,
2197
+ precision: 0
2198
+ }, m = _.sku;
2199
+ return m ? `${K.toFormatString({ value: A, precision: 4 })} ${m.unit.abbrev}` : "";
2200
+ }), oe = N(() => {
2201
+ const m = n.value.flatMap((S) => {
2202
+ var y;
2203
+ return ((y = S.skus) == null ? void 0 : y.flatMap((B) => B.amounts)) ?? [];
2204
+ }).filter((S) => S.amount.amount < 0).reduce(
2205
+ (S, y) => {
2206
+ const B = y.cost;
2207
+ if (!B) return S;
2208
+ const O = {
2209
+ ...eo(S, Math.max(S.precision, B.precision)),
2210
+ currency: B.currency
2211
+ };
2212
+ return {
2213
+ ...ot(O, B),
2214
+ currency: S.currency
2215
+ };
2216
+ },
2217
+ {
2218
+ amount: 0,
2219
+ precision: 0,
2220
+ currency: u.value
2221
+ }
2222
+ );
2223
+ return Re(m, !1, m.precision);
2224
+ });
2225
+ function ce() {
2226
+ const { startDate: A, endDate: m } = lo(l.value);
2227
+ A !== null && m !== null && (l.value = {
2228
+ startDate: A,
2229
+ endDate: m
2230
+ });
2231
+ }
2232
+ const pe = N(() => i("inventory.ingredient.valuationMethod.WAVG"));
2233
+ function ke(A, m) {
2234
+ if (C.value === "adjustment")
2235
+ return null;
2236
+ const S = x.value.filter(
2237
+ (O) => O.mechanism === C.value && O.skuId === _.sku._id
2238
+ );
2239
+ if (S.length === 0) return null;
2240
+ const y = S.find((O) => {
2241
+ const X = O.meta;
2242
+ return (X == null ? void 0 : X.adjustmentId) === A;
2243
+ });
2244
+ if (y) return y.cost;
2245
+ const B = [...S].filter((O) => new Date(O.snapshotAt) <= new Date(m)).sort((O, X) => new Date(X.snapshotAt).getTime() - new Date(O.snapshotAt).getTime());
2246
+ return B.length > 0 ? B[0].cost : null;
2247
+ }
2248
+ const be = N(() => {
2249
+ var y, B, O, X;
2250
+ const A = [...n.value].reverse().find((se) => {
2251
+ var ne, ie;
2252
+ return (ie = (ne = se.skus) == null ? void 0 : ne.find) == null ? void 0 : ie.call(ne, (de) => de.sku._id === _.sku._id);
2253
+ });
2254
+ if (!A) return "No data";
2255
+ const m = (y = A.skus) == null ? void 0 : y.find((se) => se.sku._id === _.sku._id);
2256
+ if (!m) return "No data";
2257
+ const S = m.toBalance;
2258
+ if (C.value === "adjustment") {
2259
+ const se = [...m.amounts].reverse()[0], ne = {
2260
+ amount: ((B = se.cost) == null ? void 0 : B.amount) ?? 0,
2261
+ precision: ((O = se.cost) == null ? void 0 : O.precision) ?? 0
2262
+ }, ie = se.amount, de = ie.amount == 0 ? K.fromNumber(0) : K.divide([ne, ie]), Se = K.multiply([de, S]);
2263
+ return {
2264
+ ...Se,
2265
+ currency: Se.amount === 0 ? u.value : ((X = se.cost) == null ? void 0 : X.currency) ?? u.value
2266
+ };
2267
+ } else {
2268
+ const se = A.effectiveAt ?? De(A._id), ne = ke(
2269
+ A._id,
2270
+ se ?? (/* @__PURE__ */ new Date()).toISOString()
2271
+ );
2272
+ if (!ne) return "No data";
2273
+ const ie = K.fromDinero(ne), de = K.multiply([ie, S]);
2274
+ return {
2275
+ ...de,
2276
+ currency: de.amount === 0 ? u.value : ne.currency
2277
+ };
2278
+ }
2279
+ }), w = N(() => {
2280
+ const A = [...n.value].reverse().computeFirst((S) => {
2281
+ var B, O;
2282
+ const y = (O = (B = S.skus) == null ? void 0 : B.find) == null ? void 0 : O.call(B, (X) => X.sku._id === _.sku._id);
2283
+ return y == null ? void 0 : y.toCostBalances;
2284
+ });
2285
+ return !A || A.some((S) => S.cost == null) ? "No data" : {
2286
+ ...A.reduce((S, y) => K.add([S, K.fromDinero(y.cost)]), {
2287
+ amount: 0,
2288
+ precision: 0
2289
+ }),
2290
+ currency: u.value
2291
+ };
2292
+ }), g = N(() => _.sku.valuation === it.Enum.FIFO ? w.value : be.value);
2293
+ function G() {
2294
+ const { startDate: A, endDate: m } = ro(l.value);
2295
+ A !== null && m !== null && (l.value = {
2296
+ startDate: A,
2297
+ endDate: m
2298
+ });
2299
+ }
2300
+ const q = z(!0), M = z(!1), R = z(null);
2301
+ function te(A) {
2302
+ R.value = R.value === A ? null : A;
2303
+ }
2304
+ const le = N(() => {
2305
+ const A = R.value;
2306
+ return A ? c.value.filter(
2307
+ (m) => m.adjustments.some(
2308
+ (S) => {
2309
+ var y;
2310
+ return (y = S.skus) == null ? void 0 : y.some(
2311
+ (B) => B.sku._id === _.sku._id && B.amounts.some((O) => O.type === A)
2312
+ );
2313
+ }
2314
+ )
2315
+ ) : c.value;
2316
+ }), re = qe(_, "show");
2317
+ return (A, m) => {
2318
+ const S = P("FmButton"), y = P("FmField"), B = P("FmDateRangePicker"), O = P("FmSpacer"), X = P("FmSwitch"), se = P("FmIcon"), ne = P("FmTooltip"), ie = P("FmMenuDivider"), de = P("FmChip"), Se = P("FmSelect"), Te = P("FmCardSection"), Ae = P("FmCard"), He = P("FmCircularProgress"), jt = P("FmSideSheet");
2319
+ return p(), ee(jt, {
2320
+ "dismiss-away": "",
2321
+ modelValue: o(re),
2322
+ "onUpdate:modelValue": m[8] || (m[8] = (Ve) => Ne(re) ? re.value = Ve : null),
2323
+ "close-button": !1,
2324
+ "max-width": 800
2325
+ }, {
2326
+ "side-sheet-header": U(() => [
2327
+ e("div", _s, [
2328
+ e("div", ks, r(o(i)("inventory.stock.history.title", [A.sku.name])), 1),
2329
+ b(S, {
2330
+ variant: "tertiary",
2331
+ "prepend-icon": "close",
2332
+ onClick: m[0] || (m[0] = (Ve) => re.value = !1)
2333
+ })
2334
+ ])
2335
+ ]),
2336
+ default: U(() => {
2337
+ var Ve;
2338
+ return [
2339
+ e("div", bs, [
2340
+ e("div", hs, [
2341
+ e("div", gs, [
2342
+ e("div", xs, [
2343
+ b(B, {
2344
+ modelValue: l.value,
2345
+ "onUpdate:modelValue": m[1] || (m[1] = (me) => l.value = me),
2346
+ "show-predefined-range": "",
2347
+ "start-label": "",
2348
+ "end-label": "",
2349
+ "z-index": 50
2350
+ }, {
2351
+ "trigger-button": U(({ opened: me }) => [
2352
+ b(y, {
2353
+ "prepend-icon": "calendar_month",
2354
+ focused: me
2355
+ }, {
2356
+ default: U(() => [
2357
+ ve(r(l.value.startDate) + " - " + r(l.value.endDate), 1)
2358
+ ]),
2359
+ _: 2
2360
+ }, 1032, ["focused"])
2361
+ ]),
2362
+ _: 1
2363
+ }, 8, ["modelValue"])
2364
+ ]),
2365
+ b(S, {
2366
+ variant: "tertiary",
2367
+ onClick: m[2] || (m[2] = (me) => ce()),
2368
+ "prepend-icon": "navigate_before"
2369
+ }),
2370
+ b(S, {
2371
+ variant: "tertiary",
2372
+ onClick: m[3] || (m[3] = (me) => G()),
2373
+ "prepend-icon": "navigate_next"
2374
+ })
2375
+ ]),
2376
+ e("div", Ss, [
2377
+ R.value ? (p(), ee(S, {
2378
+ key: 0,
2379
+ variant: "secondary",
2380
+ label: o(i)(`inventory.inventoryAdjustment.type.${R.value}`),
2381
+ "append-icon": "close",
2382
+ onClick: m[4] || (m[4] = (me) => R.value = null)
2383
+ }, null, 8, ["label"])) : Q("", !0),
2384
+ b(O),
2385
+ b(Ge, null, {
2386
+ default: U(() => [
2387
+ e("div", ws, [
2388
+ e("div", $s, r(o(i)("inventory.stock.history.debug")), 1),
2389
+ b(X, {
2390
+ modelValue: M.value,
2391
+ "onUpdate:modelValue": m[5] || (m[5] = (me) => M.value = me)
2392
+ }, null, 8, ["modelValue"])
2393
+ ])
2394
+ ]),
2395
+ _: 1
2396
+ })
2397
+ ]),
2398
+ k.value ? Q("", !0) : (p(), ee(Ae, {
2399
+ key: 0,
2400
+ variant: "outlined"
2401
+ }, {
2402
+ default: U(() => [
2403
+ b(Te, { class: "flex flex-col gap-4" }, {
2404
+ default: U(() => [
2405
+ e("div", {
2406
+ class: he(["flex items-center cursor-pointer", { "pb-16": q.value }]),
2407
+ onClick: m[6] || (m[6] = (me) => q.value = !q.value)
2408
+ }, [
2409
+ e("div", As, r(o(i)("inventory.stock.history.summary.title")), 1),
2410
+ b(se, {
2411
+ name: q.value ? "expand_more" : "expand_less",
2412
+ color: "#777777",
2413
+ size: "md"
2414
+ }, null, 8, ["name"])
2415
+ ], 2),
2416
+ q.value ? (p(), E("div", Fs, [
2417
+ e("div", js, [
2418
+ e("div", Cs, r(o(i)("inventory.stock.history.summary.totalPurchase")), 1),
2419
+ e("div", Bs, r(I.value.PURCHASE), 1)
2420
+ ]),
2421
+ e("div", Vs, [
2422
+ e("div", Ds, [
2423
+ ve(r(o(i)("inventory.stock.history.summary.totalSales")) + "  ", 1),
2424
+ W.value != null ? (p(), ee(ne, {
2425
+ key: 0,
2426
+ variant: "plain",
2427
+ placement: "top",
2428
+ content: `Before: ${W.value}`,
2429
+ "z-index": 50
2430
+ }, {
2431
+ default: U(() => [
2432
+ b(se, {
2433
+ name: "warning",
2434
+ size: "sm"
2435
+ })
2436
+ ]),
2437
+ _: 1
2438
+ }, 8, ["content"])) : Q("", !0)
2439
+ ]),
2440
+ e("div", Is, r(I.value.SALES), 1)
2441
+ ]),
2442
+ e("div", Ms, [
2443
+ e("div", Ts, r(o(i)("inventory.stock.history.summary.totalLose")), 1),
2444
+ e("div", Hs, r(I.value.LOSE), 1)
2445
+ ]),
2446
+ e("div", Es, [
2447
+ e("div", Us, r(o(i)("inventory.stock.history.summary.totalRequest")), 1),
2448
+ e("div", Rs, r(I.value.REQUEST), 1)
2449
+ ]),
2450
+ e("div", Ps, [
2451
+ e("div", Ns, r(o(i)("inventory.stock.history.summary.totalReceive")), 1),
2452
+ e("div", Os, r(I.value.RECEIVE), 1)
2453
+ ]),
2454
+ e("div", Ls, [
2455
+ e("div", zs, r(o(i)("inventory.stock.history.summary.totalConvert")), 1),
2456
+ e("div", Ys, r(I.value.CONVERT), 1)
2457
+ ]),
2458
+ e("div", qs, [
2459
+ e("div", Gs, r(o(i)("inventory.stock.history.summary.totalDamage")), 1),
2460
+ e("div", Ws, r(I.value.DAMAGE), 1)
2461
+ ]),
2462
+ e("div", Ks, [
2463
+ e("div", Xs, r(o(i)("inventory.stock.history.summary.firstAdjustmentBalance")), 1),
2464
+ e("div", Js, r(Y.value), 1)
2465
+ ]),
2466
+ e("div", Qs, [
2467
+ e("div", Zs, r(o(i)("inventory.stock.history.summary.lastAdjustmentBalance")), 1),
2468
+ e("div", ea, r(Z.value), 1)
2469
+ ]),
2470
+ e("div", ta, [
2471
+ e("div", oa, [
2472
+ ve(r(o(i)("inventory.stock.history.summary.lastClosingBalance")) + " ", 1),
2473
+ o(D) ? (p(), E("span", na, "(" + r(o(D)) + ")", 1)) : Q("", !0)
2474
+ ]),
2475
+ e("div", sa, r(o(L)), 1)
2476
+ ])
2477
+ ])) : Q("", !0),
2478
+ q.value ? (p(), ee(wt, {
2479
+ key: 1,
2480
+ "feature-key": "total-cost"
2481
+ }, {
2482
+ default: U(() => [
2483
+ e("div", aa, [
2484
+ b(ie, { class: "w-full" }),
2485
+ e("div", la, [
2486
+ e("div", ra, [
2487
+ e("div", ia, [
2488
+ e("div", ua, [
2489
+ ve(r(o(i)("inventory.stock.history.estimatedValue")) + " ", 1),
2490
+ b(ne, {
2491
+ variant: "plain",
2492
+ placement: "top",
2493
+ content: `[${pe.value}] ${o(i)("inventory.stock.history.estimatedValueTooltip")}`,
2494
+ "z-index": 50
2495
+ }, {
2496
+ default: U(() => [
2497
+ b(se, {
2498
+ name: "help",
2499
+ size: "sm"
2500
+ })
2501
+ ]),
2502
+ _: 1
2503
+ }, 8, ["content"])
2504
+ ])
2505
+ ]),
2506
+ e("div", ca, [
2507
+ A.sku.valuation === o(it).Enum.FIFO ? (p(), E(ae, { key: 0 }, [
2508
+ b(de, {
2509
+ label: "FIFO",
2510
+ compact: ""
2511
+ }),
2512
+ ve(" " + r(typeof g.value != "string" ? o(Re)(
2513
+ g.value,
2514
+ !1,
2515
+ g.value.precision
2516
+ ) : g.value), 1)
2517
+ ], 64)) : (p(), E(ae, { key: 1 }, [
2518
+ ve(r(typeof g.value != "string" ? o(Re)(
2519
+ g.value,
2520
+ !1,
2521
+ g.value.precision
2522
+ ) : g.value), 1)
2523
+ ], 64))
2524
+ ]),
2525
+ b(Se, {
2526
+ modelValue: C.value,
2527
+ "onUpdate:modelValue": m[7] || (m[7] = (me) => C.value = me),
2528
+ items: a.value,
2529
+ compact: "",
2530
+ size: "sm",
2531
+ style: { width: "200px" }
2532
+ }, null, 8, ["modelValue", "items"])
2533
+ ]),
2534
+ e("div", da, [
2535
+ e("div", ma, [
2536
+ e("div", fa, [
2537
+ ve(r(o(i)("inventory.stock.history.costSold")) + " ", 1),
2538
+ b(ne, {
2539
+ variant: "plain",
2540
+ placement: "top",
2541
+ "z-index": 50
2542
+ }, {
2543
+ content: U(() => [
2544
+ e("div", va, r(o(i)("inventory.stock.history.costSoldTooltip")), 1)
2545
+ ]),
2546
+ default: U(() => [
2547
+ b(se, {
2548
+ name: "help",
2549
+ size: "sm"
2550
+ })
2551
+ ]),
2552
+ _: 1
2553
+ })
2554
+ ])
2555
+ ]),
2556
+ e("div", pa, r(oe.value), 1)
2557
+ ])
2558
+ ])
2559
+ ])
2560
+ ]),
2561
+ _: 1
2562
+ })) : Q("", !0)
2563
+ ]),
2564
+ _: 1
2565
+ })
2566
+ ]),
2567
+ _: 1
2568
+ }))
2569
+ ]),
2570
+ k.value ? (p(), E("div", ya, [
2571
+ b(O),
2572
+ b(He, { size: "xl" }),
2573
+ e("div", _a, r(o(i)("inventory.stock.history.loading")), 1),
2574
+ b(O),
2575
+ b(O)
2576
+ ])) : c.value && ((Ve = c.value) == null ? void 0 : Ve.length) > 0 ? (p(), E("div", ka, [
2577
+ (p(!0), E(ae, null, fe(le.value, (me) => (p(), E(ae, {
2578
+ key: me.date
2579
+ }, [
2580
+ A.sku ? (p(), ee(vs, {
2581
+ key: 0,
2582
+ record: me,
2583
+ sku: A.sku,
2584
+ bills: s.value,
2585
+ "unit-cost-history": x.value,
2586
+ "cost-mechanism": C.value,
2587
+ "type-filter": R.value,
2588
+ debug: M.value,
2589
+ onRefreshHistory: t,
2590
+ onToggleType: te
2591
+ }, null, 8, ["record", "sku", "bills", "unit-cost-history", "cost-mechanism", "type-filter", "debug"])) : Q("", !0)
2592
+ ], 64))), 128))
2593
+ ])) : (p(), E("div", ba, [
2594
+ b(O),
2595
+ e("div", null, [
2596
+ e("img", {
2597
+ src: o(uo),
2598
+ alt: "List is empty"
2599
+ }, null, 8, ha)
2600
+ ]),
2601
+ e("div", ga, r(o(i)("inventory.stock.history.noRecords")), 1),
2602
+ e("div", xa, r(o(i)("inventory.stock.history.changeDateRange")), 1),
2603
+ b(O),
2604
+ b(O)
2605
+ ]))
2606
+ ])
2607
+ ];
2608
+ }),
2609
+ _: 1
2610
+ }, 8, ["modelValue"]);
2611
+ };
2612
+ }
2613
+ }), wa = /* @__PURE__ */ ye({
2614
+ __name: "HrmPermissionGuard",
2615
+ props: {
2616
+ permission: { default: void 0 },
2617
+ permissions: { default: void 0 },
2618
+ mode: { default: "all" }
2619
+ },
2620
+ setup(j) {
2621
+ const f = j, h = N(() => {
2622
+ const F = [];
2623
+ return f.permission && F.push(f.permission), f.permissions && F.push(...f.permissions), F;
2624
+ });
2625
+ Vt(() => {
2626
+ });
2627
+ const { hasPermission: v } = $t(h, () => f.mode);
2628
+ return (F, $) => o(v) ? at(F.$slots, "default", { key: 0 }) : at(F.$slots, "fallback", { key: 1 });
2629
+ }
2630
+ });
2631
+ function $a(j) {
2632
+ const f = fo(), h = Ce(), v = z(!1), F = z(null), $ = z(null);
2633
+ let u = null, i = !1, _ = !1;
2634
+ function L() {
2635
+ if (_) return;
2636
+ const d = h.currentLocationDBName;
2637
+ if (!d) return;
2638
+ _ = !0;
2639
+ const C = {
2640
+ type: "refresh-balance",
2641
+ params: { locationId: d }
2642
+ }, { unsubscribe: a, initialState: x } = f.subscribe(
2643
+ C,
2644
+ D
2645
+ );
2646
+ u = a, x.then((l) => {
2647
+ l != null && l.initialState && D(l.initialState);
2648
+ }).catch((l) => {
2649
+ console.error("Failed to fetch refresh-balance initial state", l);
2650
+ });
2651
+ }
2652
+ async function D(d) {
2653
+ var C, a, x;
2654
+ if (!(!_ || !d)) {
2655
+ if (F.value = d, d.completedAt && ($.value = d.completedAt), d.message === "processing" || !d.completedAt && !d.message) {
2656
+ i = !0, v.value = !0;
2657
+ return;
2658
+ }
2659
+ if (d.message === "completed" || d.completedAt) {
2660
+ if (!i) return;
2661
+ k();
2662
+ try {
2663
+ await j.onCompleted();
2664
+ } catch (l) {
2665
+ console.error("Failed to reload after refresh", l);
2666
+ }
2667
+ return;
2668
+ }
2669
+ if (d.message === "error" || (C = d.message) != null && C.startsWith("error:")) {
2670
+ console.log("Stock balance refresh error:", d.message);
2671
+ const l = (a = d.message) != null && a.startsWith("error:") ? d.message.slice(6).trim() : "Failed to refresh stock balance.";
2672
+ k(), await ((x = j.onError) == null ? void 0 : x.call(j, l));
2673
+ }
2674
+ }
2675
+ }
2676
+ function k() {
2677
+ u && (u(), u = null), _ = !1, i = !1, v.value = !1, F.value = null;
2678
+ }
2679
+ return Dt(() => {
2680
+ k();
2681
+ }), {
2682
+ refreshing: v,
2683
+ refreshStatus: F,
2684
+ lastCompletedAt: $,
2685
+ startListening: L,
2686
+ stopListening: k
2687
+ };
2688
+ }
2689
+ const Aa = {
2690
+ key: 0,
2691
+ class: "flex items-center gap-1"
2692
+ }, Fa = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, ja = { class: "flex flex-col gap-8" }, Ca = { class: "flex flex-col" }, Ba = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, Va = { class: "fm-typo-en-body-lg-600 text-fm-color-typo-primary line-clamp-1" }, cl = /* @__PURE__ */ ye({
2693
+ __name: "StockView",
2694
+ setup(j) {
2695
+ const { t: f } = _e(), h = Le(), v = Ce(), F = ze(), $ = At(), u = Be(), i = ht(), _ = vo(), { columnDefs: L } = xo(), D = et(), { hasPermission: k } = $t(
2696
+ N(() => [
2697
+ {
2698
+ action: Ee.Action.manage,
2699
+ subject: Ee.Subject.Business.inventory_stockAdjustment
2700
+ }
2701
+ ])
2702
+ ), d = N(
2703
+ () => {
2704
+ var M;
2705
+ return k.value || ((M = D.sessionUser.value) == null ? void 0 : M.role.isAdmin);
2706
+ }
2707
+ ), C = Ye(), a = xe();
2708
+ v.watchLocation(J);
2709
+ const x = N(
2710
+ () => new Set(_.getAvailableItems(_.businessSubsidiaryId))
2711
+ ), l = z(!1), t = z(!1), { refreshing: n, lastCompletedAt: c, startListening: s, stopListening: T } = $a({
2712
+ onCompleted: async () => {
2713
+ await J(), t.value = !1, a.open({
2714
+ title: "Balance refreshed",
2715
+ message: "Stock balance has been recalculated.",
2716
+ type: "success"
2717
+ });
2718
+ },
2719
+ onError: (M) => {
2720
+ t.value = !1, console.log("Error refreshing stock balance", M), a.open({
2721
+ title: f("inventory.common.refreshFailed"),
2722
+ message: M || f("inventory.stock.stock_balance.refreshBalanceError"),
2723
+ type: "error"
2724
+ });
2725
+ }
2726
+ }), H = N(() => n.value || t.value);
2727
+ async function V() {
2728
+ s();
2729
+ const M = f("inventory.stock.stock_balance.refreshBalanceDescription"), R = c.value ? `${M}
2730
+
2731
+ Last refreshed: ${new Date(c.value).toLocaleString()}` : M;
2732
+ C.open({
2733
+ title: f("inventory.stock.stock_balance.refreshBalance"),
2734
+ message: R,
2735
+ closeButton: !0,
2736
+ primaryActions: {
2737
+ text: f("common.confirm"),
2738
+ close: !1,
2739
+ isLoading: H,
2740
+ disabled: H
2741
+ },
2742
+ secondaryActions: {
2743
+ text: f("common.close"),
2744
+ close: !0,
2745
+ variant: "tertiary",
2746
+ disabled: H
2747
+ }
2748
+ }).onPrimary(async () => {
2749
+ if (!t.value) {
2750
+ t.value = !0;
2751
+ try {
2752
+ await u.recalculation.refreshCurrentBalances();
2753
+ } catch (te) {
2754
+ console.log("Failed to queue refresh balan22ce", typeof te);
2755
+ const le = typeof te == "object" ? JSON.stringify(te) : String(te);
2756
+ console.log("Error details:", le), t.value = !1, a.open({
2757
+ title: f("inventory.common.refreshFailed"),
2758
+ message: (te instanceof Error ? te.message : null) ?? f("inventory.stock.stock_balance.refreshBalanceError"),
2759
+ type: "error"
2760
+ });
2761
+ }
2762
+ }
2763
+ }).onClose(() => {
2764
+ t.value = !1, T();
2765
+ });
2766
+ }
2767
+ async function J() {
2768
+ if (v._currentLocation) {
2769
+ l.value = !0;
2770
+ try {
2771
+ await F.readStockBalance(), await i.readStockEstimateBalance();
2772
+ } catch (M) {
2773
+ a.open({
2774
+ title: f("inventory.stock.error.title"),
2775
+ message: f("inventory.stock.error.message"),
2776
+ type: "error"
2777
+ }), console.error("error on fetch stock balance", M);
2778
+ } finally {
2779
+ l.value = !1;
2780
+ }
2781
+ }
2782
+ }
2783
+ const I = N(() => [
2784
+ {
2785
+ type: "string",
2786
+ key: "status",
2787
+ entity: "sku",
2788
+ values: ["Active", "Inactive"]
2789
+ }
2790
+ ]), W = z({
2791
+ logic: "AND",
2792
+ rules: [
2793
+ {
2794
+ property: "status",
2795
+ operator: "$in",
2796
+ value: ["Active"],
2797
+ type: "string"
2798
+ }
2799
+ ]
2800
+ }), Y = N(() => {
2801
+ var te, le, re;
2802
+ const M = W.value ? po.build(W.value) : null, R = [];
2803
+ for (const A of h.skus) {
2804
+ let m = !0;
2805
+ if (_.isEnabled && oe.value && x.value && m && (m = x.value.has(A._id)), M && m && (m = yo(
2806
+ {
2807
+ status: A.isInactive ? "Inactive" : "Active"
2808
+ },
2809
+ M
2810
+ )), m) {
2811
+ const S = A.trackingMeasurement;
2812
+ let y = (le = (te = F.stockBalance.skus) == null ? void 0 : te.find(
2813
+ (X) => X.id === A._id
2814
+ )) == null ? void 0 : le.balance, B = i.inventoryForecast.skus.find(
2815
+ (X) => X.id === A._id
2816
+ );
2817
+ const O = {
2818
+ ...A,
2819
+ balance: y ?? {
2820
+ amount: 0,
2821
+ precision: 0
2822
+ },
2823
+ operator: B == null ? void 0 : B.operator,
2824
+ day: (B == null ? void 0 : B.depletionDays) ?? void 0,
2825
+ trackingUnitAbbrev: S ? ((re = A.unit.measurements.find((X) => X.id === S)) == null ? void 0 : re.abbrev) ?? "" : A.unit.abbrev
2826
+ };
2827
+ R.push(O);
2828
+ }
2829
+ }
2830
+ return R;
2831
+ }), Z = z(""), oe = z(!0), { breakpoints: ce } = Gt(), pe = N(() => ce.value.xs || ce.value.sm), ke = N(() => pe.value ? 10 : 20), be = Mt(), w = N(() => {
2832
+ const M = [
2833
+ {
2834
+ label: f("inventory.stock.stock_balance.refreshBalance"),
2835
+ value: "refresh-balance",
2836
+ isPrimary: !0,
2837
+ prependIcon: "calculate"
2838
+ },
2839
+ {
2840
+ label: f("inventory.common.refresh"),
2841
+ value: "refresh"
2842
+ },
2843
+ {
2844
+ label: f("inventory.common.export"),
2845
+ value: "export"
2846
+ }
2847
+ ];
2848
+ return d.value && M.push({
2849
+ label: f("inventory.stock.stock_adjustment.title"),
2850
+ value: "stockAdjustment"
2851
+ }), M;
2852
+ }), g = z(!1);
2853
+ function G() {
2854
+ g.value = !0;
2855
+ }
2856
+ function q(M) {
2857
+ switch (M) {
2858
+ case "refresh-balance":
2859
+ return V();
2860
+ case "refresh":
2861
+ return J();
2862
+ case "export":
2863
+ return Lt(Y.value);
2864
+ case "stockAdjustment":
2865
+ return G();
2866
+ }
2867
+ }
2868
+ return (M, R) => {
2869
+ const te = P("FmSwitch"), le = P("FmTable");
2870
+ return p(), ee(Tt, {
2871
+ title: o(f)("inventory.stock.title"),
2872
+ actions: w.value,
2873
+ "onClick:action": q
2874
+ }, {
2875
+ default: U(() => {
2876
+ var re, A, m, S;
2877
+ return [
2878
+ e("div", {
2879
+ class: he([
2880
+ "flex flex-col gap-8 max-h-full",
2881
+ {
2882
+ "p-0": pe.value,
2883
+ "px-24 ": !pe.value
2884
+ }
2885
+ ])
2886
+ }, [
2887
+ b(mo, {
2888
+ searchable: "",
2889
+ "change-location": "",
2890
+ search: Z.value,
2891
+ "onUpdate:search": R[1] || (R[1] = (y) => Z.value = y),
2892
+ "hide-filter-options": !0,
2893
+ filterable: "",
2894
+ "filter-attributes": I.value,
2895
+ filter: W.value,
2896
+ "onUpdate:filter": R[2] || (R[2] = (y) => W.value = y)
2897
+ }, {
2898
+ default: U(() => [
2899
+ o(_).isEnabled ? (p(), E("div", Aa, [
2900
+ e("span", Fa, r(o(f)("inventory.integration.netsuite.subsidiaryHierarchy.filtering")), 1),
2901
+ b(zt),
2902
+ b(Ge, null, {
2903
+ default: U(() => [
2904
+ b(te, {
2905
+ modelValue: oe.value,
2906
+ "onUpdate:modelValue": R[0] || (R[0] = (y) => oe.value = y)
2907
+ }, null, 8, ["modelValue"])
2908
+ ]),
2909
+ _: 1
2910
+ })
2911
+ ])) : Q("", !0)
2912
+ ]),
2913
+ _: 1
2914
+ }, 8, ["search", "filter-attributes", "filter"]),
2915
+ (p(), ee(le, {
2916
+ style: Qe(o(be).tableHeight),
2917
+ "column-defs": o(L),
2918
+ "row-data": Y.value,
2919
+ "search-value": Z.value,
2920
+ loading: l.value || o(n) || !o(v)._currentLocation,
2921
+ key: (re = o(v)._currentLocation) == null ? void 0 : re.dbName,
2922
+ onRowClick: R[3] || (R[3] = (y) => o($).showSkuHistory(y.original)),
2923
+ "page-size": ke.value
2924
+ }, {
2925
+ "list-row": U((y) => [
2926
+ b(co, {
2927
+ row: y,
2928
+ onRowClick: o($).showSkuHistory
2929
+ }, {
2930
+ default: U((B) => {
2931
+ var O, X, se, ne, ie, de, Se, Te, Ae, He;
2932
+ return [
2933
+ e("div", ja, [
2934
+ e("div", Ca, [
2935
+ e("div", Ba, [
2936
+ b(o(ft), {
2937
+ render: (se = (X = (O = B.code) == null ? void 0 : O.column) == null ? void 0 : X.columnDef) == null ? void 0 : se.cell,
2938
+ props: (ie = (ne = B.code) == null ? void 0 : ne.getContext) == null ? void 0 : ie.call(ne)
2939
+ }, null, 8, ["render", "props"])
2940
+ ]),
2941
+ e("div", Va, [
2942
+ b(o(ft), {
2943
+ render: (Te = (Se = (de = B.name) == null ? void 0 : de.column) == null ? void 0 : Se.columnDef) == null ? void 0 : Te.cell,
2944
+ props: (He = (Ae = B.name) == null ? void 0 : Ae.getContext) == null ? void 0 : He.call(Ae)
2945
+ }, null, 8, ["render", "props"])
2946
+ ])
2947
+ ]),
2948
+ e("div", null, [
2949
+ b(Je, {
2950
+ days: y.original.day
2951
+ }, null, 8, ["days"])
2952
+ ]),
2953
+ e("div", null, [
2954
+ b(kt, {
2955
+ class: "xs:w-[160px]",
2956
+ unit: y.original.unit,
2957
+ sku: y.original,
2958
+ amount: y.original.balance,
2959
+ "default-tracking-measurement": y.original.trackingMeasurement ?? void 0
2960
+ }, null, 8, ["unit", "sku", "amount", "default-tracking-measurement"])
2961
+ ])
2962
+ ])
2963
+ ];
2964
+ }),
2965
+ _: 2
2966
+ }, 1032, ["row", "onRowClick"])
2967
+ ]),
2968
+ _: 1
2969
+ }, 8, ["style", "column-defs", "row-data", "search-value", "loading", "page-size"]))
2970
+ ], 2),
2971
+ (p(), ee(It, { to: "body" }, [
2972
+ (A = o($).stockHistoryProps) != null && A.sku ? (p(), ee(Sa, lt(We({ key: 0 }, o($).stockHistoryProps)), null, 16)) : Q("", !0),
2973
+ (m = o($).convertSkuDialogProps) != null && m.sku ? (p(), ee(Eo, lt(We({ key: 1 }, o($).convertSkuDialogProps)), null, 16)) : Q("", !0),
2974
+ (S = o($).adjustSkuDialogProps) != null && S.stock ? (p(), ee(Xo, We({ key: 2 }, o($).adjustSkuDialogProps, {
2975
+ onSubmitted: R[4] || (R[4] = (y) => J())
2976
+ }), null, 16)) : Q("", !0),
2977
+ b(wa, {
2978
+ permission: {
2979
+ action: o(Ee).Action.manage,
2980
+ subject: o(Ee).Subject.Business.inventory_stockAdjustment
2981
+ }
2982
+ }, {
2983
+ default: U(() => [
2984
+ g.value ? (p(), ee(un, {
2985
+ key: 0,
2986
+ show: g.value,
2987
+ "onUpdate:show": R[5] || (R[5] = (y) => g.value = y),
2988
+ onSubmitted: R[6] || (R[6] = (y) => J())
2989
+ }, null, 8, ["show"])) : Q("", !0)
2990
+ ]),
2991
+ _: 1
2992
+ }, 8, ["permission"])
2993
+ ]))
2994
+ ];
2995
+ }),
2996
+ _: 1
2997
+ }, 8, ["title", "actions"]);
2998
+ };
2999
+ }
3000
+ });
3001
+ export {
3002
+ cl as default
3003
+ };