public async Task <HttpResponseMessage> ExportExcelBranchPromotionDetail(string startDate, string endDate) { DateTime?startDateTime = Utilities.ToDateTime(startDate); DateTime?endDateTime = Utilities.ToDateTime(endDate); GoalGoodsCategoryTypeEnum[] goalGoodsCategoryTypeIds = new GoalGoodsCategoryTypeEnum[] { GoalGoodsCategoryTypeEnum.Group , GoalGoodsCategoryTypeEnum.Single }; var entity = await promotionBS.LoadReportBranchPromotionDetail(startDateTime.Value, endDateTime.Value, goalGoodsCategoryTypeIds); if (entity.ReturnStatus == false) { return(CreateErrorResponse(entity)); } var dataResult = entity.ResultValue.GroupBy(x => x.BranchId) .Select(x => new ReportBranchPromotionDetailViewModel { BranchId = x.Key, BranchName = x.FirstOrDefault(y => y.BranchId == x.Key).BranchName, ManagerFulfillmentPercent = x.FirstOrDefault(y => y.BranchId == x.Key).ManagerFulfillmentPercent, SellerFulfillmentPercent = x.FirstOrDefault(y => y.BranchId == x.Key).SellerFulfillmentPercent, TotalFinalPromotion = x.FirstOrDefault(y => y.BranchId == x.Key).TotalFinalPromotion, TotalPromotionWithOutFulfillmentPercent = x.FirstOrDefault(y => y.BranchId == x.Key).TotalPromotionWithOutFulfillmentPercent, GoalPromotions = x.Select(y => new GoalPromotion { FinalPromotion = y.FinalPromotion, GoalGoodsCategoryName = y.GoalGoodsCategoryName, PromotionWithOutFulfillmentPercent = y.PromotionWithOutFulfillmentPercent }).ToList() }).ToList(); string downloadUrl = $"/excel/branch_sales_overview{DateTime.Now.Ticks}.xlsx"; string caption = $" گزارش پورسانت مراکز از فروش {startDate} - {endDate} "; var excelTemplate = HostingEnvironment.MapPath("/Views/Promotion/rptbranchsalesoverview/excelTemplate.html"); using (var package = new ExcelPackage()) { ExportToExcel.CreateExcelFile <ReportBranchPromotionDetailViewModel>(dataResult , outputFileName: downloadUrl , excelTemplatePath: excelTemplate , caption: caption , package: package , getLoopObjects: (ReportBranchPromotionDetailViewModel record) => record.GoalPromotions ); } return(Request.CreateResponse(HttpStatusCode.OK, downloadUrl)); }
private void BtnExportExcel_Click(object sender, EventArgs e) { //Get save file location of the excel file string fileLoc = exl.GetSavePath(ref txtCriteria, ref cboFilter); txtLogs.AppendText($"Save file location is set.{ NewLine }"); //Create an empty excel file exl.CreateExcelFile(fileLoc); txtLogs.AppendText($"Done creating excel file.{ NewLine }"); //Export all data to excel file exl.ExportEntriesToExcel(fileLoc, entries, bc, oi, a, ma, cd); txtLogs.AppendText($"Fill excel file with property data.{ NewLine }"); txtLogs.AppendText($"Excel file is now ready.{ NewLine }"); Console.WriteLine(); }
public async Task <HttpResponseMessage> ExportExcelBranchReceiptGoals(int year, int month, int goalGoodsCategoryTypeId) { var entity = await promotionBS.LoadReportBranchReceipt(year, month, (GoalGoodsCategoryTypeEnum)goalGoodsCategoryTypeId); if (entity.ReturnStatus == false) { return(CreateErrorResponse(entity)); } var lst_responses = entity.ResultValue.GroupBy(x => new { x.BranchName }) .Select(x => new ReportBranchReceiptGoalViewModel { BranchName = x.Key.BranchName, TotalSales = x.FirstOrDefault(y => y.BranchName == x.Key.BranchName).TotalSales, TotalQuantity = x.FirstOrDefault(y => y.BranchName == x.Key.BranchName).TotalQuantity, FinalPromotion = x.FirstOrDefault(y => y.BranchName == x.Key.BranchName).FinalPromotion, FulfilledPercent = Math.Round(x.FirstOrDefault(y => y.BranchName == x.Key.BranchName).FulfilledPercent, MidpointRounding.AwayFromZero), AmountSpecified = x.FirstOrDefault(y => y.BranchName == x.Key.BranchName).AmountSpecified, ReceiptAmount = x.FirstOrDefault(y => y.BranchName == x.Key.BranchName).ReceiptAmount, PositionTotalAmount = x.Sum(y => y.PositionPromotion), GoalGoodsCategoryName = x.FirstOrDefault(y => y.BranchName == x.Key.BranchName).GoalGoodsCategoryName, PositionPromotions = x.Select(y => new PositionPromotion { PositionTitle = y.PositionTitle, Promotion = y.PositionPromotion }).ToList() }).ToList(); string downloadUrl = $"/excel/branch_receipt{DateTime.Now.Ticks}.xlsx"; string caption = $" گزارش عملکرد {lst_responses.First().GoalGoodsCategoryName} سال {year} - ماه {month} "; var excelTemplate = HostingEnvironment.MapPath("/Views/Promotion/rptbranchreceipt/excelTemplate.html"); using (var package = new ExcelPackage()) { ExportToExcel.CreateExcelFile <ReportBranchReceiptGoalViewModel>(lst_responses , outputFileName: downloadUrl , excelTemplatePath: excelTemplate , caption: caption , package: package , getLoopObjects: (ReportBranchReceiptGoalViewModel record) => record.PositionPromotions ); } return(Request.CreateResponse(HttpStatusCode.OK, downloadUrl)); }
public async Task <HttpResponseMessage> ExportExcelOverView(int year, int month) { var entity = await promotionBS.LoadReportOverView(year, month); if (entity.ReturnStatus == false) { return(CreateErrorResponse(entity)); } var mapper = GetMapper(); var dataModelView = mapper.Map <List <BranchPromotionViewModel> >(entity.ResultValue); string caption = $"عملکرد نهایی سال {year} ماه {month} "; var excelTemplate = HostingEnvironment.MapPath("/Views/Promotion/rptoverview/excelTemplate.html"); string downloadUrl = $"/excel/over_view{DateTime.Now.Ticks}.xlsx"; using (var package = new ExcelPackage()) { ExportToExcel.CreateExcelFile(dataModelView, downloadUrl, excelTemplate, package, caption); } return(Request.CreateResponse(HttpStatusCode.OK, downloadUrl)); }
public async Task <HttpResponseMessage> ExportExcelSaleGoals(string startDate, string endDate, int goalGoodsCategoryId) { DateTime?startDateTime = Utilities.ToDateTime(startDate); DateTime?endDateTime = Utilities.ToDateTime(endDate); if (startDateTime.HasValue && endDateTime.HasValue) { var result_goal = await goalBS.EntityLoader.LoadAsync(where : x => x.GoalGoodsCategoryId == goalGoodsCategoryId && x.StartDate >= startDateTime.Value && x.EndDate <= endDateTime.Value, includes : x => x.GoalGoodsCategory); if (result_goal.ReturnStatus == false) { return(CreateErrorResponse(result_goal)); } string caption = $" گزارش عملکرد اهداف فروش محدوده تاریخ {startDate} - {endDate} هدف {result_goal.ResultValue.GoalGoodsCategory.Name}"; if (result_goal.ResultValue.ApprovePromotionTypeId == ApprovePromotionTypeEnum.Branch) { if (result_goal.ResultValue.ComputingTypeId == ComputingTypeEnum.Amount || result_goal.ResultValue.ComputingTypeId == ComputingTypeEnum.Quantities) { var result_report = await promotionBS.LoadReport_Amount_Quantities_Goal(startDateTime.Value, endDateTime.Value, goalGoodsCategoryId); if (result_report.ReturnStatus == false) { return(CreateErrorResponse(result_report)); } var lst_response = LoadReport_Amount_Quantities_Goal(result_report.ResultValue); string downloadUrl = $"/excel/branch_amountgoal{DateTime.Now.Ticks}.xlsx"; var excelTemplate = HostingEnvironment.MapPath("/Views/Promotion/rptbranchsales/excelBranchAmountTemplate.html"); using (var package = new ExcelPackage()) { ExportToExcel.CreateExcelFile <ReportSales_Amount_Qualntity_ViewModel>(lst_response, downloadUrl, excelTemplate, package, caption: caption , generatorHeader: (List <ReportSales_Amount_Qualntity_ViewModel> data, string template) => { if (data.Count == 0) { return(string.Empty); } var loop = string.Empty; for (int i = 1; i <= data[0].PromotionGoalSteps.Count; i++) { loop += template.Replace("$index", i.ToString()); } return(loop); } , getLoopObjects: (ReportSales_Amount_Qualntity_ViewModel record) => record.PromotionGoalSteps); } return(Request.CreateResponse(HttpStatusCode.OK, downloadUrl)); } else if (result_goal.ResultValue.ComputingTypeId == ComputingTypeEnum.Percentage) { var result_report = await promotionBS.LoadReport_Percent_Goal(startDateTime.Value, endDateTime.Value, goalGoodsCategoryId); if (result_report.ReturnStatus == false) { return(CreateErrorResponse(result_report)); } string downloadUrl = $"/excel/branch_quantitygoal{DateTime.Now.Ticks}.xlsx"; var excelTemplate = HostingEnvironment.MapPath("/Views/Promotion/rptbranchsales/excelBranchQuantityTemplate.html"); using (var package = new ExcelPackage()) { ExportToExcel.CreateExcelFile <ReportBranchSalesGoal>(result_report.ResultValue, downloadUrl, excelTemplate, package, caption: caption); } return(Request.CreateResponse(HttpStatusCode.OK, downloadUrl)); } } else if (result_goal.ResultValue.ApprovePromotionTypeId == ApprovePromotionTypeEnum.Seller) { var result_report = await promotionBS.LoadReport_Seller_Goal(startDateTime.Value, endDateTime.Value, goalGoodsCategoryId); if (result_report.ReturnStatus == false) { return(CreateErrorResponse(result_report)); } var lst_response = LoadReport_Seller_Goal(result_report.ResultValue); string downloadUrl = $"/excel/Seller_Goal{DateTime.Now.Ticks}.xlsx"; var excelTemplate = HostingEnvironment.MapPath("/Views/Promotion/rptbranchsales/excelSellerTemplate.html"); using (var package = new ExcelPackage()) { ExportToExcel.CreateExcelFile <ReportSellerGoalViewModel>(lst_response, downloadUrl, excelTemplate, package, caption: caption , generatorHeader: (List <ReportSellerGoalViewModel> data, string template) => { if (data.Count == 0) { return(string.Empty); } var loop = string.Empty; for (int i = 1; i <= data[0].PromotionGoalSteps.Count; i++) { loop += template.Replace("$index", i.ToString()); } return(loop); } , getLoopObjects: (ReportSellerGoalViewModel record) => record.PromotionGoalSteps); } return(Request.CreateResponse(HttpStatusCode.OK, downloadUrl)); } } return(Request.CreateResponse(HttpStatusCode.BadRequest)); }