tango-app-api-payment-subscription 3.4.0-alpha.1 → 3.4.0-alpha.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tango-app-api-payment-subscription",
3
- "version": "3.4.0-alpha.1",
3
+ "version": "3.4.0-alpha.3",
4
4
  "description": "paymentSubscription",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -1280,22 +1280,22 @@ export async function migrateInvoice( req, res ) {
1280
1280
  }
1281
1281
  export async function PaymentStatusChange( req, res ) {
1282
1282
  try {
1283
- let invoice= await invoiceService.findOne({ invoice: req.body.invoiceId })
1283
+ let invoice= await invoiceService.findOne( { invoice: req.body.invoiceId } );
1284
1284
  let updateInvoice = await invoiceService.updateOne( { invoice: req.body.invoiceId }, { paymentStatus: req.body.status } );
1285
1285
  let logObj = {
1286
- userName: req.user?.userName,
1287
- email: req.user?.email,
1288
- clientId: invoice.clientId,
1289
- logSubType: 'PaymentStatus',
1290
- logType: 'invoice',
1291
- date: new Date(),
1292
- changes: [ `The payment status has been updated to ${req.body.status} for invoice ${req.body.invoiceId}.` ],
1293
- eventType: '',
1294
- timestamp: new Date(),
1295
- showTo: [ 'tango' ],
1296
- };
1297
- console.log( logObj );
1298
- insertOpenSearchData( JSON.parse( process.env.OPENSEARCH ).activityLog, logObj );
1286
+ userName: req.user?.userName,
1287
+ email: req.user?.email,
1288
+ clientId: invoice.clientId,
1289
+ logSubType: 'PaymentStatus',
1290
+ logType: 'invoice',
1291
+ date: new Date(),
1292
+ changes: [ `The payment status has been updated to ${req.body.status} for invoice ${req.body.invoiceId}.` ],
1293
+ eventType: '',
1294
+ timestamp: new Date(),
1295
+ showTo: [ 'tango' ],
1296
+ };
1297
+ console.log( logObj );
1298
+ insertOpenSearchData( JSON.parse( process.env.OPENSEARCH ).activityLog, logObj );
1299
1299
  if ( updateInvoice ) {
1300
1300
  res.sendSuccess( 'Payment status aginst the invoice changed to '+req.body.status );
1301
1301
  }
@@ -2316,6 +2316,46 @@ export const priceList = async ( req, res ) => {
2316
2316
  export const pricingListUpdate = async ( req, res ) => {
2317
2317
  try {
2318
2318
  let getPriceInfo = await basePricingService.findOne( { clientId: { $exists: true }, clientId: req.body.clientId }, { standard: 1, step: 1 } );
2319
+ let findClient = await paymentService.findOneClient( { clientId: req.body.clientId } );
2320
+
2321
+ console.log( getPriceInfo );
2322
+
2323
+
2324
+ let oldData ={
2325
+ pricingType: findClient.priceType,
2326
+ };
2327
+
2328
+ if ( findClient.priceType==='standard' ) {
2329
+ getPriceInfo.standard.map( ( item ) => {
2330
+ oldData = {
2331
+ ...oldData,
2332
+ [item.productName+' '+'negotiatePrice']: item.negotiatePrice,
2333
+ };
2334
+ if ( item.discountPercentage ) {
2335
+ oldData = {
2336
+ ...oldData,
2337
+ [item.productName+' '+'discountPercentage']: item.discountPercentage+'%',
2338
+ };
2339
+ }
2340
+ } );
2341
+ } else {
2342
+ getPriceInfo.step.map( ( item ) => {
2343
+ oldData = {
2344
+ ...oldData,
2345
+ [item.productName+' '+'negotiatePrice']: item.negotiatePrice,
2346
+ };
2347
+ if ( item.discountPercentage ) {
2348
+ oldData = {
2349
+ ...oldData,
2350
+ [item.productName+' '+'discountPercentage']: item.discountPercentage+'%',
2351
+ };
2352
+ }
2353
+ } );
2354
+ }
2355
+
2356
+ let newData ={
2357
+ pricingType: req.body.type,
2358
+ };
2319
2359
  if ( !getPriceInfo ) {
2320
2360
  if ( !req.body.client.planDetails.product.length ) {
2321
2361
  return res.sendError( 'no product found', 204 );
@@ -2338,8 +2378,9 @@ export const pricingListUpdate = async ( req, res ) => {
2338
2378
  let subtotal = 0;
2339
2379
  let origPrice = 0;
2340
2380
 
2341
- let GST = req.body.client.paymentInvoice.currencyType == 'dollar'?5:18;
2381
+ let GST = req.body.client.paymentInvoice.currencyType == 'dollar'?0:18;
2342
2382
  productList.products.forEach( ( item ) => {
2383
+ console.log( '---->1', item );
2343
2384
  let [ firstWord, secondWord ] = item.productName.replace( /([a-z])([A-Z])/g, '$1 $2' ).split( ' ' );
2344
2385
  firstWord = firstWord.charAt( 0 ).toUpperCase() + firstWord.slice( 1 );
2345
2386
  item.productName = firstWord + ' ' + secondWord;
@@ -2367,16 +2408,27 @@ export const pricingListUpdate = async ( req, res ) => {
2367
2408
  GST: req.body.client.paymentInvoice.currencyType == 'dollar' ? 5 : GST,
2368
2409
  };
2369
2410
  req.body.products.forEach( ( item ) => {
2411
+ console.log( '---->', item );
2370
2412
  delete item.originalPrice;
2371
2413
  delete item.oldPrice;
2372
2414
  delete item.oldStoreCount;
2373
2415
  delete item.storeCount;
2374
2416
  delete item.price;
2417
+
2418
+
2375
2419
  if ( item.negotiatePrice ) {
2376
2420
  item.negotiatePrice = Number( item.negotiatePrice );
2421
+ newData = {
2422
+ ...newData,
2423
+ [item.productName+' '+'negotiatePrice']: item.negotiatePrice,
2424
+ };
2377
2425
  }
2378
2426
  if ( item.discountPercentage ) {
2379
2427
  item.discountPercentage = Number( item.discountPercentage );
2428
+ newData = {
2429
+ ...newData,
2430
+ [item.productName+' '+'discountPercentage']: item.discountPercentage+'%',
2431
+ };
2380
2432
  }
2381
2433
 
2382
2434
  if ( req.body.type == 'step' ) {
@@ -2414,11 +2466,12 @@ export const pricingListUpdate = async ( req, res ) => {
2414
2466
  }
2415
2467
  let keys = [];
2416
2468
  if ( req.body.type == 'standard' ) {
2417
- keys = [ 'productName', 'discountPercentage', 'basePrice', 'negotiatePrice' ];
2469
+ keys = [ 'discountPercentage', 'negotiatePrice' ];
2418
2470
  }
2419
- if ( req.body.type == 'standard' ) {
2420
- keys = [ 'productName', 'discountPercentage', 'basePrice', 'negotiatePrice', 'storeRange' ];
2471
+ if ( req.body.type == 'step' ) {
2472
+ keys = [ 'discountPercentage', 'negotiatePrice', 'storeRange' ];
2421
2473
  }
2474
+
2422
2475
  const logObj = {
2423
2476
  clientId: req.body.clientId,
2424
2477
  userName: req.user?.userName,
@@ -2429,7 +2482,12 @@ export const pricingListUpdate = async ( req, res ) => {
2429
2482
  changes: keys,
2430
2483
  eventType: 'update',
2431
2484
  showTo: [ 'client', 'tango' ],
2485
+ previous: oldData,
2486
+ current: newData,
2487
+ oldData: oldData,
2488
+ newData: newData,
2432
2489
  };
2490
+ console.log( logObj );
2433
2491
  insertOpenSearchData( JSON.parse( process.env.OPENSEARCH ).activityLog, logObj );
2434
2492
  return res.sendSuccess( 'Pricig Updated Successfully' );
2435
2493
  } );