示例#1
0
 DateTime getPaymentDueTerm()
 {
     try
     {
         return(DateOfIssue.AddDays(PaymentMethod.DueTerm));
     }
     catch (Exception)
     {
         return(DateOfIssue);
     }
 }
示例#2
0
        public void generate()
        {
            string    path = "invoiceTemplate.xml";
            XDocument doc  = XDocument.Load(path);
            XElement  root = doc.Element("Template");

            string header = root.Element("Header").Value;

            header = string.Format(header, Company.Name, Company.FullAddress, Company.NIP, Company.REGON, Company.Phone, Company.Email, Company.Website, Company.BankName, Company.BankAccount);

            string cityOfIssue    = root.Element("DatePlace").Value;
            string dateOfIssue    = DateOfIssue.ToShortDateString();
            string dateOfDelivery = DateOfDelivery.ToShortDateString();

            cityOfIssue = string.Format(cityOfIssue, dateOfIssue, IssuePlace, dateOfDelivery);

            string title = root.Element("Title").Value;

            title = string.Format(title, Number);

            string sellerBuyer = root.Element("SellerBuyer").Value;

            sellerBuyer = string.Format(sellerBuyer, Company.FullName, Company.FullAddress, Company.NIP, Contractor.FullName, Contractor.FullAddress, Contractor.NIP);

            header += cityOfIssue += title += sellerBuyer;

            string invoiceItemsTable   = root.Element("InvoiceItemsTableHeader").Value;
            string invoiceItemsSummary = root.Element("InvoiceItemTableSummary").Value;
            string invoiceItem         = root.Element("InvoiceItem").Value;

            int i = 1;

            foreach (InvoiceItem item in InvoiceItems)
            {
                string newItem = string.Format(invoiceItem, i, item.Item.Name, item.Item.UnitOfMeasure, item.Quantity, item.Item.UnitPrice.ToString("0.00"), item.ValueNetto.ToString("0.00"), item.Item.VatRate.ToString("0.00"), item.VATValue.ToString("0.00"), item.ValueBrutto.ToString("0.00"));
                Console.WriteLine(newItem);
                invoiceItemsTable += newItem;
                i++;
            }
            invoiceItemsSummary = string.Format(invoiceItemsSummary, TotalValueNetto.ToString("0.00"), TotalVATValue.ToString("0.00"), TotalValueBrutto.ToString("0.00"));
            invoiceItemsTable  += invoiceItemsSummary;

            string taxTableHeader  = root.Element("TaxTableHeader").Value;
            string tax             = root.Element("Tax").Value;
            string taxTableSummary = root.Element("TaxTableSummary").Value;
            string taxTable        = taxTableHeader + tax + taxTableSummary;

            string priceSummary = root.Element("PriceSummary").Value;

            priceSummary = string.Format(priceSummary, TotalValueBrutto.ToString("0.00"), "słownie złotych", "groszy");
            string paymentMethod = root.Element("PaymentMethod").Value;

            paymentMethod = string.Format(paymentMethod, PaymentMethod.Name, DateOfIssue.AddDays(PaymentMethod.DueDate).ToShortDateString());
            string issuer = root.Element("Issuer").Value;

            issuer = string.Format(issuer, Company.IssuerName);
            string footer = paymentMethod + issuer;


            string output = header + invoiceItemsTable + taxTable + priceSummary + footer;

            output = output.Replace("~^~^", "{{");
            output = output.Replace("^~^~", "}}");
            output = output.Replace("~^", "{");
            output = output.Replace("^~", "}");
            File.WriteAllText("out.tex", output);

            Process process = new Process();

            process.StartInfo.FileName  = "pdflatex";
            process.StartInfo.Arguments = "out.tex";
            process.Start();
            //process.Dispose();
        }
