@things-factory/sales-base 4.0.39 → 4.0.40
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/controllers/ecommerce/sellercraft-controller.js +4 -3
- package/dist-server/controllers/ecommerce/sellercraft-controller.js.map +1 -1
- package/dist-server/service/arrival-notice/arrival-notice-mutation.js +40 -33
- package/dist-server/service/arrival-notice/arrival-notice-mutation.js.map +1 -1
- package/dist-server/service/arrival-notice/arrival-notice-query.js +88 -76
- package/dist-server/service/arrival-notice/arrival-notice-query.js.map +1 -1
- package/dist-server/service/arrival-notice/arrival-notice-types.js +8 -0
- package/dist-server/service/arrival-notice/arrival-notice-types.js.map +1 -1
- package/dist-server/service/arrival-notice/arrival-notice.js +20 -15
- package/dist-server/service/arrival-notice/arrival-notice.js.map +1 -1
- package/dist-server/service/delivery-order/delivery-order-mutation.js +28 -26
- package/dist-server/service/delivery-order/delivery-order-mutation.js.map +1 -1
- package/dist-server/service/delivery-order/delivery-order-query.js +14 -14
- package/dist-server/service/delivery-order/delivery-order-query.js.map +1 -1
- package/dist-server/service/delivery-order/delivery-order-summary-report.js +145 -0
- package/dist-server/service/delivery-order/delivery-order-summary-report.js.map +1 -0
- package/dist-server/service/delivery-order/delivery-order.js +16 -13
- package/dist-server/service/delivery-order/delivery-order.js.map +1 -1
- package/dist-server/service/delivery-order/index.js +3 -1
- package/dist-server/service/delivery-order/index.js.map +1 -1
- package/dist-server/service/index.js +12 -4
- package/dist-server/service/index.js.map +1 -1
- package/dist-server/service/invoice/invoice-mutation.js +21 -3
- package/dist-server/service/invoice/invoice-mutation.js.map +1 -1
- package/dist-server/service/invoice/invoice-query.js +5 -7
- package/dist-server/service/invoice/invoice-query.js.map +1 -1
- package/dist-server/service/invoice/invoice-types.js +302 -20
- package/dist-server/service/invoice/invoice-types.js.map +1 -1
- package/dist-server/service/invoice/invoice.js +190 -26
- package/dist-server/service/invoice/invoice.js.map +1 -1
- package/dist-server/service/invoice-product/index.js +21 -0
- package/dist-server/service/invoice-product/index.js.map +1 -0
- package/dist-server/service/invoice-product/invoice-product-mutation.js +70 -0
- package/dist-server/service/invoice-product/invoice-product-mutation.js.map +1 -0
- package/dist-server/service/invoice-product/invoice-product-query.js +95 -0
- package/dist-server/service/invoice-product/invoice-product-query.js.map +1 -0
- package/dist-server/service/invoice-product/invoice-product-types.js +125 -0
- package/dist-server/service/invoice-product/invoice-product-types.js.map +1 -0
- package/dist-server/service/invoice-product/invoice-product.js +117 -0
- package/dist-server/service/invoice-product/invoice-product.js.map +1 -0
- package/dist-server/service/order-inventory/order-inventory-query.js +9 -7
- package/dist-server/service/order-inventory/order-inventory-query.js.map +1 -1
- package/dist-server/service/order-inventory/order-inventory.js +28 -22
- package/dist-server/service/order-inventory/order-inventory.js.map +1 -1
- package/dist-server/service/order-product/order-product.js +26 -21
- package/dist-server/service/order-product/order-product.js.map +1 -1
- package/dist-server/service/order-vas/order-vas.js +34 -27
- package/dist-server/service/order-vas/order-vas.js.map +1 -1
- package/dist-server/service/purchase-order/purchase-order-mutation.js +23 -36
- package/dist-server/service/purchase-order/purchase-order-mutation.js.map +1 -1
- package/dist-server/service/release-good/release-good-mutation.js +64 -74
- package/dist-server/service/release-good/release-good-mutation.js.map +1 -1
- package/dist-server/service/release-good/release-good-query.js +5 -5
- package/dist-server/service/release-good/release-good-query.js.map +1 -1
- package/dist-server/service/release-good/release-good.js +2 -0
- package/dist-server/service/release-good/release-good.js.map +1 -1
- package/dist-server/service/return-order/return-order-mutation.js +3 -3
- package/dist-server/service/return-order/return-order-mutation.js.map +1 -1
- package/dist-server/utils/order-no-generator.js +7 -0
- package/dist-server/utils/order-no-generator.js.map +1 -1
- package/package.json +12 -12
- package/server/controllers/ecommerce/sellercraft-controller.ts +2 -1
- package/server/service/arrival-notice/arrival-notice-mutation.ts +9 -13
- package/server/service/arrival-notice/arrival-notice-query.ts +92 -76
- package/server/service/arrival-notice/arrival-notice-types.ts +6 -0
- package/server/service/arrival-notice/arrival-notice.ts +6 -1
- package/server/service/delivery-order/delivery-order-mutation.ts +4 -8
- package/server/service/delivery-order/delivery-order-query.ts +4 -4
- package/server/service/delivery-order/delivery-order-summary-report.ts +152 -0
- package/server/service/delivery-order/delivery-order.ts +4 -1
- package/server/service/delivery-order/index.ts +3 -1
- package/server/service/index.ts +20 -12
- package/server/service/invoice/invoice-mutation.ts +45 -7
- package/server/service/invoice/invoice-query.ts +6 -6
- package/server/service/invoice/invoice-types.ts +231 -18
- package/server/service/invoice/invoice.ts +154 -20
- package/server/service/invoice-product/index.ts +9 -0
- package/server/service/invoice-product/invoice-product-mutation.ts +54 -0
- package/server/service/invoice-product/invoice-product-query.ts +55 -0
- package/server/service/invoice-product/invoice-product-types.ts +80 -0
- package/server/service/invoice-product/invoice-product.ts +93 -0
- package/server/service/order-inventory/order-inventory-query.ts +3 -1
- package/server/service/order-inventory/order-inventory.ts +7 -9
- package/server/service/order-product/order-product.ts +13 -13
- package/server/service/order-vas/order-vas.ts +15 -15
- package/server/service/purchase-order/purchase-order-mutation.ts +19 -21
- package/server/service/release-good/release-good-mutation.ts +28 -45
- package/server/service/release-good/release-good-query.ts +9 -16
- package/server/service/release-good/release-good.ts +2 -0
- package/server/service/return-order/return-order-mutation.ts +5 -4
- package/server/utils/order-no-generator.ts +11 -0
|
@@ -3,7 +3,8 @@ import { Product, ProductDetail } from '@things-factory/product-base'
|
|
|
3
3
|
import { Inventory, INVENTORY_STATUS, LOCATION_TYPE } from '@things-factory/warehouse-base'
|
|
4
4
|
|
|
5
5
|
import { ORDER_PRODUCT_STATUS } from '../../constants'
|
|
6
|
-
import { OrderProduct
|
|
6
|
+
import { OrderProduct } from '../../service/order-product/order-product'
|
|
7
|
+
import { ReleaseGood } from '../../service/release-good/release-good'
|
|
7
8
|
import { OrderController } from '../order-controller'
|
|
8
9
|
|
|
9
10
|
export class SellercraftController extends OrderController {
|
|
@@ -17,18 +17,6 @@ import { Product } from '@things-factory/product-base'
|
|
|
17
17
|
import { Setting } from '@things-factory/setting-base'
|
|
18
18
|
import { Domain } from '@things-factory/shell'
|
|
19
19
|
|
|
20
|
-
import {
|
|
21
|
-
ArrivalNoticePatch,
|
|
22
|
-
CollectionOrder,
|
|
23
|
-
JobSheet,
|
|
24
|
-
NewArrivalNotice,
|
|
25
|
-
NewOrderProduct,
|
|
26
|
-
OrderProduct,
|
|
27
|
-
OrderProductPatch,
|
|
28
|
-
OrderVas,
|
|
29
|
-
ReleaseGood,
|
|
30
|
-
Vas
|
|
31
|
-
} from '../'
|
|
32
20
|
import {
|
|
33
21
|
ORDER_NUMBER_RULE_TYPE,
|
|
34
22
|
ORDER_NUMBER_SETTING_KEY,
|
|
@@ -40,11 +28,18 @@ import {
|
|
|
40
28
|
import { ATTACHMENT_TYPE } from '../../constants/attachment-type'
|
|
41
29
|
import { ValidationError } from '../../errors'
|
|
42
30
|
import { OrderNoGenerator } from '../../utils/order-no-generator'
|
|
31
|
+
import { CollectionOrder } from '../collection-order/collection-order'
|
|
32
|
+
import { JobSheet } from '../job-sheet/job-sheet'
|
|
43
33
|
import { generateJobSheet } from '../job-sheet/job-sheet-mutation'
|
|
34
|
+
import { OrderProduct } from '../order-product/order-product'
|
|
35
|
+
import { NewOrderProduct, OrderProductPatch } from '../order-product/order-product-types'
|
|
36
|
+
import { OrderVas } from '../order-vas/order-vas'
|
|
37
|
+
import { ReleaseGood } from '../release-good/release-good'
|
|
44
38
|
import { confirmReleaseGood, deleteReleaseGood, rejectReleaseGood } from '../release-good/release-good-mutation'
|
|
39
|
+
import { Vas } from '../vas/vas'
|
|
45
40
|
import { validateBulkArrivalNoticesFunction } from './'
|
|
46
41
|
import { ArrivalNotice } from './arrival-notice'
|
|
47
|
-
import { ArrivalNoticeList, RawArrivalNotice } from './arrival-notice-types'
|
|
42
|
+
import { ArrivalNoticeList, ArrivalNoticePatch, NewArrivalNotice, RawArrivalNotice } from './arrival-notice-types'
|
|
48
43
|
|
|
49
44
|
const debug = require('debug')('things-factory:operato-wms:addArrivalNotice')
|
|
50
45
|
|
|
@@ -956,6 +951,7 @@ function extractArrivalNotices(rawArrivalNotices): Partial<ArrivalNotice[]> {
|
|
|
956
951
|
const orderProduct: Partial<OrderProduct> = {
|
|
957
952
|
product,
|
|
958
953
|
batchId: raw.batchId,
|
|
954
|
+
batchIdRef: raw.batchIdRef,
|
|
959
955
|
packingType: raw.packingType,
|
|
960
956
|
packingSize: raw.packingSize,
|
|
961
957
|
packQty: raw.packQty,
|
|
@@ -349,6 +349,7 @@ export async function validateBulkArrivalNoticesFunction(
|
|
|
349
349
|
container_size: raw.containerSize || null,
|
|
350
350
|
sku: raw.sku || null,
|
|
351
351
|
batch_id: raw.batchId || null,
|
|
352
|
+
batch_id_ref: raw.batchIdRef || null,
|
|
352
353
|
packing_type: raw.packingType || null,
|
|
353
354
|
packing_size: raw.packingSize || null,
|
|
354
355
|
uom: raw.uom || null,
|
|
@@ -362,7 +363,7 @@ export async function validateBulkArrivalNoticesFunction(
|
|
|
362
363
|
|
|
363
364
|
await trxMgr.query(
|
|
364
365
|
`
|
|
365
|
-
CREATE TEMP TABLE
|
|
366
|
+
CREATE TEMP TABLE raw_arrival_notices(
|
|
366
367
|
ref_no VARCHAR(150),
|
|
367
368
|
ref_no_2 VARCHAR(150),
|
|
368
369
|
ref_no_3 VARCHAR(150),
|
|
@@ -376,6 +377,7 @@ export async function validateBulkArrivalNoticesFunction(
|
|
|
376
377
|
loose_item BOOLEAN,
|
|
377
378
|
sku VARCHAR(150),
|
|
378
379
|
batch_id VARCHAR(100),
|
|
380
|
+
batch_id_ref VARCHAR(100),
|
|
379
381
|
packing_type VARCHAR(50),
|
|
380
382
|
packing_size INT,
|
|
381
383
|
uom VARCHAR(10),
|
|
@@ -389,30 +391,39 @@ export async function validateBulkArrivalNoticesFunction(
|
|
|
389
391
|
|
|
390
392
|
await trxMgr.query(
|
|
391
393
|
`
|
|
392
|
-
|
|
394
|
+
CREATE TEMP TABLE temp_gan AS (
|
|
395
|
+
SELECT an.name, an.ref_no, an.ref_no_2, an.ref_no_3, an.eta_date, an.truck_no, an.own_transport, an.container, an.container_no, an.container_size, an.import_cargo, an.loose_item
|
|
396
|
+
FROM arrival_notices an
|
|
397
|
+
WHERE EXISTS (
|
|
398
|
+
SELECT raw.* FROM
|
|
399
|
+
JSON_POPULATE_RECORDSET(NULL:: arrival_notices, $1) raw
|
|
400
|
+
WHERE raw.ref_no = an.ref_no
|
|
401
|
+
AND raw.ref_no_2 = an.ref_no_2
|
|
402
|
+
AND raw.ref_no_3 = an.ref_no_3
|
|
403
|
+
AND raw.eta_date::date = an.eta_date::date
|
|
404
|
+
AND raw.truck_no = an.truck_no
|
|
405
|
+
AND raw.own_transport = an.own_transport
|
|
406
|
+
AND raw.container = an.container
|
|
407
|
+
AND raw.container_no = an.container_no
|
|
408
|
+
AND raw.container_size = an.container_size
|
|
409
|
+
AND raw.loose_item = an.loose_item
|
|
410
|
+
AND raw.import_cargo = an.import_cargo
|
|
411
|
+
)
|
|
412
|
+
)
|
|
413
|
+
`,
|
|
414
|
+
[json_oi]
|
|
415
|
+
)
|
|
416
|
+
|
|
417
|
+
await trxMgr.query(
|
|
418
|
+
`
|
|
419
|
+
INSERT INTO raw_arrival_notices
|
|
393
420
|
SELECT
|
|
394
|
-
js.ref_no,
|
|
395
|
-
js.
|
|
396
|
-
js.
|
|
397
|
-
js.
|
|
398
|
-
js.truck_no,
|
|
399
|
-
js.own_transport,
|
|
400
|
-
js.container,
|
|
401
|
-
js.container_no,
|
|
402
|
-
js.container_size,
|
|
403
|
-
js.import_cargo,
|
|
404
|
-
js.loose_item,
|
|
405
|
-
js.sku,
|
|
406
|
-
js.batch_id,
|
|
407
|
-
js.packing_type,
|
|
408
|
-
js.packing_size,
|
|
409
|
-
js.uom,
|
|
410
|
-
js.pack_qty,
|
|
411
|
-
js.pallet_qty,
|
|
412
|
-
js.unit_price,
|
|
413
|
-
js.manufacture_year
|
|
421
|
+
js.ref_no, js.ref_no_2, js.ref_no_3, js.eta_date, js.truck_no, js.own_transport, js.container,
|
|
422
|
+
js.container_no, js.container_size, js.import_cargo, js.loose_item, js.sku, js.batch_id,
|
|
423
|
+
js.batch_id_ref, js.packing_type, js.packing_size, js.uom, js.pack_qty, js.pallet_qty,
|
|
424
|
+
js.unit_price, js.manufacture_year
|
|
414
425
|
FROM
|
|
415
|
-
JSON_POPULATE_RECORDSET(NULL
|
|
426
|
+
JSON_POPULATE_RECORDSET(NULL:: raw_arrival_notices, $1) js;
|
|
416
427
|
`,
|
|
417
428
|
[json_oi]
|
|
418
429
|
)
|
|
@@ -420,71 +431,75 @@ export async function validateBulkArrivalNoticesFunction(
|
|
|
420
431
|
let validatedItems = await trxMgr.query(
|
|
421
432
|
`
|
|
422
433
|
SELECT
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
+
raw.ref_no,
|
|
435
|
+
raw.ref_no_2,
|
|
436
|
+
raw.ref_no_3,
|
|
437
|
+
raw.eta_date,
|
|
438
|
+
raw.truck_no,
|
|
439
|
+
raw.own_transport,
|
|
440
|
+
raw.container,
|
|
441
|
+
raw.container_no,
|
|
442
|
+
raw.container_size,
|
|
443
|
+
raw.import_cargo,
|
|
444
|
+
raw.loose_item,
|
|
434
445
|
pr.id AS product_id,
|
|
435
446
|
pd.id AS product_detail_id,
|
|
436
|
-
|
|
447
|
+
raw.sku AS sku,
|
|
437
448
|
CASE WHEN pr.description NOT IN (NULL, '', '-') THEN CONCAT(pr.name, '(', pr.description, ')') ELSE pr.name END AS product_info,
|
|
438
|
-
|
|
449
|
+
raw.batch_id,
|
|
450
|
+
raw.batch_id_ref,
|
|
439
451
|
pd.packing_type,
|
|
440
452
|
pd.packing_size,
|
|
441
|
-
|
|
442
|
-
pd.uom_value,
|
|
443
|
-
pd.uom,
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
CASE WHEN an.
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
ELSE '' END AS error_msg
|
|
453
|
+
sum(raw.pack_qty) AS pack_qty,
|
|
454
|
+
sum(pd.uom_value) AS uom_value,
|
|
455
|
+
CONCAT(SUM(COALESCE(ROUND(pd.uom_value:: numeric, 2), 0)) * SUM(COALESCE(raw.pack_qty, 0)), ' ', pd.uom) AS total_uom_value,
|
|
456
|
+
pd.uom,
|
|
457
|
+
sum(raw.pallet_qty) AS pallet_qty,
|
|
458
|
+
raw.unit_price,
|
|
459
|
+
raw.manufacture_year,
|
|
460
|
+
CASE WHEN an.ref_no NOTNULL THEN concat('order duplicated with ', an.name)
|
|
461
|
+
WHEN pr.id ISNULL OR pd.id ISNULL OR raw.sku ISNULL THEN 'product not found'
|
|
462
|
+
WHEN raw.pack_qty ISNULL OR raw.pack_qty <= 0 THEN 'invalid pack qty'
|
|
463
|
+
WHEN raw.batch_id ISNULL THEN 'batch no. is required'
|
|
464
|
+
WHEN raw.ref_no ISNULL OR raw.ref_no = '' THEN 'ref no. is required'
|
|
465
|
+
WHEN raw.eta_date ISNULL OR raw.eta_date = '' THEN 'eta date is required'
|
|
466
|
+
WHEN raw.eta_date::date < now()::date THEN 'backdate is not allowed'
|
|
467
|
+
WHEN raw.container_no NOTNULL AND raw.container_size ISNULL OR raw.container_no ISNULL AND raw.container_size NOTNULL THEN 'incomplete container information'
|
|
468
|
+
WHEN raw.unit_price < 0 THEN 'invalid unit price'
|
|
469
|
+
WHEN raw.pallet_qty < 0 THEN 'invalid pallet qty'
|
|
470
|
+
ELSE '' END AS error_msg
|
|
459
471
|
FROM
|
|
460
|
-
|
|
461
|
-
LEFT JOIN
|
|
462
|
-
AND
|
|
463
|
-
AND
|
|
464
|
-
AND
|
|
465
|
-
AND
|
|
466
|
-
AND
|
|
467
|
-
AND
|
|
468
|
-
AND
|
|
469
|
-
AND
|
|
470
|
-
AND
|
|
471
|
-
|
|
472
|
+
raw_arrival_notices raw
|
|
473
|
+
LEFT JOIN temp_gan an ON raw.ref_no = an.ref_no
|
|
474
|
+
AND raw.ref_no_2 = an.ref_no_2
|
|
475
|
+
AND raw.ref_no_3 = an.ref_no_3
|
|
476
|
+
AND raw.eta_date::date = an.eta_date::date
|
|
477
|
+
AND raw.truck_no = an.truck_no
|
|
478
|
+
AND raw.own_transport = an.own_transport
|
|
479
|
+
AND raw.container = an.container
|
|
480
|
+
AND raw.container_no = an.container_no
|
|
481
|
+
AND raw.container_size = an.container_size
|
|
482
|
+
AND raw.loose_item = an.loose_item
|
|
483
|
+
AND raw.import_cargo = an.import_cargo
|
|
484
|
+
LEFT JOIN products pr ON LOWER(pr.sku) = LOWER(raw.sku)
|
|
472
485
|
LEFT JOIN product_details pd ON pr.id = pd.product_id
|
|
473
|
-
AND
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
486
|
+
AND pr.bizplace_id = $1
|
|
487
|
+
AND CASE WHEN raw.packing_type NOTNULL AND raw.packing_size NOTNULL AND raw.uom NOTNULL
|
|
488
|
+
THEN pd.packing_type = raw.packing_type AND pd.packing_size = raw.packing_size AND pd.uom = raw.uom
|
|
489
|
+
WHEN raw.packing_type NOTNULL AND raw.packing_size NOTNULL AND raw.uom ISNULL
|
|
490
|
+
THEN pd.packing_type = raw.packing_type AND pd.packing_size = raw.packing_size AND pd.is_default IS TRUE
|
|
491
|
+
WHEN raw.packing_type ISNULL AND raw.packing_size ISNULL AND raw.uom NOTNULL
|
|
492
|
+
THEN pd.uom = raw.uom AND pd.is_default IS TRUE ELSE pd.is_default IS TRUE
|
|
479
493
|
END
|
|
480
|
-
|
|
481
|
-
pr.
|
|
482
|
-
|
|
494
|
+
GROUP BY raw.ref_no, raw.ref_no_2, raw.ref_no_3, raw.eta_date, raw.truck_no, raw.own_transport, raw.container, raw.container_no, raw.container_size, raw.import_cargo, raw.loose_item,
|
|
495
|
+
pr.id, pd.id, raw.sku, pr.name, pr.description, raw.batch_id, raw.batch_id_ref, raw.packing_type, raw.packing_size, raw.uom, raw.unit_price, raw.manufacture_year, an.ref_no, an.name, raw.pack_qty,
|
|
496
|
+
raw.pallet_qty
|
|
497
|
+
ORDER BY raw.ref_no, raw.ref_no_2, raw.ref_no_3, raw.sku
|
|
483
498
|
`,
|
|
484
499
|
[companyBizplace.id]
|
|
485
500
|
)
|
|
486
501
|
|
|
487
|
-
await trxMgr.query('DROP TABLE
|
|
502
|
+
await trxMgr.query('DROP TABLE raw_arrival_notices, temp_gan')
|
|
488
503
|
|
|
489
504
|
return validatedItems.map(item => {
|
|
490
505
|
let manufactureYear = item.manufacture_year
|
|
@@ -510,6 +525,7 @@ export async function validateBulkArrivalNoticesFunction(
|
|
|
510
525
|
sku: item.sku,
|
|
511
526
|
productInfo: item.product_info,
|
|
512
527
|
batchId: item.batch_id,
|
|
528
|
+
batchIdRef: item.batch_id_ref,
|
|
513
529
|
packingType: item.packing_type,
|
|
514
530
|
packingSize: item.packing_size,
|
|
515
531
|
uom: item.uom,
|
|
@@ -98,6 +98,9 @@ export class NewArrivalNotice {
|
|
|
98
98
|
@Field({ nullable: true })
|
|
99
99
|
batchId?: string
|
|
100
100
|
|
|
101
|
+
@Field({ nullable: true })
|
|
102
|
+
batchIdRef?: string
|
|
103
|
+
|
|
101
104
|
@Field({ nullable: true })
|
|
102
105
|
packingType?: string
|
|
103
106
|
|
|
@@ -263,6 +266,9 @@ export class RawArrivalNotice {
|
|
|
263
266
|
@Field({ nullable: true })
|
|
264
267
|
batchId?: string
|
|
265
268
|
|
|
269
|
+
@Field({ nullable: true })
|
|
270
|
+
batchIdRef?: string
|
|
271
|
+
|
|
266
272
|
@Field({ nullable: true })
|
|
267
273
|
packingType?: string
|
|
268
274
|
|
|
@@ -18,7 +18,12 @@ import { User } from '@things-factory/auth-base'
|
|
|
18
18
|
import { Bizplace, ContactPoint } from '@things-factory/biz-base'
|
|
19
19
|
import { Domain } from '@things-factory/shell'
|
|
20
20
|
|
|
21
|
-
import { CollectionOrder
|
|
21
|
+
import { CollectionOrder } from '../collection-order/collection-order'
|
|
22
|
+
import { OrderInventory } from '../order-inventory/order-inventory'
|
|
23
|
+
import { OrderProduct } from '../order-product/order-product'
|
|
24
|
+
import { OrderVas } from '../order-vas/order-vas'
|
|
25
|
+
import { PurchaseOrder } from '../purchase-order/purchase-order'
|
|
26
|
+
import { ReleaseGood } from '../release-good/release-good'
|
|
22
27
|
|
|
23
28
|
@Entity()
|
|
24
29
|
@Index('ix_arrival-notice_0', (arrivalNotice: ArrivalNotice) => [arrivalNotice.domain, arrivalNotice.name], {
|
|
@@ -12,14 +12,6 @@ import { Domain, ObjectRef } from '@things-factory/shell'
|
|
|
12
12
|
import { TransportDriver, TransportVehicle, TRUCK_STATUS } from '@things-factory/transport-base'
|
|
13
13
|
import { Inventory } from '@things-factory/warehouse-base'
|
|
14
14
|
|
|
15
|
-
import {
|
|
16
|
-
DeliveryOrderPatch,
|
|
17
|
-
NewDeliveryOrder,
|
|
18
|
-
NewOrderInventory,
|
|
19
|
-
OrderInventory,
|
|
20
|
-
OrderInventoryPatch,
|
|
21
|
-
ReleaseGood
|
|
22
|
-
} from '../'
|
|
23
15
|
import {
|
|
24
16
|
ORDER_INVENTORY_STATUS,
|
|
25
17
|
ORDER_NUMBER_RULE_TYPE,
|
|
@@ -28,7 +20,11 @@ import {
|
|
|
28
20
|
ORDER_TYPES
|
|
29
21
|
} from '../../constants'
|
|
30
22
|
import { OrderNoGenerator } from '../../utils/order-no-generator'
|
|
23
|
+
import { OrderInventory } from '../order-inventory/order-inventory'
|
|
24
|
+
import { NewOrderInventory, OrderInventoryPatch } from '../order-inventory/order-inventory-types'
|
|
25
|
+
import { ReleaseGood } from '../release-good/release-good'
|
|
31
26
|
import { DeliveryOrder } from './delivery-order'
|
|
27
|
+
import { DeliveryOrderPatch, NewDeliveryOrder } from './delivery-order-types'
|
|
32
28
|
|
|
33
29
|
@Resolver(DeliveryOrder)
|
|
34
30
|
export class DeliveryOrderMutation {
|
|
@@ -8,9 +8,12 @@ import { Product } from '@things-factory/product-base'
|
|
|
8
8
|
import { buildQuery, convertListParams, Domain, Filter, ListParam, Pagination, Sorting } from '@things-factory/shell'
|
|
9
9
|
import { Inventory } from '@things-factory/warehouse-base'
|
|
10
10
|
|
|
11
|
-
import { DeliveryOrderList, OrderInventory, OrderInventoryList, ReleaseGood } from '../'
|
|
12
11
|
import { ORDER_STATUS } from '../../constants'
|
|
12
|
+
import { OrderInventory } from '../order-inventory/order-inventory'
|
|
13
|
+
import { OrderInventoryList } from '../order-inventory/order-inventory-types'
|
|
14
|
+
import { ReleaseGood } from '../release-good/release-good'
|
|
13
15
|
import { DeliveryOrder } from './delivery-order'
|
|
16
|
+
import { DeliveryOrderList } from './delivery-order-types'
|
|
14
17
|
|
|
15
18
|
const debug = require('debug')('things-factory:sales-base:delivery-orders')
|
|
16
19
|
|
|
@@ -100,9 +103,6 @@ export class DeliveryOrderQuery {
|
|
|
100
103
|
qb.leftJoinAndSelect('do.releaseGood', 'releaseGood')
|
|
101
104
|
qb.leftJoinAndSelect('do.transportDriver', 'td')
|
|
102
105
|
qb.leftJoinAndSelect('do.transportVehicle', 'th')
|
|
103
|
-
qb.leftJoinAndSelect('do.orderInventories', 'oi')
|
|
104
|
-
qb.leftJoinAndSelect('oi.inventory', 'inv')
|
|
105
|
-
qb.leftJoinAndSelect('inv.product', 'prd')
|
|
106
106
|
qb.leftJoinAndSelect('do.creator', 'creator')
|
|
107
107
|
qb.leftJoinAndSelect('do.updater', 'updater')
|
|
108
108
|
qb.leftJoin(
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { Args, Ctx, Query, Resolver } from 'type-graphql'
|
|
2
|
+
import { getRepository } from 'typeorm'
|
|
3
|
+
|
|
4
|
+
import { User } from '@things-factory/auth-base'
|
|
5
|
+
import { getPermittedBizplaceIds } from '@things-factory/biz-base'
|
|
6
|
+
import { buildQuery, convertListParams, Domain, ListParam } from '@things-factory/shell'
|
|
7
|
+
|
|
8
|
+
import { ReleaseGood } from '../release-good/release-good'
|
|
9
|
+
import { DeliveryOrder } from './delivery-order'
|
|
10
|
+
import { DeliveryOrderList } from './delivery-order-types'
|
|
11
|
+
|
|
12
|
+
const debug = require('debug')('things-factory:sales-base:delivery-orders')
|
|
13
|
+
|
|
14
|
+
@Resolver(DeliveryOrder)
|
|
15
|
+
export class DeliveryOrderSummaryReport {
|
|
16
|
+
@Query(returns => DeliveryOrderList)
|
|
17
|
+
async deliveryOrderSummaryReport(@Ctx() context: any, @Args() params: ListParam): Promise<DeliveryOrderList> {
|
|
18
|
+
try {
|
|
19
|
+
const { domain, user }: { domain: Domain; user: User } = context.state
|
|
20
|
+
|
|
21
|
+
const bizplaceFilter = params.filters.find(param => param.name === 'bizplaceId')
|
|
22
|
+
if (!bizplaceFilter) {
|
|
23
|
+
params.filters.push({
|
|
24
|
+
name: 'bizplaceId',
|
|
25
|
+
operator: 'in',
|
|
26
|
+
value: await getPermittedBizplaceIds(domain, user),
|
|
27
|
+
relation: false
|
|
28
|
+
})
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const releaseGoodParam = params.filters.find(param => param.name === 'releaseGoodNo')
|
|
32
|
+
if (releaseGoodParam) {
|
|
33
|
+
let arrFilters = []
|
|
34
|
+
params.filters.splice(
|
|
35
|
+
params.filters.findIndex(item => item.name == 'releaseGoodNo'),
|
|
36
|
+
1
|
|
37
|
+
)
|
|
38
|
+
arrFilters.push({ ...releaseGoodParam, name: 'name' })
|
|
39
|
+
|
|
40
|
+
const foundReleaseGoods: ReleaseGood[] = await getRepository(ReleaseGood).find({
|
|
41
|
+
...convertListParams({ filters: arrFilters })
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
if (foundReleaseGoods && foundReleaseGoods.length) {
|
|
45
|
+
params.filters.push({
|
|
46
|
+
name: 'releaseGoodId',
|
|
47
|
+
operator: 'in',
|
|
48
|
+
value: foundReleaseGoods.map((releaseGood: ReleaseGood) => releaseGood.id),
|
|
49
|
+
relation: false
|
|
50
|
+
})
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const tzOffsetIdx = params.filters.findIndex(param => param.name === 'tzoffset')
|
|
55
|
+
let tzOffset = 0
|
|
56
|
+
if (tzOffsetIdx >= 0) {
|
|
57
|
+
tzOffset = params.filters[tzOffsetIdx].value
|
|
58
|
+
params.filters.splice(tzOffsetIdx, 1)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const fromDateParamIdx = params.filters.findIndex(param => param.name === 'fromDate')
|
|
62
|
+
if (fromDateParamIdx >= 0) {
|
|
63
|
+
let fromDateVal = new Date(params.filters[fromDateParamIdx].value)
|
|
64
|
+
params.filters.splice(fromDateParamIdx, 1)
|
|
65
|
+
|
|
66
|
+
params.filters.push({
|
|
67
|
+
name: 'createdAt',
|
|
68
|
+
operator: 'gte',
|
|
69
|
+
value: fromDateVal.toISOString(),
|
|
70
|
+
relation: false
|
|
71
|
+
})
|
|
72
|
+
}
|
|
73
|
+
const toDateParamIdx = params.filters.findIndex(param => param.name === 'toDate')
|
|
74
|
+
if (toDateParamIdx >= 0) {
|
|
75
|
+
let toDateVal = new Date(params.filters[toDateParamIdx].value)
|
|
76
|
+
params.filters.splice(toDateParamIdx, 1)
|
|
77
|
+
|
|
78
|
+
params.filters.push({
|
|
79
|
+
name: 'createdAt',
|
|
80
|
+
operator: 'lt',
|
|
81
|
+
value: new Date(toDateVal.setDate(toDateVal.getDate() + 1)).toISOString(),
|
|
82
|
+
relation: false
|
|
83
|
+
})
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
let refNoFilter = params.filters.find(x => x.name == 'refNo')
|
|
87
|
+
let refNo2Filter = params.filters.find(x => x.name == 'refNo2')
|
|
88
|
+
let refNo3Filter = params.filters.find(x => x.name == 'refNo3')
|
|
89
|
+
|
|
90
|
+
params.filters = params.filters.filter(x => x.name != 'refNo' && x.name != 'refNo2' && x.name != 'refNo3')
|
|
91
|
+
|
|
92
|
+
const qb: any = getRepository(DeliveryOrder).createQueryBuilder('do')
|
|
93
|
+
buildQuery(qb, params, context)
|
|
94
|
+
qb.addSelect('COALESCE("cc".rank, 99999)', 'rank')
|
|
95
|
+
qb.leftJoinAndSelect('do.domain', 'domain')
|
|
96
|
+
qb.leftJoinAndSelect('do.bizplace', 'bizplace')
|
|
97
|
+
qb.leftJoinAndSelect('do.releaseGood', 'releaseGood')
|
|
98
|
+
qb.leftJoinAndSelect('do.transportDriver', 'td')
|
|
99
|
+
qb.leftJoinAndSelect('do.transportVehicle', 'th')
|
|
100
|
+
qb.leftJoinAndSelect('do.orderInventories', 'oi')
|
|
101
|
+
qb.leftJoinAndSelect('oi.inventory', 'inv')
|
|
102
|
+
qb.leftJoinAndSelect('inv.product', 'prd')
|
|
103
|
+
qb.leftJoinAndSelect('do.creator', 'creator')
|
|
104
|
+
qb.leftJoinAndSelect('do.updater', 'updater')
|
|
105
|
+
qb.leftJoin(
|
|
106
|
+
subQuery => {
|
|
107
|
+
return subQuery
|
|
108
|
+
.select(`ccd.rank`, 'rank')
|
|
109
|
+
.addSelect(`ccd.name`, 'status')
|
|
110
|
+
.from(`common_code_details`, 'ccd')
|
|
111
|
+
.innerJoin(`ccd.commonCode`, 'cc')
|
|
112
|
+
.where(`ccd.domain_id = :domainId`, { domainId: domain.id })
|
|
113
|
+
.andWhere(`cc.name = 'DELIVERY_STATUS'`)
|
|
114
|
+
},
|
|
115
|
+
'cc',
|
|
116
|
+
'cc.status = do.status'
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
if (refNoFilter?.value) {
|
|
120
|
+
qb.andWhere('releaseGood.ref_no ilike :refNo', { refNo: refNoFilter.value })
|
|
121
|
+
}
|
|
122
|
+
if (refNo2Filter?.value) {
|
|
123
|
+
qb.andWhere('releaseGood.ref_no_2 ilike :refNo2', { refNo2: refNo2Filter.value })
|
|
124
|
+
}
|
|
125
|
+
if (refNo3Filter?.value) {
|
|
126
|
+
qb.andWhere('releaseGood.ref_no_3 ilike :refNo3', { refNo3: refNo3Filter.value })
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const arrChildSortData = ['refNo', 'refNo2', 'refNo3']
|
|
130
|
+
const arrNameSortData = ['bizplace', 'releaseGood', 'updater']
|
|
131
|
+
const sort = (params.sortings || []).reduce(
|
|
132
|
+
(acc, sort) => ({
|
|
133
|
+
...acc,
|
|
134
|
+
[arrChildSortData.indexOf(sort.name) >= 0
|
|
135
|
+
? 'releaseGood.' + sort.name
|
|
136
|
+
: arrNameSortData.indexOf(sort.name) >= 0
|
|
137
|
+
? sort.name + '.name'
|
|
138
|
+
: 'do.' + sort.name]: sort.desc ? 'DESC' : 'ASC'
|
|
139
|
+
}),
|
|
140
|
+
params.sortings.length < 1 ? { rank: 'ASC', 'do.createdAt': 'DESC' } : {}
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
qb.orderBy(sort)
|
|
144
|
+
|
|
145
|
+
const [items, total] = await qb.getManyAndCount()
|
|
146
|
+
return { items, total }
|
|
147
|
+
} catch (error) {
|
|
148
|
+
debug('deliveryOrders', error.toString())
|
|
149
|
+
throw error
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
@@ -17,7 +17,10 @@ import { Bizplace } from '@things-factory/biz-base'
|
|
|
17
17
|
import { Domain } from '@things-factory/shell'
|
|
18
18
|
import { TransportDriver, TransportVehicle } from '@things-factory/transport-base'
|
|
19
19
|
|
|
20
|
-
import { OrderInventory
|
|
20
|
+
import { OrderInventory } from '../order-inventory/order-inventory'
|
|
21
|
+
import { ReleaseGood } from '../release-good/release-good'
|
|
22
|
+
import { RetailReplenishmentOrder } from '../retail-replenishment-order/retail-replenishment-order'
|
|
23
|
+
import { TransferOrder } from '../transfer-order/transfer-order'
|
|
21
24
|
|
|
22
25
|
@Entity()
|
|
23
26
|
@Index('ix_delivery-order_0', (deliveryOrder: DeliveryOrder) => [deliveryOrder.domain, deliveryOrder.name], {
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { DeliveryOrder } from './delivery-order'
|
|
2
2
|
import { DeliveryOrderMutation } from './delivery-order-mutation'
|
|
3
3
|
import { DeliveryOrderQuery } from './delivery-order-query'
|
|
4
|
+
import { DeliveryOrderSummaryReport } from './delivery-order-summary-report'
|
|
4
5
|
|
|
5
6
|
export const entities = [DeliveryOrder]
|
|
6
|
-
export const resolvers = [DeliveryOrderQuery, DeliveryOrderMutation]
|
|
7
|
+
export const resolvers = [DeliveryOrderQuery, DeliveryOrderMutation, DeliveryOrderSummaryReport]
|
|
7
8
|
|
|
8
9
|
export * from './delivery-order-mutation'
|
|
9
10
|
export * from './delivery-order-query'
|
|
11
|
+
export * from './delivery-order-summary-report'
|
package/server/service/index.ts
CHANGED
|
@@ -1,13 +1,3 @@
|
|
|
1
|
-
/* IMPORT ENTITIES AND RESOLVERS */
|
|
2
|
-
import { entities as ManifestEntities, resolvers as ManifestResolvers } from './manifest'
|
|
3
|
-
import {
|
|
4
|
-
entities as ReverseKittingOrderInventoryEntities,
|
|
5
|
-
resolvers as ReverseKittingOrderInventoryResolvers
|
|
6
|
-
} from './reverse-kitting-order-inventory'
|
|
7
|
-
import {
|
|
8
|
-
entities as ReverseKittingOrderEntities,
|
|
9
|
-
resolvers as ReverseKittingOrderResolvers
|
|
10
|
-
} from './reverse-kitting-order'
|
|
11
1
|
import { entities as ArrivalNoticeEntity, resolvers as ArrivalNoticeResolvers } from './arrival-notice'
|
|
12
2
|
import { entities as ClaimEntity, resolvers as ClaimResolvers } from './claim'
|
|
13
3
|
import { entities as ClaimDetailEntity, resolvers as ClaimDetailResolvers } from './claim-detail'
|
|
@@ -17,7 +7,10 @@ import { entities as DeliveryOrderEntity, resolvers as DeliveryOrderResolvers }
|
|
|
17
7
|
import { entities as GoodsReceivalNoteEntity, resolvers as GoodsReceivalNoteResolvers } from './goods-receival-note'
|
|
18
8
|
import { entities as InventoryCheckEntity, resolvers as InventoryCheckResolvers } from './inventory-check'
|
|
19
9
|
import { entities as InvoiceEntity, resolvers as InvoiceResolvers } from './invoice'
|
|
10
|
+
import { entities as InvoiceProductEntity, resolvers as InvoiceProductResolvers } from './invoice-product'
|
|
20
11
|
import { entities as JobSheetEntity, resolvers as JobSheetResolvers } from './job-sheet'
|
|
12
|
+
/* IMPORT ENTITIES AND RESOLVERS */
|
|
13
|
+
import { entities as ManifestEntities, resolvers as ManifestResolvers } from './manifest'
|
|
21
14
|
import { entities as OrderInventoryEntity, resolvers as OrderInventoryResolvers } from './order-inventory'
|
|
22
15
|
import { entities as OrderProductEntity, resolvers as OrderProductResolvers } from './order-product'
|
|
23
16
|
import { entities as OrderVasEntity, resolvers as OrderVasResolvers } from './order-vas'
|
|
@@ -33,6 +26,14 @@ import {
|
|
|
33
26
|
resolvers as RetailReplenishmentOrderResolvers
|
|
34
27
|
} from './retail-replenishment-order'
|
|
35
28
|
import { entities as ReturnOrderEntity, resolvers as ReturnOrderResolvers } from './return-order'
|
|
29
|
+
import {
|
|
30
|
+
entities as ReverseKittingOrderEntities,
|
|
31
|
+
resolvers as ReverseKittingOrderResolvers
|
|
32
|
+
} from './reverse-kitting-order'
|
|
33
|
+
import {
|
|
34
|
+
entities as ReverseKittingOrderInventoryEntities,
|
|
35
|
+
resolvers as ReverseKittingOrderInventoryResolvers
|
|
36
|
+
} from './reverse-kitting-order-inventory'
|
|
36
37
|
import { entities as ShippingOrderEntity, resolvers as ShippingOrderResolvers } from './shipping-order'
|
|
37
38
|
import { entities as TransferOrderEntity, resolvers as TransferOrderResolvers } from './transfer-order'
|
|
38
39
|
import { entities as VasEntity, resolvers as VasResolvers } from './vas'
|
|
@@ -51,6 +52,7 @@ export * from './delivery-order/delivery-order'
|
|
|
51
52
|
export * from './goods-receival-note/goods-receival-note'
|
|
52
53
|
export * from './inventory-check/inventory-check'
|
|
53
54
|
export * from './invoice/invoice'
|
|
55
|
+
export * from './invoice-product/invoice-product'
|
|
54
56
|
export * from './job-sheet/job-sheet'
|
|
55
57
|
export * from './order-inventory/order-inventory'
|
|
56
58
|
export * from './order-product/order-product'
|
|
@@ -75,6 +77,7 @@ export * from './delivery-order/delivery-order-types'
|
|
|
75
77
|
export * from './goods-receival-note/goods-receival-note-types'
|
|
76
78
|
export * from './inventory-check/inventory-check-types'
|
|
77
79
|
export * from './invoice/invoice-types'
|
|
80
|
+
export * from './invoice-product/invoice-product-types'
|
|
78
81
|
export * from './job-sheet/job-sheet-types'
|
|
79
82
|
export * from './order-inventory/order-inventory-types'
|
|
80
83
|
export * from './order-product/order-product-types'
|
|
@@ -100,6 +103,7 @@ export * from './delivery-order/delivery-order-mutation'
|
|
|
100
103
|
export * from './goods-receival-note/goods-receival-note-mutation'
|
|
101
104
|
export * from './inventory-check/inventory-check-mutation'
|
|
102
105
|
export * from './invoice/invoice-mutation'
|
|
106
|
+
export * from './invoice-product/invoice-product-mutation'
|
|
103
107
|
export * from './job-sheet/job-sheet-mutation'
|
|
104
108
|
export * from './order-inventory/order-inventory-mutation'
|
|
105
109
|
export * from './order-product/order-product-mutation'
|
|
@@ -121,9 +125,11 @@ export * from './claim-order/claim-order-query'
|
|
|
121
125
|
export * from './claim/claim-query'
|
|
122
126
|
export * from './collection-order/collection-order-query'
|
|
123
127
|
export * from './delivery-order/delivery-order-query'
|
|
128
|
+
export * from './delivery-order/delivery-order-summary-report'
|
|
124
129
|
export * from './goods-receival-note/goods-receival-note-query'
|
|
125
130
|
export * from './inventory-check/inventory-check-query'
|
|
126
131
|
export * from './invoice/invoice-query'
|
|
132
|
+
export * from './invoice-product/invoice-product-query'
|
|
127
133
|
export * from './job-sheet/job-sheet-query'
|
|
128
134
|
export * from './order-inventory/order-inventory-query'
|
|
129
135
|
export * from './order-product/order-product-query'
|
|
@@ -141,7 +147,7 @@ export * from './vas/vas-query'
|
|
|
141
147
|
|
|
142
148
|
export const entities = [
|
|
143
149
|
/* ENTITIES */
|
|
144
|
-
|
|
150
|
+
...ManifestEntities,
|
|
145
151
|
...ReverseKittingOrderInventoryEntities,
|
|
146
152
|
...ReverseKittingOrderEntities,
|
|
147
153
|
...ArrivalNoticeEntity,
|
|
@@ -153,6 +159,7 @@ export const entities = [
|
|
|
153
159
|
...GoodsReceivalNoteEntity,
|
|
154
160
|
...InventoryCheckEntity,
|
|
155
161
|
...InvoiceEntity,
|
|
162
|
+
...InvoiceProductEntity,
|
|
156
163
|
...JobSheetEntity,
|
|
157
164
|
...OrderInventoryEntity,
|
|
158
165
|
...OrderProductEntity,
|
|
@@ -171,7 +178,7 @@ export const entities = [
|
|
|
171
178
|
export const schema = {
|
|
172
179
|
resolverClasses: [
|
|
173
180
|
/* RESOLVER CLASSES */
|
|
174
|
-
|
|
181
|
+
...ManifestResolvers,
|
|
175
182
|
...ReverseKittingOrderInventoryResolvers,
|
|
176
183
|
...ReverseKittingOrderResolvers,
|
|
177
184
|
...ArrivalNoticeResolvers,
|
|
@@ -183,6 +190,7 @@ export const schema = {
|
|
|
183
190
|
...GoodsReceivalNoteResolvers,
|
|
184
191
|
...InventoryCheckResolvers,
|
|
185
192
|
...InvoiceResolvers,
|
|
193
|
+
...InvoiceProductResolvers,
|
|
186
194
|
...JobSheetResolvers,
|
|
187
195
|
...OrderInventoryResolvers,
|
|
188
196
|
...OrderProductResolvers,
|