Esempio n. 1
0
        public IActionResult ReportRekapBox()
        {
            RekapKotakEmpatOutputModel OutPutData = null;
            ReportKotaEmpatInputModel  filter     = new ReportKotaEmpatInputModel();

            if (HttpContext.Session.GetString(SessionKeyID) != null && HttpContext.Session.GetString(SessionKeyID) != "")
            {
                filter.UserID = Guid.Parse(HttpContext.Session.GetString(SessionKeyID));
                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri(BaseAPI + "Dashboard/");
                    var responseTask = client.PostAsJsonAsync <ReportKotaEmpatInputModel>("ReportRekapBox", filter);
                    responseTask.Wait();

                    var result = responseTask.Result;
                    if (result.IsSuccessStatusCode)
                    {
                        var content = result.Content.ReadAsStringAsync();
                        RekapKotakEmpatResponseModel resutl = Newtonsoft.Json.JsonConvert.DeserializeObject <RekapKotakEmpatResponseModel>(content.Result);
                        OutPutData = resutl.data;
                    }
                    else                     //web api sent error response
                    {
                        //log response status here..
                        ModelState.AddModelError(string.Empty, "Terjadi kesalahan. Mohon hubungi admin.");
                    }
                }
            }
            return(Json(OutPutData));
        }
Esempio n. 2
0
        public RekapKotakEmpatOutputModel GetKotakEmpat(ReportKotaEmpatInputModel data)
        {
            RekapKotakEmpatOutputModel outputModel = new RekapKotakEmpatOutputModel();

            DateTime today = DateTime.Now;

            int totalBooking = 0;

            if (data.UserID != null && data.UserID != Guid.Empty)
            {
                totalBooking = db.Book.Count(x => x.UserID == data.UserID);
            }
            else
            {
                totalBooking = db.Book.Count();
            }

            int totalOrder = 0;

            if (data.UserID != null && data.UserID != Guid.Empty)
            {
                totalOrder = db.Book.Count(x => x.PaymentID != Guid.Empty && x.UserID == data.UserID);
            }
            else
            {
                totalOrder = db.Book.Count(x => x.PaymentID != Guid.Empty);
            }

            int totalUseSite = 0;


            if (data.UserID != null && data.UserID != Guid.Empty)
            {
                //totalUseSite = db.BookDetail.Where(x => x.EndDate <= DateTime.Now && x.CreateDate.Month == today.Month).GroupBy(x => x.SiteItemID).Count();
                totalUseSite = (from bd in db.BookDetail
                                join s in db.TitikLokasi on bd.SiteID equals s.ID
                                where bd.EndDate <= DateTime.Now && bd.CreateDate.Month == today.Month && s.OwnerByUserID == data.UserID
                                select new {
                    SiteID = bd.SiteID
                }).Distinct().Count();
            }
            else
            {
                totalUseSite = (from bd in db.BookDetail
                                join s in db.TitikLokasi on bd.SiteID equals s.ID
                                where bd.EndDate <= DateTime.Now && bd.CreateDate.Month == today.Month
                                select new
                {
                    SiteID = bd.SiteID
                }).Distinct().Count();
            }

            int totalSite = 0;

            if (data.UserID != null && data.UserID != Guid.Empty)
            {
                totalSite = db.TitikLokasi.Where(x => x.DeletedDate == null && x.OwnerByUserID == data.UserID).Count();
            }
            else
            {
                totalSite = db.TitikLokasi.Where(x => x.DeletedDate == null).Count();
            }

            outputModel.TotalBooking = totalBooking;
            outputModel.TotalOrder   = totalOrder;
            outputModel.TotalUseSite = totalUseSite;
            outputModel.TotalSite    = totalSite;

            var dataRevenue = (from b in db.Book
                               from bd in db.BookDetail.Where(d => d.BookID == b.ID).DefaultIfEmpty()
                               join p in db.Payment on b.PaymentID equals p.ID
                               join s in db.TitikLokasi on bd.SiteID equals s.ID
                               where b.CreateDate.Month == today.Month
                               select new Revenue()
            {
                //TotalRevenue = db.BookDetail.Where(d => d.BookID == b.ID).Sum(o => o.FinalPrice != 0 ? o.FinalPrice : o.Price),
                TotalRevenue = bd.FinalPrice != 0 ? bd.FinalPrice : bd.Price,
                PartRevenue = p.TotalPaid,
                UserID = s.OwnerByUserID
            });

            if (data.UserID != null && data.UserID != Guid.Empty)
            {
                dataRevenue = dataRevenue.Where(x => x.UserID == data.UserID);
            }

            outputModel.TotalRevenue = dataRevenue.Sum(x => x.TotalRevenue);
            outputModel.Revenue      = dataRevenue.Sum(x => x.PartRevenue);



            return(outputModel);
        }