Browse Source

开票登记新增销售

hsun 2 years ago
parent
commit
31831cab74
2 changed files with 41 additions and 2 deletions
  1. 31 1
      controller/contract/register.go
  2. 10 1
      models/fms/contract_invoice.go

+ 31 - 1
controller/contract/register.go

@@ -15,6 +15,7 @@ import (
 	"hongze/fms_api/models/fms"
 	"hongze/fms_api/models/system"
 	"hongze/fms_api/services/alarm_msg"
+	crmService "hongze/fms_api/services/crm"
 	fmsService "hongze/fms_api/services/fms"
 	"hongze/fms_api/utils"
 	"net/http"
@@ -679,6 +680,17 @@ func (rg *RegisterController) Invoice(c *gin.Context) {
 	noChangeInvoiceIds := make([]int, 0)
 	newInvoice := make([]*fms.ContractInvoice, 0)
 	if len(req.AmountList) > 0 {
+		// 获取销售分组信息
+		sellerList, e := crmService.GetSellerDepartmentListWithGroupAndTeam()
+		if e != nil {
+			resp.FailData("获取销售失败", "Err:"+e.Error(), c)
+			return
+		}
+		sellerMap := make(map[int]*crm.SellerAdminWithGroupTeam)
+		for i := range sellerList {
+			sellerMap[sellerList[i].SellerId] = sellerList[i]
+		}
+
 		for i := range req.AmountList {
 			if req.AmountList[i].Amount <= 0 {
 				resp.Fail("登记金额有误", c)
@@ -688,6 +700,11 @@ func (rg *RegisterController) Invoice(c *gin.Context) {
 				resp.Fail("请选择日期", c)
 				return
 			}
+			// 开票登记销售必填
+			if req.InvoiceType == fms.ContractInvoiceTypeMake && req.AmountList[i].SellerId <= 0 {
+				resp.Fail("请选择销售", c)
+				return
+			}
 			t, e := time.ParseInLocation(utils.FormatDate, req.AmountList[i].InvoiceDate, time.Local)
 			if e != nil {
 				resp.FailData("日期格式有误", "Err:"+e.Error(), c)
@@ -695,7 +712,8 @@ func (rg *RegisterController) Invoice(c *gin.Context) {
 			}
 			if req.AmountList[i].InvoiceId > 0 {
 				noChangeInvoiceIds = append(noChangeInvoiceIds, req.AmountList[i].InvoiceId)
-			} else {
+			}
+			if req.AmountList[i].InvoiceId == 0 {
 				v := &fms.ContractInvoice{
 					ContractRegisterId: req.ContractRegisterId,
 					ContractCode:       item.ContractCode,
@@ -707,6 +725,18 @@ func (rg *RegisterController) Invoice(c *gin.Context) {
 					Remark:             req.AmountList[i].Remark,
 				}
 				v.Set()
+				// 销售信息
+				if req.InvoiceType == fms.ContractInvoiceTypeMake {
+					sellerItem := sellerMap[req.AmountList[i].SellerId]
+					if sellerItem == nil {
+						resp.Fail("销售信息异常", c)
+						return
+					}
+					v.SellerId = sellerItem.SellerId
+					v.SellerName = sellerItem.SellerName
+					v.SellerGroupId = sellerItem.GroupId
+					v.SellerTeamId = sellerItem.TeamId
+				}
 				newInvoice = append(newInvoice, v)
 			}
 		}

+ 10 - 1
models/fms/contract_invoice.go

@@ -15,6 +15,10 @@ type ContractInvoice struct {
 	Amount             float64   `gorm:"column:amount" json:"amount" description:"金额"`
 	InvoiceType        int       `gorm:"column:invoice_type" json:"invoice_type" description:"类型: 1-开票登记; 2-到款登记"`
 	InvoiceDate        time.Time `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:"销售名称"`
+	SellerGroupId      int       `gorm:"column:seller_group_id" json:"seller_group_id" description:"销售分组ID"`
+	SellerTeamId       int       `gorm:"column:seller_team_id" json:"seller_team_id" description:"销售小组ID"`
 	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:"备注信息"`
@@ -34,6 +38,8 @@ type ContractInvoiceItem struct {
 	Amount             float64 `gorm:"column:amount" json:"amount" description:"金额"`
 	InvoiceType        int     `gorm:"column:invoice_type" json:"invoice_type" description:"类型: 1-开票登记; 2-到款登记"`
 	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:"销售名称"`
 	Remark             string  `gorm:"column:remark" json:"remark" description:"备注信息"`
 	CreateTime         string  `gorm:"column:create_time" json:"create_time" description:"创建时间"`
 }
@@ -121,6 +127,7 @@ type ContractInvoiceSaveItem struct {
 	Amount      float64 `json:"amount" description:"开票金额/到款金额"`
 	InvoiceDate string  `json:"invoice_date" description:"开票日期/到款月"`
 	Remark      string  `json:"remark" description:"备注"`
+	SellerId    int     `json:"seller_id" description:"销售ID"`
 }
 
 // GetContractInvoiceItemList 获取开票到款列表
@@ -149,6 +156,8 @@ func formatContractInvoice2ItemList(list []*ContractInvoice) (itemList []*Contra
 			Amount:             list[i].Amount,
 			InvoiceType:        list[i].InvoiceType,
 			InvoiceDate:        utils.TimeTransferString(utils.FormatDate, list[i].InvoiceDate),
+			SellerId:           list[i].SellerId,
+			SellerName:         list[i].SellerName,
 			Remark:             list[i].Remark,
 			CreateTime:         utils.TimeTransferString(utils.FormatDateTime, list[i].CreateTime),
 		})
@@ -206,4 +215,4 @@ func DeleteContractInvoicesByRegisterId(registerId int) (err error) {
 	sql := `UPDATE contract_invoice SET is_deleted = 1 WHERE contract_register_id = ?`
 	err = global.DEFAULT_MYSQL.Exec(sql, registerId).Error
 	return
-}
+}