v1.0.0
This commit is contained in:
105
internal/domains/finance/value_objects/invoice_info.go
Normal file
105
internal/domains/finance/value_objects/invoice_info.go
Normal file
@@ -0,0 +1,105 @@
|
||||
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
|
||||
}
|
||||
36
internal/domains/finance/value_objects/invoice_type.go
Normal file
36
internal/domains/finance/value_objects/invoice_type.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package value_objects
|
||||
|
||||
// InvoiceType 发票类型枚举
|
||||
type InvoiceType string
|
||||
|
||||
const (
|
||||
InvoiceTypeGeneral InvoiceType = "general" // 增值税普通发票 (普票)
|
||||
InvoiceTypeSpecial InvoiceType = "special" // 增值税专用发票 (专票)
|
||||
)
|
||||
|
||||
// String 返回发票类型的字符串表示
|
||||
func (it InvoiceType) String() string {
|
||||
return string(it)
|
||||
}
|
||||
|
||||
// IsValid 验证发票类型是否有效
|
||||
func (it InvoiceType) IsValid() bool {
|
||||
switch it {
|
||||
case InvoiceTypeGeneral, InvoiceTypeSpecial:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// GetDisplayName 获取发票类型的显示名称
|
||||
func (it InvoiceType) GetDisplayName() string {
|
||||
switch it {
|
||||
case InvoiceTypeGeneral:
|
||||
return "增值税普通发票 (普票)"
|
||||
case InvoiceTypeSpecial:
|
||||
return "增值税专用发票 (专票)"
|
||||
default:
|
||||
return "未知类型"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user