Ejemplo n.º 1
0
        public FileResult GetReportAsExcel([FromBody] ReportConditionData reportConditionData)
        {
            var report     = reportService.GetReport(reportConditionData);
            var excelBytes = report.GetAsExcel();

            return(File(excelBytes, ContentType.Xlsx, reportConditionData.ReportCode + ".xlsx"));
        }
Ejemplo n.º 2
0
        public ActionResult GetChartData([FromBody] ReportConditionData reportConditionData)
        {
            var report = reportService.GetReport(reportConditionData);
            var data   = report.GetChartData();

            return(Ok(data));
        }
Ejemplo n.º 3
0
        public FileResult GetReportAsPdf([FromBody] ReportConditionData reportConditionData)
        {
            var report   = reportService.GetReport(reportConditionData);
            var pdfBytes = report.GetAsPDF();

            //TODO: не бесплатная версия... Evaluation Only. Created with Aspose.Cells for .NET.Copyright 2003 - 2018 Aspose Pty Ltd.
            return(File(pdfBytes, System.Net.Mime.MediaTypeNames.Application.Octet, reportConditionData.ReportCode + ".pdf"));
        }
Ejemplo n.º 4
0
        public IssuedProtectionDocumentsReport(ReportConditionData rportConditionData) : base(rportConditionData)
        {
            rportConditionData.DateFrom = rportConditionData.DateFrom ?? new DateTimeOffset(new DateTime(DateTime.Now.Year, 1, 1));
            rportConditionData.DateTo   = rportConditionData.DateTo ?? DateTimeOffset.Now;

            rportConditionData.DateFrom = rportConditionData.DateFrom.Value.ToLocalTime();
            rportConditionData.DateTo   = rportConditionData.DateTo.Value.ToLocalTime();
        }
Ejemplo n.º 5
0
        public ReceivedRequestReport(ReportConditionData rportConditionData) : base(rportConditionData)
        {
            rportConditionData.DateFrom = rportConditionData.DateFrom ?? new DateTimeOffset(new DateTime(DateTime.Now.Year, 1, 1));
            rportConditionData.DateTo   = rportConditionData.DateTo ?? DateTimeOffset.Now;

            rportConditionData.DateFrom = rportConditionData.DateFrom.Value.ToLocalTime();
            rportConditionData.DateTo   = rportConditionData.DateTo.Value.ToLocalTime();
        }
