Browse Source

无代付至有代付的开票登记处理

hsun 2 years ago
parent
commit
f75c94c699
2 changed files with 18 additions and 0 deletions
  1. 11 0
      controller/contract/register.go
  2. 7 0
      models/fms/contract_invoice.go

+ 11 - 0
controller/contract/register.go

@@ -14,6 +14,7 @@ import (
 	"hongze/fms_api/models/crm"
 	"hongze/fms_api/models/fms"
 	"hongze/fms_api/models/system"
+	"hongze/fms_api/services/alarm_msg"
 	fmsService "hongze/fms_api/services/fms"
 	"hongze/fms_api/utils"
 	"net/http"
@@ -344,6 +345,7 @@ func (rg *RegisterController) Edit(c *gin.Context) {
 		resp.Fail("合同编号已存在", c)
 		return
 	}
+	originHasPayment := item.HasPayment
 
 	updateCols := []string{
 		"ContractCode", "RelateContractCode", "CrmContractId", "ContractSource", "CompanyName", "ActualCompanyName",
@@ -390,6 +392,15 @@ func (rg *RegisterController) Edit(c *gin.Context) {
 		return
 	}
 
+	// 若从无代付修改为有代付, 则删除无代付期间新增的所有开票/到款登记(此情况并不经常出现, 但是可能会存在这种操作)
+	if originHasPayment == 0 && req.HasPayment == 1 {
+		go func() {
+			if e = fms.DeleteContractInvoicesByRegisterId(item.ContractRegisterId); e != nil {
+				alarm_msg.SendAlarmMsg("无代付修改为有代付, 删除开票到款记录失败, ErrMsg: "+err.Error(), 3)
+			}
+		}()
+	}
+
 	// 校验金额-是否修改状态
 	go fmsService.CheckContractRegisterAmount(item.ContractRegisterId)
 

+ 7 - 0
models/fms/contract_invoice.go

@@ -200,3 +200,10 @@ func formatContractInvoice2Item(item *ContractInvoice) (formatItem *ContractInvo
 	formatItem.CreateTime = utils.TimeTransferString(utils.FormatDateTime, item.CreateTime)
 	return
 }
+
+// DeleteContractInvoicesByRegisterId 根据合同登记ID删除开票/到款记录
+func DeleteContractInvoicesByRegisterId(registerId int) (err error) {
+	sql := `UPDATE contract_invoice SET is_deleted = 1 WHERE contract_register_id = ?`
+	err = global.DEFAULT_MYSQL.Exec(sql, registerId).Error
+	return
+}