Переглянути джерело

feat: 扣款金额和结算编号

caipin 1 рік тому
батько
коміт
5b51024aba

+ 4 - 3
dao/contract_dao.go

@@ -16,12 +16,12 @@ import (
 	"go.mod/models"
 )
 
-//数据库操作引擎
+// 数据库操作引擎
 type ContractDao struct {
 	engine *xorm.Engine
 }
 
-//获得一个DAO对象
+// 获得一个DAO对象
 func NewContractDao(engine *xorm.Engine) *ContractDao {
 	return &ContractDao{
 		engine: engine,
@@ -379,7 +379,7 @@ func (d *ContractDao) DeleteExpenditure(projectId int, bidsectionId int, treeId
 }
 
 // 关闭合同
-func (d *ContractDao) Close(projectId int, bidsectionId int, treeId int, id int) error {
+func (d *ContractDao) Close(projectId int, bidsectionId int, treeId int, id int, settlementCode string) error {
 
 	session := d.engine.NewSession()
 	defer session.Close()
@@ -392,6 +392,7 @@ func (d *ContractDao) Close(projectId int, bidsectionId int, treeId int, id int)
 	contractsCm := models.CmContracts{}
 	contractsCm.Status = 2
 	contractsCm.Locking = 1
+	contractsCm.SettlementCode = settlementCode
 	successNum, err := session.Where("id = ? and project_id = ? and bidsection_id = ? ", id, projectId, bidsectionId).Update(contractsCm)
 	if err != nil {
 		session.Rollback()

+ 8 - 3
dao/contract_paid_dao.go

@@ -15,12 +15,12 @@ import (
 	"go.mod/models"
 )
 
-//数据库操作引擎
+// 数据库操作引擎
 type ContractPaidDao struct {
 	engine *xorm.Engine
 }
 
-//获得一个DAO对象
+// 获得一个DAO对象
 func NewContractPaidDao(engine *xorm.Engine) *ContractPaidDao {
 	return &ContractPaidDao{
 		engine: engine,
@@ -107,9 +107,14 @@ func (d *ContractPaidDao) UpdatePaidTotalPrice(projectId int, bidsectionId int,
 	}
 	priceTotal := 0.00
 	contractsPrice := 0.00
+	// 扣款金额合计
+	contractDeductionTotal := 0.00
 	for _, item := range datalist {
 		price, _ := strconv.ParseFloat(item.Price, 64)
 		priceTotal = priceTotal + price
+		contractDeduction, _ := strconv.ParseFloat(item.ContractDeduction, 64)
+		contractDeductionTotal = contractDeductionTotal + contractDeduction
+
 		if item.ContractsId == contractsId {
 			contractsPrice = contractsPrice + price
 		}
@@ -126,7 +131,7 @@ func (d *ContractPaidDao) UpdatePaidTotalPrice(projectId int, bidsectionId int,
 	}
 
 	// 2.更新合同表 合同下回款总金额
-	_, err = session.Exec("UPDATE  cm_contracts SET `paid` = ? , status = ?,locking=0 where id = ? ", contractsPrice, contractStatus, contractsId)
+	_, err = session.Exec("UPDATE  cm_contracts SET `paid` = ? , contract_deduction_total= ?, status = ?,locking=0 where id = ? ", contractsPrice, contractDeductionTotal, contractStatus, contractsId)
 	if err != nil {
 		session.Rollback()
 		return errors.New("金额更新失败")

+ 21 - 0
lib/jlzf_test.go

@@ -0,0 +1,21 @@
+package lib_test
+
+import (
+	"testing"
+
+	"go.mod/lib"
+	"go.mod/web/viewmodels"
+)
+
+func TestValid(t *testing.T) {
+	Jlzf := lib.NewJlzf()
+
+	loginData := viewmodels.Login{
+		Account:  "fuqingqing",
+		Password: "dfsdf",
+		Code:     "P1002",
+	}
+
+	Jlzf.LoginValid(loginData)
+
+}

+ 23 - 21
models/cm_contracts.go

@@ -5,25 +5,27 @@ import (
 )
 
 type CmContracts struct {
-	Id            int       `xorm:"not null pk autoincr comment('自增ID') INT(11)"`
-	TreeId        int       `xorm:"not null default 0 comment('树ID') INT(11)"`
-	ContractsType int       `xorm:"not null default 1 comment('合同类型(1收入2支出)') TINYINT(1)"`
-	ProjectId     int       `xorm:"not null default 0 comment('项目ID') INT(11)"`
-	BidsectionId  int       `xorm:"default 0 comment('标段ID') INT(11)"`
-	Name          string    `xorm:"not null comment('合同名称') VARCHAR(64)"`
-	Content       string    `xorm:"comment('合同内容') VARCHAR(1024)"`
-	Code          string    `xorm:"comment('合同编号') VARCHAR(32)"`
-	PartyA        string    `xorm:"comment('甲方') VARCHAR(32)"`
-	PartyASigner  string    `xorm:"comment('甲方签约人') VARCHAR(32)"`
-	PartyB        string    `xorm:"comment('乙方') VARCHAR(32)"`
-	PartyBSigner  string    `xorm:"comment('乙方签约人') VARCHAR(32)"`
-	SignerTime    time.Time `xorm:"comment('签约日期') DATETIME"`
-	Remarks       string    `xorm:"comment('备注') VARCHAR(1024)"`
-	Price         string    `xorm:"not null default 0.00 comment('合同金额') DECIMAL(12,2)"`
-	Returned      string    `xorm:"not null default 0.00 comment('回款总金额') DECIMAL(12,2)"`
-	Paid          string    `xorm:"not null default 0.00 comment('合同已支付总金额') DECIMAL(12,2)"`
-	Status        int       `xorm:"not null default 0 comment('合同状态(0履行中1待关闭2已关闭)') TINYINT(1)"`
-	Locking       int       `xorm:"not null default 0 comment('锁定(0未锁定1锁定)') TINYINT(1)"`
-	CreateTime    time.Time `xorm:"comment('创建时间') DATETIME"`
-	UpdateTime    time.Time `xorm:"not null default 'CURRENT_TIMESTAMP' comment('更新时间') TIMESTAMP"`
+	Id                     int       `xorm:"not null pk autoincr comment('自增ID') INT(11)"`
+	TreeId                 int       `xorm:"not null default 0 comment('树ID') INT(11)"`
+	ContractsType          int       `xorm:"not null default 1 comment('合同类型(1收入2支出)') TINYINT(1)"`
+	ProjectId              int       `xorm:"not null default 0 comment('项目ID') INT(11)"`
+	BidsectionId           int       `xorm:"default 0 comment('标段ID') INT(11)"`
+	Name                   string    `xorm:"not null comment('合同名称') VARCHAR(64)"`
+	Content                string    `xorm:"comment('合同内容') VARCHAR(1024)"`
+	Code                   string    `xorm:"comment('合同编号') VARCHAR(32)"`
+	PartyA                 string    `xorm:"comment('甲方') VARCHAR(32)"`
+	PartyASigner           string    `xorm:"comment('甲方签约人') VARCHAR(32)"`
+	PartyB                 string    `xorm:"comment('乙方') VARCHAR(32)"`
+	PartyBSigner           string    `xorm:"comment('乙方签约人') VARCHAR(32)"`
+	SignerTime             time.Time `xorm:"comment('签约日期') DATETIME"`
+	Remarks                string    `xorm:"comment('备注') VARCHAR(1024)"`
+	Price                  string    `xorm:"not null default 0.00 comment('合同金额') DECIMAL(12,2)"`
+	Returned               string    `xorm:"not null default 0.00 comment('回款总金额') DECIMAL(12,2)"`
+	Paid                   string    `xorm:"not null default 0.00 comment('合同已支付总金额') DECIMAL(12,2)"`
+	ContractDeductionTotal string    `xorm:"not null default 0.00 comment('扣款金额合计') DECIMAL(12,2)"`
+	Status                 int       `xorm:"not null default 0 comment('合同状态(0履行中1待关闭2已关闭)') TINYINT(1)"`
+	Locking                int       `xorm:"not null default 0 comment('锁定(0未锁定1锁定)') TINYINT(1)"`
+	SettlementCode         string    `xorm:"comment('结算书编号') VARCHAR(255)"`
+	CreateTime             time.Time `xorm:"comment('创建时间') DATETIME"`
+	UpdateTime             time.Time `xorm:"not null default 'CURRENT_TIMESTAMP' comment('更新时间') TIMESTAMP"`
 }

+ 15 - 14
models/cm_contracts_paid.go

@@ -5,18 +5,19 @@ import (
 )
 
 type CmContractsPaid struct {
-	Id           int       `xorm:"not null pk autoincr comment('自增ID') INT(11)"`
-	ContractsId  int       `xorm:"not null default 0 comment('合同ID') INT(11)"`
-	ProjectId    int       `xorm:"not null default 0 comment('项目ID') INT(11)"`
-	BidsectionId int       `xorm:"not null default 0 comment('标段ID') INT(11)"`
-	TreeId       int       `xorm:"not null default 0 comment('项目节ID') INT(11)"`
-	Time         time.Time `xorm:"comment('支付日期') DATETIME"`
-	Price        string    `xorm:"default 0.00 comment('支付金额') DECIMAL(12,2)"`
-	Way          string    `xorm:"comment('支付方式') VARCHAR(32)"`
-	CreateUser   string    `xorm:"comment('创建人') VARCHAR(32)"`
-	AccountId    int       `xorm:"not null default 0 comment('项目用户ID') INT(11)"`
-	Remarks      string    `xorm:"comment('备注') VARCHAR(512)"`
-	Annexes      int       `xorm:"default 0 comment('附件数量') TINYINT(2)"`
-	CreateTime   time.Time `xorm:"comment('创建时间') DATETIME"`
-	UpdateTime   time.Time `xorm:"not null default 'CURRENT_TIMESTAMP' comment('更新时间') TIMESTAMP"`
+	Id                int       `xorm:"not null pk autoincr comment('自增ID') INT(11)"`
+	ContractsId       int       `xorm:"not null default 0 comment('合同ID') INT(11)"`
+	ProjectId         int       `xorm:"not null default 0 comment('项目ID') INT(11)"`
+	BidsectionId      int       `xorm:"not null default 0 comment('标段ID') INT(11)"`
+	TreeId            int       `xorm:"not null default 0 comment('项目节ID') INT(11)"`
+	Time              time.Time `xorm:"comment('支付日期') DATETIME"`
+	Price             string    `xorm:"default 0.00 comment('支付金额') DECIMAL(12,2)"`
+	ContractDeduction string    `xorm:"default 0.00 comment('支付金额') DECIMAL(12,2)"`
+	Way               string    `xorm:"comment('支付方式') VARCHAR(32)"`
+	CreateUser        string    `xorm:"comment('创建人') VARCHAR(32)"`
+	AccountId         int       `xorm:"not null default 0 comment('项目用户ID') INT(11)"`
+	Remarks           string    `xorm:"comment('备注') VARCHAR(512)"`
+	Annexes           int       `xorm:"default 0 comment('附件数量') TINYINT(2)"`
+	CreateTime        time.Time `xorm:"comment('创建时间') DATETIME"`
+	UpdateTime        time.Time `xorm:"not null default 'CURRENT_TIMESTAMP' comment('更新时间') TIMESTAMP"`
 }

+ 8 - 1
services/contract_paid_service.go

@@ -55,10 +55,13 @@ func (s *contractService) PaidCreate(returnData *viewmodels.ContractsPaid, proje
 	// if err != nil {
 	// 	return errors.New("金额填写有误")
 	// }
+	contractDeductionPrice := decimal.NewFromFloat(returnData.ContractDeduction)
 	contractPrice, _ := decimal.NewFromString(contract.Price)
 	paidPrice, _ := decimal.NewFromString(contract.Paid)
 	resultPrice := contractPrice.Sub(paidPrice)
+	resultPrice = resultPrice.Add(contractDeductionPrice)
 
+	//  合同额-已支付金额+已扣款金额
 	if price.GreaterThan(resultPrice) {
 		return errors.New("支付金额不能超过合同金额")
 	}
@@ -83,6 +86,7 @@ func (s *contractService) PaidCreate(returnData *viewmodels.ContractsPaid, proje
 	contractsReturnCm.AccountId = projectAccountId
 
 	contractsReturnCm.Price = fmt.Sprintf("%.2f", returnData.Price)
+	contractsReturnCm.ContractDeduction = fmt.Sprintf("%.2f", returnData.ContractDeduction)
 
 	// 3.新增回款
 	err = s.contractPaidDao.Add(contractsReturnCm)
@@ -155,6 +159,7 @@ func (s *contractService) PaidUpdate(returnData *viewmodels.ContractsPaid, proje
 	// }
 
 	contractsReturnCm.Price = fmt.Sprintf("%.2f", returnData.Price)
+	contractsReturnCm.ContractDeduction = fmt.Sprintf("%.2f", returnData.ContractDeduction)
 
 	// 3.更新已支付信息
 	err = s.contractPaidDao.Update(contractsReturnCm, contractsId, bidsectionId)
@@ -220,6 +225,9 @@ func (s *contractService) makeContractPaidVM(data *models.CmContractsPaid) *view
 	viewContractsReturn.BidsectionId = bidsectionId
 	viewContractsReturn.Time = data.Time.Format(conf.SysTimeform)
 
+	contractDeduction, _ := strconv.ParseFloat(data.ContractDeduction, 64)
+	viewContractsReturn.ContractDeduction = contractDeduction
+
 	price, _ := strconv.ParseFloat(data.Price, 64)
 	// fmt.Sprintf("%.2f", price)
 	viewContractsReturn.Price = price
@@ -275,7 +283,6 @@ func (s *contractService) ValidRuleContractPaid(ctx iris.Context) (*viewmodels.C
 	return contractsVaild, nil
 }
 
-//
 func (s *contractService) ValidRuleContractPaidDel(ctx iris.Context) (*viewmodels.ContractsPaid, error) {
 	// 创建一个存放前端传过来参数
 	contractsVaild := &viewmodels.ContractsPaid{}

+ 9 - 8
services/contract_service.go

@@ -24,7 +24,7 @@ import (
 	"go.mod/web/viewmodels"
 )
 
-//定义项目用户Service接口
+// 定义项目用户Service接口
 type ContractService interface {
 	ValidRuleDepth(ctx iris.Context) (*viewmodels.TreeSectionContract, error)
 	ValidRuleTemplate(ctx iris.Context) (*viewmodels.TreeSectionContract, error)
@@ -64,7 +64,7 @@ type ContractService interface {
 	Add(contractData *viewmodels.Contracts, projectId int, bidsectionId int, treeId int) error
 	Update(contractData *viewmodels.Contracts, projectId int, bidsectionId int, treeId int) error
 	Delete(projectId int, bidsectionId int, treeId int, id int) error
-	Close(projectId int, bidsectionId int, treeId int, id int, treeType int) error
+	Close(projectId int, bidsectionId int, treeId int, id int, treeType int, settlementCode string) error
 	Unlock(projectId int, bidsectionId int, treeId int, id int, treeType int) error
 	GetSurvey(bidsectionId int, projectId int, contractsType int) map[string]interface{}
 
@@ -85,7 +85,7 @@ type ContractService interface {
 	PaidDelete(projectId int, bidsectionId int, contractsId int, id int) error
 }
 
-//返回service操作类
+// 返回service操作类
 type contractService struct {
 	treeContractDao   *dao.TreeContractDao
 	contractDao       *dao.ContractDao
@@ -95,7 +95,7 @@ type contractService struct {
 	annexDao          *dao.AnnexDao
 }
 
-//创建项目用户service
+// 创建项目用户service
 func NewContractService() ContractService {
 	return &contractService{
 		treeContractDao:   dao.NewTreeContractDao(datasource.InstanceDbMaster()),
@@ -323,7 +323,7 @@ func (s *contractService) ValidRuleContractClose(ctx iris.Context) (*viewmodels.
 	return contractsVaild, nil
 }
 
-//------------------------------------------------------------
+// ------------------------------------------------------------
 // 获得项目节
 func (s *contractService) Get(treeId int, bidsectionId int, projectId int, treeType int) *viewmodels.TreeSectionContract {
 	// 1.获得项目节
@@ -507,7 +507,7 @@ func (s *contractService) Delete(projectId int, bidsectionId int, treeId int, id
 }
 
 // 关闭合同
-func (s *contractService) Close(projectId int, bidsectionId int, treeId int, id int, treeType int) error {
+func (s *contractService) Close(projectId int, bidsectionId int, treeId int, id int, treeType int, settlementCode string) error {
 	// 1. 项目节存在
 	contractsTree := s.treeContractDao.Get(treeId, bidsectionId, projectId, treeType)
 	if contractsTree.Id == 0 {
@@ -524,7 +524,7 @@ func (s *contractService) Close(projectId int, bidsectionId int, treeId int, id
 	}
 
 	// 关闭合同
-	err := s.contractDao.Close(projectId, bidsectionId, treeId, id)
+	err := s.contractDao.Close(projectId, bidsectionId, treeId, id, settlementCode)
 	if err != nil {
 		return err
 	}
@@ -553,7 +553,7 @@ func (s *contractService) Unlock(projectId int, bidsectionId int, treeId int, id
 	return nil
 }
 
-//获得合同收入概况
+// 获得合同收入概况
 func (s *contractService) GetSurvey(bidsectionId int, projectId int, contractsType int) map[string]interface{} {
 	// 1.获得收入合同
 	year := time.Now().Year()
@@ -719,6 +719,7 @@ func (s *contractService) makeContractVM(contract *models.CmContracts) viewmodel
 	contractsVM.Paid = contract.Paid
 	contractsVM.Status = contract.Status
 	contractsVM.Locking = contract.Locking
+	contractsVM.ContractDeductionTotal = contract.ContractDeductionTotal
 
 	contractsVM.CreateTime = contract.CreateTime.Format(conf.SysTimeform)
 	contractsVM.UpdateTime = contract.UpdateTime.Format(conf.SysTimeform)

+ 1 - 1
web/api/contract_api.go

@@ -441,7 +441,7 @@ func (c *ContractApi) PostClose() {
 		return
 	}
 
-	err = c.ServiceContract.Close(projectIdInt, bidsectionId, treeId, id, contractData.TreeType)
+	err = c.ServiceContract.Close(projectIdInt, bidsectionId, treeId, id, contractData.TreeType, contractData.SettlementCode)
 	if err != nil {
 		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
 		return

+ 10 - 7
web/viewmodels/contract.go

@@ -19,13 +19,14 @@ type Contracts struct {
 	Name          string `form:"name" json:"name" `
 	Code          string `form:"code" json:"code" `
 	// PriceFloat    float64 `form:"priceFloat" json:"priceFloat" `
-	Price      float64 `form:"price" json:"price" `
-	Returned   string  `form:"returned" json:"returned" `
-	Paid       string  `form:"paid" json:"paid" `
-	Status     int     `form:"status" json:"status" `
-	Locking    int     `form:"locking" json:"locking" `
-	CreateTime string  `form:"createTime" json:"createTime" `
-	UpdateTime string  `form:"updateTime" json:"updateTime" `
+	Price                  float64 `form:"price" json:"price" `
+	Returned               string  `form:"returned" json:"returned" `
+	Paid                   string  `form:"paid" json:"paid" `
+	ContractDeductionTotal string  `form:"contractDeductionTotal" json:"contractDeductionTotal" `
+	Status                 int     `form:"status" json:"status" `
+	Locking                int     `form:"locking" json:"locking" `
+	CreateTime             string  `form:"createTime" json:"createTime" `
+	UpdateTime             string  `form:"updateTime" json:"updateTime" `
 
 	Content      string `form:"content" json:"content" `
 	PartyA       string `form:"partyA" json:"partyA" `
@@ -35,6 +36,7 @@ type Contracts struct {
 	SignerTime   string `form:"signerTime" json:"signerTime" `
 	Remarks      string `form:"remarks" json:"remarks" `
 
+	SettlementCode string `form:"settlementCode" json:"settlementCode" `
 	// SectionName string `form:"sectionName" json:"sectionName" `
 
 	// 前端需要
@@ -76,6 +78,7 @@ func (l Contracts) ValidateDel() error {
 		validation.Field(&l.Id, validation.Required.Error("合同ID不能为空")),
 		validation.Field(&l.TreeId, validation.Required.Error("项目节ID不能为空")),
 		validation.Field(&l.BidsectionId, validation.Required.Error("标段ID不能为空")),
+		validation.Field(&l.SettlementCode, validation.Required.Error("结算书编号不能为空")),
 	)
 }
 

+ 14 - 14
web/viewmodels/contracts_paid.go

@@ -9,20 +9,20 @@ package viewmodels
 import validation "github.com/go-ozzo/ozzo-validation/v3"
 
 type ContractsPaid struct {
-	Id           string  `form:"id" json:"id" `
-	ContractsId  string  `form:"contractsId" json:"contractsId" `
-	ProjectId    string  `form:"projectId" json:"projectId" `
-	BidsectionId string  `form:"bidsectionId" json:"bidsectionId" `
-	Time         string  `form:"time" json:"time" `
-	Price        float64 `form:"price" json:"price" `
-	Way          string  `form:"way" json:"way" `
-	CreateUser   string  `form:"createUser" json:"createUser" `
-	AccountId    string  `form:"accountId" json:"accountId" `
-	Remarks      string  `form:"remarks" json:"remarks" `
-	CreateTime   string  `form:"createTime" json:"createTime" `
-	FileCounts   int64   `from:"fileCounts" json:"fileCounts"`
-
-	Page int `form:"page" json:"page" `
+	Id                string  `form:"id" json:"id" `
+	ContractsId       string  `form:"contractsId" json:"contractsId" `
+	ProjectId         string  `form:"projectId" json:"projectId" `
+	BidsectionId      string  `form:"bidsectionId" json:"bidsectionId" `
+	Time              string  `form:"time" json:"time" `
+	Price             float64 `form:"price" json:"price" `
+	Way               string  `form:"way" json:"way" `
+	CreateUser        string  `form:"createUser" json:"createUser" `
+	AccountId         string  `form:"accountId" json:"accountId" `
+	Remarks           string  `form:"remarks" json:"remarks" `
+	CreateTime        string  `form:"createTime" json:"createTime" `
+	FileCounts        int64   `from:"fileCounts" json:"fileCounts"`
+	ContractDeduction float64 `form:"contractDeduction" json:"contractDeduction" `
+	Page              int     `form:"page" json:"page" `
 }
 
 // 验证方法