@things-factory/warehouse-base 5.0.14 → 6.0.0-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (142) hide show
  1. package/dist-server/controllers/ecommerce/ecommerce-controller.js +1 -1
  2. package/dist-server/controllers/ecommerce/ecommerce-controller.js.map +1 -1
  3. package/dist-server/controllers/ecommerce/sellercraft-controller.js +64 -60
  4. package/dist-server/controllers/ecommerce/sellercraft-controller.js.map +1 -1
  5. package/dist-server/controllers/warehouse-controller.js +7 -5
  6. package/dist-server/controllers/warehouse-controller.js.map +1 -1
  7. package/dist-server/service/inventory/inventory-mutation.js +6 -6
  8. package/dist-server/service/inventory/inventory-mutation.js.map +1 -1
  9. package/dist-server/service/inventory/inventory-query.js +217 -195
  10. package/dist-server/service/inventory/inventory-query.js.map +1 -1
  11. package/dist-server/service/inventory/inventory-types.js +14 -15
  12. package/dist-server/service/inventory/inventory-types.js.map +1 -1
  13. package/dist-server/service/inventory/inventory.js +62 -42
  14. package/dist-server/service/inventory/inventory.js.map +1 -1
  15. package/dist-server/service/inventory-change/inventory-change-mutation.js +252 -216
  16. package/dist-server/service/inventory-change/inventory-change-mutation.js.map +1 -1
  17. package/dist-server/service/inventory-change/inventory-change-query.js +6 -7
  18. package/dist-server/service/inventory-change/inventory-change-query.js.map +1 -1
  19. package/dist-server/service/inventory-change/inventory-change.js +7 -7
  20. package/dist-server/service/inventory-change/inventory-change.js.map +1 -1
  21. package/dist-server/service/inventory-history/inventory-history-mutation.js +1 -1
  22. package/dist-server/service/inventory-history/inventory-history-mutation.js.map +1 -1
  23. package/dist-server/service/inventory-history/inventory-history-query.js +89 -99
  24. package/dist-server/service/inventory-history/inventory-history-query.js.map +1 -1
  25. package/dist-server/service/inventory-history/inventory-history-types.js +3 -3
  26. package/dist-server/service/inventory-history/inventory-history-types.js.map +1 -1
  27. package/dist-server/service/inventory-history/inventory-history.js +7 -7
  28. package/dist-server/service/inventory-history/inventory-history.js.map +1 -1
  29. package/dist-server/service/inventory-item/inventory-item-mutation.js +10 -10
  30. package/dist-server/service/inventory-item/inventory-item-mutation.js.map +1 -1
  31. package/dist-server/service/inventory-item/inventory-item-query.js +18 -17
  32. package/dist-server/service/inventory-item/inventory-item-query.js.map +1 -1
  33. package/dist-server/service/inventory-item/inventory-item-type.js +4 -5
  34. package/dist-server/service/inventory-item/inventory-item-type.js.map +1 -1
  35. package/dist-server/service/inventory-item/inventory-item.js +5 -5
  36. package/dist-server/service/inventory-item/inventory-item.js.map +1 -1
  37. package/dist-server/service/inventory-item-change/inventory-item-change-mutation.js +4 -4
  38. package/dist-server/service/inventory-item-change/inventory-item-change-mutation.js.map +1 -1
  39. package/dist-server/service/inventory-item-change/inventory-item-change-query.js +7 -9
  40. package/dist-server/service/inventory-item-change/inventory-item-change-query.js.map +1 -1
  41. package/dist-server/service/inventory-item-change/inventory-item-change-type.js +6 -7
  42. package/dist-server/service/inventory-item-change/inventory-item-change-type.js.map +1 -1
  43. package/dist-server/service/inventory-item-change/inventory-item-change.js +3 -4
  44. package/dist-server/service/inventory-item-change/inventory-item-change.js.map +1 -1
  45. package/dist-server/service/inventory-product/inventory-product-mutation.js +4 -4
  46. package/dist-server/service/inventory-product/inventory-product-mutation.js.map +1 -1
  47. package/dist-server/service/inventory-product/inventory-product-query.js +7 -9
  48. package/dist-server/service/inventory-product/inventory-product-query.js.map +1 -1
  49. package/dist-server/service/inventory-product/inventory-product-type.js +1 -2
  50. package/dist-server/service/inventory-product/inventory-product-type.js.map +1 -1
  51. package/dist-server/service/inventory-product/inventory-product.js +5 -5
  52. package/dist-server/service/inventory-product/inventory-product.js.map +1 -1
  53. package/dist-server/service/location/location-mutation.js +5 -5
  54. package/dist-server/service/location/location-mutation.js.map +1 -1
  55. package/dist-server/service/location/location-query.js +17 -19
  56. package/dist-server/service/location/location-query.js.map +1 -1
  57. package/dist-server/service/location/location-types.js +3 -3
  58. package/dist-server/service/location/location-types.js.map +1 -1
  59. package/dist-server/service/location/location.js +14 -14
  60. package/dist-server/service/location/location.js.map +1 -1
  61. package/dist-server/service/movement/movement-mutation.js +6 -5
  62. package/dist-server/service/movement/movement-mutation.js.map +1 -1
  63. package/dist-server/service/movement/movement-query.js +15 -15
  64. package/dist-server/service/movement/movement-query.js.map +1 -1
  65. package/dist-server/service/movement/movement-types.js +4 -5
  66. package/dist-server/service/movement/movement-types.js.map +1 -1
  67. package/dist-server/service/movement/movement.js +5 -5
  68. package/dist-server/service/movement/movement.js.map +1 -1
  69. package/dist-server/service/pallet/pallet-mutation.js +5 -5
  70. package/dist-server/service/pallet/pallet-mutation.js.map +1 -1
  71. package/dist-server/service/pallet/pallet-query.js +9 -11
  72. package/dist-server/service/pallet/pallet-query.js.map +1 -1
  73. package/dist-server/service/pallet/pallet-types.js +5 -6
  74. package/dist-server/service/pallet/pallet-types.js.map +1 -1
  75. package/dist-server/service/pallet/pallet.js +6 -6
  76. package/dist-server/service/pallet/pallet.js.map +1 -1
  77. package/dist-server/service/pallet-count/pallet-count-mutation.js +1 -1
  78. package/dist-server/service/pallet-count/pallet-count-mutation.js.map +1 -1
  79. package/dist-server/service/pallet-count/pallet-count-query.js +6 -8
  80. package/dist-server/service/pallet-count/pallet-count-query.js.map +1 -1
  81. package/dist-server/service/pallet-count/pallet-count.js +3 -4
  82. package/dist-server/service/pallet-count/pallet-count.js.map +1 -1
  83. package/dist-server/service/pallet-history/pallet-history-mutation.js +1 -1
  84. package/dist-server/service/pallet-history/pallet-history-mutation.js.map +1 -1
  85. package/dist-server/service/pallet-history/pallet-history-query.js +6 -8
  86. package/dist-server/service/pallet-history/pallet-history-query.js.map +1 -1
  87. package/dist-server/service/pallet-history/pallet-history.js +6 -6
  88. package/dist-server/service/pallet-history/pallet-history.js.map +1 -1
  89. package/dist-server/service/reduced-inventory-history/reduced-inventory-history.js +1 -1
  90. package/dist-server/service/reduced-inventory-history/reduced-inventory-history.js.map +1 -1
  91. package/dist-server/service/tote/tote-mutation.js +4 -4
  92. package/dist-server/service/tote/tote-mutation.js.map +1 -1
  93. package/dist-server/service/tote/tote-query.js +12 -13
  94. package/dist-server/service/tote/tote-query.js.map +1 -1
  95. package/dist-server/service/tote/tote-types.js +2 -3
  96. package/dist-server/service/tote/tote-types.js.map +1 -1
  97. package/dist-server/service/tote/tote.js +5 -5
  98. package/dist-server/service/tote/tote.js.map +1 -1
  99. package/dist-server/service/warehouse/warehouse-mutation.js +1 -1
  100. package/dist-server/service/warehouse/warehouse-mutation.js.map +1 -1
  101. package/dist-server/service/warehouse/warehouse-query.js +9 -10
  102. package/dist-server/service/warehouse/warehouse-query.js.map +1 -1
  103. package/dist-server/service/warehouse/warehouse.js +12 -12
  104. package/dist-server/service/warehouse/warehouse.js.map +1 -1
  105. package/dist-server/tsconfig.tsbuildinfo +1 -1
  106. package/dist-server/utils/inventory-util.js +16 -16
  107. package/dist-server/utils/inventory-util.js.map +1 -1
  108. package/package.json +8 -8
  109. package/server/controllers/ecommerce/ecommerce-controller.ts +1 -1
  110. package/server/controllers/ecommerce/sellercraft-controller.ts +75 -65
  111. package/server/controllers/warehouse-controller.ts +9 -4
  112. package/server/service/inventory/inventory-mutation.ts +28 -24
  113. package/server/service/inventory/inventory-query.ts +269 -304
  114. package/server/service/inventory/inventory.ts +50 -35
  115. package/server/service/inventory-change/inventory-change-mutation.ts +305 -256
  116. package/server/service/inventory-change/inventory-change-query.ts +9 -9
  117. package/server/service/inventory-history/inventory-history-mutation.ts +12 -15
  118. package/server/service/inventory-history/inventory-history-query.ts +158 -133
  119. package/server/service/inventory-item/inventory-item-mutation.ts +20 -17
  120. package/server/service/inventory-item/inventory-item-query.ts +28 -18
  121. package/server/service/inventory-item-change/inventory-item-change-mutation.ts +12 -9
  122. package/server/service/inventory-item-change/inventory-item-change-query.ts +10 -8
  123. package/server/service/inventory-product/inventory-product-mutation.ts +16 -12
  124. package/server/service/inventory-product/inventory-product-query.ts +7 -8
  125. package/server/service/location/location-mutation.ts +24 -24
  126. package/server/service/location/location-query.ts +27 -23
  127. package/server/service/location/location.ts +11 -10
  128. package/server/service/movement/movement-mutation.ts +7 -8
  129. package/server/service/movement/movement-query.ts +18 -16
  130. package/server/service/pallet/pallet-mutation.ts +18 -20
  131. package/server/service/pallet/pallet-query.ts +13 -14
  132. package/server/service/pallet-count/pallet-count-mutation.ts +20 -17
  133. package/server/service/pallet-count/pallet-count-query.ts +6 -7
  134. package/server/service/pallet-history/pallet-history-mutation.ts +15 -15
  135. package/server/service/pallet-history/pallet-history-query.ts +7 -8
  136. package/server/service/reduced-inventory-history/reduced-inventory-history.ts +1 -1
  137. package/server/service/tote/tote-mutation.ts +23 -22
  138. package/server/service/tote/tote-query.ts +18 -14
  139. package/server/service/warehouse/warehouse-mutation.ts +21 -18
  140. package/server/service/warehouse/warehouse-query.ts +11 -11
  141. package/server/service/warehouse/warehouse.ts +7 -7
  142. package/server/utils/inventory-util.ts +10 -10
