ziwen 1 éve
szülő
commit
8b784a0168

+ 1 - 1
controller/contract/pre_register.go

@@ -828,7 +828,7 @@ func (rg *PreRegisterController) Detail(c *gin.Context) {
 		return
 	}
 
-	dupList, e := fms.GetDuplicateContractInvoiceDetailItemList(nItme.CompanyName, nItme.StartDate, nItme.EndDate, req.InvoiceType)
+	dupList, e := fms.GetDuplicateContractInvoiceDetailItemListWithType(nItme.CompanyName, nItme.StartDate, nItme.EndDate, req.InvoiceType)
 	if e != nil {
 		err = fmt.Errorf("获取开票到款列表失败, Err: %s", e.Error())
 		return

+ 75 - 0
controller/contract/register.go

@@ -484,6 +484,81 @@ func (rg *RegisterController) Add(c *gin.Context) {
 				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
+				}
+			}
+		}
+
+
 		ppOB := new(fms.ContractPreRegister)
 		items, e := ppOB.FetchByRegisterId(req.ContractRegisterId)
 		if e != nil {

+ 16 - 2
models/fms/contract_invoice.go

@@ -598,8 +598,8 @@ func (c *ContractInvoice) FetchByRegisterId(registerId int) (items []*ContractIn
 	return
 }
 
-// GetDuplicateContractInvoiceDetailItemList 预登记列表详情用-获取开票到款列表
-func GetDuplicateContractInvoiceDetailItemList(companyName, startDate, endDate string, invoiceType int) (itemList []*ContractInvoiceDetailItem, err error) {
+// GetDuplicateContractInvoiceDetailItemListWithType 预登记列表详情用-获取开票到款列表
+func GetDuplicateContractInvoiceDetailItemListWithType(companyName, startDate, endDate string, invoiceType int) (itemList []*ContractInvoiceDetailItem, err error) {
 	list := make([]*ContractInvoice, 0)
 	err = global.DEFAULT_MYSQL.Table("contract_invoice as a ").
 		Select(" a.* ").
@@ -617,4 +617,18 @@ func GetDuplicateContractInvoiceDetailItemList(companyName, startDate, endDate s
 func GetContractInvoiceByRegisterIdAndType(registerId int) (items *ContractInvoice, err error) {
 	err = global.DEFAULT_MYSQL.Model(ContractInvoice{}).Where("is_deleted = 0 AND contract_register_id = ? AND invoice_type = 2", registerId).Order("create_time DESC").First(&items).Error
 	return
+}
+
+// GetDuplicateContractInvoiceDetailItemList 预登记列表详情用-获取开票到款列表
+func GetDuplicateContractInvoiceDetailItemList(companyName, startDate, endDate string) (list []*ContractInvoice, err error) {
+	err = global.DEFAULT_MYSQL.Table("contract_invoice as a ").
+		Select(" a.* ").
+		Joins(" JOIN contract_register as b ON a.contract_register_id = b.contract_register_id ").
+		Where(fmt.Sprintf("a.is_deleted = 0 AND b.company_name = '%s' AND b.start_date= '%s' AND b.end_date= '%s' AND b.is_deleted=0 AND (a.invoice_type=3 OR a.invoice_type=4) ",companyName, startDate, endDate)).
+		Order("a.contract_invoice_id ASC").
+		Find(&list).Error
+	if err != nil {
+		return
+	}
+	return
 }