You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

503 lines
23 KiB

10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
  1. using Swift.web.Library;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Linq;
  6. using System.Threading.Tasks;
  7. using System.Web.UI;
  8. namespace Swift.web.DashboardV2
  9. {
  10. public partial class Dashboard2 : System.Web.UI.Page
  11. {
  12. private SwiftLibrary sl = new SwiftLibrary();
  13. private RemittanceLibrary _remit = new RemittanceLibrary();
  14. private static string TodaysSentPaidRole = "20221100";
  15. private static string TransactionStaticsRole = "20221200";
  16. private static string BranchTransactionRole = "20221300";
  17. private static string CustomerOverviewRole = "20221400";
  18. private static string ComplianceOfacRole = "20221500";
  19. private static string AgentwiseNumberRole = "20221600";
  20. //private static string UserwiseNumberRole = "20221700";
  21. private static string customerKycStatus = "20221700";
  22. private static string LawsonSummaryRole = "20221800";
  23. protected void Page_Load(object sender, EventArgs e)
  24. {
  25. sl.CheckSession();
  26. string methodName = Request.Form["MethodName"];
  27. CheckRole();
  28. if (!IsPostBack)
  29. {
  30. if (methodName == "GetDashboardData")
  31. {
  32. GetDashboardData();
  33. // RegisterAsyncTask(new PageAsyncTask(GetDashboardDataAsync));
  34. }
  35. }
  36. }
  37. public async Task GetDashboardDataAsync()
  38. {
  39. Task.Factory.StartNew(() => GetDashboardData()).Wait();
  40. }
  41. private void CheckRole()
  42. {
  43. todaysSentPaidRoleDiv.Attributes.Remove("style");
  44. transactionStaticsRoleDiv.Attributes.Remove("style");
  45. branchTransactionRoleDiv.Attributes.Remove("style");
  46. customerOverviewRoleDiv.Attributes.Remove("style");
  47. complianceOfacRoleDiv.Attributes.Remove("style");
  48. //agentWiseTxnRoleDiv.Attributes.Remove("style");
  49. //userwiseDailyTxnRoleDiv.Attributes.Remove("style");
  50. customerKycStatusList.Attributes.Remove("style");
  51. //lawsonCardSummaryRoleDiv.Attributes.Remove("style");
  52. //if (!sl.HasRight(TodaysSentPaidRole))
  53. // todaysSentPaidRoleDiv.Attributes.Add("style", "display:none;");
  54. //if (!sl.HasRight(TransactionStaticsRole))
  55. // transactionStaticsRoleDiv.Attributes.Add("style", "display:none;");
  56. //if (!sl.HasRight(BranchTransactionRole))
  57. // branchTransactionRoleDiv.Attributes.Add("style", "display:none;");
  58. //if (!sl.HasRight(CustomerOverviewRole))
  59. // customerOverviewRoleDiv.Attributes.Add("style", "display:none;");
  60. //if (!sl.HasRight(ComplianceOfacRole))
  61. // complianceOfacRoleDiv.Attributes.Add("style", "display:none;");
  62. ////if (!sl.HasRight(AgentwiseNumberRole))
  63. //// agentWiseTxnRoleDiv.Attributes.Add("style", "display:none;");
  64. //if (!sl.HasRight(customerKycStatus))
  65. // customerKycStatusList.Attributes.Add("style", "display:none;");
  66. //if (!sl.HasRight(LawsonSummaryRole))
  67. // lawsonCardSummaryRoleDiv.Attributes.Add("style", "display:none;");
  68. }
  69. private void GetDashboardData()
  70. {
  71. DashboardData data = new DashboardData();
  72. string dateRange = Request.Form["DateRange"];
  73. if (string.IsNullOrEmpty(dateRange))
  74. {
  75. data.Message = "Invalid Date Range!";
  76. GetStatic.JsonResponse(data, this);
  77. return;
  78. }
  79. if (!dateRange.Contains(" to "))
  80. {
  81. data.Message = "Invalid Date Range!";
  82. GetStatic.JsonResponse(data, this);
  83. return;
  84. }
  85. string fromDate = dateRange.Split(new string[] { " to " }, StringSplitOptions.None)[0];
  86. string toDate = dateRange.Split(new string[] { " to " }, StringSplitOptions.None)[1];
  87. string sql = "EXEC PROC_GET_DASHBOARD_DATA_V2 @Flag = 'Dashboard', @User = 'admin', @fromDate = " + sl.FilterString(fromDate) + ", @toDate = " + sl.FilterString(toDate);
  88. DataSet ds = _remit.ExecuteDataset(sql);
  89. if (ds.Tables == null || ds.Tables.Count <= 0)
  90. {
  91. data.Message = "Data is empty.";
  92. GetStatic.JsonResponse(data, this);
  93. return;
  94. }
  95. DataTable dt = ds.Tables[0];
  96. //if (dt == null || dt.Rows.Count <= 0)
  97. //{
  98. // data.Message = "Data is empty.";
  99. // GetStatic.JsonResponse(data, this);
  100. // return;
  101. //}
  102. List<TxnData> txnData = new List<TxnData>();
  103. //dt.AsEnumerable().Select(x => new TxnData()
  104. //{
  105. // cancelApprovedDate = (x["cancelApprovedDate"].ToString() ?? ""),
  106. // createdDate = (x["createdDate"].ToString() ?? ""),
  107. // id = (x["id"].ToString() ?? ""),
  108. // monthNameTxn = x["monthNameTxn"].ToString(),
  109. // paidDate = x["paidDate"].ToString(),
  110. // payStatus = x["payStatus"].ToString(),
  111. // pCountry = x["pCountry"].ToString(),
  112. // sAgent = x["sAgent"].ToString(),
  113. // sAgentName = x["sAgentName"].ToString(),
  114. // tranStatus = x["tranStatus"].ToString(),
  115. // tranType = x["tranType"].ToString(),
  116. // createdBy = x["createdBy"].ToString(),
  117. // actAsBranch = x["actAsBranch"].ToString(),
  118. //}
  119. // ).ToList();
  120. foreach (DataRow item in dt.Rows)
  121. {
  122. txnData.Add(new TxnData
  123. {
  124. cancelApprovedDate = Convert.ToString(item["cancelApprovedDate"]),
  125. createdDate = Convert.ToString(item["createdDate"]),
  126. id = Convert.ToString(item["id"]),
  127. monthNameTxn = Convert.ToString(item["monthNameTxn"]),
  128. paidDate = Convert.ToString(item["paidDate"]),
  129. payStatus = Convert.ToString(item["payStatus"]),
  130. pCountry = Convert.ToString(item["pCountry"]),
  131. sAgent = Convert.ToString(item["sAgent"]),
  132. sAgentName = Convert.ToString(item["sAgentName"]),
  133. tranStatus = Convert.ToString(item["tranStatus"]),
  134. tranType = Convert.ToString(item["tranType"]),
  135. createdBy = Convert.ToString(item["createdBy"]),
  136. actAsBranch = Convert.ToString(item["actAsBranch"])
  137. });
  138. }
  139. string todaysDate = DateTime.Now.ToString("MM-dd-yyyy");
  140. //var listData = DataTableToList(dt).ToList();
  141. data.TodaysSent = Convert.ToString(txnData.Where(x => x.createdDate == todaysDate).Count());
  142. data.SevenDaysSent = txnData.Where(x => GetStatic.ParseDateTime(x.createdDate) < GetStatic.ParseDateTime(todaysDate)
  143. && GetStatic.ParseDateTime(x.createdDate) > GetStatic.ParseDateTime(todaysDate).Value.AddDays(-8))
  144. .GroupBy(x => x.createdDate).Select(x => new { TxnCount = x.Count(), Day = x.Key })
  145. .OrderBy(x => x.Day)
  146. .ToList();
  147. data.TodaysPaid = Convert.ToString(txnData.Where(x => x.paidDate == todaysDate
  148. && (x.tranStatus.ToLower() == "paid" || x.tranStatus.ToLower() == "paid")).Count());
  149. data.SevenDaysPaid = txnData.Where(x => GetStatic.ParseDateTime(x.createdDate) < GetStatic.ParseDateTime(todaysDate)
  150. && GetStatic.ParseDateTime(x.createdDate) > GetStatic.ParseDateTime(todaysDate).Value.AddDays(-8)
  151. && (x.tranStatus.ToLower() == "paid" || x.tranStatus.ToLower() == "paid"))
  152. .GroupBy(x => x.createdDate).Select(x => new { TxnCount = x.Count(), Day = x.Key })
  153. .OrderBy(x => x.Day)
  154. .ToList();
  155. data.TodaysCancel = Convert.ToString(txnData.Where(x => x.cancelApprovedDate == todaysDate
  156. && (x.tranStatus.ToLower() == "cancel" || x.tranStatus.ToLower() == "cancel")).Count());
  157. data.SevenDaysCancel = txnData.Where(x => GetStatic.ParseDateTime(x.createdDate) < GetStatic.ParseDateTime(todaysDate)
  158. && GetStatic.ParseDateTime(x.createdDate) > GetStatic.ParseDateTime(todaysDate).Value.AddDays(-8)
  159. && (x.tranStatus.ToLower() == "cancel" || x.tranStatus.ToLower() == "cancel"))
  160. .GroupBy(x => x.createdDate).Select(x => new { TxnCount = x.Count(), Day = x.Key })
  161. .OrderBy(x => x.Day)
  162. .ToList();
  163. data.MobileSent = Convert.ToString(txnData.Where(x => x.createdDate == todaysDate
  164. && x.tranType.ToLower() == "m").Count());
  165. data.SevenDaysMobileSent = txnData.Where(x => GetStatic.ParseDateTime(x.createdDate) < GetStatic.ParseDateTime(todaysDate)
  166. && GetStatic.ParseDateTime(x.createdDate) > GetStatic.ParseDateTime(todaysDate).Value.AddDays(-8)
  167. && x.tranType.ToLower() == "m")
  168. .GroupBy(x => x.createdDate).Select(x => new { TxnCount = x.Count(), Day = x.Key })
  169. .OrderBy(x => x.Day)
  170. .ToList();
  171. data.TotalCounterTxn = Convert.ToString(txnData.Where(x => x.tranType.ToLower() == "m").Count());
  172. data.TotalMobileTxn = Convert.ToString(txnData.Where(x => x.tranType.ToLower() == "i").Count());
  173. //data.AgentWiseTxn = txnData.Where(x => x.tranStatus.ToLower() != "cancel" && x.actAsBranch.ToLower() != "y")
  174. // .GroupBy(x => x.sAgentName)
  175. // .Select(x => new { TxnCount = x.Count(), BranchName = x.Key })
  176. // .OrderByDescending(x => x.TxnCount).ToList();
  177. data.UserWiseTxn = txnData.Where(x => x.tranStatus.ToLower() != "cancel" && x.sAgentName != "JME Online"
  178. && GetStatic.ParseDateTime(x.createdDate) == GetStatic.ParseDateTime(todaysDate))
  179. .GroupBy(x => x.createdBy)
  180. .Select(x => new { TxnCount = x.Count(), UserName = x.Key })
  181. .OrderByDescending(x => x.TxnCount).ToList();
  182. data.BranchTxn = txnData.Where(x => x.tranStatus.ToLower() != "cancel" && x.actAsBranch.ToLower() == "y")
  183. .GroupBy(x => x.sAgentName)
  184. .Select(x => new { TxnCount = x.Count(), BranchName = x.Key })
  185. .OrderByDescending(x => x.TxnCount).ToList();
  186. //var countryTxn = txnData.Where(x => x.tranStatus.ToLower() != "cancel")
  187. // .GroupBy(a => a.pCountry, x => x.monthNameTxn)
  188. // .Select(x => new { TxnCount = x.Count(), CountryName = x.Key, MonthName = x.Key.ToList() }).ToList();
  189. List<TransactionStatics> transactionStatics = new List<TransactionStatics>();
  190. //while (txnData.Count > 0)
  191. //{
  192. // TransactionStatics statics = new TransactionStatics();
  193. // statics.name = Convert.ToString(txnData.Select(x => x.pCountry).FirstOrDefault());
  194. // //statics.dataOther = txnData.Where(x => x.pCountry.ToLower() == statics.name.ToLower() && x.tranStatus.ToLower() != "cancel")
  195. // // .GroupBy(x => x.monthNameTxn)
  196. // // .Select(x => new TransactionStaticsDetail { Month = x.Key, TxnCount = x.Count().ToString() }).ToList();
  197. // statics.data = txnData.Where(x => x.pCountry.ToLower() == statics.name.ToLower() && x.tranStatus.ToLower() != "cancel")
  198. // .GroupBy(x => x.monthNameTxn)
  199. // .Select(x => x.Count().ToString()).ToList();
  200. // txnData.RemoveAll(x => x.pCountry.ToLower() == statics.name.ToLower());
  201. // transactionStatics.Add(statics);
  202. //}
  203. data.TransactionStatics = transactionStatics;
  204. if (ds.Tables.Count > 1)
  205. {
  206. if (ds.Tables[1] != null && ds.Tables[1].Rows.Count > 0)
  207. {
  208. try
  209. {
  210. data.ComplianceData = new ComplianceData();
  211. foreach (DataRow item in ds.Tables[1].Rows)
  212. {
  213. if(item["Head"].ToString().Contains("Mobile") || item["Head"].ToString().Contains("Web"))
  214. {
  215. data.ComplianceData.OFACComplianceMobileTxnsKycLater = Convert.ToString(item["Count"]);
  216. }
  217. else
  218. {
  219. data.ComplianceData.OFACComplianceTxns = Convert.ToString(item["Count"]);
  220. }
  221. }
  222. }
  223. catch (Exception ex)
  224. {
  225. data.ComplianceData = new ComplianceData();
  226. }
  227. }
  228. }
  229. if (ds.Tables.Count > 2)
  230. {
  231. if (ds.Tables[2] != null || ds.Tables[2].Rows.Count <= 0)
  232. {
  233. try
  234. {
  235. data.CustomerData = new CustomerData
  236. {
  237. TotalCustomers = GetStatic.ShowDecimalWithoutZero(Convert.ToString(ds.Tables[2].Rows[0]["TotalCustomers"])),
  238. MobileCustomers = GetStatic.ShowDecimalWithoutZero(Convert.ToString(ds.Tables[2].Rows[0]["MobileCustomers"]))
  239. };
  240. data.TodaysRegistration = Convert.ToString(ds.Tables[2].Rows[0]["TodaysRegistration"]);
  241. data.TodaysMobileRegistration = Convert.ToString(ds.Tables[2].Rows[0]["TodaysMobileRegistration"]);
  242. data.TodaysMobileActivation = Convert.ToString(ds.Tables[2].Rows[0]["TodayMobileActivation"]);
  243. }
  244. catch (Exception ex)
  245. {
  246. data.CustomerData = new CustomerData();
  247. }
  248. }
  249. }
  250. if (ds.Tables.Count > 3)
  251. {
  252. if (ds.Tables[3] != null || ds.Tables[3].Rows.Count <= 0)
  253. {
  254. try
  255. {
  256. data.LawsonSummary = DataTableToList(ds.Tables[3]);
  257. }
  258. catch (Exception ex)
  259. {
  260. data.LawsonSummary = new object();
  261. }
  262. }
  263. }
  264. if (ds.Tables.Count > 4)
  265. {
  266. if (ds.Tables[4] != null || ds.Tables[4].Rows.Count <= 0)
  267. {
  268. try
  269. {
  270. var customerReglst = ds.Tables[4].AsEnumerable().ToList();
  271. data.SevenDaysRegistration = customerReglst.Where(r => r.Field<string>("CustomerType").Equals("C"))
  272. .Select(x => new { RegCount = x.Field<int>("RegCount").ToString(), Day = x.Field<string>("Day") }).ToList();
  273. data.SevenDaysMobileRegistration = customerReglst.Where(r => r.Field<string>("CustomerType").Equals("M"))
  274. .Select(x => new { RegCount = x.Field<int>("RegCount").ToString(), Day = x.Field<string>("Day") }).ToList();
  275. data.SevenDaysMobileActivation = customerReglst.Where(r => r.Field<string>("CustomerType").Equals("A"))
  276. .Select(x => new { RegCount = x.Field<int>("RegCount").ToString(), Day = x.Field<string>("Day") }).ToList();
  277. }
  278. catch (Exception ex)
  279. {
  280. data.LawsonSummary = new object();
  281. }
  282. }
  283. }
  284. if (ds.Tables.Count > 5)
  285. {
  286. if (ds.Tables[5] != null || ds.Tables[5].Rows.Count <= 0)
  287. {
  288. data.TransactionStatics1 = new Root();
  289. data.Months = ds.Tables[5].AsEnumerable()
  290. .Select(x => x.Field<string>("month_name")).ToList();
  291. data.MonthsValues = ds.Tables[5].AsEnumerable()
  292. .Select(x => x.Field<int>("Month_count").ToString()).ToList();
  293. }
  294. }
  295. if (ds.Tables.Count > 6)
  296. {
  297. if (ds.Tables[6] != null || ds.Tables[6].Rows.Count <= 0)
  298. {
  299. data.AgentWiseTxn = ds.Tables[6].AsEnumerable()
  300. .Select(x => new { BranchName= x.Field<string>("sAgentName"), CurrentMonth = (x.Field<int>("CurrentMonth")).ToString(), PreviousMonth = (x.Field<int>("PreviousMonth")).ToString() })
  301. .ToList();
  302. }
  303. }
  304. if (ds.Tables.Count > 7)
  305. {
  306. if (ds.Tables[7] != null || ds.Tables[7].Rows.Count <= 0)
  307. {
  308. try
  309. {
  310. data.KycStatus = new KycStatus
  311. {
  312. KycNotCompleted = Convert.ToString(ds.Tables[7].Rows[0]["kycNotCompleted"]),
  313. KycProcessing = Convert.ToString(ds.Tables[7].Rows[0]["kycProcessing"]),
  314. KycCompleted = Convert.ToString(ds.Tables[7].Rows[0]["kycCompleted"])
  315. };
  316. }
  317. catch (Exception ex)
  318. {
  319. data.KycStatus = new KycStatus();
  320. }
  321. }
  322. }
  323. GetStatic.JsonResponse(data, this);
  324. }
  325. public List<Dictionary<string, object>> DataTableToList(DataTable table)
  326. {
  327. var list = new List<Dictionary<string, object>>();
  328. if (table == null)
  329. return list;
  330. foreach (DataRow row in table.Rows)
  331. {
  332. var dict = new Dictionary<string, object>();
  333. foreach (DataColumn col in table.Columns)
  334. {
  335. dict[col.ColumnName] = string.IsNullOrEmpty(row[col].ToString()) ? "" : row[col];
  336. }
  337. list.Add(dict);
  338. }
  339. return list;
  340. }
  341. public class TxnData
  342. {
  343. internal string actAsBranch;
  344. public string createdDate { get; set; }
  345. public string sAgent { get; set; }
  346. public string sAgentName { get; set; }
  347. public string pCountry { get; set; }
  348. public string tranType { get; set; }
  349. public string tranStatus { get; set; }
  350. public string payStatus { get; set; }
  351. public string paidDate { get; set; }
  352. public string cancelApprovedDate { get; set; }
  353. public string monthNameTxn { get; set; }
  354. public string id { get; set; }
  355. public string createdBy { get; set; }
  356. }
  357. public class DashboardData
  358. {
  359. public object UserWiseTxn { get; set; }
  360. public object LawsonSummary { get; set; }
  361. public string TodaysSent { get; set; }
  362. public object SevenDaysSent { get; set; }
  363. public string TodaysPaid { get; set; }
  364. public object SevenDaysPaid { get; set; }
  365. public string TodaysCancel { get; set; }
  366. public string TodaysRegistration { get; set; }
  367. public string TodaysMobileRegistration { get; set; }
  368. public string TodaysMobileActivation { get; set; }
  369. public object SevenDaysCancel { get; set; }
  370. public string MobileSent { get; set; }
  371. public object SevenDaysMobileSent { get; set; }
  372. public object SevenDaysMobileRegistration { get; set; }
  373. public object SevenDaysRegistration { get; set; }
  374. public object SevenDaysMobileActivation { get; set; }
  375. public List<TransactionStatics> TransactionStatics { get; set; }
  376. public Root TransactionStatics1 { get; set; }
  377. public List<string> Months { get; set; }
  378. public List<string> MonthsValues { get; set; }
  379. public object AgentWiseTxn { get; set; }
  380. public string TotalCounterTxn { get; set; }
  381. public string TotalMobileTxn { get; set; }
  382. public object BranchTxn { get; set; }
  383. public ComplianceData ComplianceData { get; set; }
  384. public CustomerData CustomerData { get; set; }
  385. public KycStatus KycStatus { get; set; }
  386. public string Message { get; set; }
  387. }
  388. public class ComplianceData
  389. {
  390. public string OFACComplianceTxns { get; set; }
  391. public string OFACComplianceMobileTxns { get; set; }
  392. public string OFACComplianceMobileTxnsKycLater { get; set; }
  393. //public string OFACComplianceMobileTxnsKycNow { get; set; }
  394. }
  395. public class CustomerData
  396. {
  397. public string TotalCustomers { get; set; }
  398. public string MobileCustomers { get; set; }
  399. }
  400. public class TransactionStatics
  401. {
  402. public string name { get; set; }
  403. public List<TransactionStaticsDetail> dataOther { get; set; }
  404. public List<string> data { get; set; }
  405. }
  406. public class KeyValue
  407. {
  408. public string x { get; set; }
  409. public string y { get; set; }
  410. }
  411. public class Root
  412. {
  413. public List<KeyValue> data { get; set; }
  414. }
  415. public class TransactionStaticsDetail
  416. {
  417. public string Month { get; set; }
  418. public string TxnCount { get; set; }
  419. }
  420. public class BranchWiseTxn
  421. {
  422. public string BranchName { get; set; }
  423. public string TxnCount { get; set; }
  424. }
  425. public class KycStatus
  426. {
  427. public string KycNotCompleted { get; set; }
  428. public string KycProcessing { get; set; }
  429. public string KycCompleted { get; set; }
  430. }
  431. }
  432. }