tango-app-api-payment-subscription 3.0.39-dev → 3.0.40-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.39-dev",
3
+ "version": "3.0.40-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.83",
29
- "tango-app-api-middleware": "^1.0.2-test",
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;
@@ -696,7 +696,7 @@ export const invoiceDetails = async ( req, res ) => {
696
696
 
697
697
  export const updateInvoiceDetails = async ( req, res ) => {
698
698
  try {
699
- let clientInvoiceDetails = await paymentService.findOne( { clientId: req.params.clientId, status: 'active' }, { paymentInvoice: 1 } );
699
+ let clientInvoiceDetails = await paymentService.findOne( { clientId: req.params.clientId }, { paymentInvoice: 1 } );
700
700
  if ( !clientInvoiceDetails ) {
701
701
  return res.sendError( 'no data found', 204 );
702
702
  }
@@ -1580,6 +1580,11 @@ export const invoiceList = async ( req, res ) => {
1580
1580
  delete item.products;
1581
1581
  } );
1582
1582
  }
1583
+ invoiceDetails[0].data.forEach( ( item ) => {
1584
+ if ( req.body?.client?.paymentInvoice?.currencyType == 'dollar' ) {
1585
+ item.amount = convertINRtoUSD( item.amount );
1586
+ }
1587
+ } );
1583
1588
  let data = {
1584
1589
  data: invoiceDetails[0].data,
1585
1590
  count: invoiceDetails[0].count[0].count,
@@ -1595,12 +1600,13 @@ export const invoiceList = async ( req, res ) => {
1595
1600
  if ( item.status == 'free' ) {
1596
1601
  item.amount = 'Free';
1597
1602
  }
1603
+ item.products = item.products.map( ( item ) => item.product.product );
1598
1604
  exportData.push( {
1599
1605
  'Invoice': item.invoice,
1600
1606
  'Billing Date': item.billingDate,
1601
1607
  'Stores': item.stores,
1602
1608
  ...( req.user.userType == 'tango' ? { 'Products': item.products } : {} ),
1603
- 'Amount': item.amount,
1609
+ 'Amount': req.body?.client?.paymentInvoice?.currencyType == 'dollar' ? item.amount : item.amount,
1604
1610
  ...( req.user.userType == 'client' ? { 'Payment Method': item.paymentMethod } : {} ),
1605
1611
  'Status': item.status,
1606
1612
  } );
@@ -1695,8 +1701,8 @@ export const priceList = async ( req, res ) => {
1695
1701
  } );
1696
1702
  } );
1697
1703
  data = temp;
1698
- let discountPrice = totalProductPrice - totalnegotiatePrice;
1699
- let discountPercentage = discountPrice > 0 ? ( discountPrice / totalProductPrice ) * 100 : 0;
1704
+ let discountPrice = originalTotalPrice - discountTotalPrice;
1705
+ let discountPercentage = discountPrice > 0 ? ( discountPrice / originalTotalPrice ) * 100 : 0;
1700
1706
  let gstAmount = discountTotalPrice * ( 18 / 100 );
1701
1707
  let finalValue = parseFloat( discountTotalPrice ) + gstAmount;
