|
@@ -381,8 +381,10 @@ func (rg *RegisterController) Add(c *gin.Context) {
|
|
|
resp.FailMsg("操作失败", "获取合同套餐详情失败, Err: "+e.Error(), c)
|
|
|
return
|
|
|
}
|
|
|
-
|
|
|
+ // 合同有效时长(计算付款方式)
|
|
|
+ dayDiff := ob.EndDate.Sub(ob.StartDate).Hours() / 24
|
|
|
// 新增合同及套餐
|
|
|
+ logList := make([]*fms.ContractRegisterLog, 0)
|
|
|
if req.Supplement == 1 {
|
|
|
//新增到款信息
|
|
|
if ob.HasInvoice == 0 {
|
|
@@ -405,8 +407,6 @@ func (rg *RegisterController) Add(c *gin.Context) {
|
|
|
resp.FailMsg("操作失败", "获取合同开票到款列表失败, Err: "+e.Error(), c)
|
|
|
return
|
|
|
}
|
|
|
- // 合同有效时长(计算付款方式)
|
|
|
- dayDiff := ob.EndDate.Sub(ob.StartDate).Hours() / 24
|
|
|
|
|
|
// 获取销售分组信息
|
|
|
sellerList, e := crmService.GetSellerDepartmentListWithGroupAndTeam()
|
|
@@ -418,7 +418,6 @@ func (rg *RegisterController) Add(c *gin.Context) {
|
|
|
for i := range sellerList {
|
|
|
sellerMap[sellerList[i].SellerId] = sellerList[i]
|
|
|
}
|
|
|
- logList := make([]*fms.ContractRegisterLog, 0)
|
|
|
for _, ppItem := range invoiceList {
|
|
|
v := &fms.ContractInvoice{
|
|
|
ContractRegisterId: ob.ContractRegisterId,
|
|
@@ -485,6 +484,7 @@ func (rg *RegisterController) Add(c *gin.Context) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ //处理重复公司名日期等重复的开票到款记录
|
|
|
dupList, e := fms.GetDuplicateContractInvoiceDetailItemList(ob.CompanyName, req.StartDate, req.EndDate)
|
|
|
if e != nil {
|
|
|
err = fmt.Errorf("获取开票到款列表失败, Err: %s", e.Error())
|
|
@@ -601,6 +601,86 @@ func (rg *RegisterController) Add(c *gin.Context) {
|
|
|
resp.FailMsg("操作失败", "新增合同及套餐失败, Err: "+e.Error(), c)
|
|
|
return
|
|
|
}
|
|
|
+ //处理重复公司名日期等重复的开票到款记录
|
|
|
+ dupList, e := fms.GetDuplicateContractInvoiceDetailItemList(ob.CompanyName, req.StartDate, req.EndDate)
|
|
|
+ if e != nil {
|
|
|
+ err = fmt.Errorf("获取开票到款列表失败, Err: %s", e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, ppItem := range dupList {
|
|
|
+ if ppItem.ContractRegisterId != req.ContractRegisterId{
|
|
|
+ v := &fms.ContractInvoice{
|
|
|
+ ContractRegisterId: ob.ContractRegisterId,
|
|
|
+ ContractCode: ob.ContractCode,
|
|
|
+ Amount: ppItem.Amount,
|
|
|
+ OriginAmount: ppItem.OriginAmount,
|
|
|
+ CurrencyUnit: ppItem.CurrencyUnit,
|
|
|
+ InvoiceDate: ppItem.InvoiceDate,
|
|
|
+ SellerId: ppItem.SellerId,
|
|
|
+ SellerName: ppItem.SellerName,
|
|
|
+ SellerGroupId: ppItem.SellerGroupId,
|
|
|
+ SellerGroupName: ppItem.SellerGroupName,
|
|
|
+ SellerTeamId: ppItem.SellerTeamId,
|
|
|
+ SellerTeamName: ppItem.SellerTeamName,
|
|
|
+ AdminId: int(adminInfo.AdminId),
|
|
|
+ AdminName: adminInfo.RealName,
|
|
|
+ Remark: ppItem.Remark,
|
|
|
+ ServiceProductId: ppItem.ServiceProductId,
|
|
|
+ IsPrePay: 1,
|
|
|
+ StartDate: ppItem.StartDate,
|
|
|
+ EndDate: ppItem.EndDate,
|
|
|
+ }
|
|
|
+ if ppItem.InvoiceType == 3 {
|
|
|
+ v.InvoiceType = 1
|
|
|
+ } else if ppItem.InvoiceType == 4 {
|
|
|
+ v.InvoiceType = 2
|
|
|
+ }
|
|
|
+ v.Set()
|
|
|
+ // 到款登记-付款方式
|
|
|
+ v.PayType = fmsService.CalculateContractPaymentType(ppItem.Amount, ob.ContractAmount, dayDiff)
|
|
|
+
|
|
|
+ // 新增的记录
|
|
|
+ opData := ""
|
|
|
+ opDataByte, e := json.Marshal(req)
|
|
|
+ if e != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ opData = string(opDataByte)
|
|
|
+ opType := fms.ContractRegisterOpTypePreInvoice
|
|
|
+ newAmount := decimal.NewFromFloat(0).Round(2)
|
|
|
+ a := decimal.NewFromFloat(v.Amount).Round(2)
|
|
|
+ newAmount = newAmount.Add(a)
|
|
|
+ ia, _ := newAmount.Round(2).Float64()
|
|
|
+ logList = append(logList, &fms.ContractRegisterLog{
|
|
|
+ ContractRegisterId: ob.ContractRegisterId,
|
|
|
+ AdminId: int(adminInfo.AdminId),
|
|
|
+ AdminName: adminInfo.RealName,
|
|
|
+ OpData: opData,
|
|
|
+ OpType: opType,
|
|
|
+ CreateTime: nowTime,
|
|
|
+ AmountRemark: fmt.Sprint("新增", fms.ContractInvoiceKeyNameMap[opType], "金额", ia, "元"),
|
|
|
+ })
|
|
|
+
|
|
|
+ if e := v.Create(); e != nil {
|
|
|
+ resp.FailData("日期格式有误", "Err:"+e.Error(), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ //最后删除预到款记录
|
|
|
+ e = ppItem.Delete()
|
|
|
+ if e != nil {
|
|
|
+ resp.FailMsg("删除预到款记录失败", "Err:"+e.Error(), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 操作日志
|
|
|
+ go func() {
|
|
|
+ logOB := new(fms.ContractRegisterLog)
|
|
|
+ if e := logOB.AddInBatches(logList); e != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }()
|
|
|
}
|
|
|
|
|
|
// 操作日志
|