@things-factory/sales-base 4.3.129 → 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/constants/order.js +5 -1
- package/dist-server/constants/order.js.map +1 -1
- package/dist-server/service/arrival-notice/arrival-notice.js +5 -0
- package/dist-server/service/arrival-notice/arrival-notice.js.map +1 -1
- package/dist-server/service/delivery-order/delivery-order-mutation.js +29 -27
- package/dist-server/service/delivery-order/delivery-order-mutation.js.map +1 -1
- package/dist-server/service/draft-release-good/draft-release-good-mutation.js +179 -168
- package/dist-server/service/draft-release-good/draft-release-good-mutation.js.map +1 -1
- package/dist-server/service/goods-receival-note/goods-receival-note-mutation.js +0 -24
- package/dist-server/service/goods-receival-note/goods-receival-note-mutation.js.map +1 -1
- package/dist-server/service/purchase-order/purchase-order-mutation.js +16 -1
- package/dist-server/service/purchase-order/purchase-order-mutation.js.map +1 -1
- package/dist-server/service/purchase-order/purchase-order-types.js +18 -2
- package/dist-server/service/purchase-order/purchase-order-types.js.map +1 -1
- package/dist-server/service/purchase-order/purchase-order.js +23 -3
- package/dist-server/service/purchase-order/purchase-order.js.map +1 -1
- package/dist-server/service/release-good/release-good-mutation.js +0 -17
- package/dist-server/service/release-good/release-good-mutation.js.map +1 -1
- package/dist-server/service/release-good/release-good.js +5 -0
- package/dist-server/service/release-good/release-good.js.map +1 -1
- package/package.json +14 -15
- package/server/constants/order.ts +5 -0
- package/server/service/arrival-notice/arrival-notice.ts +4 -0
- package/server/service/delivery-order/delivery-order-mutation.ts +30 -30
- package/server/service/draft-release-good/draft-release-good-mutation.ts +221 -210
- package/server/service/goods-receival-note/goods-receival-note-mutation.ts +0 -27
- package/server/service/purchase-order/purchase-order-mutation.ts +22 -10
- package/server/service/purchase-order/purchase-order-types.ts +16 -2
- package/server/service/purchase-order/purchase-order.ts +23 -5
- package/server/service/release-good/release-good-mutation.ts +3 -23
- package/server/service/release-good/release-good.ts +4 -0
- package/LICENSE.md +0 -21
package/package.json
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@things-factory/sales-base",
|
|
3
|
-
"version": "4.3.
|
|
3
|
+
"version": "4.3.132",
|
|
4
4
|
"main": "dist-server/index.js",
|
|
5
5
|
"browser": "client/index.js",
|
|
6
6
|
"things-factory": true,
|
|
7
|
-
"license": "MIT",
|
|
8
7
|
"author": "",
|
|
9
8
|
"description": "Module to handle orders",
|
|
10
9
|
"publishConfig": {
|
|
@@ -24,18 +23,18 @@
|
|
|
24
23
|
"migration:create": "node ../../node_modules/typeorm/cli.js migration:create -d ./server/migrations"
|
|
25
24
|
},
|
|
26
25
|
"dependencies": {
|
|
27
|
-
"@things-factory/attachment-base": "^4.3.
|
|
28
|
-
"@things-factory/auth-base": "^4.3.
|
|
29
|
-
"@things-factory/biz-base": "^4.3.
|
|
30
|
-
"@things-factory/code-base": "^4.3.
|
|
31
|
-
"@things-factory/integration-accounting": "^4.3.
|
|
32
|
-
"@things-factory/integration-sftp": "^4.3.
|
|
33
|
-
"@things-factory/notification": "^4.3.
|
|
34
|
-
"@things-factory/product-base": "^4.3.
|
|
35
|
-
"@things-factory/setting-base": "^4.3.
|
|
36
|
-
"@things-factory/shell": "^4.3.
|
|
37
|
-
"@things-factory/transport-base": "^4.3.
|
|
38
|
-
"@things-factory/warehouse-base": "^4.3.
|
|
26
|
+
"@things-factory/attachment-base": "^4.3.131",
|
|
27
|
+
"@things-factory/auth-base": "^4.3.131",
|
|
28
|
+
"@things-factory/biz-base": "^4.3.131",
|
|
29
|
+
"@things-factory/code-base": "^4.3.131",
|
|
30
|
+
"@things-factory/integration-accounting": "^4.3.131",
|
|
31
|
+
"@things-factory/integration-sftp": "^4.3.131",
|
|
32
|
+
"@things-factory/notification": "^4.3.131",
|
|
33
|
+
"@things-factory/product-base": "^4.3.131",
|
|
34
|
+
"@things-factory/setting-base": "^4.3.131",
|
|
35
|
+
"@things-factory/shell": "^4.3.131",
|
|
36
|
+
"@things-factory/transport-base": "^4.3.131",
|
|
37
|
+
"@things-factory/warehouse-base": "^4.3.132"
|
|
39
38
|
},
|
|
40
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "4eb399665fdb2475691201409c7574bc95de3d95"
|
|
41
40
|
}
|
|
@@ -152,6 +152,10 @@ export class ArrivalNotice {
|
|
|
152
152
|
@Field({ nullable: true })
|
|
153
153
|
source: string
|
|
154
154
|
|
|
155
|
+
@Column({ nullable: true })
|
|
156
|
+
@Field({ nullable: true })
|
|
157
|
+
orderSourceType: string
|
|
158
|
+
|
|
155
159
|
@OneToOne(type => PurchaseOrder, { nullable: true })
|
|
156
160
|
@JoinColumn()
|
|
157
161
|
@Field(type => PurchaseOrder, { nullable: true })
|
|
@@ -3,11 +3,11 @@ import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'
|
|
|
3
3
|
import { EntityManager, getRepository, In, Repository } from 'typeorm'
|
|
4
4
|
|
|
5
5
|
import { Attachment, createAttachment, deleteAttachment } from '@things-factory/attachment-base'
|
|
6
|
-
import { User } from '@things-factory/auth-base'
|
|
6
|
+
import { ApplicationType, User } from '@things-factory/auth-base'
|
|
7
7
|
import { Bizplace, ContactPoint, getPermittedBizplaceIds } from '@things-factory/biz-base'
|
|
8
|
-
|
|
8
|
+
import { logger } from '@things-factory/env'
|
|
9
9
|
import { generateId } from '@things-factory/id-rule-base'
|
|
10
|
-
|
|
10
|
+
import { Account, AccountingAPI } from '@things-factory/integration-accounting'
|
|
11
11
|
import { Product } from '@things-factory/product-base'
|
|
12
12
|
import { Setting } from '@things-factory/setting-base'
|
|
13
13
|
import { Domain, ObjectRef } from '@things-factory/shell'
|
|
@@ -423,33 +423,33 @@ export class DeliveryOrderMutation {
|
|
|
423
423
|
updater: user
|
|
424
424
|
})
|
|
425
425
|
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
426
|
+
const orderSource: string = foundReleaseGood.source
|
|
427
|
+
switch (orderSource) {
|
|
428
|
+
case ApplicationType.XILNEX:
|
|
429
|
+
if (foundDeliveryOrder.status === ORDER_STATUS.READY_TO_DISPATCH) {
|
|
430
|
+
const xilnex: Account = await tx.getRepository(Account).findOne({
|
|
431
|
+
domain: foundDeliveryOrder.bizplace.domain,
|
|
432
|
+
status: 'active',
|
|
433
|
+
platform: 'xilnex'
|
|
434
|
+
})
|
|
435
|
+
|
|
436
|
+
if (xilnex) {
|
|
437
|
+
try {
|
|
438
|
+
await AccountingAPI.createTransferNote(xilnex, {
|
|
439
|
+
releaseGood: foundReleaseGood,
|
|
440
|
+
deliveryOrder: foundDeliveryOrder,
|
|
441
|
+
orderInventories
|
|
442
|
+
})
|
|
443
|
+
} catch (error) {
|
|
444
|
+
logger.error(`delivery-order-mutation[dispatchDeliveryOrder]: ${error}`)
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
break
|
|
449
|
+
|
|
450
|
+
default:
|
|
451
|
+
break
|
|
452
|
+
}
|
|
453
453
|
|
|
454
454
|
return foundDeliveryOrder
|
|
455
455
|
} catch (e) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { FileUpload, GraphQLUpload } from 'graphql-upload'
|
|
2
2
|
import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'
|
|
3
3
|
import { EntityManager, getConnection, getRepository, In, IsNull, Repository } from 'typeorm'
|
|
4
|
+
import { logger } from '@things-factory/env'
|
|
4
5
|
|
|
5
6
|
import { Attachment, createAttachments, deleteAttachmentsByRef } from '@things-factory/attachment-base'
|
|
6
7
|
import { User } from '@things-factory/auth-base'
|
|
@@ -185,240 +186,250 @@ export class DraftReleaseGoodMutation {
|
|
|
185
186
|
// @Arg('bizplaceId', type => String) bizplaceId: string
|
|
186
187
|
): Promise<boolean> {
|
|
187
188
|
const { domain, user, tx } = context.state
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
where: {
|
|
191
|
-
domain,
|
|
192
|
-
id: In(ids),
|
|
193
|
-
status: DRAFT_RELEASE_ORDER_STATUS.DRAFT
|
|
194
|
-
},
|
|
195
|
-
relations: [
|
|
196
|
-
'orderProducts',
|
|
197
|
-
'orderProducts.product',
|
|
198
|
-
'orderProducts.productBundle',
|
|
199
|
-
'shippingOrder',
|
|
200
|
-
'bizplace',
|
|
201
|
-
'bizplace.domain',
|
|
202
|
-
'domain',
|
|
203
|
-
'creator',
|
|
204
|
-
'updater'
|
|
205
|
-
]
|
|
206
|
-
})
|
|
207
|
-
if (updatableDraftOrders.length > 0) {
|
|
208
|
-
let createdReleaseGoods: ReleaseGood[] = []
|
|
209
|
-
const settingRepo: Repository<Setting> = tx?.getRepository(Setting) || getRepository(Setting)
|
|
210
|
-
|
|
211
|
-
const roNoSetting: Setting = await settingRepo.findOne({
|
|
189
|
+
try {
|
|
190
|
+
const updatableDraftOrders = await tx.getRepository(DraftReleaseGood).find({
|
|
212
191
|
where: {
|
|
213
192
|
domain,
|
|
214
|
-
|
|
215
|
-
|
|
193
|
+
id: In(ids),
|
|
194
|
+
status: DRAFT_RELEASE_ORDER_STATUS.DRAFT
|
|
195
|
+
},
|
|
196
|
+
relations: [
|
|
197
|
+
'orderProducts',
|
|
198
|
+
'orderProducts.product',
|
|
199
|
+
'orderProducts.productBundle',
|
|
200
|
+
'shippingOrder',
|
|
201
|
+
'bizplace',
|
|
202
|
+
'bizplace.domain',
|
|
203
|
+
'domain',
|
|
204
|
+
'creator',
|
|
205
|
+
'updater'
|
|
206
|
+
]
|
|
216
207
|
})
|
|
217
208
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
let foundPermittedBizplace: Bizplace
|
|
223
|
-
let companyBizplace: Bizplace
|
|
209
|
+
if (updatableDraftOrders.length > 0) {
|
|
210
|
+
let createdReleaseGoods: ReleaseGood[] = []
|
|
211
|
+
const settingRepo: Repository<Setting> = tx?.getRepository(Setting) || getRepository(Setting)
|
|
224
212
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
const companyDomain: Domain = foundPermittedBizplace.company.domain
|
|
230
|
-
companyBizplace = await parentTx.getRepository(Bizplace).findOne({ where: { domain: companyDomain } })
|
|
231
|
-
} else {
|
|
232
|
-
return false
|
|
213
|
+
const roNoSetting: Setting = await settingRepo.findOne({
|
|
214
|
+
where: {
|
|
215
|
+
domain,
|
|
216
|
+
name: ORDER_NUMBER_SETTING_KEY.RO_NUMBER_RULE
|
|
233
217
|
}
|
|
218
|
+
})
|
|
234
219
|
|
|
235
|
-
|
|
220
|
+
for (let index = 0; index < updatableDraftOrders.length; index++) {
|
|
221
|
+
await getConnection().transaction(async (parentTx: EntityManager) => {
|
|
222
|
+
const draftOrder = updatableDraftOrders[index]
|
|
236
223
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
return itm.product.id
|
|
249
|
-
}),
|
|
250
|
-
...draftOrder.orderProducts
|
|
251
|
-
.filter(itm => itm?.productBundle)
|
|
252
|
-
.map(itm => {
|
|
253
|
-
return itm.productBundle.id
|
|
254
|
-
})
|
|
255
|
-
]
|
|
256
|
-
}
|
|
257
|
-
]
|
|
258
|
-
},
|
|
259
|
-
context,
|
|
260
|
-
parentTx
|
|
261
|
-
)
|
|
262
|
-
|
|
263
|
-
draftOrder.orderProducts = draftOrder.orderProducts.map(itm => {
|
|
264
|
-
let foundProductInv = productInventory.items.find(
|
|
265
|
-
i =>
|
|
266
|
-
(i.productId == itm?.product?.id || i.productId == itm?.productBundle?.id) &&
|
|
267
|
-
i.packingType == itm.packingType &&
|
|
268
|
-
i.packingSize == itm.packingSize &&
|
|
269
|
-
i.uom == itm.uom &&
|
|
270
|
-
itm.releaseQty <= i.remainQty
|
|
271
|
-
)
|
|
272
|
-
return {
|
|
273
|
-
...itm,
|
|
274
|
-
releaseUomValue: (foundProductInv.remainUomValue / foundProductInv.remainQty) * itm.releaseQty,
|
|
275
|
-
status: foundProductInv ? 'suffice' : 'insufficient'
|
|
224
|
+
let foundPermittedBizplace: Bizplace
|
|
225
|
+
let companyBizplace: Bizplace
|
|
226
|
+
|
|
227
|
+
if (draftOrder?.bizplace?.id) {
|
|
228
|
+
foundPermittedBizplace = await parentTx.getRepository(Bizplace).findOne(draftOrder.bizplace.id, {
|
|
229
|
+
relations: ['company', 'company.domain']
|
|
230
|
+
})
|
|
231
|
+
const companyDomain: Domain = foundPermittedBizplace.company.domain
|
|
232
|
+
companyBizplace = await parentTx.getRepository(Bizplace).findOne({ where: { domain: companyDomain } })
|
|
233
|
+
} else {
|
|
234
|
+
return false
|
|
276
235
|
}
|
|
277
|
-
})
|
|
278
236
|
|
|
279
|
-
|
|
280
|
-
if (!insufficient) {
|
|
281
|
-
//create RO
|
|
282
|
-
let releaseGood = { ...draftOrder }
|
|
283
|
-
delete releaseGood.id
|
|
284
|
-
delete releaseGood.name
|
|
285
|
-
delete releaseGood.createdAt
|
|
286
|
-
delete releaseGood.createdBy
|
|
287
|
-
delete releaseGood.updatedAt
|
|
288
|
-
delete releaseGood.updatedBy
|
|
289
|
-
|
|
290
|
-
let orderInventories = []
|
|
291
|
-
|
|
292
|
-
for (let index = 0; index < draftOrder.orderProducts.length; index++) {
|
|
293
|
-
const itm: Partial<OrderProduct> = draftOrder.orderProducts[index]
|
|
294
|
-
let data = []
|
|
295
|
-
if (itm.productBundle) {
|
|
296
|
-
let bundle: ProductBundle = await parentTx.getRepository(ProductBundle).findOne({
|
|
297
|
-
where: { id: itm.productBundle.id },
|
|
298
|
-
relations: [
|
|
299
|
-
'productBundleSettings',
|
|
300
|
-
'productBundleSettings.productDetail',
|
|
301
|
-
'productBundleSettings.product'
|
|
302
|
-
]
|
|
303
|
-
})
|
|
237
|
+
const bizplaces: Bizplace[] = [foundPermittedBizplace, companyBizplace]
|
|
304
238
|
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
sku: objProductBundleSetting.product.sku,
|
|
309
|
-
packingType: objProductBundleSetting.productDetail.packingType,
|
|
310
|
-
packingSize: objProductBundleSetting.productDetail.packingSize,
|
|
311
|
-
uom: objProductBundleSetting.productDetail.uom,
|
|
312
|
-
releaseQty: objProductBundleSetting.bundleQty * itm.releaseQty,
|
|
313
|
-
assignedQty: undefined,
|
|
314
|
-
assignedUomValue: undefined,
|
|
315
|
-
releaseUomValue: objProductBundleSetting.bundleQty * itm.releaseQty * itm.releaseUomValue
|
|
316
|
-
})
|
|
317
|
-
}
|
|
318
|
-
} else {
|
|
319
|
-
data = [
|
|
320
|
-
{
|
|
321
|
-
sku: itm.product.sku,
|
|
322
|
-
packingType: itm.packingType,
|
|
323
|
-
packingSize: itm.packingSize,
|
|
324
|
-
uom: itm.uom,
|
|
325
|
-
releaseQty: itm.releaseQty,
|
|
326
|
-
assignedQty: undefined,
|
|
327
|
-
assignedUomValue: undefined,
|
|
328
|
-
releaseUomValue: itm.releaseUomValue
|
|
329
|
-
}
|
|
330
|
-
]
|
|
331
|
-
}
|
|
239
|
+
let loggerJson = JSON.stringify({ refNo: draftOrder.refNo, bizplaceId: draftOrder.bizplace.id, domain })
|
|
240
|
+
try {
|
|
241
|
+
console.time(`creating_order:${loggerJson}`)
|
|
332
242
|
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
243
|
+
let productInventory = await InventoryUtil.bizplaceProductInventory(
|
|
244
|
+
bizplaces,
|
|
245
|
+
{
|
|
246
|
+
filters: [
|
|
247
|
+
{
|
|
248
|
+
name: 'productId',
|
|
249
|
+
operator: 'in',
|
|
250
|
+
value: [
|
|
251
|
+
...draftOrder.orderProducts
|
|
252
|
+
.filter(itm => itm?.product)
|
|
253
|
+
.map(itm => {
|
|
254
|
+
return itm.product.id
|
|
255
|
+
}),
|
|
256
|
+
...draftOrder.orderProducts
|
|
257
|
+
.filter(itm => itm?.productBundle)
|
|
258
|
+
.map(itm => {
|
|
259
|
+
return itm.productBundle.id
|
|
260
|
+
})
|
|
261
|
+
]
|
|
262
|
+
}
|
|
263
|
+
]
|
|
264
|
+
},
|
|
265
|
+
context,
|
|
266
|
+
parentTx
|
|
267
|
+
)
|
|
268
|
+
|
|
269
|
+
draftOrder.orderProducts = draftOrder.orderProducts.map(itm => {
|
|
270
|
+
let foundProductInv = productInventory.items.find(
|
|
271
|
+
i =>
|
|
272
|
+
(i.productId == itm?.product?.id || i.productId == itm?.productBundle?.id) &&
|
|
273
|
+
i.packingType == itm.packingType &&
|
|
274
|
+
i.packingSize == itm.packingSize &&
|
|
275
|
+
i.uom == itm.uom &&
|
|
276
|
+
itm.releaseQty <= i.remainQty
|
|
340
277
|
)
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
existingOI.uomValue = existingOI.uomValue + data.uomValue
|
|
346
|
-
} else {
|
|
347
|
-
orderInventories.push({ ...data, orderProduct: itm })
|
|
278
|
+
return {
|
|
279
|
+
...itm,
|
|
280
|
+
releaseUomValue: (foundProductInv.remainUomValue / foundProductInv.remainQty) * itm.releaseQty,
|
|
281
|
+
status: foundProductInv ? 'suffice' : 'insufficient'
|
|
348
282
|
}
|
|
349
283
|
})
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
284
|
+
|
|
285
|
+
let insufficient = draftOrder.orderProducts.find(op => op.status == 'insufficient')
|
|
286
|
+
if (!insufficient) {
|
|
287
|
+
//create RO
|
|
288
|
+
let releaseGood = { ...draftOrder }
|
|
289
|
+
delete releaseGood.id
|
|
290
|
+
delete releaseGood.name
|
|
291
|
+
delete releaseGood.createdAt
|
|
292
|
+
delete releaseGood.createdBy
|
|
293
|
+
delete releaseGood.updatedAt
|
|
294
|
+
delete releaseGood.updatedBy
|
|
295
|
+
|
|
296
|
+
let orderInventories = []
|
|
297
|
+
|
|
298
|
+
for (let index = 0; index < draftOrder.orderProducts.length; index++) {
|
|
299
|
+
const itm: Partial<OrderProduct> = draftOrder.orderProducts[index]
|
|
300
|
+
let data = []
|
|
301
|
+
if (itm.productBundle) {
|
|
302
|
+
let bundle: ProductBundle = await parentTx.getRepository(ProductBundle).findOne({
|
|
303
|
+
where: { id: itm.productBundle.id },
|
|
304
|
+
relations: [
|
|
305
|
+
'productBundleSettings',
|
|
306
|
+
'productBundleSettings.productDetail',
|
|
307
|
+
'productBundleSettings.product'
|
|
308
|
+
]
|
|
309
|
+
})
|
|
310
|
+
|
|
311
|
+
for (let index2 = 0; index2 < bundle.productBundleSettings.length; index2++) {
|
|
312
|
+
const objProductBundleSetting = bundle.productBundleSettings[index2]
|
|
313
|
+
data.push({
|
|
314
|
+
sku: objProductBundleSetting.product.sku,
|
|
315
|
+
packingType: objProductBundleSetting.productDetail.packingType,
|
|
316
|
+
packingSize: objProductBundleSetting.productDetail.packingSize,
|
|
317
|
+
uom: objProductBundleSetting.productDetail.uom,
|
|
318
|
+
releaseQty: objProductBundleSetting.bundleQty * itm.releaseQty,
|
|
319
|
+
assignedQty: undefined,
|
|
320
|
+
assignedUomValue: undefined,
|
|
321
|
+
releaseUomValue: objProductBundleSetting.bundleQty * itm.releaseQty * itm.releaseUomValue
|
|
322
|
+
})
|
|
323
|
+
}
|
|
324
|
+
} else {
|
|
325
|
+
data = [
|
|
326
|
+
{
|
|
327
|
+
sku: itm.product.sku,
|
|
328
|
+
packingType: itm.packingType,
|
|
329
|
+
packingSize: itm.packingSize,
|
|
330
|
+
uom: itm.uom,
|
|
331
|
+
releaseQty: itm.releaseQty,
|
|
332
|
+
assignedQty: undefined,
|
|
333
|
+
assignedUomValue: undefined,
|
|
334
|
+
releaseUomValue: itm.releaseUomValue
|
|
335
|
+
}
|
|
336
|
+
]
|
|
371
337
|
}
|
|
372
|
-
})
|
|
373
|
-
let createdReleaseGood: ReleaseGood = await bulkGenerateReleaseGood(
|
|
374
|
-
releaseGood,
|
|
375
|
-
releaseGood.bizplace.id,
|
|
376
|
-
roNoSetting,
|
|
377
|
-
domain,
|
|
378
|
-
user,
|
|
379
|
-
childTx
|
|
380
|
-
)
|
|
381
|
-
await childTx
|
|
382
|
-
.getRepository(DraftReleaseGood)
|
|
383
|
-
.update(
|
|
384
|
-
{ id: draftOrder.id },
|
|
385
|
-
{ releaseGood: createdReleaseGood, status: DRAFT_RELEASE_ORDER_STATUS.SUBMITTED }
|
|
386
|
-
)
|
|
387
338
|
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
339
|
+
data.forEach(data => {
|
|
340
|
+
let existingOI = orderInventories.find(
|
|
341
|
+
itm =>
|
|
342
|
+
itm.sku == data.sku &&
|
|
343
|
+
itm.packingType == data.packingType &&
|
|
344
|
+
itm.packingSize == data.packingSize &&
|
|
345
|
+
itm.uom == data.uom
|
|
346
|
+
)
|
|
347
|
+
|
|
348
|
+
if (existingOI) {
|
|
349
|
+
existingOI.releaseQty = existingOI.releaseQty + data.releaseQty
|
|
350
|
+
existingOI.releaseUomValue = existingOI.releaseUomValue + data.uomValue
|
|
351
|
+
existingOI.uomValue = existingOI.uomValue + data.uomValue
|
|
352
|
+
} else {
|
|
353
|
+
orderInventories.push({ ...data, orderProduct: itm })
|
|
354
|
+
}
|
|
355
|
+
})
|
|
356
|
+
}
|
|
357
|
+
await getConnection().transaction(async (childTx: EntityManager) => {
|
|
358
|
+
let availableItems: any[] = await bulkReleaseGoodsAvailableItemsFunction(
|
|
359
|
+
orderInventories,
|
|
360
|
+
draftOrder.bizplace.id,
|
|
361
|
+
context,
|
|
362
|
+
childTx
|
|
363
|
+
)
|
|
364
|
+
if (availableItems.some(item => !item.releaseQty || item.releaseQty > item.assignedQty))
|
|
365
|
+
throw new ValidationError({
|
|
366
|
+
...ValidationError.ERROR_CODES.INSUFFICIENT_STOCK,
|
|
367
|
+
detail: { data: JSON.stringify(availableItems) }
|
|
368
|
+
})
|
|
369
|
+
// update orderInventories if availableItems are valid
|
|
370
|
+
releaseGood.orderInventories = availableItems.map(itm => {
|
|
371
|
+
return {
|
|
372
|
+
...itm,
|
|
373
|
+
releaseQty: itm.releaseQty,
|
|
374
|
+
releaseUomValue: itm.releaseUomValue,
|
|
375
|
+
uomValue: itm.uomValue
|
|
376
|
+
}
|
|
377
|
+
})
|
|
378
|
+
let createdReleaseGood: ReleaseGood = await bulkGenerateReleaseGood(
|
|
379
|
+
releaseGood,
|
|
380
|
+
releaseGood.bizplace.id,
|
|
381
|
+
roNoSetting,
|
|
382
|
+
domain,
|
|
383
|
+
user,
|
|
384
|
+
childTx
|
|
385
|
+
)
|
|
386
|
+
await childTx
|
|
387
|
+
.getRepository(DraftReleaseGood)
|
|
388
|
+
.update(
|
|
389
|
+
{ id: draftOrder.id },
|
|
390
|
+
{ releaseGood: createdReleaseGood, status: DRAFT_RELEASE_ORDER_STATUS.SUBMITTED }
|
|
391
|
+
)
|
|
392
|
+
|
|
393
|
+
const directReceiveSetting: Setting = await tx.getRepository(Setting).findOne({
|
|
394
|
+
where: { domain, category: 'id-rule', name: 'enable-direct-receive-release-order' }
|
|
395
|
+
})
|
|
391
396
|
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
397
|
+
const partnerDirectReceiveSetting: PartnerSetting = await tx.getRepository(PartnerSetting).findOne({
|
|
398
|
+
where: { setting: directReceiveSetting, domain, partnerDomain: draftOrder.bizplace?.domain }
|
|
399
|
+
})
|
|
395
400
|
|
|
396
|
-
|
|
401
|
+
let settingValue
|
|
397
402
|
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
403
|
+
if (
|
|
404
|
+
!isNaN(partnerDirectReceiveSetting?.value) &&
|
|
405
|
+
!isNaN(parseFloat(partnerDirectReceiveSetting?.value))
|
|
406
|
+
) {
|
|
407
|
+
settingValue = parseFloat(partnerDirectReceiveSetting.value)
|
|
408
|
+
} else {
|
|
409
|
+
settingValue = parseFloat(directReceiveSetting.value)
|
|
410
|
+
}
|
|
406
411
|
|
|
407
|
-
|
|
412
|
+
createdReleaseGood = await confirmReleaseGood(createdReleaseGood.name, context, childTx)
|
|
408
413
|
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
414
|
+
if (settingValue > 1) {
|
|
415
|
+
createdReleaseGood = await receiveReleaseGood(createdReleaseGood.name, context, childTx)
|
|
416
|
+
}
|
|
417
|
+
})
|
|
418
|
+
}
|
|
419
|
+
} catch (e) {
|
|
420
|
+
logger.error(`draft-release-good-mutation[generateReleaseGoodsFromDraft:${loggerJson}]: ${e?.message}`)
|
|
421
|
+
} finally {
|
|
422
|
+
console.timeEnd(`creating_order:${loggerJson}`)
|
|
415
423
|
}
|
|
416
|
-
}
|
|
417
|
-
}
|
|
424
|
+
})
|
|
425
|
+
}
|
|
418
426
|
}
|
|
427
|
+
|
|
428
|
+
return true
|
|
429
|
+
} catch (e) {
|
|
430
|
+
logger.error(`draft-release-good-mutation[generateReleaseGoodsFromDraft]: ${e?.message}`)
|
|
419
431
|
}
|
|
420
432
|
|
|
421
|
-
return true
|
|
422
433
|
}
|
|
423
434
|
}
|
|
424
435
|
|
|
@@ -761,8 +772,8 @@ export async function upsertDraftReleaseGoodProducts(
|
|
|
761
772
|
updatePatch['packingType'] = op?.packingType
|
|
762
773
|
? op.packingType
|
|
763
774
|
: product?.packingType
|
|
764
|
-
|
|
765
|
-
|
|
775
|
+
? product.packingType
|
|
776
|
+
: productBundle.packingType
|
|
766
777
|
updatePatch['uom'] = op?.uom ? op.uom : product?.primaryUnit ? product.primaryUnit : 'UNIT'
|
|
767
778
|
updatePatch['uomValue'] = op?.uomValue ? op.uomValue : product?.primaryValue ? product.primaryValue : 0
|
|
768
779
|
|
|
@@ -3,9 +3,7 @@ import { EntityManager, getRepository, In, Repository } from 'typeorm'
|
|
|
3
3
|
|
|
4
4
|
import { User } from '@things-factory/auth-base'
|
|
5
5
|
import { Bizplace } from '@things-factory/biz-base'
|
|
6
|
-
// import { logger } from '@things-factory/env'
|
|
7
6
|
import { generateId } from '@things-factory/id-rule-base'
|
|
8
|
-
// import { Account, AccountingAPI } from '@things-factory/integration-accounting'
|
|
9
7
|
import { Setting } from '@things-factory/setting-base'
|
|
10
8
|
import { Domain } from '@things-factory/shell'
|
|
11
9
|
|
|
@@ -129,30 +127,5 @@ export async function generateGoodsReceivalNote(
|
|
|
129
127
|
updater: user
|
|
130
128
|
})
|
|
131
129
|
|
|
132
|
-
// const orderSource: string = arrivalNotice.source
|
|
133
|
-
// switch (orderSource) {
|
|
134
|
-
// case ApplicationType.XILNEX:
|
|
135
|
-
// const xilnex: Account = await tx.getRepository(Account).findOne({
|
|
136
|
-
// domain: arrivalNotice.bizplace.domain,
|
|
137
|
-
// status: 'active',
|
|
138
|
-
// platform: 'xilnex'
|
|
139
|
-
// })
|
|
140
|
-
|
|
141
|
-
// if (xilnex) {
|
|
142
|
-
// try {
|
|
143
|
-
// await AccountingAPI.createGoodsReceivedNote(xilnex, {
|
|
144
|
-
// arrivalNotice,
|
|
145
|
-
// orderProducts: arrivalNotice.orderProducts
|
|
146
|
-
// })
|
|
147
|
-
// } catch (error) {
|
|
148
|
-
// logger.error(`goods-receival-note-mutation[generateGoodsReceivalNote]: ${error}`)
|
|
149
|
-
// }
|
|
150
|
-
// }
|
|
151
|
-
// break
|
|
152
|
-
|
|
153
|
-
// default:
|
|
154
|
-
// break
|
|
155
|
-
// }
|
|
156
|
-
|
|
157
130
|
return goodReceiveNote
|
|
158
131
|
}
|