@things-factory/warehouse-base 6.0.133 → 6.0.136

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.
@@ -168,7 +168,7 @@ let InventoryMutation = class InventoryMutation {
168
168
  inventory.packingType !== newRecord.packingType) {
169
169
  transactionType = 'ADJUSTMENT';
170
170
  lastSeq = lastSeq + 1;
171
- let inventoryHistory = Object.assign(Object.assign({}, inventory), { domain: domain, bizplace: inventory.bizplace.id, openingQty: inventory.qty, openingUomValue: inventory.uomValue, qty: -inventory.qty || 0, uomValue: -inventory.uomValue || 0, name: utils_1.InventoryNoGenerator.inventoryHistoryName(), seq: lastSeq, transactionType: transactionType, status: constants_1.INVENTORY_STATUS.TERMINATED, productId: inventory.product.id, warehouseId: inventory.warehouse.id, locationId: inventory.location.id, creator: user, updater: user });
171
+ let inventoryHistory = Object.assign(Object.assign({}, inventory), { domain: domain, bizplace: inventory.bizplace.id, openingQty: inventory.qty, openingUomValue: inventory.uomValue, qty: -inventory.qty || 0, uomValue: -inventory.uomValue || 0, name: utils_1.InventoryNoGenerator.inventoryHistoryName(), seq: lastSeq, inventory, transactionType: transactionType, status: constants_1.INVENTORY_STATUS.TERMINATED, productId: inventory.product.id, warehouseId: inventory.warehouse.id, locationId: inventory.location.id, creator: user, updater: user });
172
172
  delete inventoryHistory.id;
173
173
  await tx.getRepository(inventory_history_1.InventoryHistory).save(inventoryHistory);
174
174
  newHistoryRecord.qty = newRecord.qty || inventory.qty;
@@ -180,7 +180,7 @@ let InventoryMutation = class InventoryMutation {
180
180
  }
181
181
  //Transaction type will be RELOCATE if there is only location change. Any other changes will be considered Adjustment.
182
182
  lastSeq = lastSeq + 1;
183
- let inventoryHistory = Object.assign(Object.assign(Object.assign({}, inventory), newHistoryRecord), { domain: domain, creator: user, updater: user, name: utils_1.InventoryNoGenerator.inventoryHistoryName(), seq: lastSeq, transactionType: transactionType == '' ? 'ADJUSTMENT' : transactionType, productId: newHistoryRecord.product ? newHistoryRecord.product.id : inventory.product.id, warehouseId: newHistoryRecord.warehouse ? newHistoryRecord.warehouse.id : inventory.warehouse.id, locationId: newHistoryRecord.location ? newHistoryRecord.location.id : inventory.location.id });
183
+ let inventoryHistory = Object.assign(Object.assign(Object.assign({}, inventory), newHistoryRecord), { domain: domain, creator: user, updater: user, name: utils_1.InventoryNoGenerator.inventoryHistoryName(), seq: lastSeq, inventory, transactionType: transactionType == '' ? 'ADJUSTMENT' : transactionType, productId: newHistoryRecord.product ? newHistoryRecord.product.id : inventory.product.id, warehouseId: newHistoryRecord.warehouse ? newHistoryRecord.warehouse.id : inventory.warehouse.id, locationId: newHistoryRecord.location ? newHistoryRecord.location.id : inventory.location.id });
184
184
  delete inventoryHistory.id;
185
185
  await tx.getRepository(inventory_history_1.InventoryHistory).save(inventoryHistory);
186
186
  const result = await inventoryRepo.save(Object.assign(Object.assign(Object.assign({}, inventory), newRecord), { updater: user, lastSeq: lastSeq }));
@@ -196,7 +196,7 @@ let InventoryMutation = class InventoryMutation {
196
196
  });
197
197
  return true;
198
198
  }
