Browse Source

到款统计导出

xiexiaoyuan 2 years ago
parent
commit
e1cae32a31

+ 73 - 6
controller/census/invoice_payment.go

@@ -327,7 +327,7 @@ func ExportInvoicePaymentCensusList(c *gin.Context, results *fms.InvoicePaymentC
 
 	// 表头, 套餐动态获取
 	rowTitle := []string{"序号", "客户名称", "是否新客户", "合同有效期", "开票日", "开票金额", "到款日", "到款金额", "付款方式", "销售",
-		"组别"}
+		"销售组别", "销售类型"}
 	serviceTempCond := ``
 	serviceTempPars := make([]interface{}, 0)
 	serviceTempOB := new(fms.ContractServiceTemplate)
@@ -336,18 +336,75 @@ func ExportInvoicePaymentCensusList(c *gin.Context, results *fms.InvoicePaymentC
 		resp.FailData("获取套餐模板列表失败", "Err:"+e.Error(), c)
 		return
 	}
+	serviceTempListMap := make(map[int]*fms.ContractServiceTemplate)
+	var serviceTempShow [] *fms.ContractServiceTemplate
 	for i := range serviceTempList {
-		rowTitle = append(rowTitle, serviceTempList[i].Title)
+		serviceTempListMap[serviceTempList[i].ServiceTemplateId] = serviceTempList[i]
+	}
+	for i := range serviceTempList {
+		if serviceTempList[i].ProductId == 1 {
+			rowTitle = append(rowTitle, serviceTempList[i].Title)
+			serviceTempShow = append(serviceTempShow, serviceTempList[i])
+		}else if serviceTempList[i].ProductId == 2{
+			if serviceTempList[i].Title == "行业套餐" ||  serviceTempList[i].Title == "45万" ||  serviceTempList[i].Title == "70万"{
+				continue
+			}
+			if serviceTempList[i].Pid > 0 &&  serviceTempListMap[serviceTempList[i].Pid].Pid > 0 {
+				continue
+			}
+			rowTitle = append(rowTitle, serviceTempList[i].Title)
+			serviceTempShow = append(serviceTempShow, serviceTempList[i])
+		}
 	}
 
+	hi := 0
+	insertHi := 0
 	titleRow := sheet.AddRow()
 	for i := range rowTitle {
 		v := titleRow.AddCell()
 		v.SetString(rowTitle[i])
 		v.SetStyle(style)
+		if rowTitle[i] != "权益大套餐" && rowTitle[i] != "医药" && rowTitle[i] != "消费" && rowTitle[i] != "科技" && rowTitle[i] != "智造" {
+			v.VMerge = 1
+			hi ++
+		}else{
+			if insertHi == 0 {
+				insertHi = hi
+			}
+			v.HMerge = 1
+			titleRow.AddCell().SetString("")
+		}
+	}
+
+	// 新增一行放主观和客观
+	specialRow := sheet.AddRow()
+	for i:=0; i< hi; i++ {
+		if i == insertHi {
+			v1 := specialRow.AddCell()
+			v1.SetString("45万")
+			v1.SetStyle(style)
+			v1 = specialRow.AddCell()
+			v1.SetString("70万")
+			v1.SetStyle(style)
+			for j:=0; j<8;j++ {
+				if j%2 ==0 {
+					v1 = specialRow.AddCell()
+					v1.SetString("主观")
+					v1.SetStyle(style)
+				}else{
+					v1 = specialRow.AddCell()
+					v1.SetString("客观")
+					v1.SetStyle(style)
+				}
+			}
+		}else{
+			v := specialRow.AddCell()
+			v.SetString("")
+		}
 	}
 
 	newCompanyMap := map[int]string{0: "否", 1: "是"}
