@things-factory/sales-base 8.0.2 → 8.0.5
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 +12 -12
- package/server/constants/attachment-type.ts +0 -9
- package/server/constants/index.ts +0 -7
- package/server/constants/load-type.ts +0 -4
- package/server/constants/order.ts +0 -203
- package/server/constants/product-group-type.ts +0 -4
- package/server/constants/release-good.ts +0 -9
- package/server/constants/transfer-order-type.ts +0 -6
- package/server/constants/validation-error-code.ts +0 -3
- package/server/constants/vas-target-type.ts +0 -25
- package/server/controllers/ecommerce/ecommerce-controller.ts +0 -122
- package/server/controllers/ecommerce/index.ts +0 -2
- package/server/controllers/ecommerce/sellercraft-controller.ts +0 -182
- package/server/controllers/index.ts +0 -2
- package/server/controllers/order-controller.ts +0 -296
- package/server/errors/index.ts +0 -1
- package/server/errors/validation-error.ts +0 -25
- package/server/index.ts +0 -5
- package/server/migrations/index.ts +0 -9
- package/server/service/arrival-notice/arrival-notice-mutation.ts +0 -1152
- package/server/service/arrival-notice/arrival-notice-query.ts +0 -549
- package/server/service/arrival-notice/arrival-notice-types.ts +0 -310
- package/server/service/arrival-notice/arrival-notice.ts +0 -202
- package/server/service/arrival-notice/index.ts +0 -9
- package/server/service/claim/claim-mutation.ts +0 -308
- package/server/service/claim/claim-query.ts +0 -122
- package/server/service/claim/claim-types.ts +0 -130
- package/server/service/claim/claim.ts +0 -140
- package/server/service/claim/index.ts +0 -9
- package/server/service/claim-detail/claim-detail-mutation.ts +0 -102
- package/server/service/claim-detail/claim-detail-query.ts +0 -55
- package/server/service/claim-detail/claim-detail-types.ts +0 -47
- package/server/service/claim-detail/claim-detail.ts +0 -69
- package/server/service/claim-detail/index.ts +0 -9
- package/server/service/claim-order/claim-order-mutation.ts +0 -101
- package/server/service/claim-order/claim-order-query.ts +0 -47
- package/server/service/claim-order/claim-order-types.ts +0 -35
- package/server/service/claim-order/claim-order.ts +0 -81
- package/server/service/claim-order/index.ts +0 -9
- package/server/service/collection-order/collection-order-mutation.ts +0 -245
- package/server/service/collection-order/collection-order-query.ts +0 -97
- package/server/service/collection-order/collection-order-types.ts +0 -165
- package/server/service/collection-order/collection-order.ts +0 -135
- package/server/service/collection-order/index.ts +0 -9
- package/server/service/delivery-order/delivery-order-mutation.ts +0 -967
- package/server/service/delivery-order/delivery-order-query.ts +0 -631
- package/server/service/delivery-order/delivery-order-types.ts +0 -268
- package/server/service/delivery-order/delivery-order.ts +0 -258
- package/server/service/delivery-order/index.ts +0 -9
- package/server/service/draft-release-good/draft-release-good-mutation.ts +0 -765
- package/server/service/draft-release-good/draft-release-good-query.ts +0 -354
- package/server/service/draft-release-good/draft-release-good-type.ts +0 -261
- package/server/service/draft-release-good/draft-release-good.ts +0 -284
- package/server/service/draft-release-good/index.ts +0 -9
- package/server/service/goods-receival-note/goods-receival-note-mutation.ts +0 -129
- package/server/service/goods-receival-note/goods-receival-note-query.ts +0 -280
- package/server/service/goods-receival-note/goods-receival-note-types.ts +0 -105
- package/server/service/goods-receival-note/goods-receival-note.ts +0 -127
- package/server/service/goods-receival-note/index.ts +0 -9
- package/server/service/index.ts +0 -238
- package/server/service/inventory-check/index.ts +0 -9
- package/server/service/inventory-check/inventory-check-mutation.ts +0 -149
- package/server/service/inventory-check/inventory-check-query.ts +0 -48
- package/server/service/inventory-check/inventory-check-types.ts +0 -48
- package/server/service/inventory-check/inventory-check.ts +0 -90
- package/server/service/invoice/index.ts +0 -9
- package/server/service/invoice/invoice-mutation.ts +0 -95
- package/server/service/invoice/invoice-query.ts +0 -53
- package/server/service/invoice/invoice-types.ts +0 -279
- package/server/service/invoice/invoice.ts +0 -230
- package/server/service/invoice-product/index.ts +0 -9
- package/server/service/invoice-product/invoice-product-mutation.ts +0 -54
- package/server/service/invoice-product/invoice-product-query.ts +0 -54
- package/server/service/invoice-product/invoice-product-types.ts +0 -84
- package/server/service/invoice-product/invoice-product.ts +0 -92
- package/server/service/job-sheet/index.ts +0 -9
- package/server/service/job-sheet/job-sheet-mutation.ts +0 -92
- package/server/service/job-sheet/job-sheet-query.ts +0 -112
- package/server/service/job-sheet/job-sheet-types.ts +0 -78
- package/server/service/job-sheet/job-sheet.ts +0 -102
- package/server/service/manifest/index.ts +0 -6
- package/server/service/manifest/manifest-mutation.ts +0 -190
- package/server/service/manifest/manifest-query.ts +0 -149
- package/server/service/manifest/manifest-type.ts +0 -84
- package/server/service/manifest/manifest.ts +0 -114
- package/server/service/order-inventory/index.ts +0 -9
- package/server/service/order-inventory/order-inventory-mutation.ts +0 -54
- package/server/service/order-inventory/order-inventory-query.ts +0 -722
- package/server/service/order-inventory/order-inventory-types.ts +0 -238
- package/server/service/order-inventory/order-inventory.ts +0 -401
- package/server/service/order-product/index.ts +0 -9
- package/server/service/order-product/order-product-mutation.ts +0 -48
- package/server/service/order-product/order-product-query.ts +0 -89
- package/server/service/order-product/order-product-types.ts +0 -335
- package/server/service/order-product/order-product.ts +0 -362
- package/server/service/order-tote/index.ts +0 -9
- package/server/service/order-tote/order-tote-mutation.ts +0 -31
- package/server/service/order-tote/order-tote-query.ts +0 -112
- package/server/service/order-tote/order-tote-types.ts +0 -47
- package/server/service/order-tote/order-tote.ts +0 -73
- package/server/service/order-tote-item/index.ts +0 -9
- package/server/service/order-tote-item/order-tote-item-mutation.ts +0 -31
- package/server/service/order-tote-item/order-tote-item-query.ts +0 -82
- package/server/service/order-tote-item/order-tote-item-types.ts +0 -56
- package/server/service/order-tote-item/order-tote-item.ts +0 -72
- package/server/service/order-tote-seal/index.ts +0 -9
- package/server/service/order-tote-seal/order-tote-seal-mutation.ts +0 -31
- package/server/service/order-tote-seal/order-tote-seal-query.ts +0 -59
- package/server/service/order-tote-seal/order-tote-seal-types.ts +0 -41
- package/server/service/order-tote-seal/order-tote-seal.ts +0 -46
- package/server/service/order-vas/index.ts +0 -9
- package/server/service/order-vas/order-vas-mutation.ts +0 -20
- package/server/service/order-vas/order-vas-query.ts +0 -72
- package/server/service/order-vas/order-vas-types.ts +0 -159
- package/server/service/order-vas/order-vas.ts +0 -207
- package/server/service/others/index.ts +0 -5
- package/server/service/others/other-query.ts +0 -563
- package/server/service/others/other-types.ts +0 -115
- package/server/service/purchase-order/index.ts +0 -9
- package/server/service/purchase-order/purchase-order-mutation.ts +0 -458
- package/server/service/purchase-order/purchase-order-query.ts +0 -90
- package/server/service/purchase-order/purchase-order-types.ts +0 -154
- package/server/service/purchase-order/purchase-order.ts +0 -172
- package/server/service/purchase-order-other-charge/index.ts +0 -9
- package/server/service/purchase-order-other-charge/purchase-order-other-charge-mutation.ts +0 -31
- package/server/service/purchase-order-other-charge/purchase-order-other-charge-query.ts +0 -52
- package/server/service/purchase-order-other-charge/purchase-order-other-charge-types.ts +0 -44
- package/server/service/purchase-order-other-charge/purchase-order-other-charge.ts +0 -68
- package/server/service/release-good/index.ts +0 -9
- package/server/service/release-good/release-good-mutation.ts +0 -1686
- package/server/service/release-good/release-good-query.ts +0 -980
- package/server/service/release-good/release-good-types.ts +0 -662
- package/server/service/release-good/release-good.ts +0 -490
- package/server/service/retail-replenishment-order/index.ts +0 -9
- package/server/service/retail-replenishment-order/retail-replenishment-order-mutation.ts +0 -382
- package/server/service/retail-replenishment-order/retail-replenishment-order-query.ts +0 -54
- package/server/service/retail-replenishment-order/retail-replenishment-order-types.ts +0 -101
- package/server/service/retail-replenishment-order/retail-replenishment-order.ts +0 -115
- package/server/service/return-order/index.ts +0 -9
- package/server/service/return-order/return-order-mutation.ts +0 -516
- package/server/service/return-order/return-order-query.ts +0 -226
- package/server/service/return-order/return-order-types.ts +0 -196
- package/server/service/return-order/return-order.ts +0 -127
- package/server/service/reverse-kitting-order/index.ts +0 -9
- package/server/service/reverse-kitting-order/reverse-kitting-order-mutation.ts +0 -500
- package/server/service/reverse-kitting-order/reverse-kitting-order-query.ts +0 -197
- package/server/service/reverse-kitting-order/reverse-kitting-order-type.ts +0 -173
- package/server/service/reverse-kitting-order/reverse-kitting-order.ts +0 -121
- package/server/service/reverse-kitting-order-inventory/index.ts +0 -9
- package/server/service/reverse-kitting-order-inventory/reverse-kitting-order-inventory-mutation.ts +0 -129
- package/server/service/reverse-kitting-order-inventory/reverse-kitting-order-inventory-query.ts +0 -52
- package/server/service/reverse-kitting-order-inventory/reverse-kitting-order-inventory-type.ts +0 -95
- package/server/service/reverse-kitting-order-inventory/reverse-kitting-order-inventory.ts +0 -143
- package/server/service/shipping-order/index.ts +0 -9
- package/server/service/shipping-order/shipping-order-mutation.ts +0 -61
- package/server/service/shipping-order/shipping-order-query.ts +0 -61
- package/server/service/shipping-order/shipping-order-types.ts +0 -89
- package/server/service/shipping-order/shipping-order.ts +0 -129
- package/server/service/transfer-order/index.ts +0 -9
- package/server/service/transfer-order/transfer-order-mutation.ts +0 -309
- package/server/service/transfer-order/transfer-order-query.ts +0 -66
- package/server/service/transfer-order/transfer-order-types.ts +0 -97
- package/server/service/transfer-order/transfer-order.ts +0 -117
- package/server/service/vas/index.ts +0 -9
- package/server/service/vas/vas-mutation.ts +0 -106
- package/server/service/vas/vas-query.ts +0 -60
- package/server/service/vas/vas-types.ts +0 -71
- package/server/service/vas/vas.ts +0 -77
- package/server/service/vas-order/index.ts +0 -9
- package/server/service/vas-order/vas-order-mutation.ts +0 -259
- package/server/service/vas-order/vas-order-query.ts +0 -119
- package/server/service/vas-order/vas-order-types.ts +0 -49
- package/server/service/vas-order/vas-order.ts +0 -81
- package/server/utils/datetime-util.ts +0 -54
- package/server/utils/index.ts +0 -3
- package/server/utils/inventory-util.ts +0 -1155
- package/server/utils/order-no-generator.ts +0 -146
|
@@ -1,967 +0,0 @@
|
|
|
1
|
-
import type { FileUpload } from 'graphql-upload/GraphQLUpload.js'
|
|
2
|
-
import GraphQLUpload from 'graphql-upload/GraphQLUpload.js'
|
|
3
|
-
import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'
|
|
4
|
-
import { EntityManager, In, Repository } from 'typeorm'
|
|
5
|
-
|
|
6
|
-
import { Attachment, createAttachment, deleteAttachment } from '@things-factory/attachment-base'
|
|
7
|
-
import { User } from '@things-factory/auth-base'
|
|
8
|
-
import { Bizplace, ContactPoint, getPermittedBizplaceIds } from '@things-factory/biz-base'
|
|
9
|
-
import { generateId } from '@things-factory/id-rule-base'
|
|
10
|
-
import { Product } from '@things-factory/product-base'
|
|
11
|
-
import { Setting } from '@things-factory/setting-base'
|
|
12
|
-
import { Domain, getRepository, ObjectRef } from '@things-factory/shell'
|
|
13
|
-
import { TransportDriver, TransportVehicle, TRUCK_STATUS } from '@things-factory/transport-base'
|
|
14
|
-
import { Inventory } from '@things-factory/warehouse-base'
|
|
15
|
-
|
|
16
|
-
import {
|
|
17
|
-
ORDER_INVENTORY_STATUS,
|
|
18
|
-
ORDER_NUMBER_RULE_TYPE,
|
|
19
|
-
ORDER_NUMBER_SETTING_KEY,
|
|
20
|
-
ORDER_STATUS,
|
|
21
|
-
ORDER_TYPES
|
|
22
|
-
} from '../../constants'
|
|
23
|
-
import { OrderNoGenerator } from '../../utils/order-no-generator'
|
|
24
|
-
import { OrderInventory } from '../order-inventory/order-inventory'
|
|
25
|
-
import { NewOrderInventory, OrderInventoryPatch } from '../order-inventory/order-inventory-types'
|
|
26
|
-
import { ReleaseGood } from '../release-good/release-good'
|
|
27
|
-
import { ExportInformationPatch, ShippingOrderInfoPatch } from '../release-good/release-good-types'
|
|
28
|
-
import { ShippingOrder } from '../shipping-order/shipping-order'
|
|
29
|
-
import { DeliveryOrder } from './delivery-order'
|
|
30
|
-
import { DeliveryOrderPatch, NewDeliveryOrder } from './delivery-order-types'
|
|
31
|
-
|
|
32
|
-
@Resolver(DeliveryOrder)
|
|
33
|
-
export class DeliveryOrderMutation {
|
|
34
|
-
@Directive('@transaction')
|
|
35
|
-
@Mutation(returns => DeliveryOrder)
|
|
36
|
-
async createDeliveryOrder(
|
|
37
|
-
@Ctx() context: ResolverContext,
|
|
38
|
-
@Arg('orderInfo', type => NewDeliveryOrder, { nullable: true }) orderInfo?: NewDeliveryOrder,
|
|
39
|
-
@Arg('customerBizplace', type => ObjectRef, { nullable: true }) customerBizplace?: ObjectRef,
|
|
40
|
-
@Arg('targetInventories', type => [NewOrderInventory], { nullable: true }) targetInventories?: NewOrderInventory[],
|
|
41
|
-
@Arg('file', type => [GraphQLUpload], { nullable: true }) file?: FileUpload[]
|
|
42
|
-
): Promise<DeliveryOrder> {
|
|
43
|
-
const { tx, domain, user } = context.state
|
|
44
|
-
|
|
45
|
-
return await createDeliveryOrder(orderInfo, customerBizplace as any, targetInventories, file, domain, user, tx)
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
@Directive('@transaction')
|
|
49
|
-
@Mutation(returns => DeliveryOrder)
|
|
50
|
-
async updateDeliveryOrder(
|
|
51
|
-
@Arg('name') name: string,
|
|
52
|
-
@Arg('patch', type => DeliveryOrderPatch) patch: DeliveryOrderPatch,
|
|
53
|
-
@Ctx() context: ResolverContext
|
|
54
|
-
): Promise<DeliveryOrder> {
|
|
55
|
-
const { tx, domain, user } = context.state
|
|
56
|
-
|
|
57
|
-
const deliveryOrder = await tx.getRepository(DeliveryOrder).findOne({
|
|
58
|
-
where: {
|
|
59
|
-
domain: { id: domain.id },
|
|
60
|
-
name,
|
|
61
|
-
bizplace: In(await getPermittedBizplaceIds(domain, user))
|
|
62
|
-
}
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
return await tx.getRepository(DeliveryOrder).save({
|
|
66
|
-
...deliveryOrder,
|
|
67
|
-
...patch,
|
|
68
|
-
updater: user
|
|
69
|
-
})
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
@Directive('@transaction')
|
|
73
|
-
@Mutation(returns => Boolean)
|
|
74
|
-
async deleteDeliveryOrder(@Arg('name') name: string, @Ctx() context: ResolverContext): Promise<boolean> {
|
|
75
|
-
const { tx, domain } = context.state
|
|
76
|
-
|
|
77
|
-
const foundDO = await tx.getRepository(DeliveryOrder).findOne({
|
|
78
|
-
where: { domain: { id: domain.id }, name }
|
|
79
|
-
})
|
|
80
|
-
if (foundDO) {
|
|
81
|
-
const previousAttachment: Attachment = await tx.getRepository(Attachment).findOne({
|
|
82
|
-
where: { domain: { id: domain.id }, refBy: foundDO.id }
|
|
83
|
-
})
|
|
84
|
-
if (previousAttachment) await deleteAttachment(null, { id: previousAttachment.id }, context)
|
|
85
|
-
await tx.getRepository(DeliveryOrder).delete({ domain: { id: domain.id }, name })
|
|
86
|
-
}
|
|
87
|
-
return true
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
@Directive('@transaction')
|
|
91
|
-
@Mutation(returns => DeliveryOrder)
|
|
92
|
-
async generateDeliveryOrder(
|
|
93
|
-
@Ctx() context: ResolverContext,
|
|
94
|
-
@Arg('orderInfo', type => DeliveryOrderPatch, { nullable: true }) orderInfo?: DeliveryOrderPatch,
|
|
95
|
-
@Arg('customerBizplace', type => ObjectRef, { nullable: true }) customerBizplace?: ObjectRef,
|
|
96
|
-
@Arg('releaseGood', type => ObjectRef, { nullable: true }) releaseGood?: ObjectRef,
|
|
97
|
-
@Arg('targetInventories', type => [ObjectRef], { nullable: true }) targetInventories?: ObjectRef[]
|
|
98
|
-
): Promise<DeliveryOrder> {
|
|
99
|
-
const { tx, domain, user } = context.state
|
|
100
|
-
|
|
101
|
-
return await generateDeliveryOrder(
|
|
102
|
-
orderInfo,
|
|
103
|
-
targetInventories as any,
|
|
104
|
-
customerBizplace as any,
|
|
105
|
-
releaseGood as any,
|
|
106
|
-
domain,
|
|
107
|
-
user,
|
|
108
|
-
tx
|
|
109
|
-
)
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
@Directive('@transaction')
|
|
113
|
-
@Mutation(returns => DeliveryOrder)
|
|
114
|
-
async confirmDeliveryOrder(@Arg('name') name: string, @Ctx() context: ResolverContext): Promise<DeliveryOrder> {
|
|
115
|
-
const { tx, domain, user } = context.state
|
|
116
|
-
|
|
117
|
-
const foundDeliveryOrder: DeliveryOrder = await tx.getRepository(DeliveryOrder).findOne({
|
|
118
|
-
where: { domain: { id: domain.id }, name },
|
|
119
|
-
relations: ['creator', 'updater']
|
|
120
|
-
})
|
|
121
|
-
|
|
122
|
-
let deliveryOrder: DeliveryOrder
|
|
123
|
-
if (!foundDeliveryOrder) throw new Error(`Delivery Order doesn't exists.`)
|
|
124
|
-
if (foundDeliveryOrder.status !== ORDER_STATUS.PENDING) throw new Error('Not confirmable status.')
|
|
125
|
-
|
|
126
|
-
// delivery Order Status change (PENDING => PENDING_RECEIVE)
|
|
127
|
-
deliveryOrder = await tx.getRepository(DeliveryOrder).save({
|
|
128
|
-
...foundDeliveryOrder,
|
|
129
|
-
status: ORDER_STATUS.PENDING_RECEIVE,
|
|
130
|
-
updater: user
|
|
131
|
-
})
|
|
132
|
-
|
|
133
|
-
return deliveryOrder
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
@Directive('@transaction')
|
|
137
|
-
@Mutation(returns => DeliveryOrder)
|
|
138
|
-
async receiveDeliveryOrder(@Arg('name') name: string, @Ctx() context: ResolverContext): Promise<DeliveryOrder> {
|
|
139
|
-
try {
|
|
140
|
-
const { tx, domain, user } = context.state
|
|
141
|
-
|
|
142
|
-
const deliveryOrder: DeliveryOrder = await tx.getRepository(DeliveryOrder).findOne({
|
|
143
|
-
where: { domain: { id: domain.id }, name }
|
|
144
|
-
})
|
|
145
|
-
|
|
146
|
-
if (!deliveryOrder) throw new Error(`Delivery order doesn't exists.`)
|
|
147
|
-
if (deliveryOrder.status !== ORDER_STATUS.PENDING_RECEIVE) throw new Error(`Status is not receivable.`)
|
|
148
|
-
|
|
149
|
-
await tx.getRepository(DeliveryOrder).save({
|
|
150
|
-
...deliveryOrder,
|
|
151
|
-
status: ORDER_STATUS.READY_TO_DISPATCH,
|
|
152
|
-
updater: user
|
|
153
|
-
})
|
|
154
|
-
|
|
155
|
-
return deliveryOrder
|
|
156
|
-
} catch (e) {
|
|
157
|
-
throw e
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
@Directive('@transaction')
|
|
162
|
-
@Mutation(returns => DeliveryOrder)
|
|
163
|
-
async checkDeliveredOrder(
|
|
164
|
-
@Ctx() context: ResolverContext,
|
|
165
|
-
@Arg('name') name: string,
|
|
166
|
-
@Arg('patch', type => DeliveryOrderPatch, { nullable: true }) patch?: DeliveryOrderPatch
|
|
167
|
-
): Promise<DeliveryOrder> {
|
|
168
|
-
try {
|
|
169
|
-
const { tx, domain, user } = context.state
|
|
170
|
-
const deliveryOrder: DeliveryOrder = await tx.getRepository(DeliveryOrder).findOne({
|
|
171
|
-
where: { domain: { id: domain.id }, name },
|
|
172
|
-
relations: ['bizplace', 'transportDriver', 'transportVehicle']
|
|
173
|
-
})
|
|
174
|
-
|
|
175
|
-
if (!deliveryOrder) throw new Error(`Delivery order doesn't exists.`)
|
|
176
|
-
if (deliveryOrder.status !== ORDER_STATUS.DELIVERING) throw new Error(`Status is not receivable.`)
|
|
177
|
-
|
|
178
|
-
let orderInventories: OrderInventory[] = await tx.getRepository(OrderInventory).find({
|
|
179
|
-
where: { domain: { id: domain.id }, deliveryOrder: { id: deliveryOrder.id } },
|
|
180
|
-
relations: ['product']
|
|
181
|
-
})
|
|
182
|
-
|
|
183
|
-
// update order inventory status for manual DO only
|
|
184
|
-
orderInventories = orderInventories.map((orderInventory: OrderInventory) => {
|
|
185
|
-
if (
|
|
186
|
-
orderInventory.type === ORDER_TYPES.DELIVERY &&
|
|
187
|
-
orderInventory.status === ORDER_INVENTORY_STATUS.DELIVERING
|
|
188
|
-
) {
|
|
189
|
-
return {
|
|
190
|
-
...orderInventory,
|
|
191
|
-
status: ORDER_INVENTORY_STATUS.DONE
|
|
192
|
-
}
|
|
193
|
-
} else return orderInventory
|
|
194
|
-
})
|
|
195
|
-
await tx.getRepository(OrderInventory).save(orderInventories)
|
|
196
|
-
|
|
197
|
-
await tx.getRepository(DeliveryOrder).save({
|
|
198
|
-
...deliveryOrder,
|
|
199
|
-
...patch,
|
|
200
|
-
status: ORDER_STATUS.DONE,
|
|
201
|
-
updater: user
|
|
202
|
-
})
|
|
203
|
-
|
|
204
|
-
if (!deliveryOrder?.ownCollection) {
|
|
205
|
-
const foundTruck: TransportVehicle = deliveryOrder.transportVehicle
|
|
206
|
-
await tx.getRepository(TransportVehicle).save({
|
|
207
|
-
...foundTruck,
|
|
208
|
-
status: TRUCK_STATUS.AVAILABLE,
|
|
209
|
-
updater: user
|
|
210
|
-
})
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
return deliveryOrder
|
|
214
|
-
} catch (e) {
|
|
215
|
-
throw e
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
/**
|
|
220
|
-
* comment start
|
|
221
|
-
* detailed review needed 06 Aug 2022 by @ChrisLim-git
|
|
222
|
-
* @param context
|
|
223
|
-
* @param orderInfo
|
|
224
|
-
* @param orderItems
|
|
225
|
-
* @param shippingOrderInfo
|
|
226
|
-
* @param exportInfo
|
|
227
|
-
* @returns DeliveryOrder
|
|
228
|
-
*/
|
|
229
|
-
@Directive('@transaction')
|
|
230
|
-
@Mutation(returns => DeliveryOrder)
|
|
231
|
-
async dispatchDeliveryOrder(
|
|
232
|
-
@Ctx() context: ResolverContext,
|
|
233
|
-
@Arg('orderInfo', type => DeliveryOrderPatch, { nullable: true }) orderInfo?: DeliveryOrderPatch,
|
|
234
|
-
@Arg('orderItems', type => [OrderInventoryPatch], { nullable: true }) orderItems?: OrderInventoryPatch[],
|
|
235
|
-
@Arg('shippingInfo', type => ShippingOrderInfoPatch, { nullable: true })
|
|
236
|
-
shippingOrderInfo?: ShippingOrderInfoPatch,
|
|
237
|
-
@Arg('exportInfo', type => ExportInformationPatch, { nullable: true }) exportInfo?: ExportInformationPatch
|
|
238
|
-
): Promise<DeliveryOrder> {
|
|
239
|
-
try {
|
|
240
|
-
const { tx, domain, user } = context.state
|
|
241
|
-
const foundDeliveryOrder: DeliveryOrder = await tx.getRepository(DeliveryOrder).findOne({
|
|
242
|
-
where: { domain: { id: domain.id }, name: orderInfo.name },
|
|
243
|
-
relations: ['transportVehicle', 'bizplace']
|
|
244
|
-
})
|
|
245
|
-
|
|
246
|
-
const foundReleaseGood: ReleaseGood = await tx.getRepository(ReleaseGood).findOne({
|
|
247
|
-
where: {
|
|
248
|
-
name: orderInfo.releaseGoodNo,
|
|
249
|
-
domain: { id: domain.id }
|
|
250
|
-
},
|
|
251
|
-
relations: ['shippingOrder']
|
|
252
|
-
})
|
|
253
|
-
|
|
254
|
-
if (!foundDeliveryOrder) throw new Error(`Delivery order doesn't exists.`)
|
|
255
|
-
if (foundDeliveryOrder.status === ORDER_STATUS.PENDING_CANCEL)
|
|
256
|
-
throw new Error('Release order is pending for cancel')
|
|
257
|
-
|
|
258
|
-
foundDeliveryOrder.ownCollection = orderInfo.transportType == 'Own Transport' ? true : false
|
|
259
|
-
|
|
260
|
-
let deliveryOrderStatus = foundDeliveryOrder.status
|
|
261
|
-
let orderInventories: OrderInventory[]
|
|
262
|
-
orderInventories = await tx.getRepository(OrderInventory).find({
|
|
263
|
-
where: { domain: { id: domain.id }, deliveryOrder: { id: foundDeliveryOrder.id } },
|
|
264
|
-
relations: ['inventory', 'inventory.product', 'inventory.reusablePallet']
|
|
265
|
-
})
|
|
266
|
-
|
|
267
|
-
orderInventories = orderInventories.map((orderInventory: OrderInventory) => {
|
|
268
|
-
const inventory: Inventory = orderInventory.inventory
|
|
269
|
-
const product: Product = inventory.product
|
|
270
|
-
const foundItem = inventory.reusablePallet
|
|
271
|
-
? orderItems.filter(
|
|
272
|
-
(item: any) =>
|
|
273
|
-
item.productName === `${product.name} (${product.description})` &&
|
|
274
|
-
item.batchId === orderInventory.batchId &&
|
|
275
|
-
item.pallet === inventory.reusablePallet.name
|
|
276
|
-
)
|
|
277
|
-
: orderItems.filter(
|
|
278
|
-
(item: any) =>
|
|
279
|
-
item.productName === `${product.name} (${product.description})` &&
|
|
280
|
-
item.batchId === orderInventory.batchId
|
|
281
|
-
)
|
|
282
|
-
|
|
283
|
-
if (foundItem[0].remark !== '') orderInventory.remark = foundItem[0].remark
|
|
284
|
-
return orderInventory
|
|
285
|
-
})
|
|
286
|
-
await tx.getRepository(OrderInventory).save(orderInventories)
|
|
287
|
-
|
|
288
|
-
// if there is other destination value, create a new contact point
|
|
289
|
-
let foundCP: any = {}
|
|
290
|
-
if (orderInfo?.otherDestination) {
|
|
291
|
-
foundCP = {
|
|
292
|
-
domain,
|
|
293
|
-
name: orderInfo.contactName,
|
|
294
|
-
bizplace: foundDeliveryOrder.bizplace,
|
|
295
|
-
address: orderInfo.otherDestination,
|
|
296
|
-
billingAddress: orderInfo.billingAddress,
|
|
297
|
-
phone: orderInfo.contactPhone,
|
|
298
|
-
email: orderInfo.contactEmail,
|
|
299
|
-
companyName: orderInfo.contactCompany,
|
|
300
|
-
type: orderInfo.contactType,
|
|
301
|
-
creator: user
|
|
302
|
-
}
|
|
303
|
-
foundCP = await tx.getRepository(ContactPoint).save(foundCP)
|
|
304
|
-
} else {
|
|
305
|
-
foundCP = await tx.getRepository(ContactPoint).findOne({
|
|
306
|
-
where: { domain: { id: domain.id }, id: orderInfo.contactPoint, bizplace: foundDeliveryOrder.bizplace }
|
|
307
|
-
})
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
let transportDriver: TransportDriver = null
|
|
311
|
-
let transportVehicle: TransportVehicle = null
|
|
312
|
-
if (orderInfo?.ownDriver) {
|
|
313
|
-
transportDriver = await tx.getRepository(TransportDriver).findOne({
|
|
314
|
-
where: { domain: { id: domain.id }, name: orderInfo.ownDriver }
|
|
315
|
-
})
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
if (orderInfo?.ownTruck) {
|
|
319
|
-
transportVehicle = await tx.getRepository(TransportVehicle).findOne({
|
|
320
|
-
where: { domain: { id: domain.id }, name: orderInfo.ownTruck }
|
|
321
|
-
})
|
|
322
|
-
|
|
323
|
-
await tx.getRepository(TransportVehicle).save({
|
|
324
|
-
...transportVehicle,
|
|
325
|
-
status: TRUCK_STATUS.IN_USE,
|
|
326
|
-
updater: user
|
|
327
|
-
})
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
if (foundDeliveryOrder.status === ORDER_STATUS.READY_TO_DISPATCH) {
|
|
331
|
-
// update status to DELIVERING if current status is READY_TO_DISPATCH
|
|
332
|
-
deliveryOrderStatus = ORDER_STATUS.DELIVERING
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
// save export option information
|
|
336
|
-
if (orderInfo?.exportOption) {
|
|
337
|
-
let savedShippingOrder: any = ''
|
|
338
|
-
/**
|
|
339
|
-
* Could potentially override important data
|
|
340
|
-
*/
|
|
341
|
-
if (foundReleaseGood.shippingOrder == null) {
|
|
342
|
-
savedShippingOrder = await tx.getRepository(ShippingOrder).save({
|
|
343
|
-
name: OrderNoGenerator.shippingOrder(),
|
|
344
|
-
shipName: exportInfo.shipName,
|
|
345
|
-
containerNo: exportInfo.containerNo,
|
|
346
|
-
containerArrivalDate: exportInfo.containerArrivalDate,
|
|
347
|
-
containerLeavingDate: exportInfo.containerLeavingDate,
|
|
348
|
-
status: ORDER_STATUS.PENDING,
|
|
349
|
-
domain,
|
|
350
|
-
bizplace: foundDeliveryOrder.bizplace,
|
|
351
|
-
creator: user,
|
|
352
|
-
updater: user
|
|
353
|
-
})
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
/**
|
|
357
|
-
* @oscarchuaweiwen-fsd
|
|
358
|
-
* I think the expectation here is to update instead of save
|
|
359
|
-
* Should use .update instead of .save as it will override data that was not meant to be updated
|
|
360
|
-
* example:
|
|
361
|
-
*
|
|
362
|
-
* savedShippingOrder = await tx.getRepository(ShippingOrder).update({
|
|
363
|
-
* shipName: exportInfo.shipName,
|
|
364
|
-
* containerNo: exportInfo.containerNo,
|
|
365
|
-
* containerArrivalDate: exportInfo.containerArrivalDate,
|
|
366
|
-
* containerLeavingDate: exportInfo.containerLeavingDate,
|
|
367
|
-
* status: ORDER_STATUS.PENDING,
|
|
368
|
-
* updater: user
|
|
369
|
-
* })
|
|
370
|
-
*
|
|
371
|
-
* Unless the intention was not to update but to insert
|
|
372
|
-
*/
|
|
373
|
-
savedShippingOrder = await tx.getRepository(ShippingOrder).save({
|
|
374
|
-
...foundReleaseGood.shippingOrder,
|
|
375
|
-
name: OrderNoGenerator.shippingOrder(),
|
|
376
|
-
shipName: exportInfo.shipName,
|
|
377
|
-
containerNo: exportInfo.containerNo,
|
|
378
|
-
containerArrivalDate: exportInfo.containerArrivalDate,
|
|
379
|
-
containerLeavingDate: exportInfo.containerLeavingDate,
|
|
380
|
-
status: ORDER_STATUS.PENDING,
|
|
381
|
-
domain,
|
|
382
|
-
bizplace: foundDeliveryOrder.bizplace,
|
|
383
|
-
creator: user,
|
|
384
|
-
updater: user
|
|
385
|
-
})
|
|
386
|
-
/** */
|
|
387
|
-
|
|
388
|
-
exportInfo = savedShippingOrder
|
|
389
|
-
foundReleaseGood.exportOption = true
|
|
390
|
-
} else {
|
|
391
|
-
foundReleaseGood.exportOption = false
|
|
392
|
-
foundReleaseGood.collectionOrderNo = ''
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
await tx.getRepository(ReleaseGood).save({
|
|
396
|
-
...foundReleaseGood,
|
|
397
|
-
shippingOrder: {
|
|
398
|
-
...exportInfo
|
|
399
|
-
},
|
|
400
|
-
collectionOrderNo: orderInfo.coNo
|
|
401
|
-
})
|
|
402
|
-
|
|
403
|
-
await tx.getRepository(DeliveryOrder).save({
|
|
404
|
-
...foundDeliveryOrder,
|
|
405
|
-
transportDriver,
|
|
406
|
-
palletQty: orderInfo?.totalPalletQty,
|
|
407
|
-
transportVehicle,
|
|
408
|
-
contactPointRefId: foundCP?.id || null,
|
|
409
|
-
otherDriver: orderInfo?.otherDriver || null,
|
|
410
|
-
truckNo: orderInfo?.otherTruck || orderInfo?.ownTruck,
|
|
411
|
-
to: foundCP?.address,
|
|
412
|
-
deliveryDate: orderInfo?.deliveryDate,
|
|
413
|
-
deliveryDateTime: new Date(),
|
|
414
|
-
remark: orderInfo?.remark,
|
|
415
|
-
status: deliveryOrderStatus,
|
|
416
|
-
reusablePallet: orderInfo?.reusablePallet,
|
|
417
|
-
attentionTo: shippingOrderInfo?.attentionTo || null,
|
|
418
|
-
attentionCompany: shippingOrderInfo?.attentionCompany || null,
|
|
419
|
-
city: shippingOrderInfo?.city || null,
|
|
420
|
-
state: shippingOrderInfo?.state || null,
|
|
421
|
-
postalCode: shippingOrderInfo?.postalCode || null,
|
|
422
|
-
country: shippingOrderInfo?.country || null,
|
|
423
|
-
phone1: shippingOrderInfo?.phone1 || null,
|
|
424
|
-
deliveryAddress1: shippingOrderInfo?.deliveryAddress1 || null,
|
|
425
|
-
billingAddress: shippingOrderInfo?.billingAddress || null,
|
|
426
|
-
billingCountry: shippingOrderInfo?.billingCountry || null,
|
|
427
|
-
billingPostalCode: shippingOrderInfo?.billingPostalCode || null,
|
|
428
|
-
billingState: shippingOrderInfo?.billingState || null,
|
|
429
|
-
billingCity: shippingOrderInfo?.billingCity || null,
|
|
430
|
-
updater: user
|
|
431
|
-
})
|
|
432
|
-
|
|
433
|
-
return foundDeliveryOrder
|
|
434
|
-
} catch (e) {
|
|
435
|
-
throw e
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
/** */
|
|
439
|
-
|
|
440
|
-
@Directive('@transaction')
|
|
441
|
-
@Mutation(returns => DeliveryOrder)
|
|
442
|
-
async dispatchManualDeliveryOrder(
|
|
443
|
-
@Ctx() context: ResolverContext,
|
|
444
|
-
@Arg('orderInfo', type => DeliveryOrderPatch, { nullable: true }) orderInfo?: DeliveryOrderPatch,
|
|
445
|
-
@Arg('orderItems', type => [OrderInventoryPatch], { nullable: true }) orderItems?: OrderInventoryPatch[]
|
|
446
|
-
): Promise<DeliveryOrder> {
|
|
447
|
-
try {
|
|
448
|
-
const { tx, domain, user } = context.state
|
|
449
|
-
const foundDeliveryOrder: DeliveryOrder = await tx.getRepository(DeliveryOrder).findOne({
|
|
450
|
-
where: { domain: { id: domain.id }, name: orderInfo.name },
|
|
451
|
-
relations: ['transportVehicle', 'bizplace']
|
|
452
|
-
})
|
|
453
|
-
|
|
454
|
-
if (!foundDeliveryOrder) throw new Error(`Delivery order doesn't exists.`)
|
|
455
|
-
if (foundDeliveryOrder.status === ORDER_STATUS.PENDING_CANCEL)
|
|
456
|
-
throw new Error('Release order is pending for cancel')
|
|
457
|
-
|
|
458
|
-
let deliveryOrderStatus = foundDeliveryOrder.status
|
|
459
|
-
let orderInventories: OrderInventory[]
|
|
460
|
-
orderInventories = await tx.getRepository(OrderInventory).find({
|
|
461
|
-
where: { domain: { id: domain.id }, deliveryOrder: { id: foundDeliveryOrder.id } },
|
|
462
|
-
relations: ['product']
|
|
463
|
-
})
|
|
464
|
-
|
|
465
|
-
// if there is other destination value, create a new contact point
|
|
466
|
-
let foundCP: any = {}
|
|
467
|
-
if (orderInfo?.otherDestination) {
|
|
468
|
-
foundCP = {
|
|
469
|
-
domain,
|
|
470
|
-
name: orderInfo.contactName,
|
|
471
|
-
bizplace: foundDeliveryOrder.bizplace,
|
|
472
|
-
address: orderInfo.otherDestination,
|
|
473
|
-
billingAddress: orderInfo.billingAddress,
|
|
474
|
-
phone: orderInfo.contactPhone,
|
|
475
|
-
email: orderInfo.contactEmail,
|
|
476
|
-
companyName: orderInfo.contactCompany,
|
|
477
|
-
type: orderInfo.contactType,
|
|
478
|
-
creator: user
|
|
479
|
-
}
|
|
480
|
-
foundCP = await tx.getRepository(ContactPoint).save(foundCP)
|
|
481
|
-
} else {
|
|
482
|
-
foundCP = await tx.getRepository(ContactPoint).findOne({
|
|
483
|
-
where: { domain: { id: domain.id }, id: orderInfo.contactPoint }
|
|
484
|
-
})
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
let transportDriver: TransportDriver = null
|
|
488
|
-
let transportVehicle: TransportVehicle = null
|
|
489
|
-
if (orderInfo?.ownDriver) {
|
|
490
|
-
transportDriver = await tx.getRepository(TransportDriver).findOne({
|
|
491
|
-
where: { domain: { id: domain.id }, name: orderInfo.ownDriver }
|
|
492
|
-
})
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
if (orderInfo?.ownTruck) {
|
|
496
|
-
transportVehicle = await tx.getRepository(TransportVehicle).findOne({
|
|
497
|
-
where: { domain: { id: domain.id }, name: orderInfo.ownTruck }
|
|
498
|
-
})
|
|
499
|
-
|
|
500
|
-
await tx.getRepository(TransportVehicle).save({
|
|
501
|
-
...transportVehicle,
|
|
502
|
-
status: TRUCK_STATUS.IN_USE,
|
|
503
|
-
updater: user
|
|
504
|
-
})
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
orderInventories = orderInventories.map((orderInventory: OrderInventory) => {
|
|
508
|
-
const remark = orderItems.find(
|
|
509
|
-
(item: any) => item.productId === orderInventory.product.id && item.batchId === orderInventory.batchId
|
|
510
|
-
).remark
|
|
511
|
-
|
|
512
|
-
// add remark if found, else remain existing remark
|
|
513
|
-
if (remark) {
|
|
514
|
-
orderInventory.remark = remark
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
// update status of DO and order inventory to DELIVERING if current status is READY_TO_DISPATCH
|
|
518
|
-
if (foundDeliveryOrder.status === ORDER_STATUS.READY_TO_DISPATCH) {
|
|
519
|
-
deliveryOrderStatus = ORDER_STATUS.DELIVERING
|
|
520
|
-
orderInventory.status = ORDER_STATUS.DELIVERING
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
return orderInventory
|
|
524
|
-
})
|
|
525
|
-
await tx.getRepository(OrderInventory).save(orderInventories)
|
|
526
|
-
|
|
527
|
-
await tx.getRepository(DeliveryOrder).save({
|
|
528
|
-
...foundDeliveryOrder,
|
|
529
|
-
transportDriver,
|
|
530
|
-
transportVehicle,
|
|
531
|
-
contactPointRefId: foundCP.id || null,
|
|
532
|
-
otherDriver: orderInfo?.otherDriver || null,
|
|
533
|
-
truckNo: orderInfo?.otherTruck || orderInfo?.ownTruck,
|
|
534
|
-
to: foundCP.address,
|
|
535
|
-
deliveryDate: orderInfo.deliveryDate,
|
|
536
|
-
deliveryDateTime: new Date(),
|
|
537
|
-
remark: orderInfo.remark,
|
|
538
|
-
status: deliveryOrderStatus,
|
|
539
|
-
reusablePallet: orderInfo.reusablePallet,
|
|
540
|
-
updater: user
|
|
541
|
-
})
|
|
542
|
-
|
|
543
|
-
return foundDeliveryOrder
|
|
544
|
-
} catch (e) {
|
|
545
|
-
throw e
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
@Directive('@transaction')
|
|
550
|
-
@Mutation(returns => DeliveryOrder)
|
|
551
|
-
async sendDeliveryOrder(
|
|
552
|
-
@Ctx() context: ResolverContext,
|
|
553
|
-
@Arg('orderInfo', type => DeliveryOrderPatch, { nullable: true }) orderInfo?: DeliveryOrderPatch,
|
|
554
|
-
@Arg('orderItems', type => [OrderInventoryPatch], { nullable: true }) orderItems?: OrderInventoryPatch[]
|
|
555
|
-
): Promise<DeliveryOrder> {
|
|
556
|
-
try {
|
|
557
|
-
const { tx, domain, user } = context.state
|
|
558
|
-
const foundDeliveryOrder: DeliveryOrder = await tx.getRepository(DeliveryOrder).findOne({
|
|
559
|
-
where: { domain: { id: domain.id }, name: orderInfo.name },
|
|
560
|
-
relations: ['transportVehicle', 'bizplace']
|
|
561
|
-
})
|
|
562
|
-
|
|
563
|
-
if (!foundDeliveryOrder) throw new Error(`Delivery order doesn't exists.`)
|
|
564
|
-
if (foundDeliveryOrder.status === ORDER_STATUS.PENDING_CANCEL)
|
|
565
|
-
throw new Error('Release order is pending for cancel')
|
|
566
|
-
|
|
567
|
-
let deliveryOrderStatus = foundDeliveryOrder.status
|
|
568
|
-
let orderInventories: OrderInventory[]
|
|
569
|
-
orderInventories = await tx.getRepository(OrderInventory).find({
|
|
570
|
-
where: { domain: { id: domain.id }, deliveryOrder: { id: foundDeliveryOrder.id } },
|
|
571
|
-
relations: ['inventory', 'inventory.product', 'inventory.reusablePallet']
|
|
572
|
-
})
|
|
573
|
-
|
|
574
|
-
orderInventories = orderInventories.map((orderInventory: OrderInventory) => {
|
|
575
|
-
const inventory: Inventory = orderInventory.inventory
|
|
576
|
-
const product: Product = inventory.product
|
|
577
|
-
const foundItem = inventory.reusablePallet
|
|
578
|
-
? orderItems.filter(
|
|
579
|
-
(item: any) =>
|
|
580
|
-
item.productName === `${product.name} (${product.description})` &&
|
|
581
|
-
item.batchId === orderInventory.batchId &&
|
|
582
|
-
item.pallet === inventory.reusablePallet.name
|
|
583
|
-
)
|
|
584
|
-
: orderItems.filter(
|
|
585
|
-
(item: any) =>
|
|
586
|
-
item.productName === `${product.name} (${product.description})` &&
|
|
587
|
-
item.batchId === orderInventory.batchId
|
|
588
|
-
)
|
|
589
|
-
if (foundItem[0].remark !== '') orderInventory.remark = foundItem[0].remark
|
|
590
|
-
return orderInventory
|
|
591
|
-
})
|
|
592
|
-
await tx.getRepository(OrderInventory).save(orderInventories)
|
|
593
|
-
|
|
594
|
-
let transportDriver: TransportDriver = null
|
|
595
|
-
let transportVehicle: TransportVehicle = null
|
|
596
|
-
if (orderInfo?.ownDriver) {
|
|
597
|
-
transportDriver = await tx.getRepository(TransportDriver).findOne({
|
|
598
|
-
where: { domain: { id: domain.id }, name: orderInfo.ownDriver }
|
|
599
|
-
})
|
|
600
|
-
}
|
|
601
|
-
|
|
602
|
-
if (orderInfo?.ownTruck) {
|
|
603
|
-
transportVehicle = await tx.getRepository(TransportVehicle).findOne({
|
|
604
|
-
where: { domain: { id: domain.id }, name: orderInfo.ownTruck }
|
|
605
|
-
})
|
|
606
|
-
|
|
607
|
-
await tx.getRepository(TransportVehicle).save({
|
|
608
|
-
...transportVehicle,
|
|
609
|
-
status: TRUCK_STATUS.IN_USE,
|
|
610
|
-
updater: user
|
|
611
|
-
})
|
|
612
|
-
}
|
|
613
|
-
|
|
614
|
-
if (foundDeliveryOrder.status === ORDER_STATUS.READY_TO_DISPATCH) {
|
|
615
|
-
// update status to DELIVERING if current status is READY_TO_DISPATCH
|
|
616
|
-
deliveryOrderStatus = ORDER_STATUS.DELIVERING
|
|
617
|
-
}
|
|
618
|
-
|
|
619
|
-
await tx.getRepository(DeliveryOrder).save({
|
|
620
|
-
...foundDeliveryOrder,
|
|
621
|
-
transportDriver,
|
|
622
|
-
transportVehicle,
|
|
623
|
-
otherDriver: orderInfo?.otherDriver || null,
|
|
624
|
-
truckNo: orderInfo?.otherTruck || orderInfo?.ownTruck,
|
|
625
|
-
to: foundDeliveryOrder.bizplace.address,
|
|
626
|
-
deliveryDate: orderInfo.deliveryDate,
|
|
627
|
-
remark: orderInfo.remark,
|
|
628
|
-
status: deliveryOrderStatus,
|
|
629
|
-
reusablePallet: orderInfo.reusablePallet,
|
|
630
|
-
updater: user
|
|
631
|
-
})
|
|
632
|
-
|
|
633
|
-
return foundDeliveryOrder
|
|
634
|
-
} catch (e) {
|
|
635
|
-
throw e
|
|
636
|
-
}
|
|
637
|
-
return
|
|
638
|
-
}
|
|
639
|
-
|
|
640
|
-
@Directive('@transaction')
|
|
641
|
-
@Mutation(returns => DeliveryOrder)
|
|
642
|
-
async rejectDeliveryOrder(
|
|
643
|
-
@Arg('name') name: string,
|
|
644
|
-
@Arg('patch', type => DeliveryOrderPatch) patch: DeliveryOrderPatch,
|
|
645
|
-
@Ctx() context: ResolverContext
|
|
646
|
-
): Promise<DeliveryOrder> {
|
|
647
|
-
try {
|
|
648
|
-
const { tx, domain, user } = context.state
|
|
649
|
-
|
|
650
|
-
const deliveryOrder: DeliveryOrder = await tx.getRepository(DeliveryOrder).findOne({
|
|
651
|
-
where: { domain: { id: domain.id }, name }
|
|
652
|
-
})
|
|
653
|
-
|
|
654
|
-
if (!deliveryOrder) throw new Error(`Delivery order doesn't exists.`)
|
|
655
|
-
if (deliveryOrder.status !== ORDER_STATUS.PENDING_RECEIVE) throw new Error(`Status is not receivable.`)
|
|
656
|
-
|
|
657
|
-
await tx.getRepository(DeliveryOrder).save({
|
|
658
|
-
...deliveryOrder,
|
|
659
|
-
status: ORDER_STATUS.READY_TO_DISPATCH,
|
|
660
|
-
updater: user
|
|
661
|
-
})
|
|
662
|
-
|
|
663
|
-
return deliveryOrder
|
|
664
|
-
} catch (e) {
|
|
665
|
-
throw e
|
|
666
|
-
}
|
|
667
|
-
}
|
|
668
|
-
|
|
669
|
-
@Directive('@transaction')
|
|
670
|
-
@Mutation(returns => DeliveryOrder)
|
|
671
|
-
async submitGoodsDeliveryNote(
|
|
672
|
-
@Ctx() context: ResolverContext,
|
|
673
|
-
@Arg('name') name: string,
|
|
674
|
-
@Arg('file', type => GraphQLUpload, { nullable: true }) file?: FileUpload
|
|
675
|
-
): Promise<DeliveryOrder> {
|
|
676
|
-
const { tx, domain, user } = context.state
|
|
677
|
-
|
|
678
|
-
const foundDO: DeliveryOrder = await tx.getRepository(DeliveryOrder).findOne({
|
|
679
|
-
where: { domain: { id: domain.id }, name },
|
|
680
|
-
relations: ['bizplace']
|
|
681
|
-
})
|
|
682
|
-
|
|
683
|
-
if (!foundDO) throw new Error(`DO doesn't exists.`)
|
|
684
|
-
|
|
685
|
-
const foundAttachment: Attachment = await tx.getRepository(Attachment).findOne({
|
|
686
|
-
where: { domain: { id: domain.id }, refBy: foundDO.id }
|
|
687
|
-
})
|
|
688
|
-
|
|
689
|
-
const attachment = {
|
|
690
|
-
refType: 'DO',
|
|
691
|
-
refBy: foundDO.id,
|
|
692
|
-
file: file,
|
|
693
|
-
category: 'DO' /* TODO use refType */
|
|
694
|
-
}
|
|
695
|
-
|
|
696
|
-
if (!foundAttachment) {
|
|
697
|
-
await createAttachment(null, { attachment }, context)
|
|
698
|
-
} else {
|
|
699
|
-
const id = foundAttachment.id
|
|
700
|
-
await deleteAttachment(null, { id }, context)
|
|
701
|
-
await createAttachment(null, { attachment }, context)
|
|
702
|
-
}
|
|
703
|
-
|
|
704
|
-
return await tx.getRepository(DeliveryOrder).save({
|
|
705
|
-
...foundDO,
|
|
706
|
-
status: ORDER_STATUS.DONE,
|
|
707
|
-
updater: user
|
|
708
|
-
})
|
|
709
|
-
}
|
|
710
|
-
}
|
|
711
|
-
|
|
712
|
-
export async function createDeliveryOrder(
|
|
713
|
-
orderInfo: any,
|
|
714
|
-
customerBizplace: Bizplace,
|
|
715
|
-
targetInventories: (OrderInventory | NewOrderInventory)[],
|
|
716
|
-
file: FileUpload[],
|
|
717
|
-
domain: Domain,
|
|
718
|
-
user: User,
|
|
719
|
-
tx?: EntityManager
|
|
720
|
-
): Promise<DeliveryOrder> {
|
|
721
|
-
const bizplaceRepo: Repository<Bizplace> = tx?.getRepository(Bizplace) || getRepository(Bizplace)
|
|
722
|
-
const deliveryOrderRepo: Repository<DeliveryOrder> = tx?.getRepository(DeliveryOrder) || getRepository(DeliveryOrder)
|
|
723
|
-
const productRepo: Repository<Product> = tx?.getRepository(Product) || getRepository(Product)
|
|
724
|
-
const transportVehicleRepo: Repository<TransportVehicle> =
|
|
725
|
-
tx?.getRepository(TransportVehicle) || getRepository(TransportVehicle)
|
|
726
|
-
const transportDriverRepo: Repository<TransportDriver> =
|
|
727
|
-
tx?.getRepository(TransportDriver) || getRepository(TransportDriver)
|
|
728
|
-
const orderInventoryRepo: Repository<OrderInventory> =
|
|
729
|
-
tx?.getRepository(OrderInventory) || getRepository(OrderInventory)
|
|
730
|
-
const settingRepo: Repository<Setting> = tx?.getRepository(Setting) || getRepository(Setting)
|
|
731
|
-
|
|
732
|
-
const foundBizplace: Bizplace = await bizplaceRepo.findOne({
|
|
733
|
-
where: {
|
|
734
|
-
id: customerBizplace.id,
|
|
735
|
-
name: customerBizplace.name
|
|
736
|
-
}
|
|
737
|
-
})
|
|
738
|
-
|
|
739
|
-
if (!foundBizplace) throw new Error(`customer not found`)
|
|
740
|
-
|
|
741
|
-
// #1 find order number setting and set as DO name
|
|
742
|
-
const doNoSetting: Setting = await settingRepo.findOne({
|
|
743
|
-
where: {
|
|
744
|
-
domain: { id: domain.id },
|
|
745
|
-
name: ORDER_NUMBER_SETTING_KEY.DO_NUMBER_RULE
|
|
746
|
-
}
|
|
747
|
-
})
|
|
748
|
-
|
|
749
|
-
let orderNo: string = ''
|
|
750
|
-
|
|
751
|
-
if (doNoSetting) {
|
|
752
|
-
orderNo = await generateId({ domain, type: ORDER_NUMBER_RULE_TYPE.DO_NUMBER, seed: {} })
|
|
753
|
-
} else {
|
|
754
|
-
orderNo = OrderNoGenerator.deliveryOrder()
|
|
755
|
-
}
|
|
756
|
-
|
|
757
|
-
// #2 update truck vehicle status to IN_USE (only if using warehouse truck)
|
|
758
|
-
let transportVehicle: TransportVehicle = null
|
|
759
|
-
let transportDriver: TransportDriver = null
|
|
760
|
-
|
|
761
|
-
if (!orderInfo.ownCollection) {
|
|
762
|
-
transportVehicle = await transportVehicleRepo.findOne({
|
|
763
|
-
where: {
|
|
764
|
-
domain: { id: domain.id },
|
|
765
|
-
id: orderInfo.transportVehicle
|
|
766
|
-
}
|
|
767
|
-
})
|
|
768
|
-
|
|
769
|
-
transportDriver = await transportDriverRepo.findOne({
|
|
770
|
-
where: {
|
|
771
|
-
domain: { id: domain.id },
|
|
772
|
-
id: orderInfo.transportDriver
|
|
773
|
-
}
|
|
774
|
-
})
|
|
775
|
-
|
|
776
|
-
transportVehicle = {
|
|
777
|
-
...transportVehicle,
|
|
778
|
-
status: TRUCK_STATUS.IN_USE,
|
|
779
|
-
updater: user
|
|
780
|
-
}
|
|
781
|
-
|
|
782
|
-
await transportVehicleRepo.save(transportVehicle)
|
|
783
|
-
}
|
|
784
|
-
|
|
785
|
-
// #3 save other destination info in Contact Point if there's any
|
|
786
|
-
let foundCP: ContactPoint = {} as any
|
|
787
|
-
if (orderInfo?.otherDestination) {
|
|
788
|
-
foundCP = {
|
|
789
|
-
domain,
|
|
790
|
-
name: orderInfo.contactName,
|
|
791
|
-
bizplace: foundBizplace,
|
|
792
|
-
address: orderInfo.otherDestination,
|
|
793
|
-
billingAddress: orderInfo.otherBillingAddress ? orderInfo.otherBillingAddress : orderInfo.otherDestination,
|
|
794
|
-
phone: orderInfo.contactPhone || '-',
|
|
795
|
-
email: orderInfo.contactEmail || '-',
|
|
796
|
-
companyName: orderInfo.contactCompany || '-',
|
|
797
|
-
type: orderInfo.contactType,
|
|
798
|
-
creator: user,
|
|
799
|
-
updater: user
|
|
800
|
-
} as any
|
|
801
|
-
foundCP = await tx.getRepository(ContactPoint).save(foundCP)
|
|
802
|
-
} else {
|
|
803
|
-
foundCP = await tx.getRepository(ContactPoint).findOne({
|
|
804
|
-
where: { domain: { id: domain.id }, id: orderInfo.contactPointRefId, bizplace: foundBizplace }
|
|
805
|
-
})
|
|
806
|
-
}
|
|
807
|
-
|
|
808
|
-
// #4 save the delivery order info
|
|
809
|
-
let totalPalletQty = 0
|
|
810
|
-
targetInventories.forEach(oi => (totalPalletQty += oi.palletQty))
|
|
811
|
-
|
|
812
|
-
let deliveryOrder: any = {
|
|
813
|
-
domain,
|
|
814
|
-
name: orderNo,
|
|
815
|
-
refNo: orderInfo.refNo,
|
|
816
|
-
bizplace: foundBizplace,
|
|
817
|
-
deliveryDate: orderInfo.deliveryDate,
|
|
818
|
-
ownCollection: orderInfo.ownCollection,
|
|
819
|
-
truckNo: orderInfo.truckNo,
|
|
820
|
-
palletQty: totalPalletQty,
|
|
821
|
-
status: ORDER_STATUS.READY_TO_DISPATCH,
|
|
822
|
-
contactPointRefId: foundCP.id,
|
|
823
|
-
remark: orderInfo.remark,
|
|
824
|
-
transportDriver,
|
|
825
|
-
transportVehicle,
|
|
826
|
-
otherDriver: orderInfo.otherDriver,
|
|
827
|
-
creator: user,
|
|
828
|
-
updater: user
|
|
829
|
-
}
|
|
830
|
-
deliveryOrder = <DeliveryOrder>await deliveryOrderRepo.save(deliveryOrder)
|
|
831
|
-
|
|
832
|
-
// #5 save order inventories
|
|
833
|
-
targetInventories = await Promise.all(
|
|
834
|
-
targetInventories.map(async (orderInventory: OrderInventory) => {
|
|
835
|
-
const product: Product = await productRepo.findOne({
|
|
836
|
-
where: {
|
|
837
|
-
id: orderInventory.product.id
|
|
838
|
-
}
|
|
839
|
-
})
|
|
840
|
-
|
|
841
|
-
if (!product) throw new Error(`product not found`)
|
|
842
|
-
return {
|
|
843
|
-
...orderInventory,
|
|
844
|
-
domain,
|
|
845
|
-
product,
|
|
846
|
-
name: OrderNoGenerator.orderInventory(),
|
|
847
|
-
bizplace: foundBizplace,
|
|
848
|
-
status: ORDER_INVENTORY_STATUS.READY_TO_DISPATCH,
|
|
849
|
-
type: ORDER_TYPES.DELIVERY,
|
|
850
|
-
deliveryOrder,
|
|
851
|
-
creator: user,
|
|
852
|
-
updater: user
|
|
853
|
-
}
|
|
854
|
-
})
|
|
855
|
-
)
|
|
856
|
-
await orderInventoryRepo.save(targetInventories as any)
|
|
857
|
-
|
|
858
|
-
// if (file?.length) {
|
|
859
|
-
// const attachments: Attachment[] = file.map(attachment => {
|
|
860
|
-
// return {
|
|
861
|
-
// file: attachment,
|
|
862
|
-
// refType: ATTACHMENT_TYPE.GAN,
|
|
863
|
-
// refBy: deliveryOrder.id,
|
|
864
|
-
// category: ATTACHMENT_TYPE.GAN /* TODO use refType */
|
|
865
|
-
// }
|
|
866
|
-
// })
|
|
867
|
-
// await createAttachments(_, { attachments }, context)
|
|
868
|
-
// }
|
|
869
|
-
|
|
870
|
-
return deliveryOrder
|
|
871
|
-
}
|
|
872
|
-
|
|
873
|
-
export async function generateDeliveryOrder(
|
|
874
|
-
orderInfo: DeliveryOrder | DeliveryOrderPatch,
|
|
875
|
-
targetInventories: OrderInventory[],
|
|
876
|
-
customerBizplace: Bizplace,
|
|
877
|
-
releaseGood: ReleaseGood,
|
|
878
|
-
domain: Domain,
|
|
879
|
-
user: User,
|
|
880
|
-
tx?: EntityManager
|
|
881
|
-
): Promise<DeliveryOrder> {
|
|
882
|
-
/**
|
|
883
|
-
* 1. Validation for creating DO - data existing
|
|
884
|
-
*/
|
|
885
|
-
const deliveryOrderRepo: Repository<DeliveryOrder> = tx?.getRepository(DeliveryOrder) || getRepository(DeliveryOrder)
|
|
886
|
-
const transportVehicleRepo: Repository<TransportVehicle> =
|
|
887
|
-
tx?.getRepository(TransportVehicle) || getRepository(TransportVehicle)
|
|
888
|
-
const transportDriverRepo: Repository<TransportDriver> =
|
|
889
|
-
tx?.getRepository(TransportDriver) || getRepository(TransportDriver)
|
|
890
|
-
const orderInventoryRepo: Repository<OrderInventory> =
|
|
891
|
-
tx?.getRepository(OrderInventory) || getRepository(OrderInventory)
|
|
892
|
-
const settingRepo: Repository<Setting> = tx?.getRepository(Setting) || getRepository(Setting)
|
|
893
|
-
|
|
894
|
-
let transportVehicle: TransportVehicle = null
|
|
895
|
-
if (orderInfo?.truckNo) {
|
|
896
|
-
transportVehicle = await transportVehicleRepo.findOne({
|
|
897
|
-
where: { domain: { id: domain.id }, name: orderInfo.truckNo }
|
|
898
|
-
})
|
|
899
|
-
}
|
|
900
|
-
|
|
901
|
-
let transportDriver: TransportDriver = null
|
|
902
|
-
if (orderInfo?.transportDriver) {
|
|
903
|
-
transportDriver = await transportDriverRepo.findOne({
|
|
904
|
-
where: { domain: { id: domain.id }, id: orderInfo.transportDriver.id }
|
|
905
|
-
})
|
|
906
|
-
}
|
|
907
|
-
|
|
908
|
-
const doNoSetting: Setting = await settingRepo.findOne({
|
|
909
|
-
where: {
|
|
910
|
-
domain: { id: domain.id },
|
|
911
|
-
name: ORDER_NUMBER_SETTING_KEY.DO_NUMBER_RULE
|
|
912
|
-
}
|
|
913
|
-
})
|
|
914
|
-
|
|
915
|
-
let orderNo: string = ''
|
|
916
|
-
|
|
917
|
-
if (doNoSetting) {
|
|
918
|
-
orderNo = await generateId({ domain, type: ORDER_NUMBER_RULE_TYPE.DO_NUMBER, seed: {} })
|
|
919
|
-
} else {
|
|
920
|
-
orderNo = OrderNoGenerator.deliveryOrder()
|
|
921
|
-
}
|
|
922
|
-
|
|
923
|
-
// insert shipping information from r/o to d/o
|
|
924
|
-
|
|
925
|
-
let deliveryOrder: any = {
|
|
926
|
-
domain,
|
|
927
|
-
name: orderNo,
|
|
928
|
-
bizplace: customerBizplace,
|
|
929
|
-
releaseGood,
|
|
930
|
-
refNo: releaseGood.refNo,
|
|
931
|
-
ownCollection: orderInfo.ownCollection,
|
|
932
|
-
truckNo: orderInfo?.truckNo || null,
|
|
933
|
-
palletQty: orderInfo?.palletQty || null,
|
|
934
|
-
transportVehicle,
|
|
935
|
-
transportDriver,
|
|
936
|
-
status: ORDER_STATUS.READY_TO_DISPATCH,
|
|
937
|
-
contactPointRefId: orderInfo?.contactPointRefId || null,
|
|
938
|
-
attentionTo: releaseGood?.attentionTo || null,
|
|
939
|
-
attentionCompany: releaseGood?.attentionCompany || null,
|
|
940
|
-
city: releaseGood?.city || null,
|
|
941
|
-
state: releaseGood?.state || null,
|
|
942
|
-
postalCode: releaseGood?.postalCode || null,
|
|
943
|
-
country: releaseGood?.country || null,
|
|
944
|
-
phone1: releaseGood?.phone1 || null,
|
|
945
|
-
deliveryAddress1: releaseGood?.deliveryAddress1 || null,
|
|
946
|
-
billingAddress: releaseGood?.billingAddress || null,
|
|
947
|
-
billingCountry: releaseGood?.billingCountry || null,
|
|
948
|
-
billingPostalCode: releaseGood?.billingPostalCode || null,
|
|
949
|
-
billingState: releaseGood?.billingState || null,
|
|
950
|
-
billingCity: releaseGood?.billingCity || null,
|
|
951
|
-
creator: user,
|
|
952
|
-
updater: user
|
|
953
|
-
}
|
|
954
|
-
|
|
955
|
-
deliveryOrder = <DeliveryOrder>await deliveryOrderRepo.save(deliveryOrder)
|
|
956
|
-
|
|
957
|
-
targetInventories = targetInventories.map((targetInventory: OrderInventory) => {
|
|
958
|
-
return {
|
|
959
|
-
...targetInventory,
|
|
960
|
-
deliveryOrder,
|
|
961
|
-
updater: user
|
|
962
|
-
}
|
|
963
|
-
})
|
|
964
|
-
await orderInventoryRepo.save(targetInventories)
|
|
965
|
-
|
|
966
|
-
return deliveryOrder
|
|
967
|
-
}
|