@things-factory/sales-base 4.3.108 → 4.3.110
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/delivery-order/delivery-order-mutation.js +30 -3
- package/dist-server/service/delivery-order/delivery-order-mutation.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/goods-receival-note/goods-receival-note-mutation.js +32 -4
- package/dist-server/service/goods-receival-note/goods-receival-note-mutation.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 +10 -18
- package/dist-server/service/order-product/order-product-types.js.map +1 -1
- package/dist-server/service/order-product/order-product.js +5 -0
- 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 +177 -196
- 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 +2 -3
- 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/return-order/return-order-mutation.js +0 -3
- 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 +104 -39
- package/dist-server/utils/inventory-util.js.map +1 -1
- package/package.json +14 -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/delivery-order/delivery-order-mutation.ts +49 -19
- 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/goods-receival-note/goods-receival-note-mutation.ts +38 -4
- 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 +0 -6
- package/server/service/order-product/order-product.ts +4 -0
- package/server/service/order-vas/order-vas.ts +1 -6
- package/server/service/others/other-query.ts +219 -231
- 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 +2 -3
- package/server/service/release-good/release-good-types.ts +3 -4
- package/server/service/return-order/return-order-mutation.ts +1 -4
- 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 +149 -75
- 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,
|
|
@@ -188,12 +187,6 @@ export class OtherQuery {
|
|
|
188
187
|
operator: 'eq',
|
|
189
188
|
value: orderInventory.packingType
|
|
190
189
|
})
|
|
191
|
-
} else {
|
|
192
|
-
filters.push({
|
|
193
|
-
name: 'packingType',
|
|
194
|
-
operator: 'eq',
|
|
195
|
-
value: ''
|
|
196
|
-
})
|
|
197
190
|
}
|
|
198
191
|
|
|
199
192
|
const params: any = {
|
|
@@ -212,30 +205,32 @@ export class OtherQuery {
|
|
|
212
205
|
|
|
213
206
|
let packageUomValue = availableItem ? availableItem.remainUomValue / availableItem.remainQty : null
|
|
214
207
|
const newOrderInventory: any = {
|
|
215
|
-
product:
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
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,
|
|
239
234
|
releaseQty: orderInventory.releaseQty
|
|
240
235
|
? Number.isInteger(orderInventory.releaseQty)
|
|
241
236
|
? orderInventory.releaseQty
|
|
@@ -247,7 +242,7 @@ export class OtherQuery {
|
|
|
247
242
|
: null
|
|
248
243
|
: null,
|
|
249
244
|
groupType: availableItem ? availableItem.groupType : null,
|
|
250
|
-
isError: !availableItem
|
|
245
|
+
isError: !availableItem ? true : false
|
|
251
246
|
}
|
|
252
247
|
|
|
253
248
|
newOrderInventories.push(newOrderInventory)
|
|
@@ -301,132 +296,128 @@ export class OtherQuery {
|
|
|
301
296
|
@Arg('partnerBizplaceId') partnerBizplaceId: string,
|
|
302
297
|
@Arg('orderProducts', type => [NewOrderProduct], { nullable: true }) orderProducts: NewOrderProduct[]
|
|
303
298
|
): Promise<OrderProduct[]> {
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
context.state
|
|
299
|
+
const { domain, user, tx, bizplace }: { domain: Domain; user: User; tx: EntityManager; bizplace: Bizplace } =
|
|
300
|
+
context.state
|
|
307
301
|
|
|
308
|
-
|
|
302
|
+
const productDetailRepo = tx.getRepository(ProductDetail)
|
|
309
303
|
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
304
|
+
let permittedBizplaces: Bizplace[] = await getPermittedBizplaces(domain, user)
|
|
305
|
+
let foundPermittedBizplace: Bizplace
|
|
306
|
+
let companyBizplace: Bizplace
|
|
313
307
|
|
|
314
|
-
|
|
315
|
-
|
|
308
|
+
if (partnerBizplaceId) {
|
|
309
|
+
foundPermittedBizplace = permittedBizplaces.find(biz => biz.id == partnerBizplaceId)
|
|
316
310
|
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
}
|
|
323
|
-
const companyDomain: Domain = foundPermittedBizplace.company.domain
|
|
324
|
-
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
|
+
})
|
|
325
316
|
}
|
|
317
|
+
const companyDomain: Domain = foundPermittedBizplace.company.domain
|
|
318
|
+
companyBizplace = await tx.getRepository(Bizplace).findOne({ where: { domain: companyDomain } })
|
|
326
319
|
}
|
|
320
|
+
}
|
|
327
321
|
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
let strictProduct = 'false'
|
|
322
|
+
const bizplaces: Bizplace[] = [foundPermittedBizplace, companyBizplace]
|
|
323
|
+
if (bizplace) bizplaces.push(bizplace)
|
|
332
324
|
|
|
333
|
-
|
|
334
|
-
where: { domain, category: 'id-rule', name: 'strict-product-selection' }
|
|
335
|
-
})
|
|
325
|
+
let strictProduct: boolean = false
|
|
336
326
|
|
|
337
|
-
|
|
327
|
+
const strictProductSelectionSetting: Setting = await tx.getRepository(Setting).findOne({
|
|
328
|
+
where: { domain, category: 'id-rule', name: 'strict-product-selection' }
|
|
329
|
+
})
|
|
338
330
|
|
|
339
|
-
|
|
340
|
-
where: { setting: strictProductSelectionSetting, domain, partnerDomain: foundPermittedBizplace?.domain }
|
|
341
|
-
})
|
|
331
|
+
if (strictProductSelectionSetting) strictProduct = strictProductSelectionSetting.value
|
|
342
332
|
|
|
343
|
-
|
|
333
|
+
const partnerStrictProductSelectionSetting: PartnerSetting = await tx.getRepository(PartnerSetting).findOne({
|
|
334
|
+
where: { setting: strictProductSelectionSetting, domain, partnerDomain: foundPermittedBizplace?.domain }
|
|
335
|
+
})
|
|
344
336
|
|
|
345
|
-
|
|
337
|
+
if (partnerStrictProductSelectionSetting) strictProduct = partnerStrictProductSelectionSetting.value
|
|
346
338
|
|
|
347
|
-
|
|
348
|
-
const orderProduct = orderProducts[i]
|
|
349
|
-
const productSKU: string = orderProduct.productSKU
|
|
350
|
-
const foundProduct: Product = await tx.getRepository(Product).findOne({
|
|
351
|
-
where: {
|
|
352
|
-
sku: productSKU,
|
|
353
|
-
bizplace: companyBizplace
|
|
354
|
-
}
|
|
355
|
-
})
|
|
339
|
+
let newOrderProducts: any[] = []
|
|
356
340
|
|
|
357
|
-
|
|
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
|
+
})
|
|
358
350
|
|
|
359
|
-
|
|
360
|
-
let productDetail: ProductDetail
|
|
361
|
-
const hasConditions: boolean = Boolean(
|
|
362
|
-
(orderProduct?.packingType && orderProduct?.packingType.trim() != '') ||
|
|
363
|
-
(orderProduct?.uom && orderProduct?.uom.trim() != '') ||
|
|
364
|
-
orderProduct?.uomValue
|
|
365
|
-
)
|
|
366
|
-
let productDetailCondition: any = { product: foundProduct }
|
|
351
|
+
let newOrderProduct: any
|
|
367
352
|
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
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 }
|
|
371
360
|
|
|
372
|
-
|
|
361
|
+
if (hasConditions) {
|
|
362
|
+
if (orderProduct?.packingType && orderProduct.packingType.trim() != '')
|
|
363
|
+
productDetailCondition.packingType = orderProduct.packingType.trim()
|
|
373
364
|
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
365
|
+
if (orderProduct?.uom && orderProduct.uom.trim() != '') productDetailCondition.uom = orderProduct.uom.trim()
|
|
366
|
+
} else {
|
|
367
|
+
productDetailCondition.isDefault = true
|
|
368
|
+
}
|
|
378
369
|
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
370
|
+
productDetail = await productDetailRepo.findOne({
|
|
371
|
+
where: productDetailCondition
|
|
372
|
+
})
|
|
382
373
|
|
|
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
|
-
|
|
413
|
-
|
|
414
|
-
: 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}`
|
|
415
405
|
: null
|
|
416
|
-
|
|
417
|
-
}
|
|
418
|
-
|
|
406
|
+
: null
|
|
407
|
+
}
|
|
408
|
+
} else {
|
|
409
|
+
newOrderProduct = {
|
|
410
|
+
...orderProduct,
|
|
411
|
+
productName: orderProduct.productSKU,
|
|
412
|
+
isError: true
|
|
419
413
|
}
|
|
420
|
-
|
|
421
|
-
newOrderProducts.push(newOrderProduct)
|
|
422
414
|
}
|
|
423
415
|
|
|
424
|
-
|
|
425
|
-
} catch (e) {
|
|
426
|
-
return e
|
|
416
|
+
newOrderProducts.push(newOrderProduct)
|
|
427
417
|
}
|
|
428
|
-
}
|
|
429
418
|
|
|
419
|
+
return newOrderProducts
|
|
420
|
+
}
|
|
430
421
|
@Directive('@privilege(category: "order_customer", privilege: "query")')
|
|
431
422
|
@Directive('@transaction')
|
|
432
423
|
@Query(returns => [InventoryProductGroup])
|
|
@@ -435,129 +426,126 @@ export class OtherQuery {
|
|
|
435
426
|
@Arg('partnerBizplaceId') partnerBizplaceId: string,
|
|
436
427
|
@Arg('orderProducts', type => [NewOrderProduct], { nullable: true }) orderProducts: NewOrderProduct[]
|
|
437
428
|
): Promise<OrderProduct[]> {
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
context.state
|
|
429
|
+
const { domain, user, tx, bizplace }: { domain: Domain; user: User; tx: EntityManager; bizplace: Bizplace } =
|
|
430
|
+
context.state
|
|
441
431
|
|
|
442
|
-
|
|
432
|
+
const productDetailRepo = tx.getRepository(ProductDetail)
|
|
443
433
|
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
434
|
+
let permittedBizplaces: Bizplace[] = await getPermittedBizplaces(domain, user)
|
|
435
|
+
let foundPermittedBizplace: Bizplace
|
|
436
|
+
let companyBizplace: Bizplace
|
|
447
437
|
|
|
448
|
-
|
|
449
|
-
|
|
438
|
+
if (partnerBizplaceId) {
|
|
439
|
+
foundPermittedBizplace = permittedBizplaces.find(biz => biz.id == partnerBizplaceId)
|
|
450
440
|
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
}
|
|
457
|
-
const companyDomain: Domain = foundPermittedBizplace.company.domain
|
|
458
|
-
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
|
+
})
|
|
459
446
|
}
|
|
447
|
+
const companyDomain: Domain = foundPermittedBizplace.company.domain
|
|
448
|
+
companyBizplace = await tx.getRepository(Bizplace).findOne({ where: { domain: companyDomain } })
|
|
460
449
|
}
|
|
450
|
+
}
|
|
461
451
|
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
let strictProduct: boolean = false
|
|
452
|
+
const bizplaces: Bizplace[] = [foundPermittedBizplace, companyBizplace]
|
|
453
|
+
if (bizplace) bizplaces.push(bizplace)
|
|
466
454
|
|
|
467
|
-
|
|
468
|
-
where: { domain, category: 'id-rule', name: 'strict-product-selection' }
|
|
469
|
-
})
|
|
455
|
+
let strictProduct: boolean = false
|
|
470
456
|
|
|
471
|
-
|
|
457
|
+
const strictProductSelectionSetting: Setting = await tx.getRepository(Setting).findOne({
|
|
458
|
+
where: { domain, category: 'id-rule', name: 'strict-product-selection' }
|
|
459
|
+
})
|
|
472
460
|
|
|
473
|
-
|
|
474
|
-
where: { setting: strictProductSelectionSetting, domain, partnerDomain: foundPermittedBizplace?.domain }
|
|
475
|
-
})
|
|
461
|
+
if (strictProductSelectionSetting) strictProduct = strictProductSelectionSetting.value
|
|
476
462
|
|
|
477
|
-
|
|
463
|
+
const partnerStrictProductSelectionSetting: PartnerSetting = await tx.getRepository(PartnerSetting).findOne({
|
|
464
|
+
where: { setting: strictProductSelectionSetting, domain, partnerDomain: foundPermittedBizplace?.domain }
|
|
465
|
+
})
|
|
478
466
|
|
|
479
|
-
|
|
467
|
+
if (partnerStrictProductSelectionSetting) strictProduct = partnerStrictProductSelectionSetting.value
|
|
480
468
|
|
|
481
|
-
|
|
482
|
-
const orderProduct = orderProducts[i]
|
|
483
|
-
const productSKU: string = orderProduct.productSKU
|
|
484
|
-
const foundProduct: Product = await tx.getRepository(Product).findOne({
|
|
485
|
-
where: {
|
|
486
|
-
sku: productSKU,
|
|
487
|
-
bizplace: companyBizplace
|
|
488
|
-
}
|
|
489
|
-
})
|
|
469
|
+
let newOrderProducts: any[] = []
|
|
490
470
|
|
|
491
|
-
|
|
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
|
+
})
|
|
492
480
|
|
|
493
|
-
|
|
494
|
-
let productDetail: ProductDetail
|
|
495
|
-
const hasConditions: boolean = Boolean(
|
|
496
|
-
(orderProduct?.packingType && orderProduct?.packingType.trim() != '') ||
|
|
497
|
-
(orderProduct?.uom && orderProduct?.uom.trim() != '')
|
|
498
|
-
)
|
|
499
|
-
let productDetailCondition: any = { product: foundProduct }
|
|
481
|
+
let newOrderProduct: any
|
|
500
482
|
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
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 }
|
|
504
490
|
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
productDetailCondition.
|
|
508
|
-
}
|
|
491
|
+
if (hasConditions) {
|
|
492
|
+
if (orderProduct?.packingType && orderProduct.packingType.trim() != '')
|
|
493
|
+
productDetailCondition.packingType = orderProduct.packingType.trim()
|
|
509
494
|
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
495
|
+
if (orderProduct?.uom && orderProduct.uom.trim() != '') productDetailCondition.uom = orderProduct.uom.trim()
|
|
496
|
+
} else {
|
|
497
|
+
productDetailCondition.isDefault = true
|
|
498
|
+
}
|
|
513
499
|
|
|
514
|
-
|
|
500
|
+
productDetail = await productDetailRepo.findOne({
|
|
501
|
+
where: productDetailCondition
|
|
502
|
+
})
|
|
515
503
|
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
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}`
|
|
520
535
|
: null
|
|
521
|
-
:
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
packingSize: productDetail?.packingSize ? productDetail.packingSize : null,
|
|
529
|
-
uom: productDetail?.uom ? productDetail.uom : null,
|
|
530
|
-
uomValue: uomValue,
|
|
531
|
-
productName: `${foundProduct.name}(${foundProduct.description}(${foundProduct.sku}))`,
|
|
532
|
-
productBrand: foundProduct?.brand ? foundProduct.brand : null,
|
|
533
|
-
isError: productDetail ? false : true,
|
|
534
|
-
product: {
|
|
535
|
-
id: foundProduct.id,
|
|
536
|
-
name: foundProduct.name,
|
|
537
|
-
sku: foundProduct.sku,
|
|
538
|
-
type: foundProduct.type,
|
|
539
|
-
brand: foundProduct.brand,
|
|
540
|
-
primaryUnit: productDetail?.uom ? productDetail.uom : null,
|
|
541
|
-
primaryValue: productDetail?.uomValue ? productDetail.uomValue : null
|
|
542
|
-
},
|
|
543
|
-
productDetail,
|
|
544
|
-
totalUomValue:
|
|
545
|
-
orderProduct.packQty > 0
|
|
546
|
-
? uomValue
|
|
547
|
-
? `${(orderProduct.packQty * uomValue).toFixed(2)} ${productDetail.uom}`
|
|
548
|
-
: null
|
|
549
|
-
: null
|
|
550
|
-
}
|
|
551
|
-
} else {
|
|
552
|
-
throw new Error(`(${orderProduct.productSKU}) sku not found`)
|
|
536
|
+
: null
|
|
537
|
+
}
|
|
538
|
+
} else {
|
|
539
|
+
newOrderProduct = {
|
|
540
|
+
...orderProduct,
|
|
541
|
+
productName: orderProduct.productSKU,
|
|
542
|
+
isError: true
|
|
553
543
|
}
|
|
554
|
-
|
|
555
|
-
newOrderProducts.push(newOrderProduct)
|
|
556
544
|
}
|
|
557
545
|
|
|
558
|
-
|
|
559
|
-
} catch (e) {
|
|
560
|
-
return e
|
|
546
|
+
newOrderProducts.push(newOrderProduct)
|
|
561
547
|
}
|
|
548
|
+
|
|
549
|
+
return newOrderProducts
|
|
562
550
|
}
|
|
563
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,
|