@things-factory/sales-base 4.3.41 → 4.3.44

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.
@@ -13,7 +13,6 @@ import { Domain, ObjectRef } from '@things-factory/shell'
13
13
  import { TransportDriver, TransportVehicle, TRUCK_STATUS } from '@things-factory/transport-base'
14
14
  import { Inventory } from '@things-factory/warehouse-base'
15
15
 
16
-
17
16
  import {
18
17
  ORDER_INVENTORY_STATUS,
19
18
  ORDER_NUMBER_RULE_TYPE,
@@ -27,7 +26,7 @@ import { NewOrderInventory, OrderInventoryPatch } from '../order-inventory/order
27
26
  import { ReleaseGood } from '../release-good/release-good'
28
27
  import { DeliveryOrder } from './delivery-order'
29
28
  import { DeliveryOrderPatch, NewDeliveryOrder } from './delivery-order-types'
30
- import { ShippingOrderInfoPatch } from '../release-good/release-good-types'
29
+ import { exportInformationPatch, ShippingOrderInfoPatch } from '../release-good/release-good-types'
31
30
 
32
31
  @Resolver(DeliveryOrder)
33
32
  export class DeliveryOrderMutation {
@@ -209,13 +208,15 @@ export class DeliveryOrderMutation {
209
208
  }
210
209
 
211
210
  @Directive('@transaction')
211
+ //** Comment: @Oscar, this class name title is not conform to the naming convention set, kindly change. */
212
212
  @Mutation(returns => DeliveryOrder)
213
213
  async dispatchDeliveryOrder(
214
214
  @Ctx() context: any,
215
215
  @Arg('orderInfo', type => DeliveryOrderPatch, { nullable: true }) orderInfo?: DeliveryOrderPatch,
216
216
  @Arg('orderItems', type => [OrderInventoryPatch], { nullable: true }) orderItems?: OrderInventoryPatch[],
217
- @Arg('shippingOrderInfo', type => ShippingOrderInfoPatch, { nullable: true })
218
- shippingOrderInfo?: ShippingOrderInfoPatch
217
+ @Arg('shippingInfo', type => ShippingOrderInfoPatch, { nullable: true })
218
+ shippingOrderInfo?: ShippingOrderInfoPatch,
219
+ @Arg('exportInfo', type => exportInformationPatch, { nullable: true }) exportInfo?: exportInformationPatch
219
220
  ): Promise<DeliveryOrder> {
220
221
  try {
221
222
  const { tx, domain, user }: { tx: EntityManager; domain: Domain; user: User } = context.state
@@ -236,7 +237,7 @@ export class DeliveryOrderMutation {
236
237
  if (foundDeliveryOrder.status === ORDER_STATUS.PENDING_CANCEL)
237
238
  throw new Error('Release order is pending for cancel')
238
239
 
239
- // @Oscar you can write it this way
240
+ // @Oscar you can write it this way
240
241
  // foundDeliveryOrder.ownCollection = orderInfo.transportType == 'Own Transport' ? true : false
241
242
 
242
243
  if (orderInfo.transportType == 'Own Transport') {
@@ -257,16 +258,16 @@ export class DeliveryOrderMutation {
257
258
  const product: Product = inventory.product
258
259
  const foundItem = inventory.reusablePallet
259
260
  ? orderItems.filter(
260
- (item: any) =>
261
- item.productName === `${product.name} (${product.description})` &&
262
- item.batchId === orderInventory.batchId &&
263
- item.pallet === inventory.reusablePallet.name
264
- )
261
+ (item: any) =>
262
+ item.productName === `${product.name} (${product.description})` &&
263
+ item.batchId === orderInventory.batchId &&
264
+ item.pallet === inventory.reusablePallet.name
265
+ )
265
266
  : orderItems.filter(
266
- (item: any) =>
267
- item.productName === `${product.name} (${product.description})` &&
268
- item.batchId === orderInventory.batchId
269
- )
267
+ (item: any) =>
268
+ item.productName === `${product.name} (${product.description})` &&
269
+ item.batchId === orderInventory.batchId
270
+ )
270
271
 
271
272
  if (foundItem[0].remark !== '') orderInventory.remark = foundItem[0].remark
272
273
  return orderInventory
@@ -320,24 +321,16 @@ export class DeliveryOrderMutation {
320
321
  deliveryOrderStatus = ORDER_STATUS.DELIVERING
321
322
  }
322
323
 
323
- shippingOrderInfo.deliveryAddress1 = shippingOrderInfo.deliveryAddress
324
- shippingOrderInfo.country = shippingOrderInfo.deliveryCountry
325
- shippingOrderInfo.state = shippingOrderInfo.deliveryState
326
- shippingOrderInfo.city = shippingOrderInfo.deliveryCity
327
- shippingOrderInfo.phone1 = shippingOrderInfo.contact
328
- shippingOrderInfo.postalCode = shippingOrderInfo.deliveryPostalCode
329
- shippingOrderInfo.attentionCompany = shippingOrderInfo.companyName
330
- shippingOrderInfo.collectionOrderNo = orderInfo.coNo
331
-
324
+ // save export option information
332
325
  if (orderInfo?.exportOption) {
333
326
  let savedShippingOrder: any = ''
334
327
  if (foundReleaseGood.shippingOrder == null) {
335
328
  savedShippingOrder = await tx.getRepository(ShippingOrder).save({
336
329
  name: OrderNoGenerator.shippingOrder(),
337
- shipName: shippingOrderInfo.shippingOrder.shipName,
338
- containerNo: shippingOrderInfo.shippingOrder.containerNo,
339
- containerArrivalDate: shippingOrderInfo.shippingOrder.containerArrivalDate,
340
- containerLeavingDate: shippingOrderInfo.shippingOrder.containerLeavingDate,
330
+ shipName: exportInfo.shipName,
331
+ containerNo: exportInfo.containerNo,
332
+ containerArrivalDate: exportInfo.containerArrivalDate,
333
+ containerLeavingDate: exportInfo.containerLeavingDate,
341
334
  status: ORDER_STATUS.PENDING,
342
335
  domain,
343
336
  bizplace: foundDeliveryOrder.bizplace,
@@ -348,17 +341,17 @@ export class DeliveryOrderMutation {
348
341
  savedShippingOrder = await tx.getRepository(ShippingOrder).save({
349
342
  ...foundReleaseGood.shippingOrder,
350
343
  name: OrderNoGenerator.shippingOrder(),
351
- shipName: shippingOrderInfo.shippingOrder.shipName,
352
- containerNo: shippingOrderInfo.shippingOrder.containerNo,
353
- containerArrivalDate: shippingOrderInfo.shippingOrder.containerArrivalDate,
354
- containerLeavingDate: shippingOrderInfo.shippingOrder.containerLeavingDate,
344
+ shipName: exportInfo.shipName,
345
+ containerNo: exportInfo.containerNo,
346
+ containerArrivalDate: exportInfo.containerArrivalDate,
347
+ containerLeavingDate: exportInfo.containerLeavingDate,
355
348
  status: ORDER_STATUS.PENDING,
356
349
  domain,
357
350
  bizplace: foundDeliveryOrder.bizplace,
358
351
  creator: user,
359
352
  updater: user
360
353
  })
361
- shippingOrderInfo.shippingOrder = savedShippingOrder
354
+ exportInfo = savedShippingOrder
362
355
  foundReleaseGood.exportOption = true
363
356
  } else {
364
357
  foundReleaseGood.exportOption = false
@@ -367,7 +360,10 @@ export class DeliveryOrderMutation {
367
360
 
368
361
  await tx.getRepository(ReleaseGood).save({
369
362
  ...foundReleaseGood,
370
- ...shippingOrderInfo
363
+ shippingOrder: {
364
+ ...exportInfo
365
+ },
366
+ collectionOrderNo: orderInfo.coNo
371
367
  })
372
368
 
373
369
  await tx.getRepository(DeliveryOrder).save({
@@ -383,6 +379,19 @@ export class DeliveryOrderMutation {
383
379
  remark: orderInfo?.remark,
384
380
  status: deliveryOrderStatus,
385
381
  reusablePallet: orderInfo?.reusablePallet,
382
+ attentionTo: shippingOrderInfo?.attentionTo || null,
383
+ attentionCompany: shippingOrderInfo?.attentionCompany || null,
384
+ city: shippingOrderInfo?.city || null,
385
+ state: shippingOrderInfo?.state || null,
386
+ postalCode: shippingOrderInfo?.postalCode || null,
387
+ country: shippingOrderInfo?.country || null,
388
+ phone1: shippingOrderInfo?.phone1 || null,
389
+ deliveryAddress1: shippingOrderInfo?.deliveryAddress1 || null,
390
+ billingAddress: shippingOrderInfo?.billingAddress || null,
391
+ billingCountry: shippingOrderInfo?.billingCountry || null,
392
+ billingPostalCode: shippingOrderInfo?.billingPostalCode || null,
393
+ billingState: shippingOrderInfo?.billingState || null,
394
+ billingCity: shippingOrderInfo?.billingCity || null,
386
395
  updater: user
387
396
  })
388
397
 
@@ -397,9 +406,7 @@ export class DeliveryOrderMutation {
397
406
  async dispatchManualDeliveryOrder(
398
407
  @Ctx() context: any,
399
408
  @Arg('orderInfo', type => DeliveryOrderPatch, { nullable: true }) orderInfo?: DeliveryOrderPatch,
400
- @Arg('orderItems', type => [OrderInventoryPatch], { nullable: true }) orderItems?: OrderInventoryPatch[],
401
- @Arg('shippingOrderInfo', type => ShippingOrderInfoPatch, { nullable: true })
402
- shippingOrderInfo?: ShippingOrderInfoPatch
409
+ @Arg('orderItems', type => [OrderInventoryPatch], { nullable: true }) orderItems?: OrderInventoryPatch[]
403
410
  ): Promise<DeliveryOrder> {
404
411
  try {
405
412
  const { tx, domain, user }: { tx: EntityManager; domain: Domain; user: User } = context.state
@@ -774,6 +781,8 @@ export async function generateDeliveryOrder(
774
781
  orderNo = OrderNoGenerator.deliveryOrder()
775
782
  }
776
783
 
784
+ // insert shipping information from r/o to d/o
785
+
777
786
  let deliveryOrder: any = {
778
787
  domain,
779
788
  name: orderNo,
@@ -786,6 +795,19 @@ export async function generateDeliveryOrder(
786
795
  transportVehicle,
787
796
  status: ORDER_STATUS.READY_TO_DISPATCH,
788
797
  contactPointRefId: orderInfo?.contactPointRefId || null,
798
+ attentionTo: releaseGood?.attentionTo || null,
799
+ attentionCompany: releaseGood?.attentionCompany || null,
800
+ city: releaseGood?.city || null,
801
+ state: releaseGood?.state || null,
802
+ postalCode: releaseGood?.postalCode || null,
803
+ country: releaseGood?.country || null,
804
+ phone1: releaseGood?.phone1 || null,
805
+ deliveryAddress1: releaseGood?.deliveryAddress1 || null,
806
+ billingAddress: releaseGood?.billingAddress || null,
807
+ billingCountry: releaseGood?.billingCountry || null,
808
+ billingPostalCode: releaseGood?.billingPostalCode || null,
809
+ billingState: releaseGood?.billingState || null,
810
+ billingCity: releaseGood?.billingCity || null,
789
811
  creator: user,
790
812
  updater: user
791
813
  }
@@ -169,6 +169,74 @@ export class DeliveryOrder {
169
169
  @Field({ nullable: true })
170
170
  description: string
171
171
 
172
+ @Column({ nullable: true })
173
+ @Field({ nullable: true })
174
+ attentionTo: string
175
+
176
+ @Column({ nullable: true })
177
+ @Field({ nullable: true })
178
+ attentionCompany: string
179
+
180
+ @Column({ nullable: true })
181
+ @Field({ nullable: true })
182
+ city: string
183
+
184
+ @Column({ nullable: true })
185
+ @Field({ nullable: true })
186
+ state: string
187
+
188
+ @Column({ nullable: true })
189
+ @Field({ nullable: true })
190
+ postalCode: string
191
+
192
+ @Column({ nullable: true })
193
+ @Field({ nullable: true })
194
+ country: string
195
+
196
+ @Column({ nullable: true })
197
+ @Field({ nullable: true })
198
+ phone1: string
199
+
200
+ @Column({ nullable: true })
201
+ @Field({ nullable: true })
202
+ deliveryAddress1: string
203
+
204
+ @Column({ nullable: true })
205
+ @Field({ nullable: true })
206
+ deliveryAddress2: string
207
+
208
+ @Column({ nullable: true })
209
+ @Field({ nullable: true })
210
+ deliveryAddress3: string
211
+
212
+ @Column({ nullable: true })
213
+ @Field({ nullable: true })
214
+ deliveryAddress4: string
215
+
216
+ @Column({ nullable: true })
217
+ @Field({ nullable: true })
218
+ deliveryAddress5: string
219
+
220
+ @Column({ nullable: true })
221
+ @Field({ nullable: true })
222
+ billingAddress: string
223
+
224
+ @Column({ nullable: true })
225
+ @Field({ nullable: true })
226
+ billingCountry: string
227
+
228
+ @Column({ nullable: true })
229
+ @Field({ nullable: true })
230
+ billingPostalCode: string
231
+
232
+ @Column({ nullable: true })
233
+ @Field({ nullable: true })
234
+ billingState: string
235
+
236
+ @Column({ nullable: true })
237
+ @Field({ nullable: true })
238
+ billingCity: string
239
+
172
240
  @CreateDateColumn()
173
241
  @Field()
174
242
  createdAt: Date
@@ -134,7 +134,7 @@ export class ReleaseGoodMutation {
134
134
  context,
135
135
  tx
136
136
  )
137
- } catch (error) { }
137
+ } catch (error) {}
138
138
 
139
139
  if (errorsCaught.length)
140
140
  throw new ValidationError({
@@ -228,15 +228,7 @@ export class ReleaseGoodMutation {
228
228
 
229
229
  releaseGood.shippingOrder = newShippingOrder
230
230
  }
231
-
232
- shippingOrderInfo.deliveryAddress1 = shippingOrderInfo.deliveryFullAddress
233
- shippingOrderInfo.country = shippingOrderInfo.deliveryCountry
234
- shippingOrderInfo.state = shippingOrderInfo.deliveryState
235
- shippingOrderInfo.city = shippingOrderInfo.deliveryCity
236
- shippingOrderInfo.phone1 = shippingOrderInfo.contact
237
- shippingOrderInfo.postalCode = shippingOrderInfo.deliveryPostalCode
238
- shippingOrderInfo.attentionCompany = shippingOrderInfo.companyName
239
-
231
+
240
232
  foundReleaseGood = await tx.getRepository(ReleaseGood).save({
241
233
  ...foundReleaseGood,
242
234
  ...releaseGood,
@@ -560,36 +552,6 @@ export async function generateReleaseGoodFunction(
560
552
  }
561
553
  })
562
554
 
563
- let attentionToBind = releaseGood?.attentionTo
564
- let billingAddressBind = releaseGood?.billingAddress
565
- let deliveryAddressBind = releaseGood?.deliveryAddress1
566
- let attentionCompanyBind = releaseGood?.companyName
567
- let cityBind = releaseGood?.city
568
- let stateBind = releaseGood?.state
569
- let postalCodeBind = releaseGood?.postalCode
570
- let countryBind = releaseGood?.country
571
- let contactBind = releaseGood?.phone1
572
- let billingCityBind = releaseGood?.billingCity
573
- let billingCountryBind = releaseGood?.billingCountry
574
- let billingPostalCodeBind = releaseGood?.billingPostalCode
575
- let billingStateBind = releaseGood?.billingState
576
-
577
- if (Object.keys(shippingOrderInfo).length > 0) {
578
- attentionToBind = shippingOrderInfo.attentionTo
579
- billingAddressBind = shippingOrderInfo.billingAddress
580
- deliveryAddressBind = shippingOrderInfo.deliveryAddress
581
- attentionCompanyBind = shippingOrderInfo.companyName
582
- cityBind = shippingOrderInfo.deliveryCity
583
- stateBind = shippingOrderInfo.deliveryState
584
- postalCodeBind = shippingOrderInfo.deliveryPostalCode
585
- countryBind = shippingOrderInfo.deliveryCountry
586
- contactBind = shippingOrderInfo.contact
587
- billingCityBind = shippingOrderInfo.billingCity
588
- billingCountryBind = shippingOrderInfo.billingCountry
589
- billingPostalCodeBind = shippingOrderInfo.billingPostalCode
590
- billingStateBind = shippingOrderInfo.billingState
591
- }
592
-
593
555
  newReleaseGood = {
594
556
  ...newReleaseGood,
595
557
  name: roNoSetting
@@ -603,25 +565,41 @@ export async function generateReleaseGoodFunction(
603
565
  ownTransport: releaseGood.ownTransport,
604
566
  packingOption: releaseGood.packingOption,
605
567
  marketplaceOrderStatus: releaseGood?.marketplaceOrderStatus || null,
606
- billingAddress: billingAddressBind || null,
607
- deliveryAddress1: deliveryAddressBind || null,
568
+ billingAddress: (releaseGood.type == 'b2c'
569
+ ? releaseGood?.billingAddress || null
570
+ : shippingOrderInfo.billingAddress || null),
571
+ deliveryAddress1: (releaseGood.type == 'b2c'
572
+ ? releaseGood?.deliveryAddress1 || null
573
+ : shippingOrderInfo.deliveryAddress1 || null),
608
574
  deliveryAddress2: releaseGood?.deliveryAddress2 || null,
609
575
  deliveryAddress3: releaseGood?.deliveryAddress3 || null,
610
576
  deliveryAddress4: releaseGood?.deliveryAddress4 || null,
611
577
  deliveryAddress5: releaseGood?.deliveryAddress5 || null,
612
- attentionTo: attentionToBind || null,
613
- attentionCompany: attentionCompanyBind || null,
614
- city: cityBind || null,
615
- state: stateBind || null,
616
- postalCode: postalCodeBind || null,
617
- country: countryBind || null,
618
- phone1: contactBind || null,
578
+ attentionTo: (releaseGood.type == 'b2c'
579
+ ? releaseGood?.attentionTo || null
580
+ : shippingOrderInfo.attentionTo || null),
581
+ attentionCompany: (releaseGood.type =='b2c'
582
+ ? releaseGood?.companyName || null
583
+ : shippingOrderInfo.attentionCompany || null),
584
+ city: (releaseGood.type == 'b2c' ? releaseGood?.city || null : shippingOrderInfo.city || null),
585
+ state: (releaseGood.type == 'b2c' ? releaseGood?.state || null : shippingOrderInfo.state || null),
586
+ postalCode: (releaseGood.type == 'b2c' ? releaseGood?.postalCode || null : shippingOrderInfo.postalCode || null),
587
+ country: (releaseGood.type == 'b2c' ? releaseGood?.country || null : shippingOrderInfo.country || null),
588
+ phone1: (releaseGood.type == 'b2c' ? releaseGood?.phone1 || null : shippingOrderInfo.phone1 || null),
619
589
  phone2: releaseGood?.phone2 || null,
620
590
  email: releaseGood?.email || null,
621
- billingCity: billingCityBind || null,
622
- billingCountry: billingCountryBind || null,
623
- billingPostalCode: billingPostalCodeBind || null,
624
- billingState: billingStateBind || null,
591
+ billingCity: (releaseGood.type == 'b2c'
592
+ ? releaseGood?.billingCity || null
593
+ : shippingOrderInfo.billingCity || null),
594
+ billingCountry: (releaseGood.type == 'b2c'
595
+ ? releaseGood?.billingCountry || null
596
+ : shippingOrderInfo.billingCountry || null),
597
+ billingPostalCode: (releaseGood.type == 'b2c'
598
+ ? releaseGood?.billingPostalCode || null
599
+ : shippingOrderInfo.billingPostalCode || null),
600
+ billingState: (releaseGood.type == 'b2c'
601
+ ? releaseGood?.billingState || null
602
+ : shippingOrderInfo.billingState || null),
625
603
  transporter: releaseGood?.transporter,
626
604
  trackingNo: releaseGood?.trackingNo,
627
605
  airwayBill: releaseGood?.airwayBill,
@@ -360,16 +360,16 @@ export class NewReleaseGood {
360
360
  @Field({ nullable: true })
361
361
  stopId: string
362
362
 
363
- @Field({ nullable: true})
363
+ @Field({ nullable: true })
364
364
  billingCity: string
365
365
 
366
- @Field({ nullable: true})
366
+ @Field({ nullable: true })
367
367
  billingPostalCode: string
368
368
 
369
- @Field({ nullable: true})
369
+ @Field({ nullable: true })
370
370
  billingCountry: string
371
-
372
- @Field({ nullable: true})
371
+
372
+ @Field({ nullable: true })
373
373
  billingState: string
374
374
  }
375
375
 
@@ -542,7 +542,8 @@ export class ReleaseGoodPatch {
542
542
  }
543
543
 
544
544
  @InputType()
545
- export class ShippingOrderInformationPatch {
545
+ //** Comment: @Oscar, this class name title is not conform to the naming convention set, kindly change. */
546
+ export class exportInformationPatch {
546
547
  @Field({ nullable: true })
547
548
  id?: string
548
549
 
@@ -581,7 +582,7 @@ export class ShippingOrderInfoPatch {
581
582
 
582
583
  @Field({ nullable: true })
583
584
  billingCountry: string
584
-
585
+
585
586
  @Field({ nullable: true })
586
587
  companyName: string
587
588
 
@@ -623,20 +624,16 @@ export class ShippingOrderInfoPatch {
623
624
 
624
625
  @Field({ nullable: true })
625
626
  postalCode: string
626
-
627
+
627
628
  @Field({ nullable: true })
628
629
  attentionCompany: string
629
-
630
- @Field({ nullable: true})
630
+
631
+ @Field({ nullable: true })
631
632
  collectionOrderNo: string
632
633
 
633
- @Field({ nullable: true})
634
+ @Field({ nullable: true })
634
635
  billingFullAddress: string
635
636
 
636
- @Field({ nullable: true})
637
+ @Field({ nullable: true })
637
638
  deliveryFullAddress: string
638
-
639
- @Field(type => ShippingOrderInformationPatch, { nullable: true })
640
- shippingOrder: ShippingOrderInformationPatch
641
639
  }
642
-
@@ -28,7 +28,7 @@ import {
28
28
  OrderProduct,
29
29
  OrderVas,
30
30
  ShippingOrder,
31
- ShippingOrderInfo,
31
+ ShippingOrderInfo
32
32
  } from '../'
33
33
 
34
34
  import { ReleaseOrderType } from '../../constants'
@@ -96,8 +96,8 @@ export class ReleaseGood {
96
96
  DATABASE_TYPE == 'postgres' || DATABASE_TYPE == 'mysql' || DATABASE_TYPE == 'mariadb'
97
97
  ? 'enum'
98
98
  : DATABASE_TYPE == 'oracle'
99
- ? 'varchar2'
100
- : 'smallint',
99
+ ? 'varchar2'
100
+ : 'smallint',
101
101
  enum: ReleaseOrderType,
102
102
  default: ReleaseOrderType.B2B
103
103
  })
@@ -164,8 +164,8 @@ export class ReleaseGood {
164
164
  DATABASE_TYPE == 'postgres' || DATABASE_TYPE == 'mysql' || DATABASE_TYPE == 'mariadb'
165
165
  ? 'enum'
166
166
  : DATABASE_TYPE == 'oracle'
167
- ? 'varchar2'
168
- : 'smallint',
167
+ ? 'varchar2'
168
+ : 'smallint',
169
169
  enum: DispatchmentStatus,
170
170
  default: DispatchmentStatus.READY_TO_DISPATCH
171
171
  })
@@ -441,6 +441,9 @@ export class ReleaseGood {
441
441
  @Field({ nullable: true })
442
442
  orderRemark: Boolean
443
443
 
444
- @Field({nullable:true})
444
+ @Field({ nullable: true })
445
445
  invStatus: String
446
+
447
+ @Field({ nullable: true })
448
+ matchDeliveryAddress: Boolean
446
449
  }