@things-factory/worksheet-base 6.0.44 → 6.0.45

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.
@@ -118,7 +118,7 @@ async function switchLocationStatus(domain, location, updater, trxMgr) {
118
118
  const allocatedItemsCnt = await invRepo.countBy({
119
119
  domain: { id: domain.id },
120
120
  status: warehouse_base_1.INVENTORY_STATUS.STORED,
121
- location
121
+ location: { id: location.id }
122
122
  });
123
123
  if (!allocatedItemsCnt && location.status !== warehouse_base_1.LOCATION_STATUS.EMPTY) {
124
124
  location = await locationRepo.save(Object.assign(Object.assign({}, location), { status: warehouse_base_1.LOCATION_STATUS.EMPTY, updater }));
@@ -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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S,CAAC;SACvB,CAAC,CAAA;QACF,OAAO,GAAG,SAAS,CAAC,OAAO,CAAA;KAC5B;IAED,MAAM,EAAE,cAAc,EAAE,GAAG,SAAS,CAAA;IACpC,MAAM,EAAE,qBAAqB,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 {\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\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,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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vB,CAAC,CAAA;QACF,OAAO,GAAG,SAAS,CAAC,OAAO,CAAA;KAC5B;IAED,MAAM,EAAE,cAAc,EAAE,GAAG,SAAS,CAAA;IACpC,MAAM,EAAE,qBAAqB,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 {\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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@things-factory/worksheet-base",
3
- "version": "6.0.44",
3
+ "version": "6.0.45",
4
4
  "main": "dist-server/index.js",
5
5
  "browser": "client/index.js",
6
6
  "things-factory": true,
@@ -33,11 +33,11 @@
33
33
  "@things-factory/integration-sftp": "^6.0.43",
34
34
  "@things-factory/marketplace-base": "^6.0.43",
35
35
  "@things-factory/notification": "^6.0.43",
36
- "@things-factory/sales-base": "^6.0.43",
36
+ "@things-factory/sales-base": "^6.0.45",
37
37
  "@things-factory/setting-base": "^6.0.43",
38
38
  "@things-factory/shell": "^6.0.43",
39
39
  "@things-factory/transport-base": "^6.0.43",
40
40
  "@things-factory/warehouse-base": "^6.0.43"
41
41
  },
42
- "gitHead": "af00adff86a6371d85e2d03b51e17695af09d858"
42
+ "gitHead": "7ed9a41bd28093df9b43126ee38c0cdd0522afda"
43
43
  }
@@ -147,7 +147,7 @@ export class UnloadingWorksheetController extends VasWorksheetController {
147
147
  type: RULE_TYPE.LOT_NUMBER_ID,
148
148
  seed: { date: DateGenerator.generateDate() }
149
149
  })
150
- await this.checkCartonDuplication(cartonId, orderId)
150
+ if (inventory?.cartonId) await this.checkCartonDuplication(cartonId, orderId)
151
151
  } else {
152
152
  await this.checkPalletDuplication(palletId)
153
153
  }
@@ -1,4 +1,4 @@
1
- import { EntityManager, EntitySchema, Equal, FindOneOptions, In, Not, getRepository } from 'typeorm'
1
+ import { EntityManager, EntitySchema, Equal, FindOneOptions, In, Not } from 'typeorm'
2
2
 
3
3
  import { Role, User } from '@things-factory/auth-base'
4
4
  import { Bizplace, getDomainUsers } from '@things-factory/biz-base'
@@ -17,7 +17,7 @@ import {
17
17
  ReturnOrder,
18
18
  VasOrder
19
19
  } from '@things-factory/sales-base'
20
- import { Domain } from '@things-factory/shell'
20
+ import { Domain, getRepository } from '@things-factory/shell'
21
21
  import { Inventory, INVENTORY_STATUS, InventoryItem, Pallet } from '@things-factory/warehouse-base'
22
22
 
23
23
  import { WORKSHEET_STATUS, WORKSHEET_TYPE } from '../constants'
@@ -392,7 +392,7 @@ export class WorksheetController {
392
392
  let existingWorksheet: Worksheet
393
393
  try {
394
394
  existingWorksheet = await this.findWorksheetByRefOrder(refOrder, type)
395
- } catch (e) { }
395
+ } catch (e) {}
396
396
 
397
397
  if (existingWorksheet)
398
398
  throw new Error(
@@ -511,7 +511,6 @@ export class WorksheetController {
511
511
  if (!refOrder.updater?.id) refOrder = this.setStamp(refOrder)
512
512
 
513
513
  if (currentStatus && entitySchema == ReleaseGood) {
514
-
515
514
  let res = await getRepository(entitySchema).query(
516
515
  `
517
516
  update release_goods
@@ -1054,14 +1053,11 @@ export class WorksheetController {
1054
1053
  return childQty
1055
1054
  }
1056
1055
 
1057
- public async getDirectQty(
1058
- productDetail: ProductDetail,
1059
- productBarcode: string,
1060
- qty: number
1061
- ): Promise<any> {
1056
+ public async getDirectQty(productDetail: ProductDetail, productBarcode: string, qty: number): Promise<any> {
1062
1057
  try {
1063
1058
  console.time('getDirectQty')
1064
- let results = await this.trxMgr.query(`
1059
+ let results = await this.trxMgr.query(
1060
+ `
1065
1061
  WITH RECURSIVE cte as (
1066
1062
  select * from (
1067
1063
  select pd.product_id as "productId", id, pd.packing_size as "packingSize",
@@ -1078,14 +1074,11 @@ export class WorksheetController {
1078
1074
  where pd.deleted_at is null
1079
1075
  )
1080
1076
  select * from cte where gtin = $3
1081
- `, [
1082
- productDetail.id,
1083
- qty,
1084
- productBarcode
1085
- ])
1077
+ `,
1078
+ [productDetail.id, qty, productBarcode]
1079
+ )
1086
1080
 
1087
- if (results.length <= 0)
1088
- throw new Error(this.ERROR_MSG.FIND.NO_RESULT(productBarcode))
1081
+ if (results.length <= 0) throw new Error(this.ERROR_MSG.FIND.NO_RESULT(productBarcode))
1089
1082
 
1090
1083
  console.timeEnd('getDirectQty')
1091
1084
  return results[0]
@@ -1094,8 +1087,6 @@ export class WorksheetController {
1094
1087
  }
1095
1088
  }
1096
1089
 
1097
-
1098
-
1099
1090
  /**
1100
1091
  * @summary Check for product child qty at any scanned level
1101
1092
  * @description It will check every level of product detail by comparing scanned level and GAN registered level.
@@ -153,7 +153,7 @@ export async function switchLocationStatus(
153
153
  const allocatedItemsCnt: number = await invRepo.countBy({
154
154
  domain: { id: domain.id },
155
155
  status: INVENTORY_STATUS.STORED,
156
- location
156
+ location: { id: location.id }
157
157
  })
158
158
 
159
159
  if (!allocatedItemsCnt && location.status !== LOCATION_STATUS.EMPTY) {