@things-factory/worksheet-base 4.3.388 → 4.3.390
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.
- package/dist-server/controllers/inspect/cycle-count-worksheet-controller.js +164 -38
- package/dist-server/controllers/inspect/cycle-count-worksheet-controller.js.map +1 -1
- package/dist-server/graphql/resolvers/worksheet/cycle-count-adjustment.js +35 -5
- package/dist-server/graphql/resolvers/worksheet/cycle-count-adjustment.js.map +1 -1
- package/dist-server/graphql/resolvers/worksheet/cycle-count-worksheet-for-carton.js +3 -1
- package/dist-server/graphql/resolvers/worksheet/cycle-count-worksheet-for-carton.js.map +1 -1
- package/dist-server/graphql/resolvers/worksheet/cycle-count-worksheet-for-pallet.js +8 -2
- package/dist-server/graphql/resolvers/worksheet/cycle-count-worksheet-for-pallet.js.map +1 -1
- package/dist-server/graphql/resolvers/worksheet/packing-worksheet.js +6 -18
- package/dist-server/graphql/resolvers/worksheet/packing-worksheet.js.map +1 -1
- package/dist-server/graphql/types/worksheet/worksheet-detail-info.js +1 -0
- package/dist-server/graphql/types/worksheet/worksheet-detail-info.js.map +1 -1
- package/dist-server/utils/lmd-util.js +1 -1
- package/dist-server/utils/lmd-util.js.map +1 -1
- package/package.json +9 -9
- package/server/controllers/inspect/cycle-count-worksheet-controller.ts +245 -57
- package/server/graphql/resolvers/worksheet/cycle-count-adjustment.ts +47 -6
- package/server/graphql/resolvers/worksheet/cycle-count-worksheet-for-carton.ts +6 -1
- package/server/graphql/resolvers/worksheet/cycle-count-worksheet-for-pallet.ts +11 -2
- package/server/graphql/resolvers/worksheet/packing-worksheet.ts +6 -19
- package/server/graphql/types/worksheet/worksheet-detail-info.ts +1 -0
- package/server/utils/lmd-util.ts +1 -1
|
@@ -18,6 +18,7 @@ import { WORKSHEET_STATUS, WORKSHEET_TYPE } from '../../constants'
|
|
|
18
18
|
import { Worksheet, WorksheetDetail } from '../../entities'
|
|
19
19
|
import { WorksheetNoGenerator } from '../../utils'
|
|
20
20
|
import { WorksheetController } from '../worksheet-controller'
|
|
21
|
+
import { cycleCountAdjustment } from '../../graphql/resolvers/worksheet/cycle-count-adjustment'
|
|
21
22
|
|
|
22
23
|
export class CycleCountWorksheetController extends WorksheetController {
|
|
23
24
|
private async createCycleCountWorksheet(
|
|
@@ -265,6 +266,16 @@ export class CycleCountWorksheetController extends WorksheetController {
|
|
|
265
266
|
})
|
|
266
267
|
|
|
267
268
|
if (notDoneCount === 0) {
|
|
269
|
+
if (currentCycleCountWorksheet.checkCount != 1) {
|
|
270
|
+
await cycleCountAdjustment(
|
|
271
|
+
this.trxMgr,
|
|
272
|
+
this.domain,
|
|
273
|
+
this.user,
|
|
274
|
+
currentCycleCountWorksheet.name,
|
|
275
|
+
existingInventoryCheck.name
|
|
276
|
+
)
|
|
277
|
+
}
|
|
278
|
+
|
|
268
279
|
// Step 11: Update status of existing InventoryCheck
|
|
269
280
|
existingInventoryCheck.status = ORDER_STATUS.INSPECTING
|
|
270
281
|
existingInventoryCheck.updater = this.user
|
|
@@ -282,11 +293,134 @@ export class CycleCountWorksheetController extends WorksheetController {
|
|
|
282
293
|
|
|
283
294
|
return nextRoundWorksheet
|
|
284
295
|
} catch (error) {
|
|
285
|
-
console.error('An error occurred while creating the next round cycle count worksheet:', error)
|
|
286
296
|
throw new Error('Failed to create next round cycle count worksheet')
|
|
287
297
|
}
|
|
288
298
|
}
|
|
289
299
|
|
|
300
|
+
private async sameCycleCountWorksheet(
|
|
301
|
+
customerId: string,
|
|
302
|
+
existingInventoryCheck: InventoryCheck,
|
|
303
|
+
executionDate: string,
|
|
304
|
+
executingWorksheet: Worksheet,
|
|
305
|
+
notTallyWorksheet: Worksheet,
|
|
306
|
+
inventoryCheckItemIds: string[]
|
|
307
|
+
): Promise<Worksheet> {
|
|
308
|
+
try {
|
|
309
|
+
// Step 1: Fetch current InventoryCheckItems
|
|
310
|
+
const currentInventoryCheckItems: InventoryCheckItem[] = await this.trxMgr
|
|
311
|
+
.getRepository(InventoryCheckItem)
|
|
312
|
+
.findByIds(inventoryCheckItemIds)
|
|
313
|
+
|
|
314
|
+
// Step 2: Create new InventoryCheckItems based on the current ones
|
|
315
|
+
const continuedInventoryCheckItems = currentInventoryCheckItems.map(currentItem => {
|
|
316
|
+
let newItem: InventoryCheckItem = new InventoryCheckItem()
|
|
317
|
+
|
|
318
|
+
Object.assign(newItem, currentItem)
|
|
319
|
+
newItem.id = undefined
|
|
320
|
+
newItem.domain = this.domain
|
|
321
|
+
newItem.bizplace = customerId
|
|
322
|
+
newItem.inventoryCheck = currentItem.inventoryCheckId
|
|
323
|
+
newItem.status = INVENTORY_CHECK_ITEM_STATUS.INSPECTING
|
|
324
|
+
newItem.name = OrderNoGenerator.inventoryCheckItem()
|
|
325
|
+
newItem.originQty = currentItem.inspectedQty || currentItem.originQty
|
|
326
|
+
newItem.originUomValue = currentItem.inspectedUomValue || currentItem.originUomValue
|
|
327
|
+
newItem.originBatchNo = currentItem.inspectedBatchNo || currentItem.originBatchNo
|
|
328
|
+
newItem.originLocation = currentItem.inspectedLocationId || currentItem.originLocationId
|
|
329
|
+
newItem.inspectedQty = null
|
|
330
|
+
newItem.inspectedUomValue = null
|
|
331
|
+
newItem.inspectedBatchNo = null
|
|
332
|
+
newItem.inspectedLocationId = null
|
|
333
|
+
newItem.countNo = currentItem.countNo + 1
|
|
334
|
+
newItem.inventory = currentItem.inventoryId
|
|
335
|
+
newItem.product = currentItem.productId
|
|
336
|
+
newItem.productDetail = currentItem.productDetailId
|
|
337
|
+
newItem.creator = this.user
|
|
338
|
+
newItem.updater = this.user
|
|
339
|
+
|
|
340
|
+
return newItem
|
|
341
|
+
})
|
|
342
|
+
|
|
343
|
+
// Step 3: Save the new InventoryCheckItems
|
|
344
|
+
await this.trxMgr.getRepository(InventoryCheckItem).save(continuedInventoryCheckItems, { chunk: 500 })
|
|
345
|
+
|
|
346
|
+
// Step 4: Create new Worksheet Details based on new InventoryCheckItems
|
|
347
|
+
let continuedWorksheetDetails = continuedInventoryCheckItems.map(newItem => {
|
|
348
|
+
let detail: WorksheetDetail = new WorksheetDetail()
|
|
349
|
+
|
|
350
|
+
detail.domain = this.domain
|
|
351
|
+
detail.bizplace = customerId
|
|
352
|
+
detail.worksheet = executingWorksheet
|
|
353
|
+
detail.name = WorksheetNoGenerator.cycleCountDetail()
|
|
354
|
+
detail.targetInventoryCheckItem = newItem
|
|
355
|
+
detail.type = WORKSHEET_TYPE.CYCLE_COUNT
|
|
356
|
+
detail.status = WORKSHEET_STATUS.EXECUTING
|
|
357
|
+
detail.creator = this.user
|
|
358
|
+
detail.updater = this.user
|
|
359
|
+
|
|
360
|
+
return detail
|
|
361
|
+
})
|
|
362
|
+
|
|
363
|
+
// Step 5: Save the new Worksheet Details
|
|
364
|
+
await this.trxMgr.getRepository(WorksheetDetail).save(continuedWorksheetDetails, { chunk: 500 })
|
|
365
|
+
|
|
366
|
+
// Step 6: Mark the selected inventory as TERMINATED
|
|
367
|
+
currentInventoryCheckItems.forEach(item => {
|
|
368
|
+
item.status = INVENTORY_CHECK_ITEM_STATUS.TERMINATED
|
|
369
|
+
item.updater = this.user
|
|
370
|
+
})
|
|
371
|
+
await this.trxMgr.getRepository(InventoryCheckItem).save(currentInventoryCheckItems)
|
|
372
|
+
|
|
373
|
+
// Step 7: Directly update the worksheet details
|
|
374
|
+
await this.trxMgr
|
|
375
|
+
.getRepository(WorksheetDetail)
|
|
376
|
+
.createQueryBuilder()
|
|
377
|
+
.update(WorksheetDetail)
|
|
378
|
+
.set({
|
|
379
|
+
status: WORKSHEET_STATUS.DONE,
|
|
380
|
+
updater: this.user
|
|
381
|
+
})
|
|
382
|
+
.where('targetInventoryCheckItem IN (:...ids)', { ids: currentInventoryCheckItems.map(item => item.id) })
|
|
383
|
+
.execute()
|
|
384
|
+
|
|
385
|
+
// Check if any record is not DONE
|
|
386
|
+
const notDoneCount = await this.trxMgr.getRepository(WorksheetDetail).count({
|
|
387
|
+
where: {
|
|
388
|
+
worksheet: notTallyWorksheet,
|
|
389
|
+
status: Not(Equal(WORKSHEET_STATUS.DONE))
|
|
390
|
+
}
|
|
391
|
+
})
|
|
392
|
+
|
|
393
|
+
if (notDoneCount === 0) {
|
|
394
|
+
if (notTallyWorksheet.checkCount != 1) {
|
|
395
|
+
await cycleCountAdjustment(
|
|
396
|
+
this.trxMgr,
|
|
397
|
+
this.domain,
|
|
398
|
+
this.user,
|
|
399
|
+
notTallyWorksheet.name,
|
|
400
|
+
existingInventoryCheck.name
|
|
401
|
+
)
|
|
402
|
+
}
|
|
403
|
+
// Step 11: Update status of existing InventoryCheck
|
|
404
|
+
existingInventoryCheck.status = ORDER_STATUS.INSPECTING
|
|
405
|
+
existingInventoryCheck.updater = this.user
|
|
406
|
+
await this.trxMgr.getRepository(InventoryCheck).save(existingInventoryCheck)
|
|
407
|
+
|
|
408
|
+
// Step 12: Mark the current worksheet as DONE
|
|
409
|
+
notTallyWorksheet.status = WORKSHEET_STATUS.DONE
|
|
410
|
+
notTallyWorksheet.updater = this.user
|
|
411
|
+
await this.trxMgr.getRepository(Worksheet).save(notTallyWorksheet)
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
existingInventoryCheck.executionDate = executionDate
|
|
415
|
+
existingInventoryCheck.updater = this.user
|
|
416
|
+
await this.trxMgr.getRepository(InventoryCheck).save(existingInventoryCheck)
|
|
417
|
+
|
|
418
|
+
return executingWorksheet // Return the same executing worksheet
|
|
419
|
+
} catch (error) {
|
|
420
|
+
throw new Error('Failed to use same cycle count worksheet')
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
|
|
290
424
|
async generateCycleCountWorksheet(
|
|
291
425
|
executionDate: string,
|
|
292
426
|
customerId: string,
|
|
@@ -307,7 +441,7 @@ export class CycleCountWorksheetController extends WorksheetController {
|
|
|
307
441
|
})
|
|
308
442
|
|
|
309
443
|
const worksheetRepository = this.trxMgr.getRepository(Worksheet)
|
|
310
|
-
const
|
|
444
|
+
const foundCycleCountWorksheets: Worksheet[] = await worksheetRepository.find({
|
|
311
445
|
where: {
|
|
312
446
|
domain: this.domain,
|
|
313
447
|
bizplace: customerBizplace,
|
|
@@ -320,16 +454,39 @@ export class CycleCountWorksheetController extends WorksheetController {
|
|
|
320
454
|
relations: ['worksheetDetails', 'worksheetDetails.targetInventoryCheckItem', 'inventoryCheck']
|
|
321
455
|
})
|
|
322
456
|
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
457
|
+
const worksheetStatuses = foundCycleCountWorksheets.map(worksheet => worksheet.status)
|
|
458
|
+
|
|
459
|
+
if (foundCycleCountWorksheets.length >= 1 && inventoryCheckItemIds.length) {
|
|
460
|
+
const executingWorksheet = foundCycleCountWorksheets.find(
|
|
461
|
+
worksheet => worksheet.status === WORKSHEET_STATUS.EXECUTING
|
|
462
|
+
)
|
|
463
|
+
const notTallyWorksheet = foundCycleCountWorksheets.find(
|
|
464
|
+
worksheet => worksheet.status === WORKSHEET_STATUS.NOT_TALLY
|
|
330
465
|
)
|
|
466
|
+
|
|
467
|
+
if (
|
|
468
|
+
worksheetStatuses.includes(WORKSHEET_STATUS.EXECUTING) &&
|
|
469
|
+
worksheetStatuses.includes(WORKSHEET_STATUS.NOT_TALLY)
|
|
470
|
+
) {
|
|
471
|
+
return await this.sameCycleCountWorksheet(
|
|
472
|
+
customerId,
|
|
473
|
+
foundInventoryCheck,
|
|
474
|
+
executionDate,
|
|
475
|
+
executingWorksheet,
|
|
476
|
+
notTallyWorksheet,
|
|
477
|
+
inventoryCheckItemIds
|
|
478
|
+
)
|
|
479
|
+
} else if (worksheetStatuses.includes(WORKSHEET_STATUS.NOT_TALLY)) {
|
|
480
|
+
return await this.createNextRoundCycleCountWorksheet(
|
|
481
|
+
customerId,
|
|
482
|
+
foundInventoryCheck,
|
|
483
|
+
executionDate,
|
|
484
|
+
notTallyWorksheet,
|
|
485
|
+
inventoryCheckItemIds
|
|
486
|
+
)
|
|
487
|
+
}
|
|
331
488
|
} else {
|
|
332
|
-
if (
|
|
489
|
+
if (foundCycleCountWorksheets.length >= 1) {
|
|
333
490
|
throw new Error('Unfinished cycle count worksheet exists.')
|
|
334
491
|
}
|
|
335
492
|
return await this.createCycleCountWorksheet(
|
|
@@ -364,7 +521,7 @@ export class CycleCountWorksheetController extends WorksheetController {
|
|
|
364
521
|
})
|
|
365
522
|
|
|
366
523
|
const worksheetRepository = this.trxMgr.getRepository(Worksheet)
|
|
367
|
-
const
|
|
524
|
+
const foundCycleCountWorksheets: Worksheet[] = await worksheetRepository.find({
|
|
368
525
|
where: {
|
|
369
526
|
domain: this.domain,
|
|
370
527
|
bizplace: customerBizplace,
|
|
@@ -377,6 +534,8 @@ export class CycleCountWorksheetController extends WorksheetController {
|
|
|
377
534
|
relations: ['worksheetDetails', 'worksheetDetails.targetInventoryCheckItem', 'inventoryCheck']
|
|
378
535
|
})
|
|
379
536
|
|
|
537
|
+
const worksheetStatuses = foundCycleCountWorksheets.map(worksheet => worksheet.status)
|
|
538
|
+
|
|
380
539
|
const qb = this.trxMgr.getRepository(InventoryCheckItem).createQueryBuilder('inventoryCheckItem')
|
|
381
540
|
qb.innerJoinAndSelect('inventoryCheckItem.inventory', 'inventory')
|
|
382
541
|
.innerJoinAndSelect('inventoryCheckItem.productDetail', 'productDetail')
|
|
@@ -395,13 +554,31 @@ export class CycleCountWorksheetController extends WorksheetController {
|
|
|
395
554
|
const inventoryCheckItems: InventoryCheckItem[] = await qb.getMany()
|
|
396
555
|
|
|
397
556
|
const inventoryCheckItemIds = inventoryCheckItems.map(item => item.id)
|
|
557
|
+
const executingWorksheet = foundCycleCountWorksheets.find(
|
|
558
|
+
worksheet => worksheet.status === WORKSHEET_STATUS.EXECUTING
|
|
559
|
+
)
|
|
560
|
+
const notTallyWorksheet = foundCycleCountWorksheets.find(
|
|
561
|
+
worksheet => worksheet.status === WORKSHEET_STATUS.NOT_TALLY
|
|
562
|
+
)
|
|
398
563
|
|
|
399
|
-
if (
|
|
564
|
+
if (
|
|
565
|
+
worksheetStatuses.includes(WORKSHEET_STATUS.EXECUTING) &&
|
|
566
|
+
worksheetStatuses.includes(WORKSHEET_STATUS.NOT_TALLY)
|
|
567
|
+
) {
|
|
568
|
+
return await this.sameCycleCountWorksheet(
|
|
569
|
+
customerId,
|
|
570
|
+
foundInventoryCheck,
|
|
571
|
+
executionDate,
|
|
572
|
+
executingWorksheet,
|
|
573
|
+
notTallyWorksheet,
|
|
574
|
+
inventoryCheckItemIds
|
|
575
|
+
)
|
|
576
|
+
} else if (worksheetStatuses.includes(WORKSHEET_STATUS.NOT_TALLY)) {
|
|
400
577
|
return await this.createNextRoundCycleCountWorksheet(
|
|
401
578
|
customerId,
|
|
402
579
|
foundInventoryCheck,
|
|
403
580
|
executionDate,
|
|
404
|
-
|
|
581
|
+
notTallyWorksheet,
|
|
405
582
|
inventoryCheckItemIds
|
|
406
583
|
)
|
|
407
584
|
}
|
|
@@ -461,8 +638,9 @@ export class CycleCountWorksheetController extends WorksheetController {
|
|
|
461
638
|
const {
|
|
462
639
|
originBatchNo,
|
|
463
640
|
originQty,
|
|
464
|
-
originUomValue
|
|
465
|
-
|
|
641
|
+
originUomValue,
|
|
642
|
+
originLocationId
|
|
643
|
+
}: { originBatchNo: string; originQty: number; originUomValue: number, originLocationId: string } = targetInventoryCheckItem
|
|
466
644
|
|
|
467
645
|
const isChanged: boolean =
|
|
468
646
|
originBatchNo !== inspectedBatchNo || originQty !== inspectedQty || originUomValue !== inspectedUomValue
|
|
@@ -478,7 +656,7 @@ export class CycleCountWorksheetController extends WorksheetController {
|
|
|
478
656
|
targetInventoryCheckItem.inspectedBatchNo = inspectedBatchNo
|
|
479
657
|
targetInventoryCheckItem.inspectedQty = inspectedQty
|
|
480
658
|
targetInventoryCheckItem.inspectedUomValue = inspectedUomValue
|
|
481
|
-
targetInventoryCheckItem.inspectedLocation =
|
|
659
|
+
targetInventoryCheckItem.inspectedLocation = originLocationId
|
|
482
660
|
targetInventoryCheckItem.status = targetInventoryCheckItemStatus
|
|
483
661
|
targetInventoryCheckItem.updater = this.user
|
|
484
662
|
await this.updateOrderTargets([targetInventoryCheckItem])
|
|
@@ -1079,57 +1257,67 @@ export class CycleCountWorksheetController extends WorksheetController {
|
|
|
1079
1257
|
this.checkRecordValidity(worksheet, { status: WORKSHEET_STATUS.EXECUTING })
|
|
1080
1258
|
|
|
1081
1259
|
const worksheetDetails: WorksheetDetail[] = worksheet.worksheetDetails
|
|
1260
|
+
const doneWorksheetDetails = worksheetDetails.filter(wsd => wsd.status === 'DONE')
|
|
1082
1261
|
const targetInventoryCheckItems: InventoryCheckItem[] = worksheetDetails.map(
|
|
1083
1262
|
(wsd: WorksheetDetail) => wsd.targetInventoryCheckItem
|
|
1084
1263
|
)
|
|
1264
|
+
if (doneWorksheetDetails.length === worksheetDetails.length && worksheet.checkCount != 1) {
|
|
1265
|
+
await cycleCountAdjustment(this.trxMgr, this.domain, this.user, worksheet.name, inventoryCheck.name)
|
|
1085
1266
|
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1267
|
+
worksheet = await this.trxMgr.getRepository(Worksheet).findOne({
|
|
1268
|
+
domain: this.domain,
|
|
1269
|
+
type: In([WORKSHEET_TYPE.CYCLE_COUNT, WORKSHEET_TYPE.CYCLE_COUNT_RECHECK]),
|
|
1270
|
+
inventoryCheck
|
|
1271
|
+
})
|
|
1272
|
+
} else {
|
|
1273
|
+
const {
|
|
1274
|
+
tallyTargetInventoryCheckItems,
|
|
1275
|
+
notTallyTargetInventoryCheckItems
|
|
1276
|
+
}: {
|
|
1277
|
+
tallyTargetInventoryCheckItems: InventoryCheckItem[]
|
|
1278
|
+
notTallyTargetInventoryCheckItems: InventoryCheckItem[]
|
|
1279
|
+
} = targetInventoryCheckItems.reduce(
|
|
1280
|
+
(result, targetInventoryCheckItem: InventoryCheckItem) => {
|
|
1281
|
+
if (targetInventoryCheckItem.status !== INVENTORY_CHECK_ITEM_STATUS.INSPECTED) {
|
|
1282
|
+
result.notTallyTargetInventoryCheckItems.push(targetInventoryCheckItem)
|
|
1283
|
+
} else {
|
|
1284
|
+
result.tallyTargetInventoryCheckItems.push(targetInventoryCheckItem)
|
|
1285
|
+
}
|
|
1286
|
+
|
|
1287
|
+
return result
|
|
1288
|
+
},
|
|
1289
|
+
{
|
|
1290
|
+
tallyTargetInventoryCheckItems: [],
|
|
1291
|
+
notTallyTargetInventoryCheckItems: []
|
|
1098
1292
|
}
|
|
1293
|
+
)
|
|
1099
1294
|
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
const tallyInventories: Inventory[] = tallyTargetInventoryCheckItems.map(
|
|
1109
|
-
targetInventoryCheckItem => targetInventoryCheckItem.inventory
|
|
1110
|
-
)
|
|
1111
|
-
tallyTargetInventoryCheckItems.forEach((targetInventoryCheckItem: InventoryCheckItem) => {
|
|
1112
|
-
targetInventoryCheckItem.status = INVENTORY_CHECK_ITEM_STATUS.TERMINATED
|
|
1113
|
-
targetInventoryCheckItem.updater = this.user
|
|
1114
|
-
})
|
|
1115
|
-
await this.trxMgr.getRepository(InventoryCheckItem).save(tallyTargetInventoryCheckItems, { chunk: 500 })
|
|
1295
|
+
const tallyInventories: Inventory[] = tallyTargetInventoryCheckItems.map(
|
|
1296
|
+
targetInventoryCheckItem => targetInventoryCheckItem.inventory
|
|
1297
|
+
)
|
|
1298
|
+
tallyTargetInventoryCheckItems.forEach((targetInventoryCheckItem: InventoryCheckItem) => {
|
|
1299
|
+
targetInventoryCheckItem.status = INVENTORY_CHECK_ITEM_STATUS.TERMINATED
|
|
1300
|
+
targetInventoryCheckItem.updater = this.user
|
|
1301
|
+
})
|
|
1302
|
+
await this.trxMgr.getRepository(InventoryCheckItem).save(tallyTargetInventoryCheckItems, { chunk: 500 })
|
|
1116
1303
|
|
|
1117
|
-
|
|
1304
|
+
await this.trxMgr.getRepository(Inventory).save(tallyInventories, { chunk: 500 })
|
|
1118
1305
|
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1306
|
+
if (notTallyTargetInventoryCheckItems.length) {
|
|
1307
|
+
worksheet.status = WORKSHEET_STATUS.NOT_TALLY
|
|
1308
|
+
inventoryCheck.status = ORDER_STATUS.PENDING_REVIEW
|
|
1309
|
+
} else {
|
|
1310
|
+
worksheet.status = WORKSHEET_STATUS.DONE
|
|
1311
|
+
inventoryCheck.status = ORDER_STATUS.DONE
|
|
1312
|
+
}
|
|
1126
1313
|
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1314
|
+
worksheet.endedAt = new Date()
|
|
1315
|
+
worksheet.updater = this.user
|
|
1316
|
+
await this.trxMgr.getRepository(Worksheet).save(worksheet)
|
|
1130
1317
|
|
|
1131
|
-
|
|
1132
|
-
|
|
1318
|
+
inventoryCheck.updater = this.user
|
|
1319
|
+
await this.trxMgr.getRepository(InventoryCheck).save(inventoryCheck)
|
|
1320
|
+
}
|
|
1133
1321
|
|
|
1134
1322
|
return worksheet
|
|
1135
1323
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EntityManager, In } from 'typeorm'
|
|
1
|
+
import { EntityManager, In, Not } from 'typeorm'
|
|
2
2
|
|
|
3
3
|
import { Application, ApplicationType, User } from '@things-factory/auth-base'
|
|
4
4
|
import { Sellercraft, SellercraftStatus } from '@things-factory/integration-sellercraft'
|
|
@@ -52,6 +52,16 @@ export async function cycleCountAdjustment(
|
|
|
52
52
|
}
|
|
53
53
|
})
|
|
54
54
|
|
|
55
|
+
const inspectingItems: InventoryCheckItem[] = await tx.getRepository(InventoryCheckItem).find({
|
|
56
|
+
where: {
|
|
57
|
+
inventoryCheck: cycleCount,
|
|
58
|
+
status: 'INSPECTING'
|
|
59
|
+
},
|
|
60
|
+
relations: ['inventory']
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
const inspectingInventoryIds = new Set(inspectingItems.map(item => item.inventory.id))
|
|
64
|
+
|
|
55
65
|
let worksheet: Worksheet = await tx.getRepository(Worksheet).findOne({
|
|
56
66
|
where: {
|
|
57
67
|
domain,
|
|
@@ -66,8 +76,7 @@ export async function cycleCountAdjustment(
|
|
|
66
76
|
where: {
|
|
67
77
|
domain,
|
|
68
78
|
worksheet,
|
|
69
|
-
type: In([WORKSHEET_TYPE.CYCLE_COUNT, WORKSHEET_TYPE.CYCLE_COUNT_RECHECK])
|
|
70
|
-
status: WORKSHEET_STATUS.NOT_TALLY
|
|
79
|
+
type: In([WORKSHEET_TYPE.CYCLE_COUNT, WORKSHEET_TYPE.CYCLE_COUNT_RECHECK])
|
|
71
80
|
},
|
|
72
81
|
relations: [
|
|
73
82
|
'targetInventoryCheckItem',
|
|
@@ -87,7 +96,29 @@ export async function cycleCountAdjustment(
|
|
|
87
96
|
]
|
|
88
97
|
})
|
|
89
98
|
|
|
90
|
-
|
|
99
|
+
// Filter worksheetDetails that meet any of the specified conditions
|
|
100
|
+
const relevantWorksheetDetails = worksheetDetails.filter(worksheetDetail => {
|
|
101
|
+
const checkItem = worksheetDetail.targetInventoryCheckItem
|
|
102
|
+
const inventory = checkItem.inventory
|
|
103
|
+
|
|
104
|
+
// Exclude items that are under inspection elsewhere
|
|
105
|
+
if (inspectingInventoryIds.has(inventory.id)) {
|
|
106
|
+
return false
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return (
|
|
110
|
+
checkItem.status === ORDER_INVENTORY_STATUS.MISSING ||
|
|
111
|
+
checkItem.inspectedQty === 0 ||
|
|
112
|
+
checkItem.status === INVENTORY_CHECK_ITEM_STATUS.ADDED ||
|
|
113
|
+
inventory.status === 'CC_ADDED' ||
|
|
114
|
+
checkItem.inspectedQty !== inventory.qty ||
|
|
115
|
+
checkItem.inspectedBatchNo !== inventory.batchId ||
|
|
116
|
+
checkItem.inspectedLocation.id !== inventory.location.id ||
|
|
117
|
+
checkItem.inspectedUomValue !== inventory.uomValue
|
|
118
|
+
)
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
for (let worksheetDetail of relevantWorksheetDetails) {
|
|
91
122
|
const targetInventoryCheckItem: InventoryCheckItem = worksheetDetail.targetInventoryCheckItem
|
|
92
123
|
let inventory: Inventory = targetInventoryCheckItem.inventory
|
|
93
124
|
|
|
@@ -176,12 +207,17 @@ export async function cycleCountAdjustment(
|
|
|
176
207
|
const powrupController: PowrupController = new PowrupController()
|
|
177
208
|
powrupController.updateStock([inventory], customerDomain, user, tx)
|
|
178
209
|
}
|
|
179
|
-
} else if (
|
|
210
|
+
} else if (
|
|
211
|
+
targetInventoryCheckItem.status === INVENTORY_CHECK_ITEM_STATUS.ADDED ||
|
|
212
|
+
inventory.status === 'CC_ADDED'
|
|
213
|
+
) {
|
|
180
214
|
const inventories: Inventory[] = await tx.getRepository(Inventory).find({
|
|
181
215
|
where: { id: targetInventoryCheckItem.inventory.id, domain, status: INVENTORY_STATUS.CC_ADDED }
|
|
182
216
|
})
|
|
183
217
|
|
|
184
218
|
for (let inventory of inventories) {
|
|
219
|
+
inventory.qty = targetInventoryCheckItem.inspectedQty
|
|
220
|
+
inventory.uomValue = targetInventoryCheckItem.inspectedUomValue
|
|
185
221
|
inventory.status = INVENTORY_STATUS.STORED
|
|
186
222
|
inventory.creator = user
|
|
187
223
|
inventory.updater = user
|
|
@@ -218,7 +254,12 @@ export async function cycleCountAdjustment(
|
|
|
218
254
|
location: targetInventoryCheckItem.inventory.location
|
|
219
255
|
})
|
|
220
256
|
}
|
|
221
|
-
} else
|
|
257
|
+
} else if (
|
|
258
|
+
targetInventoryCheckItem.inspectedQty !== inventory.qty ||
|
|
259
|
+
targetInventoryCheckItem.inspectedBatchNo !== inventory.batchId ||
|
|
260
|
+
targetInventoryCheckItem.inspectedLocation.id !== inventory.location.id ||
|
|
261
|
+
targetInventoryCheckItem.inspectedUomValue !== inventory.uomValue
|
|
262
|
+
) {
|
|
222
263
|
const prevLocationId: string = inventory.location.id
|
|
223
264
|
|
|
224
265
|
if (targetInventoryCheckItem.inspectedBatchNo !== inventory.batchId) {
|
|
@@ -34,6 +34,7 @@ export const cycleCountWorksheetForCartonResolver = {
|
|
|
34
34
|
qb.leftJoinAndSelect('WSD.targetInventoryCheckItem', 'T_INV')
|
|
35
35
|
.leftJoinAndSelect('T_INV.inventory', 'INV')
|
|
36
36
|
.leftJoinAndSelect('T_INV.inspectedLocation', 'INS_LOC')
|
|
37
|
+
.leftJoinAndSelect('T_INV.originLocation', 'ORG_LOC')
|
|
37
38
|
.leftJoinAndSelect('INV.location', 'LOC_INV')
|
|
38
39
|
.leftJoinAndSelect('T_INV.product', 'PROD')
|
|
39
40
|
.leftJoinAndSelect('INV.product', 'PROD_INV')
|
|
@@ -51,7 +52,10 @@ export const cycleCountWorksheetForCartonResolver = {
|
|
|
51
52
|
}
|
|
52
53
|
|
|
53
54
|
if (locationName) {
|
|
54
|
-
qb.andWhere(
|
|
55
|
+
qb.andWhere(
|
|
56
|
+
'("ORG_LOC"."name" = :locationName OR "LOC_INV"."name" = :locationName OR "INS_LOC"."name" = :locationName',
|
|
57
|
+
{ locationName }
|
|
58
|
+
)
|
|
55
59
|
}
|
|
56
60
|
|
|
57
61
|
if (cartonId) {
|
|
@@ -93,6 +97,7 @@ export const cycleCountWorksheetForCartonResolver = {
|
|
|
93
97
|
qty: inventory?.qty,
|
|
94
98
|
uomValue: inventory?.uomValue,
|
|
95
99
|
uom: inventory?.uom,
|
|
100
|
+
originLocation: targetInventoryCheckItem?.originLocation,
|
|
96
101
|
inspectedQty: targetInventoryCheckItem?.inspectedQty,
|
|
97
102
|
inspectedUomValue: targetInventoryCheckItem?.inspectedUomValue,
|
|
98
103
|
inspectedLocation: targetInventoryCheckItem?.inspectedLocation,
|
|
@@ -35,6 +35,7 @@ export const cycleCountWorksheetForPalletResolver = {
|
|
|
35
35
|
qb.leftJoinAndSelect('WSD.targetInventoryCheckItem', 'T_INV')
|
|
36
36
|
.leftJoinAndSelect('T_INV.inventory', 'INV')
|
|
37
37
|
.leftJoinAndSelect('T_INV.inspectedLocation', 'INS_LOC')
|
|
38
|
+
.leftJoinAndSelect('T_INV.originLocation', 'ORG_LOC')
|
|
38
39
|
.leftJoinAndSelect('INV.location', 'LOC_INV')
|
|
39
40
|
.leftJoinAndSelect('T_INV.product', 'PROD')
|
|
40
41
|
.leftJoinAndSelect('INV.product', 'PROD_INV')
|
|
@@ -52,7 +53,10 @@ export const cycleCountWorksheetForPalletResolver = {
|
|
|
52
53
|
}
|
|
53
54
|
|
|
54
55
|
if (locationName) {
|
|
55
|
-
qb.andWhere(
|
|
56
|
+
qb.andWhere(
|
|
57
|
+
'("ORG_LOC"."name" = :locationName OR "LOC_INV"."name" = :locationName OR "INS_LOC"."name" = :locationName',
|
|
58
|
+
{ locationName }
|
|
59
|
+
)
|
|
56
60
|
}
|
|
57
61
|
|
|
58
62
|
if (cartonId) {
|
|
@@ -94,6 +98,7 @@ export const cycleCountWorksheetForPalletResolver = {
|
|
|
94
98
|
qty: inventory?.qty,
|
|
95
99
|
uomValue: inventory?.uomValue,
|
|
96
100
|
uom: inventory?.uom,
|
|
101
|
+
originLocation: targetInventoryCheckItem?.originLocation,
|
|
97
102
|
inspectedQty: targetInventoryCheckItem?.inspectedQty,
|
|
98
103
|
inspectedUomValue: targetInventoryCheckItem?.inspectedUomValue,
|
|
99
104
|
inspectedLocation: targetInventoryCheckItem?.inspectedLocation,
|
|
@@ -101,7 +106,11 @@ export const cycleCountWorksheetForPalletResolver = {
|
|
|
101
106
|
status: cycleCountWSD.status,
|
|
102
107
|
targetName: targetInventoryCheckItem?.name,
|
|
103
108
|
packingType: inventory?.packingType ? inventory.packingType : productDetails.packingType,
|
|
104
|
-
location:
|
|
109
|
+
location: targetInventoryCheckItem?.originLocation
|
|
110
|
+
? targetInventoryCheckItem.originLocation
|
|
111
|
+
: inventory?.location
|
|
112
|
+
? inventory.location
|
|
113
|
+
: targetInventoryCheckItem.inspectedLocation,
|
|
105
114
|
relatedInvCheckItem: targetInventoryCheckItem
|
|
106
115
|
}
|
|
107
116
|
})
|
|
@@ -529,12 +529,12 @@ async function queryPackingWorksheet(tx, domain, assignee, binLocation) {
|
|
|
529
529
|
.innerJoinAndSelect('rg.orderInventories', 'oi')
|
|
530
530
|
.innerJoinAndSelect('oi.binLocation', 'l')
|
|
531
531
|
.leftJoinAndSelect('rg.orderPackages', 'op')
|
|
532
|
-
.
|
|
533
|
-
.
|
|
534
|
-
.
|
|
535
|
-
.
|
|
536
|
-
.
|
|
537
|
-
.
|
|
532
|
+
.leftJoinAndSelect('op.orderPackageItems', 'opi')
|
|
533
|
+
.leftJoinAndSelect('opi.orderProduct', 'opr')
|
|
534
|
+
.leftJoinAndSelect('opi.productDetail', 'pd')
|
|
535
|
+
.leftJoinAndSelect('pd.product', 'p')
|
|
536
|
+
.leftJoinAndSelect('p.productDetails', 'pd2')
|
|
537
|
+
.leftJoinAndSelect('pd2.productBarcodes', 'pb')
|
|
538
538
|
.innerJoin('worksheets', 'w', 'w.release_good_id = rg.id')
|
|
539
539
|
.where('rg.domain_id = :domainId', { domainId: domain.id })
|
|
540
540
|
.andWhere('oi.status IN (:...orderInventoryStatus)', {
|
|
@@ -555,19 +555,6 @@ async function queryPackingWorksheet(tx, domain, assignee, binLocation) {
|
|
|
555
555
|
.addOrderBy('rg.status', 'ASC')
|
|
556
556
|
.addOrderBy('w.created_at', 'ASC')
|
|
557
557
|
|
|
558
|
-
if (assignee) {
|
|
559
|
-
qb.andWhere('ws.assignee_id = :assigneeId', { assigneeId: assignee.id })
|
|
560
|
-
} else {
|
|
561
|
-
qb.andWhere('ws.assignee_id is null')
|
|
562
|
-
}
|
|
563
|
-
|
|
564
|
-
qb.orderBy('releaseGood.status', 'ASC')
|
|
565
|
-
.addOrderBy('ws.created_at', 'ASC')
|
|
566
|
-
.addOrderBy('releaseGood.name', 'ASC')
|
|
567
|
-
.groupBy('ws.created_at')
|
|
568
|
-
.addGroupBy('releaseGood.name')
|
|
569
|
-
.addGroupBy('releaseGood.id')
|
|
570
|
-
|
|
571
558
|
let releaseGood = await qb.getOne()
|
|
572
559
|
|
|
573
560
|
if (!releaseGood) {
|
package/server/utils/lmd-util.ts
CHANGED
|
@@ -123,7 +123,7 @@ export async function createLmdParcel(releaseGoods, tx, domain, user, marketplac
|
|
|
123
123
|
address3: releaseGood?.deliveryAddress3,
|
|
124
124
|
ward: releaseGood?.ward?.toUpperCase(), //only for viettel lmd
|
|
125
125
|
city: releaseGood.city?.toUpperCase(),
|
|
126
|
-
postcode: releaseGood
|
|
126
|
+
postcode: releaseGood?.postalCode,
|
|
127
127
|
district: releaseGood?.district?.toUpperCase() || releaseGood.city?.toUpperCase(),
|
|
128
128
|
state:
|
|
129
129
|
releaseGood?.state?.toUpperCase() ||
|