tango-app-api-payment-subscription 3.0.18-dev → 3.0.20-dev
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.
|
|
3
|
+
"version": "3.0.20-dev",
|
|
4
4
|
"description": "paymentSubscription",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -23,7 +23,10 @@
|
|
|
23
23
|
"tango-api-schema": "^2.0.62",
|
|
24
24
|
"tango-app-api-middleware": "^1.0.49-dev",
|
|
25
25
|
"winston": "^3.12.0",
|
|
26
|
-
"winston-daily-rotate-file": "^5.0.0"
|
|
26
|
+
"winston-daily-rotate-file": "^5.0.0",
|
|
27
|
+
"html-to-pdfmake": "^2.5.6",
|
|
28
|
+
"jsdom": "^24.0.0",
|
|
29
|
+
"pdfmake": "^0.2.10"
|
|
27
30
|
},
|
|
28
31
|
"devDependencies": {
|
|
29
32
|
"eslint": "^8.57.0",
|
|
@@ -10,6 +10,9 @@ import dayjs from 'dayjs';
|
|
|
10
10
|
import Handlebars from 'handlebars';
|
|
11
11
|
import fs from 'fs';
|
|
12
12
|
import path from 'path';
|
|
13
|
+
import { JSDOM } from 'jsdom';
|
|
14
|
+
import pdfMake from 'pdfmake';
|
|
15
|
+
import htmlToPdfmake from 'html-to-pdfmake';
|
|
13
16
|
|
|
14
17
|
export const addBilling = async ( req, res ) => {
|
|
15
18
|
try {
|
|
@@ -630,13 +633,13 @@ export const notificationList = async ( req, res ) => {
|
|
|
630
633
|
if ( item.product?.trialStartDate && item.product?.trialEndDate ) {
|
|
631
634
|
let [ firstWord, secondWord ] = item.product.productName.replace( /([a-z])([A-Z])/g, '$1 $2' ).split( ' ' );
|
|
632
635
|
firstWord = firstWord.charAt( 0 ).toUpperCase() + firstWord.slice( 1 );
|
|
633
|
-
let startDate = dayjs( item.product.trialStartDate );
|
|
634
|
-
let endDate = dayjs( item.product.trialEndDate ).startOf( 'day' );
|
|
636
|
+
let startDate = dayjs( item.product.trialStartDate ).startOf( 'day' );
|
|
637
|
+
let endDate = dayjs( item.product.trialEndDate ).startOf( 'day' ).add( 1, 'days' );
|
|
635
638
|
let date = dayjs().startOf( 'day' );
|
|
636
639
|
let days = date.diff( startDate, 'day' );
|
|
637
640
|
let totalDays = endDate.diff( startDate, 'day' );
|
|
638
641
|
let percentage = Math.round( ( days / totalDays )* 100 );
|
|
639
|
-
let leftDays = endDate.diff( date, 'day' )
|
|
642
|
+
let leftDays = endDate.diff( date, 'day' );
|
|
640
643
|
notificationList.push( {
|
|
641
644
|
product: item.product.productName,
|
|
642
645
|
name: `${firstWord} ${secondWord}`,
|
|
@@ -758,7 +761,7 @@ export const trialExtendRequestApproval = async ( req, res ) => {
|
|
|
758
761
|
days: req.body.days,
|
|
759
762
|
date: trialDate,
|
|
760
763
|
};
|
|
761
|
-
const templateHtml = fs.readFileSync( path.resolve( path.dirname( '' ) ) + '/src/hbs/
|
|
764
|
+
const templateHtml = fs.readFileSync( path.resolve( path.dirname( '' ) ) + '/src/hbs/trialExtentionEmail.hbs', 'utf8' );
|
|
762
765
|
const template = Handlebars.compile( templateHtml );
|
|
763
766
|
const html = template( { data: data } );
|
|
764
767
|
let params = {
|
|
@@ -772,6 +775,7 @@ export const trialExtendRequestApproval = async ( req, res ) => {
|
|
|
772
775
|
}
|
|
773
776
|
return res.sendSuccess( 'Trial Extended Successfully' );
|
|
774
777
|
} ).catch( ( e ) => {
|
|
778
|
+
logger.error( { error: e, function: 'trialExtendRequestApproval' } );
|
|
775
779
|
return res.sendError( e, 500 );
|
|
776
780
|
} );
|
|
777
781
|
} catch ( e ) {
|
|
@@ -925,6 +929,7 @@ export const productViewList = async ( req, res ) => {
|
|
|
925
929
|
},
|
|
926
930
|
},
|
|
927
931
|
];
|
|
932
|
+
|
|
928
933
|
let storeProductCount = await storeService.aggregate( query );
|
|
929
934
|
let clientProduct = await paymentService.findOne( { clientId: req.query.clientId }, { 'planDetails.product': 1 } );
|
|
930
935
|
|
|
@@ -953,6 +958,11 @@ export const productViewList = async ( req, res ) => {
|
|
|
953
958
|
},
|
|
954
959
|
);
|
|
955
960
|
} );
|
|
961
|
+
if ( req.query.sortBy == -1 ) {
|
|
962
|
+
products.sort( ( a, b ) => b.storeCount - a.storeCount ? -1 : 1 );
|
|
963
|
+
} else {
|
|
964
|
+
products.sort( ( a, b ) => a.storeCount - b.storeCount ? 1 : -1 );
|
|
965
|
+
}
|
|
956
966
|
// storeProductCount.forEach( ( item ) => {
|
|
957
967
|
// let productBasePrice = productPrice.basePricing.find( ( product ) => product.productName == item.product );
|
|
958
968
|
// if ( productBasePrice ) {
|
|
@@ -1227,14 +1237,14 @@ export const invoiceList = async ( req, res ) => {
|
|
|
1227
1237
|
$project: {
|
|
1228
1238
|
_id: 1,
|
|
1229
1239
|
invoice: 1,
|
|
1230
|
-
stores: 1,
|
|
1231
1240
|
billingDate: 1,
|
|
1232
|
-
|
|
1233
|
-
|
|
1241
|
+
stores: 1,
|
|
1242
|
+
products: 1,
|
|
1234
1243
|
amount: 1,
|
|
1244
|
+
paymentMethod: 1,
|
|
1245
|
+
status: 1,
|
|
1235
1246
|
discount: 1,
|
|
1236
1247
|
revisedAmount: 1,
|
|
1237
|
-
products: 1,
|
|
1238
1248
|
},
|
|
1239
1249
|
} );
|
|
1240
1250
|
|
|
@@ -1274,6 +1284,7 @@ export const invoiceList = async ( req, res ) => {
|
|
|
1274
1284
|
if ( !req.body.export ) {
|
|
1275
1285
|
return res.sendSuccess( data );
|
|
1276
1286
|
} else {
|
|
1287
|
+
let exportData = [];
|
|
1277
1288
|
invoiceDetails[0].data.forEach( ( item ) => {
|
|
1278
1289
|
if ( item.status == 'trial' ) {
|
|
1279
1290
|
item.amount = 'Trial';
|
|
@@ -1281,10 +1292,17 @@ export const invoiceList = async ( req, res ) => {
|
|
|
1281
1292
|
if ( item.status == 'free' ) {
|
|
1282
1293
|
item.amount = 'Free';
|
|
1283
1294
|
}
|
|
1284
|
-
|
|
1285
|
-
|
|
1295
|
+
exportData.push( {
|
|
1296
|
+
'Invoice': item.invoice,
|
|
1297
|
+
'Billing Date': item.billingDate,
|
|
1298
|
+
'Stores': item.stores,
|
|
1299
|
+
...( req.user.userType == 'tango' ? { 'Products': item.products } : {} ),
|
|
1300
|
+
'Amount': item.amount,
|
|
1301
|
+
...( req.user.userType == 'client' ? { 'Payment Method': item.paymentMethod } : {} ),
|
|
1302
|
+
'Status': item.status,
|
|
1303
|
+
} );
|
|
1286
1304
|
} );
|
|
1287
|
-
download(
|
|
1305
|
+
await download( exportData, res );
|
|
1288
1306
|
}
|
|
1289
1307
|
} catch ( e ) {
|
|
1290
1308
|
logger.error( { error: e, function: 'invoiceList' } );
|
|
@@ -1380,7 +1398,7 @@ export const priceList = async ( req, res ) => {
|
|
|
1380
1398
|
let result = {
|
|
1381
1399
|
product: data,
|
|
1382
1400
|
totalActualPrice: originalTotalPrice,
|
|
1383
|
-
totalNegotiatePrice: discountTotalPrice,
|
|
1401
|
+
totalNegotiatePrice: discountTotalPrice.toFixed( 2 ),
|
|
1384
1402
|
actualPrice: totalProductPrice,
|
|
1385
1403
|
negotiatePrice: totalnegotiatePrice,
|
|
1386
1404
|
discountPrice: discountPrice,
|
|
@@ -1531,7 +1549,7 @@ export const updatedRevisedPrice = async ( req, res ) => {
|
|
|
1531
1549
|
|
|
1532
1550
|
export const unpaidInvoiceList = async ( req, res ) => {
|
|
1533
1551
|
try {
|
|
1534
|
-
let invoiceDetails = await invoiceService.find( { clientId: req.params.clientId, status: { $
|
|
1552
|
+
let invoiceDetails = await invoiceService.find( { clientId: req.params.clientId, status: { $nin: [ 'paid', 'trial', 'free' ] } }, { invoice: 1, status: 1, amount: 1, revisedAmount: 1, totalAmount: 1, discount: 1 } );
|
|
1535
1553
|
if ( !invoiceDetails.length ) {
|
|
1536
1554
|
return res.sendError( 'no data found', 204 );
|
|
1537
1555
|
}
|
|
@@ -1677,12 +1695,34 @@ export const getExpiredClients = async ( req, res ) => {
|
|
|
1677
1695
|
|
|
1678
1696
|
export const invoiceDownload = async ( req, res ) => {
|
|
1679
1697
|
try {
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1698
|
+
const templateHtml = fs.readFileSync( path.resolve( path.dirname( '' ) ) + '/src/hbs/invoicePdf.hbs', 'utf8' );
|
|
1699
|
+
const template = Handlebars.compile( templateHtml );
|
|
1700
|
+
const html = template( { data: '' } );
|
|
1701
|
+
let fonts = {
|
|
1702
|
+
Helvetica: {
|
|
1703
|
+
normal: 'Helvetica',
|
|
1704
|
+
bold: 'Helvetica-Bold',
|
|
1705
|
+
italics: 'Helvetica-Oblique',
|
|
1706
|
+
bolditalics: 'Helvetica-BoldOblique',
|
|
1707
|
+
},
|
|
1708
|
+
};
|
|
1709
|
+
let printer = new pdfMake( fonts );
|
|
1710
|
+
|
|
1711
|
+
let { window } = new JSDOM( '' );
|
|
1712
|
+
const htmlTemplate = htmlToPdfmake( html, { window: window, tableAutoSize: true } );
|
|
1713
|
+
|
|
1714
|
+
const docDefinition = {
|
|
1715
|
+
content: htmlTemplate,
|
|
1716
|
+
defaultStyle: {
|
|
1717
|
+
font: 'Helvetica',
|
|
1718
|
+
},
|
|
1719
|
+
};
|
|
1720
|
+
let pdfDoc = printer.createPdfKitDocument( docDefinition );
|
|
1721
|
+
res.setHeader( 'Content-disposition', `attachment; filename=Report_1.pdf` );
|
|
1722
|
+
res.setHeader( 'Content-Type', 'application/pdf' );
|
|
1723
|
+
pdfDoc.pipe( res );
|
|
1724
|
+
pdfDoc.end();
|
|
1684
1725
|
} catch ( e ) {
|
|
1685
|
-
// console.log( e );
|
|
1686
1726
|
logger.error( { error: e, function: 'invoiceDownload' } );
|
|
1687
1727
|
return res.sendError( e, 500 );
|
|
1688
1728
|
}
|
|
@@ -1707,7 +1747,7 @@ export const updateInvoiceStatus = async ( req, res ) => {
|
|
|
1707
1747
|
return res.sendSuccess( 'Invoice updated Successfully' );
|
|
1708
1748
|
} );
|
|
1709
1749
|
} catch ( e ) {
|
|
1710
|
-
logger.error( { error: e, function: '
|
|
1750
|
+
logger.error( { error: e, function: 'updateInvoiceStatus' } );
|
|
1711
1751
|
return res.sendError( e, 500 );
|
|
1712
1752
|
}
|
|
1713
1753
|
};
|
|
@@ -1744,8 +1784,7 @@ export const invoiceCreate = async ( req, res ) => {
|
|
|
1744
1784
|
}
|
|
1745
1785
|
return res.sendSuccess( 'Invoice Created Successfully' );
|
|
1746
1786
|
} catch ( e ) {
|
|
1747
|
-
|
|
1748
|
-
logger.error( { error: e, function: 'invoiceDownload' } );
|
|
1787
|
+
logger.error( { error: e, function: 'invoiceCreate' } );
|
|
1749
1788
|
return res.sendError( e, 500 );
|
|
1750
1789
|
}
|
|
1751
1790
|
};
|
|
@@ -20,6 +20,14 @@ export const validateStoreParams = {
|
|
|
20
20
|
} ),
|
|
21
21
|
};
|
|
22
22
|
|
|
23
|
+
export const validateProductListParams = {
|
|
24
|
+
query: joi.object( {
|
|
25
|
+
clientId: joi.string().required(),
|
|
26
|
+
sortColumn: joi.string().required(),
|
|
27
|
+
sortBy: joi.number().required(),
|
|
28
|
+
} ),
|
|
29
|
+
};
|
|
30
|
+
|
|
23
31
|
export const validateProducts = {
|
|
24
32
|
body: joi.object( {
|
|
25
33
|
camaraPerSqft: joi.string().required(),
|
|
@@ -96,7 +96,7 @@ paymentSubscriptionRouter.get( '/admin/getProductViewList', isAllowedSessionHand
|
|
|
96
96
|
userType: [ 'tango' ], access: [
|
|
97
97
|
{ featureName: 'settings', name: 'paymentSubscriptions', permissions: [ 'isView' ] },
|
|
98
98
|
],
|
|
99
|
-
} ), validate( validationDtos.
|
|
99
|
+
} ), validate( validationDtos.validateProductListParams ), validateClient, paymentController.productViewList );
|
|
100
100
|
|
|
101
101
|
paymentSubscriptionRouter.post( '/admin/getstoreViewList', isAllowedSessionHandler, authorize( {
|
|
102
102
|
userType: [ 'tango' ], access: [
|
|
@@ -154,7 +154,7 @@ paymentSubscriptionRouter.post( '/admin/getStoreProducts', isAllowedSessionHandl
|
|
|
154
154
|
|
|
155
155
|
paymentSubscriptionRouter.get( '/trialRemaindList', paymentController.getRemindClients );
|
|
156
156
|
paymentSubscriptionRouter.get( '/trialExpiredList', paymentController.getExpiredClients );
|
|
157
|
-
paymentSubscriptionRouter.
|
|
157
|
+
paymentSubscriptionRouter.post( '/invoiceDownload', paymentController.invoiceDownload );
|
|
158
158
|
paymentSubscriptionRouter.post( '/invoiceStatusUpdate/:invoiceId', paymentController.updateInvoiceStatus );
|
|
159
159
|
paymentSubscriptionRouter.post( '/invoice/create', validateClient, paymentController.invoiceCreate );
|
|
160
160
|
|