@things-factory/worksheet-base 6.2.140 → 6.2.147
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.
|
@@ -16,11 +16,7 @@ async function generateInventoryHistory(inventory, refOrder, transactionType, qt
|
|
|
16
16
|
throw new Error(`Can't find out ID of inventory.`);
|
|
17
17
|
if (!(refOrder === null || refOrder === void 0 ? void 0 : refOrder.id) || !refOrder.name)
|
|
18
18
|
throw new Error(`Can't find out ID or Name of Reference Order`);
|
|
19
|
-
if (!(inventory === null || inventory === void 0 ? void 0 : inventory.domain) ||
|
|
20
|
-
!(inventory === null || inventory === void 0 ? void 0 : inventory.bizplace) ||
|
|
21
|
-
!((_a = inventory === null || inventory === void 0 ? void 0 : inventory.product) === null || _a === void 0 ? void 0 : _a.id) ||
|
|
22
|
-
!((_b = inventory === null || inventory === void 0 ? void 0 : inventory.warehouse) === null || _b === void 0 ? void 0 : _b.id) ||
|
|
23
|
-
!((_c = inventory === null || inventory === void 0 ? void 0 : inventory.location) === null || _c === void 0 ? void 0 : _c.id)) {
|
|
19
|
+
if (!(inventory === null || inventory === void 0 ? void 0 : inventory.domain) || !(inventory === null || inventory === void 0 ? void 0 : inventory.bizplace) || !((_a = inventory === null || inventory === void 0 ? void 0 : inventory.product) === null || _a === void 0 ? void 0 : _a.id) || !((_b = inventory === null || inventory === void 0 ? void 0 : inventory.warehouse) === null || _b === void 0 ? void 0 : _b.id) || !((_c = inventory === null || inventory === void 0 ? void 0 : inventory.location) === null || _c === void 0 ? void 0 : _c.id)) {
|
|
24
20
|
inventory = await invRepo.findOne({
|
|
25
21
|
where: { id: inventory.id },
|
|
26
22
|
relations: ['domain', 'bizplace', 'product', 'warehouse', 'location']
|
|
@@ -93,6 +89,7 @@ async function generateInventoryHistory(inventory, refOrder, transactionType, qt
|
|
|
93
89
|
inventoryHistory.bizplace = inventory.bizplace;
|
|
94
90
|
inventoryHistory.creator = user;
|
|
95
91
|
inventoryHistory.updater = user;
|
|
92
|
+
inventoryHistory.auxInfo3 = inventory.auxInfo3;
|
|
96
93
|
inventoryHistory = await invHistoryRepo.save(inventoryHistory);
|
|
97
94
|
if (inventory.lastSeq !== seq) {
|
|
98
95
|
await invRepo.save({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inventory-util.js","sourceRoot":"","sources":["../../server/utils/inventory-util.ts"],"names":[],"mappings":";;;AAIA,+DAAsD;AACtD,iDAA6D;AAC7D,mEAQuC;AAEvC;;;GAGG;AACI,KAAK,UAAU,wBAAwB,CAC5C,SAAoB,EACpB,QAAa,EACb,eAAuB,EACvB,MAAc,CAAC,EACf,WAAmB,CAAC,EACpB,IAAU,EACV,MAAsB,EACtB,kBAA6B,EAAE;;IAE/B,MAAM,cAAc,GAClB,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,aAAa,CAAC,iCAAgB,CAAC,KAAI,IAAA,qBAAa,EAAC,iCAAgB,CAAC,CAAA;IAC5E,MAAM,OAAO,GAA0B,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,aAAa,CAAC,0BAAS,CAAC,KAAI,IAAA,qBAAa,EAAC,0BAAS,CAAC,CAAA;IAEnG,IAAI,CAAC,CAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,EAAE,CAAA;QAAE,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAA;IACtE,IAAI,CAAC,CAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,EAAE,CAAA,IAAI,CAAC,QAAQ,CAAC,IAAI;QAAE,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAA;IACpG,IACE,CAAC,CAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,MAAM,CAAA;QAClB,CAAC,CAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,QAAQ,CAAA;QACpB,CAAC,CAAA,MAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,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IAAI,CAAC,gBAAgB,IAAI,cAAc,IAAI,CAAC;QAAE,OAAO,KAAK,CAAA;IAEpF,IAAI,IAAI,GAAS,IAAI,IAAI,EAAE,CAAA;IAC3B,MAAM,YAAY,GAAS,IAAI,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,gBAAgB,CAAC,CAAC,CAAA;IACpF,MAAM,UAAU,GAAS,IAAI,IAAI,CAAC,cAAc,CAAC,CAAA;IAEjD,OAAO,UAAU,GAAG,YAAY,CAAA;AAClC,CAAC;AArBD,kDAqBC","sourcesContent":["import { EntityManager, Repository } from 'typeorm'\n\nimport { User } from '@things-factory/auth-base'\nimport { Bizplace } from '@things-factory/biz-base'\nimport { Product } from '@things-factory/product-base'\nimport { Domain, getRepository } from '@things-factory/shell'\nimport {\n Inventory,\n INVENTORY_STATUS,\n InventoryHistory,\n InventoryNoGenerator,\n Location,\n LOCATION_STATUS,\n LOCATION_TYPE\n} from '@things-factory/warehouse-base'\n\n/**\n * @description It will insert new record into inventory histories table.\n * seq will be calculated based on number of records for one specific pallet id (provided by inventory object)\n */\nexport async function generateInventoryHistory(\n inventory: Inventory,\n refOrder: any,\n transactionType: string,\n qty: number = 0,\n uomValue: number = 0,\n user: User,\n trxMgr?: EntityManager,\n targetInventory: Inventory = {}\n): Promise<InventoryHistory> {\n const invHistoryRepo: Repository<InventoryHistory> =\n trxMgr?.getRepository(InventoryHistory) || getRepository(InventoryHistory)\n const invRepo: Repository<Inventory> = trxMgr?.getRepository(Inventory) || getRepository(Inventory)\n\n if (!inventory?.id) throw new Error(`Can't find out ID of inventory.`)\n if (!refOrder?.id || !refOrder.name) throw new Error(`Can't find out ID or Name of Reference Order`)\n if (\n !inventory?.domain ||\n !inventory?.bizplace ||\n !inventory?.product?.id ||\n !inventory?.warehouse?.id ||\n !inventory?.location?.id\n ) {\n inventory = await invRepo.findOne({\n where: { id: inventory.id },\n relations: ['domain', 'bizplace', 'product', 'warehouse', 'location']\n })\n }\n\n const domain: Domain = inventory.domain\n const location: Location = inventory.location\n\n const seq: number = await invHistoryRepo.countBy({\n domain: { id: inventory.domain.id },\n palletId: inventory.palletId\n })\n let openingQty: number = 0\n let openingUomValue: number = 0\n\n if (seq) {\n const lastInvHistory: InventoryHistory = await invHistoryRepo.findOneBy({\n domain: { id: inventory.domain.id },\n palletId: inventory.palletId,\n seq: seq - 1\n })\n\n openingQty = lastInvHistory.openingQty + lastInvHistory.qty\n openingUomValue = lastInvHistory.openingUomValue + lastInvHistory.uomValue\n }\n\n if (transactionType == 'PICKING' || transactionType == 'UNLOADING') {\n const [findSameOrderHistory, total]: InventoryHistory = await invHistoryRepo.findAndCountBy({\n domain: { id: inventory.domain.id },\n palletId: inventory.palletId,\n refOrderId: refOrder.id\n })\n\n if (findSameOrderHistory) {\n let prevTotalQty = 0\n let prevTotalUomValue = 0\n for (let oh of findSameOrderHistory) {\n prevTotalQty += oh.qty\n prevTotalUomValue += oh.uomValue\n }\n qty -= prevTotalQty\n uomValue -= prevTotalUomValue\n }\n }\n\n let inventoryHistory: InventoryHistory = new InventoryHistory()\n inventoryHistory.name = InventoryNoGenerator.inventoryHistoryName()\n inventoryHistory.description = inventory.description\n inventoryHistory.seq = seq\n inventoryHistory.palletId = inventory.palletId\n inventoryHistory.cartonId = inventory.cartonId\n inventoryHistory.batchId = inventory.batchId\n inventoryHistory.batchIdRef = inventory.batchIdRef\n inventoryHistory.status = inventory.status\n inventoryHistory.transactionType = transactionType\n inventoryHistory.refOrderId = refOrder?.id || null\n inventoryHistory.orderNo = refOrder?.name || null\n inventoryHistory.orderRefNo = refOrder?.refNo || null\n inventoryHistory.inventory = inventory\n inventoryHistory.targetInventory = targetInventory\n inventoryHistory.product = inventory.product\n inventoryHistory.reusablePallet = inventory.reusablePallet\n inventoryHistory.zone = inventory.zone\n inventoryHistory.warehouse = inventory.warehouse\n inventoryHistory.location = inventory.location\n inventoryHistory.expirationDate = inventory.expirationDate\n inventoryHistory.packingType = inventory.packingType\n inventoryHistory.packingSize = inventory.packingSize\n inventoryHistory.uom = inventory.uom\n inventoryHistory.qty = qty\n inventoryHistory.openingQty = openingQty\n inventoryHistory.uomValue = uomValue\n inventoryHistory.openingUomValue = openingUomValue\n inventoryHistory.unitCost = inventory.unitCost\n inventoryHistory.domain = inventory.domain\n inventoryHistory.bizplace = inventory.bizplace\n inventoryHistory.creator = user\n inventoryHistory.updater = user\n\n inventoryHistory = await invHistoryRepo.save(inventoryHistory)\n\n if (inventory.lastSeq !== seq) {\n await invRepo.save({\n id: inventory.id,\n lastSeq: inventoryHistory.seq,\n updater: user\n })\n }\n\n await switchLocationStatus(domain, location, user, trxMgr)\n return inventoryHistory\n}\n\n/**\n * @description: Check location emptiness and update status of location\n * @param domain\n * @param location\n * @param updater\n * @param trxMgr\n */\nexport async function switchLocationStatus(\n domain: Domain,\n location: Location,\n updater: User,\n trxMgr?: EntityManager\n): Promise<Location> {\n const invRepo: Repository<Inventory> = trxMgr?.getRepository(Inventory) || getRepository(Inventory)\n const locationRepo: Repository<Location> = trxMgr?.getRepository(Location) || getRepository(Location)\n const allocatedItemsCnt: number = await invRepo.countBy({\n domain: { id: domain.id },\n status: INVENTORY_STATUS.STORED,\n location: { id: location.id }\n })\n\n if (!allocatedItemsCnt && location.status !== LOCATION_STATUS.EMPTY) {\n location = await locationRepo.save({\n ...location,\n status: LOCATION_STATUS.EMPTY,\n updater\n })\n } else if (allocatedItemsCnt && location.status === LOCATION_STATUS.EMPTY) {\n location = await locationRepo.save({\n ...location,\n status: LOCATION_STATUS.OCCUPIED,\n updater\n })\n }\n\n return location\n}\n\nexport async function checkPalletDuplication(\n domain: Domain,\n bizplace: Bizplace,\n palletId: string,\n trxMgr?: EntityManager\n): Promise<boolean> {\n const invRepo: Repository<Inventory> = trxMgr?.getRepository(Inventory) || getRepository(Inventory)\n const duplicatedPalletCnt: number = await invRepo.countBy({\n domain: { id: domain.id },\n bizplace,\n palletId\n })\n\n return Boolean(duplicatedPalletCnt)\n}\n\n/**\n * @description Check whether inventory is same with passed conditions\n * @param {Domain} domain\n * @param {Bizplace} bizplace\n * @param {String} palletId\n * @param {String} batchId\n * @param {String | Product} product\n * @param {String} packingType\n * @param {EntityManager} trxMgr\n */\nexport async function checkPalletIdenticallity(\n domain: Domain,\n bizplace: Bizplace,\n palletId: string,\n batchId: string,\n product: string | Product,\n packingType: string,\n trxMgr?: EntityManager\n): Promise<{ identicallity: boolean; errorMessage?: string }> {\n const productRepo: Repository<Product> = trxMgr?.getRepository(Product) || getRepository(Product)\n const invRepo: Repository<Inventory> = trxMgr?.getRepository(Inventory) || getRepository(Inventory)\n\n if (typeof product === 'string') {\n const foundProduct: Product = await productRepo.findOneBy({ id: product })\n if (!foundProduct) throw new Error(`Failed to find product with ${product}`)\n product = foundProduct\n }\n\n const inv: Inventory = await invRepo.findOne({\n where: { domain: { id: domain.id }, bizplace: { id: bizplace.id }, palletId },\n relations: ['product']\n })\n\n if (batchId !== inv.batchId) return { identicallity: false, errorMessage: `Batch ID is not matched with ${batchId}` }\n\n if (product?.id !== inv?.product?.id)\n return { identicallity: false, errorMessage: `Product is not matched with ${product.name}` }\n\n if (packingType !== inv.packingType)\n return { identicallity: false, errorMessage: `Packing Type is not matched with ${packingType}` }\n\n return { identicallity: true }\n}\n\n/**\n * @description: Get inventory based on picking strategy and sorting rule\n * @param { worksheetId, batchId, bizplaceId, productId, packingType, pickingStrategy, locationSortingRules }\n * @param trxMgr\n */\nexport async function inventoriesByStrategy(\n { worksheetId, batchId, bizplaceId, productId, packingType, packingSize, uom, pickingStrategy, locationSortingRules },\n domain: Domain,\n trxMgr: EntityManager\n) {\n const qb = await trxMgr.getRepository(Inventory).createQueryBuilder('INV')\n qb.innerJoinAndSelect('INV.product', 'PROD')\n .innerJoinAndSelect('INV.location', 'LOC')\n .addSelect(subQuery =>\n subQuery\n .select('COALESCE(SUM(release_qty), 0)', 'releaseQty')\n .from('order_inventories', 'OI')\n .where('\"OI\".\"inventory_id\" = \"INV\".\"id\"')\n .andWhere(\"\\\"OI\\\".\\\"status\\\" IN ('PENDING', 'PENDING_RECEIVE', 'PENDING_WORKSHEET', 'PENDING_SPLIT')\")\n .andWhere('\"OI\".\"ref_worksheet_id\" <> :worksheetId', { worksheetId: worksheetId })\n )\n .addSelect(subQuery =>\n subQuery\n .select('COALESCE(SUM(release_uom_value), 0)', 'releaseUomValue')\n .from('order_inventories', 'OI')\n .where('\"OI\".\"inventory_id\" = \"INV\".\"id\"')\n .andWhere(\"\\\"OI\\\".\\\"status\\\" IN ('PENDING', 'PENDING_RECEIVE', 'PENDING_WORKSHEET', 'PENDING_SPLIT')\")\n .andWhere('\"OI\".\"ref_worksheet_id\" <> :worksheetId', { worksheetId: worksheetId })\n )\n .andWhere('\"INV\".\"domain_id\" = :domainId')\n .andWhere('\"PROD\".\"id\" = :productId')\n .andWhere('\"INV\".\"packing_type\" = :packingType')\n .andWhere('\"INV\".\"packing_size\" = :packingSize')\n .andWhere('\"INV\".\"uom\" = :uom')\n .andWhere('\"INV\".\"status\" = :status', { status: 'STORED' })\n .andWhere('\"LOC\".\"type\" NOT IN (:...locationTypes)', {\n locationTypes: [LOCATION_TYPE.QUARANTINE, LOCATION_TYPE.RESERVE]\n })\n .setParameters({\n domainId: domain.id,\n productId,\n packingType,\n packingSize,\n uom\n })\n\n if (batchId !== '') {\n qb.andWhere('\"INV\".\"batch_id\" = :batchId', { batchId })\n }\n\n if (bizplaceId) {\n qb.andWhere('\"INV\".\"bizplace_id\" = :bizplaceId', { bizplaceId: bizplaceId })\n }\n\n let locIdx = 0\n\n switch (pickingStrategy.toUpperCase()) {\n case 'FIFO':\n qb.orderBy('\"INV\".\"created_at\"', 'ASC')\n if (locationSortingRules) {\n for (const key in locationSortingRules) {\n qb.addOrderBy(`LOC.${key}`, locationSortingRules[key])\n }\n }\n break\n\n case 'LIFO':\n qb.orderBy('\"INV\".\"created_at\"', 'DESC')\n if (locationSortingRules) {\n for (const key in locationSortingRules) {\n qb.addOrderBy(`LOC.${key}`, locationSortingRules[key])\n }\n }\n break\n\n case 'FEFO':\n qb.orderBy('\"INV\".\"expiration_date\"', 'ASC')\n qb.addOrderBy('\"INV\".\"created_at\"', 'ASC')\n if (locationSortingRules) {\n for (const key in locationSortingRules) {\n qb.addOrderBy(`LOC.${key}`, locationSortingRules[key])\n }\n }\n break\n\n case 'FMFO':\n qb.orderBy('\"INV\".\"manufacture_date\"', 'ASC')\n qb.addOrderBy('\"INV\".\"created_at\"', 'ASC')\n if (locationSortingRules) {\n for (const key in locationSortingRules) {\n qb.addOrderBy(`LOC.${key}`, locationSortingRules[key])\n }\n }\n break\n\n case 'LOCATION':\n if (locationSortingRules) {\n for (const key in locationSortingRules) {\n if (locIdx === 0) {\n qb.orderBy(`LOC.${key}`, locationSortingRules[key])\n } else {\n qb.addOrderBy(`LOC.${key}`, locationSortingRules[key])\n }\n ++locIdx\n }\n } else qb.orderBy('\"LOC\".\"name\"', 'DESC')\n break\n }\n\n const { entities, raw } = await qb.getRawAndEntities()\n const items = entities\n .map((inv: Inventory, idx: number) => {\n const qty: number = inv?.qty > 0 ? inv.qty : 0\n const uomValue: number = inv?.uomValue > 0 ? inv.uomValue : 0\n const lockedQty: number = inv.lockedQty || 0\n const lockedUomValue: number = inv.lockedUomValue || 0\n const releaseQty: number = parseInt(raw[idx].releaseQty) || 0\n const releaseUomValue: number = parseFloat(raw[idx].releaseUomValue) || 0\n\n return {\n ...inv,\n qty: qty - lockedQty - releaseQty,\n uomValue: uomValue - lockedUomValue - releaseUomValue\n }\n })\n .filter((inv: Inventory) => inv.qty > 0)\n\n const total: number = await qb.getCount()\n return { items, total }\n}\n\nexport async function isInventoryExpiring(inventory: Inventory): Promise<boolean> {\n if (!inventory.id) throw new Error('No inventory id provided')\n let product: Product | undefined = inventory.product\n if (!product) {\n inventory = await getRepository(Inventory).findOne({\n where: { id: inventory.id },\n relations: ['product']\n })\n product = inventory.product\n }\n\n const { expirationDate } = inventory\n const { isRequiredCheckExpiry, expirationPeriod } = product\n\n if (!isRequiredCheckExpiry || !expirationPeriod || expirationDate <= 0) return false\n\n let date: Date = new Date()\n const acceptBefore: Date = new Date(date.setDate(date.getDate() + expirationPeriod))\n const expiryDate: Date = new Date(expirationDate)\n\n return expiryDate < acceptBefore\n}\n"]}
|
|
1
|
+
{"version":3,"file":"inventory-util.js","sourceRoot":"","sources":["../../server/utils/inventory-util.ts"],"names":[],"mappings":";;;AAIA,+DAAsD;AACtD,iDAA6D;AAC7D,mEAA8J;AAE9J;;;GAGG;AACI,KAAK,UAAU,wBAAwB,CAC5C,SAAoB,EACpB,QAAa,EACb,eAAuB,EACvB,MAAc,CAAC,EACf,WAAmB,CAAC,EACpB,IAAU,EACV,MAAsB,EACtB,kBAA6B,EAAE;;IAE/B,MAAM,cAAc,GAAiC,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,aAAa,CAAC,iCAAgB,CAAC,KAAI,IAAA,qBAAa,EAAC,iCAAgB,CAAC,CAAA;IAC/H,MAAM,OAAO,GAA0B,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,aAAa,CAAC,0BAAS,CAAC,KAAI,IAAA,qBAAa,EAAC,0BAAS,CAAC,CAAA;IAEnG,IAAI,CAAC,CAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,EAAE,CAAA;QAAE,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAA;IACtE,IAAI,CAAC,CAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,EAAE,CAAA,IAAI,CAAC,QAAQ,CAAC,IAAI;QAAE,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAA;IACpG,IAAI,CAAC,CAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,MAAM,CAAA,IAAI,CAAC,CAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,QAAQ,CAAA,IAAI,CAAC,CAAA,MAAA,SAAS,aAAT,SAAS,uBAAT,SAA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EAAE,gBAAgB,EAAE,GAAG,OAAO,CAAA;IAE3D,IAAI,CAAC,qBAAqB,IAAI,CAAC,gBAAgB,IAAI,cAAc,IAAI,CAAC;QAAE,OAAO,KAAK,CAAA;IAEpF,IAAI,IAAI,GAAS,IAAI,IAAI,EAAE,CAAA;IAC3B,MAAM,YAAY,GAAS,IAAI,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,gBAAgB,CAAC,CAAC,CAAA;IACpF,MAAM,UAAU,GAAS,IAAI,IAAI,CAAC,cAAc,CAAC,CAAA;IAEjD,OAAO,UAAU,GAAG,YAAY,CAAA;AAClC,CAAC;AArBD,kDAqBC","sourcesContent":["import { EntityManager, Repository } from 'typeorm'\n\nimport { User } from '@things-factory/auth-base'\nimport { Bizplace } from '@things-factory/biz-base'\nimport { Product } from '@things-factory/product-base'\nimport { Domain, getRepository } from '@things-factory/shell'\nimport { Inventory, INVENTORY_STATUS, InventoryHistory, InventoryNoGenerator, Location, LOCATION_STATUS, LOCATION_TYPE } from '@things-factory/warehouse-base'\n\n/**\n * @description It will insert new record into inventory histories table.\n * seq will be calculated based on number of records for one specific pallet id (provided by inventory object)\n */\nexport async function generateInventoryHistory(\n inventory: Inventory,\n refOrder: any,\n transactionType: string,\n qty: number = 0,\n uomValue: number = 0,\n user: User,\n trxMgr?: EntityManager,\n targetInventory: Inventory = {}\n): Promise<InventoryHistory> {\n const invHistoryRepo: Repository<InventoryHistory> = trxMgr?.getRepository(InventoryHistory) || getRepository(InventoryHistory)\n const invRepo: Repository<Inventory> = trxMgr?.getRepository(Inventory) || getRepository(Inventory)\n\n if (!inventory?.id) throw new Error(`Can't find out ID of inventory.`)\n if (!refOrder?.id || !refOrder.name) throw new Error(`Can't find out ID or Name of Reference Order`)\n if (!inventory?.domain || !inventory?.bizplace || !inventory?.product?.id || !inventory?.warehouse?.id || !inventory?.location?.id) {\n inventory = await invRepo.findOne({\n where: { id: inventory.id },\n relations: ['domain', 'bizplace', 'product', 'warehouse', 'location']\n })\n }\n\n const domain: Domain = inventory.domain\n const location: Location = inventory.location\n\n const seq: number = await invHistoryRepo.countBy({\n domain: { id: inventory.domain.id },\n palletId: inventory.palletId\n })\n let openingQty: number = 0\n let openingUomValue: number = 0\n\n if (seq) {\n const lastInvHistory: InventoryHistory = await invHistoryRepo.findOneBy({\n domain: { id: inventory.domain.id },\n palletId: inventory.palletId,\n seq: seq - 1\n })\n\n openingQty = lastInvHistory.openingQty + lastInvHistory.qty\n openingUomValue = lastInvHistory.openingUomValue + lastInvHistory.uomValue\n }\n\n if (transactionType == 'PICKING' || transactionType == 'UNLOADING') {\n const [findSameOrderHistory, total]: InventoryHistory = await invHistoryRepo.findAndCountBy({\n domain: { id: inventory.domain.id },\n palletId: inventory.palletId,\n refOrderId: refOrder.id\n })\n\n if (findSameOrderHistory) {\n let prevTotalQty = 0\n let prevTotalUomValue = 0\n for (let oh of findSameOrderHistory) {\n prevTotalQty += oh.qty\n prevTotalUomValue += oh.uomValue\n }\n qty -= prevTotalQty\n uomValue -= prevTotalUomValue\n }\n }\n\n let inventoryHistory: InventoryHistory = new InventoryHistory()\n inventoryHistory.name = InventoryNoGenerator.inventoryHistoryName()\n inventoryHistory.description = inventory.description\n inventoryHistory.seq = seq\n inventoryHistory.palletId = inventory.palletId\n inventoryHistory.cartonId = inventory.cartonId\n inventoryHistory.batchId = inventory.batchId\n inventoryHistory.batchIdRef = inventory.batchIdRef\n inventoryHistory.status = inventory.status\n inventoryHistory.transactionType = transactionType\n inventoryHistory.refOrderId = refOrder?.id || null\n inventoryHistory.orderNo = refOrder?.name || null\n inventoryHistory.orderRefNo = refOrder?.refNo || null\n inventoryHistory.inventory = inventory\n inventoryHistory.targetInventory = targetInventory\n inventoryHistory.product = inventory.product\n inventoryHistory.reusablePallet = inventory.reusablePallet\n inventoryHistory.zone = inventory.zone\n inventoryHistory.warehouse = inventory.warehouse\n inventoryHistory.location = inventory.location\n inventoryHistory.expirationDate = inventory.expirationDate\n inventoryHistory.packingType = inventory.packingType\n inventoryHistory.packingSize = inventory.packingSize\n inventoryHistory.uom = inventory.uom\n inventoryHistory.qty = qty\n inventoryHistory.openingQty = openingQty\n inventoryHistory.uomValue = uomValue\n inventoryHistory.openingUomValue = openingUomValue\n inventoryHistory.unitCost = inventory.unitCost\n inventoryHistory.domain = inventory.domain\n inventoryHistory.bizplace = inventory.bizplace\n inventoryHistory.creator = user\n inventoryHistory.updater = user\n inventoryHistory.auxInfo3 = inventory.auxInfo3\n\n inventoryHistory = await invHistoryRepo.save(inventoryHistory)\n\n if (inventory.lastSeq !== seq) {\n await invRepo.save({\n id: inventory.id,\n lastSeq: inventoryHistory.seq,\n updater: user\n })\n }\n\n await switchLocationStatus(domain, location, user, trxMgr)\n return inventoryHistory\n}\n\n/**\n * @description: Check location emptiness and update status of location\n * @param domain\n * @param location\n * @param updater\n * @param trxMgr\n */\nexport async function switchLocationStatus(domain: Domain, location: Location, updater: User, trxMgr?: EntityManager): Promise<Location> {\n const invRepo: Repository<Inventory> = trxMgr?.getRepository(Inventory) || getRepository(Inventory)\n const locationRepo: Repository<Location> = trxMgr?.getRepository(Location) || getRepository(Location)\n const allocatedItemsCnt: number = await invRepo.countBy({\n domain: { id: domain.id },\n status: INVENTORY_STATUS.STORED,\n location: { id: location.id }\n })\n\n if (!allocatedItemsCnt && location.status !== LOCATION_STATUS.EMPTY) {\n location = await locationRepo.save({\n ...location,\n status: LOCATION_STATUS.EMPTY,\n updater\n })\n } else if (allocatedItemsCnt && location.status === LOCATION_STATUS.EMPTY) {\n location = await locationRepo.save({\n ...location,\n status: LOCATION_STATUS.OCCUPIED,\n updater\n })\n }\n\n return location\n}\n\nexport async function checkPalletDuplication(domain: Domain, bizplace: Bizplace, palletId: string, trxMgr?: EntityManager): Promise<boolean> {\n const invRepo: Repository<Inventory> = trxMgr?.getRepository(Inventory) || getRepository(Inventory)\n const duplicatedPalletCnt: number = await invRepo.countBy({\n domain: { id: domain.id },\n bizplace,\n palletId\n })\n\n return Boolean(duplicatedPalletCnt)\n}\n\n/**\n * @description Check whether inventory is same with passed conditions\n * @param {Domain} domain\n * @param {Bizplace} bizplace\n * @param {String} palletId\n * @param {String} batchId\n * @param {String | Product} product\n * @param {String} packingType\n * @param {EntityManager} trxMgr\n */\nexport async function checkPalletIdenticallity(\n domain: Domain,\n bizplace: Bizplace,\n palletId: string,\n batchId: string,\n product: string | Product,\n packingType: string,\n trxMgr?: EntityManager\n): Promise<{ identicallity: boolean; errorMessage?: string }> {\n const productRepo: Repository<Product> = trxMgr?.getRepository(Product) || getRepository(Product)\n const invRepo: Repository<Inventory> = trxMgr?.getRepository(Inventory) || getRepository(Inventory)\n\n if (typeof product === 'string') {\n const foundProduct: Product = await productRepo.findOneBy({ id: product })\n if (!foundProduct) throw new Error(`Failed to find product with ${product}`)\n product = foundProduct\n }\n\n const inv: Inventory = await invRepo.findOne({\n where: { domain: { id: domain.id }, bizplace: { id: bizplace.id }, palletId },\n relations: ['product']\n })\n\n if (batchId !== inv.batchId) return { identicallity: false, errorMessage: `Batch ID is not matched with ${batchId}` }\n\n if (product?.id !== inv?.product?.id) return { identicallity: false, errorMessage: `Product is not matched with ${product.name}` }\n\n if (packingType !== inv.packingType) return { identicallity: false, errorMessage: `Packing Type is not matched with ${packingType}` }\n\n return { identicallity: true }\n}\n\n/**\n * @description: Get inventory based on picking strategy and sorting rule\n * @param { worksheetId, batchId, bizplaceId, productId, packingType, pickingStrategy, locationSortingRules }\n * @param trxMgr\n */\nexport async function inventoriesByStrategy(\n { worksheetId, batchId, bizplaceId, productId, packingType, packingSize, uom, pickingStrategy, locationSortingRules },\n domain: Domain,\n trxMgr: EntityManager\n) {\n const qb = await trxMgr.getRepository(Inventory).createQueryBuilder('INV')\n qb.innerJoinAndSelect('INV.product', 'PROD')\n .innerJoinAndSelect('INV.location', 'LOC')\n .addSelect(subQuery =>\n subQuery\n .select('COALESCE(SUM(release_qty), 0)', 'releaseQty')\n .from('order_inventories', 'OI')\n .where('\"OI\".\"inventory_id\" = \"INV\".\"id\"')\n .andWhere(\"\\\"OI\\\".\\\"status\\\" IN ('PENDING', 'PENDING_RECEIVE', 'PENDING_WORKSHEET', 'PENDING_SPLIT')\")\n .andWhere('\"OI\".\"ref_worksheet_id\" <> :worksheetId', { worksheetId: worksheetId })\n )\n .addSelect(subQuery =>\n subQuery\n .select('COALESCE(SUM(release_uom_value), 0)', 'releaseUomValue')\n .from('order_inventories', 'OI')\n .where('\"OI\".\"inventory_id\" = \"INV\".\"id\"')\n .andWhere(\"\\\"OI\\\".\\\"status\\\" IN ('PENDING', 'PENDING_RECEIVE', 'PENDING_WORKSHEET', 'PENDING_SPLIT')\")\n .andWhere('\"OI\".\"ref_worksheet_id\" <> :worksheetId', { worksheetId: worksheetId })\n )\n .andWhere('\"INV\".\"domain_id\" = :domainId')\n .andWhere('\"PROD\".\"id\" = :productId')\n .andWhere('\"INV\".\"packing_type\" = :packingType')\n .andWhere('\"INV\".\"packing_size\" = :packingSize')\n .andWhere('\"INV\".\"uom\" = :uom')\n .andWhere('\"INV\".\"status\" = :status', { status: 'STORED' })\n .andWhere('\"LOC\".\"type\" NOT IN (:...locationTypes)', {\n locationTypes: [LOCATION_TYPE.QUARANTINE, LOCATION_TYPE.RESERVE]\n })\n .setParameters({\n domainId: domain.id,\n productId,\n packingType,\n packingSize,\n uom\n })\n\n if (batchId !== '') {\n qb.andWhere('\"INV\".\"batch_id\" = :batchId', { batchId })\n }\n\n if (bizplaceId) {\n qb.andWhere('\"INV\".\"bizplace_id\" = :bizplaceId', { bizplaceId: bizplaceId })\n }\n\n let locIdx = 0\n\n switch (pickingStrategy.toUpperCase()) {\n case 'FIFO':\n qb.orderBy('\"INV\".\"created_at\"', 'ASC')\n if (locationSortingRules) {\n for (const key in locationSortingRules) {\n qb.addOrderBy(`LOC.${key}`, locationSortingRules[key])\n }\n }\n break\n\n case 'LIFO':\n qb.orderBy('\"INV\".\"created_at\"', 'DESC')\n if (locationSortingRules) {\n for (const key in locationSortingRules) {\n qb.addOrderBy(`LOC.${key}`, locationSortingRules[key])\n }\n }\n break\n\n case 'FEFO':\n qb.orderBy('\"INV\".\"expiration_date\"', 'ASC')\n qb.addOrderBy('\"INV\".\"created_at\"', 'ASC')\n if (locationSortingRules) {\n for (const key in locationSortingRules) {\n qb.addOrderBy(`LOC.${key}`, locationSortingRules[key])\n }\n }\n break\n\n case 'FMFO':\n qb.orderBy('\"INV\".\"manufacture_date\"', 'ASC')\n qb.addOrderBy('\"INV\".\"created_at\"', 'ASC')\n if (locationSortingRules) {\n for (const key in locationSortingRules) {\n qb.addOrderBy(`LOC.${key}`, locationSortingRules[key])\n }\n }\n break\n\n case 'LOCATION':\n if (locationSortingRules) {\n for (const key in locationSortingRules) {\n if (locIdx === 0) {\n qb.orderBy(`LOC.${key}`, locationSortingRules[key])\n } else {\n qb.addOrderBy(`LOC.${key}`, locationSortingRules[key])\n }\n ++locIdx\n }\n } else qb.orderBy('\"LOC\".\"name\"', 'DESC')\n break\n }\n\n const { entities, raw } = await qb.getRawAndEntities()\n const items = entities\n .map((inv: Inventory, idx: number) => {\n const qty: number = inv?.qty > 0 ? inv.qty : 0\n const uomValue: number = inv?.uomValue > 0 ? inv.uomValue : 0\n const lockedQty: number = inv.lockedQty || 0\n const lockedUomValue: number = inv.lockedUomValue || 0\n const releaseQty: number = parseInt(raw[idx].releaseQty) || 0\n const releaseUomValue: number = parseFloat(raw[idx].releaseUomValue) || 0\n\n return {\n ...inv,\n qty: qty - lockedQty - releaseQty,\n uomValue: uomValue - lockedUomValue - releaseUomValue\n }\n })\n .filter((inv: Inventory) => inv.qty > 0)\n\n const total: number = await qb.getCount()\n return { items, total }\n}\n\nexport async function isInventoryExpiring(inventory: Inventory): Promise<boolean> {\n if (!inventory.id) throw new Error('No inventory id provided')\n let product: Product | undefined = inventory.product\n if (!product) {\n inventory = await getRepository(Inventory).findOne({\n where: { id: inventory.id },\n relations: ['product']\n })\n product = inventory.product\n }\n\n const { expirationDate } = inventory\n const { isRequiredCheckExpiry, expirationPeriod } = product\n\n if (!isRequiredCheckExpiry || !expirationPeriod || expirationDate <= 0) return false\n\n let date: Date = new Date()\n const acceptBefore: Date = new Date(date.setDate(date.getDate() + expirationPeriod))\n const expiryDate: Date = new Date(expirationDate)\n\n return expiryDate < acceptBefore\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@things-factory/worksheet-base",
|
|
3
|
-
"version": "6.2.
|
|
3
|
+
"version": "6.2.147",
|
|
4
4
|
"main": "dist-server/index.js",
|
|
5
5
|
"browser": "client/index.js",
|
|
6
6
|
"things-factory": true,
|
|
@@ -24,21 +24,21 @@
|
|
|
24
24
|
"migration:create": "node ../../node_modules/typeorm/cli.js migration:create -d ./server/migrations"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@things-factory/auth-base": "^6.2.
|
|
28
|
-
"@things-factory/biz-base": "^6.2.
|
|
29
|
-
"@things-factory/document-template-base": "^6.2.
|
|
30
|
-
"@things-factory/id-rule-base": "^6.2.
|
|
31
|
-
"@things-factory/integration-lmd": "^6.2.
|
|
32
|
-
"@things-factory/integration-marketplace": "^6.2.
|
|
33
|
-
"@things-factory/integration-sellercraft": "^6.2.
|
|
34
|
-
"@things-factory/integration-sftp": "^6.2.
|
|
35
|
-
"@things-factory/marketplace-base": "^6.2.
|
|
36
|
-
"@things-factory/notification": "^6.2.
|
|
37
|
-
"@things-factory/sales-base": "^6.2.
|
|
38
|
-
"@things-factory/setting-base": "^6.2.
|
|
39
|
-
"@things-factory/shell": "^6.2.
|
|
40
|
-
"@things-factory/transport-base": "^6.2.
|
|
41
|
-
"@things-factory/warehouse-base": "^6.2.
|
|
27
|
+
"@things-factory/auth-base": "^6.2.147",
|
|
28
|
+
"@things-factory/biz-base": "^6.2.147",
|
|
29
|
+
"@things-factory/document-template-base": "^6.2.147",
|
|
30
|
+
"@things-factory/id-rule-base": "^6.2.147",
|
|
31
|
+
"@things-factory/integration-lmd": "^6.2.147",
|
|
32
|
+
"@things-factory/integration-marketplace": "^6.2.147",
|
|
33
|
+
"@things-factory/integration-sellercraft": "^6.2.147",
|
|
34
|
+
"@things-factory/integration-sftp": "^6.2.147",
|
|
35
|
+
"@things-factory/marketplace-base": "^6.2.147",
|
|
36
|
+
"@things-factory/notification": "^6.2.147",
|
|
37
|
+
"@things-factory/sales-base": "^6.2.147",
|
|
38
|
+
"@things-factory/setting-base": "^6.2.147",
|
|
39
|
+
"@things-factory/shell": "^6.2.147",
|
|
40
|
+
"@things-factory/transport-base": "^6.2.147",
|
|
41
|
+
"@things-factory/warehouse-base": "^6.2.147"
|
|
42
42
|
},
|
|
43
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "4b93b26f0edfea36d6273d1caf736477a5e2ceed"
|
|
44
44
|
}
|
|
@@ -4,15 +4,7 @@ import { User } from '@things-factory/auth-base'
|
|
|
4
4
|
import { Bizplace } from '@things-factory/biz-base'
|
|
5
5
|
import { Product } from '@things-factory/product-base'
|
|
6
6
|
import { Domain, getRepository } from '@things-factory/shell'
|
|
7
|
-
import {
|
|
8
|
-
Inventory,
|
|
9
|
-
INVENTORY_STATUS,
|
|
10
|
-
InventoryHistory,
|
|
11
|
-
InventoryNoGenerator,
|
|
12
|
-
Location,
|
|
13
|
-
LOCATION_STATUS,
|
|
14
|
-
LOCATION_TYPE
|
|
15
|
-
} from '@things-factory/warehouse-base'
|
|
7
|
+
import { Inventory, INVENTORY_STATUS, InventoryHistory, InventoryNoGenerator, Location, LOCATION_STATUS, LOCATION_TYPE } from '@things-factory/warehouse-base'
|
|
16
8
|
|
|
17
9
|
/**
|
|
18
10
|
* @description It will insert new record into inventory histories table.
|
|
@@ -28,19 +20,12 @@ export async function generateInventoryHistory(
|
|
|
28
20
|
trxMgr?: EntityManager,
|
|
29
21
|
targetInventory: Inventory = {}
|
|
30
22
|
): Promise<InventoryHistory> {
|
|
31
|
-
const invHistoryRepo: Repository<InventoryHistory> =
|
|
32
|
-
trxMgr?.getRepository(InventoryHistory) || getRepository(InventoryHistory)
|
|
23
|
+
const invHistoryRepo: Repository<InventoryHistory> = trxMgr?.getRepository(InventoryHistory) || getRepository(InventoryHistory)
|
|
33
24
|
const invRepo: Repository<Inventory> = trxMgr?.getRepository(Inventory) || getRepository(Inventory)
|
|
34
25
|
|
|
35
26
|
if (!inventory?.id) throw new Error(`Can't find out ID of inventory.`)
|
|
36
27
|
if (!refOrder?.id || !refOrder.name) throw new Error(`Can't find out ID or Name of Reference Order`)
|
|
37
|
-
if (
|
|
38
|
-
!inventory?.domain ||
|
|
39
|
-
!inventory?.bizplace ||
|
|
40
|
-
!inventory?.product?.id ||
|
|
41
|
-
!inventory?.warehouse?.id ||
|
|
42
|
-
!inventory?.location?.id
|
|
43
|
-
) {
|
|
28
|
+
if (!inventory?.domain || !inventory?.bizplace || !inventory?.product?.id || !inventory?.warehouse?.id || !inventory?.location?.id) {
|
|
44
29
|
inventory = await invRepo.findOne({
|
|
45
30
|
where: { id: inventory.id },
|
|
46
31
|
relations: ['domain', 'bizplace', 'product', 'warehouse', 'location']
|
|
@@ -120,6 +105,7 @@ export async function generateInventoryHistory(
|
|
|
120
105
|
inventoryHistory.bizplace = inventory.bizplace
|
|
121
106
|
inventoryHistory.creator = user
|
|
122
107
|
inventoryHistory.updater = user
|
|
108
|
+
inventoryHistory.auxInfo3 = inventory.auxInfo3
|
|
123
109
|
|
|
124
110
|
inventoryHistory = await invHistoryRepo.save(inventoryHistory)
|
|
125
111
|
|
|
@@ -142,12 +128,7 @@ export async function generateInventoryHistory(
|
|
|
142
128
|
* @param updater
|
|
143
129
|
* @param trxMgr
|
|
144
130
|
*/
|
|
145
|
-
export async function switchLocationStatus(
|
|
146
|
-
domain: Domain,
|
|
147
|
-
location: Location,
|
|
148
|
-
updater: User,
|
|
149
|
-
trxMgr?: EntityManager
|
|
150
|
-
): Promise<Location> {
|
|
131
|
+
export async function switchLocationStatus(domain: Domain, location: Location, updater: User, trxMgr?: EntityManager): Promise<Location> {
|
|
151
132
|
const invRepo: Repository<Inventory> = trxMgr?.getRepository(Inventory) || getRepository(Inventory)
|
|
152
133
|
const locationRepo: Repository<Location> = trxMgr?.getRepository(Location) || getRepository(Location)
|
|
153
134
|
const allocatedItemsCnt: number = await invRepo.countBy({
|
|
@@ -173,12 +154,7 @@ export async function switchLocationStatus(
|
|
|
173
154
|
return location
|
|
174
155
|
}
|
|
175
156
|
|
|
176
|
-
export async function checkPalletDuplication(
|
|
177
|
-
domain: Domain,
|
|
178
|
-
bizplace: Bizplace,
|
|
179
|
-
palletId: string,
|
|
180
|
-
trxMgr?: EntityManager
|
|
181
|
-
): Promise<boolean> {
|
|
157
|
+
export async function checkPalletDuplication(domain: Domain, bizplace: Bizplace, palletId: string, trxMgr?: EntityManager): Promise<boolean> {
|
|
182
158
|
const invRepo: Repository<Inventory> = trxMgr?.getRepository(Inventory) || getRepository(Inventory)
|
|
183
159
|
const duplicatedPalletCnt: number = await invRepo.countBy({
|
|
184
160
|
domain: { id: domain.id },
|
|
@@ -224,11 +200,9 @@ export async function checkPalletIdenticallity(
|
|
|
224
200
|
|
|
225
201
|
if (batchId !== inv.batchId) return { identicallity: false, errorMessage: `Batch ID is not matched with ${batchId}` }
|
|
226
202
|
|
|
227
|
-
if (product?.id !== inv?.product?.id)
|
|
228
|
-
return { identicallity: false, errorMessage: `Product is not matched with ${product.name}` }
|
|
203
|
+
if (product?.id !== inv?.product?.id) return { identicallity: false, errorMessage: `Product is not matched with ${product.name}` }
|
|
229
204
|
|
|
230
|
-
if (packingType !== inv.packingType)
|
|
231
|
-
return { identicallity: false, errorMessage: `Packing Type is not matched with ${packingType}` }
|
|
205
|
+
if (packingType !== inv.packingType) return { identicallity: false, errorMessage: `Packing Type is not matched with ${packingType}` }
|
|
232
206
|
|
|
233
207
|
return { identicallity: true }
|
|
234
208
|
}
|