public FactuurDetailViewModel(IDialogService dialogService, IDuraFactViewModel parent, ISession session, Factuur factuur) { if (factuur.Items.Count == 0) _nieuweFactuur = true; _dialogService = dialogService; Parent = parent as DuraFactViewModel; _session = session; Factuur = factuur; }
public static string CreateFactuur(Factuur factuur) { try { var filename = GenerateFileName(factuur); using (var fs = new FileStream(Path.Combine(FactuurFolder.FullName, filename), FileMode.Create)) { var document = new Document(PageSize.A4, 25, 25, 30, 1); var writer = PdfWriter.GetInstance(document, fs); writer.PageEvent = new FactuurHelper(); // Add meta information to the document document.AddAuthor("Dura - Vanseveren"); document.AddCreator("DuraFact"); document.AddKeywords("Factuur"); document.AddSubject(string.Format("Factuur {0}", factuur.FactuurNummer)); document.AddTitle("Factuur"); // Open the document to enable you to write to the document document.Open(); // Makes it possible to add text to a specific place in the document using // a X & Y placement syntax. var content = writer.DirectContent; // Add a footer template to the document // content.AddTemplate(PdfFooter(content, factuur), 30, 1); // Add a logo to the invoice var img = DuraLogo; img.ScalePercent(80); img.SetAbsolutePosition(40, 650); content.AddImage(img); // First we must activate writing content.BeginText(); // First we write out the header information AddKlantData(factuur, content); WriteText(content, "Factuur", 40, 600, 20, true); AddFactuurData(factuur, content); // You need to call the EndText() method before we can write graphics to the document! content.EndText(); // Separate the header from the rows with a line // Draw a line by setting the line width and position content.SetLineWidth(0f); content.MoveTo(40, 590); content.LineTo(560, 590); content.Stroke(); // Don't forget to call the BeginText() method when done doing graphics! content.BeginText(); // Before we write the lines, it's good to assign a "last position to write" // variable to validate against if we need to make a page break while outputting. // Change it to 510 to write to test a page break; the fourth line on a new page const int lastwriteposition = 150; // Loop thru the table of items and set the linespacing to 12 points. // Note that we use the -= operator, the coordinates goes from the bottom of the page! var topMargin = 570; if (!string.IsNullOrEmpty(factuur.Opmerking)) { WriteText(content, "Opmerking", 40, topMargin, 12, true); topMargin -= 20; foreach (string s in factuur.Opmerking.Split(new string[] { Environment.NewLine }, StringSplitOptions.None)) { WriteText(content, s, 40, topMargin, 10); topMargin -= 16; } topMargin -= 4; } AddItemData(factuur, document, lastwriteposition, content, ref topMargin); // You need to call the EndText() method before we can write graphics to the document! content.EndText(); // Separate the header from the rows with a line // Draw a line by setting the line width and position content.SetLineWidth(0f); content.MoveTo(40, topMargin); content.LineTo(560, topMargin); content.Stroke(); // Don't forget to call the BeginText() method when done doing graphics! content.BeginText(); topMargin -= 15; AddBTWData(factuur, content, topMargin); // End the writing of text content.EndText(); // Close the document, the writer and the filestream! document.Close(); writer.Close(); fs.Close(); return Path.Combine(FactuurFolder.FullName, filename); } } catch { return string.Empty; } }
private static string GenerateFileNameHerinnering(Factuur factuur) { // check if year folder exists if (HerinneringFolder.GetDirectories(factuur.FacturatieDatum.Year.ToString()).Length == 0) HerinneringFolder.CreateSubdirectory(factuur.FacturatieDatum.Year.ToString()); return string.Format(@"{3}\{0}_{1}_{2}_{4}.pdf", factuur.Klant.Naam.ToUpper(), factuur.Klant.Voornaam, factuur.FacturatieDatum.ToString("yyyyMMdd"), factuur.FacturatieDatum.Year, DateTime.Now.ToString("yyyyMMdd")); }
private static string GenerateFileName(Factuur factuur) { // check if year folder exists var yearFolder = FactuurFolder.GetDirectories(factuur.FacturatieDatum.Year.ToString()).Length == 0 ? FactuurFolder.CreateSubdirectory(factuur.FacturatieDatum.Year.ToString()) : FactuurFolder.GetDirectories(factuur.FacturatieDatum.Year.ToString())[0]; // check if letter folder exists if (yearFolder.GetDirectories(factuur.Klant.Naam.Substring(0, 1).ToUpper()).Length == 0) yearFolder.CreateSubdirectory(factuur.Klant.Naam.Substring(0, 1).ToUpper()); return string.Format(@"{3}\{4}\{0}_{1}_{2}.pdf", factuur.Klant.Naam.ToUpper(), factuur.Klant.Voornaam, factuur.FacturatieDatum.ToString("yyyyMMdd"), factuur.FacturatieDatum.Year, factuur.Klant.Naam.Substring(0, 1).ToUpper()); }
private static void AddKlantData(Factuur factuur, PdfContentByte content) { WriteText(content, factuur.Klant.ToString(), 330, 730, 10); WriteText(content, factuur.Klant.Adres.StraatNrBus, 330, 718, 10); WriteText(content, factuur.Klant.Adres.PostcodeGemeente, 330, 706, 10); if (!string.IsNullOrEmpty(factuur.Klant.BTWNummer)) WriteText(content, string.Format("BTW BE {0}", factuur.Klant.BTWNummer), 330, 684, 10); }
private static void AddItemData(Factuur factuur, Document document, int lastwriteposition, PdfContentByte content, ref int topMargin) { // Loop thru the rows in the rows table // Start by writing out the line headers // Line headers const int aantalMargin = 360, ehprijsMargin = 450, totaalMargin = 540; WriteText(content, "Omschrijving", 40, topMargin, 12, true); WriteText(content, "Aantal", aantalMargin, topMargin, 12, true, PdfContentByte.ALIGN_RIGHT); WriteText(content, "Prijs/EH", ehprijsMargin, topMargin, 12, true, PdfContentByte.ALIGN_RIGHT); WriteText(content, "Bedrag", totaalMargin, topMargin, 12, true, PdfContentByte.ALIGN_RIGHT); topMargin -= 20; foreach (var item in factuur.Items) { var opmerkingBottom = topMargin; foreach (var s in item.Omschrijving.Split(new[] { Environment.NewLine }, StringSplitOptions.None)) { WriteText(content, s, 40, opmerkingBottom, 10); opmerkingBottom -= 16; } WriteText(content, item.Aantal.ToString(), aantalMargin, topMargin, 10, false, PdfContentByte.ALIGN_RIGHT); WriteText(content, string.Format("{0:C}", Math.Round(item.EenheidsPrijs, 2)), ehprijsMargin, topMargin, 10, false, PdfContentByte.ALIGN_RIGHT); WriteText(content, string.Format("{0:C}", item.TotaalPrijs), totaalMargin, topMargin, 10, false, PdfContentByte.ALIGN_RIGHT); // This is the line spacing, if you change the font size, you might want to change this as well. topMargin = opmerkingBottom; // Implement a page break function, checking if the write position has reached the lastwriteposition if (topMargin > lastwriteposition) continue; // We need to end the writing before we change the page content.EndText(); // Make the page break document.NewPage(); // Start the writing again content.BeginText(); topMargin = 780; WriteText(content, "Omschrijving", 40, topMargin, 12, true); WriteText(content, "Aantal", aantalMargin, topMargin, 12, true, PdfContentByte.ALIGN_RIGHT); WriteText(content, "Prijs/EH", ehprijsMargin, topMargin, 12, true, PdfContentByte.ALIGN_RIGHT); WriteText(content, "Bedrag", totaalMargin, topMargin, 12, true, PdfContentByte.ALIGN_RIGHT); // Assign the new write location on page two! // Here you might want to implement a new header function for the new page topMargin -= 20; } }
private static void AddFactuurData(Factuur factuur, PdfContentByte content) { WriteText(content, "Fact. nr.", 360, 615, 12, true, PdfContentByte.ALIGN_RIGHT); WriteText(content, "Fact. dat.", 450, 615, 12, true, PdfContentByte.ALIGN_RIGHT); WriteText(content, "Verval dat.", 540, 615, 12, true, PdfContentByte.ALIGN_RIGHT); WriteText(content, factuur.FactuurNummer.ToString(), 360, 600, 10, false, PdfContentByte.ALIGN_RIGHT); WriteText(content, factuur.FacturatieDatum.ToShortDateString(), 450, 600, 10, false, PdfContentByte.ALIGN_RIGHT); WriteText(content, factuur.VervalDatum.ToShortDateString(), 540, 600, 10, false, PdfContentByte.ALIGN_RIGHT); }
private static void AddBTWData(Factuur factuur, PdfContentByte content, int topMargin) { WriteText(content, "BTW %", 40, topMargin, 10, true); WriteText(content, "basis", 160, topMargin, 10, true, PdfContentByte.ALIGN_RIGHT); WriteText(content, "BTW", 220, topMargin, 10, true, PdfContentByte.ALIGN_RIGHT); if (factuur.BTW == BTWPercentage.MedeContractant) WriteText(content, "BTW te voldoen door medecontractant KB 1 Art 20.", 250, topMargin, 8); WriteText(content, "0 %", 40, topMargin - 12, 10); WriteText(content, "6 %", 40, topMargin - 24, 10); WriteText(content, "21 %", 40, topMargin - 36, 10); int offset; switch (factuur.BTW) { case BTWPercentage.Levering: offset = 36; break; case BTWPercentage.Normaal: offset = 24; break; default: offset = 12; break; } WriteText(content, string.Format("{0:C}", factuur.TotaalExcl), 160, topMargin - offset, 10, false, PdfContentByte.ALIGN_RIGHT); WriteText(content, string.Format("{0:C}", factuur.TotaalBTW), 220, topMargin - offset, 10, false, PdfContentByte.ALIGN_RIGHT); WriteText(content, "Totaal basis:", 300, topMargin - 12, 10); WriteText(content, string.Format("{0:C}", factuur.TotaalExcl), 540, topMargin - 12, 10, false, PdfContentByte.ALIGN_RIGHT); WriteText(content, "Totaal BTW:", 300, topMargin - 24, 10); WriteText(content, string.Format("{0:C}", factuur.TotaalBTW), 540, topMargin - 24, 10, false, PdfContentByte.ALIGN_RIGHT); WriteText(content, "Te betalen:", 300, topMargin - 45, 18); WriteText(content, string.Format("{0:C}", factuur.TotaalIncl), 540, topMargin - 45, 18, true, PdfContentByte.ALIGN_RIGHT); }
public static string GenerateHerinnering(Factuur factuur) { try { var filename = GenerateFileNameHerinnering(factuur); using (var fs = new FileStream(Path.Combine(HerinneringFolder.FullName, filename), FileMode.Create)) { var document = new Document(PageSize.A4, 25, 25, 30, 1); var writer = PdfWriter.GetInstance(document, fs); // Add meta information to the document document.AddAuthor("Dura - Vanseveren"); document.AddCreator("DuraFact"); document.AddKeywords("Herinnering"); document.AddSubject(string.Format("Herinnering voor factuur {0}", factuur.FactuurNummer)); document.AddTitle("Herinnering"); // Open the document to enable you to write to the document document.Open(); // Makes it possible to add text to a specific place in the document using // a X & Y placement syntax. var content = writer.DirectContent; // Add a footer template to the document // content.AddTemplate(PdfFooter(content, factuur), 30, 1); // Add a logo to the invoice var img = DuraLogo; img.ScalePercent(80); img.SetAbsolutePosition(40, 650); content.AddImage(img); // First we must activate writing content.BeginText(); // First we write out the header information AddKlantData(factuur, content); WriteText(content, string.Format("Tielt, {0}", DateTime.Now.ToShortDateString()), 40, 600, 10); WriteText(content, "Herinnering", 40, 550, 20, true); WriteText(content, "Geachte heer/mevrouw", 40, 520, 10); WriteText(content, string.Format("Wij hebben bij u een betalingsachterstand van {0:C} geconstateerd.", factuur.TotaalIncl), 40, 500, 10); WriteText(content, "Dit bedrag heeft betrekking op de onderstaande factuur:", 40, 485, 10); const int aantalMargin = 230, ehprijsMargin = 300, totaalMargin = 460; WriteText(content, "Factuur", 140, 460, 12, true, PdfContentByte.ALIGN_RIGHT); WriteText(content, "Datum", aantalMargin, 460, 12, true, PdfContentByte.ALIGN_RIGHT); WriteText(content, "Bedrag", ehprijsMargin, 460, 12, true, PdfContentByte.ALIGN_RIGHT); WriteText(content, "Betalingskenmerk", totaalMargin, 460, 12, true, PdfContentByte.ALIGN_RIGHT); WriteText(content, factuur.FactuurNummer.ToString(), 140, 440, 10, false, PdfContentByte.ALIGN_RIGHT); WriteText(content, factuur.FacturatieDatum.ToShortDateString(), aantalMargin, 440, 10, false, PdfContentByte.ALIGN_RIGHT); WriteText(content, string.Format("{0:C}", factuur.TotaalIncl), ehprijsMargin, 440, 10, false, PdfContentByte.ALIGN_RIGHT); WriteText(content, factuur.FacturatieDatum.ToShortDateString(), totaalMargin, 440, 10, false, PdfContentByte.ALIGN_RIGHT); WriteText(content, string.Format("Wij verzoeken u nu vriendelijk het bovenstaande bedrag zulks ten bedrage van {0:C} te doen overmaken.", factuur.TotaalIncl), 40, 400, 10); WriteText(content, "Dit kan op rekeningnummer 733-0318587-69 bij KBC of 001-6090654-03 bij BNP Paribas Fortis onder vermelding", 40, 385, 10); WriteText(content, "van uw betalingskenmerk.", 40, 370, 10); WriteText(content, "Wanneer u vragen mocht hebben over deze herinnering, verzoeken wij u zo spoedig mogelijk contact op te nemen", 40, 355, 10); WriteText(content, "op het telefoonnummer (051) 40 34 77.", 40, 340, 10); WriteText(content, "Heeft u inmiddels uw betalingsachterstand voldaan, dan is deze herinnering voor u niet meer van toepassing.", 40, 325, 10); WriteText(content, "Hoogachtend,", 40, 280, 10); WriteText(content, "Filip Vanseveren", 40, 180, 10); // End the writing of text content.EndText(); // Close the document, the writer and the filestream! document.Close(); writer.Close(); fs.Close(); return Path.Combine(HerinneringFolder.FullName, filename); } } catch { return string.Empty; } }
public FactuurDetailViewModel(IDuraFactViewModel parent, ISession session, Factuur factuur) : this(ImplementationLocator.Resolve<IDialogService>(), parent, session, factuur) { }