Example #1
0
        public IncomeSummaryViewModel MapIncomeDTOListToIncomeSummaryViewModel(List <IIncome> incomeDTOList, int currentPage)
        {
            if (incomeDTOList == null || !incomeDTOList.Any())
            {
                return(new IncomeSummaryViewModel());
            }

            IncomeSummaryViewModel incomeSummaryViewModel = new IncomeSummaryViewModel()
            {
                IncomeViewModels = MapIncomesDTOListToViewModelList(incomeDTOList),
                TotalAmount      = GetTotalIncomeAmount(incomeDTOList),
                PagingViewModel  = PagingHelpers.MapPagingViewModel(MAXNUMBEROFPAGES, currentPage, incomeDTOList[0].TotalCount)
            };

            return(incomeSummaryViewModel);
        }
Example #2
0
        public ActionResult IncomeSummary(DateTime?fromDate, DateTime?toDate)
        {
            var nfi = (NumberFormatInfo)CultureInfo.InvariantCulture.NumberFormat.Clone();

            nfi.NumberGroupSeparator = " ";

            var queryToDate   = toDate ?? DateTime.Now.Date;
            var queryFromDate = fromDate ?? queryToDate.AddDays(-30);

            var deskGroupList = (from dg in _db.DeskGroups
                                 select new
            {
                Name = dg.Name
            }).ToList();

            var KRSList = (from dg in _db.DeskGroups
                           join d in _db.Desks on dg.DeskGroupId equals d.GroupId
                           join info in _db.VServiceReceiptIncomeInfo on d.DeskId equals info.DeskIssuedId
                           where info.DateTime >= queryFromDate && info.DateTime < queryToDate.AddDays(1)
                           group new { info, dg } by dg.DeskGroupId into g
                           select new IncomeSummaryViewItemGroup
            {
                Name = g.FirstOrDefault().dg.Name,
                AmountKRS = g.Sum(ig => ig.info.Amount)
            }).ToList();

            var CorpTicketList = (from dg in _db.DeskGroups
                                  join d in _db.Desks on dg.DeskGroupId equals d.GroupId
                                  join ti in _db.VReceiptTicketInfo on d.DeskId equals ti.DeskId
                                  join cri in _db.CorporatorReceiptItems on ti.TicketOperationId equals cri.TicketOperationId
                                  join cr in _db.CorporatorReceipts on cri.CorporatorReceiptId equals cr.CorporatorReceiptId
                                  where cr.PaidDateTime >= queryFromDate && cr.PaidDateTime < queryToDate.AddDays(1) &&
                                  cr.StatusId == CorporatorReceipt.CRPaymentStatus.Paid &&
                                  cr.TypeId == CorporatorReceipt.CRType.CorpClient && cri.TypeId == CorporatorReceiptItem.CRIType.Ticket
                                  group new { dg, cri, ti } by dg.DeskGroupId into g
                                  select new IncomeSummaryViewItemGroup
            {
                Name = g.FirstOrDefault().dg.Name,
                AmountCorp = g.Sum(sg => sg.cri.IsPercent ? sg.cri.Amount * sg.cri.FeeRate / 100 : sg.cri.PerSegment ? sg.cri.FeeRate * sg.ti.SegCount : sg.cri.FeeRate)
            }).ToList();

            var CorpLuggageList = (from dg in _db.DeskGroups
                                   join d in _db.Desks on dg.DeskGroupId equals d.GroupId
                                   join ti in _db.VReceiptLuggageInfo on d.DeskId equals ti.DeskId
                                   join cri in _db.CorporatorReceiptItems on ti.TicketOperationId equals cri.TicketOperationId
                                   join cr in _db.CorporatorReceipts on cri.CorporatorReceiptId equals cr.CorporatorReceiptId
                                   where cr.PaidDateTime >= queryFromDate && cr.PaidDateTime < queryToDate.AddDays(1) &&
                                   cr.StatusId == CorporatorReceipt.CRPaymentStatus.Paid &&
                                   cr.TypeId == CorporatorReceipt.CRType.CorpClient && cri.TypeId == CorporatorReceiptItem.CRIType.Luggage
                                   group new { dg, cri, ti } by dg.DeskGroupId into g
                                   select new IncomeSummaryViewItemGroup
            {
                Name = g.FirstOrDefault().dg.Name,
                AmountCorp = g.Sum(sg => sg.cri.IsPercent ? sg.cri.Amount * sg.cri.FeeRate / 100 : sg.cri.FeeRate),
            }).ToList();

            var OtherList = (from income in _db.Incomes
                             .Include(e => e.DeskGroup)
                             from io in _db.IncomeOperations.Where(io => income.IncomeId == io.IncomeId)
                             .OrderByDescending(io => io.OperationDateTime).Take(1).DefaultIfEmpty()
                             where io.OperationDateTime >= queryFromDate &&
                             io.OperationDateTime < queryToDate.AddDays(1) &&
                             io.OperationTypeId == IncomeOperation.IOType.New
                             group income by income.DeskGroupId
                             into g
                             select new
            {
                Name = g.FirstOrDefault().DeskGroup.Name,
                Amount = g.Sum(ig => ig.Amount)
            }).ToList();

            var model = new IncomeSummaryViewModel
            {
                FromDate   = queryFromDate.ToString("d"),
                ToDate     = queryToDate.ToString("d"),
                ItemGroups = (from dg in deskGroupList
                              from k in KRSList.Where(c => c.Name == dg.Name).DefaultIfEmpty()
                              from ct in CorpTicketList.Where(c => c.Name == dg.Name).DefaultIfEmpty()
                              from cl in CorpLuggageList.Where(c => c.Name == dg.Name).DefaultIfEmpty()
                              from ol in OtherList.Where(c => c.Name == dg.Name).DefaultIfEmpty()
                              select new IncomeSummaryViewItemGroup
                {
                    Name = dg.Name,
                    AmountKRS = (k == null ? 0 : k.AmountKRS),
                    AmountCorp = (ct == null ? 0 : ct.AmountCorp) + (cl == null ? 0 : cl.AmountCorp),
                    AmountOther = ol?.Amount ?? 0
                }).ToList()
            };

            model.AmountKRS      = model.ItemGroups.Sum(ig => ig.AmountKRS).ToString("#,0.00", nfi);
            model.AmountCorp     = model.ItemGroups.Sum(ig => ig.AmountCorp).ToString("#,0.00", nfi);
            model.AmountAgentFee = (from c in _db.Counterparties.Where(c => c.Type.Description == "Провайдер услуг")
                                    from t in _db.ProviderAgentFeeTransactions
                                    .Where(t => t.TransactionDateTime >= queryFromDate &&
                                           t.TransactionDateTime < queryToDate.AddDays(1) && c.ITN == t.ProviderId).DefaultIfEmpty()
                                    select t).Sum(t => t.Amount).ToString("#,0.00", nfi);
            model.AmountSubagent = (from s in _db.SubagentFeeTransactions
                                    where s.TransactionDateTime >= queryFromDate && s.TransactionDateTime < queryToDate.AddDays(1)
                                    select s).Sum(s => s.Amount).ToString("#,0.00", nfi);
            model.AmountOther = model.ItemGroups.Sum(ig => ig.AmountOther).ToString("#,0.00", nfi);

            return(PartialView(model));
        }