Пример #1
0
        protected override ExportResult TryExportItems(IEnumerable <EnergyCustomerPayment> energyPayments)
        {
            if (energyPayments == null)
            {
                return(new ExportResult());
            }

            var customerPaymentModels = energyPayments
                                        .Where(item => item != null)
                                        .Select(item =>
                                                new EnergyCustomersReportItem(
                                                    item.EnergyCustomer.Number,
                                                    item.NewDayValue,
                                                    item.NewNightValue,
                                                    item.Cost,
                                                    item.CreateDate));

            var customerPaymentModelsCount = customerPaymentModels.Count();

            if (customerPaymentModelsCount == 0)
            {
                return(new ExportResult());
            }

            var reportModel = new EnergyCustomersReport(beginDatetime, endDatetime, customerPaymentModels);

            var wordReport = new WordReportController(Config.EnergyCustomersReportTemplateFilename);

            wordReport.CreateReport(reportModel);

            return(new ExportResult(customerPaymentModelsCount, energyPayments.Count() - customerPaymentModelsCount));
        }
        protected override ExportResult TryExportItems(IEnumerable <WaterCustomerPayment> waterCustomerPayments)
        {
            if (waterCustomerPayments == null)
            {
                return(new ExportResult());
            }

            var customerPaymentModels = waterCustomerPayments
                                        .Where(waterCustomerPayment => waterCustomerPayment != null)
                                        .Select(waterCustomerPayment =>
            {
                decimal paymentAndPenaltyCost = waterCustomerPayment.Cost + waterCustomerPayment.Penalty;

                return(new WaterCustomersReportItem(
                           waterCustomerPayment.CreateDate,
                           waterCustomerPayment.WaterCustomer.Number,
                           waterCustomerPayment.CounterValue1,
                           waterCustomerPayment.CounterValue2,
                           waterCustomerPayment.CounterValue3,
                           waterCustomerPayment.Cost,
                           waterCustomerPayment.Penalty,
                           paymentAndPenaltyCost,
                           waterCustomerPayment.CommissionValue,
                           paymentAndPenaltyCost + waterCustomerPayment.CommissionValue));
            });

            int customerPaymentModelsCount = customerPaymentModels.Count();

            if (customerPaymentModelsCount == 0)
            {
                return(new ExportResult());
            }

            var reportModel = new WaterCustomersReport(Settings.WaterСommissionPercent, customerPaymentModels); //TODO: коммисия от платежа к платежу может быть разная

            var wordReport = new WordReportController(Config.WaterCustomersReportTemplateFilename);

            wordReport.CreateReport(reportModel);

            return(new ExportResult(customerPaymentModelsCount, waterCustomerPayments.Count() - customerPaymentModelsCount));
        }
