Created
March 17, 2025 08:33
-
-
Save dheerapat/f9b4bf2c7ff1021b061224425f1c1f27 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| enum WarehouseLocationERP { | |
| Thaphra = 'WH02', | |
| Thairath = 'WH03', | |
| Province = 'WH90', | |
| MachineInventory = 'WH25' | |
| } | |
| enum VirtualWarehouseERP { | |
| ReadyToUseWarehouse = '02', | |
| Machine = '03', | |
| Repack = '05' | |
| }; | |
| interface MaterialERPFilter { | |
| warehouseLocation: WarehouseLocationERP | |
| virtualWarehouses?: VirtualWarehouseERP[] | |
| } | |
| function getLocationCode (warehouseLocation: WarehouseLocationERP, virtualWarehouse?: VirtualWarehouseERP): string { | |
| if (!virtualWarehouse) { | |
| return warehouseLocation; | |
| } | |
| if (virtualWarehouse == VirtualWarehouseERP.Machine) { | |
| return WarehouseLocationERP.MachineInventory; | |
| } | |
| return `${warehouseLocation}-${virtualWarehouse}`; | |
| } | |
| function makeMaterialFilter (filter: MaterialERPFilter[]): string { | |
| let filterValue = ''; | |
| for (const value of filter) { | |
| const virtualWarehouses = value.virtualWarehouses || []; | |
| if (virtualWarehouses.length > 0) { | |
| for (const virtualWarehouse of virtualWarehouses) { | |
| const locationCodeFilter = `locationCode eq '${getLocationCode(value.warehouseLocation, virtualWarehouse)}'`; | |
| filterValue = filterValue ? `${filterValue} or ${locationCodeFilter}` : locationCodeFilter; | |
| } | |
| } | |
| } | |
| // TODO: For now, made the quick action and will back to refactor this | |
| return filterValue ? `?$filter=(${filterValue}) and (InventoryPostingGroup eq 'IG' or InventoryPostingGroup eq 'FG')` : ''; | |
| } | |
| console.log(makeMaterialFilter([{warehouseLocation: WarehouseLocationERP.Thairath, virtualWarehouses: [VirtualWarehouseERP.ReadyToUseWarehouse]}])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment