示例#1
0
        public void InitReport()
        {
            DateTime start = new DateTime(2016, 1, 1);
            DateTime end   = new DateTime(2017, 12, 31);

            result    = report.Report(customerId, start, end);
            resultGet = report.Report(customerIdGet);
        }
示例#2
0
        public InvoiceReviewCustomerModel Report(int id, DateTime StartDate, DateTime EndDate)
        {
            InvoiceReviewCustomerModel result = new InvoiceReviewCustomerModel();

            result.StartDate  = StartDate;
            result.EndDate    = EndDate;
            result.CustomerId = id;
            var Invoices = _unitOfWork.Invoices.Get().Where(x => (x.Date >= StartDate && x.Date <= EndDate)).ToList();
            var Items    = Invoices.SelectMany(x => x.Items).ToList();

            var query2 = Invoices.Where(x => x.Customer.Id == id)
                         .GroupBy(
                x => new {
                Id        = x.Id,
                InvoiceNo = x.InvoiceNo,
                Date      = x.Date,
                ShippedOn = x.ShippedOn,
                Status    = (int)x.Status,
                Vat       = x.Vat,
                Name      = x.Customer.Name
            })
                         .Select(x => new
            {
                Id        = x.Key.Id,
                InvoiceNo = x.Key.InvoiceNo,
                Date      = x.Key.Date,
                ShippedOn = x.Key.ShippedOn,
                Status    = x.Key.Status,
                Vat       = x.Key.Vat,
                Total     = x.Sum(y => y.Total)
            }).ToList();
            Customer customer = _unitOfWork.Customers.Get().FirstOrDefault(x => x.Id == id);

            result.CustomerName = customer.Name;
            double total = 0;

            foreach (var item in query2)
            {
                total += Math.Round(item.Total, 2);
                result.Invoices.Add(new InvoiceReviewModel()
                {
                    InvoiceId     = item.Id,
                    InvoiceNo     = item.InvoiceNo,
                    InvoiceTotal  = Math.Round((item.Total), 2),
                    InvoiceStatus = item.Status,
                    InvoiceDate   = item.Date,
                    ShippedOn     = item.ShippedOn
                });
            }
            result.GrandTotal = Math.Round(total, 2);

            return(result);
        }