Example #1
0
        private void ExportData()
        {
            ReportExport reportExport = new ReportExport();

            string reportName = Request.QueryString["rn"];


            Session["__ExportDS"] = reportExport.RetieveExportDataForReport((Telerik.Reporting.InstanceReportSource)ReportViewer.ReportSource, reportName);

            if (Session["__ExportDS"] != null)
            {
                Server.Transfer("../Reports/csvexport.aspx?filename=" + reportName + ".csv");
            }
        }
Example #2
0
        /// <summary> Gets the given request. </summary>
        /// <param name="request"> The request. </param>
        /// <returns> A Task&lt;object&gt; </returns>
        public object Get(GetReportDownload request)
        {
            if (string.IsNullOrEmpty(request.IncludeItemTypes))
            {
                return(null);
            }

            request.DisplayType = "Export";
            ReportViewType reportViewType = ReportHelper.GetReportViewType(request.ReportView);
            var            headers        = new Dictionary <string, string>();
            string         fileExtension  = "csv";
            string         contentType    = "text/plain;charset='utf-8'";

            switch (request.ExportType)
            {
            case ReportExportType.CSV:
                break;

            case ReportExportType.Excel:
                contentType   = "application/vnd.ms-excel";
                fileExtension = "xls";
                break;
            }

            var filename = "ReportExport." + fileExtension;

            headers["Content-Disposition"] = string.Format("attachment; filename=\"{0}\"", filename);
            headers["Content-Encoding"]    = "UTF-8";

            var          user   = !string.IsNullOrWhiteSpace(request.UserId) ? _userManager.GetUserById(request.UserId) : null;
            ReportResult result = null;

            switch (reportViewType)
            {
            case ReportViewType.ReportData:
                ReportIncludeItemTypes reportRowType = ReportHelper.GetRowType(request.IncludeItemTypes);
                ReportBuilder          dataBuilder   = new ReportBuilder(_libraryManager);
                QueryResult <BaseItem> queryResult   = GetQueryResult(request, user);
                result = dataBuilder.GetResult(queryResult.Items, request);
                result.TotalRecordCount = queryResult.TotalRecordCount;
                break;

            case ReportViewType.ReportActivities:
                result = GetReportActivities(request);
                break;
            }

            string returnResult = string.Empty;

            switch (request.ExportType)
            {
            case ReportExportType.CSV:
                returnResult = new ReportExport().ExportToCsv(result);
                break;

            case ReportExportType.Excel:
                returnResult = new ReportExport().ExportToExcel(result);
                break;
            }

            return(_resultFactory.GetResult(returnResult, contentType, headers));
        }
        public async Task <ReportExport> ExportNonVatDocumentByCriteriaAsync(int page, int itemPerPage, long?documentId, string partnerName, string type, string startDate, string endDate, string objGuid)
        {
            var query  = nonVatDocumentRepo.AllAsNoTracking();
            var report = new ReportExport();


            if (documentId != null)
            {
                query = query.Where(e => e.Id == documentId);
                report.DocumentsTypes = "document";
            }
            else
            {
                if (!string.IsNullOrEmpty(type))
                {
                    report.DocumentsTypes = SetType(type);
                    if (type == "proformInvoice")
                    {
                        query = query.Where(e => e.Type == Data.CompanyData.Models.Enums.NonVatDocumentTypes.ProformaInvoice);
                        report.DocumentsTypes = "Проформа фактури";
                    }
                    else if (type == "protocol")
                    {
                        query = query.Where(e => e.Type == Data.CompanyData.Models.Enums.NonVatDocumentTypes.Protocol);
                        report.DocumentsTypes = "Протоколи";
                    }
                    else if (type == "stock")
                    {
                        query = query.Where(e => e.Type == Data.CompanyData.Models.Enums.NonVatDocumentTypes.Stock);
                        report.DocumentsTypes = "Стокови разписки";
                    }
                    else
                    {
                        report.DocumentsTypes = "Складови документи";
                    }
                }
                else
                {
                    report.DocumentsTypes = "Данъчни документи";
                }

                if (!string.IsNullOrEmpty(partnerName))
                {
                    report.CompanyName = partnerName;
                    var partnerId = await partnerService.GetPartnerByName(partnerName);

                    if (partnerId != null)
                    {
                        query = query.Where(e => e.PartnerId == partnerId.Id);
                    }
                    else
                    {
                        query = query.Where(e => e.PartnerId == 0);
                    }
                }

                if (!string.IsNullOrEmpty(startDate))
                {
                    DateTime date;
                    var      isDate = DateTime.TryParse(startDate, new CultureInfo("bg-BG"), DateTimeStyles.None, out date);
                    if (isDate)
                    {
                        query = query.Where(e => e.CreatedDate >= date);
                    }
                }

                if (!string.IsNullOrEmpty(endDate))
                {
                    DateTime date;
                    var      isDate = DateTime.TryParse(endDate, new CultureInfo("bg-BG"), DateTimeStyles.None, out date);
                    if (isDate)
                    {
                        query = query.Where(e => e.CreatedDate <= date);
                    }
                }

                if (!string.IsNullOrEmpty(objGuid))
                {
                    query          = query.Where(e => e.CompanyObject.GUID == objGuid);
                    report.Objects = userCompanyTemp.CurrentCompanyAppObjects.Where(o => o.GUID == objGuid).FirstOrDefault()?.ObjectName;
                }
            }



            var result = await query.OrderByDescending(e => e.CreatedDate).ThenByDescending(e => e.Id).Select(e => new
            {
                Id           = e.Id,
                PartnerName  = e.Partner.Name,
                CreatedDate  = e.CreatedDate,
                DocumentType = e.Type.ToString(),
                Base         = e.SubTottal,
                Vat          = e.Vat ?? 0,
                Tottal       = e.Tottal,
            }).ToListAsync();


            if (string.IsNullOrEmpty(startDate))
            {
                report.StartDate = result.OrderBy(e => e.CreatedDate).FirstOrDefault()?.CreatedDate.ToString("dd.MM.yyyy");
            }
            else
            {
                report.StartDate = startDate;
            }

            if (string.IsNullOrEmpty(endDate))
            {
                report.EndDate = DateTime.Now.ToString("dd.MM.yyyy");
            }
            else
            {
                report.EndDate = endDate;
            }

            report.Documents = result.Select(e => new DocumentShortView()
            {
                Id            = e.Id,
                PartnerName   = e.PartnerName,
                CreatedDate   = e.CreatedDate.ToString("dd.MM.yyyy"),
                DocumentType  = SetType(e.DocumentType.ToString()),
                Base          = e.Base,
                Vat           = e.Vat,
                Tottal        = e.Tottal,
                IsVatDocument = true,
            });
            return(report);
        }