ziwen 1 年之前
父節點
當前提交
ccc5a10430
共有 2 個文件被更改,包括 11 次插入9 次删除
  1. 8 5
      controller/census/invoice_payment.go
  2. 3 4
      models/fms/invoice_payment_summary.go

+ 8 - 5
controller/census/invoice_payment.go

@@ -846,7 +846,7 @@ func (ct *InvoicePaymentController) List(c *gin.Context) {
 
 			amountCond := `a.id IN ? AND (a.invoice_id <> 0 OR (a.payment_id <> 0 AND a.invoice_id =0))`
 			amountPars := make([]interface{}, 0)
-			amountPars = append(amountTotalPars, summaryIds)
+			amountPars = append(amountPars, summaryIds)
 			amountSum, e := fms.GetContractSummaryInvoicePaymentAmount(amountCond, amountPars)
 			if e != nil {
 				totalErr = fmt.Errorf("获取汇总金额合计失败, Err: %s", e.Error())
@@ -1166,10 +1166,11 @@ func getCensusIncomeListV2(ch chan models.CensusIncomeChartResp, req fms.IncomeL
 				var amountTotal float64
 
 				if len(summaryIds) > 0 {
-					amountCond := `a.id IN ? AND (a.invoice_id <> 0 OR (a.payment_id <> 0 AND a.invoice_id =0))`
+					amountCond := `a.id IN ? `
 					amountPars := make([]interface{}, 0)
 					amountPars = append(amountPars, summaryIds)
-					amountCond += ` AND (b.invoice_time BETWEEN ? AND ?) OR (d.invoice_time BETWEEN ? AND ?)`
+					amountCond += ` AND ((a.invoice_id <> 0 AND b.invoice_time BETWEEN ? AND ?)`
+					amountCond += `OR (a.payment_id <> 0 AND a.invoice_id = 0 AND d.invoice_time BETWEEN ? AND ?))`
 					amountPars = append(amountPars, st, ed, st, ed)
 					results, e := fms.GetContractSummaryIncomeAmount(amountCond, amountPars)
 					if e != nil {
@@ -1181,6 +1182,7 @@ func getCensusIncomeListV2(ch chan models.CensusIncomeChartResp, req fms.IncomeL
 					for _, result := range results {
 						incomeChart.DataList = append(incomeChart.DataList, result)
 						amountSum += result.Amount
+						fmt.Println("result.Amount:",result.Amount)
 					}
 					amountTotal, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", amountSum), 64)
 					accumulate += amountTotal
@@ -1257,10 +1259,11 @@ func getCensusIncomeListV2(ch chan models.CensusIncomeChartResp, req fms.IncomeL
 				var prevAmountTotal float64
 
 				if len(prevSummaryIds) > 0 {
-					amountCond := `a.id IN ? AND (a.invoice_id <> 0 OR (a.payment_id <> 0 AND a.invoice_id =0))`
+					amountCond := `a.id IN ? `
 					amountPars := make([]interface{}, 0)
 					amountPars = append(amountPars, prevSummaryIds)
-					amountCond += ` AND (b.invoice_time BETWEEN ? AND ?) OR (d.invoice_time BETWEEN ? AND ?)`
+					amountCond += ` AND ((a.invoice_id <> 0 AND b.invoice_time BETWEEN ? AND ?)`
+					amountCond += `OR (a.payment_id <> 0 AND a.invoice_id = 0 AND d.invoice_time BETWEEN ? AND ?))`
 					amountPars = append(amountPars, prevSt, prevEd)
 					results, e := fms.GetContractSummaryIncomeAmount(amountCond, amountPars)
 					if e != nil {

+ 3 - 4
models/fms/invoice_payment_summary.go

@@ -167,11 +167,10 @@ func DeleteInvoicePaymentSummaryByInvoiceIdAndPaymentId(invoiceId, arriveId, reg
 
 // GetContractSummaryInvoicePaymentAmount 获取汇总金额合计信息
 func GetContractSummaryInvoicePaymentAmount(condition string, pars []interface{}) (amountTotal float64, err error) {
-	joinCond := ` (a.invoice_id = b.contract_invoice_id OR a.payment_id = b.contract_invoice_id) `
-
 	query := global.DEFAULT_MYSQL.Table("invoice_payment_summary AS a").
-		Select("b.amount").
-		Joins(fmt.Sprintf(" JOIN contract_invoice AS b ON %s AND b.is_deleted = 0 ", joinCond)).
+		Select("IF(a.invoice_id=0,d.amount, b.amount) AS amount").
+		Joins("LEFT JOIN contract_invoice AS b ON a.invoice_id = b.contract_invoice_id AND b.is_deleted = 0 ").
+		Joins("LEFT JOIN contract_invoice AS d ON a.payment_id = d.contract_invoice_id AND d.is_deleted = 0").
 		Where(condition, pars...).Group("id")
 	nq := global.DEFAULT_MYSQL.Table("(?) AS e", query).
 		Select(" IFNULL( SUM( e.amount ), 0 ) ")