/// <summary> /// Creates invoice from specified data. /// </summary> /// <returns>Returns Invoice</returns> public Invoice CreateInvoice() { if (!ValidateData()) { MessageBoxLocalizer.ShowDialog( Properties.Resources.MESSAGE_INVOICE_FILL_ALL_DATA, Properties.Resources.MESSAGE_TITLE_FILL_DATA, MessageBoxButton.OK, MessageBoxImage.Exclamation ); return null; } Invoice invoice = new Invoice(); invoice.Purchaser = new CompanySettings(); invoice.Purchaser.CompanyName = this.tbx_CompanyName.Text; invoice.Purchaser.CompanyHouseNumber = this.tbx_HouseNumber.Text; invoice.Purchaser.CompanyStreet = this.tbx_Street.Text; invoice.Purchaser.CompanyCity = this.tbx_City.Text; invoice.Purchaser.CompanyPostCode = this.tbx_PostCode.Text; invoice.Purchaser.CompanyCountry = this.tbx_Country.Text; invoice.Purchaser.CompanyIco = this.tbx_ICO.Text; invoice.Purchaser.CompanyDic = this.tbx_DIC.Text; invoice.InvoiceNumber = this.tbx_InvoiceNumber.Text; invoice.InvoicePriceWithDph = this.tbx_InvoicePriceWith.Text; invoice.InvoicePriceWithoutDph = this.tbx_InvoicePriceWithout.Text; invoice.InvoiceReason = this.tbx_InvoiceReason.Text; invoice.DateIssue = this.date_Issue.SelectedDate.Value.ToShortDateString(); invoice.DateDue = this.date_Due.SelectedDate.Value.ToShortDateString(); return invoice; }
/// <summary> /// Create invoice based on parameters /// </summary> /// <param name="invoice">Invoice to print</param> /// <param name="save">True to save invoice, false to not</param> public void CreateInvoiceOverView(Invoice invoice, bool save = true) { // Create PDF page PdfPage page = NewPage(); // Draw invoice try { // Get initial data int pageWidth = (int)page.Width.Value, pageHeight = (int)page.Height.Value, reserve = 20, footerHeight = 30; string invoiceNumber = invoice.InvoiceNumber; string invoiceReason = invoice.InvoiceReason; string invoicePriceWithDph = invoice.InvoicePriceWithDph; string invoicePriceWithoutDph = invoice.InvoicePriceWithoutDph; // Draw invoice number and remember its height int companyInfoStartY = DrawInvoiceHeader(page, invoiceNumber, pageWidth / 2 + reserve, 0, pageWidth / 2 - reserve); companyInfoStartY += reserve; // Draw Supplier Hashtable supplier = CreateSupplierHashTable(invoiceNumber); int supplierInfoEndY = DrawCompanyInfo(page, supplier, 0, companyInfoStartY, pageWidth / 2 - reserve); // Draw purchaser Hashtable purchaser = CreatePurchaserHashTable(invoice); int purchaserInfoEndY = DrawCompanyInfo(page, purchaser, pageWidth / 2 + reserve, companyInfoStartY, pageWidth / 2 - reserve); // Draw Invoice Price int invoiceEndY = DrawInvoicePrice(page, invoiceReason, invoicePriceWithDph, invoicePriceWithoutDph, 0, Math.Max(supplierInfoEndY, purchaserInfoEndY), pageWidth); // Draw footer DrawInvoiceFooter(page, this.karafaSettings.InvoiceFooter, 0, pageHeight - footerHeight, pageWidth, footerHeight); // Save invoice (and show it) SaveDocument(invoiceNumber, false); } catch (Exception ex) { Karafa.Errors.KarafaLogger.LogError(ex); // Report error only when this document should be shown if (save) KarafaMainWindow.Instance.ReportProcess( Properties.Resources.MESSAGE_ERROR_INVOICE_FAILED ); } }
/// <summary> /// Draw purchaser data /// </summary> /// <param name="invoice">Invoice with Purchaser definiton</param> /// <returns>Updated parameters</returns> private Hashtable CreatePurchaserHashTable(Invoice invoice) { Hashtable purchaser = new Hashtable(10); purchaser.Add(Properties.Resources.HTK_SUPPLIER, false); purchaser.Add(Properties.Resources.HTK_COMPANY_NAME, invoice.Purchaser.CompanyName); purchaser.Add( Properties.Resources.HTK_COMPANY_STREET, string.Format( "{0} {1}", invoice.Purchaser.CompanyStreet, invoice.Purchaser.CompanyHouseNumber ) ); purchaser.Add( Properties.Resources.HTK_COMPANY_CITY, string.Format( "{0} {1}", invoice.Purchaser.CompanyCity, invoice.Purchaser.CompanyPostCode ) ); purchaser.Add(Properties.Resources.HTK_COMPANY_COUNTRY, invoice.Purchaser.CompanyCountry); purchaser.Add( Properties.Resources.HTK_COMPANY_IC, string.Format("{0} {1}", Properties.Resources.LABEL_INVOICE_ICO, invoice.Purchaser.CompanyIco) ); purchaser.Add( Properties.Resources.HTK_COMPANY_DIC, (string.IsNullOrEmpty(invoice.Purchaser.CompanyDic) ? Properties.Resources.LABEL_NOT_DPH_PAYER : string.Format("{0} {1}", Properties.Resources.LABEL_INVOICE_DIC, invoice.Purchaser.CompanyDic)) ); purchaser.Add( Properties.Resources.HTK_INVOICE_DATE_ISSUE, string.Format( "{0} {1}", Properties.Resources.LABEL_INVOICE_DATE_ISSUE, invoice.DateIssue ) ); purchaser.Add( Properties.Resources.HTK_INVOICE_DATE_DUE, string.Format( "{0} {1}", Properties.Resources.LABEL_INVOICE_DATE_DUE, invoice.DateDue ) ); return purchaser; }