@things-factory/sales-base 4.3.105 → 4.3.113-alpha.0
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/service/arrival-notice/arrival-notice-mutation.js +6 -5
- package/dist-server/service/arrival-notice/arrival-notice-mutation.js.map +1 -1
- package/dist-server/service/arrival-notice/arrival-notice-query.js +1 -0
- package/dist-server/service/arrival-notice/arrival-notice-query.js.map +1 -1
- package/dist-server/service/draft-release-good/draft-release-good-mutation.js +3 -4
- package/dist-server/service/draft-release-good/draft-release-good-mutation.js.map +1 -1
- package/dist-server/service/draft-release-good/draft-release-good-query.js +11 -15
- package/dist-server/service/draft-release-good/draft-release-good-query.js.map +1 -1
- package/dist-server/service/invoice-product/invoice-product.js +8 -3
- package/dist-server/service/invoice-product/invoice-product.js.map +1 -1
- package/dist-server/service/order-inventory/order-inventory-query.js +2 -1
- package/dist-server/service/order-inventory/order-inventory-query.js.map +1 -1
- package/dist-server/service/order-inventory/order-inventory-types.js +18 -10
- package/dist-server/service/order-inventory/order-inventory-types.js.map +1 -1
- package/dist-server/service/order-inventory/order-inventory.js +12 -3
- package/dist-server/service/order-inventory/order-inventory.js.map +1 -1
- package/dist-server/service/order-product/order-product-query.js +1 -0
- package/dist-server/service/order-product/order-product-query.js.map +1 -1
- package/dist-server/service/order-product/order-product-types.js +18 -10
- package/dist-server/service/order-product/order-product-types.js.map +1 -1
- package/dist-server/service/order-vas/order-vas.js +8 -3
- package/dist-server/service/order-vas/order-vas.js.map +1 -1
- package/dist-server/service/others/other-query.js +196 -177
- package/dist-server/service/others/other-query.js.map +1 -1
- package/dist-server/service/others/other-types.js +9 -1
- package/dist-server/service/others/other-types.js.map +1 -1
- package/dist-server/service/purchase-order/purchase-order-mutation.js +10 -2
- package/dist-server/service/purchase-order/purchase-order-mutation.js.map +1 -1
- package/dist-server/service/purchase-order/purchase-order-query.js +1 -0
- package/dist-server/service/purchase-order/purchase-order-query.js.map +1 -1
- package/dist-server/service/release-good/release-good-mutation.js +18 -8
- package/dist-server/service/release-good/release-good-mutation.js.map +1 -1
- package/dist-server/service/release-good/release-good-query.js +5 -7
- package/dist-server/service/release-good/release-good-query.js.map +1 -1
- package/dist-server/service/release-good/release-good-types.js +8 -4
- package/dist-server/service/release-good/release-good-types.js.map +1 -1
- package/dist-server/service/return-order/return-order-mutation.js +3 -0
- package/dist-server/service/return-order/return-order-mutation.js.map +1 -1
- package/dist-server/service/return-order/return-order-types.js.map +1 -1
- package/dist-server/service/reverse-kitting-order-inventory/reverse-kitting-order-inventory.js +8 -3
- package/dist-server/service/reverse-kitting-order-inventory/reverse-kitting-order-inventory.js.map +1 -1
- package/dist-server/utils/inventory-util.js +39 -104
- package/dist-server/utils/inventory-util.js.map +1 -1
- package/package.json +13 -13
- package/server/service/arrival-notice/arrival-notice-mutation.ts +6 -3
- package/server/service/arrival-notice/arrival-notice-query.ts +1 -0
- package/server/service/draft-release-good/draft-release-good-mutation.ts +3 -4
- package/server/service/draft-release-good/draft-release-good-query.ts +17 -21
- package/server/service/invoice-product/invoice-product.ts +5 -1
- package/server/service/order-inventory/order-inventory-query.ts +2 -0
- package/server/service/order-inventory/order-inventory-types.ts +6 -0
- package/server/service/order-inventory/order-inventory.ts +8 -1
- package/server/service/order-product/order-product-query.ts +1 -0
- package/server/service/order-product/order-product-types.ts +6 -0
- package/server/service/order-vas/order-vas.ts +6 -1
- package/server/service/others/other-query.ts +231 -219
- package/server/service/others/other-types.ts +7 -1
- package/server/service/purchase-order/purchase-order-mutation.ts +10 -1
- package/server/service/purchase-order/purchase-order-query.ts +1 -0
- package/server/service/release-good/release-good-mutation.ts +21 -8
- package/server/service/release-good/release-good-query.ts +5 -8
- package/server/service/release-good/release-good-types.ts +4 -3
- package/server/service/return-order/return-order-mutation.ts +4 -1
- package/server/service/return-order/return-order-types.ts +1 -0
- package/server/service/reverse-kitting-order-inventory/reverse-kitting-order-inventory.ts +5 -1
- package/server/utils/inventory-util.ts +75 -149
- package/translations/en.json +1 -0
- package/translations/ko.json +2 -1
- package/translations/ms.json +2 -1
- package/translations/zh.json +25 -0
|
@@ -286,6 +286,7 @@ export class OrderInventoryQuery {
|
|
|
286
286
|
.leftJoinAndSelect('oi.bizplace', 'bizplace')
|
|
287
287
|
.leftJoinAndSelect('oi.inventory', 'inventory')
|
|
288
288
|
.leftJoinAndSelect('inventory.product', 'product')
|
|
289
|
+
.leftJoinAndSelect('inventory.productDetail', 'productDetail')
|
|
289
290
|
.leftJoinAndSelect('oi.creator', 'creator')
|
|
290
291
|
.leftJoinAndSelect('oi.updater', 'updater')
|
|
291
292
|
|
|
@@ -299,6 +300,7 @@ export class OrderInventoryQuery {
|
|
|
299
300
|
releaseGoodName: item.releaseGood.name,
|
|
300
301
|
palletId: item.inventory.palletId,
|
|
301
302
|
productId: item.inventory.product.id,
|
|
303
|
+
productDetailId: item.inventory.productDetail.id,
|
|
302
304
|
productName: item.inventory.product.name,
|
|
303
305
|
productSKU: item.inventory.product.sku,
|
|
304
306
|
productBrand: item.inventory.product.brand,
|
|
@@ -41,6 +41,9 @@ export class NewOrderInventory {
|
|
|
41
41
|
@Field(type => NewProduct, { nullable: true })
|
|
42
42
|
product: NewProduct
|
|
43
43
|
|
|
44
|
+
@Field(type => ObjectRef, { nullable: true })
|
|
45
|
+
productDetail: ObjectRef
|
|
46
|
+
|
|
44
47
|
@Field({ nullable: true })
|
|
45
48
|
productSKU: string
|
|
46
49
|
|
|
@@ -200,6 +203,9 @@ export class OrderInventoryPatch {
|
|
|
200
203
|
@Field({ nullable: true })
|
|
201
204
|
productId: string
|
|
202
205
|
|
|
206
|
+
@Field({ nullable: true })
|
|
207
|
+
productDetailId: string
|
|
208
|
+
|
|
203
209
|
@Field({ nullable: true })
|
|
204
210
|
orderProductId: string
|
|
205
211
|
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
|
|
14
14
|
import { User } from '@things-factory/auth-base'
|
|
15
15
|
import { Bizplace } from '@things-factory/biz-base'
|
|
16
|
-
import { Product } from '@things-factory/product-base'
|
|
16
|
+
import { Product, ProductDetail} from '@things-factory/product-base'
|
|
17
17
|
import { Domain } from '@things-factory/shell'
|
|
18
18
|
import { Inventory, Location } from '@things-factory/warehouse-base'
|
|
19
19
|
|
|
@@ -341,6 +341,13 @@ export class OrderInventory {
|
|
|
341
341
|
@Field({ nullable: true })
|
|
342
342
|
loadedAt: Date
|
|
343
343
|
|
|
344
|
+
@ManyToOne(type => ProductDetail, { nullable: true })
|
|
345
|
+
@Field({ nullable: true })
|
|
346
|
+
productDetail: ProductDetail
|
|
347
|
+
|
|
348
|
+
@Field({ nullable: true })
|
|
349
|
+
productDetailId: String
|
|
350
|
+
|
|
344
351
|
@Field({ nullable: true })
|
|
345
352
|
dispatchedAt: Date
|
|
346
353
|
|
|
@@ -26,6 +26,7 @@ export class OrderProductQuery {
|
|
|
26
26
|
|
|
27
27
|
let qb: SelectQueryBuilder<OrderProduct> = await getRepository(OrderProduct).createQueryBuilder('op')
|
|
28
28
|
qb.leftJoinAndSelect('op.product', 'product')
|
|
29
|
+
.leftJoinAndSelect('op.productDetail', 'productDetail')
|
|
29
30
|
.leftJoinAndSelect('op.domain', 'domain')
|
|
30
31
|
.leftJoinAndSelect('op.bizplace', 'bizplace')
|
|
31
32
|
.leftJoinAndSelect('bizplace.company', 'company')
|
|
@@ -90,6 +90,9 @@ export class OrderProductPatch {
|
|
|
90
90
|
@Field(type => ObjectRef, { nullable: true })
|
|
91
91
|
toInventory: ObjectRef
|
|
92
92
|
|
|
93
|
+
@Field(type => ObjectRef, { nullable: true })
|
|
94
|
+
productDetail: ObjectRef
|
|
95
|
+
|
|
93
96
|
@Field(type => InboundProduct, { nullable: true })
|
|
94
97
|
product: InboundProduct
|
|
95
98
|
|
|
@@ -231,6 +234,9 @@ export class NewOrderProduct {
|
|
|
231
234
|
@Field(type => ObjectRef, { nullable: true })
|
|
232
235
|
toInventory: ObjectRef
|
|
233
236
|
|
|
237
|
+
@Field(type => ObjectRef, { nullable: true })
|
|
238
|
+
productDetail: ObjectRef
|
|
239
|
+
|
|
234
240
|
@Field(type => InboundProduct, { nullable: true })
|
|
235
241
|
product: InboundProduct
|
|
236
242
|
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
|
|
13
13
|
import { User } from '@things-factory/auth-base'
|
|
14
14
|
import { Bizplace } from '@things-factory/biz-base'
|
|
15
|
-
import { Product } from '@things-factory/product-base'
|
|
15
|
+
import { Product, ProductDetail } from '@things-factory/product-base'
|
|
16
16
|
import { Domain } from '@things-factory/shell'
|
|
17
17
|
import { Inventory } from '@things-factory/warehouse-base'
|
|
18
18
|
|
|
@@ -200,6 +200,10 @@ export class OrderVas {
|
|
|
200
200
|
@Field()
|
|
201
201
|
updatedAt: Date
|
|
202
202
|
|
|
203
|
+
@ManyToOne(type => ProductDetail, { nullable: true })
|
|
204
|
+
@Field({ nullable: true })
|
|
205
|
+
productDetail: ProductDetail
|
|
206
|
+
|
|
203
207
|
@ManyToOne(type => User)
|
|
204
208
|
@Field(type => User, { nullable: true })
|
|
205
209
|
creator: User
|
|
@@ -213,4 +217,5 @@ export class OrderVas {
|
|
|
213
217
|
|
|
214
218
|
@RelationId((orderVas: OrderVas) => orderVas.updater)
|
|
215
219
|
updaterId: string
|
|
220
|
+
|
|
216
221
|
}
|
|
@@ -7,6 +7,7 @@ import { Bizplace, getPermittedBizplaces } from '@things-factory/biz-base'
|
|
|
7
7
|
import { Product, ProductDetail } from '@things-factory/product-base'
|
|
8
8
|
import { PartnerSetting, Setting } from '@things-factory/setting-base'
|
|
9
9
|
import { Domain, ListParam } from '@things-factory/shell'
|
|
10
|
+
import i18next from 'i18next'
|
|
10
11
|
|
|
11
12
|
import {
|
|
12
13
|
InventoryProductGroup,
|
|
@@ -187,6 +188,12 @@ export class OtherQuery {
|
|
|
187
188
|
operator: 'eq',
|
|
188
189
|
value: orderInventory.packingType
|
|
189
190
|
})
|
|
191
|
+
} else {
|
|
192
|
+
filters.push({
|
|
193
|
+
name: 'packingType',
|
|
194
|
+
operator: 'eq',
|
|
195
|
+
value: ''
|
|
196
|
+
})
|
|
190
197
|
}
|
|
191
198
|
|
|
192
199
|
const params: any = {
|
|
@@ -205,32 +212,30 @@ export class OtherQuery {
|
|
|
205
212
|
|
|
206
213
|
let packageUomValue = availableItem ? availableItem.remainUomValue / availableItem.remainQty : null
|
|
207
214
|
const newOrderInventory: any = {
|
|
208
|
-
product:
|
|
209
|
-
? {
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
packingType: availableItem ? availableItem.packingType : orderInventory.packingType,
|
|
233
|
-
packingSize: availableItem ? availableItem.packingSize : 1,
|
|
215
|
+
product:
|
|
216
|
+
total > 0 ? { id: items[0].productId, sku: items[0].productSKU, name: items[0].productName } : { id: null },
|
|
217
|
+
productDetail: total > 0 ? { id: items[0].productDetailId } : null,
|
|
218
|
+
inventory:
|
|
219
|
+
total > 0
|
|
220
|
+
? {
|
|
221
|
+
...items[0],
|
|
222
|
+
remainQty: total > 0 ? items[0].remainQty : null,
|
|
223
|
+
remainUomValue: total > 0 ? items[0].remainUomValue : null,
|
|
224
|
+
remainUomValueWithUom: total > 0 ? items[0].remainUomValueWithUom : ''
|
|
225
|
+
}
|
|
226
|
+
: null,
|
|
227
|
+
productId: total > 0 ? items[0].productId : null,
|
|
228
|
+
productDetailID: total > 0 ? items[0].productDetailId : null,
|
|
229
|
+
productSKU: total > 0 ? items[0].productSKU : orderInventory.productSKU,
|
|
230
|
+
productName: total > 0 ? items[0].productName : null,
|
|
231
|
+
uom: total > 0 ? items[0].uom : null,
|
|
232
|
+
remainQty: total > 0 ? items[0].remainQty : null,
|
|
233
|
+
remainUomValue: total > 0 ? items[0].remainUomValue : null,
|
|
234
|
+
remainUomValueWithUom: total > 0 ? items[0].remainUomValueWithUom : '',
|
|
235
|
+
batchId: total > 0 ? items[0].batchId : null,
|
|
236
|
+
batchIdRef: total > 0 ? items[0].batchIdRef : null,
|
|
237
|
+
packingType: total > 0 ? items[0].packingType : orderInventory.packingType,
|
|
238
|
+
packingSize: total > 0 ? items[0].packingSize : 1,
|
|
234
239
|
releaseQty: orderInventory.releaseQty
|
|
235
240
|
? Number.isInteger(orderInventory.releaseQty)
|
|
236
241
|
? orderInventory.releaseQty
|
|
@@ -242,7 +247,7 @@ export class OtherQuery {
|
|
|
242
247
|
: null
|
|
243
248
|
: null,
|
|
244
249
|
groupType: availableItem ? availableItem.groupType : null,
|
|
245
|
-
isError: !availableItem ? true : false
|
|
250
|
+
isError: !availableItem || !orderInventory.releaseQty || !orderInventory.packingType ? true : false
|
|
246
251
|
}
|
|
247
252
|
|
|
248
253
|
newOrderInventories.push(newOrderInventory)
|
|
@@ -296,128 +301,132 @@ export class OtherQuery {
|
|
|
296
301
|
@Arg('partnerBizplaceId') partnerBizplaceId: string,
|
|
297
302
|
@Arg('orderProducts', type => [NewOrderProduct], { nullable: true }) orderProducts: NewOrderProduct[]
|
|
298
303
|
): Promise<OrderProduct[]> {
|
|
299
|
-
|
|
300
|
-
|
|
304
|
+
try {
|
|
305
|
+
const { domain, user, tx, bizplace }: { domain: Domain; user: User; tx: EntityManager; bizplace: Bizplace } =
|
|
306
|
+
context.state
|
|
301
307
|
|
|
302
|
-
|
|
308
|
+
const productDetailRepo = tx.getRepository(ProductDetail)
|
|
303
309
|
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
310
|
+
let permittedBizplaces: Bizplace[] = await getPermittedBizplaces(domain, user)
|
|
311
|
+
let foundPermittedBizplace: Bizplace
|
|
312
|
+
let companyBizplace: Bizplace
|
|
307
313
|
|
|
308
|
-
|
|
309
|
-
|
|
314
|
+
if (partnerBizplaceId) {
|
|
315
|
+
foundPermittedBizplace = permittedBizplaces.find(biz => biz.id == partnerBizplaceId)
|
|
310
316
|
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
317
|
+
if (foundPermittedBizplace) {
|
|
318
|
+
if (!foundPermittedBizplace.company?.id) {
|
|
319
|
+
foundPermittedBizplace = await tx.getRepository(Bizplace).findOne(foundPermittedBizplace.id, {
|
|
320
|
+
relations: ['domain', 'company', 'company.domain']
|
|
321
|
+
})
|
|
322
|
+
}
|
|
323
|
+
const companyDomain: Domain = foundPermittedBizplace.company.domain
|
|
324
|
+
companyBizplace = await tx.getRepository(Bizplace).findOne({ where: { domain: companyDomain } })
|
|
316
325
|
}
|
|
317
|
-
const companyDomain: Domain = foundPermittedBizplace.company.domain
|
|
318
|
-
companyBizplace = await tx.getRepository(Bizplace).findOne({ where: { domain: companyDomain } })
|
|
319
326
|
}
|
|
320
|
-
}
|
|
321
327
|
|
|
322
|
-
|
|
323
|
-
|
|
328
|
+
const bizplaces: Bizplace[] = [foundPermittedBizplace, companyBizplace]
|
|
329
|
+
if (bizplace) bizplaces.push(bizplace)
|
|
324
330
|
|
|
325
|
-
|
|
331
|
+
let strictProduct = 'false'
|
|
326
332
|
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
333
|
+
const strictProductSelectionSetting: Setting = await tx.getRepository(Setting).findOne({
|
|
334
|
+
where: { domain, category: 'id-rule', name: 'strict-product-selection' }
|
|
335
|
+
})
|
|
330
336
|
|
|
331
|
-
|
|
337
|
+
if (strictProductSelectionSetting) strictProduct = strictProductSelectionSetting.value
|
|
332
338
|
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
339
|
+
const partnerStrictProductSelectionSetting: PartnerSetting = await tx.getRepository(PartnerSetting).findOne({
|
|
340
|
+
where: { setting: strictProductSelectionSetting, domain, partnerDomain: foundPermittedBizplace?.domain }
|
|
341
|
+
})
|
|
336
342
|
|
|
337
|
-
|
|
343
|
+
if (partnerStrictProductSelectionSetting) strictProduct = partnerStrictProductSelectionSetting.value
|
|
338
344
|
|
|
339
|
-
|
|
345
|
+
let newOrderProducts: any[] = []
|
|
340
346
|
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
347
|
+
for (var i = 0; i < orderProducts.length; i++) {
|
|
348
|
+
const orderProduct = orderProducts[i]
|
|
349
|
+
const productSKU: string = orderProduct.productSKU
|
|
350
|
+
const foundProduct: Product = await tx.getRepository(Product).findOne({
|
|
351
|
+
where: {
|
|
352
|
+
sku: productSKU,
|
|
353
|
+
bizplace: companyBizplace
|
|
354
|
+
}
|
|
355
|
+
})
|
|
350
356
|
|
|
351
|
-
|
|
357
|
+
let newOrderProduct: any
|
|
352
358
|
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
359
|
+
if (foundProduct) {
|
|
360
|
+
let productDetail: ProductDetail
|
|
361
|
+
const hasConditions: boolean = Boolean(
|
|
362
|
+
(orderProduct?.packingType && orderProduct?.packingType.trim() != '') ||
|
|
363
|
+
(orderProduct?.uom && orderProduct?.uom.trim() != '') ||
|
|
364
|
+
orderProduct?.uomValue
|
|
365
|
+
)
|
|
366
|
+
let productDetailCondition: any = { product: foundProduct }
|
|
360
367
|
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
368
|
+
if (hasConditions && strictProduct == 'true') {
|
|
369
|
+
if (orderProduct?.packingType && orderProduct.packingType.trim() != '')
|
|
370
|
+
productDetailCondition.packingType = orderProduct.packingType.trim()
|
|
364
371
|
|
|
365
|
-
|
|
366
|
-
} else {
|
|
367
|
-
productDetailCondition.isDefault = true
|
|
368
|
-
}
|
|
372
|
+
if (orderProduct?.uom && orderProduct.uom.trim() != '') productDetailCondition.uom = orderProduct.uom.trim()
|
|
369
373
|
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
374
|
+
if (orderProduct?.uomValue) productDetailCondition.uomValue = orderProduct.uomValue
|
|
375
|
+
} else {
|
|
376
|
+
productDetailCondition.isDefault = true
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
productDetail = await productDetailRepo.findOne({
|
|
380
|
+
where: productDetailCondition
|
|
381
|
+
})
|
|
373
382
|
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
383
|
+
if (!productDetail) throw new Error(i18next.t('error.product_not_found'))
|
|
384
|
+
|
|
385
|
+
//check if is strict product selection for uom value, uom, packing type
|
|
386
|
+
const uomValue: number = strictProduct == 'true' ? productDetail.uomValue : orderProduct.uomValue
|
|
387
|
+
|
|
388
|
+
const uom = strictProduct == 'true' ? productDetail.uom : orderProduct.uom
|
|
389
|
+
|
|
390
|
+
const packingType = strictProduct == 'true' ? productDetail.packingType : orderProduct.packingType
|
|
391
|
+
|
|
392
|
+
newOrderProduct = {
|
|
393
|
+
...orderProduct,
|
|
394
|
+
packingType,
|
|
395
|
+
packingSize: productDetail ? productDetail.packingSize : orderProduct.packingSize,
|
|
396
|
+
uom,
|
|
397
|
+
uomValue,
|
|
398
|
+
productName: `${foundProduct.name}(${foundProduct.description}(${foundProduct.sku}))`,
|
|
399
|
+
productBrand: foundProduct?.brand ? foundProduct.brand : null,
|
|
400
|
+
product: {
|
|
401
|
+
id: foundProduct.id,
|
|
402
|
+
name: foundProduct.name,
|
|
403
|
+
sku: foundProduct.sku,
|
|
404
|
+
type: foundProduct.type,
|
|
405
|
+
brand: foundProduct.brand,
|
|
406
|
+
primaryUnit: productDetail ? productDetail.uom : null,
|
|
407
|
+
primaryValue: productDetail ? productDetail.uomValue : null
|
|
408
|
+
},
|
|
409
|
+
productDetail,
|
|
410
|
+
totalUomValue:
|
|
411
|
+
orderProduct.packQty > 0
|
|
412
|
+
? uomValue
|
|
413
|
+
? `${(orderProduct.packQty * uomValue).toFixed(2)} ${uom}`
|
|
414
|
+
: null
|
|
405
415
|
: null
|
|
406
|
-
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
newOrderProduct = {
|
|
410
|
-
...orderProduct,
|
|
411
|
-
productName: orderProduct.productSKU,
|
|
412
|
-
isError: true
|
|
416
|
+
}
|
|
417
|
+
} else {
|
|
418
|
+
throw new Error(i18next.t('error.product_not_found'))
|
|
413
419
|
}
|
|
420
|
+
|
|
421
|
+
newOrderProducts.push(newOrderProduct)
|
|
414
422
|
}
|
|
415
423
|
|
|
416
|
-
newOrderProducts
|
|
424
|
+
return newOrderProducts
|
|
425
|
+
} catch (e) {
|
|
426
|
+
return e
|
|
417
427
|
}
|
|
418
|
-
|
|
419
|
-
return newOrderProducts
|
|
420
428
|
}
|
|
429
|
+
|
|
421
430
|
@Directive('@privilege(category: "order_customer", privilege: "query")')
|
|
422
431
|
@Directive('@transaction')
|
|
423
432
|
@Query(returns => [InventoryProductGroup])
|
|
@@ -426,126 +435,129 @@ export class OtherQuery {
|
|
|
426
435
|
@Arg('partnerBizplaceId') partnerBizplaceId: string,
|
|
427
436
|
@Arg('orderProducts', type => [NewOrderProduct], { nullable: true }) orderProducts: NewOrderProduct[]
|
|
428
437
|
): Promise<OrderProduct[]> {
|
|
429
|
-
|
|
430
|
-
|
|
438
|
+
try {
|
|
439
|
+
const { domain, user, tx, bizplace }: { domain: Domain; user: User; tx: EntityManager; bizplace: Bizplace } =
|
|
440
|
+
context.state
|
|
431
441
|
|
|
432
|
-
|
|
442
|
+
const productDetailRepo = tx.getRepository(ProductDetail)
|
|
433
443
|
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
444
|
+
let permittedBizplaces: Bizplace[] = await getPermittedBizplaces(domain, user)
|
|
445
|
+
let foundPermittedBizplace: Bizplace
|
|
446
|
+
let companyBizplace: Bizplace
|
|
437
447
|
|
|
438
|
-
|
|
439
|
-
|
|
448
|
+
if (partnerBizplaceId) {
|
|
449
|
+
foundPermittedBizplace = permittedBizplaces.find(biz => biz.id == partnerBizplaceId)
|
|
440
450
|
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
451
|
+
if (foundPermittedBizplace) {
|
|
452
|
+
if (!foundPermittedBizplace.company?.id) {
|
|
453
|
+
foundPermittedBizplace = await tx.getRepository(Bizplace).findOne(foundPermittedBizplace.id, {
|
|
454
|
+
relations: ['domain', 'company', 'company.domain']
|
|
455
|
+
})
|
|
456
|
+
}
|
|
457
|
+
const companyDomain: Domain = foundPermittedBizplace.company.domain
|
|
458
|
+
companyBizplace = await tx.getRepository(Bizplace).findOne({ where: { domain: companyDomain } })
|
|
446
459
|
}
|
|
447
|
-
const companyDomain: Domain = foundPermittedBizplace.company.domain
|
|
448
|
-
companyBizplace = await tx.getRepository(Bizplace).findOne({ where: { domain: companyDomain } })
|
|
449
460
|
}
|
|
450
|
-
}
|
|
451
461
|
|
|
452
|
-
|
|
453
|
-
|
|
462
|
+
const bizplaces: Bizplace[] = [foundPermittedBizplace, companyBizplace]
|
|
463
|
+
if (bizplace) bizplaces.push(bizplace)
|
|
454
464
|
|
|
455
|
-
|
|
465
|
+
let strictProduct: boolean = false
|
|
456
466
|
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
467
|
+
const strictProductSelectionSetting: Setting = await tx.getRepository(Setting).findOne({
|
|
468
|
+
where: { domain, category: 'id-rule', name: 'strict-product-selection' }
|
|
469
|
+
})
|
|
460
470
|
|
|
461
|
-
|
|
471
|
+
if (strictProductSelectionSetting) strictProduct = strictProductSelectionSetting.value
|
|
462
472
|
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
473
|
+
const partnerStrictProductSelectionSetting: PartnerSetting = await tx.getRepository(PartnerSetting).findOne({
|
|
474
|
+
where: { setting: strictProductSelectionSetting, domain, partnerDomain: foundPermittedBizplace?.domain }
|
|
475
|
+
})
|
|
466
476
|
|
|
467
|
-
|
|
477
|
+
if (partnerStrictProductSelectionSetting) strictProduct = partnerStrictProductSelectionSetting.value
|
|
468
478
|
|
|
469
|
-
|
|
479
|
+
let newOrderProducts: any[] = []
|
|
470
480
|
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
481
|
+
for (var i = 0; i < orderProducts.length; i++) {
|
|
482
|
+
const orderProduct = orderProducts[i]
|
|
483
|
+
const productSKU: string = orderProduct.productSKU
|
|
484
|
+
const foundProduct: Product = await tx.getRepository(Product).findOne({
|
|
485
|
+
where: {
|
|
486
|
+
sku: productSKU,
|
|
487
|
+
bizplace: companyBizplace
|
|
488
|
+
}
|
|
489
|
+
})
|
|
480
490
|
|
|
481
|
-
|
|
491
|
+
let newOrderProduct: any
|
|
482
492
|
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
493
|
+
if (foundProduct) {
|
|
494
|
+
let productDetail: ProductDetail
|
|
495
|
+
const hasConditions: boolean = Boolean(
|
|
496
|
+
(orderProduct?.packingType && orderProduct?.packingType.trim() != '') ||
|
|
497
|
+
(orderProduct?.uom && orderProduct?.uom.trim() != '')
|
|
498
|
+
)
|
|
499
|
+
let productDetailCondition: any = { product: foundProduct }
|
|
490
500
|
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
501
|
+
if (hasConditions) {
|
|
502
|
+
if (orderProduct?.packingType && orderProduct.packingType.trim() != '')
|
|
503
|
+
productDetailCondition.packingType = orderProduct.packingType.trim()
|
|
494
504
|
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
505
|
+
if (orderProduct?.uom && orderProduct.uom.trim() != '') productDetailCondition.uom = orderProduct.uom.trim()
|
|
506
|
+
} else {
|
|
507
|
+
productDetailCondition.isDefault = true
|
|
508
|
+
}
|
|
499
509
|
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
510
|
+
productDetail = await productDetailRepo.findOne({
|
|
511
|
+
where: productDetailCondition
|
|
512
|
+
})
|
|
513
|
+
|
|
514
|
+
if (!productDetail) throw new Error('Invalid packing type or uom')
|
|
503
515
|
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
: null
|
|
509
|
-
: orderProduct?.uomValue
|
|
510
|
-
? orderProduct.uomValue
|
|
511
|
-
: productDetail.uomValue
|
|
512
|
-
|
|
513
|
-
newOrderProduct = {
|
|
514
|
-
...orderProduct,
|
|
515
|
-
packingType: orderProduct?.packingType ? orderProduct.packingType : productDetail.packingType,
|
|
516
|
-
packingSize: productDetail?.packingSize ? productDetail.packingSize : null,
|
|
517
|
-
uom: productDetail?.uom ? productDetail.uom : null,
|
|
518
|
-
uomValue: uomValue,
|
|
519
|
-
productName: `${foundProduct.name}(${foundProduct.description}(${foundProduct.sku}))`,
|
|
520
|
-
productBrand: foundProduct?.brand ? foundProduct.brand : null,
|
|
521
|
-
isError: productDetail ? false : true,
|
|
522
|
-
product: {
|
|
523
|
-
id: foundProduct.id,
|
|
524
|
-
name: foundProduct.name,
|
|
525
|
-
sku: foundProduct.sku,
|
|
526
|
-
type: foundProduct.type,
|
|
527
|
-
brand: foundProduct.brand,
|
|
528
|
-
primaryUnit: productDetail?.uom ? productDetail.uom : null,
|
|
529
|
-
primaryValue: productDetail?.uomValue ? productDetail.uomValue : null
|
|
530
|
-
},
|
|
531
|
-
totalUomValue:
|
|
532
|
-
orderProduct.packQty > 0
|
|
533
|
-
? uomValue
|
|
534
|
-
? `${(orderProduct.packQty * uomValue).toFixed(2)} ${productDetail.uom}`
|
|
516
|
+
const uomValue: number =
|
|
517
|
+
strictProduct == true
|
|
518
|
+
? productDetail?.uomValue
|
|
519
|
+
? productDetail.uomValue
|
|
535
520
|
: null
|
|
536
|
-
:
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
521
|
+
: orderProduct?.uomValue
|
|
522
|
+
? orderProduct.uomValue
|
|
523
|
+
: productDetail.uomValue
|
|
524
|
+
|
|
525
|
+
newOrderProduct = {
|
|
526
|
+
...orderProduct,
|
|
527
|
+
packingType: orderProduct?.packingType ? orderProduct.packingType : productDetail.packingType,
|
|
528
|
+
packingSize: productDetail?.packingSize ? productDetail.packingSize : null,
|
|
529
|
+
uom: productDetail?.uom ? productDetail.uom : null,
|
|
530
|
+
uomValue: uomValue,
|
|
531
|
+
productName: `${foundProduct.name}(${foundProduct.description}(${foundProduct.sku}))`,
|
|
532
|
+
productBrand: foundProduct?.brand ? foundProduct.brand : null,
|
|
533
|
+
isError: productDetail ? false : true,
|
|
534
|
+
product: {
|
|
535
|
+
id: foundProduct.id,
|
|
536
|
+
name: foundProduct.name,
|
|
537
|
+
sku: foundProduct.sku,
|
|
538
|
+
type: foundProduct.type,
|
|
539
|
+
brand: foundProduct.brand,
|
|
540
|
+
primaryUnit: productDetail?.uom ? productDetail.uom : null,
|
|
541
|
+
primaryValue: productDetail?.uomValue ? productDetail.uomValue : null
|
|
542
|
+
},
|
|
543
|
+
productDetail,
|
|
544
|
+
totalUomValue:
|
|
545
|
+
orderProduct.packQty > 0
|
|
546
|
+
? uomValue
|
|
547
|
+
? `${(orderProduct.packQty * uomValue).toFixed(2)} ${productDetail.uom}`
|
|
548
|
+
: null
|
|
549
|
+
: null
|
|
550
|
+
}
|
|
551
|
+
} else {
|
|
552
|
+
throw new Error(`(${orderProduct.productSKU}) sku not found`)
|
|
543
553
|
}
|
|
554
|
+
|
|
555
|
+
newOrderProducts.push(newOrderProduct)
|
|
544
556
|
}
|
|
545
557
|
|
|
546
|
-
newOrderProducts
|
|
558
|
+
return newOrderProducts
|
|
559
|
+
} catch (e) {
|
|
560
|
+
return e
|
|
547
561
|
}
|
|
548
|
-
|
|
549
|
-
return newOrderProducts
|
|
550
562
|
}
|
|
551
563
|
}
|