@things-factory/operato-mms 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 +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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@things-factory/operato-mms",
|
|
3
|
-
"version": "6.1.
|
|
3
|
+
"version": "6.1.85",
|
|
4
4
|
"main": "dist-server/index.js",
|
|
5
5
|
"browser": "client/index.js",
|
|
6
6
|
"things-factory": true,
|
|
@@ -19,12 +19,12 @@
|
|
|
19
19
|
"scripts": {
|
|
20
20
|
"serve": "things-factory operato-mms",
|
|
21
21
|
"serve:dev": "npm run build:server && things-factory-dev operato-mms",
|
|
22
|
-
"build": "
|
|
23
|
-
"build:
|
|
24
|
-
"build:
|
|
22
|
+
"build": "npm run build:server",
|
|
23
|
+
"build:server": "npm run clean:server && tsc --p ./server/tsconfig.json",
|
|
24
|
+
"build:app": "npm run clean:app && webpack --config ../builder/webpack.config.js",
|
|
25
25
|
"clean:server": "rm -rf dist-server",
|
|
26
|
-
"clean:
|
|
27
|
-
"clean": "npm run clean:server
|
|
26
|
+
"clean:app": "rm -rf dist-app",
|
|
27
|
+
"clean": "npm run clean:server",
|
|
28
28
|
"migration": "things-factory-migration",
|
|
29
29
|
"migration:privileges": "things-factory-migration-privileges",
|
|
30
30
|
"migration:create": "node ../../node_modules/typeorm/cli.js migration:create -d ./server/migrations",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"migration:revert": "node ../../node_modules/typeorm/cli.js migration:revert",
|
|
34
34
|
"stop:dev": "kill $(lsof -t -i:3000,3001)",
|
|
35
35
|
"stop": "things-factory-stop operato-mms",
|
|
36
|
-
"docker": "things-factory-dockerize hatiolab/operato-mms:latest hatiolab/operato-mms:$npm_package_version linux/amd64",
|
|
36
|
+
"docker": "npm run build:app && things-factory-dockerize hatiolab/operato-mms:latest hatiolab/operato-mms:$npm_package_version linux/amd64",
|
|
37
37
|
"docker:push": "docker image push hatiolab/operato-mms:latest && docker image push hatiolab/operato-mms:$npm_package_version",
|
|
38
38
|
"docker:run": "docker run --platform linux/amd64 -p 4000:3000 hatiolab/operato-mms:latest"
|
|
39
39
|
},
|
|
@@ -69,39 +69,39 @@
|
|
|
69
69
|
"@operato/scene-timer": "^1.0.0",
|
|
70
70
|
"@operato/scene-visualizer": "^1.0.0",
|
|
71
71
|
"@operato/scene-wheel-sorter": "^1.0.0",
|
|
72
|
-
"@things-factory/apptool-ui": "^6.1.
|
|
73
|
-
"@things-factory/attachment-base": "^6.1.
|
|
74
|
-
"@things-factory/auth-ui": "^6.1.
|
|
75
|
-
"@things-factory/biz-base": "^6.1.
|
|
76
|
-
"@things-factory/board-service": "^6.1.
|
|
77
|
-
"@things-factory/board-ui": "^6.1.
|
|
78
|
-
"@things-factory/code-ui": "^6.1.
|
|
79
|
-
"@things-factory/context-ui": "^6.1.
|
|
80
|
-
"@things-factory/dashboard": "^6.1.
|
|
81
|
-
"@things-factory/export-ui": "^6.1.
|
|
82
|
-
"@things-factory/export-ui-csv": "^6.1.
|
|
83
|
-
"@things-factory/export-ui-excel": "^6.1.
|
|
84
|
-
"@things-factory/geography": "^6.1.
|
|
85
|
-
"@things-factory/help": "^6.1.
|
|
86
|
-
"@things-factory/i18n-base": "^6.1.
|
|
87
|
-
"@things-factory/integration-fulfillment": "^6.1.
|
|
88
|
-
"@things-factory/integration-lmd": "^6.1.
|
|
89
|
-
"@things-factory/lite-menu": "^6.1.
|
|
90
|
-
"@things-factory/marketplace-base": "^6.1.
|
|
91
|
-
"@things-factory/more-ui": "^6.1.
|
|
92
|
-
"@things-factory/notification": "^6.1.
|
|
93
|
-
"@things-factory/oauth2-client": "^6.1.
|
|
72
|
+
"@things-factory/apptool-ui": "^6.1.84",
|
|
73
|
+
"@things-factory/attachment-base": "^6.1.84",
|
|
74
|
+
"@things-factory/auth-ui": "^6.1.84",
|
|
75
|
+
"@things-factory/biz-base": "^6.1.84",
|
|
76
|
+
"@things-factory/board-service": "^6.1.84",
|
|
77
|
+
"@things-factory/board-ui": "^6.1.84",
|
|
78
|
+
"@things-factory/code-ui": "^6.1.84",
|
|
79
|
+
"@things-factory/context-ui": "^6.1.84",
|
|
80
|
+
"@things-factory/dashboard": "^6.1.84",
|
|
81
|
+
"@things-factory/export-ui": "^6.1.84",
|
|
82
|
+
"@things-factory/export-ui-csv": "^6.1.84",
|
|
83
|
+
"@things-factory/export-ui-excel": "^6.1.84",
|
|
84
|
+
"@things-factory/geography": "^6.1.84",
|
|
85
|
+
"@things-factory/help": "^6.1.84",
|
|
86
|
+
"@things-factory/i18n-base": "^6.1.84",
|
|
87
|
+
"@things-factory/integration-fulfillment": "^6.1.84",
|
|
88
|
+
"@things-factory/integration-lmd": "^6.1.84",
|
|
89
|
+
"@things-factory/lite-menu": "^6.1.84",
|
|
90
|
+
"@things-factory/marketplace-base": "^6.1.84",
|
|
91
|
+
"@things-factory/more-ui": "^6.1.84",
|
|
92
|
+
"@things-factory/notification": "^6.1.84",
|
|
93
|
+
"@things-factory/oauth2-client": "^6.1.84",
|
|
94
94
|
"@things-factory/pdf": "^6.1.79",
|
|
95
|
-
"@things-factory/product-base": "^6.1.
|
|
96
|
-
"@things-factory/resource-ui": "^6.1.
|
|
95
|
+
"@things-factory/product-base": "^6.1.84",
|
|
96
|
+
"@things-factory/resource-ui": "^6.1.84",
|
|
97
97
|
"@things-factory/scene-google-map": "^6.1.79",
|
|
98
|
-
"@things-factory/setting-ui": "^6.1.
|
|
99
|
-
"@things-factory/system-ui": "^6.1.
|
|
100
|
-
"@things-factory/warehouse-base": "^6.1.
|
|
98
|
+
"@things-factory/setting-ui": "^6.1.84",
|
|
99
|
+
"@things-factory/system-ui": "^6.1.84",
|
|
100
|
+
"@things-factory/warehouse-base": "^6.1.84"
|
|
101
101
|
},
|
|
102
102
|
"devDependencies": {
|
|
103
|
-
"@things-factory/builder": "^6.1.
|
|
103
|
+
"@things-factory/builder": "^6.1.85",
|
|
104
104
|
"@types/node-fetch": "^2.5.7"
|
|
105
105
|
},
|
|
106
|
-
"gitHead": "
|
|
106
|
+
"gitHead": "5ebda26d71b4181008aea1b2eb8cd9169928e55d"
|
|
107
107
|
}
|
|
File without changes
|
package/server/entities/index.ts
DELETED
package/server/graphql/index.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import * as InterfaceWithHub from './interface-with-hub'
|
|
2
|
-
import * as WarehouseProduct from './warehouse-product'
|
|
3
|
-
import * as ShippingProviders from './shipping-provider'
|
|
4
|
-
|
|
5
|
-
export const queries = [InterfaceWithHub.Query, ShippingProviders.Query]
|
|
6
|
-
|
|
7
|
-
export const mutations = [InterfaceWithHub.Mutation, WarehouseProduct.Mutation]
|
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
import { Bizplace, getCustomerBizplaces } from '@things-factory/biz-base'
|
|
2
|
-
import { FulfillmentAPI, FulfillmentCenter } from '@things-factory/integration-fulfillment'
|
|
3
|
-
import {
|
|
4
|
-
MarketplaceOrder,
|
|
5
|
-
MarketplaceOrderItem,
|
|
6
|
-
MarketplaceOrderShipping,
|
|
7
|
-
MarketplaceOrderShippingItem
|
|
8
|
-
} from '@things-factory/marketplace-base'
|
|
9
|
-
import { Product, ProductBundle } from '@things-factory/product-base'
|
|
10
|
-
import { Domain, getRepository } from '@things-factory/shell'
|
|
11
|
-
|
|
12
|
-
export const addReleaseOrderResolver = {
|
|
13
|
-
async addReleaseOrder(
|
|
14
|
-
_: void,
|
|
15
|
-
{ marketplaceOrderIds, warehouseId }: { marketplaceOrderIds: any; warehouseId: string },
|
|
16
|
-
context: any
|
|
17
|
-
): Promise<void> {
|
|
18
|
-
const { domain } = context.state
|
|
19
|
-
|
|
20
|
-
const fulfilmentCenter: FulfillmentCenter = await FulfillmentAPI.getFulfillmentCenter(warehouseId)
|
|
21
|
-
const centerId: string = fulfilmentCenter.centerId
|
|
22
|
-
|
|
23
|
-
var warehouseDomain: Domain = await getRepository(Domain).findOne({ where: { subdomain: centerId } })
|
|
24
|
-
var customerBizplaces: Bizplace[] = await getCustomerBizplaces(warehouseDomain)
|
|
25
|
-
|
|
26
|
-
const customerBizplaceId: string = customerBizplaces.find(
|
|
27
|
-
customerBizplace => customerBizplace.company.domain.id === domain.id
|
|
28
|
-
).id
|
|
29
|
-
|
|
30
|
-
for (var i = 0; i < marketplaceOrderIds.length; i++) {
|
|
31
|
-
const marketplaceOrderId = marketplaceOrderIds[i]
|
|
32
|
-
|
|
33
|
-
const marketplaceOrder: MarketplaceOrder = await getRepository(MarketplaceOrder).findOne({
|
|
34
|
-
where: {
|
|
35
|
-
id: marketplaceOrderId
|
|
36
|
-
},
|
|
37
|
-
relations: [
|
|
38
|
-
'marketplaceOrderItems',
|
|
39
|
-
'marketplaceOrderItems.marketplaceProductVariation',
|
|
40
|
-
'marketplaceOrderItems.marketplaceOrderShippingItems',
|
|
41
|
-
'marketplaceOrderItems.marketplaceOrderShippingItems.marketplaceOrderShipping',
|
|
42
|
-
'marketplaceStore'
|
|
43
|
-
]
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
const marketplaceOrderItems: MarketplaceOrderItem[] = marketplaceOrder.marketplaceOrderItems
|
|
47
|
-
|
|
48
|
-
let marketplaceOrderShippings: MarketplaceOrderShipping[] = await getRepository(MarketplaceOrderShipping).find({
|
|
49
|
-
where: { orderNoRef: marketplaceOrder.orderNo, domain: { id: domain.id } },
|
|
50
|
-
order: { subOrderNoRef: 'ASC' },
|
|
51
|
-
relations: [
|
|
52
|
-
'marketplaceOrderShippingItems',
|
|
53
|
-
'marketplaceOrderShippingItems.marketplaceOrderItem',
|
|
54
|
-
'marketplaceOrderShippingItems.product'
|
|
55
|
-
]
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
for (let j = 0; j < marketplaceOrderShippings.length; j++) {
|
|
59
|
-
let marketplaceOrderShipping: MarketplaceOrderShipping = marketplaceOrderShippings[j]
|
|
60
|
-
let marketplaceOrderShippingItems: MarketplaceOrderShippingItem[] =
|
|
61
|
-
marketplaceOrderShipping.marketplaceOrderShippingItems
|
|
62
|
-
|
|
63
|
-
if (!marketplaceOrderShipping?.releaseOrderId) {
|
|
64
|
-
const date: Date = new Date()
|
|
65
|
-
const releaseDate = `${date.getFullYear()}-${(date.getMonth() + 1).toString().padStart(2, '0')}-${date
|
|
66
|
-
.getDate()
|
|
67
|
-
.toString()
|
|
68
|
-
.padStart(2, '0')}`
|
|
69
|
-
|
|
70
|
-
var newReleaseOrder: any = {
|
|
71
|
-
releaseDate,
|
|
72
|
-
type: 'b2c',
|
|
73
|
-
transporter: marketplaceOrder.shippingProvider,
|
|
74
|
-
trackingNo: marketplaceOrderShipping?.ownTrackingNo
|
|
75
|
-
? marketplaceOrderShipping.ownTrackingNo
|
|
76
|
-
: marketplaceOrderShipping.trackingNo,
|
|
77
|
-
packingOption: true,
|
|
78
|
-
exportOption: false,
|
|
79
|
-
ownTransport: true,
|
|
80
|
-
courierOption: true,
|
|
81
|
-
collectionOrderNo: marketplaceOrder.orderNo,
|
|
82
|
-
refNo: marketplaceOrder.orderNo,
|
|
83
|
-
refNo2:
|
|
84
|
-
marketplaceOrderShippings.length > 1 ? marketplaceOrderShipping?.subOrderNoRef : marketplaceOrder.orderNo,
|
|
85
|
-
deliverTo: {
|
|
86
|
-
deliveryAddress1: marketplaceOrderShipping.address1,
|
|
87
|
-
deliveryAddress2: marketplaceOrderShipping.address2,
|
|
88
|
-
deliveryAddress3: marketplaceOrderShipping.address3,
|
|
89
|
-
deliveryAddress4: marketplaceOrderShipping.address4,
|
|
90
|
-
deliveryAddress5: marketplaceOrderShipping.address5,
|
|
91
|
-
attentionTo: marketplaceOrderShipping.attentionTo,
|
|
92
|
-
city: marketplaceOrderShipping.city,
|
|
93
|
-
postalCode: marketplaceOrderShipping.postCode,
|
|
94
|
-
country: marketplaceOrderShipping.country,
|
|
95
|
-
state: marketplaceOrderShipping.state,
|
|
96
|
-
phone1: marketplaceOrderShipping.phone1,
|
|
97
|
-
phone2: marketplaceOrderShipping?.phone2 ? marketplaceOrderShipping.phone2 : null
|
|
98
|
-
},
|
|
99
|
-
marketplaceOrderStatus: marketplaceOrder.status,
|
|
100
|
-
airwayBill: marketplaceOrderShipping?.airwayBill ? marketplaceOrderShipping.airwayBill : null,
|
|
101
|
-
invoice: marketplaceOrderShipping?.invoice ? marketplaceOrderShipping.invoice : null,
|
|
102
|
-
orderInventories: marketplaceOrderShippingItems.map(marketplaceOrderShippingItem => {
|
|
103
|
-
return {
|
|
104
|
-
product: {
|
|
105
|
-
sku: marketplaceOrderShippingItem.product.sku
|
|
106
|
-
},
|
|
107
|
-
releaseQty: marketplaceOrderShippingItem.qty
|
|
108
|
-
}
|
|
109
|
-
})
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
try {
|
|
113
|
-
var releaseOrder: any = await FulfillmentAPI.createOutboundOrder(fulfilmentCenter, {
|
|
114
|
-
customerBizplaceId,
|
|
115
|
-
releaseOrder: newReleaseOrder
|
|
116
|
-
})
|
|
117
|
-
|
|
118
|
-
marketplaceOrderShipping.releaseOrderId = releaseOrder.id
|
|
119
|
-
marketplaceOrderShipping.fulfillmentCenter = fulfilmentCenter
|
|
120
|
-
await getRepository(MarketplaceOrderShipping).save(marketplaceOrderShipping)
|
|
121
|
-
|
|
122
|
-
if (releaseOrder && releaseOrder?.id) {
|
|
123
|
-
marketplaceOrder.releaseOrderId = releaseOrder.id
|
|
124
|
-
marketplaceOrder.fulfillmentCenter = fulfilmentCenter
|
|
125
|
-
await getRepository(MarketplaceOrder).save(marketplaceOrder)
|
|
126
|
-
}
|
|
127
|
-
} catch (e) {}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
var invoiceProducts = await Promise.all(
|
|
132
|
-
marketplaceOrderItems.map(async mi => {
|
|
133
|
-
let product: Product = await getRepository(Product).findOne({
|
|
134
|
-
where: { domain: { id: domain.id }, sku: mi.marketplaceProductVariation.sku }
|
|
135
|
-
})
|
|
136
|
-
|
|
137
|
-
let productBundle: ProductBundle
|
|
138
|
-
if (!product) {
|
|
139
|
-
productBundle = await getRepository(ProductBundle).findOne({
|
|
140
|
-
where: { domain: { id: domain.id }, sku: mi.marketplaceProductVariation.sku }
|
|
141
|
-
})
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
return {
|
|
145
|
-
sku: product ? product.sku : productBundle.sku,
|
|
146
|
-
name: product ? product.name : productBundle.name,
|
|
147
|
-
description: product ? product.description : productBundle.description,
|
|
148
|
-
qty: mi.qty,
|
|
149
|
-
unitPrice: (mi?.originalPrice || 0) / mi.qty,
|
|
150
|
-
paidPrice: (mi?.paidPrice || 0) / mi.qty,
|
|
151
|
-
discount: mi?.discount || 0,
|
|
152
|
-
shippingFeePaidByCustomer: mi?.shippingFeePaidByCustomer || 0
|
|
153
|
-
}
|
|
154
|
-
})
|
|
155
|
-
)
|
|
156
|
-
|
|
157
|
-
let newInvoice = {
|
|
158
|
-
invoiceProducts,
|
|
159
|
-
name: '-',
|
|
160
|
-
refNo1: newReleaseOrder.refNo.toString(),
|
|
161
|
-
refNo2: newReleaseOrder.refNo2.toString(),
|
|
162
|
-
issuedOn: new Date(),
|
|
163
|
-
from: marketplaceOrder.marketplaceStore.storeName,
|
|
164
|
-
fromContactPhone: '-',
|
|
165
|
-
fromAddress1: '-',
|
|
166
|
-
fromAddress2: null,
|
|
167
|
-
fromAddress3: null,
|
|
168
|
-
fromAddress4: null,
|
|
169
|
-
fromAddress5: null,
|
|
170
|
-
fromPostcode: null,
|
|
171
|
-
fromCity: null,
|
|
172
|
-
fromState: null,
|
|
173
|
-
fromCountry: null,
|
|
174
|
-
deliverTo: newReleaseOrder.deliverTo.attentionTo || '-',
|
|
175
|
-
deliverToPhone: newReleaseOrder.deliverTo.phone1 || '-',
|
|
176
|
-
deliveryAddress1: newReleaseOrder.deliverTo.deliveryAddress1 || '-',
|
|
177
|
-
deliveryAddress2: newReleaseOrder.deliverTo.deliveryAddress2,
|
|
178
|
-
deliveryAddress3: newReleaseOrder.deliverTo.deliveryAddress3,
|
|
179
|
-
deliveryAddress4: newReleaseOrder.deliverTo.deliveryAddress4,
|
|
180
|
-
deliveryAddress5: newReleaseOrder.deliverTo.deliveryAddress5,
|
|
181
|
-
deliveryPostcode: newReleaseOrder.deliverTo.postalCode || '-',
|
|
182
|
-
deliveryCity: newReleaseOrder.deliverTo.city || '-',
|
|
183
|
-
deliveryState: newReleaseOrder.deliverTo.state || '-',
|
|
184
|
-
deliveryCountry: newReleaseOrder.deliverTo.country || '-',
|
|
185
|
-
billTo: newReleaseOrder.deliverTo.attentionTo || '-',
|
|
186
|
-
billToPhone: newReleaseOrder.deliverTo.phone1 || '-',
|
|
187
|
-
billingAddress1: newReleaseOrder.deliverTo.billingAddress || newReleaseOrder.deliverTo.deliveryAddress1 || '-',
|
|
188
|
-
billingAddress2: null,
|
|
189
|
-
billingAddress3: null,
|
|
190
|
-
billingAddress4: null,
|
|
191
|
-
billingAddress5: null,
|
|
192
|
-
billingPostcode: '-',
|
|
193
|
-
billingCity: '-',
|
|
194
|
-
billingState: '-',
|
|
195
|
-
billingCountry: '-'
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
try {
|
|
199
|
-
await FulfillmentAPI.createSalesInvoice(fulfilmentCenter, {
|
|
200
|
-
customerBizplaceId,
|
|
201
|
-
invoice: newInvoice
|
|
202
|
-
})
|
|
203
|
-
} catch (e) {}
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
}
|
|
@@ -1,209 +0,0 @@
|
|
|
1
|
-
import { createQueryBuilder, SelectQueryBuilder } from 'typeorm'
|
|
2
|
-
|
|
3
|
-
import { Bizplace, getCustomerBizplaces } from '@things-factory/biz-base'
|
|
4
|
-
import { FulfillmentAPI } from '@things-factory/integration-fulfillment'
|
|
5
|
-
import {
|
|
6
|
-
MarketplaceOrder,
|
|
7
|
-
MarketplaceOrderItem,
|
|
8
|
-
MarketplaceOrderShipping,
|
|
9
|
-
MarketplaceOrderShippingItem
|
|
10
|
-
} from '@things-factory/marketplace-base'
|
|
11
|
-
import { Product, ProductBundle } from '@things-factory/product-base'
|
|
12
|
-
import { Domain, getRepository } from '@things-factory/shell'
|
|
13
|
-
|
|
14
|
-
export const autoAddReleaseOrderResolver = {
|
|
15
|
-
async autoAddReleaseOrder(
|
|
16
|
-
_: void,
|
|
17
|
-
{ warehouseId }: { warehouseId: string },
|
|
18
|
-
context: ResolverContext
|
|
19
|
-
): Promise<void> {
|
|
20
|
-
const { domain } = context.state
|
|
21
|
-
|
|
22
|
-
const qb: SelectQueryBuilder<MarketplaceOrder> = createQueryBuilder(MarketplaceOrder, 'MO')
|
|
23
|
-
const marketplaceOrders: MarketplaceOrder[] = await qb
|
|
24
|
-
.leftJoinAndSelect('MO.marketplaceOrderItems', 'MOI')
|
|
25
|
-
.leftJoinAndSelect('MOI.marketplaceOrderShippingItems', 'MOSI')
|
|
26
|
-
.leftJoinAndSelect('MOSI.marketplaceOrderShipping', 'MOS')
|
|
27
|
-
.leftJoinAndSelect('MOI.marketplaceProductVariation', 'MPV')
|
|
28
|
-
.leftJoinAndSelect('MO.marketplaceStore', 'MPS')
|
|
29
|
-
.where('MO.domain = :domainId', { domainId: domain.id })
|
|
30
|
-
.andWhere('MO.releaseOrderId IS NULL')
|
|
31
|
-
.andWhere('MO.status IN (:...status)', {
|
|
32
|
-
status: ['ready_to_ship', 'unfulfilled', 'packed', 'processing']
|
|
33
|
-
})
|
|
34
|
-
.andWhere('MPS.status = :marketplaceStatus', { marketplaceStatus: 'ACTIVE' })
|
|
35
|
-
.getMany()
|
|
36
|
-
|
|
37
|
-
var fulfilmentCenter = await FulfillmentAPI.getFulfillmentCenter(warehouseId)
|
|
38
|
-
var centerId: string = fulfilmentCenter.centerId
|
|
39
|
-
|
|
40
|
-
var warehouseDomain: Domain = await getRepository(Domain).findOne({ where: { subdomain: centerId } })
|
|
41
|
-
var customerBizplaces: Bizplace[] = await getCustomerBizplaces(warehouseDomain)
|
|
42
|
-
const customerBizplaceId: string = customerBizplaces.find(
|
|
43
|
-
customerBizplace => customerBizplace.company.domain.id === domain.id
|
|
44
|
-
).id
|
|
45
|
-
|
|
46
|
-
for (var i = 0; i < marketplaceOrders.length; i++) {
|
|
47
|
-
const marketplaceOrder = marketplaceOrders[i]
|
|
48
|
-
|
|
49
|
-
const marketplaceOrderItems: MarketplaceOrderItem[] = marketplaceOrder.marketplaceOrderItems
|
|
50
|
-
|
|
51
|
-
const marketplaceOrderShippings: MarketplaceOrderShipping[] = await getRepository(MarketplaceOrderShipping).find({
|
|
52
|
-
where: { orderNoRef: marketplaceOrder.orderNo, domain: { id: domain.id } },
|
|
53
|
-
order: { subOrderNoRef: 'ASC' },
|
|
54
|
-
relations: [
|
|
55
|
-
'marketplaceOrderShippingItems',
|
|
56
|
-
'marketplaceOrderShippingItems.marketplaceOrderItem',
|
|
57
|
-
'marketplaceOrderShippingItems.product'
|
|
58
|
-
]
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
for (let j = 0; j < marketplaceOrderShippings.length; j++) {
|
|
62
|
-
let marketplaceOrderShipping: MarketplaceOrderShipping = marketplaceOrderShippings[j]
|
|
63
|
-
let marketplaceOrderShippingItems: MarketplaceOrderShippingItem[] =
|
|
64
|
-
marketplaceOrderShipping.marketplaceOrderShippingItems
|
|
65
|
-
|
|
66
|
-
if (!marketplaceOrderShipping?.releaseOrderId) {
|
|
67
|
-
const date: Date = new Date()
|
|
68
|
-
const releaseDate = `${date.getFullYear()}-${(date.getMonth() + 1).toString().padStart(2, '0')}-${date
|
|
69
|
-
.getDate()
|
|
70
|
-
.toString()
|
|
71
|
-
.padStart(2, '0')}`
|
|
72
|
-
|
|
73
|
-
var newReleaseOrder: any = {
|
|
74
|
-
releaseDate,
|
|
75
|
-
type: 'b2c',
|
|
76
|
-
transporter: marketplaceOrder.shippingProvider,
|
|
77
|
-
trackingNo: marketplaceOrderShipping?.ownTrackingNo
|
|
78
|
-
? marketplaceOrderShipping.ownTrackingNo
|
|
79
|
-
: marketplaceOrderShipping.trackingNo,
|
|
80
|
-
packingOption: true,
|
|
81
|
-
exportOption: false,
|
|
82
|
-
ownTransport: true,
|
|
83
|
-
courierOption: true,
|
|
84
|
-
collectionOrderNo: marketplaceOrder.orderNo,
|
|
85
|
-
refNo: marketplaceOrder.orderNo,
|
|
86
|
-
refNo2:
|
|
87
|
-
marketplaceOrderShippings.length > 1 ? marketplaceOrderShipping?.subOrderNoRef : marketplaceOrder.orderNo,
|
|
88
|
-
deliverTo: {
|
|
89
|
-
deliveryAddress1: marketplaceOrderShipping.address1,
|
|
90
|
-
deliveryAddress2: marketplaceOrderShipping.address2,
|
|
91
|
-
deliveryAddress3: marketplaceOrderShipping.address3,
|
|
92
|
-
deliveryAddress4: marketplaceOrderShipping.address4,
|
|
93
|
-
deliveryAddress5: marketplaceOrderShipping.address5,
|
|
94
|
-
attentionTo: marketplaceOrderShipping.attentionTo,
|
|
95
|
-
city: marketplaceOrderShipping.city,
|
|
96
|
-
postalCode: marketplaceOrderShipping.postCode,
|
|
97
|
-
country: marketplaceOrderShipping.country,
|
|
98
|
-
state: marketplaceOrderShipping.state,
|
|
99
|
-
phone1: marketplaceOrderShipping.phone1,
|
|
100
|
-
phone2: marketplaceOrderShipping?.phone2 ? marketplaceOrderShipping.phone2 : null
|
|
101
|
-
},
|
|
102
|
-
marketplaceOrderStatus: marketplaceOrder.status,
|
|
103
|
-
airwayBill: marketplaceOrderShipping?.airwayBill ? marketplaceOrderShipping.airwayBill : null,
|
|
104
|
-
invoice: marketplaceOrderShipping?.invoice ? marketplaceOrderShipping.invoice : null,
|
|
105
|
-
orderInventories: marketplaceOrderShippingItems.map(marketplaceOrderShippingItem => {
|
|
106
|
-
return {
|
|
107
|
-
product: {
|
|
108
|
-
sku: marketplaceOrderShippingItem.product.sku
|
|
109
|
-
},
|
|
110
|
-
releaseQty: marketplaceOrderShippingItem.qty
|
|
111
|
-
}
|
|
112
|
-
})
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
try {
|
|
116
|
-
var releaseOrder: any = await FulfillmentAPI.createOutboundOrder(fulfilmentCenter, {
|
|
117
|
-
customerBizplaceId,
|
|
118
|
-
releaseOrder: newReleaseOrder
|
|
119
|
-
})
|
|
120
|
-
|
|
121
|
-
marketplaceOrderShipping.releaseOrderId = releaseOrder.id
|
|
122
|
-
marketplaceOrderShipping.fulfillmentCenter = fulfilmentCenter
|
|
123
|
-
await getRepository(MarketplaceOrderShipping).save(marketplaceOrderShipping)
|
|
124
|
-
|
|
125
|
-
if (releaseOrder && releaseOrder?.id) {
|
|
126
|
-
marketplaceOrder.releaseOrderId = releaseOrder.id
|
|
127
|
-
marketplaceOrder.fulfillmentCenter = fulfilmentCenter
|
|
128
|
-
await getRepository(MarketplaceOrder).save(marketplaceOrder)
|
|
129
|
-
}
|
|
130
|
-
} catch (e) {}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
var invoiceProducts = await Promise.all(
|
|
135
|
-
marketplaceOrderItems.map(async mi => {
|
|
136
|
-
let product: Product = await getRepository(Product).findOne({
|
|
137
|
-
where: { domain: { id: domain.id }, sku: mi.marketplaceProductVariation.sku }
|
|
138
|
-
})
|
|
139
|
-
|
|
140
|
-
let productBundle: ProductBundle
|
|
141
|
-
if (!product) {
|
|
142
|
-
productBundle = await getRepository(ProductBundle).findOne({
|
|
143
|
-
where: { domain: { id: domain.id }, sku: mi.marketplaceProductVariation.sku }
|
|
144
|
-
})
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
return {
|
|
148
|
-
sku: product ? product.sku : productBundle.sku,
|
|
149
|
-
name: product ? product.name : productBundle.name,
|
|
150
|
-
description: product ? product.description : productBundle.description,
|
|
151
|
-
qty: mi.qty,
|
|
152
|
-
unitPrice: (mi?.originalPrice || 0) / mi.qty,
|
|
153
|
-
paidPrice: (mi?.paidPrice || 0) / mi.qty,
|
|
154
|
-
discount: mi?.discount || 0,
|
|
155
|
-
shippingFeePaidByCustomer: mi?.shippingFeePaidByCustomer || 0
|
|
156
|
-
}
|
|
157
|
-
})
|
|
158
|
-
)
|
|
159
|
-
|
|
160
|
-
let newInvoice = {
|
|
161
|
-
invoiceProducts,
|
|
162
|
-
name: '-',
|
|
163
|
-
refNo1: newReleaseOrder.refNo.toString(),
|
|
164
|
-
refNo2: newReleaseOrder.refNo2.toString(),
|
|
165
|
-
issuedOn: new Date(),
|
|
166
|
-
from: marketplaceOrder.marketplaceStore.storeName,
|
|
167
|
-
fromContactPhone: '-',
|
|
168
|
-
fromAddress1: '-',
|
|
169
|
-
fromAddress2: null,
|
|
170
|
-
fromAddress3: null,
|
|
171
|
-
fromAddress4: null,
|
|
172
|
-
fromAddress5: null,
|
|
173
|
-
fromPostcode: null,
|
|
174
|
-
fromCity: null,
|
|
175
|
-
fromState: null,
|
|
176
|
-
fromCountry: null,
|
|
177
|
-
deliverTo: newReleaseOrder.deliverTo.attentionTo || '-',
|
|
178
|
-
deliverToPhone: newReleaseOrder.deliverTo.phone1 || '-',
|
|
179
|
-
deliveryAddress1: newReleaseOrder.deliverTo.deliveryAddress1 || '-',
|
|
180
|
-
deliveryAddress2: newReleaseOrder.deliverTo.deliveryAddress2,
|
|
181
|
-
deliveryAddress3: newReleaseOrder.deliverTo.deliveryAddress3,
|
|
182
|
-
deliveryAddress4: newReleaseOrder.deliverTo.deliveryAddress4,
|
|
183
|
-
deliveryAddress5: newReleaseOrder.deliverTo.deliveryAddress5,
|
|
184
|
-
deliveryPostcode: newReleaseOrder.deliverTo.postalCode || '-',
|
|
185
|
-
deliveryCity: newReleaseOrder.deliverTo.city || '-',
|
|
186
|
-
deliveryState: newReleaseOrder.deliverTo.state || '-',
|
|
187
|
-
deliveryCountry: newReleaseOrder.deliverTo.country || '-',
|
|
188
|
-
billTo: newReleaseOrder.deliverTo.attentionTo || '-',
|
|
189
|
-
billToPhone: newReleaseOrder.deliverTo.phone1 || '-',
|
|
190
|
-
billingAddress1: newReleaseOrder.deliverTo.billingAddress || newReleaseOrder.deliverTo.deliveryAddress1 || '-',
|
|
191
|
-
billingAddress2: null,
|
|
192
|
-
billingAddress3: null,
|
|
193
|
-
billingAddress4: null,
|
|
194
|
-
billingAddress5: null,
|
|
195
|
-
billingPostcode: '-',
|
|
196
|
-
billingCity: '-',
|
|
197
|
-
billingState: '-',
|
|
198
|
-
billingCountry: '-'
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
try {
|
|
202
|
-
await FulfillmentAPI.createSalesInvoice(fulfilmentCenter, {
|
|
203
|
-
customerBizplaceId,
|
|
204
|
-
invoice: newInvoice
|
|
205
|
-
})
|
|
206
|
-
} catch (e) {}
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
}
|