@things-factory/warehouse-base 4.3.108 → 4.3.109

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 (46) hide show
  1. package/dist-server/controllers/warehouse-controller.js.map +1 -1
  2. package/dist-server/service/inventory/inventory-query.js +36 -28
  3. package/dist-server/service/inventory/inventory-query.js.map +1 -1
  4. package/dist-server/service/inventory/inventory-types.js +12 -16
  5. package/dist-server/service/inventory/inventory-types.js.map +1 -1
  6. package/dist-server/service/inventory/inventory.js +1 -4
  7. package/dist-server/service/inventory/inventory.js.map +1 -1
  8. package/dist-server/service/inventory-change/inventory-change-mutation.js +2 -6
  9. package/dist-server/service/inventory-change/inventory-change-mutation.js.map +1 -1
  10. package/dist-server/service/inventory-history/inventory-history-query.js +3 -5
  11. package/dist-server/service/inventory-history/inventory-history-query.js.map +1 -1
  12. package/dist-server/service/inventory-item/inventory-item.js +3 -8
  13. package/dist-server/service/inventory-item/inventory-item.js.map +1 -1
  14. package/dist-server/service/inventory-product/inventory-product.js +3 -8
  15. package/dist-server/service/inventory-product/inventory-product.js.map +1 -1
  16. package/dist-server/service/location/location-mutation.js +1 -3
  17. package/dist-server/service/location/location-mutation.js.map +1 -1
  18. package/dist-server/service/pallet/pallet-mutation.js +33 -35
  19. package/dist-server/service/pallet/pallet-mutation.js.map +1 -1
  20. package/dist-server/service/tote/tote-mutation.js +1 -1
  21. package/dist-server/service/tote/tote-mutation.js.map +1 -1
  22. package/dist-server/service/tote/tote-query.js +5 -7
  23. package/dist-server/service/tote/tote-query.js.map +1 -1
  24. package/dist-server/service/warehouse/warehouse-mutation.js +1 -33
  25. package/dist-server/service/warehouse/warehouse-mutation.js.map +1 -1
  26. package/dist-server/utils/inventory-util.js +25 -86
  27. package/dist-server/utils/inventory-util.js.map +1 -1
  28. package/package.json +8 -8
  29. package/server/controllers/warehouse-controller.ts +1 -0
  30. package/server/service/inventory/inventory-query.ts +44 -33
  31. package/server/service/inventory/inventory-types.ts +0 -3
  32. package/server/service/inventory/inventory.ts +1 -3
  33. package/server/service/inventory-change/inventory-change-mutation.ts +5 -8
  34. package/server/service/inventory-history/inventory-history-query.ts +8 -43
  35. package/server/service/inventory-item/inventory-item.ts +2 -9
  36. package/server/service/inventory-product/inventory-product.ts +1 -5
  37. package/server/service/location/location-mutation.ts +1 -3
  38. package/server/service/pallet/pallet-mutation.ts +69 -50
  39. package/server/service/tote/tote-mutation.ts +1 -1
  40. package/server/service/tote/tote-query.ts +7 -9
  41. package/server/service/warehouse/warehouse-mutation.ts +2 -41
  42. package/server/utils/inventory-util.ts +51 -116
  43. package/translations/en.json +2 -4
  44. package/translations/ko.json +2 -4
  45. package/translations/ms.json +2 -4
  46. package/translations/zh.json +12 -14
@@ -131,7 +131,7 @@ export async function generateInventoryHistory(
131
131
 
132
132
  inventory = await invRepo.findOne({
133
133
  where: { id: inventory.id },
134
- relations: ['domain', 'bizplace', 'product', 'warehouse', 'location', 'productDetail']
134
+ relations: ['domain', 'bizplace', 'product', 'warehouse', 'location']
135
135
  })
136
136
 
137
137
  const domain: Domain = inventory.domain
@@ -147,133 +147,68 @@ export async function generateInventoryHistory(
147
147
  }
148
148
  })
149
149
 
