|
@@ -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
|
|
|
}
|