ziwen 2 years ago
parent
commit
6b7c52bf14
3 changed files with 216 additions and 85 deletions
  1. 51 73
      controller/contract/pre_register.go
  2. 156 0
      models/fms/contract_pre_register.go
  3. 9 12
      services/fms/invoice_payment.go

+ 51 - 73
controller/contract/pre_register.go

@@ -21,78 +21,6 @@ import (
 // // RegisterController 合同登记
 type PreRegisterController struct{}
 
-// List
-// @Title 到款预登记列表
-// @Description 到款预登记列表
-// @Param   Keyword			query	string	false	"关键词"
-// @Param   StartDate		query	string	false	"约定开始时间"
-// @Param   EndDate			query	string	false	"约定结束时间"
-// @Param   SortType   		query   string  true       "如何排序,是正序还是倒序,枚举值:`asc 正序`,`desc 倒叙`"
-// @Success 200 {object} fms.ContractRegisterItem
-// @router /contract/pre_pay/list [get]
-//func (rg *PrePaymentController) List1(c *gin.Context) {
-//	var req fms.PrePayListReq
-//	if e := c.BindQuery(&req); e != nil {
-//		err, ok := e.(validator.ValidationErrors)
-//		if !ok {
-//			resp.FailData("参数解析失败", "Err:"+e.Error(), c)
-//			return
-//		}
-//		resp.FailData("参数解析失败", err.Translate(global.Trans), c)
-//		return
-//	}
-//
-//	cond := `1 = 1`
-//	pars := make([]interface{}, 0)
-//	// 客户姓名/销售
-//	if req.Keyword != "" {
-//		kw := "%" + req.Keyword + "%"
-//		cond += ` AND (company_name LIKE ? OR seller_name LIKE ? )`
-//		pars = append(pars, kw, kw)
-//	}
-//	if req.StartDate != "" && req.EndDate != "" {
-//		st := fmt.Sprint(req.StartDate, " 00:00:00")
-//		ed := fmt.Sprint(req.EndDate, " 23:59:59")
-//		cond += ` AND (create_time BETWEEN ? AND ?)`
-//		pars = append(pars, st, ed)
-//	}
-//
-//	// 货币列表
-//	currencyOB := new(fms.CurrencyUnit)
-//	currencyCond := `enable = 1`
-//	currencyPars := make([]interface{}, 0)
-//	currencyList, e := currencyOB.List(currencyCond, currencyPars)
-//	if e != nil {
-//		resp.FailMsg("获取失败", "获取货币列表失败, Err: "+e.Error(), c)
-//		return
-//	}
-//	unitMap := make(map[string]string)
-//	for i := range currencyList {
-//		unitMap[currencyList[i].Code] = currencyList[i].UnitName
-//	}
-//
-//	page := new(base.Page)
-//	page.SetPageSize(req.PageSize)
-//	page.SetCurrent(req.Current)
-//	sortTypeMap := map[int]bool{0: false, 1: true, 2: false}
-//	page.AddOrderItem(base.OrderItem{Column: "create_time", Asc: sortTypeMap[req.SortType]})
-//
-//	total, list, e := fms.GetPrePayItemPageList(page, cond, pars)
-//	if e != nil {
-//		resp.FailMsg("获取失败", "获取预登记列表失败, Err: "+e.Error(), c)
-//		return
-//	}
-//	for i := range list {
-//		list[i].UnitName = unitMap[list[i].CurrencyUnit]
-//	}
-//
-//	page.SetTotal(total)
-//	baseData := new(base.BaseData)
-//	baseData.SetPage(page)
-//	baseData.SetList(list)
-//	resp.OkData("获取成功", baseData, c)
-//}
-
 // InvoiceList
 // @Title 开票/到款列表
 // @Description 开票/到款列表
@@ -145,7 +73,7 @@ func (rg *PreRegisterController) List(c *gin.Context) {
 	sortTypeMap := map[int]bool{0: false, 1: true, 2: false}
 	page.AddOrderItem(base.OrderItem{Column: "create_time", Asc: sortTypeMap[0]})
 
-	total, list, e := fms.GetContractInvoiceItemPageList(page, cond, pars)
+	total, list, e := fms.GetContractPreRegisterItemPageList(page, cond, pars)
 	if e != nil {
 		resp.FailMsg("获取失败", "获取预登记列表失败, Err: "+e.Error(), c)
 		return
@@ -325,6 +253,56 @@ func (rg *PreRegisterController) Add(c *gin.Context) {
 			resp.FailMsg("操作失败", "新增预登记失败, Err: "+e.Error(), c)
 			return
 		}
+
+		//预登记列表
+		pp := &fms.ContractPreRegister{
+			ContractRegisterId: ob.ContractRegisterId,
+			InvoiceType:        req.RegisterType,
+			InvoiceDate:        registerDate,
+			AdminId:            int(adminInfo.AdminId),
+			AdminName:          adminInfo.AdminName,
+			Remark:             r.Remark,
+			ServiceProductId:   r.ServiceProductId,
+			IsPrePay:           1,
+			StartDate:          startDate,
+			EndDate:            endDate,
+			TimeBase:           base.TimeBase{},
+		}
+		pp.Set()
+		if pp.InvoiceType == fms.ContractInvoiceTypePreMake {
+			//开票走开票字段
+			pp.InvoiceDate = registerDate
+			pp.OriginAmount = r.Amount
+			pp.CurrencyUnit = r.CurrencyUnit
+			a, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", pp.OriginAmount/rate), 64)
+			pp.Amount = a
+
+			sellerItem := sellerMap[r.SellerId]
+			if sellerItem == nil {
+				resp.Fail("销售信息异常", c)
+				return
+			}
+
+			pp.SellerId = sellerItem.SellerId
+			pp.SellerName = sellerItem.SellerName
+			pp.SellerGroupId = sellerItem.GroupId
+			pp.SellerGroupName = sellerItem.GroupName
+			pp.SellerTeamId = sellerItem.TeamId
+			pp.SellerTeamName = sellerItem.TeamName
+		} else {
+			//到款
+			pp.ArriveDate = registerDate
+			pp.ArriveOriginAmount = r.Amount
+			pp.ArriveCurrencyUnit = r.CurrencyUnit
+			a, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", pp.ArriveOriginAmount/rate), 64)
+			pp.ArriveAmount = a
+		}
+
+		// 新增开票到款记录
+		if e = pp.Create(); e != nil {
+			resp.FailMsg("操作失败", "新增预登记失败, Err: "+e.Error(), c)
+			return
+		}
 	}
 
 	// 开票到款汇总

+ 156 - 0
models/fms/contract_pre_register.go

@@ -0,0 +1,156 @@
+package fms
+
+import (
+	"hongze/fms_api/global"
+	"hongze/fms_api/models/base"
+	"hongze/fms_api/utils"
+	"time"
+)
+
+// PreRegister 合同开票表
+type ContractPreRegister struct {
+	PreRegisterId      int       `gorm:"primaryKey;column:pre_register_id" json:"pre_register_id" description:"预登记ID"`
+	ContractRegisterId int       `gorm:"column:contract_register_id" json:"contract_register_id" description:"登记ID"`
+	Amount             float64   `gorm:"column:amount" json:"amount" description:"开票换算后的金额(人民币)"`
+	OriginAmount       float64   `gorm:"column:origin_amount" json:"origin_amount" description:"开票金额"`
+	CurrencyUnit       string    `gorm:"column:currency_unit" json:"currency_unit" description:"开票货币国际代码"`
+	ArriveAmount       float64   `gorm:"column:arrive_amount" json:"arrive_amount" description:"到款换算后的金额(人民币)"`
+	ArriveOriginAmount float64   `gorm:"column:arrive_origin_amount" json:"arrive_origin_amount" description:"到款金额"`
+	ArriveCurrencyUnit string    `gorm:"column:arrive_currency_unit" json:"arrive_currency_unit" description:"到款货币国际代码"`
+	InvoiceType        int       `gorm:"column:invoice_type" json:"invoice_type" description:"类型: 1-开票登记; 2-到款登记;3-开票预登记;4-到款预登记"`
+	InvoiceDate        time.Time `gorm:"column:invoice_time" json:"invoice_time" description:"开票日"`
+	ArriveDate         time.Time `gorm:"column:arrive_time" json:"arrive_time" description:"到款日"`
+	SellerId           int       `gorm:"column:seller_id" json:"seller_id" description:"销售ID"`
+	SellerName         string    `gorm:"column:seller_name" json:"seller_name" description:"销售名称"`
+	SellerGroupId      int       `gorm:"column:seller_group_id" json:"seller_group_id" description:"销售分组ID"`
+	SellerGroupName    string    `gorm:"column:seller_group_name" json:"seller_group_name" description:"销售分组名称"`
+	SellerTeamId       int       `gorm:"column:seller_team_id" json:"seller_team_id" description:"销售小组ID"`
+	SellerTeamName     string    `gorm:"column:seller_team_name" json:"seller_team_name" description:"销售小组名称"`
+	AdminId            int       `gorm:"column:admin_id" json:"admin_id" description:"操作人ID"`
+	AdminName          string    `gorm:"column:admin_name" json:"admin_name" description:"操作人姓名"`
+	Remark             string    `gorm:"column:remark" json:"remark" description:"备注信息"`
+	ServiceProductId   int       `gorm:"column:service_product_id" json:"service_product_id" description:"套餐类型:1ficc套餐,2权益套餐"`
+	IsPrePay           int       `gorm:"column:is_pre_pay" json:"is_pre_pay" description:"是否预付款: 0-不是; 1-是"`
+	StartDate          time.Time `gorm:"column:start_date" json:"start_date" description:"约定开始时间"`
+	EndDate            time.Time `gorm:"column:end_date" json:"end_date" description:"约定结束时间"`
+	base.TimeBase
+}
+
+func (c *ContractPreRegister) TableName() string {
+	return "contract_pre_register"
+}
+
+// ContractPreRegisterItem 合同开票/到款
+type ContractPreRegisterItem struct {
+	PreRegisterId      int     `gorm:"primaryKey;column:pre_register_id" json:"pre_register_id" description:"预登记ID"`
+	ContractRegisterId int     `gorm:"column:contract_register_id" json:"contract_register_id" description:"登记ID"`
+	ContractStatus     int     `json:"contract_status" description:"合同状态: 1-已审批; 2-单章寄出; 3-已签回"`
+	Amount             float64 `gorm:"column:amount" json:"amount" description:"开票换算后的金额(人民币)"`
+	OriginAmount       float64 `gorm:"column:origin_amount" json:"origin_amount" description:"开票金额"`
+	CurrencyUnit       string  `gorm:"column:currency_unit" json:"currency_unit" description:"开票货币国际代码"`
+	ArriveAmount       float64 `gorm:"column:arrive_amount" json:"arrive_amount" description:"到款换算后的金额(人民币)"`
+	ArriveOriginAmount float64 `gorm:"column:arrive_origin_amount" json:"arrive_origin_amount" description:"到款金额"`
+	ArriveCurrencyUnit string  `gorm:"column:arrive_currency_unit" json:"arrive_currency_unit" description:"到款货币国际代码"`
+	UnitName           string  `json:"unit_name" description:"货币单位名称"`
+	InvoiceType        int     `gorm:"column:invoice_type" json:"invoice_type" description:"类型: 1-开票登记; 2-到款登记;3-开票预登记;4-到款预登记"`
+	InvoiceDate        string  `gorm:"column:invoice_time" json:"invoice_time" description:"开票日期/到款月"`
+	SellerId           int     `gorm:"column:seller_id" json:"seller_id" description:"销售ID"`
+	SellerName         string  `gorm:"column:seller_name" json:"seller_name" description:"销售名称"`
+	PayType            int     `gorm:"column:pay_type" json:"pay_type" description:"付款方式:0-无;1-年付;2-半年付;3-季付;4-次付;5-异常"`
+	Remark             string  `gorm:"column:remark" json:"remark" description:"开票备注信息"`
+	ArriveRemark       string  `gorm:"column:arrive_remark" json:"arrive_remark" description:"到款备注信息"`
+	ServiceProductId   int     `gorm:"column:service_product_id" json:"service_product_id" description:"套餐类型:1ficc套餐,2权益套餐"`
+	IsPrePay           int     `gorm:"column:is_pre_pay" json:"is_pre_pay" description:"是否预付款: 0-不是; 1-是"`
+	StartDate          string  `gorm:"column:start_date" json:"start_date" description:"约定开始时间"`
+	EndDate            string  `gorm:"column:end_date" json:"end_date" description:"约定结束时间"`
+	CreateTime         string  `gorm:"column:create_time" json:"create_time" description:"创建时间"`
+}
+
+// formatContractInvoice2Item 格式化ContractInvoiceItem
+func formatContractPreRegister2Item(item *ContractPreRegister) (formatItem *ContractPreRegisterItem) {
+	formatItem = new(ContractPreRegisterItem)
+	formatItem.PreRegisterId = item.PreRegisterId
+	formatItem.ContractRegisterId = item.ContractRegisterId
+	formatItem.Amount = item.Amount
+	formatItem.OriginAmount = item.OriginAmount
+	formatItem.CurrencyUnit = item.CurrencyUnit
+	formatItem.ArriveAmount = item.ArriveAmount
+	formatItem.ArriveOriginAmount = item.ArriveOriginAmount
+	formatItem.ArriveCurrencyUnit = item.ArriveCurrencyUnit
+	formatItem.InvoiceType = item.InvoiceType
+	formatItem.InvoiceDate = utils.TimeTransferString(utils.FormatDate, item.InvoiceDate)
+	formatItem.SellerId = item.SellerId
+	formatItem.SellerName = item.SellerName
+	formatItem.Remark = item.Remark
+	formatItem.IsPrePay = item.IsPrePay
+	formatItem.ServiceProductId = item.ServiceProductId
+	formatItem.CreateTime = utils.TimeTransferString(utils.FormatDateTime, item.CreateTime)
+	return
+}
+
+// GetContractInvoiceItemPageList 获取合同开票/到款列表-分页
+func GetContractPreRegisterItemPageList(page base.IPage, condition string, pars []interface{}) (count int64, results []*ContractPreRegisterItem, err error) {
+	list := make([]*ContractPreRegister, 0)
+	query := global.DEFAULT_MYSQL.Table("contract_pre_register").
+		Where(condition, pars...)
+	query.Count(&count)
+	if len(page.GetOrderItemsString()) > 0 {
+		query = query.Order(page.GetOrderItemsString())
+	}
+	err = query.Limit(int(page.GetPageSize())).Offset(int(page.Offset())).Find(&list).Error
+	if err != nil {
+		return
+	}
+	for i := range list {
+		results = append(results, formatContractPreRegister2Item(list[i]))
+	}
+	return
+}
+
+func (c *ContractPreRegister) Create() (err error) {
+	err = global.DEFAULT_MYSQL.Create(c).Error
+	return
+}
+
+// GetContractInvoiceItemList 获取开票到款列表
+func GetContractPreRegisterItemList(condition string, pars []interface{}) (itemList []*ContractPreRegisterItem, err error) {
+	list := make([]*ContractPreRegister, 0)
+	err = global.DEFAULT_MYSQL.Model(ContractPreRegister{}).
+		Where("is_deleted = 0").
+		Where(condition, pars...).
+		Order("contract_invoice_id ASC").
+		Find(&list).Error
+	if err != nil {
+		return
+	}
+	itemList = formatContractPreRegister2ItemList(list)
+	return
+}
+
+// formatContractPreRegister2ItemList 格式化ContractInvoice
+func formatContractPreRegister2ItemList(list []*ContractPreRegister) (itemList []*ContractPreRegisterItem) {
+	itemList = make([]*ContractPreRegisterItem, 0)
+	for i := range list {
+		itemList = append(itemList, &ContractPreRegisterItem{
+			PreRegisterId:      list[i].PreRegisterId,
+			ContractRegisterId: list[i].ContractRegisterId,
+			Amount:             list[i].Amount,
+			OriginAmount:       list[i].OriginAmount,
+			CurrencyUnit:       list[i].CurrencyUnit,
+			ArriveAmount:       list[i].ArriveAmount,
+			ArriveOriginAmount: list[i].ArriveOriginAmount,
+			ArriveCurrencyUnit: list[i].ArriveCurrencyUnit,
+			InvoiceType:        list[i].InvoiceType,
+			InvoiceDate:        utils.TimeTransferString(utils.FormatDate, list[i].InvoiceDate),
+			SellerId:           list[i].SellerId,
+			SellerName:         list[i].SellerName,
+			Remark:             list[i].Remark,
+			ServiceProductId:   list[i].ServiceProductId,
+			IsPrePay:           list[i].IsPrePay,
+			StartDate:          list[i].StartDate.Format(utils.FormatDate),
+			EndDate:            list[i].StartDate.Format(utils.FormatDate),
+			CreateTime:         utils.TimeTransferString(utils.FormatDateTime, list[i].CreateTime),
+		})
+	}
+	return
+}

+ 9 - 12
services/fms/invoice_payment.go

@@ -445,48 +445,45 @@ func CalculatePaymentServiceAmount(registerId int) (err error) {
 }
 
 // SummaryInvoicePaymentByPreRegister 预登记时汇总
-func SummaryInvoicePaymentByPreRegister(invoiceId, registerId int) {
+func SummaryInvoicePaymentByPreRegister(registerId int) {
 	var err error
 	defer func() {
 		if err != nil {
 			alarm_msg.SendAlarmMsg(fmt.Sprintf("汇总开票到款失败, ErrMsg: \n%s", err.Error()), 3)
 		}
 	}()
+
 	// 获取开票到款信息
 	cond := `contract_register_id = ?`
 	pars := make([]interface{}, 0)
 	pars = append(pars, registerId)
-	list, e := fms.GetContractInvoiceItemList(cond, pars)
+	list, e := fms.GetContractPreRegisterItemList(cond, pars)
 	if e != nil {
 		err = fmt.Errorf("获取开票到款列表失败, Err: %s", e.Error())
 		return
 	}
-
-	// 获取开票到款信息
 	ficcInvoiceIds := make([]int, 0)
 	ficcPaymentIds := make([]int, 0)
 	raiInvoiceIds := make([]int, 0)
 	raiPaymentIds := make([]int, 0)
-
 	for i := range list {
 		if list[i].InvoiceType == fms.ContractInvoiceTypePreMake {
 			if list[i].ServiceProductId == crm.CompanyProductFicc {
-				ficcInvoiceIds = append(ficcInvoiceIds, list[i].ContractInvoiceId)
+				ficcInvoiceIds = append(ficcInvoiceIds, list[i].PreRegisterId)
 			} else if list[i].ServiceProductId == crm.CompanyProductRai {
-				raiInvoiceIds = append(raiInvoiceIds, list[i].ContractInvoiceId)
+				raiInvoiceIds = append(raiInvoiceIds, list[i].PreRegisterId)
 			}
 			continue
 		}
-		if list[i].InvoiceType == fms.ContractInvoiceTypePay {
+		if list[i].InvoiceType == fms.ContractInvoiceTypePrePay {
 			if list[i].ServiceProductId == crm.CompanyProductFicc {
-				ficcPaymentIds = append(ficcPaymentIds, list[i].ContractInvoiceId)
+				ficcPaymentIds = append(ficcPaymentIds, list[i].PreRegisterId)
 			} else if list[i].ServiceProductId == crm.CompanyProductRai {
-				raiPaymentIds = append(raiPaymentIds, list[i].ContractInvoiceId)
+				raiPaymentIds = append(raiPaymentIds, list[i].PreRegisterId)
 			}
+			continue
 		}
 	}
-
-
 	ficcInvoiceLen := len(ficcInvoiceIds)
 	raiInvoiceLen := len(raiInvoiceIds)
 	ficcPaymentLen := len(ficcPaymentIds)