| | |
| | | // Invoice 销售发票 |
| | | Invoice struct { |
| | | Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` |
| | | Number string `json:"number" gorm:"column:number;type:varchar(255);comment:发票编号"` |
| | | ClientId int `gorm:"client_id" json:"clientId"` // 客户id |
| | | Client Client `gorm:"foreignKey:ClientId"` |
| | | InvoiceTypeId int `gorm:"invoice_type_id" json:"invoiceTypeId"` // 发票类型id |
| | |
| | | CourierCompanyId int `gorm:"courier_company_id" json:"courierCompanyId"` // 物流公司 |
| | | CourierCompany CourierCompany `gorm:"foreignKey:CourierCompanyId"` |
| | | Products []*Product `json:"products" gorm:"many2many:invoice_product;"` |
| | | CodeStandID string `json:"codeStandID" gorm:"column:code_stand_id;type:varchar(255);comment:编码id"` |
| | | } |
| | | |
| | | // InvoiceSearch 销售发票搜索条件 |
| | |
| | | if slf.SourceId > 0 { |
| | | db = db.Where("source_id = ?", slf.SourceId) |
| | | } |
| | | if slf.Number != "" { |
| | | db.Where("number = ?", slf.Number) |
| | | } |
| | | |
| | | return db |
| | | } |
| | |
| | | return record, err |
| | | } |
| | | |
| | | func (slf *InvoiceSearch) Count() (int64, error) { |
| | | var db = slf.build() |
| | | var total int64 |
| | | err := db.Count(&total).Error |
| | | return total, err |
| | | } |
| | | |
| | | func (slf *InvoiceSearch) MaxAutoIncr() (int, error) { |
| | | type Result struct { |
| | | Max int |
| | | } |
| | | |
| | | var ( |
| | | result Result |
| | | db = slf.build() |
| | | ) |
| | | |
| | | err := db.Select("MAX(id) as max").Scan(&result).Error |
| | | if err != nil { |
| | | return result.Max, fmt.Errorf("max err: %v", err) |
| | | } |
| | | return result.Max, nil |
| | | } |
| | | |
| | | func (slf *InvoiceSearch) SetNumber(number string) *InvoiceSearch { |
| | | slf.Number = number |
| | | return slf |
| | | } |
| | | |
| | | func (slf *InvoiceSearch) SetId(id int) *InvoiceSearch { |
| | | slf.Id = id |
| | | return slf |