@things-factory/operato-mms 6.1.82 → 6.1.84
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 +36 -36
- package/server/controllers/index.ts +0 -0
- package/server/entities/index.ts +0 -3
- package/server/graphql/index.ts +0 -7
- package/server/graphql/resolvers/index.ts +0 -7
- package/server/graphql/resolvers/interface-with-hub/add-release-order.ts +0 -206
- package/server/graphql/resolvers/interface-with-hub/auto-add-release-order.ts +0 -209
- package/server/graphql/resolvers/interface-with-hub/auto-update-all-marketplace-product-variation-quantity.ts +0 -184
- package/server/graphql/resolvers/interface-with-hub/generate-replenishment-order.ts +0 -32
- package/server/graphql/resolvers/interface-with-hub/index.ts +0 -18
- package/server/graphql/resolvers/interface-with-hub/warehouse-marketplace-products.ts +0 -247
- package/server/graphql/resolvers/shipping-provider/index.ts +0 -5
- package/server/graphql/resolvers/shipping-provider/shipping-providers.ts +0 -39
- package/server/graphql/resolvers/warehouse-product/auto-link-warehouse-marketplace-product-variations.ts +0 -87
- package/server/graphql/resolvers/warehouse-product/index.ts +0 -5
- package/server/graphql/types/index.ts +0 -9
- package/server/graphql/types/interface-with-hub/index.ts +0 -28
- package/server/graphql/types/interface-with-hub/new-stock-replenishment.ts +0 -28
- package/server/graphql/types/interface-with-hub/replenishment-order-product.ts +0 -44
- package/server/graphql/types/interface-with-hub/stock-replenishment-list.ts +0 -10
- package/server/graphql/types/interface-with-hub/stock-replenishment.ts +0 -41
- package/server/graphql/types/interface-with-hub/warehouse-inventory.ts +0 -11
- package/server/graphql/types/interface-with-hub/warehouse-marketplace-product-list.ts +0 -8
- package/server/graphql/types/interface-with-hub/warehouse-marketplace-product.ts +0 -14
- package/server/graphql/types/shipping-provider/index.ts +0 -8
- package/server/graphql/types/shipping-provider/shipping-provider-list.ts +0 -7
- package/server/graphql/types/shipping-provider/shipping-provider.ts +0 -7
- package/server/graphql/types/warehouse-product/index.ts +0 -9
- package/server/graphql/types/warehouse-product/warehouse-product.ts +0 -9
- package/server/index.ts +0 -20
- package/server/middlewares/index.ts +0 -3
- package/server/migrations/1599732967233-SeedCommonCode.ts +0 -64
- package/server/migrations/1608009991075-SeedUser.ts +0 -60
- package/server/migrations/index.ts +0 -9
- package/server/routers/etrax-router.ts +0 -190
- package/server/routers/shopify-pos-public-router.ts +0 -151
- package/server/routes.ts +0 -9
- package/server/util/interface-helper.ts +0 -58
- package/server/util/no-generator.ts +0 -11
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
import { getConnection } from 'typeorm'
|
|
2
|
-
|
|
3
|
-
import { logger } from '@things-factory/env'
|
|
4
|
-
import { FulfillmentAPI } from '@things-factory/integration-fulfillment'
|
|
5
|
-
import { MarketplaceSetting, MarketplaceStore, StoreAPI } from '@things-factory/integration-marketplace'
|
|
6
|
-
import { MarketplaceProductVariation } from '@things-factory/marketplace-base'
|
|
7
|
-
import { Product, ProductDetail } from '@things-factory/product-base'
|
|
8
|
-
import { Domain, getRepository } from '@things-factory/shell'
|
|
9
|
-
import { getProductBundleInventory, Inventory, INVENTORY_STATUS, LOCATION_TYPE } from '@things-factory/warehouse-base'
|
|
10
|
-
|
|
11
|
-
export const autoUpdateAllMarketplaceProductVariationQuantityResolver = {
|
|
12
|
-
async autoUpdateAllMarketplaceProductVariationQuantity(
|
|
13
|
-
_: any,
|
|
14
|
-
{ companyDomainId, warehouseId },
|
|
15
|
-
context: ResolverContext
|
|
16
|
-
) {
|
|
17
|
-
const companyDomain: Domain = await getRepository(Domain).findOneBy({ id: companyDomainId })
|
|
18
|
-
|
|
19
|
-
const marketplaceStores: MarketplaceStore[] = await getRepository(MarketplaceStore).find({
|
|
20
|
-
where: { domain: { id: companyDomain.id }, status: 'ACTIVE' },
|
|
21
|
-
relations: ['marketplaceDistributors']
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
const fulfilmentCenter = await FulfillmentAPI.getFulfillmentCenter(warehouseId)
|
|
25
|
-
const centerId: string = fulfilmentCenter.centerId
|
|
26
|
-
const warehouseDomain: Domain = await getRepository(Domain).findOne({ where: { subdomain: centerId } })
|
|
27
|
-
|
|
28
|
-
let products: Product[] = await getRepository(Product).find({
|
|
29
|
-
where: { domain: { id: companyDomain.id } },
|
|
30
|
-
relations: ['productDetails']
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
let inventoryProducts: any[] = await Promise.all(
|
|
34
|
-
products.map(async product => {
|
|
35
|
-
const productDetails: ProductDetail[] = product.productDetails
|
|
36
|
-
const defaultProductDetail: ProductDetail = productDetails.filter(productDetail => productDetail.isDefault)[0]
|
|
37
|
-
|
|
38
|
-
let qb = await getRepository(Inventory).createQueryBuilder('inv')
|
|
39
|
-
qb.leftJoinAndSelect('inv.location', 'loc')
|
|
40
|
-
.andWhere('"inv"."domain_id" = :domainId')
|
|
41
|
-
.andWhere('"inv"."product_id" = :productId')
|
|
42
|
-
.andWhere('"inv"."status" != :status')
|
|
43
|
-
.andWhere('"loc"."type" NOT IN (:...locationTypes)')
|
|
44
|
-
.setParameters({
|
|
45
|
-
domainId: warehouseDomain.id,
|
|
46
|
-
productId: product.id,
|
|
47
|
-
status: INVENTORY_STATUS.TERMINATED,
|
|
48
|
-
locationTypes: [LOCATION_TYPE.QUARANTINE, LOCATION_TYPE.RESERVE]
|
|
49
|
-
})
|
|
50
|
-
|
|
51
|
-
let inventories: Inventory[] = await qb.getMany()
|
|
52
|
-
|
|
53
|
-
const inventoryQty: number = inventories.reduce((total, currentValue) => {
|
|
54
|
-
total += currentValue.qty
|
|
55
|
-
return total
|
|
56
|
-
}, 0)
|
|
57
|
-
|
|
58
|
-
const inventoryLockedQty: number = inventories.reduce((total, currentValue) => {
|
|
59
|
-
total += currentValue.lockedQty
|
|
60
|
-
return total
|
|
61
|
-
}, 0)
|
|
62
|
-
|
|
63
|
-
return {
|
|
64
|
-
product,
|
|
65
|
-
sku: product.sku,
|
|
66
|
-
name: product.name,
|
|
67
|
-
packingType: defaultProductDetail.packingType,
|
|
68
|
-
packingSize: defaultProductDetail.packingSize,
|
|
69
|
-
uom: defaultProductDetail.uom,
|
|
70
|
-
qty: inventoryQty - inventoryLockedQty
|
|
71
|
-
}
|
|
72
|
-
})
|
|
73
|
-
)
|
|
74
|
-
|
|
75
|
-
await getConnection().transaction(async tx => {
|
|
76
|
-
let bundleProductInventories: any[] = await getProductBundleInventory(
|
|
77
|
-
warehouseDomain,
|
|
78
|
-
companyDomain,
|
|
79
|
-
inventoryProducts,
|
|
80
|
-
tx
|
|
81
|
-
)
|
|
82
|
-
|
|
83
|
-
bundleProductInventories.map(bundleProductInventory => {
|
|
84
|
-
inventoryProducts.push(bundleProductInventory)
|
|
85
|
-
})
|
|
86
|
-
})
|
|
87
|
-
|
|
88
|
-
for (let i = 0; i < marketplaceStores.length; i++) {
|
|
89
|
-
try {
|
|
90
|
-
const marketplaceStore: MarketplaceStore = marketplaceStores[i]
|
|
91
|
-
|
|
92
|
-
const marketplaceSetting: MarketplaceSetting = await getRepository(MarketplaceSetting).findOne({
|
|
93
|
-
where: { marketplaceStore: { id: marketplaceStore.id }, category: 'stock_allocation' }
|
|
94
|
-
})
|
|
95
|
-
|
|
96
|
-
for (let j = 0; j < inventoryProducts.length; j++) {
|
|
97
|
-
try {
|
|
98
|
-
await getConnection().transaction(async tx => {
|
|
99
|
-
const inventoryProduct = inventoryProducts[j]
|
|
100
|
-
const marketplaceProductVariations: MarketplaceProductVariation[] = await tx
|
|
101
|
-
.getRepository(MarketplaceProductVariation)
|
|
102
|
-
.find({
|
|
103
|
-
where: { domain: { id: companyDomain.id }, sku: inventoryProduct.sku },
|
|
104
|
-
relations: ['marketplaceProduct', 'marketplaceProduct.marketplaceStore']
|
|
105
|
-
})
|
|
106
|
-
|
|
107
|
-
let storeProductVariations: MarketplaceProductVariation[] = marketplaceProductVariations.filter(
|
|
108
|
-
productVariation => productVariation.marketplaceProduct.marketplaceStore.id === marketplaceStore.id
|
|
109
|
-
)
|
|
110
|
-
|
|
111
|
-
let percentageValue: number = 100
|
|
112
|
-
if (storeProductVariations) {
|
|
113
|
-
for (let k = 0; k < storeProductVariations.length; k++) {
|
|
114
|
-
let storeProductVariation: MarketplaceProductVariation = storeProductVariations[k]
|
|
115
|
-
if (marketplaceSetting) {
|
|
116
|
-
percentageValue = parseInt(marketplaceSetting.value)
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
let remainQty: number = Math.floor(
|
|
120
|
-
(inventoryProduct.qty - storeProductVariation.reserveQty) * (percentageValue / 100)
|
|
121
|
-
)
|
|
122
|
-
if (remainQty < 0) remainQty = 0
|
|
123
|
-
|
|
124
|
-
let productVariationLocationId = storeProductVariation?.locationId
|
|
125
|
-
let adjustQty: number = remainQty
|
|
126
|
-
|
|
127
|
-
if (marketplaceStore.platform === 'shopify') {
|
|
128
|
-
let locationIds: any[] = JSON.parse(productVariationLocationId)
|
|
129
|
-
adjustQty = adjustQty - storeProductVariation.qty
|
|
130
|
-
if (locationIds[0]?.location_id) productVariationLocationId = locationIds[0].location_id
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
let validMarketplaceDistributors: any[] = []
|
|
134
|
-
if (marketplaceStore.marketplaceDistributors) {
|
|
135
|
-
validMarketplaceDistributors = marketplaceStore.marketplaceDistributors.filter(
|
|
136
|
-
distributor => distributor.status === 'ACTIVE'
|
|
137
|
-
)
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
const hasVariation: boolean = storeProductVariation?.marketplaceProduct?.hasVariation
|
|
141
|
-
|
|
142
|
-
if (hasVariation) {
|
|
143
|
-
await StoreAPI.updateStoreProductVariationStock(marketplaceStore, [
|
|
144
|
-
{
|
|
145
|
-
itemId: storeProductVariation.marketplaceProduct.itemId,
|
|
146
|
-
variationId: storeProductVariation.variationId,
|
|
147
|
-
variationSku: storeProductVariation.variationSku,
|
|
148
|
-
qty: adjustQty,
|
|
149
|
-
locationId: productVariationLocationId,
|
|
150
|
-
inventoryItemId: storeProductVariation.inventoryItemId,
|
|
151
|
-
distributors: validMarketplaceDistributors
|
|
152
|
-
}
|
|
153
|
-
])
|
|
154
|
-
} else {
|
|
155
|
-
await StoreAPI.updateStoreProductStock(marketplaceStore, [
|
|
156
|
-
{
|
|
157
|
-
itemId: storeProductVariation.marketplaceProduct.itemId,
|
|
158
|
-
variationId: storeProductVariation.variationId,
|
|
159
|
-
variationSku: storeProductVariation.variationSku,
|
|
160
|
-
qty: adjustQty,
|
|
161
|
-
distributors: validMarketplaceDistributors
|
|
162
|
-
}
|
|
163
|
-
])
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
storeProductVariation.qty = remainQty
|
|
167
|
-
await tx.getRepository(MarketplaceProductVariation).save(storeProductVariation)
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
})
|
|
171
|
-
} catch (error) {
|
|
172
|
-
logger.error(
|
|
173
|
-
`interface-with-hub[autoUpdateAllMarketplaceProductVariationQuantity]inventoryProducts: ${error}`
|
|
174
|
-
)
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
} catch (e) {
|
|
178
|
-
logger.error(`interface-with-hub[autoUpdateAllMarketplaceProductVariationQuantity]marketplaceStores: ${e}`)
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
return true
|
|
183
|
-
}
|
|
184
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { Bizplace, getSubdomainBizplace } from '@things-factory/biz-base'
|
|
2
|
-
import { FulfillmentAPI } from '@things-factory/integration-fulfillment'
|
|
3
|
-
import { StoreReplenishment } from '@things-factory/marketplace-base'
|
|
4
|
-
|
|
5
|
-
export const generateReplenishmentOrderResolver = {
|
|
6
|
-
async generateReplenishmentOrder(
|
|
7
|
-
_: void,
|
|
8
|
-
{ storeReplenishmentId, warehouseId }: { storeReplenishmentId: string; warehouseId: string },
|
|
9
|
-
context: ResolverContext
|
|
10
|
-
): Promise<any> {
|
|
11
|
-
const { tx } = context.state
|
|
12
|
-
|
|
13
|
-
let storeReplenishment: StoreReplenishment = await tx.getRepository(StoreReplenishment).findOne({
|
|
14
|
-
where: { id: storeReplenishmentId },
|
|
15
|
-
relations: ['storeReplenishmentItems']
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
var fulfillmentCenter = await FulfillmentAPI.getFulfillmentCenter(warehouseId)
|
|
19
|
-
var centerId: string = fulfillmentCenter.centerId
|
|
20
|
-
|
|
21
|
-
var subdominBizplace: Bizplace = await getSubdomainBizplace(centerId)
|
|
22
|
-
var warehouseBizplaceId: string = subdominBizplace?.id
|
|
23
|
-
|
|
24
|
-
var arrivalNotice = await FulfillmentAPI.createInboundOrder(fulfillmentCenter, {
|
|
25
|
-
warehouseBizplaceId,
|
|
26
|
-
storeReplenishment
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
storeReplenishment.arrivalNoticeId = arrivalNotice.id
|
|
30
|
-
await tx.getRepository(StoreReplenishment).save(storeReplenishment)
|
|
31
|
-
}
|
|
32
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { addReleaseOrderResolver } from './add-release-order'
|
|
2
|
-
import { autoAddReleaseOrderResolver } from './auto-add-release-order'
|
|
3
|
-
import { autoUpdateAllMarketplaceProductVariationQuantityResolver } from './auto-update-all-marketplace-product-variation-quantity'
|
|
4
|
-
import { generateReplenishmentOrderResolver } from './generate-replenishment-order'
|
|
5
|
-
import { warehouseMarketplaceProduct, warehouseMarketplaceProductsResolver } from './warehouse-marketplace-products'
|
|
6
|
-
|
|
7
|
-
export const Query = {
|
|
8
|
-
...warehouseMarketplaceProductsResolver
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export const Mutation = {
|
|
12
|
-
...addReleaseOrderResolver,
|
|
13
|
-
...autoAddReleaseOrderResolver,
|
|
14
|
-
...generateReplenishmentOrderResolver,
|
|
15
|
-
...autoUpdateAllMarketplaceProductVariationQuantityResolver
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export { warehouseMarketplaceProduct }
|
|
@@ -1,247 +0,0 @@
|
|
|
1
|
-
import { EntityManager } from 'typeorm'
|
|
2
|
-
|
|
3
|
-
import { User } from '@things-factory/auth-base'
|
|
4
|
-
import { Bizplace, getCompanyBizplace, getMyBizplace } from '@things-factory/biz-base'
|
|
5
|
-
import { Domain, ListParam } from '@things-factory/shell'
|
|
6
|
-
|
|
7
|
-
export const warehouseMarketplaceProductsResolver = {
|
|
8
|
-
async warehouseMarketplaceProducts(_: any, params: ListParam, context: ResolverContext): Promise<any> {
|
|
9
|
-
try {
|
|
10
|
-
const { domain, user, tx } = context.state
|
|
11
|
-
return warehouseMarketplaceProduct(params, domain, user, tx)
|
|
12
|
-
} catch (error) {
|
|
13
|
-
throw error
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export async function warehouseMarketplaceProduct(params: ListParam, domain: Domain, user: User, tx?: EntityManager) {
|
|
19
|
-
const productFilters = params.filters.filter(x => x.name == 'product_info')
|
|
20
|
-
const filters = params.filters.filter(x => x.name != 'product_info')
|
|
21
|
-
|
|
22
|
-
const companyBizplace: Bizplace = await getCompanyBizplace(domain, user)
|
|
23
|
-
const myBizplace: Bizplace = await getMyBizplace(domain, user)
|
|
24
|
-
|
|
25
|
-
params.filters = [...filters, { name: 'bizplace_id', operator: 'in', value: [companyBizplace.id, myBizplace.id] }]
|
|
26
|
-
|
|
27
|
-
const bizplaceIds: string = params.filters
|
|
28
|
-
.find((filter: any) => filter.name === 'bizplace_id')
|
|
29
|
-
.value.map((id: string) => `'${id}'`)
|
|
30
|
-
.join()
|
|
31
|
-
|
|
32
|
-
let productQuery = ''
|
|
33
|
-
if (productFilters && productFilters.length > 0) {
|
|
34
|
-
let productInfo = productFilters[0]
|
|
35
|
-
productQuery = ` AND (
|
|
36
|
-
Lower("Product"."sku") LIKE '${productInfo.value.toLowerCase()}'
|
|
37
|
-
OR Lower("Product"."name") LIKE '${productInfo.value.toLowerCase()}'
|
|
38
|
-
OR Lower("Product"."description") LIKE '${productInfo.value.toLowerCase()}')`
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
await tx.query(`
|
|
42
|
-
CREATE TEMP TABLE "temp_products" ON COMMIT DROP AS (
|
|
43
|
-
SELECT * FROM (
|
|
44
|
-
SELECT "Product"."id" AS "product_id", "Product"."sku" AS "product_sku", "Product"."name" AS "product_name",
|
|
45
|
-
"Product"."description" AS "product_description", "Product"."creator_id", "Product"."updater_id",
|
|
46
|
-
"Product"."bizplace_id" AS "product_bizplace_id", 'PRODUCT' AS "type"
|
|
47
|
-
FROM products "Product"
|
|
48
|
-
WHERE 1=1
|
|
49
|
-
AND "Product"."deleted_at" IS NULL
|
|
50
|
-
AND "Product"."bizplace_id" IN (${bizplaceIds})
|
|
51
|
-
${productQuery}
|
|
52
|
-
) d1
|
|
53
|
-
UNION ALL
|
|
54
|
-
SELECT * FROM
|
|
55
|
-
(
|
|
56
|
-
SELECT "Product"."id" AS "product_id", "Product"."sku" AS "product_sku", "Product"."name" AS "product_name",
|
|
57
|
-
"Product"."description" AS "product_description", "Product"."creator_id", "Product"."updater_id",
|
|
58
|
-
"Product"."bizplace_id" AS "product_bizplace_id", 'BUNDLE' AS "type"
|
|
59
|
-
FROM product_bundles "Product"
|
|
60
|
-
WHERE 1 = 1
|
|
61
|
-
AND "Product"."status" = 'ACTIVATED'
|
|
62
|
-
AND "Product"."bizplace_id" IN (${bizplaceIds})
|
|
63
|
-
${productQuery}
|
|
64
|
-
) d2
|
|
65
|
-
)
|
|
66
|
-
`)
|
|
67
|
-
|
|
68
|
-
await tx.query(
|
|
69
|
-
`
|
|
70
|
-
CREATE TEMP TABLE "temp_order_inventories" ON COMMIT DROP AS (
|
|
71
|
-
SELECT
|
|
72
|
-
SUM(oi.release_qty) AS release_qty, SUM(oi.release_uom_value) AS release_uom_value, oi.batch_id, oi.batch_id_ref,
|
|
73
|
-
oi.product_id, p.product_name, oi.packing_type, oi.packing_size, oi.uom
|
|
74
|
-
FROM
|
|
75
|
-
order_inventories oi
|
|
76
|
-
LEFT JOIN
|
|
77
|
-
temp_products p ON oi.product_id = p.product_id
|
|
78
|
-
INNER JOIN
|
|
79
|
-
domains d2 on d2.id = oi.domain_id and d2.ext_type ='warehouse'
|
|
80
|
-
INNER JOIN
|
|
81
|
-
fulfillment_centers fc ON fc.center_id = d2.subdomain
|
|
82
|
-
WHERE
|
|
83
|
-
fc.domain_id = $1
|
|
84
|
-
AND (oi.status = 'PENDING' or oi.status = 'PENDING_RECEIVE' or oi.status = 'PENDING_WORKSHEET' or oi.status = 'PENDING_SPLIT')
|
|
85
|
-
AND oi.batch_id NOTNULL AND oi.product_id NOTNULL AND oi.packing_type NOTNULL AND oi.packing_size NOTNULL AND oi.inventory_id IS NULL
|
|
86
|
-
GROUP BY
|
|
87
|
-
oi.batch_id, oi.batch_id_ref, oi.product_id, oi.packing_type,
|
|
88
|
-
oi.packing_size, oi.uom, p.product_name
|
|
89
|
-
);
|
|
90
|
-
`,
|
|
91
|
-
[domain.id]
|
|
92
|
-
)
|
|
93
|
-
|
|
94
|
-
await tx.query(
|
|
95
|
-
`
|
|
96
|
-
CREATE TEMP TABLE "temp_inventory" ON COMMIT DROP AS (
|
|
97
|
-
select "i2".*, coalesce("oi".release_qty,0) + coalesce("i2".locked_qty,0) as "inventory_locked_qty" from (
|
|
98
|
-
select "fc"."id" as "fulfillment_id", "fc"."name" as "fulfillment_name",
|
|
99
|
-
"i2"."product_id", sum(coalesce("locked_qty",0)) as "locked_qty", sum(coalesce("qty",0)) as "inventory_qty",
|
|
100
|
-
"i2"."domain_id", "i2"."packing_type", "i2"."packing_size", "i2"."uom"
|
|
101
|
-
from inventories "i2"
|
|
102
|
-
inner join warehouses "w" on "w"."id" = "i2"."warehouse_id"
|
|
103
|
-
inner join domains "d2" on "d2"."id" = "w"."domain_id" and "d2"."ext_type" ='warehouse'
|
|
104
|
-
inner join fulfillment_centers "fc" ON "fc"."center_id" = "d2"."subdomain"
|
|
105
|
-
inner join (
|
|
106
|
-
select "Product"."product_id" from (
|
|
107
|
-
select case when "Product"."type" = 'PRODUCT' then "Product"."product_id" else "pbs"."product_id" end as "product_id"
|
|
108
|
-
from temp_products "Product"
|
|
109
|
-
left join product_bundles "pb" on "pb"."id" = "Product"."product_id"
|
|
110
|
-
left join product_bundle_settings "pbs" on "pbs"."product_bundle_id" = "pb"."id"
|
|
111
|
-
) "Product"
|
|
112
|
-
group by "Product"."product_id"
|
|
113
|
-
) "Product" on "Product"."product_id" = "i2"."product_id"
|
|
114
|
-
where "fc"."domain_id" = $1
|
|
115
|
-
and "i2"."status" = 'STORED'
|
|
116
|
-
group by "i2"."domain_id", "fc"."id", "fc"."name", "i2"."product_id", "i2"."packing_type", "i2"."packing_size", "i2"."uom"
|
|
117
|
-
) as "i2"
|
|
118
|
-
left join temp_order_inventories "oi" on "i2"."product_id" = "oi"."product_id"
|
|
119
|
-
AND "i2"."packing_type" = "oi"."packing_type"
|
|
120
|
-
AND "i2"."packing_size" = "oi"."packing_size"
|
|
121
|
-
AND "i2"."uom" = "oi"."uom"
|
|
122
|
-
)
|
|
123
|
-
`,
|
|
124
|
-
[domain.id]
|
|
125
|
-
)
|
|
126
|
-
|
|
127
|
-
await tx.query(`
|
|
128
|
-
CREATE TEMP TABLE "temp_json_warehouse_marketplace_products" ON COMMIT DROP AS (
|
|
129
|
-
select "product_id", array_to_json(array_agg(row_to_json(dt))) AS "Json_marketplaceProducts" FROM (
|
|
130
|
-
select "dt"."marketplace_store_id", "dt"."product_id", "dt"."sku", array_agg(row_to_json(dt)) as product_variation
|
|
131
|
-
from (
|
|
132
|
-
select "mp"."marketplace_store_id" as "marketplace_store_id", "mpv"."sku", "mpv"."id" as "marketplace_product_variation_id",
|
|
133
|
-
concat("mpv"."variation_sku", ' (', "mpv"."name", ')') as "name", "mpv"."qty" as "qty", "mpv"."reserve_qty" as "reserve_qty",
|
|
134
|
-
"Product"."product_id" AS "product_id"
|
|
135
|
-
from marketplace_product_variations "mpv"
|
|
136
|
-
inner join marketplace_products "mp" on "mp"."id" = "mpv"."marketplace_product_id"
|
|
137
|
-
inner join temp_products "Product" on "mpv"."sku" = "Product"."product_sku"
|
|
138
|
-
) as "dt"
|
|
139
|
-
group by "dt"."marketplace_store_id", "dt"."sku", "dt"."product_id"
|
|
140
|
-
) "dt" group by "dt"."product_id"
|
|
141
|
-
)
|
|
142
|
-
`)
|
|
143
|
-
|
|
144
|
-
await tx.query(
|
|
145
|
-
`
|
|
146
|
-
CREATE TEMP TABLE temp_json_warehouse_inventory ON COMMIT DROP AS (
|
|
147
|
-
select "product_id", array_to_json(array_agg((row_to_json("dt")))) AS "Json_warehouseInventory" from(
|
|
148
|
-
select "domain_id", "fulfillment_id", "fulfillment_name",
|
|
149
|
-
"product_id", "inventory_locked_qty", "inventory_qty"
|
|
150
|
-
from temp_inventory
|
|
151
|
-
union
|
|
152
|
-
select "bundledInv"."domain_id", "bundledInv"."fulfillment_id", "bundledInv"."fulfillment_name", "bundledInv"."product_id",
|
|
153
|
-
max("bundledInv"."inventory_locked_qty") as "inventory_locked_qty", min("bundledInv"."inventory_qty") as "inventory_qty" from (
|
|
154
|
-
select "Product"."product_id", fc.domain_id, "fc"."id" as "fulfillment_id", "fc"."name" as "fulfillment_name",
|
|
155
|
-
"pbs"."bundle_qty",
|
|
156
|
-
case when "pbs"."bundle_qty" <= 0 then 0 else floor(greatest("i2"."inventory_qty", 0)/ "pbs"."bundle_qty")- floor((greatest("i2"."inventory_qty", 0) - greatest("i2"."inventory_locked_qty",0)) / "pbs"."bundle_qty") end AS "inventory_locked_qty",
|
|
157
|
-
case when "pbs"."bundle_qty" <= 0 then 0 else floor(greatest("i2"."inventory_qty", 0)/ "pbs"."bundle_qty") end AS "inventory_qty"
|
|
158
|
-
from temp_products "Product"
|
|
159
|
-
inner join product_bundle_settings pbs ON pbs.product_bundle_id = "Product"."product_id"
|
|
160
|
-
inner join products p on p.id = pbs.product_id
|
|
161
|
-
cross join fulfillment_centers fc
|
|
162
|
-
inner join domains "d2" on "d2"."ext_type" ='warehouse' and "fc"."center_id" = "d2"."subdomain"
|
|
163
|
-
left join temp_inventory i2 ON i2.product_id = pbs.product_id and "d2"."id" = "i2"."domain_id"
|
|
164
|
-
where "fc"."domain_id" = $1
|
|
165
|
-
order by fc.id, "Product"."product_sku", p.sku
|
|
166
|
-
) "bundledInv"
|
|
167
|
-
group by "domain_id","fulfillment_id","fulfillment_name","product_id"
|
|
168
|
-
) "dt" group by "dt"."product_id"
|
|
169
|
-
)
|
|
170
|
-
`,
|
|
171
|
-
[domain.id]
|
|
172
|
-
)
|
|
173
|
-
|
|
174
|
-
await tx.query(`
|
|
175
|
-
CREATE TEMP TABLE temp_warehouse_marketplace_products ON COMMIT DROP as (
|
|
176
|
-
SELECT "Product"."product_id" AS "Product_id", "Product"."product_sku" AS "Product_sku",
|
|
177
|
-
"Product"."product_name" AS "Product_name", "Product"."product_description" AS "Product_description",
|
|
178
|
-
"Product"."product_bizplace_id" AS "Product_bizplace_id",
|
|
179
|
-
"Product"."creator_id" AS "Product_creator_id", "Product"."updater_id" AS "Product_updater_id",
|
|
180
|
-
"Bizplace"."name" AS "Bizplace_name", "Bizplace"."description" AS "Bizplace_description", "Bizplace"."address" AS "Bizplace_address", "Bizplace"."postal_code" AS "Bizplace_postal_code",
|
|
181
|
-
"Bizplace"."latlng" AS "Bizplace_latlng", "Bizplace"."status" AS "Bizplace_status", "Bizplace"."created_at" AS "Bizplace_created_at", "Bizplace"."updated_at" AS "Bizplace_updated_at",
|
|
182
|
-
"Bizplace"."domain_id" AS "Bizplace_domain_id", "Bizplace"."company_id" AS "Bizplace_company_id", "Bizplace"."creator_id" AS "Bizplace_creator_id", "Bizplace"."updater_id" AS "Bizplace_updater_id",
|
|
183
|
-
"Creator"."id" AS "Creator_id", "Creator"."name" AS "Creator_name", "Creator"."description" AS "Creator_description", "Creator"."email" AS "Creator_email",
|
|
184
|
-
"Updater"."id" AS "Updater_id", "Updater"."name" AS "Updater_name", "Updater"."description" AS "Updater_description", "Updater"."email" AS "Updater_email"
|
|
185
|
-
,COALESCE("whInv"."Json_warehouseInventory", null) AS "Json_warehouseInventory"
|
|
186
|
-
,COALESCE("mktPrd"."Json_marketplaceProducts", null) AS "Json_marketplaceProducts"
|
|
187
|
-
FROM "temp_products" "Product"
|
|
188
|
-
LEFT JOIN "bizplaces" "Bizplace" ON "Bizplace"."id" = "Product"."product_bizplace_id"
|
|
189
|
-
LEFT JOIN "users" "Creator" ON "Creator"."id"="Product"."creator_id"
|
|
190
|
-
LEFT JOIN "users" "Updater" ON "Updater"."id"="Product"."updater_id"
|
|
191
|
-
LEFT JOIN "temp_json_warehouse_inventory" "whInv" ON "whInv"."product_id" = "Product"."product_id"
|
|
192
|
-
LEFT JOIN "temp_json_warehouse_marketplace_products" "mktPrd" ON "mktPrd"."product_id" = "Product"."product_id"
|
|
193
|
-
)
|
|
194
|
-
`)
|
|
195
|
-
|
|
196
|
-
const offsetQuery: string = params?.pagination
|
|
197
|
-
? `OFFSET ${(params.pagination.page - 1) * params.pagination.limit} LIMIT ${params.pagination.limit}`
|
|
198
|
-
: ''
|
|
199
|
-
|
|
200
|
-
const total: any = await tx.query(`select count(*) from temp_warehouse_marketplace_products`)
|
|
201
|
-
|
|
202
|
-
const items: any[] = await tx.query(
|
|
203
|
-
`
|
|
204
|
-
select * from temp_warehouse_marketplace_products ${offsetQuery}
|
|
205
|
-
`
|
|
206
|
-
)
|
|
207
|
-
|
|
208
|
-
return {
|
|
209
|
-
items: items.map((itm, index) => {
|
|
210
|
-
return {
|
|
211
|
-
seq: index + (params?.pagination ? (params.pagination.page - 1) * params.pagination.limit + 1 : 0),
|
|
212
|
-
id: itm.Product_id,
|
|
213
|
-
sku: itm.Product_sku,
|
|
214
|
-
name: itm.Product_name,
|
|
215
|
-
description: itm.Product_description,
|
|
216
|
-
marketplaceProduct: itm.Json_marketplaceProducts
|
|
217
|
-
? itm.Json_marketplaceProducts.map(product => {
|
|
218
|
-
return {
|
|
219
|
-
marketplaceStore: { id: product.marketplace_store_id },
|
|
220
|
-
marketplaceProductVariations: product.product_variation.map(variation => {
|
|
221
|
-
return {
|
|
222
|
-
id: variation.marketplace_product_variation_id,
|
|
223
|
-
name: variation.name,
|
|
224
|
-
qty: variation.qty,
|
|
225
|
-
reserveQty: variation.reserve_qty
|
|
226
|
-
}
|
|
227
|
-
})
|
|
228
|
-
}
|
|
229
|
-
})
|
|
230
|
-
: null,
|
|
231
|
-
warehouseInventory: itm.Json_warehouseInventory
|
|
232
|
-
? itm.Json_warehouseInventory.map(inventory => {
|
|
233
|
-
return {
|
|
234
|
-
bizplace: { id: inventory.fulfillment_id, name: inventory.fulfillment_name },
|
|
235
|
-
product: { id: inventory.product_id },
|
|
236
|
-
qty: inventory.inventory_qty,
|
|
237
|
-
lockedQty: inventory.inventory_locked_qty ? inventory.inventory_locked_qty : 0,
|
|
238
|
-
remainQty:
|
|
239
|
-
inventory.inventory_qty - (inventory.inventory_locked_qty ? inventory.inventory_locked_qty : 0)
|
|
240
|
-
}
|
|
241
|
-
})
|
|
242
|
-
: null
|
|
243
|
-
}
|
|
244
|
-
}),
|
|
245
|
-
total: total[0].count
|
|
246
|
-
}
|
|
247
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { MarketplaceOrder } from '@things-factory/marketplace-base'
|
|
2
|
-
import { getRepository, ListParam } from '@things-factory/shell'
|
|
3
|
-
|
|
4
|
-
export const shippingProviders = {
|
|
5
|
-
async shippingProviders(
|
|
6
|
-
_: any,
|
|
7
|
-
params: ListParam & { statuses?: string[]; storeId?: string },
|
|
8
|
-
context: ResolverContext
|
|
9
|
-
) {
|
|
10
|
-
try {
|
|
11
|
-
const { domain } = context.state
|
|
12
|
-
|
|
13
|
-
let statusFilter = ``
|
|
14
|
-
if (params.statuses) {
|
|
15
|
-
statusFilter = `AND status in (${params.statuses.map(e => {
|
|
16
|
-
return `'` + e + `'`
|
|
17
|
-
})})`
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
let items: any[] = await getRepository(MarketplaceOrder).query(
|
|
21
|
-
`
|
|
22
|
-
SELECT DISTINCT shipping_provider FROM marketplace_orders WHERE domain_id = '${domain.id}' AND marketplace_store_id = '${params.storeId}' AND shipping_provider IS NOT null AND shipping_provider != ''
|
|
23
|
-
` + statusFilter
|
|
24
|
-
)
|
|
25
|
-
|
|
26
|
-
items = items.map(e => {
|
|
27
|
-
const { shipping_provider: shippingProvider } = e
|
|
28
|
-
|
|
29
|
-
return {
|
|
30
|
-
shippingProvider
|
|
31
|
-
}
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
return { items }
|
|
35
|
-
} catch (error) {
|
|
36
|
-
throw error
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import { In, IsNull } from 'typeorm'
|
|
2
|
-
|
|
3
|
-
import { MarketplaceProduct, MarketplaceProductVariation } from '@things-factory/marketplace-base'
|
|
4
|
-
import { publishProgress } from '@things-factory/shell'
|
|
5
|
-
|
|
6
|
-
import { warehouseMarketplaceProduct } from '../interface-with-hub/warehouse-marketplace-products'
|
|
7
|
-
|
|
8
|
-
export const autoLinkWarehouseMarketplaceProductVariationsResolver = {
|
|
9
|
-
async autoLinkWarehouseMarketplaceProductVariations(
|
|
10
|
-
_: any,
|
|
11
|
-
{ marketplaceStoreIds, isCheckedSku },
|
|
12
|
-
context: ResolverContext
|
|
13
|
-
): Promise<Boolean> {
|
|
14
|
-
const { domain, user, tx } = context.state
|
|
15
|
-
|
|
16
|
-
const tag = `progress-link-product`
|
|
17
|
-
|
|
18
|
-
await linkMarketplaceProductVariations({
|
|
19
|
-
domain,
|
|
20
|
-
user,
|
|
21
|
-
tag,
|
|
22
|
-
marketplaceStoreIds,
|
|
23
|
-
isCheckedSku,
|
|
24
|
-
tx
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
return true
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
async function linkMarketplaceProductVariations({ domain, user, tag, marketplaceStoreIds, isCheckedSku, tx }) {
|
|
32
|
-
try {
|
|
33
|
-
const params: any = { filters: [], sortings: [] }
|
|
34
|
-
const warehouseMarketplaceProducts = await warehouseMarketplaceProduct(params, domain, user, tx)
|
|
35
|
-
|
|
36
|
-
const marketplaceProducts: MarketplaceProduct[] = await tx.getRepository(MarketplaceProduct).find({
|
|
37
|
-
where: { domain: { id: domain.id }, marketplaceStore: In(marketplaceStoreIds) }
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
let marketplaceProductVariations: MarketplaceProductVariation[] = await tx
|
|
41
|
-
.getRepository(MarketplaceProductVariation)
|
|
42
|
-
.find({
|
|
43
|
-
where: {
|
|
44
|
-
domain: { id: domain.id },
|
|
45
|
-
marketplaceProduct: In(marketplaceProducts.map(product => product.id)),
|
|
46
|
-
sku: IsNull()
|
|
47
|
-
}
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
let total: number = marketplaceProductVariations?.length
|
|
51
|
-
|
|
52
|
-
const linkedProductVariations: MarketplaceProductVariation[] = await Promise.all(
|
|
53
|
-
marketplaceProductVariations.map((productVariation: MarketplaceProductVariation, idx) => {
|
|
54
|
-
let foundSku: any
|
|
55
|
-
|
|
56
|
-
if (isCheckedSku) {
|
|
57
|
-
foundSku = warehouseMarketplaceProducts.items.find(
|
|
58
|
-
warehouseProd => warehouseProd.sku === productVariation.variationSku
|
|
59
|
-
)
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
productVariation.sku = foundSku?.sku ? foundSku.sku : null
|
|
63
|
-
productVariation.updater = user
|
|
64
|
-
|
|
65
|
-
publishProgress({
|
|
66
|
-
domain: { id: domain.id },
|
|
67
|
-
tag,
|
|
68
|
-
progress: Math.floor((idx / total) * 100),
|
|
69
|
-
message: `${idx} / ${total}`
|
|
70
|
-
})
|
|
71
|
-
|
|
72
|
-
return productVariation
|
|
73
|
-
})
|
|
74
|
-
)
|
|
75
|
-
|
|
76
|
-
await tx.getRepository(MarketplaceProductVariation).save(linkedProductVariations)
|
|
77
|
-
} catch (ex) {
|
|
78
|
-
publishProgress({
|
|
79
|
-
domain,
|
|
80
|
-
tag,
|
|
81
|
-
progress: -1,
|
|
82
|
-
message: 'failed'
|
|
83
|
-
})
|
|
84
|
-
|
|
85
|
-
throw ex
|
|
86
|
-
}
|
|
87
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import * as InterfaceWithHub from './interface-with-hub'
|
|
2
|
-
import * as WarehouseProduct from './warehouse-product'
|
|
3
|
-
import * as ShippingProvider from './shipping-provider'
|
|
4
|
-
|
|
5
|
-
export const queries = [InterfaceWithHub.Query, ShippingProvider.Query]
|
|
6
|
-
|
|
7
|
-
export const mutations = [InterfaceWithHub.Mutation, WarehouseProduct.Mutation]
|
|
8
|
-
|
|
9
|
-
export const types = [...InterfaceWithHub.Types, ...WarehouseProduct.Types, ...ShippingProvider.Types]
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { NewStockReplenishment } from './new-stock-replenishment'
|
|
2
|
-
import { ReplenishmentOrderProduct } from './replenishment-order-product'
|
|
3
|
-
import { StockReplenishment } from './stock-replenishment'
|
|
4
|
-
import { StockReplenishmentList } from './stock-replenishment-list'
|
|
5
|
-
import { WarehouseInventory } from './warehouse-inventory'
|
|
6
|
-
import { WarehouseMarketplaceProduct } from './warehouse-marketplace-product'
|
|
7
|
-
import { WarehouseMarketplaceProductList } from './warehouse-marketplace-product-list'
|
|
8
|
-
|
|
9
|
-
export const Mutation = /* GraphQL */ `
|
|
10
|
-
addReleaseOrder(marketplaceOrderIds: [String]!, warehouseId: String!): Boolean @transaction
|
|
11
|
-
autoAddReleaseOrder(warehouseId: String): Boolean @transaction
|
|
12
|
-
generateReplenishmentOrder(stockReplenishmentId: String!, warehouseId: String!): StockReplenishment @transaction
|
|
13
|
-
autoUpdateAllMarketplaceProductVariationQuantity(companyDomainId: String, warehouseId: String): Boolean @transaction
|
|
14
|
-
`
|
|
15
|
-
|
|
16
|
-
export const Query = /* GraphQL */ `
|
|
17
|
-
warehouseMarketplaceProducts(filters: [Filter], pagination: Pagination, sortings: [Sorting]): WarehouseMarketplaceProductList @transaction
|
|
18
|
-
`
|
|
19
|
-
|
|
20
|
-
export const Types = [
|
|
21
|
-
StockReplenishment,
|
|
22
|
-
NewStockReplenishment,
|
|
23
|
-
ReplenishmentOrderProduct,
|
|
24
|
-
StockReplenishmentList,
|
|
25
|
-
WarehouseInventory,
|
|
26
|
-
WarehouseMarketplaceProduct,
|
|
27
|
-
WarehouseMarketplaceProductList
|
|
28
|
-
]
|