199
- async inventoryTransfer(originPalletId, palletId, cartonId, fromLocationName, toLocationName, qty, context) {
199
+ async inventoryTransfer(originPalletId, palletId, cartonId, fromLocationName, toLocationName, qty, reason, context) {
200
200
  const { domain, user, tx } = context.state;
201
201
  const fromLocation = await tx.getRepository(location_1.Location).findOne({
202
202
  where: { domain: { id: domain.id }, name: fromLocationName },
@@ -208,7 +208,7 @@ let InventoryMutation = class InventoryMutation {
208
208
  relations: ['domain', 'warehouse']
209
209
  });
210
210
  if (!toLocation)
211
- throw new Error(`To location doesn't exists`);
211
+ throw new Error(context.t(`error.To_location_does_not_exists`));
212
212
  if (qty < 0)
213
213
  throw new Error(`Invalid quantity`);
214
214
  // 2. search for related inventory
@@ -252,8 +252,8 @@ let InventoryMutation = class InventoryMutation {
252
252
  newInventory.lockedQty = 0;
253
253
  newInventory.uomValue = transferUomValue;
254
254
  newInventory.lockedUomValue = 0;
255
- await transactionInventory.transactionInventory(Object.assign(Object.assign({}, inventory), { qty: inventory.qty - transferQty, uomValue: inventory.uomValue - transferUomValue }), null, -transferQty, -transferUomValue, constants_1.INVENTORY_TRANSACTION_TYPE.RELOCATE);
256
- await transactionInventory.transactionInventory(newInventory, null, transferQty, transferUomValue, constants_1.INVENTORY_TRANSACTION_TYPE.RELOCATE);
255
+ await transactionInventory.transactionInventory(Object.assign(Object.assign({}, inventory), { qty: inventory.qty - transferQty, uomValue: inventory.uomValue - transferUomValue }), null, -transferQty, -transferUomValue, constants_1.INVENTORY_TRANSACTION_TYPE.RELOCATE, reason || null);
256
+ await transactionInventory.transactionInventory(newInventory, null, transferQty, transferUomValue, constants_1.INVENTORY_TRANSACTION_TYPE.RELOCATE, reason || null);
257
257
  if (sellercraft) {
258
258
  const sellercraftCtrl = new controllers_1.SellercraftController(tx, domain, user);
259
259
  await sellercraftCtrl.updateSellercraftStock(sellercraft, inventory);
@@ -267,12 +267,12 @@ let InventoryMutation = class InventoryMutation {
267
267
  inventory.updater = user;
268
268
  inventory.cartonId = cartonId;
269
269
  let isEmptyLocation = await tx.getRepository(inventory_1.Inventory).find({
270
- where: { location: fromLocation }
270
+ where: { location: { id: fromLocation.id } }
271
271
  });
272
272
  if ((isEmptyLocation.length = 1)) {
273
273
  await tx.getRepository(location_1.Location).save(Object.assign(Object.assign({}, fromLocation), { status: constants_1.LOCATION_STATUS.EMPTY }));
274
274
  }
275
- await transactionInventory.transactionInventory(inventory, null, 0, 0, constants_1.INVENTORY_TRANSACTION_TYPE.RELOCATE);
275
+ await transactionInventory.transactionInventory(inventory, null, 0, 0, constants_1.INVENTORY_TRANSACTION_TYPE.RELOCATE, reason || null);
276
276
  if (sellercraft) {
277
277
  const sellercraftCtrl = new controllers_1.SellercraftController(tx, domain, user);
278
278
  await sellercraftCtrl.updateSellercraftStock(sellercraft, inventory);
@@ -292,6 +292,13 @@ let InventoryMutation = class InventoryMutation {
292
292
  await partialTransferFunc(inventory, qty, fromLocation, toLocation, cartonId, palletId, context);
293
293
  }
294
294
  else {
295
+ if (!palletId) {
296
+ palletId = await (0, id_rule_base_1.generateId)({
297
+ domain: domain,
298
+ type: constants_1.RULE_TYPE.LOT_NUMBER_ID,
299
+ seed: { date: utils_1.DateGenerator.generateDate() }
300
+ });
301
+ }
295
302
  await partialTransferFunc(inventory, qty, fromLocation, toLocation, null, palletId, context);
296
303
  }
297
304
  return true;
@@ -368,9 +375,10 @@ tslib_1.__decorate([
368
375
  tslib_1.__param(3, (0, type_graphql_1.Arg)('fromLocationName')),
369
376
  tslib_1.__param(4, (0, type_graphql_1.Arg)('toLocationName')),
370
377
  tslib_1.__param(5, (0, type_graphql_1.Arg)('qty')),
371
- tslib_1.__param(6, (0, type_graphql_1.Ctx)()),
378
+ tslib_1.__param(6, (0, type_graphql_1.Arg)('reason', { nullable: true })),
379
+ tslib_1.__param(7, (0, type_graphql_1.Ctx)()),
372
380
  tslib_1.__metadata("design:type", Function),
373
- tslib_1.__metadata("design:paramtypes", [String, String, String, String, String, Number, Object]),
381
+ tslib_1.__metadata("design:paramtypes", [String, String, String, String, String, Number, String, Object]),
374
382
  tslib_1.__metadata("design:returntype", Promise)
375
383
  ], InventoryMutation.prototype, "inventoryTransfer", null);
376
384
  InventoryMutation = tslib_1.__decorate([
@@ -1 +1 @@
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;AAGzD,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAItB,AAAN,KAAK,CAAC,eAAe,CACD,SAAuB,EAClC,OAAwB;QAE/B,MAAM,EAAE,EAAE,EAAE,GAAG,OAAO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NP;AAKK;IAHL,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,KAAK,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAA;IAC5B,mBAAA,IAAA,kBAAG,GAAE,CAAA;;;;0DASP;AAKK;IAHL,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;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: { id: domain.id }, 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: { id: domain.id }, name: fromLocationName },\n relations: ['domain', 'warehouse']\n })\n // 1. check toLocation exist\n const toLocation: Location = await tx.getRepository(Location).findOne({\n where: { domain: { id: domain.id }, 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: { id: inventory.bizplace.domain.id }, 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"]}
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;AAGzD,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAItB,AAAN,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;IAKK,AAAN,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,EAAE,EAAE,QAAQ,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC;aAC3D,QAAQ,CAAC,+BAA+B,EAAE,EAAE,UAAU,EAAE,KAAK,CA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A,IAAA,kBAAG,GAAE,CAAA;;;;0DASP;AAKK;IAHL,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,EAAC,QAAQ,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAA;IACjC,mBAAA,IAAA,kBAAG,GAAE,CAAA;;;;0DA2JP;AA1eU,iBAAiB;IAD7B,IAAA,uBAAQ,EAAC,qBAAS,CAAC;GACP,iBAAiB,CA2e7B;AA3eY,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: { id: domain.id }, 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 inventory,\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 inventory,\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 @Arg('reason', { nullable: true }) reason: string,\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: { id: domain.id }, name: fromLocationName },\n relations: ['domain', 'warehouse']\n })\n // 1. check toLocation exist\n const toLocation: Location = await tx.getRepository(Location).findOne({\n where: { domain: { id: domain.id }, name: toLocationName },\n relations: ['domain', 'warehouse']\n })\n if (!toLocation) throw new Error(context.t(`error.To_location_does_not_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: { id: inventory.bizplace.domain.id }, 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 reason || null\n )\n\n await transactionInventory.transactionInventory(\n newInventory,\n null,\n transferQty,\n transferUomValue,\n INVENTORY_TRANSACTION_TYPE.RELOCATE,\n reason || null\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: { id: fromLocation.id } }\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(\n inventory,\n null,\n 0,\n 0,\n INVENTORY_TRANSACTION_TYPE.RELOCATE,\n reason || null\n )\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 if (!palletId) {\n palletId = await generateId({\n domain: domain,\n type: RULE_TYPE.LOT_NUMBER_ID,\n seed: { date: DateGenerator.generateDate() }\n })\n }\n await partialTransferFunc(inventory, qty, fromLocation, toLocation, null, palletId, context)\n }\n\n return true\n }\n}\n"]}
@@ -130,6 +130,13 @@ let InventoryQuery = class InventoryQuery {
130
130
  relations: ['domain', 'bizplace', 'product', 'location', 'warehouse', 'creator', 'updater']
131
131
  });
132
132
  }
133
+ async inventoryById(id, context) {
134
+ const { domain } = context.state;
135
+ return await (0, shell_1.getRepository)(inventory_1.Inventory).findOne({
136
+ where: { domain: { id: domain.id }, id },
137
+ relations: ['domain', 'bizplace', 'product', 'location', 'warehouse', 'creator', 'updater']
138
+ });
139
+ }
133
140
  async inventoryByPallet(palletId, context) {
134
141
  const { domain } = context.state;
135
142
  return await (0, shell_1.getRepository)(inventory_1.Inventory).findOne({
@@ -168,7 +175,7 @@ let InventoryQuery = class InventoryQuery {
168
175
  .addSelect('i.product_quality', 'productQuality')
169
176
  .addSelect('i.packing_type', 'packingType')
170
177
  .addSelect('COALESCE(SUM(i.qty), 0)', 'qty')
171
- .addSelect('COALESCE(SUM(i.locked_qty), 0)', 'lockQty')
178
+ .addSelect('COALESCE(SUM(i.locked_qty), 0)', 'lockedQty')
172
179
  .addSelect('COALESCE(SUM(i.uom_value), 0)', 'uomValue')
173
180
  .addSelect('COALESCE(SUM(i.locked_uom_value), 0)', 'lockedUomValue')
174
181
  .innerJoin('i.product', 'product', 'i.product_id = product.id')
@@ -870,6 +877,15 @@ tslib_1.__decorate([
870
877
  tslib_1.__metadata("design:paramtypes", [String, Object]),
871
878
  tslib_1.__metadata("design:returntype", Promise)
872
879
  ], InventoryQuery.prototype, "inventory", null);
880
+ tslib_1.__decorate([
881
+ (0, type_graphql_1.Directive)('@privilege(category: "inventory", privilege: "query", domainOwnerGranted: true)'),
882
+ (0, type_graphql_1.Query)(returns => inventory_1.Inventory),
883
+ tslib_1.__param(0, (0, type_graphql_1.Arg)('id')),
884
+ tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
885
+ tslib_1.__metadata("design:type", Function),
886
+ tslib_1.__metadata("design:paramtypes", [String, Object]),
887
+ tslib_1.__metadata("design:returntype", Promise)
888
+ ], InventoryQuery.prototype, "inventoryById", null);
873
889
  tslib_1.__decorate([
874
890
  (0, type_graphql_1.Directive)('@privilege(category: "inventory", privilege: "query", domainOwnerGranted: true)'),
875
891
  (0, type_graphql_1.Query)(returns => inventory_1.Inventory),