@things-factory/sales-base 4.3.137 → 4.3.139
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/arrival-notice/arrival-notice-mutation.js +6 -5
- package/dist-server/service/arrival-notice/arrival-notice-mutation.js.map +1 -1
- package/dist-server/service/arrival-notice/arrival-notice-query.js +1 -0
- package/dist-server/service/arrival-notice/arrival-notice-query.js.map +1 -1
- package/dist-server/service/draft-release-good/draft-release-good-mutation.js +2 -4
- package/dist-server/service/draft-release-good/draft-release-good-mutation.js.map +1 -1
- package/dist-server/service/draft-release-good/draft-release-good-query.js +11 -15
- package/dist-server/service/draft-release-good/draft-release-good-query.js.map +1 -1
- package/dist-server/service/invoice-product/invoice-product.js +8 -3
- package/dist-server/service/invoice-product/invoice-product.js.map +1 -1
- package/dist-server/service/order-inventory/order-inventory-query.js +2 -1
- package/dist-server/service/order-inventory/order-inventory-query.js.map +1 -1
- package/dist-server/service/order-inventory/order-inventory-types.js +18 -10
- package/dist-server/service/order-inventory/order-inventory-types.js.map +1 -1
- package/dist-server/service/order-inventory/order-inventory.js +12 -3
- package/dist-server/service/order-inventory/order-inventory.js.map +1 -1
- package/dist-server/service/order-product/order-product-query.js +1 -0
- package/dist-server/service/order-product/order-product-query.js.map +1 -1
- package/dist-server/service/order-product/order-product-types.js +18 -10
- package/dist-server/service/order-product/order-product-types.js.map +1 -1
- package/dist-server/service/order-vas/order-vas.js +8 -3
- package/dist-server/service/order-vas/order-vas.js.map +1 -1
- package/dist-server/service/others/other-query.js +186 -177
- package/dist-server/service/others/other-query.js.map +1 -1
- package/dist-server/service/others/other-types.js +9 -1
- package/dist-server/service/others/other-types.js.map +1 -1
- package/dist-server/service/purchase-order/purchase-order-mutation.js +10 -2
- package/dist-server/service/purchase-order/purchase-order-mutation.js.map +1 -1
- package/dist-server/service/purchase-order/purchase-order-query.js +1 -0
- package/dist-server/service/purchase-order/purchase-order-query.js.map +1 -1
- package/dist-server/service/release-good/release-good-mutation.js +22 -10
- package/dist-server/service/release-good/release-good-mutation.js.map +1 -1
- package/dist-server/service/release-good/release-good-query.js +2 -0
- package/dist-server/service/release-good/release-good-query.js.map +1 -1
- package/dist-server/service/release-good/release-good-types.js +8 -4
- package/dist-server/service/release-good/release-good-types.js.map +1 -1
- package/dist-server/service/release-good/release-good.js +1 -0
- package/dist-server/service/release-good/release-good.js.map +1 -1
- package/dist-server/service/return-order/return-order-mutation.js +3 -0
- package/dist-server/service/return-order/return-order-mutation.js.map +1 -1
- package/dist-server/service/return-order/return-order-types.js.map +1 -1
- package/dist-server/service/reverse-kitting-order-inventory/reverse-kitting-order-inventory.js +8 -3
- package/dist-server/service/reverse-kitting-order-inventory/reverse-kitting-order-inventory.js.map +1 -1
- package/dist-server/utils/inventory-util.js +39 -104
- package/dist-server/utils/inventory-util.js.map +1 -1
- package/package.json +13 -13
- package/server/service/arrival-notice/arrival-notice-mutation.ts +6 -3
- package/server/service/arrival-notice/arrival-notice-query.ts +1 -0
- package/server/service/draft-release-good/draft-release-good-mutation.ts +4 -7
- package/server/service/draft-release-good/draft-release-good-query.ts +17 -21
- package/server/service/invoice-product/invoice-product.ts +5 -1
- package/server/service/order-inventory/order-inventory-query.ts +2 -0
- package/server/service/order-inventory/order-inventory-types.ts +6 -0
- package/server/service/order-inventory/order-inventory.ts +8 -1
- package/server/service/order-product/order-product-query.ts +1 -0
- package/server/service/order-product/order-product-types.ts +6 -0
- package/server/service/order-vas/order-vas.ts +6 -1
- package/server/service/others/other-query.ts +231 -220
- package/server/service/others/other-types.ts +7 -1
- package/server/service/purchase-order/purchase-order-mutation.ts +10 -1
- package/server/service/purchase-order/purchase-order-query.ts +1 -0
- package/server/service/release-good/release-good-mutation.ts +31 -18
- package/server/service/release-good/release-good-query.ts +2 -0
- package/server/service/release-good/release-good-types.ts +4 -3
- package/server/service/release-good/release-good.ts +1 -0
- package/server/service/return-order/return-order-mutation.ts +4 -1
- package/server/service/return-order/return-order-types.ts +1 -0
- package/server/service/reverse-kitting-order-inventory/reverse-kitting-order-inventory.ts +5 -1
- package/server/utils/inventory-util.ts +75 -149
- package/translations/en.json +1 -0
- package/translations/ko.json +2 -1
- package/translations/ms.json +2 -1
- package/translations/zh.json +25 -0
|
@@ -7,6 +7,7 @@ import { Bizplace, getPermittedBizplaces } from '@things-factory/biz-base'
|
|
|
7
7
|
import { Product, ProductDetail } from '@things-factory/product-base'
|
|
8
8
|
import { PartnerSetting, Setting } from '@things-factory/setting-base'
|
|
9
9
|
import { Domain, ListParam } from '@things-factory/shell'
|
|
10
|
+
import i18next from 'i18next'
|
|
10
11
|
|
|
11
12
|
import {
|
|
12
13
|
InventoryProductGroup,
|
|
@@ -205,32 +206,30 @@ export class OtherQuery {
|
|
|
205
206
|
|
|
206
207
|
let packageUomValue = availableItem ? availableItem.remainUomValue / availableItem.remainQty : null
|
|
207
208
|
const newOrderInventory: any = {
|
|
208
|
-
product:
|
|
209
|
-
? {
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
packingType: availableItem ? availableItem.packingType : orderInventory.packingType,
|
|
233
|
-
packingSize: availableItem ? availableItem.packingSize : 1,
|
|
209
|
+
product:
|
|
210
|
+
total > 0 ? { id: items[0].productId, sku: items[0].productSKU, name: items[0].productName } : { id: null },
|
|
211
|
+
productDetail: total > 0 ? { id: items[0].productDetailId } : null,
|
|
212
|
+
inventory:
|
|
213
|
+
total > 0
|
|
214
|
+
? {
|
|
215
|
+
...items[0],
|
|
216
|
+
remainQty: total > 0 ? items[0].remainQty : null,
|
|
217
|
+
remainUomValue: total > 0 ? items[0].remainUomValue : null,
|
|
218
|
+
remainUomValueWithUom: total > 0 ? items[0].remainUomValueWithUom : ''
|
|
219
|
+
}
|
|
220
|
+
: null,
|
|
221
|
+
productId: total > 0 ? items[0].productId : null,
|
|
222
|
+
productDetailID: total > 0 ? items[0].productDetailId : null,
|
|
223
|
+
productSKU: total > 0 ? items[0].productSKU : orderInventory.productSKU,
|
|
224
|
+
productName: total > 0 ? items[0].productName : null,
|
|
225
|
+
uom: total > 0 ? items[0].uom : null,
|
|
226
|
+
remainQty: total > 0 ? items[0].remainQty : null,
|
|
227
|
+
remainUomValue: total > 0 ? items[0].remainUomValue : null,
|
|
228
|
+
remainUomValueWithUom: total > 0 ? items[0].remainUomValueWithUom : '',
|
|
229
|
+
batchId: total > 0 ? items[0].batchId : null,
|
|
230
|
+
batchIdRef: total > 0 ? items[0].batchIdRef : null,
|
|
231
|
+
packingType: total > 0 ? items[0].packingType : orderInventory.packingType,
|
|
232
|
+
packingSize: total > 0 ? items[0].packingSize : 1,
|
|
234
233
|
releaseQty: orderInventory.releaseQty
|
|
235
234
|
? Number.isInteger(orderInventory.releaseQty)
|
|
236
235
|
? orderInventory.releaseQty
|
|
@@ -242,7 +241,7 @@ export class OtherQuery {
|
|
|
242
241
|
: null
|
|
243
242
|
: null,
|
|
244
243
|
groupType: availableItem ? availableItem.groupType : null,
|
|
245
|
-
isError: !availableItem ? true : false
|
|
244
|
+
isError: !availableItem || !orderInventory.releaseQty || !orderInventory.packingType ? true : false
|
|
246
245
|
}
|
|
247
246
|
|
|
248
247
|
newOrderInventories.push(newOrderInventory)
|
|
@@ -296,128 +295,137 @@ export class OtherQuery {
|
|
|
296
295
|
@Arg('partnerBizplaceId') partnerBizplaceId: string,
|
|
297
296
|
@Arg('orderProducts', type => [NewOrderProduct], { nullable: true }) orderProducts: NewOrderProduct[]
|
|
298
297
|
): Promise<OrderProduct[]> {
|
|
299
|
-
|
|
300
|
-
|
|
298
|
+
try {
|
|
299
|
+
const { domain, user, tx, bizplace }: { domain: Domain; user: User; tx: EntityManager; bizplace: Bizplace } =
|
|
300
|
+
context.state
|
|
301
301
|
|
|
302
|
-
|
|
302
|
+
const productDetailRepo = tx.getRepository(ProductDetail)
|
|
303
303
|
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
304
|
+
let permittedBizplaces: Bizplace[] = await getPermittedBizplaces(domain, user)
|
|
305
|
+
let foundPermittedBizplace: Bizplace
|
|
306
|
+
let companyBizplace: Bizplace
|
|
307
307
|
|
|
308
|
-
|
|
309
|
-
|
|
308
|
+
if (partnerBizplaceId) {
|
|
309
|
+
foundPermittedBizplace = permittedBizplaces.find(biz => biz.id == partnerBizplaceId)
|
|
310
310
|
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
311
|
+
if (foundPermittedBizplace) {
|
|
312
|
+
if (!foundPermittedBizplace.company?.id) {
|
|
313
|
+
foundPermittedBizplace = await tx.getRepository(Bizplace).findOne(foundPermittedBizplace.id, {
|
|
314
|
+
relations: ['domain', 'company', 'company.domain']
|
|
315
|
+
})
|
|
316
|
+
}
|
|
317
|
+
const companyDomain: Domain = foundPermittedBizplace.company.domain
|
|
318
|
+
companyBizplace = await tx.getRepository(Bizplace).findOne({ where: { domain: companyDomain } })
|
|
316
319
|
}
|
|
317
|
-
const companyDomain: Domain = foundPermittedBizplace.company.domain
|
|
318
|
-
companyBizplace = await tx.getRepository(Bizplace).findOne({ where: { domain: companyDomain } })
|
|
319
320
|
}
|
|
320
|
-
}
|
|
321
321
|
|
|
322
|
-
|
|
323
|
-
|
|
322
|
+
const bizplaces: Bizplace[] = [foundPermittedBizplace, companyBizplace]
|
|
323
|
+
if (bizplace) bizplaces.push(bizplace)
|
|
324
324
|
|
|
325
|
-
|
|
325
|
+
let strictProduct = 'false'
|
|
326
326
|
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
327
|
+
const strictProductSelectionSetting: Setting = await tx.getRepository(Setting).findOne({
|
|
328
|
+
where: { domain, category: 'id-rule', name: 'strict-product-selection' }
|
|
329
|
+
})
|
|
330
330
|
|
|
331
|
-
|
|
331
|
+
if (strictProductSelectionSetting) strictProduct = strictProductSelectionSetting.value
|
|
332
332
|
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
333
|
+
const partnerStrictProductSelectionSetting: PartnerSetting = await tx.getRepository(PartnerSetting).findOne({
|
|
334
|
+
where: { setting: strictProductSelectionSetting, domain, partnerDomain: foundPermittedBizplace?.domain }
|
|
335
|
+
})
|
|
336
336
|
|
|
337
|
-
|
|
337
|
+
if (partnerStrictProductSelectionSetting) strictProduct = partnerStrictProductSelectionSetting.value
|
|
338
338
|
|
|
339
|
-
|
|
339
|
+
let newOrderProducts: any[] = []
|
|
340
340
|
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
341
|
+
for (var i = 0; i < orderProducts.length; i++) {
|
|
342
|
+
const orderProduct = orderProducts[i]
|
|
343
|
+
const productSKU: string = orderProduct.productSKU
|
|
344
|
+
const foundProduct: Product = await tx.getRepository(Product).findOne({
|
|
345
|
+
where: {
|
|
346
|
+
sku: productSKU,
|
|
347
|
+
bizplace: companyBizplace
|
|
348
|
+
}
|
|
349
|
+
})
|
|
350
350
|
|
|
351
|
-
|
|
351
|
+
let newOrderProduct: any
|
|
352
352
|
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
353
|
+
if (foundProduct) {
|
|
354
|
+
let productDetail: ProductDetail
|
|
355
|
+
const hasConditions: boolean = Boolean(
|
|
356
|
+
(orderProduct?.packingType && orderProduct?.packingType.trim() != '') ||
|
|
357
|
+
(orderProduct?.uom && orderProduct?.uom.trim() != '') ||
|
|
358
|
+
orderProduct?.uomValue
|
|
359
|
+
)
|
|
360
|
+
let productDetailCondition: any = { product: foundProduct }
|
|
360
361
|
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
362
|
+
if (hasConditions && strictProduct == 'true') {
|
|
363
|
+
if (orderProduct?.packingType && orderProduct.packingType.trim() != '')
|
|
364
|
+
productDetailCondition.packingType = orderProduct.packingType.trim()
|
|
364
365
|
|
|
365
|
-
|
|
366
|
-
} else {
|
|
367
|
-
productDetailCondition.isDefault = true
|
|
368
|
-
}
|
|
366
|
+
if (orderProduct?.uom && orderProduct.uom.trim() != '') productDetailCondition.uom = orderProduct.uom.trim()
|
|
369
367
|
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
368
|
+
if (orderProduct?.uomValue) productDetailCondition.uomValue = orderProduct.uomValue
|
|
369
|
+
} else {
|
|
370
|
+
productDetailCondition.isDefault = true
|
|
371
|
+
}
|
|
373
372
|
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
? orderProduct.uomValue
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
373
|
+
productDetail = await productDetailRepo.findOne({
|
|
374
|
+
where: productDetailCondition
|
|
375
|
+
})
|
|
376
|
+
|
|
377
|
+
//check if is strict product selection for uom value, uom, packing type
|
|
378
|
+
const uomValue: number =
|
|
379
|
+
strictProduct == 'true' && productDetail ? productDetail.uomValue : orderProduct.uomValue
|
|
380
|
+
|
|
381
|
+
const uom = strictProduct == 'true' && productDetail ? productDetail.uom : orderProduct.uom
|
|
382
|
+
|
|
383
|
+
const packingType =
|
|
384
|
+
strictProduct == 'true' && productDetail ? productDetail.packingType : orderProduct.packingType
|
|
385
|
+
|
|
386
|
+
newOrderProduct = {
|
|
387
|
+
...orderProduct,
|
|
388
|
+
packingType,
|
|
389
|
+
packingSize: productDetail ? productDetail.packingSize : orderProduct.packingSize,
|
|
390
|
+
uom,
|
|
391
|
+
uomValue,
|
|
392
|
+
productName: `${foundProduct.name}(${foundProduct.description}(${foundProduct.sku}))`,
|
|
393
|
+
productBrand: foundProduct?.brand ? foundProduct.brand : null,
|
|
394
|
+
product: {
|
|
395
|
+
id: foundProduct.id,
|
|
396
|
+
name: foundProduct.name,
|
|
397
|
+
sku: foundProduct.sku,
|
|
398
|
+
type: foundProduct.type,
|
|
399
|
+
brand: foundProduct.brand,
|
|
400
|
+
primaryUnit: productDetail ? productDetail.uom : null,
|
|
401
|
+
primaryValue: productDetail ? productDetail.uomValue : null
|
|
402
|
+
},
|
|
403
|
+
productDetail,
|
|
404
|
+
totalUomValue:
|
|
405
|
+
orderProduct.packQty > 0
|
|
406
|
+
? uomValue
|
|
407
|
+
? `${(orderProduct.packQty * uomValue).toFixed(2)} ${uom}`
|
|
408
|
+
: null
|
|
409
|
+
: null,
|
|
410
|
+
isError: productDetail ? false : true
|
|
411
|
+
}
|
|
412
|
+
} else {
|
|
413
|
+
newOrderProduct = {
|
|
414
|
+
...orderProduct,
|
|
415
|
+
productName: orderProduct.productSKU,
|
|
416
|
+
isError: true
|
|
417
|
+
}
|
|
413
418
|
}
|
|
419
|
+
|
|
420
|
+
newOrderProducts.push(newOrderProduct)
|
|
414
421
|
}
|
|
415
422
|
|
|
416
|
-
newOrderProducts
|
|
423
|
+
return newOrderProducts
|
|
424
|
+
} catch (e) {
|
|
425
|
+
return e
|
|
417
426
|
}
|
|
418
|
-
|
|
419
|
-
return newOrderProducts
|
|
420
427
|
}
|
|
428
|
+
|
|
421
429
|
@Directive('@privilege(category: "order_customer", privilege: "query")')
|
|
422
430
|
@Directive('@transaction')
|
|
423
431
|
@Query(returns => [InventoryProductGroup])
|
|
@@ -426,126 +434,129 @@ export class OtherQuery {
|
|
|
426
434
|
@Arg('partnerBizplaceId') partnerBizplaceId: string,
|
|
427
435
|
@Arg('orderProducts', type => [NewOrderProduct], { nullable: true }) orderProducts: NewOrderProduct[]
|
|
428
436
|
): Promise<OrderProduct[]> {
|
|
429
|
-
|
|
430
|
-
|
|
437
|
+
try {
|
|
438
|
+
const { domain, user, tx, bizplace }: { domain: Domain; user: User; tx: EntityManager; bizplace: Bizplace } =
|
|
439
|
+
context.state
|
|
431
440
|
|
|
432
|
-
|
|
441
|
+
const productDetailRepo = tx.getRepository(ProductDetail)
|
|
433
442
|
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
443
|
+
let permittedBizplaces: Bizplace[] = await getPermittedBizplaces(domain, user)
|
|
444
|
+
let foundPermittedBizplace: Bizplace
|
|
445
|
+
let companyBizplace: Bizplace
|
|
437
446
|
|
|
438
|
-
|
|
439
|
-
|
|
447
|
+
if (partnerBizplaceId) {
|
|
448
|
+
foundPermittedBizplace = permittedBizplaces.find(biz => biz.id == partnerBizplaceId)
|
|
440
449
|
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
450
|
+
if (foundPermittedBizplace) {
|
|
451
|
+
if (!foundPermittedBizplace.company?.id) {
|
|
452
|
+
foundPermittedBizplace = await tx.getRepository(Bizplace).findOne(foundPermittedBizplace.id, {
|
|
453
|
+
relations: ['domain', 'company', 'company.domain']
|
|
454
|
+
})
|
|
455
|
+
}
|
|
456
|
+
const companyDomain: Domain = foundPermittedBizplace.company.domain
|
|
457
|
+
companyBizplace = await tx.getRepository(Bizplace).findOne({ where: { domain: companyDomain } })
|
|
446
458
|
}
|
|
447
|
-
const companyDomain: Domain = foundPermittedBizplace.company.domain
|
|
448
|
-
companyBizplace = await tx.getRepository(Bizplace).findOne({ where: { domain: companyDomain } })
|
|
449
459
|
}
|
|
450
|
-
}
|
|
451
460
|
|
|
452
|
-
|
|
453
|
-
|
|
461
|
+
const bizplaces: Bizplace[] = [foundPermittedBizplace, companyBizplace]
|
|
462
|
+
if (bizplace) bizplaces.push(bizplace)
|
|
454
463
|
|
|
455
|
-
|
|
464
|
+
let strictProduct: boolean = false
|
|
456
465
|
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
466
|
+
const strictProductSelectionSetting: Setting = await tx.getRepository(Setting).findOne({
|
|
467
|
+
where: { domain, category: 'id-rule', name: 'strict-product-selection' }
|
|
468
|
+
})
|
|
460
469
|
|
|
461
|
-
|
|
470
|
+
if (strictProductSelectionSetting) strictProduct = strictProductSelectionSetting.value
|
|
462
471
|
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
472
|
+
const partnerStrictProductSelectionSetting: PartnerSetting = await tx.getRepository(PartnerSetting).findOne({
|
|
473
|
+
where: { setting: strictProductSelectionSetting, domain, partnerDomain: foundPermittedBizplace?.domain }
|
|
474
|
+
})
|
|
466
475
|
|
|
467
|
-
|
|
476
|
+
if (partnerStrictProductSelectionSetting) strictProduct = partnerStrictProductSelectionSetting.value
|
|
468
477
|
|
|
469
|
-
|
|
478
|
+
let newOrderProducts: any[] = []
|
|
470
479
|
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
+
for (var i = 0; i < orderProducts.length; i++) {
|
|
481
|
+
const orderProduct = orderProducts[i]
|
|
482
|
+
const productSKU: string = orderProduct.productSKU
|
|
483
|
+
const foundProduct: Product = await tx.getRepository(Product).findOne({
|
|
484
|
+
where: {
|
|
485
|
+
sku: productSKU,
|
|
486
|
+
bizplace: companyBizplace
|
|
487
|
+
}
|
|
488
|
+
})
|
|
480
489
|
|
|
481
|
-
|
|
490
|
+
let newOrderProduct: any
|
|
482
491
|
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
492
|
+
if (foundProduct) {
|
|
493
|
+
let productDetail: ProductDetail
|
|
494
|
+
const hasConditions: boolean = Boolean(
|
|
495
|
+
(orderProduct?.packingType && orderProduct?.packingType.trim() != '') ||
|
|
496
|
+
(orderProduct?.uom && orderProduct?.uom.trim() != '')
|
|
497
|
+
)
|
|
498
|
+
let productDetailCondition: any = { product: foundProduct }
|
|
490
499
|
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
500
|
+
if (hasConditions) {
|
|
501
|
+
if (orderProduct?.packingType && orderProduct.packingType.trim() != '')
|
|
502
|
+
productDetailCondition.packingType = orderProduct.packingType.trim()
|
|
494
503
|
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
504
|
+
if (orderProduct?.uom && orderProduct.uom.trim() != '') productDetailCondition.uom = orderProduct.uom.trim()
|
|
505
|
+
} else {
|
|
506
|
+
productDetailCondition.isDefault = true
|
|
507
|
+
}
|
|
499
508
|
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
509
|
+
productDetail = await productDetailRepo.findOne({
|
|
510
|
+
where: productDetailCondition
|
|
511
|
+
})
|
|
512
|
+
|
|
513
|
+
if (!productDetail) throw new Error('Invalid packing type or uom')
|
|
503
514
|
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
: null
|
|
509
|
-
: orderProduct?.uomValue
|
|
510
|
-
? orderProduct.uomValue
|
|
511
|
-
: productDetail.uomValue
|
|
512
|
-
|
|
513
|
-
newOrderProduct = {
|
|
514
|
-
...orderProduct,
|
|
515
|
-
packingType: orderProduct?.packingType ? orderProduct.packingType : productDetail.packingType,
|
|
516
|
-
packingSize: productDetail?.packingSize ? productDetail.packingSize : null,
|
|
517
|
-
uom: productDetail?.uom ? productDetail.uom : null,
|
|
518
|
-
uomValue: uomValue,
|
|
519
|
-
productName: `${foundProduct.name}(${foundProduct.description}(${foundProduct.sku}))`,
|
|
520
|
-
productBrand: foundProduct?.brand ? foundProduct.brand : null,
|
|
521
|
-
isError: productDetail ? false : true,
|
|
522
|
-
product: {
|
|
523
|
-
id: foundProduct.id,
|
|
524
|
-
name: foundProduct.name,
|
|
525
|
-
sku: foundProduct.sku,
|
|
526
|
-
type: foundProduct.type,
|
|
527
|
-
brand: foundProduct.brand,
|
|
528
|
-
primaryUnit: productDetail?.uom ? productDetail.uom : null,
|
|
529
|
-
primaryValue: productDetail?.uomValue ? productDetail.uomValue : null
|
|
530
|
-
},
|
|
531
|
-
totalUomValue:
|
|
532
|
-
orderProduct.packQty > 0
|
|
533
|
-
? uomValue
|
|
534
|
-
? `${(orderProduct.packQty * uomValue).toFixed(2)} ${productDetail.uom}`
|
|
515
|
+
const uomValue: number =
|
|
516
|
+
strictProduct == true
|
|
517
|
+
? productDetail?.uomValue
|
|
518
|
+
? productDetail.uomValue
|
|
535
519
|
: null
|
|
536
|
-
:
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
520
|
+
: orderProduct?.uomValue
|
|
521
|
+
? orderProduct.uomValue
|
|
522
|
+
: productDetail.uomValue
|
|
523
|
+
|
|
524
|
+
newOrderProduct = {
|
|
525
|
+
...orderProduct,
|
|
526
|
+
packingType: orderProduct?.packingType ? orderProduct.packingType : productDetail.packingType,
|
|
527
|
+
packingSize: productDetail?.packingSize ? productDetail.packingSize : null,
|
|
528
|
+
uom: productDetail?.uom ? productDetail.uom : null,
|
|
529
|
+
uomValue: uomValue,
|
|
530
|
+
productName: `${foundProduct.name}(${foundProduct.description}(${foundProduct.sku}))`,
|
|
531
|
+
productBrand: foundProduct?.brand ? foundProduct.brand : null,
|
|
532
|
+
isError: productDetail ? false : true,
|
|
533
|
+
product: {
|
|
534
|
+
id: foundProduct.id,
|
|
535
|
+
name: foundProduct.name,
|
|
536
|
+
sku: foundProduct.sku,
|
|
537
|
+
type: foundProduct.type,
|
|
538
|
+
brand: foundProduct.brand,
|
|
539
|
+
primaryUnit: productDetail?.uom ? productDetail.uom : null,
|
|
540
|
+
primaryValue: productDetail?.uomValue ? productDetail.uomValue : null
|
|
541
|
+
},
|
|
542
|
+
productDetail,
|
|
543
|
+
totalUomValue:
|
|
544
|
+
orderProduct.packQty > 0
|
|
545
|
+
? uomValue
|
|
546
|
+
? `${(orderProduct.packQty * uomValue).toFixed(2)} ${productDetail.uom}`
|
|
547
|
+
: null
|
|
548
|
+
: null
|
|
549
|
+
}
|
|
550
|
+
} else {
|
|
551
|
+
throw new Error(`(${orderProduct.productSKU}) sku not found`)
|
|
543
552
|
}
|
|
553
|
+
|
|
554
|
+
newOrderProducts.push(newOrderProduct)
|
|
544
555
|
}
|
|
545
556
|
|
|
546
|
-
newOrderProducts
|
|
557
|
+
return newOrderProducts
|
|
558
|
+
} catch (e) {
|
|
559
|
+
return e
|
|
547
560
|
}
|
|
548
|
-
|
|
549
|
-
return newOrderProducts
|
|
550
561
|
}
|
|
551
562
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Field, Float, Int, ObjectType } from 'type-graphql'
|
|
2
|
-
import { Product } from '@things-factory/product-base'
|
|
2
|
+
import { Product, ProductDetail } from '@things-factory/product-base'
|
|
3
3
|
import { ScalarDate } from '@things-factory/shell'
|
|
4
4
|
|
|
5
5
|
@ObjectType()
|
|
@@ -19,6 +19,9 @@ export class InventoryProductGroup {
|
|
|
19
19
|
@Field({ nullable: true })
|
|
20
20
|
productId: string
|
|
21
21
|
|
|
22
|
+
@Field({ nullable: true })
|
|
23
|
+
productDetailId: string
|
|
24
|
+
|
|
22
25
|
@Field({ nullable: true })
|
|
23
26
|
batchId: string
|
|
24
27
|
|
|
@@ -102,4 +105,7 @@ export class InventoryProductGroup {
|
|
|
102
105
|
|
|
103
106
|
@Field(type => Product, { nullable: true })
|
|
104
107
|
product: Product
|
|
108
|
+
|
|
109
|
+
@Field(type => ProductDetail, { nullable: true })
|
|
110
|
+
productDetail: ProductDetail
|
|
105
111
|
}
|
|
@@ -65,7 +65,14 @@ export class PurchaseOrderMutation {
|
|
|
65
65
|
|
|
66
66
|
const findPurchaseOrder: PurchaseOrder = await getRepository(PurchaseOrder).findOne({
|
|
67
67
|
where: { domain, id },
|
|
68
|
-
relations: [
|
|
68
|
+
relations: [
|
|
69
|
+
'orderProducts',
|
|
70
|
+
'orderProducts.product',
|
|
71
|
+
'orderProducts.productDetail',
|
|
72
|
+
'bufferLocation',
|
|
73
|
+
'bizplace',
|
|
74
|
+
'domain'
|
|
75
|
+
]
|
|
69
76
|
})
|
|
70
77
|
|
|
71
78
|
// const findPurchaseOrder: PurchaseOrder = await tx.getRepository(PurchaseOrder).findOne({id}, { relations:['bizplace']})
|
|
@@ -430,6 +437,7 @@ export async function upsertPurchaseOrderProducts(
|
|
|
430
437
|
const bizplaceRepo: Repository<Product> = tx?.getRepository(Bizplace) || getRepository(Bizplace)
|
|
431
438
|
const orderProductRepo: Repository<OrderProduct> = tx?.getRepository(OrderProduct) || getRepository(OrderProduct)
|
|
432
439
|
const productRepo: Repository<Product> = tx?.getRepository(Product) || getRepository(Product)
|
|
440
|
+
const productDetailRepo: Repository<Product> = tx?.getRepository(ProductDetail) || getRepository(ProductDetail)
|
|
433
441
|
|
|
434
442
|
// // Remove all existing order products that do not exist in current input
|
|
435
443
|
let removeOP = purchaseOrder.orderProducts.filter(
|
|
@@ -455,6 +463,7 @@ export async function upsertPurchaseOrderProducts(
|
|
|
455
463
|
bizplace: bizplace,
|
|
456
464
|
name: op?.id ? op.name : OrderNoGenerator.orderProduct(),
|
|
457
465
|
product: await productRepo.findOne(op.product.id),
|
|
466
|
+
productDetail: await productDetailRepo.findOne(op.productDetail.id),
|
|
458
467
|
packingSize: foundProductDetail?.packingSize || 1,
|
|
459
468
|
purchaseOrder: purchaseOrder,
|
|
460
469
|
status: purchaseOrder.status,
|