From b1d6bb79aba9f98e581dec77dab4bb5584fa32f6 Mon Sep 17 00:00:00 2001 From: sp Date: Fri, 7 Aug 2020 20:13:39 +0530 Subject: [PATCH] bank fix --- bank.go | 71 +++++++++++++++++++++++++++++++++++++++++++---------- document.go | 2 ++ item.go | 11 --------- 3 files changed, 60 insertions(+), 24 deletions(-) diff --git a/bank.go b/bank.go index 5c0e177..b5a2a67 100644 --- a/bank.go +++ b/bank.go @@ -3,22 +3,67 @@ package generator import "github.com/jung-kurt/gofpdf" type Bank struct { - PayBy string // Tax in percent ex 17 - BankName string // Tax in amount ex 123.40 - Address string - AccountType string - IFSC string - IBAN string - SWIFT string - pdf *gofpdf.Fpdf + PayBy string // Tax in percent ex 17 + BankName string // Tax in amount ex 123.40 + Address string + AccountType string + IFSC string + SWIFT string + AccountNumber string + pdf *gofpdf.Fpdf } func (b *Bank) appendBankTODoc(x float64, y float64, fill bool, pdf *gofpdf.Fpdf) { - pdf.SetXY(x, y) b.pdf = pdf - pdf.Ln(20) - pdf.SetFont("Helvetica", "B", 10) - pdf.Cell(40, 0, "Payment Details") - pdf.SetFont("Helvetica", "", 10) + b.pdf.Ln(20) + b.pdf.SetFont("Helvetica", "B", 10) + b.text(40, 0, "Payment Details") b.pdf.Ln(5) + b.pdf.SetFont("Helvetica", "", 10) + headers := []string{ + "Pay By", "Bank Name", "Address", "Account Type (current/savings)", + "A/c No.", "IFSC", "SWIFT (international)", + } + + b.pdf.SetDrawColor(64, 64, 64) + for i := 0; i < len(headers); i++ { + b.pdf.SetFont("Helvetica", "B", 10) + b.textFormat(60, 5, headers[i], "1", 0, "R", true, 0, "") + b.pdf.SetFont("Helvetica", "", 10) + switch i { + case 0: + b.textFormat(100, 5, b.PayBy, "1", 0, "L", false, 0, "") + break + case 1: + b.textFormat(100, 5, b.BankName, "1", 0, "L", false, 0, "") + break + case 2: + b.textFormat(100, 5, b.Address, "1", 0, "L", false, 0, "") + break + case 3: + b.textFormat(100, 5, b.AccountType, "1", 0, "L", false, 0, "") + break + case 4: + b.textFormat(100, 5, b.AccountNumber, "1", 0, "L", false, 0, "") + break + case 5: + b.textFormat(100, 5, b.IFSC, "1", 0, "L", false, 0, "") + break + case 6: + b.textFormat(100, 5, b.SWIFT, "1", 0, "L", false, 0, "") + break + } + b.pdf.Ln(5) + } +} + +func (b *Bank) text(x, y float64, txtStr string) { + unicodeToPDF := b.pdf.UnicodeTranslatorFromDescriptor("") + b.pdf.Cell(x, y, unicodeToPDF(txtStr)) +} + +func (b *Bank) textFormat(w, h float64, txtStr string, borderStr string, ln int, + alignStr string, fill bool, link int, linkStr string) { + unicodeToPDF := b.pdf.UnicodeTranslatorFromDescriptor("") + b.pdf.CellFormat(w, h, unicodeToPDF(txtStr), borderStr, ln, alignStr, fill, link, linkStr) } diff --git a/document.go b/document.go index 49e5952..6286bca 100644 --- a/document.go +++ b/document.go @@ -99,6 +99,8 @@ func (d *Document) Build() (*gofpdf.Fpdf, error) { // Append payment term d.appendPaymentTerm(pdf) + d.appendBank(pdf) + // Append js to autoprint if AutoPrint == true if d.Options.AutoPrint { pdf.SetJavascript("print(true);") diff --git a/item.go b/item.go index 8a9a24b..856506f 100644 --- a/item.go +++ b/item.go @@ -52,17 +52,6 @@ func (i *Item) appendColTo(options *Options, pdf *gofpdf.Fpdf) { pdf.SetX(155) pdf.CellFormat(20, 6, taxString, "0", 0, "", false, 0, "") - discountType, discountAmount := i.Discount.getDiscount() - var discountString string - if discountType == "percent" { - discountString = fmt.Sprintf("%s %s", discountAmount, encodeString("%")) - } else { - discountString = fmt.Sprintf("%s %s", discountAmount, encodeString("€")) - } - - pdf.SetX(155) - pdf.CellFormat(20, 6, discountString, "0", 0, "", false, 0, "") - // TOTAL TTC pdf.SetX(175) pdf.CellFormat(25, 6, ac.FormatMoneyDecimal(i.totalTTC()), "0", 0, "", false, 0, "")