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