@things-factory/worksheet-base 8.0.94 → 8.0.98

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.
@@ -33,18 +33,23 @@ async function generateInventoryHistory(inventory, refOrder, transactionType, qt
33
33
  }
34
34
  const domain = inventory.domain;
35
35
  const location = inventory.location;
36
- const seq = await invHistoryRepo.countBy({
37
- domain: { id: inventory.domain.id },
38
- palletId: inventory.palletId
36
+ // 동시성 제어 - 트랜잭션 내에서 해당 재고 행을 FOR UPDATE로 잠가, 동시 실행이 같은 seq 읽어 중복 기록하는 것을 막는다.
37
+ if (trxMgr) {
38
+ await invRepo.findOne({ where: { id: inventory.id }, lock: { mode: 'pessimistic_write' } });
39
+ }
40
+ // 최신 재고이력을 seq 내림차순으로 조회
41
+ const lastInvHistory = await invHistoryRepo.findOne({
42
+ where: {
43
+ domain: { id: inventory.domain.id },
44
+ palletId: inventory.palletId
45
+ },
46
+ order: { seq: 'DESC' }
39
47
  });
48
+ // 다음 seq는 마지막 seq + 1 (이력이 없으면 0)
49
+ const seq = lastInvHistory ? lastInvHistory.seq + 1 : 0;
40
50
  let openingQty = 0;
41
51
  let openingUomValue = 0;
42
- if (seq) {
43
- const lastInvHistory = await invHistoryRepo.findOneBy({
44
- domain: { id: inventory.domain.id },
45
- palletId: inventory.palletId,
46
- seq: seq - 1
47
- });
52
+ if (lastInvHistory) {
48
53
  openingQty = lastInvHistory.openingQty + lastInvHistory.qty;
49
54
  openingUomValue = lastInvHistory.openingUomValue + lastInvHistory.uomValue;
50
55
  }
@@ -1 +1 @@
1
- {"version":3,"file":"inventory-util.js","sourceRoot":"","sources":["../../server/utils/inventory-util.ts"],"names":[],"mappings":";;AAoBA,4DAqHC;AASD,oDA6BC;AAED,wDAcC;AAYD,4DAgCC;AAOD,sDA4HC;AAED,kDAqBC;AAjYD,+DAAsD;AACtD,iDAA6D;AAC7D,mEAQuC;AAEvC;;;GAGG;AACI,KAAK,UAAU,wBAAw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c,CAAC,IAAI,CAAC;QAAE,OAAO,KAAK,CAAA;IAE5F,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","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 = {} as any\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 // @ts-ignore\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 as any).targetInventory = targetInventory as any\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(\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 || Number(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":";;AAoBA,4DA2HC;AASD,oDA6BC;AAED,wDAcC;AAYD,4DAgCC;AAOD,sDA4HC;AAED,kDAqBC;AAvYD,+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,EAAS;;IAEtC,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,a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E,CAAA;AACzB,CAAC;AAEM,KAAK,UAAU,mBAAmB,CAAC,SAAoB;IAC5D,IAAI,CAAC,SAAS,CAAC,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAA;IAC9D,IAAI,OAAO,GAAwB,SAAS,CAAC,OAAO,CAAA;IACpD,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,SAAS,GAAG,MAAM,IAAA,qBAAa,EAAC,0BAAS,CAAC,CAAC,OAAO,CAAC;YACjD,KAAK,EAAE,EAAE,EAAE,EAAE,SAAS,CAAC,EAAE,EAAE;YAC3B,SAAS,EAAE,CAAC,SAAS,CAAC;SACvB,CAAC,CAAA;QACF,OAAO,GAAG,SAAS,CAAC,OAAO,CAAA;IAC7B,CAAC;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,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC;QAAE,OAAO,KAAK,CAAA;IAE5F,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","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 = {} as any\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 // 동시성 제어 - 트랜잭션 내에서 해당 재고 행을 FOR UPDATE로 잠가, 동시 실행이 같은 seq를 읽어 중복 기록하는 것을 막는다.\n if (trxMgr) {\n await invRepo.findOne({ where: { id: inventory.id }, lock: { mode: 'pessimistic_write' } })\n }\n\n // 최신 재고이력을 seq 내림차순으로 조회\n const lastInvHistory: InventoryHistory = await invHistoryRepo.findOne({\n where: {\n domain: { id: inventory.domain.id },\n palletId: inventory.palletId\n },\n order: { seq: 'DESC' }\n })\n\n // 다음 seq는 마지막 seq + 1 (이력이 없으면 0)\n const seq: number = lastInvHistory ? lastInvHistory.seq + 1 : 0\n let openingQty: number = 0\n let openingUomValue: number = 0\n\n if (lastInvHistory) {\n openingQty = lastInvHistory.openingQty + lastInvHistory.qty\n openingUomValue = lastInvHistory.openingUomValue + lastInvHistory.uomValue\n }\n\n if (transactionType == 'PICKING' || transactionType == 'UNLOADING') {\n // @ts-ignore\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 as any).targetInventory = targetInventory as any\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(\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 || Number(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": "8.0.94",
3
+ "version": "8.0.98",
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 ./server/migrations/migration"
25
25
  },
26
26
  "dependencies": {
27
- "@things-factory/auth-base": "^8.0.94",
28
- "@things-factory/biz-base": "^8.0.94",
29
- "@things-factory/document-template-base": "^8.0.94",
30
- "@things-factory/id-rule-base": "^8.0.94",
31
- "@things-factory/integration-lmd": "^8.0.94",
32
- "@things-factory/integration-marketplace": "^8.0.94",
33
- "@things-factory/integration-sellercraft": "^8.0.94",
34
- "@things-factory/integration-sftp": "^8.0.94",
35
- "@things-factory/marketplace-base": "^8.0.94",
36
- "@things-factory/notification": "^8.0.94",
37
- "@things-factory/sales-base": "^8.0.94",
38
- "@things-factory/setting-base": "^8.0.94",
39
- "@things-factory/shell": "^8.0.94",
40
- "@things-factory/transport-base": "^8.0.94",
41
- "@things-factory/warehouse-base": "^8.0.94"
27
+ "@things-factory/auth-base": "^8.0.97",
28
+ "@things-factory/biz-base": "^8.0.97",
29
+ "@things-factory/document-template-base": "^8.0.97",
30
+ "@things-factory/id-rule-base": "^8.0.97",
31
+ "@things-factory/integration-lmd": "^8.0.97",
32
+ "@things-factory/integration-marketplace": "^8.0.97",
33
+ "@things-factory/integration-sellercraft": "^8.0.97",
34
+ "@things-factory/integration-sftp": "^8.0.97",
35
+ "@things-factory/marketplace-base": "^8.0.97",
36
+ "@things-factory/notification": "^8.0.97",
37
+ "@things-factory/sales-base": "^8.0.97",
38
+ "@things-factory/setting-base": "^8.0.97",
39
+ "@things-factory/shell": "^8.0.97",
40
+ "@things-factory/transport-base": "^8.0.97",
41
+ "@things-factory/warehouse-base": "^8.0.97"
42
42
  },
43
- "gitHead": "8624fb1b8c9d979f1b5edf747c5ee1d08cf79a6f"
43
+ "gitHead": "4b84be96f0d941aa559abab5b3a5f540bac3c74f"
44
44
  }
@@ -90,6 +90,17 @@ export class PutawayWorksheetController extends VasWorksheetController {
90
90
  targetInventory = await this.trxMgr.getRepository(OrderInventory).save(targetInventory)
91
91
  }
92
92
 
93
+ // 적치 취소(undo putaway) 등으로 이미 이 재고의 적치 상세가 있으면 중복 생성하지 않는다.
94
+ // (취소된 팔레트가 이후 부분하차 완료 시 UNLOADED 재고로 다시 잡혀 같은 LOT이 2줄 생기는 문제 방지)
95
+ const existingWsdCnt: number = await this.trxMgr.getRepository(WorksheetDetail).count({
96
+ where: {
97
+ domain: { id: this.domain.id },
98
+ worksheet: { id: worksheet.id },
99
+ targetInventory: { id: targetInventory.id }
100
+ }
101
+ })
102
+ if (existingWsdCnt) continue
103
+
93
104
  const newWorksheetDetails: WorksheetDetail[] = await this.createWorksheetDetails(
94
105
  worksheet,
95
106
  WORKSHEET_TYPE.PUTAWAY,
@@ -388,7 +399,9 @@ export class PutawayWorksheetController extends VasWorksheetController {
388
399
  where: { domain: { id: this.domain.id }, name: worksheetDetail.fromLocation.name }
389
400
  })
390
401
  inventory.location = bufferLocation
391
- inventory.status = INVENTORY_STATUS.UNLOADED
402
+ // 적치 상세가 EXECUTING으로 살아있으므로 UNLOADED가 아닌 PUTTING_AWAY로 되돌린다.
403
+ // UNLOADED로 두면 이후 부분하차 완료 시 새 하차 재고로 잡혀 적치 상세가 중복 생성된다.
404
+ inventory.status = INVENTORY_STATUS.PUTTING_AWAY
392
405
  await this.transactionInventory(inventory, arrivalNotice, 0, 0, INVENTORY_TRANSACTION_TYPE.UNDO_PUTAWAY)
393
406
 
394
407
  targetInventory.status = ORDER_PRODUCT_STATUS.PUTTING_AWAY
@@ -424,7 +437,7 @@ export class PutawayWorksheetController extends VasWorksheetController {
424
437
  where: { domain: { id: this.domain.id }, name: worksheetDetail.fromLocation.name }
425
438
  })
426
439
  inventory.location = bufferLocation
427
- inventory.status = INVENTORY_STATUS.UNLOADED
440
+ inventory.status = INVENTORY_STATUS.PUTTING_AWAY // undoPallet과 동일 사유
428
441
  await this.transactionInventory(inventory, arrivalNotice, 0, 0, INVENTORY_TRANSACTION_TYPE.UNDO_PUTAWAY)
429
442
 
430
443
  targetInventory.status = ORDER_PRODUCT_STATUS.PUTTING_AWAY
@@ -50,20 +50,26 @@ export async function generateInventoryHistory(
50
50
  const domain: Domain = inventory.domain
51
51
  const location: Location = inventory.location
52
52
 
53
- const seq: number = await invHistoryRepo.countBy({
54
- domain: { id: inventory.domain.id },
55
- palletId: inventory.palletId
53
+ // 동시성 제어 - 트랜잭션 내에서 해당 재고 행을 FOR UPDATE로 잠가, 동시 실행이 같은 seq 읽어 중복 기록하는 것을 막는다.
54
+ if (trxMgr) {
55
+ await invRepo.findOne({ where: { id: inventory.id }, lock: { mode: 'pessimistic_write' } })
56
+ }
57
+
58
+ // 최신 재고이력을 seq 내림차순으로 조회
59
+ const lastInvHistory: InventoryHistory = await invHistoryRepo.findOne({
60
+ where: {
61
+ domain: { id: inventory.domain.id },
62
+ palletId: inventory.palletId
63
+ },
64
+ order: { seq: 'DESC' }
56
65
  })
66
+
67
+ // 다음 seq는 마지막 seq + 1 (이력이 없으면 0)
68
+ const seq: number = lastInvHistory ? lastInvHistory.seq + 1 : 0
57
69
  let openingQty: number = 0
58
70
  let openingUomValue: number = 0
59
71
 
60
- if (seq) {
61
- const lastInvHistory: InventoryHistory = await invHistoryRepo.findOneBy({
62
- domain: { id: inventory.domain.id },
63
- palletId: inventory.palletId,
64
- seq: seq - 1
65
- })
66
-
72
+ if (lastInvHistory) {
67
73
  openingQty = lastInvHistory.openingQty + lastInvHistory.qty
68
74
  openingUomValue = lastInvHistory.openingUomValue + lastInvHistory.uomValue
69
75
  }