model/serviceContract.go | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
service/invoice.go | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
model/serviceContract.go
@@ -34,10 +34,10 @@ ServiceTimes int `json:"serviceTimes" gorm:"column:service_times;type:int;comment:服务次数"` Terms string `json:"terms" gorm:"column:terms;type:text;comment:条款"` Remark string `json:"remark" gorm:"column:remark;type:text;comment:备注"` AmountReceivable decimal.Decimal `gorm:"amount_receivable" json:"amountReceivable"` // 应收金额 AmountReceived decimal.Decimal `gorm:"amount_received" json:"amountReceived"` // 已收金额 AmountInvoiced decimal.Decimal `gorm:"amount_invoiced" json:"amountInvoiced"` // 已开票金额 AmountUnInvoiced decimal.Decimal `gorm:"-" json:"amountUnInvoiced"` // 未开票金额 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"` // 已收金额 AmountInvoiced decimal.Decimal `gorm:"column:amount_invoiced;type:decimal(12,2);comment:未开票金额" json:"amountInvoiced"` // 已开票金额 AmountUnInvoiced decimal.Decimal `gorm:"column:amount_not_invoiced;type:decimal(12,2);comment:未开票金额" json:"amountUnInvoiced"` // 未开票金额 Products []*Product `json:"products" gorm:"many2many:service_contract_product;"` gorm.Model `json:"-"` } service/invoice.go
@@ -22,22 +22,25 @@ if err != nil { return ecode.DBErr } var amountInvoiced decimal.Decimal var amountInvoiced, amountNotInvoiced decimal.Decimal rightProducts := NewProductsService().PickRightProducts(invoice.Products, serviceContract.Products) for _, product := range rightProducts { amountInvoiced = serviceContract.AmountInvoiced.Add(product.Amount.Mul(product.Price)) amountNotInvoiced = serviceContract.AmountUnInvoiced.Sub(product.Amount.Mul(product.Price)) } amountInvoiced = amountInvoiced.Round(2) if amountInvoiced.GreaterThan(serviceContract.AmountReceivable) { return ecode.SContractInvoiceProductPriceGreaterThanReceivableAmountErr } amountNotInvoiced = amountNotInvoiced.Round(2) //if amountInvoiced.GreaterThan(serviceContract.AmountReceivable) { // return ecode.SContractInvoiceProductPriceGreaterThanReceivableAmountErr //} err = model.WithTransaction(func(db *gorm.DB) error { err = model.NewInvoiceSearch().Create(invoice) if err != nil { return err } return model.NewServiceContractSearch().SetId(invoice.SourceId).UpdateByMap(map[string]interface{}{ "amount_invoiced": amountInvoiced, "amount_invoiced": amountInvoiced, "amount_not_invoiced": amountNotInvoiced, }) }) if err != nil {