+	sellerTypeMap := map[int]string{1:"FICC销售", 2:"权益销售"}
 	for k, v := range list {
 		dataRow := sheet.AddRow()
 		// 前四个单元格根据每行开票到款条数向下合并
@@ -380,14 +437,22 @@ func ExportInvoicePaymentCensusList(c *gin.Context, results *fms.InvoicePaymentC
 				fms.ContractPaymentPayTypeNameMap[v2.PayType], // 付款方式
 				v2.SellerName,                                 // 销售
 				v2.SellerGroupName,                            // 组别
+				sellerTypeMap[v2.SellerType],                  // 销售类型
 			}
 			// 套餐金额信息
-			for i := range serviceTempList {
+			for i := range serviceTempShow {
 				sa := ""
 				for s2 := range v2.ServiceAmountList {
-					if v2.ServiceAmountList[s2].ServiceTemplateId == serviceTempList[i].ServiceTemplateId {
-						sa = fmt.Sprint(v2.ServiceAmountList[s2].Amount)
-						break
+					item := v2.ServiceAmountList[s2]
+					if item.ServiceTemplateId == serviceTempList[i].ServiceTemplateId {
+						if serviceTempList[i].Title == "医药" || serviceTempList[i].Title == "消费" {
+							// todo 则需要查询对应的主观和客观的金额
+
+							break
+						}else{
+							sa = fmt.Sprint(v2.ServiceAmountList[s2].Amount)
+							break
+						}
 					}
 				}
 				rowData = append(rowData, sa)
@@ -839,3 +904,5 @@ func (ct *InvoicePaymentController) List(c *gin.Context) {
 	baseData.SetList(results)
 	resp.OkData("获取成功", baseData, c)
 }
+
+

+ 0 - 4
controller/contract/payment.go

@@ -74,10 +74,6 @@ func (ct *PaymentController) DistributePaymentServiceAmount(c *gin.Context) {
 
 	addList := make([]*fms.ContractPaymentServiceAmount, 0)
 	// todo 判断是否符合均分金额的条件
-	/*templateIds := make([]int)
-	for i := range req.List {
-
-	}*/
 	for i := range req.List {
 		if req.List[i].Amount <= 0 {
 			continue

+ 82 - 10
controller/contract/register.go

@@ -232,6 +232,39 @@ func (rg *RegisterController) Add(c *gin.Context) {
 		return
 	}
 
+	// 查询销售信息
+	var (
+		sellerId int
+		raiSellerId int
+		sellerName string
+		raiSellerName string
+	)
+
+	if req.SellerIds != "" {
+		admin := new(crm.Admin)
+		sellerIds := strings.Split(req.SellerIds, ",")
+		if len(sellerIds) > 2 {
+			resp.Fail("最多只能选择两个销售", c)
+			return
+		}
+		var pars []interface{}
+		cond := ` admin_id in (?) `
+		pars = append(pars, sellerIds)
+		sellers, e := admin.List(cond, pars)
+		if e != nil {
+			resp.FailMsg("获取销售信息失败", "获取销售信息失败, Err: "+e.Error(), c)
+			return
+		}
+		for _, v := range sellers {
+			if v.DepartmentId == crm.SellerDepartmentId {
+				sellerId = v.AdminId
+				sellerName = v.AdminName
+			}else if v.DepartmentId == crm.RaiSellerDepartmentId {
+				raiSellerId = v.AdminId
+				raiSellerName = v.AdminName
+			}
+		}
+	}
 	nowTime := time.Now().Local()
 	ob.ContractCode = req.ContractCode
 	ob.RelateContractCode = req.RelateContractCode
@@ -240,10 +273,10 @@ func (rg *RegisterController) Add(c *gin.Context) {
 	ob.CompanyName = req.CompanyName
 	ob.ActualCompanyName = req.ActualCompanyName
 	ob.ProductIds = req.ProductIds
-	ob.SellerId = req.SellerId
-	ob.SellerName = req.SellerName
-	ob.RaiSellerId = req.RaiSellerId
-	ob.RaiSellerName = req.RaiSellerName
+	ob.SellerId = sellerId
+	ob.SellerName = sellerName
+	ob.RaiSellerId = raiSellerId
+	ob.RaiSellerName = raiSellerName
 	ob.ContractType = req.ContractType
 	ob.ContractAmount = req.ContractAmount
 	ob.CurrencyUnit = req.CurrencyUnit
@@ -463,6 +496,41 @@ func (rg *RegisterController) Edit(c *gin.Context) {
 		resp.FailMsg("操作失败", "获取合同登记信息失败, Err:"+e.Error(), c)
 		return
 	}
+
+	// 查询销售信息
+	var (
+		sellerId int
+		raiSellerId int
+		sellerName string
+		raiSellerName string
+	)
+
+	if req.SellerIds != "" {
+		admin := new(crm.Admin)
+		sellerIds := strings.Split(req.SellerIds, ",")
+		if len(sellerIds) > 2 {
+			resp.Fail("最多只能选择两个销售", c)
+			return
+		}
+		var pars []interface{}
+		cond := ` admin_id in (?) `
+		pars = append(pars, sellerIds)
+		sellers, e := admin.List(cond, pars)
+		if e != nil {
+			resp.FailMsg("获取销售信息失败", "获取销售信息失败, Err: "+e.Error(), c)
+			return
+		}
+		for _, v := range sellers {
+			if v.DepartmentId == crm.SellerDepartmentId {
+				sellerId = v.AdminId
+				sellerName = v.AdminName
+			}else if v.DepartmentId == crm.RaiSellerDepartmentId {
+				raiSellerId = v.AdminId
+				raiSellerName = v.AdminName
+			}
+		}
+	}
+
 	// 是否存在相同合同编号的登记
 	existCond := `contract_code = ?`
 	existPars := make([]interface{}, 0)
@@ -491,10 +559,10 @@ func (rg *RegisterController) Edit(c *gin.Context) {
 	item.ContractSource = req.ContractSource
 	item.CompanyName = req.CompanyName
 	item.ActualCompanyName = req.ActualCompanyName
-	item.SellerId = req.SellerId
-	item.SellerName = req.SellerName
-	item.RaiSellerId = req.RaiSellerId
-	item.RaiSellerName = req.RaiSellerName
+	item.SellerId = sellerId
+	item.SellerName = sellerName
+	item.RaiSellerId = raiSellerId
+	item.RaiSellerName = raiSellerName
 	item.ContractType = req.ContractType
 	item.ContractAmount = req.ContractAmount
 	item.StartDate = startDate
@@ -1826,7 +1894,7 @@ func ExportInvoiceList(c *gin.Context, req fms.ContractInvoiceListReq, results *
 	sheet.AddRow()
 
 	// 列表数据表头
-	titles := []string{"合同编号", fmt.Sprintf("%s金额", listName), "金额单位", "换算金额(元)",
+	titles := []string{"合同编号", "套餐类型", fmt.Sprintf("%s金额", listName), "金额单位", "换算金额(元)",
 		fmt.Sprintf("%s日期", listName), "销售", "备注"}
 	titleRow := sheet.AddRow()
 	titleRow.SetHeight(40)
@@ -1835,12 +1903,16 @@ func ExportInvoiceList(c *gin.Context, req fms.ContractInvoiceListReq, results *
 		c.SetString(titles[i])
 		c.SetStyle(style)
 	}
-
+	ServiceTemplateStrMap := map[int]string{
+		crm.CompanyProductFicc: "FICC套餐",
+		crm.CompanyProductRai: "权益套餐",
+	}
 	// 单元格赋值
 	for _, v := range list {
 		dataRow := sheet.AddRow()
 		dataRow.SetHeight(20)
 		dataRow.AddCell().SetString(v.ContractCode)             // 合同编号
+		dataRow.AddCell().SetString(ServiceTemplateStrMap[v.ServiceProductId]) // 套餐类型
 		dataRow.AddCell().SetString(fmt.Sprint(v.OriginAmount)) // 开票金额
 		dataRow.AddCell().SetString(v.UnitName)                 // 金额单位
 		dataRow.AddCell().SetString(fmt.Sprint(v.Amount))       // 换算金额(元)

+ 15 - 0
models/fms/contract_payment_service_amount.go

@@ -62,6 +62,12 @@ type DistributePaymentServiceAmountReq struct {
 	List               []*DistributePaymentServiceAmountItem `json:"list"`
 }
 
+// GetPaymentServiceAmountReq 到款登记-查询分配套餐金额请求体
+type GetPaymentServiceAmountReq struct {
+	ContractRegisterId int `json:"contract_register_id" binding:"required,gte=1" description:"合同登记ID"`
+	ContractPaymentId  int `json:"contract_payment_id" binding:"required,gte=1" description:"到款登记ID"`
+}
+
 // DistributePaymentServiceAmountItem 到款登记-分配套餐金额列表信息
 type DistributePaymentServiceAmountItem struct {
 	ContractPaymentServiceAmountId int     `json:"contract_payment_service_amount_id"`
@@ -91,3 +97,12 @@ func CreatePaymentServiceAmount(registerId, payId int, addList []*ContractPaymen
 	}
 	return
 }
+
+// GetIndustryServiceTempAmount 获取对应的主客观分配的金额
+func GetIndustryServiceTempAmount(contractPaymentIds []int) (list []*ContractPaymentServiceAmount, err error) {
+	err = global.DEFAULT_MYSQL.Model(ContractPaymentServiceAmount{}).
+		Where("is_deleted = 0").
+		Where("service_template_pid > 0").
+		Find(&list).Error
+	return
+}

+ 1 - 4
models/fms/contract_register.go

@@ -166,10 +166,7 @@ type ContractRegisterAddReq struct {
 	ContractSource     int                           `json:"contract_source" binding:"oneof=0 1" description:"合同来源: 0-非系统合同导入; 1-CRM合同导入"`
 	CompanyName        string                        `json:"company_name" binding:"required" description:"客户名称"`
 	ActualCompanyName  string                        `json:"actual_company_name" description:"实际使用方"`
-	SellerId           int                           `json:"seller_id" binding:"required" description:"CRM系统-销售ID"`
-	SellerName         string                        `json:"seller_name" binding:"required" description:"CRM系统-销售名称"`
-	RaiSellerId        int                           `json:"rai_seller_id" description:"CRM系统-权益销售ID"`
-	RaiSellerName      string                        `json:"rai_seller_name" description:"CRM系统-权益销售名称"`
+	SellerIds          string                        `json:"seller_ids" binding:"required" description:"CRM系统-销售ID"`
 	ContractType       int                           `json:"contract_type" binding:"oneof=1 2 3 4" description:"合同类型: 1-新签; 2-续约; 3-代付; 4-补充协议"`
 	ContractAmount     float64                       `json:"contract_amount" binding:"required" description:"合同金额"`
 	CurrencyUnit       string                        `json:"currency_unit" binding:"required" description:"货币单位"`

+ 11 - 0
services/fms/invoice_payment.go

@@ -278,3 +278,14 @@ func SummaryInvoicePaymentByContractRegisterId(registerId int) {
 	}
 	return
 }
+
+// CalculatePaymentServiceAmount
+func CalculatePaymentServiceAmount()  {
+	// todo 判断是否符合均分金额的条件,如果符合,需要生成金额分配记录表
+	// 如果用户去修改了套餐信息,需要删除对应的自动分配记录吗
+	// 如果有被删的到款登记,则批量删除对应的到款登记下的金额分配记录
+	// 从新创建的到款登记里重新分配金额
+	// 先判断这个合同的到款登记是新创建的还是被编辑的,
+	// 如果该合同的到款登记是新的,则直接创建分配金额记录
+	// 如果该合同的到款登记是已经存在的,则判断金额是否被修改,如果被修改,是否需要重新分配
+}