|
@@ -291,13 +291,13 @@ func (rg *RegisterController) Add(c *gin.Context) {
|
|
|
return
|
|
|
}*/
|
|
|
nowTime := time.Now().Local()
|
|
|
+ ob.ContractRegisterId = req.ContractRegisterId
|
|
|
ob.ContractCode = req.ContractCode
|
|
|
ob.RelateContractCode = req.RelateContractCode
|
|
|
ob.RelateContractMainCode = req.RelateContractMainCode
|
|
|
ob.CrmContractId = req.CrmContractId
|
|
|
ob.ContractSource = req.ContractSource
|
|
|
ob.CompanyName = req.CompanyName
|
|
|
- ob.ActualCompanyName = req.ActualCompanyName
|
|
|
ob.ProductIds = req.ProductIds
|
|
|
ob.SellerId = sellerId
|
|
|
ob.SellerName = sellerName
|
|
@@ -316,8 +316,13 @@ func (rg *RegisterController) Add(c *gin.Context) {
|
|
|
ob.Remark = req.Remark
|
|
|
ob.ServiceRemark = req.ServiceRemark
|
|
|
ob.HasPayment = req.HasPayment
|
|
|
- ob.NewCompany = req.NewCompany
|
|
|
ob.Set()
|
|
|
+ updateCols := []string{
|
|
|
+ "ContractCode","RelateContractCode", "RelateContractMainCode","CrmContractId","ContractSource",
|
|
|
+ "ProductIds", "CompanyName", "SellerId", "SellerName", "StartDate", "EndDate",
|
|
|
+ "RaiSellerId", "RaiSellerName", "ModifyTime","ContractType","ContractAmount","CurrencyUnit","RMBRate",
|
|
|
+ "SignDate","AgreedPayTime","ContractStatus","RegisterStatus", "Remark", "HasPayment",
|
|
|
+ }
|
|
|
// 存在代付的直接完成登记, 且不允许进行开票/到款登记
|
|
|
if req.HasPayment == 1 || req.ContractStatus == fms.ContractStatusEnd {
|
|
|
ob.RegisterStatus = fms.ContractRegisterStatusComplete
|
|
@@ -355,20 +360,19 @@ func (rg *RegisterController) Add(c *gin.Context) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- //新增合同信息
|
|
|
- if e = fms.CreateContractRegisterAndServicesAndPayMent(ob, serviceList); e != nil {
|
|
|
- resp.FailMsg("操作失败", "新增合同及套餐失败, Err: "+e.Error(), c)
|
|
|
+ //修改合同信息-假合同变成真合同
|
|
|
+ if e = ob.Update(updateCols); e != nil {
|
|
|
+ resp.FailMsg("操作失败", "更新合同登记失败, Err:"+e.Error(), c)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- prePayOB := new(fms.ContractInvoice)
|
|
|
- ppItem, e := prePayOB.Fetch(req.ContractInvoiceId)
|
|
|
+ invoiceOB := new(fms.ContractInvoice)
|
|
|
+ invoiceCond := `contract_register_id = ?`
|
|
|
+ invoicePars := make([]interface{}, 0)
|
|
|
+ invoicePars = append(invoicePars, req.ContractRegisterId)
|
|
|
+ invoiceList, e := invoiceOB.List(invoiceCond, invoicePars, "")
|
|
|
if e != nil {
|
|
|
- if e == utils.ErrNoRow {
|
|
|
- resp.Fail("预到款不存在或已被删除", c)
|
|
|
- return
|
|
|
- }
|
|
|
- resp.FailMsg("获取预到款记录失败", "Err:"+e.Error(), c)
|
|
|
+ resp.FailMsg("操作失败", "获取合同开票到款列表失败, Err: "+e.Error(), c)
|
|
|
return
|
|
|
}
|
|
|
// 合同有效时长(计算付款方式)
|
|
@@ -384,56 +388,76 @@ 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,
|
|
|
+ ContractCode: ob.ContractCode,
|
|
|
+ Amount: ppItem.Amount,
|
|
|
+ OriginAmount: ppItem.OriginAmount,
|
|
|
+ CurrencyUnit: ppItem.CurrencyUnit,
|
|
|
+ InvoiceDate: ppItem.InvoiceDate,
|
|
|
+ AdminId: int(adminInfo.AdminId),
|
|
|
+ AdminName: adminInfo.RealName,
|
|
|
+ Remark: ppItem.Remark,
|
|
|
+ IsPrePay: 1,
|
|
|
+ }
|
|
|
+ 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)
|
|
|
|
|
|
- v := &fms.ContractInvoice{
|
|
|
- ContractRegisterId: ob.ContractRegisterId,
|
|
|
- ContractCode: ob.ContractCode,
|
|
|
- Amount: ppItem.Amount,
|
|
|
- OriginAmount: ppItem.OriginAmount,
|
|
|
- CurrencyUnit: ppItem.CurrencyUnit,
|
|
|
- InvoiceType: fms.ContractInvoiceTypePay,
|
|
|
- InvoiceDate: ppItem.InvoiceDate,
|
|
|
- AdminId: int(adminInfo.AdminId),
|
|
|
- AdminName: adminInfo.RealName,
|
|
|
- Remark: ppItem.Remark,
|
|
|
- IsPrePay: 1,
|
|
|
- }
|
|
|
- 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, "元"),
|
|
|
+ })
|
|
|
|
|
|
- // 新增的记录
|
|
|
- logList := make([]*fms.ContractRegisterLog, 0)
|
|
|
- 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
|
|
|
+ }
|
|
|
|
|
|
- if e := v.Create(); e != nil {
|
|
|
- resp.FailData("日期格式有误", "Err:"+e.Error(), c)
|
|
|
+ //最后删除预到款记录
|
|
|
+ e = ppItem.Delete()
|
|
|
+ if e != nil {
|
|
|
+ resp.FailMsg("删除预到款记录失败", "Err:"+e.Error(), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ppOB := new(fms.ContractPreRegister)
|
|
|
+ item, e := ppOB.FetchByRegisterId(req.ContractRegisterId)
|
|
|
+ if e != nil {
|
|
|
+ if e == utils.ErrNoRow {
|
|
|
+ resp.Fail("预登记记录不存在或已被删除", c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ resp.FailMsg("获取预登记失败", "Err:"+e.Error(), c)
|
|
|
return
|
|
|
}
|
|
|
-
|
|
|
- //最后删除预到款记录
|
|
|
- e = ppItem.Delete()
|
|
|
+ e = item.Delete()
|
|
|
if e != nil {
|
|
|
- resp.FailMsg("删除预到款记录失败", "Err:"+e.Error(), c)
|
|
|
+ resp.FailMsg("删除预登记失败", "Err:"+e.Error(), c)
|
|
|
return
|
|
|
}
|
|
|
// 校验金额-是否修改状态
|
|
@@ -583,9 +607,9 @@ func (rg *RegisterController) Edit(c *gin.Context) {
|
|
|
originHasPayment := item.HasPayment
|
|
|
|
|
|
updateCols := []string{
|
|
|
- "ProductIds", "ContractCode", "RelateContractCode", "CrmContractId", "ContractSource", "CompanyName", "ActualCompanyName",
|
|
|
+ "ProductIds", "ContractCode", "RelateContractCode", "CrmContractId", "ContractSource", "CompanyName",
|
|
|
"SellerId", "SellerName", "ContractType", "ContractAmount", "StartDate", "EndDate", "SignDate", "AgreedPayTime","RaiSellerId","RaiSellerName",
|
|
|
- "ContractStatus", "RegisterStatus", "Remark", "ServiceRemark", "HasPayment", "NewCompany", "ModifyTime",
|
|
|
+ "ContractStatus", "RegisterStatus", "Remark", "ServiceRemark", "HasPayment", "ModifyTime",
|
|
|
}
|
|
|
nowTime := time.Now().Local()
|
|
|
item.ProductIds = req.ProductIds
|
|
@@ -595,7 +619,6 @@ func (rg *RegisterController) Edit(c *gin.Context) {
|
|
|
item.CrmContractId = req.CrmContractId
|
|
|
item.ContractSource = req.ContractSource
|
|
|
item.CompanyName = req.CompanyName
|
|
|
- item.ActualCompanyName = req.ActualCompanyName
|
|
|
item.SellerId = sellerId
|
|
|
item.SellerName = sellerName
|
|
|
item.RaiSellerId = raiSellerId
|
|
@@ -611,7 +634,6 @@ func (rg *RegisterController) Edit(c *gin.Context) {
|
|
|
item.Remark = req.Remark
|
|
|
item.ServiceRemark = req.ServiceRemark
|
|
|
item.HasPayment = req.HasPayment
|
|
|
- item.NewCompany = req.NewCompany
|
|
|
item.ModifyTime = nowTime
|
|
|
|
|
|
// 存在代付的直接完成登记, 且不允许进行开票/到款登记
|