Пример #3
0
        protected override ExportResult TryExportItems(IEnumerable <ArticleSale> articleSales)
        {
            if (articleSales == null)
            {
                return(new ExportResult());
            }

            var articleSalesModels = articleSales
                                     .Where(item => item != null)
                                     .Select(item =>
                                             new ArticlesSalesReportItem(
                                                 item.ArticlePrice.Article.Name,
                                                 item.ArticlePrice.Article.Code,
                                                 item.Quantity,
                                                 item.ArticlePrice.Value,
                                                 item.ArticlePrice.Value * (decimal)item.Quantity));

            var articleSalesModelsCount = articleSalesModels.Count();

            if (articleSalesModelsCount == 0)
            {
                return(new ExportResult());
            }

            var totalCost   = articleSalesModels.Sum(item => item.ArticleCost);
            var reportModel = new ArticlesSalesReport(
                beginDatetime,
                endDatetime,
                totalCost,
                Utils.GetNdsPart(totalCost, Config.ArticlesNdsPercent),
                articleSalesModels);

            var wordReport = new WordReportController(Config.ArticlesSalesReportTemplateFilename);

            wordReport.CreateReport(reportModel);

            return(new ExportResult(articleSalesModelsCount, articleSales.Count() - articleSalesModelsCount));
        }
        protected override ExportResult TryExportItems(IEnumerable <CommonPaymentsDataSource> commonPaymentsDataSources)
        {
            if (commonPaymentsDataSources == null)
            {
                return(new ExportResult());
            }

            var commonPayments = commonPaymentsDataSources.FirstOrDefault();

            if (commonPayments == null)
            {
                return(new ExportResult());
            }

            var commonPaymentsItemModels = new List <CommonPaymentsReportItem>();

            for (DateTime currentDate = beginDatetime.DayBegin(); currentDate <= endDatetime; currentDate = currentDate.AddDays(1))
            {
                commonPaymentsItemModels.Add(
                    new CommonPaymentsReportItem(currentDate));
            }

            int     countItems       = 0;
            decimal finalEnergyTotal = 0;
            decimal finalWaterWithoutCommissionTotal    = 0;
            decimal finalWaterCommissionTotal           = 0;
            decimal finalGarbageWithoutComissionTotal   = 0;
            decimal finalGarbageCommissionTotal         = 0;
            decimal finalRepairWithoutCommissionTotal   = 0;
            decimal finalRepairCommissionTotal          = 0;
            decimal finalHotWaterWithoutCommissionTotal = 0;
            decimal finalHotWaterCommissionTotal        = 0;

            foreach (var energyCustomerPayment in commonPayments.EnergyCustomersPayments)
            {
                if (energyCustomerPayment == null)
                {
                    continue;
                }

                var targetModelItem = commonPaymentsItemModels
                                      .FirstOrDefault(itemModel => itemModel.Date == energyCustomerPayment.CreateDate.DayBegin());
                if (targetModelItem == null)
                {
                    continue;
                }

                targetModelItem.EnergyTotal += energyCustomerPayment.Cost;
                finalEnergyTotal            += energyCustomerPayment.Cost;

                countItems++;
            }

            foreach (var waterCustomerPayment in commonPayments.WaterCustomersPayments)
            {
                if (waterCustomerPayment == null)
                {
                    continue;
                }

                var targetModelItem = commonPaymentsItemModels
                                      .FirstOrDefault(itemModel => itemModel.Date == waterCustomerPayment.CreateDate.DayBegin());
                if (targetModelItem == null)
                {
                    continue;
                }

                targetModelItem.WaterWithoutCommissionTotal += waterCustomerPayment.Cost + waterCustomerPayment.Penalty;
                finalWaterWithoutCommissionTotal            += waterCustomerPayment.Cost + waterCustomerPayment.Penalty;

                targetModelItem.WaterCommissionTotal += waterCustomerPayment.CommissionValue;
                finalWaterCommissionTotal            += waterCustomerPayment.CommissionValue;

                countItems++;
            }

            foreach (var garbagePayment in commonPayments.GarbagePayments)
            {
                if (garbagePayment == null)
                {
                    continue;
                }

                var targetModelItem = commonPaymentsItemModels
                                      .FirstOrDefault(itemModel => itemModel.Date == garbagePayment.CreateDate.DayBegin());
                if (targetModelItem == null)
                {
                    continue;
                }

                targetModelItem.GarbageWithoutCommissionTotal += garbagePayment.Cost;
                finalGarbageWithoutComissionTotal             += garbagePayment.Cost;

                targetModelItem.GarbageCommissionTotal += garbagePayment.CommissionValue;
                finalGarbageCommissionTotal            += garbagePayment.CommissionValue;

                countItems++;
            }

            foreach (var repairPayment in commonPayments.RepairPayments)
            {
                if (repairPayment == null)
                {
                    continue;
                }

                var targetModelItem = commonPaymentsItemModels
                                      .FirstOrDefault(itemModel => itemModel.Date == repairPayment.CreateDate.DayBegin());
                if (targetModelItem == null)
                {
                    continue;
                }

                targetModelItem.RepairWithoutCommissionTotal += repairPayment.Cost;
                finalRepairWithoutCommissionTotal            += repairPayment.Cost;

                targetModelItem.RepairCommissionTotal += repairPayment.CommissionValue;
                finalRepairCommissionTotal            += repairPayment.CommissionValue;

                countItems++;
            }

            foreach (var hotWaterPayment in commonPayments.HotWaterPayments)
            {
                if (hotWaterPayment == null)
                {
                    continue;
                }

                var targetModelItem = commonPaymentsItemModels
                                      .FirstOrDefault(itemModel => itemModel.Date == hotWaterPayment.CreateDate.DayBegin());
                if (targetModelItem == null)
                {
                    continue;
                }

                targetModelItem.HotWaterWithoutCommissionTotal += hotWaterPayment.Total;
                finalHotWaterWithoutCommissionTotal            += hotWaterPayment.Total;

                targetModelItem.HotWaterCommissionTotal += hotWaterPayment.CommisionTotal;
                finalHotWaterCommissionTotal            += hotWaterPayment.CommisionTotal;
            }

            if (countItems == 0)
            {
                return(new ExportResult(0, commonPayments.AllPaymentsCount));
            }

            var reportModel = new CommonPaymentsReport(
                beginDatetime, endDatetime, commonPaymentsItemModels,
                finalEnergyTotal,
                finalWaterWithoutCommissionTotal, finalWaterCommissionTotal,
                finalGarbageWithoutComissionTotal, finalGarbageCommissionTotal,
                finalRepairWithoutCommissionTotal, finalRepairCommissionTotal,
                finalHotWaterWithoutCommissionTotal, finalHotWaterCommissionTotal);

            var wordReport = new WordReportController(Config.CommonPaymentsReportTemplateFilename);

            wordReport.CreateReport(reportModel);

            return(new ExportResult(countItems, commonPayments.AllPaymentsCount - countItems));
        }