@ -12,12 +12,15 @@ using Repository.MobileV2;
using System ;
using System.Collections.Generic ;
using System.Data ;
using System.Diagnostics ;
using System.IO ;
using System.Linq ;
using System.Net.Http.Headers ;
using System.Text ;
using System.Threading.Tasks ;
using System.Web ;
namespace Business.Mobile
{
public class MobileV2Business : IMobileV2Business
@ -314,11 +317,144 @@ namespace Business.Mobile
public JsonRxResponse DownLoadStatement ( DateFilterParams search , string userId )
{
//TranHistoryResponse trn = new TranHistoryResponse();
var r = _requestServicesv2 . TransactionPrintPdf ( search , userId ) ;
if ( r ? . RecentTransactions = = null )
{
// Log or return an error message
return new JsonRxResponse ( ) { ErrorCode = "1" , Msg = "No recent transactions found." } ;
}
StringBuilder htmlContent = new StringBuilder ( ) ;
//var imageUrl = "data:image/png;base64," + Convert.ToBase64String(System.IO.File.ReadAllBytes("wwwroot/images/logo.png"));
//var svgContent = System.IO.File.ReadAllText("wwwroot/images/imelondon.svg");
//var imageUrl1 = $"data:image/svg+xml;base64,{Convert.ToBase64String(Encoding.UTF8.GetBytes(svgContent))}";
htmlContent . AppendLine ( "<html><head><style> .header {overflow: auto;}" +
".img1 {float: left; width: 350px; height: 60px; }" +
".img {float: right; width: 150px; height: 60px;-webkit-filter: grayscale(100%); filter: grayscale(100%);}" +
" .parag {text-align: justify;} " +
"</style></head> <body> " +
" <div class='header'>" +
//$"<img class='img' src='{imageUrl}' />" +
// $"<img class='img1' src='{imageUrl1}' />" +
"<div class=\"parag\"><p>" +
"<br /><br /><br /><br /><b> IME is the trading name of Subhida UK Ltd company.</b>" +
"<br /> Registration No.: 6432399" +
"<br />FCA Registration No.: 576127" +
"<br />HMRC Registration No.: 12663526" +
"<br /> Registered Address : Pentax House South Hill Avenue, South Harrow," +
"<br />London, HA2 0DU" +
"<br />Email:info@imelondon.co.uk</p> </div></div>" +
"<h1>Transaction List</h1>" ) ;
htmlContent . AppendLine ( "<table style='border-collapse: collapse;'><thead><tr>" +
"<th style='border: 1px solid black; padding: 5px;'>S.N</th>" +
"<th style='border: 1px solid black; padding: 5px;'>Receiver Name</th>" +
"<th style='border: 1px solid black; padding: 5px;'>Send Date</th>" +
"<th style='border: 1px solid black; padding: 5px;'>Tran Id</th>" +
"<th style='border: 1px solid black; padding: 5px;'>Control No</th>" +
"<th style='border: 1px solid black; padding: 5px;'>Delivery Method</th>" +
"<th style='border: 1px solid black; padding: 5px;'>Status</th>" +
"<th style='border: 1px solid black; padding: 5px;'>Transfer Amt</th>" +
"<th style='border: 1px solid black; padding: 5px;'>Receive Amt</th>" +
"</tr></thead><tbody>" ) ;
int sn = 1 ;
decimal totalPayoutAmt = 0 ;
foreach ( var transa in r . RecentTransactions )
{
if ( decimal . TryParse ( transa . PayoutAmt , out decimal payoutAmtDecimal ) )
{
totalPayoutAmt + = payoutAmtDecimal ;
}
htmlContent . AppendLine (
$"<tr style='border: 1px solid black;'>" +
$"<td style='border: 1px solid black; padding: 5px;'>{sn}</td>" +
$"<td style='border: 1px solid black; padding: 5px;'>{transa.User}</td>" +
$"<td style='border: 1px solid black; padding: 5px;'>{transa.SendDate}</td>" +
$"<td style='border: 1px solid black; padding: 5px;'>{transa.TranId}</td>" +
$"<td style='border: 1px solid black; padding: 5px;'>{transa.ControlNo}</td>" +
$"<td style='border: 1px solid black; padding: 5px;'>{transa.PayoutMode}</td>" +
$"<td style='border: 1px solid black; padding: 5px;'>{transa.PayStatus}</td>" +
$"<td style='border: 1px solid black; padding: 5px;'>{transa.CollAmt}</td>" +
$"<td style='border: 1px solid black; padding: 5px;'>{transa.PayoutAmt}</td>" +
$"</tr>" ) ;
sn + + ;
}
htmlContent . AppendLine (
$"<tr style='border: 1px solid black;'>" +
$"<td></td>" +
$"<td></td>" +
$"<td></td>" +
$"<td></td>" +
$"<td></td>" +
$"<td></td>" +
$"<td></td>" +
$"<td style='border: 1px solid black; padding: 5px;'>Total:</td>" +
$"<td style='border: 1px solid black; padding: 5px;'>{totalPayoutAmt}</td>" +
$"</tr>" ) ;
htmlContent . AppendLine ( "</tbody></table></body></html>" ) ;
var filePath = ApplicationConfig . DownloadPdf ( ) ;
var fileName = $"{userId}-{DateTime.Now.ToString(" yyyyMMddHHss ")}.pdf" ;
var fileUrl = Path . Combine ( filePath , fileName ) ;
var pdfBytes = GeneratePdf ( htmlContent . ToString ( ) ) ;
// byte[] data = Encoding.UTF8.GetBytes(htmlContent.ToString());
File . WriteAllBytes ( fileUrl , pdfBytes ) ;
var fileUrlName = Path . GetFileName ( fileUrl ) ;
var filePathUrl = $"{ HttpContext.Current.Request.Url.Scheme + " : //" + HttpContext.Current.Request.Url.Authority + HttpContext.Current.Request.ApplicationPath.TrimEnd('/')}/Download/{fileUrlName.Replace("//", "\\")}";
//var filePathUrl = $"{HttpContext.Current.Request.Url.Scheme}://{HttpContext.Current.Request.Url.Authority}/{fileUrlName}";
//JsonRxResponse jsonRx = new JsonRxResponse() { ErrorCode = "0", Msg = "Success", Data = filePathUrl };
//return jsonRx;
JsonRxResponse jsonRx = new JsonRxResponse ( ) { ErrorCode = "0" , Msg = "Success" } ;
jsonRx . Data = "http://77.68.15.91:1082/download/sample.pdf" ;
//JsonRxResponse jrx = _requestServicesv2.PrintPdf(userId);
//jsonRx.Data = "http://77.68.15.91:1082/Download/sample.pdf";
jsonRx . Data = filePathUrl ;
return jsonRx ;
}
private byte [ ] GeneratePdf ( string htmlContent )
{
var fileName = Path . GetTempFileName ( ) ;
// Save the HTML content to a temporary file
System . IO . File . WriteAllText ( fileName + ".html" , htmlContent ) ;
// Run the WkHtmlToPdf process
var process = new Process ( )
{
StartInfo = new ProcessStartInfo
{
FileName = @"C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe" , // Provide the full path here
Arguments = $"{fileName}.html {fileName}.pdf" ,
RedirectStandardOutput = true ,
RedirectStandardError = true ,
UseShellExecute = false ,
CreateNoWindow = true ,
}
} ;
process . Start ( ) ;
process . WaitForExit ( ) ;
// Read the generated PDF into a byte array
var pdfBytes = System . IO . File . ReadAllBytes ( $"{fileName}.pdf" ) ;
// Cleanup temporary files
//System.IO.File.Delete($"{fileName}.html");
//System.IO.File.Delete($"{fileName}.pdf");
return pdfBytes ;
}