Ejemplo n.º 6
0
        internal override ReportData Execute(ReportConditionData reportFilterData)
        {
            var protectionDocRepository = Uow.GetRepository <ProtectionDoc>();

            var query = protectionDocRepository.AsQueryable().Where(r => r.Type != null &&
                                                                    r.Request != null && r.Request.Addressee != null && r.Request.Addressee.Type != null &&
                                                                    string.IsNullOrEmpty(r.GosNumber) == false &&
                                                                    string.IsNullOrEmpty(r.Bulletins.Any() ? r.Bulletins.FirstOrDefault().Bulletin.Number : string.Empty) == false &&
                                                                    r.Bulletins.Any() && r.Bulletins.FirstOrDefault().Bulletin.PublishDate.HasValue
                                                                    );

            if (reportFilterData.ProtectionDocTypeIds != null && reportFilterData.ProtectionDocTypeIds.Any())
            {
                query = query.Where(r => reportFilterData.ProtectionDocTypeIds.Contains(r.TypeId));
            }

            query = query.Where(r => r.Bulletins.Any() && (r.Bulletins.FirstOrDefault().Bulletin.PublishDate >= reportFilterData.DateFrom && r.Bulletins.FirstOrDefault().Bulletin.PublishDate <= reportFilterData.DateTo));

            var protectionDocTypes = Uow.GetRepository <DicProtectionDocType>().AsQueryable().Select(r => new { r.Code, r.NameRu });

            #region local Filters

            IQueryable <ProtectionDoc> residentFilter(IQueryable <ProtectionDoc> protectionDoc)
            {
                return(protectionDoc.Where(r => r.Request.Addressee.IsNotResident));
            }

            IQueryable <ProtectionDoc> nonResidentFilter(IQueryable <ProtectionDoc> protectionDoc)
            {
                return(protectionDoc.Where(r => !r.Request.Addressee.IsNotResident));
            }

            var patentCodes = new string[] {
                DicProtectionDocTypeCodes.RequestTypeInventionCode,
                DicProtectionDocTypeCodes.RequestTypeUsefulModelCode,
                DicProtectionDocTypeCodes.RequestTypeIndustrialSampleCode,
                DicProtectionDocTypeCodes.RequestTypeSelectionAchieveCode,
                DicProtectionDocTypeCodes.ProtectionDocTypeInventionCode,
                DicProtectionDocTypeCodes.ProtectionDocTypeUsefulModelCode,
                DicProtectionDocTypeCodes.ProtectionDocTypeIndustrialSampleCode,
                DicProtectionDocTypeCodes.ProtectionDocTypeSelectionAchieveCode,
            };

            var certificateCodes = new string[] {
                DicProtectionDocTypeCodes.RequestTypeNameOfOriginCode,
                DicProtectionDocTypeCodes.RequestTypeTrademarkCode,
                DicProtectionDocTypeCodes.ProtectionDocTypeInternationalTrademarkCode,
                DicProtectionDocTypeCodes.ProtectionDocTypeNameOfOriginCode,
                DicProtectionDocTypeCodes.ProtectionDocTypeTrademarkCode,
            };

            var patentDocuments      = query.Where(r => patentCodes.Contains(r.Type.Code));
            var certificateDocuments = query.Where(r => certificateCodes.Contains(r.Type.Code));

            var residentPatentDocuments    = residentFilter(patentDocuments);
            var nonResidentPatentDocuments = nonResidentFilter(patentDocuments);

            var residentCertificateDocuments    = residentFilter(certificateDocuments);
            var nonResidentCertificateDocuments = nonResidentFilter(certificateDocuments);

            #endregion


            #region Кол-во выданных охранных документов (патентов)

            var emptyIssuedProtectionDocumentReportDTO = new List <IssuedProtectionDocumentReportDTO>();

            foreach (var protectionDocType in protectionDocTypes.Where(r => patentCodes.Contains(r.Code) &&
                                                                       r.Code != DicProtectionDocTypeCodes.RequestTypeSelectionAchieveCode))
            {
                emptyIssuedProtectionDocumentReportDTO.Add(new IssuedProtectionDocumentReportDTO {
                    ProtectionDocumentTypeName = protectionDocType.NameRu
                });
            }

            var selectiveProtectionDocTypeName = protectionDocTypes.First(r => r.Code == DicProtectionDocTypeCodes.RequestTypeSelectionAchieveCode).NameRu;
            emptyIssuedProtectionDocumentReportDTO.Add(new IssuedProtectionDocumentReportDTO {
                ProtectionDocumentTypeName = string.Format("{0} (сорта растений)", selectiveProtectionDocTypeName)
            });
            emptyIssuedProtectionDocumentReportDTO.Add(new IssuedProtectionDocumentReportDTO {
                ProtectionDocumentTypeName = string.Format("{0} (породы животных)", selectiveProtectionDocTypeName)
            });


            var simpleResidentPatentDocuments = residentPatentDocuments.Where(r => r.Type.Code != DicProtectionDocTypeCodes.RequestTypeSelectionAchieveCode)
                                                .GroupBy(r => new { r.TypeId, r.Type.NameRu })
                                                .Select(r => new IssuedProtectionDocumentReportDTO
            {
                ProtectionDocumentTypeName = r.Key.NameRu,
                NationalCustomerCount      = r.Count(),
            }).ToList();
            var simpleNonResidentPatentDocuments = nonResidentPatentDocuments.Where(r => r.Type.Code != DicProtectionDocTypeCodes.RequestTypeSelectionAchieveCode)
                                                   .GroupBy(r => new { r.TypeId, r.Type.NameRu })
                                                   .Select(r => new IssuedProtectionDocumentReportDTO
            {
                ProtectionDocumentTypeName = r.Key.NameRu,
                NotNationalCustomerCount   = r.Count(),
            }).ToList();

            var simplePatentDocuments = simpleResidentPatentDocuments.Union(simpleNonResidentPatentDocuments)
                                        .GroupBy(r => r.ProtectionDocumentTypeName)
                                        .Select(r => new IssuedProtectionDocumentReportDTO
            {
                ProtectionDocumentTypeName = r.Key,
                NationalCustomerCount      = r.Sum(g => g.NationalCustomerCount),
                NotNationalCustomerCount   = r.Sum(g => g.NotNationalCustomerCount),
                FullReqestCountByType      = r.Sum(g => g.NationalCustomerCount) + r.Sum(g => g.NotNationalCustomerCount)
            }).ToList();

            #region По селекционным достижениям (породы животных)


            var residentSAPlantGrowingPatentDocuments = residentPatentDocuments.Where(r => r.Type.Code == DicProtectionDocTypeCodes.RequestTypeSelectionAchieveCode &&
                                                                                      r.SelectionAchieveType != null && r.SelectionAchieveType.Code == DicSelectionAchieveTypeCodes.AnimalHusbandry)
                                                        .GroupBy(r => new { r.TypeId, r.Type.NameRu })
                                                        .Select(r => new IssuedProtectionDocumentReportDTO
            {
                ProtectionDocumentTypeName = string.Format("{0} (породы животных)", r.Key.NameRu),
                NationalCustomerCount      = r.Count(),
            }).ToList();

            var nonRresidentSAPlantGrowingPatentDocuments = nonResidentPatentDocuments.Where(r => r.Type.Code == DicProtectionDocTypeCodes.RequestTypeSelectionAchieveCode &&
                                                                                             r.SelectionAchieveType != null && r.SelectionAchieveType.Code == DicSelectionAchieveTypeCodes.AnimalHusbandry)
                                                            .GroupBy(r => new { r.TypeId, r.Type.NameRu })
                                                            .Select(r => new IssuedProtectionDocumentReportDTO
            {
                ProtectionDocumentTypeName = string.Format("{0} (породы животных)", r.Key.NameRu),
                NotNationalCustomerCount   = r.Count(),
            }).ToList();

            var SAPlantGrowingPatentDocuments = residentSAPlantGrowingPatentDocuments.Union(nonRresidentSAPlantGrowingPatentDocuments)
                                                .GroupBy(r => r.ProtectionDocumentTypeName)
                                                .Select(r => new IssuedProtectionDocumentReportDTO
            {
                ProtectionDocumentTypeName = r.Key,
                NationalCustomerCount      = r.Sum(g => g.NationalCustomerCount),
                NotNationalCustomerCount   = r.Sum(g => g.NotNationalCustomerCount),
                FullReqestCountByType      = r.Sum(g => g.NationalCustomerCount) + r.Sum(g => g.NotNationalCustomerCount)
            }).ToList();

            #endregion

            #region По селекционным достижениям (сорта растений)

            var residentSACattleBreedingPatentDocuments = residentPatentDocuments.Where(r => r.Type.Code == DicProtectionDocTypeCodes.RequestTypeSelectionAchieveCode &&
                                                                                        r.SelectionAchieveType != null && r.SelectionAchieveType.Code == DicSelectionAchieveTypeCodes.Agricultural)
                                                          .GroupBy(r => new { r.TypeId, r.Type.NameRu })
                                                          .Select(r => new IssuedProtectionDocumentReportDTO
            {
                ProtectionDocumentTypeName = string.Format("{0} (сорта растений)", r.Key.NameRu),
                NationalCustomerCount      = r.Count(),
            }).ToList();

            var nonResidentSACattleBreedingPatentDocuments = nonResidentPatentDocuments.Where(r => r.Type.Code == DicProtectionDocTypeCodes.RequestTypeSelectionAchieveCode &&
                                                                                              r.SelectionAchieveType != null && r.SelectionAchieveType.Code == DicSelectionAchieveTypeCodes.Agricultural)
                                                             .GroupBy(r => new { r.TypeId, r.Type.NameRu })
                                                             .Select(r => new IssuedProtectionDocumentReportDTO
            {
                ProtectionDocumentTypeName = string.Format("{0} (сорта растений)", r.Key.NameRu),
                NotNationalCustomerCount   = r.Count(),
            }).ToList();

            var SACattleBreedingPatentDocuments = residentSACattleBreedingPatentDocuments.Union(nonResidentSACattleBreedingPatentDocuments)
                                                  .GroupBy(r => r.ProtectionDocumentTypeName)
                                                  .Select(r => new IssuedProtectionDocumentReportDTO
            {
                ProtectionDocumentTypeName = r.Key,
                NationalCustomerCount      = r.Sum(g => g.NationalCustomerCount),
                NotNationalCustomerCount   = r.Sum(g => g.NotNationalCustomerCount),
                FullReqestCountByType      = r.Sum(g => g.NationalCustomerCount) + r.Sum(g => g.NotNationalCustomerCount)
            }).ToList();


            #endregion

            var grouppedPatentDocuments = simplePatentDocuments
                                          .Union(SACattleBreedingPatentDocuments)
                                          .Union(SAPlantGrowingPatentDocuments)
                                          .Union(emptyIssuedProtectionDocumentReportDTO)
                                          .GroupBy(r => r.ProtectionDocumentTypeName)
                                          .Select(r => new IssuedProtectionDocumentReportDTO
            {
                IsPatent = true,
                ProtectionDocumentTypeName = r.Key,
                NationalCustomerCount      = r.Sum(g => g.NationalCustomerCount),
                NotNationalCustomerCount   = r.Sum(g => g.NotNationalCustomerCount),
                FullReqestCountByType      = r.Sum(g => g.NationalCustomerCount) + r.Sum(g => g.NotNationalCustomerCount)
            }).ToList();


            #endregion

            #region Кол-во выданных охранных документов (свидетельств, выписок)

            var emptyIssuedProtectionDocumentReportDTOCertificate = new List <IssuedProtectionDocumentReportDTO>();

            foreach (var protectionDocType in protectionDocTypes.Where(r => certificateCodes.Contains(r.Code) && r.Code != DicProtectionDocTypeCodes.ProtectionDocTypeInternationalTrademarkCode))
            {
                emptyIssuedProtectionDocumentReportDTOCertificate.Add(new IssuedProtectionDocumentReportDTO {
                    ProtectionDocumentTypeName = protectionDocType.NameRu
                });
            }

            var simpleResidentCertificatesDocuments = residentCertificateDocuments.Where(r => r.SubType != null && r.SubType.Code == DicProtectionDocSubtypeCodes.WellKnownTradeMark)
                                                      .GroupBy(r => new { r.TypeId, r.Type.NameRu })
                                                      .Select(r => new IssuedProtectionDocumentReportDTO
            {
                ProtectionDocumentTypeName = r.Key.NameRu,
                NationalCustomerCount      = r.Count(),
            }).ToList();

            var simpleNonResidentCertificatesDocuments = nonResidentCertificateDocuments.Where(r => r.Type.Code != DicProtectionDocTypeCodes.ProtectionDocTypeInternationalTrademarkCode &&
                                                                                               r.SubType != null && r.SubType.Code == DicProtectionDocSubtypeCodes.WellKnownTradeMark)
                                                         .GroupBy(r => new { r.TypeId, r.Type.NameRu })
                                                         .Select(r => new IssuedProtectionDocumentReportDTO
            {
                ProtectionDocumentTypeName = r.Key.NameRu,
                NotNationalCustomerCount   = r.Count(),
            }).ToList();

            var grouppedCertificatesDocuments = simpleResidentCertificatesDocuments
                                                .Union(simpleNonResidentCertificatesDocuments)
                                                .Union(emptyIssuedProtectionDocumentReportDTOCertificate)
                                                .GroupBy(r => r.ProtectionDocumentTypeName)
                                                .Select(r => new IssuedProtectionDocumentReportDTO
            {
                IsCertificate = true,
                ProtectionDocumentTypeName = r.Key,
                NationalCustomerCount      = r.Sum(g => g.NationalCustomerCount),
                NotNationalCustomerCount   = r.Sum(g => g.NotNationalCustomerCount),
                FullReqestCountByType      = r.Sum(g => g.NationalCustomerCount) + r.Sum(g => g.NotNationalCustomerCount)
            }).ToList();

            #region Международыне товарные знаки

            var grouppedInternationalTrademarks = query.Where(r => r.Type.Code == DicProtectionDocTypeCodes.ProtectionDocTypeInternationalTrademarkCode)
                                                  .GroupBy(r => new { r.TypeId, r.Type.NameRu })
                                                  .Select(r => new IssuedProtectionDocumentReportDTO
            {
                ProtectionDocumentTypeName = r.Key.NameRu,
                FullReqestCountByType      = r.Count()
            }).FirstOrDefault();

            #endregion

            #endregion

            #region Общеизвестные товарные знаки (ТЗ)

            var FTMResidentCertificatesDocuments = residentCertificateDocuments.Where(r => r.SubType == null ||
                                                                                      (r.SubType != null && r.SubType.Code != DicProtectionDocSubtypeCodes.WellKnownTradeMark))
                                                   .GroupBy(r => new { r.TypeId, r.Type.NameRu })
                                                   .Select(r => new IssuedProtectionDocumentReportDTO
            {
                ProtectionDocumentTypeName = r.Key.NameRu,
                NationalCustomerCount      = r.Count(),
            }).ToList();

            var FTMNonResidentCertificatesDocuments = nonResidentCertificateDocuments.Where(r => r.SubType == null ||
                                                                                            (r.SubType != null && r.SubType.Code != DicProtectionDocSubtypeCodes.WellKnownTradeMark))
                                                      .GroupBy(r => new { r.TypeId, r.Type.NameRu })
                                                      .Select(r => new IssuedProtectionDocumentReportDTO
            {
                ProtectionDocumentTypeName = r.Key.NameRu,
                NotNationalCustomerCount   = r.Count(),
            }).ToList();

            var grouppedFTMCertificatesDocuments = FTMResidentCertificatesDocuments.Union(FTMNonResidentCertificatesDocuments)
                                                   .GroupBy(r => r.ProtectionDocumentTypeName)
                                                   .Select(r => new IssuedProtectionDocumentReportDTO
            {
                IsCertificate = true,
                ProtectionDocumentTypeName = "Общеизвестные товарные знаки",
                NationalCustomerCount      = r.Sum(g => g.NationalCustomerCount),
                NotNationalCustomerCount   = r.Sum(g => g.NotNationalCustomerCount),
                FullReqestCountByType      = r.Sum(g => g.NationalCustomerCount) + r.Sum(g => g.NotNationalCustomerCount)
            }).FirstOrDefault();


            #endregion


            var rows = new List <Row>();

            var rowNumber = 1;
            //Патенты
            foreach (var grouppedPatentDocument in grouppedPatentDocuments)
            {
                var row = new Row
                {
                    Cells = new List <Cell>
                    {
                        new Cell {
                            Value = rowNumber++
                        },
                        new Cell {
                            Value = grouppedPatentDocument.ProtectionDocumentTypeName
                        },
                        new Cell {
                            Value = grouppedPatentDocument.NationalCustomerCount
                        },
                        new Cell {
                            Value = grouppedPatentDocument.NotNationalCustomerCount
                        },
                    }
                };

                if (rowNumber == 2)
                {
                    row.Cells.Add(new Cell {
                        Value = " ", CollSpan = 2, RowSpan = 5, IsTextAlignCenter = true
                    });
                }
                else
                {
                    row.Cells.Add(new Cell());
                    row.Cells.Add(new Cell());
                }

                row.Cells.Add(new Cell {
                    Value = grouppedPatentDocument.FullReqestCountByType
                });

                rows.Add(row);
            }

            //Свидетельства, выписоки
            foreach (var grouppedCertificatesDocument in grouppedCertificatesDocuments)
            {
                var row = new Row
                {
                    Cells = new List <Cell>
                    {
                        new Cell {
                            Value = rowNumber++
                        },
                        new Cell {
                            Value = grouppedCertificatesDocument.ProtectionDocumentTypeName
                        }
                    }
                };

                if (rowNumber == 7)
                {
                    row.Cells.Add(new Cell {
                        Value = " ", CollSpan = 2, RowSpan = 3, IsTextAlignCenter = true
                    });
                }
                else
                {
                    row.Cells.Add(new Cell());
                    row.Cells.Add(new Cell());
                }


                row.Cells.Add(new Cell {
                    Value = grouppedCertificatesDocument.NationalCustomerCount
                });
                row.Cells.Add(new Cell {
                    Value = grouppedCertificatesDocument.NotNationalCustomerCount
                });
                row.Cells.Add(new Cell {
                    Value = grouppedCertificatesDocument.FullReqestCountByType
                });

                rows.Add(row);
            }

            //Международные Товарные Знаки
            if (grouppedInternationalTrademarks == null)
            {
                grouppedInternationalTrademarks = new IssuedProtectionDocumentReportDTO
                {
                    ProtectionDocumentTypeName = protectionDocTypes.FirstOrDefault(r => r.Code == DicProtectionDocTypeCodes.ProtectionDocTypeInternationalTrademarkCode).NameRu
                };
            }

            rows.Add(new Row
            {
                Cells = new List <Cell>
                {
                    new Cell {
                        Value = rowNumber++
                    },
                    new Cell {
                        Value = grouppedInternationalTrademarks.ProtectionDocumentTypeName
                    },
                    new Cell {
                    },
                    new Cell {
                    },
                    new Cell {
                        Value = grouppedInternationalTrademarks.FullReqestCountByType, CollSpan = 2, IsTextAlignCenter = true
                    },
                    new Cell {
                        Value = grouppedInternationalTrademarks.FullReqestCountByType
                    },
                }
            });

            //Общее количество выданных охранных документов на объекты промышленной собственности	11510
            rows.Add(new Row
            {
                Cells = new List <Cell>
                {
                    new Cell {
                        Value = "Общее количество выданных охранных документов на объекты промышленной собственности", CollSpan = 6, IsBold = true
                    },
                    new Cell {
                        Value = rows.Sum(r => r.Cells[r.Cells.Count - 1].Value)
                    },
                }
            });


            //Общеизвестные товарные знаки
            if (grouppedFTMCertificatesDocuments == null)
            {
                grouppedFTMCertificatesDocuments = new IssuedProtectionDocumentReportDTO
                {
                    ProtectionDocumentTypeName = "Общеизвестные товарные знаки"
                };
            }

            rows.Add(new Row
            {
                Cells = new List <Cell>
                {
                    new Cell {
                        Value = rowNumber++
                    },
                    new Cell {
                        Value = grouppedFTMCertificatesDocuments.ProtectionDocumentTypeName
                    },
                    new Cell {
                        Value = " ", CollSpan = 2, IsTextAlignCenter = true
                    },
                    new Cell {
                        Value = grouppedFTMCertificatesDocuments.NationalCustomerCount
                    },
                    new Cell {
                        Value = grouppedFTMCertificatesDocuments.NotNationalCustomerCount
                    },
                    new Cell {
                        Value = grouppedFTMCertificatesDocuments.FullReqestCountByType
                    },
                }
            });

            return(new ReportData {
                Rows = rows
            });
        }
