@things-factory/warehouse-base 4.3.79 → 4.3.80-alpha.0
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-query.js +10 -4
- package/dist-server/service/inventory/inventory-query.js.map +1 -1
- package/dist-server/service/inventory/inventory.js +4 -0
- package/dist-server/service/inventory/inventory.js.map +1 -1
- package/dist-server/service/inventory-change/inventory-change-mutation.js +16 -5
- package/dist-server/service/inventory-change/inventory-change-mutation.js.map +1 -1
- package/dist-server/service/inventory-history/inventory-history-query.js +3 -3
- package/dist-server/service/inventory-item/inventory-item.js +8 -3
- package/dist-server/service/inventory-item/inventory-item.js.map +1 -1
- package/dist-server/service/inventory-product/inventory-product.js +8 -3
- package/dist-server/service/inventory-product/inventory-product.js.map +1 -1
- package/dist-server/utils/inventory-util.js +83 -24
- package/dist-server/utils/inventory-util.js.map +1 -1
- package/package.json +8 -8
- package/server/service/inventory/inventory-query.ts +25 -12
- package/server/service/inventory/inventory.ts +3 -0
- package/server/service/inventory-change/inventory-change-mutation.ts +18 -10
- package/server/service/inventory-history/inventory-history-query.ts +3 -3
- package/server/service/inventory-item/inventory-item.ts +9 -2
- package/server/service/inventory-product/inventory-product.ts +5 -1
- package/server/utils/inventory-util.ts +117 -51
|
@@ -147,68 +147,134 @@ export async function generateInventoryHistory(
|
|
|
147
147
|
}
|
|
148
148
|
})
|
|
149
149
|
|
|
150
|
-
let
|
|
151
|
-
let
|
|
152
|
-
let
|
|
153
|
-
|
|
154
|
-
if (lastInvHistory) {
|
|
155
|
-
openingQty = lastInvHistory.openingQty + lastInvHistory.qty
|
|
156
|
-
openingUomValue = lastInvHistory.openingUomValue + lastInvHistory.uomValue
|
|
157
|
-
seq = lastInvHistory.seq + 1
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
let remainQty = (openingQty || 0) + (qty || 0)
|
|
161
|
-
|
|
162
|
-
let inventoryHistory: any = new InventoryHistory()
|
|
163
|
-
|
|
164
|
-
inventoryHistory = {
|
|
165
|
-
...inventory,
|
|
166
|
-
name: InventoryNoGenerator.inventoryHistoryName(),
|
|
167
|
-
inventory,
|
|
168
|
-
seq: seq,
|
|
169
|
-
status: remainQty == 0 ? INVENTORY_STATUS.TERMINATED : inventory.status,
|
|
170
|
-
transactionType,
|
|
150
|
+
let lastSeq: number
|
|
151
|
+
let res: any
|
|
152
|
+
let inventoryHistoryFields: any = {
|
|
171
153
|
refOrderId: refOrder?.id || null,
|
|
172
154
|
orderNo: refOrder?.name || null,
|
|
173
155
|
orderRefNo: refOrder?.refNo || null,
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
uomValue,
|
|
177
|
-
openingUomValue: openingUomValue,
|
|
156
|
+
uom: inventory?.uom,
|
|
157
|
+
|
|
178
158
|
creator: user,
|
|
179
|
-
updater: user
|
|
159
|
+
updater: user,
|
|
160
|
+
domain: inventory?.domain,
|
|
161
|
+
bizplace: inventory?.bizplace,
|
|
162
|
+
reusablePallet: inventory?.reusablePallet,
|
|
163
|
+
inventory: inventory,
|
|
164
|
+
product: inventory?.product,
|
|
165
|
+
warehouse: inventory?.warehouse,
|
|
166
|
+
location: inventory?.location,
|
|
167
|
+
|
|
168
|
+
palletId: inventory?.palletId,
|
|
169
|
+
batchId: inventory?.batchId,
|
|
170
|
+
zone: inventory?.zone,
|
|
171
|
+
packingType: inventory?.packingType,
|
|
172
|
+
description: inventory?.description,
|
|
173
|
+
expirationDate: inventory?.expirationDate,
|
|
174
|
+
unitCost: inventory?.unitCost,
|
|
175
|
+
batchIdRef: inventory?.batchIdRef,
|
|
176
|
+
cartonId: inventory?.cartonId,
|
|
177
|
+
manufactureYear: inventory?.manufactureYear,
|
|
178
|
+
packingSize: inventory?.packingSize,
|
|
179
|
+
manufactureDate: inventory?.manufactureDate
|
|
180
180
|
}
|
|
181
181
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
182
|
+
if (!lastInvHistory) {
|
|
183
|
+
res = await invHistoryRepo
|
|
184
|
+
.createQueryBuilder()
|
|
185
|
+
.insert()
|
|
186
|
+
.into(InventoryHistory)
|
|
187
|
+
.values([
|
|
188
|
+
{
|
|
189
|
+
...inventoryHistoryFields,
|
|
190
|
+
name: InventoryNoGenerator.inventoryHistoryName(),
|
|
191
|
+
status: inventory.status,
|
|
192
|
+
transactionType,
|
|
193
|
+
qty,
|
|
194
|
+
openingQty: 0,
|
|
195
|
+
uomValue,
|
|
196
|
+
openingUomValue: 0,
|
|
197
|
+
seq: 0
|
|
198
|
+
}
|
|
199
|
+
])
|
|
200
|
+
.returning('*')
|
|
201
|
+
.execute()
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
if (transactionType == 'PICKING' || transactionType == 'UNLOADING') {
|
|
205
|
+
const findSameOrderHistory: InventoryHistory[] = await invHistoryRepo.find({
|
|
206
|
+
domain: inventory.domain,
|
|
207
|
+
palletId: inventory.palletId,
|
|
208
|
+
refOrderId: refOrder.id
|
|
209
|
+
})
|
|
210
|
+
|
|
211
|
+
if (findSameOrderHistory.length > 0) {
|
|
212
|
+
let prevTotalQty = 0
|
|
213
|
+
let prevTotalUomValue = 0
|
|
214
|
+
for (let oh of findSameOrderHistory) {
|
|
215
|
+
prevTotalQty += oh.qty
|
|
216
|
+
prevTotalUomValue += oh.uomValue
|
|
217
|
+
}
|
|
218
|
+
qty -= prevTotalQty
|
|
219
|
+
uomValue -= prevTotalUomValue
|
|
220
|
+
}
|
|
201
221
|
}
|
|
222
|
+
|
|
223
|
+
res = await invHistoryRepo
|
|
224
|
+
.createQueryBuilder()
|
|
225
|
+
.insert()
|
|
226
|
+
.into(InventoryHistory)
|
|
227
|
+
.values([
|
|
228
|
+
{
|
|
229
|
+
...inventoryHistoryFields,
|
|
230
|
+
name: InventoryNoGenerator.inventoryHistoryName(),
|
|
231
|
+
status: () =>
|
|
232
|
+
`(select case when opening_qty + ${qty} = 0 then 'TERMINATED' else 'STORED' end as status from inventory_histories where inventory_id = '${inventory.id}' order by seq desc limit 1)`,
|
|
233
|
+
transactionType,
|
|
234
|
+
qty,
|
|
235
|
+
openingQty: () =>
|
|
236
|
+
`(select opening_qty from inventory_histories where inventory_id = '${inventory.id}' order by seq desc limit 1) + ${qty}`,
|
|
237
|
+
uomValue,
|
|
238
|
+
openingUomValue: () =>
|
|
239
|
+
`(select opening_uom_value from inventory_histories where inventory_id = '${inventory.id}' order by seq desc limit 1) + ${uomValue}`,
|
|
240
|
+
seq: () =>
|
|
241
|
+
`(select seq from inventory_histories where inventory_id = '${inventory.id}' order by seq desc limit 1) + 1`
|
|
242
|
+
}
|
|
243
|
+
])
|
|
244
|
+
.returning('*')
|
|
245
|
+
.execute()
|
|
246
|
+
}
|
|
202
247
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
248
|
+
let newInventoryHistory: InventoryHistory = res.generatedMaps[0]
|
|
249
|
+
lastSeq = newInventoryHistory.seq
|
|
250
|
+
|
|
251
|
+
if (newInventoryHistory.openingQty == 0) {
|
|
252
|
+
let terminatedRes = await invHistoryRepo
|
|
253
|
+
.createQueryBuilder()
|
|
254
|
+
.insert()
|
|
255
|
+
.into(InventoryHistory)
|
|
256
|
+
.values([
|
|
257
|
+
{
|
|
258
|
+
...inventoryHistoryFields,
|
|
259
|
+
name: InventoryNoGenerator.inventoryHistoryName(),
|
|
260
|
+
status: INVENTORY_STATUS.TERMINATED,
|
|
261
|
+
transactionType: INVENTORY_TRANSACTION_TYPE.TERMINATED,
|
|
262
|
+
qty: 0,
|
|
263
|
+
openingQty: 0,
|
|
264
|
+
uomValue: 0,
|
|
265
|
+
openingUomValue: 0,
|
|
266
|
+
seq: () =>
|
|
267
|
+
`(select seq from inventory_histories where inventory_id = '${inventory.id}' order by seq desc limit 1) + 1`
|
|
268
|
+
}
|
|
269
|
+
])
|
|
270
|
+
.returning('seq')
|
|
271
|
+
.execute()
|
|
272
|
+
|
|
273
|
+
lastSeq = terminatedRes.generatedMaps[0].seq
|
|
206
274
|
inventory.status = INVENTORY_STATUS.TERMINATED
|
|
207
275
|
}
|
|
208
276
|
|
|
209
|
-
|
|
210
|
-
await invRepo.update(inventory.id, { lastSeq: newInventoryHistory.seq, updater: user })
|
|
211
|
-
}
|
|
277
|
+
await invRepo.update(inventory.id, { lastSeq, updater: user })
|
|
212
278
|
|
|
213
279
|
await switchLocationStatus(domain, location, user, trxMgr)
|
|
214
280
|
return newInventoryHistory
|