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