You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

101 lines
4.9 KiB
Go

package model
import (
"errors"
"github.com/fonchain_enterprise/fonchain-approval/api/approval"
m2 "github.com/fonchain_enterprise/fonchain-approval/pkg/m"
"github.com/jinzhu/copier"
"gorm.io/plugin/soft_delete"
"time"
)
type FinancialFrom struct {
ID uint64 `gorm:"primaryKey;column:id" json:"id"` // ID
DeletedAt soft_delete.DeletedAt `gorm:"column:deleted_at" json:"deletedAt"` // 删除时间
CreatedAt time.Time `gorm:"column:created_at" json:"createdAt"` // 创建时间
UpdatedAt time.Time `gorm:"column:updated_at" json:"updatedAt"`
ApprovalID uint64 `gorm:"primaryKey;column:approval_id" json:"approvalId"` // 关联申请的ID
PaymentCompany string `json:"paymentCompany" gorm:"column:payment_company;type:varchar(2048);comment:付款公司别"`
TransactionDepartment string `json:"transactionDepartment" gorm:"column:transaction_department;type:varchar(255);comment:经办部门"`
Payee string `json:"payee" gorm:"column:payee;type:varchar(2048);comment:收款人全称"`
BeneficiaryBank string `json:"beneficiaryBank" gorm:"column:beneficiary_bank;type:varchar(1024);comment:收款人开户行"`
BankNo string `json:"bankNo" gorm:"column:bank_no;type:varchar(1024);comment:收款人账号"`
CostInfo []*CostInfo `json:"costInfo" gorm:"column:cost_info;type:json;comment:费用说明"`
PaymentMethod string `json:"paymentMethod" gorm:"column:payment_method;type:varchar(255);comment:付款方式"`
InvoiceInfo []*InvoiceInfo `json:"invoiceInfo" gorm:"column:invoice_info;type:json;comment:发票信息"`
}
type CostInfo struct {
Description string `json:"description" gorm:"column:description;type:text;comment:说明"`
UnitPrice string `json:"unitPrice" gorm:"column:unit_price;type:varchar(255);comment:费用单价"`
CostUnit string `json:"costUnit" gorm:"column:cost_unit;type:varchar(255);comment:费用单位"`
CostNum int64 `json:"costNum" gorm:"column:cost_num;type:int;comment:费用数量"`
TotalPrice string `json:"totalPrice" gorm:"column:total_price;type:varchar(255);comment:费用总额"`
UsedDepartment string `json:"usedDepartment" gorm:"column:used_department;type:varchar(2048);comment:使用部门"`
}
type InvoiceInfo struct {
InvoiceDate string `json:"invoiceDate" gorm:"column:invoice_date;type:varchar(255);comment:发票日期"`
InvoiceNo string `json:"invoiceNo" gorm:"column:invoice_no;type:varchar(255);comment:发票号码"`
InvoiceProvider string `json:"invoiceProvider" gorm:"column:invoice_provider;type:varchar(1024);comment:发票提供者"`
Amount string `json:"amount" gorm:"column:amount;type:varchar(255);comment:发票或付款金额"`
UseTo string `json:"useTo" gorm:"column:use_to;type:varchar(1024);comment:用途"`
Applicant string `json:"applicant" gorm:"column:applicant;varchar(255);comment:申请人"`
PaymentMethod string `json:"paymentMethod" gorm:"column:payment_method;type:varchar(255);comment:付款方式"`
PaymentObj string `json:"paymentObj" gorm:"column:payment_obj;type:varchar(255);comment:付款或报销对象"`
InvoiceType string `json:"invoiceType" gorm:"column:invoice_type;type:varchar(255);comment:发票类型"`
Notes string `json:"notes" gorm:"column:notes;type:text;comment:备注"`
}
// TableName get sql table name.获取数据库表名
func (m *FinancialFrom) TableName() string {
return "financial_from"
}
func (m *FinancialFrom) GetApproval(id uint64) (*Approval, error) {
var entity *Approval
if err := DB.
Preload("ApprovalWorkFlows").
Preload("ApprovalType").
Preload("FinancialFrom").
First(&entity, id).Error; err != nil {
return entity, err
}
return entity, nil
}
func (m *FinancialFrom) SaveApprovalContent(in *approval.CreateRequest, a *Approval) error {
copier.CopyWithOption(&m, in.FinancialFrom, copier.Option{DeepCopy: true})
m.ApprovalID = a.ID
return DB.Create(&m).Error
}
func (m *FinancialFrom) UpdateApprovalContent(in *approval.CreateRequest, a *Approval) error {
var entity *FinancialFrom
if err := DB.Where(&FinancialFrom{ApprovalID: a.ID}).First(&entity).Error; err != nil {
return errors.New(m2.ErrorNotFound)
}
copier.CopyWithOption(&m, in.FinancialFrom, copier.Option{DeepCopy: true})
m.ID = entity.ID
return DB.Model(&m).Updates(m).Error
}
func (m *FinancialFrom) BuildResContent(a *Approval, request *approval.CreateRequest) {
if a.FinancialFrom != nil {
copier.CopyWithOption(&request.FinancialFrom, a.FinancialFrom, copier.Option{DeepCopy: true})
}
}
func (m *FinancialFrom) DeleteApproval(p *Approval) error {
return DB.Where(&FinancialFrom{ApprovalID: p.ID}).Delete(&FinancialFrom{}).Error
}