|
|
@ -67,90 +67,87 @@ namespace Swift.web.Remit.Transaction.Reports.TransactionNew |
|
|
|
|
|
|
|
if (dt.Rows.Count == 0) |
|
|
|
{ |
|
|
|
str.Append("<tr><td colspan='12' style='color:red' align='center'><b>No Records Found!</td></b></tr>"); |
|
|
|
rpt_grid.InnerHtml = "<tr><td colspan='12' style='color:red' align='center'><b>No Records Found!</td></b></tr>"; |
|
|
|
return; |
|
|
|
} |
|
|
|
else |
|
|
|
|
|
|
|
Dictionary<string, DataTable> payoutPartnerData = new Dictionary<string, DataTable>(); |
|
|
|
|
|
|
|
foreach (DataRow dr in dt.Rows) |
|
|
|
{ |
|
|
|
string currentPayoutPartner = string.Empty; |
|
|
|
bool isFirstRow = true; |
|
|
|
int[] totalAmountIndexes = { 13, 15, 16,17, 19, 21}; |
|
|
|
string payoutPartner = dr["PAYOUT_PARTNER"].ToString().Trim(); |
|
|
|
|
|
|
|
decimal[] totalAmounts = new decimal[cols]; |
|
|
|
Array.Clear(totalAmounts, 0, totalAmounts.Length); |
|
|
|
foreach (DataRow dr in dt.Rows) |
|
|
|
if (!payoutPartnerData.ContainsKey(payoutPartner)) |
|
|
|
{ |
|
|
|
string payoutPartner = dr["PAYOUT_PARTNER"].ToString(); |
|
|
|
DataTable partnerDataTable = dt.Clone(); |
|
|
|
partnerDataTable.TableName = payoutPartner; |
|
|
|
payoutPartnerData[payoutPartner] = partnerDataTable; |
|
|
|
} |
|
|
|
|
|
|
|
if (payoutPartner != currentPayoutPartner) |
|
|
|
{ |
|
|
|
if (!isFirstRow) |
|
|
|
{ |
|
|
|
str.Append("<tr>"); |
|
|
|
str.Append("<td align=\"left\"><b>Total</b></td>"); |
|
|
|
for (int i = 1; i < cols; i++) |
|
|
|
{ |
|
|
|
if (totalAmountIndexes.Contains(i)) |
|
|
|
{ |
|
|
|
str.Append("<td align=\"left\">" + totalAmounts[i] + "</td>"); |
|
|
|
totalAmounts[i] = 0; // Reset totalAmount for the new partner
|
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
str.Append("<td align=\"left\"></td>"); |
|
|
|
} |
|
|
|
} |
|
|
|
str.Append("</tr>"); |
|
|
|
} |
|
|
|
str.Append("<h3><b>Payout Partner: " + payoutPartner + "</b></h3>"); |
|
|
|
|
|
|
|
str.Append("<table class='table table-responsive table-bordered'>"); |
|
|
|
for (int i = 0; i < cols; i++) |
|
|
|
{ |
|
|
|
str.Append("<th><div align=\"left\">" + dt.Columns[i].ColumnName + "</div></th>"); |
|
|
|
} |
|
|
|
currentPayoutPartner = payoutPartner; |
|
|
|
isFirstRow = false; |
|
|
|
} |
|
|
|
str.AppendLine("<tr class=\"" + GetPayStatus(dr["PAYSTATUS"].ToString()) + "\">"); |
|
|
|
payoutPartnerData[payoutPartner].ImportRow(dr); |
|
|
|
} |
|
|
|
|
|
|
|
StringBuilder combinedTables = new StringBuilder(); |
|
|
|
|
|
|
|
foreach (var partnerData in payoutPartnerData) |
|
|
|
{ |
|
|
|
string payoutPartner = partnerData.Key; |
|
|
|
DataTable partnerTable = partnerData.Value; |
|
|
|
|
|
|
|
StringBuilder strTable = new StringBuilder(); |
|
|
|
|
|
|
|
strTable.Append("<h3><b>Payout Partner: " + payoutPartner + "</b></h3>"); |
|
|
|
strTable.Append("<table class='table table-responsive table-bordered'>"); |
|
|
|
|
|
|
|
for (int i = 0; i < cols; i++) |
|
|
|
strTable.Append("<tr>"); |
|
|
|
foreach (DataColumn col in partnerTable.Columns) |
|
|
|
{ |
|
|
|
strTable.Append("<th><div align=\"left\">" + col.ColumnName + "</div></th>"); |
|
|
|
} |
|
|
|
strTable.Append("</tr>"); |
|
|
|
|
|
|
|
foreach (DataRow row in partnerTable.Rows) |
|
|
|
{ |
|
|
|
string payStatusClass = GetPayStatus(row["PAYSTATUS"].ToString()); |
|
|
|
strTable.Append("<tr class=\"" + payStatusClass + "\">"); |
|
|
|
|
|
|
|
foreach (var item in row.ItemArray) |
|
|
|
{ |
|
|
|
str.Append("<td align=\"left\">" + dr[i] + "</td>"); |
|
|
|
if (totalAmountIndexes.Contains(i)) |
|
|
|
{ |
|
|
|
decimal currentAmount; |
|
|
|
if (decimal.TryParse(dr[i].ToString(), out currentAmount)) |
|
|
|
{ |
|
|
|
totalAmounts[i] += currentAmount; // Accumulate total amount for each specific column index
|
|
|
|
} |
|
|
|
} |
|
|
|
strTable.Append("<td align=\"left\">" + item.ToString() + "</td>"); |
|
|
|
} |
|
|
|
str.Append("</tr>"); |
|
|
|
strTable.Append("</tr>"); |
|
|
|
} |
|
|
|
if (!isFirstRow) |
|
|
|
|
|
|
|
combinedTables.Append(strTable.ToString()); |
|
|
|
|
|
|
|
combinedTables.Append("<tr>"); |
|
|
|
combinedTables.Append("<td align=\"left\"><b>Total</b></td>"); |
|
|
|
|
|
|
|
for (int i = 1; i < partnerTable.Columns.Count; i++) |
|
|
|
{ |
|
|
|
str.Append("<tr>"); |
|
|
|
str.Append("<td align=\"left\"><b>Total</b></td>"); |
|
|
|
for (int i = 1; i < cols; i++) |
|
|
|
if (i == 14 || i == 16 || i == 18 || i == 20 || i == 22) |
|
|
|
{ |
|
|
|
decimal total = partnerTable.AsEnumerable() |
|
|
|
.Sum(row => decimal.TryParse(row[i].ToString(), out decimal val) ? val : 0); |
|
|
|
|
|
|
|
combinedTables.Append("<td align=\"left\">" + total + "</td>"); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
if (totalAmountIndexes.Contains(i)) |
|
|
|
{ |
|
|
|
str.Append("<td align=\"left\">" + totalAmounts[i] + "</td>"); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
str.Append("<td align=\"left\"></td>"); |
|
|
|
} |
|
|
|
combinedTables.Append("<td align=\"left\"></td>"); |
|
|
|
} |
|
|
|
str.Append("</tr>"); |
|
|
|
} |
|
|
|
|
|
|
|
combinedTables.Append("</tr>"); |
|
|
|
combinedTables.Append("</table>"); |
|
|
|
} |
|
|
|
str.Append("</table>"); |
|
|
|
if(mode == "download") |
|
|
|
|
|
|
|
rpt_grid.InnerHtml = combinedTables.ToString(); |
|
|
|
|
|
|
|
if (mode == "download") |
|
|
|
{ |
|
|
|
ExportToExcel(dt, "txnReport"); |
|
|
|
} |
|
|
|
rpt_grid.InnerHtml = str.ToString(); |
|
|
|
ExportToExcel(combinedTables.ToString(), "txnReport"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private string GetPayStatus(string paystatus) |
|
|
@ -168,48 +165,33 @@ namespace Swift.web.Remit.Transaction.Reports.TransactionNew |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
protected void ExportToExcel(DataTable table, string fileName) |
|
|
|
protected void ExportToExcel(string htmlContent, string fileName) |
|
|
|
{ |
|
|
|
HttpContext.Current.Response.Clear(); |
|
|
|
HttpContext.Current.Response.ClearContent(); |
|
|
|
HttpContext.Current.Response.ClearHeaders(); |
|
|
|
HttpContext.Current.Response.Buffer = true; |
|
|
|
HttpContext.Current.Response.ContentType = "application/ms-excel"; |
|
|
|
HttpContext.Current.Response.Write(@"<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.0 Transitional//EN"">"); |
|
|
|
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName + ".xls"); |
|
|
|
|
|
|
|
HttpContext.Current.Response.Charset = "utf-8"; |
|
|
|
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("windows-1250"); |
|
|
|
HttpContext.Current.Response.Write("<font style='font-size:10.0pt; font-family:Calibri;'>"); |
|
|
|
HttpContext.Current.Response.Write("<br/><br/><br/>"); |
|
|
|
HttpContext.Current.Response.Write("<table border='1' bgColor='#ffffff' " + |
|
|
|
"borderColor='#000000' cellSpacing='0' cellPadding='0' " + |
|
|
|
"style='font-size:10.0pt; font-family:Calibri; background:white;'> <tr>"); |
|
|
|
int columnscount = table.Columns.Count; |
|
|
|
|
|
|
|
for (int j = 0; j < columnscount; j++) |
|
|
|
{ |
|
|
|
HttpContext.Current.Response.Write("<td>"); |
|
|
|
HttpContext.Current.Response.Write("<strong>"); |
|
|
|
HttpContext.Current.Response.Write(table.Columns[j].ColumnName.ToString()); |
|
|
|
HttpContext.Current.Response.Write("</strong>"); |
|
|
|
HttpContext.Current.Response.Write("</td>"); |
|
|
|
} |
|
|
|
HttpContext.Current.Response.Write("</tr>"); |
|
|
|
foreach (DataRow row in table.Rows) |
|
|
|
{ |
|
|
|
HttpContext.Current.Response.Write("<tr>"); |
|
|
|
for (int i = 0; i < table.Columns.Count; i++) |
|
|
|
{ |
|
|
|
HttpContext.Current.Response.Write("<td style='textmode'>"); |
|
|
|
HttpContext.Current.Response.Write(row[i].ToString()); |
|
|
|
HttpContext.Current.Response.Write("</td>"); |
|
|
|
} |
|
|
|
|
|
|
|
HttpContext.Current.Response.Write("</tr>"); |
|
|
|
} |
|
|
|
HttpContext.Current.Response.Write("</table>"); |
|
|
|
HttpContext.Current.Response.Write("</font>"); |
|
|
|
HttpContext.Current.Response.Write("<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:x='urn:schemas-microsoft-com:office:excel' xmlns='http://www.w3.org/TR/REC-html40'>"); |
|
|
|
HttpContext.Current.Response.Write("<head>"); |
|
|
|
HttpContext.Current.Response.Write("<style>"); |
|
|
|
HttpContext.Current.Response.Write("@page { margin: 1in 0.75in 1in 0.75in; }"); |
|
|
|
HttpContext.Current.Response.Write("table { border-collapse: collapse; width: 100%; }"); |
|
|
|
HttpContext.Current.Response.Write("th, td { border: 1px solid black; padding: 8px; }"); |
|
|
|
HttpContext.Current.Response.Write("</style>"); |
|
|
|
HttpContext.Current.Response.Write("</head>"); |
|
|
|
HttpContext.Current.Response.Write("<body>"); |
|
|
|
|
|
|
|
HttpContext.Current.Response.Write(htmlContent); |
|
|
|
|
|
|
|
HttpContext.Current.Response.Write("</body>"); |
|
|
|
HttpContext.Current.Response.Write("</html>"); |
|
|
|
|
|
|
|
HttpContext.Current.Response.Flush(); |
|
|
|
HttpContext.Current.Response.End(); |
|
|
|
} |
|
|
|