ziwen hai 1 ano
pai
achega
f5590e1d72
Modificáronse 2 ficheiros con 60 adicións e 0 borrados
  1. 8 0
      controller/contract/pre_register.go
  2. 52 0
      services/fms/contract_register.go

+ 8 - 0
controller/contract/pre_register.go

@@ -399,6 +399,9 @@ func (rg *PreRegisterController) Add(c *gin.Context) {
 	// 开票到款汇总
 	go fmsService.SummaryInvoicePaymentByContractRegisterId(ob.ContractRegisterId)
 
+	//预登记后更新register表开票到款合计金额
+	go fmsService.CheckContractRegisterAmountAfterPre(ob.ContractRegisterId)
+
 	resp.Ok("操作成功", c)
 }
 
@@ -682,6 +685,8 @@ func (rg *PreRegisterController) Edit(c *gin.Context) {
 	// 开票到款汇总
 	go fmsService.SummaryInvoicePaymentByContractRegisterId(ob.ContractRegisterId)
 
+	//预登记后更新register表开票到款合计金额
+	go fmsService.CheckContractRegisterAmountAfterPre(ob.ContractRegisterId)
 	resp.Ok("操作成功", c)
 }
 
@@ -1233,5 +1238,8 @@ func (rg *PreRegisterController) Save(c *gin.Context) {
 	// 开票到款汇总
 	go fmsService.SummaryInvoicePaymentByContractRegisterId(ob.ContractRegisterId)
 
+	//预登记后更新register表开票到款合计金额
+	go fmsService.CheckContractRegisterAmountAfterPre(ob.ContractRegisterId)
+
 	resp.Ok("操作成功", c)
 }

+ 52 - 0
services/fms/contract_register.go

@@ -405,4 +405,56 @@ func GetContractServiceNameFormat(registerIds []int) (serviceNameMap map[int]str
 		serviceNameMap[k] = strings.Trim(serviceNameMap[k], ",")
 	}
 	return
+}
+
+// CheckContractRegisterAmountAfterPre 预登记后更新register表开票到款合计金额
+func CheckContractRegisterAmountAfterPre(registerId int) {
+	var err error
+	defer func() {
+		if err != nil {
+			alarm_msg.SendAlarmMsg("校验合同登记金额失败, ErrMsg: "+err.Error(), 3)
+		}
+	}()
+
+	// 获取合同登记信息
+	cr := new(fms.ContractRegister)
+	item, e := cr.Fetch(registerId)
+	if e != nil {
+		err = errors.New("获取合同登记信息失败, Err: " + e.Error())
+		return
+	}
+
+	// 获取开票/到款信息
+	invoiceCond := `contract_register_id = ?`
+	invoicePars := make([]interface{}, 0)
+	invoicePars = append(invoicePars, registerId)
+	ci := new(fms.ContractInvoice)
+	invoiceList, e := ci.List(invoiceCond, invoicePars, "")
+	if e != nil {
+		err = errors.New("获取开票到款信息失败, Err: " + e.Error())
+		return
+	}
+	invoiceAmount := decimal.NewFromFloat(0).Round(2)
+	paymentAmount := decimal.NewFromFloat(0).Round(2)
+	for i := range invoiceList {
+		a := decimal.NewFromFloat(invoiceList[i].OriginAmount).Round(2)
+		if invoiceList[i].InvoiceType == fms.ContractInvoiceTypePreMake {
+			invoiceAmount = invoiceAmount.Add(a)
+		}
+		if invoiceList[i].InvoiceType == fms.ContractInvoiceTypePrePay {
+			paymentAmount = paymentAmount.Add(a)
+		}
+	}
+
+	updateCols := []string{"InvoicedAmount", "PaymentAmount", "ModifyTime"}
+	ia, _ := invoiceAmount.Round(2).Float64()
+	pa, _ := paymentAmount.Round(2).Float64()
+	item.InvoicedAmount = ia
+	item.PaymentAmount = pa
+	item.ModifyTime = time.Now().Local()
+	if e = item.Update(updateCols); e != nil {
+		err = errors.New("更新合同登记金额及状态失败, Err: " + e.Error())
+		return
+	}
+	return
 }