tango-app-api-payment-subscription 3.0.39-dev → 3.0.41-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.41-dev",
|
|
4
4
|
"description": "paymentSubscription",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"nodemon": "^3.1.0",
|
|
26
26
|
"pdfmake": "^0.2.10",
|
|
27
27
|
"swagger-ui-express": "^5.0.0",
|
|
28
|
-
"tango-api-schema": "^2.0.
|
|
29
|
-
"tango-app-api-middleware": "^1.0.
|
|
28
|
+
"tango-api-schema": "^2.0.89",
|
|
29
|
+
"tango-app-api-middleware": "^1.0.58-dev",
|
|
30
30
|
"winston": "^3.12.0",
|
|
31
31
|
"winston-daily-rotate-file": "^5.0.0"
|
|
32
32
|
},
|
|
@@ -324,7 +324,7 @@ async function calculatePricing( req, res ) {
|
|
|
324
324
|
}
|
|
325
325
|
finalPrice = Math.ceil( finalPrice / 10 ) * 10; // for round off to 10 position
|
|
326
326
|
if ( input.currencyType && input.currencyType == 'dollar' ) {
|
|
327
|
-
dollerprice = ( ( finalPrice * 50 ) / 100 );
|
|
327
|
+
let dollerprice = ( ( finalPrice * 50 ) / 100 );
|
|
328
328
|
finalPrice = ( dollerprice + finalPrice ) / 84;
|
|
329
329
|
dollerpriceOriginal = ( ( OriginalPrice * 50 ) / 100 );
|
|
330
330
|
OriginalPrice = ( dollerpriceOriginal + OriginalPrice ) / 84;
|
|
@@ -505,6 +505,32 @@ export const updateSubscription = async ( req, res ) => {
|
|
|
505
505
|
if ( result.modifiedCount ) {
|
|
506
506
|
req.body.clientId = req.params.clientId;
|
|
507
507
|
updatePricing( req, res, true );
|
|
508
|
+
let products = data.planDetails.product.map( ( item ) => {
|
|
509
|
+
let [ firstWord, secondWord ] = item.productName.replace( /([a-z])([A-Z])/g, '$1 $2' ).split( ' ' );
|
|
510
|
+
return firstWord.toLowerCase() + '_' + secondWord.toLowerCase();
|
|
511
|
+
} );
|
|
512
|
+
await axios.get( `${appConfig.url.oldapidomain}/oldBrandGet/${req.params.clientId}`, { headers: { Authorization: 'Bearer d47433f8-9a33-47c7-ba43-1a0fbac28f66' } } ).then( async ( response ) => {
|
|
513
|
+
let existsProducts = Object.keys( response.data.data.subscribed_features );
|
|
514
|
+
existsProducts.forEach( ( item ) => {
|
|
515
|
+
if ( products.includes( item ) ) {
|
|
516
|
+
response.data.data.subscribed_features[item] = true;
|
|
517
|
+
} else {
|
|
518
|
+
response.data.data.subscribed_features[item] = false;
|
|
519
|
+
}
|
|
520
|
+
} );
|
|
521
|
+
products.forEach( ( item ) => {
|
|
522
|
+
if ( !existsProducts.includes( item ) ) {
|
|
523
|
+
response.data.data.subscribed_features[item] = true;
|
|
524
|
+
}
|
|
525
|
+
} );
|
|
526
|
+
await axios.post( `${appConfig.url.oldapidomain}/oldBrandUpdate/${response.data.data._id}`, response.data.data, { headers: { Authorization: 'Bearer d47433f8-9a33-47c7-ba43-1a0fbac28f66' } } ).then( ( result ) => {
|
|
527
|
+
logger.info( result.data );
|
|
528
|
+
} ).catch( ( error ) => {
|
|
529
|
+
logger.error( { error: error, function: 'old Product update' } );
|
|
530
|
+
} );
|
|
531
|
+
} ).catch( ( error ) => {
|
|
532
|
+
logger.error( { error: error, function: 'old Product update' } );
|
|
533
|
+
} );
|
|
508
534
|
return res.sendSuccess( { message: 'Subscription Updated Successfully' } );
|
|
509
535
|
} else {
|
|
510
536
|
return res.sendError( 'Something went wrong', 500 );
|
|
@@ -696,7 +722,7 @@ export const invoiceDetails = async ( req, res ) => {
|
|
|
696
722
|
|
|
697
723
|
export const updateInvoiceDetails = async ( req, res ) => {
|
|
698
724
|
try {
|
|
699
|
-
let clientInvoiceDetails = await paymentService.findOne( { clientId: req.params.clientId
|
|
725
|
+
let clientInvoiceDetails = await paymentService.findOne( { clientId: req.params.clientId }, { paymentInvoice: 1 } );
|
|
700
726
|
if ( !clientInvoiceDetails ) {
|
|
701
727
|
return res.sendError( 'no data found', 204 );
|
|
702
728
|
}
|
|
@@ -863,6 +889,32 @@ export const trialApproval = async ( req, res ) => {
|
|
|
863
889
|
};
|
|
864
890
|
await sendEmailWithSES( params.toEmail, params.mailSubject, params.htmlBody, params.attachment, params.sourceEmail );
|
|
865
891
|
}
|
|
892
|
+
let products = clientProducts.planDetails.product.map( ( item ) => {
|
|
893
|
+
let [ firstWord, secondWord ] = item.productName.replace( /([a-z])([A-Z])/g, '$1 $2' ).split( ' ' );
|
|
894
|
+
return firstWord.toLowerCase() + '_' + secondWord.toLowerCase();
|
|
895
|
+
} );
|
|
896
|
+
await axios.get( `${appConfig.url.oldapidomain}/oldBrandGet/${requestData.clientId}`, { headers: { Authorization: 'Bearer d47433f8-9a33-47c7-ba43-1a0fbac28f66' } } ).then( async ( response ) => {
|
|
897
|
+
let existsProducts = Object.keys( response.data.data.subscribed_features );
|
|
898
|
+
existsProducts.forEach( ( item ) => {
|
|
899
|
+
if ( products.includes( item ) ) {
|
|
900
|
+
response.data.data.subscribed_features[item] = true;
|
|
901
|
+
} else {
|
|
902
|
+
response.data.data.subscribed_features[item] = false;
|
|
903
|
+
}
|
|
904
|
+
} );
|
|
905
|
+
products.forEach( ( item ) => {
|
|
906
|
+
if ( !existsProducts.includes( item ) ) {
|
|
907
|
+
response.data.data.subscribed_features[item] = true;
|
|
908
|
+
}
|
|
909
|
+
} );
|
|
910
|
+
await axios.post( `${appConfig.url.oldapidomain}/oldBrandUpdate/${response.data.data._id}`, response.data.data, { headers: { Authorization: 'Bearer d47433f8-9a33-47c7-ba43-1a0fbac28f66' } } ).then( ( result ) => {
|
|
911
|
+
logger.info( result.data );
|
|
912
|
+
} ).catch( ( error ) => {
|
|
913
|
+
logger.error( { error: error, function: 'old Product update' } );
|
|
914
|
+
} );
|
|
915
|
+
} ).catch( ( error ) => {
|
|
916
|
+
logger.error( { error: error, function: 'old Product update' } );
|
|
917
|
+
} );
|
|
866
918
|
}
|
|
867
919
|
const logObj = {
|
|
868
920
|
clientId: req.body.clientId,
|
|
@@ -1064,6 +1116,32 @@ export const productSubscribe = async ( req, res ) => {
|
|
|
1064
1116
|
logger.error( { error: error, function: 'oldBulkStoreUpdate' } );
|
|
1065
1117
|
} );
|
|
1066
1118
|
updatePricing( req, res, true );
|
|
1119
|
+
let products = clientInfo.planDetails.product.map( ( item ) => {
|
|
1120
|
+
let [ firstWord, secondWord ] = item.productName.replace( /([a-z])([A-Z])/g, '$1 $2' ).split( ' ' );
|
|
1121
|
+
return firstWord.toLowerCase() + '_' + secondWord.toLowerCase();
|
|
1122
|
+
} );
|
|
1123
|
+
await axios.get( `${appConfig.url.oldapidomain}/oldBrandGet/${clientInfo.clientId}`, { headers: { Authorization: 'Bearer d47433f8-9a33-47c7-ba43-1a0fbac28f66' } } ).then( async ( response ) => {
|
|
1124
|
+
let existsProducts = Object.keys( response.data.data.subscribed_features );
|
|
1125
|
+
existsProducts.forEach( ( item ) => {
|
|
1126
|
+
if ( products.includes( item ) ) {
|
|
1127
|
+
response.data.data.subscribed_features[item] = true;
|
|
1128
|
+
} else {
|
|
1129
|
+
response.data.data.subscribed_features[item] = false;
|
|
1130
|
+
}
|
|
1131
|
+
} );
|
|
1132
|
+
products.forEach( ( item ) => {
|
|
1133
|
+
if ( !existsProducts.includes( item ) ) {
|
|
1134
|
+
response.data.data.subscribed_features[item] = true;
|
|
1135
|
+
}
|
|
1136
|
+
} );
|
|
1137
|
+
await axios.post( `${appConfig.url.oldapidomain}/oldBrandUpdate/${response.data.data._id}`, response.data.data, { headers: { Authorization: 'Bearer d47433f8-9a33-47c7-ba43-1a0fbac28f66' } } ).then( ( result ) => {
|
|
1138
|
+
logger.info( result.data );
|
|
1139
|
+
} ).catch( ( error ) => {
|
|
1140
|
+
logger.error( { error: error, function: 'old Product update' } );
|
|
1141
|
+
} );
|
|
1142
|
+
} ).catch( ( error ) => {
|
|
1143
|
+
logger.error( { error: error, function: 'old Product update' } );
|
|
1144
|
+
} );
|
|
1067
1145
|
} );
|
|
1068
1146
|
const logObj = {
|
|
1069
1147
|
clientId: req.body.clientId,
|
|
@@ -1474,6 +1552,32 @@ export const addStoreProduct = async ( req, res ) => {
|
|
|
1474
1552
|
eventType: 'update',
|
|
1475
1553
|
};
|
|
1476
1554
|
insertOpenSearchData( 'tango-retail-activity-logs', logObj );
|
|
1555
|
+
let products = clientInfo.planDetails.product.map( ( item ) => {
|
|
1556
|
+
let [ firstWord, secondWord ] = item.productName.replace( /([a-z])([A-Z])/g, '$1 $2' ).split( ' ' );
|
|
1557
|
+
return firstWord.toLowerCase() + '_' + secondWord.toLowerCase();
|
|
1558
|
+
} );
|
|
1559
|
+
await axios.get( `${appConfig.url.oldapidomain}/oldBrandGet/${req.body.clientId}`, { headers: { Authorization: 'Bearer d47433f8-9a33-47c7-ba43-1a0fbac28f66' } } ).then( async ( response ) => {
|
|
1560
|
+
let existsProducts = Object.keys( response.data.data.subscribed_features );
|
|
1561
|
+
existsProducts.forEach( ( item ) => {
|
|
1562
|
+
if ( products.includes( item ) ) {
|
|
1563
|
+
response.data.data.subscribed_features[item] = true;
|
|
1564
|
+
} else {
|
|
1565
|
+
response.data.data.subscribed_features[item] = false;
|
|
1566
|
+
}
|
|
1567
|
+
} );
|
|
1568
|
+
products.forEach( ( item ) => {
|
|
1569
|
+
if ( !existsProducts.includes( item ) ) {
|
|
1570
|
+
response.data.data.subscribed_features[item] = true;
|
|
1571
|
+
}
|
|
1572
|
+
} );
|
|
1573
|
+
await axios.post( `${appConfig.url.oldapidomain}/oldBrandUpdate/${response.data.data._id}`, response.data.data, { headers: { Authorization: 'Bearer d47433f8-9a33-47c7-ba43-1a0fbac28f66' } } ).then( ( result ) => {
|
|
1574
|
+
logger.info( result.data );
|
|
1575
|
+
} ).catch( ( error ) => {
|
|
1576
|
+
logger.error( { error: error, function: 'old Product update' } );
|
|
1577
|
+
} );
|
|
1578
|
+
} ).catch( ( error ) => {
|
|
1579
|
+
logger.error( { error: error, function: 'old Product update' } );
|
|
1580
|
+
} );
|
|
1477
1581
|
return res.sendSuccess( 'product updated Successfully' );
|
|
1478
1582
|
} catch ( e ) {
|
|
1479
1583
|
logger.error( { error: e, function: 'addStoreProduct' } );
|
|
@@ -1580,6 +1684,11 @@ export const invoiceList = async ( req, res ) => {
|
|
|
1580
1684
|
delete item.products;
|
|
1581
1685
|
} );
|
|
1582
1686
|
}
|
|
1687
|
+
invoiceDetails[0].data.forEach( ( item ) => {
|
|
1688
|
+
if ( req.body?.client?.paymentInvoice?.currencyType == 'dollar' ) {
|
|
1689
|
+
item.amount = convertINRtoUSD( item.amount );
|
|
1690
|
+
}
|
|
1691
|
+
} );
|
|
1583
1692
|
let data = {
|
|
1584
1693
|
data: invoiceDetails[0].data,
|
|
1585
1694
|
count: invoiceDetails[0].count[0].count,
|
|
@@ -1595,12 +1704,13 @@ export const invoiceList = async ( req, res ) => {
|
|
|
1595
1704
|
if ( item.status == 'free' ) {
|
|
1596
1705
|
item.amount = 'Free';
|
|
1597
1706
|
}
|
|
1707
|
+
item.products = item.products.map( ( item ) => item.product.product );
|
|
1598
1708
|
exportData.push( {
|
|
1599
1709
|
'Invoice': item.invoice,
|
|
1600
1710
|
'Billing Date': item.billingDate,
|
|
1601
1711
|
'Stores': item.stores,
|
|
1602
1712
|
...( req.user.userType == 'tango' ? { 'Products': item.products } : {} ),
|
|
1603
|
-
'Amount': item.amount,
|
|
1713
|
+
'Amount': req.body?.client?.paymentInvoice?.currencyType == 'dollar' ? item.amount : item.amount,
|
|
1604
1714
|
...( req.user.userType == 'client' ? { 'Payment Method': item.paymentMethod } : {} ),
|
|
1605
1715
|
'Status': item.status,
|
|
1606
1716
|
} );
|
|
@@ -1695,8 +1805,8 @@ export const priceList = async ( req, res ) => {
|
|
|
1695
1805
|
} );
|
|
1696
1806
|
} );
|
|
1697
1807
|
data = temp;
|
|
1698
|
-
let discountPrice =
|
|
1699
|
-
let discountPercentage = discountPrice > 0 ? ( discountPrice /
|
|
1808
|
+
let discountPrice = originalTotalPrice - discountTotalPrice;
|
|
1809
|
+
let discountPercentage = discountPrice > 0 ? ( discountPrice / originalTotalPrice ) * 100 : 0;
|
|
1700
1810
|
let gstAmount = discountTotalPrice * ( 18 / 100 );
|
|
1701
1811
|
let finalValue = parseFloat( discountTotalPrice ) + gstAmount;
|
|
1702
1812
|
let result = {
|
|
@@ -1738,6 +1848,11 @@ export const pricingListUpdate = async ( req, res ) => {
|
|
|
1738
1848
|
if ( req.body?.products && req.body?.products?.length ) {
|
|
1739
1849
|
productList = JSON.parse( JSON.stringify( req.body ) );
|
|
1740
1850
|
let amount =0;
|
|
1851
|
+
let origPrice=0;
|
|
1852
|
+
let IGST = 18;
|
|
1853
|
+
let CGST = 9;
|
|
1854
|
+
let SGST = 9;
|
|
1855
|
+
let gst = req.body.client.paymentInvoice.currencyType == 'dollar' ? IGST : ( CGST + SGST );
|
|
1741
1856
|
productList.products.forEach( ( item ) => {
|
|
1742
1857
|
let [ firstWord, secondWord ] = item.productName.replace( /([a-z])([A-Z])/g, '$1 $2' ).split( ' ' );
|
|
1743
1858
|
firstWord = firstWord.charAt( 0 ).toUpperCase() + firstWord.slice( 1 );
|
|
@@ -1746,17 +1861,28 @@ export const pricingListUpdate = async ( req, res ) => {
|
|
|
1746
1861
|
item.basePrice = convertINRtoUSD( item.basePrice );
|
|
1747
1862
|
item.price = convertINRtoUSD( item.price );
|
|
1748
1863
|
}
|
|
1749
|
-
|
|
1864
|
+
let count = item.storeCount;
|
|
1865
|
+
if ( req.body.type == 'step' ) {
|
|
1750
1866
|
item.storeCount = item.storeRange;
|
|
1867
|
+
let rangeSplit = item.storeRange.split( '-' );
|
|
1868
|
+
count = parseInt( rangeSplit[1] ) - parseInt( rangeSplit[0] );
|
|
1751
1869
|
}
|
|
1752
1870
|
amount = amount + item.price;
|
|
1871
|
+
origPrice = origPrice + ( item.basePrice * count );
|
|
1872
|
+
item.price = item.price.toFixed( 2 );
|
|
1753
1873
|
} );
|
|
1874
|
+
let discountAmount = origPrice - amount;
|
|
1875
|
+
let discountPercentage = ( discountAmount / origPrice ) * 100;
|
|
1754
1876
|
productList = {
|
|
1755
1877
|
...productList,
|
|
1756
|
-
amount: amount,
|
|
1878
|
+
amount: amount.toFixed( 2 ),
|
|
1757
1879
|
currencyType: req.body.client.paymentInvoice.currencyType == 'dollar' ? '$' : '₹',
|
|
1758
1880
|
total: amount.toFixed( 2 ),
|
|
1759
|
-
|
|
1881
|
+
final: ( parseFloat( amount ) + parseFloat( ( amount * gst ) / 100 ) ).toFixed( 2 ),
|
|
1882
|
+
discount: `${discountPercentage.toFixed( 2 )}% (-${discountAmount.toFixed( 2 )})`,
|
|
1883
|
+
IGST: req.body.client.paymentInvoice.currencyType == 'dollar' ? IGST : 0,
|
|
1884
|
+
CGST: req.body.client.paymentInvoice.currencyType == 'inr' ? CGST : 0,
|
|
1885
|
+
SGST: req.body.client.paymentInvoice.currencyType == 'inr' ? SGST : 0,
|
|
1760
1886
|
};
|
|
1761
1887
|
req.body.products.forEach( ( item ) => {
|
|
1762
1888
|
delete item.originalPrice;
|
|
@@ -1777,24 +1903,26 @@ export const pricingListUpdate = async ( req, res ) => {
|
|
|
1777
1903
|
getPriceInfo.step = req.body.products;
|
|
1778
1904
|
}
|
|
1779
1905
|
getPriceInfo.save().then( async () => {
|
|
1780
|
-
let clientDetails = await paymentService.findOne( { clientId: req.body.clientId }, { priceType: 1 } );
|
|
1906
|
+
let clientDetails = await paymentService.findOne( { clientId: req.body.clientId }, { priceType: 1, paymentInvoice: 1 } );
|
|
1781
1907
|
clientDetails.priceType = req.body.type;
|
|
1782
1908
|
|
|
1783
1909
|
clientDetails.save();
|
|
1784
1910
|
|
|
1785
|
-
let userDetails= await userService.findOne( { clientId: req.body.clientId, role: 'superadmin' } );
|
|
1786
|
-
if (
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1911
|
+
// let userDetails= await userService.findOne( { clientId: req.body.clientId, role: 'superadmin' } );
|
|
1912
|
+
if ( clientDetails?.paymentInvoice?.paymentAgreementTo?.length ) {
|
|
1913
|
+
clientDetails.paymentInvoice.paymentAgreementTo.forEach( ( email ) => {
|
|
1914
|
+
const templateHtml = fs.readFileSync( path.resolve( path.dirname( '' ) ) + '/src/hbs/revisedPriceEmail.hbs', 'utf8' );
|
|
1915
|
+
const template = Handlebars.compile( templateHtml );
|
|
1916
|
+
const html = template( { data: productList } );
|
|
1917
|
+
let params = {
|
|
1918
|
+
toEmail: email,
|
|
1919
|
+
mailSubject: 'Invoice Revised',
|
|
1920
|
+
htmlBody: html,
|
|
1921
|
+
attachment: '',
|
|
1922
|
+
sourceEmail: appConfig.cloud.aws.ses.adminEmail,
|
|
1923
|
+
};
|
|
1924
|
+
sendEmailWithSES( params.toEmail, params.mailSubject, params.htmlBody, params.attachment, params.sourceEmail );
|
|
1925
|
+
} );
|
|
1798
1926
|
}
|
|
1799
1927
|
let keys = [];
|
|
1800
1928
|
if ( req.body.type == 'standard' ) {
|
|
@@ -1866,7 +1994,12 @@ async function updatePricing( req, res, update ) {
|
|
|
1866
1994
|
}
|
|
1867
1995
|
let product = [];
|
|
1868
1996
|
let clientId = req.body.clientId;
|
|
1997
|
+
let paymentInvoice = clientDetails.paymentInvoice;
|
|
1869
1998
|
if ( !update ) {
|
|
1999
|
+
let userDetails= await userService.findOne( { clientId: req.body.clientId, role: 'superadmin' } );
|
|
2000
|
+
paymentInvoice.invoiceTo = [ userDetails.email ];
|
|
2001
|
+
paymentInvoice.paymentAgreementTo = [ userDetails.email ];
|
|
2002
|
+
paymentInvoice.currencyType = userDetails.countryCode == '91' ? 'inr': 'dollar';
|
|
1870
2003
|
clientDetails.planDetails.product.forEach( ( item ) => {
|
|
1871
2004
|
product.push( {
|
|
1872
2005
|
productName: item.productName,
|
|
@@ -1900,6 +2033,7 @@ async function updatePricing( req, res, update ) {
|
|
|
1900
2033
|
'planDetails.paymentStatus': clientDetails?.subscriptionType == 'free' ? 'free' : paymentStatus,
|
|
1901
2034
|
'planDetails.product': product,
|
|
1902
2035
|
'price': pricingDetails.price,
|
|
2036
|
+
'paymentInvoice': paymentInvoice,
|
|
1903
2037
|
};
|
|
1904
2038
|
await paymentService.updateOne( { clientId: clientId }, details );
|
|
1905
2039
|
}
|
|
@@ -1915,11 +2049,15 @@ export const updatedRevisedPrice = async ( req, res ) => {
|
|
|
1915
2049
|
invoiceDetails.revisedAmount = req.body.revisedAmount;
|
|
1916
2050
|
invoiceDetails.discount = req.body.discount;
|
|
1917
2051
|
invoiceDetails.save().then( async () => {
|
|
1918
|
-
let
|
|
1919
|
-
|
|
2052
|
+
let clientDetails = await paymentService.findOne( { clientId: invoiceDetails.clientId } );
|
|
2053
|
+
// let userDetails= await userService.findOne( { clientId: invoiceDetails.clientId, role: 'superadmin' } );
|
|
2054
|
+
if ( clientDetails.paymentInvoice.invoiceTo.length ) {
|
|
1920
2055
|
let invoiceInfo;
|
|
1921
|
-
let clientDetails = await paymentService.findOne( { clientId: invoiceDetails.clientId } );
|
|
1922
2056
|
let amount = 0;
|
|
2057
|
+
let IGST = 18;
|
|
2058
|
+
let CGST = 9;
|
|
2059
|
+
let SGST = 9;
|
|
2060
|
+
let gst = clientDetails?.paymentInvoice?.currencyType == 'dollar' ? IGST : ( CGST + SGST );
|
|
1923
2061
|
invoiceDetails.products.forEach( ( item ) => {
|
|
1924
2062
|
let [ firstWord, secondWord ] = item.product.product.replace( /([a-z])([A-Z])/g, '$1 $2' ).split( ' ' );
|
|
1925
2063
|
firstWord = firstWord.charAt( 0 ).toUpperCase() + firstWord.slice( 1 );
|
|
@@ -1936,6 +2074,7 @@ export const updatedRevisedPrice = async ( req, res ) => {
|
|
|
1936
2074
|
let invoiceDate= dayjs( invoiceDetails.createdAt ).format( 'DD MMM, YYYY' );
|
|
1937
2075
|
let days = clientDetails?.paymentInvoice?.extendPaymentPeriodDays || 10;
|
|
1938
2076
|
let dueDate = invoiceDetails?.dueDate ? dayjs( invoiceDetails?.dueDate ).format( 'DD MMM, YYYY' ) : dayjs().add( days, 'days' ).format( 'DD MMM, YYYY' );
|
|
2077
|
+
let discountAmount = ( amount * req.body.discount ) / 100;
|
|
1939
2078
|
invoiceInfo = {
|
|
1940
2079
|
...invoiceDetails._doc,
|
|
1941
2080
|
clientName: clientDetails.clientName,
|
|
@@ -1943,22 +2082,28 @@ export const updatedRevisedPrice = async ( req, res ) => {
|
|
|
1943
2082
|
address: clientDetails.billingDetails.billingAddress,
|
|
1944
2083
|
amount: amount.toFixed( 2 ),
|
|
1945
2084
|
currencyType: clientDetails.paymentInvoice.currencyType == 'dollar' ? '$' : '₹',
|
|
1946
|
-
discount: req.body.discount
|
|
1947
|
-
total:
|
|
2085
|
+
discount: `${req.body.discount.toFixed( 2 )}% (-${discountAmount.toFixed( 2 )})`,
|
|
2086
|
+
total: ( parseFloat( amount ) + parseFloat( ( amount * gst ) / 100 ) ).toFixed( 2 ),
|
|
2087
|
+
final: req.body.revisedAmount.toFixed( 2 ),
|
|
2088
|
+
IGST: clientDetails.paymentInvoice.currencyType == 'dollar' ? IGST : 0,
|
|
2089
|
+
CGST: clientDetails.paymentInvoice.currencyType == 'inr' ? CGST : 0,
|
|
2090
|
+
SGST: clientDetails.paymentInvoice.currencyType == 'inr' ? SGST : 0,
|
|
1948
2091
|
invoiceDate,
|
|
1949
2092
|
dueDate,
|
|
1950
2093
|
};
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
2094
|
+
clientDetails.paymentInvoice.invoiceTo.forEach( ( email ) => {
|
|
2095
|
+
const templateHtml = fs.readFileSync( path.resolve( path.dirname( '' ) ) + '/src/hbs/trialCreditNoteEmail.hbs', 'utf8' );
|
|
2096
|
+
const template = Handlebars.compile( templateHtml );
|
|
2097
|
+
const html = template( { data: invoiceInfo } );
|
|
2098
|
+
let params = {
|
|
2099
|
+
toEmail: email,
|
|
2100
|
+
mailSubject: 'Credit Note',
|
|
2101
|
+
htmlBody: html,
|
|
2102
|
+
attachment: '',
|
|
2103
|
+
sourceEmail: appConfig.cloud.aws.ses.adminEmail,
|
|
2104
|
+
};
|
|
2105
|
+
sendEmailWithSES( params.toEmail, params.mailSubject, params.htmlBody, params.attachment, params.sourceEmail );
|
|
2106
|
+
} );
|
|
1962
2107
|
}
|
|
1963
2108
|
const logObj = {
|
|
1964
2109
|
clientId: req.body.clientId,
|
|
@@ -192,39 +192,55 @@ export const validateUpdateSubscriptionParams = {
|
|
|
192
192
|
body: validateUpdateSubscriptionSchema,
|
|
193
193
|
};
|
|
194
194
|
|
|
195
|
-
export const dailyPricingSchema = {
|
|
195
|
+
export const dailyPricingSchema = joi.object( {
|
|
196
196
|
clientId: joi.array().required(),
|
|
197
197
|
date: joi.string().required(),
|
|
198
|
-
};
|
|
198
|
+
} );
|
|
199
199
|
|
|
200
200
|
export const dailyPricingParams = {
|
|
201
201
|
body: dailyPricingSchema,
|
|
202
202
|
};
|
|
203
203
|
|
|
204
|
-
export const invoiceGenerateSchema = {
|
|
204
|
+
export const invoiceGenerateSchema = joi.object( {
|
|
205
205
|
clientId: joi.array().required(),
|
|
206
206
|
fromDate: joi.string().required(),
|
|
207
207
|
toDate: joi.string().required(),
|
|
208
|
-
};
|
|
208
|
+
} );
|
|
209
209
|
|
|
210
210
|
export const invoiceGenerateParams = {
|
|
211
211
|
body: invoiceGenerateSchema,
|
|
212
212
|
};
|
|
213
213
|
|
|
214
|
-
export const invoiceUpdateSchema = {
|
|
214
|
+
export const invoiceUpdateSchema = joi.object( {
|
|
215
215
|
amount: joi.number().required(),
|
|
216
216
|
paymentType: joi.string().required(),
|
|
217
217
|
paymentReferenceId: joi.string().required(),
|
|
218
|
-
};
|
|
218
|
+
} );
|
|
219
|
+
|
|
219
220
|
export const invoiceUpdateParams = {
|
|
220
221
|
body: invoiceUpdateSchema,
|
|
221
222
|
};
|
|
222
223
|
|
|
223
224
|
|
|
224
|
-
export const invoiceRevisedSchema = {
|
|
225
|
+
export const invoiceRevisedSchema = joi.object( {
|
|
225
226
|
invoiceId: joi.string().required(),
|
|
226
|
-
};
|
|
227
|
+
} );
|
|
228
|
+
|
|
227
229
|
export const invoiceRevisedParams = {
|
|
228
230
|
params: invoiceRevisedSchema,
|
|
229
231
|
};
|
|
230
232
|
|
|
233
|
+
export const validateInvoiceUpdateSchema = joi.object( {
|
|
234
|
+
proRate: joi.string().required(),
|
|
235
|
+
paymenttype: joi.string().required(),
|
|
236
|
+
paymentCycle: joi.string().required(),
|
|
237
|
+
currencyType: joi.string().required(),
|
|
238
|
+
invoiceTo: joi.array().items( joi.string().email().message( 'Enter valid Email' ) ).required(),
|
|
239
|
+
paymentAgreementTo: joi.array().items( joi.string().email().message( 'Enter valid Email' ) ).required(),
|
|
240
|
+
invoiceOn: joi.string().required(),
|
|
241
|
+
extendPaymentPeriodDays: joi.number().required(),
|
|
242
|
+
} );
|
|
243
|
+
|
|
244
|
+
export const validateInvoiceUpdateParams = {
|
|
245
|
+
body: validateInvoiceUpdateSchema,
|
|
246
|
+
};
|
|
@@ -211,7 +211,19 @@
|
|
|
211
211
|
<td class="invoicesub" style="padding-left:30px; line-height: 24px;">IGST</td>
|
|
212
212
|
<td></td>
|
|
213
213
|
<td></td>
|
|
214
|
-
<td class="invoicesub">
|
|
214
|
+
<td class="invoicesub">{{data.IGST}}%</td>
|
|
215
|
+
</tr>
|
|
216
|
+
<tr bgcolor="#ffffff" style="border:none;margin-top:0px;">
|
|
217
|
+
<td class="invoicesub" style="padding-left:30px; line-height: 24px;">CGST</td>
|
|
218
|
+
<td></td>
|
|
219
|
+
<td></td>
|
|
220
|
+
<td class="invoicesub">{{data.CGST}}%</td>
|
|
221
|
+
</tr>
|
|
222
|
+
<tr bgcolor="#ffffff" style="border:none;margin-top:0px;">
|
|
223
|
+
<td class="invoicesub" style="padding-left:30px; line-height: 24px;">SGST</td>
|
|
224
|
+
<td></td>
|
|
225
|
+
<td></td>
|
|
226
|
+
<td class="invoicesub">{{data.SGST}}%</td>
|
|
215
227
|
</tr>
|
|
216
228
|
<tr bgcolor="#ffffff" style="border:none;margin-top:0px;">
|
|
217
229
|
<td class="invoicesub" style="padding-left:30px; line-height: 24px;">Total</td>
|
|
@@ -223,7 +235,7 @@
|
|
|
223
235
|
<td class="invoicesub" style="padding-left:30px; line-height: 24px;">Discount</td>
|
|
224
236
|
<td></td>
|
|
225
237
|
<td></td>
|
|
226
|
-
<td class="invoicesub">{{data.discount}}
|
|
238
|
+
<td class="invoicesub">{{data.discount}}</td>
|
|
227
239
|
</tr>
|
|
228
240
|
<tr>
|
|
229
241
|
<td colspan="4" align="left" bgcolor="#ffffff"
|
|
@@ -236,7 +248,7 @@
|
|
|
236
248
|
<td class="invoicesub" style="padding-left:30px; ">Final Value</td>
|
|
237
249
|
<td></td>
|
|
238
250
|
<td></td>
|
|
239
|
-
<td class="invoicesub">{{data.currencyType}} {{data.
|
|
251
|
+
<td class="invoicesub">{{data.currencyType}} {{data.final}}</td>
|
|
240
252
|
</tr>
|
|
241
253
|
</table>
|
|
242
254
|
</td>
|
|
@@ -514,7 +514,19 @@
|
|
|
514
514
|
<td class="invoicesub">IGST</td>
|
|
515
515
|
<td></td>
|
|
516
516
|
<td></td>
|
|
517
|
-
<td class="invoicesub">
|
|
517
|
+
<td class="invoicesub">{{data.IGST}}%</td>
|
|
518
|
+
</tr>
|
|
519
|
+
<tr style="border:none;margin-top:10px;">
|
|
520
|
+
<td class="invoicesub">CGST</td>
|
|
521
|
+
<td></td>
|
|
522
|
+
<td></td>
|
|
523
|
+
<td class="invoicesub">{{data.CGST}}%</td>
|
|
524
|
+
</tr>
|
|
525
|
+
<tr style="border:none;margin-top:10px;">
|
|
526
|
+
<td class="invoicesub">SGST</td>
|
|
527
|
+
<td></td>
|
|
528
|
+
<td></td>
|
|
529
|
+
<td class="invoicesub">{{data.SGST}}%</td>
|
|
518
530
|
</tr>
|
|
519
531
|
<tr style="border:none;margin-top:10px;">
|
|
520
532
|
<td class="invoicesub">Total</td>
|
|
@@ -539,7 +551,7 @@
|
|
|
539
551
|
<td class="invoicesub">Final Value</td>
|
|
540
552
|
<td></td>
|
|
541
553
|
<td></td>
|
|
542
|
-
<td class="invoicesub">{{data.currencyType}} {{data.
|
|
554
|
+
<td class="invoicesub">{{data.currencyType}} {{data.final}}</td>
|
|
543
555
|
</tr>
|
|
544
556
|
</table>
|
|
545
557
|
</td>
|
|
@@ -60,7 +60,7 @@ paymentSubscriptionRouter.put( '/update/InvoiceDetails/:clientId', isAllowedSess
|
|
|
60
60
|
userType: [ 'tango' ], access: [
|
|
61
61
|
{ featureName: 'settings', name: 'paymentSubscriptions', permissions: [ 'isEdit' ] },
|
|
62
62
|
],
|
|
63
|
-
} ), validate( validationDtos.
|
|
63
|
+
} ), validate( validationDtos.validateInvoiceUpdateParams ), paymentController.updateInvoiceDetails );
|
|
64
64
|
|
|
65
65
|
paymentSubscriptionRouter.get( '/admin/notificationList', isAllowedSessionHandler, authorize( {
|
|
66
66
|
userType: [ 'tango' ], access: [
|