Пример #1
0
        public void CreatePdf(Invoice invoice, string filePath)
        {
            PdfPTable saleTable = SaleTable(invoice);

            FileStream fileStream = new FileStream(filePath,
                                                    FileMode.Create,
                                                    FileAccess.Write,
                                                    FileShare.None);

            Document doc = new Document();
            PdfWriter.GetInstance(doc, fileStream);
            doc.Open();

            Paragraph date = new Paragraph("Date: " + invoice.Date.ToShortDateString()) {Alignment = 2};

            doc.Add(date);

            doc.Add(new Paragraph("Invoice To:"));
            doc.Add(new Paragraph(invoice.Customer));

            Paragraph separator = new Paragraph("_____________________________________________________________________________      ");
            separator.SpacingAfter = 5.5f;
            doc.Add(separator);

            doc.Add(saleTable);
            doc.Close();
        }
Пример #2
0
        public Invoice Calculate(Job job, String customerName)
        {
            if (job == null)
            {
                throw new ArgumentNullException("job");
            }

            var invoice = new Invoice
            {
                Customer = customerName,
                Date = DateTime.Now,
                Items = job.Items.Select(GetLineItem).ToList()
            };
            invoice.TotalAmount = GetTotalCaclulationStrategy(job).Calculate(invoice.Items.ToList());

            return invoice;
        }
Пример #3
0
        private PdfPTable SaleTable(Invoice invoice)
        {
            var itemList = invoice.Items;

            PdfPTable table = new PdfPTable(3);
            table.TotalWidth = 1000f;
            float[] widths = new float[] { 0.5f, 4f, 1f};
            table.SetWidths(widths);

            table.AddCell(HeaderCell("Item"));
            table.AddCell(HeaderCell("Description"));
            table.AddCell(HeaderCell("Price"));

            foreach (var item in itemList)
            {
                table.AddCell(QuantityCell((itemList.IndexOf(item) + 1).ToString() + "."));
                table.AddCell(item.Name);
                table.AddCell(PriceCell(item.Amount.ToString("C")));
            }

            PdfPCell grandTotal = new PdfPCell(new Phrase(invoice.TotalAmount.ToString("C")))
            {
                Border = Rectangle.TOP_BORDER,
                HorizontalAlignment = 2
            };

            PdfPCell gtText = new PdfPCell(new Phrase("Grand Total:"))
            {
                HorizontalAlignment = 2,
                Colspan = 2,
                Border = Rectangle.TOP_BORDER
            };

            table.AddCell(gtText);
            table.AddCell(grandTotal);

            return table;
        }
Пример #4
0
 public void Write(Invoice invoice, String filePath)
 {
     CreatePdf(invoice, filePath);
 }