Browse Source

Merge branch 'dev/2.1'

hsun 2 years ago
parent
commit
a1c53acad9
2 changed files with 47 additions and 23 deletions
  1. 40 23
      controller/contract/register.go
  2. 7 0
      models/fms/invoice_payment_summary.go

+ 40 - 23
controller/contract/register.go

@@ -539,7 +539,12 @@ func (rg *RegisterController) Del(c *gin.Context) {
 	// 删除对应的开票到款登记
 	go func() {
 		if e = fms.DeleteContractInvoicesByRegisterId(item.ContractRegisterId); e != nil {
-			alarm_msg.SendAlarmMsg("删除合同登记后, 删除开票到款记录失败, ErrMsg: "+err.Error(), 3)
+			alarm_msg.SendAlarmMsg(fmt.Sprintf("删除合同登记%d后, 删除开票到款记录失败, ErrMsg: %s", item.ContractRegisterId, e.Error()), 3)
+			return
+		}
+		if e = fms.DeleteInvoicePaymentSummaryByRegisterId(item.ContractRegisterId); e != nil {
+			alarm_msg.SendAlarmMsg(fmt.Sprintf("删除合同登记%d后, 删除开票到款汇总数据失败, ErrMsg: %s", item.ContractRegisterId, e.Error()), 3)
+			return
 		}
 	}()
 
@@ -1100,7 +1105,7 @@ func (rg *RegisterController) Export(c *gin.Context) {
 	// 1行1列-右合并两格
 	cell1 := titleRow.AddCell()
 	cell1.HMerge = 3
-	cell1.SetString("FICC客户签约表  2022")
+	cell1.SetString("FICC客户签约表")
 	cell1.SetStyle(style)
 	// 右增两列空白格用于第一列合并, 否则后续单元格合并会有问题
 	titleRow.AddCell().SetString("")
@@ -1257,37 +1262,37 @@ func (rg *RegisterController) Export(c *gin.Context) {
 		// 开票/到款信息
 		ivList := invoiceMap[v.ContractRegisterId]
 		ivListLen := len(ivList)
-		if ivList != nil && len(ivList) > 0 {
-			for ia := 0; ia < maxInvoice; ia++ {
-				if ia < ivListLen {
+		for ia := 0; ia < maxInvoice; ia++ {
+			if ia < ivListLen {
+				if ivList != nil && ivList[ia] != nil {
 					dataRow.AddCell().SetString(utils.TimeTransferString("2006/01/02", ivList[ia].InvoiceDate)) // 开票日
-					dataRow.AddCell().SetString(fmt.Sprint(ivList[ia].Amount))                                  // 开票金额
+					dataRow.AddCell().SetString(fmt.Sprint(ivList[ia].OriginAmount))                            // 开票金额
 					dataRow.AddCell().SetString(ivList[ia].SellerName)                                          // 销售名称
 					dataRow.AddCell().SetString(ivList[ia].Remark)                                              // 开票备注
-				} else {
-					// 这里要把不够的填充为空
-					dataRow.AddCell().SetString("")
-					dataRow.AddCell().SetString("")
-					dataRow.AddCell().SetString("")
-					dataRow.AddCell().SetString("")
+					continue
 				}
 			}
+			// 这里要把不够的填充为空
+			dataRow.AddCell().SetString("")
+			dataRow.AddCell().SetString("")
+			dataRow.AddCell().SetString("")
+			dataRow.AddCell().SetString("")
 		}
 		pyList := paymentMap[v.ContractRegisterId]
 		pyListLen := len(pyList)
-		if pyList != nil && pyListLen > 0 {
-			for ib := 0; ib < maxPayment; ib++ {
-				if ib < pyListLen {
+		for ib := 0; ib < maxPayment; ib++ {
+			if ib < pyListLen {
+				if pyList != nil && pyList[ib] != nil {
 					dataRow.AddCell().SetString(utils.TimeTransferString("2006/01/02", pyList[ib].InvoiceDate)) // 收款日
-					dataRow.AddCell().SetString(fmt.Sprint(pyList[ib].Amount))                                  // 收款金额
+					dataRow.AddCell().SetString(fmt.Sprint(pyList[ib].OriginAmount))                            // 收款金额
 					dataRow.AddCell().SetString(pyList[ib].Remark)                                              // 收款备注
-				} else {
-					// 已经是最后的几列了其实可以不用填充空, 万一后面要加列此处还是填充上吧
-					dataRow.AddCell().SetString("")
-					dataRow.AddCell().SetString("")
-					dataRow.AddCell().SetString("")
+					continue
 				}
 			}
+			// 这里要把不够的填充为空
+			dataRow.AddCell().SetString("")
+			dataRow.AddCell().SetString("")
+			dataRow.AddCell().SetString("")
 		}
 	}
 
@@ -1981,7 +1986,13 @@ func (rg *RegisterController) Import(c *gin.Context) {
 									resp.Fail(fmt.Sprintf("第%d行开票金额%d有误, 请按模板导入", i+1, n), c)
 									return
 								}
-								rowInvoices[ir].Amount = amount
+								if rowRegister.RMBRate <= 0 {
+									resp.Fail(fmt.Sprintf("第%d行开票金额换算%d有误, 请按模板导入金额单位", i+1, n), c)
+									return
+								}
+								a, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", amount/rowRegister.RMBRate), 64)
+								rowInvoices[ir].OriginAmount = amount
+								rowInvoices[ir].Amount = a
 							}
 							continue
 						}
@@ -2049,12 +2060,18 @@ func (rg *RegisterController) Import(c *gin.Context) {
 									resp.Fail(fmt.Sprintf("第%d行到款金额%d有误, 请按模板导入", i+1, n), c)
 									return
 								}
+								if rowRegister.RMBRate <= 0 {
+									resp.Fail(fmt.Sprintf("第%d行到款金额换算%d有误, 请按模板导入金额单位", i+1, n), c)
+									return
+								}
 								// 付款方式
 								dayDiff := rowRegister.EndDate.Sub(rowRegister.StartDate).Hours() / 24
 								contractAmount := rowRegister.ContractAmount
 								payType := fmsService.CalculateContractPaymentType(amount, contractAmount, dayDiff)
-								rowPayments[ir].Amount = amount
 								rowPayments[ir].PayType = payType
+								rowPayments[ir].OriginAmount = amount
+								a, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", amount/rowRegister.RMBRate), 64)
+								rowPayments[ir].Amount = a
 							}
 							continue
 						}

+ 7 - 0
models/fms/invoice_payment_summary.go

@@ -146,3 +146,10 @@ func GetSummaryListCurrencySum(condition string, pars []interface{}, amountType
 	err = query.Find(&results).Error
 	return
 }
+
+// DeleteInvoicePaymentSummaryByRegisterId 根据合同登记ID删除汇总数据
+func DeleteInvoicePaymentSummaryByRegisterId(registerId int) (err error) {
+	sql := `DELETE FROM invoice_payment_summary WHERE register_id = ?`
+	err = global.DEFAULT_MYSQL.Exec(sql, registerId).Error
+	return
+}