Notes
![]() ![]() Notes - notes.io |
using PdfSharp.Pdf;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Globalization;
using System.IO;
using System.Threading.Tasks;
using YourNamespace.Service.IService;
using YourNamespace.DataModel.Models;
public class CommissionController : Controller
{
private readonly ICommissionService commissionService;
private readonly IWebHostEnvironment environment;
public CommissionController(ICommissionService commissionService, IWebHostEnvironment environment)
{
this.commissionService = commissionService;
this.environment = environment;
}
[HttpPost]
public async Task<IActionResult> GeneratePdfOfEber(string startDate, string endDate)
{
try
{
// Fetch data from service
string managerId = "5303747171857";
var model = await commissionService.GetHourlyCommissionForAccountManagersAsync(startDate, endDate, managerId);
DateTime.TryParseExact(endDate, "MM/dd/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime parsedEndDate);
var month = parsedEndDate.ToString("MM-yyyy");
// Create a new PDF document
PdfDocument pdfDocument = new PdfDocument();
PdfPage pdfPage = pdfDocument.AddPage();
XGraphics gfx = XGraphics.FromPdfPage(pdfPage);
gfx.MUH = PdfFontEncoding.Unicode; // Ensure that Unicode text is properly encoded
// Add image to the PDF
string imagePath = Path.Combine(environment.WebRootPath, "images", "logo_white.png");
if (System.IO.File.Exists(imagePath))
{
XImage xImage = XImage.FromFile(imagePath);
gfx.DrawImage(xImage, 10, 10, 50, 50); // Adjust position and size as needed
}
else
{
Console.WriteLine("Image file not found: " + imagePath);
}
// Add title
XFont font = new XFont("Verdana", 16, XFontStyle.Bold);
gfx.DrawString("Commissions Eber Oroz: " + month, font, XBrushes.Black, new XRect(0, 70, pdfPage.Width, 30), XStringFormats.TopCenter);
// Add table header
XFont headerFont = new XFont("Verdana", 12, XFontStyle.Bold);
double yPoint = 100;
gfx.DrawString("Customer", headerFont, XBrushes.Black, new XRect(10, yPoint, 100, 30));
gfx.DrawString("ITEM", headerFont, XBrushes.Black, new XRect(110, yPoint, 100, 30));
gfx.DrawString("Margen", headerFont, XBrushes.Black, new XRect(210, yPoint, 100, 30));
gfx.DrawString("Coef. 5%", headerFont, XBrushes.Black, new XRect(310, yPoint, 100, 30));
gfx.DrawString("Eber", headerFont, XBrushes.Black, new XRect(410, yPoint, 100, 30));
// Add data to table
XFont dataFont = new XFont("Verdana", 10, XFontStyle.Regular);
yPoint += 30;
if (model.HourlyCommissionCompanyGroupModelList != null)
{
foreach (var companyGroup in model.HourlyCommissionCompanyGroupModelList)
{
if (companyGroup.HourlyCommissionModel != null)
{
foreach (var item in companyGroup.HourlyCommissionModel)
{
gfx.DrawString(item.Customer, dataFont, XBrushes.Black, new XRect(10, yPoint, 100, 30));
gfx.DrawString(item.ITEM, dataFont, XBrushes.Black, new XRect(110, yPoint, 100, 30));
gfx.DrawString(item?.Margen?.ToString(), dataFont, XBrushes.Black, new XRect(210, yPoint, 100, 30));
gfx.DrawString(item?.Coeff5Percent?.ToString(), dataFont, XBrushes.Black, new XRect(310, yPoint, 100, 30));
gfx.DrawString(item?.Eber?.ToString(), dataFont, XBrushes.Black, new XRect(410, yPoint, 100, 30));
yPoint += 20;
}
// Footer row for each company group
gfx.DrawString(companyGroup.Customer, dataFont, XBrushes.Black, new XRect(10, yPoint, 100, 30));
gfx.DrawString(companyGroup.EmployeeCount.ToString(), dataFont, XBrushes.Black, new XRect(110, yPoint, 100, 30));
gfx.DrawString(companyGroup.TotalMargen.ToString("C"), dataFont, XBrushes.Black, new XRect(210, yPoint, 100, 30));
gfx.DrawString(companyGroup.TotalCoeff5Percent.ToString("C"), dataFont, XBrushes.Black, new XRect(310, yPoint, 100, 30));
gfx.DrawString(companyGroup.TotalEber.ToString("C"), dataFont, XBrushes.Black, new XRect(410, yPoint, 100, 30));
yPoint += 20;
}
}
}
// Render the document and return it
using (var memoryStream = new MemoryStream())
{
pdfDocument.Save(memoryStream);
string fileName = $"EO_Commissions_{month}.pdf";
return File(memoryStream.ToArray(), "application/pdf", fileName);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
throw;
}
}
}
![]() |
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team