public async Task <IViewComponentResult> InvokeAsync(int id, string FromDate, string ToDate)
        {
            DateTime From = new DateTime();
            DateTime To   = new DateTime();

            try
            {
                this.GetFromTo_default_FirstMonthToNow(ref From, ref To, FromDate, ToDate);
            }
            catch (Exception ex)
            {
                ViewBag.err = ex;
                return(View("Error"));
            }

            var colleagusTransactios = colleages.GetFromToTransactionByColleagueIdAsync(id, From, To.AddDays(1));

            TempData["maxAmount"] = 50000;
            if (colleagusTransactios.Count() > 0)
            {
                double max1  = Convert.ToDouble(colleagusTransactios.Select(x => x.MyTransaction?.Amount ?? 0).Max());
                double max2  = Convert.ToDouble(colleagusTransactios.Select(x => x.MyReceipt?.Amount ?? 0).Max());
                double max   = max1 > max2 ? max1 : max2;
                double div   = Math.Pow(10, max.ToString().Count() - 1);
                double round = Math.Ceiling(max / div) * div;
                TempData["maxAmount"] = round;
            }
            TempData["FromDate"] = From.ToShortDateString();
            TempData["ToDate"]   = To.ToShortDateString();
            return(View(colleagusTransactios));
        }
        // GET: App/Colleague/Details/5
        public async Task <IActionResult> Details(int?id, string FromDate = "", string ToDate = "")
        {
            if (id == null)
            {
                ViewBag.err = new NotFoundException();
                return(View("Error"));
            }

            Colleague colleague;

            try
            {
                colleague = await colleagues.GetByIdAsync(id.Value);
            }
            catch (Exception ex)
            {
                ViewBag.err = ex;
                return(View("Error"));
            }

            List <DateTime> months    = this.GetFirstOfAllSolarMonth();
            string          ChartData = "[";

            for (int i = 0; i < months.Count - 1; i++)
            {
                double sum          = 0;
                var    transactions = colleagues.GetFromToTransactionByColleagueIdAsync(id.Value, months[i], months[i + 1]);
                sum = transactions
                      .Select(x =>
                              (x.MyTransaction?.Amount ?? 0) + (x.MyReceipt?.Amount ?? 0))
                      .Sum();

                ChartData += sum.ToString();
                ChartData += ", ";
            }
            ChartData         = ChartData.Substring(0, ChartData.Length - 1) + "]";
            ViewBag.ChartData = ChartData;

            ViewBag.FromDate = FromDate;
            ViewBag.ToDate   = ToDate;
            return(View(colleague));
        }
Example #3
0
        public async Task <IActionResult> Export(int?ColleagueID, int?SponsorID, string FromDate, string ToDate)
        {
            string    path     = _hostingEnvironment.WebRootPath + @"\Catch\";
            string    fileName = string.Empty;
            DateTime  From     = new DateTime();
            DateTime  To       = new DateTime();
            DataTable dt       = new DataTable();

            dt.Columns.Add("SponsorName");
            dt.Columns.Add("Phone");
            dt.Columns.Add("Date");
            dt.Columns.Add("Time");
            dt.Columns.Add("ReceiptNumber");
            dt.Columns.Add("CardNumber");
            dt.Columns.Add("TrackingNumber");
            dt.Columns.Add("Amount");

            try
            {
                this.GetFromTo_default_FirstMonthToNow(ref From, ref To, FromDate.ToSolar(), ToDate.ToSolar());
            }
            catch (Exception ex)
            {
                ViewBag.err = ex;
                return(View("Error"));
            }

            RedirectToActionResult           view;
            IEnumerable <SponsorTransaction> transactions;

            if (ColleagueID != null)
            {
                transactions = colleages.GetFromToTransactionByColleagueIdAsync(ColleagueID.Value, From, To);
                fileName    += colleages.GetByIdAsync(ColleagueID.Value).Result.Name.ToString();
                view         = RedirectToAction("Details", "Colleague", new { id = ColleagueID.Value });
            }
            else if (SponsorID != null)
            {
                transactions = await sponsors.GetFromToTransactionBySponsorIdAsync(SponsorID.Value, From, To);

                fileName += transactions.First().MySponsor.Name.ToString();
                view      = RedirectToAction("Details", "Sponsor", new { id = SponsorID.Value });
            }
            else
            {
                transactions = await sponsors.GetFromToTransactionAsync(From, To);

                fileName += "_";
                view      = RedirectToAction("Index", "Home");
            }

            fileName += "_From" + From.ToSolar().Replace('/', '.') + "To" + To.ToSolar().Replace('/', '.') + ".xlsx";

            foreach (var trnsctn in transactions)
            {
                DataRow row = dt.NewRow();

                row["SponsorName"]    = trnsctn.MySponsor.Name.ToString();
                row["Phone"]          = trnsctn.MySponsor.PhoneNumber.ToString();
                row["Date"]           = trnsctn.MyTransaction?.TransactionDate.ToSolar() ?? trnsctn.MyReceipt.TransactionDate.ToSolar();
                row["Time"]           = trnsctn.MyTransaction?.TransactionDate.TimeOfDay.ToString() ?? trnsctn.MyReceipt.TransactionDate.TimeOfDay.ToString();
                row["ReceiptNumber"]  = trnsctn.MyReceipt?.ReceiptNumber.ToString() ?? string.Empty;
                row["CardNumber"]     = trnsctn.MyTransaction?.LastFourNumbersOfBankCard.ToString() ?? string.Empty;
                row["TrackingNumber"] = trnsctn.MyTransaction?.TrackingNumber.ToString() ?? string.Empty;
                row["Amount"]         = trnsctn.MyTransaction?.Amount.ToString() ?? trnsctn.MyReceipt.Amount.ToString();

                dt.Rows.Add(row);
            }

            Excel.Write(path + fileName, dt);

            this.SetViewMessage("Exported Transactions successfully", WebMessageType.Success);
            return(view);
        }