@things-factory/worksheet-base 4.3.130 → 4.3.132
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-server/controllers/outbound/loading-worksheet-controller.js +8 -1
- package/dist-server/controllers/outbound/loading-worksheet-controller.js.map +1 -1
- package/dist-server/controllers/outbound/packing-worksheet-controller.js +27 -12
- package/dist-server/controllers/outbound/packing-worksheet-controller.js.map +1 -1
- package/dist-server/controllers/pos/index.js +18 -0
- package/dist-server/controllers/pos/index.js.map +1 -0
- package/dist-server/controllers/pos/xilnex-controller.js +183 -0
- package/dist-server/controllers/pos/xilnex-controller.js.map +1 -0
- package/dist-server/graphql/resolvers/worksheet/confirm-cancellation-release-order.js +33 -35
- package/dist-server/graphql/resolvers/worksheet/confirm-cancellation-release-order.js.map +1 -1
- package/dist-server/graphql/resolvers/worksheet/loading/complete-loading.js +11 -0
- package/dist-server/graphql/resolvers/worksheet/loading/complete-loading.js.map +1 -1
- package/dist-server/graphql/resolvers/worksheet/packing/complete-packing.js +22 -0
- package/dist-server/graphql/resolvers/worksheet/packing/complete-packing.js.map +1 -1
- package/dist-server/graphql/resolvers/worksheet/picking/complete-batch-picking.js +22 -15
- package/dist-server/graphql/resolvers/worksheet/picking/complete-batch-picking.js.map +1 -1
- package/dist-server/graphql/resolvers/worksheet/picking/complete-picking.js +45 -48
- package/dist-server/graphql/resolvers/worksheet/picking/complete-picking.js.map +1 -1
- package/dist-server/graphql/resolvers/worksheet/unloading/complete-unloading-partially.js +13 -0
- package/dist-server/graphql/resolvers/worksheet/unloading/complete-unloading-partially.js.map +1 -1
- package/dist-server/graphql/resolvers/worksheet/unloading/complete-unloading.js +11 -0
- package/dist-server/graphql/resolvers/worksheet/unloading/complete-unloading.js.map +1 -1
- package/package.json +18 -19
- package/server/controllers/outbound/loading-worksheet-controller.ts +11 -4
- package/server/controllers/outbound/packing-worksheet-controller.ts +34 -19
- package/server/controllers/pos/index.ts +1 -0
- package/server/controllers/pos/xilnex-controller.ts +218 -0
- package/server/graphql/resolvers/worksheet/confirm-cancellation-release-order.ts +34 -38
- package/server/graphql/resolvers/worksheet/loading/complete-loading.ts +14 -0
- package/server/graphql/resolvers/worksheet/packing/complete-packing.ts +24 -0
- package/server/graphql/resolvers/worksheet/picking/complete-batch-picking.ts +25 -19
- package/server/graphql/resolvers/worksheet/picking/complete-picking.ts +50 -52
- package/server/graphql/resolvers/worksheet/unloading/complete-unloading-partially.ts +19 -1
- package/server/graphql/resolvers/worksheet/unloading/complete-unloading.ts +14 -0
- package/LICENSE.md +0 -21
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import { EntityManager } from 'typeorm'
|
|
2
|
+
|
|
3
|
+
import { logger } from '@things-factory/env'
|
|
4
|
+
import { Accounting, AccountingAPI } from '@things-factory/integration-accounting'
|
|
5
|
+
import {
|
|
6
|
+
ArrivalNotice,
|
|
7
|
+
DeliveryOrder,
|
|
8
|
+
ORDER_SOURCE_TYPE,
|
|
9
|
+
OrderInventory,
|
|
10
|
+
ReleaseGood
|
|
11
|
+
} from '@things-factory/sales-base'
|
|
12
|
+
import { Inventory } from '@things-factory/warehouse-base'
|
|
13
|
+
|
|
14
|
+
import { WorksheetDetail } from '../../entities'
|
|
15
|
+
import { WorksheetController } from '../worksheet-controller'
|
|
16
|
+
|
|
17
|
+
export class XilnexController extends WorksheetController {
|
|
18
|
+
async createInboundDocument(
|
|
19
|
+
tx: EntityManager,
|
|
20
|
+
xilnex: Accounting,
|
|
21
|
+
arrivalNoticeId: string,
|
|
22
|
+
inventoryIds: string[]
|
|
23
|
+
): Promise<void> {
|
|
24
|
+
try {
|
|
25
|
+
const arrivalNotice: ArrivalNotice = await tx.getRepository(ArrivalNotice).findOne({
|
|
26
|
+
where: { id: arrivalNoticeId },
|
|
27
|
+
relations: ['domain', 'bizplace', 'bizplace.domain']
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
let qb = tx
|
|
31
|
+
.getRepository(Inventory)
|
|
32
|
+
.createQueryBuilder('iv')
|
|
33
|
+
.select('p.sku', 'productSku')
|
|
34
|
+
.addSelect('SUM(COALESCE(iv.qty,0))', 'totalQty')
|
|
35
|
+
.addSelect('SUM(COALESCE(iv.unit_cost,0))', 'unitCost')
|
|
36
|
+
.innerJoin('iv.location', 'loc')
|
|
37
|
+
.innerJoin('iv.product', 'p')
|
|
38
|
+
.where('"iv"."id" IN (:...inventoryIds)')
|
|
39
|
+
.groupBy('iv.product_id')
|
|
40
|
+
.addGroupBy('p.sku')
|
|
41
|
+
.setParameters({
|
|
42
|
+
inventoryIds: inventoryIds
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
let qbResult: any = await qb.getRawMany()
|
|
46
|
+
let orderProducts: any[] = qbResult.map(item => {
|
|
47
|
+
return {
|
|
48
|
+
product: {
|
|
49
|
+
sku: item.productSku
|
|
50
|
+
},
|
|
51
|
+
actualPackQty: item.totalQty,
|
|
52
|
+
unitPrice: item.unitCost
|
|
53
|
+
}
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
const orderSourceType: string = arrivalNotice.orderSourceType
|
|
57
|
+
switch (orderSourceType) {
|
|
58
|
+
case ORDER_SOURCE_TYPE.XILNEX_PO:
|
|
59
|
+
await AccountingAPI.createPurchaseReceive(xilnex, {
|
|
60
|
+
arrivalNotice,
|
|
61
|
+
orderProducts: orderProducts
|
|
62
|
+
})
|
|
63
|
+
break
|
|
64
|
+
|
|
65
|
+
case ORDER_SOURCE_TYPE.XILNEX_TRANSFER_NOTE:
|
|
66
|
+
await AccountingAPI.createGoodsReceivedNote(xilnex, {
|
|
67
|
+
arrivalNotice,
|
|
68
|
+
orderProducts: orderProducts
|
|
69
|
+
})
|
|
70
|
+
break
|
|
71
|
+
|
|
72
|
+
default:
|
|
73
|
+
break
|
|
74
|
+
}
|
|
75
|
+
} catch (error) {
|
|
76
|
+
logger.error(`xilnex-controller[createInboundDocument]: ${error}`)
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async createPartialUnloadInboundDocument(
|
|
81
|
+
tx: EntityManager,
|
|
82
|
+
xilnex: Accounting,
|
|
83
|
+
arrivalNotice: ArrivalNotice,
|
|
84
|
+
worksheetDetails: any[]
|
|
85
|
+
): Promise<void> {
|
|
86
|
+
try {
|
|
87
|
+
let orderProducts: any[] = []
|
|
88
|
+
await Promise.all(
|
|
89
|
+
worksheetDetails.map(async wd => {
|
|
90
|
+
let worksheetDetail: WorksheetDetail = await tx.getRepository(WorksheetDetail).findOne({
|
|
91
|
+
where: { name: wd.name, domain: arrivalNotice.domain, bizplace: arrivalNotice.bizplace },
|
|
92
|
+
relations: ['targetProduct', 'targetProduct.product']
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
orderProducts.push({
|
|
96
|
+
product: {
|
|
97
|
+
sku: worksheetDetail.targetProduct.product.sku
|
|
98
|
+
},
|
|
99
|
+
actualPackQty: wd.actualPackQty,
|
|
100
|
+
unitPrice: worksheetDetail.targetProduct.unitPrice
|
|
101
|
+
})
|
|
102
|
+
})
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
const orderSourceType: string = arrivalNotice.orderSourceType
|
|
106
|
+
switch (orderSourceType) {
|
|
107
|
+
case ORDER_SOURCE_TYPE.XILNEX_PO:
|
|
108
|
+
await AccountingAPI.createPurchaseReceive(xilnex, {
|
|
109
|
+
arrivalNotice,
|
|
110
|
+
orderProducts: orderProducts
|
|
111
|
+
})
|
|
112
|
+
break
|
|
113
|
+
|
|
114
|
+
case ORDER_SOURCE_TYPE.XILNEX_TRANSFER_NOTE:
|
|
115
|
+
await AccountingAPI.createGoodsReceivedNote(xilnex, {
|
|
116
|
+
arrivalNotice,
|
|
117
|
+
orderProducts: orderProducts
|
|
118
|
+
})
|
|
119
|
+
break
|
|
120
|
+
|
|
121
|
+
default:
|
|
122
|
+
break
|
|
123
|
+
}
|
|
124
|
+
} catch (error) {
|
|
125
|
+
logger.error(`xilnex-controller[createInboundDocument]: ${error}`)
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
async deliveryTransferNote(tx: EntityManager, xilnex: Accounting, releaseGoodId: string): Promise<void> {
|
|
130
|
+
try {
|
|
131
|
+
const releaseGood: ReleaseGood = await tx.getRepository(ReleaseGood).findOne({
|
|
132
|
+
where: { id: releaseGoodId },
|
|
133
|
+
relations: ['domain', 'bizplace', 'bizplace.domain', 'deliveryOrders']
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
let deliveryOrders: DeliveryOrder[] = releaseGood.deliveryOrders
|
|
137
|
+
await Promise.all(
|
|
138
|
+
deliveryOrders.map(async deliveryOrder => {
|
|
139
|
+
let qb = tx
|
|
140
|
+
.getRepository(OrderInventory)
|
|
141
|
+
.createQueryBuilder('oi')
|
|
142
|
+
.select('op.ref_item_id', 'refItemId')
|
|
143
|
+
.addSelect('SUM(COALESCE(oi.release_qty,0))', 'totalReleaseQty')
|
|
144
|
+
.leftJoin('oi.order_product', 'op')
|
|
145
|
+
.where('"oi"."delivery_order_id" = :deliveryOrderId')
|
|
146
|
+
.andWhere('"oi"."domain_id" = :domainId')
|
|
147
|
+
.andWhere('"oi"."bizplace_id" = :bizplaceId')
|
|
148
|
+
.groupBy('op.ref_item_id')
|
|
149
|
+
.setParameters({
|
|
150
|
+
deliveryOrderId: deliveryOrder.id,
|
|
151
|
+
domainId: releaseGood.domain.id,
|
|
152
|
+
bizplaceId: releaseGood.bizplace.id
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
let qbResult: any = await qb.getRawMany()
|
|
156
|
+
let orderProducts: any[] = qbResult.map(item => {
|
|
157
|
+
return {
|
|
158
|
+
refItemId: item.refItemId,
|
|
159
|
+
releaseQty: item.totalReleaseQty
|
|
160
|
+
}
|
|
161
|
+
})
|
|
162
|
+
|
|
163
|
+
await AccountingAPI.deliveryTransferNote(xilnex, {
|
|
164
|
+
releaseGood,
|
|
165
|
+
orderProducts: orderProducts
|
|
166
|
+
})
|
|
167
|
+
})
|
|
168
|
+
)
|
|
169
|
+
} catch (error) {
|
|
170
|
+
logger.error(`xilnex-controller[createShipment]: ${error}`)
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
async createShipment(tx: EntityManager, xilnex: Accounting, releaseGoodId: string): Promise<void> {
|
|
175
|
+
try {
|
|
176
|
+
const releaseGood: ReleaseGood = await tx.getRepository(ReleaseGood).findOne({
|
|
177
|
+
where: { id: releaseGoodId },
|
|
178
|
+
relations: ['domain', 'bizplace', 'bizplace.domain', 'deliveryOrders']
|
|
179
|
+
})
|
|
180
|
+
|
|
181
|
+
let deliveryOrders: DeliveryOrder[] = releaseGood.deliveryOrders
|
|
182
|
+
await Promise.all(
|
|
183
|
+
deliveryOrders.map(async deliveryOrder => {
|
|
184
|
+
let qb = tx
|
|
185
|
+
.getRepository(OrderInventory)
|
|
186
|
+
.createQueryBuilder('oi')
|
|
187
|
+
.select('op.ref_item_id', 'refItemId')
|
|
188
|
+
.addSelect('SUM(COALESCE(oi.release_qty,0))', 'totalReleaseQty')
|
|
189
|
+
.leftJoin('oi.order_product', 'op')
|
|
190
|
+
.where('"oi"."delivery_order_id" = :deliveryOrderId')
|
|
191
|
+
.andWhere('"oi"."domain_id" = :domainId')
|
|
192
|
+
.andWhere('"oi"."bizplace_id" = :bizplaceId')
|
|
193
|
+
.groupBy('op.ref_item_id')
|
|
194
|
+
.setParameters({
|
|
195
|
+
deliveryOrderId: deliveryOrder.id,
|
|
196
|
+
domainId: releaseGood.domain.id,
|
|
197
|
+
bizplaceId: releaseGood.bizplace.id
|
|
198
|
+
})
|
|
199
|
+
|
|
200
|
+
let qbResult: any = await qb.getRawMany()
|
|
201
|
+
let orderProducts: any[] = qbResult.map(item => {
|
|
202
|
+
return {
|
|
203
|
+
refItemId: item.refItemId,
|
|
204
|
+
releaseQty: item.totalReleaseQty
|
|
205
|
+
}
|
|
206
|
+
})
|
|
207
|
+
|
|
208
|
+
await AccountingAPI.createShipment(xilnex, {
|
|
209
|
+
releaseGood,
|
|
210
|
+
orderProducts: orderProducts
|
|
211
|
+
})
|
|
212
|
+
})
|
|
213
|
+
)
|
|
214
|
+
} catch (error) {
|
|
215
|
+
logger.error(`xilnex-controller[createShipment]: ${error}`)
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { EntityManager, In } from 'typeorm'
|
|
2
2
|
|
|
3
3
|
import { User } from '@things-factory/auth-base'
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
import { logger } from '@things-factory/env'
|
|
5
|
+
import { Account, AccountingAPI } from '@things-factory/integration-accounting'
|
|
6
6
|
import {
|
|
7
7
|
DeliveryOrder,
|
|
8
8
|
ORDER_INVENTORY_STATUS,
|
|
@@ -30,8 +30,6 @@ export const confirmCancellationReleaseOrder = {
|
|
|
30
30
|
'orderInventories',
|
|
31
31
|
'orderInventories.inventory',
|
|
32
32
|
'orderInventories.inventory.location',
|
|
33
|
-
'orderInventories.inventory.product',
|
|
34
|
-
'orderInventories.inventory.productDetail',
|
|
35
33
|
'orderVass'
|
|
36
34
|
]
|
|
37
35
|
})
|
|
@@ -196,40 +194,38 @@ export const confirmCancellationReleaseOrder = {
|
|
|
196
194
|
releaseGood.updater = user
|
|
197
195
|
await tx.getRepository(ReleaseGood).save(releaseGood)
|
|
198
196
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
// createSalesReturn(account)
|
|
232
|
-
// }
|
|
197
|
+
if (releaseGood?.refNo3 && releaseGood?.type == 'b2c') {
|
|
198
|
+
const account: Account = await tx
|
|
199
|
+
.getRepository(Account)
|
|
200
|
+
.findOne({ domain: releaseGood.bizplace.domain, status: 'active' })
|
|
201
|
+
|
|
202
|
+
// Xilnex create shipment and create sales return if sales invoice is completed
|
|
203
|
+
const createSalesReturn = async account => {
|
|
204
|
+
if (account) {
|
|
205
|
+
if (account.platform == 'xilnex') {
|
|
206
|
+
try {
|
|
207
|
+
await AccountingAPI.createShipment(account, {
|
|
208
|
+
releaseGood,
|
|
209
|
+
orderProducts: releaseGood.orderProducts
|
|
210
|
+
})
|
|
211
|
+
} catch (error) {
|
|
212
|
+
logger.error(`confirm-cancellation-release-order[createShipment]: ${error}`)
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
try {
|
|
216
|
+
await AccountingAPI.createSalesReturn(account, {
|
|
217
|
+
releaseGood,
|
|
218
|
+
orderProducts: releaseGood.orderProducts
|
|
219
|
+
})
|
|
220
|
+
} catch (error) {
|
|
221
|
+
logger.error(`confirm-cancellation-release-order[createSalesReturn]: ${error}`)
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
createSalesReturn(account)
|
|
228
|
+
}
|
|
233
229
|
|
|
234
230
|
return
|
|
235
231
|
}
|
|
@@ -2,6 +2,7 @@ import { EntityManager } from 'typeorm'
|
|
|
2
2
|
|
|
3
3
|
import { ApplicationType, User } from '@things-factory/auth-base'
|
|
4
4
|
import { Bizplace, Company } from '@things-factory/biz-base'
|
|
5
|
+
import { Account } from '@things-factory/integration-accounting'
|
|
5
6
|
import { FulfillmentCenter } from '@things-factory/integration-fulfillment'
|
|
6
7
|
import { Sftp, SftpAPI } from '@things-factory/integration-sftp'
|
|
7
8
|
import { ORDER_INVENTORY_STATUS, ORDER_STATUS, OrderInventory, ReleaseGood } from '@things-factory/sales-base'
|
|
@@ -10,6 +11,7 @@ import { InventoryItem } from '@things-factory/warehouse-base'
|
|
|
10
11
|
|
|
11
12
|
import { WORKSHEET_TYPE } from '../../../../constants'
|
|
12
13
|
import { LoadingWorksheetController, ReturningWorksheetController } from '../../../../controllers'
|
|
14
|
+
import { XilnexController } from '../../../../controllers/pos'
|
|
13
15
|
import { Worksheet, WorksheetDetail } from '../../../../entities'
|
|
14
16
|
|
|
15
17
|
export const completeLoadingResolver = {
|
|
@@ -98,6 +100,18 @@ export async function completeLoading(
|
|
|
98
100
|
}
|
|
99
101
|
break
|
|
100
102
|
|
|
103
|
+
case ApplicationType.XILNEX:
|
|
104
|
+
const xilnex: Account = await tx
|
|
105
|
+
.getRepository(Account)
|
|
106
|
+
.findOne({ where: { domain: releaseGood.bizplace.domain, status: 'active', platform: 'xilnex' } })
|
|
107
|
+
|
|
108
|
+
if (xilnex) {
|
|
109
|
+
const xilnexCtrl: XilnexController = new XilnexController(tx, domain, user)
|
|
110
|
+
await xilnexCtrl.deliveryTransferNote(tx, xilnex, releaseGood.id)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
break
|
|
114
|
+
|
|
101
115
|
default:
|
|
102
116
|
break
|
|
103
117
|
}
|
|
@@ -2,9 +2,13 @@ import { EntityManager } from 'typeorm'
|
|
|
2
2
|
|
|
3
3
|
import { User } from '@things-factory/auth-base'
|
|
4
4
|
import { Bizplace, getMyBizplace } from '@things-factory/biz-base'
|
|
5
|
+
import { logger } from '@things-factory/env'
|
|
6
|
+
import { Account } from '@things-factory/integration-accounting'
|
|
7
|
+
import { ReleaseGood } from '@things-factory/sales-base'
|
|
5
8
|
import { Domain } from '@things-factory/shell'
|
|
6
9
|
|
|
7
10
|
import { PackingWorksheetController } from '../../../../controllers/'
|
|
11
|
+
import { XilnexController } from '../../../../controllers/pos'
|
|
8
12
|
import { WorksheetController } from '../../../../controllers/worksheet-controller'
|
|
9
13
|
|
|
10
14
|
export const completePackingResolver = {
|
|
@@ -12,6 +16,26 @@ export const completePackingResolver = {
|
|
|
12
16
|
const { tx, domain, user }: { tx: EntityManager; domain: Domain; user: User } = context.state
|
|
13
17
|
await completePacking(tx, domain, user, releaseGoodNo)
|
|
14
18
|
|
|
19
|
+
const releaseGood: ReleaseGood = await tx.getRepository(ReleaseGood).findOne({
|
|
20
|
+
where: { name: releaseGoodNo, domain },
|
|
21
|
+
relations: ['bizplace', 'bizplace.domain']
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
if (releaseGood.type == 'b2c') {
|
|
25
|
+
const xilnex: Account = await tx
|
|
26
|
+
.getRepository(Account)
|
|
27
|
+
.findOne({ where: { domain: releaseGood.bizplace.domain, status: 'active', platform: 'xilnex' } })
|
|
28
|
+
|
|
29
|
+
if (xilnex) {
|
|
30
|
+
try {
|
|
31
|
+
const xilnexCtrl: XilnexController = new XilnexController(tx, domain, user)
|
|
32
|
+
await xilnexCtrl.createShipment(tx, xilnex, releaseGood.id)
|
|
33
|
+
} catch (error) {
|
|
34
|
+
logger.error(`worksheet-base[completePacking]: ${error}`)
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
15
39
|
const bizplace: Bizplace = await getMyBizplace(domain, user)
|
|
16
40
|
const worksheetController: WorksheetController = new WorksheetController(tx, domain, user)
|
|
17
41
|
await worksheetController.notifyToCustomer(bizplace, {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EntityManager } from 'typeorm'
|
|
1
|
+
import { EntityManager, getManager } from 'typeorm'
|
|
2
2
|
|
|
3
3
|
import { ApplicationType, User } from '@things-factory/auth-base'
|
|
4
4
|
import { Bizplace, getMyBizplace } from '@things-factory/biz-base'
|
|
@@ -76,26 +76,32 @@ export async function completeBatchPicking(
|
|
|
76
76
|
.findOne({ domain: worksheet.bizplace.domain, status: SellercraftStatus.ACTIVE })
|
|
77
77
|
|
|
78
78
|
if (sellercraft) {
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
.
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
79
|
+
const initSCOrderShipment = async (sellercraft: Sellercraft, foundReleaseGood: ReleaseGood) => {
|
|
80
|
+
await getManager().transaction(async txMgr => {
|
|
81
|
+
const sellercraftCtrl: SellercraftController = new SellercraftController(txMgr, domain, user)
|
|
82
|
+
|
|
83
|
+
if (!releaseGood?.packageId) {
|
|
84
|
+
releaseGood = await sellercraftCtrl.packOrder(sellercraft, foundReleaseGood)
|
|
85
|
+
|
|
86
|
+
if (releaseGood?.packageId) {
|
|
87
|
+
await txMgr
|
|
88
|
+
.getRepository(ReleaseGood)
|
|
89
|
+
.update({ id: releaseGood.id }, { packageId: releaseGood.packageId, updater: releaseGood.updater })
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const rtsTriggerLevel: Setting = await tx.getRepository(Setting).findOne({
|
|
94
|
+
where: { domain, category: 'id-rule', name: 'rts-trigger-level' }
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
if (rtsTriggerLevel && parseInt(rtsTriggerLevel?.value || 0) == 1) {
|
|
98
|
+
await sellercraftCtrl.initiateOrderShipment(sellercraft, releaseGood)
|
|
99
|
+
}
|
|
100
|
+
})
|
|
90
101
|
}
|
|
91
102
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
})
|
|
95
|
-
|
|
96
|
-
if (rtsTriggerLevel && parseInt(rtsTriggerLevel?.value || 0) == 1) {
|
|
97
|
-
sellercraftCtrl.initiateOrderShipment(sellercraft, foundReleaseGood)
|
|
98
|
-
}
|
|
103
|
+
// asynchronouly call to initiate sellercraft order shipment/ RTS
|
|
104
|
+
initSCOrderShipment(sellercraft, foundReleaseGood)
|
|
99
105
|
}
|
|
100
106
|
break
|
|
101
107
|
|
|
@@ -2,8 +2,8 @@ import { EntityManager, getManager } from 'typeorm'
|
|
|
2
2
|
|
|
3
3
|
import { ApplicationType, User } from '@things-factory/auth-base'
|
|
4
4
|
import { Bizplace, ContactPoint, getMyBizplace } from '@things-factory/biz-base'
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
import { logger } from '@things-factory/env'
|
|
6
|
+
import { Account, AccountingAPI } from '@things-factory/integration-accounting'
|
|
7
7
|
import { LastMileAPI, LastMileDelivery } from '@things-factory/integration-lmd'
|
|
8
8
|
import { MarketplaceStore, MarketplaceTransporter } from '@things-factory/integration-marketplace'
|
|
9
9
|
import { Sellercraft, SellercraftStatus } from '@things-factory/integration-sellercraft'
|
|
@@ -97,8 +97,9 @@ export async function completePicking(
|
|
|
97
97
|
const sellercraft: Sellercraft = await tx
|
|
98
98
|
.getRepository(Sellercraft)
|
|
99
99
|
.findOne({ domain: releaseGood.bizplace.domain, status: SellercraftStatus.ACTIVE })
|
|
100
|
-
|
|
101
|
-
|
|
100
|
+
|
|
101
|
+
if (sellercraft) {
|
|
102
|
+
const initSCOrderShipment = async sellercraft => {
|
|
102
103
|
await getManager().transaction(async txMgr => {
|
|
103
104
|
const sellercraftCtrl: SellercraftController = new SellercraftController(txMgr, domain, user)
|
|
104
105
|
|
|
@@ -125,10 +126,9 @@ export async function completePicking(
|
|
|
125
126
|
}
|
|
126
127
|
})
|
|
127
128
|
}
|
|
129
|
+
// asynchronouly call to initiate sellercraft order shipment/ RTS
|
|
130
|
+
initSCOrderShipment(sellercraft)
|
|
128
131
|
}
|
|
129
|
-
|
|
130
|
-
// asynchronouly call to initiate sellercraft order shipment/ RTS
|
|
131
|
-
initSCOrderShipment(sellercraft)
|
|
132
132
|
break
|
|
133
133
|
|
|
134
134
|
case ApplicationType.MMS:
|
|
@@ -255,51 +255,49 @@ export async function completePicking(
|
|
|
255
255
|
break
|
|
256
256
|
}
|
|
257
257
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
//
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
// createSalesOrder(account)
|
|
302
|
-
// }
|
|
258
|
+
const account: Account = await tx
|
|
259
|
+
.getRepository(Account)
|
|
260
|
+
.findOne({ domain: releaseGood.bizplace.domain, status: 'active' })
|
|
261
|
+
|
|
262
|
+
// Xilnex Create Sales Order and Post Sales Order to Sales Invoice
|
|
263
|
+
const createSalesOrder = async (account, tx) => {
|
|
264
|
+
if (account) {
|
|
265
|
+
try {
|
|
266
|
+
if (account.platform == 'xilnex') {
|
|
267
|
+
const salesOrder: any = await AccountingAPI.createSalesOrder(account, {
|
|
268
|
+
releaseGood,
|
|
269
|
+
orderProducts: releaseGood.orderProducts
|
|
270
|
+
})
|
|
271
|
+
|
|
272
|
+
if (salesOrder) {
|
|
273
|
+
const salesInvoice: any = await AccountingAPI.postSalesOrderToSalesInvoice(account, {
|
|
274
|
+
orderId: salesOrder?.id || null
|
|
275
|
+
})
|
|
276
|
+
|
|
277
|
+
const salesOrderItems: any = salesInvoice.sale.items
|
|
278
|
+
await Promise.all(
|
|
279
|
+
releaseGood.orderProducts.map(async op => {
|
|
280
|
+
const matchedProduct: any = salesOrderItems.find(soi => soi.itemId == op.productDetail.refCode)
|
|
281
|
+
if (matchedProduct) {
|
|
282
|
+
await tx.getRepository(OrderProduct).update({ id: op.id }, { refItemId: matchedProduct.id })
|
|
283
|
+
}
|
|
284
|
+
})
|
|
285
|
+
)
|
|
286
|
+
|
|
287
|
+
await tx
|
|
288
|
+
.getRepository(ReleaseGood)
|
|
289
|
+
.update({ id: releaseGood.id }, { collectionOrderNo: salesInvoice.salesId, updater: releaseGood.updater })
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
} catch (error) {
|
|
293
|
+
logger.error(`complete-picking[createSalesOrder]: ${error}`)
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
if (releaseGood.type == 'b2c') {
|
|
299
|
+
await createSalesOrder(account, tx)
|
|
300
|
+
}
|
|
303
301
|
|
|
304
302
|
if (releaseGood.packingOption) {
|
|
305
303
|
const packingWSCtrl: PackingWorksheetController = new PackingWorksheetController(tx, domain, user)
|
|
@@ -1,13 +1,31 @@
|
|
|
1
|
+
import { EntityManager } from 'typeorm'
|
|
2
|
+
|
|
1
3
|
import { User } from '@things-factory/auth-base'
|
|
4
|
+
import { Account } from '@things-factory/integration-accounting'
|
|
5
|
+
import { ArrivalNotice } from '@things-factory/sales-base'
|
|
2
6
|
import { Domain } from '@things-factory/shell'
|
|
3
|
-
|
|
7
|
+
|
|
4
8
|
import { UnloadingWorksheetController } from '../../../../controllers'
|
|
9
|
+
import { XilnexController } from '../../../../controllers/pos'
|
|
5
10
|
import { WorksheetDetail } from '../../../../entities'
|
|
6
11
|
|
|
7
12
|
export const completeUnloadingPartiallyResolver = {
|
|
8
13
|
async completeUnloadingPartially(_: any, { arrivalNoticeNo, worksheetDetail }, context: any) {
|
|
9
14
|
const { tx, domain, user }: { tx: EntityManager; domain: Domain; user: User } = context.state
|
|
10
15
|
await completeUnloadingPartially(tx, domain, user, arrivalNoticeNo, worksheetDetail)
|
|
16
|
+
|
|
17
|
+
const arrivalNotice: ArrivalNotice = await tx
|
|
18
|
+
.getRepository(ArrivalNotice)
|
|
19
|
+
.findOne({ where: { name: arrivalNoticeNo, domain }, relations: ['domain', 'bizplace', 'bizplace.domain'] })
|
|
20
|
+
|
|
21
|
+
const xilnex: Account = await tx
|
|
22
|
+
.getRepository(Account)
|
|
23
|
+
.findOne({ where: { domain: arrivalNotice.bizplace.domain, status: 'active', platform: 'xilnex' } })
|
|
24
|
+
|
|
25
|
+
if (xilnex) {
|
|
26
|
+
const xilnexCtrl: XilnexController = new XilnexController(tx, domain, user)
|
|
27
|
+
await xilnexCtrl.createPartialUnloadInboundDocument(tx, xilnex, arrivalNotice, worksheetDetail)
|
|
28
|
+
}
|
|
11
29
|
}
|
|
12
30
|
}
|
|
13
31
|
|
|
@@ -2,12 +2,14 @@ import { EntityManager, In } from 'typeorm'
|
|
|
2
2
|
|
|
3
3
|
import { User } from '@things-factory/auth-base'
|
|
4
4
|
import { Bizplace } from '@things-factory/biz-base'
|
|
5
|
+
import { Account } from '@things-factory/integration-accounting'
|
|
5
6
|
import { ArrivalNotice, generateGoodsReceivalNote } from '@things-factory/sales-base'
|
|
6
7
|
import { Domain } from '@things-factory/shell'
|
|
7
8
|
import { Inventory, INVENTORY_STATUS } from '@things-factory/warehouse-base'
|
|
8
9
|
|
|
9
10
|
import { WORKSHEET_STATUS } from '../../../../constants'
|
|
10
11
|
import { PutawayWorksheetController, UnloadingWorksheetController } from '../../../../controllers'
|
|
12
|
+
import { XilnexController } from '../../../../controllers/pos'
|
|
11
13
|
import { Worksheet, WorksheetDetail } from '../../../../entities'
|
|
12
14
|
|
|
13
15
|
export const completeUnloadingResolver = {
|
|
@@ -37,6 +39,8 @@ export const completeUnloadingResolver = {
|
|
|
37
39
|
where: { domain, refOrderId: arrivalNotice.id, status: In([INVENTORY_STATUS.UNLOADED, INVENTORY_STATUS.CHECKED]) }
|
|
38
40
|
})
|
|
39
41
|
|
|
42
|
+
const inventoryIds: string[] = inventories.map(iv => iv.id)
|
|
43
|
+
|
|
40
44
|
putawayWorksheet = await putawayWSCtrl.generatePutawayWorksheet(arrivalNotice.name, inventories)
|
|
41
45
|
|
|
42
46
|
if (putawayWorksheet.status === WORKSHEET_STATUS.DEACTIVATED) {
|
|
@@ -46,6 +50,16 @@ export const completeUnloadingResolver = {
|
|
|
46
50
|
const bizplaceId: Bizplace = arrivalNotice.bizplace.id
|
|
47
51
|
await generateGoodsReceivalNote({ refNo: arrivalNoticeNo, customer: bizplaceId }, domain, user, tx)
|
|
48
52
|
|
|
53
|
+
const customerDomain: Domain = arrivalNotice.bizplace.domain
|
|
54
|
+
const xilnex: Account = await tx
|
|
55
|
+
.getRepository(Account)
|
|
56
|
+
.findOne({ where: { domain: customerDomain, status: 'active', platform: 'xilnex' } })
|
|
57
|
+
|
|
58
|
+
if (xilnex) {
|
|
59
|
+
const xilnexCtrl: XilnexController = new XilnexController(tx, domain, user)
|
|
60
|
+
await xilnexCtrl.createInboundDocument(tx, xilnex, arrivalNotice.id, inventoryIds)
|
|
61
|
+
}
|
|
62
|
+
|
|
49
63
|
const worksheetController: UnloadingWorksheetController = new UnloadingWorksheetController(tx, domain, user)
|
|
50
64
|
worksheetController.notifyToOfficeAdmin({
|
|
51
65
|
title: `Unloading Completed (${arrivalNotice.bizplace.name}, ${arrivalNotice.name})`,
|