@things-factory/warehouse-base 4.1.18 → 4.1.27
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/service/inventory/inventory-mutation.js +18 -8
- package/dist-server/service/inventory/inventory-mutation.js.map +1 -1
- package/dist-server/service/inventory/inventory-types.js +7 -7
- package/dist-server/service/inventory/inventory-types.js.map +1 -1
- package/dist-server/service/inventory/inventory.js +6 -0
- package/dist-server/service/inventory/inventory.js.map +1 -1
- package/dist-server/service/inventory-change/inventory-change-mutation.js +45 -20
- package/dist-server/service/inventory-change/inventory-change-mutation.js.map +1 -1
- package/dist-server/service/inventory-change/inventory-change.js +5 -0
- package/dist-server/service/inventory-change/inventory-change.js.map +1 -1
- package/dist-server/service/inventory-history/inventory-history-query.js +104 -0
- package/dist-server/service/inventory-history/inventory-history-query.js.map +1 -1
- package/dist-server/service/inventory-history/inventory-history-types.js +121 -1
- package/dist-server/service/inventory-history/inventory-history-types.js.map +1 -1
- package/dist-server/service/inventory-history/inventory-history.js +7 -2
- package/dist-server/service/inventory-history/inventory-history.js.map +1 -1
- package/dist-server/utils/inventory-util.js +106 -4
- package/dist-server/utils/inventory-util.js.map +1 -1
- package/package.json +8 -8
- package/server/service/inventory/inventory-mutation.ts +49 -13
- package/server/service/inventory/inventory-types.ts +6 -6
- package/server/service/inventory/inventory.ts +5 -0
- package/server/service/inventory-change/inventory-change-mutation.ts +41 -12
- package/server/service/inventory-change/inventory-change.ts +4 -0
- package/server/service/inventory-history/inventory-history-query.ts +124 -1
- package/server/service/inventory-history/inventory-history-types.ts +86 -0
- package/server/service/inventory-history/inventory-history.ts +6 -2
- package/server/utils/inventory-util.ts +136 -13
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getProductBundleInventory = exports.checkPalletIdenticallity = exports.checkPalletDuplication = exports.switchLocationStatus = exports.generateInventoryHistory = exports.InventoryUtil = void 0;
|
|
3
|
+
exports.getInventoriesByStrategy = exports.getProductBundleInventory = exports.checkPalletIdenticallity = exports.checkPalletDuplication = exports.switchLocationStatus = exports.generateInventoryHistory = exports.InventoryUtil = void 0;
|
|
4
4
|
const typeorm_1 = require("typeorm");
|
|
5
5
|
const product_base_1 = require("@things-factory/product-base");
|
|
6
6
|
const constants_1 = require("../constants");
|
|
@@ -107,11 +107,11 @@ async function generateInventoryHistory(inventory, refOrder, transactionType, qt
|
|
|
107
107
|
const lastInvHistory = await invHistoryRepo.findOne({
|
|
108
108
|
where: {
|
|
109
109
|
domain: inventory.domain,
|
|
110
|
-
palletId: inventory.palletId
|
|
110
|
+
palletId: inventory.palletId
|
|
111
111
|
},
|
|
112
112
|
order: {
|
|
113
113
|
seq: 'DESC'
|
|
114
|
-
}
|
|
114
|
+
}
|
|
115
115
|
});
|
|
116
116
|
let seq = 0;
|
|
117
117
|
let openingQty = 0;
|
|
@@ -121,7 +121,7 @@ async function generateInventoryHistory(inventory, refOrder, transactionType, qt
|
|
|
121
121
|
openingUomValue = lastInvHistory.openingUomValue + lastInvHistory.uomValue;
|
|
122
122
|
seq = lastInvHistory.seq + 1;
|
|
123
123
|
}
|
|
124
|
-
let remainQty = (
|
|
124
|
+
let remainQty = (openingQty || 0) + (qty || 0);
|
|
125
125
|
let inventoryHistory = new service_1.InventoryHistory();
|
|
126
126
|
inventoryHistory = Object.assign(Object.assign({}, inventory), { name: utils_1.InventoryNoGenerator.inventoryHistoryName(), inventory, seq: seq, status: remainQty == 0 ? constants_1.INVENTORY_STATUS.TERMINATED : inventory.status, transactionType, refOrderId: (refOrder === null || refOrder === void 0 ? void 0 : refOrder.id) || null, orderNo: (refOrder === null || refOrder === void 0 ? void 0 : refOrder.name) || null, orderRefNo: (refOrder === null || refOrder === void 0 ? void 0 : refOrder.refNo) || null, qty,
|
|
127
127
|
openingQty,
|
|
@@ -247,4 +247,106 @@ async function getProductBundleInventory(domain, productOwnerDomain, orderProduc
|
|
|
247
247
|
return result;
|
|
248
248
|
}
|
|
249
249
|
exports.getProductBundleInventory = getProductBundleInventory;
|
|
250
|
+
/**
|
|
251
|
+
* @description This function will return multiple products
|
|
252
|
+
* and it is different with @inventoriesByStrategy that returns
|
|
253
|
+
* inventories for one product only
|
|
254
|
+
* @param {string} bizplaceId
|
|
255
|
+
* @param {string} worksheetId
|
|
256
|
+
* @param {any[]} orderProducts
|
|
257
|
+
* @param {string} pickingStrategy
|
|
258
|
+
* @param {[Object]} locationSortingRules
|
|
259
|
+
* @param {EntityManager} trxMgr
|
|
260
|
+
* @returns inventories for multiple products
|
|
261
|
+
*/
|
|
262
|
+
async function getInventoriesByStrategy(domainId, bizplaceId, worksheetId, orderProducts, pickingStrategy, locationSortingRules, trxMgr) {
|
|
263
|
+
let orderProductsJSON = JSON.stringify(orderProducts);
|
|
264
|
+
let orderBy = 'ORDER BY op."productId"';
|
|
265
|
+
let locationSortings = (locationSortingRules || []).map((rule) => {
|
|
266
|
+
return `, l.${rule.name} ${rule.descOrder ? 'DESC' : ''}`;
|
|
267
|
+
});
|
|
268
|
+
switch (pickingStrategy.toUpperCase()) {
|
|
269
|
+
case 'FIFO':
|
|
270
|
+
orderBy += ', i.created_at';
|
|
271
|
+
if (locationSortingRules === null || locationSortingRules === void 0 ? void 0 : locationSortingRules.length) {
|
|
272
|
+
orderBy += locationSortings.join('');
|
|
273
|
+
}
|
|
274
|
+
break;
|
|
275
|
+
case 'LIFO':
|
|
276
|
+
orderBy += ', i.created_at DESC';
|
|
277
|
+
if (locationSortingRules === null || locationSortingRules === void 0 ? void 0 : locationSortingRules.length) {
|
|
278
|
+
orderBy += locationSortings.join('');
|
|
279
|
+
}
|
|
280
|
+
break;
|
|
281
|
+
case 'FEFO':
|
|
282
|
+
orderBy += ', i.expiration_date';
|
|
283
|
+
if (locationSortingRules === null || locationSortingRules === void 0 ? void 0 : locationSortingRules.length) {
|
|
284
|
+
orderBy += locationSortings.join('');
|
|
285
|
+
}
|
|
286
|
+
break;
|
|
287
|
+
case 'LOCATION':
|
|
288
|
+
if (locationSortingRules === null || locationSortingRules === void 0 ? void 0 : locationSortingRules.length) {
|
|
289
|
+
orderBy += locationSortings.join('');
|
|
290
|
+
}
|
|
291
|
+
else
|
|
292
|
+
orderBy += ', l.name DESC';
|
|
293
|
+
break;
|
|
294
|
+
default:
|
|
295
|
+
orderBy += ', i.created_at';
|
|
296
|
+
break;
|
|
297
|
+
}
|
|
298
|
+
await trxMgr.query(`
|
|
299
|
+
CREATE TEMP TABLE temp_op2(
|
|
300
|
+
"productId" VARCHAR(50),
|
|
301
|
+
"batchId" VARCHAR(50),
|
|
302
|
+
"packingType" VARCHAR(50),
|
|
303
|
+
"packingSize" INT,
|
|
304
|
+
"uom" VARCHAR(10),
|
|
305
|
+
"releaseQty" INT
|
|
306
|
+
);
|
|
307
|
+
`);
|
|
308
|
+
await trxMgr.query(`
|
|
309
|
+
INSERT INTO temp_op2
|
|
310
|
+
SELECT "productId", "batchId", "packingType", "packingSize", "uom", "releaseQty"
|
|
311
|
+
FROM JSON_POPULATE_RECORDSET(NULL::temp_op2, $1) js
|
|
312
|
+
`, [orderProductsJSON]);
|
|
313
|
+
await trxMgr.query(`
|
|
314
|
+
CREATE TEMP TABLE acc_oi2 AS (
|
|
315
|
+
SELECT oi.inventory_id, SUM(oi.release_qty) AS total_release_qty, SUM(oi.release_uom_value) AS total_release_uom_value
|
|
316
|
+
FROM order_inventories oi
|
|
317
|
+
WHERE oi.status IN ('PENDING','PENDING_RECEIVE','PENDING_WORKSHEET','PENDING_SPLIT')
|
|
318
|
+
AND oi.bizplace_id = $1
|
|
319
|
+
AND oi.inventory_id NOTNULL
|
|
320
|
+
AND oi.ref_worksheet_id != $2
|
|
321
|
+
GROUP BY oi.inventory_id
|
|
322
|
+
)
|
|
323
|
+
`, [bizplaceId, worksheetId]);
|
|
324
|
+
// get inventories
|
|
325
|
+
let inventories = await trxMgr.query(`
|
|
326
|
+
SELECT
|
|
327
|
+
i.id,
|
|
328
|
+
op."productId",
|
|
329
|
+
op."batchId",
|
|
330
|
+
i.qty - COALESCE(i.locked_qty,0) - COALESCE(foo.total_release_qty,0) AS "remainQty",
|
|
331
|
+
i.uom_value - COALESCE(i.locked_uom_value,0) - COALESCE(foo.total_release_uom_value,0) AS "remainUomValue",
|
|
332
|
+
op."packingType",
|
|
333
|
+
op."packingSize",
|
|
334
|
+
op."uom"
|
|
335
|
+
FROM inventories i
|
|
336
|
+
INNER JOIN locations l ON i.location_id = l.id
|
|
337
|
+
AND l.TYPE NOT IN ($1, $2)
|
|
338
|
+
INNER JOIN temp_op2 op ON i.product_id = op."productId"::uuid
|
|
339
|
+
AND i.batch_id = op."batchId"
|
|
340
|
+
AND i.packing_type = op."packingType"
|
|
341
|
+
AND i.packing_size = op."packingSize"
|
|
342
|
+
LEFT JOIN acc_oi2 foo ON i.id = foo.inventory_id
|
|
343
|
+
WHERE i.domain_id = $3
|
|
344
|
+
AND i.bizplace_id = $4
|
|
345
|
+
AND i.status = $5
|
|
346
|
+
${orderBy}
|
|
347
|
+
`, [constants_1.LOCATION_TYPE.QUARANTINE, constants_1.LOCATION_TYPE.RESERVE, domainId, bizplaceId, constants_1.INVENTORY_STATUS.STORED]);
|
|
348
|
+
await trxMgr.query('DROP TABLE temp_op2, acc_oi2');
|
|
349
|
+
return inventories;
|
|
350
|
+
}
|
|
351
|
+
exports.getInventoriesByStrategy = getInventoriesByStrategy;
|
|
250
352
|
//# sourceMappingURL=inventory-util.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inventory-util.js","sourceRoot":"","sources":["../../server/utils/inventory-util.ts"],"names":[],"mappings":";;;AAAA,qCAAkE;AAIlE,+DAAsD;AAGtD,
|
|
1
|
+
{"version":3,"file":"inventory-util.js","sourceRoot":"","sources":["../../server/utils/inventory-util.ts"],"names":[],"mappings":";;;AAAA,qCAAkE;AAIlE,+DAAsD;AAGtD,4CAA2G;AAC3G,wCAAkE;AACl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AiB,CAAC,CACpB,CAAA;IAED,MAAM,MAAM,CAAC,KAAK,CAChB;;;;;;;;;;GAUD,EACC,CAAC,UAAU,EAAE,WAAW,CAAC,CAC1B,CAAA;IAED,kBAAkB;IAClB,IAAI,WAAW,GAAG,MAAM,MAAM,CAAC,KAAK,CAClC;;;;;;;;;;;;;;;;;;;;;MAqBE,OAAO;GACV,EACC,CAAC,yBAAa,CAAC,UAAU,EAAE,yBAAa,CAAC,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,4BAAgB,CAAC,MAAM,CAAC,CACjG,CAAA;IAED,MAAM,MAAM,CAAC,KAAK,CAAC,8BAA8B,CAAC,CAAA;IAElD,OAAO,WAAW,CAAA;AACpB,CAAC;AArHD,4DAqHC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@things-factory/warehouse-base",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.27",
|
|
4
4
|
"main": "dist-server/index.js",
|
|
5
5
|
"browser": "client/index.js",
|
|
6
6
|
"things-factory": true,
|
|
@@ -24,12 +24,12 @@
|
|
|
24
24
|
"migration:create": "node ../../node_modules/typeorm/cli.js migration:create -d ./server/migrations"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@things-factory/biz-base": "^4.1.
|
|
28
|
-
"@things-factory/id-rule-base": "^4.1.
|
|
29
|
-
"@things-factory/integration-sellercraft": "^4.1.
|
|
30
|
-
"@things-factory/marketplace-base": "^4.1.
|
|
31
|
-
"@things-factory/product-base": "^4.1.
|
|
32
|
-
"@things-factory/setting-base": "^4.1.
|
|
27
|
+
"@things-factory/biz-base": "^4.1.27",
|
|
28
|
+
"@things-factory/id-rule-base": "^4.1.27",
|
|
29
|
+
"@things-factory/integration-sellercraft": "^4.1.27",
|
|
30
|
+
"@things-factory/marketplace-base": "^4.1.27",
|
|
31
|
+
"@things-factory/product-base": "^4.1.27",
|
|
32
|
+
"@things-factory/setting-base": "^4.1.27"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "d2bcc934a52e1a2f68738ec8b56ad72503172f6f"
|
|
35
35
|
}
|
|
@@ -7,7 +7,7 @@ import { Product } from '@things-factory/product-base'
|
|
|
7
7
|
import { generateId } from '@things-factory/id-rule-base'
|
|
8
8
|
import { Domain } from '@things-factory/shell'
|
|
9
9
|
|
|
10
|
-
import { RULE_TYPE, INVENTORY_STATUS, INVENTORY_TRANSACTION_TYPE } from '../../constants'
|
|
10
|
+
import { RULE_TYPE, INVENTORY_STATUS, INVENTORY_TRANSACTION_TYPE, LOCATION_STATUS } from '../../constants'
|
|
11
11
|
import { generateInventoryHistory, InventoryNoGenerator, InventoryUtil, DateGenerator } from '../../utils'
|
|
12
12
|
import { InventoryHistory } from '../inventory-history/inventory-history'
|
|
13
13
|
import { Location } from '../location/location'
|
|
@@ -345,6 +345,10 @@ export class InventoryMutation {
|
|
|
345
345
|
): Promise<Boolean> {
|
|
346
346
|
const { domain, user, tx }: { domain: Domain; user: User; tx: EntityManager } = context.state
|
|
347
347
|
|
|
348
|
+
const fromLocation: Location = await tx.getRepository(Location).findOne({
|
|
349
|
+
where: { domain: domain, name: fromLocationName },
|
|
350
|
+
relations: ['domain', 'warehouse']
|
|
351
|
+
})
|
|
348
352
|
// 1. check toLocation exist
|
|
349
353
|
const toLocation: Location = await tx.getRepository(Location).findOne({
|
|
350
354
|
where: { domain: domain, name: toLocationName },
|
|
@@ -370,24 +374,32 @@ export class InventoryMutation {
|
|
|
370
374
|
let inventory: Inventory = await invQb.getOne()
|
|
371
375
|
if (!inventory) throw new Error('Inventory not found')
|
|
372
376
|
|
|
373
|
-
if (qty >
|
|
377
|
+
if (qty > inventory.qty - (inventory?.lockedQty > 0 ? inventory.lockedQty : 0))
|
|
378
|
+
throw new Error('Transfer quantity exceeded inventory quantity')
|
|
374
379
|
|
|
375
380
|
if (toLocation.name == inventory.location.name) throw new Error('Inventory is in current location')
|
|
376
381
|
|
|
377
382
|
let transactionInventory = new InventoryUtil(tx, domain, user)
|
|
378
383
|
|
|
379
|
-
const partialTransferFunc = async function (inventory, qty, toLocation, cartonId, palletId, context) {
|
|
384
|
+
const partialTransferFunc = async function (inventory, qty, fromLocation, toLocation, cartonId, palletId, context) {
|
|
380
385
|
const { user, tx }: { domain: Domain; user: User; tx: EntityManager } = context.state
|
|
381
386
|
|
|
382
|
-
if (qty <
|
|
387
|
+
if (qty < inventory.qty - (inventory?.lockedQty > 0 ? inventory.lockedQty : 0)) {
|
|
383
388
|
if (!palletId || palletId.trim() == '') throw new Error('Require new lot id for partial transfer')
|
|
384
389
|
|
|
385
390
|
let transferQty = qty
|
|
386
|
-
let transferUomValue = (
|
|
387
|
-
let newInventory = {
|
|
391
|
+
let transferUomValue = (inventory.uomValue / inventory.qty) * qty
|
|
392
|
+
let newInventory = {
|
|
393
|
+
...inventory,
|
|
394
|
+
palletId,
|
|
395
|
+
location: toLocation,
|
|
396
|
+
warehouse: toLocation.warehouse,
|
|
397
|
+
zone: toLocation.zone,
|
|
398
|
+
creator: user,
|
|
399
|
+
updater: user
|
|
400
|
+
}
|
|
388
401
|
|
|
389
402
|
delete newInventory.id
|
|
390
|
-
delete newInventory.createdAt
|
|
391
403
|
delete newInventory.updatedAt
|
|
392
404
|
|
|
393
405
|
newInventory.cartonId = cartonId
|
|
@@ -396,14 +408,38 @@ export class InventoryMutation {
|
|
|
396
408
|
newInventory.uomValue = transferUomValue
|
|
397
409
|
newInventory.lockedUomValue = 0
|
|
398
410
|
|
|
399
|
-
await transactionInventory.transactionInventory(
|
|
400
|
-
|
|
401
|
-
|
|
411
|
+
await transactionInventory.transactionInventory(
|
|
412
|
+
{ ...inventory, qty: inventory.qty - transferQty, uomValue: inventory.uomValue - transferUomValue },
|
|
413
|
+
null,
|
|
414
|
+
-transferQty,
|
|
415
|
+
-transferUomValue,
|
|
416
|
+
INVENTORY_TRANSACTION_TYPE.RELOCATE
|
|
417
|
+
)
|
|
418
|
+
|
|
419
|
+
await transactionInventory.transactionInventory(
|
|
420
|
+
newInventory,
|
|
421
|
+
null,
|
|
422
|
+
transferQty,
|
|
423
|
+
transferUomValue,
|
|
424
|
+
INVENTORY_TRANSACTION_TYPE.RELOCATE
|
|
425
|
+
)
|
|
402
426
|
} else {
|
|
403
427
|
inventory.warehouse = toLocation.warehouse
|
|
404
428
|
inventory.location = toLocation
|
|
405
429
|
inventory.zone = toLocation.zone
|
|
406
430
|
inventory.updater = user
|
|
431
|
+
inventory.cartonId = cartonId
|
|
432
|
+
|
|
433
|
+
let isEmptyLocation = await tx.getRepository(Inventory).find({
|
|
434
|
+
where: { location: fromLocation }
|
|
435
|
+
})
|
|
436
|
+
|
|
437
|
+
if ((isEmptyLocation.length = 1)) {
|
|
438
|
+
await tx.getRepository(Location).save({
|
|
439
|
+
...fromLocation,
|
|
440
|
+
status: LOCATION_STATUS.EMPTY
|
|
441
|
+
})
|
|
442
|
+
}
|
|
407
443
|
|
|
408
444
|
await transactionInventory.transactionInventory(inventory, null, 0, 0, INVENTORY_TRANSACTION_TYPE.RELOCATE)
|
|
409
445
|
}
|
|
@@ -412,7 +448,7 @@ export class InventoryMutation {
|
|
|
412
448
|
if (inventory.cartonId && inventory.cartonId != '') {
|
|
413
449
|
if (!cartonId) throw new Error('Require carton id')
|
|
414
450
|
|
|
415
|
-
if (qty <
|
|
451
|
+
if (qty < inventory.qty - (inventory?.lockedQty > 0 ? inventory.lockedQty : 0)) {
|
|
416
452
|
palletId = await generateId({
|
|
417
453
|
domain: domain,
|
|
418
454
|
type: RULE_TYPE.LOT_NUMBER_ID,
|
|
@@ -420,9 +456,9 @@ export class InventoryMutation {
|
|
|
420
456
|
})
|
|
421
457
|
}
|
|
422
458
|
|
|
423
|
-
await partialTransferFunc(inventory, qty, toLocation, cartonId, palletId, context)
|
|
459
|
+
await partialTransferFunc(inventory, qty, fromLocation, toLocation, cartonId, palletId, context)
|
|
424
460
|
} else {
|
|
425
|
-
await partialTransferFunc(inventory, qty, toLocation, null, palletId, context)
|
|
461
|
+
await partialTransferFunc(inventory, qty, fromLocation, toLocation, null, palletId, context)
|
|
426
462
|
}
|
|
427
463
|
|
|
428
464
|
return true
|
|
@@ -2,7 +2,7 @@ import { Field, Float, InputType, Int, ObjectType } from 'type-graphql'
|
|
|
2
2
|
|
|
3
3
|
import { User } from '@things-factory/auth-base'
|
|
4
4
|
import { ProductBundleSetting } from '@things-factory/product-base'
|
|
5
|
-
import { Domain, ObjectRef } from '@things-factory/shell'
|
|
5
|
+
import { Domain, ObjectRef, ScalarDate } from '@things-factory/shell'
|
|
6
6
|
|
|
7
7
|
import { Inventory } from './inventory'
|
|
8
8
|
|
|
@@ -65,7 +65,7 @@ export class InventoryPatch {
|
|
|
65
65
|
@Field({ nullable: true })
|
|
66
66
|
reusablePalletId?: string
|
|
67
67
|
|
|
68
|
-
@Field({ nullable: true })
|
|
68
|
+
@Field(type => ObjectRef, { nullable: true })
|
|
69
69
|
location?: ObjectRef
|
|
70
70
|
|
|
71
71
|
@Field({ nullable: true })
|
|
@@ -116,8 +116,8 @@ export class InventoryPatch {
|
|
|
116
116
|
@Field({ nullable: true })
|
|
117
117
|
expirationDate?: string
|
|
118
118
|
|
|
119
|
-
@Field(type =>
|
|
120
|
-
|
|
119
|
+
@Field(type => ScalarDate, { nullable: true })
|
|
120
|
+
manufactureDate: Date
|
|
121
121
|
|
|
122
122
|
@Field(type => Float, { nullable: true })
|
|
123
123
|
unitCost?: number
|
|
@@ -200,8 +200,8 @@ export class NewInventory {
|
|
|
200
200
|
@Field({ nullable: true })
|
|
201
201
|
expirationDate?: string
|
|
202
202
|
|
|
203
|
-
@Field(type =>
|
|
204
|
-
|
|
203
|
+
@Field(type => ScalarDate, { nullable: true })
|
|
204
|
+
manufactureDate: Date
|
|
205
205
|
}
|
|
206
206
|
|
|
207
207
|
@ObjectType()
|
|
@@ -123,6 +123,10 @@ export class Inventory {
|
|
|
123
123
|
@Field({ nullable: true })
|
|
124
124
|
manufactureYear: number
|
|
125
125
|
|
|
126
|
+
@Column('date', { nullable: true })
|
|
127
|
+
@Field(type => ScalarDate, { nullable: true })
|
|
128
|
+
manufactureDate: Date
|
|
129
|
+
|
|
126
130
|
@Column('float', { nullable: true })
|
|
127
131
|
@Field({ nullable: true })
|
|
128
132
|
costPrice: number
|
|
@@ -287,6 +291,7 @@ export class Inventory {
|
|
|
287
291
|
this.expirationDate = obj.Inventory_expiration_date
|
|
288
292
|
this.unitCost = obj.Inventory_unit_cost
|
|
289
293
|
this.manufactureYear = obj.Inventory_manufacture_year
|
|
294
|
+
this.manufactureDate = obj.Inventory_manufacture_date
|
|
290
295
|
this.batchIdRef = obj.Inventory_batch_id_ref
|
|
291
296
|
this.cartonId = obj.Inventory_carton_id
|
|
292
297
|
this.packingSize = obj.Inventory_packing_size
|
|
@@ -135,8 +135,26 @@ export class InventoryChangeMutation {
|
|
|
135
135
|
) {
|
|
136
136
|
const { domain, user, tx }: { domain: Domain; user: User; tx: EntityManager } = context.state
|
|
137
137
|
|
|
138
|
-
const _createRecords =
|
|
139
|
-
const _updateRecords =
|
|
138
|
+
const _createRecords = []
|
|
139
|
+
const _updateRecords = []
|
|
140
|
+
|
|
141
|
+
for (let i = 0; i < patches.length; i++) {
|
|
142
|
+
let foundExistingPallet = await tx.getRepository(Inventory).findOne({
|
|
143
|
+
where: { domain, palletId: patches[i]?.palletId }
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
if (!foundExistingPallet) {
|
|
147
|
+
foundExistingPallet = await tx.getRepository(Inventory).findOne({
|
|
148
|
+
where: { id: patches[i]?.id }
|
|
149
|
+
})
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (foundExistingPallet) {
|
|
153
|
+
_updateRecords.push(patches[i])
|
|
154
|
+
} else {
|
|
155
|
+
_createRecords.push(patches[i])
|
|
156
|
+
}
|
|
157
|
+
}
|
|
140
158
|
|
|
141
159
|
const inventoryChangeRepo = tx.getRepository(InventoryChange)
|
|
142
160
|
if (_createRecords.length > 0) {
|
|
@@ -180,10 +198,17 @@ export class InventoryChangeMutation {
|
|
|
180
198
|
const updateRecord = _updateRecords[i]
|
|
181
199
|
|
|
182
200
|
let existingRecord = await tx.getRepository(Inventory).findOne({
|
|
183
|
-
where: {
|
|
201
|
+
where: { domain, palletId: updateRecord?.palletId },
|
|
184
202
|
relations: ['location', 'warehouse', 'product', 'bizplace']
|
|
185
203
|
})
|
|
186
204
|
|
|
205
|
+
if (!existingRecord) {
|
|
206
|
+
existingRecord = await tx.getRepository(Inventory).findOne({
|
|
207
|
+
where: { domain, id: updateRecord?.id },
|
|
208
|
+
relations: ['location', 'warehouse', 'product', 'bizplace']
|
|
209
|
+
})
|
|
210
|
+
}
|
|
211
|
+
|
|
187
212
|
if (!!updateRecord?.location?.id) {
|
|
188
213
|
var location = await tx.getRepository(Location).findOne({
|
|
189
214
|
where: { id: updateRecord.location.id },
|
|
@@ -519,15 +544,19 @@ export class InventoryChangeMutation {
|
|
|
519
544
|
|
|
520
545
|
const dateStr = yy + mm + dd
|
|
521
546
|
|
|
522
|
-
let palletId =
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
547
|
+
let palletId = newRecord.palletId
|
|
548
|
+
|
|
549
|
+
if (!newRecord.palletId?.trim()) {
|
|
550
|
+
palletId = await generateId({
|
|
551
|
+
domain: domain,
|
|
552
|
+
type: 'adjustment_pallet_id',
|
|
553
|
+
seed: {
|
|
554
|
+
batchId: newRecord.batchId,
|
|
555
|
+
date: dateStr
|
|
556
|
+
}
|
|
557
|
+
})
|
|
558
|
+
if (!palletId) throw new Error('No adjustment pallet id setting rule found')
|
|
559
|
+
}
|
|
531
560
|
|
|
532
561
|
var location = await tx.getRepository(Location).findOne({
|
|
533
562
|
where: { id: newRecord.location.id },
|
|
@@ -127,6 +127,10 @@ export class InventoryChange {
|
|
|
127
127
|
@Field({ nullable: true })
|
|
128
128
|
manufactureYear: number
|
|
129
129
|
|
|
130
|
+
@Column('date', { nullable: true })
|
|
131
|
+
@Field(type => ScalarDate, { nullable: true })
|
|
132
|
+
manufactureDate: Date
|
|
133
|
+
|
|
130
134
|
@Column()
|
|
131
135
|
@Field()
|
|
132
136
|
transactionType: string
|
|
@@ -4,8 +4,9 @@ import { Between, Brackets, EntityManager, getRepository, In, Raw, SelectQueryBu
|
|
|
4
4
|
import { User } from '@things-factory/auth-base'
|
|
5
5
|
import { Bizplace, getMyBizplace, getPermittedBizplaceIds } from '@things-factory/biz-base'
|
|
6
6
|
import { Product } from '@things-factory/product-base'
|
|
7
|
-
import { convertListParams, Domain, Filter, ListParam, Pagination, Sorting } from '@things-factory/shell'
|
|
7
|
+
import { buildQuery, convertListParams, Domain, Filter, ListParam, Pagination, Sorting } from '@things-factory/shell'
|
|
8
8
|
|
|
9
|
+
import { RawInventoryHistoryList } from '../'
|
|
9
10
|
import { InventoryList } from '../inventory/inventory-types'
|
|
10
11
|
import { Location } from '../location/location'
|
|
11
12
|
import { Warehouse } from '../warehouse/warehouse'
|
|
@@ -1172,6 +1173,128 @@ export class InventoryHistoryQuery {
|
|
|
1172
1173
|
return { items, total: total[0].count }
|
|
1173
1174
|
}
|
|
1174
1175
|
|
|
1176
|
+
@Directive('@transaction')
|
|
1177
|
+
@Query(returns => RawInventoryHistoryList)
|
|
1178
|
+
async bizplaceInventoryHistoriesForExport(
|
|
1179
|
+
@Ctx() context: any,
|
|
1180
|
+
@Arg('inventoryHistory', type => InventoryHistoryPatch, { nullable: true })
|
|
1181
|
+
inventoryHistory?: InventoryHistoryPatch,
|
|
1182
|
+
@Arg('filters', type => [Filter], { nullable: true }) filters?: Filter[]
|
|
1183
|
+
): Promise<RawInventoryHistoryList> {
|
|
1184
|
+
const { domain, tx }: { domain: Domain; user: User; tx: EntityManager } = context.state
|
|
1185
|
+
|
|
1186
|
+
const customerBizplace: Bizplace = await tx.getRepository(Bizplace).findOne(inventoryHistory.bizplace.id)
|
|
1187
|
+
|
|
1188
|
+
const productFilters = filters.find(x => x.name == 'product_info')
|
|
1189
|
+
filters = filters.filter(x => x.name != 'product_info')
|
|
1190
|
+
|
|
1191
|
+
const fromDate: Date = new Date(inventoryHistory.fromDate)
|
|
1192
|
+
const toDate: Date = new Date(inventoryHistory.toDate)
|
|
1193
|
+
|
|
1194
|
+
if (productFilters) {
|
|
1195
|
+
let productFilterValue = `%${productFilters.value.toLowerCase()}%`
|
|
1196
|
+
const productQb: SelectQueryBuilder<Product> = getRepository(Product).createQueryBuilder('prd')
|
|
1197
|
+
|
|
1198
|
+
productQb.where(
|
|
1199
|
+
new Brackets(qb => {
|
|
1200
|
+
qb.where('Lower(prd.sku) LIKE :productInfo', { productInfo: productFilterValue })
|
|
1201
|
+
.orWhere('Lower(prd.name) LIKE :productInfo', { productInfo: productFilterValue })
|
|
1202
|
+
.orWhere('Lower(prd.description) LIKE :productInfo', { productInfo: productFilterValue })
|
|
1203
|
+
.orWhere('Lower(prd.brand) LIKE :productInfo', { productInfo: productFilterValue })
|
|
1204
|
+
})
|
|
1205
|
+
)
|
|
1206
|
+
|
|
1207
|
+
const _products = await productQb.getMany()
|
|
1208
|
+
|
|
1209
|
+
filters.push({
|
|
1210
|
+
name: 'product_id',
|
|
1211
|
+
operator: 'in',
|
|
1212
|
+
value: _products.map((product: Product) => product.id)
|
|
1213
|
+
})
|
|
1214
|
+
}
|
|
1215
|
+
|
|
1216
|
+
if (inventoryHistory && inventoryHistory.warehouseName) {
|
|
1217
|
+
const _warehouses: Warehouse[] = await tx.getRepository(Warehouse).find({
|
|
1218
|
+
domain: domain,
|
|
1219
|
+
name: Raw(alias => `LOWER(${alias}) LIKE '${inventoryHistory.warehouseName.toLowerCase()}'`)
|
|
1220
|
+
})
|
|
1221
|
+
|
|
1222
|
+
filters.push({
|
|
1223
|
+
name: 'warehouse_id',
|
|
1224
|
+
operator: 'in',
|
|
1225
|
+
value: _warehouses.map((warehouse: Warehouse) => warehouse.id)
|
|
1226
|
+
})
|
|
1227
|
+
}
|
|
1228
|
+
|
|
1229
|
+
if (inventoryHistory && inventoryHistory.locationName) {
|
|
1230
|
+
const _locations = await tx.getRepository(Location).find({
|
|
1231
|
+
where: {
|
|
1232
|
+
domain: domain,
|
|
1233
|
+
name: Raw(alias => `LOWER(${alias}) LIKE '${inventoryHistory.locationName.toLowerCase()}'`)
|
|
1234
|
+
}
|
|
1235
|
+
})
|
|
1236
|
+
|
|
1237
|
+
filters.push({
|
|
1238
|
+
name: 'location_id',
|
|
1239
|
+
operator: 'in',
|
|
1240
|
+
value: _locations.map((location: Location) => location.id)
|
|
1241
|
+
})
|
|
1242
|
+
}
|
|
1243
|
+
|
|
1244
|
+
filters.push(
|
|
1245
|
+
{
|
|
1246
|
+
name: 'createdAt',
|
|
1247
|
+
operator: 'between',
|
|
1248
|
+
value: [fromDate, toDate]
|
|
1249
|
+
},
|
|
1250
|
+
{
|
|
1251
|
+
name: 'bizplace_id',
|
|
1252
|
+
operator: 'eq',
|
|
1253
|
+
value: customerBizplace.id
|
|
1254
|
+
}
|
|
1255
|
+
)
|
|
1256
|
+
|
|
1257
|
+
const qb: SelectQueryBuilder<InventoryHistory> = getRepository(InventoryHistory).createQueryBuilder('ih')
|
|
1258
|
+
buildQuery(qb, { filters }, context)
|
|
1259
|
+
|
|
1260
|
+
qb.select('prd.sku', 'sku')
|
|
1261
|
+
.addSelect('prd.name', 'productName')
|
|
1262
|
+
.addSelect('prd.description', 'productDescription')
|
|
1263
|
+
.addSelect('prd.brand', 'brand')
|
|
1264
|
+
.addSelect('ih.seq', 'seq')
|
|
1265
|
+
.addSelect('ih.pallet_id', 'palletId')
|
|
1266
|
+
.addSelect('ih.carton_id', 'cartonId')
|
|
1267
|
+
.addSelect('ih.batch_id', 'batchId')
|
|
1268
|
+
.addSelect('ih.batch_id_ref', 'batchIdRef')
|
|
1269
|
+
.addSelect('ih.opening_qty', 'openingQty')
|
|
1270
|
+
.addSelect('ih.qty', 'qty')
|
|
1271
|
+
.addSelect('ih.opening_uom_value', 'openingUomValue')
|
|
1272
|
+
.addSelect('ih.uom_value', 'uomValue')
|
|
1273
|
+
.addSelect('ih.uom', 'uom')
|
|
1274
|
+
.addSelect('ih.zone', 'zone')
|
|
1275
|
+
.addSelect('ih.order_no', 'orderNo')
|
|
1276
|
+
.addSelect('ih.order_ref_no', 'refNo')
|
|
1277
|
+
.addSelect('ih.status', 'status')
|
|
1278
|
+
.addSelect('ih.transaction_type', 'transactionType')
|
|
1279
|
+
.addSelect('bzp.name', 'bizplace')
|
|
1280
|
+
.addSelect('wh.name', 'warehouse')
|
|
1281
|
+
.addSelect('lc.name', 'location')
|
|
1282
|
+
.addSelect('ih.created_at', 'createdAt')
|
|
1283
|
+
.addSelect('ih.updated_at', 'updatedAt')
|
|
1284
|
+
.addSelect('up.name', 'updater')
|
|
1285
|
+
.leftJoin('ih.product', 'prd')
|
|
1286
|
+
.leftJoin('ih.warehouse', 'wh')
|
|
1287
|
+
.leftJoin('ih.location', 'lc')
|
|
1288
|
+
.leftJoin('ih.bizplace', 'bzp')
|
|
1289
|
+
.leftJoin('ih.updater', 'up')
|
|
1290
|
+
.orderBy('ih.pallet_id')
|
|
1291
|
+
.addOrderBy('ih.seq')
|
|
1292
|
+
|
|
1293
|
+
const [items, total] = await Promise.all([qb.getRawMany(), qb.getCount()])
|
|
1294
|
+
|
|
1295
|
+
return { items, total }
|
|
1296
|
+
}
|
|
1297
|
+
|
|
1175
1298
|
@FieldResolver(type => Domain)
|
|
1176
1299
|
async domain(@Root() inventoryHistory: InventoryHistory) {
|
|
1177
1300
|
return await getRepository(Domain).findOne(inventoryHistory.domainId)
|