Browse Source

TransactionPdf

Mobile-pdf
Dinesh 9 months ago
parent
commit
b2d4846a17
  1. 2
      Business/Business.csproj
  2. 20
      Business/MobileV2/FileStreamResult.cs
  3. 128
      Business/MobileV2/MobileV2Business.cs
  4. 8
      Common/Model/JsonRxResponse.cs
  5. 2
      Repository/MobileV2/IMobileV2Repo.cs
  6. 97
      Repository/MobileV2/MobileV2Repo.cs

2
Business/Business.csproj

@ -104,6 +104,8 @@
<Compile Include="KftcPasswordRule\PasswordValidationResult.cs" />
<Compile Include="KftcPasswordRule\PatternMatchRule.cs" />
<Compile Include="KftcPasswordRule\ValidationModel.cs" />
<Compile Include="MobileV2\FileContentResult.cs" />
<Compile Include="MobileV2\FileStreamResult.cs" />
<Compile Include="MobileV2\IMobileV2Business.cs" />
<Compile Include="Mobile\IMobileServices.cs" />
<Compile Include="Mobile\MobileServices.cs" />

20
Business/MobileV2/FileStreamResult.cs

@ -0,0 +1,20 @@
using Common;
using System.IO;
using System.Net.Http.Headers;
namespace Business.Mobile
{
internal class FileStreamResult : JsonRxResponse
{
private MemoryStream stream;
private MediaTypeHeaderValue mediaTypeHeaderValue;
public FileStreamResult(MemoryStream stream, MediaTypeHeaderValue mediaTypeHeaderValue)
{
this.stream = stream;
this.mediaTypeHeaderValue = mediaTypeHeaderValue;
}
public string FileDownloadName { get; set; }
}
}

128
Business/MobileV2/MobileV2Business.cs

@ -12,8 +12,10 @@ 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;
@ -314,7 +316,97 @@ namespace Business.Mobile
public JsonRxResponse DownLoadStatement(DateFilterParams search, string userId)
{
//TranHistoryResponse trn = new TranHistoryResponse();
var r= _requestServicesv2.TransactionPrintPdf(search, userId);
//r = TranHistoryResponse;
//var jsonResult = _requestServicesv2.GetReceiverInformationV2(search, customerId, countryId);
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 pdfBytes = GeneratePdf(htmlContent.ToString());
//return System.IO.File.OpenRead(pdfBytes, "application/pdf", "TransactionReport.pdf");
// string path = "wwwroot/download/workplace-learning-report-2021.pdf";
//_ = System.IO.File.ReadAllBytes(path);
//return new FileContentResult(htmlContent, "application/pdf");
//string htmlContent = "wwwroot/download/workplace-learning-report-2021.pdf";
var stream = new MemoryStream(File.ReadAllBytes(htmlContent.ToString()));
return new FileStreamResult(stream, new MediaTypeHeaderValue("application/pdf"))
{
FileDownloadName = "TransactionReport.pdf"
};
JsonRxResponse jsonRx = new JsonRxResponse() { ErrorCode = "0", Msg = "Success" };
//JsonRxResponse jrx = _requestServicesv2.PrintPdf(userId);
jsonRx.Data = "http://77.68.15.91:1082/download/sample.pdf";
return jsonRx;
@ -322,6 +414,42 @@ namespace Business.Mobile
}
//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;
//}
public JsonRxResponse UpdateCustomerProfile(CustomerDetailV2 profileV2)
{

8
Common/Model/JsonRxResponse.cs

@ -1,7 +1,11 @@
namespace Common
using Common.Model;
using System.Collections.Generic;
namespace Common
{
public class JsonRxResponse
{
private string _errorCode = "";
private string _msg = "";
private string _id = "";
@ -76,5 +80,7 @@
Id = id;
Extra = extra;
}
public List<TranHistoryResponse> RecentTransactions { get; set; }
}
}

2
Repository/MobileV2/IMobileV2Repo.cs

