| | |
| | | package model
|
| | |
|
| | | import (
|
| | | "aps_crm/constvar"
|
| | | "aps_crm/pkg/mysqlx"
|
| | | "gorm.io/gorm"
|
| | | "time"
|
| | | )
|
| | |
|
| | | type (
|
| | | ServiceContract struct {
|
| | | Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
|
| | | ClientId int `json:"clientId" gorm:"column:client_id;type:int;comment:客户id"`
|
| | | Number string `json:"number" gorm:"column:number;type:varchar(255);comment:合同编号"`
|
| | | MemberId int `json:"memberId" gorm:"column:member_id;type:int;comment:负责人id"`
|
| | | ContactId int `json:"contactId" gorm:"column:contact_id;type:int;comment:联系人id"`
|
| | | SaleChanceId int `json:"saleChanceId" gorm:"column:sale_chance_id;type:int;comment:销售机会id"`
|
| | | ContractId int `json:"contractId" gorm:"column:contract_id;type:int;comment:合同id"`
|
| | | QuotationId int `json:"quotationId" gorm:"column:quotation_id;type:int;comment:报价单id"`
|
| | | ServiceContractTypeId int `json:"serviceContractTypeId" gorm:"column:service_contract_type_id;type:int;comment:合同类型id"`
|
| | | SignTime time.Time `json:"signTime" gorm:"column:sign_time;type:datetime;comment:签约时间"`
|
| | | StartTime time.Time `json:"startTime" gorm:"column:start_time;type:datetime;comment:开始时间"`
|
| | | EndTime time.Time `json:"endTime" gorm:"column:end_time;type:datetime;comment:结束时间"`
|
| | | ServiceContractStatusId int `json:"serviceContractStatusId" gorm:"column:service_contract_status_id;type:int;comment:合同状态id"`
|
| | | 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:备注"`
|
| | | Products []Product `json:"products" gorm:"many2many:serviceContract_product;"`
|
| | | gorm.Model `json:"-"`
|
| | | }
|
| | |
|
| | | ServiceContractSearch struct {
|
| | | ServiceContract
|
| | |
|
| | | Orm *gorm.DB
|
| | | QueryClass constvar.ServiceContractQueryClass
|
| | | KeywordType constvar.ServiceContractKeywordType
|
| | | Keyword interface{}
|
| | | OrderBy string
|
| | | PageNum int
|
| | | PageSize int
|
| | | }
|
| | | )
|
| | |
|
| | | func (ServiceContract) TableName() string {
|
| | | return "service_contract"
|
| | | }
|
| | |
|
| | | func NewServiceContractSearch() *ServiceContractSearch {
|
| | | return &ServiceContractSearch{
|
| | | Orm: mysqlx.GetDB(),
|
| | | }
|
| | | }
|
| | |
|
| | | func (slf *ServiceContractSearch) build() *gorm.DB {
|
| | | var db = slf.Orm.Model(&ServiceContract{})
|
| | | if slf.Id != 0 {
|
| | | db = db.Where("id = ?", slf.Id)
|
| | | }
|
| | | switch slf.QueryClass {
|
| | | case constvar.ServiceContractQueryClassExpireAfter30Day:
|
| | | db = db.Where("end_time > ?", time.Now(), time.Now().AddDate(0, 0, 30))
|
| | | case constvar.ServiceContractQueryClassExpireAfter60Day:
|
| | | db = db.Where("end_time > ?", time.Now(), time.Now().AddDate(0, 0, 60))
|
| | | case constvar.ServiceContractQueryClassExpiredBefore15Day:
|
| | | db = db.Where("end_time < ?", time.Now().AddDate(0, 0, -15))
|
| | | case constvar.ServiceContractQueryClassExpiredBefore60Day:
|
| | | db = db.Where("end_time < ?", time.Now().AddDate(0, 0, -60))
|
| | |
|
| | | }
|
| | | switch slf.KeywordType {
|
| | | case constvar.ServiceContractKeywordContractNo:
|
| | | db = db.Where("number = ?", slf.Keyword)
|
| | | case constvar.ServiceContractKeywordCustomerName:
|
| | | db = db.Where("client_id = ?", slf.Keyword)
|
| | | case constvar.ServiceContractKeywordContractDate:
|
| | | db = db.Where("sign_time = ?", slf.Keyword)
|
| | | case constvar.ServiceContractKeywordContractType:
|
| | | db = db.Where("service_contract_type_id = ?", slf.Keyword)
|
| | | case constvar.ServiceContractKeywordContractStatus:
|
| | | db = db.Where("service_contract_status_id = ?", slf.Keyword)
|
| | | case constvar.ServiceContractKeywordPrincipal:
|
| | | db = db.Where("member_id = ?", slf.Keyword)
|
| | | case constvar.ServiceContractKeywordProductName:
|
| | | subQuery := db.Table("service_contract_id").Select("product_id").Where("product_id = ?", slf.Keyword)
|
| | | db = db.Where("id = ?", subQuery)
|
| | | case constvar.ServiceContractKeywordServiceBeginDate:
|
| | | db = db.Where("start_time = ?", slf.Keyword)
|
| | | case constvar.ServiceContractKeywordServiceEndDate:
|
| | | db = db.Where("end_time = ?", slf.Keyword)
|
| | | case constvar.ServiceContractKeywordServiceTotalPrice:
|
| | | //todo
|
| | |
|
| | | }
|
| | |
|
| | | return db
|
| | | }
|
| | |
|
| | | func (slf *ServiceContractSearch) Create(record *ServiceContract) error {
|
| | | var db = slf.build()
|
| | | return db.Create(record).Error
|
| | | }
|
| | |
|
| | | func (slf *ServiceContractSearch) Update(record *ServiceContract) error {
|
| | | var db = slf.build()
|
| | | return db.Updates(record).Error
|
| | | }
|
| | |
|
| | | func (slf *ServiceContractSearch) Delete() error {
|
| | | var db = slf.build()
|
| | | return db.Delete(&ServiceContract{}).Error
|
| | | }
|
| | |
|
| | | func (slf *ServiceContractSearch) Find() (*ServiceContract, error) {
|
| | | var db = slf.build()
|
| | | var record = &ServiceContract{}
|
| | | err := db.First(record).Error
|
| | | return record, err
|
| | | }
|
| | |
|
| | | func (slf *ServiceContractSearch) FindAll() ([]*ServiceContract, int64, error) {
|
| | | var db = slf.build()
|
| | | var records = make([]*ServiceContract, 0)
|
| | | var total int64
|
| | | if err := db.Count(&total).Error; err != nil {
|
| | | return records, total, err
|
| | | }
|
| | | if slf.PageNum > 0 && slf.PageSize > 0 {
|
| | | db = db.Limit(slf.PageSize).Offset((slf.PageNum - 1) * slf.PageSize)
|
| | | }
|
| | |
|
| | | if slf.PageNum > 0 && slf.PageSize > 0 {
|
| | | db = db.Limit(slf.PageSize).Offset((slf.PageNum - 1) * slf.PageSize)
|
| | | }
|
| | |
|
| | | err := db.Preload("Products").Find(&records).Error
|
| | | return records, total, err
|
| | | }
|
| | |
|
| | | func (slf *ServiceContractSearch) SetId(id int) *ServiceContractSearch {
|
| | | slf.Id = id
|
| | | return slf
|
| | | }
|
| | |
|
| | | func (slf *ServiceContractSearch) SetKeywordType(keyword constvar.ServiceContractKeywordType) *ServiceContractSearch {
|
| | | slf.KeywordType = keyword
|
| | | return slf
|
| | | }
|
| | |
|
| | | func (slf *ServiceContractSearch) SetQueryClass(queryClass constvar.ServiceContractQueryClass) *ServiceContractSearch {
|
| | | slf.QueryClass = queryClass
|
| | | return slf
|
| | | }
|
| | |
|
| | | func (slf *ServiceContractSearch) SetKeyword(keyword string) *ServiceContractSearch {
|
| | | slf.Keyword = keyword
|
| | | return slf
|
| | | }
|
| | |
|
| | | func (slf *ServiceContractSearch) SetPage(page, size int) *ServiceContractSearch {
|
| | | slf.PageNum, slf.PageSize = page, size
|
| | | return slf
|
| | | }
|
| | |
|
| | | func (slf *ServiceContractSearch) SetOrder(order string) *ServiceContractSearch {
|
| | | slf.OrderBy = order
|
| | | return slf
|
| | | }
|
| | | func (slf *ServiceContractSearch) SetIds(ids []int) *ServiceContractSearch {
|
| | | slf.Orm = slf.Orm.Where("id in (?)", ids)
|
| | | return slf
|
| | | }
|
| | | package model |
| | | |
| | | import ( |
| | | "aps_crm/constvar" |
| | | "aps_crm/pkg/mysqlx" |
| | | "fmt" |
| | | "github.com/shopspring/decimal" |
| | | "gorm.io/gorm" |
| | | "gorm.io/gorm/clause" |
| | | "time" |
| | | ) |
| | | |
| | | type ( |
| | | ServiceContract struct { |
| | | Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` |
| | | ClientId int `json:"clientId" gorm:"column:client_id;type:int;comment:客户id"` |
| | | Client Client `json:"client" gorm:"foreignKey:ClientId"` |
| | | Number string `json:"number" gorm:"column:number;type:varchar(255);comment:合同编号"` |
| | | MemberId int `json:"memberId" gorm:"column:member_id;type:int;comment:负责人id"` |
| | | Member User `json:"member" gorm:"foreignKey:MemberId"` |
| | | ContactId int `json:"contactId" gorm:"column:contact_id;type:int;comment:联系人id"` |
| | | Contact Contact `json:"contact" gorm:"foreignKey:ContactId"` |
| | | SaleChanceId int `json:"saleChanceId" gorm:"column:sale_chance_id;type:int;comment:销售机会id"` |
| | | SaleChance SaleChance `json:"SaleChance" gorm:"foreignKey:SaleChanceId"` |
| | | SalesDetailsId int `json:"salesDetailsId" gorm:"column:sales_details_id;type:int;comment:合同订单id"` |
| | | SalesDetails SalesDetails `json:"salesDetails" gorm:"foreignKey:SalesDetailsId"` |
| | | QuotationId int `json:"quotationId" gorm:"column:quotation_id;type:int;comment:报价单id"` |
| | | Quotation Quotation `json:"quotation" gorm:"foreignKey:QuotationId"` |
| | | ServiceContractTypeId int `json:"serviceContractTypeId" gorm:"column:service_contract_type_id;type:int;comment:合同类型id"` |
| | | ServiceContractType ServiceContractType `json:"serviceContractType" gorm:"foreignKey:ServiceContractTypeId"` |
| | | SignTime string `json:"signTime" gorm:"column:sign_time;type:varchar(255);comment:签约时间"` |
| | | StartTime string `json:"startTime" gorm:"column:start_time;type:varchar(255);comment:开始时间"` |
| | | EndTime string `json:"endTime" gorm:"column:end_time;type:varchar(255);comment:结束时间"` |
| | | ServiceContractStatusId int `json:"serviceContractStatusId" gorm:"column:service_contract_status_id;type:int;comment:合同状态id"` |
| | | ServiceContractStatus ServiceContractStatus `json:"serviceContractStatus" gorm:"foreignKey:ServiceContractStatusId"` |
| | | 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:"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"` // 未开票金额 |
| | | AmountTotal decimal.Decimal `gorm:"column:amount_total;type:decimal(12,2);comment:价税合计" json:"amountTotal"` // 价税合计 |
| | | Products []*Product `json:"products" gorm:"many2many:service_contract_product;"` |
| | | CodeStandID string `json:"codeStandID" gorm:"column:code_stand_id;type:varchar(255);comment:编码id"` |
| | | CrmModel |
| | | } |
| | | |
| | | ServiceContractSearch struct { |
| | | ServiceContract |
| | | Orm *gorm.DB |
| | | QueryClass constvar.ServiceContractQueryClass |
| | | KeywordType constvar.ServiceContractKeywordType |
| | | Keyword interface{} |
| | | OrderBy string |
| | | PageNum int |
| | | PageSize int |
| | | Preload bool |
| | | MemberIds []int |
| | | } |
| | | ) |
| | | |
| | | func (slf *ServiceContract) TableName() string { |
| | | return "service_contract" |
| | | } |
| | | |
| | | func NewServiceContractSearch() *ServiceContractSearch { |
| | | return &ServiceContractSearch{ |
| | | Orm: mysqlx.GetDB(), |
| | | } |
| | | } |
| | | |
| | | func (slf *ServiceContractSearch) build() *gorm.DB { |
| | | var db = slf.Orm.Model(&ServiceContract{}) |
| | | if slf.Id != 0 { |
| | | db = db.Where("id = ?", slf.Id) |
| | | } |
| | | switch slf.QueryClass { |
| | | case constvar.ServiceContractQueryClassExpireAfter30Day: |
| | | db = db.Where("end_time > ?", time.Now().AddDate(0, 0, 30).Format("2006-01-02")) |
| | | case constvar.ServiceContractQueryClassExpireAfter60Day: |
| | | db = db.Where("end_time > ?", time.Now().AddDate(0, 0, 60).Format("2006-01-02")) |
| | | case constvar.ServiceContractQueryClassExpiredBefore15Day: |
| | | db = db.Where("end_time < ?", time.Now().AddDate(0, 0, -15).Format("2006-01-02")) |
| | | case constvar.ServiceContractQueryClassExpiredBefore60Day: |
| | | db = db.Where("end_time < ?", time.Now().AddDate(0, 0, -60).Format("2006-01-02")) |
| | | } |
| | | switch slf.KeywordType { |
| | | case constvar.ServiceContractKeywordContractNo: |
| | | db = db.Where("number like ?", fmt.Sprintf("%%%s%%", slf.Keyword)) |
| | | case constvar.ServiceContractKeywordCustomerName: |
| | | db = db.Joins("Client", clause.LeftJoin).Where("Client.name like ?", fmt.Sprintf("%%%s%%", slf.Keyword)) |
| | | case constvar.ServiceContractKeywordContractDate: |
| | | db = db.Where("sign_time = ?", slf.Keyword) |
| | | case constvar.ServiceContractKeywordContractType: |
| | | db = db.Joins("left join service_contract_type on service_contract_type.id = service_contract.service_contract_type_id") |
| | | db = db.Where("service_contract_type.name like ?", fmt.Sprintf("%%%s%%", slf.Keyword)) |
| | | case constvar.ServiceContractKeywordContractStatus: |
| | | db = db.Joins("left join service_contract_status on service_contract_status.id = service_contract.service_contract_status_id") |
| | | db = db.Where("service_contract_status.name like ?", fmt.Sprintf("%%%s%%", slf.Keyword)) |
| | | case constvar.ServiceContractKeywordPrincipal: |
| | | db = db.Joins("left join user on user.id = service_contract.member_id").Where("user.username like ?", fmt.Sprintf("%%%s%%", slf.Keyword)) |
| | | case constvar.ServiceContractKeywordProductName: |
| | | db = db.Joins("left join service_contract_product scp on scp.service_contract_id = service_contract.id left join products on scp.product_id = products.id").Where("products.name like ?", fmt.Sprintf("%%%s%%", slf.Keyword)) |
| | | case constvar.ServiceContractKeywordServiceBeginDate: |
| | | db = db.Where("start_time = ?", slf.Keyword) |
| | | case constvar.ServiceContractKeywordServiceEndDate: |
| | | db = db.Where("end_time = ?", slf.Keyword) |
| | | case constvar.ServiceContractKeywordServiceTotalPrice: |
| | | db = db.Where("amount_receivable = ?", slf.Keyword) |
| | | |
| | | } |
| | | |
| | | if len(slf.MemberIds) > 0 { |
| | | db = db.Where("service_contract.member_id in ?", slf.MemberIds) |
| | | } |
| | | |
| | | if slf.Preload { |
| | | db = db. |
| | | Preload("Client"). |
| | | Preload("Member"). |
| | | Preload("Contact"). |
| | | Preload("SaleChance"). |
| | | Preload("SalesDetails"). |
| | | Preload("Quotation"). |
| | | Preload("ServiceContractType"). |
| | | Preload("ServiceContractStatus"). |
| | | Preload("Products"). |
| | | Preload("Client"). |
| | | Preload("ServiceContractType"). |
| | | Preload("ServiceContractStatus"). |
| | | Preload("Contact") |
| | | } |
| | | |
| | | if slf.SalesDetailsId != 0 { |
| | | db = db.Where("sales_details_id = ?", slf.SalesDetailsId) |
| | | } |
| | | |
| | | if slf.QuotationId != 0 { |
| | | db = db.Where("quotation_id = ?", slf.QuotationId) |
| | | } |
| | | if slf.SaleChanceId != 0 { |
| | | db = db.Where("sale_chance_id = ?", slf.SaleChanceId) |
| | | } |
| | | if slf.ContactId != 0 { |
| | | db = db.Where("contact_id = ?", slf.ContactId) |
| | | } |
| | | if slf.Number != "" { |
| | | db = db.Where("number = ?", slf.Number) |
| | | } |
| | | return db |
| | | } |
| | | |
| | | func (slf *ServiceContractSearch) Create(record *ServiceContract) error { |
| | | var db = slf.build() |
| | | return db.Create(record).Error |
| | | } |
| | | |
| | | func (slf *ServiceContractSearch) Update(record *ServiceContract) error { |
| | | var db = slf.build() |
| | | return db.Updates(record).Error |
| | | } |
| | | |
| | | func (slf *ServiceContractSearch) Delete() error { |
| | | var db = slf.build() |
| | | return db.Delete(&ServiceContract{}).Error |
| | | } |
| | | |
| | | func (slf *ServiceContractSearch) DeleteByIds(ids []int) error { |
| | | var db = slf.build() |
| | | db = db.Where("id in ?", ids) |
| | | return db.Delete(&ServiceContract{}).Error |
| | | } |
| | | |
| | | func (slf *ServiceContractSearch) Find() ([]*ServiceContract, int64, error) { |
| | | var db = slf.build() |
| | | var records = make([]*ServiceContract, 0) |
| | | var total int64 |
| | | if err := db.Count(&total).Error; err != nil { |
| | | return records, total, err |
| | | } |
| | | if slf.PageNum > 0 && slf.PageSize > 0 { |
| | | db = db.Limit(slf.PageSize).Offset((slf.PageNum - 1) * slf.PageSize) |
| | | } |
| | | |
| | | err := db.Order("id desc").Find(&records).Error |
| | | return records, total, err |
| | | } |
| | | |
| | | func (slf *ServiceContractSearch) Count() (int64, error) { |
| | | var db = slf.build() |
| | | var total int64 |
| | | err := db.Count(&total).Error |
| | | return total, err |
| | | } |
| | | |
| | | func (slf *ServiceContractSearch) 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 *ServiceContractSearch) SetNumber(number string) *ServiceContractSearch { |
| | | slf.Number = number |
| | | return slf |
| | | } |
| | | |
| | | func (slf *ServiceContractSearch) SetId(id int) *ServiceContractSearch { |
| | | slf.Id = id |
| | | return slf |
| | | } |
| | | |
| | | func (slf *ServiceContractSearch) SetKeywordType(keyword constvar.ServiceContractKeywordType) *ServiceContractSearch { |
| | | slf.KeywordType = keyword |
| | | return slf |
| | | } |
| | | |
| | | func (slf *ServiceContractSearch) SetQueryClass(queryClass constvar.ServiceContractQueryClass) *ServiceContractSearch { |
| | | slf.QueryClass = queryClass |
| | | return slf |
| | | } |
| | | |
| | | func (slf *ServiceContractSearch) SetKeyword(keyword string) *ServiceContractSearch { |
| | | slf.Keyword = keyword |
| | | return slf |
| | | } |
| | | |
| | | func (slf *ServiceContractSearch) SetPage(page, size int) *ServiceContractSearch { |
| | | slf.PageNum, slf.PageSize = page, size |
| | | return slf |
| | | } |
| | | |
| | | func (slf *ServiceContractSearch) SetOrder(order string) *ServiceContractSearch { |
| | | slf.OrderBy = order |
| | | return slf |
| | | } |
| | | func (slf *ServiceContractSearch) SetIds(ids []int) *ServiceContractSearch { |
| | | slf.Orm = slf.Orm.Where("id in (?)", ids) |
| | | return slf |
| | | } |
| | | |
| | | func (slf *ServiceContractSearch) SetMemberIds(memberIds []int) *ServiceContractSearch { |
| | | slf.MemberIds = memberIds |
| | | return slf |
| | | } |
| | | |
| | | func (slf *ServiceContractSearch) SetSalesDetailsId(salesDetailsId int) *ServiceContractSearch { |
| | | slf.SalesDetailsId = salesDetailsId |
| | | return slf |
| | | } |
| | | |
| | | func (slf *ServiceContractSearch) SetQuotationId(quotationId int) *ServiceContractSearch { |
| | | slf.QuotationId = quotationId |
| | | return slf |
| | | } |
| | | |
| | | func (slf *ServiceContractSearch) SetSaleChanceId(saleChanceId int) *ServiceContractSearch { |
| | | slf.SaleChanceId = saleChanceId |
| | | return slf |
| | | } |
| | | |
| | | func (slf *ServiceContractSearch) SetContactId(contactId int) *ServiceContractSearch { |
| | | slf.ContactId = contactId |
| | | return slf |
| | | } |
| | | |
| | | func (slf *ServiceContractSearch) SetPreload(preload bool) *ServiceContractSearch { |
| | | slf.Preload = preload |
| | | return slf |
| | | } |
| | | |
| | | func (slf *ServiceContractSearch) 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 *ServiceContractSearch) First() (*ServiceContract, error) { |
| | | var ( |
| | | record = new(ServiceContract) |
| | | db = slf.build() |
| | | ) |
| | | |
| | | if err := db.First(record).Error; err != nil { |
| | | return record, err |
| | | } |
| | | |
| | | return record, nil |
| | | } |
| | | |
| | | func (slf *ServiceContractSearch) AmountReceivableAdd(tx *gorm.DB, id int, amount decimal.Decimal) error { |
| | | slf.Orm = tx |
| | | record, err := slf.SetId(id).First() |
| | | if err != nil { |
| | | return err |
| | | } |
| | | amount = record.AmountReceivable.Add(amount) |
| | | return slf.UpdateByMap(map[string]interface{}{"amount_receivable": amount}) |
| | | } |
| | | func (slf *ServiceContractSearch) AmountReceivedAdd(tx *gorm.DB, id int, amount decimal.Decimal) error { |
| | | slf.Orm = tx |
| | | record, err := slf.SetId(id).First() |
| | | if err != nil { |
| | | return err |
| | | } |
| | | amount = record.AmountReceived.Add(amount) |
| | | return slf.UpdateByMap(map[string]interface{}{"amount_received": amount}) |
| | | } |
| | | func (slf *ServiceContractSearch) AmountInvoicedAdd(tx *gorm.DB, id int, amount decimal.Decimal) error { |
| | | slf.Orm = tx |
| | | record, err := slf.SetId(id).First() |
| | | if err != nil { |
| | | return err |
| | | } |
| | | amount = record.AmountInvoiced.Add(amount) |
| | | return slf.UpdateByMap(map[string]interface{}{"amount_invoiced": amount}) |
| | | } |
| | | func (slf *ServiceContractSearch) AmountNotInvoicedAdd(tx *gorm.DB, id int, amount decimal.Decimal) error { |
| | | slf.Orm = tx |
| | | record, err := slf.SetId(id).First() |
| | | if err != nil { |
| | | return err |
| | | } |
| | | amount = record.AmountUnInvoiced.Add(amount) |
| | | return slf.UpdateByMap(map[string]interface{}{"amount_not_invoiced": amount}) |
| | | } |