@things-factory/warehouse-base 6.2.126 → 6.2.128
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/index.js +3 -1
- package/dist-server/index.js.map +1 -1
- package/dist-server/service/inventory/inventory-mutation.js +140 -136
- package/dist-server/service/inventory/inventory-mutation.js.map +1 -1
- package/dist-server/service/inventory/inventory-query.js +4 -10
- package/dist-server/service/inventory/inventory-query.js.map +1 -1
- package/dist-server/service/pallet/pallet-query.js +1 -1
- package/dist-server/service/pallet/pallet-query.js.map +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/server/index.ts +2 -6
- package/server/service/inventory/inventory-mutation.ts +222 -218
- package/server/service/inventory/inventory-query.ts +14 -66
- package/server/service/pallet/pallet-query.ts +2 -6
package/dist-server/index.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.approveInventoryChanges = exports.updateWarehouse = exports.deleteWarehouses = exports.deleteWarehouse = exports.createWarehouse = exports.updateLocation = exports.deleteLocations = exports.deleteLocation = exports.createLocation = void 0;
|
|
3
|
+
exports.approveInventoryChanges = exports.updateWarehouse = exports.deleteWarehouses = exports.deleteWarehouse = exports.createWarehouse = exports.updateLocation = exports.deleteLocations = exports.deleteLocation = exports.createLocation = exports.updateMultipleInventory = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
tslib_1.__exportStar(require("./constants"), exports);
|
|
6
|
+
var inventory_mutation_1 = require("./service/inventory/inventory-mutation");
|
|
7
|
+
Object.defineProperty(exports, "updateMultipleInventory", { enumerable: true, get: function () { return inventory_mutation_1.updateMultipleInventory; } });
|
|
6
8
|
var location_mutation_1 = require("./service/location/location-mutation");
|
|
7
9
|
Object.defineProperty(exports, "createLocation", { enumerable: true, get: function () { return location_mutation_1.createLocation; } });
|
|
8
10
|
Object.defineProperty(exports, "deleteLocation", { enumerable: true, get: function () { return location_mutation_1.deleteLocation; } });
|
package/dist-server/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../server/index.ts"],"names":[],"mappings":";;;;AAAA,sDAA2B;AAC3B,0EAAsH;AAA7G,mHAAA,cAAc,OAAA;AAAE,mHAAA,cAAc,OAAA;AAAE,oHAAA,eAAe,OAAA;AAAE,mHAAA,cAAc,OAAA;AACxE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../server/index.ts"],"names":[],"mappings":";;;;AAAA,sDAA2B;AAC3B,6EAAgF;AAAvE,6HAAA,uBAAuB,OAAA;AAChC,0EAAsH;AAA7G,mHAAA,cAAc,OAAA;AAAE,mHAAA,cAAc,OAAA;AAAE,oHAAA,eAAe,OAAA;AAAE,mHAAA,cAAc,OAAA;AACxE,6EAA4H;AAAnH,qHAAA,eAAe,OAAA;AAAE,qHAAA,eAAe,OAAA;AAAE,sHAAA,gBAAgB,OAAA;AAAE,qHAAA,eAAe,OAAA;AAC5E,uDAA4B;AAC5B,kDAAuB;AACvB,oDAAyB;AACzB,8EAAmD;AAEnD,kGAA8F;AAArF,oIAAA,uBAAuB,OAAA","sourcesContent":["export * from './constants'\nexport { updateMultipleInventory } from './service/inventory/inventory-mutation'\nexport { createLocation, deleteLocation, deleteLocations, updateLocation } from './service/location/location-mutation'\nexport { createWarehouse, deleteWarehouse, deleteWarehouses, updateWarehouse } from './service/warehouse/warehouse-mutation'\nexport * from './migrations'\nexport * from './utils'\nexport * from './service'\nexport * from './service/inventory/inventory-query'\n\nexport { approveInventoryChanges } from './service/inventory-change/inventory-change-mutation'\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.InventoryMutation = void 0;
|
|
3
|
+
exports.updateMultipleInventory = exports.InventoryMutation = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const type_graphql_1 = require("type-graphql");
|
|
6
6
|
const typeorm_1 = require("typeorm");
|
|
@@ -50,141 +50,7 @@ let InventoryMutation = class InventoryMutation {
|
|
|
50
50
|
return true;
|
|
51
51
|
}
|
|
52
52
|
async updateMultipleInventory(patches, context) {
|
|
53
|
-
|
|
54
|
-
let results = [];
|
|
55
|
-
const _createRecords = patches.filter((patch) => !patch.id);
|
|
56
|
-
const _updateRecords = patches.filter((patch) => patch.id);
|
|
57
|
-
const inventoryRepo = tx.getRepository(inventory_1.Inventory);
|
|
58
|
-
if (_createRecords.length > 0) {
|
|
59
|
-
let today = new Date();
|
|
60
|
-
let year = today.getFullYear();
|
|
61
|
-
let month = today.getMonth();
|
|
62
|
-
let date = today.getDate();
|
|
63
|
-
for (let i = 0; i < _createRecords.length; i++) {
|
|
64
|
-
const total = await tx.getRepository(inventory_1.Inventory).countBy({
|
|
65
|
-
createdAt: (0, typeorm_1.MoreThan)(new Date(year, month, date))
|
|
66
|
-
});
|
|
67
|
-
const newRecord = _createRecords[i];
|
|
68
|
-
if (newRecord.location && newRecord.location.id) {
|
|
69
|
-
var location = await tx.getRepository(location_1.Location).findOne({
|
|
70
|
-
where: { id: newRecord.location.id },
|
|
71
|
-
relations: ['warehouse']
|
|
72
|
-
});
|
|
73
|
-
newRecord.location = location;
|
|
74
|
-
newRecord.zone = location.zone;
|
|
75
|
-
newRecord.warehouse = location.warehouse;
|
|
76
|
-
}
|
|
77
|
-
if (newRecord.bizplace && newRecord.bizplace.id) {
|
|
78
|
-
newRecord.bizplace = (await tx.getRepository(biz_base_1.Bizplace).findOneBy({ id: newRecord.bizplace.id }));
|
|
79
|
-
}
|
|
80
|
-
if (newRecord.product && newRecord.product.id) {
|
|
81
|
-
var product = (await tx.getRepository(product_base_1.Product).findOneBy({ id: newRecord.product.id }));
|
|
82
|
-
newRecord.product = product;
|
|
83
|
-
}
|
|
84
|
-
let palletId = 'P' +
|
|
85
|
-
year.toString().substr(year.toString().length - 2) +
|
|
86
|
-
('0' + (month + 1).toString()).substr(('0' + (month + 1).toString()).toString().length - 2) +
|
|
87
|
-
('0' + date.toString()).substr(('0' + date.toString()).length - 2) +
|
|
88
|
-
('0000' + (total + 1).toString()).substr(('0000' + (total + 1).toString()).length - 4);
|
|
89
|
-
newRecord.name = palletId;
|
|
90
|
-
newRecord.status = newRecord.qty < 1 ? 'TERMINATED' : 'STORED';
|
|
91
|
-
newRecord.palletId = palletId;
|
|
92
|
-
const result = await inventoryRepo.save(Object.assign({ domain: domain, creator: user, updater: user, lastSeq: 0 }, newRecord));
|
|
93
|
-
await tx.getRepository(inventory_history_1.InventoryHistory).save(Object.assign(Object.assign({}, newRecord), { domain: domain, creator: user, updater: user, name: utils_1.InventoryNoGenerator.inventoryHistoryName(), seq: 0, transactionType: 'NEW', productId: newRecord.product.id, warehouseId: newRecord.warehouse.id, locationId: newRecord.location.id }));
|
|
94
|
-
results.push(Object.assign(Object.assign({}, result), { cuFlag: '+' }));
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
if (_updateRecords.length > 0) {
|
|
98
|
-
for (let i = 0; i < _updateRecords.length; i++) {
|
|
99
|
-
const newRecord = _updateRecords[i];
|
|
100
|
-
const newHistoryRecord = JSON.parse(JSON.stringify(_updateRecords[i]));
|
|
101
|
-
let transactionType = '';
|
|
102
|
-
let inventory = await inventoryRepo.findOne({
|
|
103
|
-
where: { id: newRecord.id },
|
|
104
|
-
relations: ['warehouse', 'location', 'product', 'bizplace']
|
|
105
|
-
});
|
|
106
|
-
newHistoryRecord.openingQty = inventory.qty;
|
|
107
|
-
newHistoryRecord.openingUomValue = inventory.uomValue;
|
|
108
|
-
// Get last sequence from InventoryHistory
|
|
109
|
-
let latestEntry = await tx.getRepository(inventory_history_1.InventoryHistory).find({
|
|
110
|
-
where: { palletId: inventory.palletId },
|
|
111
|
-
order: { seq: 'DESC' },
|
|
112
|
-
take: 1
|
|
113
|
-
});
|
|
114
|
-
let lastSeq = latestEntry[0].seq;
|
|
115
|
-
// Condition 1: Change location (RELOCATE)
|
|
116
|
-
if (newRecord.location && newRecord.location.id) {
|
|
117
|
-
var location = await tx.getRepository(location_1.Location).findOne({
|
|
118
|
-
where: { id: newRecord.location.id },
|
|
119
|
-
relations: ['warehouse']
|
|
120
|
-
});
|
|
121
|
-
newRecord.location = location;
|
|
122
|
-
newRecord.zone = location.zone;
|
|
123
|
-
newRecord.warehouse = location.warehouse;
|
|
124
|
-
newHistoryRecord.location = location;
|
|
125
|
-
newHistoryRecord.zone = location.zone;
|
|
126
|
-
newHistoryRecord.warehouse = location.warehouse;
|
|
127
|
-
transactionType = 'RELOCATE';
|
|
128
|
-
}
|
|
129
|
-
// Condition 2: Change of qty or uomValue.
|
|
130
|
-
// Set qty movement for inventory history
|
|
131
|
-
if (typeof newRecord.qty != 'undefined') {
|
|
132
|
-
transactionType = 'ADJUSTMENT';
|
|
133
|
-
newHistoryRecord.qty = newRecord.qty - inventory.qty;
|
|
134
|
-
if (newRecord.qty < 1) {
|
|
135
|
-
newRecord.status = 'TERMINATED';
|
|
136
|
-
newRecord.qty = 0;
|
|
137
|
-
newRecord.uomValue = 0;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
else {
|
|
141
|
-
newHistoryRecord.qty = 0;
|
|
142
|
-
}
|
|
143
|
-
// Set uomValue movement for inventory history
|
|
144
|
-
if (typeof newRecord.uomValue != 'undefined') {
|
|
145
|
-
transactionType = 'ADJUSTMENT';
|
|
146
|
-
newHistoryRecord.uomValue = newRecord.uomValue - inventory.uomValue;
|
|
147
|
-
if (newRecord.uomValue < 1) {
|
|
148
|
-
newRecord.uomValue = 0;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
else {
|
|
152
|
-
newHistoryRecord.uomValue = 0;
|
|
153
|
-
}
|
|
154
|
-
// Condition 3: Change of bizplace or product or batch id or packing type
|
|
155
|
-
if (newRecord.bizplace && newRecord.bizplace.id) {
|
|
156
|
-
newRecord.bizplace = (await tx.getRepository(biz_base_1.Bizplace).findOneBy({ id: newRecord.bizplace.id }));
|
|
157
|
-
}
|
|
158
|
-
if (newRecord.product && newRecord.product.id) {
|
|
159
|
-
newRecord.product = (await tx.getRepository(product_base_1.Product).findOneBy({ id: newRecord.product.id }));
|
|
160
|
-
}
|
|
161
|
-
if ((newRecord.product && newRecord.product.id) || (newRecord.bizplace && newRecord.bizplace.id) || newRecord.batchId || newRecord.packingType) {
|
|
162
|
-
if (inventory.bizplace.id !== (newRecord.bizplace ? newRecord.bizplace.id : '') ||
|
|
163
|
-
inventory.product.id !== (newRecord.product ? newRecord.product.id : '') ||
|
|
164
|
-
inventory.batchId !== newRecord.batchId ||
|
|
165
|
-
inventory.packingType !== newRecord.packingType) {
|
|
166
|
-
transactionType = 'ADJUSTMENT';
|
|
167
|
-
lastSeq = lastSeq + 1;
|
|
168
|
-
let inventoryHistory = Object.assign(Object.assign({}, inventory), { domain: domain, bizplace: inventory.bizplace.id, openingQty: inventory.qty, openingUomValue: inventory.uomValue, qty: -inventory.qty || 0, uomValue: -inventory.uomValue || 0, name: utils_1.InventoryNoGenerator.inventoryHistoryName(), seq: lastSeq, inventory, transactionType: transactionType, status: constants_1.INVENTORY_STATUS.TERMINATED, productId: inventory.product.id, warehouseId: inventory.warehouse.id, locationId: inventory.location.id, creator: user, updater: user });
|
|
169
|
-
delete inventoryHistory.id;
|
|
170
|
-
await tx.getRepository(inventory_history_1.InventoryHistory).save(inventoryHistory);
|
|
171
|
-
newHistoryRecord.qty = newRecord.qty || inventory.qty;
|
|
172
|
-
newHistoryRecord.uomValue = newRecord.uomValue || inventory.uomValue || 0;
|
|
173
|
-
newHistoryRecord.openingQty = 0;
|
|
174
|
-
newHistoryRecord.openingUomValue = 0;
|
|
175
|
-
newHistoryRecord.batchId = newRecord.batchId || inventory.batchId || '-';
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
//Transaction type will be RELOCATE if there is only location change. Any other changes will be considered Adjustment.
|
|
179
|
-
lastSeq = lastSeq + 1;
|
|
180
|
-
let inventoryHistory = Object.assign(Object.assign(Object.assign({}, inventory), newHistoryRecord), { domain: domain, creator: user, updater: user, name: utils_1.InventoryNoGenerator.inventoryHistoryName(), seq: lastSeq, inventory, transactionType: transactionType == '' ? 'ADJUSTMENT' : transactionType, productId: newHistoryRecord.product ? newHistoryRecord.product.id : inventory.product.id, warehouseId: newHistoryRecord.warehouse ? newHistoryRecord.warehouse.id : inventory.warehouse.id, locationId: newHistoryRecord.location ? newHistoryRecord.location.id : inventory.location.id });
|
|
181
|
-
delete inventoryHistory.id;
|
|
182
|
-
await tx.getRepository(inventory_history_1.InventoryHistory).save(inventoryHistory);
|
|
183
|
-
const result = await inventoryRepo.save(Object.assign(Object.assign(Object.assign({}, inventory), newRecord), { updater: user, lastSeq: lastSeq }));
|
|
184
|
-
results.push(Object.assign(Object.assign({}, result), { cuFlag: 'M' }));
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
return results;
|
|
53
|
+
return await updateMultipleInventory(patches, context);
|
|
188
54
|
}
|
|
189
55
|
async deleteInventories(ids, context) {
|
|
190
56
|
const { tx } = context.state;
|
|
@@ -390,4 +256,142 @@ InventoryMutation = tslib_1.__decorate([
|
|
|
390
256
|
(0, type_graphql_1.Resolver)(inventory_1.Inventory)
|
|
391
257
|
], InventoryMutation);
|
|
392
258
|
exports.InventoryMutation = InventoryMutation;
|
|
259
|
+
async function updateMultipleInventory(patches, context) {
|
|
260
|
+
const { domain, user, tx } = context.state;
|
|
261
|
+
let results = [];
|
|
262
|
+
const _createRecords = patches.filter((patch) => !patch.id);
|
|
263
|
+
const _updateRecords = patches.filter((patch) => patch.id);
|
|
264
|
+
const inventoryRepo = tx.getRepository(inventory_1.Inventory);
|
|
265
|
+
if (_createRecords.length > 0) {
|
|
266
|
+
let today = new Date();
|
|
267
|
+
let year = today.getFullYear();
|
|
268
|
+
let month = today.getMonth();
|
|
269
|
+
let date = today.getDate();
|
|
270
|
+
for (let i = 0; i < _createRecords.length; i++) {
|
|
271
|
+
const total = await tx.getRepository(inventory_1.Inventory).countBy({
|
|
272
|
+
createdAt: (0, typeorm_1.MoreThan)(new Date(year, month, date))
|
|
273
|
+
});
|
|
274
|
+
const newRecord = _createRecords[i];
|
|
275
|
+
if (newRecord.location && newRecord.location.id) {
|
|
276
|
+
var location = await tx.getRepository(location_1.Location).findOne({
|
|
277
|
+
where: { id: newRecord.location.id },
|
|
278
|
+
relations: ['warehouse']
|
|
279
|
+
});
|
|
280
|
+
newRecord.location = location;
|
|
281
|
+
newRecord.zone = location.zone;
|
|
282
|
+
newRecord.warehouse = location.warehouse;
|
|
283
|
+
}
|
|
284
|
+
if (newRecord.bizplace && newRecord.bizplace.id) {
|
|
285
|
+
newRecord.bizplace = (await tx.getRepository(biz_base_1.Bizplace).findOneBy({ id: newRecord.bizplace.id }));
|
|
286
|
+
}
|
|
287
|
+
if (newRecord.product && newRecord.product.id) {
|
|
288
|
+
var product = (await tx.getRepository(product_base_1.Product).findOneBy({ id: newRecord.product.id }));
|
|
289
|
+
newRecord.product = product;
|
|
290
|
+
}
|
|
291
|
+
let palletId = 'P' +
|
|
292
|
+
year.toString().substr(year.toString().length - 2) +
|
|
293
|
+
('0' + (month + 1).toString()).substr(('0' + (month + 1).toString()).toString().length - 2) +
|
|
294
|
+
('0' + date.toString()).substr(('0' + date.toString()).length - 2) +
|
|
295
|
+
('0000' + (total + 1).toString()).substr(('0000' + (total + 1).toString()).length - 4);
|
|
296
|
+
newRecord.name = palletId;
|
|
297
|
+
newRecord.status = newRecord.qty < 1 ? 'TERMINATED' : 'STORED';
|
|
298
|
+
newRecord.palletId = palletId;
|
|
299
|
+
const result = await inventoryRepo.save(Object.assign({ domain: domain, creator: user, updater: user, lastSeq: 0 }, newRecord));
|
|
300
|
+
await tx.getRepository(inventory_history_1.InventoryHistory).save(Object.assign(Object.assign({}, newRecord), { domain: domain, creator: user, updater: user, name: utils_1.InventoryNoGenerator.inventoryHistoryName(), seq: 0, transactionType: 'NEW', productId: newRecord.product.id, warehouseId: newRecord.warehouse.id, locationId: newRecord.location.id }));
|
|
301
|
+
results.push(Object.assign(Object.assign({}, result), { cuFlag: '+' }));
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
if (_updateRecords.length > 0) {
|
|
305
|
+
for (let i = 0; i < _updateRecords.length; i++) {
|
|
306
|
+
const newRecord = _updateRecords[i];
|
|
307
|
+
const newHistoryRecord = JSON.parse(JSON.stringify(_updateRecords[i]));
|
|
308
|
+
let transactionType = '';
|
|
309
|
+
let inventory = await inventoryRepo.findOne({
|
|
310
|
+
where: { id: newRecord.id },
|
|
311
|
+
relations: ['warehouse', 'location', 'product', 'bizplace']
|
|
312
|
+
});
|
|
313
|
+
newHistoryRecord.openingQty = inventory.qty;
|
|
314
|
+
newHistoryRecord.openingUomValue = inventory.uomValue;
|
|
315
|
+
// Get last sequence from InventoryHistory
|
|
316
|
+
let latestEntry = await tx.getRepository(inventory_history_1.InventoryHistory).find({
|
|
317
|
+
where: { palletId: inventory.palletId },
|
|
318
|
+
order: { seq: 'DESC' },
|
|
319
|
+
take: 1
|
|
320
|
+
});
|
|
321
|
+
let lastSeq = latestEntry[0].seq;
|
|
322
|
+
// Condition 1: Change location (RELOCATE)
|
|
323
|
+
if (newRecord.location && newRecord.location.id) {
|
|
324
|
+
var location = await tx.getRepository(location_1.Location).findOne({
|
|
325
|
+
where: { id: newRecord.location.id },
|
|
326
|
+
relations: ['warehouse']
|
|
327
|
+
});
|
|
328
|
+
newRecord.location = location;
|
|
329
|
+
newRecord.zone = location.zone;
|
|
330
|
+
newRecord.warehouse = location.warehouse;
|
|
331
|
+
newHistoryRecord.location = location;
|
|
332
|
+
newHistoryRecord.zone = location.zone;
|
|
333
|
+
newHistoryRecord.warehouse = location.warehouse;
|
|
334
|
+
transactionType = 'RELOCATE';
|
|
335
|
+
}
|
|
336
|
+
// Condition 2: Change of qty or uomValue.
|
|
337
|
+
// Set qty movement for inventory history
|
|
338
|
+
if (typeof newRecord.qty != 'undefined') {
|
|
339
|
+
transactionType = 'ADJUSTMENT';
|
|
340
|
+
newHistoryRecord.qty = newRecord.qty - inventory.qty;
|
|
341
|
+
if (newRecord.qty < 1) {
|
|
342
|
+
newRecord.status = 'TERMINATED';
|
|
343
|
+
newRecord.qty = 0;
|
|
344
|
+
newRecord.uomValue = 0;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
else {
|
|
348
|
+
newHistoryRecord.qty = 0;
|
|
349
|
+
}
|
|
350
|
+
// Set uomValue movement for inventory history
|
|
351
|
+
if (typeof newRecord.uomValue != 'undefined') {
|
|
352
|
+
transactionType = 'ADJUSTMENT';
|
|
353
|
+
newHistoryRecord.uomValue = newRecord.uomValue - inventory.uomValue;
|
|
354
|
+
if (newRecord.uomValue < 1) {
|
|
355
|
+
newRecord.uomValue = 0;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
else {
|
|
359
|
+
newHistoryRecord.uomValue = 0;
|
|
360
|
+
}
|
|
361
|
+
// Condition 3: Change of bizplace or product or batch id or packing type
|
|
362
|
+
if (newRecord.bizplace && newRecord.bizplace.id) {
|
|
363
|
+
newRecord.bizplace = (await tx.getRepository(biz_base_1.Bizplace).findOneBy({ id: newRecord.bizplace.id }));
|
|
364
|
+
}
|
|
365
|
+
if (newRecord.product && newRecord.product.id) {
|
|
366
|
+
newRecord.product = (await tx.getRepository(product_base_1.Product).findOneBy({ id: newRecord.product.id }));
|
|
367
|
+
}
|
|
368
|
+
if ((newRecord.product && newRecord.product.id) || (newRecord.bizplace && newRecord.bizplace.id) || newRecord.batchId || newRecord.packingType) {
|
|
369
|
+
if (inventory.bizplace.id !== (newRecord.bizplace ? newRecord.bizplace.id : '') ||
|
|
370
|
+
inventory.product.id !== (newRecord.product ? newRecord.product.id : '') ||
|
|
371
|
+
inventory.batchId !== newRecord.batchId ||
|
|
372
|
+
inventory.packingType !== newRecord.packingType) {
|
|
373
|
+
transactionType = 'ADJUSTMENT';
|
|
374
|
+
lastSeq = lastSeq + 1;
|
|
375
|
+
let inventoryHistory = Object.assign(Object.assign({}, inventory), { domain: domain, bizplace: inventory.bizplace.id, openingQty: inventory.qty, openingUomValue: inventory.uomValue, qty: -inventory.qty || 0, uomValue: -inventory.uomValue || 0, name: utils_1.InventoryNoGenerator.inventoryHistoryName(), seq: lastSeq, inventory, transactionType: transactionType, status: constants_1.INVENTORY_STATUS.TERMINATED, productId: inventory.product.id, warehouseId: inventory.warehouse.id, locationId: inventory.location.id, creator: user, updater: user });
|
|
376
|
+
delete inventoryHistory.id;
|
|
377
|
+
await tx.getRepository(inventory_history_1.InventoryHistory).save(inventoryHistory);
|
|
378
|
+
newHistoryRecord.qty = newRecord.qty || inventory.qty;
|
|
379
|
+
newHistoryRecord.uomValue = newRecord.uomValue || inventory.uomValue || 0;
|
|
380
|
+
newHistoryRecord.openingQty = 0;
|
|
381
|
+
newHistoryRecord.openingUomValue = 0;
|
|
382
|
+
newHistoryRecord.batchId = newRecord.batchId || inventory.batchId || '-';
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
//Transaction type will be RELOCATE if there is only location change. Any other changes will be considered Adjustment.
|
|
386
|
+
lastSeq = lastSeq + 1;
|
|
387
|
+
let inventoryHistory = Object.assign(Object.assign(Object.assign({}, inventory), newHistoryRecord), { domain: domain, creator: user, updater: user, name: utils_1.InventoryNoGenerator.inventoryHistoryName(), seq: lastSeq, inventory, transactionType: transactionType == '' ? 'ADJUSTMENT' : transactionType, productId: newHistoryRecord.product ? newHistoryRecord.product.id : inventory.product.id, warehouseId: newHistoryRecord.warehouse ? newHistoryRecord.warehouse.id : inventory.warehouse.id, locationId: newHistoryRecord.location ? newHistoryRecord.location.id : inventory.location.id });
|
|
388
|
+
delete inventoryHistory.id;
|
|
389
|
+
await tx.getRepository(inventory_history_1.InventoryHistory).save(inventoryHistory);
|
|
390
|
+
const result = await inventoryRepo.save(Object.assign(Object.assign(Object.assign({}, inventory), newRecord), { updater: user, lastSeq: lastSeq }));
|
|
391
|
+
results.push(Object.assign(Object.assign({}, result), { cuFlag: 'M' }));
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
return results;
|
|
395
|
+
}
|
|
396
|
+
exports.updateMultipleInventory = updateMultipleInventory;
|
|
393
397
|
//# sourceMappingURL=inventory-mutation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inventory-mutation.js","sourceRoot":"","sources":["../../../server/service/inventory/inventory-mutation.ts"],"names":[],"mappings":";;;;AAAA,+CAAsE;AACtE,qCAA0D;AAE1D,uDAAmD;AACnD,+DAAyD;AACzD,qFAAwF;AACxF,+DAAsD;AAEtD,+CAA0G;AAC1G,mDAAyD;AACzD,uCAAgF;AAChF,8EAAyE;AACzE,mDAA+C;AAC/C,2CAAuC;AACvC,uDAAgE;AAGzD,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAItB,AAAN,KAAK,CAAC,eAAe,CAAmB,SAAuB,EAAS,OAAwB;QAC9F,MAAM,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAE5B,OAAO,MAAM,EAAE,CAAC,aAAa,CAAC,qBAAS,CAAC,CAAC,IAAI,iBAC3C,MAAM,EAAE,OAAO,CAAC,KAAK,CAAC,MAAM,EAC5B,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,IAAI,EAC3B,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,IAAI,IACxB,SAAS,EACZ,CAAA;IACJ,CAAC;IAKK,AAAN,KAAK,CAAC,eAAe,CAAe,KAAqB,EAAS,OAAwB;QACxF,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAE1C,MAAM,KAAK,GAAkC,MAAM,EAAE;aAClD,aAAa,CAAC,qBAAS,CAAC;aACxB,kBAAkB,CAAC,KAAK,CAAC;aACzB,KAAK,CAAC,2BAA2B,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iB","sourcesContent":["import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'\nimport { In, MoreThan, SelectQueryBuilder } from 'typeorm'\n\nimport { Bizplace } from '@things-factory/biz-base'\nimport { generateId } from '@things-factory/id-rule-base'\nimport { Sellercraft, SellercraftStatus } from '@things-factory/integration-sellercraft'\nimport { Product } from '@things-factory/product-base'\n\nimport { INVENTORY_STATUS, INVENTORY_TRANSACTION_TYPE, LOCATION_STATUS, RULE_TYPE } from '../../constants'\nimport { SellercraftController } from '../../controllers'\nimport { DateGenerator, InventoryNoGenerator, InventoryUtil } from '../../utils'\nimport { InventoryHistory } from '../inventory-history/inventory-history'\nimport { Location } from '../location/location'\nimport { Inventory } from './inventory'\nimport { InventoryPatch, NewInventory } from './inventory-types'\n\n@Resolver(Inventory)\nexport class InventoryMutation {\n @Directive('@privilege(category: \"inventory\", privilege: \"mutation\")')\n @Directive('@transaction')\n @Mutation(returns => Inventory)\n async createInventory(@Arg('inventory') inventory: NewInventory, @Ctx() context: ResolverContext): Promise<Inventory> {\n const { tx } = context.state\n\n return await tx.getRepository(Inventory).save({\n domain: context.state.domain,\n creator: context.state.user,\n updater: context.state.user,\n ...inventory\n })\n }\n\n @Directive('@privilege(category: \"inventory\", privilege: \"mutation\")')\n @Directive('@transaction')\n @Mutation(returns => Inventory)\n async updateInventory(@Arg('patch') patch: InventoryPatch, @Ctx() context: ResolverContext): Promise<Inventory> {\n const { domain, user, tx } = context.state\n\n const invQb: SelectQueryBuilder<Inventory> = await tx\n .getRepository(Inventory)\n .createQueryBuilder('INV')\n .where('INV.domain_id = :domainId', { domainId: domain.id })\n .andWhere('INV.bizplace_id = :bizplaceId', { bizplaceId: patch.bizplace.id })\n .andWhere('INV.batch_id = :batchId', { batchId: patch.batchId })\n .andWhere('INV.product_id = :productId', { productId: patch.product.id })\n .andWhere('INV.packing_type = :packingType', { packingType: patch.packingType })\n .andWhere('INV.packing_size = :packingSize', { packingSize: patch.packingSize })\n\n if (patch?.cartonId) invQb.andWhere('INV.carton_id = :cartonId', { cartonId: patch.cartonId })\n else invQb.andWhere('INV.pallet_id = :palletId', { palletId: patch.palletId })\n\n const inventory = await invQb.getOne()\n\n return await tx.getRepository(Inventory).save({\n ...inventory,\n ...patch,\n updater: user\n })\n }\n\n @Directive('@privilege(category: \"inventory\", privilege: \"mutation\")')\n @Directive('@transaction')\n @Mutation(returns => Inventory)\n async updateInventoryRemark(@Arg('id') id: string, @Arg('remark') remark: string, @Ctx() context: ResolverContext): Promise<Inventory> {\n const { domain, user, tx } = context.state\n\n const repository = tx.getRepository(Inventory)\n const inventory = await repository.findOne({ where: { domain: { id: domain.id }, id } })\n\n return await repository.save({\n ...inventory,\n remark,\n updater: user\n })\n }\n\n @Directive('@privilege(category: \"inventory\", privilege: \"mutation\")')\n @Directive('@transaction')\n @Mutation(returns => Boolean)\n async deleteInventory(@Arg('name') name: string, @Ctx() context: ResolverContext): Promise<Boolean> {\n const { tx } = context.state\n\n await tx.getRepository(Inventory).delete({ domain: { id: context.state.domain.id }, name })\n return true\n }\n\n @Directive('@privilege(category: \"inventory\", privilege: \"mutation\")')\n @Directive('@transaction')\n @Mutation(returns => [Inventory])\n async updateMultipleInventory(@Arg('patches', type => [InventoryPatch]) patches: InventoryPatch[], @Ctx() context: ResolverContext): Promise<Inventory[]> {\n const { domain, user, tx } = context.state\n\n let results = []\n const _createRecords = patches.filter((patch: any) => !patch.id)\n const _updateRecords = patches.filter((patch: any) => patch.id)\n\n const inventoryRepo = tx.getRepository(Inventory)\n if (_createRecords.length > 0) {\n let today = new Date()\n let year = today.getFullYear()\n let month = today.getMonth()\n let date = today.getDate()\n\n for (let i = 0; i < _createRecords.length; i++) {\n const total = await tx.getRepository(Inventory).countBy({\n createdAt: MoreThan(new Date(year, month, date))\n })\n\n const newRecord = _createRecords[i]\n\n if (newRecord.location && newRecord.location.id) {\n var location = await tx.getRepository(Location).findOne({\n where: { id: newRecord.location.id },\n relations: ['warehouse']\n })\n newRecord.location = location\n newRecord.zone = location.zone\n newRecord.warehouse = location.warehouse\n }\n\n if (newRecord.bizplace && newRecord.bizplace.id) {\n newRecord.bizplace = (await tx.getRepository(Bizplace).findOneBy({ id: newRecord.bizplace.id })) as any\n }\n\n if (newRecord.product && newRecord.product.id) {\n var product = (await tx.getRepository(Product).findOneBy({ id: newRecord.product.id })) as any\n newRecord.product = product\n }\n\n let palletId =\n 'P' +\n year.toString().substr(year.toString().length - 2) +\n ('0' + (month + 1).toString()).substr(('0' + (month + 1).toString()).toString().length - 2) +\n ('0' + date.toString()).substr(('0' + date.toString()).length - 2) +\n ('0000' + (total + 1).toString()).substr(('0000' + (total + 1).toString()).length - 4)\n\n newRecord.name = palletId\n newRecord.status = newRecord.qty < 1 ? 'TERMINATED' : 'STORED'\n newRecord.palletId = palletId\n\n const result = await inventoryRepo.save({\n domain: domain,\n creator: user,\n updater: user,\n lastSeq: 0,\n ...newRecord\n } as any)\n\n await tx.getRepository(InventoryHistory).save({\n ...newRecord,\n domain: domain,\n creator: user,\n updater: user,\n name: InventoryNoGenerator.inventoryHistoryName(),\n seq: 0,\n transactionType: 'NEW',\n productId: newRecord.product.id,\n warehouseId: newRecord.warehouse.id,\n locationId: newRecord.location.id\n })\n\n results.push({ ...result, cuFlag: '+' })\n }\n }\n\n if (_updateRecords.length > 0) {\n for (let i = 0; i < _updateRecords.length; i++) {\n const newRecord = _updateRecords[i]\n const newHistoryRecord = JSON.parse(JSON.stringify(_updateRecords[i]))\n let transactionType = ''\n\n let inventory = await inventoryRepo.findOne({\n where: { id: newRecord.id },\n relations: ['warehouse', 'location', 'product', 'bizplace']\n })\n newHistoryRecord.openingQty = inventory.qty\n newHistoryRecord.openingUomValue = inventory.uomValue\n\n // Get last sequence from InventoryHistory\n let latestEntry = await tx.getRepository(InventoryHistory).find({\n where: { palletId: inventory.palletId },\n order: { seq: 'DESC' },\n take: 1\n })\n let lastSeq = latestEntry[0].seq\n\n // Condition 1: Change location (RELOCATE)\n if (newRecord.location && newRecord.location.id) {\n var location = await tx.getRepository(Location).findOne({\n where: { id: newRecord.location.id },\n relations: ['warehouse']\n })\n newRecord.location = location\n newRecord.zone = location.zone\n newRecord.warehouse = location.warehouse\n\n newHistoryRecord.location = location\n newHistoryRecord.zone = location.zone\n newHistoryRecord.warehouse = location.warehouse\n\n transactionType = 'RELOCATE'\n }\n\n // Condition 2: Change of qty or uomValue.\n // Set qty movement for inventory history\n if (typeof newRecord.qty != 'undefined') {\n transactionType = 'ADJUSTMENT'\n newHistoryRecord.qty = newRecord.qty - inventory.qty\n if (newRecord.qty < 1) {\n newRecord.status = 'TERMINATED'\n newRecord.qty = 0\n newRecord.uomValue = 0\n }\n } else {\n newHistoryRecord.qty = 0\n }\n // Set uomValue movement for inventory history\n if (typeof newRecord.uomValue != 'undefined') {\n transactionType = 'ADJUSTMENT'\n newHistoryRecord.uomValue = newRecord.uomValue - inventory.uomValue\n if (newRecord.uomValue < 1) {\n newRecord.uomValue = 0\n }\n } else {\n newHistoryRecord.uomValue = 0\n }\n\n // Condition 3: Change of bizplace or product or batch id or packing type\n if (newRecord.bizplace && newRecord.bizplace.id) {\n newRecord.bizplace = (await tx.getRepository(Bizplace).findOneBy({ id: newRecord.bizplace.id })) as any\n }\n\n if (newRecord.product && newRecord.product.id) {\n newRecord.product = (await tx.getRepository(Product).findOneBy({ id: newRecord.product.id })) as any\n }\n\n if ((newRecord.product && newRecord.product.id) || (newRecord.bizplace && newRecord.bizplace.id) || newRecord.batchId || newRecord.packingType) {\n if (\n inventory.bizplace.id !== (newRecord.bizplace ? newRecord.bizplace.id : '') ||\n inventory.product.id !== (newRecord.product ? newRecord.product.id : '') ||\n inventory.batchId !== newRecord.batchId ||\n inventory.packingType !== newRecord.packingType\n ) {\n transactionType = 'ADJUSTMENT'\n lastSeq = lastSeq + 1\n let inventoryHistory = {\n ...inventory,\n domain: domain,\n bizplace: inventory.bizplace.id,\n openingQty: inventory.qty,\n openingUomValue: inventory.uomValue,\n qty: -inventory.qty || 0,\n uomValue: -inventory.uomValue || 0,\n name: InventoryNoGenerator.inventoryHistoryName(),\n seq: lastSeq,\n inventory,\n transactionType: transactionType,\n status: INVENTORY_STATUS.TERMINATED,\n productId: inventory.product.id,\n warehouseId: inventory.warehouse.id,\n locationId: inventory.location.id,\n creator: user,\n updater: user\n }\n\n delete inventoryHistory.id\n await tx.getRepository(InventoryHistory).save(inventoryHistory as any)\n\n newHistoryRecord.qty = newRecord.qty || inventory.qty\n newHistoryRecord.uomValue = newRecord.uomValue || inventory.uomValue || 0\n newHistoryRecord.openingQty = 0\n newHistoryRecord.openingUomValue = 0\n newHistoryRecord.batchId = newRecord.batchId || inventory.batchId || '-'\n }\n }\n\n //Transaction type will be RELOCATE if there is only location change. Any other changes will be considered Adjustment.\n lastSeq = lastSeq + 1\n let inventoryHistory = {\n ...inventory,\n ...newHistoryRecord,\n domain: domain,\n creator: user,\n updater: user,\n name: InventoryNoGenerator.inventoryHistoryName(),\n seq: lastSeq,\n inventory,\n transactionType: transactionType == '' ? 'ADJUSTMENT' : transactionType,\n productId: newHistoryRecord.product ? newHistoryRecord.product.id : inventory.product.id,\n warehouseId: newHistoryRecord.warehouse ? newHistoryRecord.warehouse.id : inventory.warehouse.id,\n locationId: newHistoryRecord.location ? newHistoryRecord.location.id : inventory.location.id\n }\n\n delete inventoryHistory.id\n await tx.getRepository(InventoryHistory).save(inventoryHistory)\n\n const result = await inventoryRepo.save({\n ...inventory,\n ...newRecord,\n updater: user,\n lastSeq: lastSeq\n })\n\n results.push({ ...result, cuFlag: 'M' })\n }\n }\n\n return results\n }\n\n @Directive('@privilege(category: \"inventory\", privilege: \"mutation\")')\n @Directive('@transaction')\n @Mutation(returns => Boolean)\n async deleteInventories(@Arg('ids', type => [String]) ids: string[], @Ctx() context: ResolverContext): Promise<Boolean> {\n const { tx } = context.state\n\n await tx.getRepository(Inventory).delete({\n id: In(ids)\n })\n\n return true\n }\n\n @Directive('@privilege(category: \"inventory\", privilege: \"mutation\")')\n @Directive('@transaction')\n @Mutation(returns => Boolean)\n async inventoryTransfer(\n @Arg('originPalletId') originPalletId: string,\n @Arg('palletId', { nullable: true }) palletId: string,\n @Arg('cartonId', { nullable: true }) cartonId: string,\n @Arg('fromLocationName') fromLocationName: string,\n @Arg('toLocationName') toLocationName: string,\n @Arg('qty') qty: number,\n @Arg('reason', { nullable: true }) reason: string,\n @Ctx() context: ResolverContext\n ): Promise<Boolean> {\n const { domain, user, tx } = context.state\n\n const fromLocation: Location = await tx.getRepository(Location).findOne({\n where: { domain: { id: domain.id }, name: fromLocationName },\n relations: ['domain', 'warehouse']\n })\n // 1. check toLocation exist\n const toLocation: Location = await tx.getRepository(Location).findOne({\n where: { domain: { id: domain.id }, name: toLocationName },\n relations: ['domain', 'warehouse']\n })\n if (!toLocation) throw new Error(context.t(`error.To_location_does_not_exists`))\n\n if (qty < 0) throw new Error(`Invalid quantity`)\n\n // 2. search for related inventory\n const invQb: SelectQueryBuilder<Inventory> = await tx\n .getRepository(Inventory)\n .createQueryBuilder('INV')\n .innerJoinAndSelect('INV.location', 'loc')\n .innerJoinAndSelect('INV.product', 'product')\n .innerJoinAndSelect('INV.bizplace', 'bizplace')\n .leftJoinAndSelect('INV.refInventory', 'refInventory')\n .leftJoinAndSelect('INV.reusablePallet', 'reusablePallet')\n .leftJoinAndSelect('INV.productDetail', 'productDetail')\n .leftJoinAndSelect('bizplace.domain', 'domain')\n .leftJoinAndSelect('product.productDetails', 'productDetails')\n .leftJoinAndSelect('INV.originInventory', 'originInventory')\n .where('INV.domain_id = :domainId', { domainId: domain.id })\n .andWhere('INV.pallet_id = :palletId', { palletId: originPalletId })\n\n let inventory: Inventory = await invQb.getOne()\n if (!inventory) throw new Error('Inventory not found')\n\n if (qty > inventory.qty - (inventory?.lockedQty > 0 ? inventory.lockedQty : 0)) throw new Error('Transfer quantity exceeded inventory quantity')\n\n if (toLocation.name == inventory.location.name) throw new Error('Inventory is in current location')\n\n let transactionInventory = new InventoryUtil(tx, domain, user)\n\n const sellercraft: Sellercraft = await tx.getRepository(Sellercraft).findOne({\n where: { domain: { id: inventory.bizplace.domain.id }, status: SellercraftStatus.ACTIVE },\n relations: ['domain']\n })\n\n const partialTransferFunc = async function (inventory, qty, fromLocation, toLocation, cartonId, palletId, context) {\n const { user, tx } = context.state\n\n if (qty < inventory.qty - (inventory?.lockedQty > 0 ? inventory.lockedQty : 0)) {\n if (!palletId || palletId.trim() == '') throw new Error('Require new lot id for partial transfer')\n\n let transferQty = qty\n let transferUomValue = (inventory.uomValue / inventory.qty) * qty\n let newInventory = {\n ...inventory,\n palletId,\n location: toLocation,\n warehouse: toLocation.warehouse,\n zone: toLocation.zone,\n creator: user,\n updater: user\n }\n\n delete newInventory.id\n delete newInventory.updatedAt\n\n newInventory.cartonId = cartonId\n newInventory.qty = transferQty\n newInventory.lockedQty = 0\n newInventory.uomValue = transferUomValue\n newInventory.lockedUomValue = 0\n if (inventory.originInventory?.id) {\n newInventory.originInventory = { id: inventory.originInventory.id }\n } else {\n newInventory.originInventory = { id: inventory.id }\n }\n\n await transactionInventory.transactionInventory(\n { ...inventory, qty: inventory.qty - transferQty, uomValue: inventory.uomValue - transferUomValue },\n null,\n -transferQty,\n -transferUomValue,\n INVENTORY_TRANSACTION_TYPE.RELOCATE,\n reason || null\n )\n\n await transactionInventory.transactionInventory(newInventory, null, transferQty, transferUomValue, INVENTORY_TRANSACTION_TYPE.RELOCATE, reason || null)\n\n if (sellercraft) {\n const sellercraftCtrl: SellercraftController = new SellercraftController(tx, domain, user)\n await sellercraftCtrl.updateSellercraftStock(sellercraft, inventory)\n await sellercraftCtrl.updateSellercraftStock(sellercraft, newInventory)\n }\n } else {\n inventory.warehouse = toLocation.warehouse\n inventory.location = toLocation\n inventory.zone = toLocation.zone\n inventory.updater = user\n inventory.cartonId = cartonId\n\n let isEmptyLocation = await tx.getRepository(Inventory).find({\n where: { location: { id: fromLocation.id } }\n })\n\n if ((isEmptyLocation.length = 1)) {\n await tx.getRepository(Location).save({\n ...fromLocation,\n status: LOCATION_STATUS.EMPTY\n })\n }\n\n await transactionInventory.transactionInventory(inventory, null, 0, 0, INVENTORY_TRANSACTION_TYPE.RELOCATE, reason || null)\n\n if (sellercraft) {\n const sellercraftCtrl: SellercraftController = new SellercraftController(tx, domain, user)\n await sellercraftCtrl.updateSellercraftStock(sellercraft, inventory)\n }\n }\n }\n\n if (inventory.cartonId && inventory.cartonId != '') {\n if (!cartonId) throw new Error('Require carton id')\n\n if (qty < inventory.qty - (inventory?.lockedQty > 0 ? inventory.lockedQty : 0)) {\n palletId = await generateId({\n domain: domain,\n type: RULE_TYPE.LOT_NUMBER_ID,\n seed: { date: DateGenerator.generateDate() }\n })\n }\n\n await partialTransferFunc(inventory, qty, fromLocation, toLocation, cartonId, palletId, context)\n } else {\n if (!palletId) {\n palletId = await generateId({\n domain: domain,\n type: RULE_TYPE.LOT_NUMBER_ID,\n seed: { date: DateGenerator.generateDate() }\n })\n }\n await partialTransferFunc(inventory, qty, fromLocation, toLocation, null, palletId, context)\n }\n\n return true\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"inventory-mutation.js","sourceRoot":"","sources":["../../../server/service/inventory/inventory-mutation.ts"],"names":[],"mappings":";;;;AAAA,+CAAsE;AACtE,qCAA0D;AAE1D,uDAAmD;AACnD,+DAAyD;AACzD,qFAAwF;AACxF,+DAAsD;AAEtD,+CAA0G;AAC1G,mDAAyD;AACzD,uCAAgF;AAChF,8EAAyE;AACzE,mDAA+C;AAC/C,2CAAuC;AACvC,uDAAgE;AAGzD,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAItB,AAAN,KAAK,CAAC,eAAe,CAAmB,SAAuB,EAAS,OAAwB;QAC9F,MAAM,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAE5B,OAAO,MAAM,EAAE,CAAC,aAAa,CAAC,qBAAS,CAAC,CAAC,IAAI,iBAC3C,MAAM,EAAE,OAAO,CAAC,KAAK,CAAC,MAAM,EAC5B,OAAO,EAAE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,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,GAC7F,CAAA;YAED,OAAO,gBAAgB,CAAC,EAAE,CAAA;YAC1B,MAAM,EAAE,CAAC,aAAa,CAAC,oCAAgB,CAAC,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAA;YAE/D,MAAM,MAAM,GAAG,MAAM,aAAa,CAAC,IAAI,+CAClC,SAAS,GACT,SAAS,KACZ,OAAO,EAAE,IAAI,EACb,OAAO,EAAE,OAAO,IAChB,CAAA;YAEF,OAAO,CAAC,IAAI,iCAAM,MAAM,KAAE,MAAM,EAAE,GAAG,IAAG,CAAA;SACzC;KACF;IAED,OAAO,OAAO,CAAA;AAChB,CAAC;AA3ND,0DA2NC","sourcesContent":["import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'\nimport { In, MoreThan, SelectQueryBuilder } from 'typeorm'\n\nimport { Bizplace } from '@things-factory/biz-base'\nimport { generateId } from '@things-factory/id-rule-base'\nimport { Sellercraft, SellercraftStatus } from '@things-factory/integration-sellercraft'\nimport { Product } from '@things-factory/product-base'\n\nimport { INVENTORY_STATUS, INVENTORY_TRANSACTION_TYPE, LOCATION_STATUS, RULE_TYPE } from '../../constants'\nimport { SellercraftController } from '../../controllers'\nimport { DateGenerator, InventoryNoGenerator, InventoryUtil } from '../../utils'\nimport { InventoryHistory } from '../inventory-history/inventory-history'\nimport { Location } from '../location/location'\nimport { Inventory } from './inventory'\nimport { InventoryPatch, NewInventory } from './inventory-types'\n\n@Resolver(Inventory)\nexport class InventoryMutation {\n @Directive('@privilege(category: \"inventory\", privilege: \"mutation\")')\n @Directive('@transaction')\n @Mutation(returns => Inventory)\n async createInventory(@Arg('inventory') inventory: NewInventory, @Ctx() context: ResolverContext): Promise<Inventory> {\n const { tx } = context.state\n\n return await tx.getRepository(Inventory).save({\n domain: context.state.domain,\n creator: context.state.user,\n updater: context.state.user,\n ...inventory\n })\n }\n\n @Directive('@privilege(category: \"inventory\", privilege: \"mutation\")')\n @Directive('@transaction')\n @Mutation(returns => Inventory)\n async updateInventory(@Arg('patch') patch: InventoryPatch, @Ctx() context: ResolverContext): Promise<Inventory> {\n const { domain, user, tx } = context.state\n\n const invQb: SelectQueryBuilder<Inventory> = await tx\n .getRepository(Inventory)\n .createQueryBuilder('INV')\n .where('INV.domain_id = :domainId', { domainId: domain.id })\n .andWhere('INV.bizplace_id = :bizplaceId', { bizplaceId: patch.bizplace.id })\n .andWhere('INV.batch_id = :batchId', { batchId: patch.batchId })\n .andWhere('INV.product_id = :productId', { productId: patch.product.id })\n .andWhere('INV.packing_type = :packingType', { packingType: patch.packingType })\n .andWhere('INV.packing_size = :packingSize', { packingSize: patch.packingSize })\n\n if (patch?.cartonId) invQb.andWhere('INV.carton_id = :cartonId', { cartonId: patch.cartonId })\n else invQb.andWhere('INV.pallet_id = :palletId', { palletId: patch.palletId })\n\n const inventory = await invQb.getOne()\n\n return await tx.getRepository(Inventory).save({\n ...inventory,\n ...patch,\n updater: user\n })\n }\n\n @Directive('@privilege(category: \"inventory\", privilege: \"mutation\")')\n @Directive('@transaction')\n @Mutation(returns => Inventory)\n async updateInventoryRemark(@Arg('id') id: string, @Arg('remark') remark: string, @Ctx() context: ResolverContext): Promise<Inventory> {\n const { domain, user, tx } = context.state\n\n const repository = tx.getRepository(Inventory)\n const inventory = await repository.findOne({ where: { domain: { id: domain.id }, id } })\n\n return await repository.save({\n ...inventory,\n remark,\n updater: user\n })\n }\n\n @Directive('@privilege(category: \"inventory\", privilege: \"mutation\")')\n @Directive('@transaction')\n @Mutation(returns => Boolean)\n async deleteInventory(@Arg('name') name: string, @Ctx() context: ResolverContext): Promise<Boolean> {\n const { tx } = context.state\n\n await tx.getRepository(Inventory).delete({ domain: { id: context.state.domain.id }, name })\n return true\n }\n\n @Directive('@privilege(category: \"inventory\", privilege: \"mutation\")')\n @Directive('@transaction')\n @Mutation(returns => [Inventory])\n async updateMultipleInventory(@Arg('patches', type => [InventoryPatch]) patches: InventoryPatch[], @Ctx() context: ResolverContext): Promise<Inventory[]> {\n return await updateMultipleInventory(patches, context)\n }\n\n @Directive('@privilege(category: \"inventory\", privilege: \"mutation\")')\n @Directive('@transaction')\n @Mutation(returns => Boolean)\n async deleteInventories(@Arg('ids', type => [String]) ids: string[], @Ctx() context: ResolverContext): Promise<Boolean> {\n const { tx } = context.state\n\n await tx.getRepository(Inventory).delete({\n id: In(ids)\n })\n\n return true\n }\n\n @Directive('@privilege(category: \"inventory\", privilege: \"mutation\")')\n @Directive('@transaction')\n @Mutation(returns => Boolean)\n async inventoryTransfer(\n @Arg('originPalletId') originPalletId: string,\n @Arg('palletId', { nullable: true }) palletId: string,\n @Arg('cartonId', { nullable: true }) cartonId: string,\n @Arg('fromLocationName') fromLocationName: string,\n @Arg('toLocationName') toLocationName: string,\n @Arg('qty') qty: number,\n @Arg('reason', { nullable: true }) reason: string,\n @Ctx() context: ResolverContext\n ): Promise<Boolean> {\n const { domain, user, tx } = context.state\n\n const fromLocation: Location = await tx.getRepository(Location).findOne({\n where: { domain: { id: domain.id }, name: fromLocationName },\n relations: ['domain', 'warehouse']\n })\n // 1. check toLocation exist\n const toLocation: Location = await tx.getRepository(Location).findOne({\n where: { domain: { id: domain.id }, name: toLocationName },\n relations: ['domain', 'warehouse']\n })\n if (!toLocation) throw new Error(context.t(`error.To_location_does_not_exists`))\n\n if (qty < 0) throw new Error(`Invalid quantity`)\n\n // 2. search for related inventory\n const invQb: SelectQueryBuilder<Inventory> = await tx\n .getRepository(Inventory)\n .createQueryBuilder('INV')\n .innerJoinAndSelect('INV.location', 'loc')\n .innerJoinAndSelect('INV.product', 'product')\n .innerJoinAndSelect('INV.bizplace', 'bizplace')\n .leftJoinAndSelect('INV.refInventory', 'refInventory')\n .leftJoinAndSelect('INV.reusablePallet', 'reusablePallet')\n .leftJoinAndSelect('INV.productDetail', 'productDetail')\n .leftJoinAndSelect('bizplace.domain', 'domain')\n .leftJoinAndSelect('product.productDetails', 'productDetails')\n .leftJoinAndSelect('INV.originInventory', 'originInventory')\n .where('INV.domain_id = :domainId', { domainId: domain.id })\n .andWhere('INV.pallet_id = :palletId', { palletId: originPalletId })\n\n let inventory: Inventory = await invQb.getOne()\n if (!inventory) throw new Error('Inventory not found')\n\n if (qty > inventory.qty - (inventory?.lockedQty > 0 ? inventory.lockedQty : 0)) throw new Error('Transfer quantity exceeded inventory quantity')\n\n if (toLocation.name == inventory.location.name) throw new Error('Inventory is in current location')\n\n let transactionInventory = new InventoryUtil(tx, domain, user)\n\n const sellercraft: Sellercraft = await tx.getRepository(Sellercraft).findOne({\n where: { domain: { id: inventory.bizplace.domain.id }, status: SellercraftStatus.ACTIVE },\n relations: ['domain']\n })\n\n const partialTransferFunc = async function (inventory, qty, fromLocation, toLocation, cartonId, palletId, context) {\n const { user, tx } = context.state\n\n if (qty < inventory.qty - (inventory?.lockedQty > 0 ? inventory.lockedQty : 0)) {\n if (!palletId || palletId.trim() == '') throw new Error('Require new lot id for partial transfer')\n\n let transferQty = qty\n let transferUomValue = (inventory.uomValue / inventory.qty) * qty\n let newInventory = {\n ...inventory,\n palletId,\n location: toLocation,\n warehouse: toLocation.warehouse,\n zone: toLocation.zone,\n creator: user,\n updater: user\n }\n\n delete newInventory.id\n delete newInventory.updatedAt\n\n newInventory.cartonId = cartonId\n newInventory.qty = transferQty\n newInventory.lockedQty = 0\n newInventory.uomValue = transferUomValue\n newInventory.lockedUomValue = 0\n if (inventory.originInventory?.id) {\n newInventory.originInventory = { id: inventory.originInventory.id }\n } else {\n newInventory.originInventory = { id: inventory.id }\n }\n\n await transactionInventory.transactionInventory(\n { ...inventory, qty: inventory.qty - transferQty, uomValue: inventory.uomValue - transferUomValue },\n null,\n -transferQty,\n -transferUomValue,\n INVENTORY_TRANSACTION_TYPE.RELOCATE,\n reason || null\n )\n\n await transactionInventory.transactionInventory(newInventory, null, transferQty, transferUomValue, INVENTORY_TRANSACTION_TYPE.RELOCATE, reason || null)\n\n if (sellercraft) {\n const sellercraftCtrl: SellercraftController = new SellercraftController(tx, domain, user)\n await sellercraftCtrl.updateSellercraftStock(sellercraft, inventory)\n await sellercraftCtrl.updateSellercraftStock(sellercraft, newInventory)\n }\n } else {\n inventory.warehouse = toLocation.warehouse\n inventory.location = toLocation\n inventory.zone = toLocation.zone\n inventory.updater = user\n inventory.cartonId = cartonId\n\n let isEmptyLocation = await tx.getRepository(Inventory).find({\n where: { location: { id: fromLocation.id } }\n })\n\n if ((isEmptyLocation.length = 1)) {\n await tx.getRepository(Location).save({\n ...fromLocation,\n status: LOCATION_STATUS.EMPTY\n })\n }\n\n await transactionInventory.transactionInventory(inventory, null, 0, 0, INVENTORY_TRANSACTION_TYPE.RELOCATE, reason || null)\n\n if (sellercraft) {\n const sellercraftCtrl: SellercraftController = new SellercraftController(tx, domain, user)\n await sellercraftCtrl.updateSellercraftStock(sellercraft, inventory)\n }\n }\n }\n\n if (inventory.cartonId && inventory.cartonId != '') {\n if (!cartonId) throw new Error('Require carton id')\n\n if (qty < inventory.qty - (inventory?.lockedQty > 0 ? inventory.lockedQty : 0)) {\n palletId = await generateId({\n domain: domain,\n type: RULE_TYPE.LOT_NUMBER_ID,\n seed: { date: DateGenerator.generateDate() }\n })\n }\n\n await partialTransferFunc(inventory, qty, fromLocation, toLocation, cartonId, palletId, context)\n } else {\n if (!palletId) {\n palletId = await generateId({\n domain: domain,\n type: RULE_TYPE.LOT_NUMBER_ID,\n seed: { date: DateGenerator.generateDate() }\n })\n }\n await partialTransferFunc(inventory, qty, fromLocation, toLocation, null, palletId, context)\n }\n\n return true\n }\n}\n\nexport async function updateMultipleInventory(patches: InventoryPatch[], context: ResolverContext): Promise<Inventory[]> {\n const { domain, user, tx } = context.state\n\n let results = []\n const _createRecords = patches.filter((patch: any) => !patch.id)\n const _updateRecords = patches.filter((patch: any) => patch.id)\n\n const inventoryRepo = tx.getRepository(Inventory)\n if (_createRecords.length > 0) {\n let today = new Date()\n let year = today.getFullYear()\n let month = today.getMonth()\n let date = today.getDate()\n\n for (let i = 0; i < _createRecords.length; i++) {\n const total = await tx.getRepository(Inventory).countBy({\n createdAt: MoreThan(new Date(year, month, date))\n })\n\n const newRecord = _createRecords[i]\n\n if (newRecord.location && newRecord.location.id) {\n var location = await tx.getRepository(Location).findOne({\n where: { id: newRecord.location.id },\n relations: ['warehouse']\n })\n newRecord.location = location\n newRecord.zone = location.zone\n newRecord.warehouse = location.warehouse\n }\n\n if (newRecord.bizplace && newRecord.bizplace.id) {\n newRecord.bizplace = (await tx.getRepository(Bizplace).findOneBy({ id: newRecord.bizplace.id })) as any\n }\n\n if (newRecord.product && newRecord.product.id) {\n var product = (await tx.getRepository(Product).findOneBy({ id: newRecord.product.id })) as any\n newRecord.product = product\n }\n\n let palletId =\n 'P' +\n year.toString().substr(year.toString().length - 2) +\n ('0' + (month + 1).toString()).substr(('0' + (month + 1).toString()).toString().length - 2) +\n ('0' + date.toString()).substr(('0' + date.toString()).length - 2) +\n ('0000' + (total + 1).toString()).substr(('0000' + (total + 1).toString()).length - 4)\n\n newRecord.name = palletId\n newRecord.status = newRecord.qty < 1 ? 'TERMINATED' : 'STORED'\n newRecord.palletId = palletId\n\n const result = await inventoryRepo.save({\n domain: domain,\n creator: user,\n updater: user,\n lastSeq: 0,\n ...newRecord\n } as any)\n\n await tx.getRepository(InventoryHistory).save({\n ...newRecord,\n domain: domain,\n creator: user,\n updater: user,\n name: InventoryNoGenerator.inventoryHistoryName(),\n seq: 0,\n transactionType: 'NEW',\n productId: newRecord.product.id,\n warehouseId: newRecord.warehouse.id,\n locationId: newRecord.location.id\n })\n\n results.push({ ...result, cuFlag: '+' })\n }\n }\n\n if (_updateRecords.length > 0) {\n for (let i = 0; i < _updateRecords.length; i++) {\n const newRecord = _updateRecords[i]\n const newHistoryRecord = JSON.parse(JSON.stringify(_updateRecords[i]))\n let transactionType = ''\n\n let inventory = await inventoryRepo.findOne({\n where: { id: newRecord.id },\n relations: ['warehouse', 'location', 'product', 'bizplace']\n })\n newHistoryRecord.openingQty = inventory.qty\n newHistoryRecord.openingUomValue = inventory.uomValue\n\n // Get last sequence from InventoryHistory\n let latestEntry = await tx.getRepository(InventoryHistory).find({\n where: { palletId: inventory.palletId },\n order: { seq: 'DESC' },\n take: 1\n })\n let lastSeq = latestEntry[0].seq\n\n // Condition 1: Change location (RELOCATE)\n if (newRecord.location && newRecord.location.id) {\n var location = await tx.getRepository(Location).findOne({\n where: { id: newRecord.location.id },\n relations: ['warehouse']\n })\n newRecord.location = location\n newRecord.zone = location.zone\n newRecord.warehouse = location.warehouse\n\n newHistoryRecord.location = location\n newHistoryRecord.zone = location.zone\n newHistoryRecord.warehouse = location.warehouse\n\n transactionType = 'RELOCATE'\n }\n\n // Condition 2: Change of qty or uomValue.\n // Set qty movement for inventory history\n if (typeof newRecord.qty != 'undefined') {\n transactionType = 'ADJUSTMENT'\n newHistoryRecord.qty = newRecord.qty - inventory.qty\n if (newRecord.qty < 1) {\n newRecord.status = 'TERMINATED'\n newRecord.qty = 0\n newRecord.uomValue = 0\n }\n } else {\n newHistoryRecord.qty = 0\n }\n // Set uomValue movement for inventory history\n if (typeof newRecord.uomValue != 'undefined') {\n transactionType = 'ADJUSTMENT'\n newHistoryRecord.uomValue = newRecord.uomValue - inventory.uomValue\n if (newRecord.uomValue < 1) {\n newRecord.uomValue = 0\n }\n } else {\n newHistoryRecord.uomValue = 0\n }\n\n // Condition 3: Change of bizplace or product or batch id or packing type\n if (newRecord.bizplace && newRecord.bizplace.id) {\n newRecord.bizplace = (await tx.getRepository(Bizplace).findOneBy({ id: newRecord.bizplace.id })) as any\n }\n\n if (newRecord.product && newRecord.product.id) {\n newRecord.product = (await tx.getRepository(Product).findOneBy({ id: newRecord.product.id })) as any\n }\n\n if ((newRecord.product && newRecord.product.id) || (newRecord.bizplace && newRecord.bizplace.id) || newRecord.batchId || newRecord.packingType) {\n if (\n inventory.bizplace.id !== (newRecord.bizplace ? newRecord.bizplace.id : '') ||\n inventory.product.id !== (newRecord.product ? newRecord.product.id : '') ||\n inventory.batchId !== newRecord.batchId ||\n inventory.packingType !== newRecord.packingType\n ) {\n transactionType = 'ADJUSTMENT'\n lastSeq = lastSeq + 1\n let inventoryHistory: any = {\n ...inventory,\n domain: domain,\n bizplace: inventory.bizplace.id,\n openingQty: inventory.qty,\n openingUomValue: inventory.uomValue,\n qty: -inventory.qty || 0,\n uomValue: -inventory.uomValue || 0,\n name: InventoryNoGenerator.inventoryHistoryName(),\n seq: lastSeq,\n inventory,\n transactionType: transactionType,\n status: INVENTORY_STATUS.TERMINATED,\n productId: inventory.product.id,\n warehouseId: inventory.warehouse.id,\n locationId: inventory.location.id,\n creator: user,\n updater: user\n }\n\n delete inventoryHistory.id\n await tx.getRepository(InventoryHistory).save(inventoryHistory as any)\n\n newHistoryRecord.qty = newRecord.qty || inventory.qty\n newHistoryRecord.uomValue = newRecord.uomValue || inventory.uomValue || 0\n newHistoryRecord.openingQty = 0\n newHistoryRecord.openingUomValue = 0\n newHistoryRecord.batchId = newRecord.batchId || inventory.batchId || '-'\n }\n }\n\n //Transaction type will be RELOCATE if there is only location change. Any other changes will be considered Adjustment.\n lastSeq = lastSeq + 1\n let inventoryHistory = {\n ...inventory,\n ...newHistoryRecord,\n domain: domain,\n creator: user,\n updater: user,\n name: InventoryNoGenerator.inventoryHistoryName(),\n seq: lastSeq,\n inventory,\n transactionType: transactionType == '' ? 'ADJUSTMENT' : transactionType,\n productId: newHistoryRecord.product ? newHistoryRecord.product.id : inventory.product.id,\n warehouseId: newHistoryRecord.warehouse ? newHistoryRecord.warehouse.id : inventory.warehouse.id,\n locationId: newHistoryRecord.location ? newHistoryRecord.location.id : inventory.location.id\n }\n\n delete inventoryHistory.id\n await tx.getRepository(InventoryHistory).save(inventoryHistory)\n\n const result = await inventoryRepo.save({\n ...inventory,\n ...newRecord,\n updater: user,\n lastSeq: lastSeq\n })\n\n results.push({ ...result, cuFlag: 'M' })\n }\n }\n\n return results\n}\n"]}
|
|
@@ -95,9 +95,7 @@ let InventoryQuery = class InventoryQuery {
|
|
|
95
95
|
// Apply sorting based on child data
|
|
96
96
|
if ((sortings === null || sortings === void 0 ? void 0 : sortings.length) !== 0) {
|
|
97
97
|
const arrChildSortData = ['bizplace', 'product', 'location', 'warehouse', 'zone'];
|
|
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
|
|
99
|
-
? 'DESC'
|
|
100
|
-
: 'ASC' })), {});
|
|
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 ? 'DESC' : 'ASC' })), {});
|
|
101
99
|
qb.orderBy(sort);
|
|
102
100
|
}
|
|
103
101
|
if ((locationSortingRules === null || locationSortingRules === void 0 ? void 0 : locationSortingRules.length) > 0) {
|
|
@@ -179,7 +177,7 @@ let InventoryQuery = class InventoryQuery {
|
|
|
179
177
|
.addSelect('COALESCE(SUM(i.locked_qty), 0)', 'lockedQty')
|
|
180
178
|
.addSelect('COALESCE(SUM(i.uom_value), 0)', 'uomValue')
|
|
181
179
|
.addSelect('COALESCE(SUM(i.locked_uom_value), 0)', 'lockedUomValue')
|
|
182
|
-
.innerJoin('i.product', 'product', '
|
|
180
|
+
.innerJoin('i.product', 'product', 'product.deleted_at IS NULL')
|
|
183
181
|
.andWhere('i.status = :status', { status: constants_1.INVENTORY_STATUS.STORED })
|
|
184
182
|
.andWhere('i.expiration_date >= now()')
|
|
185
183
|
.andWhere('product.domain_id = :domain', { domain: domain.id })
|
|
@@ -469,9 +467,7 @@ let InventoryQuery = class InventoryQuery {
|
|
|
469
467
|
where: { domain: { id: context.state.domain.id }, palletId: palletB, status: constants_1.INVENTORY_STATUS.STORED },
|
|
470
468
|
relations: ['product']
|
|
471
469
|
});
|
|
472
|
-
return (
|
|
473
|
-
((_a = invA === null || invA === void 0 ? void 0 : invA.product) === null || _a === void 0 ? void 0 : _a.id) === ((_b = invB === null || invB === void 0 ? void 0 : invB.product) === null || _b === void 0 ? void 0 : _b.id) &&
|
|
474
|
-
(invA === null || invA === void 0 ? void 0 : invA.packingType) === (invB === null || invB === void 0 ? void 0 : invB.packingType));
|
|
470
|
+
return (invA === null || invA === void 0 ? void 0 : invA.batchId) === (invB === null || invB === void 0 ? void 0 : invB.batchId) && ((_a = invA === null || invA === void 0 ? void 0 : invA.product) === null || _a === void 0 ? void 0 : _a.id) === ((_b = invB === null || invB === void 0 ? void 0 : invB.product) === null || _b === void 0 ? void 0 : _b.id) && (invA === null || invA === void 0 ? void 0 : invA.packingType) === (invB === null || invB === void 0 ? void 0 : invB.packingType);
|
|
475
471
|
}
|
|
476
472
|
async checkCartonIdenticality(cartonA, palletA, cartonB, context) {
|
|
477
473
|
var _a, _b;
|
|
@@ -1120,9 +1116,7 @@ async function inventoriesByStrategy({ worksheetId, batchId, bizplaceId, product
|
|
|
1120
1116
|
case 'LOCATION':
|
|
1121
1117
|
if ((locationSortingRules === null || locationSortingRules === void 0 ? void 0 : locationSortingRules.length) > 0) {
|
|
1122
1118
|
locationSortingRules.forEach((rule, idx) => {
|
|
1123
|
-
idx === 0
|
|
1124
|
-
? qb.orderBy(`LOC.${rule.name}`, rule.desc ? 'DESC' : 'ASC')
|
|
1125
|
-
: qb.addOrderBy(`LOC.${rule.name}`, rule.desc ? 'DESC' : 'ASC');
|
|
1119
|
+
idx === 0 ? qb.orderBy(`LOC.${rule.name}`, rule.desc ? 'DESC' : 'ASC') : qb.addOrderBy(`LOC.${rule.name}`, rule.desc ? 'DESC' : 'ASC');
|
|
1126
1120
|
});
|
|
1127
1121
|
}
|
|
1128
1122
|
else
|