Skip to content

Commit

Permalink
Merge pull request #3 from postprime/add_invoice_number
Browse files Browse the repository at this point in the history
Add invoice registration number to invoice
  • Loading branch information
chunvv authored Jun 23, 2023
2 parents 039ec85 + c6078ec commit b2d06db
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 25 deletions.
3 changes: 2 additions & 1 deletion build.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ package invoice_generator

import (
"fmt"
"github.com/jung-kurt/gofpdf"
"io"
"net/http"
"os"
"time"

"github.com/jung-kurt/gofpdf"
)

func (d *Document) Build() (*gofpdf.Fpdf, error) {
Expand Down
19 changes: 14 additions & 5 deletions contact.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,18 @@ package invoice_generator
import (
"bytes"
b64 "encoding/base64"
"github.com/jung-kurt/gofpdf"
"fmt"
"image"

"github.com/jung-kurt/gofpdf"
)

type Contact struct {
Name string `json:"name,omitempty" validate:"required,min=1,max=256"`
Logo *[]byte `json:"logo,omitempty"`
Address *Address `json:"address,omitempty"`
Email string `json:"email,omitempty"`
Name string `json:"name,omitempty" validate:"required,min=1,max=256"`
Logo *[]byte `json:"logo,omitempty"`
Address *Address `json:"address,omitempty"`
Email string `json:"email,omitempty"`
InvoiceRegistrationNumber string `json:"invoice_registration_number,omitempty"`
}

func (c *Contact) appendContactTODoc(x float64, y float64, fill bool, logoAlign string, pdf *gofpdf.Fpdf) float64 {
Expand Down Expand Up @@ -54,6 +57,12 @@ func (c *Contact) appendContactTODoc(x float64, y float64, fill bool, logoAlign
pdf.Cell(40, 8, c.Name)
pdf.SetFont("deja", "", 10)

if c.InvoiceRegistrationNumber != "" {
pdf.SetXY(x, pdf.GetY()+8)
invoiceNumberString := fmt.Sprintf("%s: %s", "登録番号", c.InvoiceRegistrationNumber)
pdf.Cell(40, 5, invoiceNumberString)
}

if c.Address != nil {
var addrRectHeight float64 = 17

Expand Down
37 changes: 19 additions & 18 deletions document.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,23 @@ import "github.com/jung-kurt/gofpdf"
type Document struct {
pdf *gofpdf.Fpdf

Options *Options `json:"options,omitempty"`
Header *HeaderFooter `json:"header,omitempty"`
Footer *HeaderFooter `json:"footer,omitempty"`
Type string `json:"type,omitempty" validate:"required,oneof=INVOICE RECEIPT"`
Number string `json:"version,omitempty" validate:"max=32"`
Description string `json:"description,omitempty" validate:"max=1024"`
Notes string `json:"notes,omitempty"`
Company *Contact `json:"company,omitempty" validate:"required"`
Customer *Contact `json:"customer,omitempty" validate:"required"`
Items []*Item `json:"items,omitempty"`
Date string `json:"date,omitempty"`
ValidityDate string `json:"validity_date,omitempty"`
PaymentTerm string `json:"payment_term,omitempty"`
AfterCommission *AfterCommission `json:"after_commission,omitempty"`
ConsumptionTax *ConsumptionTax `json:"consumption_tax,omitempty"`
WithholdingTax *WithholdingTax `json:"withholding_tax,omitempty"`
PaymentFree *PaymentFree `json:"payment_free,omitempty"`
PaidAmount *PaidAmount `json:"paid_amount,omitempty"`
Options *Options `json:"options,omitempty"`
Header *HeaderFooter `json:"header,omitempty"`
Footer *HeaderFooter `json:"footer,omitempty"`
Type string `json:"type,omitempty" validate:"required,oneof=INVOICE RECEIPT"`
Number string `json:"version,omitempty" validate:"max=32"`
Description string `json:"description,omitempty" validate:"max=1024"`
Notes string `json:"notes,omitempty"`
Company *Contact `json:"company,omitempty" validate:"required"`
Customer *Contact `json:"customer,omitempty" validate:"required"`
Items []*Item `json:"items,omitempty"`
Date string `json:"date,omitempty"`
ValidityDate string `json:"validity_date,omitempty"`
PaymentTerm string `json:"payment_term,omitempty"`
AfterCommission *AfterCommission `json:"after_commission,omitempty"`
ConsumptionTax *ConsumptionTax `json:"consumption_tax,omitempty"`
WithholdingTax *WithholdingTax `json:"withholding_tax,omitempty"`
PaymentFree *PaymentFree `json:"payment_free,omitempty"`
PaidAmount *PaidAmount `json:"paid_amount,omitempty"`
InvoiceRegistrationNumber *string `json:"invoice_registration_number,omitempty"`
}
15 changes: 14 additions & 1 deletion generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,20 @@ func TestNew(t *testing.T) {
Address: &Address{Country: " ", City: " ", Address: " ", Address2: " ", PostalCode: " "},
})

doc.SetCustomer(&Contact{Name: "安部 慎之介 様"})
doc.SetCustomer(
&Contact{
Name: "安部 慎之介 様",
Address: &Address{
Address: "港区芝浦3-8-1",
Address2: "ホゲホゲビル 3F",
PostalCode: "1080023",
City: "東京都",
Country: "日本",
},
Email: "[email protected]",
InvoiceRegistrationNumber: "T1234567891234",
},
)

//doc.AppendItem(&Item{Name: "対象期間のDKTの売上", Total: 900000, Tax: &Tax{Amount: 90000}})

Expand Down
Binary file modified payment_details_example.pdf
Binary file not shown.

0 comments on commit b2d06db

Please sign in to comment.