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