Skip to content

Commit

Permalink
Update MigFile to C0401Invoice
Browse files Browse the repository at this point in the history
  • Loading branch information
PichuChen committed Mar 2, 2024
1 parent 1ebb879 commit 4893c8f
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 23 deletions.
20 changes: 20 additions & 0 deletions mig/invoice_main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ type F0401InvoiceMain struct {
BondedAreaConfirm string `xml:"BondedAreaConfirm,omitempty"`
}

type C0401InvoiceMain struct {
InvoiceMain

CarrierType string `xml:"CarrierType,omitempty"`
CarrierId1 string `xml:"CarrierId1,omitempty"`
CarrierId2 string `xml:"CarrierId2,omitempty"`
PrintMark string `xml:"PrintMark"`
NPOBAN string `xml:"NPOBAN,omitempty"`
RandomNumber string `xml:"RandomNumber,omitempty"`
BondedAreaConfirm string `xml:"BondedAreaConfirm,omitempty"`
}

func (block *InvoiceMain) Validate() error {
if block.InvoiceNumber == "" {
return fmt.Errorf("發票號碼 (InvoiceNumber) 為必填")
Expand Down Expand Up @@ -191,3 +203,11 @@ func (block *F0401InvoiceMain) Validate() error {

return nil
}

func (block *C0401InvoiceMain) Validate() error {
err := block.InvoiceMain.Validate()
if err != nil {
return err
}
return nil
}
8 changes: 4 additions & 4 deletions mig/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ type RoleDescription struct {
RoleRemark string `xml:"RoleRemark,omitempty"`
}

type MigFile struct {
type C0401Invoice struct {
XMLName xml.Name `xml:"Invoice"`
Text string `xml:",chardata"`
Xmlns string `xml:"xmlns,attr"`

Main *InvoiceMain `xml:"Main"`
Main *C0401InvoiceMain `xml:"Main"`
Details *InvoiceDetail `xml:"Details"`
Amount *C0401InvoiceAmount `xml:"Amount"`
}

func NewMigFile(b []byte) (*MigFile, error) {
f := MigFile{}
func NewC0401Invoice(b []byte) (*C0401Invoice, error) {
f := C0401Invoice{}

if err := xml.Unmarshal(b, &f); err != nil {
log.Fatal(err)
Expand Down
40 changes: 21 additions & 19 deletions mig/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,28 @@ import (
func TestMarshalC0401(t *testing.T) {
tc, _ := ioutil.ReadFile("testcases/C0401/01.xml")

actual, _ := NewMigFile(tc)

expected := MigFile{
Main: &InvoiceMain{
InvoiceNumber: "AA00000000",
InvoiceDate: "20060102",
InvoiceTime: "15:04:05",
Seller: &RoleDescription{
Identifier: "54834795",
Name: "台灣智慧家庭股份有限公司",
Address: "Address",
PersonInCharge: "PersonInCharge",
EmailAddress: "example@example.com",
},
Buyer: &RoleDescription{
Identifier: "0000000000",
Name: "Buyer Name",
actual, _ := NewC0401Invoice(tc)

expected := C0401Invoice{
Main: &C0401InvoiceMain{
InvoiceMain: InvoiceMain{
InvoiceNumber: "AA00000000",
InvoiceDate: "20060102",
InvoiceTime: "15:04:05",
Seller: &RoleDescription{
Identifier: "54834795",
Name: "台灣智慧家庭股份有限公司",
Address: "Address",
PersonInCharge: "PersonInCharge",
EmailAddress: "example@example.com",
},
Buyer: &RoleDescription{
Identifier: "0000000000",
Name: "Buyer Name",
},
InvoiceType: "07",
DonateMark: "0",
},
InvoiceType: "07",
DonateMark: "0",
CarrierType: "EJ1507",
CarrierId1: "CarrierId1",
CarrierId2: "CarrierId2",
Expand Down

0 comments on commit 4893c8f

Please sign in to comment.