|
@@ -8,15 +8,16 @@ import (
|
|
|
|
|
|
type Reimbursement struct {
|
|
|
global.GVA_MODEL
|
|
|
- ProjectCode string `json:"projectCode" form:"projectCode" gorm:"comment:项目编号"`
|
|
|
- Name string `json:"name" form:"name" gorm:"comment:项目名称"`
|
|
|
- Applicant string `json:"applicant" form:"applicant" gorm:"comment:报销申请人"`
|
|
|
- ApplicationTime string `json:"applicationTime" form:"applicationTime" gorm:"comment:申请日期"`
|
|
|
- Approval int `json:"approval" form:"approval" gorm:"comment:报销审批人"`
|
|
|
- User SysUser `json:"user" form:"user" gorm:"foreignKey:Approval;references:id;"`
|
|
|
- Price decimal.Decimal `json:"price" form:"price" gorm:"comment:项目金额;type:decimal(10,2)"`
|
|
|
- Genre string `json:"genre" form:"genre" gorm:"comment:费用类型"`
|
|
|
- FeeDetails []FeeDetails `json:"feeDetails" form:"feeDetails" gorm:"-"`
|
|
|
+ ProjectCode string `json:"projectCode" form:"projectCode" gorm:"comment:项目编号"`
|
|
|
+ Name string `json:"name" form:"name" gorm:"comment:项目名称"`
|
|
|
+ Applicant string `json:"applicant" form:"applicant" gorm:"comment:报销申请人"`
|
|
|
+ ApplicationTime string `json:"applicationTime" form:"applicationTime" gorm:"comment:申请日期"`
|
|
|
+ Approval int `json:"approval" form:"approval" gorm:"comment:报销审批人"`
|
|
|
+ User SysUser `json:"user" form:"user" gorm:"foreignKey:Approval;references:id;"`
|
|
|
+ ReimbursementPrice decimal.Decimal `json:"reimbursementPrice" form:"reimbursementPrice" gorm:"comment:项目金额;type:decimal(10,2)"`
|
|
|
+ Genre int `json:"genre" form:"genre" gorm:"comment:费用类型"`
|
|
|
+ ExpensesGenre ExpensesGenre `json:"expensesGenre" form:"expensesGenre" gorm:"foreignKey:Genre;references:id;"`
|
|
|
+ FeeDetails []FeeDetails `json:"feeDetails" form:"feeDetails" gorm:"-"`
|
|
|
}
|
|
|
|
|
|
func (Reimbursement) TableName() string {
|
|
@@ -31,7 +32,7 @@ func QueryReimbursementList(limit, offset int, code, name, time string) (reimbur
|
|
|
db := global.GVA_DB.Model(&Reimbursement{}).Where("project_code = ?", code)
|
|
|
// 如果有条件搜索 下方会自动创建搜索语句
|
|
|
if name != "" {
|
|
|
- db = db.Where("name LIKE ?", "%"+name+"%")
|
|
|
+ db = db.Where("applicant LIKE ?", "%"+name+"%")
|
|
|
}
|
|
|
if time != "" {
|
|
|
db = db.Where("DATE_FORMAT(application_time, '%Y-%m') = ?", time)
|
|
@@ -40,12 +41,12 @@ func QueryReimbursementList(limit, offset int, code, name, time string) (reimbur
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
|
- err = db.Order("id desc").Limit(limit).Offset(offset).Preload("User").Find(&reimbursement).Error
|
|
|
+ err = db.Order("id desc").Limit(limit).Offset(offset).Preload("ExpensesGenre").Preload("User").Find(&reimbursement).Error
|
|
|
return reimbursement, total, err
|
|
|
}
|
|
|
|
|
|
func QueryReimbursement(code string) (reimbursement []Reimbursement, err error) {
|
|
|
- err = global.GVA_DB.Model(&Reimbursement{}).Where("project_code = ?", code).Preload("User").Find(&reimbursement).Error
|
|
|
+ err = global.GVA_DB.Model(&Reimbursement{}).Where("project_code = ?", code).Preload("ExpensesGenre").Preload("User").Find(&reimbursement).Error
|
|
|
return reimbursement, err
|
|
|
}
|
|
|
|
|
@@ -59,6 +60,7 @@ func (r Reimbursement) CreateReimbursement() error {
|
|
|
return txErr
|
|
|
}
|
|
|
for _, feeDetail := range r.FeeDetails {
|
|
|
+ feeDetail.ReimbursementId = r.ID
|
|
|
txErr := tx.Create(&feeDetail).Error
|
|
|
if txErr != nil {
|
|
|
return txErr
|
|
@@ -77,11 +79,12 @@ func (r Reimbursement) UpdateReimbursement() error {
|
|
|
if txErr != nil {
|
|
|
return txErr
|
|
|
}
|
|
|
- txErr = tx.Model(&r).Updates(&r).Error
|
|
|
+ txErr = tx.Model(&r).Where("id = ?", r.ID).Updates(&r).Error
|
|
|
if txErr != nil {
|
|
|
return txErr
|
|
|
}
|
|
|
for _, feeDetail := range r.FeeDetails {
|
|
|
+ feeDetail.ReimbursementId = r.ID
|
|
|
txErr := tx.Create(&feeDetail).Error
|
|
|
if txErr != nil {
|
|
|
return txErr
|