示例#3
0
        // typeCode = 0 - generate invoice
        // typeCode = 1 - generate invoice duplicate eith current date
        public string generate(int typeCode)
        {
            string    path = "templates/invoice.xml";
            XDocument doc  = XDocument.Load(path);
            XElement  root = doc.Element("Template");

            string dateTimeFormat = "yyyy-MM-dd";

            string header = root.Element("Header").Value;

            header = string.Format(header, Company.Name, Company.FullAddress, Company.Phone, Company.Email, Company.Website, Company.BankName, Company.BankAccountNumber);

            string title       = root.Element("Title").Value;
            string dateOfIssue = DateOfIssue.ToString(dateTimeFormat);

            if (typeCode == 1)
            {
                string duplicateTitle = " - DUPLIKAT";
                Number      = Number + duplicateTitle;
                dateOfIssue = DateTime.Now.ToString(dateTimeFormat);
            }

            title = string.Format(title, Number);

            string cityOfIssue    = root.Element("DatePlace").Value;
            string dateOfDelivery = DateOfDelivery.ToString(dateTimeFormat);

            cityOfIssue = string.Format(cityOfIssue, dateOfIssue, Company.InvoiceIssueCity, dateOfDelivery);



            string sellerBuyer = root.Element("SellerBuyer").Value;

            sellerBuyer = string.Format(sellerBuyer, Company.FullName, Company.FullAddress, Company.NIP, Contractor.FullName, Contractor.FullAddress, Contractor.NIP);

            header += cityOfIssue += title += sellerBuyer;

            string invoiceItemsTable   = root.Element("InvoiceItemsTableHeader").Value;
            string invoiceItemsSummary = root.Element("InvoiceItemTableSummary").Value;
            string invoiceItem         = root.Element("InvoiceItem").Value;

            int i = 1;

            foreach (InvoiceItem item in InvoiceItems)
            {
                string newItem = string.Format(invoiceItem, i, item.Name, item.UnitOfMeasureShortName, item.Quantity, item.Price.ToString("0.00"), item.TotalPrice.ToString("0.00"), item.VATValue.ToString("0.00"), item.TotalVATValue.ToString("0.00"), item.TotalPriceBrutto.ToString("0.00"));
                invoiceItemsTable += newItem;
                i++;
            }
            invoiceItemsSummary = string.Format(invoiceItemsSummary, TotalValue.ToString("0.00"), TotalVATValue.ToString("0.00"), TotalValueInclVat.ToString("0.00"));
            invoiceItemsTable  += invoiceItemsSummary;

            string taxTableHeader = root.Element("TaxTableHeader").Value;
            string tax            = root.Element("Tax").Value;

            tax = string.Format(tax, "23", TotalValue.ToString("0.00"), TotalVATValue.ToString("0.00"), TotalValueInclVat.ToString("0.00"));
            string taxTableSummary = root.Element("TaxTableSummary").Value;

            taxTableSummary = string.Format(taxTableSummary, TotalValue.ToString("0.00"), TotalVATValue.ToString("0.00"), TotalValueInclVat.ToString("0.00"));
            string taxTable = taxTableHeader + tax + taxTableSummary;

            string priceSummary = root.Element("PriceSummary").Value;

            priceSummary = string.Format(priceSummary, TotalValueInclVat.ToString("0.00"), getValueInWords(TotalValueInclVat));
            string paymentMethod = root.Element("PaymentMethod").Value;

            paymentMethod = string.Format(paymentMethod, PaymentMethod.Name, DateOfIssue.AddDays(PaymentMethod.DueTerm).ToString(dateTimeFormat));
            string issuer = root.Element("Issuer").Value;

            issuer = string.Format(issuer, Company.InvoiceIssuerName);
            string footer = paymentMethod + issuer;


            //string output = header + invoiceItemsTable + priceSummary + footer;
            string output = header + invoiceItemsTable + taxTable + priceSummary + footer;

            output = output.Replace("~^~^", "{{");
            output = output.Replace("^~^~", "}}");
            output = output.Replace("~^", "{");
            output = output.Replace("^~", "}");


            string time = DateTime.Now.ToFileTime().ToString();

            string outputFile = Tools.getHash(sellerBuyer + time);

            File.WriteAllText("tmp/" + outputFile + ".tex", output);

            Process process = new Process();

            process.StartInfo.WorkingDirectory = "tmp";
            process.StartInfo.FileName         = "pdflatex";
            process.StartInfo.Arguments        = outputFile + ".tex";
            process.Start();

            // wait to avoid FileNotFoundException
            //Task.Delay(5000);
            process.Dispose();
            return(outputFile + ".pdf");
        }