@ -19,5 +19,7 @@ namespace Repository.MobileV2
DataRow GetResidenceType(string customerId);
JsonRxResponse SaveKycSettings(KycOption kycOption);
JsonRxResponse UpdateCustomerProfile(CustomerDetailV2 req);
//JsonRxResponse PrintPdf(string userId);
JsonRxResponse TransactionPrintPdf(DateFilterParams search, string userId);
}
}

97
Repository/MobileV2/MobileV2Repo.cs

@ -486,5 +486,102 @@ namespace Repository.MobileV2
Extra = _dbRes.Id
};
}
//public JsonRxResponse PrintPdf(TranHistoryResponse tranHistory)
//{
// var sql = "Exec mobile_proc_TranHistory @flag='tran-history-v2'";
// sql += ", @customerId = " + _dao.FilterString(tranHistory.User);
// sql += ", @postalCode = " + _dao.FilterString(req.PostalCode);
// sql += ", @address1 = " + _dao.FilterString(req.Address1);
// sql += ", @address2 = " + _dao.FilterString(req.Address2);
// Log.DebugFormat("UpdateProfile | SQL:{0}", sql);
// var _dbRes = _dao.ParseDbResult(sql);
// return new JsonRxResponse
// {
// ErrorCode = _dbRes.ResponseCode,
// Msg = _dbRes.Msg,
// Extra = _dbRes.Id
// };
//}
public JsonRxResponse TransactionPrintPdf(DateFilterParams search,string userId)
{
MyTransferDto myTransferDto = new MyTransferDto() { RecentTransactions = new List<TranHistoryResponse>() };
JsonRxResponse jsonRx = new JsonRxResponse();
// TranHistoryResponse tran = new TranHistoryResponse();
try
{
var sql1 = "Exec mobile_proc_TranHistory @flag='tran-history-v2'";
sql1 += ", @customerId =" + _dao.FilterString(userId);
sql1 += ", @fromDate=" + _dao.FilterString(search.FromDate);
sql1 += ", @toDate=" + _dao.FilterString(search.ToDate);
var dataSet = _dao.ExecuteDataset(sql1);
Log.DebugFormat("GetTransactionHistory | SQL : {0}", sql1);
var ds = _dao.ExecuteDataset(sql1);
if (ds == null)
{
myTransferDto.RecentTransactions = null;
}
else
{
if (ds.Tables.Count > 1)
{
DataTable data = ds.Tables[1];
foreach (DataRow dr in data.Rows)
{
TranHistoryResponse tranHistoryResponse = new TranHistoryResponse()
{
User = Convert.ToString(dr["userId"]),
TranId = Convert.ToString(dr["tranId"]),
ControlNo = Convert.ToString(dr["controlNo"]),
CollAmt = Convert.ToString(dr["collAmount"]),
PayoutAmt = Utilities.ShowDecimal(Convert.ToString(dr["payoutAmt"])),
PCurr = Convert.ToString(dr["pCurr"]),
CollCurr = Convert.ToString(dr["collCurr"]),
PayStatus = Convert.ToString(dr["payStatus"]),
PayoutMode = Convert.ToString(dr["payoutMode"]),
SendDate = Convert.ToString(dr["sendDate"]),
PaidDate = Convert.ToString(dr["paidDate"]),
DisplayActions = dr["DisplayActions"].ToString(),
//ColorIcon = GetColor(dr["payStatus"].ToString()),
//ColorCode = GetColorCode(dr["payStatus"].ToString()),
//TextCode = GetTextCode(dr["payStatus"].ToString()),
// PayoutAgent = Convert.ToString(dr["PayoutAgent"]),
};
myTransferDto.RecentTransactions.Add(tranHistoryResponse);
}
}
}
jsonRx.ErrorCode = "0";
jsonRx.Msg = "Success";
jsonRx.Data = myTransferDto;
return jsonRx;
}
catch (Exception e)
{
Log.DebugFormat($"Exception : {e.ToString()}");
jsonRx.ErrorCode = "1";
//jsonRx.Msg = "Failed";
//var map = Utilities.GetLanguageMapping(RESPONSE_MSG.GET_RECEIVER_INFORMATION_FAIL_2.ToString(), lang);
jsonRx.Msg = $"Exception has occured at GetTransactionHistory";
return jsonRx;
}
}
}
}
Loading…
Cancel
Save