| | |
| | | type ( |
| | | // ServiceCollectionPlan 收款计划 |
| | | ServiceCollectionPlan struct { |
| | | Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` |
| | | CollectionType int `gorm:"collection_type" json:"collectionType"` // 类型(1 计划收款日期 2 项目状态) |
| | | SourceType int `gorm:"source_type" json:"sourceType"` // 源单类型(1销售明细2服务合同3销售发票) |
| | | SourceId int `gorm:"source_id" json:"sourceId"` // 源单id |
| | | PrincipalId int `gorm:"principal_id" json:"principalId"` // 收款负责人ID |
| | | Term int `gorm:"term" json:"term"` // 期次 |
| | | Percent decimal.Decimal `gorm:"percent" json:"percent"` // 比例 |
| | | Amount decimal.Decimal `gorm:"amount" json:"amount"` // 金额 |
| | | MoneyType string `gorm:"money_type" json:"moneyType"` // 币种 |
| | | CollectionDate time.Time `gorm:"collection_date" json:"collectionDate"` // 计划收款日期 |
| | | Remark string `gorm:"remark" json:"remark"` // 备注 |
| | | Status constvar.CollectionStatus `gorm:"status" json:"status"` // 状态(1未收2已收) |
| | | FileId int `gorm:"file_id" json:"fileId"` // 附件id |
| | | Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` |
| | | CollectionType int `gorm:"collection_type" json:"collectionType"` // 类型(1 计划收款日期 2 项目状态) |
| | | SourceType constvar.CollectionSourceType `gorm:"source_type" json:"sourceType"` // 源单类型(1销售明细2服务合同3销售发票) |
| | | SourceId int `gorm:"source_id" json:"sourceId"` // 源单id |
| | | PrincipalId int `gorm:"principal_id" json:"principalId"` // 收款负责人ID |
| | | Term int `gorm:"term" json:"term"` // 期次 |
| | | Percent decimal.Decimal `gorm:"percent" json:"percent"` // 比例 |
| | | Amount decimal.Decimal `gorm:"amount" json:"amount"` // 金额 |
| | | MoneyType string `gorm:"money_type" json:"moneyType"` // 币种 |
| | | CollectionDate time.Time `gorm:"collection_date" json:"collectionDate"` // 计划收款日期 |
| | | Remark string `gorm:"remark" json:"remark"` // 备注 |
| | | Status constvar.CollectionStatus `gorm:"status" json:"status"` // 状态(1未收2部分已收3已收) |
| | | AmountReceivable decimal.Decimal `gorm:"column:amount_receivable;type:decimal(12,2);comment:应收金额" json:"amountReceivable"` // 应收金额 |
| | | AmountReceived decimal.Decimal `gorm:"column:amount_received;type:decimal(12,2);comment:已收金额" json:"amountReceived"` // 已收金额 |
| | | AmountTotal decimal.Decimal `gorm:"column:amount_total;type:decimal(12,2);comment:总额" json:"amountTotal"` // 总额 |
| | | FileId int `gorm:"file_id" json:"fileId"` // 附件id |
| | | } |
| | | |
| | | // ServiceCollectionPlanSearch 收款计划搜索条件 |
| | |
| | | return records, total, err |
| | | } |
| | | |
| | | func (slf *ServiceCollectionPlanSearch) UpdateByMap(upMap map[string]interface{}) error { |
| | | var ( |
| | | db = slf.build() |
| | | ) |
| | | |
| | | if err := db.Updates(upMap).Error; err != nil { |
| | | return fmt.Errorf("update by map err: %v, upMap: %+v", err, upMap) |
| | | } |
| | | |
| | | return nil |
| | | } |
| | | |
| | | func (slf *ServiceCollectionPlanSearch) UpdateStatusAndAmount(collection *ServiceCollectionPlan, receiveAmount decimal.Decimal) error { |
| | | receivedAmount := collection.AmountReceived.Add(receiveAmount) |
| | | var status constvar.CollectionStatus |
| | | if receiveAmount.GreaterThanOrEqual(collection.AmountTotal) { |
| | | status = constvar.CollectionStatusCollected |
| | | } else { |
| | | status = constvar.CollectionStatusSubCollected |
| | | } |
| | | receivableAmount := collection.AmountTotal.Add(receivedAmount) |
| | | err := slf.SetId(collection.Id).UpdateByMap(map[string]interface{}{ |
| | | "status": status, |
| | | "amount_received": receivedAmount, |
| | | "amount_receivable": receivableAmount}) |
| | | if err != nil { |
| | | return err |
| | | } |
| | | |
| | | return nil |
| | | } |
| | | |
| | | // InitDefaultData 初始化数据 |
| | | func (slf *ServiceCollectionPlanSearch) InitDefaultData() error { |
| | | var ( |