public OfferViewModel()
 {
     dataHandler  = DatabaseFacade.GetInstance();
     pdfExporter  = new PDFExporter();
     currentOffer = new Offer(DateTime.Now);
     Items        = dataHandler.GetAllItems();
 }
Exemple #2
0
        public void PDFGenerator(IExtendOffer currentOffer, string path)
        {
            using (doc)
            {
                PdfWriter.GetInstance(doc, new FileStream(path: path, mode: FileMode.Create));
                doc.Open();

                //Section: Customer Information List
                Paragraph customerInformationParagraph = new Paragraph("KUNDE INFORMATION");
                if (currentOffer.MyCustomer != null)
                {
                    customerInformationList.Add(currentOffer.MyCustomer.CustomerName);
                    customerInformationList.Add(currentOffer.MyCustomer.CustomerAddress);
                    customerInformationList.Add(currentOffer.MyCustomer.CustomerZip + "");
                    customerInformationList.Add("CVR nummer: " + currentOffer.MyCustomer.CVRNumber);
                    customerInformationList.Add(currentOffer.MyCustomer.Email);
                }
                else
                {
                    customerInformationList.Add("INGEN KUNDE VALGT");
                }

                //Section: Economy Table
                economyTable.AddCell("SUBTOTAL:");
                economyTable.AddCell(currentOffer.OfferSubTotal + " DKK");
                economyTable.AddCell("KUNDERABAT:");
                if (currentOffer.MyCustomer == null)
                {
                    economyTable.AddCell("0 %");
                }
                else
                {
                    economyTable.AddCell(currentOffer.MyCustomer.CustomerDiscountPercent + " %");
                }
                economyTable.AddCell("TILBUDSRABAT");
                economyTable.AddCell(currentOffer.OfferDiscountPercent + " %");
                economyTable.AddCell("TRANSPORTOMKOSTNINGER:");
                economyTable.AddCell(currentOffer.ForwardingAgentPrice + " DKK");
                economyTable.AddCell("TOTAL RABAT:");
                economyTable.AddCell(currentOffer.TotalPercentDiscount.ToString());
                economyTable.AddCell("TOTAL BELØB SPARET:");
                economyTable.AddCell(currentOffer.TotalDiscountedPrice.ToString());
                economyTable.AddCell("TOTAL:");
                economyTable.AddCell(currentOffer.OfferTotal + " DKK");

                //Section: OfferLines Table
                //Make headerrows
                offerLineTable.AddCell("Vare nr.");
                offerLineTable.AddCell("Varenavn");
                offerLineTable.AddCell("Antal varer");
                offerLineTable.AddCell("Stk. pris, DKK");
                offerLineTable.AddCell("Tilbudspris, DKK");
                offerLineTable.AddCell("Rabat, %");
                offerLineTable.AddCell("Total, DKK");

                //Add offerlines to OfferLines Table
                foreach (OfferLine offerLine in currentOffer.OfferLines)
                {
                    offerLineTable.AddCell(offerLine.ItemNo);
                    offerLineTable.AddCell(offerLine.ItemName);
                    offerLineTable.AddCell(offerLine.Quantity + "");
                    offerLineTable.AddCell(offerLine.ItemPrice + "");
                    offerLineTable.AddCell(offerLine.DiscountedPrice + "");
                    offerLineTable.AddCell(offerLine.PercentDiscount + "");
                    offerLineTable.AddCell(offerLine.OfferLineTotal + "");
                }

                //Section: Write to document
                //Add all information to the document
                doc.Add(customerInformationParagraph);
                doc.Add(customerInformationList);
                doc.Add(offerLineTable);
                doc.Add(economyTable);
                doc.Close();
            }
        }