@things-factory/sales-base 4.3.637 → 4.3.638
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 +3 -34
- package/dist-server/service/arrival-notice/arrival-notice-mutation.js.map +1 -1
- package/dist-server/service/arrival-notice/arrival-notice-query.js +3 -10
- package/dist-server/service/arrival-notice/arrival-notice-query.js.map +1 -1
- package/dist-server/service/arrival-notice/arrival-notice-types.js +2 -2
- package/dist-server/service/arrival-notice/arrival-notice-types.js.map +1 -1
- package/dist-server/service/inventory-check-item/inventory-check-item-types.js +12 -48
- package/dist-server/service/inventory-check-item/inventory-check-item-types.js.map +1 -1
- package/dist-server/service/inventory-check-item/inventory-check-item.js +4 -56
- package/dist-server/service/inventory-check-item/inventory-check-item.js.map +1 -1
- package/dist-server/service/order-inventory/order-inventory-query.js +1 -5
- package/dist-server/service/order-inventory/order-inventory-query.js.map +1 -1
- package/dist-server/service/order-inventory/order-inventory-types.js +12 -12
- package/dist-server/service/order-inventory/order-inventory-types.js.map +1 -1
- package/dist-server/service/order-inventory/order-inventory.js +13 -189
- package/dist-server/service/order-inventory/order-inventory.js.map +1 -1
- package/dist-server/service/order-package-item/order-package-item-types.js +2 -14
- package/dist-server/service/order-package-item/order-package-item-types.js.map +1 -1
- package/dist-server/service/order-package-item/order-package-item.js +2 -28
- package/dist-server/service/order-package-item/order-package-item.js.map +1 -1
- package/dist-server/service/order-product/order-product-types.js +18 -18
- package/dist-server/service/order-product/order-product-types.js.map +1 -1
- package/dist-server/service/order-product/order-product.js +13 -104
- package/dist-server/service/order-product/order-product.js.map +1 -1
- package/dist-server/service/order-tote-item/order-tote-item-types.js +2 -2
- package/dist-server/service/order-tote-item/order-tote-item-types.js.map +1 -1
- package/dist-server/service/order-tote-item/order-tote-item.js +1 -13
- package/dist-server/service/order-tote-item/order-tote-item.js.map +1 -1
- package/dist-server/service/others/other-types.js +0 -4
- package/dist-server/service/others/other-types.js.map +1 -1
- package/dist-server/service/release-good/release-good-mutation.js +6 -35
- package/dist-server/service/release-good/release-good-mutation.js.map +1 -1
- package/dist-server/service/release-good/release-good-query.js +19 -24
- package/dist-server/service/release-good/release-good-query.js.map +1 -1
- package/dist-server/service/release-good/release-good-types.js +1 -1
- package/dist-server/service/release-good/release-good-types.js.map +1 -1
- package/dist-server/utils/inventory-util.js +8 -12
- package/dist-server/utils/inventory-util.js.map +1 -1
- package/package.json +7 -7
- package/server/service/arrival-notice/arrival-notice-mutation.ts +3 -40
- package/server/service/arrival-notice/arrival-notice-query.ts +68 -40
- package/server/service/arrival-notice/arrival-notice-types.ts +4 -4
- package/server/service/inventory-check-item/inventory-check-item-types.ts +10 -37
- package/server/service/inventory-check-item/inventory-check-item.ts +4 -52
- package/server/service/order-inventory/order-inventory-query.ts +0 -5
- package/server/service/order-inventory/order-inventory-types.ts +12 -12
- package/server/service/order-inventory/order-inventory.ts +13 -171
- package/server/service/order-package-item/order-package-item-types.ts +3 -12
- package/server/service/order-package-item/order-package-item.ts +2 -26
- package/server/service/order-product/order-product-types.ts +18 -18
- package/server/service/order-product/order-product.ts +12 -96
- package/server/service/order-tote-item/order-tote-item-types.ts +3 -3
- package/server/service/order-tote-item/order-tote-item.ts +1 -12
- package/server/service/others/other-types.ts +0 -3
- package/server/service/release-good/release-good-mutation.ts +9 -51
- package/server/service/release-good/release-good-query.ts +124 -89
- package/server/service/release-good/release-good-types.ts +1 -1
- package/server/utils/inventory-util.ts +54 -44
|
@@ -1,20 +1,62 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
Arg,
|
|
3
|
+
Args,
|
|
4
|
+
Ctx,
|
|
5
|
+
Directive,
|
|
6
|
+
FieldResolver,
|
|
7
|
+
Query,
|
|
8
|
+
Resolver,
|
|
9
|
+
Root
|
|
10
|
+
} from 'type-graphql'
|
|
11
|
+
import {
|
|
12
|
+
EntityManager,
|
|
13
|
+
getRepository,
|
|
14
|
+
In,
|
|
15
|
+
Repository,
|
|
16
|
+
SelectQueryBuilder
|
|
17
|
+
} from 'typeorm'
|
|
3
18
|
|
|
4
19
|
import { Attachment } from '@things-factory/attachment-base'
|
|
5
|
-
import {
|
|
6
|
-
|
|
20
|
+
import {
|
|
21
|
+
checkUserBelongsDomain,
|
|
22
|
+
User
|
|
23
|
+
} from '@things-factory/auth-base'
|
|
24
|
+
import {
|
|
25
|
+
Bizplace,
|
|
26
|
+
getCompanyBizplace,
|
|
27
|
+
getMyBizplace,
|
|
28
|
+
getPermittedBizplaceIds
|
|
29
|
+
} from '@things-factory/biz-base'
|
|
7
30
|
import { logger } from '@things-factory/env'
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
31
|
+
import {
|
|
32
|
+
buildQuery,
|
|
33
|
+
Domain,
|
|
34
|
+
Filter,
|
|
35
|
+
ListParam,
|
|
36
|
+
Pagination,
|
|
37
|
+
Sorting
|
|
38
|
+
} from '@things-factory/shell'
|
|
39
|
+
import {
|
|
40
|
+
Inventory,
|
|
41
|
+
LOCATION_TYPE
|
|
42
|
+
} from '@things-factory/warehouse-base'
|
|
43
|
+
|
|
44
|
+
import {
|
|
45
|
+
ATTACHMENT_TYPE,
|
|
46
|
+
ORDER_INVENTORY_STATUS,
|
|
47
|
+
ORDER_STATUS,
|
|
48
|
+
ORDER_VAS_STATUS
|
|
49
|
+
} from '../../constants'
|
|
12
50
|
import { convertExcelDateToISO } from '../../utils/datetime-util'
|
|
13
51
|
import { OrderInventory } from '../order-inventory/order-inventory'
|
|
14
52
|
import { OrderPackage } from '../order-package/order-package'
|
|
15
53
|
import { ShippingOrder } from '../shipping-order/shipping-order'
|
|
16
54
|
import { ReleaseGood } from './release-good'
|
|
17
|
-
import {
|
|
55
|
+
import {
|
|
56
|
+
NewReleaseGood,
|
|
57
|
+
ReleasableInventoryList,
|
|
58
|
+
ReleaseGoodList
|
|
59
|
+
} from './release-good-types'
|
|
18
60
|
|
|
19
61
|
@Resolver(ReleaseGood)
|
|
20
62
|
export class ReleaseGoodQuery {
|
|
@@ -478,9 +520,9 @@ export class ReleaseGoodQuery {
|
|
|
478
520
|
params.filters.splice(fromDateParamIdx, 1)
|
|
479
521
|
|
|
480
522
|
params.filters.push({
|
|
481
|
-
name: typeFilter == 'b2c' || isReleaseDateSearch.value ? 'releaseDate' : 'createdAt',
|
|
523
|
+
name: (typeFilter == 'b2c' || isReleaseDateSearch.value) ? 'releaseDate' : 'createdAt',
|
|
482
524
|
operator: 'gte',
|
|
483
|
-
value: typeFilter == 'b2c' || isReleaseDateSearch.value ? releaseDateFrom : fromDateVal.toISOString(),
|
|
525
|
+
value: (typeFilter == 'b2c' || isReleaseDateSearch.value) ? releaseDateFrom : fromDateVal.toISOString(),
|
|
484
526
|
relation: false
|
|
485
527
|
})
|
|
486
528
|
}
|
|
@@ -492,21 +534,15 @@ export class ReleaseGoodQuery {
|
|
|
492
534
|
params.filters.splice(toDateParamIdx, 1)
|
|
493
535
|
|
|
494
536
|
params.filters.push({
|
|
495
|
-
name: typeFilter == 'b2c' || isReleaseDateSearch.value ? 'releaseDate' : 'createdAt',
|
|
496
|
-
operator: typeFilter == 'b2c' || isReleaseDateSearch.value ? 'lte' : 'lt',
|
|
537
|
+
name: (typeFilter == 'b2c' || isReleaseDateSearch.value) ? 'releaseDate' : 'createdAt',
|
|
538
|
+
operator: (typeFilter == 'b2c' || isReleaseDateSearch.value) ? 'lte' : 'lt',
|
|
497
539
|
value:
|
|
498
|
-
typeFilter == 'b2c' || isReleaseDateSearch.value
|
|
499
|
-
? releaseDateTo
|
|
500
|
-
: new Date(toDateVal.setDate(toDateVal.getDate() + 1)).toISOString(),
|
|
540
|
+
(typeFilter == 'b2c' || isReleaseDateSearch.value) ? releaseDateTo : new Date(toDateVal.setDate(toDateVal.getDate() + 1)).toISOString(),
|
|
501
541
|
relation: false
|
|
502
542
|
})
|
|
503
543
|
}
|
|
504
544
|
|
|
505
|
-
if (!!isReleaseDateSearch)
|
|
506
|
-
params.filters.splice(
|
|
507
|
-
params.filters.findIndex(param => param.name == 'isReleaseDateSearch'),
|
|
508
|
-
1
|
|
509
|
-
)
|
|
545
|
+
if (!!isReleaseDateSearch) params.filters.splice(params.filters.findIndex(param => param.name == 'isReleaseDateSearch'), 1)
|
|
510
546
|
|
|
511
547
|
if (noOfItemsFilter && noOfItemsFilter.value == 1) {
|
|
512
548
|
params.filters.find(param => param.name === 'noOfItems').operator = 'eq'
|
|
@@ -541,9 +577,13 @@ export class ReleaseGoodQuery {
|
|
|
541
577
|
|
|
542
578
|
if (hasVas) {
|
|
543
579
|
if (hasVas.value == true) {
|
|
544
|
-
qb.andWhere(
|
|
580
|
+
qb.andWhere(
|
|
581
|
+
`ov.release_good_id notnull`
|
|
582
|
+
)
|
|
545
583
|
} else if (hasVas.value == false && !vasStatusFilter) {
|
|
546
|
-
qb.andWhere(
|
|
584
|
+
qb.andWhere(
|
|
585
|
+
`ov.release_good_id is null`
|
|
586
|
+
)
|
|
547
587
|
}
|
|
548
588
|
}
|
|
549
589
|
|
|
@@ -561,8 +601,7 @@ export class ReleaseGoodQuery {
|
|
|
561
601
|
release_goods rg2
|
|
562
602
|
LEFT JOIN order_vass ov2 on ov2.release_good_id = rg2.id
|
|
563
603
|
WHERE ov2.status = 'PENDING_APPROVE'
|
|
564
|
-
)`,
|
|
565
|
-
{ vasStatus: vasStatusFilter.value }
|
|
604
|
+
)`, { vasStatus: vasStatusFilter.value}
|
|
566
605
|
)
|
|
567
606
|
}
|
|
568
607
|
}
|
|
@@ -679,12 +718,12 @@ export class ReleaseGoodQuery {
|
|
|
679
718
|
platformCode: newPlatformCode ? newPlatformCode : item.platformCode,
|
|
680
719
|
transporter: orderPackages?.length
|
|
681
720
|
? [
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
721
|
+
...new Set(
|
|
722
|
+
orderPackages.map(op => {
|
|
723
|
+
return op.transporter
|
|
724
|
+
})
|
|
725
|
+
)
|
|
726
|
+
].join(', ')
|
|
688
727
|
: null,
|
|
689
728
|
orderRemark: item?.remark ? true : false
|
|
690
729
|
}
|
|
@@ -750,27 +789,24 @@ export class ReleaseGoodQuery {
|
|
|
750
789
|
${batchId ? `AND LOWER(${INV_ALIAS}.batch_id) LIKE '%${batchId.toLowerCase()}%'` : ''}
|
|
751
790
|
${packingType ? `AND LOWER(${INV_ALIAS}.packing_type) LIKE '%${packingType.toLowerCase()}%'` : ''}
|
|
752
791
|
${containerNo ? `AND LOWER(${GAN_ALIAS}.container_no) LIKE '%${containerNo.toLowerCase()}%'` : ''}
|
|
753
|
-
${
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
filters.find((filter: { name: string; operator: string; value: any }) => filter.name === 'inventory')
|
|
765
|
-
.operator
|
|
766
|
-
} (
|
|
792
|
+
${product?.length > 0 && product[0]
|
|
793
|
+
? `AND ${PROD_ALIAS}.id IN (${product.map((id: string) => `'${id}'`).join(', ')})`
|
|
794
|
+
: product[0] === null
|
|
795
|
+
? `AND ${PROD_ALIAS}.id isnull`
|
|
796
|
+
: ''
|
|
797
|
+
}
|
|
798
|
+
${inventory?.length > 0
|
|
799
|
+
? `
|
|
800
|
+
AND (${INV_ALIAS}.batch_id, ${PROD_ALIAS}.id) ${filters.find((filter: { name: string; operator: string; value: any }) => filter.name === 'inventory')
|
|
801
|
+
.operator
|
|
802
|
+
} (
|
|
767
803
|
${inventory
|
|
768
|
-
|
|
769
|
-
|
|
804
|
+
.map((inv: { batchId: string; productId: string }) => `('${inv.batchId}', '${inv.productId}')`)
|
|
805
|
+
.join(', ')}
|
|
770
806
|
)
|
|
771
807
|
`
|
|
772
|
-
|
|
773
|
-
|
|
808
|
+
: ''
|
|
809
|
+
}
|
|
774
810
|
`
|
|
775
811
|
|
|
776
812
|
// ${product?.length > 0 ? `AND ${PROD_ALIAS}.id IN (${product.map((id: string) => id ? `'${id}'` : null).join(', ')})` : ''}
|
|
@@ -960,7 +996,7 @@ export async function bulkReleaseGoodsAvailableItemsFunction(
|
|
|
960
996
|
packing_type VARCHAR(50),
|
|
961
997
|
packing_size FLOAT,
|
|
962
998
|
uom VARCHAR(10),
|
|
963
|
-
release_qty
|
|
999
|
+
release_qty INT
|
|
964
1000
|
);
|
|
965
1001
|
`
|
|
966
1002
|
)
|
|
@@ -1017,11 +1053,9 @@ export async function bulkReleaseGoodsAvailableItemsFunction(
|
|
|
1017
1053
|
AND oi.uom = i.uom
|
|
1018
1054
|
AND oi.domain_id = $1
|
|
1019
1055
|
AND oi.bizplace_id = $2
|
|
1020
|
-
), 0) as "remain_uom_value"
|
|
1021
|
-
p.is_inventory_decimal
|
|
1056
|
+
), 0) as "remain_uom_value"
|
|
1022
1057
|
FROM inventories i
|
|
1023
1058
|
LEFT JOIN locations l ON i.location_id = l.id
|
|
1024
|
-
LEFT JOIN products p ON i.product_id = p.id
|
|
1025
1059
|
INNER JOIN (
|
|
1026
1060
|
SELECT rrg.product_id, rrg.product_detail_id, rrg.sku, rrg.product_info, rrg.packing_type, rrg.packing_size, rrg.uom
|
|
1027
1061
|
FROM raw_release_goods rrg
|
|
@@ -1037,7 +1071,7 @@ export async function bulkReleaseGoodsAvailableItemsFunction(
|
|
|
1037
1071
|
AND i.obsolete = false
|
|
1038
1072
|
AND i.transfer_qty <= 0
|
|
1039
1073
|
AND i.transfer_uom_value <= 0
|
|
1040
|
-
GROUP BY i.product_id, foo.product_detail_id, foo.sku, foo.product_info, i.packing_type, i.packing_size, i.uom
|
|
1074
|
+
GROUP BY i.product_id, foo.product_detail_id, foo.sku, foo.product_info, i.packing_type, i.packing_size, i.uom
|
|
1041
1075
|
${useDetailedQuery ? ', i.batch_id, i.carton_id, i.expiration_date' : ''}
|
|
1042
1076
|
ORDER BY foo.sku, remain_qty DESC
|
|
1043
1077
|
) SELECT * FROM inv WHERE remain_qty > 0
|
|
@@ -1048,7 +1082,7 @@ export async function bulkReleaseGoodsAvailableItemsFunction(
|
|
|
1048
1082
|
await tx.query(`DROP TABLE raw_release_goods`)
|
|
1049
1083
|
|
|
1050
1084
|
availableItems = availableItems.map(item => {
|
|
1051
|
-
|
|
1085
|
+
return {
|
|
1052
1086
|
productId: item.product_id,
|
|
1053
1087
|
productDetailId: item.product_detail_id,
|
|
1054
1088
|
productInfo: item.product_info,
|
|
@@ -1060,10 +1094,8 @@ export async function bulkReleaseGoodsAvailableItemsFunction(
|
|
|
1060
1094
|
remainUomValue: item.remain_uom_value,
|
|
1061
1095
|
batchId: item.batch_id ? item.batch_id : null,
|
|
1062
1096
|
cartonId: item.carton_id ? item.carton_id : null,
|
|
1063
|
-
expirationDate: item.expiration_date ? _getStdDateStr(new Date(item.expiration_date)) : null
|
|
1064
|
-
isInventoryDecimal: item.is_inventory_decimal === true
|
|
1097
|
+
expirationDate: item.expiration_date ? _getStdDateStr(new Date(item.expiration_date)) : null
|
|
1065
1098
|
}
|
|
1066
|
-
return mappedItem
|
|
1067
1099
|
})
|
|
1068
1100
|
|
|
1069
1101
|
return _extractData(rawReleaseGoods, availableItems)
|
|
@@ -1114,10 +1146,15 @@ function _extractData(rawData, validatedData) {
|
|
|
1114
1146
|
// if sku is matched, assign qty and product id
|
|
1115
1147
|
if (idx >= 0) {
|
|
1116
1148
|
// assign qty to rawData as much as possible
|
|
1117
|
-
releaseUomValue =
|
|
1149
|
+
releaseUomValue =
|
|
1150
|
+
(Math.round((data[idx]?.remainUomValue / data[idx]?.remainQty) * 100) / 100) * raw.releaseQty
|
|
1118
1151
|
|
|
1119
1152
|
raw.assignedQty =
|
|
1120
|
-
data[idx].remainQty >= raw.releaseQty
|
|
1153
|
+
data[idx].remainQty >= raw.releaseQty
|
|
1154
|
+
? raw.releaseQty > 0
|
|
1155
|
+
? raw.releaseQty
|
|
1156
|
+
: 0
|
|
1157
|
+
: data[idx].remainQty
|
|
1121
1158
|
|
|
1122
1159
|
raw.assignedUomValue =
|
|
1123
1160
|
data[idx].remainUomValue >= releaseUomValue
|
|
@@ -1136,69 +1173,67 @@ function _extractData(rawData, validatedData) {
|
|
|
1136
1173
|
raw.packingType = data[idx].packingType
|
|
1137
1174
|
raw.packingSize = data[idx].packingSize
|
|
1138
1175
|
raw.uom = data[idx].uom
|
|
1139
|
-
raw.isInventoryDecimal = data[idx].isInventoryDecimal === true
|
|
1140
1176
|
} else {
|
|
1141
1177
|
raw.assignedQty = 0
|
|
1142
1178
|
raw.assignedUomValue = 0
|
|
1143
1179
|
raw.productId = null
|
|
1144
1180
|
}
|
|
1145
1181
|
|
|
1182
|
+
|
|
1146
1183
|
const dateRegex = /^\d{4}-\d{2}-\d{2}$/
|
|
1147
1184
|
|
|
1148
1185
|
return {
|
|
1149
1186
|
...raw,
|
|
1150
1187
|
releaseUomValue,
|
|
1151
1188
|
errorMsg: (() => {
|
|
1152
|
-
const errors = []
|
|
1189
|
+
const errors = [];
|
|
1153
1190
|
|
|
1154
|
-
if (errMsg)
|
|
1191
|
+
if (errMsg){
|
|
1155
1192
|
errors.push(errMsg)
|
|
1156
1193
|
}
|
|
1157
1194
|
if (!raw.productId || !raw.productDetailId) {
|
|
1158
|
-
errors.push('inventory or product not found')
|
|
1159
|
-
}
|
|
1160
|
-
if (raw.releaseQty <= 0) {
|
|
1161
|
-
errors.push('invalid release qty')
|
|
1195
|
+
errors.push('inventory or product not found');
|
|
1162
1196
|
}
|
|
1163
|
-
if (raw.releaseQty
|
|
1164
|
-
errors.push('
|
|
1197
|
+
if (raw.releaseQty <= 0 || raw.releaseQty % 1 !== 0) {
|
|
1198
|
+
errors.push('invalid release qty');
|
|
1165
1199
|
}
|
|
1166
1200
|
if (raw.assignedQty < raw.releaseQty) {
|
|
1167
|
-
errors.push('insufficient stock')
|
|
1201
|
+
errors.push('insufficient stock');
|
|
1168
1202
|
}
|
|
1169
|
-
if
|
|
1170
|
-
errors.push('invalid release date format. please use yyyy
|
|
1203
|
+
if(!dateRegex.test(raw.releaseDate)){
|
|
1204
|
+
errors.push('invalid release date format. please use dd/mm/yyyy')
|
|
1171
1205
|
}
|
|
1172
1206
|
if (raw.releaseDate === '') {
|
|
1173
|
-
errors.push('release date is empty')
|
|
1207
|
+
errors.push('release date is empty');
|
|
1174
1208
|
}
|
|
1175
1209
|
if (raw.releaseDate < _getStdDateStr(new Date())) {
|
|
1176
|
-
errors.push('backdate is not allowed')
|
|
1210
|
+
errors.push('backdate is not allowed');
|
|
1177
1211
|
}
|
|
1178
1212
|
if (!raw.refNo || raw.refNo === '') {
|
|
1179
|
-
errors.push('ref no is empty')
|
|
1213
|
+
errors.push('ref no is empty');
|
|
1180
1214
|
}
|
|
1181
|
-
|
|
1182
|
-
if (!raw.attentionTo) errors.push('attention to is empty')
|
|
1183
|
-
if (!raw.postalCode) errors.push('postal code is empty')
|
|
1184
|
-
if (!raw.country) errors.push('country is empty')
|
|
1185
|
-
if (!raw.deliveryAddress1) errors.push('delivery address 1 is empty')
|
|
1186
|
-
if (!raw.city) errors.push('city is empty')
|
|
1187
|
-
if (!raw.phone1) errors.push('contact is empty')
|
|
1188
|
-
if (!raw.state) errors.push('state is empty')
|
|
1215
|
+
if (raw?.type === 'b2c') {
|
|
1216
|
+
if (!raw.attentionTo) errors.push('attention to is empty');
|
|
1217
|
+
if (!raw.postalCode) errors.push('postal code is empty');
|
|
1218
|
+
if (!raw.country) errors.push('country is empty');
|
|
1219
|
+
if (!raw.deliveryAddress1) errors.push('delivery address 1 is empty');
|
|
1220
|
+
if (!raw.city) errors.push('city is empty');
|
|
1221
|
+
if (!raw.phone1) errors.push('contact is empty');
|
|
1222
|
+
if (!raw.state) errors.push('state is empty');
|
|
1189
1223
|
if ((raw.codOption && !raw.paidAmount) || raw.paidAmount < 0 || raw.paidAmount == null) {
|
|
1190
|
-
errors.push('invalid paid amount')
|
|
1224
|
+
errors.push('invalid paid amount');
|
|
1191
1225
|
}
|
|
1192
|
-
if
|
|
1226
|
+
if(raw?.expirationDate != null && !dateRegex.test(raw?.expirationDate)){
|
|
1193
1227
|
errors.push('invalid expiration date format. please use dd/mm/yyyy')
|
|
1194
1228
|
}
|
|
1195
1229
|
if (raw.airwayBill && raw.lmdOption === true) {
|
|
1196
|
-
errors.push('kindly remove AWB as LMD is marked as true')
|
|
1230
|
+
errors.push('kindly remove AWB as LMD is marked as true');
|
|
1197
1231
|
}
|
|
1198
1232
|
}
|
|
1199
|
-
return errors.length > 0 ? errors.join(', ') : ''
|
|
1200
|
-
})()
|
|
1201
|
-
}
|
|
1233
|
+
return errors.length > 0 ? errors.join(', ') : ''// Combine all errors into a single string
|
|
1234
|
+
})(),
|
|
1235
|
+
};
|
|
1236
|
+
|
|
1202
1237
|
})
|
|
1203
1238
|
}
|
|
1204
1239
|
|
|
@@ -99,7 +99,7 @@ export class InventoryInfos {
|
|
|
99
99
|
@Field(type => Float, { nullable: true })
|
|
100
100
|
packingSize?: number
|
|
101
101
|
|
|
102
|
-
@Field(type =>
|
|
102
|
+
@Field(type => Int, { nullable: false })
|
|
103
103
|
qty?: number
|
|
104
104
|
|
|
105
105
|
@Field(type => Float, { nullable: true })
|
|
@@ -1,10 +1,29 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
EntityManager,
|
|
3
|
+
Equal,
|
|
4
|
+
getRepository,
|
|
5
|
+
In,
|
|
6
|
+
Not,
|
|
7
|
+
Raw,
|
|
8
|
+
Repository,
|
|
9
|
+
SelectQueryBuilder
|
|
10
|
+
} from 'typeorm'
|
|
2
11
|
|
|
3
12
|
import { User } from '@things-factory/auth-base'
|
|
4
13
|
import { Bizplace } from '@things-factory/biz-base'
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
14
|
+
import {
|
|
15
|
+
Product,
|
|
16
|
+
ProductBundle,
|
|
17
|
+
ProductDetail
|
|
18
|
+
} from '@things-factory/product-base'
|
|
19
|
+
import {
|
|
20
|
+
PartnerSetting,
|
|
21
|
+
Setting
|
|
22
|
+
} from '@things-factory/setting-base'
|
|
23
|
+
import {
|
|
24
|
+
Domain,
|
|
25
|
+
ListParam
|
|
26
|
+
} from '@things-factory/shell'
|
|
8
27
|
import {
|
|
9
28
|
generateInventoryHistory,
|
|
10
29
|
Inventory,
|
|
@@ -284,7 +303,6 @@ export const InventoryUtil = {
|
|
|
284
303
|
COALESCE(p.sku, '') AS "productSKU",
|
|
285
304
|
COALESCE(p.brand, '') AS "productBrand",
|
|
286
305
|
p.id AS "productId",
|
|
287
|
-
p.is_inventory_decimal AS "isInventoryDecimal",
|
|
288
306
|
i.product_detail_id AS "productDetailId",
|
|
289
307
|
SUM(COALESCE(i.qty, 0)) - SUM(COALESCE(i.locked_qty, 0)) - MAX(COALESCE(bp.bundle_product_release_qty, 0)) - SUM(COALESCE(pds.unassigned_qty, 0)) AS "remainQty",
|
|
290
308
|
SUM(COALESCE(i.uom_value, 0)) - SUM(COALESCE(i.locked_uom_value, 0)) - MAX(COALESCE(bp.bundle_product_release_uom_value, 0)) - SUM(COALESCE(pds.unassigned_uom_value, 0)) AS "remainUomValue",
|
|
@@ -312,9 +330,8 @@ export const InventoryUtil = {
|
|
|
312
330
|
AND i.transfer_uom_value <= 0
|
|
313
331
|
AND i.lock_inventory is not true
|
|
314
332
|
AND CASE WHEN i.expiration_date IS NOT NULL AND p.min_outbound_shelf_life IS NOT NULL THEN CURRENT_DATE < i.expiration_date - p.min_outbound_shelf_life ELSE true END
|
|
315
|
-
${
|
|
316
|
-
|
|
317
|
-
? `AND i.id NOT IN (
|
|
333
|
+
${cycleCountFilter ?
|
|
334
|
+
`AND i.id NOT IN (
|
|
318
335
|
SELECT DISTINCT(ici.inventory_id) FROM worksheets w
|
|
319
336
|
INNER JOIN worksheet_details wd ON wd.worksheet_id = w.id
|
|
320
337
|
INNER JOIN inventory_check_items ici ON wd.target_inventory_check_item_id = ici.id
|
|
@@ -322,9 +339,8 @@ export const InventoryUtil = {
|
|
|
322
339
|
AND w.status != 'DONE'
|
|
323
340
|
AND w.bizplace_id IN (${bizplaceIds})
|
|
324
341
|
AND w.domain_id = '${domain.id}'
|
|
325
|
-
)`
|
|
326
|
-
|
|
327
|
-
}
|
|
342
|
+
)` :
|
|
343
|
+
`AND true`}
|
|
328
344
|
${productWhereClause}
|
|
329
345
|
GROUP BY
|
|
330
346
|
i.product_detail_id,
|
|
@@ -345,7 +361,6 @@ export const InventoryUtil = {
|
|
|
345
361
|
pb.sku AS "productSKU",
|
|
346
362
|
'brand' AS "productBrand",
|
|
347
363
|
id AS "productId",
|
|
348
|
-
false AS "isInventoryDecimal",
|
|
349
364
|
pbs.product_detail_id AS "productDetailId",
|
|
350
365
|
MIN(FLOOR(pbs."availableQty")) AS "remainQty",
|
|
351
366
|
MIN(FLOOR(pbs."availableUomValue")) AS "remainUomValue",
|
|
@@ -415,7 +430,7 @@ export const InventoryUtil = {
|
|
|
415
430
|
} OFFSET $1 LIMIT $2`,
|
|
416
431
|
[(params.pagination.page - 1) * params.pagination.limit, params.pagination.limit]
|
|
417
432
|
)
|
|
418
|
-
}
|
|
433
|
+
}
|
|
419
434
|
|
|
420
435
|
await trxMgr.query(`drop table temp_inventory_product_group`)
|
|
421
436
|
|
|
@@ -425,12 +440,7 @@ export const InventoryUtil = {
|
|
|
425
440
|
}
|
|
426
441
|
},
|
|
427
442
|
|
|
428
|
-
async bizplaceInventoryProductGroupImport(
|
|
429
|
-
bizplaces: Bizplace[],
|
|
430
|
-
params: ListParam,
|
|
431
|
-
context: any,
|
|
432
|
-
trxMgr: EntityManager
|
|
433
|
-
) {
|
|
443
|
+
async bizplaceInventoryProductGroupImport(bizplaces: Bizplace[], params: ListParam, context: any, trxMgr: EntityManager) {
|
|
434
444
|
try {
|
|
435
445
|
let filters = params.filters
|
|
436
446
|
const { domain }: { domain: Domain } = context.state
|
|
@@ -453,7 +463,6 @@ export const InventoryUtil = {
|
|
|
453
463
|
COALESCE(p.sku, '') AS "productSKU",
|
|
454
464
|
COALESCE(p.brand, '') AS "productBrand",
|
|
455
465
|
p.id AS "productId",
|
|
456
|
-
p.is_inventory_decimal AS "isInventoryDecimal",
|
|
457
466
|
i.product_detail_id AS "productDetailId",
|
|
458
467
|
p.picking_strategy AS "pickingStrategy",
|
|
459
468
|
i.created_at AS "createdAt",
|
|
@@ -518,7 +527,6 @@ export const InventoryUtil = {
|
|
|
518
527
|
'brand' AS "productBrand",
|
|
519
528
|
id AS "productId",
|
|
520
529
|
pbs.product_detail_id AS "productDetailId",
|
|
521
|
-
false AS "isInventoryDecimal",
|
|
522
530
|
NULL AS "pickingStrategy",
|
|
523
531
|
NULL AS "createdAt",
|
|
524
532
|
NULL AS "expirationDate",
|
|
@@ -562,37 +570,36 @@ export const InventoryUtil = {
|
|
|
562
570
|
})
|
|
563
571
|
|
|
564
572
|
const getLocationSortingClause = (inventoryAssignmentSetting: any) => {
|
|
565
|
-
|
|
573
|
+
let locationSortingRules: Array<{ name: string; desc: boolean }> = []
|
|
566
574
|
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
}
|
|
573
|
-
} catch (error) {
|
|
574
|
-
console.error('Invalid JSON in inventoryAssignmentSetting:', error)
|
|
575
|
+
if (inventoryAssignmentSetting) {
|
|
576
|
+
try {
|
|
577
|
+
let locationSetting = JSON.parse(inventoryAssignmentSetting.value)
|
|
578
|
+
for (const key in locationSetting) {
|
|
579
|
+
locationSortingRules.push({ name: key, desc: locationSetting[key] !== 'ASC' })
|
|
575
580
|
}
|
|
581
|
+
} catch (error) {
|
|
582
|
+
console.error("Invalid JSON in inventoryAssignmentSetting:", error)
|
|
576
583
|
}
|
|
584
|
+
}
|
|
577
585
|
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
rule => `
|
|
586
|
+
if (locationSortingRules.length) {
|
|
587
|
+
return locationSortingRules
|
|
588
|
+
.map(rule => `
|
|
582
589
|
CASE
|
|
583
590
|
WHEN "pickingStrategy" = 'LOCATION' THEN "${rule.name}"
|
|
584
591
|
END ${rule.desc ? 'DESC' : 'ASC'}
|
|
585
|
-
`
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
}
|
|
592
|
+
`)
|
|
593
|
+
.join(',\n')
|
|
594
|
+
}
|
|
589
595
|
|
|
590
|
-
|
|
596
|
+
return `
|
|
591
597
|
CASE
|
|
592
598
|
WHEN "pickingStrategy" = 'LOCATION' THEN "locationName"
|
|
593
599
|
END ASC
|
|
594
600
|
`
|
|
595
|
-
|
|
601
|
+
}
|
|
602
|
+
|
|
596
603
|
|
|
597
604
|
await trxMgr.query(queryStrings, [domain.id])
|
|
598
605
|
|
|
@@ -601,6 +608,7 @@ export const InventoryUtil = {
|
|
|
601
608
|
let items: any[] = []
|
|
602
609
|
|
|
603
610
|
if (!params?.pagination) {
|
|
611
|
+
|
|
604
612
|
const orderByClause = `
|
|
605
613
|
ORDER BY
|
|
606
614
|
${getLocationSortingClause(inventoryAssignmentSetting)},
|
|
@@ -621,7 +629,9 @@ export const InventoryUtil = {
|
|
|
621
629
|
ELSE NULL
|
|
622
630
|
END ASC
|
|
623
631
|
`
|
|
624
|
-
items = await trxMgr.query(
|
|
632
|
+
items = await trxMgr.query(
|
|
633
|
+
`select * from temp_inventory_product_group ${orderByClause}`
|
|
634
|
+
)
|
|
625
635
|
}
|
|
626
636
|
|
|
627
637
|
await trxMgr.query(`drop table temp_inventory_product_group`)
|
|
@@ -797,7 +807,7 @@ export const InventoryUtil = {
|
|
|
797
807
|
)
|
|
798
808
|
|
|
799
809
|
resultQb.forEach(itm => {
|
|
800
|
-
if (
|
|
810
|
+
if (itm.releaseQty > itm.availableQty) {
|
|
801
811
|
throw new ValidationError({
|
|
802
812
|
...ValidationError.ERROR_CODES.RELEASE_QTY_OVER_LIMIT,
|
|
803
813
|
detail: { data: JSON.stringify(resultQb) }
|
|
@@ -1326,7 +1336,7 @@ export function _composeTargetInventories(
|
|
|
1326
1336
|
let orderInventory: OrderInventory = new OrderInventory()
|
|
1327
1337
|
|
|
1328
1338
|
if (inventory.remainQty > leftReleaseQty) {
|
|
1329
|
-
const uomValuePerQty: number = Math.round((inventory.remainUomValue / inventory.remainQty) *
|
|
1339
|
+
const uomValuePerQty: number = Math.round((inventory.remainUomValue / inventory.remainQty) * 100) / 100
|
|
1330
1340
|
|
|
1331
1341
|
compReleaseQty += leftReleaseQty
|
|
1332
1342
|
compReleaseUomValue += leftReleaseUomValue
|
|
@@ -1334,7 +1344,7 @@ export function _composeTargetInventories(
|
|
|
1334
1344
|
orderInventory = {
|
|
1335
1345
|
...orderInventory,
|
|
1336
1346
|
releaseQty: leftReleaseQty,
|
|
1337
|
-
releaseUomValue: Math.round(leftReleaseQty * uomValuePerQty *
|
|
1347
|
+
releaseUomValue: Math.round(leftReleaseQty * uomValuePerQty * 100) / 100
|
|
1338
1348
|
}
|
|
1339
1349
|
} else {
|
|
1340
1350
|
compReleaseQty += inventory.remainQty
|