caipin 1 rok pred
rodič
commit
5a964d02b0

+ 1 - 0
dao/contract_dao.go

@@ -407,6 +407,7 @@ func (d *ContractDao) Close(projectId int, bidsectionId int, treeId int, id int,
 	treeContractsCm := models.CmTreeContracts{}
 	treeContractsCm.ContractStatus = 2
 	treeContractsCm.ContractLocking = 1
+	treeContractsCm.SettlementCode = settlementCode
 	successNum, err = session.Where("tree_id = ? and project_id = ? and bidsection_id = ? ", treeId, projectId, bidsectionId).Update(treeContractsCm)
 	if err != nil {
 		session.Rollback()

+ 7 - 5
dao/contract_paid_dao.go

@@ -112,11 +112,12 @@ func (d *ContractPaidDao) UpdatePaidTotalPrice(projectId int, bidsectionId int,
 	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
+
+			contractDeduction, _ := strconv.ParseFloat(item.ContractDeduction, 64)
+			contractDeductionTotal = contractDeductionTotal + contractDeduction
 		}
 	}
 	priceTotal, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", priceTotal), 64)
@@ -131,14 +132,15 @@ func (d *ContractPaidDao) UpdatePaidTotalPrice(projectId int, bidsectionId int,
 	}
 
 	// 2.更新合同表 合同下回款总金额
-	_, err = session.Exec("UPDATE  cm_contracts SET `paid` = ? , contract_deduction_total= ?, status = ?,locking=0 where id = ? ", contractsPrice, contractDeductionTotal, 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("金额更新失败")
 	}
 	// 3.更新项目节 合同下回款总金额
-	_, err = session.Exec("UPDATE  cm_tree_contracts SET `contracts_paid` = ? , contract_status = ?,contract_locking=0 where project_id = ? and bidsection_id=? and contract_id=? ",
-		contractsPrice, contractStatus, projectId, bidsectionId, contractsId)
+	_, err = session.Exec("UPDATE  cm_tree_contracts SET `contracts_paid` = ?,contract_deduction_total = ? , contract_status = ?,contract_locking=0 where project_id = ? and bidsection_id=? and contract_id=? ",
+		contractsPrice, contractDeductionTotal, contractStatus, projectId, bidsectionId, contractsId)
 	if err != nil {
 		session.Rollback()
 		return errors.New("金额更新失败")

+ 23 - 21
models/cm_tree_contracts.go

@@ -5,25 +5,27 @@ import (
 )
 
 type CmTreeContracts struct {
-	Id               int       `xorm:"not null pk autoincr comment('自增ID') INT(11)"`
-	TreeType         int       `xorm:"not null default 0 comment('项目节类型(0收入,1支出)') TINYINT(1)"`
-	TreeId           int       `xorm:"not null comment('树ID') INT(11)"`
-	ParentId         int       `xorm:"not null default 0 comment('父级ID') INT(11)"`
-	Name             string    `xorm:"not null comment('名称') VARCHAR(64)"`
-	Code             string    `xorm:"comment('项目节编号') VARCHAR(32)"`
-	Depth            int       `xorm:"not null default 0 comment('深度') TINYINT(4)"`
-	Serial           int       `xorm:"not null default 0 comment('序号') INT(11)"`
-	Attribution      string    `xorm:"comment('归属') VARCHAR(32)"`
-	Sort             int       `xorm:"not null default 0 comment('排序') TINYINT(4)"`
-	ProjectId        int       `xorm:"not null default 0 comment('项目ID') INT(11)"`
-	BidsectionId     int       `xorm:"comment('标段ID') INT(11)"`
-	ContractId       int       `xorm:"not null default 0 comment('合同ID') INT(11)"`
-	ContractName     string    `xorm:"comment('合同名称') VARCHAR(64)"`
-	ContractCode     string    `xorm:"comment('合同编号') VARCHAR(32)"`
-	ContractPrice    string    `xorm:"not null default 0.00 comment('合同金额') DECIMAL(12,2)"`
-	ContractReturned string    `xorm:"not null default 0.00 comment('回款金额') DECIMAL(12,2)"`
-	ContractsPaid    string    `xorm:"not null default 0.00 comment('合同已支付金额') DECIMAL(12,2)"`
-	ContractStatus   int       `xorm:"not null default 0 comment('合同状态(0履行中1待关闭2正常关闭)') TINYINT(1)"`
-	ContractLocking  int       `xorm:"not null default 0 comment('合同锁定(0未锁定1锁定)') TINYINT(1)"`
-	CreateTime       time.Time `xorm:"comment('创建时间') DATETIME"`
+	Id                     int       `xorm:"not null pk autoincr comment('自增ID') INT(11)"`
+	TreeType               int       `xorm:"not null default 0 comment('项目节类型(0收入,1支出)') TINYINT(1)"`
+	TreeId                 int       `xorm:"not null comment('树ID') INT(11)"`
+	ParentId               int       `xorm:"not null default 0 comment('父级ID') INT(11)"`
+	Name                   string    `xorm:"not null comment('名称') VARCHAR(64)"`
+	Code                   string    `xorm:"comment('项目节编号') VARCHAR(32)"`
+	Depth                  int       `xorm:"not null default 0 comment('深度') TINYINT(4)"`
+	Serial                 int       `xorm:"not null default 0 comment('序号') INT(11)"`
+	Attribution            string    `xorm:"comment('归属') VARCHAR(32)"`
+	Sort                   int       `xorm:"not null default 0 comment('排序') TINYINT(4)"`
+	ProjectId              int       `xorm:"not null default 0 comment('项目ID') INT(11)"`
+	BidsectionId           int       `xorm:"comment('标段ID') INT(11)"`
+	ContractId             int       `xorm:"not null default 0 comment('合同ID') INT(11)"`
+	ContractName           string    `xorm:"comment('合同名称') VARCHAR(64)"`
+	ContractCode           string    `xorm:"comment('合同编号') VARCHAR(32)"`
+	ContractPrice          string    `xorm:"not null default 0.00 comment('合同金额') DECIMAL(12,2)"`
+	ContractReturned       string    `xorm:"not null default 0.00 comment('回款金额') DECIMAL(12,2)"`
+	ContractsPaid          string    `xorm:"not null default 0.00 comment('合同已支付金额') DECIMAL(12,2)"`
+	ContractDeductionTotal string    `xorm:"not null default 0.00 comment('扣款金额合计') DECIMAL(12,2)"`
+	ContractStatus         int       `xorm:"not null default 0 comment('合同状态(0履行中1待关闭2正常关闭)') TINYINT(1)"`
+	ContractLocking        int       `xorm:"not null default 0 comment('合同锁定(0未锁定1锁定)') TINYINT(1)"`
+	SettlementCode         string    `xorm:"comment('结算书编号') VARCHAR(255)"`
+	CreateTime             time.Time `xorm:"comment('创建时间') DATETIME"`
 }

+ 4 - 0
services/contract_paid_service.go

@@ -58,8 +58,10 @@ func (s *contractService) PaidCreate(returnData *viewmodels.ContractsPaid, proje
 	contractDeductionPrice := decimal.NewFromFloat(returnData.ContractDeduction)
 	contractPrice, _ := decimal.NewFromString(contract.Price)
 	paidPrice, _ := decimal.NewFromString(contract.Paid)
+	paidContractDeductionTotal, _ := decimal.NewFromString(contract.ContractDeductionTotal)
 	resultPrice := contractPrice.Sub(paidPrice)
 	resultPrice = resultPrice.Add(contractDeductionPrice)
+	resultPrice = resultPrice.Add(paidContractDeductionTotal)
 
 	//  合同额-已支付金额+已扣款金额
 	if price.GreaterThan(resultPrice) {
@@ -128,6 +130,7 @@ func (s *contractService) PaidUpdate(returnData *viewmodels.ContractsPaid, proje
 	// }
 	contractPrice, _ := decimal.NewFromString(contract.Price)
 	paidPrice, _ := decimal.NewFromString(contract.Paid)
+	paidContractDeductionTotal, _ := decimal.NewFromString(contract.ContractDeductionTotal)
 	// 当前回款金额
 	returnedPresentPrice, _ := decimal.NewFromString(contractPaid.Price)
 	// 合同金额-(回款总金额-当前回款金额)
@@ -135,6 +138,7 @@ func (s *contractService) PaidUpdate(returnData *viewmodels.ContractsPaid, proje
 	subPrice := paidPrice.Sub(returnedPresentPrice)
 	// 合同金额-subPrice
 	resultPrice := contractPrice.Sub(subPrice)
+	resultPrice = resultPrice.Add(paidContractDeductionTotal)
 
 	if price.GreaterThan(resultPrice) {
 		return errors.New("支付金额不能超过合同金额")

+ 3 - 3
services/tree_service.go

@@ -24,7 +24,7 @@ import (
 	"go.mod/web/viewmodels"
 )
 
-//定义项目Service接口
+// 定义项目Service接口
 type TreeService interface {
 	//ValidManager(code string, account string, password string) error
 	ValidRule(ctx iris.Context) (viewmodels.Tree, error)
@@ -40,13 +40,13 @@ type TreeService interface {
 	Move(id int, moveId int, projectId int) error
 }
 
-//返回service操作类
+// 返回service操作类
 type treeService struct {
 	dao                  *dao.TreeDao
 	permissionAccountDao *dao.PermissionAccountDao
 }
 
-//创建项目service
+// 创建项目service
 func NewTreeService() TreeService {
 	return &treeService{
 		dao:                  dao.NewTreeDao(datasource.InstanceDbMaster()),