150
- let lastSeq: number
151
- let res: any
152
- let inventoryHistoryFields: any = {
150
+ let seq: number = 0
151
+ let openingQty: number = 0
152
+ let openingUomValue: number = 0
153
+
154
+ if (lastInvHistory) {
155
+ openingQty = lastInvHistory.openingQty + lastInvHistory.qty
156
+ openingUomValue = lastInvHistory.openingUomValue + lastInvHistory.uomValue
157
+ seq = lastInvHistory.seq + 1
158
+ }
159
+
160
+ let remainQty = (openingQty || 0) + (qty || 0)
161
+
162
+ let inventoryHistory: any = new InventoryHistory()
163
+
164
+ inventoryHistory = {
165
+ ...inventory,
166
+ name: InventoryNoGenerator.inventoryHistoryName(),
167
+ inventory,
168
+ seq: seq,
169
+ status: remainQty == 0 ? INVENTORY_STATUS.TERMINATED : inventory.status,
170
+ transactionType,
153
171
  refOrderId: refOrder?.id || null,
154
172
  orderNo: refOrder?.name || null,
155
173
  orderRefNo: refOrder?.refNo || null,
156
- uom: inventory?.uom,
157
-
174
+ qty,
175
+ openingQty,
176
+ uomValue,
177
+ openingUomValue: openingUomValue,
158
178
  creator: user,
159
- updater: user,
160
- domain: inventory?.domain,
161
- bizplace: inventory?.bizplace,
162
- reusablePallet: inventory?.reusablePallet,
163
- inventory: inventory,
164
- product: inventory?.product,
165
- productDetail: inventory?.productDetail,
166
- warehouse: inventory?.warehouse,
167
- location: inventory?.location,
168
-
169
- palletId: inventory?.palletId,
170
- batchId: inventory?.batchId,
171
- zone: inventory?.zone,
172
- packingType: inventory?.packingType,
173
- description: inventory?.description,
174
- expirationDate: inventory?.expirationDate,
175
- unitCost: inventory?.unitCost,
176
- batchIdRef: inventory?.batchIdRef,
177
- cartonId: inventory?.cartonId,
178
- manufactureYear: inventory?.manufactureYear,
179
- packingSize: inventory?.packingSize,
180
- manufactureDate: inventory?.manufactureDate,
181
- status: inventory.status
179
+ updater: user
182
180
  }
183
181
 
184
- if (!lastInvHistory) {
185
- res = await invHistoryRepo
186
- .createQueryBuilder()
187
- .insert()
188
- .into(InventoryHistory)
189
- .values([
190
- {
191
- ...inventoryHistoryFields,
192
- name: InventoryNoGenerator.inventoryHistoryName(),
193
- status: inventory.status,
194
- transactionType,
195
- qty,
196
- openingQty: 0,
197
- uomValue,
198
- openingUomValue: 0,
199
- seq: 0
200
- }
201
- ])
202
- .returning('*')
203
- .execute()
204
- } else {
205
- if (transactionType == 'PICKING' || transactionType == 'UNLOADING') {
206
- const findSameOrderHistory: InventoryHistory[] = await invHistoryRepo.find({
207
- domain: inventory.domain,
208
- palletId: inventory.palletId,
209
- refOrderId: refOrder.id
210
- })
211
-
212
- if (findSameOrderHistory.length > 0) {
213
- let prevTotalQty = 0
214
- let prevTotalUomValue = 0
215
- for (let oh of findSameOrderHistory) {
216
- prevTotalQty += oh.qty
217
- prevTotalUomValue += oh.uomValue
218
- }
219
- qty -= prevTotalQty
220
- uomValue -= prevTotalUomValue
221
- }
182
+ delete inventoryHistory.updatedAt
183
+ delete inventoryHistory.createdAt
184
+ delete inventoryHistory.id
185
+
186
+ let newInventoryHistory = await invHistoryRepo.save(inventoryHistory)
187
+
188
+ if (remainQty == 0) {
189
+ seq = seq + 1
190
+ let terminatedHistory = {
191
+ ...newInventoryHistory,
192
+ name: InventoryNoGenerator.inventoryHistoryName(),
193
+ seq: seq,
194
+ status: INVENTORY_STATUS.TERMINATED,
195
+ transactionType: INVENTORY_TRANSACTION_TYPE.TERMINATED,
196
+ uom: inventory.uom,
197
+ qty: 0,
198
+ openingQty: 0,
199
+ uomValue: 0,
200
+ openingUomValue: 0
222
201
  }
223
202
 
224
- res = await invHistoryRepo
225
- .createQueryBuilder()
226
- .insert()
227
- .into(InventoryHistory)
228
- .values([
229
- {
230
- ...inventoryHistoryFields,
231
- name: InventoryNoGenerator.inventoryHistoryName(),
232
- transactionType,
233
- qty,
234
- openingQty: () =>
235
- `(select opening_qty from inventory_histories where pallet_id = '${inventory.palletId}' and domain_id = '${domain.id}' order by seq desc limit 1) + (select qty from inventory_histories where pallet_id = '${inventory.palletId}' and domain_id = '${domain.id}' order by seq desc limit 1)`,
236
- uomValue,
237
- openingUomValue: () =>
238
- `(select opening_uom_value from inventory_histories where pallet_id = '${inventory.palletId}' and domain_id = '${domain.id}' order by seq desc limit 1) + ${uomValue}`,
239
- seq: () =>
240
- `(select seq from inventory_histories where pallet_id = '${inventory.palletId}' and domain_id = '${domain.id}' order by seq desc limit 1) + 1`
241
- }
242
- ])
243
- .returning('*')
244
- .execute()
245
- }
203
+ delete terminatedHistory.id
246
204
 
247
- let newInventoryHistory: InventoryHistory = res.generatedMaps[0]
248
- lastSeq = newInventoryHistory.seq
249
-
250
- if (newInventoryHistory.openingQty + qty == 0 && transactionType != 'UNDO_UNLOADING') {
251
- let terminatedRes = await invHistoryRepo
252
- .createQueryBuilder()
253
- .insert()
254
- .into(InventoryHistory)
255
- .values([
256
- {
257
- ...inventoryHistoryFields,
258
- name: InventoryNoGenerator.inventoryHistoryName(),
259
- status: INVENTORY_STATUS.TERMINATED,
260
- transactionType: INVENTORY_TRANSACTION_TYPE.TERMINATED,
261
- qty: 0,
262
- openingQty: 0,
263
- uomValue: 0,
264
- openingUomValue: 0,
265
- seq: () =>
266
- `(select seq from inventory_histories where inventory_id = '${inventory.id}' order by seq desc limit 1) + 1`
267
- }
268
- ])
269
- .returning('seq')
270
- .execute()
271
-
272
- lastSeq = terminatedRes.generatedMaps[0].seq
205
+ newInventoryHistory = await invHistoryRepo.save(terminatedHistory)
273
206
  inventory.status = INVENTORY_STATUS.TERMINATED
274
207
  }
275
208
 
276
- await invRepo.update(inventory.id, { lastSeq, updater: user })
209
+ if (inventory.lastSeq !== seq) {
210
+ await invRepo.update(inventory.id, { lastSeq: newInventoryHistory.seq, updater: user })
211
+ }
277
212
 
278
213
  await switchLocationStatus(domain, location, user, trxMgr)
279
214
  return newInventoryHistory
@@ -1,7 +1,4 @@
1
1
  {
2
- "error.no_location_found": "no location found",
3
- "error.pallet (x) already exists": "Pallet ({x}) already exists",
4
- "error.warehouse (x) already exists": "Warehouse ({x}) already exists",
5
2
  "field.location": "location",
6
3
  "field.product_batch": "product batch",
7
4
  "field.lot": "lot",
@@ -19,5 +16,6 @@
19
16
  "field.qty": "qty",
20
17
  "field.state": "state",
21
18
  "field.date": "date",
22
- "field.type": "type"
19
+ "field.type": "type",
20
+ "error.no_location_found": "no location found"
23
21
  }
@@ -1,7 +1,4 @@
1
1
  {
2
- "error.no_location_found": "발견된 로케이션이 없습니다",
3
- "error.pallet (x) already exists": "[ko] Pallet ({x}) already exists",
4
- "error.warehouse (x) already exists": "[ko] Warehouse ({x}) already exists",
5
2
  "field.location": "로케이션",
6
3
  "field.product_batch": "제품 배치",
7
4
  "field.lot": "롯트",
@@ -19,5 +16,6 @@
19
16
  "field.qty": "수량",
20
17
  "field.state": "국가",
21
18
  "field.date": "날짜",
22
- "field.type": "유형"
19
+ "field.type": "유형",
20
+ "error.no_location_found": "발견된 로케이션이 없습니다"
23
21
  }
@@ -1,7 +1,4 @@
1
1
  {
2
- "error.no_location_found": "[ms]no location found",
3
- "error.pallet (x) already exists": "[ms] Pallet ({x}) already exists",
4
- "error.warehouse (x) already exists": "[ko] Warehouse ({x}) already exists",
5
2
  "field.location": "lokasi",
6
3
  "field.product_batch": "kumpulan produk",
7
4
  "field.lot": "lot",
@@ -19,5 +16,6 @@
19
16
  "field.qty": "kuantiti",
20
17
  "field.state": "keadaan",
21
18
  "field.date": "tarikh",
22
- "field.type": "jenis"
19
+ "field.type": "jenis",
20
+ "error.no_location_found": "[ms]no location found"
23
21
  }
@@ -1,23 +1,21 @@
1
1
  {
2
- "error.no_location_found": "[zh]no location found",
3
- "error.pallet (x) already exists": "[zh] Pallet ({x}) already exists",
4
- "error.warehouse (x) already exists": "[ko] Warehouse ({x}) already exists",
5
- "field.bizplace": "分部",
6
- "field.date": "日期",
7
- "field.end_qty": "最终数量",
8
- "field.in_qty": "进口数量",
9
2
  "field.location": "位置",
10
- "field.lot": "地块",
11
- "field.out_qty": "出口数量",
12
3
  "field.product_batch": "产品批次",
13
- "field.product": "产品",
14
- "field.qty": "数量",
4
+ "field.lot": "地块",
5
+ "field.warehouse": "仓库",
6
+ "field.zone": "区",
15
7
  "field.section": "段",
8
+ "field.unit": "单元",
16
9
  "field.shelf": "架子",
10
+ "field.bizplace": "分部",
17
11
  "field.start_qty": "开始数量",
12
+ "field.in_qty": "进口数量",
13
+ "field.out_qty": "出口数量",
14
+ "field.end_qty": "最终数量",
15
+ "field.product": "产品",
16
+ "field.qty": "数量",
18
17
  "field.state": "状态",
18
+ "field.date": "日期",
19
19
  "field.type": "类型",
20
- "field.unit": "单元",
21
- "field.warehouse": "仓库",
22
- "field.zone": "区"
20
+ "error.no_location_found": "[zh]no location found"
23
21
  }