Exemplo n.º 1
0
        public async Task <AgedPayablesDetailsReportDto> GetAgedReceivablesReportAsync(AgedReceivablesModel model)
        {
            var PageResult = await _reportManager.GetAgedReceivablesReportAsync(model);

            return(PageResult);
        }
Exemplo n.º 2
0
        public async Task <List <AgedReceivablesReportDto> > GetAgedReceivablesReportAsync(AgedReceivablesModel model)
        {
            List <AgedReceivablesReportDto> agedReceivablesReportDtosList;
            List <InvoiceDetailDto>         invoiceDetailDtoList;

            if (model.CustomerId == 0)
            {
                agedReceivablesReportDtosList = await(from c in _dataContext.Customers
                                                      select new AgedReceivablesReportDto
                {
                    CustomerId   = c.Id,
                    CustomerName = c.FirstName + "" + c.MiddleName + "" + c.LastName
                }).ToListAsync();
            }
            else
            {
                agedReceivablesReportDtosList = await(from c in _dataContext.Customers
                                                      where c.Id == model.CustomerId
                                                      select new AgedReceivablesReportDto
                {
                    CustomerId   = c.Id,
                    CustomerName = c.FirstName + "" + c.MiddleName + "" + c.LastName
                }).ToListAsync();
            }

            foreach (var agedReceivables in agedReceivablesReportDtosList)
            {
                var test = agedReceivables;
                invoiceDetailDtoList = await(from i in _dataContext.Invoices
                                             where i.CustomerId == agedReceivables.CustomerId && i.Status != Constants.InvoiceStatus.Deleted
                                             select new InvoiceDetailDto
                {
                    TotalAmount = i.TotalAmount,
                    DueDate     = i.DueDate,
                    Status      = i.Status
                }).ToListAsync();

                foreach (var item in invoiceDetailDtoList)
                {
                    DateTime firstDate  = new System.DateTime(item.DueDate.Year, item.DueDate.Month, item.DueDate.Day);
                    DateTime SecondDate = new System.DateTime(model.AsOfDate.Year, model.AsOfDate.Month, model.AsOfDate.Day);

                    System.TimeSpan diff  = SecondDate.Subtract(firstDate);
                    System.TimeSpan diff1 = SecondDate - firstDate;

                    String diff2 = (SecondDate - firstDate).TotalDays.ToString();
                    var    date  = Int16.Parse(diff2);
                    if (date <= 0)
                    {
                        agedReceivables.NotYetOverDue += item.TotalAmount;
                        agedReceivables.TotalAmount   += item.TotalAmount;
                        agedReceivables.CountNotYetOverDue++;
                    }
                    else if (date > 0 && date <= 30)
                    {
                        agedReceivables.LessThan30  += item.TotalAmount;
                        agedReceivables.TotalAmount += item.TotalAmount;
                        agedReceivables.TotalUnpaid += item.TotalAmount;

                        agedReceivables.CountLessThan30++;
                    }
                    else if (date > 30 && date <= 60)
                    {
                        agedReceivables.ThirtyFirstToSixty += item.TotalAmount;
                        agedReceivables.TotalAmount        += item.TotalAmount;
                        agedReceivables.TotalUnpaid        += item.TotalAmount;
                        agedReceivables.CountThirtyFirstToSixty++;
                    }
                    else if (date > 60 && date <= 90)
                    {
                        agedReceivables.SixtyOneToNinety += item.TotalAmount;
                        agedReceivables.TotalAmount      += item.TotalAmount;
                        agedReceivables.TotalUnpaid      += item.TotalAmount;
                        agedReceivables.CountSixtyOneToNinety++;
                    }
                    else
                    {
                        agedReceivables.MoreThanNinety += item.TotalAmount;
                        agedReceivables.TotalAmount    += item.TotalAmount;
                        agedReceivables.TotalUnpaid    += item.TotalAmount;
                        agedReceivables.CountMoreThanNinety++;
                    }
                }
                if (model.ReportType == 1)
                {
                    invoiceDetailDtoList = invoiceDetailDtoList.Where(p => p.Status == Constants.InvoiceStatus.Paid).ToList();
                }
                invoiceDetailDtoList        = invoiceDetailDtoList.Where(p => (p.DueDate >= model.AsOfDate)).ToList();
                agedReceivables.TotalUnpaid = invoiceDetailDtoList.Sum(x => x.TotalAmount);
            }
            return(agedReceivablesReportDtosList);
        }