From 4893c8ffae5b8089a56ac9deef7b2e607530893b Mon Sep 17 00:00:00 2001 From: Pichu Date: Sat, 2 Mar 2024 17:17:59 +0800 Subject: [PATCH] Update MigFile to C0401Invoice --- mig/invoice_main.go | 20 ++++++++++++++++++++ mig/main.go | 8 ++++---- mig/main_test.go | 40 +++++++++++++++++++++------------------- 3 files changed, 45 insertions(+), 23 deletions(-) diff --git a/mig/invoice_main.go b/mig/invoice_main.go index 050480d..35c32f3 100644 --- a/mig/invoice_main.go +++ b/mig/invoice_main.go @@ -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) 為必填") @@ -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 +} diff --git a/mig/main.go b/mig/main.go index edbf8b2..6dcf1df 100644 --- a/mig/main.go +++ b/mig/main.go @@ -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) diff --git a/mig/main_test.go b/mig/main_test.go index 68bc724..62477b4 100644 --- a/mig/main_test.go +++ b/mig/main_test.go @@ -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",