Example #1
0
        public void GenerateInvoice(MemoryStream stream, Invoice invoiceData)
        {
            Document doc = null;

            try
            {
                // Initialize the PDF document
                doc = new Document();
                PdfWriter writer = PdfWriter.GetInstance(doc, stream);

                // Set the margins and page size
                this.SetStandardPageSize(doc);

                // Open the document for writing content
                doc.Open();

                this.AddPageWithTable(doc, invoiceData);

                // Add a final page
                this.SetStandardPageSize(doc);  // Reset the margins and page size
            }
            catch (DocumentException ex)
            {
                // Handle iTextSharp errors
                _Logger.Error("BookingInvoice", ex);
            }
            finally
            {
                // Clean up
                doc.Close();
                doc = null;
            }
        }
Example #2
0
        /// <summary>
        /// Add all the booking content
        /// </summary>
        /// <param name="doc"></param>
        void AddPageWithTable(Document doc, Invoice invoiceData)
        {
            // Add a new page to the document
            doc.NewPage();

            var context = ModelFactory.GetUnitOfWork();
            var mRepo = ModelFactory.GetRepository<IMemberRepository>(context);
            var lRepo = ModelFactory.GetRepository<ILocalisationRepository>(context);

            var client = mRepo.Get(invoiceData.MemberId);
            var localisation = lRepo.Get(invoiceData.LocalisationId);

            var bookingOwner = new StringBuilder();
            bookingOwner.AppendLine(localisation.Name);
            bookingOwner.AppendLine(localisation.Member.GetFullDisplayName());
            bookingOwner.AppendLine(localisation.Member.MemberMainData.PhoneNumber);
            bookingOwner.AppendLine(localisation.Member.Email);
            if (!string.IsNullOrEmpty(localisation.Member.MemberMainData.TaxNumber))
                bookingOwner.AppendLine(string.Format(Worki.Resources.Models.Booking.Invoice.TaxNumber,localisation.Member.MemberMainData.TaxNumber));
            if (!string.IsNullOrEmpty(localisation.Member.MemberMainData.SiretNumber))
                bookingOwner.AppendLine(string.Format(Worki.Resources.Models.Booking.Invoice.SiretNumber, localisation.Member.MemberMainData.SiretNumber));

            this.AddParagraph(doc, Element.ALIGN_LEFT, _standardFont, new Chunk(bookingOwner.ToString()));

            var bookingClient = new StringBuilder();
            bookingClient.AppendLine(client.GetFullDisplayName());
            if (!string.IsNullOrEmpty(client.MemberMainData.CompanyName))
                bookingClient.AppendLine(client.MemberMainData.CompanyName);
            bookingClient.AppendLine(client.MemberMainData.Address);
            bookingClient.AppendLine(client.MemberMainData.PostalCode + " " + client.MemberMainData.City);
            bookingClient.AppendLine(client.MemberMainData.Country);
            if (!string.IsNullOrEmpty(client.MemberMainData.TaxNumber))
                bookingClient.AppendLine(string.Format(Worki.Resources.Models.Booking.Invoice.TaxNumber, client.MemberMainData.TaxNumber));

            this.AddParagraph(doc, Element.ALIGN_RIGHT, _standardFont, new Chunk(bookingClient.ToString()));

            var billingDesc = new StringBuilder();
            billingDesc.AppendLine(string.Format(Worki.Resources.Models.Booking.Invoice.InvoiceNumber,invoiceData.InvoiceNumber.DisplayName()));
            billingDesc.AppendLine(string.Format(Worki.Resources.Models.Booking.Invoice.Date, CultureHelpers.GetSpecificFormat(DateTime.Now, CultureHelpers.TimeFormat.Date)));

            this.AddParagraph(doc, Element.ALIGN_LEFT, _standardFont, new Chunk(billingDesc.ToString()));

            PdfPTable table = new PdfPTable(4);
            float[] widths = new float[] { 3f, 1f, 1f, 1f };
            table.SetWidths(widths);
            table.WidthPercentage = 100f;
            table.SpacingBefore = 20f;
            table.SpacingAfter = 10f;

            //headers
            this.AddCellHeader(table, Worki.Resources.Models.Booking.Invoice.Description);
            this.AddCellHeader(table, Worki.Resources.Models.Booking.Invoice.Quantity);
            this.AddCellHeader(table, Worki.Resources.Models.Booking.Invoice.PriceWT);
            this.AddCellHeader(table, Worki.Resources.Models.Booking.Invoice.SubTotal);

            var currency = (Offer.CurrencyEnum)invoiceData.Currency;

            //offer
            foreach (var item in invoiceData.InvoiceItems)
            {
                this.AddCell(table, item.Description, Element.ALIGN_LEFT, Rectangle.BOTTOM_BORDER);
                this.AddCell(table, item.Quantity.ToString(), Element.ALIGN_RIGHT, Rectangle.BOTTOM_BORDER);
                this.AddCell(table, item.GetWithoutTax().GetPriceDisplay(currency), Element.ALIGN_RIGHT, Rectangle.BOTTOM_BORDER);
                this.AddCell(table, (item.Price * item.Quantity).GetPriceDisplay(currency), Element.ALIGN_RIGHT, Rectangle.BOTTOM_BORDER);
            }

            //total
            this.AddCell(table, Worki.Resources.Models.Booking.Invoice.TotalWithoutTax, Element.ALIGN_LEFT, Rectangle.BOTTOM_BORDER , 3);
            this.AddCell(table, invoiceData.GetTotalWithoutTax().GetPriceDisplay(currency), Element.ALIGN_RIGHT, Rectangle.BOTTOM_BORDER);

            this.AddCell(table, Worki.Resources.Models.Booking.Invoice.TotalTax, Element.ALIGN_LEFT, Rectangle.BOTTOM_BORDER, 3);
            this.AddCell(table, invoiceData.GetTotalTax().GetPriceDisplay(currency), Element.ALIGN_RIGHT, Rectangle.BOTTOM_BORDER);

            this.AddCell(table, Worki.Resources.Models.Booking.Invoice.Total, Element.ALIGN_LEFT, Rectangle.TOP_BORDER, 3, 2f, _smallFontBold);
            this.AddCell(table, invoiceData.GetTotal().GetPriceDisplay(currency), Element.ALIGN_RIGHT, Rectangle.TOP_BORDER, 1, 2f, _smallFontBold);

            doc.Add(table);  // Add the list to the page

            this.AddParagraph(doc, Element.ALIGN_LEFT, _standardFont, new Chunk(string.Format(Worki.Resources.Models.Booking.Invoice.PaymentBy, Offer.GetPaymentTypeEnumType((int)invoiceData.PaymentType))));

            this.AddParagraph(doc, Element.ALIGN_LEFT, _standardFont, new Chunk("\n\n"));
            this.AddParagraph(doc, Element.ALIGN_RIGHT, _standardFont, new Chunk(string.Format(Worki.Resources.Models.Booking.Invoice.SeeYouSoon, localisation.Name)));
        }