@@ -11,7 +11,7 @@ const warehouse_controller_1 = require("../warehouse-controller");
11
11
  class EcommerceController extends warehouse_controller_1.WarehouseController {
12
12
  async updateProductVariationStock(marketplaceStores, productId, companyDomain) {
13
13
  var _a;
14
- const product = await this.trxMgr.getRepository(product_base_1.Product).findOne(productId);
14
+ const product = await this.trxMgr.getRepository(product_base_1.Product).findOneBy({ id: productId });
15
15
  let inventories = await this.trxMgr.getRepository(inventory_1.Inventory).find({
16
16
  where: { domain: this.domain, product, status: (0, typeorm_1.Not)((0, typeorm_1.Equal)(constants_1.INVENTORY_STATUS.TERMINATED)) },
17
17
  relations: ['location']
@@ -1 +1 @@
1
- {"version":3,"file":"ecommerce-controller.js","sourceRoot":"","sources":["../../../server/controllers/ecommerce/ecommerce-controller.ts"],"names":[],"mappings":";;;AAAA,qCAAoC;AAEpC,qFAAwG;AACxG,uEAA8E;AAC9E,+DAAsD;AAGtD,+CAAiE;AACjE,iEAA6D;AAC7D,kEAA6D;AAE7D,MAAa,mBAAoB,SAAQ,0CAAmB;IAC1D,KAAK,CAAC,2BAA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eorm'\n\nimport { MarketplaceSetting, MarketplaceStore, StoreAPI } from '@things-factory/integration-marketplace'\nimport { MarketplaceProductVariation } from '@things-factory/marketplace-base'\nimport { Product } from '@things-factory/product-base'\nimport { Domain } from '@things-factory/shell'\n\nimport { INVENTORY_STATUS, LOCATION_TYPE } from '../../constants'\nimport { Inventory } from '../../service/inventory/inventory'\nimport { WarehouseController } from '../warehouse-controller'\n\nexport class EcommerceController extends WarehouseController {\n async updateProductVariationStock(\n marketplaceStores: MarketplaceStore[],\n productId: string,\n companyDomain: Domain\n ): Promise<void> {\n const product: Product = await this.trxMgr.getRepository(Product).findOne(productId)\n let inventories: Inventory[] = await this.trxMgr.getRepository(Inventory).find({\n where: { domain: this.domain, product, status: Not(Equal(INVENTORY_STATUS.TERMINATED)) },\n relations: ['location']\n })\n\n inventories = inventories.filter(\n inventory =>\n inventory?.location.type !== LOCATION_TYPE.QUARANTINE || inventory?.location.type !== LOCATION_TYPE.RESERVE\n )\n\n const inventoryQty: number = inventories.reduce((total, currentValue) => {\n total += currentValue.qty\n return total\n }, 0)\n\n const inventoryLockedQty: number = inventories.reduce((total, currentValue) => {\n total += currentValue.lockedQty\n return total\n }, 0)\n\n const inventoryProduct: any = {\n sku: product.sku,\n name: product.name,\n qty: inventoryQty - inventoryLockedQty\n }\n\n for (var i = 0; i < marketplaceStores.length; i++) {\n const marketplaceStore = marketplaceStores[i]\n\n // get marketplace setting based on marketplace connection\n const marketplaceSetting: MarketplaceSetting = await this.trxMgr.getRepository(MarketplaceSetting).findOne({\n where: { marketplaceStore, category: 'stock_allocation' }\n })\n\n const marketplaceProductVariations: MarketplaceProductVariation[] = await this.trxMgr\n .getRepository(MarketplaceProductVariation)\n .find({\n where: { domain: companyDomain, sku: inventoryProduct.sku },\n relations: ['marketplaceProduct', 'marketplaceProduct.marketplaceStore']\n })\n\n let marketplaceProductVariation: MarketplaceProductVariation = marketplaceProductVariations.filter(\n productVariation => productVariation.marketplaceProduct.marketplaceStore.id === marketplaceStore.id\n )[0]\n\n if (marketplaceProductVariation) {\n // update stock qty based on calculated inventory by product qty\n let percentageValue: number = 100\n if (marketplaceSetting) {\n percentageValue = parseInt(marketplaceSetting.value)\n }\n\n let productVariationLocationId = marketplaceProductVariation?.locationId\n let adjustQty: number = Math.floor(inventoryProduct.qty * (percentageValue / 100))\n if (marketplaceStore.platform === 'shopify') {\n let locationIds: any[] = JSON.parse(productVariationLocationId)\n adjustQty = adjustQty - marketplaceProductVariation.qty\n if (locationIds[0]?.location_id) productVariationLocationId = locationIds[0].location_id\n }\n\n let validMarketplaceDistributors: any[] = []\n if (marketplaceStore.marketplaceDistributors) {\n validMarketplaceDistributors = marketplaceStore.marketplaceDistributors.filter(\n distributor => distributor.status === 'ACTIVE'\n )\n }\n\n await StoreAPI.updateStoreProductVariationStock(marketplaceStore, [\n {\n itemId: marketplaceProductVariation.marketplaceProduct.itemId,\n variationId: marketplaceProductVariation.variationId,\n variationSku: marketplaceProductVariation.variationSku,\n qty: adjustQty,\n locationId: productVariationLocationId,\n inventoryItemId: marketplaceProductVariation.inventoryItemId,\n distributors: validMarketplaceDistributors\n }\n ])\n\n marketplaceProductVariation.qty = Math.floor(inventoryProduct.qty * (percentageValue / 100))\n marketplaceProductVariation.updater = this.user\n await this.trxMgr.getRepository(MarketplaceProductVariation).save(marketplaceProductVariation)\n }\n }\n }\n}\n"]}
1
+ {"version":3,"file":"ecommerce-controller.js","sourceRoot":"","sources":["../../../server/controllers/ecommerce/ecommerce-controller.ts"],"names":[],"mappings":";;;AAAA,qCAAoC;AAEpC,qFAAwG;AACxG,uEAA8E;AAC9E,+DAAsD;AAGtD,+CAAiE;AACjE,iEAA6D;AAC7D,kEAA6D;AAE7D,MAAa,mBAAoB,SAAQ,0CAAmB;IAC1D,KAAK,CAAC,2BAA2B,CAC/B,iBAAqC,EACrC,SAAiB,EACjB,aAAqB;;QAErB,MAAM,OAAO,GAAY,MAAM,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,sBAAO,CA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CAAC,0BAA0B,CAAC,CAAA;oBAC/D,SAAS,GAAG,SAAS,GAAG,2BAA2B,CAAC,GAAG,CAAA;oBACvD,IAAI,MAAA,WAAW,CAAC,CAAC,CAAC,0CAAE,WAAW;wBAAE,0BAA0B,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,WAAW,CAAA;iBACzF;gBAED,IAAI,4BAA4B,GAAU,EAAE,CAAA;gBAC5C,IAAI,gBAAgB,CAAC,uBAAuB,EAAE;oBAC5C,4BAA4B,GAAG,gBAAgB,CAAC,uBAAuB,CAAC,MAAM,CAC5E,WAAW,CAAC,EAAE,CAAC,WAAW,CAAC,MAAM,KAAK,QAAQ,CAC/C,CAAA;iBACF;gBAED,MAAM,kCAAQ,CAAC,gCAAgC,CAAC,gBAAgB,EAAE;oBAChE;wBACE,MAAM,EAAE,2BAA2B,CAAC,kBAAkB,CAAC,MAAM;wBAC7D,WAAW,EAAE,2BAA2B,CAAC,WAAW;wBACpD,YAAY,EAAE,2BAA2B,CAAC,YAAY;wBACtD,GAAG,EAAE,SAAS;wBACd,UAAU,EAAE,0BAA0B;wBACtC,eAAe,EAAE,2BAA2B,CAAC,eAAe;wBAC5D,YAAY,EAAE,4BAA4B;qBAC3C;iBACF,CAAC,CAAA;gBAEF,2BAA2B,CAAC,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,GAAG,GAAG,CAAC,eAAe,GAAG,GAAG,CAAC,CAAC,CAAA;gBAC5F,2BAA2B,CAAC,OAAO,GAAG,IAAI,CAAC,IAAI,CAAA;gBAC/C,MAAM,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,8CAA2B,CAAC,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAA;aAC/F;SACF;IACH,CAAC;CACF;AA5FD,kDA4FC","sourcesContent":["import { Equal, Not } from 'typeorm'\n\nimport { MarketplaceSetting, MarketplaceStore, StoreAPI } from '@things-factory/integration-marketplace'\nimport { MarketplaceProductVariation } from '@things-factory/marketplace-base'\nimport { Product } from '@things-factory/product-base'\nimport { Domain } from '@things-factory/shell'\n\nimport { INVENTORY_STATUS, LOCATION_TYPE } from '../../constants'\nimport { Inventory } from '../../service/inventory/inventory'\nimport { WarehouseController } from '../warehouse-controller'\n\nexport class EcommerceController extends WarehouseController {\n async updateProductVariationStock(\n marketplaceStores: MarketplaceStore[],\n productId: string,\n companyDomain: Domain\n ): Promise<void> {\n const product: Product = await this.trxMgr.getRepository(Product).findOneBy({ id: productId })\n let inventories: Inventory[] = await this.trxMgr.getRepository(Inventory).find({\n where: { domain: this.domain, product, status: Not(Equal(INVENTORY_STATUS.TERMINATED)) },\n relations: ['location']\n })\n\n inventories = inventories.filter(\n inventory =>\n inventory?.location.type !== LOCATION_TYPE.QUARANTINE || inventory?.location.type !== LOCATION_TYPE.RESERVE\n )\n\n const inventoryQty: number = inventories.reduce((total, currentValue) => {\n total += currentValue.qty\n return total\n }, 0)\n\n const inventoryLockedQty: number = inventories.reduce((total, currentValue) => {\n total += currentValue.lockedQty\n return total\n }, 0)\n\n const inventoryProduct: any = {\n sku: product.sku,\n name: product.name,\n qty: inventoryQty - inventoryLockedQty\n }\n\n for (var i = 0; i < marketplaceStores.length; i++) {\n const marketplaceStore = marketplaceStores[i]\n\n // get marketplace setting based on marketplace connection\n const marketplaceSetting: MarketplaceSetting = await this.trxMgr.getRepository(MarketplaceSetting).findOne({\n where: { marketplaceStore, category: 'stock_allocation' }\n })\n\n const marketplaceProductVariations: MarketplaceProductVariation[] = await this.trxMgr\n .getRepository(MarketplaceProductVariation)\n .find({\n where: { domain: companyDomain, sku: inventoryProduct.sku },\n relations: ['marketplaceProduct', 'marketplaceProduct.marketplaceStore']\n })\n\n let marketplaceProductVariation: MarketplaceProductVariation = marketplaceProductVariations.filter(\n productVariation => productVariation.marketplaceProduct.marketplaceStore.id === marketplaceStore.id\n )[0]\n\n if (marketplaceProductVariation) {\n // update stock qty based on calculated inventory by product qty\n let percentageValue: number = 100\n if (marketplaceSetting) {\n percentageValue = parseInt(marketplaceSetting.value)\n }\n\n let productVariationLocationId = marketplaceProductVariation?.locationId\n let adjustQty: number = Math.floor(inventoryProduct.qty * (percentageValue / 100))\n if (marketplaceStore.platform === 'shopify') {\n let locationIds: any[] = JSON.parse(productVariationLocationId)\n adjustQty = adjustQty - marketplaceProductVariation.qty\n if (locationIds[0]?.location_id) productVariationLocationId = locationIds[0].location_id\n }\n\n let validMarketplaceDistributors: any[] = []\n if (marketplaceStore.marketplaceDistributors) {\n validMarketplaceDistributors = marketplaceStore.marketplaceDistributors.filter(\n distributor => distributor.status === 'ACTIVE'\n )\n }\n\n await StoreAPI.updateStoreProductVariationStock(marketplaceStore, [\n {\n itemId: marketplaceProductVariation.marketplaceProduct.itemId,\n variationId: marketplaceProductVariation.variationId,\n variationSku: marketplaceProductVariation.variationSku,\n qty: adjustQty,\n locationId: productVariationLocationId,\n inventoryItemId: marketplaceProductVariation.inventoryItemId,\n distributors: validMarketplaceDistributors\n }\n ])\n\n marketplaceProductVariation.qty = Math.floor(inventoryProduct.qty * (percentageValue / 100))\n marketplaceProductVariation.updater = this.user\n await this.trxMgr.getRepository(MarketplaceProductVariation).save(marketplaceProductVariation)\n }\n }\n }\n}\n"]}
@@ -8,68 +8,72 @@ const inventory_1 = require("../../service/inventory/inventory");
8
8
  const warehouse_controller_1 = require("../warehouse-controller");
9
9
  class SellercraftController extends warehouse_controller_1.WarehouseController {
10
10
  async updateSellercraftStock(sellercraft, inventory) {
11
- const bizplace = await this.trxMgr.getRepository(biz_base_1.Bizplace).findOne({ domain: sellercraft.domain });
12
- let product = inventory.product;
13
- const productDetails = product.productDetails;
14
- let qb = await this.trxMgr.getRepository(inventory_1.Inventory).createQueryBuilder('inv');
15
- qb.leftJoinAndSelect('inv.location', 'loc')
16
- .andWhere('"inv"."domain_id" = :domainId')
17
- .andWhere('"inv"."bizplace_id" = :bizplaceId')
18
- .andWhere('"inv"."product_id" = :productId')
19
- .andWhere('"inv"."status" != :status')
20
- .andWhere('"loc"."type" NOT IN (:...locationTypes)')
21
- .setParameters({
22
- domainId: this.domain.id,
23
- bizplaceId: bizplace.id,
24
- productId: product.id,
25
- status: constants_1.INVENTORY_STATUS.TERMINATED,
26
- locationTypes: [constants_1.LOCATION_TYPE.QUARANTINE, constants_1.LOCATION_TYPE.RESERVE]
27
- });
28
- let inventories = await qb.getMany();
29
- let defaultProductDetail = product.productDetails.find(productDetail => productDetail.isDefault);
30
- let inventoryTotalQty = 0;
31
- let inventoryTotalLockedQty = 0;
32
- if ((inventories === null || inventories === void 0 ? void 0 : inventories.length) > 0) {
33
- const sellercraftInvs = await Promise.all(inventories.map(async (inventory) => {
34
- const inventoryPackingType = inventory.packingType;
35
- let packingSize = 1;
36
- if (inventoryPackingType !== defaultProductDetail.packingType) {
37
- const unmatchingProductDetail = product.productDetails.find(productDetail => productDetail.packingType === inventoryPackingType);
38
- packingSize = await this.getChildPackingSize(productDetails, defaultProductDetail, unmatchingProductDetail);
11
+ let sellercraftSetting = sellercraft.sellercraftSetting;
12
+ let disableUpdateStock = (sellercraftSetting === null || sellercraftSetting === void 0 ? void 0 : sellercraftSetting.disableUpdateStock) && (sellercraftSetting === null || sellercraftSetting === void 0 ? void 0 : sellercraftSetting.disableUpdateStock) == 1 ? true : false;
13
+ if (!disableUpdateStock) {
14
+ const bizplace = await this.trxMgr.getRepository(biz_base_1.Bizplace).findOneBy({ domain: sellercraft.domain });
15
+ let product = inventory.product;
16
+ const productDetails = product.productDetails;
17
+ let qb = await this.trxMgr.getRepository(inventory_1.Inventory).createQueryBuilder('inv');
18
+ qb.leftJoinAndSelect('inv.location', 'loc')
19
+ .andWhere('"inv"."domain_id" = :domainId')
20
+ .andWhere('"inv"."bizplace_id" = :bizplaceId')
21
+ .andWhere('"inv"."product_id" = :productId')
22
+ .andWhere('"inv"."status" = :status')
23
+ .andWhere('"loc"."type" NOT IN (:...locationTypes)')
24
+ .setParameters({
25
+ domainId: this.domain.id,
26
+ bizplaceId: bizplace.id,
27
+ productId: product.id,
28
+ status: constants_1.INVENTORY_STATUS.STORED,
29
+ locationTypes: [constants_1.LOCATION_TYPE.QUARANTINE, constants_1.LOCATION_TYPE.RESERVE]
30
+ });
31
+ let inventories = await qb.getMany();
32
+ let defaultProductDetail = product.productDetails.find(productDetail => productDetail.isDefault);
33
+ let inventoryTotalQty = 0;
34
+ let inventoryTotalLockedQty = 0;
35
+ if ((inventories === null || inventories === void 0 ? void 0 : inventories.length) > 0) {
36
+ const sellercraftInvs = await Promise.all(inventories.map(async (inventory) => {
37
+ const inventoryPackingType = inventory.packingType;
38
+ let packingSize = 1;
39
+ if (inventoryPackingType !== defaultProductDetail.packingType) {
40
+ const unmatchingProductDetail = product.productDetails.find(productDetail => productDetail.packingType === inventoryPackingType);
41
+ packingSize = await this.getChildPackingSize(productDetails, defaultProductDetail, unmatchingProductDetail);
42
+ }
43
+ return { totalQty: inventory.qty * packingSize, totalLockedQty: inventory.lockedQty * packingSize };
44
+ }));
45
+ inventoryTotalQty = sellercraftInvs.reduce((total, currentValue) => {
46
+ total += currentValue.totalQty;
47
+ return total;
48
+ }, 0);
49
+ inventoryTotalLockedQty = sellercraftInvs.reduce((total, currentValue) => {
50
+ total += currentValue.totalLockedQty;
51
+ return total;
52
+ }, 0);
53
+ }
54
+ const sellercraftInv = [
55
+ {
56
+ sku: product.sku,
57
+ gtin: defaultProductDetail.gtin,
58
+ stock: {
59
+ quantity_total: inventoryTotalQty,
60
+ quantity_reserved: inventoryTotalLockedQty,
61
+ unit_of_measure: 'EA'
62
+ },
63
+ package_weight_gm: defaultProductDetail.nettWeight < 1 ? 1 : defaultProductDetail.nettWeight,
64
+ package_dimensions: {
65
+ length_mm: defaultProductDetail.depth < 1 ? 1 : defaultProductDetail.depth,
66
+ width_mm: defaultProductDetail.width < 1 ? 1 : defaultProductDetail.width,
67
+ height_mm: defaultProductDetail.height < 1 ? 1 : defaultProductDetail.height
68
+ }
39
69
  }
40
- return { totalQty: inventory.qty * packingSize, totalLockedQty: inventory.lockedQty * packingSize };
41
- }));
42
- inventoryTotalQty = sellercraftInvs.reduce((total, currentValue) => {
43
- total += currentValue.totalQty;
44
- return total;
45
- }, 0);
46
- inventoryTotalLockedQty = sellercraftInvs.reduce((total, currentValue) => {
47
- total += currentValue.totalLockedQty;
48
- return total;
49
- }, 0);
70
+ ];
71
+ await integration_sellercraft_1.SellercraftAPI.updateProduct(sellercraft, {
72
+ context: { state: { domain: this === null || this === void 0 ? void 0 : this.domain, user: this === null || this === void 0 ? void 0 : this.user } },
73
+ accountId: sellercraft.accountId,
74
+ sellercraftInv
75
+ });
50
76
  }
51
- const sellercraftInv = [
52
- {
53
- sku: product.sku,
54
- gtin: defaultProductDetail.gtin,
55
- stock: {
56
- quantity_total: inventoryTotalQty,
57
- quantity_reserved: inventoryTotalLockedQty,
58
- unit_of_measure: 'EA'
59
- },
60
- package_weight_gm: defaultProductDetail.nettWeight < 1 ? 1 : defaultProductDetail.nettWeight,
61
- package_dimensions: {
62
- length_mm: defaultProductDetail.depth < 1 ? 1 : defaultProductDetail.depth,
63
- width_mm: defaultProductDetail.width < 1 ? 1 : defaultProductDetail.width,
64
- height_mm: defaultProductDetail.height < 1 ? 1 : defaultProductDetail.height
65
- }
66
- }
67
- ];
68
- await integration_sellercraft_1.SellercraftAPI.updateProduct(sellercraft, {
69
- context: { state: { domain: this === null || this === void 0 ? void 0 : this.domain, user: this === null || this === void 0 ? void 0 : this.user } },
70
- accountId: sellercraft.accountId,
71
- sellercraftInv
72
- });
73
77
  }
74
78
  }
75
79
  exports.SellercraftController = SellercraftController;
@@ -1 +1 @@
1
- {"version":3,"file":"sellercraft-controller.js","sourceRoot":"","sources":["../../../server/controllers/ecommerce/sellercraft-controller.ts"],"names":[],"mappings":";;;AAAA,uDAAmD;AACnD,qFAAqF;AAGrF,+CAAiE;AACjE,iEAA6D;AAC7D,kEAA6D;AAE7D,MAAa,qBAAsB,SAAQ,0CAAmB;IAC5D,KAAK,CAAC,sBAAsB,CAAC,WAAwB,E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gBACD,iBAAiB,EAAE,oBAAoB,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,oBAAoB,CAAC,UAAU;gBAC5F,kBAAkB,EAAE;oBAClB,SAAS,EAAE,oBAAoB,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,oBAAoB,CAAC,KAAK;oBAC1E,QAAQ,EAAE,oBAAoB,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,oBAAoB,CAAC,KAAK;oBACzE,SAAS,EAAE,oBAAoB,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,oBAAoB,CAAC,MAAM;iBAC7E;aACF;SACF,CAAA;QAED,MAAM,wCAAc,CAAC,aAAa,CAAC,WAAW,EAAE;YAC9C,OAAO,EAAE,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,MAAM,EAAE,IAAI,EAAE,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,IAAI,EAAE,EAAE;YAC9D,SAAS,EAAE,WAAW,CAAC,SAAS;YAChC,cAAc;SACf,CAAC,CAAA;IACJ,CAAC;CACF;AAjFD,sDAiFC","sourcesContent":["import { Bizplace } from '@things-factory/biz-base'\nimport { Sellercraft, SellercraftAPI } from '@things-factory/integration-sellercraft'\nimport { Product, ProductDetail } from '@things-factory/product-base'\n\nimport { INVENTORY_STATUS, LOCATION_TYPE } from '../../constants'\nimport { Inventory } from '../../service/inventory/inventory'\nimport { WarehouseController } from '../warehouse-controller'\n\nexport class SellercraftController extends WarehouseController {\n async updateSellercraftStock(sellercraft: Sellercraft, inventory: Inventory): Promise<void> {\n const bizplace: Bizplace = await this.trxMgr.getRepository(Bizplace).findOne({ domain: sellercraft.domain })\n\n let product: Product = inventory.product\n const productDetails: ProductDetail[] = product.productDetails\n\n let qb = await this.trxMgr.getRepository(Inventory).createQueryBuilder('inv')\n qb.leftJoinAndSelect('inv.location', 'loc')\n .andWhere('\"inv\".\"domain_id\" = :domainId')\n .andWhere('\"inv\".\"bizplace_id\" = :bizplaceId')\n .andWhere('\"inv\".\"product_id\" = :productId')\n .andWhere('\"inv\".\"status\" != :status')\n .andWhere('\"loc\".\"type\" NOT IN (:...locationTypes)')\n .setParameters({\n domainId: this.domain.id,\n bizplaceId: bizplace.id,\n productId: product.id,\n status: INVENTORY_STATUS.TERMINATED,\n locationTypes: [LOCATION_TYPE.QUARANTINE, LOCATION_TYPE.RESERVE]\n })\n\n let inventories: Inventory[] = await qb.getMany()\n\n let defaultProductDetail: ProductDetail = product.productDetails.find(productDetail => productDetail.isDefault)\n let inventoryTotalQty: number = 0\n let inventoryTotalLockedQty: number = 0\n\n if (inventories?.length > 0) {\n const sellercraftInvs: any[] = await Promise.all(\n inventories.map(async (inventory: Inventory) => {\n const inventoryPackingType: string = inventory.packingType\n\n let packingSize: number = 1\n if (inventoryPackingType !== defaultProductDetail.packingType) {\n const unmatchingProductDetail: ProductDetail = product.productDetails.find(\n productDetail => productDetail.packingType === inventoryPackingType\n )\n\n packingSize = await this.getChildPackingSize(productDetails, defaultProductDetail, unmatchingProductDetail)\n }\n\n return { totalQty: inventory.qty * packingSize, totalLockedQty: inventory.lockedQty * packingSize }\n })\n )\n\n inventoryTotalQty = sellercraftInvs.reduce((total, currentValue) => {\n total += currentValue.totalQty\n return total\n }, 0)\n\n inventoryTotalLockedQty = sellercraftInvs.reduce((total, currentValue) => {\n total += currentValue.totalLockedQty\n return total\n }, 0)\n }\n\n const sellercraftInv: any[] = [\n {\n sku: product.sku,\n gtin: defaultProductDetail.gtin,\n stock: {\n quantity_total: inventoryTotalQty,\n quantity_reserved: inventoryTotalLockedQty,\n unit_of_measure: 'EA'\n },\n package_weight_gm: defaultProductDetail.nettWeight < 1 ? 1 : defaultProductDetail.nettWeight,\n package_dimensions: {\n length_mm: defaultProductDetail.depth < 1 ? 1 : defaultProductDetail.depth,\n width_mm: defaultProductDetail.width < 1 ? 1 : defaultProductDetail.width,\n height_mm: defaultProductDetail.height < 1 ? 1 : defaultProductDetail.height\n }\n }\n ]\n\n await SellercraftAPI.updateProduct(sellercraft, {\n context: { state: { domain: this?.domain, user: this?.user } },\n accountId: sellercraft.accountId,\n sellercraftInv\n })\n }\n}\n"]}
1
+ {"version":3,"file":"sellercraft-controller.js","sourceRoot":"","sources":["../../../server/controllers/ecommerce/sellercraft-controller.ts"],"names":[],"mappings":";;;AAAA,uDAAmD;AACnD,qFAAqF;AAGrF,+CAAiE;AACjE,iEAA6D;AAC7D,kEAA6D;AAE7D,MAAa,qBAAsB,SAAQ,0CAAmB;IAC5D,KAAK,CAAC,sBAAsB,CAAC,WAAwB,EAAE,SAAoB;QACzE,IAAI,kBAAkB,GAAQ,WAAW,CAAC,kBAAkB,CAAA;QAC5D,IAAI,kBAAkB,GACpB,CAAA,kBAAkB,aAAlB,kBAAkB,uBAAlB,kBAAkB,CAAE,kBAAkB,KAAI,CAAA,kBAAkB,aAAlB,kBAAkB,uBAAlB,kBAAkB,CAAE,kBAAkB,KAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAA;QAEtG,IAAI,CAAC,kBAAkB,EAAE;YACvB,MAAM,QAAQ,GAAa,MAAM,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,mBAAQ,CAAC,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,WAAW,CAAC,MAAM,EAAE,CAAC,CAAA;YAE9G,IAAI,OAAO,GAAY,SAAS,CAAC,OAAO,CAAA;YACxC,MAAM,cAAc,GAAoB,OAAO,CAAC,cAAc,CAAA;YAE9D,IAAI,EAAE,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,qBAAS,CAAC,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAA;YAC7E,EAAE,CAAC,iBAAiB,CAAC,cAAc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,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,oBAAoB,CAAC,MAAM;qBAC7E;iBACF;aACF,CAAA;YAED,MAAM,wCAAc,CAAC,aAAa,CAAC,WAAW,EAAE;gBAC9C,OAAO,EAAE,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,MAAM,EAAE,IAAI,EAAE,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,IAAI,EAAE,EAAE;gBAC9D,SAAS,EAAE,WAAW,CAAC,SAAS;gBAChC,cAAc;aACf,CAAC,CAAA;SACH;IACH,CAAC;CACF;AA3FD,sDA2FC","sourcesContent":["import { Bizplace } from '@things-factory/biz-base'\nimport { Sellercraft, SellercraftAPI } from '@things-factory/integration-sellercraft'\nimport { Product, ProductDetail } from '@things-factory/product-base'\n\nimport { INVENTORY_STATUS, LOCATION_TYPE } from '../../constants'\nimport { Inventory } from '../../service/inventory/inventory'\nimport { WarehouseController } from '../warehouse-controller'\n\nexport class SellercraftController extends WarehouseController {\n async updateSellercraftStock(sellercraft: Sellercraft, inventory: Inventory): Promise<void> {\n let sellercraftSetting: any = sellercraft.sellercraftSetting\n let disableUpdateStock: boolean =\n sellercraftSetting?.disableUpdateStock && sellercraftSetting?.disableUpdateStock == 1 ? true : false\n\n if (!disableUpdateStock) {\n const bizplace: Bizplace = await this.trxMgr.getRepository(Bizplace).findOneBy({ domain: sellercraft.domain })\n\n let product: Product = inventory.product\n const productDetails: ProductDetail[] = product.productDetails\n\n let qb = await this.trxMgr.getRepository(Inventory).createQueryBuilder('inv')\n qb.leftJoinAndSelect('inv.location', 'loc')\n .andWhere('\"inv\".\"domain_id\" = :domainId')\n .andWhere('\"inv\".\"bizplace_id\" = :bizplaceId')\n .andWhere('\"inv\".\"product_id\" = :productId')\n .andWhere('\"inv\".\"status\" = :status')\n .andWhere('\"loc\".\"type\" NOT IN (:...locationTypes)')\n .setParameters({\n domainId: this.domain.id,\n bizplaceId: bizplace.id,\n productId: product.id,\n status: INVENTORY_STATUS.STORED,\n locationTypes: [LOCATION_TYPE.QUARANTINE, LOCATION_TYPE.RESERVE]\n })\n\n let inventories: Inventory[] = await qb.getMany()\n\n let defaultProductDetail: ProductDetail = product.productDetails.find(productDetail => productDetail.isDefault)\n let inventoryTotalQty: number = 0\n let inventoryTotalLockedQty: number = 0\n\n if (inventories?.length > 0) {\n const sellercraftInvs: any[] = await Promise.all(\n inventories.map(async (inventory: Inventory) => {\n const inventoryPackingType: string = inventory.packingType\n\n let packingSize: number = 1\n if (inventoryPackingType !== defaultProductDetail.packingType) {\n const unmatchingProductDetail: ProductDetail = product.productDetails.find(\n productDetail => productDetail.packingType === inventoryPackingType\n )\n\n packingSize = await this.getChildPackingSize(\n productDetails,\n defaultProductDetail,\n unmatchingProductDetail\n )\n }\n\n return { totalQty: inventory.qty * packingSize, totalLockedQty: inventory.lockedQty * packingSize }\n })\n )\n\n inventoryTotalQty = sellercraftInvs.reduce((total, currentValue) => {\n total += currentValue.totalQty\n return total\n }, 0)\n\n inventoryTotalLockedQty = sellercraftInvs.reduce((total, currentValue) => {\n total += currentValue.totalLockedQty\n return total\n }, 0)\n }\n\n const sellercraftInv: any[] = [\n {\n sku: product.sku,\n gtin: defaultProductDetail.gtin,\n stock: {\n quantity_total: inventoryTotalQty,\n quantity_reserved: inventoryTotalLockedQty,\n unit_of_measure: 'EA'\n },\n package_weight_gm: defaultProductDetail.nettWeight < 1 ? 1 : defaultProductDetail.nettWeight,\n package_dimensions: {\n length_mm: defaultProductDetail.depth < 1 ? 1 : defaultProductDetail.depth,\n width_mm: defaultProductDetail.width < 1 ? 1 : defaultProductDetail.width,\n height_mm: defaultProductDetail.height < 1 ? 1 : defaultProductDetail.height\n }\n }\n ]\n\n await SellercraftAPI.updateProduct(sellercraft, {\n context: { state: { domain: this?.domain, user: this?.user } },\n accountId: sellercraft.accountId,\n sellercraftInv\n })\n }\n }\n}\n"]}
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.WarehouseController = void 0;
4
4
  const auth_base_1 = require("@things-factory/auth-base");
5
5
  const biz_base_1 = require("@things-factory/biz-base");
6
- const notification_1 = require("@things-factory/notification");
7
6
  class WarehouseController {
8
7
  constructor(trxMgr, domain, user) {
9
8
  this.ERROR_MSG = {
@@ -40,10 +39,13 @@ class WarehouseController {
40
39
  */
41
40
  async notifyToUsers(users, message) {
42
41
  const receivers = users.map(user => user.id);
43
- await (0, notification_1.sendNotification)({
44
- receivers,
45
- message
46
- });
42
+ /**
43
+ * @notes Temporary off sendNotification due to suspect of causing wms down
44
+ */
45
+ // await sendNotification({
46
+ // receivers,
47
+ // message
48
+ // })
47
49
  }
48
50
  /**
49
51
  * @summary Notify to office admin
@@ -1 +1 @@
1
- {"version":3,"file":"warehouse-controller.js","sourceRoot":"","sources":["../../server/controllers/warehouse-controller.ts"],"names":[],"mappings":";;;AAEA,yDAAsD;AACtD,uDAAmE;AACnE,+DAA+D;AAgB/D,MAAa,mBAAmB;IAgC9B,YAAY,MAAqB,EAAE,MAAc,EAAE,IAAU;QA/B7C,cAAS,GAAG;YAC1B,IAAI,EAAE;gBACJ,SAAS,EAAE,CAAC,SAAc,EAAE,EAAE,CAAC,6CAA6C,SAAS,EAAE;gBACvF,eAAe,EAAE,CAAC,SAAc,EAAE,EAAE,CAAC,kDAAkD,SAAS,EAAE;gBAClG,SAAS,EAAE,CAAC,MAAW,EAAE,MAAW,EAAE,EAAE,CAAC,2BAA2B,MAAM,UAAU,MAAM,EAAE;aAC7F;YACD,MAAM,EAAE;gBACN,SAAS,EAAE,uBAAuB;gBAClC,aAAa,EAAE,+BAA+B;gBAC9C,aAAa,EAAE,+BAA+B;aAC/C;YACD,MAAM,EAAE;gBACN,aAAa,EAAE,wBAAwB;gBACvC,aAAa,EAAE,+BAA+B;aAC/C;YACD,QAAQ,EAAE;gBACR,sBAAsB,EAAE,CAAC,KAAa,EAAE,a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AM,CAAA;QAC/C,IAAI,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,OAAO;YAAE,MAAM,CAAC,OAAO,GAAG,IAAI,CAAC,IAAI,CAAA;QAC7D,IAAI,CAAC,MAAM,CAAC,OAAO;YAAE,MAAM,CAAC,OAAO,GAAG,IAAI,CAAC,IAAI,CAAA;QAE/C,OAAO,MAAM,CAAA;IACf,CAAC;IAED,cAAc,CAAC,MAA2B;QACxC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,GAAW,EAAE,EAAE;YAC1C,IAAI,MAAM,CAAC,GAAG,CAAC,KAAK,IAAI,IAAI,MAAM,CAAC,GAAG,CAAC,YAAY,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;gBAAE,OAAO,MAAM,CAAC,GAAG,CAAC,CAAA;QAC3G,CAAC,CAAC,CAAA;QAEF,OAAO,MAAM,CAAA;IACf,CAAC;CACF;AA3JD,kDA2JC","sourcesContent":["import { EntityManager } from 'typeorm'\n\nimport { Role, User } from '@things-factory/auth-base'\nimport { Bizplace, getDomainUsers } from '@things-factory/biz-base'\nimport { sendNotification } from '@things-factory/notification'\nimport { ProductDetail } from '@things-factory/product-base'\nimport { Domain } from '@things-factory/shell'\n\nexport interface BasicInterface {\n domain: Domain\n user: User\n}\n\nexport type NotificationMsgInterface = {\n title: string\n body: string\n url: string\n data: any\n}\n\nexport class WarehouseController {\n public readonly ERROR_MSG = {\n FIND: {\n NO_RESULT: (condition: any) => `There's no results matched with condition ${condition}`,\n NO_CHILD_RESULT: (condition: any) => `There's no child result matched with condition ${condition}`,\n NOT_MATCH: (source: any, target: any) => `Unable to find matching ${target} using ${source}`\n },\n CREATE: {\n ID_EXISTS: 'Target has ID already',\n EMPTY_CREATOR: 'Cannot create without creator',\n EMPTY_UPDATER: 'Cannot create without updater'\n },\n UPDATE: {\n ID_NOT_EXISTS: `Target doesn't have ID`,\n EMPTY_UPDATER: 'Cannot update without updater'\n },\n VALIDITY: {\n UNEXPECTED_FIELD_VALUE: (field: string, expectedValue: any, actualValue: any) =>\n `Expected ${field} value is ${expectedValue} but got ${actualValue}`,\n DUPLICATED: (field: string, value: any) => `There is duplicated ${field} value (${value})`,\n CANT_PROCEED_STEP_BY: (step: string, reason: string) => `Can't proceed to ${step} it because ${reason}`\n }\n }\n\n private readonly ROLE_NAMES: Record<string, string> = {\n OFFICE_ADMIN: 'Office Admin'\n }\n\n protected trxMgr: EntityManager\n protected domain: Domain\n protected user: User\n\n constructor(trxMgr: EntityManager, domain: Domain, user: User) {\n this.trxMgr = trxMgr\n this.domain = domain\n this.user = user\n }\n\n /**\n * @summary Notify to passed users\n * @description Passed notification message will be sent to passed users\n */\n async notifyToUsers(users: User[], message: NotificationMsgInterface): Promise<void> {\n const receivers: any[] = users.map(user => user.id)\n await sendNotification({\n receivers,\n message\n })\n }\n\n /**\n * @summary Notify to office admin\n * @description Passed notification message will be sent to office admin of current domain\n * default role name is defiend as ROLE_NAME.OFFICE_ADMIn by default\n * You can change role name by passing roleName as parameter\n */\n async notifyToOfficeAdmin(message: NotificationMsgInterface, roleName?: string): Promise<void> {\n const users: User[] = await this.trxMgr\n .getRepository('users_roles')\n .createQueryBuilder('ur')\n .select('ur.users_id', 'id')\n .where(qb => {\n const subQuery = qb\n .subQuery()\n .select('role.id')\n .from(Role, 'role')\n .where('role.name = :roleName', { roleName: roleName || this.ROLE_NAMES.OFFICE_ADMIN })\n .andWhere('role.domain_id = :domainId', { domainId: this.domain.id })\n .getQuery()\n return 'ur.roles_id IN ' + subQuery\n })\n .getRawMany()\n\n this.notifyToUsers(users, message)\n }\n\n /**\n * @summary Notify to customer of passed bizplace\n * @description Passed notification message will be sent to customer of passed bizplace\n */\n async notifyToCustomer(bizplace: Bizplace, message: NotificationMsgInterface): Promise<void> {\n const users: any[] = await getDomainUsers(bizplace, this.trxMgr)\n\n this.notifyToUsers(users, message)\n }\n\n async getChildPackingSize(\n productDetails: ProductDetail[],\n defaultProductDetail: ProductDetail,\n unmatchingProductDetail: ProductDetail\n ): Promise<number> {\n let hasChildRelation: boolean = Boolean(unmatchingProductDetail?.childProductDetail)\n let hasMatchingChild: boolean\n let packingSize: number = 1\n let currentChildProductDetail: ProductDetail\n\n if (hasChildRelation) {\n currentChildProductDetail = productDetails.find(\n (productDetail: ProductDetail) => productDetail.id === unmatchingProductDetail.childProductDetail.id\n )\n\n if (!currentChildProductDetail) {\n throw new Error(this.ERROR_MSG.FIND.NOT_MATCH('packing type', `GTIN (${unmatchingProductDetail.gtin})`))\n }\n\n hasMatchingChild = Boolean(defaultProductDetail.id === currentChildProductDetail.id)\n if (hasMatchingChild) {\n packingSize = unmatchingProductDetail.packingSize\n } else {\n packingSize = unmatchingProductDetail.packingSize * packingSize\n }\n } else {\n throw new Error(this.ERROR_MSG.FIND.NO_CHILD_RESULT(`${unmatchingProductDetail.gtin}`))\n }\n\n while (hasChildRelation && !hasMatchingChild) {\n if (hasMatchingChild) {\n packingSize = currentChildProductDetail.packingSize * packingSize // 12 x 10\n } else if (!hasMatchingChild && hasChildRelation) {\n packingSize = currentChildProductDetail.packingSize * packingSize // 12 x 10\n currentChildProductDetail = productDetails.find(\n (productDetail: ProductDetail) => productDetail.id === currentChildProductDetail.childProductDetail.id\n )\n\n hasChildRelation = Boolean(currentChildProductDetail?.childProductDetail)\n hasMatchingChild = Boolean(defaultProductDetail.id === currentChildProductDetail.id)\n } else if (!hasChildRelation && !hasMatchingChild) {\n throw new Error(this.ERROR_MSG.FIND.NO_RESULT(unmatchingProductDetail.gtin))\n }\n }\n\n return packingSize\n }\n\n /**\n * @summary set common stamp like domain, creator, updater\n * @description Set common stamp to passed record\n * If it doesn't have id it will handle it as creating one\n * If it has id it will handle it as updating one\n */\n setStamp(record: Record<string, any>): Record<string, any> {\n if (!record.domain) record.domain = this.domain\n if (!record.id && !record.creator) record.creator = this.user\n if (!record.updater) record.updater = this.user\n\n return record\n }\n\n tidyConditions(record: Record<string, any>): Record<string, any> {\n Object.keys(record).forEach((key: string) => {\n if (record[key] === null || record[key] instanceof Date || Array.isArray(record[key])) delete record[key]\n })\n\n return record\n }\n}\n"]}
1
+ {"version":3,"file":"warehouse-controller.js","sourceRoot":"","sources":["../../server/controllers/warehouse-controller.ts"],"names":[],"mappings":";;;AAEA,yDAAsD;AACtD,uDAAmE;AAiBnE,MAAa,mBAAmB;IAgC9B,YAAY,MAAqB,EAAE,MAAc,EAAE,IAAU;QA/B7C,cAAS,GAAG;YAC1B,IAAI,EAAE;gBACJ,SAAS,EAAE,CAAC,SAAc,EAAE,EAAE,CAAC,6CAA6C,SAAS,EAAE;gBACvF,eAAe,EAAE,CAAC,SAAc,EAAE,EAAE,CAAC,kDAAkD,SAAS,EAAE;gBAClG,SAAS,EAAE,CAAC,MAAW,EAAE,MAAW,EAAE,EAAE,CAAC,2BAA2B,MAAM,UAAU,MAAM,EAAE;aAC7F;YACD,MAAM,EAAE;gBACN,SAAS,EAAE,uBAAuB;gBAClC,aAAa,EAAE,+BAA+B;gBAC9C,aAAa,EAAE,+BAA+B;aAC/C;YACD,MAAM,EAAE;gBACN,aAAa,EAAE,wBAAwB;gBACvC,aAAa,EAAE,+BAA+B;aAC/C;YACD,QAAQ,EAAE;gBACR,sBAAsB,EAAE,CAAC,KAAa,EAAE,aAAkB,EAAE,WAAgB,EAAE,EAAE,CAC9E,YAAY,KAAK,aAAa,aAAa,YAAY,WAAW,EAAE;gBACtE,UAAU,EAAE,CAAC,KAAa,EAAE,KAAU,EAAE,EAAE,CAAC,uBAAuB,KAAK,WAAW,KAAK,GAAG;gBAC1F,oBAAoB,EAAE,CAAC,IAAY,EAAE,MAAc,EAAE,EAAE,CAAC,oBAAoB,IAAI,eAAe,MAAM,EAAE;aACxG;SACF,CAAA;QAEgB,eAAU,GAA2B;YACpD,YAAY,EAAE,cAAc;SAC7B,CAAA;QAOC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAA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AK,IAAI,IAAI,MAAM,CAAC,GAAG,CAAC,YAAY,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;gBAAE,OAAO,MAAM,CAAC,GAAG,CAAC,CAAA;QAC3G,CAAC,CAAC,CAAA;QAEF,OAAO,MAAM,CAAA;IACf,CAAC;CACF;AAhKD,kDAgKC","sourcesContent":["import { EntityManager } from 'typeorm'\n\nimport { Role, User } from '@things-factory/auth-base'\nimport { Bizplace, getDomainUsers } from '@things-factory/biz-base'\nimport { sendNotification } from '@things-factory/notification'\nimport { ProductDetail } from '@things-factory/product-base'\nimport { Domain } from '@things-factory/shell'\n\nexport interface BasicInterface {\n domain: Domain\n user: User\n}\n\nexport type NotificationMsgInterface = {\n title: string\n body: string\n url: string\n data: any\n}\n\nexport class WarehouseController {\n public readonly ERROR_MSG = {\n FIND: {\n NO_RESULT: (condition: any) => `There's no results matched with condition ${condition}`,\n NO_CHILD_RESULT: (condition: any) => `There's no child result matched with condition ${condition}`,\n NOT_MATCH: (source: any, target: any) => `Unable to find matching ${target} using ${source}`\n },\n CREATE: {\n ID_EXISTS: 'Target has ID already',\n EMPTY_CREATOR: 'Cannot create without creator',\n EMPTY_UPDATER: 'Cannot create without updater'\n },\n UPDATE: {\n ID_NOT_EXISTS: `Target doesn't have ID`,\n EMPTY_UPDATER: 'Cannot update without updater'\n },\n VALIDITY: {\n UNEXPECTED_FIELD_VALUE: (field: string, expectedValue: any, actualValue: any) =>\n `Expected ${field} value is ${expectedValue} but got ${actualValue}`,\n DUPLICATED: (field: string, value: any) => `There is duplicated ${field} value (${value})`,\n CANT_PROCEED_STEP_BY: (step: string, reason: string) => `Can't proceed to ${step} it because ${reason}`\n }\n }\n\n private readonly ROLE_NAMES: Record<string, string> = {\n OFFICE_ADMIN: 'Office Admin'\n }\n\n protected trxMgr: EntityManager\n protected domain: Domain\n protected user: User\n\n constructor(trxMgr: EntityManager, domain: Domain, user: User) {\n this.trxMgr = trxMgr\n this.domain = domain\n this.user = user\n }\n\n /**\n * @summary Notify to passed users\n * @description Passed notification message will be sent to passed users\n */\n async notifyToUsers(users: User[], message: NotificationMsgInterface): Promise<void> {\n const receivers: any[] = users.map(user => user.id)\n\n /**\n * @notes Temporary off sendNotification due to suspect of causing wms down\n */\n\n // await sendNotification({\n // receivers,\n // message\n // })\n }\n\n /**\n * @summary Notify to office admin\n * @description Passed notification message will be sent to office admin of current domain\n * default role name is defiend as ROLE_NAME.OFFICE_ADMIn by default\n * You can change role name by passing roleName as parameter\n */\n async notifyToOfficeAdmin(message: NotificationMsgInterface, roleName?: string): Promise<void> {\n const users: User[] = await this.trxMgr\n .getRepository('users_roles')\n .createQueryBuilder('ur')\n .select('ur.users_id', 'id')\n .where(qb => {\n const subQuery = qb\n .subQuery()\n .select('role.id')\n .from(Role, 'role')\n .where('role.name = :roleName', { roleName: roleName || this.ROLE_NAMES.OFFICE_ADMIN })\n .andWhere('role.domain_id = :domainId', { domainId: this.domain.id })\n .getQuery()\n return 'ur.roles_id IN ' + subQuery\n })\n .getRawMany()\n\n this.notifyToUsers(users, message)\n }\n\n /**\n * @summary Notify to customer of passed bizplace\n * @description Passed notification message will be sent to customer of passed bizplace\n */\n async notifyToCustomer(bizplace: Bizplace, message: NotificationMsgInterface): Promise<void> {\n const users: any[] = await getDomainUsers(bizplace, this.trxMgr)\n\n this.notifyToUsers(users, message)\n }\n\n async getChildPackingSize(\n productDetails: ProductDetail[],\n defaultProductDetail: ProductDetail,\n unmatchingProductDetail: ProductDetail\n ): Promise<number> {\n let hasChildRelation: boolean = Boolean(unmatchingProductDetail?.childProductDetail)\n let hasMatchingChild: boolean\n let packingSize: number = 1\n let currentChildProductDetail: ProductDetail\n\n if (hasChildRelation) {\n currentChildProductDetail = productDetails.find(\n (productDetail: ProductDetail) => productDetail.id === unmatchingProductDetail.childProductDetail.id\n )\n\n if (!currentChildProductDetail) {\n throw new Error(this.ERROR_MSG.FIND.NOT_MATCH('packing type', `GTIN (${unmatchingProductDetail.gtin})`))\n }\n\n hasMatchingChild = Boolean(defaultProductDetail.id === currentChildProductDetail.id)\n if (hasMatchingChild) {\n packingSize = unmatchingProductDetail.packingSize\n } else {\n packingSize = unmatchingProductDetail.packingSize * packingSize\n }\n } else {\n throw new Error(this.ERROR_MSG.FIND.NO_CHILD_RESULT(`${unmatchingProductDetail.gtin}`))\n }\n\n while (hasChildRelation && !hasMatchingChild) {\n if (hasMatchingChild) {\n packingSize = currentChildProductDetail.packingSize * packingSize // 12 x 10\n } else if (!hasMatchingChild && hasChildRelation) {\n packingSize = currentChildProductDetail.packingSize * packingSize // 12 x 10\n currentChildProductDetail = productDetails.find(\n (productDetail: ProductDetail) => productDetail.id === currentChildProductDetail.childProductDetail.id\n )\n\n hasChildRelation = Boolean(currentChildProductDetail?.childProductDetail)\n hasMatchingChild = Boolean(defaultProductDetail.id === currentChildProductDetail.id)\n } else if (!hasChildRelation && !hasMatchingChild) {\n throw new Error(this.ERROR_MSG.FIND.NO_RESULT(unmatchingProductDetail.gtin))\n }\n }\n\n return packingSize\n }\n\n /**\n * @summary set common stamp like domain, creator, updater\n * @description Set common stamp to passed record\n * If it doesn't have id it will handle it as creating one\n * If it has id it will handle it as updating one\n */\n setStamp(record: Record<string, any>): Record<string, any> {\n if (!record.domain) record.domain = this.domain\n if (!record.id && !record.creator) record.creator = this.user\n if (!record.updater) record.updater = this.user\n\n return record\n }\n\n tidyConditions(record: Record<string, any>): Record<string, any> {\n Object.keys(record).forEach((key: string) => {\n if (record[key] === null || record[key] instanceof Date || Array.isArray(record[key])) delete record[key]\n })\n\n return record\n }\n}\n"]}
@@ -46,7 +46,7 @@ let InventoryMutation = class InventoryMutation {
46
46
  }
47
47
  async deleteInventory(name, context) {
48
48
  const { tx } = context.state;
49
- await tx.getRepository(inventory_1.Inventory).delete({ domain: context.state.domain, name });
49
+ await tx.getRepository(inventory_1.Inventory).delete({ domain: { id: context.state.domain.id }, name });
50
50
  return true;
51
51
  }
52
52
  async updateMultipleInventory(patches, context) {
@@ -61,7 +61,7 @@ let InventoryMutation = class InventoryMutation {
61
61
  let month = today.getMonth();
62
62
  let date = today.getDate();
63
63
  for (let i = 0; i < _createRecords.length; i++) {
64
- const total = await tx.getRepository(inventory_1.Inventory).count({
64
+ const total = await tx.getRepository(inventory_1.Inventory).countBy({
65
65
  createdAt: (0, typeorm_1.MoreThan)(new Date(year, month, date))
66
66
  });
67
67
  const newRecord = _createRecords[i];
@@ -75,10 +75,10 @@ let InventoryMutation = class InventoryMutation {
75
75
  newRecord.warehouse = location.warehouse;
76
76
  }
77
77
  if (newRecord.bizplace && newRecord.bizplace.id) {
78
- newRecord.bizplace = await tx.getRepository(biz_base_1.Bizplace).findOne(newRecord.bizplace.id);
78
+ newRecord.bizplace = (await tx.getRepository(biz_base_1.Bizplace).findOneBy({ id: newRecord.bizplace.id }));
79
79
  }
80
80
  if (newRecord.product && newRecord.product.id) {
81
- var product = await tx.getRepository(product_base_1.Product).findOne(newRecord.product.id);
81
+ var product = (await tx.getRepository(product_base_1.Product).findOneBy({ id: newRecord.product.id }));
82
82
  newRecord.product = product;
83
83
  }
84
84
  let palletId = 'P' +
@@ -153,10 +153,10 @@ let InventoryMutation = class InventoryMutation {
153
153
  }
154
154
  // Condition 3: Change of bizplace or product or batch id or packing type
155
155
  if (newRecord.bizplace && newRecord.bizplace.id) {
156
- newRecord.bizplace = await tx.getRepository(biz_base_1.Bizplace).findOne(newRecord.bizplace.id);
156
+ newRecord.bizplace = (await tx.getRepository(biz_base_1.Bizplace).findOneBy({ id: newRecord.bizplace.id }));
157
157
  }
158
158
  if (newRecord.product && newRecord.product.id) {
159
- newRecord.product = await tx.getRepository(product_base_1.Product).findOne(newRecord.product.id);
159
+ newRecord.product = (await tx.getRepository(product_base_1.Product).findOneBy({ id: newRecord.product.id }));
160
160
  }
161
161
  if ((newRecord.product && newRecord.product.id) ||
162
162
  (newRecord.bizplace && newRecord.bizplace.id) ||
@@ -1 +1 @@
1
- {"version":3,"file":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BAAA,IAAA,kBAAG,GAAE,CAAA;;;;gEA+NP;AAKD;IAHC,IAAA,wBAAS,EAAC,0DAA0D,CAAC;IACrE,IAAA,wBAAS,EAAC,cAAc,CAAC;IACzB,IAAA,uBAAQ,EAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC;IACJ,mBAAA,IAAA,kBAAG,EAAC,KAAK,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAA;IAAiB,mBAAA,IAAA,kBAAG,GAAE,CAAA;;;;0DAQ1E;AAKD;IAHC,IAAA,wBAAS,EAAC,0DAA0D,CAAC;IACrE,IAAA,wBAAS,EAAC,cAAc,CAAC;IACzB,IAAA,uBAAQ,EAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC;IAE1B,mBAAA,IAAA,kBAAG,EAAC,gBAAgB,CAAC,CAAA;IACrB,mBAAA,IAAA,kBAAG,EAAC,UAAU,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAA;IACnC,mBAAA,IAAA,kBAAG,EAAC,UAAU,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAA;IACnC,mBAAA,IAAA,kBAAG,EAAC,kBAAkB,CAAC,CAAA;IACvB,mBAAA,IAAA,kBAAG,EAAC,gBAAgB,CAAC,CAAA;IACrB,mBAAA,IAAA,kBAAG,EAAC,KAAK,CAAC,CAAA;IACV,mBAAA,IAAA,kBAAG,GAAE,CAAA;;;;0DA2IP;AAjdU,iBAAiB;IAD7B,IAAA,uBAAQ,EAAC,qBAAS,CAAC;GACP,iBAAiB,CAkd7B;AAldY,8CAAiB","sourcesContent":["import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'\nimport { EntityManager, In, MoreThan, SelectQueryBuilder } from 'typeorm'\n\nimport { User } from '@things-factory/auth-base'\nimport { Bizplace } from '@things-factory/biz-base'\nimport { generateId } from '@things-factory/id-rule-base'\nimport { Sellercraft, SellercraftStatus } from '@things-factory/integration-sellercraft'\nimport { Product } from '@things-factory/product-base'\nimport { Domain } from '@things-factory/shell'\n\nimport { INVENTORY_STATUS, INVENTORY_TRANSACTION_TYPE, LOCATION_STATUS, RULE_TYPE } from '../../constants'\nimport { SellercraftController } from '../../controllers'\nimport { DateGenerator, InventoryNoGenerator, InventoryUtil } from '../../utils'\nimport { InventoryHistory } from '../inventory-history/inventory-history'\nimport { Location } from '../location/location'\nimport { Inventory } from './inventory'\nimport { InventoryPatch, NewInventory } from './inventory-types'\n\n@Resolver(Inventory)\nexport class InventoryMutation {\n @Directive('@privilege(category: \"inventory\", privilege: \"mutation\")')\n @Directive('@transaction')\n @Mutation(returns => Inventory)\n async createInventory(@Arg('inventory') inventory: NewInventory, @Ctx() context: any): Promise<Inventory> {\n const { tx }: { tx: EntityManager } = context.state\n\n return await tx.getRepository(Inventory).save({\n domain: context.state.domain,\n creator: context.state.user,\n updater: context.state.user,\n ...inventory\n })\n }\n\n @Directive('@privilege(category: \"inventory\", privilege: \"mutation\")')\n @Directive('@transaction')\n @Mutation(returns => Inventory)\n async updateInventory(@Arg('patch') patch: InventoryPatch, @Ctx() context: any): Promise<Inventory> {\n const { domain, user, tx }: { domain: Domain; user: User; tx: EntityManager } = context.state\n\n const invQb: SelectQueryBuilder<Inventory> = await tx\n .getRepository(Inventory)\n .createQueryBuilder('INV')\n .where('INV.domain_id = :domainId', { domainId: domain.id })\n .andWhere('INV.bizplace_id = :bizplaceId', { bizplaceId: patch.bizplace.id })\n .andWhere('INV.batch_id = :batchId', { batchId: patch.batchId })\n .andWhere('INV.product_id = :productId', { productId: patch.product.id })\n .andWhere('INV.packing_type = :packingType', { packingType: patch.packingType })\n .andWhere('INV.packing_size = :packingSize', { packingSize: patch.packingSize })\n\n if (patch?.cartonId) invQb.andWhere('INV.carton_id = :cartonId', { cartonId: patch.cartonId })\n else invQb.andWhere('INV.pallet_id = :palletId', { palletId: patch.palletId })\n\n const inventory = await invQb.getOne()\n\n return await tx.getRepository(Inventory).save({\n ...inventory,\n ...patch,\n updater: user\n })\n }\n\n @Directive('@privilege(category: \"inventory\", privilege: \"mutation\")')\n @Directive('@transaction')\n @Mutation(returns => Inventory)\n async updateInventoryRemark(\n @Arg('id') id: string,\n @Arg('remark') remark: string,\n @Ctx() context: any\n ): Promise<Inventory> {\n const { domain, user, tx }: { domain: Domain; user: User; tx: EntityManager } = context.state\n\n const repository = tx.getRepository(Inventory)\n const inventory = await repository.findOne({ where: { domain: domain, id } })\n\n return await repository.save({\n ...inventory,\n remark,\n updater: user\n })\n }\n\n @Directive('@privilege(category: \"inventory\", privilege: \"mutation\")')\n @Directive('@transaction')\n @Mutation(returns => Boolean)\n async deleteInventory(@Arg('name') name: string, @Ctx() context: any): Promise<Boolean> {\n const { tx }: { tx: EntityManager } = context.state\n\n await tx.getRepository(Inventory).delete({ domain: context.state.domain, name })\n return true\n }\n\n @Directive('@privilege(category: \"inventory\", privilege: \"mutation\")')\n @Directive('@transaction')\n @Mutation(returns => [Inventory])\n async updateMultipleInventory(\n @Arg('patches', type => [InventoryPatch]) patches: InventoryPatch[],\n @Ctx() context: any\n ): Promise<Inventory[]> {\n const { domain, user, tx }: { domain: Domain; user: User; tx: EntityManager } = context.state\n\n let results = []\n const _createRecords = patches.filter((patch: any) => !patch.id)\n const _updateRecords = patches.filter((patch: any) => patch.id)\n\n const inventoryRepo = tx.getRepository(Inventory)\n if (_createRecords.length > 0) {\n let today = new Date()\n let year = today.getFullYear()\n let month = today.getMonth()\n let date = today.getDate()\n\n for (let i = 0; i < _createRecords.length; i++) {\n const total = await tx.getRepository(Inventory).count({\n createdAt: MoreThan(new Date(year, month, date))\n })\n\n const newRecord = _createRecords[i]\n\n if (newRecord.location && newRecord.location.id) {\n var location = await tx.getRepository(Location).findOne({\n where: { id: newRecord.location.id },\n relations: ['warehouse']\n })\n newRecord.location = location\n newRecord.zone = location.zone\n newRecord.warehouse = location.warehouse\n }\n\n if (newRecord.bizplace && newRecord.bizplace.id) {\n newRecord.bizplace = await tx.getRepository(Bizplace).findOne(newRecord.bizplace.id)\n }\n\n if (newRecord.product && newRecord.product.id) {\n var product = await tx.getRepository(Product).findOne(newRecord.product.id)\n newRecord.product = product\n }\n\n let palletId =\n 'P' +\n year.toString().substr(year.toString().length - 2) +\n ('0' + (month + 1).toString()).substr(('0' + (month + 1).toString()).toString().length - 2) +\n ('0' + date.toString()).substr(('0' + date.toString()).length - 2) +\n ('0000' + (total + 1).toString()).substr(('0000' + (total + 1).toString()).length - 4)\n\n newRecord.name = palletId\n newRecord.status = newRecord.qty < 1 ? 'TERMINATED' : 'STORED'\n newRecord.palletId = palletId\n\n const result = await inventoryRepo.save({\n domain: domain,\n creator: user,\n updater: user,\n lastSeq: 0,\n ...newRecord\n } as any)\n\n await tx.getRepository(InventoryHistory).save({\n ...newRecord,\n domain: domain,\n creator: user,\n updater: user,\n name: InventoryNoGenerator.inventoryHistoryName(),\n seq: 0,\n transactionType: 'NEW',\n productId: newRecord.product.id,\n warehouseId: newRecord.warehouse.id,\n locationId: newRecord.location.id\n })\n\n results.push({ ...result, cuFlag: '+' })\n }\n }\n\n if (_updateRecords.length > 0) {\n for (let i = 0; i < _updateRecords.length; i++) {\n const newRecord = _updateRecords[i]\n const newHistoryRecord = JSON.parse(JSON.stringify(_updateRecords[i]))\n let transactionType = ''\n\n let inventory = await inventoryRepo.findOne({\n where: { id: newRecord.id },\n relations: ['warehouse', 'location', 'product', 'bizplace']\n })\n newHistoryRecord.openingQty = inventory.qty\n newHistoryRecord.openingUomValue = inventory.uomValue\n\n // Get last sequence from InventoryHistory\n let latestEntry = await tx.getRepository(InventoryHistory).find({\n where: { palletId: inventory.palletId },\n order: { seq: 'DESC' },\n take: 1\n })\n let lastSeq = latestEntry[0].seq\n\n // Condition 1: Change location (RELOCATE)\n if (newRecord.location && newRecord.location.id) {\n var location = await tx.getRepository(Location).findOne({\n where: { id: newRecord.location.id },\n relations: ['warehouse']\n })\n newRecord.location = location\n newRecord.zone = location.zone\n newRecord.warehouse = location.warehouse\n\n newHistoryRecord.location = location\n newHistoryRecord.zone = location.zone\n newHistoryRecord.warehouse = location.warehouse\n\n transactionType = 'RELOCATE'\n }\n\n // Condition 2: Change of qty or uomValue.\n // Set qty movement for inventory history\n if (typeof newRecord.qty != 'undefined') {\n transactionType = 'ADJUSTMENT'\n newHistoryRecord.qty = newRecord.qty - inventory.qty\n if (newRecord.qty < 1) {\n newRecord.status = 'TERMINATED'\n newRecord.qty = 0\n newRecord.uomValue = 0\n }\n } else {\n newHistoryRecord.qty = 0\n }\n // Set uomValue movement for inventory history\n if (typeof newRecord.uomValue != 'undefined') {\n transactionType = 'ADJUSTMENT'\n newHistoryRecord.uomValue = newRecord.uomValue - inventory.uomValue\n if (newRecord.uomValue < 1) {\n newRecord.uomValue = 0\n }\n } else {\n newHistoryRecord.uomValue = 0\n }\n\n // Condition 3: Change of bizplace or product or batch id or packing type\n if (newRecord.bizplace && newRecord.bizplace.id) {\n newRecord.bizplace = await tx.getRepository(Bizplace).findOne(newRecord.bizplace.id)\n }\n\n if (newRecord.product && newRecord.product.id) {\n newRecord.product = await tx.getRepository(Product).findOne(newRecord.product.id)\n }\n\n if (\n (newRecord.product && newRecord.product.id) ||\n (newRecord.bizplace && newRecord.bizplace.id) ||\n newRecord.batchId ||\n newRecord.packingType\n ) {\n if (\n inventory.bizplace.id !== (newRecord.bizplace ? newRecord.bizplace.id : '') ||\n inventory.product.id !== (newRecord.product ? newRecord.product.id : '') ||\n inventory.batchId !== newRecord.batchId ||\n inventory.packingType !== newRecord.packingType\n ) {\n transactionType = 'ADJUSTMENT'\n lastSeq = lastSeq + 1\n let inventoryHistory = {\n ...inventory,\n domain: domain,\n bizplace: inventory.bizplace.id,\n openingQty: inventory.qty,\n openingUomValue: inventory.uomValue,\n qty: -inventory.qty || 0,\n uomValue: -inventory.uomValue || 0,\n name: InventoryNoGenerator.inventoryHistoryName(),\n seq: lastSeq,\n transactionType: transactionType,\n status: INVENTORY_STATUS.TERMINATED,\n productId: inventory.product.id,\n warehouseId: inventory.warehouse.id,\n locationId: inventory.location.id,\n creator: user,\n updater: user\n }\n\n delete inventoryHistory.id\n await tx.getRepository(InventoryHistory).save(inventoryHistory as any)\n\n newHistoryRecord.qty = newRecord.qty || inventory.qty\n newHistoryRecord.uomValue = newRecord.uomValue || inventory.uomValue || 0\n newHistoryRecord.openingQty = 0\n newHistoryRecord.openingUomValue = 0\n newHistoryRecord.batchId = newRecord.batchId || inventory.batchId || '-'\n }\n }\n\n //Transaction type will be RELOCATE if there is only location change. Any other changes will be considered Adjustment.\n lastSeq = lastSeq + 1\n let inventoryHistory = {\n ...inventory,\n ...newHistoryRecord,\n domain: domain,\n creator: user,\n updater: user,\n name: InventoryNoGenerator.inventoryHistoryName(),\n seq: lastSeq,\n transactionType: transactionType == '' ? 'ADJUSTMENT' : transactionType,\n productId: newHistoryRecord.product ? newHistoryRecord.product.id : inventory.product.id,\n warehouseId: newHistoryRecord.warehouse ? newHistoryRecord.warehouse.id : inventory.warehouse.id,\n locationId: newHistoryRecord.location ? newHistoryRecord.location.id : inventory.location.id\n }\n\n delete inventoryHistory.id\n await tx.getRepository(InventoryHistory).save(inventoryHistory)\n\n const result = await inventoryRepo.save({\n ...inventory,\n ...newRecord,\n updater: user,\n lastSeq: lastSeq\n })\n\n results.push({ ...result, cuFlag: 'M' })\n }\n }\n\n return results\n }\n\n @Directive('@privilege(category: \"inventory\", privilege: \"mutation\")')\n @Directive('@transaction')\n @Mutation(returns => Boolean)\n async deleteInventories(@Arg('ids', type => [String]) ids: string[], @Ctx() context: any): Promise<Boolean> {\n const { tx }: { tx: EntityManager } = context.state\n\n await tx.getRepository(Inventory).delete({\n id: In(ids)\n })\n\n return true\n }\n\n @Directive('@privilege(category: \"inventory\", privilege: \"mutation\")')\n @Directive('@transaction')\n @Mutation(returns => Boolean)\n async inventoryTransfer(\n @Arg('originPalletId') originPalletId: string,\n @Arg('palletId', { nullable: true }) palletId: string,\n @Arg('cartonId', { nullable: true }) cartonId: string,\n @Arg('fromLocationName') fromLocationName: string,\n @Arg('toLocationName') toLocationName: string,\n @Arg('qty') qty: number,\n @Ctx() context: any\n ): Promise<Boolean> {\n const { domain, user, tx }: { domain: Domain; user: User; tx: EntityManager } = context.state\n\n const fromLocation: Location = await tx.getRepository(Location).findOne({\n where: { domain: domain, name: fromLocationName },\n relations: ['domain', 'warehouse']\n })\n // 1. check toLocation exist\n const toLocation: Location = await tx.getRepository(Location).findOne({\n where: { domain: domain, name: toLocationName },\n relations: ['domain', 'warehouse']\n })\n if (!toLocation) throw new Error(`To location doesn't exists`)\n\n if (qty < 0) throw new Error(`Invalid quantity`)\n\n // 2. search for related inventory\n const invQb: SelectQueryBuilder<Inventory> = await tx\n .getRepository(Inventory)\n .createQueryBuilder('INV')\n .innerJoinAndSelect('INV.location', 'loc')\n .innerJoinAndSelect('INV.product', 'product')\n .innerJoinAndSelect('INV.bizplace', 'bizplace')\n .leftJoinAndSelect('INV.refInventory', 'refInventory')\n .leftJoinAndSelect('INV.reusablePallet', 'reusablePallet')\n .leftJoinAndSelect('INV.productDetail', 'productDetail')\n .leftJoinAndSelect('bizplace.domain', 'domain')\n .leftJoinAndSelect('product.productDetails', 'productDetails')\n .where('INV.domain_id = :domainId', { domainId: domain.id })\n .andWhere('INV.pallet_id = :palletId', { palletId: originPalletId })\n\n let inventory: Inventory = await invQb.getOne()\n if (!inventory) throw new Error('Inventory not found')\n\n if (qty > inventory.qty - (inventory?.lockedQty > 0 ? inventory.lockedQty : 0))\n throw new Error('Transfer quantity exceeded inventory quantity')\n\n if (toLocation.name == inventory.location.name) throw new Error('Inventory is in current location')\n\n let transactionInventory = new InventoryUtil(tx, domain, user)\n\n const sellercraft: Sellercraft = await tx.getRepository(Sellercraft).findOne({\n where: { domain: inventory.bizplace.domain, status: SellercraftStatus.ACTIVE },\n relations: ['domain']\n })\n\n const partialTransferFunc = async function (inventory, qty, fromLocation, toLocation, cartonId, palletId, context) {\n const { user, tx }: { domain: Domain; user: User; tx: EntityManager } = context.state\n\n if (qty < inventory.qty - (inventory?.lockedQty > 0 ? inventory.lockedQty : 0)) {\n if (!palletId || palletId.trim() == '') throw new Error('Require new lot id for partial transfer')\n\n let transferQty = qty\n let transferUomValue = (inventory.uomValue / inventory.qty) * qty\n let newInventory = {\n ...inventory,\n palletId,\n location: toLocation,\n warehouse: toLocation.warehouse,\n zone: toLocation.zone,\n creator: user,\n updater: user\n }\n\n delete newInventory.id\n delete newInventory.updatedAt\n\n newInventory.cartonId = cartonId\n newInventory.qty = transferQty\n newInventory.lockedQty = 0\n newInventory.uomValue = transferUomValue\n newInventory.lockedUomValue = 0\n\n await transactionInventory.transactionInventory(\n { ...inventory, qty: inventory.qty - transferQty, uomValue: inventory.uomValue - transferUomValue },\n null,\n -transferQty,\n -transferUomValue,\n INVENTORY_TRANSACTION_TYPE.RELOCATE\n )\n\n await transactionInventory.transactionInventory(\n newInventory,\n null,\n transferQty,\n transferUomValue,\n INVENTORY_TRANSACTION_TYPE.RELOCATE\n )\n\n if (sellercraft) {\n const sellercraftCtrl: SellercraftController = new SellercraftController(tx, domain, user)\n await sellercraftCtrl.updateSellercraftStock(sellercraft, inventory)\n await sellercraftCtrl.updateSellercraftStock(sellercraft, newInventory)\n }\n } else {\n inventory.warehouse = toLocation.warehouse\n inventory.location = toLocation\n inventory.zone = toLocation.zone\n inventory.updater = user\n inventory.cartonId = cartonId\n\n let isEmptyLocation = await tx.getRepository(Inventory).find({\n where: { location: fromLocation }\n })\n\n if ((isEmptyLocation.length = 1)) {\n await tx.getRepository(Location).save({\n ...fromLocation,\n status: LOCATION_STATUS.EMPTY\n })\n }\n\n await transactionInventory.transactionInventory(inventory, null, 0, 0, INVENTORY_TRANSACTION_TYPE.RELOCATE)\n\n if (sellercraft) {\n const sellercraftCtrl: SellercraftController = new SellercraftController(tx, domain, user)\n await sellercraftCtrl.updateSellercraftStock(sellercraft, inventory)\n }\n }\n }\n\n if (inventory.cartonId && inventory.cartonId != '') {\n if (!cartonId) throw new Error('Require carton id')\n\n if (qty < inventory.qty - (inventory?.lockedQty > 0 ? inventory.lockedQty : 0)) {\n palletId = await generateId({\n domain: domain,\n type: RULE_TYPE.LOT_NUMBER_ID,\n seed: { date: DateGenerator.generateDate() }\n })\n }\n\n await partialTransferFunc(inventory, qty, fromLocation, toLocation, cartonId, palletId, context)\n } else {\n await partialTransferFunc(inventory, qty, fromLocation, toLocation, null, palletId, context)\n }\n\n return true\n }\n}\n"]}
1
+ {"version":3,"file":"inventory-mutation.js","sourceRoot":"","sources":["../../../server/service/inventory/inventory-mutation.ts"],"names":[],"mappings":";;;;AAAA,+CAAsE;AACtE,qCAA0D;AAE1D,uDAAmD;AACnD,+DAAyD;AACzD,qFAAwF;AACxF,+DAAsD;AAEtD,+CAA0G;AAC1G,mDAAyD;AACzD,uCAAgF;AAChF,8EAAyE;AACzE,mDAA+C;AAC/C,2CAAuC;AACvC,uDAAgE;AAGhE,IAAa,iBAAiB,GAA9B,MAAa,iBAAiB;IAI5B,KAAK,CAAC,eAAe,CACD,SAAuB,EAClC,OAAwB;QAE/B,MAAM,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAE5B,OAAO,MAAM,EAAE,CAAC,aAAa,CAAC,qBAAS,CAAC,CAAC,IAAI,iBAC3C,MAAM,EAAE,OAAO,CAAC,KAAK,CAAC,MAAM,EAC5B,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,IAAI,EAC3B,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,IAAI,IACxB,SAAS,EACZ,CAAA;IACJ,CAAC;IAKD,KAAK,CAAC,eAAe,CAAe,KAAqB,EAAS,OAAwB;QACxF,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAE1C,MAAM,KAAK,GAAkC,MAAM,EAAE;aAClD,aAAa,CAAC,qBAAS,CAAC;aACxB,kBAAkB,CAAC,KAAK,CAAC;aACzB,KAAK,CAAC,2BAA2B,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AAC,CAAA;IACvB,mBAAA,IAAA,kBAAG,EAAC,gBAAgB,CAAC,CAAA;IACrB,mBAAA,IAAA,kBAAG,EAAC,KAAK,CAAC,CAAA;IACV,mBAAA,IAAA,kBAAG,GAAE,CAAA;;;;0DA2IP;AAvdU,iBAAiB;IAD7B,IAAA,uBAAQ,EAAC,qBAAS,CAAC;GACP,iBAAiB,CAwd7B;AAxdY,8CAAiB","sourcesContent":["import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'\nimport { In, MoreThan, SelectQueryBuilder } from 'typeorm'\n\nimport { Bizplace } from '@things-factory/biz-base'\nimport { generateId } from '@things-factory/id-rule-base'\nimport { Sellercraft, SellercraftStatus } from '@things-factory/integration-sellercraft'\nimport { Product } from '@things-factory/product-base'\n\nimport { INVENTORY_STATUS, INVENTORY_TRANSACTION_TYPE, LOCATION_STATUS, RULE_TYPE } from '../../constants'\nimport { SellercraftController } from '../../controllers'\nimport { DateGenerator, InventoryNoGenerator, InventoryUtil } from '../../utils'\nimport { InventoryHistory } from '../inventory-history/inventory-history'\nimport { Location } from '../location/location'\nimport { Inventory } from './inventory'\nimport { InventoryPatch, NewInventory } from './inventory-types'\n\n@Resolver(Inventory)\nexport class InventoryMutation {\n @Directive('@privilege(category: \"inventory\", privilege: \"mutation\")')\n @Directive('@transaction')\n @Mutation(returns => Inventory)\n async createInventory(\n @Arg('inventory') inventory: NewInventory,\n @Ctx() context: ResolverContext\n ): Promise<Inventory> {\n const { tx } = context.state\n\n return await tx.getRepository(Inventory).save({\n domain: context.state.domain,\n creator: context.state.user,\n updater: context.state.user,\n ...inventory\n })\n }\n\n @Directive('@privilege(category: \"inventory\", privilege: \"mutation\")')\n @Directive('@transaction')\n @Mutation(returns => Inventory)\n async updateInventory(@Arg('patch') patch: InventoryPatch, @Ctx() context: ResolverContext): Promise<Inventory> {\n const { domain, user, tx } = context.state\n\n const invQb: SelectQueryBuilder<Inventory> = await tx\n .getRepository(Inventory)\n .createQueryBuilder('INV')\n .where('INV.domain_id = :domainId', { domainId: domain.id })\n .andWhere('INV.bizplace_id = :bizplaceId', { bizplaceId: patch.bizplace.id })\n .andWhere('INV.batch_id = :batchId', { batchId: patch.batchId })\n .andWhere('INV.product_id = :productId', { productId: patch.product.id })\n .andWhere('INV.packing_type = :packingType', { packingType: patch.packingType })\n .andWhere('INV.packing_size = :packingSize', { packingSize: patch.packingSize })\n\n if (patch?.cartonId) invQb.andWhere('INV.carton_id = :cartonId', { cartonId: patch.cartonId })\n else invQb.andWhere('INV.pallet_id = :palletId', { palletId: patch.palletId })\n\n const inventory = await invQb.getOne()\n\n return await tx.getRepository(Inventory).save({\n ...inventory,\n ...patch,\n updater: user\n })\n }\n\n @Directive('@privilege(category: \"inventory\", privilege: \"mutation\")')\n @Directive('@transaction')\n @Mutation(returns => Inventory)\n async updateInventoryRemark(\n @Arg('id') id: string,\n @Arg('remark') remark: string,\n @Ctx() context: ResolverContext\n ): Promise<Inventory> {\n const { domain, user, tx } = context.state\n\n const repository = tx.getRepository(Inventory)\n const inventory = await repository.findOne({ where: { domain: domain, id } })\n\n return await repository.save({\n ...inventory,\n remark,\n updater: user\n })\n }\n\n @Directive('@privilege(category: \"inventory\", privilege: \"mutation\")')\n @Directive('@transaction')\n @Mutation(returns => Boolean)\n async deleteInventory(@Arg('name') name: string, @Ctx() context: ResolverContext): Promise<Boolean> {\n const { tx } = context.state\n\n await tx.getRepository(Inventory).delete({ domain: { id: context.state.domain.id }, name })\n return true\n }\n\n @Directive('@privilege(category: \"inventory\", privilege: \"mutation\")')\n @Directive('@transaction')\n @Mutation(returns => [Inventory])\n async updateMultipleInventory(\n @Arg('patches', type => [InventoryPatch]) patches: InventoryPatch[],\n @Ctx() context: ResolverContext\n ): Promise<Inventory[]> {\n const { domain, user, tx } = context.state\n\n let results = []\n const _createRecords = patches.filter((patch: any) => !patch.id)\n const _updateRecords = patches.filter((patch: any) => patch.id)\n\n const inventoryRepo = tx.getRepository(Inventory)\n if (_createRecords.length > 0) {\n let today = new Date()\n let year = today.getFullYear()\n let month = today.getMonth()\n let date = today.getDate()\n\n for (let i = 0; i < _createRecords.length; i++) {\n const total = await tx.getRepository(Inventory).countBy({\n createdAt: MoreThan(new Date(year, month, date))\n })\n\n const newRecord = _createRecords[i]\n\n if (newRecord.location && newRecord.location.id) {\n var location = await tx.getRepository(Location).findOne({\n where: { id: newRecord.location.id },\n relations: ['warehouse']\n })\n newRecord.location = location\n newRecord.zone = location.zone\n newRecord.warehouse = location.warehouse\n }\n\n if (newRecord.bizplace && newRecord.bizplace.id) {\n newRecord.bizplace = (await tx.getRepository(Bizplace).findOneBy({ id: newRecord.bizplace.id })) as any\n }\n\n if (newRecord.product && newRecord.product.id) {\n var product = (await tx.getRepository(Product).findOneBy({ id: newRecord.product.id })) as any\n newRecord.product = product\n }\n\n let palletId =\n 'P' +\n year.toString().substr(year.toString().length - 2) +\n ('0' + (month + 1).toString()).substr(('0' + (month + 1).toString()).toString().length - 2) +\n ('0' + date.toString()).substr(('0' + date.toString()).length - 2) +\n ('0000' + (total + 1).toString()).substr(('0000' + (total + 1).toString()).length - 4)\n\n newRecord.name = palletId\n newRecord.status = newRecord.qty < 1 ? 'TERMINATED' : 'STORED'\n newRecord.palletId = palletId\n\n const result = await inventoryRepo.save({\n domain: domain,\n creator: user,\n updater: user,\n lastSeq: 0,\n ...newRecord\n } as any)\n\n await tx.getRepository(InventoryHistory).save({\n ...newRecord,\n domain: domain,\n creator: user,\n updater: user,\n name: InventoryNoGenerator.inventoryHistoryName(),\n seq: 0,\n transactionType: 'NEW',\n productId: newRecord.product.id,\n warehouseId: newRecord.warehouse.id,\n locationId: newRecord.location.id\n })\n\n results.push({ ...result, cuFlag: '+' })\n }\n }\n\n if (_updateRecords.length > 0) {\n for (let i = 0; i < _updateRecords.length; i++) {\n const newRecord = _updateRecords[i]\n const newHistoryRecord = JSON.parse(JSON.stringify(_updateRecords[i]))\n let transactionType = ''\n\n let inventory = await inventoryRepo.findOne({\n where: { id: newRecord.id },\n relations: ['warehouse', 'location', 'product', 'bizplace']\n })\n newHistoryRecord.openingQty = inventory.qty\n newHistoryRecord.openingUomValue = inventory.uomValue\n\n // Get last sequence from InventoryHistory\n let latestEntry = await tx.getRepository(InventoryHistory).find({\n where: { palletId: inventory.palletId },\n order: { seq: 'DESC' },\n take: 1\n })\n let lastSeq = latestEntry[0].seq\n\n // Condition 1: Change location (RELOCATE)\n if (newRecord.location && newRecord.location.id) {\n var location = await tx.getRepository(Location).findOne({\n where: { id: newRecord.location.id },\n relations: ['warehouse']\n })\n newRecord.location = location\n newRecord.zone = location.zone\n newRecord.warehouse = location.warehouse\n\n newHistoryRecord.location = location\n newHistoryRecord.zone = location.zone\n newHistoryRecord.warehouse = location.warehouse\n\n transactionType = 'RELOCATE'\n }\n\n // Condition 2: Change of qty or uomValue.\n // Set qty movement for inventory history\n if (typeof newRecord.qty != 'undefined') {\n transactionType = 'ADJUSTMENT'\n newHistoryRecord.qty = newRecord.qty - inventory.qty\n if (newRecord.qty < 1) {\n newRecord.status = 'TERMINATED'\n newRecord.qty = 0\n newRecord.uomValue = 0\n }\n } else {\n newHistoryRecord.qty = 0\n }\n // Set uomValue movement for inventory history\n if (typeof newRecord.uomValue != 'undefined') {\n transactionType = 'ADJUSTMENT'\n newHistoryRecord.uomValue = newRecord.uomValue - inventory.uomValue\n if (newRecord.uomValue < 1) {\n newRecord.uomValue = 0\n }\n } else {\n newHistoryRecord.uomValue = 0\n }\n\n // Condition 3: Change of bizplace or product or batch id or packing type\n if (newRecord.bizplace && newRecord.bizplace.id) {\n newRecord.bizplace = (await tx.getRepository(Bizplace).findOneBy({ id: newRecord.bizplace.id })) as any\n }\n\n if (newRecord.product && newRecord.product.id) {\n newRecord.product = (await tx.getRepository(Product).findOneBy({ id: newRecord.product.id })) as any\n }\n\n if (\n (newRecord.product && newRecord.product.id) ||\n (newRecord.bizplace && newRecord.bizplace.id) ||\n newRecord.batchId ||\n newRecord.packingType\n ) {\n if (\n inventory.bizplace.id !== (newRecord.bizplace ? newRecord.bizplace.id : '') ||\n inventory.product.id !== (newRecord.product ? newRecord.product.id : '') ||\n inventory.batchId !== newRecord.batchId ||\n inventory.packingType !== newRecord.packingType\n ) {\n transactionType = 'ADJUSTMENT'\n lastSeq = lastSeq + 1\n let inventoryHistory = {\n ...inventory,\n domain: domain,\n bizplace: inventory.bizplace.id,\n openingQty: inventory.qty,\n openingUomValue: inventory.uomValue,\n qty: -inventory.qty || 0,\n uomValue: -inventory.uomValue || 0,\n name: InventoryNoGenerator.inventoryHistoryName(),\n seq: lastSeq,\n transactionType: transactionType,\n status: INVENTORY_STATUS.TERMINATED,\n productId: inventory.product.id,\n warehouseId: inventory.warehouse.id,\n locationId: inventory.location.id,\n creator: user,\n updater: user\n }\n\n delete inventoryHistory.id\n await tx.getRepository(InventoryHistory).save(inventoryHistory as any)\n\n newHistoryRecord.qty = newRecord.qty || inventory.qty\n newHistoryRecord.uomValue = newRecord.uomValue || inventory.uomValue || 0\n newHistoryRecord.openingQty = 0\n newHistoryRecord.openingUomValue = 0\n newHistoryRecord.batchId = newRecord.batchId || inventory.batchId || '-'\n }\n }\n\n //Transaction type will be RELOCATE if there is only location change. Any other changes will be considered Adjustment.\n lastSeq = lastSeq + 1\n let inventoryHistory = {\n ...inventory,\n ...newHistoryRecord,\n domain: domain,\n creator: user,\n updater: user,\n name: InventoryNoGenerator.inventoryHistoryName(),\n seq: lastSeq,\n transactionType: transactionType == '' ? 'ADJUSTMENT' : transactionType,\n productId: newHistoryRecord.product ? newHistoryRecord.product.id : inventory.product.id,\n warehouseId: newHistoryRecord.warehouse ? newHistoryRecord.warehouse.id : inventory.warehouse.id,\n locationId: newHistoryRecord.location ? newHistoryRecord.location.id : inventory.location.id\n }\n\n delete inventoryHistory.id\n await tx.getRepository(InventoryHistory).save(inventoryHistory)\n\n const result = await inventoryRepo.save({\n ...inventory,\n ...newRecord,\n updater: user,\n lastSeq: lastSeq\n })\n\n results.push({ ...result, cuFlag: 'M' })\n }\n }\n\n return results\n }\n\n @Directive('@privilege(category: \"inventory\", privilege: \"mutation\")')\n @Directive('@transaction')\n @Mutation(returns => Boolean)\n async deleteInventories(\n @Arg('ids', type => [String]) ids: string[],\n @Ctx() context: ResolverContext\n ): Promise<Boolean> {\n const { tx } = context.state\n\n await tx.getRepository(Inventory).delete({\n id: In(ids)\n })\n\n return true\n }\n\n @Directive('@privilege(category: \"inventory\", privilege: \"mutation\")')\n @Directive('@transaction')\n @Mutation(returns => Boolean)\n async inventoryTransfer(\n @Arg('originPalletId') originPalletId: string,\n @Arg('palletId', { nullable: true }) palletId: string,\n @Arg('cartonId', { nullable: true }) cartonId: string,\n @Arg('fromLocationName') fromLocationName: string,\n @Arg('toLocationName') toLocationName: string,\n @Arg('qty') qty: number,\n @Ctx() context: ResolverContext\n ): Promise<Boolean> {\n const { domain, user, tx } = context.state\n\n const fromLocation: Location = await tx.getRepository(Location).findOne({\n where: { domain: domain, name: fromLocationName },\n relations: ['domain', 'warehouse']\n })\n // 1. check toLocation exist\n const toLocation: Location = await tx.getRepository(Location).findOne({\n where: { domain: domain, name: toLocationName },\n relations: ['domain', 'warehouse']\n })\n if (!toLocation) throw new Error(`To location doesn't exists`)\n\n if (qty < 0) throw new Error(`Invalid quantity`)\n\n // 2. search for related inventory\n const invQb: SelectQueryBuilder<Inventory> = await tx\n .getRepository(Inventory)\n .createQueryBuilder('INV')\n .innerJoinAndSelect('INV.location', 'loc')\n .innerJoinAndSelect('INV.product', 'product')\n .innerJoinAndSelect('INV.bizplace', 'bizplace')\n .leftJoinAndSelect('INV.refInventory', 'refInventory')\n .leftJoinAndSelect('INV.reusablePallet', 'reusablePallet')\n .leftJoinAndSelect('INV.productDetail', 'productDetail')\n .leftJoinAndSelect('bizplace.domain', 'domain')\n .leftJoinAndSelect('product.productDetails', 'productDetails')\n .where('INV.domain_id = :domainId', { domainId: domain.id })\n .andWhere('INV.pallet_id = :palletId', { palletId: originPalletId })\n\n let inventory: Inventory = await invQb.getOne()\n if (!inventory) throw new Error('Inventory not found')\n\n if (qty > inventory.qty - (inventory?.lockedQty > 0 ? inventory.lockedQty : 0))\n throw new Error('Transfer quantity exceeded inventory quantity')\n\n if (toLocation.name == inventory.location.name) throw new Error('Inventory is in current location')\n\n let transactionInventory = new InventoryUtil(tx, domain, user)\n\n const sellercraft: Sellercraft = await tx.getRepository(Sellercraft).findOne({\n where: { domain: inventory.bizplace.domain, status: SellercraftStatus.ACTIVE },\n relations: ['domain']\n })\n\n const partialTransferFunc = async function (inventory, qty, fromLocation, toLocation, cartonId, palletId, context) {\n const { user, tx } = context.state\n\n if (qty < inventory.qty - (inventory?.lockedQty > 0 ? inventory.lockedQty : 0)) {\n if (!palletId || palletId.trim() == '') throw new Error('Require new lot id for partial transfer')\n\n let transferQty = qty\n let transferUomValue = (inventory.uomValue / inventory.qty) * qty\n let newInventory = {\n ...inventory,\n palletId,\n location: toLocation,\n warehouse: toLocation.warehouse,\n zone: toLocation.zone,\n creator: user,\n updater: user\n }\n\n delete newInventory.id\n delete newInventory.updatedAt\n\n newInventory.cartonId = cartonId\n newInventory.qty = transferQty\n newInventory.lockedQty = 0\n newInventory.uomValue = transferUomValue\n newInventory.lockedUomValue = 0\n\n await transactionInventory.transactionInventory(\n { ...inventory, qty: inventory.qty - transferQty, uomValue: inventory.uomValue - transferUomValue },\n null,\n -transferQty,\n -transferUomValue,\n INVENTORY_TRANSACTION_TYPE.RELOCATE\n )\n\n await transactionInventory.transactionInventory(\n newInventory,\n null,\n transferQty,\n transferUomValue,\n INVENTORY_TRANSACTION_TYPE.RELOCATE\n )\n\n if (sellercraft) {\n const sellercraftCtrl: SellercraftController = new SellercraftController(tx, domain, user)\n await sellercraftCtrl.updateSellercraftStock(sellercraft, inventory)\n await sellercraftCtrl.updateSellercraftStock(sellercraft, newInventory)\n }\n } else {\n inventory.warehouse = toLocation.warehouse\n inventory.location = toLocation\n inventory.zone = toLocation.zone\n inventory.updater = user\n inventory.cartonId = cartonId\n\n let isEmptyLocation = await tx.getRepository(Inventory).find({\n where: { location: fromLocation }\n })\n\n if ((isEmptyLocation.length = 1)) {\n await tx.getRepository(Location).save({\n ...fromLocation,\n status: LOCATION_STATUS.EMPTY\n })\n }\n\n await transactionInventory.transactionInventory(inventory, null, 0, 0, INVENTORY_TRANSACTION_TYPE.RELOCATE)\n\n if (sellercraft) {\n const sellercraftCtrl: SellercraftController = new SellercraftController(tx, domain, user)\n await sellercraftCtrl.updateSellercraftStock(sellercraft, inventory)\n }\n }\n }\n\n if (inventory.cartonId && inventory.cartonId != '') {\n if (!cartonId) throw new Error('Require carton id')\n\n if (qty < inventory.qty - (inventory?.lockedQty > 0 ? inventory.lockedQty : 0)) {\n palletId = await generateId({\n domain: domain,\n type: RULE_TYPE.LOT_NUMBER_ID,\n seed: { date: DateGenerator.generateDate() }\n })\n }\n\n await partialTransferFunc(inventory, qty, fromLocation, toLocation, cartonId, palletId, context)\n } else {\n await partialTransferFunc(inventory, qty, fromLocation, toLocation, null, palletId, context)\n }\n\n return true\n }\n}\n"]}