public ActionResult <CollectionResponse <Transaction> > GetReport([FromQuery] TransactionReportRequest request) { var response = new CollectionResponse <Transaction>(); try { var transactions = _dacTransaction .Where(t => t.CreatedDate.Date >= request.StartDate.Date && t.CreatedDate.Date <= request.EndDate.Date && (string.IsNullOrEmpty(request.PaymentStatus) || t.PaymentStatus.Equals(request.PaymentStatus)) ) .OrderByDescending(t => t.CreatedDate); response.Collections = TranslateToModel(transactions); response.Status.SetSuccess(); } catch (Exception e) { Console.WriteLine(e); response.Status.SetError(e); } return(response); }
public IActionResult Report(string searchDate) { var model = new ReportViewModel(); try { var searchDateSplited = searchDate?.Split(" - ") ?? new [] { DateTime.Today.ToString("d"), DateTime.Today.ToString("d") }; DateTime.TryParseExact(searchDateSplited[0], "d", null, DateTimeStyles.None, out var start); DateTime.TryParseExact(searchDateSplited[1], "d", null, DateTimeStyles.None, out var end); var url = CreateServiceUrl(Constant.ConfigKey.ApiUrlTransactionReport); var request = new TransactionReportRequest() { StartDate = start, EndDate = end }; var response = Requestor().Get <CollectionResponse <Transaction> >(url, request); CheckResponse(response); model.Transactions = response.Collections; model.StartDate = start; model.EndDate = end; if (response.Collections.Any()) { var paymentStatus = new[] { Constant.PaymentStatus.Hold, Constant.PaymentStatus.Paid, Constant.PaymentStatus.Canceled }; var paymentTypes = new[] { Constant.PaymentType.Card, Constant.PaymentType.Cash, Constant.PaymentType.Other, }; model.PaymentStatusTable = GenerateReportTable <ReportItemPayment>(response.Collections, paymentStatus, "PaymentStatus"); model.PaymentTypeTable = GenerateReportTable <ReportItemBase>(response.Collections, paymentTypes, "PaymentType"); } } catch (Exception e) { SetErrorMessage(e); } return(View(model)); }
/// <summary> /// Gets the transaction response. /// </summary> /// <param name="reportRequest">The report request.</param> /// <returns></returns> public TransactionReportResponse GetTransactionResponse(TransactionReportRequest reportRequest) { AbstractPostRequestStrategy <TransactionReportRequest, TransactionReportResponse> requestStrategy = new TransactionDetailReportStrategy(reportRequest); requestStrategy.SendRequest(); return(requestStrategy.RestResponse.Data); }
/// <summary> /// Gets the transaction response. /// </summary> /// <param name="parameters">The parameters.</param> /// <returns></returns> public TransactionReportResponse GetTransactionResponse(IDictionary <string, string> parameters) { TransactionReportRequest request = base.CreateBaseRequest <TransactionReportRequest>(ServerType.Reports, parameters); ReportDetailsBuilder builder = new ReportDetailsBuilder(request); request.Details = builder.Details; return(reportService.GetTransactionResponse(request)); }
public IActionResult Index() { var model = new DashboardViewModel(); try { model.UserName = HttpContext.Session .GetValue <User>(Constant.SessionKey.JsonUser)?.Name; var url = CreateServiceUrl(Constant.ConfigKey.ApiUrlTransactionReport); var request = new TransactionReportRequest { StartDate = DateTime.Today, EndDate = DateTime.Today, PaymentStatus = Constant.PaymentStatus.Paid }; var response = Requestor().Get <CollectionResponse <Transaction> >(url, request); CheckResponse(response); model.Transactions = response.Collections; model.TotalTransaction = response.Collections.Count; model.TotalSales = response.Collections.Sum(t => t.TotalPrice - t.Discount.Value); foreach (var transaction in response.Collections) { foreach (var sp in transaction.SelectedProducts) { if (model.TopSellings.Any(p => p.Product.Id == sp.Product.Id)) { var index = model.TopSellings.FindIndex(p => p.Product.Id == sp.Product.Id); model.TopSellings[index].Quantity += sp.Quantity; } else { model.TopSellings.Add(new TopSelling { Product = sp.Product, Quantity = sp.Quantity }); } } } const int maxTopSelling = DashboardViewModel.MaxTopSellings; if (model.TopSellings.Count > maxTopSelling) { model.TopSellings = model.TopSellings .OrderByDescending(t => t.Quantity) .ToList() .GetRange(0, maxTopSelling); } } catch (Exception e) { SetErrorMessage(e); } return(View(model)); }