ziwen 1 vuosi sitten
vanhempi
commit
327acea4d5

+ 72 - 49
controller/contract/pre_register.go

@@ -219,7 +219,7 @@ func (rg *PreRegisterController) Add(c *gin.Context) {
 		resp.FailMsg("操作失败", "新增合同失败, Err: "+e.Error(), c)
 		return
 	}
-	if ob.ContractRegisterId == 0{
+	if ob.ContractRegisterId == 0 {
 		resp.FailMsg("操作失败", "新增合同失败,合同ID为0", c)
 		return
 	}
@@ -274,21 +274,19 @@ func (rg *PreRegisterController) Add(c *gin.Context) {
 		a, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", v.OriginAmount/rate), 64)
 		v.Amount = a
 
-		if req.RegisterType == fms.ContractInvoiceTypePreMake {
-			sellerItem := sellerMap[r.SellerId]
-			if sellerItem == nil {
-				resp.Fail("销售信息异常", c)
-				return
-			}
-
-			v.SellerId = sellerItem.SellerId
-			v.SellerName = sellerItem.SellerName
-			v.SellerGroupId = sellerItem.GroupId
-			v.SellerGroupName = sellerItem.GroupName
-			v.SellerTeamId = sellerItem.TeamId
-			v.SellerTeamName = sellerItem.TeamName
+		sellerItem := sellerMap[r.SellerId]
+		if sellerItem == nil {
+			resp.Fail("销售信息异常", c)
+			return
 		}
 
+		v.SellerId = sellerItem.SellerId
+		v.SellerName = sellerItem.SellerName
+		v.SellerGroupId = sellerItem.GroupId
+		v.SellerGroupName = sellerItem.GroupName
+		v.SellerTeamId = sellerItem.TeamId
+		v.SellerTeamName = sellerItem.TeamName
+
 		// 新增开票到款记录
 		if e = v.Create(); e != nil {
 			resp.FailMsg("操作失败", "新增预登记失败, Err: "+e.Error(), c)
@@ -360,7 +358,7 @@ func (rg *PreRegisterController) Add(c *gin.Context) {
 		}
 
 		// 新增开票到款记录
-		if pp.ContractRegisterId == 0{
+		if pp.ContractRegisterId == 0 {
 			resp.FailMsg("操作失败", "新增预登记失败,合同ID为0", c)
 			return
 		}
@@ -538,21 +536,19 @@ func (rg *PreRegisterController) Edit(c *gin.Context) {
 		a, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", v.OriginAmount/rate), 64)
 		v.Amount = a
 
-		if req.RegisterType == fms.ContractInvoiceTypePreMake {
-			sellerItem := sellerMap[r.SellerId]
-			if sellerItem == nil {
-				resp.Fail("销售信息异常", c)
-				return
-			}
-
-			v.SellerId = sellerItem.SellerId
-			v.SellerName = sellerItem.SellerName
-			v.SellerGroupId = sellerItem.GroupId
-			v.SellerGroupName = sellerItem.GroupName
-			v.SellerTeamId = sellerItem.TeamId
-			v.SellerTeamName = sellerItem.TeamName
+		sellerItem := sellerMap[r.SellerId]
+		if sellerItem == nil {
+			resp.Fail("销售信息异常", c)
+			return
 		}
 
+		v.SellerId = sellerItem.SellerId
+		v.SellerName = sellerItem.SellerName
+		v.SellerGroupId = sellerItem.GroupId
+		v.SellerGroupName = sellerItem.GroupName
+		v.SellerTeamId = sellerItem.TeamId
+		v.SellerTeamName = sellerItem.TeamName
+
 		//预登记列表
 		pp := &fms.ContractPreRegister{
 			PreRegisterId:      r.PreRegisterId,
@@ -599,7 +595,7 @@ func (rg *PreRegisterController) Edit(c *gin.Context) {
 			pp.PaymentSellerTeamName = sellerItem.TeamName
 			ppUpdateCols = append(ppUpdateCols, "InvoiceDate", "Amount", "OriginAmount", "SellerId",
 				"SellerName", "SellerGroupId", "SellerGroupName", "SellerTeamId", "SellerTeamName", "InvoiceId",
-				"PaymentSellerId","PaymentSellerName","PaymentSellerGroupId","PaymentSellerGroupName","PaymentSellerTeamId","PaymentSellerTeamName")
+				"PaymentSellerId", "PaymentSellerName", "PaymentSellerGroupId", "PaymentSellerGroupName", "PaymentSellerTeamId", "PaymentSellerTeamName")
 		} else {
 			//到款
 			pp.ArriveRemark = r.Remark
@@ -615,7 +611,6 @@ func (rg *PreRegisterController) Edit(c *gin.Context) {
 				return
 			}
 
-
 			pp.PaymentSellerId = sellerItem.SellerId
 			pp.PaymentSellerName = sellerItem.SellerName
 			pp.PaymentSellerGroupId = sellerItem.GroupId
@@ -623,7 +618,7 @@ func (rg *PreRegisterController) Edit(c *gin.Context) {
 			pp.PaymentSellerTeamId = sellerItem.TeamId
 			pp.PaymentSellerTeamName = sellerItem.TeamName
 			ppUpdateCols = append(ppUpdateCols, "CurrencyUnit", "ArriveDate", "ArriveAmount", "ArriveOriginAmount", "ArriveId",
-				"PaymentSellerId","PaymentSellerName","PaymentSellerGroupId","PaymentSellerGroupName","PaymentSellerTeamId","PaymentSellerTeamName")
+				"PaymentSellerId", "PaymentSellerName", "PaymentSellerGroupId", "PaymentSellerGroupName", "PaymentSellerTeamId", "PaymentSellerTeamName")
 		}
 
 		if pp.PreRegisterId == 0 {
@@ -647,7 +642,7 @@ func (rg *PreRegisterController) Edit(c *gin.Context) {
 	}
 	invoiceUpdateCols := []string{
 		"CurrencyUnit", "OriginAmount", "Amount", "InvoiceDate", "AdminId", "AdminName", "Remark",
-		"ServiceProductId", "StartDate", "EndDate", "ModifyTime",
+		"ServiceProductId", "StartDate", "EndDate", "ModifyTime","SellerId", "SellerName", "SellerGroupId","SellerGroupName","SellerTeamId","SellerTeamName",
 	}
 	// 更新合同登记、套餐、开票到款
 	if e = fms.UpdateContractPreRegister(ob, updateCols, serviceList, invoiceList, invoiceUpdateCols, req.DelInvoiceIds, req.DelPreRegisterIds, ppList); e != nil {
@@ -833,6 +828,15 @@ func (rg *PreRegisterController) Detail(c *gin.Context) {
 		return
 	}
 
+	dupList, e := fms.GetDuplicateContractInvoiceDetailItemList(nItme.CompanyName, nItme.StartDate, nItme.EndDate)
+	if e != nil {
+		err = fmt.Errorf("获取开票到款列表失败, Err: %s", e.Error())
+		return
+	}
+
+	list = append(list, dupList...)
+
+
 	//获取ficc小套餐品种
 	sysConf := new(system.SysConfig)
 	confCond := `config_code = ?`
@@ -1071,23 +1075,21 @@ func (rg *PreRegisterController) Save(c *gin.Context) {
 		a, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", v.OriginAmount/rate), 64)
 		v.Amount = a
 
-		if req.RegisterType == fms.ContractInvoiceTypePreMake {
-			sellerItem := sellerMap[r.SellerId]
-			if sellerItem == nil {
-				resp.Fail("销售信息异常", c)
-				return
-			}
-
-			v.SellerId = sellerItem.SellerId
-			v.SellerName = sellerItem.SellerName
-			v.SellerGroupId = sellerItem.GroupId
-			v.SellerGroupName = sellerItem.GroupName
-			v.SellerTeamId = sellerItem.TeamId
-			v.SellerTeamName = sellerItem.TeamName
-			invoiceUpdateCols = append(invoiceUpdateCols, "SellerId", "SellerName", "SellerGroupId",
-				"SellerGroupName", "SellerTeamId", "SellerTeamName")
+		sellerItem := sellerMap[r.SellerId]
+		if sellerItem == nil {
+			resp.Fail("销售信息异常", c)
+			return
 		}
 
+		v.SellerId = sellerItem.SellerId
+		v.SellerName = sellerItem.SellerName
+		v.SellerGroupId = sellerItem.GroupId
+		v.SellerGroupName = sellerItem.GroupName
+		v.SellerTeamId = sellerItem.TeamId
+		v.SellerTeamName = sellerItem.TeamName
+		invoiceUpdateCols = append(invoiceUpdateCols, "SellerId", "SellerName", "SellerGroupId",
+			"SellerGroupName", "SellerTeamId", "SellerTeamName")
+
 		// 新增开票到款记录
 		if v.ContractInvoiceId != 0 {
 			//更新
@@ -1138,8 +1140,15 @@ func (rg *PreRegisterController) Save(c *gin.Context) {
 			pp.SellerGroupName = sellerItem.GroupName
 			pp.SellerTeamId = sellerItem.TeamId
 			pp.SellerTeamName = sellerItem.TeamName
+			pp.PaymentSellerId = sellerItem.SellerId
+			pp.PaymentSellerName = sellerItem.SellerName
+			pp.PaymentSellerGroupId = sellerItem.GroupId
+			pp.PaymentSellerGroupName = sellerItem.GroupName
+			pp.PaymentSellerTeamId = sellerItem.TeamId
+			pp.PaymentSellerTeamName = sellerItem.TeamName
 			ppUpdateCols = append(ppUpdateCols, "InvoiceDate", "Amount", "OriginAmount", "SellerId",
-				"SellerName", "SellerGroupId", "SellerGroupName", "SellerTeamId", "SellerTeamName", "Remark")
+				"SellerName", "SellerGroupId", "SellerGroupName", "SellerTeamId", "SellerTeamName", "Remark",
+				"PaymentSellerId", "PaymentSellerName", "PaymentSellerGroupId", "PaymentSellerGroupName", "PaymentSellerTeamId", "PaymentSellerTeamName")
 		} else {
 			//到款
 			pp.ArriveRemark = r.Remark
@@ -1147,7 +1156,21 @@ func (rg *PreRegisterController) Save(c *gin.Context) {
 			pp.ArriveOriginAmount = r.Amount
 			a, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", pp.ArriveOriginAmount/rate), 64)
 			pp.ArriveAmount = a
-			ppUpdateCols = append(ppUpdateCols, "ArriveRemark", "CurrencyUnit", "ArriveDate", "ArriveAmount", "ArriveOriginAmount")
+
+			sellerItem := sellerMap[r.SellerId]
+			if sellerItem == nil {
+				resp.Fail("销售信息异常", c)
+				return
+			}
+
+			pp.PaymentSellerId = sellerItem.SellerId
+			pp.PaymentSellerName = sellerItem.SellerName
+			pp.PaymentSellerGroupId = sellerItem.GroupId
+			pp.PaymentSellerGroupName = sellerItem.GroupName
+			pp.PaymentSellerTeamId = sellerItem.TeamId
+			pp.PaymentSellerTeamName = sellerItem.TeamName
+			ppUpdateCols = append(ppUpdateCols, "ArriveRemark", "CurrencyUnit", "ArriveDate", "ArriveAmount", "ArriveOriginAmount",
+				"PaymentSellerId", "PaymentSellerName", "PaymentSellerGroupId", "PaymentSellerGroupName", "PaymentSellerTeamId", "PaymentSellerTeamName")
 		}
 
 		ppUpdateCols = append(ppUpdateCols,

+ 1 - 1
controller/contract/register.go

@@ -1939,7 +1939,7 @@ func (rg *RegisterController) Export(c *gin.Context) {
 					dataRow.AddCell().SetString(utils.TimeTransferString("2006/01/02", pyList[ib].InvoiceDate)) // 收款日
 					dataRow.AddCell().SetString(fmt.Sprint(pyList[ib].OriginAmount))                            // 收款金额
 					dataRow.AddCell().SetString(serviceProductIdMap[pyList[ib].ServiceProductId])               // 套餐类型
-					dataRow.AddCell().SetString(ivList[ib].SellerName)                                          // 销售名称
+					dataRow.AddCell().SetString(pyList[ib].SellerName)                                          // 销售名称
 					dataRow.AddCell().SetString(pyList[ib].Remark)                                              // 收款备注
 					continue
 				}

+ 16 - 0
models/fms/contract_invoice.go

@@ -597,3 +597,19 @@ func (c *ContractInvoice) FetchByRegisterId(registerId int) (items []*ContractIn
 	err = global.DEFAULT_MYSQL.Model(c).Where("is_deleted = 0 AND contract_register_id = ?", registerId).Scan(&items).Error
 	return
 }
+
+// GetDuplicateContractInvoiceDetailItemList 预登记列表详情用-获取开票到款列表
+func GetDuplicateContractInvoiceDetailItemList(companyName, startDate, endDate string) (itemList []*ContractInvoiceDetailItem, err error) {
+	list := make([]*ContractInvoice, 0)
+	err = global.DEFAULT_MYSQL.Table("contract_invoice as a ").
+		Select(" a.* ").
+		Joins(" JOIN contract_register as b ON a.contract_register_id = b.contract_register_id ").
+		Where(fmt.Sprintf("a.is_deleted = 0 AND b.company_name = '%s' AND b.start_date= '%s' AND b.end_date= '%s' ",companyName, startDate, endDate)).
+		Order("a.contract_invoice_id ASC").
+		Find(&list).Error
+	if err != nil {
+		return
+	}
+	itemList = formatContractInvoice2DetailItemList(list)
+	return
+}

+ 48 - 17
models/fms/contract_register.go

@@ -656,6 +656,26 @@ func UpdateContractPreRegister(item *ContractRegister, updateCols []string, serv
 	}
 	tx.Model(&invoiceItem).Select([]string{"StartDate", "EndDate", "CurrencyUnit"}).Where("ContractRegisterId", item.ContractRegisterId).Updates(invoiceItem)
 
+	//pp := &ContractPreRegister{}
+	//ppItem, e := pp.Fetch(ppList[0].PreRegisterId)
+	//if e != nil {
+	//	err = e
+	//}
+	//otherInvoiceItem := ContractInvoice{}
+	//if ppList[0].InvoiceType == ContractInvoiceTypePreMake {
+	//	otherInvoiceItem.ContractInvoiceId = ppItem.ArriveId
+	//	if ppItem.ArriveId > 0 {
+	//		//如果是开票类型,那么更新预登记里的预到款销售信息
+	//		otherInvoiceItem.SellerId = invoiceList[0].SellerId
+	//		otherInvoiceItem.SellerName = invoiceList[0].SellerName
+	//		otherInvoiceItem.SellerGroupId = invoiceList[0].SellerGroupId
+	//		otherInvoiceItem.SellerGroupName = invoiceList[0].SellerGroupName
+	//		otherInvoiceItem.SellerTeamId = invoiceList[0].SellerTeamId
+	//		otherInvoiceItem.SellerTeamName = invoiceList[0].SellerTeamName
+	//	}
+	//	tx.Model(&otherInvoiceItem).Select([]string{"SellerId", "SellerName", "SellerGroupId","SellerGroupName","SellerTeamId","SellerTeamName"}).Updates(otherInvoiceItem)
+	//}
+
 	//删除
 	if len(delInvoiceIds) > 0 {
 		for _, id := range delInvoiceIds {
@@ -735,6 +755,34 @@ func UpdateContractRegisterPre(item *ContractRegister, updateCols []string, serv
 		productId = invoiceList[0].ServiceProductId
 	}
 
+	pp := &ContractPreRegister{}
+	ppItem, e := pp.Fetch(ppList[0].PreRegisterId)
+	if e != nil {
+		err = e
+	}
+	//更新同一预登记记录下的productid
+	otherInvoiceItem := ContractInvoice{
+		ServiceProductId: productId,
+	}
+	if ppList[0].InvoiceType == ContractInvoiceTypePreMake {
+		otherInvoiceItem.ContractInvoiceId = ppItem.ArriveId
+		if ppItem.ArriveId > 0 {
+			//如果是开票类型,那么更新预登记里的预到款销售信息
+			otherInvoiceItem.SellerId = invoiceList[0].SellerId
+			otherInvoiceItem.SellerName = invoiceList[0].SellerName
+			otherInvoiceItem.SellerGroupId = invoiceList[0].SellerGroupId
+			otherInvoiceItem.SellerGroupName = invoiceList[0].SellerGroupName
+			otherInvoiceItem.SellerTeamId = invoiceList[0].SellerTeamId
+			otherInvoiceItem.SellerTeamName = invoiceList[0].SellerTeamName
+		}
+		tx.Model(&otherInvoiceItem).Select([]string{"ServiceProductId","SellerId", "SellerName", "SellerGroupId","SellerGroupName","SellerTeamId","SellerTeamName"}).Updates(otherInvoiceItem)
+	} else {
+		otherInvoiceItem.ContractInvoiceId = ppItem.InvoiceId
+		tx.Model(&otherInvoiceItem).Select([]string{"ServiceProductId"}).Updates(otherInvoiceItem)
+	}
+
+
+
 	//更新另一类型的invoice表数据
 	invoiceItem := ContractInvoice{
 		ContractRegisterId: item.ContractRegisterId,
@@ -779,23 +827,6 @@ func UpdateContractRegisterPre(item *ContractRegister, updateCols []string, serv
 		}
 	}
 
-	pp := &ContractPreRegister{}
-	ppItem, e := pp.Fetch(ppList[0].PreRegisterId)
-	if e != nil {
-		err = e
-	}
-	//更新同一预登记记录下的productid
-	otherInvoiceItem := ContractInvoice{
-		ServiceProductId: productId,
-	}
-	if ppList[0].InvoiceType == 3 {
-		otherInvoiceItem.ContractInvoiceId = ppItem.ArriveId
-	} else {
-		otherInvoiceItem.ContractInvoiceId = ppItem.InvoiceId
-	}
-
-	tx.Model(&otherInvoiceItem).Select([]string{"ServiceProductId"}).Updates(otherInvoiceItem)
-
 	return
 }