tango-app-api-payment-subscription 3.0.7 → 3.0.8

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.0.7",
3
+ "version": "3.0.8",
4
4
  "description": "paymentSubscription",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -15,8 +15,16 @@ export const addBilling = async ( req, res ) => {
15
15
  };
16
16
  let result = await paymentService.updateOne( { clientId: req.body.clientId }, params );
17
17
  if ( result.modifiedCount ) {
18
+ let clientInfo = await paymentService.findOne( { clientId: req.body.clientId }, { 'clientName': 1, 'billingDetails.gstNumber': 1, 'billingDetails.billingAddress': 1 } );
19
+ let resultData = {};
20
+ resultData.clientName = clientInfo.clientName || '';
21
+ let billingDetails = {};
22
+ billingDetails.billingAddress = clientInfo.billingDetails.billingAddress;
23
+ billingDetails.gstNumber = clientInfo.billingDetails.gstNumber;
24
+ billingDetails.nextBillingDate = '--';
25
+ resultData.billingDetails = billingDetails;
18
26
  logger.info( 'Billing Details Added Successfully' );
19
- return res.sendSuccess( { message: 'Bank Details Added Successfully' } );
27
+ return res.sendSuccess( { message: 'Billing Details Added Successfully', data: resultData } );
20
28
  } else {
21
29
  logger.error( 'Error Occurs WHile updating billing Detaisls' );
22
30
  return res.sendError( 'Something Went Wrong', 500 );
@@ -29,7 +37,7 @@ export const addBilling = async ( req, res ) => {
29
37
  };
30
38
 
31
39
 
32
- export const billingInfo = async ( req, res, next ) => {
40
+ export const clientBillingSubscriptionInfo = async ( req, res, next ) => {
33
41
  try {
34
42
  let query = [
35
43
  {
@@ -60,14 +68,80 @@ export const billingInfo = async ( req, res, next ) => {
60
68
  if ( !clientInfo ) {
61
69
  return res.sendError( 'no data found', 204 );
62
70
  }
63
- let storeCount = await storeService.count( { clientId: clientInfo.clientId } );
71
+ let storeCount = await storeService.count( { clientId: clientInfo[0].clientId } );
72
+
73
+ let totalProducts = clientInfo[0].planDetails.product;
74
+ let liveProducts = [];
75
+ let trialProducts = [];
76
+ let expiredProducts = [];
77
+ let currentDate = new Date();
78
+
79
+ // Function to calculate the difference between two dates
80
+ function dateDifference( date1, date2 ) {
81
+ // Convert both dates to milliseconds
82
+ let date1ms = date1.getTime();
83
+ let date2ms = date2.getTime();
84
+ // Calculate the difference in milliseconds
85
+ let differencems = Math.abs( date1ms - date2ms );
86
+ // Convert the difference back to days
87
+ return Math.floor( differencems / ( 1000 * 60 * 60 * 24 ) );
88
+ }
89
+
90
+ totalProducts.forEach( ( element ) => {
91
+ if ( element.status == 'live' ) {
92
+ liveProducts.push( { 'productName': element.productName } );
93
+ element.toolTip = 'Subscribed';
94
+ }
95
+ if ( element.status == 'trial' && ( element.trialEndDate >= currentDate ) ) {
96
+ let differenceInDays = dateDifference( element.trialEndDate, currentDate );
97
+ trialProducts.push( { 'productName': element.productName, 'toolTip': differenceInDays +' days trial left' } );
98
+ element.toolTip = 'On Trial';
99
+ }
100
+ if ( element.status == 'trial' && ( element.trialEndDate < currentDate ) ) {
101
+ expiredProducts.push( { 'productName': element.productName, 'toolTip': 'Trial Expired' } );
102
+ element.toolTip = 'Trial Expired';
103
+ }
104
+ } );
105
+
106
+ let priceType = '';
107
+ if ( clientInfo[0].priceType == 'step' ) {
108
+ priceType = 'Step Pricing';
109
+ } else if ( clientInfo[0].priceType == 'standard' ) {
110
+ priceType = 'Standard Pricing';
111
+ }
112
+
113
+ // Check Due Limit from invoice //
114
+
115
+ // Check Client Request from client request//
116
+ let getClientRequest = await clientRequestService.find( { clientId: clientInfo[0].clientId, status: 'pending' } );
117
+ let getPCR = true;
118
+ if ( !getClientRequest.length ) {
119
+ getPCR = false;
120
+ }
121
+
122
+ let currentPlanInfo = {};
123
+ currentPlanInfo.paymentStatus = clientInfo[0].planDetails.paymentStatus || '--';
124
+ currentPlanInfo.dueLimitReached = false;
125
+ currentPlanInfo.price = clientInfo[0].price || '--';
126
+ currentPlanInfo.priceType = priceType || '--';
127
+ currentPlanInfo.subscriptionType = clientInfo[0].planDetails.subscriptionType || '--';
128
+ currentPlanInfo.subscriptionPeriod = clientInfo[0].planDetails.subscriptionPeriod || '--';
129
+ currentPlanInfo.storeCount = storeCount || '--';
130
+ currentPlanInfo.totalCamera = clientInfo[0].planDetails.totalCamera || '--';
131
+ currentPlanInfo.totalStores = clientInfo[0].planDetails.totalStores || '--';
132
+ currentPlanInfo.storeSize = clientInfo[0].planDetails.totalStores || '--';
133
+ currentPlanInfo.liveProducts = liveProducts || '--';
134
+ currentPlanInfo.trialProducts = trialProducts || '--';
135
+ currentPlanInfo.expiredProducts = expiredProducts || '--';
136
+ currentPlanInfo.product = totalProducts || '--';
137
+ currentPlanInfo.pendingClientRequest = getPCR;
64
138
 
65
139
  let data = {
66
140
  _id: clientInfo[0]._id,
67
141
  clientId: clientInfo[0].clientId,
68
- currentPlanInfo: { ...clientInfo[0].planDetails, storeCount: storeCount, price: clientInfo[0].price, priceType: clientInfo[0].priceType },
142
+ currentPlanInfo: currentPlanInfo,
69
143
  billingDetails: { ...clientInfo[0].billingDetails, nextBillingDate: '--' },
70
- BankDetails: clientInfo[0].virtualAccount,
144
+ bankDetails: clientInfo[0].virtualAccount,
71
145
  };
72
146
 
73
147
  return res.sendSuccess( data );
@@ -8,11 +8,7 @@ export const paymentSubscriptionRouter = express.Router();
8
8
 
9
9
  paymentSubscriptionRouter.post( '/addBilling', isAllowedSessionHandler, validate( validationDtos.validateBillingParams ), validateClient, paymentController.addBilling );
10
10
 
11
- paymentSubscriptionRouter.get( '/clientBillingInfo/:clientId', isAllowedSessionHandler, validate( validationDtos.validateBrandParams ), paymentController.billingInfo );
12
-
13
- paymentSubscriptionRouter.get( '/storeList', isAllowedSessionHandler, validate( validationDtos.validateStoreParams ), paymentController.getStoreList );
14
-
15
- paymentSubscriptionRouter.get( '/clientList', isAllowedSessionHandler, paymentController.getClientList );
11
+ paymentSubscriptionRouter.get( '/clientBillingSubscriptionInfo/:clientId', isAllowedSessionHandler, validate( validationDtos.validateBrandParams ), paymentController.clientBillingSubscriptionInfo );
16
12
 
17
13
  paymentSubscriptionRouter.post( '/basePricing', validate( validationDtos.validateProducts ), paymentController.pricingInfo );
18
14