105 lines
		
	
	
		
			3.1 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
		
		
			
		
	
	
			105 lines
		
	
	
		
			3.1 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
|  | package value_objects | ||
|  | 
 | ||
|  | import ( | ||
|  | 	"errors" | ||
|  | 	"strings" | ||
|  | ) | ||
|  | 
 | ||
|  | // InvoiceInfo 发票信息值对象 | ||
|  | type InvoiceInfo struct { | ||
|  | 	CompanyName    string `json:"company_name"`    // 公司名称 | ||
|  | 	TaxpayerID     string `json:"taxpayer_id"`     // 纳税人识别号 | ||
|  | 	BankName       string `json:"bank_name"`       // 基本开户银行 | ||
|  | 	BankAccount    string `json:"bank_account"`    // 基本开户账号 | ||
|  | 	CompanyAddress string `json:"company_address"` // 企业注册地址 | ||
|  | 	CompanyPhone   string `json:"company_phone"`   // 企业注册电话 | ||
|  | 	ReceivingEmail string `json:"receiving_email"` // 发票接收邮箱 | ||
|  | } | ||
|  | 
 | ||
|  | // NewInvoiceInfo 创建发票信息值对象 | ||
|  | func NewInvoiceInfo(companyName, taxpayerID, bankName, bankAccount, companyAddress, companyPhone, receivingEmail string) *InvoiceInfo { | ||
|  | 	return &InvoiceInfo{ | ||
|  | 		CompanyName:    strings.TrimSpace(companyName), | ||
|  | 		TaxpayerID:     strings.TrimSpace(taxpayerID), | ||
|  | 		BankName:       strings.TrimSpace(bankName), | ||
|  | 		BankAccount:    strings.TrimSpace(bankAccount), | ||
|  | 		CompanyAddress: strings.TrimSpace(companyAddress), | ||
|  | 		CompanyPhone:   strings.TrimSpace(companyPhone), | ||
|  | 		ReceivingEmail: strings.TrimSpace(receivingEmail), | ||
|  | 	} | ||
|  | } | ||
|  | 
 | ||
|  | // ValidateForGeneralInvoice 验证普票信息 | ||
|  | func (ii *InvoiceInfo) ValidateForGeneralInvoice() error { | ||
|  | 	if ii.CompanyName == "" { | ||
|  | 		return errors.New("公司名称不能为空") | ||
|  | 	} | ||
|  | 	if ii.TaxpayerID == "" { | ||
|  | 		return errors.New("纳税人识别号不能为空") | ||
|  | 	} | ||
|  | 	if ii.ReceivingEmail == "" { | ||
|  | 		return errors.New("发票接收邮箱不能为空") | ||
|  | 	} | ||
|  | 	return nil | ||
|  | } | ||
|  | 
 | ||
|  | // ValidateForSpecialInvoice 验证专票信息 | ||
|  | func (ii *InvoiceInfo) ValidateForSpecialInvoice() error { | ||
|  | 	// 先验证普票必填项 | ||
|  | 	if err := ii.ValidateForGeneralInvoice(); err != nil { | ||
|  | 		return err | ||
|  | 	} | ||
|  | 	 | ||
|  | 	// 专票额外必填项 | ||
|  | 	if ii.BankName == "" { | ||
|  | 		return errors.New("基本开户银行不能为空") | ||
|  | 	} | ||
|  | 	if ii.BankAccount == "" { | ||
|  | 		return errors.New("基本开户账号不能为空") | ||
|  | 	} | ||
|  | 	if ii.CompanyAddress == "" { | ||
|  | 		return errors.New("企业注册地址不能为空") | ||
|  | 	} | ||
|  | 	if ii.CompanyPhone == "" { | ||
|  | 		return errors.New("企业注册电话不能为空") | ||
|  | 	} | ||
|  | 	return nil | ||
|  | } | ||
|  | 
 | ||
|  | // IsComplete 检查信息是否完整(专票要求) | ||
|  | func (ii *InvoiceInfo) IsComplete() bool { | ||
|  | 	return ii.CompanyName != "" && | ||
|  | 		ii.TaxpayerID != "" && | ||
|  | 		ii.BankName != "" && | ||
|  | 		ii.BankAccount != "" && | ||
|  | 		ii.CompanyAddress != "" && | ||
|  | 		ii.CompanyPhone != "" && | ||
|  | 		ii.ReceivingEmail != "" | ||
|  | } | ||
|  | 
 | ||
|  | // GetMissingFields 获取缺失的字段(专票要求) | ||
|  | func (ii *InvoiceInfo) GetMissingFields() []string { | ||
|  | 	var missing []string | ||
|  | 	if ii.CompanyName == "" { | ||
|  | 		missing = append(missing, "公司名称") | ||
|  | 	} | ||
|  | 	if ii.TaxpayerID == "" { | ||
|  | 		missing = append(missing, "纳税人识别号") | ||
|  | 	} | ||
|  | 	if ii.BankName == "" { | ||
|  | 		missing = append(missing, "基本开户银行") | ||
|  | 	} | ||
|  | 	if ii.BankAccount == "" { | ||
|  | 		missing = append(missing, "基本开户账号") | ||
|  | 	} | ||
|  | 	if ii.CompanyAddress == "" { | ||
|  | 		missing = append(missing, "企业注册地址") | ||
|  | 	} | ||
|  | 	if ii.CompanyPhone == "" { | ||
|  | 		missing = append(missing, "企业注册电话") | ||
|  | 	} | ||
|  | 	if ii.ReceivingEmail == "" { | ||
|  | 		missing = append(missing, "发票接收邮箱") | ||
|  | 	} | ||
|  | 	return missing | ||
|  | }  |