|
@@ -7,10 +7,14 @@ import (
|
|
|
"hongze/fms_api/controller/resp"
|
|
|
"hongze/fms_api/global"
|
|
|
"hongze/fms_api/models/base"
|
|
|
+ "hongze/fms_api/models/crm"
|
|
|
"hongze/fms_api/models/fms"
|
|
|
"hongze/fms_api/models/system"
|
|
|
+ crmService "hongze/fms_api/services/crm"
|
|
|
fmsService "hongze/fms_api/services/fms"
|
|
|
"hongze/fms_api/utils"
|
|
|
+ "strconv"
|
|
|
+ "strings"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
@@ -26,68 +30,68 @@ type PreRegisterController struct{}
|
|
|
// @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)
|
|
|
-}
|
|
|
+//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 开票/到款列表
|
|
@@ -141,7 +145,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.GetPrePayItemPageList(page, cond, pars)
|
|
|
+ total, list, e := fms.GetContractInvoiceItemPageList(page, cond, pars)
|
|
|
if e != nil {
|
|
|
resp.FailMsg("获取失败", "获取预登记列表失败, Err: "+e.Error(), c)
|
|
|
return
|
|
@@ -162,9 +166,9 @@ func (rg *PreRegisterController) List(c *gin.Context) {
|
|
|
// @Description 新增到款预登记
|
|
|
// @Param request body fms.PrepayAddReq true "type json string"
|
|
|
// @Success 200 string "操作成功"
|
|
|
-// @router /contract/pre_pay/add [post]
|
|
|
-func (rg *PrePaymentController) Add(c *gin.Context) {
|
|
|
- req := new(fms.PrepayAddReq)
|
|
|
+// @router /contract/pre_register/add [post]
|
|
|
+func (rg *PreRegisterController) Add(c *gin.Context) {
|
|
|
+ req := new(fms.PreRegisterAddReq)
|
|
|
err := c.ShouldBind(&req)
|
|
|
if err != nil {
|
|
|
errs, ok := err.(validator.ValidationErrors)
|
|
@@ -179,82 +183,164 @@ func (rg *PrePaymentController) Add(c *gin.Context) {
|
|
|
adminInfo := claims.(*system.SysAdmin)
|
|
|
|
|
|
// 日期校验
|
|
|
- startDate, e := time.ParseInLocation(utils.FormatDate, req.StartDate, time.Local)
|
|
|
- if e != nil {
|
|
|
- resp.FailMsg("约定开始日期格式有误", "合同开始日期格式有误, Err: "+e.Error(), c)
|
|
|
- return
|
|
|
- }
|
|
|
- endDate, e := time.ParseInLocation(utils.FormatDate, req.EndDate, time.Local)
|
|
|
- if e != nil {
|
|
|
- resp.FailMsg("约定结束日期格式有误", "合同结束日期格式有误, Err: "+e.Error(), c)
|
|
|
- return
|
|
|
+ var startDate, endDate time.Time
|
|
|
+ if req.StartDate != "" && req.EndDate != "" {
|
|
|
+ startDate, err = time.ParseInLocation(utils.FormatDate, req.StartDate, time.Local)
|
|
|
+ if err != nil {
|
|
|
+ resp.FailMsg("约定开始日期格式有误", "合同开始日期格式有误, Err: "+err.Error(), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ endDate, err = time.ParseInLocation(utils.FormatDate, req.EndDate, time.Local)
|
|
|
+ if err != nil {
|
|
|
+ resp.FailMsg("约定结束日期格式有误", "合同结束日期格式有误, Err: "+err.Error(), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- // 货币及汇率
|
|
|
- rateList, e := fmsService.GetTodayCurrencyRateList()
|
|
|
+ // 获取销售分组信息
|
|
|
+ sellerList, e := crmService.GetSellerDepartmentListWithGroupAndTeam()
|
|
|
if e != nil {
|
|
|
- resp.FailMsg("操作失败", "获取今日货币汇率失败, Err: "+e.Error(), c)
|
|
|
+ resp.FailData("获取销售失败", "Err:"+e.Error(), c)
|
|
|
return
|
|
|
}
|
|
|
- var rate float64
|
|
|
- for i := range rateList {
|
|
|
- if req.CurrencyUnit == rateList[i].Code {
|
|
|
- rate = rateList[i].RMBRate
|
|
|
- break
|
|
|
- }
|
|
|
+ sellerMap := make(map[int]*crm.SellerAdminWithGroupTeam)
|
|
|
+ for i := range sellerList {
|
|
|
+ sellerMap[sellerList[i].SellerId] = sellerList[i]
|
|
|
}
|
|
|
- if rate <= 0 {
|
|
|
- resp.FailMsg("操作失败", "货币汇率信息有误", c)
|
|
|
+
|
|
|
+ admin := new(crm.Admin)
|
|
|
+ sellerIds := strings.Split(req.SellerIds, ",")
|
|
|
+ if len(sellerIds) > 2 {
|
|
|
+ resp.Fail("最多只能选择两个销售", c)
|
|
|
return
|
|
|
}
|
|
|
-
|
|
|
- payDate, err := time.Parse(utils.FormatDate, req.PaymentDate)
|
|
|
+ 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)
|
|
|
+ resp.FailMsg("获取销售信息失败", "获取销售信息失败, Err: "+e.Error(), c)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- ob := new(fms.ContractPrePayment)
|
|
|
+ //新增合同
|
|
|
+ ob := new(fms.ContractRegister)
|
|
|
+ //ob.ContractCode = req.ContractCode
|
|
|
ob.CompanyName = req.CompanyName
|
|
|
- ob.CurrencyUnit = req.CurrencyUnit
|
|
|
+ ob.ProductIds = req.ProductIds
|
|
|
ob.StartDate = startDate
|
|
|
ob.EndDate = endDate
|
|
|
- ob.AdminId = int(adminInfo.AdminId)
|
|
|
- ob.AdminName = adminInfo.AdminName
|
|
|
- ob.Amount = req.Amount / rate
|
|
|
- ob.OriginAmount = req.Amount
|
|
|
- ob.CurrencyUnit = req.CurrencyUnit
|
|
|
- ob.Remark = req.Remark
|
|
|
- ob.PaymentDate = payDate
|
|
|
ob.Set()
|
|
|
+ if req.RegisterType == fms.ContractInvoiceTypePreMake {
|
|
|
+ //sellerItem := sellerMap[r.SellerId]
|
|
|
+ //if sellerItem == nil {
|
|
|
+ // resp.Fail("销售信息异常", c)
|
|
|
+ // return
|
|
|
+ //}
|
|
|
+ for _, v := range sellers {
|
|
|
+ if v.DepartmentId == crm.SellerDepartmentId {
|
|
|
+ ob.SellerId = v.AdminId
|
|
|
+ ob.SellerName = v.AdminName
|
|
|
+ } else if v.DepartmentId == crm.RaiSellerDepartmentId {
|
|
|
+ ob.RaiSellerId = v.AdminId
|
|
|
+ ob.RaiSellerName = v.AdminName
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- // 新增合同及套餐
|
|
|
- if e = ob.Create(); e != nil {
|
|
|
+ // 套餐信息
|
|
|
+ serviceAmountMap := make(map[int]float64)
|
|
|
+ serviceList, e := fmsService.HandleContractServiceAndDetail(req.Services, true, serviceAmountMap)
|
|
|
+ if e != nil {
|
|
|
+ resp.FailMsg("操作失败", "获取合同套餐详情失败, Err: "+e.Error(), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if e = fms.CreateContractRegisterAndServicesAndPayMent(ob, serviceList); e != nil {
|
|
|
resp.FailMsg("操作失败", "新增合同及套餐失败, Err: "+e.Error(), c)
|
|
|
return
|
|
|
}
|
|
|
- //// 开票到款汇总
|
|
|
- //nowTime := time.Now().Local()
|
|
|
- //v := new(fms.InvoicePaymentSummary)
|
|
|
- //v.CreateTime = nowTime
|
|
|
- //v.ModifyTime = nowTime
|
|
|
- //v.PrePayid = ob.PrePayId
|
|
|
- //
|
|
|
- //if e = v.Create(); e != nil {
|
|
|
- // err = fmt.Errorf("新增汇总数据失败, Err: %s", e.Error())
|
|
|
- //}
|
|
|
+
|
|
|
+ for _, r := range req.List {
|
|
|
+ // 货币及汇率
|
|
|
+ rateList, e := fmsService.GetTodayCurrencyRateList()
|
|
|
+ if e != nil {
|
|
|
+ resp.FailMsg("操作失败", "获取今日货币汇率失败, Err: "+e.Error(), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var rate float64
|
|
|
+ for i := range rateList {
|
|
|
+ if r.CurrencyUnit == rateList[i].Code {
|
|
|
+ rate = rateList[i].RMBRate
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if rate <= 0 {
|
|
|
+ resp.FailMsg("操作失败", "货币汇率信息有误", c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ registerDate, e := time.Parse(utils.FormatDate, r.RegisterDate)
|
|
|
+ if e != nil {
|
|
|
+ resp.FailMsg("日期转换失败", "日期转换失败, Err: "+e.Error(), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ v := &fms.ContractInvoice{
|
|
|
+ ContractRegisterId: ob.ContractRegisterId,
|
|
|
+ OriginAmount: r.Amount,
|
|
|
+ CurrencyUnit: r.CurrencyUnit,
|
|
|
+ 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{},
|
|
|
+ }
|
|
|
+ v.Set()
|
|
|
+
|
|
|
+ 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
|
|
|
+ }
|
|
|
+
|
|
|
+ // 新增开票到款记录
|
|
|
+ if e = v.Create(); e != nil {
|
|
|
+ resp.FailMsg("操作失败", "新增预登记失败, Err: "+e.Error(), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 开票到款汇总
|
|
|
+ go fmsService.SummaryInvoicePaymentByContractRegisterId(ob.ContractRegisterId)
|
|
|
|
|
|
resp.Ok("操作成功", c)
|
|
|
}
|
|
|
|
|
|
// Edit
|
|
|
-// @Title 编辑到款预登记
|
|
|
-// @Description 编辑到款预登记
|
|
|
+// @Title 编辑预登记
|
|
|
+// @Description 编辑预登记
|
|
|
// @Param request body fms.ContractRegisterEditReq true "type json string"
|
|
|
// @Success 200 string "操作成功"
|
|
|
-// @router /contract/pre_pay/edit [post]
|
|
|
-func (rg *PrePaymentController) Edit(c *gin.Context) {
|
|
|
- req := new(fms.PrepayEditReq)
|
|
|
+// @router /contract/pre_register/edit [post]
|
|
|
+func (rg *PreRegisterController) Edit(c *gin.Context) {
|
|
|
+ req := new(fms.PreRegisterEditReq)
|
|
|
err := c.ShouldBind(&req)
|
|
|
if err != nil {
|
|
|
errs, ok := err.(validator.ValidationErrors)
|
|
@@ -269,86 +355,172 @@ func (rg *PrePaymentController) Edit(c *gin.Context) {
|
|
|
adminInfo := claims.(*system.SysAdmin)
|
|
|
|
|
|
// 日期校验
|
|
|
- startDate, e := time.ParseInLocation(utils.FormatDate, req.StartDate, time.Local)
|
|
|
- if e != nil {
|
|
|
- resp.FailMsg("约定开始日期格式有误", "合同开始日期格式有误, Err: "+e.Error(), c)
|
|
|
- return
|
|
|
+ var startDate, endDate time.Time
|
|
|
+ if req.StartDate != "" && req.EndDate != "" {
|
|
|
+ startDate, err = time.ParseInLocation(utils.FormatDate, req.StartDate, time.Local)
|
|
|
+ if err != nil {
|
|
|
+ resp.FailMsg("约定开始日期格式有误", "合同开始日期格式有误, Err: "+err.Error(), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ endDate, err = time.ParseInLocation(utils.FormatDate, req.EndDate, time.Local)
|
|
|
+ if err != nil {
|
|
|
+ resp.FailMsg("约定结束日期格式有误", "合同结束日期格式有误, Err: "+err.Error(), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
}
|
|
|
- endDate, e := time.ParseInLocation(utils.FormatDate, req.EndDate, time.Local)
|
|
|
+
|
|
|
+ // 获取销售分组信息
|
|
|
+ sellerList, e := crmService.GetSellerDepartmentListWithGroupAndTeam()
|
|
|
if e != nil {
|
|
|
- resp.FailMsg("约定结束日期格式有误", "合同结束日期格式有误, Err: "+e.Error(), c)
|
|
|
+ resp.FailData("获取销售失败", "Err:"+e.Error(), c)
|
|
|
return
|
|
|
}
|
|
|
+ sellerMap := make(map[int]*crm.SellerAdminWithGroupTeam)
|
|
|
+ for i := range sellerList {
|
|
|
+ sellerMap[sellerList[i].SellerId] = sellerList[i]
|
|
|
+ }
|
|
|
|
|
|
- // 货币及汇率
|
|
|
- rateList, e := fmsService.GetTodayCurrencyRateList()
|
|
|
- if e != nil {
|
|
|
- resp.FailMsg("操作失败", "获取今日货币汇率失败, Err: "+e.Error(), c)
|
|
|
+ admin := new(crm.Admin)
|
|
|
+ sellerIds := strings.Split(req.SellerIds, ",")
|
|
|
+ if len(sellerIds) > 2 {
|
|
|
+ resp.Fail("最多只能选择两个销售", c)
|
|
|
return
|
|
|
}
|
|
|
- var rate float64
|
|
|
- for i := range rateList {
|
|
|
- if req.CurrencyUnit == rateList[i].Code {
|
|
|
- rate = rateList[i].RMBRate
|
|
|
- break
|
|
|
- }
|
|
|
- }
|
|
|
- if rate <= 0 {
|
|
|
- resp.FailMsg("操作失败", "货币汇率信息有误", c)
|
|
|
+ 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
|
|
|
}
|
|
|
|
|
|
- ob := new(fms.ContractPrePayment)
|
|
|
-
|
|
|
- item, e := ob.Fetch(req.PrePayId)
|
|
|
- if e != nil {
|
|
|
- if e == utils.ErrNoRow {
|
|
|
- resp.Fail("预到款登记记录不存在或已被删除", c)
|
|
|
- return
|
|
|
+ //修改合同
|
|
|
+ ob := new(fms.ContractRegister)
|
|
|
+ //ob.ContractCode = req.ContractCode
|
|
|
+ ob.ContractRegisterId = req.ContractRegisterId
|
|
|
+ ob.CompanyName = req.CompanyName
|
|
|
+ ob.ProductIds = req.ProductIds
|
|
|
+ ob.StartDate = startDate
|
|
|
+ ob.EndDate = endDate
|
|
|
+ ob.ModifyTime = time.Now().Local()
|
|
|
+ if req.RegisterType == fms.ContractInvoiceTypePreMake {
|
|
|
+ //sellerItem := sellerMap[r.SellerId]
|
|
|
+ //if sellerItem == nil {
|
|
|
+ // resp.Fail("销售信息异常", c)
|
|
|
+ // return
|
|
|
+ //}
|
|
|
+ for _, v := range sellers {
|
|
|
+ if v.DepartmentId == crm.SellerDepartmentId {
|
|
|
+ ob.SellerId = v.AdminId
|
|
|
+ ob.SellerName = v.AdminName
|
|
|
+ } else if v.DepartmentId == crm.RaiSellerDepartmentId {
|
|
|
+ ob.RaiSellerId = v.AdminId
|
|
|
+ ob.RaiSellerName = v.AdminName
|
|
|
+ }
|
|
|
}
|
|
|
- resp.FailMsg("操作失败", "获取预到款登记信息失败, Err:"+e.Error(), c)
|
|
|
- return
|
|
|
}
|
|
|
|
|
|
- payDate, err := time.Parse(utils.FormatDate, req.PaymentDate)
|
|
|
+ // 套餐信息
|
|
|
+ serviceAmountMap := make(map[int]float64)
|
|
|
+ serviceList, e := fmsService.HandleContractServiceAndDetail(req.Services, true, serviceAmountMap)
|
|
|
if e != nil {
|
|
|
- resp.FailMsg("日期转换失败", "日期转换失败, Err: "+e.Error(), c)
|
|
|
+ resp.FailMsg("操作失败", "获取合同套餐详情失败, Err: "+e.Error(), c)
|
|
|
return
|
|
|
}
|
|
|
+ updateCols := []string{
|
|
|
+ "ProductIds", "CompanyName", "SellerId", "SellerName", "StartDate", "EndDate",
|
|
|
+ "RaiSellerId", "RaiSellerName", "ModifyTime",
|
|
|
+ }
|
|
|
|
|
|
- item.CompanyName = req.CompanyName
|
|
|
- item.CurrencyUnit = req.CurrencyUnit
|
|
|
- item.StartDate = startDate
|
|
|
- item.EndDate = endDate
|
|
|
- item.AdminId = int(adminInfo.AdminId)
|
|
|
- item.AdminName = adminInfo.AdminName
|
|
|
- item.Amount = req.Amount / rate
|
|
|
- item.OriginAmount = req.Amount
|
|
|
- item.CurrencyUnit = req.CurrencyUnit
|
|
|
- item.Remark = req.Remark
|
|
|
- item.PaymentDate = payDate
|
|
|
- item.ModifyTime = time.Now().Local()
|
|
|
+ invoiceList := make([]*fms.ContractInvoice, 0)
|
|
|
+ for _, r := range req.List {
|
|
|
+ // 货币及汇率
|
|
|
+ rateList, e := fmsService.GetTodayCurrencyRateList()
|
|
|
+ if e != nil {
|
|
|
+ resp.FailMsg("操作失败", "获取今日货币汇率失败, Err: "+e.Error(), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var rate float64
|
|
|
+ for i := range rateList {
|
|
|
+ if r.CurrencyUnit == rateList[i].Code {
|
|
|
+ rate = rateList[i].RMBRate
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if rate <= 0 {
|
|
|
+ resp.FailMsg("操作失败", "货币汇率信息有误", c)
|
|
|
+ return
|
|
|
+ }
|
|
|
|
|
|
- updateCols := []string{
|
|
|
- "ContractCode", "CompanyName", "SellerId", "SellerName", "Amount", "StartDate", "EndDate",
|
|
|
- "Remark", "ModifyTime", "NewCompany", "OriginAmount", "CurrencyUnit", "PaymentDate",
|
|
|
+ registerDate, e := time.Parse(utils.FormatDate, r.RegisterDate)
|
|
|
+ if e != nil {
|
|
|
+ resp.FailMsg("日期转换失败", "日期转换失败, Err: "+e.Error(), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ v := &fms.ContractInvoice{
|
|
|
+ ContractInvoiceId: r.InvoiceId,
|
|
|
+ ContractRegisterId: ob.ContractRegisterId,
|
|
|
+ OriginAmount: r.Amount,
|
|
|
+ CurrencyUnit: r.CurrencyUnit,
|
|
|
+ InvoiceType: req.RegisterType,
|
|
|
+ InvoiceDate: registerDate,
|
|
|
+ AdminId: int(adminInfo.AdminId),
|
|
|
+ AdminName: adminInfo.AdminName,
|
|
|
+ Remark: r.Remark,
|
|
|
+ ServiceProductId: r.ServiceProductId,
|
|
|
+ IsPrePay: 1,
|
|
|
+ StartDate: startDate,
|
|
|
+ EndDate: endDate,
|
|
|
+ }
|
|
|
+ v.TimeBase.ModifyTime = time.Now().Local()
|
|
|
+
|
|
|
+ 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
|
|
|
+ }
|
|
|
+
|
|
|
+ invoiceList = append(invoiceList, v)
|
|
|
}
|
|
|
- if e = item.Update(updateCols); e != nil {
|
|
|
- resp.FailMsg("操作失败", "更新到预款登记失败, Err:"+e.Error(), c)
|
|
|
+ invoiceUpdateCols := []string{
|
|
|
+ "CurrencyUnit", "Amount", "InvoiceDate", "AdminId", "AdminName", "Remark",
|
|
|
+ "ServiceProductId", "StartDate", "EndDate", "ModifyTime",
|
|
|
+ }
|
|
|
+ // 更新合同登记、套餐、开票到款
|
|
|
+ if e = fms.UpdateContractPreRegister(ob, updateCols, serviceList, invoiceList, invoiceUpdateCols); e != nil {
|
|
|
+ resp.FailMsg("操作失败", "更新合同及套餐失败, Err: "+e.Error(), c)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+ // 开票到款汇总
|
|
|
+ go fmsService.SummaryInvoicePaymentByContractRegisterId(ob.ContractRegisterId)
|
|
|
+
|
|
|
resp.Ok("操作成功", c)
|
|
|
}
|
|
|
|
|
|
+
|
|
|
// Del
|
|
|
// @Title 删除到款预登记
|
|
|
// @Description 删除到款预登记
|
|
|
// @Param request body fms.ContractRegisterDelReq true "type json string"
|
|
|
// @Success 200 string "操作成功"
|
|
|
// @router /contract/pre_pay/del [post]
|
|
|
-func (rg *PrePaymentController) Del(c *gin.Context) {
|
|
|
- req := new(fms.PrepayDelReq)
|
|
|
+func (rg *PreRegisterController) Del(c *gin.Context) {
|
|
|
+ req := new(fms.PreRegisterDelReq)
|
|
|
err := c.ShouldBind(&req)
|
|
|
if err != nil {
|
|
|
errs, ok := err.(validator.ValidationErrors)
|
|
@@ -360,8 +532,8 @@ func (rg *PrePaymentController) Del(c *gin.Context) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- ob := new(fms.ContractPrePayment)
|
|
|
- item, e := ob.Fetch(req.PrePayId)
|
|
|
+ ob := new(fms.ContractInvoice)
|
|
|
+ item, e := ob.Fetch(req.InvoiceId)
|
|
|
if e != nil {
|
|
|
if e == utils.ErrNoRow {
|
|
|
resp.Fail("合同登记不存在或已被删除", c)
|