Example #3
0
 public InvoiceFormViewModel(Localisation localisation, Invoice model = null)
 {
     Invoice = model ?? new Invoice();
     Invoice.Init(localisation);
     var clients = localisation.LocalisationClients.ToDictionary(mc => mc.ClientId, mc => mc.Member.GetFullDisplayName());
     Clients = new SelectList(clients, "Key", "Value");
     PaymentTypes = new SelectList(Offer.GetPaymentTypeEnumTypes(), "Key", "Value", Offer.PaymentTypeEnum.Paypal);
     Currencies = new SelectList(Offer.GetCurrencyEnumTypes(), "Key", "Value", Offer.CurrencyEnum.EUR);
 }
Example #4
0
 public InvoiceFormViewModel()
 {
     Invoice = new Invoice();
 }
Example #5
0
 public InvoiceSummary(Invoice invoice)
 {
     LastName = invoice.Member.MemberMainData.LastName;
     FirstName = invoice.Member.MemberMainData.FirstName;
     Address = invoice.Member.MemberMainData.Address + " " + invoice.Member.MemberMainData.City;
     TaxNumber = invoice.Member.MemberMainData.TaxNumber;
     Date = CultureHelpers.GetSpecificFormat(invoice.CreationDate, CultureHelpers.TimeFormat.Date);
     PaymentType = Offer.GetPaymentTypeEnumType(invoice.PaymentType);
     InvoiceNumber = invoice.Id.ToString();
     Description = invoice.Title;
     Amount = invoice.GetTotal();
     Tax = Amount * invoice.TaxRate / 100;
     //Paid = true ? Worki.Resources.Views.Shared.SharedString.Yes : Worki.Resources.Views.Shared.SharedString.No;
     Paid = Worki.Resources.Views.Shared.SharedString.Yes;
 }
Example #6
0
        /// <summary>
        /// Get action method to get invoice pdf
        /// </summary>
        /// <returns>Pdf file containing summary</returns>
        public virtual ActionResult GetInvoice(int id, bool fromBooking)
        {
            var context = ModelFactory.GetUnitOfWork();
            var bRepo = ModelFactory.GetRepository<IBookingRepository>(context);
            var iRepo = ModelFactory.GetRepository<IInvoiceRepository>(context);
            try
            {
                Invoice invoiceData = null;
                if (fromBooking)
                {
                    var booking = bRepo.Get(id);
                    invoiceData = new Invoice(booking);
                }
                else
                {
                    invoiceData = iRepo.Get(id);
                }

                using (var stream = new MemoryStream())
                {
                    _InvoiceService.GenerateInvoice(stream, invoiceData);
                    return File(stream.ToArray(), "application/pdf", invoiceData.GetFileName() + ".pdf");
                }
            }
            catch (Exception ex)
            {
                _Logger.Error("GetInvoice", ex);
                return View(MVC.Shared.Views.Error);
            }
        }