Pārlūkot izejas kodu

Merge branch 'master' into debug

ziwen 1 gadu atpakaļ
vecāks
revīzija
c13c2120df

+ 24 - 7
controller/census/invoice_payment.go

@@ -1035,17 +1035,17 @@ func getCensusIncomeListV2(ch chan models.CensusIncomeChartResp, req fms.IncomeL
 
 	if req.SellerIds != "" {
 		sellerIds := strings.Split(req.SellerIds, ",")
-		cond += ` AND (a.seller_id in ? )`
-		historyCond += ` AND (seller_id in ? )`
+		cond += ` AND (a.seller_id in ? ) `
+		historyCond += ` AND (seller_id in ? ) `
 		pars = append(pars, sellerIds)
 		historyPars = append(historyPars, sellerIds)
 	}
 	if req.CompanyType == 1 {
 		cond += ` AND b.contract_type = 1 `
-		historyCond += ` AND new_company = 1`
+		historyCond += ` AND new_company = 1 `
 	} else if req.CompanyType == 2 {
 		cond += ` AND b.contract_type IN (2,3,4) `
-		historyCond += ` AND new_company = 0`
+		historyCond += ` AND new_company = 0 `
 	}
 
 	var latestTime time.Time
@@ -1731,7 +1731,7 @@ func (ct *InvoicePaymentController) NotInvoiceList(c *gin.Context) {
 				//fmt.Println("ContractRegisterId:", v.ContractRegisterId)
 				//fmt.Println("ServiceProductId:", v.ServiceProductId)
 				//fmt.Println("RegisterId:", v.RegisterId)
-				//fmt.Println("len(NotInvoiceSummaryMap[v.RegisterId]):", len(NotInvoiceSummaryMap[v.ContractRegisterId]))
+				fmt.Println("len(NotInvoiceSummaryMap[v.RegisterId]):", len(NotInvoiceSummaryMap[v.ContractRegisterId]))
 				if (v.ProductIds == "1,2" || v.ProductIds == "2,1") && len(NotInvoiceSummaryMap[v.ContractRegisterId]) == 1 {
 					// 套餐是ficc权益都有的,但是只有一个套餐有过开票到款,手动补充另一个套餐的信息
 					if v.ServiceProductId == 1 {
@@ -1848,11 +1848,28 @@ func (ct *InvoicePaymentController) NotInvoiceList(c *gin.Context) {
 					//fmt.Println("v.ContractRegisterId", v.ContractRegisterId)
 					//fmt.Println("v.ServiceProductId:", v.ServiceProductId)
 					//fmt.Println("v.NotInvoicedAmountTotal:", v.NotInvoicedAmountTotal)
+					//fmt.Println("registerId:",registerId)
 					if v.NotInvoicedAmountTotal == 0 {
 						if v.InvoiceAmountTotal > v.PaymentAmountTotal {
-							v.NotInvoicedAmountTotal = serviceAmountMap[registerId][v.ServiceProductId].ServiceAmount - v.InvoiceAmountTotal
+							// 有合规登记或补录合同过的,有serviceAmountMap信息
+							if _,ok := serviceAmountMap[registerId]; ok {
+								if _,ok2 := serviceAmountMap[registerId][v.ServiceProductId]; ok2{
+									v.NotInvoicedAmountTotal = serviceAmountMap[registerId][v.ServiceProductId].ServiceAmount - v.InvoiceAmountTotal
+								}
+							} else {
+								// 预登记没有合同套餐金额信息
+								v.NotInvoicedAmountTotal = v.InvoiceAmountTotal - v.PaymentAmountTotal
+							}
 						} else {
-							v.NotInvoicedAmountTotal = serviceAmountMap[registerId][v.ServiceProductId].ServiceAmount - v.PaymentAmountTotal
+							if _,ok := serviceAmountMap[registerId]; ok {
+								// 有合规登记或补录合同过的,有serviceAmountMap信息
+								if _,ok2 := serviceAmountMap[registerId][v.ServiceProductId]; ok2{
+									v.NotInvoicedAmountTotal = serviceAmountMap[registerId][v.ServiceProductId].ServiceAmount - v.PaymentAmountTotal
+								}
+							} else {
+								// 预登记没有合同套餐金额信息
+								v.NotInvoicedAmountTotal = v.PaymentAmountTotal - v.InvoiceAmountTotal
+							}
 						}
 					}
 					// 补充销售信息

+ 2 - 2
controller/contract/register.go

@@ -1489,7 +1489,7 @@ func (rg *RegisterController) Invoice(c *gin.Context) {
 				if req.InvoiceType == fms.ContractInvoiceTypeMake {
 					//修改对应到款的销售
 					summaryItem, err := fms.GetInvoicePaymentSummaryByRegisterIdAndInvoiceId(req.ContractRegisterId, req.AmountList[i].InvoiceId)
-					if err != nil {
+					if err != nil && err != utils.ErrNoRow {
 						resp.FailMsg("获取汇总数据失败", "修改到款销售时获取汇总数据失败, Err: "+err.Error(), c)
 						return
 					}
@@ -1655,7 +1655,7 @@ func (rg *RegisterController) Invoice(c *gin.Context) {
 	if len(newInvoice) > 0 && req.InvoiceType == fms.ContractInvoiceTypeMake {
 		for _, invoice := range newInvoice {
 			summaryItem, err := fms.GetInvoicePaymentSummaryByRegisterIdAndInvoiceId(req.ContractRegisterId, invoice.ContractInvoiceId)
-			if err != nil {
+			if err != nil && err != utils.ErrNoRow {
 				resp.FailMsg("获取汇总数据失败", "修改到款销售时获取汇总数据失败, Err: "+err.Error(), c)
 				return
 			}

+ 1 - 1
models/fms/contract_income_history.go

@@ -54,7 +54,7 @@ func GetLatestHistoryIncome(condition string, pars []interface{}) (result *Contr
 FROM
 	contract_income_history WHERE 1=1 `
 	sql += condition
-	sql += `ORDER BY invoice_time DESC  `
+	sql += ` ORDER BY invoice_time DESC  `
 	err = global.DEFAULT_MYSQL.Raw(sql, pars...).First(&result).Error
 	return
 }

+ 2 - 2
models/fms/invoice_payment_summary.go

@@ -227,14 +227,14 @@ type InvoiceSummary struct {
 // GetInvoiceCensusPageList 获取未开票统计列表-总数
 func GetInvoiceCensusPageList(page base.IPage, condition string, pars []interface{}) (results []*InvoiceSummary, count int64, err error) {
 	query := global.DEFAULT_MYSQL.Table("contract_register AS b").
-		Select("b.*, a.id as summary_id, IF(a.invoice_id >0, 1,0) as sort_invoice_id, IF(a.payment_id >0, 1,0) as sort_payment_id, COALESCE(SUM( c.amount ),0) AS invoiced_amount_count,COALESCE(SUM( d.amount ),0) AS payment_amount_count ").
+		Select("b.*, a.id as summary_id, IF(a.invoice_id >0, 1,0) as sort_invoice_id, IF(a.payment_id >0, 1,0) as sort_payment_id, COALESCE(SUM( c.origin_amount ),0) AS invoiced_amount_count,COALESCE(SUM( d.origin_amount ),0) AS payment_amount_count ").
 		Joins("left JOIN invoice_payment_summary AS a ON a.register_id = b.contract_register_id AND b.is_deleted = 0").
 		Joins("LEFT JOIN contract_invoice AS c ON a.invoice_id = c.contract_invoice_id AND c.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("contract_register_id")
 
 	nq := global.DEFAULT_MYSQL.Table("(?) AS e", query).
-		Select("*").Where(" e.invoiced_amount_count <>  e.contract_amount ")
+		Select("*").Where(" (e.invoiced_amount_count <> e.contract_amount AND e.contract_amount <> 0) OR (e.contract_amount = 0 AND e.invoiced_amount_count <> e.payment_amount_count)")
 	nq.Count(&count)
 	if len(page.GetOrderItemsString()) > 0 {
 		nq = nq.Order(page.GetOrderItemsString())