@things-factory/sales-base 4.3.212 → 4.3.214
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 +185 -138
- package/dist-server/service/arrival-notice/arrival-notice-mutation.js.map +1 -1
- package/dist-server/service/arrival-notice/arrival-notice-query.js +5 -30
- package/dist-server/service/arrival-notice/arrival-notice-query.js.map +1 -1
- package/dist-server/service/draft-release-good/draft-release-good-query.js +1 -1
- package/dist-server/service/draft-release-good/draft-release-good-query.js.map +1 -1
- package/dist-server/service/order-inventory/order-inventory.js +3 -0
- package/dist-server/service/order-inventory/order-inventory.js.map +1 -1
- package/dist-server/service/others/other-query.js +100 -57
- package/dist-server/service/others/other-query.js.map +1 -1
- package/package.json +2 -2
- package/server/service/arrival-notice/arrival-notice-mutation.ts +192 -160
- package/server/service/arrival-notice/arrival-notice-query.ts +7 -38
- package/server/service/draft-release-good/draft-release-good-query.ts +1 -1
- package/server/service/order-inventory/order-inventory.ts +5 -0
- package/server/service/others/other-query.ts +115 -89
|
@@ -212,11 +212,11 @@ export class OtherQuery {
|
|
|
212
212
|
productDetail: availableItem ? { id: availableItem.productDetailId } : null,
|
|
213
213
|
inventory: availableItem
|
|
214
214
|
? {
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
215
|
+
...availableItem,
|
|
216
|
+
remainQty: availableItem ? availableItem.remainQty : null,
|
|
217
|
+
remainUomValue: availableItem ? availableItem.remainUomValue : null,
|
|
218
|
+
remainUomValueWithUom: availableItem ? availableItem.remainUomValueWithUom : ''
|
|
219
|
+
}
|
|
220
220
|
: null,
|
|
221
221
|
productId: availableItem ? availableItem.productId : null,
|
|
222
222
|
productDetailID: availableItem ? availableItem.productDetailId : null,
|
|
@@ -299,8 +299,6 @@ export class OtherQuery {
|
|
|
299
299
|
const { domain, user, tx, bizplace }: { domain: Domain; user: User; tx: EntityManager; bizplace: Bizplace } =
|
|
300
300
|
context.state
|
|
301
301
|
|
|
302
|
-
const productDetailRepo = tx.getRepository(ProductDetail)
|
|
303
|
-
|
|
304
302
|
let permittedBizplaces: Bizplace[] = await getPermittedBizplaces(domain, user)
|
|
305
303
|
let foundPermittedBizplace: Bizplace
|
|
306
304
|
let companyBizplace: Bizplace
|
|
@@ -336,90 +334,118 @@ export class OtherQuery {
|
|
|
336
334
|
|
|
337
335
|
if (partnerStrictProductSelectionSetting) strictProduct = partnerStrictProductSelectionSetting.value
|
|
338
336
|
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
337
|
+
const json_op = JSON.stringify(
|
|
338
|
+
orderProducts.map(orderProduct => {
|
|
339
|
+
return {
|
|
340
|
+
sku: orderProduct.productSKU,
|
|
341
|
+
packing_type: orderProduct.packingType,
|
|
342
|
+
pack_qty: orderProduct.packQty,
|
|
343
|
+
pallet_qty: orderProduct.palletQty,
|
|
344
|
+
unit_price: orderProduct.unitPrice,
|
|
345
|
+
batch_id: orderProduct.batchId,
|
|
346
|
+
uom: orderProduct.uom,
|
|
347
|
+
uom_value: orderProduct.uomValue
|
|
348
348
|
}
|
|
349
349
|
})
|
|
350
|
+
)
|
|
350
351
|
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
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
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
352
|
+
// create temp table to hold the input data
|
|
353
|
+
await tx.query(`
|
|
354
|
+
CREATE TEMP TABLE raw_order_products(
|
|
355
|
+
sku VARCHAR(150),
|
|
356
|
+
packing_type VARCHAR(50),
|
|
357
|
+
pack_qty FLOAT,
|
|
358
|
+
pallet_qty FLOAT,
|
|
359
|
+
unit_price FLOAT,
|
|
360
|
+
batch_id VARCHAR(50),
|
|
361
|
+
uom VARCHAR(10),
|
|
362
|
+
uom_value FLOAT
|
|
363
|
+
);
|
|
364
|
+
`)
|
|
365
|
+
|
|
366
|
+
// insert input data into temp table
|
|
367
|
+
await tx.query(`
|
|
368
|
+
INSERT INTO raw_order_products
|
|
369
|
+
SELECT * FROM JSON_POPULATE_RECORDSET(NULL::raw_order_products, $1) js
|
|
370
|
+
`, [json_op])
|
|
371
|
+
|
|
372
|
+
// find closest matching product details from input data
|
|
373
|
+
await tx.query(`
|
|
374
|
+
create temp table matching_product_details as (
|
|
375
|
+
select row_number() over(partition by rop.sku order by is_default desc) as rn,
|
|
376
|
+
rop.sku as "rop_sku", rop.packing_type as "rop_packing_type", rop.uom as "rop_uom", rop.uom_value as "rop_uom_value", pd.*
|
|
377
|
+
from product_details pd
|
|
378
|
+
inner join products p on p.id = pd.product_id AND p.bizplace_id = $1
|
|
379
|
+
inner join raw_order_products rop ON LOWER(rop.sku) = LOWER(p.sku)
|
|
380
|
+
where
|
|
381
|
+
pd.packing_type = coalesce(rop.packing_type, pd.packing_type)
|
|
382
|
+
and pd.uom = coalesce(rop.uom, pd.uom)
|
|
383
|
+
and pd.uom_value = coalesce(rop.uom_value, pd.uom_value)
|
|
384
|
+
)`, [companyBizplace.id])
|
|
385
|
+
|
|
386
|
+
// massage data into defined structure
|
|
387
|
+
let results = await tx.query(`
|
|
388
|
+
select *,
|
|
389
|
+
case when "packQty" > 0 and "uomValue" is not null then "packQty" * "uomValue" else null end as "totalUomValue"
|
|
390
|
+
from (
|
|
391
|
+
SELECT
|
|
392
|
+
js.sku,
|
|
393
|
+
js.pack_qty as "packQty",
|
|
394
|
+
js.pallet_qty as "palletQty",
|
|
395
|
+
js.unit_price as "unitPrice",
|
|
396
|
+
js.batch_id as "batchId",
|
|
397
|
+
p.id AS "productId",
|
|
398
|
+
p.name as "productName",
|
|
399
|
+
p.brand as "productBrand",
|
|
400
|
+
p.type as "productType",
|
|
401
|
+
coalesce(mpd.uom, pdd.uom) as "productPrimaryUnit",
|
|
402
|
+
coalesce(mpd.uom_value, pdd.uom_value) as "productPrimaryValue",
|
|
403
|
+
coalesce(mpd.packing_size, pdd.packing_size) as "packingSize",
|
|
404
|
+
${strictProduct.toLowerCase() === 'false' ? `
|
|
405
|
+
coalesce(js.packing_type, mpd.packing_type, pdd.packing_type) as "packingType",
|
|
406
|
+
coalesce(js.uom, mpd.uom, js.uom) as "uom",
|
|
407
|
+
coalesce(js.uom_value, mpd.uom_value, js.uom_value) as "uomValue",
|
|
408
|
+
` : `
|
|
409
|
+
coalesce(mpd.packing_type, pdd.packing_type) as "packingType",
|
|
410
|
+
coalesce(mpd.uom, js.uom) as "uom",
|
|
411
|
+
coalesce(mpd.uom_value, js.uom_value) as "uomValue",
|
|
412
|
+
`}
|
|
413
|
+
coalesce(mpd.id, pdd.id) AS "productDetailId",
|
|
414
|
+
coalesce(mpd.cost_price, pdd.cost_price) AS "productDetailCostPrice",
|
|
415
|
+
CASE WHEN p.id is null then js.sku else concat(p.name,' (',p.description,' (',js.sku,'))') end as "productName",
|
|
416
|
+
CASE WHEN p.id is null or coalesce(mpd.id, pdd.id) is null then true else false end as "isError"
|
|
417
|
+
FROM raw_order_products js
|
|
418
|
+
LEFT JOIN products p ON LOWER(js.sku) = LOWER(p.sku) AND p.bizplace_id = $1
|
|
419
|
+
left join matching_product_details mpd on mpd.rn = 1 and mpd.rop_sku = js.sku and mpd.rop_packing_type = js.packing_type and mpd.rop_uom = js.uom
|
|
420
|
+
left join product_details pdd on p.id = pdd.product_id and pdd.is_default = true
|
|
421
|
+
) dt
|
|
422
|
+
`, [companyBizplace.id])
|
|
423
|
+
|
|
424
|
+
// remove all temp table
|
|
425
|
+
await tx.query(`DROP TABLE matching_product_details`)
|
|
426
|
+
await tx.query(`DROP TABLE raw_order_products`)
|
|
427
|
+
|
|
428
|
+
// build output structure
|
|
429
|
+
const newOrderProducts: any[] = results.map(result => {
|
|
430
|
+
return {
|
|
431
|
+
...result,
|
|
432
|
+
product: {
|
|
433
|
+
id: result.productId,
|
|
434
|
+
name: result.productName,
|
|
435
|
+
sku: result.productSku,
|
|
436
|
+
description: result.productDescription,
|
|
437
|
+
type: result.productType,
|
|
438
|
+
brand: result.productBrand,
|
|
439
|
+
primaryUnit: result.productPrimaryUnit,
|
|
440
|
+
primaryValue: result.productPrimaryValue,
|
|
441
|
+
costPrice: result.productDetailCostPrice,
|
|
442
|
+
},
|
|
443
|
+
productDetail: {
|
|
444
|
+
id: result.productDetailId,
|
|
445
|
+
costPrice: result.productDetailCostPrice,
|
|
418
446
|
}
|
|
419
447
|
}
|
|
420
|
-
|
|
421
|
-
newOrderProducts.push(newOrderProduct)
|
|
422
|
-
}
|
|
448
|
+
})
|
|
423
449
|
|
|
424
450
|
return newOrderProducts
|
|
425
451
|
} catch (e) {
|
|
@@ -494,7 +520,7 @@ export class OtherQuery {
|
|
|
494
520
|
let productDetail: ProductDetail
|
|
495
521
|
const hasConditions: boolean = Boolean(
|
|
496
522
|
(orderProduct?.packingType && orderProduct?.packingType.trim() != '') ||
|
|
497
|
-
|
|
523
|
+
(orderProduct?.uom && orderProduct?.uom.trim() != '')
|
|
498
524
|
)
|
|
499
525
|
let productDetailCondition: any = { product: foundProduct }
|
|
500
526
|
|
|
@@ -519,8 +545,8 @@ export class OtherQuery {
|
|
|
519
545
|
? productDetail.uomValue
|
|
520
546
|
: null
|
|
521
547
|
: orderProduct?.uomValue
|
|
522
|
-
|
|
523
|
-
|
|
548
|
+
? orderProduct.uomValue
|
|
549
|
+
: productDetail.uomValue
|
|
524
550
|
|
|
525
551
|
newOrderProduct = {
|
|
526
552
|
...orderProduct,
|