@things-factory/operato-hub 6.1.83 → 6.1.85
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/tsconfig.tsbuildinfo +1 -1
- package/package.json +46 -46
- package/server/controllers/bizplace-initializer/codes.ts +0 -32
- package/server/controllers/bizplace-initializer/dataset/codes.ts +0 -398
- package/server/controllers/bizplace-initializer/dataset/groups.ts +0 -21
- package/server/controllers/bizplace-initializer/dataset/index.ts +0 -5
- package/server/controllers/bizplace-initializer/dataset/menus.ts +0 -500
- package/server/controllers/bizplace-initializer/dataset/roles-privileges.ts +0 -402
- package/server/controllers/bizplace-initializer/dataset/settings.ts +0 -91
- package/server/controllers/bizplace-initializer/generate-bizplace-domain-roles.ts +0 -29
- package/server/controllers/bizplace-initializer/generate-bizplace-domain.ts +0 -56
- package/server/controllers/bizplace-initializer/groups.ts +0 -19
- package/server/controllers/bizplace-initializer/index.ts +0 -5
- package/server/controllers/bizplace-initializer/menus.ts +0 -42
- package/server/controllers/bizplace-initializer/settings.ts +0 -20
- package/server/controllers/company-initializer/business-register.ts +0 -59
- package/server/controllers/company-initializer/codes.ts +0 -147
- package/server/controllers/company-initializer/generate-company-roles.ts +0 -119
- package/server/controllers/company-initializer/index.ts +0 -6
- package/server/controllers/company-initializer/menus.ts +0 -359
- package/server/controllers/company-initializer/settings.ts +0 -33
- package/server/controllers/company-initializer/transporter.ts +0 -20
- package/server/controllers/index.ts +0 -0
- package/server/controllers/invitation.ts +0 -132
- package/server/controllers/utils/make-invitation-token.ts +0 -5
- package/server/controllers/utils/save-invitation-token.ts +0 -9
- package/server/entities/index.ts +0 -0
- package/server/errors/index.ts +0 -1
- package/server/errors/validation-error.ts +0 -17
- package/server/graphql/index.ts +0 -7
- package/server/graphql/resolvers/generators/generate-bizplace.ts +0 -40
- package/server/graphql/resolvers/generators/generate-company.ts +0 -76
- package/server/graphql/resolvers/generators/index.ts +0 -9
- package/server/graphql/resolvers/generators/update-domain-extType.ts +0 -55
- package/server/graphql/resolvers/index.ts +0 -8
- package/server/graphql/resolvers/invitations/index.ts +0 -5
- package/server/graphql/resolvers/invitations/partner-invitation.ts +0 -62
- package/server/graphql/resolvers/oauth2/company-roles-by-scope.ts +0 -38
- package/server/graphql/resolvers/oauth2/index.ts +0 -5
- package/server/graphql/resolvers/synchronization/auto-update-all-marketplace-product-variation-quantity.ts +0 -180
- package/server/graphql/resolvers/synchronization/create-dat-shipments.ts +0 -64
- package/server/graphql/resolvers/synchronization/fetch-sync-invoices.ts +0 -52
- package/server/graphql/resolvers/synchronization/fetch-sync-products.ts +0 -99
- package/server/graphql/resolvers/synchronization/fetch-sync-purchase-orders.ts +0 -75
- package/server/graphql/resolvers/synchronization/index.ts +0 -26
- package/server/graphql/resolvers/synchronization/sellercraft-pack-marketplace-order.ts +0 -91
- package/server/graphql/resolvers/synchronization/sync-all-products-to-sellercraft.ts +0 -39
- package/server/graphql/resolvers/synchronization/sync-products-from-account.ts +0 -40
- package/server/graphql/resolvers/synchronization/sync-products-to-account.ts +0 -64
- package/server/graphql/resolvers/synchronization/sync-products-to-sellercraft.ts +0 -176
- package/server/graphql/types/generators/generate-bizplace-input.ts +0 -11
- package/server/graphql/types/generators/generate-company-input.ts +0 -11
- package/server/graphql/types/generators/index.ts +0 -11
- package/server/graphql/types/generators/update-domain-type-input.ts +0 -8
- package/server/graphql/types/index.ts +0 -10
- package/server/graphql/types/invitations/index.ts +0 -5
- package/server/graphql/types/oauth2/company-role.ts +0 -8
- package/server/graphql/types/oauth2/index.ts +0 -7
- package/server/graphql/types/synchronization/index.ts +0 -33
- package/server/graphql/types/synchronization/sync-invoice-list.ts +0 -8
- package/server/graphql/types/synchronization/sync-invoice-set.ts +0 -38
- package/server/graphql/types/synchronization/sync-product-list.ts +0 -8
- package/server/graphql/types/synchronization/sync-product-set.ts +0 -8
- package/server/graphql/types/synchronization/sync-purchase-order-list.ts +0 -8
- package/server/graphql/types/synchronization/sync-purchase-order-set.ts +0 -28
- package/server/index.ts +0 -37
- package/server/middlewares/business-middleware.ts +0 -32
- package/server/middlewares/index.ts +0 -20
- package/server/middlewares/store-middleware.ts +0 -36
- package/server/middlewares/warehouse-middleware.ts +0 -36
- package/server/migrations/1597668478399-SeedBusinessDomain.ts +0 -34
- package/server/migrations/1597668478401-SeedBusinessRoles.ts +0 -377
- package/server/migrations/1608009991065-SeedUser.ts +0 -64
- package/server/migrations/index.ts +0 -9
- package/server/routers/api/index.ts +0 -3
- package/server/routers/api/restful-apis/unstable/add-contact-point.ts +0 -89
- package/server/routers/api/restful-apis/unstable/add-draft-release-order.ts +0 -198
- package/server/routers/api/restful-apis/unstable/add-inbound-order.ts +0 -246
- package/server/routers/api/restful-apis/unstable/add-marketplace-order.ts +0 -171
- package/server/routers/api/restful-apis/unstable/add-products.ts +0 -112
- package/server/routers/api/restful-apis/unstable/add-release-order.ts +0 -1061
- package/server/routers/api/restful-apis/unstable/add-sales-invoice.ts +0 -144
- package/server/routers/api/restful-apis/unstable/bizplace.ts +0 -45
- package/server/routers/api/restful-apis/unstable/cancel-marketplace-order.ts +0 -81
- package/server/routers/api/restful-apis/unstable/cancel-release-order.ts +0 -91
- package/server/routers/api/restful-apis/unstable/get-contact-point-list.ts +0 -110
- package/server/routers/api/restful-apis/unstable/get-delivery-order-detail.ts +0 -46
- package/server/routers/api/restful-apis/unstable/get-delivery-order-list.ts +0 -121
- package/server/routers/api/restful-apis/unstable/get-delivery-orders.ts +0 -178
- package/server/routers/api/restful-apis/unstable/get-goods-received-notes.ts +0 -134
- package/server/routers/api/restful-apis/unstable/get-inbound-order-detail.ts +0 -128
- package/server/routers/api/restful-apis/unstable/get-inbound-order-list.ts +0 -126
- package/server/routers/api/restful-apis/unstable/get-inventory-overall-product-group.ts +0 -99
- package/server/routers/api/restful-apis/unstable/get-inventory-product-group.ts +0 -107
- package/server/routers/api/restful-apis/unstable/get-marketplace-order-shipping-list.ts +0 -156
- package/server/routers/api/restful-apis/unstable/get-marketplace-store-list.ts +0 -81
- package/server/routers/api/restful-apis/unstable/get-onhand-inventories.ts +0 -125
- package/server/routers/api/restful-apis/unstable/get-partners.ts +0 -26
- package/server/routers/api/restful-apis/unstable/get-products.ts +0 -216
- package/server/routers/api/restful-apis/unstable/get-release-order-detail.ts +0 -138
- package/server/routers/api/restful-apis/unstable/get-release-order-list.ts +0 -199
- package/server/routers/api/restful-apis/unstable/get-warehouses.ts +0 -19
- package/server/routers/api/restful-apis/unstable/index.ts +0 -32
- package/server/routers/api/restful-apis/unstable/reject-inbound-order.ts +0 -46
- package/server/routers/api/restful-apis/unstable/set-marketplace-order-delivered.ts +0 -60
- package/server/routers/api/restful-apis/unstable/set-marketplace-order-failed-delivery.ts +0 -60
- package/server/routers/api/restful-apis/unstable/update-marketplace-order.ts +0 -111
- package/server/routers/api/restful-apis/unstable/update-marketplace-shipping-order.ts +0 -107
- package/server/routers/api/restful-apis/unstable/update-release-order-details.ts +0 -94
- package/server/routers/api/restful-apis/v1/add-contact-point.ts +0 -77
- package/server/routers/api/restful-apis/v1/add-draft-release-order.ts +0 -196
- package/server/routers/api/restful-apis/v1/add-inbound-order.ts +0 -243
- package/server/routers/api/restful-apis/v1/add-marketplace-order.ts +0 -172
- package/server/routers/api/restful-apis/v1/add-products.ts +0 -112
- package/server/routers/api/restful-apis/v1/add-release-order.ts +0 -967
- package/server/routers/api/restful-apis/v1/bizplace.ts +0 -45
- package/server/routers/api/restful-apis/v1/cancel-marketplace-order.ts +0 -81
- package/server/routers/api/restful-apis/v1/cancel-release-order.ts +0 -91
- package/server/routers/api/restful-apis/v1/get-contact-point-list.ts +0 -110
- package/server/routers/api/restful-apis/v1/get-delivery-order-detail.ts +0 -46
- package/server/routers/api/restful-apis/v1/get-delivery-order-list.ts +0 -121
- package/server/routers/api/restful-apis/v1/get-delivery-orders.ts +0 -178
- package/server/routers/api/restful-apis/v1/get-goods-received-notes.ts +0 -134
- package/server/routers/api/restful-apis/v1/get-inbound-order-detail.ts +0 -128
- package/server/routers/api/restful-apis/v1/get-inbound-order-list.ts +0 -126
- package/server/routers/api/restful-apis/v1/get-inventory-overall-product-group.ts +0 -99
- package/server/routers/api/restful-apis/v1/get-inventory-product-group.ts +0 -112
- package/server/routers/api/restful-apis/v1/get-marketplace-order-shipping-list.ts +0 -156
- package/server/routers/api/restful-apis/v1/get-marketplace-store-list.ts +0 -81
- package/server/routers/api/restful-apis/v1/get-onhand-inventories.ts +0 -125
- package/server/routers/api/restful-apis/v1/get-partners.ts +0 -26
- package/server/routers/api/restful-apis/v1/get-products.ts +0 -216
- package/server/routers/api/restful-apis/v1/get-release-order-detail.ts +0 -134
- package/server/routers/api/restful-apis/v1/get-release-order-list.ts +0 -198
- package/server/routers/api/restful-apis/v1/get-warehouses.ts +0 -19
- package/server/routers/api/restful-apis/v1/index.ts +0 -31
- package/server/routers/api/restful-apis/v1/reject-inbound-order.ts +0 -46
- package/server/routers/api/restful-apis/v1/set-marketplace-order-delivered.ts +0 -60
- package/server/routers/api/restful-apis/v1/set-marketplace-order-failed-delivery.ts +0 -60
- package/server/routers/api/restful-apis/v1/update-marketplace-order.ts +0 -111
- package/server/routers/api/restful-apis/v1/update-marketplace-shipping-order.ts +0 -104
- package/server/routers/api/restful-apis/v1/update-release-order-details.ts +0 -94
- package/server/routers/api/restful-apis/v2/add-contact-point.ts +0 -77
- package/server/routers/api/restful-apis/v2/add-draft-release-order.ts +0 -196
- package/server/routers/api/restful-apis/v2/add-inbound-order.ts +0 -243
- package/server/routers/api/restful-apis/v2/add-marketplace-order.ts +0 -172
- package/server/routers/api/restful-apis/v2/add-products.ts +0 -112
- package/server/routers/api/restful-apis/v2/add-release-order.ts +0 -967
- package/server/routers/api/restful-apis/v2/bizplace.ts +0 -45
- package/server/routers/api/restful-apis/v2/cancel-marketplace-order.ts +0 -81
- package/server/routers/api/restful-apis/v2/cancel-release-order.ts +0 -91
- package/server/routers/api/restful-apis/v2/get-contact-point-list.ts +0 -110
- package/server/routers/api/restful-apis/v2/get-delivery-order-detail.ts +0 -46
- package/server/routers/api/restful-apis/v2/get-delivery-order-list.ts +0 -121
- package/server/routers/api/restful-apis/v2/get-delivery-orders.ts +0 -178
- package/server/routers/api/restful-apis/v2/get-goods-received-notes.ts +0 -134
- package/server/routers/api/restful-apis/v2/get-inbound-order-detail.ts +0 -128
- package/server/routers/api/restful-apis/v2/get-inbound-order-list.ts +0 -126
- package/server/routers/api/restful-apis/v2/get-inventory-overall-product-group.ts +0 -99
- package/server/routers/api/restful-apis/v2/get-inventory-product-group.ts +0 -112
- package/server/routers/api/restful-apis/v2/get-marketplace-order-shipping-list.ts +0 -156
- package/server/routers/api/restful-apis/v2/get-marketplace-store-list.ts +0 -81
- package/server/routers/api/restful-apis/v2/get-onhand-inventories.ts +0 -125
- package/server/routers/api/restful-apis/v2/get-partners.ts +0 -26
- package/server/routers/api/restful-apis/v2/get-products.ts +0 -216
- package/server/routers/api/restful-apis/v2/get-release-order-detail.ts +0 -134
- package/server/routers/api/restful-apis/v2/get-release-order-list.ts +0 -198
- package/server/routers/api/restful-apis/v2/get-warehouses.ts +0 -19
- package/server/routers/api/restful-apis/v2/index.ts +0 -31
- package/server/routers/api/restful-apis/v2/reject-inbound-order.ts +0 -46
- package/server/routers/api/restful-apis/v2/set-marketplace-order-delivered.ts +0 -60
- package/server/routers/api/restful-apis/v2/set-marketplace-order-failed-delivery.ts +0 -60
- package/server/routers/api/restful-apis/v2/update-marketplace-order.ts +0 -111
- package/server/routers/api/restful-apis/v2/update-marketplace-shipping-order.ts +0 -104
- package/server/routers/api/restful-apis/v2/update-release-order-details.ts +0 -94
- package/server/routers/auth-invitation-router.ts +0 -25
- package/server/routers/business/bizplace-register-router.ts +0 -31
- package/server/routers/business/business-register-router.ts +0 -32
- package/server/routers/business/index.ts +0 -3
- package/server/routers/business/path-base-business-router.ts +0 -15
- package/server/routes.ts +0 -28
- package/server/templates/account-unlock-email.ts +0 -64
- package/server/templates/invitation-email.ts +0 -65
- package/server/templates/reset-password-email.ts +0 -64
- package/server/templates/verification-email.ts +0 -65
- package/server/utils/build-map.ts +0 -18
- package/server/utils/get-warehouses.ts +0 -115
- package/server/utils/index.ts +0 -3
- package/server/utils/order-no-generator.ts +0 -8
|
@@ -1,967 +0,0 @@
|
|
|
1
|
-
import gql from 'graphql-tag'
|
|
2
|
-
import { EntityManager, getConnection, SelectQueryBuilder } from 'typeorm'
|
|
3
|
-
|
|
4
|
-
import { restfulApiRouter as router } from '@things-factory/api'
|
|
5
|
-
import { Bizplace, getCompanyBizplace } from '@things-factory/biz-base'
|
|
6
|
-
import { createPayloadLog, PayloadType } from '@things-factory/integration-base'
|
|
7
|
-
import { Product, ProductBundle, ProductDetail } from '@things-factory/product-base'
|
|
8
|
-
import { ORDER_TYPES, OrderInventory } from '@things-factory/sales-base'
|
|
9
|
-
import { Setting } from '@things-factory/setting-base'
|
|
10
|
-
import { Inventory, INVENTORY_STATUS, LOCATION_TYPE } from '@things-factory/warehouse-base'
|
|
11
|
-
import { WorksheetDetail } from '@things-factory/worksheet-base'
|
|
12
|
-
|
|
13
|
-
import { businessMiddleware } from '../../../../middlewares/business-middleware'
|
|
14
|
-
import { warehouseMiddleware } from '../../../../middlewares/warehouse-middleware'
|
|
15
|
-
|
|
16
|
-
const debug = require('debug')('things-factory:operato-hub:restful-api:unstable:add-release-order')
|
|
17
|
-
const apiVersion = 'v1'
|
|
18
|
-
|
|
19
|
-
router.post(
|
|
20
|
-
`/${apiVersion}/warehouse/:warehouseId/add-release-order`,
|
|
21
|
-
businessMiddleware,
|
|
22
|
-
warehouseMiddleware,
|
|
23
|
-
async (context, next) => {
|
|
24
|
-
return await getConnection().transaction(async (tx: EntityManager) => {
|
|
25
|
-
const { client, domain } = context.state
|
|
26
|
-
const { warehouseId: customerBizplaceId } = context.params
|
|
27
|
-
const { t } = context
|
|
28
|
-
const bodyReq = context.request.body
|
|
29
|
-
try {
|
|
30
|
-
if (!customerBizplaceId) context.throw(404, t('error.warehouse id not found'))
|
|
31
|
-
|
|
32
|
-
if (typeof bodyReq === undefined || !Object.keys(bodyReq)?.length) {
|
|
33
|
-
context.throw(400, t('error.invalid body request format'))
|
|
34
|
-
}
|
|
35
|
-
debug('post:/add-release-order request.body', bodyReq)
|
|
36
|
-
await checkMandatoryKey(context, bodyReq)
|
|
37
|
-
|
|
38
|
-
const isAutoAssign: Boolean = bodyReq.hasOwnProperty('isAutoAssign') ? bodyReq.isAutoAssign : true
|
|
39
|
-
const requiredDraft: Boolean = bodyReq.hasOwnProperty('requiredDraft') ? bodyReq.requiredDraft : true
|
|
40
|
-
|
|
41
|
-
// get customer company's bizplace
|
|
42
|
-
const custCompanyBizplace: Bizplace = await getCompanyBizplace(null, null, customerBizplaceId, tx)
|
|
43
|
-
const customerBizplace: Bizplace = await tx.getRepository(Bizplace).findOne({
|
|
44
|
-
where: { id: customerBizplaceId }
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
let locationSortingRules = []
|
|
48
|
-
const inventoryAssignmentSetting: Setting = await tx.getRepository(Setting).findOne({
|
|
49
|
-
where: { domain: { id: domain.id }, name: 'rule-for-inventory-assignment' }
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
if (inventoryAssignmentSetting) {
|
|
53
|
-
let locationSetting = JSON.parse(inventoryAssignmentSetting.value)
|
|
54
|
-
for (const key in locationSetting) {
|
|
55
|
-
locationSortingRules.push({ name: key, desc: locationSetting[key] == 'ASC' ? false : true })
|
|
56
|
-
}
|
|
57
|
-
} else {
|
|
58
|
-
const pickingProductSetting: Setting = await tx.getRepository(Setting).findOne({
|
|
59
|
-
where: { domain: { id: domain.id }, name: 'rule-for-picking-product' }
|
|
60
|
-
})
|
|
61
|
-
if (pickingProductSetting) {
|
|
62
|
-
let locationSetting = JSON.parse(pickingProductSetting.value)
|
|
63
|
-
for (const key in locationSetting) {
|
|
64
|
-
locationSortingRules.push({ name: key, desc: locationSetting[key] == 'ASC' ? false : true })
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const orderInventories: OrderInventory[] = bodyReq.orderInventories
|
|
70
|
-
let newOrderInventories: OrderInventory[] = []
|
|
71
|
-
let bundleInfo: any[] = []
|
|
72
|
-
|
|
73
|
-
await Promise.all(
|
|
74
|
-
orderInventories.map(async orderInventory => {
|
|
75
|
-
const sku: string = orderInventory.product?.sku
|
|
76
|
-
const refCode: string = orderInventory.product?.refCode
|
|
77
|
-
const packingType: string = orderInventory.packingType
|
|
78
|
-
|
|
79
|
-
const qb: SelectQueryBuilder<ProductDetail> = tx
|
|
80
|
-
.getRepository(ProductDetail)
|
|
81
|
-
.createQueryBuilder('PD')
|
|
82
|
-
.innerJoinAndSelect('PD.product', 'PROD')
|
|
83
|
-
.where('PROD.bizplace_id = :bizplaceId', { bizplaceId: custCompanyBizplace.id })
|
|
84
|
-
|
|
85
|
-
if (!sku && !refCode) {
|
|
86
|
-
context.throw(404, t('error.sku or refCode not found'))
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
if (refCode) {
|
|
90
|
-
qb.andWhere('PD.ref_code = :refCode', { refCode })
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
if (sku) {
|
|
94
|
-
qb.andWhere('PROD.sku = :sku', { sku })
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
if (packingType) {
|
|
98
|
-
qb.andWhere('PD.packing_type = :packingType', { packingType })
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
if (!packingType && !refCode) {
|
|
102
|
-
qb.andWhere('PD.is_default = :isDefault', { isDefault: true })
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
const productDetail: ProductDetail = await qb.getOne()
|
|
106
|
-
|
|
107
|
-
if (productDetail) {
|
|
108
|
-
let newOrderInventory: OrderInventory = Object.assign({}, orderInventory)
|
|
109
|
-
|
|
110
|
-
newOrderInventory.product.sku = productDetail.product.sku
|
|
111
|
-
newOrderInventory.product = productDetail.product
|
|
112
|
-
newOrderInventory.packingType = productDetail.packingType
|
|
113
|
-
newOrderInventory.uomValue = productDetail.uomValue
|
|
114
|
-
newOrderInventories.push(newOrderInventory)
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
if (!productDetail) {
|
|
118
|
-
const qb: SelectQueryBuilder<ProductDetail> = tx
|
|
119
|
-
.getRepository(ProductBundle)
|
|
120
|
-
.createQueryBuilder('PB')
|
|
121
|
-
.innerJoinAndSelect('PB.productBundleSettings', 'PBS')
|
|
122
|
-
.innerJoinAndSelect('PBS.productDetail', 'PBD')
|
|
123
|
-
.innerJoinAndSelect('PBD.product', 'PROD')
|
|
124
|
-
.where('PB.bizplace_id = :bizplaceId', { bizplaceId: custCompanyBizplace.id })
|
|
125
|
-
|
|
126
|
-
if (!sku && !refCode) {
|
|
127
|
-
context.throw(404, t('error.sku or refCode not found'))
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
if (refCode) {
|
|
131
|
-
qb.andWhere('PB.ref_code = :refCode', { refCode })
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
if (sku) {
|
|
135
|
-
qb.andWhere('PB.sku = :sku', { sku })
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
if (packingType) {
|
|
139
|
-
qb.andWhere('PB.packing_type = :packingType', { packingType })
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
const foundProductBundle: ProductBundle = await qb.getOne()
|
|
143
|
-
|
|
144
|
-
if (foundProductBundle) {
|
|
145
|
-
bundleInfo.push({
|
|
146
|
-
productBundleId: foundProductBundle.id,
|
|
147
|
-
sku: foundProductBundle.sku,
|
|
148
|
-
releaseQty: orderInventory.releaseQty
|
|
149
|
-
})
|
|
150
|
-
const bundleProductSettings: any[] = foundProductBundle.productBundleSettings
|
|
151
|
-
bundleProductSettings.map(bundleProductSetting => {
|
|
152
|
-
const productDetailBundle: ProductDetail = bundleProductSetting.productDetail
|
|
153
|
-
|
|
154
|
-
let newOrderInventory: OrderInventory = Object.assign({}, orderInventory)
|
|
155
|
-
newOrderInventory.product.sku = productDetailBundle.product.sku
|
|
156
|
-
newOrderInventory.packingType = productDetailBundle.packingType
|
|
157
|
-
newOrderInventory.uomValue = productDetailBundle.uomValue
|
|
158
|
-
newOrderInventory.releaseQty = orderInventory.releaseQty * bundleProductSetting.bundleQty
|
|
159
|
-
newOrderInventory.product = productDetailBundle.product
|
|
160
|
-
newOrderInventories.push(newOrderInventory)
|
|
161
|
-
})
|
|
162
|
-
} else {
|
|
163
|
-
if (sku && refCode) {
|
|
164
|
-
context.throw(404, t(`error.sku ${sku} and refCode ${refCode} not exist in product / bundle master`))
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
if (sku) {
|
|
168
|
-
context.throw(404, t(`error.sku ${sku} not exist in product / bundle master`))
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
if (refCode) {
|
|
172
|
-
context.throw(404, t(`error.refCode ${refCode} not exist in product / bundle master`))
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
})
|
|
177
|
-
)
|
|
178
|
-
|
|
179
|
-
let finalOrderInventories: OrderInventory[] = []
|
|
180
|
-
|
|
181
|
-
// Case 1. Every order inventories has specified batch id
|
|
182
|
-
if (newOrderInventories.every((orderInventory: OrderInventory) => orderInventory.batchId)) {
|
|
183
|
-
finalOrderInventories = await Promise.all(
|
|
184
|
-
newOrderInventories.map(async (orderInventory: OrderInventory) => {
|
|
185
|
-
let filters: any = [
|
|
186
|
-
{
|
|
187
|
-
name: 'batchId',
|
|
188
|
-
operator: 'eq',
|
|
189
|
-
value: orderInventory.batchId
|
|
190
|
-
},
|
|
191
|
-
{
|
|
192
|
-
name: 'productName',
|
|
193
|
-
operator: 'eq',
|
|
194
|
-
value: orderInventory.product.sku
|
|
195
|
-
},
|
|
196
|
-
{
|
|
197
|
-
name: 'bizplace',
|
|
198
|
-
operator: 'in',
|
|
199
|
-
value: [customerBizplaceId]
|
|
200
|
-
}
|
|
201
|
-
]
|
|
202
|
-
|
|
203
|
-
let sortings: any = []
|
|
204
|
-
|
|
205
|
-
switch (orderInventory.product.pickingStrategy) {
|
|
206
|
-
case 'FIFO':
|
|
207
|
-
sortings.push({ name: 'created_at', desc: false })
|
|
208
|
-
break
|
|
209
|
-
|
|
210
|
-
case 'LIFO':
|
|
211
|
-
sortings.push({ name: 'created_at', desc: true })
|
|
212
|
-
break
|
|
213
|
-
|
|
214
|
-
case 'FEFO':
|
|
215
|
-
sortings.push({ name: 'expiration_date', desc: false }, { name: 'created_at', desc: false })
|
|
216
|
-
break
|
|
217
|
-
|
|
218
|
-
case 'FMFO':
|
|
219
|
-
sortings.push({ name: 'manufacture_date', desc: false }, { name: 'created_at', desc: false })
|
|
220
|
-
break
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
// 2. get all inventory data according to SKU and batchId
|
|
224
|
-
const response = await client.query({
|
|
225
|
-
query: gql`
|
|
226
|
-
query inventoriesByPallet(
|
|
227
|
-
$filters: [Filter]
|
|
228
|
-
$sortings: [Sorting]
|
|
229
|
-
$locationSortingRules: [Sorting]
|
|
230
|
-
) {
|
|
231
|
-
inventoriesByPallet(
|
|
232
|
-
filters: $filters
|
|
233
|
-
sortings: $sortings
|
|
234
|
-
locationSortingRules: $locationSortingRules
|
|
235
|
-
) {
|
|
236
|
-
items {
|
|
237
|
-
product {
|
|
238
|
-
id
|
|
239
|
-
name
|
|
240
|
-
description
|
|
241
|
-
}
|
|
242
|
-
batchId
|
|
243
|
-
packingType
|
|
244
|
-
remainQty
|
|
245
|
-
remainUomValue
|
|
246
|
-
}
|
|
247
|
-
total
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
`,
|
|
251
|
-
variables: { filters, sortings, locationSortingRules },
|
|
252
|
-
context: {
|
|
253
|
-
...context,
|
|
254
|
-
state: {
|
|
255
|
-
...context.state,
|
|
256
|
-
bizplace: customerBizplace,
|
|
257
|
-
domain
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
} as any)
|
|
261
|
-
|
|
262
|
-
if (!response.errors) {
|
|
263
|
-
const items = response.data.inventoriesByPallet.items || []
|
|
264
|
-
if (requiredDraft) {
|
|
265
|
-
if (!items?.length) {
|
|
266
|
-
context.body = {
|
|
267
|
-
result: await createDraftOrder(
|
|
268
|
-
client,
|
|
269
|
-
customerBizplace,
|
|
270
|
-
bodyReq,
|
|
271
|
-
bundleInfo,
|
|
272
|
-
domain,
|
|
273
|
-
context,
|
|
274
|
-
orderInventories,
|
|
275
|
-
tx
|
|
276
|
-
)
|
|
277
|
-
}
|
|
278
|
-
return
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
items.forEach(async item => {
|
|
283
|
-
if (requiredDraft) {
|
|
284
|
-
if (orderInventory.releaseQty > item.remainQty || orderInventory.releaseQty <= 0) {
|
|
285
|
-
context.body = {
|
|
286
|
-
result: await createDraftOrder(
|
|
287
|
-
client,
|
|
288
|
-
customerBizplace,
|
|
289
|
-
bodyReq,
|
|
290
|
-
bundleInfo,
|
|
291
|
-
domain,
|
|
292
|
-
context,
|
|
293
|
-
orderInventories,
|
|
294
|
-
tx
|
|
295
|
-
)
|
|
296
|
-
}
|
|
297
|
-
return
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
// 3. add more information to orderInventory
|
|
302
|
-
orderInventory.product.id = item.product.id
|
|
303
|
-
orderInventory.packingType = item.packingType
|
|
304
|
-
orderInventory.batchId = item.batchId
|
|
305
|
-
orderInventory.type = ORDER_TYPES.RELEASE_OF_GOODS
|
|
306
|
-
orderInventory.releaseUomValue = orderInventory.releaseQty * orderInventory.uomValue
|
|
307
|
-
orderInventory.uom = item.uom
|
|
308
|
-
})
|
|
309
|
-
|
|
310
|
-
return orderInventory
|
|
311
|
-
} else {
|
|
312
|
-
if (requiredDraft) {
|
|
313
|
-
context.body = {
|
|
314
|
-
result: await createDraftOrder(
|
|
315
|
-
client,
|
|
316
|
-
customerBizplace,
|
|
317
|
-
bodyReq,
|
|
318
|
-
bundleInfo,
|
|
319
|
-
domain,
|
|
320
|
-
context,
|
|
321
|
-
orderInventories,
|
|
322
|
-
tx
|
|
323
|
-
)
|
|
324
|
-
}
|
|
325
|
-
return
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
})
|
|
329
|
-
)
|
|
330
|
-
} else {
|
|
331
|
-
// Case 2. Some of order inventories doesn't have specified batch id
|
|
332
|
-
// MMS order doesn't have batch ID field.
|
|
333
|
-
// To cover this case first result of found inventory will be a target of RO
|
|
334
|
-
|
|
335
|
-
// To combine items from different bundles
|
|
336
|
-
newOrderInventories = combineItems(newOrderInventories)
|
|
337
|
-
|
|
338
|
-
for (let i: number = 0; i < newOrderInventories.length; i++) {
|
|
339
|
-
const orderInventory: OrderInventory = newOrderInventories[i]
|
|
340
|
-
const { product, packingType }: { product: Product; packingType: string } = orderInventory
|
|
341
|
-
const pickingStrategy: string = product.pickingStrategy
|
|
342
|
-
|
|
343
|
-
if (isAutoAssign) {
|
|
344
|
-
let qb: SelectQueryBuilder<Inventory> = tx.getRepository(Inventory).createQueryBuilder('iv')
|
|
345
|
-
qb.leftJoinAndSelect('iv.location', 'loc')
|
|
346
|
-
.andWhere('"iv"."domain_id" = :domainId')
|
|
347
|
-
.andWhere('"iv"."bizplace_id" = :bizplaceId')
|
|
348
|
-
.andWhere('"iv"."packing_type" = :packingType')
|
|
349
|
-
.andWhere('"iv"."product_id" = :productId')
|
|
350
|
-
.andWhere('"iv"."status" = :status')
|
|
351
|
-
.andWhere('"loc"."type" NOT IN (:...locationTypes)')
|
|
352
|
-
.setParameters({
|
|
353
|
-
domainId: domain.id,
|
|
354
|
-
bizplaceId: customerBizplace.id,
|
|
355
|
-
packingType: packingType,
|
|
356
|
-
productId: product.id,
|
|
357
|
-
status: INVENTORY_STATUS.STORED,
|
|
358
|
-
locationTypes: [LOCATION_TYPE.QUARANTINE, LOCATION_TYPE.RESERVE]
|
|
359
|
-
})
|
|
360
|
-
|
|
361
|
-
switch (pickingStrategy) {
|
|
362
|
-
case 'FIFO':
|
|
363
|
-
qb.orderBy('"iv"."created_at"', 'ASC')
|
|
364
|
-
if (locationSortingRules?.length > 0) {
|
|
365
|
-
locationSortingRules.forEach((rule: { name: string; desc: boolean }, idx: number) => {
|
|
366
|
-
qb.addOrderBy(`loc.${rule.name}`, rule.desc ? 'DESC' : 'ASC')
|
|
367
|
-
})
|
|
368
|
-
}
|
|
369
|
-
break
|
|
370
|
-
|
|
371
|
-
case 'LIFO':
|
|
372
|
-
qb.orderBy('"iv"."created_at"', 'DESC')
|
|
373
|
-
if (locationSortingRules?.length > 0) {
|
|
374
|
-
locationSortingRules.forEach((rule: { name: string; desc: boolean }, idx: number) => {
|
|
375
|
-
qb.addOrderBy(`loc.${rule.name}`, rule.desc ? 'DESC' : 'ASC')
|
|
376
|
-
})
|
|
377
|
-
}
|
|
378
|
-
break
|
|
379
|
-
|
|
380
|
-
case 'FEFO':
|
|
381
|
-
qb.orderBy('"iv"."expiration_date"', 'ASC')
|
|
382
|
-
qb.orderBy('"iv"."created_at"', 'ASC')
|
|
383
|
-
if (locationSortingRules?.length > 0) {
|
|
384
|
-
locationSortingRules.forEach((rule: { name: string; desc: boolean }, idx: number) => {
|
|
385
|
-
qb.addOrderBy(`loc.${rule.name}`, rule.desc ? 'DESC' : 'ASC')
|
|
386
|
-
})
|
|
387
|
-
}
|
|
388
|
-
break
|
|
389
|
-
|
|
390
|
-
case 'FMFO':
|
|
391
|
-
qb.orderBy('"iv"."manufacture_date"', 'ASC')
|
|
392
|
-
qb.orderBy('"iv"."created_at"', 'ASC')
|
|
393
|
-
if (locationSortingRules?.length > 0) {
|
|
394
|
-
locationSortingRules.forEach((rule: { name: string; desc: boolean }, idx: number) => {
|
|
395
|
-
qb.addOrderBy(`loc.${rule.name}`, rule.desc ? 'DESC' : 'ASC')
|
|
396
|
-
})
|
|
397
|
-
}
|
|
398
|
-
break
|
|
399
|
-
|
|
400
|
-
case 'LOCATION':
|
|
401
|
-
if (locationSortingRules?.length > 0) {
|
|
402
|
-
locationSortingRules.forEach((rule: { name: string; desc: boolean }, idx: number) => {
|
|
403
|
-
idx === 0
|
|
404
|
-
? qb.orderBy(`loc.${rule.name}`, rule.desc ? 'DESC' : 'ASC')
|
|
405
|
-
: qb.addOrderBy(`loc.${rule.name}`, rule.desc ? 'DESC' : 'ASC')
|
|
406
|
-
})
|
|
407
|
-
} else {
|
|
408
|
-
qb.orderBy('"loc"."name"', 'DESC')
|
|
409
|
-
}
|
|
410
|
-
break
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
let inventories: Inventory[] = await qb.getMany()
|
|
414
|
-
if (requiredDraft) {
|
|
415
|
-
if (!inventories?.length) {
|
|
416
|
-
context.body = {
|
|
417
|
-
result: await createDraftOrder(
|
|
418
|
-
client,
|
|
419
|
-
customerBizplace,
|
|
420
|
-
bodyReq,
|
|
421
|
-
bundleInfo,
|
|
422
|
-
domain,
|
|
423
|
-
context,
|
|
424
|
-
orderInventories,
|
|
425
|
-
tx
|
|
426
|
-
)
|
|
427
|
-
}
|
|
428
|
-
return
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
inventories = inventories
|
|
432
|
-
.map(inventory => {
|
|
433
|
-
return {
|
|
434
|
-
...inventory,
|
|
435
|
-
remainQty: inventory.qty - inventory.lockedQty,
|
|
436
|
-
remainUomValue: inventory.uomValue - inventory.lockedUomValue
|
|
437
|
-
}
|
|
438
|
-
})
|
|
439
|
-
.filter(inventory => inventory.remainQty > 0)
|
|
440
|
-
|
|
441
|
-
let targetInventories: WorksheetDetail[]
|
|
442
|
-
try {
|
|
443
|
-
targetInventories = _composeTargetInventories(context, product, orderInventory, inventories)
|
|
444
|
-
} catch (e) {
|
|
445
|
-
if (requiredDraft) {
|
|
446
|
-
context.body = {
|
|
447
|
-
result: await createDraftOrder(
|
|
448
|
-
client,
|
|
449
|
-
customerBizplace,
|
|
450
|
-
bodyReq,
|
|
451
|
-
bundleInfo,
|
|
452
|
-
domain,
|
|
453
|
-
context,
|
|
454
|
-
orderInventories,
|
|
455
|
-
tx
|
|
456
|
-
)
|
|
457
|
-
}
|
|
458
|
-
return
|
|
459
|
-
} else {
|
|
460
|
-
targetInventories = _composeTargetInventories(context, product, orderInventory, inventories)
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
if (!targetInventories?.length) {
|
|
464
|
-
context.throw(404, t(`error.no inventories found`))
|
|
465
|
-
}
|
|
466
|
-
targetInventories.map(item => {
|
|
467
|
-
finalOrderInventories.push(item.targetInventory)
|
|
468
|
-
})
|
|
469
|
-
} else {
|
|
470
|
-
let filters: any = [
|
|
471
|
-
{
|
|
472
|
-
name: 'productName',
|
|
473
|
-
operator: 'eq',
|
|
474
|
-
value: orderInventory.product.sku
|
|
475
|
-
},
|
|
476
|
-
{
|
|
477
|
-
name: 'bizplace_id',
|
|
478
|
-
operator: 'eq',
|
|
479
|
-
value: customerBizplaceId
|
|
480
|
-
}
|
|
481
|
-
]
|
|
482
|
-
|
|
483
|
-
// 2. get all inventory data according to SKU and batchId
|
|
484
|
-
const response = await client.query({
|
|
485
|
-
query: gql`
|
|
486
|
-
query inventoryProductGroup($filters: [Filter]) {
|
|
487
|
-
inventoryProductGroup(filters: $filters) {
|
|
488
|
-
items {
|
|
489
|
-
productId
|
|
490
|
-
productSKU
|
|
491
|
-
productName
|
|
492
|
-
batchId
|
|
493
|
-
packingType
|
|
494
|
-
remainQty
|
|
495
|
-
remainUomValue
|
|
496
|
-
}
|
|
497
|
-
total
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
`,
|
|
501
|
-
variables: { filters },
|
|
502
|
-
context: {
|
|
503
|
-
...context,
|
|
504
|
-
state: {
|
|
505
|
-
...context.state,
|
|
506
|
-
bizplace: customerBizplace,
|
|
507
|
-
domain
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
} as any)
|
|
511
|
-
|
|
512
|
-
if (!response.errors) {
|
|
513
|
-
const items = response.data.inventoryProductGroup.items || []
|
|
514
|
-
if (requiredDraft) {
|
|
515
|
-
if (!items?.length) {
|
|
516
|
-
context.body = {
|
|
517
|
-
result: await createDraftOrder(
|
|
518
|
-
client,
|
|
519
|
-
customerBizplace,
|
|
520
|
-
bodyReq,
|
|
521
|
-
bundleInfo,
|
|
522
|
-
domain,
|
|
523
|
-
context,
|
|
524
|
-
orderInventories,
|
|
525
|
-
tx
|
|
526
|
-
)
|
|
527
|
-
}
|
|
528
|
-
return
|
|
529
|
-
}
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
items.forEach(async item => {
|
|
533
|
-
if (requiredDraft) {
|
|
534
|
-
if (orderInventory.releaseQty > item.remainQty || orderInventory.releaseQty <= 0) {
|
|
535
|
-
context.body = {
|
|
536
|
-
result: await createDraftOrder(
|
|
537
|
-
client,
|
|
538
|
-
customerBizplace,
|
|
539
|
-
bodyReq,
|
|
540
|
-
bundleInfo,
|
|
541
|
-
domain,
|
|
542
|
-
context,
|
|
543
|
-
orderInventories,
|
|
544
|
-
tx
|
|
545
|
-
)
|
|
546
|
-
}
|
|
547
|
-
return
|
|
548
|
-
}
|
|
549
|
-
}
|
|
550
|
-
|
|
551
|
-
// 3. add more information to orderInventory
|
|
552
|
-
orderInventory.product = { id: item.productId }
|
|
553
|
-
orderInventory.packingType = item.packingType
|
|
554
|
-
orderInventory.batchId = item.batchId
|
|
555
|
-
orderInventory.type = ORDER_TYPES.RELEASE_OF_GOODS
|
|
556
|
-
orderInventory.releaseUomValue = orderInventory.releaseQty * orderInventory.uomValue
|
|
557
|
-
orderInventory.uom = item.uom
|
|
558
|
-
})
|
|
559
|
-
|
|
560
|
-
delete orderInventory.uomValue
|
|
561
|
-
finalOrderInventories.push(orderInventory)
|
|
562
|
-
} else {
|
|
563
|
-
if (requiredDraft) {
|
|
564
|
-
context.body = {
|
|
565
|
-
result: await createDraftOrder(
|
|
566
|
-
client,
|
|
567
|
-
customerBizplace,
|
|
568
|
-
bodyReq,
|
|
569
|
-
bundleInfo,
|
|
570
|
-
domain,
|
|
571
|
-
context,
|
|
572
|
-
orderInventories,
|
|
573
|
-
tx
|
|
574
|
-
)
|
|
575
|
-
}
|
|
576
|
-
return
|
|
577
|
-
}
|
|
578
|
-
}
|
|
579
|
-
}
|
|
580
|
-
}
|
|
581
|
-
}
|
|
582
|
-
|
|
583
|
-
context.body = {
|
|
584
|
-
result: (
|
|
585
|
-
await client.mutate({
|
|
586
|
-
mutation: gql`
|
|
587
|
-
mutation addReleaseGood(
|
|
588
|
-
$releaseGood: NewReleaseGood
|
|
589
|
-
$shippingOrder: ShippingOrderPatch
|
|
590
|
-
$file: Upload
|
|
591
|
-
) {
|
|
592
|
-
addReleaseGood(releaseGood: $releaseGood, shippingOrder: $shippingOrder, file: $file) {
|
|
593
|
-
id
|
|
594
|
-
name
|
|
595
|
-
refNo
|
|
596
|
-
status
|
|
597
|
-
truckNo
|
|
598
|
-
ownTransport
|
|
599
|
-
crossDocking
|
|
600
|
-
marketplaceOrderStatus
|
|
601
|
-
billingAddress
|
|
602
|
-
deliveryAddress1
|
|
603
|
-
deliveryAddress2
|
|
604
|
-
deliveryAddress3
|
|
605
|
-
deliveryAddress4
|
|
606
|
-
deliveryAddress5
|
|
607
|
-
attentionTo
|
|
608
|
-
attentionCompany
|
|
609
|
-
city
|
|
610
|
-
state
|
|
611
|
-
postalCode
|
|
612
|
-
country
|
|
613
|
-
phone1
|
|
614
|
-
phone2
|
|
615
|
-
email
|
|
616
|
-
transporter
|
|
617
|
-
trackingNo
|
|
618
|
-
airwayBill
|
|
619
|
-
invoice
|
|
620
|
-
type
|
|
621
|
-
storeName
|
|
622
|
-
storeId
|
|
623
|
-
routeId
|
|
624
|
-
stopId
|
|
625
|
-
arrivalNotice {
|
|
626
|
-
name
|
|
627
|
-
}
|
|
628
|
-
exportOption
|
|
629
|
-
releaseDate
|
|
630
|
-
collectionOrderNo
|
|
631
|
-
bizplace {
|
|
632
|
-
name
|
|
633
|
-
}
|
|
634
|
-
orderInventories {
|
|
635
|
-
product {
|
|
636
|
-
sku
|
|
637
|
-
name
|
|
638
|
-
description
|
|
639
|
-
}
|
|
640
|
-
batchId
|
|
641
|
-
packingType
|
|
642
|
-
packingSize
|
|
643
|
-
releaseQty
|
|
644
|
-
releaseUomValue
|
|
645
|
-
}
|
|
646
|
-
orderVass {
|
|
647
|
-
vas {
|
|
648
|
-
name
|
|
649
|
-
operationGuide
|
|
650
|
-
operationGuideType
|
|
651
|
-
}
|
|
652
|
-
set
|
|
653
|
-
targetType
|
|
654
|
-
targetBatchId
|
|
655
|
-
targetProduct {
|
|
656
|
-
name
|
|
657
|
-
description
|
|
658
|
-
}
|
|
659
|
-
packingType
|
|
660
|
-
qty
|
|
661
|
-
uomValue
|
|
662
|
-
otherTarget
|
|
663
|
-
description
|
|
664
|
-
remark
|
|
665
|
-
status
|
|
666
|
-
operationGuide
|
|
667
|
-
}
|
|
668
|
-
}
|
|
669
|
-
}
|
|
670
|
-
`,
|
|
671
|
-
variables: {
|
|
672
|
-
releaseGood: {
|
|
673
|
-
customerBizplaceId: customerBizplace.id,
|
|
674
|
-
courierOption: bodyReq.courierOption,
|
|
675
|
-
collectionOrderNo: bodyReq.collectionOrderNo,
|
|
676
|
-
exportOption: bodyReq.exportOption,
|
|
677
|
-
orderInventories: finalOrderInventories,
|
|
678
|
-
ownTransport: bodyReq.ownTransport,
|
|
679
|
-
packingOption: bodyReq.packingOption,
|
|
680
|
-
refNo: bodyReq.refNo,
|
|
681
|
-
refNo2: bodyReq?.refNo2,
|
|
682
|
-
releaseDate: bodyReq.releaseDate,
|
|
683
|
-
type: bodyReq.type,
|
|
684
|
-
marketplaceOrderStatus: bodyReq?.marketplaceOrderStatus,
|
|
685
|
-
remark: bodyReq?.remark || null,
|
|
686
|
-
billingAddress: bodyReq?.billTo?.billingAddress || null,
|
|
687
|
-
deliveryAddress1: bodyReq?.deliverTo?.deliveryAddress1 || null,
|
|
688
|
-
deliveryAddress2: bodyReq?.deliverTo?.deliveryAddress2 || null,
|
|
689
|
-
deliveryAddress3: bodyReq?.deliverTo?.deliveryAddress3 || null,
|
|
690
|
-
deliveryAddress4: bodyReq?.deliverTo?.deliveryAddress4 || null,
|
|
691
|
-
deliveryAddress5: bodyReq?.deliverTo?.deliveryAddress5 || null,
|
|
692
|
-
attentionTo: bodyReq?.deliverTo?.attentionTo || null,
|
|
693
|
-
attentionCompany: bodyReq?.deliverTo?.attentionCompany || null,
|
|
694
|
-
city: bodyReq?.deliverTo?.city || null,
|
|
695
|
-
state: bodyReq?.deliverTo?.state || null,
|
|
696
|
-
postalCode: bodyReq?.deliverTo?.postalCode || null,
|
|
697
|
-
country: bodyReq?.deliverTo?.country || null,
|
|
698
|
-
phone1: bodyReq?.deliverTo?.phone1 || null,
|
|
699
|
-
phone2: bodyReq?.deliverTo?.phone2 || null,
|
|
700
|
-
email: bodyReq?.deliverTo?.email || null,
|
|
701
|
-
transporter: bodyReq?.transporter,
|
|
702
|
-
trackingNo: bodyReq?.trackingNo,
|
|
703
|
-
airwayBill: bodyReq?.airwayBill,
|
|
704
|
-
invoice: bodyReq?.invoice,
|
|
705
|
-
bundleInfo: JSON.stringify(bundleInfo),
|
|
706
|
-
storeName: bodyReq?.storeName,
|
|
707
|
-
storeId: bodyReq?.storeId,
|
|
708
|
-
routeId: bodyReq?.routeId,
|
|
709
|
-
stopId: bodyReq?.stopId
|
|
710
|
-
}
|
|
711
|
-
},
|
|
712
|
-
context: {
|
|
713
|
-
...context,
|
|
714
|
-
hasUpload: true,
|
|
715
|
-
state: {
|
|
716
|
-
...context.state,
|
|
717
|
-
customerBizplace,
|
|
718
|
-
domain,
|
|
719
|
-
type: 'api'
|
|
720
|
-
}
|
|
721
|
-
}
|
|
722
|
-
} as any)
|
|
723
|
-
).data
|
|
724
|
-
}
|
|
725
|
-
|
|
726
|
-
createPayloadLog(
|
|
727
|
-
customerBizplaceId,
|
|
728
|
-
`/${apiVersion}/warehouse/:warehouseId/add-release-order`,
|
|
729
|
-
bodyReq,
|
|
730
|
-
context.body,
|
|
731
|
-
context,
|
|
732
|
-
PayloadType.INGESTION,
|
|
733
|
-
'hub-api'
|
|
734
|
-
)
|
|
735
|
-
} catch (error) {
|
|
736
|
-
createPayloadLog(
|
|
737
|
-
customerBizplaceId,
|
|
738
|
-
`/${apiVersion}/warehouse/:warehouseId/add-release-order`,
|
|
739
|
-
bodyReq,
|
|
740
|
-
error,
|
|
741
|
-
context,
|
|
742
|
-
PayloadType.INGESTION,
|
|
743
|
-
'hub-api'
|
|
744
|
-
)
|
|
745
|
-
throw error
|
|
746
|
-
}
|
|
747
|
-
})
|
|
748
|
-
}
|
|
749
|
-
)
|
|
750
|
-
|
|
751
|
-
export async function checkMandatoryKey(context, params) {
|
|
752
|
-
let noparams = ['releaseDate', 'exportOption'].filter(param => !(param in params))
|
|
753
|
-
|
|
754
|
-
if ('ownTransport' in params) {
|
|
755
|
-
if (params.ownTransport == true) {
|
|
756
|
-
if (!params.hasOwnProperty('collectionOrderNo')) {
|
|
757
|
-
noparams.push('collectionOrderNo')
|
|
758
|
-
}
|
|
759
|
-
}
|
|
760
|
-
} else {
|
|
761
|
-
noparams.push('ownTransport')
|
|
762
|
-
}
|
|
763
|
-
|
|
764
|
-
if ('exportOption' in params) {
|
|
765
|
-
if (params.exportOption === true) {
|
|
766
|
-
if (
|
|
767
|
-
params.exportOption.filter(
|
|
768
|
-
record =>
|
|
769
|
-
!record.containerNo || !record.containerArrivalDate || !record.containerLeavingDate || !record.shipName
|
|
770
|
-
).length
|
|
771
|
-
) {
|
|
772
|
-
noparams.push('exportOption')
|
|
773
|
-
}
|
|
774
|
-
}
|
|
775
|
-
}
|
|
776
|
-
|
|
777
|
-
if ('orderInventories' in params) {
|
|
778
|
-
params.orderInventories.forEach((param, key) => {
|
|
779
|
-
let noSubParams = []
|
|
780
|
-
|
|
781
|
-
if (!param?.releaseQty) noSubParams.push('releaseQty')
|
|
782
|
-
|
|
783
|
-
if (!param?.product) noSubParams.push('product')
|
|
784
|
-
|
|
785
|
-
if (noSubParams?.length)
|
|
786
|
-
context.throw(400, context.t('error.required param x not found', { x: `${noSubParams.join(', ')}` }))
|
|
787
|
-
})
|
|
788
|
-
} else {
|
|
789
|
-
noparams.push('orderInventories')
|
|
790
|
-
}
|
|
791
|
-
|
|
792
|
-
if (noparams?.length) {
|
|
793
|
-
context.throw(400, context.t('error.required param x not found', { x: `${noparams.join(', ')}` }))
|
|
794
|
-
}
|
|
795
|
-
|
|
796
|
-
return params
|
|
797
|
-
}
|
|
798
|
-
|
|
799
|
-
export function _composeTargetInventories(context, product, record, inventories) {
|
|
800
|
-
const { t } = context
|
|
801
|
-
let leftReleaseQty = record.releaseQty
|
|
802
|
-
let leftReleaseUomValue = record.releaseUomValue
|
|
803
|
-
let compReleaseQty = 0
|
|
804
|
-
let compReleaseUomValue = 0
|
|
805
|
-
let totalInventoryQty: number = 0
|
|
806
|
-
|
|
807
|
-
inventories.map(inventory => {
|
|
808
|
-
totalInventoryQty += inventory.remainQty
|
|
809
|
-
})
|
|
810
|
-
|
|
811
|
-
if (totalInventoryQty < record.releaseQty) {
|
|
812
|
-
context.throw(404, t(`error.invalid release qty for ${product?.sku}`)) //
|
|
813
|
-
}
|
|
814
|
-
|
|
815
|
-
let targetInventories = []
|
|
816
|
-
let idx = 0
|
|
817
|
-
while (compReleaseQty < record.releaseQty) {
|
|
818
|
-
const inv = inventories[idx]
|
|
819
|
-
|
|
820
|
-
if (inv.remainQty > leftReleaseQty) {
|
|
821
|
-
compReleaseQty += leftReleaseQty
|
|
822
|
-
compReleaseUomValue += leftReleaseUomValue
|
|
823
|
-
|
|
824
|
-
targetInventories.push({
|
|
825
|
-
targetInventory: {
|
|
826
|
-
inventory: { id: inv.id },
|
|
827
|
-
packingType: inv.packingType,
|
|
828
|
-
batchId: inv.batchId,
|
|
829
|
-
releaseQty: leftReleaseQty,
|
|
830
|
-
releaseUomValue: leftReleaseQty * record.uomValue,
|
|
831
|
-
uom: inv.uom,
|
|
832
|
-
product: { id: product.id },
|
|
833
|
-
type: ORDER_TYPES.RELEASE_OF_GOODS
|
|
834
|
-
}
|
|
835
|
-
})
|
|
836
|
-
} else {
|
|
837
|
-
compReleaseQty += inv.remainQty
|
|
838
|
-
compReleaseUomValue += inv.remainUomValue
|
|
839
|
-
leftReleaseQty -= inv.remainQty
|
|
840
|
-
leftReleaseUomValue -= inv.remainUomValue
|
|
841
|
-
|
|
842
|
-
targetInventories.push({
|
|
843
|
-
targetInventory: {
|
|
844
|
-
inventory: { id: inv.id },
|
|
845
|
-
packingType: inv.packingType,
|
|
846
|
-
batchId: inv.batchId,
|
|
847
|
-
releaseQty: inv.remainQty,
|
|
848
|
-
releaseUomValue: inv.remainUomValue,
|
|
849
|
-
uom: inv.uom,
|
|
850
|
-
product: { id: product.id },
|
|
851
|
-
type: ORDER_TYPES.RELEASE_OF_GOODS
|
|
852
|
-
}
|
|
853
|
-
})
|
|
854
|
-
}
|
|
855
|
-
|
|
856
|
-
idx++
|
|
857
|
-
}
|
|
858
|
-
|
|
859
|
-
return targetInventories
|
|
860
|
-
}
|
|
861
|
-
|
|
862
|
-
function combineItems(inventoryList) {
|
|
863
|
-
let mappedList = []
|
|
864
|
-
|
|
865
|
-
inventoryList.map(e => {
|
|
866
|
-
let item = mappedList.find(i => i.product.id === e.product.id)
|
|
867
|
-
if (item) {
|
|
868
|
-
mappedList = mappedList.filter(m => m != item)
|
|
869
|
-
item.releaseQty += e.releaseQty
|
|
870
|
-
mappedList.push(item)
|
|
871
|
-
} else {
|
|
872
|
-
mappedList.push(e)
|
|
873
|
-
}
|
|
874
|
-
})
|
|
875
|
-
|
|
876
|
-
return mappedList
|
|
877
|
-
}
|
|
878
|
-
|
|
879
|
-
async function createDraftOrder(client, customerBizplace, bodyReq, bundleInfo, domain, context, orderInventories, tx) {
|
|
880
|
-
return (
|
|
881
|
-
await client.mutate({
|
|
882
|
-
mutation: gql`
|
|
883
|
-
mutation upsertDraftReleaseGood(
|
|
884
|
-
$draftReleaseGood: DraftReleaseGoodPatch!
|
|
885
|
-
$orderProducts: [OrderProductPatch!]!
|
|
886
|
-
) {
|
|
887
|
-
upsertDraftReleaseGood(draftReleaseGood: $draftReleaseGood, orderProducts: $orderProducts) {
|
|
888
|
-
id
|
|
889
|
-
name
|
|
890
|
-
refNo
|
|
891
|
-
refNo2
|
|
892
|
-
status
|
|
893
|
-
truckNo
|
|
894
|
-
ownTransport
|
|
895
|
-
marketplaceOrderStatus
|
|
896
|
-
billingAddress
|
|
897
|
-
deliveryAddress1
|
|
898
|
-
deliveryAddress2
|
|
899
|
-
deliveryAddress3
|
|
900
|
-
deliveryAddress4
|
|
901
|
-
deliveryAddress5
|
|
902
|
-
attentionTo
|
|
903
|
-
attentionCompany
|
|
904
|
-
city
|
|
905
|
-
state
|
|
906
|
-
postalCode
|
|
907
|
-
country
|
|
908
|
-
phone1
|
|
909
|
-
phone2
|
|
910
|
-
email
|
|
911
|
-
type
|
|
912
|
-
exportOption
|
|
913
|
-
releaseDate
|
|
914
|
-
collectionOrderNo
|
|
915
|
-
bizplace {
|
|
916
|
-
name
|
|
917
|
-
}
|
|
918
|
-
}
|
|
919
|
-
}
|
|
920
|
-
`,
|
|
921
|
-
variables: {
|
|
922
|
-
draftReleaseGood: {
|
|
923
|
-
bizplace: {
|
|
924
|
-
id: customerBizplace.id
|
|
925
|
-
},
|
|
926
|
-
courierOption: bodyReq.courierOption,
|
|
927
|
-
collectionOrderNo: bodyReq.collectionOrderNo,
|
|
928
|
-
exportOption: bodyReq.exportOption,
|
|
929
|
-
ownTransport: bodyReq.ownTransport,
|
|
930
|
-
packingOption: bodyReq.packingOption,
|
|
931
|
-
refNo: bodyReq.refNo,
|
|
932
|
-
refNo2: bodyReq?.refNo2,
|
|
933
|
-
releaseDate: bodyReq.releaseDate,
|
|
934
|
-
type: bodyReq.type,
|
|
935
|
-
marketplaceOrderStatus: bodyReq?.marketplaceOrderStatus,
|
|
936
|
-
remark: bodyReq?.remark || null,
|
|
937
|
-
billingAddress: bodyReq?.billTo?.billingAddress || null,
|
|
938
|
-
deliveryAddress1: bodyReq?.deliverTo?.deliveryAddress1 || null,
|
|
939
|
-
deliveryAddress2: bodyReq?.deliverTo?.deliveryAddress2 || null,
|
|
940
|
-
deliveryAddress3: bodyReq?.deliverTo?.deliveryAddress3 || null,
|
|
941
|
-
deliveryAddress4: bodyReq?.deliverTo?.deliveryAddress4 || null,
|
|
942
|
-
deliveryAddress5: bodyReq?.deliverTo?.deliveryAddress5 || null,
|
|
943
|
-
attentionTo: bodyReq?.deliverTo?.attentionTo || null,
|
|
944
|
-
attentionCompany: bodyReq?.deliverTo?.attentionCompany || null,
|
|
945
|
-
city: bodyReq?.deliverTo?.city || null,
|
|
946
|
-
state: bodyReq?.deliverTo?.state || null,
|
|
947
|
-
postalCode: bodyReq?.deliverTo?.postalCode || null,
|
|
948
|
-
country: bodyReq?.deliverTo?.country || null,
|
|
949
|
-
phone1: bodyReq?.deliverTo?.phone1 || null,
|
|
950
|
-
phone2: bodyReq?.deliverTo?.phone2 || null,
|
|
951
|
-
email: bodyReq?.deliverTo?.email || null
|
|
952
|
-
},
|
|
953
|
-
orderProducts: orderInventories
|
|
954
|
-
},
|
|
955
|
-
context: {
|
|
956
|
-
...context,
|
|
957
|
-
hasUpload: true,
|
|
958
|
-
state: {
|
|
959
|
-
...context.state,
|
|
960
|
-
customerBizplace,
|
|
961
|
-
domain,
|
|
962
|
-
type: 'api'
|
|
963
|
-
}
|
|
964
|
-
}
|
|
965
|
-
} as any)
|
|
966
|
-
).data
|
|
967
|
-
}
|