예제 #1
0
        /// <summary>
        /// Method for generating event reports - RS
        /// </summary>
        /// <param name="eventManagementReportQueryAc"></param>
        /// <param name="currentUserInstituteId"></param>
        /// <returns></returns>
        public async Task <EventManagementReportResponseAc> GenerateEventReportAsync(EventManagementReportQueryAc eventManagementReportQueryAc, int currentUserInstituteId)
        {
            #region Fetch details

            List <EventReportAc>     eventReportAcList      = new List <EventReportAc>();
            List <EventReportDetail> eventReportDetailsList = await _imsDbContext.EventReportDetails
                                                              .Where(x => x.InstituteId == currentUserInstituteId && x.SentOn.Date >= eventManagementReportQueryAc.StartDate.Date && x.SentOn.Date <= eventManagementReportQueryAc.EndDate.Date)
                                                              .ToListAsync();

            foreach (EventReportDetail eventReportDetail in eventReportDetailsList)
            {
                eventReportAcList.Add(new EventReportAc
                {
                    Format  = EnumHelperService.GetDescription(eventReportDetail.TemplateFormat),
                    To      = eventReportDetail.To,
                    Subject = eventReportDetail.Subject,
                    Message = eventReportDetail.Message,
                    SentOn  = eventReportDetail.SentOn.ToString("dd-MMM-yyyy")
                });
            }

            #endregion

            #region Generate file

            string fileName = "Event_Report_" + DateTime.Now.Day.ToString("00") + "_" + DateTime.Now.Month.ToString("00") + "_" + DateTime.Now.Year.ToString("0000") + ".xlsx";
            return(new EventManagementReportResponseAc()
            {
                FileName = fileName,
                ResponseType = "application/ms-excel",
                FileByteArray = ExcelHelperService.GenerateExcelFromList(eventReportAcList, string.Empty)
            });

            #endregion
        }
예제 #2
0
        /// <summary>
        /// Method for generating the student fee report - RS
        /// </summary>
        /// <param name="feeManagementReportQueryAc"></param>
        /// <param name="currentUserInstituteId"></param>
        /// <returns></returns>
        public async Task <FeeManagementReportResponseAc> GenerateStudentFeeReportAsync(FeeManagementReportQueryAc feeManagementReportQueryAc, int currentUserInstituteId)
        {
            if (feeManagementReportQueryAc.StudentId != 0)
            {
                #region Set pdf data

                List <StudentFeeExcelReportAc> studentFeeExcelReportAcList = await GetStudentFeeDetailsForReportAsync(feeManagementReportQueryAc, currentUserInstituteId);

                StudentFeePdfReportAc studentFeePdfReportAc = new StudentFeePdfReportAc
                {
                    RollNumber      = studentFeeExcelReportAcList.First().RollNumber,
                    AdmissionNumber = studentFeeExcelReportAcList.First().AdmissionNumber,
                    FirstName       = studentFeeExcelReportAcList.First().FirstName,
                    LastName        = studentFeeExcelReportAcList.First().LastName,
                    CurrentClass    = studentFeeExcelReportAcList.First().CurrentClass,
                    Section         = studentFeeExcelReportAcList.First().Section,
                    Religion        = studentFeeExcelReportAcList.First().Religion,
                    IsActive        = studentFeeExcelReportAcList.First().IsActive,
                    IsArchived      = studentFeeExcelReportAcList.First().IsArchived
                };

                studentFeePdfReportAc.PaymentDetails = new List <StudentFeeExcelReportAc>();
                foreach (StudentFeeExcelReportAc studentFeeExcelReportAc in studentFeeExcelReportAcList)
                {
                    studentFeePdfReportAc.PaymentDetails.Add(new StudentFeeExcelReportAc
                    {
                        FeeComponentType = studentFeeExcelReportAc.FeeComponentType,
                        FeeComponent     = studentFeeExcelReportAc.FeeComponent,
                        Term             = studentFeeExcelReportAc.Term,
                        Amount           = studentFeeExcelReportAc.Amount,
                        PaymentDate      = studentFeeExcelReportAc.PaymentDate
                    });
                }

                #endregion

                #region Generate pdf

                string           path           = Path.Combine(Directory.GetCurrentDirectory(), "Views", "Home");
                RazorLightEngine engine         = new RazorLightEngineBuilder().UseFilesystemProject(path).UseMemoryCachingProvider().Build();
                string           resultFromFile = engine.CompileRenderAsync("StudentFeeReceiptPdf.cshtml", studentFeePdfReportAc).Result;

                string fileName = "Fee_Receipt_" + studentFeePdfReportAc.FirstName + "_" + DateTime.Now.Day.ToString("00") + "_" + DateTime.Now.Month.ToString("00") + "_" + DateTime.Now.Year.ToString("0000") + ".pdf";
                return(new FeeManagementReportResponseAc
                {
                    FileName = fileName,
                    ResponseType = "application/pdf",
                    //FileByteArray = PdfHelperService.GeneratePdfFromHtml(resultFromFile, "Reports", fileName)
                    PdfHtmlString = resultFromFile
                });

                #endregion
            }
            else
            {
                List <StudentFeeExcelReportAc> studentFeeExcelReportAcList = await GetStudentFeeDetailsForReportAsync(feeManagementReportQueryAc, currentUserInstituteId);

                #region Generate file

                string fileName = "Fee_Report_" + DateTime.Now.Day.ToString("00") + "_" + DateTime.Now.Month.ToString("00") + "_" + DateTime.Now.Year.ToString("0000") + ".xlsx";
                return(new FeeManagementReportResponseAc
                {
                    FileName = fileName,
                    ResponseType = "application/ms-excel",
                    FileByteArray = ExcelHelperService.GenerateExcelFromList(studentFeeExcelReportAcList, string.Empty)
                });

                #endregion
            }
        }