@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
@@ -1,5 +1,4 @@
1
1
  "use strict";
2
- var _a, _b, _c, _d, _e;
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
4
3
  exports.inventoriesByStrategy = exports.InventoryQuery = void 0;
5
4
  const tslib_1 = require("tslib");
@@ -7,6 +6,7 @@ const type_graphql_1 = require("type-graphql");
7
6
  const typeorm_1 = require("typeorm");
8
7
  const auth_base_1 = require("@things-factory/auth-base");
9
8
  const biz_base_1 = require("@things-factory/biz-base");
9
+ const env_1 = require("@things-factory/env");
10
10
  const product_base_1 = require("@things-factory/product-base");
11
11
  const setting_base_1 = require("@things-factory/setting-base");
12
12
  const shell_1 = require("@things-factory/shell");
@@ -15,14 +15,27 @@ const inventory_change_1 = require("../inventory-change/inventory-change");
15
15
  const inventory_1 = require("./inventory");
16
16
  const inventory_types_1 = require("./inventory-types");
17
17
  let InventoryQuery = class InventoryQuery {
18
- async inventories(context, filters, pagination, sortings, locationSortingRules) {
19
- var _a, _b;
18
+ /**
19
+ * Combined single query resolver to perform extraction of data with or without pagination
20
+ * @param context
21
+ * @param filters
22
+ * @param pagination
23
+ * @param sortings
24
+ * @param locationSortingRules
25
+ * @param exportItem
26
+ * @returns
27
+ */
28
+ async inventories(context, filters, pagination, sortings, locationSortingRules, exportItem) {
20
29
  const { domain, user, tx } = context.state;
30
+ const { page, limit } = pagination || {};
21
31
  try {
22
- const productFilters = filters.find(x => x.name == 'product_info');
23
- filters = filters.filter(x => x.name != 'product_info');
32
+ //Define special filters
33
+ const productFilters = filters.find((filter) => filter.name == 'productInfo');
34
+ const remainOnlyParam = filters.find((filter) => filter.name == 'remainOnly');
35
+ const bizplace = filters.find((filter) => filter.name === 'bizplace');
36
+ filters = filters.filter(x => ['productInfo', 'remainOnly'].indexOf(x.name) < 0);
24
37
  const params = { filters, pagination };
25
- if (!params.filters.find((filter) => filter.name === 'bizplace')) {
38
+ if (!bizplace) {
26
39
  params.filters.push({
27
40
  name: 'bizplace',
28
41
  operator: 'in',
@@ -30,38 +43,37 @@ let InventoryQuery = class InventoryQuery {
30
43
  relation: true
31
44
  });
32
45
  }
33
- const remainOnlyParam = (_a = params === null || params === void 0 ? void 0 : params.filters) === null || _a === void 0 ? void 0 : _a.find((f) => f.name === 'remainOnly');
34
- let remainOnly = false;
35
- if (typeof (remainOnlyParam === null || remainOnlyParam === void 0 ? void 0 : remainOnlyParam.value) !== 'undefined') {
36
- remainOnly = remainOnlyParam.value;
37
- params.filters = params.filters.filter((f) => f.name !== 'remainOnly');
38
- }
39
- const unlockOnlyParam = (_b = params === null || params === void 0 ? void 0 : params.filters) === null || _b === void 0 ? void 0 : _b.find((f) => f.name === 'unlockOnly');
40
- let unlockOnly = false;
41
- if (typeof (unlockOnlyParam === null || unlockOnlyParam === void 0 ? void 0 : unlockOnlyParam.value) !== 'undefined') {
42
- unlockOnly = unlockOnlyParam.value;
43
- params.filters = params.filters.filter((f) => f.name !== 'unlockOnly');
44
- }
45
- const qb = (0, typeorm_1.getRepository)(inventory_1.Inventory).createQueryBuilder('iv');
46
+ const remainOnly = (remainOnlyParam === null || remainOnlyParam === void 0 ? void 0 : remainOnlyParam.value) || false;
47
+ // Define Query data
48
+ const qb = tx.getRepository(inventory_1.Inventory).createQueryBuilder('inventory');
46
49
  (0, shell_1.buildQuery)(qb, params, context, {
47
50
  searchables: ['warehouse', 'product', 'batchId', 'location', 'palletId']
48
51
  });
49
- qb.leftJoinAndSelect('iv.bizplace', 'bizplace')
50
- .leftJoinAndSelect('iv.product', 'product')
51
- .leftJoinAndSelect('iv.warehouse', 'warehouse')
52
- .leftJoinAndSelect('iv.location', 'location')
53
- .leftJoin('iv.inventoryItems', 'ivi')
54
- .loadRelationCountAndMap('iv.inventoryItemCount', 'iv.inventoryItems', 'ivic', qb => qb.andWhere('ivic.status = :ivicStatus', {
55
- ivicStatus: constants_1.INVENTORY_STATUS.STORED
56
- }));
52
+ qb.leftJoinAndSelect('inventory.bizplace', 'bizplace')
53
+ .leftJoinAndSelect('inventory.product', 'product')
54
+ .leftJoinAndSelect('product.productDetails', 'productDetail', 'productDetail.id = inventory.product_detail_id')
55
+ .leftJoinAndSelect('inventory.warehouse', 'warehouse')
56
+ .leftJoinAndSelect('inventory.location', 'location')
57
+ .leftJoinAndSelect('inventory.creator', 'creator')
58
+ .leftJoinAndSelect('inventory.updater', 'updater')
59
+ // To get aggregated serial number in csv and total number of stored serial number
60
+ .leftJoinAndSelect(subQuery => {
61
+ return subQuery
62
+ .select('inventoryItems.inventory_id', 'inventory_item_inventory_id')
63
+ .addSelect(`SUM(case when "inventoryItems"."status" = 'STORED' then 1 else 0 end)`, 'inventory_item_count')
64
+ .addSelect(`string_agg(inventoryItems.serial_number, ', ')`, 'serial_numbers')
65
+ .from('inventory_items', 'inventoryItems')
66
+ .where(`inventoryItems.domain_id = :domainId`, { domainId: domain.id })
67
+ .andWhere(`inventoryItems.status = :ivicStatus`, { ivicStatus: constants_1.INVENTORY_STATUS.STORED })
68
+ .groupBy('inventoryItems.inventory_id');
69
+ }, 'inventoryItems', '"inventoryItems"."inventory_item_inventory_id" = "inventory"."id"');
70
+ // To get inventory with remaining qty
57
71
  if (remainOnly) {
58
- qb.andWhere('iv.qty > 0')
59
- .andWhere('CASE WHEN iv.lockedQty IS NULL THEN 0 ELSE iv.lockedQty END >= 0')
60
- .andWhere('iv.qty - CASE WHEN iv.lockedQty IS NULL THEN 0 ELSE iv.lockedQty END > 0');
61
- }
62
- if (unlockOnly) {
63
- qb.andWhere('CASE WHEN iv.lockedQty IS NULL THEN 0 ELSE iv.lockedQty END = 0');
72
+ qb.andWhere('inventory.qty > 0')
73
+ .andWhere('CASE WHEN inventory.lockedQty IS NULL THEN 0 ELSE inventory.lockedQty END >= 0')
74
+ .andWhere('inventory.qty - CASE WHEN inventory.lockedQty IS NULL THEN 0 ELSE inventory.lockedQty END > 0');
64
75
  }
76
+ // Filter based on multiple product parameters and allow to search in csv format
65
77
  if (productFilters) {
66
78
  let productFilterValue = `%${productFilters.value.toLowerCase()}%`;
67
79
  qb.andWhere(qb => {
@@ -69,7 +81,7 @@ let InventoryQuery = class InventoryQuery {
69
81
  .subQuery()
70
82
  .select()
71
83
  .from(product_base_1.Product, `products`)
72
- .where(`products.id = iv.product_id`)
84
+ .where(`products.id = Inventory.product_id`) // @chrislim Does the uppercase I in Inventory affect? I can see the rest are in lowercase i
73
85
  .andWhere(new typeorm_1.Brackets(qb => {
74
86
  qb.where('Lower(products.sku) LIKE :productInfo', { productInfo: productFilterValue })
75
87
  .orWhere('Lower(products.name) LIKE :productInfo', { productInfo: productFilterValue })
@@ -80,42 +92,34 @@ let InventoryQuery = class InventoryQuery {
80
92
  return `EXISTS ${subQuery}`;
81
93
  });
82
94
  }
95
+ // Apply sorting based on child data
83
96
  if ((sortings === null || sortings === void 0 ? void 0 : sortings.length) !== 0) {
84
97
  const arrChildSortData = ['bizplace', 'product', 'location', 'warehouse', 'zone'];
85
- const sort = (sortings || []).reduce((acc, sort) => (Object.assign(Object.assign({}, acc), { [arrChildSortData.indexOf(sort.name) >= 0 ? sort.name + '.name' : 'iv.' + sort.name]: sort.desc
98
+ const sort = (sortings || []).reduce((acc, sort) => (Object.assign(Object.assign({}, acc), { [arrChildSortData.indexOf(sort.name) >= 0 ? sort.name + '.name' : 'inventory.' + sort.name]: sort.desc
86
99
  ? 'DESC'
87
100
  : 'ASC' })), {});
88
101
  qb.orderBy(sort);
89
102
  }
90
103
  if ((locationSortingRules === null || locationSortingRules === void 0 ? void 0 : locationSortingRules.length) > 0) {
91
- locationSortingRules.forEach((rule) => {
104
+ locationSortingRules.forEach(rule => {
92
105
  qb.addOrderBy(`location.${rule.name}`, rule.desc ? 'DESC' : 'ASC');
93
106
  });
94
107
  }
95
- let [items, total] = await qb.getManyAndCount();
96
- items = await Promise.all(items.map(async (item) => {
97
- var _a;
98
- let [productDetails, inventoryItems] = await Promise.all([
99
- (0, typeorm_1.getRepository)(product_base_1.ProductDetail).find({
100
- where: {
101
- product: item.product.id,
102
- packingType: item.packingType,
103
- packingSize: item.packingSize
104
- }
105
- }),
106
- tx.query(`
107
- SELECT string_agg(ii.serial_number, ', ') AS "serialNumbers"
108
- FROM inventory_items ii
109
- WHERE ii.inventory_id = $1
110
- GROUP BY ii.inventory_id
111
- `, [item.id])
112
- ]);
113
- item.product['productDetails'] = productDetails;
114
- return Object.assign(Object.assign({}, item), { remainQty: item.qty - (item.lockedQty ? item.lockedQty : 0), remainUomValue: item.uomValue - (item.lockedUomValue ? item.lockedUomValue : 0), serialNumbers: (_a = inventoryItems[0]) === null || _a === void 0 ? void 0 : _a.serialNumbers });
115
- }));
116
- return { items, total };
108
+ // Fetch all row for exporting
109
+ if (exportItem != true && page && limit) {
110
+ qb.offset((page - 1) * limit).limit(limit);
111
+ }
112
+ let items = (await qb.getRawMany()).map(item => {
113
+ return Object.assign(Object.assign({}, new inventory_1.Inventory(item)), { serialNumbers: item.serial_numbers });
114
+ });
115
+ let total = await qb.getCount();
116
+ return {
117
+ items,
118
+ total
119
+ };
117
120
  }
118
121
  catch (error) {
122
+ env_1.logger.error(`inventory-query[inventories]: ${error}`);
119
123
  throw error;
120
124
  }
121
125
  }
@@ -129,7 +133,7 @@ let InventoryQuery = class InventoryQuery {
129
133
  async inventoryByPallet(palletId, context) {
130
134
  const { domain } = context.state;
131
135
  return await (0, typeorm_1.getRepository)(inventory_1.Inventory).findOne({
132
- where: { domain, palletId, status: (0, typeorm_1.Not)((0, typeorm_1.Equal)(constants_1.INVENTORY_STATUS.TERMINATED)) },
136
+ where: { domain: { id: domain.id }, palletId, status: (0, typeorm_1.Not)((0, typeorm_1.Equal)(constants_1.INVENTORY_STATUS.TERMINATED)) },
133
137
  relations: ['domain', 'bizplace', 'product', 'location', 'warehouse', 'creator', 'updater']
134
138
  });
135
139
  }
@@ -142,10 +146,13 @@ let InventoryQuery = class InventoryQuery {
142
146
  const limit = params.pagination.limit;
143
147
  let bizplaceFilter = params.filters.find(filter => filter.name == 'bizplace');
144
148
  let productFilter = params.filters.find(filter => filter.name == 'product');
145
- let productTypeFilter = params.filters.find(filter => filter.name == 'type');
149
+ let packingTypeFilter = params.filters.find(filter => filter.name == 'packingType');
146
150
  let availableStockFilter = params.filters.find(filter => filter.name == 'availableStock');
147
151
  let lowStockFilter = params.filters.find(filter => filter.name == 'lowStock');
148
152
  let overStockFilter = params.filters.find(filter => filter.name == 'overStock');
153
+ let quarantineStockFilter = params.filters.find(filter => filter.name == 'quarantineStock');
154
+ let reserveStockFilter = params.filters.find(filter => filter.name == 'reserveStock');
155
+ let productTypeFilter = params.filters.find(filter => filter.name == 'type');
149
156
  if (bizplaceFilter) {
150
157
  const bizplaceQueryBuilder = (0, typeorm_1.getRepository)(biz_base_1.Bizplace).createQueryBuilder('b');
151
158
  bizplaceQueryBuilder
@@ -203,27 +210,96 @@ let InventoryQuery = class InventoryQuery {
203
210
  Lower("Product"."type") LIKE ANY(ARRAY[${productTypeValue}])
204
211
  )`;
205
212
  }
213
+ let qtyStockQuery = '';
206
214
  let availableStockQuery = '';
215
+ if (reserveStockFilter === null || reserveStockFilter === void 0 ? void 0 : reserveStockFilter.value) {
216
+ qtyStockQuery += `\nAND SUM("reserveQty") > 0`;
217
+ }
218
+ if (quarantineStockFilter === null || quarantineStockFilter === void 0 ? void 0 : quarantineStockFilter.value) {
219
+ qtyStockQuery += `\nAND SUM("quarantineQty") > 0`;
220
+ }
221
+ if (availableStockFilter === null || availableStockFilter === void 0 ? void 0 : availableStockFilter.value) {
222
+ qtyStockQuery += ` AND SUM("availableQty") > 0`;
223
+ }
207
224
  if (availableStockFilter === null || availableStockFilter === void 0 ? void 0 : availableStockFilter.value) {
208
225
  availableStockQuery = ` AND SUM("Inventory"."qty") > 0`;
209
226
  }
227
+ if ((availableStockFilter === null || availableStockFilter === void 0 ? void 0 : availableStockFilter.value) && (quarantineStockFilter === null || quarantineStockFilter === void 0 ? void 0 : quarantineStockFilter.value)) {
228
+ qtyStockQuery = '';
229
+ qtyStockQuery += `\nAND (SUM("availableQty") > 0 \n OR SUM("quarantineQty") > 0)`;
230
+ }
231
+ if ((availableStockFilter === null || availableStockFilter === void 0 ? void 0 : availableStockFilter.value) && (reserveStockFilter === null || reserveStockFilter === void 0 ? void 0 : reserveStockFilter.value)) {
232
+ qtyStockQuery = '';
233
+ qtyStockQuery += `\nAND (SUM("availableQty") > 0 \n OR SUM("reserveQty") > 0)`;
234
+ }
235
+ if ((quarantineStockFilter === null || quarantineStockFilter === void 0 ? void 0 : quarantineStockFilter.value) && (reserveStockFilter === null || reserveStockFilter === void 0 ? void 0 : reserveStockFilter.value)) {
236
+ qtyStockQuery = '';
237
+ qtyStockQuery += `\nAND (SUM("quarantineQty") > 0 \n OR SUM("reserveQty") > 0)`;
238
+ }
239
+ let inventoryQuery = '';
240
+ if (packingTypeFilter) {
241
+ let packingTypeValue = packingTypeFilter.value
242
+ .toLowerCase()
243
+ .split(',')
244
+ .map(prod => {
245
+ return "'%" + prod.trim().replace(/'/g, "''") + "%'";
246
+ })
247
+ .join(',');
248
+ inventoryQuery =
249
+ inventoryQuery +
250
+ ` AND (
251
+ Lower("Inventory"."packing_type") LIKE ANY(ARRAY[${packingTypeValue}])
252
+ )`;
253
+ }
210
254
  let thresholdQuery = '';
211
- if (lowStockFilter === null || lowStockFilter === void 0 ? void 0 : lowStockFilter.value) {
212
- thresholdQuery = `AND COALESCE("ProductDetailBizplaceSetting"."min_qty", "Product"."min_qty",0) > SUM("Inventory"."qty")`;
255
+ if ((lowStockFilter === null || lowStockFilter === void 0 ? void 0 : lowStockFilter.value) && (overStockFilter === null || overStockFilter === void 0 ? void 0 : overStockFilter.value)) {
256
+ throw new Error('invalid filter combination');
213
257
  }
214
- if (overStockFilter === null || overStockFilter === void 0 ? void 0 : overStockFilter.value) {
215
- thresholdQuery = `AND COALESCE("ProductDetailBizplaceSetting"."max_qty", "Product"."max_qty",0) > 0 AND
216
- COALESCE("ProductDetailBizplaceSetting"."max_qty", "Product"."max_qty",0) < SUM("Inventory"."qty")`;
258
+ else if ((lowStockFilter === null || lowStockFilter === void 0 ? void 0 : lowStockFilter.value) && !(overStockFilter === null || overStockFilter === void 0 ? void 0 : overStockFilter.value)) {
259
+ thresholdQuery = `AND SUM(COALESCE("minQty", 0)) > SUM("availableQty")`;
260
+ }
261
+ else if (!(lowStockFilter === null || lowStockFilter === void 0 ? void 0 : lowStockFilter.value) && (overStockFilter === null || overStockFilter === void 0 ? void 0 : overStockFilter.value)) {
262
+ thresholdQuery = `AND SUM(COALESCE("maxQty", 0)) > 0 AND SUM(COALESCE("maxQty", 0)) < SUM("availableQty")`;
217
263
  }
218
264
  await tx.query(`
265
+ CREATE TEMP TABLE order_inventories_by_products AS (
266
+ SELECT "product_id", "packing_type", sum("release_qty") AS "total_release_qty" FROM order_inventories oi
267
+ WHERE "type" = 'RELEASE_OF_GOODS'
268
+ AND "domain_id" = $1
269
+ AND "inventory_id" ISNULL
270
+ AND "status" IN ('PENDING','PENDING_RECEIVE','PENDING_WORKSHEET','READY_TO_PICK'/*, 'PENDING_SPLIT' kiv sebab kalau pending split, ada yang dah assign tapi belum delete*/)
271
+ GROUP BY "product_id", "packing_type"
272
+ )`, [domain.id]);
273
+ await tx.query(`
219
274
  create temp table temp_inv_history AS
220
275
  (
221
276
  SELECT "Product"."id" AS "id", "Product"."sku" AS "sku", "Product"."brand" AS "brand", "Product"."name" AS "name", "Product"."type" AS "type", "Product"."description" AS "description",
277
+ "Inventory"."packing_type" AS "packingType",
222
278
  "Product"."weight" AS "weight", "ProductRef"."id" AS "productRefId",
223
279
  "ProductRef"."description" AS "productRefDesciption", "Bizplace"."id" AS "bizplaceId", "Bizplace"."name" AS "bizplaceName", SUM("Inventory"."qty") AS "qty" ,
224
280
  CASE WHEN SUM("Inventory"."qty") > 0 THEN SUM(COALESCE("Inventory"."unit_cost", 0) * "Inventory"."qty")/ SUM("Inventory"."qty") ELSE 0 END AS "averageUnitCost",
225
281
  COALESCE("ProductDetailBizplaceSetting"."min_qty", "Product"."min_qty",0) AS "minQty",
226
- COALESCE("ProductDetailBizplaceSetting"."max_qty", "Product"."max_qty",0) AS "maxQty"
282
+ COALESCE("ProductDetailBizplaceSetting"."max_qty", "Product"."max_qty",0) AS "maxQty",
283
+ CASE WHEN "Location"."type" NOT IN ('${constants_1.LOCATION_TYPE.QUARANTINE}','${constants_1.LOCATION_TYPE.RESERVE}')
284
+ THEN
285
+ CASE WHEN SUM("Inventory"."qty") > 0
286
+ THEN SUM("Inventory"."qty")-SUM(COALESCE("Inventory"."locked_qty", 0) + COALESCE("OrderInventoriesByProduct"."total_release_qty", 0))
287
+ ELSE 0 END
288
+ ELSE 0 END AS "availableQty",
289
+ SUM(COALESCE("Inventory"."locked_qty", 0) + COALESCE("OrderInventoriesByProduct"."total_release_qty", 0)) AS "releaseQty",
290
+ CASE WHEN "Location"."type" = '${constants_1.LOCATION_TYPE.QUARANTINE}'
291
+ THEN
292
+ CASE WHEN SUM("Inventory"."qty") > 0
293
+ THEN SUM("Inventory"."qty")-SUM(COALESCE("Inventory"."locked_qty", 0) + COALESCE("OrderInventoriesByProduct"."total_release_qty", 0))
294
+ ELSE 0 END
295
+ ELSE 0 END AS "quarantineQty",
296
+ CASE WHEN "Location"."type" = '${constants_1.LOCATION_TYPE.RESERVE}'
297
+ THEN
298
+ CASE WHEN SUM("Inventory"."qty") > 0
299
+ THEN SUM("Inventory"."qty")-SUM(COALESCE("Inventory"."locked_qty", 0) + COALESCE("OrderInventoriesByProduct"."total_release_qty", 0))
300
+ ELSE 0 END
301
+ ELSE 0 END AS "reserveQty",
302
+ CASE WHEN "Location"."type" = '${constants_1.LOCATION_TYPE.BIN}' THEN SUM("Inventory"."qty") ELSE 0 END AS "binQty"
227
303
  FROM "inventories" "Inventory"
228
304
  LEFT JOIN "products" "Product" ON "Product"."id"="Inventory"."product_id"
229
305
  LEFT JOIN "product_details" "ProductDetails" ON "ProductDetails"."product_id" = "Product"."id"
@@ -232,23 +308,43 @@ let InventoryQuery = class InventoryQuery {
232
308
  AND "ProductDetailBizplaceSetting"."domain_id" = "Inventory"."domain_id"
233
309
  LEFT JOIN "products" "ProductRef" ON "ProductRef"."id"="Product"."product_ref_id"
234
310
  INNER JOIN "bizplaces" "Bizplace" ON "Bizplace"."id"="Inventory"."bizplace_id"
311
+ INNER JOIN "locations" "Location" ON "Location"."id" = "Inventory"."location_id"
312
+ LEFT JOIN "order_inventories_by_products" "OrderInventoriesByProduct"
313
+ ON "OrderInventoriesByProduct"."product_id" = "Inventory"."product_id"
314
+ AND "OrderInventoriesByProduct"."packing_type" = "Inventory"."packing_type"
235
315
  WHERE "Inventory"."qty" >= 0
236
316
  AND "Inventory"."status" <> 'MISSING'
237
317
  AND "Inventory"."domain_id" = $1
238
318
  ${bizplaceQuery}
239
319
  ${productQuery}
240
- GROUP BY "Product"."id", "ProductRef"."id", "Bizplace"."id", "ProductDetailBizplaceSetting"."id"
320
+ GROUP BY "Product"."id", "Bizplace"."id", "ProductDetailBizplaceSetting"."id", "Inventory"."packing_type", "Location"."type", "ProductRef"."id"
241
321
  HAVING 1 = 1
242
322
  ${availableStockQuery}
243
- ${thresholdQuery}
244
323
  )`, [domain.id]);
324
+ await tx.query(`
325
+ CREATE TEMP TABLE grouped_inventories_product AS (
326
+ SELECT "id", "sku", "brand", "name", "description",
327
+ "packingType", "bizplaceId", "bizplaceName", sum("averageUnitCost") AS "averageUnitCost",
328
+ sum("minQty") AS "minQty", sum("maxQty") AS "maxQty",
329
+ sum("availableQty") AS "availableQty",
330
+ sum("quarantineQty") AS "quarantineQty",
331
+ sum("reserveQty") AS "reserveQty",
332
+ sum("releaseQty") AS "releaseQty",
333
+ sum("availableQty" + "quarantineQty" + "releaseQty" + "reserveQty" - "binQty") AS "warehouseQty"
334
+ FROM temp_inv_history
335
+ GROUP BY "id", "sku", "brand", "name", "description", "packingType", "bizplaceId", "bizplaceName"
336
+ HAVING 1=1
337
+ ${qtyStockQuery}
338
+ ${thresholdQuery}
339
+ )
340
+ `);
245
341
  const results = await tx.query(`
246
- SELECT * FROM temp_inv_history
247
- ORDER BY "bizplaceName", "sku"
342
+ SELECT * FROM grouped_inventories_product
343
+ ORDER BY "bizplaceName", "sku"
248
344
  OFFSET $1 LIMIT $2
249
345
  `, [(page - 1) * limit, limit]);
250
- const total = await tx.query(`SELECT COUNT(*) FROM temp_inv_history`);
251
- tx.query(`drop table temp_inv_history`);
346
+ const total = await tx.query(`SELECT COUNT(*) FROM grouped_inventories_product`);
347
+ await tx.query(`drop table temp_inv_history, order_inventories_by_products, grouped_inventories_product`);
252
348
  return {
253
349
  items: results.map((item) => {
254
350
  return {
@@ -258,15 +354,20 @@ let InventoryQuery = class InventoryQuery {
258
354
  sku: item.sku,
259
355
  brand: item.brand,
260
356
  description: item.description,
261
- type: item.type,
262
- weight: item.weight,
263
- productRefId: item.productRefId,
264
- bizplaceId: item.bizplaceId,
265
357
  minQty: item.minQty,
266
358
  maxQty: item.maxQty
267
359
  },
360
+ bizplace: {
361
+ id: item.bizplaceId,
362
+ name: item.bizplaceName
363
+ },
364
+ packingType: item.packingType,
268
365
  averageUnitCost: item.averageUnitCost,
269
- qty: item.qty
366
+ availableQty: item.availableQty,
367
+ releaseQty: item.releaseQty,
368
+ quarantineQty: item.quarantineQty,
369
+ reserveQty: item.reserveQty,
370
+ warehouseQty: item.warehouseQty
270
371
  };
271
372
  }),
272
373
  total: total[0].count
@@ -279,7 +380,7 @@ let InventoryQuery = class InventoryQuery {
279
380
  async inventoriesByStrategy(context, worksheetId, batchId, productName, productSku, packingType, packingSize, uom, pickingStrategy, locationSortingRules, bizplaceId) {
280
381
  const { domain, tx } = context.state;
281
382
  const inventoryAssignmentSetting = await tx.getRepository(setting_base_1.Setting).findOne({
282
- where: { domain, name: 'rule-for-inventory-assignment' }
383
+ where: { domain: { id: domain.id }, name: 'rule-for-inventory-assignment' }
283
384
  });
284
385
  if (!locationSortingRules && inventoryAssignmentSetting) {
285
386
  locationSortingRules = [];
@@ -306,11 +407,11 @@ let InventoryQuery = class InventoryQuery {
306
407
  const { tx } = context.state;
307
408
  const invRepo = tx.getRepository(inventory_1.Inventory);
308
409
  const invA = await invRepo.findOne({
309
- where: { domain: context.state.domain, palletId: palletA, status: constants_1.INVENTORY_STATUS.STORED },
410
+ where: { domain: { id: context.state.domain.id }, palletId: palletA, status: constants_1.INVENTORY_STATUS.STORED },
310
411
  relations: ['product']
311
412
  });
312
413
  const invB = await invRepo.findOne({
313
- where: { domain: context.state.domain, palletId: palletB, status: constants_1.INVENTORY_STATUS.STORED },
414
+ where: { domain: { id: context.state.domain.id }, palletId: palletB, status: constants_1.INVENTORY_STATUS.STORED },
314
415
  relations: ['product']
315
416
  });
316
417
  return ((invA === null || invA === void 0 ? void 0 : invA.batchId) === (invB === null || invB === void 0 ? void 0 : invB.batchId) &&
@@ -321,7 +422,12 @@ let InventoryQuery = class InventoryQuery {
321
422
  var _a, _b;
322
423
  const invRepo = (0, typeorm_1.getRepository)(inventory_1.Inventory);
323
424
  const invA = await invRepo.findOne({
324
- where: { domain: context.state.domain, palletId: palletA, cartonId: cartonA, status: constants_1.INVENTORY_STATUS.STORED },
425
+ where: {
426
+ domain: { id: context.state.domain.id },
427
+ palletId: palletA,
428
+ cartonId: cartonA,
429
+ status: constants_1.INVENTORY_STATUS.STORED
430
+ },
325
431
  relations: ['product']
326
432
  });
327
433
  const invB = await invRepo.findOne({
@@ -344,7 +450,7 @@ let InventoryQuery = class InventoryQuery {
344
450
  const invRepo = (0, typeorm_1.getRepository)(inventory_1.Inventory);
345
451
  const bizRepo = (0, typeorm_1.getRepository)(biz_base_1.Bizplace);
346
452
  const inventory = await invRepo.findOne({
347
- where: { domain: context.state.domain, palletId, status: constants_1.INVENTORY_STATUS.STORED },
453
+ where: { domain: { id: context.state.domain.id }, palletId, status: constants_1.INVENTORY_STATUS.STORED },
348
454
  relations: ['bizplace']
349
455
  });
350
456
  if (!inventory)
@@ -475,99 +581,6 @@ let InventoryQuery = class InventoryQuery {
475
581
  /** ************************ **/
476
582
  return { bundleGroup, bundleSetting };
477
583
  }
478
- async inventoriesForExport(context, filters, pagination, sortings, locationSortingRules) {
479
- var _a, _b;
480
- const { domain, user } = context.state;
481
- const { page, limit } = pagination;
482
- try {
483
- const productFilters = filters.find(x => x.name == 'product_info');
484
- filters = filters.filter(x => x.name != 'product_info');
485
- const params = { filters, pagination };
486
- if (!params.filters.find((filter) => filter.name === 'bizplace')) {
487
- throw new Error('Please select a customer for export.');
488
- }
489
- const remainOnlyParam = (_a = params === null || params === void 0 ? void 0 : params.filters) === null || _a === void 0 ? void 0 : _a.find((f) => f.name === 'remainOnly');
490
- let remainOnly = false;
491
- if (typeof (remainOnlyParam === null || remainOnlyParam === void 0 ? void 0 : remainOnlyParam.value) !== 'undefined') {
492
- remainOnly = remainOnlyParam.value;
493
- params.filters = params.filters.filter((f) => f.name !== 'remainOnly');
494
- }
495
- const unlockOnlyParam = (_b = params === null || params === void 0 ? void 0 : params.filters) === null || _b === void 0 ? void 0 : _b.find((f) => f.name === 'unlockOnly');
496
- let unlockOnly = false;
497
- if (typeof (unlockOnlyParam === null || unlockOnlyParam === void 0 ? void 0 : unlockOnlyParam.value) !== 'undefined') {
498
- unlockOnly = unlockOnlyParam.value;
499
- params.filters = params.filters.filter((f) => f.name !== 'unlockOnly');
500
- }
501
- const qb = (0, typeorm_1.getRepository)(inventory_1.Inventory).createQueryBuilder('Inventory');
502
- (0, shell_1.buildQuery)(qb, params, context);
503
- qb.leftJoinAndSelect('Inventory.bizplace', 'Bizplace')
504
- .leftJoinAndSelect('Inventory.product', 'Product')
505
- .leftJoinAndSelect('Inventory.warehouse', 'Warehouse')
506
- .leftJoinAndSelect('Inventory.location', 'Location')
507
- .leftJoinAndSelect('Inventory.creator', 'Creator')
508
- .leftJoinAndSelect('Inventory.updater', 'Updater')
509
- .leftJoinAndSelect(subQuery => {
510
- return subQuery
511
- .select('ii.inventory_id', 'inventory_id')
512
- .addSelect(`string_agg(ii.serial_number, ', ')`, 'serial_numbers')
513
- .from('inventory_items', 'ii')
514
- .where(`ii.domain_id = :domainId`, { domainId: domain.id })
515
- .groupBy('ii.inventory_id');
516
- }, 'ii2', 'ii2.inventory_id = Inventory.id');
517
- if (remainOnly) {
518
- qb.andWhere('Inventory.qty > 0')
519
- .andWhere('CASE WHEN Inventory.locked_qty IS NULL THEN 0 ELSE Inventory.locked_qty END >= 0')
520
- .andWhere('Inventory.qty - CASE WHEN Inventory.locked_qty IS NULL THEN 0 ELSE Inventory.locked_qty END > 0');
521
- }
522
- if (unlockOnly) {
523
- qb.andWhere('CASE WHEN Inventory.locked_qty IS NULL THEN 0 ELSE Inventory.locked_qty END = 0');
524
- }
525
- if (productFilters) {
526
- let productFilterValue = `%${productFilters.value.toLowerCase()}%`;
527
- qb.andWhere(qb => {
528
- const subQuery = qb
529
- .subQuery()
530
- .select()
531
- .from(product_base_1.Product, `products`)
532
- .where(`products.id = Inventory.product_id`)
533
- .andWhere(new typeorm_1.Brackets(qb => {
534
- qb.where('Lower(products.sku) LIKE :productInfo', { productInfo: productFilterValue })
535
- .orWhere('Lower(products.name) LIKE :productInfo', { productInfo: productFilterValue })
536
- .orWhere('Lower(products.description) LIKE :productInfo', { productInfo: productFilterValue })
537
- .orWhere('Lower(products.brand) LIKE :productInfo', { productInfo: productFilterValue });
538
- }))
539
- .getQuery();
540
- return `EXISTS ${subQuery}`;
541
- });
542
- }
543
- if ((sortings === null || sortings === void 0 ? void 0 : sortings.length) !== 0) {
544
- const arrChildSortData = ['bizplace', 'product', 'location', 'warehouse', 'zone'];
545
- const sort = (sortings || []).reduce((acc, sort) => (Object.assign(Object.assign({}, acc), { [arrChildSortData.indexOf(sort.name) >= 0 ? sort.name + '.name' : 'Inventory.' + sort.name]: sort.desc
546
- ? 'DESC'
547
- : 'ASC' })), {});
548
- qb.orderBy(sort);
549
- }
550
- if ((locationSortingRules === null || locationSortingRules === void 0 ? void 0 : locationSortingRules.length) > 0) {
551
- locationSortingRules.forEach((rule) => {
552
- qb.addOrderBy(`location.${rule.name}`, rule.desc ? 'DESC' : 'ASC');
553
- });
554
- }
555
- let items = await qb
556
- .offset((page - 1) * limit)
557
- .limit(limit)
558
- .getRawMany();
559
- let total = await qb.getCount();
560
- return {
561
- items: items.map(item => {
562
- return Object.assign(Object.assign({}, new inventory_1.Inventory(item)), { serialNumbers: item.serial_numbers });
563
- }),
564
- total
565
- };
566
- }
567
- catch (error) {
568
- throw error;
569
- }
570
- }
571
584
  async inventoriesGroupByProduct(params, context) {
572
585
  try {
573
586
  const { domain, user, tx } = context.state;
@@ -719,13 +732,13 @@ let InventoryQuery = class InventoryQuery {
719
732
  }
720
733
  }
721
734
  async domain(inventory) {
722
- return await (0, typeorm_1.getRepository)(shell_1.Domain).findOne(inventory.domainId);
735
+ return await (0, typeorm_1.getRepository)(shell_1.Domain).findOneBy({ id: inventory.domainId });
723
736
  }
724
737
  async updater(inventory) {
725
- return await (0, typeorm_1.getRepository)(auth_base_1.User).findOne(inventory.updaterId);
738
+ return await (0, typeorm_1.getRepository)(auth_base_1.User).findOneBy({ id: inventory.updaterId });
726
739
  }
727
740
  async creator(inventory) {
728
- return await (0, typeorm_1.getRepository)(auth_base_1.User).findOne(inventory.creatorId);
741
+ return await (0, typeorm_1.getRepository)(auth_base_1.User).findOneBy({ id: inventory.creatorId });
729
742
  }
730
743
  /*
731
744
  move changeCount to @FieldResolver so that system don't have
@@ -733,7 +746,7 @@ let InventoryQuery = class InventoryQuery {
733
746
  */
734
747
  async changeCount(inventory) {
735
748
  return await (0, typeorm_1.getRepository)(inventory_change_1.InventoryChange).count({
736
- where: { inventory }
749
+ where: { inventory: { id: inventory.id } }
737
750
  });
738
751
  }
739
752
  /*
@@ -776,6 +789,17 @@ let InventoryQuery = class InventoryQuery {
776
789
  `);
777
790
  return ((_a = items[0]) === null || _a === void 0 ? void 0 : _a.arrivalNoticeRefNo) || '';
778
791
  }
792
+ async arrivalNoticeNo(inventory) {
793
+ var _a;
794
+ if (!inventory.refOrderId)
795
+ return '';
796
+ let items = await (0, typeorm_1.getRepository)(inventory_1.Inventory).query(`
797
+ SELECT an.name as "arrivalNoticeNo" FROM arrival_notices an
798
+ WHERE an.id = '${inventory.refOrderId}'
799
+ LIMIT 1
800
+ `);
801
+ return ((_a = items[0]) === null || _a === void 0 ? void 0 : _a.arrivalNoticeNo) || '';
802
+ }
779
803
  };
780
804
  tslib_1.__decorate([
781
805
  (0, type_graphql_1.Directive)('@privilege(category: "inventory", privilege: "query")'),
@@ -786,8 +810,9 @@ tslib_1.__decorate([
786
810
  tslib_1.__param(2, (0, type_graphql_1.Arg)('pagination', type => shell_1.Pagination, { nullable: true })),
787
811
  tslib_1.__param(3, (0, type_graphql_1.Arg)('sortings', type => [shell_1.Sorting], { nullable: true })),
788
812
  tslib_1.__param(4, (0, type_graphql_1.Arg)('locationSortingRules', type => [shell_1.Sorting], { nullable: true })),
813
+ tslib_1.__param(5, (0, type_graphql_1.Arg)('exportItem', type => Boolean, { nullable: true })),
789
814
  tslib_1.__metadata("design:type", Function),
790
- tslib_1.__metadata("design:paramtypes", [Object, Array, typeof (_a = typeof shell_1.Pagination !== "undefined" && shell_1.Pagination) === "function" ? _a : Object, Array, Array]),
815
+ tslib_1.__metadata("design:paramtypes", [Object, Array, shell_1.Pagination, Array, Array, Boolean]),
791
816
  tslib_1.__metadata("design:returntype", Promise)
792
817
  ], InventoryQuery.prototype, "inventories", null);
793
818
  tslib_1.__decorate([
@@ -815,7 +840,7 @@ tslib_1.__decorate([
815
840
  tslib_1.__param(0, (0, type_graphql_1.Args)()),
816
841
  tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
817
842
  tslib_1.__metadata("design:type", Function),
818
- tslib_1.__metadata("design:paramtypes", [typeof (_b = typeof shell_1.ListParam !== "undefined" && shell_1.ListParam) === "function" ? _b : Object, Object]),
843
+ tslib_1.__metadata("design:paramtypes", [shell_1.ListParam, Object]),
819
844
  tslib_1.__metadata("design:returntype", Promise)
820
845
  ], InventoryQuery.prototype, "inventoriesByProduct", null);
821
846
  tslib_1.__decorate([
@@ -873,21 +898,9 @@ tslib_1.__decorate([
873
898
  tslib_1.__param(2, (0, type_graphql_1.Arg)('pagination', type => shell_1.Pagination, { nullable: true })),
874
899
  tslib_1.__param(3, (0, type_graphql_1.Arg)('sortings', type => [shell_1.Sorting], { nullable: true })),
875
900
  tslib_1.__metadata("design:type", Function),
876
- tslib_1.__metadata("design:paramtypes", [Object, Array, typeof (_c = typeof shell_1.Pagination !== "undefined" && shell_1.Pagination) === "function" ? _c : Object, Array]),
901
+ tslib_1.__metadata("design:paramtypes", [Object, Array, shell_1.Pagination, Array]),
877
902
  tslib_1.__metadata("design:returntype", Promise)
878
903
  ], InventoryQuery.prototype, "inventoriesByBundle", null);
879
- tslib_1.__decorate([
880
- (0, type_graphql_1.Directive)('@privilege(category: "inventory", privilege: "query")'),
881
- (0, type_graphql_1.Query)(returns => inventory_types_1.InventoryList),
882
- tslib_1.__param(0, (0, type_graphql_1.Ctx)()),
883
- tslib_1.__param(1, (0, type_graphql_1.Arg)('filters', type => [shell_1.Filter], { nullable: true })),
884
- tslib_1.__param(2, (0, type_graphql_1.Arg)('pagination', type => shell_1.Pagination, { nullable: true })),
885
- tslib_1.__param(3, (0, type_graphql_1.Arg)('sortings', type => [shell_1.Sorting], { nullable: true })),
886
- tslib_1.__param(4, (0, type_graphql_1.Arg)('locationSortingRules', type => [shell_1.Sorting], { nullable: true })),
887
- tslib_1.__metadata("design:type", Function),
888
- tslib_1.__metadata("design:paramtypes", [Object, Array, typeof (_d = typeof shell_1.Pagination !== "undefined" && shell_1.Pagination) === "function" ? _d : Object, Array, Array]),
889
- tslib_1.__metadata("design:returntype", Promise)
890
- ], InventoryQuery.prototype, "inventoriesForExport", null);
891
904
  tslib_1.__decorate([
892
905
  (0, type_graphql_1.Directive)('@privilege(category: "inventory", privilege: "query")'),
893
906
  (0, type_graphql_1.Directive)('@transaction'),
@@ -895,7 +908,7 @@ tslib_1.__decorate([
895
908
  tslib_1.__param(0, (0, type_graphql_1.Args)()),
896
909
  tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
897
910
  tslib_1.__metadata("design:type", Function),
898
- tslib_1.__metadata("design:paramtypes", [typeof (_e = typeof shell_1.ListParam !== "undefined" && shell_1.ListParam) === "function" ? _e : Object, Object]),
911
+ tslib_1.__metadata("design:paramtypes", [shell_1.ListParam, Object]),
899
912
  tslib_1.__metadata("design:returntype", Promise)
900
913
  ], InventoryQuery.prototype, "inventoriesGroupByProduct", null);
901
914
  tslib_1.__decorate([
@@ -947,6 +960,13 @@ tslib_1.__decorate([
947
960
  tslib_1.__metadata("design:paramtypes", [inventory_1.Inventory]),
948
961
  tslib_1.__metadata("design:returntype", Promise)
949
962
  ], InventoryQuery.prototype, "arrivalNoticeRefNo", null);
963
+ tslib_1.__decorate([
964
+ (0, type_graphql_1.FieldResolver)(type => String),
965
+ tslib_1.__param(0, (0, type_graphql_1.Root)()),
966
+ tslib_1.__metadata("design:type", Function),
967
+ tslib_1.__metadata("design:paramtypes", [inventory_1.Inventory]),
968
+ tslib_1.__metadata("design:returntype", Promise)
969
+ ], InventoryQuery.prototype, "arrivalNoticeNo", null);
950
970
  InventoryQuery = tslib_1.__decorate([
951
971
  (0, type_graphql_1.Resolver)(inventory_1.Inventory)
952
972
  ], InventoryQuery);
@@ -1008,6 +1028,7 @@ async function inventoriesByStrategy({ worksheetId, batchId, bizplaceId, product
1008
1028
  break;
1009
1029
  case 'FEFO':
1010
1030
  qb.orderBy('"INV"."expiration_date"', 'ASC');
1031
+ qb.addOrderBy('"INV"."created_at"', 'ASC');
1011
1032
  if ((locationSortingRules === null || locationSortingRules === void 0 ? void 0 : locationSortingRules.length) > 0) {
1012
1033
  locationSortingRules.forEach((rule, idx) => {
1013
1034
  qb.addOrderBy(`LOC.${rule.name}`, rule.desc ? 'DESC' : 'ASC');
@@ -1016,6 +1037,7 @@ async function inventoriesByStrategy({ worksheetId, batchId, bizplaceId, product
1016
1037
  break;
1017
1038
  case 'FMFO':
1018
1039
  qb.orderBy('"INV"."manufacture_date"', 'ASC');
1040
+ qb.addOrderBy('"INV"."created_at"', 'ASC');
1019
1041
  if ((locationSortingRules === null || locationSortingRules === void 0 ? void 0 : locationSortingRules.length) > 0) {
1020
1042
  locationSortingRules.forEach((rule, idx) => {
1021
1043
  qb.addOrderBy(`LOC.${rule.name}`, rule.desc ? 'DESC' : 'ASC');