Skip to content

Commit

Permalink
bank fix
Browse files Browse the repository at this point in the history
  • Loading branch information
sp committed Aug 7, 2020
1 parent 06eb9d4 commit b1d6bb7
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 24 deletions.
71 changes: 58 additions & 13 deletions bank.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
2 changes: 2 additions & 0 deletions document.go
Original file line number Diff line number Diff line change
Expand Up @@ -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);")
Expand Down
11 changes: 0 additions & 11 deletions item.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, "")
Expand Down

0 comments on commit b1d6bb7

Please sign in to comment.