Ejemplo n.º 7
0
 internal abstract ReportData Execute(ReportConditionData reportFilterData);
Ejemplo n.º 8
0
        internal override ReportData Execute(ReportConditionData reportFilterData)
        {
            var requestRepository = Uow.GetRepository <Request>();

            var query = requestRepository.AsQueryable().Where(r => r.Addressee != null && r.Addressee.Type != null &&
                                                              r.ProtectionDocType.Code != DicProtectionDocTypeCodes.ProtectionDocTypeDKCode);

            if (reportFilterData.ProtectionDocTypeIds != null && reportFilterData.ProtectionDocTypeIds.Any())
            {
                query = query.Where(r => reportFilterData.ProtectionDocTypeIds.Contains(r.ProtectionDocTypeId));
            }

            query = query.Where(r => r.DateCreate >= reportFilterData.DateFrom && r.DateCreate <= reportFilterData.DateTo);

            var protectionDocTypes = Uow.GetRepository <DicProtectionDocType>().AsQueryable().Select(r => new { r.Code, r.NameRu });

            #region По типам ОД

            var emptyReceivedRequestReportDTO = new List <ReceivedRequestReportDTO>();

            foreach (var protectionDocType in protectionDocTypes.Where(r => r.Code != DicProtectionDocTypeCodes.ProtectionDocTypeDKCode &&
                                                                       r.Code != DicProtectionDocTypeCodes.RequestTypeSelectionAchieveCode))
            {
                emptyReceivedRequestReportDTO.Add(new ReceivedRequestReportDTO {
                    RequestTypeName = protectionDocType.NameRu
                });
            }

            var selectiveProtectionDocTypeName = protectionDocTypes.First(r => r.Code == DicProtectionDocTypeCodes.RequestTypeSelectionAchieveCode).NameRu;
            emptyReceivedRequestReportDTO.Add(new ReceivedRequestReportDTO {
                RequestTypeName = string.Format("{0} (сорта растений)", selectiveProtectionDocTypeName)
            });
            emptyReceivedRequestReportDTO.Add(new ReceivedRequestReportDTO {
                RequestTypeName = string.Format("{0} (породы животных)", selectiveProtectionDocTypeName)
            });

            var residents = query.Where(r => !r.Addressee.IsNotResident &&
                                        r.ProtectionDocType.Code != DicProtectionDocTypeCodes.RequestTypeSelectionAchieveCode)
                            .GroupBy(r => new { r.ProtectionDocTypeId, r.ProtectionDocType.NameRu, r.ProtectionDocType.Code })
                            .Select(r => new ReceivedRequestReportDTO
            {
                RequestTypeName = r.Key.NameRu,
                NationalCustomerRequestCount = r.Count(),
            }).ToList();

            var nonResidents = query.Where(r => r.Addressee.IsNotResident &&
                                           r.ProtectionDocType.Code != DicProtectionDocTypeCodes.RequestTypeSelectionAchieveCode)
                               .GroupBy(r => new { r.ProtectionDocTypeId, r.ProtectionDocType.NameRu, r.ProtectionDocType.Code })
                               .Select(r => new ReceivedRequestReportDTO
            {
                RequestTypeName = r.Key.NameRu,
                NotNationalCustomerRequestCount = r.Count(),
            }).ToList();

            #endregion

            #region По селекционным достижениям (породы животных)

            //По селекционным достижениям (породы животных) резиденты
            var residentsCattleBreeding = query.Where(r => !r.Addressee.IsNotResident &&
                                                      r.ProtectionDocType.Code == DicProtectionDocTypeCodes.RequestTypeSelectionAchieveCode &&
                                                      r.SelectionAchieveType != null && r.SelectionAchieveType.Code == DicSelectionAchieveTypeCodes.AnimalHusbandry)
                                          .GroupBy(r => new { r.ProtectionDocTypeId, r.ProtectionDocType.NameRu })
                                          .Select(r => new ReceivedRequestReportDTO
            {
                RequestTypeName = string.Format("{0} (породы животных)", r.Key.NameRu),
                NationalCustomerRequestCount = r.Count(),
            }).ToList();
            //По селекционным достижениям (породы животных) НЕ резиденты
            var nonresidentsCattleBreeding = query.Where(r => r.Addressee.IsNotResident &&
                                                         r.ProtectionDocType.Code == DicProtectionDocTypeCodes.RequestTypeSelectionAchieveCode &&
                                                         r.SelectionAchieveType != null && r.SelectionAchieveType.Code == DicSelectionAchieveTypeCodes.AnimalHusbandry)
                                             .GroupBy(r => new { r.ProtectionDocTypeId, r.ProtectionDocType.NameRu })
                                             .Select(r => new ReceivedRequestReportDTO
            {
                RequestTypeName = string.Format("{0} (породы животных)", r.Key.NameRu),
                NationalCustomerRequestCount = r.Count(),
            }).ToList();

            #endregion

            #region По селекционным достижениям (сорта растений)

            //По селекционным достижениям (сорта растений) резиденты
            var residentsPlantGrowing = query.Where(r => !r.Addressee.IsNotResident &&
                                                    r.ProtectionDocType.Code == DicProtectionDocTypeCodes.RequestTypeSelectionAchieveCode &&
                                                    r.SelectionAchieveType != null && r.SelectionAchieveType.Code == DicSelectionAchieveTypeCodes.Agricultural)
                                        .GroupBy(r => new { r.ProtectionDocTypeId, r.ProtectionDocType.NameRu })
                                        .Select(r => new ReceivedRequestReportDTO
            {
                RequestTypeName = string.Format("{0} (сорта растений)", r.Key.NameRu),
                NationalCustomerRequestCount = r.Count(),
            }).ToList();
            //По селекционным достижениям (сорта растений) НЕ резиденты
            var nonResidentsPlantGrowing = query.Where(r => r.Addressee.IsNotResident &&
                                                       r.ProtectionDocType.Code == DicProtectionDocTypeCodes.RequestTypeSelectionAchieveCode &&
                                                       r.SelectionAchieveType != null && r.SelectionAchieveType.Code == DicSelectionAchieveTypeCodes.Agricultural)
                                           .GroupBy(r => new { r.ProtectionDocTypeId, r.ProtectionDocType.NameRu })
                                           .Select(r => new ReceivedRequestReportDTO
            {
                RequestTypeName = string.Format("{0} (сорта растений)", r.Key.NameRu),
                NationalCustomerRequestCount = r.Count(),
            }).ToList();

            #endregion

            #region Union Data

            var i = 1;
            var receivedRequestReportDTO = residents.Union(nonResidents)
                                           .GroupBy(r => r.RequestTypeName)
                                           .Select(r => new ReceivedRequestReportDTO
            {
                RequestTypeName = r.Key,
                NationalCustomerRequestCount    = r.Sum(g => g.NationalCustomerRequestCount),
                NotNationalCustomerRequestCount = r.Sum(g => g.NotNationalCustomerRequestCount),
                FullReqestCountByType           = r.Sum(g => g.NationalCustomerRequestCount) + r.Sum(g => g.NotNationalCustomerRequestCount)
            });

            receivedRequestReportDTO = receivedRequestReportDTO.Union(emptyReceivedRequestReportDTO);

            receivedRequestReportDTO = receivedRequestReportDTO.Union(residentsCattleBreeding.Union(nonresidentsCattleBreeding))
                                       .GroupBy(r => r.RequestTypeName)
                                       .Select(r => new ReceivedRequestReportDTO
            {
                RequestTypeName = r.Key,
                NationalCustomerRequestCount    = r.Sum(g => g.NationalCustomerRequestCount),
                NotNationalCustomerRequestCount = r.Sum(g => g.NotNationalCustomerRequestCount),
                FullReqestCountByType           = r.Sum(g => g.NationalCustomerRequestCount) + r.Sum(g => g.NotNationalCustomerRequestCount)
            });

            receivedRequestReportDTO = receivedRequestReportDTO.Union(residentsPlantGrowing.Union(nonResidentsPlantGrowing))
                                       .GroupBy(r => r.RequestTypeName)
                                       .Select(r => new ReceivedRequestReportDTO
            {
                RowNumber       = i++,
                RequestTypeName = r.Key,
                NationalCustomerRequestCount    = r.Sum(g => g.NationalCustomerRequestCount),
                NotNationalCustomerRequestCount = r.Sum(g => g.NotNationalCustomerRequestCount),
                FullReqestCountByType           = r.Sum(g => g.NationalCustomerRequestCount) + r.Sum(g => g.NotNationalCustomerRequestCount)
            });

            #endregion

            var rows = receivedRequestReportDTO.Select(r => r.MapReceivedRequestReport()).ToList();

            var footerRow = new Row
            {
                Cells = new List <Cell>
                {
                    new Cell {
                        Value = ""
                    },
                    new Cell {
                        Value = "Всего заявок:", IsBold = true
                    },
                    new Cell {
                        Value = receivedRequestReportDTO.Sum(r => r.NationalCustomerRequestCount)
                    },
                    new Cell {
                        Value = receivedRequestReportDTO.Sum(r => r.NotNationalCustomerRequestCount)
                    },
                    new Cell {
                        Value = receivedRequestReportDTO.Sum(r => r.FullReqestCountByType)
                    }
                }
            };

            rows.Add(footerRow);

            return(new ReportData {
                Rows = rows
            });
        }
Ejemplo n.º 9
0
 public ReportBase(ReportConditionData rportConditionData)
 {
     ReportConditionData = rportConditionData;
 }