|
|
using Swift.web.Library; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Threading.Tasks; using System.Web.UI;
namespace Swift.web.DashboardV2 { public partial class Dashboard2 : System.Web.UI.Page { private SwiftLibrary sl = new SwiftLibrary(); private RemittanceLibrary _remit = new RemittanceLibrary(); private static string TodaysSentPaidRole = "20221100"; private static string TransactionStaticsRole = "20221200"; private static string BranchTransactionRole = "20221300"; private static string CustomerOverviewRole = "20221400"; private static string ComplianceOfacRole = "20221500"; private static string AgentwiseNumberRole = "20221600"; //private static string UserwiseNumberRole = "20221700";
private static string customerKycStatus = "20221700"; private static string LawsonSummaryRole = "20221800"; protected void Page_Load(object sender, EventArgs e) { sl.CheckSession(); string methodName = Request.Form["MethodName"]; CheckRole(); if (!IsPostBack) {
if (methodName == "GetDashboardData") { GetDashboardData(); // RegisterAsyncTask(new PageAsyncTask(GetDashboardDataAsync));
} } }
public async Task GetDashboardDataAsync() { Task.Factory.StartNew(() => GetDashboardData()).Wait(); }
private void CheckRole() { todaysSentPaidRoleDiv.Attributes.Remove("style"); transactionStaticsRoleDiv.Attributes.Remove("style"); branchTransactionRoleDiv.Attributes.Remove("style"); customerOverviewRoleDiv.Attributes.Remove("style"); complianceOfacRoleDiv.Attributes.Remove("style"); //agentWiseTxnRoleDiv.Attributes.Remove("style");
//userwiseDailyTxnRoleDiv.Attributes.Remove("style");
customerKycStatusList.Attributes.Remove("style"); //lawsonCardSummaryRoleDiv.Attributes.Remove("style");
//if (!sl.HasRight(TodaysSentPaidRole))
// todaysSentPaidRoleDiv.Attributes.Add("style", "display:none;");
//if (!sl.HasRight(TransactionStaticsRole))
// transactionStaticsRoleDiv.Attributes.Add("style", "display:none;");
//if (!sl.HasRight(BranchTransactionRole))
// branchTransactionRoleDiv.Attributes.Add("style", "display:none;");
//if (!sl.HasRight(CustomerOverviewRole))
// customerOverviewRoleDiv.Attributes.Add("style", "display:none;");
//if (!sl.HasRight(ComplianceOfacRole))
// complianceOfacRoleDiv.Attributes.Add("style", "display:none;");
////if (!sl.HasRight(AgentwiseNumberRole))
//// agentWiseTxnRoleDiv.Attributes.Add("style", "display:none;");
////if (!sl.HasRight(UserwiseNumberRole))
//// userwiseDailyTxnRoleDiv.Attributes.Add("style", "display:none;");
//if (!sl.HasRight(customerKycStatus))
// customerKycStatusList.Attributes.Add("style", "display:none;");
//if (!sl.HasRight(LawsonSummaryRole))
// lawsonCardSummaryRoleDiv.Attributes.Add("style", "display:none;");
}
private void GetDashboardData() { DashboardData data = new DashboardData(); string dateRange = Request.Form["DateRange"];
if (string.IsNullOrEmpty(dateRange)) { data.Message = "Invalid Date Range!";
GetStatic.JsonResponse(data, this); return; }
if (!dateRange.Contains(" to ")) { data.Message = "Invalid Date Range!";
GetStatic.JsonResponse(data, this); return; }
string fromDate = dateRange.Split(new string[] { " to " }, StringSplitOptions.None)[0]; string toDate = dateRange.Split(new string[] { " to " }, StringSplitOptions.None)[1];
string sql = "EXEC PROC_GET_DASHBOARD_DATA_V2 @Flag = 'Dashboard', @User = 'admin', @fromDate = " + sl.FilterString(fromDate) + ", @toDate = " + sl.FilterString(toDate); DataSet ds = _remit.ExecuteDataset(sql); if (ds.Tables == null || ds.Tables.Count <= 0) { data.Message = "Data is empty.";
GetStatic.JsonResponse(data, this);
return; }
DataTable dt = ds.Tables[0]; //if (dt == null || dt.Rows.Count <= 0)
//{
// data.Message = "Data is empty.";
// GetStatic.JsonResponse(data, this);
// return;
//}
List<TxnData> txnData = new List<TxnData>();
//dt.AsEnumerable().Select(x => new TxnData()
//{
// cancelApprovedDate = (x["cancelApprovedDate"].ToString() ?? ""),
// createdDate = (x["createdDate"].ToString() ?? ""),
// id = (x["id"].ToString() ?? ""),
// monthNameTxn = x["monthNameTxn"].ToString(),
// paidDate = x["paidDate"].ToString(),
// payStatus = x["payStatus"].ToString(),
// pCountry = x["pCountry"].ToString(),
// sAgent = x["sAgent"].ToString(),
// sAgentName = x["sAgentName"].ToString(),
// tranStatus = x["tranStatus"].ToString(),
// tranType = x["tranType"].ToString(),
// createdBy = x["createdBy"].ToString(),
// actAsBranch = x["actAsBranch"].ToString(),
//}
// ).ToList();
foreach (DataRow item in dt.Rows) { txnData.Add(new TxnData { cancelApprovedDate = Convert.ToString(item["cancelApprovedDate"]), createdDate = Convert.ToString(item["createdDate"]), id = Convert.ToString(item["id"]), monthNameTxn = Convert.ToString(item["monthNameTxn"]), paidDate = Convert.ToString(item["paidDate"]), payStatus = Convert.ToString(item["payStatus"]), pCountry = Convert.ToString(item["pCountry"]), sAgent = Convert.ToString(item["sAgent"]), sAgentName = Convert.ToString(item["sAgentName"]), tranStatus = Convert.ToString(item["tranStatus"]), tranType = Convert.ToString(item["tranType"]), createdBy = Convert.ToString(item["createdBy"]), actAsBranch = Convert.ToString(item["actAsBranch"]) }); }
string todaysDate = DateTime.Now.ToString("MM-dd-yyyy"); //var listData = DataTableToList(dt).ToList();
data.TodaysSent = Convert.ToString(txnData.Where(x => x.createdDate == todaysDate).Count()); data.SevenDaysSent = txnData.Where(x => GetStatic.ParseDateTime(x.createdDate) < GetStatic.ParseDateTime(todaysDate) && GetStatic.ParseDateTime(x.createdDate) > GetStatic.ParseDateTime(todaysDate).Value.AddDays(-8)) .GroupBy(x => x.createdDate).Select(x => new { TxnCount = x.Count(), Day = x.Key }) .OrderBy(x => x.Day) .ToList();
data.TodaysPaid = Convert.ToString(txnData.Where(x => x.paidDate == todaysDate && (x.tranStatus.ToLower() == "paid" || x.tranStatus.ToLower() == "paid")).Count());
data.SevenDaysPaid = txnData.Where(x => GetStatic.ParseDateTime(x.createdDate) < GetStatic.ParseDateTime(todaysDate) && GetStatic.ParseDateTime(x.createdDate) > GetStatic.ParseDateTime(todaysDate).Value.AddDays(-8) && (x.tranStatus.ToLower() == "paid" || x.tranStatus.ToLower() == "paid")) .GroupBy(x => x.createdDate).Select(x => new { TxnCount = x.Count(), Day = x.Key }) .OrderBy(x => x.Day) .ToList();
data.TodaysCancel = Convert.ToString(txnData.Where(x => x.cancelApprovedDate == todaysDate && (x.tranStatus.ToLower() == "cancel" || x.tranStatus.ToLower() == "cancel")).Count());
data.SevenDaysCancel = txnData.Where(x => GetStatic.ParseDateTime(x.createdDate) < GetStatic.ParseDateTime(todaysDate) && GetStatic.ParseDateTime(x.createdDate) > GetStatic.ParseDateTime(todaysDate).Value.AddDays(-8) && (x.tranStatus.ToLower() == "cancel" || x.tranStatus.ToLower() == "cancel")) .GroupBy(x => x.createdDate).Select(x => new { TxnCount = x.Count(), Day = x.Key }) .OrderBy(x => x.Day) .ToList();
data.MobileSent = Convert.ToString(txnData.Where(x => x.createdDate == todaysDate && x.tranType.ToLower() == "m").Count()); data.SevenDaysMobileSent = txnData.Where(x => GetStatic.ParseDateTime(x.createdDate) < GetStatic.ParseDateTime(todaysDate) && GetStatic.ParseDateTime(x.createdDate) > GetStatic.ParseDateTime(todaysDate).Value.AddDays(-8) && x.tranType.ToLower() == "m") .GroupBy(x => x.createdDate).Select(x => new { TxnCount = x.Count(), Day = x.Key }) .OrderBy(x => x.Day) .ToList();
data.TotalCounterTxn = Convert.ToString(txnData.Where(x => x.tranType.ToLower() == "m").Count()); data.TotalMobileTxn = Convert.ToString(txnData.Where(x => x.tranType.ToLower() == "i").Count());
//data.AgentWiseTxn = txnData.Where(x => x.tranStatus.ToLower() != "cancel" && x.actAsBranch.ToLower() != "y")
// .GroupBy(x => x.sAgentName)
// .Select(x => new { TxnCount = x.Count(), BranchName = x.Key })
// .OrderByDescending(x => x.TxnCount).ToList();
data.UserWiseTxn = txnData.Where(x => x.tranStatus.ToLower() != "cancel" && x.sAgentName != "JME Online" && GetStatic.ParseDateTime(x.createdDate) == GetStatic.ParseDateTime(todaysDate)) .GroupBy(x => x.createdBy) .Select(x => new { TxnCount = x.Count(), UserName = x.Key }) .OrderByDescending(x => x.TxnCount).ToList();
data.BranchTxn = txnData.Where(x => x.tranStatus.ToLower() != "cancel" && x.actAsBranch.ToLower() == "y") .GroupBy(x => x.sAgentName) .Select(x => new { TxnCount = x.Count(), BranchName = x.Key }) .OrderByDescending(x => x.TxnCount).ToList();
//var countryTxn = txnData.Where(x => x.tranStatus.ToLower() != "cancel")
// .GroupBy(a => a.pCountry, x => x.monthNameTxn)
// .Select(x => new { TxnCount = x.Count(), CountryName = x.Key, MonthName = x.Key.ToList() }).ToList();
List<TransactionStatics> transactionStatics = new List<TransactionStatics>(); //while (txnData.Count > 0)
//{
// TransactionStatics statics = new TransactionStatics();
// statics.name = Convert.ToString(txnData.Select(x => x.pCountry).FirstOrDefault());
// //statics.dataOther = txnData.Where(x => x.pCountry.ToLower() == statics.name.ToLower() && x.tranStatus.ToLower() != "cancel")
// // .GroupBy(x => x.monthNameTxn)
// // .Select(x => new TransactionStaticsDetail { Month = x.Key, TxnCount = x.Count().ToString() }).ToList();
// statics.data = txnData.Where(x => x.pCountry.ToLower() == statics.name.ToLower() && x.tranStatus.ToLower() != "cancel")
// .GroupBy(x => x.monthNameTxn)
// .Select(x => x.Count().ToString()).ToList();
// txnData.RemoveAll(x => x.pCountry.ToLower() == statics.name.ToLower());
// transactionStatics.Add(statics);
//}
data.TransactionStatics = transactionStatics;
if (ds.Tables.Count > 1) { if (ds.Tables[1] != null && ds.Tables[1].Rows.Count > 0) { try { data.ComplianceData = new ComplianceData(); foreach (DataRow item in ds.Tables[1].Rows) { if(item["Head"].ToString().Contains("Mobile") || item["Head"].ToString().Contains("Web")) { data.ComplianceData.OFACComplianceMobileTxnsKycLater = Convert.ToString(item["Count"]); } else { data.ComplianceData.OFACComplianceTxns = Convert.ToString(item["Count"]); }
} } catch (Exception ex) { data.ComplianceData = new ComplianceData(); } } }
if (ds.Tables.Count > 2) { if (ds.Tables[2] != null || ds.Tables[2].Rows.Count <= 0) { try { data.CustomerData = new CustomerData { TotalCustomers = GetStatic.ShowDecimalWithoutZero(Convert.ToString(ds.Tables[2].Rows[0]["TotalCustomers"])), MobileCustomers = GetStatic.ShowDecimalWithoutZero(Convert.ToString(ds.Tables[2].Rows[0]["MobileCustomers"])) };
data.TodaysRegistration = Convert.ToString(ds.Tables[2].Rows[0]["TodaysRegistration"]); data.TodaysMobileRegistration = Convert.ToString(ds.Tables[2].Rows[0]["TodaysMobileRegistration"]); data.TodaysMobileActivation = Convert.ToString(ds.Tables[2].Rows[0]["TodayMobileActivation"]); } catch (Exception ex) { data.CustomerData = new CustomerData(); } } }
if (ds.Tables.Count > 3) { if (ds.Tables[3] != null || ds.Tables[3].Rows.Count <= 0) { try { data.LawsonSummary = DataTableToList(ds.Tables[3]); } catch (Exception ex) { data.LawsonSummary = new object(); } } }
if (ds.Tables.Count > 4) { if (ds.Tables[4] != null || ds.Tables[4].Rows.Count <= 0) { try { var customerReglst = ds.Tables[4].AsEnumerable().ToList();
data.SevenDaysRegistration = customerReglst.Where(r => r.Field<string>("CustomerType").Equals("C")) .Select(x => new { RegCount = x.Field<int>("RegCount").ToString(), Day = x.Field<string>("Day") }).ToList();
data.SevenDaysMobileRegistration = customerReglst.Where(r => r.Field<string>("CustomerType").Equals("M")) .Select(x => new { RegCount = x.Field<int>("RegCount").ToString(), Day = x.Field<string>("Day") }).ToList();
data.SevenDaysMobileActivation = customerReglst.Where(r => r.Field<string>("CustomerType").Equals("A")) .Select(x => new { RegCount = x.Field<int>("RegCount").ToString(), Day = x.Field<string>("Day") }).ToList();
} catch (Exception ex) { data.LawsonSummary = new object(); } } } if (ds.Tables.Count > 5) { if (ds.Tables[5] != null || ds.Tables[5].Rows.Count <= 0) {
data.TransactionStatics1 = new Root(); data.Months = ds.Tables[5].AsEnumerable() .Select(x => x.Field<string>("month_name")).ToList();
data.MonthsValues = ds.Tables[5].AsEnumerable() .Select(x => x.Field<int>("Month_count").ToString()).ToList();
} } if (ds.Tables.Count > 6) { if (ds.Tables[6] != null || ds.Tables[6].Rows.Count <= 0) {
data.AgentWiseTxn = ds.Tables[6].AsEnumerable() .Select(x => new { BranchName= x.Field<string>("sAgentName"), CurrentMonth = (x.Field<int>("CurrentMonth")).ToString(), PreviousMonth = (x.Field<int>("PreviousMonth")).ToString() }) .ToList(); } }
if (ds.Tables.Count > 7) { if (ds.Tables[7] != null || ds.Tables[7].Rows.Count <= 0) { try { data.KycStatus = new KycStatus { KycNotCompleted = Convert.ToString(ds.Tables[7].Rows[0]["kycNotCompleted"]), KycProcessing = Convert.ToString(ds.Tables[7].Rows[0]["kycProcessing"]), KycCompleted = Convert.ToString(ds.Tables[7].Rows[0]["kycCompleted"]) }; } catch (Exception ex) { data.KycStatus = new KycStatus(); } } } GetStatic.JsonResponse(data, this); }
public List<Dictionary<string, object>> DataTableToList(DataTable table) { var list = new List<Dictionary<string, object>>(); if (table == null) return list;
foreach (DataRow row in table.Rows) { var dict = new Dictionary<string, object>();
foreach (DataColumn col in table.Columns) { dict[col.ColumnName] = string.IsNullOrEmpty(row[col].ToString()) ? "" : row[col]; } list.Add(dict); }
return list; }
public class TxnData { internal string actAsBranch; public string createdDate { get; set; } public string sAgent { get; set; } public string sAgentName { get; set; } public string pCountry { get; set; } public string tranType { get; set; } public string tranStatus { get; set; } public string payStatus { get; set; } public string paidDate { get; set; } public string cancelApprovedDate { get; set; } public string monthNameTxn { get; set; } public string id { get; set; } public string createdBy { get; set; } }
public class DashboardData { public object UserWiseTxn { get; set; } public object LawsonSummary { get; set; } public string TodaysSent { get; set; } public object SevenDaysSent { get; set; } public string TodaysPaid { get; set; } public object SevenDaysPaid { get; set; } public string TodaysCancel { get; set; } public string TodaysRegistration { get; set; } public string TodaysMobileRegistration { get; set; } public string TodaysMobileActivation { get; set; } public object SevenDaysCancel { get; set; } public string MobileSent { get; set; } public object SevenDaysMobileSent { get; set; } public object SevenDaysMobileRegistration { get; set; } public object SevenDaysRegistration { get; set; }
public object SevenDaysMobileActivation { get; set; } public List<TransactionStatics> TransactionStatics { get; set; } public Root TransactionStatics1 { get; set; } public List<string> Months { get; set; } public List<string> MonthsValues { get; set; } public object AgentWiseTxn { get; set; } public string TotalCounterTxn { get; set; } public string TotalMobileTxn { get; set; } public object BranchTxn { get; set; } public ComplianceData ComplianceData { get; set; } public CustomerData CustomerData { get; set; } public KycStatus KycStatus { get; set; }
public string Message { get; set; } }
public class ComplianceData { public string OFACComplianceTxns { get; set; } public string OFACComplianceMobileTxns { get; set; } public string OFACComplianceMobileTxnsKycLater { get; set; } //public string OFACComplianceMobileTxnsKycNow { get; set; }
} public class CustomerData { public string TotalCustomers { get; set; } public string MobileCustomers { get; set; } }
public class TransactionStatics { public string name { get; set; } public List<TransactionStaticsDetail> dataOther { get; set; } public List<string> data { get; set; } }
public class KeyValue { public string x { get; set; } public string y { get; set; } } public class Root { public List<KeyValue> data { get; set; } }
public class TransactionStaticsDetail { public string Month { get; set; } public string TxnCount { get; set; } }
public class BranchWiseTxn { public string BranchName { get; set; } public string TxnCount { get; set; } } public class KycStatus { public string KycNotCompleted { get; set; } public string KycProcessing { get; set; } public string KycCompleted { get; set; } } } }
|