internal static string CreateInvoice(long userId, string status, string transid, string paymentmethod, ProductInfo productInfo, ProductPriceInfo ppi) { string companyName = string.Empty; string userPath = String.Empty; string password = HttpContext.Current.Session["access"] as string; UserInfo userInfo = null; ClientInfo clientInfo = null; using (Database db = new MySqlDatabase()) { userPath = db.GetUserDocumentPath(userId, password); userPath = userPath.Replace("\\", "/"); if (!Directory.Exists(userPath)) Directory.CreateDirectory(userPath); userInfo = db.GetUser(userId, password); clientInfo = db.GetClientInfo(userId); companyName = clientInfo.CompanyName; } // complete userPath with document name string filename = String.Format("INV{0}.pdf", transid); userPath = Path.Combine(userPath, filename); // Get the invoice template from the proper location string templatePath = Resource.InvoiceTemplate; string invoiceTemplate = HttpContext.Current.Server.MapPath(templatePath); try { InvoiceForm form = new InvoiceForm(invoiceTemplate); string culture = "nl-NL"; if (HttpContext.Current.Session["culture"] != null) culture = HttpContext.Current.Session["culture"] as string; CultureInfo cultureInfo = new CultureInfo(culture); List<string> fields = new List<string>(); fields.Add(clientInfo.GetFullName()); fields.Add(clientInfo.AddressLine1); if (!string.IsNullOrEmpty(clientInfo.AddressLine2)) fields.Add(clientInfo.AddressLine2); string tmpResidence = clientInfo.ZipCode + " " + clientInfo.City.ToUpper(); if (!string.IsNullOrEmpty(tmpResidence)) fields.Add(tmpResidence); if (!string.IsNullOrEmpty(clientInfo.Country)) fields.Add(clientInfo.Country); while (fields.Count < 5) fields.Add(" "); form.ClientAddress = fields.ToArray(); form.InvoiceDate = DateTime.Now.ToString("d", cultureInfo); form.InvoiceNumber = transid; using (Database db = new MySqlDatabase()) { Transaction transaction = db.GetTransaction(Util.UserId, transid); foreach (TransactionLine tl in transaction.TransactionLines) { form.InvoiceLines.Add(new PdfInvoiceLine() { Description = tl.Description, Quantity = tl.Quantity, UnitPrice = tl.Price, VatRate = tl.VatPercentage }); } } form.GenerateInvoice(userPath, companyName); } catch (Exception ex) { Logger.Instance.Write(LogLevel.Error, ex, "[CreateInvoice]"); } SendInvoice(userId, userPath); return userPath; }