1702
1708
  let result = {
@@ -1738,6 +1744,11 @@ export const pricingListUpdate = async ( req, res ) => {
1738
1744
  if ( req.body?.products && req.body?.products?.length ) {
1739
1745
  productList = JSON.parse( JSON.stringify( req.body ) );
1740
1746
  let amount =0;
1747
+ let origPrice=0;
1748
+ let IGST = 18;
1749
+ let CGST = 9;
1750
+ let SGST = 9;
1751
+ let gst = req.body.client.paymentInvoice.currencyType == 'dollar' ? IGST : ( CGST + SGST );
1741
1752
  productList.products.forEach( ( item ) => {
1742
1753
  let [ firstWord, secondWord ] = item.productName.replace( /([a-z])([A-Z])/g, '$1 $2' ).split( ' ' );
1743
1754
  firstWord = firstWord.charAt( 0 ).toUpperCase() + firstWord.slice( 1 );
@@ -1746,17 +1757,28 @@ export const pricingListUpdate = async ( req, res ) => {
1746
1757
  item.basePrice = convertINRtoUSD( item.basePrice );
1747
1758
  item.price = convertINRtoUSD( item.price );
1748
1759
  }
1749
- if ( req.body.client.priceType == 'step' ) {
1760
+ let count = item.storeCount;
1761
+ if ( req.body.type == 'step' ) {
1750
1762
  item.storeCount = item.storeRange;
1763
+ let rangeSplit = item.storeRange.split( '-' );
1764
+ count = parseInt( rangeSplit[1] ) - parseInt( rangeSplit[0] );
1751
1765
  }
1752
1766
  amount = amount + item.price;
1767
+ origPrice = origPrice + ( item.basePrice * count );
1768
+ item.price = item.price.toFixed( 2 );
1753
1769
  } );
1770
+ let discountAmount = origPrice - amount;
1771
+ let discountPercentage = ( discountAmount / origPrice ) * 100;
1754
1772
  productList = {
1755
1773
  ...productList,
1756
- amount: amount,
1774
+ amount: amount.toFixed( 2 ),
1757
1775
  currencyType: req.body.client.paymentInvoice.currencyType == 'dollar' ? '$' : '₹',
1758
1776
  total: amount.toFixed( 2 ),
1759
- discount: 0,
1777
+ final: ( parseFloat( amount ) + parseFloat( ( amount * gst ) / 100 ) ).toFixed( 2 ),
1778
+ discount: `${discountPercentage.toFixed( 2 )}% (-${discountAmount.toFixed( 2 )})`,
1779
+ IGST: req.body.client.paymentInvoice.currencyType == 'dollar' ? IGST : 0,
1780
+ CGST: req.body.client.paymentInvoice.currencyType == 'inr' ? CGST : 0,
1781
+ SGST: req.body.client.paymentInvoice.currencyType == 'inr' ? SGST : 0,
1760
1782
  };
1761
1783
  req.body.products.forEach( ( item ) => {
1762
1784
  delete item.originalPrice;
@@ -1777,24 +1799,26 @@ export const pricingListUpdate = async ( req, res ) => {
1777
1799
  getPriceInfo.step = req.body.products;
1778
1800
  }
1779
1801
  getPriceInfo.save().then( async () => {
1780
- let clientDetails = await paymentService.findOne( { clientId: req.body.clientId }, { priceType: 1 } );
1802
+ let clientDetails = await paymentService.findOne( { clientId: req.body.clientId }, { priceType: 1, paymentInvoice: 1 } );
1781
1803
  clientDetails.priceType = req.body.type;
1782
1804
 
1783
1805
  clientDetails.save();
1784
1806
 
1785
- let userDetails= await userService.findOne( { clientId: req.body.clientId, role: 'superadmin' } );
1786
- if ( userDetails ) {
1787
- const templateHtml = fs.readFileSync( path.resolve( path.dirname( '' ) ) + '/src/hbs/revisedPriceEmail.hbs', 'utf8' );
1788
- const template = Handlebars.compile( templateHtml );
1789
- const html = template( { data: productList } );
1790
- let params = {
1791
- toEmail: userDetails.email,
1792
- mailSubject: 'Invoice Revised',
1793
- htmlBody: html,
1794
- attachment: '',
1795
- sourceEmail: appConfig.cloud.aws.ses.adminEmail,
1796
- };
1797
- sendEmailWithSES( params.toEmail, params.mailSubject, params.htmlBody, params.attachment, params.sourceEmail );
1807
+ // let userDetails= await userService.findOne( { clientId: req.body.clientId, role: 'superadmin' } );
1808
+ if ( clientDetails?.paymentInvoice?.paymentAgreementTo?.length ) {
1809
+ clientDetails.paymentInvoice.paymentAgreementTo.forEach( ( email ) => {
1810
+ const templateHtml = fs.readFileSync( path.resolve( path.dirname( '' ) ) + '/src/hbs/revisedPriceEmail.hbs', 'utf8' );
1811
+ const template = Handlebars.compile( templateHtml );
1812
+ const html = template( { data: productList } );
1813
+ let params = {
1814
+ toEmail: email,
1815
+ mailSubject: 'Invoice Revised',
1816
+ htmlBody: html,
1817
+ attachment: '',
1818
+ sourceEmail: appConfig.cloud.aws.ses.adminEmail,
1819
+ };
1820
+ sendEmailWithSES( params.toEmail, params.mailSubject, params.htmlBody, params.attachment, params.sourceEmail );
1821
+ } );
1798
1822
  }
1799
1823
  let keys = [];
1800
1824
  if ( req.body.type == 'standard' ) {
@@ -1866,7 +1890,11 @@ async function updatePricing( req, res, update ) {
1866
1890
  }
1867
1891
  let product = [];
1868
1892
  let clientId = req.body.clientId;
1893
+ let paymentInvoice = clientDetails.paymentInvoice;
1869
1894
  if ( !update ) {
1895
+ let userDetails= await userService.findOne( { clientId: invoiceDetails.clientId, role: 'superadmin' } );
1896
+ paymentInvoice.invoiceTo = [ userDetails.email ];
1897
+ paymentInvoice.paymentAgreementTo = [ userDetails.email ];
1870
1898
  clientDetails.planDetails.product.forEach( ( item ) => {
1871
1899
  product.push( {
1872
1900
  productName: item.productName,
@@ -1900,6 +1928,7 @@ async function updatePricing( req, res, update ) {
1900
1928
  'planDetails.paymentStatus': clientDetails?.subscriptionType == 'free' ? 'free' : paymentStatus,
1901
1929
  'planDetails.product': product,
1902
1930
  'price': pricingDetails.price,
1931
+ 'paymentInvoice': paymentInvoice,
1903
1932
  };
1904
1933
  await paymentService.updateOne( { clientId: clientId }, details );
1905
1934
  }
@@ -1915,11 +1944,15 @@ export const updatedRevisedPrice = async ( req, res ) => {
1915
1944
  invoiceDetails.revisedAmount = req.body.revisedAmount;
1916
1945
  invoiceDetails.discount = req.body.discount;
1917
1946
  invoiceDetails.save().then( async () => {
1918
- let userDetails= await userService.findOne( { clientId: invoiceDetails.clientId, role: 'superadmin' } );
1919
- if ( userDetails ) {
1947
+ let clientDetails = await paymentService.findOne( { clientId: invoiceDetails.clientId } );
1948
+ // let userDetails= await userService.findOne( { clientId: invoiceDetails.clientId, role: 'superadmin' } );
1949
+ if ( clientDetails.paymentInvoice.invoiceTo.length ) {
1920
1950
  let invoiceInfo;
1921
- let clientDetails = await paymentService.findOne( { clientId: invoiceDetails.clientId } );
1922
1951
  let amount = 0;
1952
+ let IGST = 18;
1953
+ let CGST = 9;
1954
+ let SGST = 9;
1955
+ let gst = clientDetails?.paymentInvoice?.currencyType == 'dollar' ? IGST : ( CGST + SGST );
1923
1956
  invoiceDetails.products.forEach( ( item ) => {
1924
1957
  let [ firstWord, secondWord ] = item.product.product.replace( /([a-z])([A-Z])/g, '$1 $2' ).split( ' ' );
1925
1958
  firstWord = firstWord.charAt( 0 ).toUpperCase() + firstWord.slice( 1 );
@@ -1936,6 +1969,7 @@ export const updatedRevisedPrice = async ( req, res ) => {
1936
1969
  let invoiceDate= dayjs( invoiceDetails.createdAt ).format( 'DD MMM, YYYY' );
1937
1970
  let days = clientDetails?.paymentInvoice?.extendPaymentPeriodDays || 10;
1938
1971
  let dueDate = invoiceDetails?.dueDate ? dayjs( invoiceDetails?.dueDate ).format( 'DD MMM, YYYY' ) : dayjs().add( days, 'days' ).format( 'DD MMM, YYYY' );
1972
+ let discountAmount = ( amount * req.body.discount ) / 100;
1939
1973
  invoiceInfo = {
1940
1974
  ...invoiceDetails._doc,
1941
1975
  clientName: clientDetails.clientName,
@@ -1943,22 +1977,28 @@ export const updatedRevisedPrice = async ( req, res ) => {
1943
1977
  address: clientDetails.billingDetails.billingAddress,
1944
1978
  amount: amount.toFixed( 2 ),
1945
1979
  currencyType: clientDetails.paymentInvoice.currencyType == 'dollar' ? '$' : '₹',
1946
- discount: req.body.discount,
1947
- total: req.body.revisedAmount.toFixed( 2 ),
1980
+ discount: `${req.body.discount.toFixed( 2 )}% (-${discountAmount.toFixed( 2 )})`,
1981
+ total: ( parseFloat( amount ) + parseFloat( ( amount * gst ) / 100 ) ).toFixed( 2 ),
1982
+ final: req.body.revisedAmount.toFixed( 2 ),
1983
+ IGST: clientDetails.paymentInvoice.currencyType == 'dollar' ? IGST : 0,
1984
+ CGST: clientDetails.paymentInvoice.currencyType == 'inr' ? CGST : 0,
1985
+ SGST: clientDetails.paymentInvoice.currencyType == 'inr' ? SGST : 0,
1948
1986
  invoiceDate,
1949
1987
  dueDate,
1950
1988
  };
1951
- const templateHtml = fs.readFileSync( path.resolve( path.dirname( '' ) ) + '/src/hbs/trialCreditNoteEmail.hbs', 'utf8' );
1952
- const template = Handlebars.compile( templateHtml );
1953
- const html = template( { data: invoiceInfo } );
1954
- let params = {
1955
- toEmail: userDetails.email,
1956
- mailSubject: 'Credit Note',
1957
- htmlBody: html,
1958
- attachment: '',
1959
- sourceEmail: appConfig.cloud.aws.ses.adminEmail,
1960
- };
1961
- sendEmailWithSES( params.toEmail, params.mailSubject, params.htmlBody, params.attachment, params.sourceEmail );
1989
+ clientDetails.paymentInvoice.invoiceTo.forEach( ( email ) => {
1990
+ const templateHtml = fs.readFileSync( path.resolve( path.dirname( '' ) ) + '/src/hbs/trialCreditNoteEmail.hbs', 'utf8' );
1991
+ const template = Handlebars.compile( templateHtml );
1992
+ const html = template( { data: invoiceInfo } );
1993
+ let params = {
1994
+ toEmail: email,
1995
+ mailSubject: 'Credit Note',
1996
+ htmlBody: html,
1997
+ attachment: '',
1998
+ sourceEmail: appConfig.cloud.aws.ses.adminEmail,
1999
+ };
2000
+ sendEmailWithSES( params.toEmail, params.mailSubject, params.htmlBody, params.attachment, params.sourceEmail );
2001
+ } );
1962
2002
  }
1963
2003
  const logObj = {
1964
2004
  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">0%</td>
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}}%</td>
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.total}}</td>
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">0%</td>
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.total}}</td>
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.validateBrandParams ), paymentController.updateInvoiceDetails );
63
+ } ), validate( validationDtos.validateInvoiceUpdateParams ), paymentController.updateInvoiceDetails );
64
64
 
65
65
  paymentSubscriptionRouter.get( '/admin/notificationList', isAllowedSessionHandler, authorize( {
66
66
  userType: [ 'tango' ], access: [