Bladeren bron

前后:结算金额总数

dubch 4 jaren geleden
bovenliggende
commit
c1fc5008e7

+ 12 - 0
src/dashoo.cn/backend/api/business/oilcontract/contract/contract.go

@@ -77,6 +77,18 @@ type OilContract struct {
 	ImportSecondUnit     string    `json:"ImportSecondUnit" xorm:"comment('导入二级单位') VARCHAR(255) 'ImportSecondUnit'"`
 	Class     			 string    `json:"Class" xorm:"comment('类别') VARCHAR(255) 'Class'"`
 }
+type OilContractMoney struct {
+	Id                   int       `json:"Id" xorm:"not null pk autoincr INT(11) 'Id'"`
+	ContractId           int       `json:"ContractId" xorm:"default 0 comment('合同ID') INT(11) 'ContractId'"`
+	Year         		 string    `json:"Year" xorm:"comment('年份') VARCHAR(50) 'Year'"`
+	Money          		 string    `json:"Money" xorm:"comment('当年结算金额') VARCHAR(255) 'Money'"`
+	CreateOn             time.Time `json:"CreateOn" xorm:"DATETIME 'CreateOn'"`
+	CreateUserId         int       `json:"CreateUserId" xorm:"INT(11) 'CreateUserId'"`
+	CreateBy             string    `json:"CreateBy" xorm:"VARCHAR(50) 'CreateBy'"`
+	ModifiedOn           time.Time `json:"ModifiedOn" xorm:"DATETIME 'ModifiedOn'"`
+	ModifiedUserId       int       `json:"ModifiedUserId" xorm:"INT(11) 'ModifiedUserId'"`
+	ModifiedBy           string    `json:"ModifiedBy" xorm:"default '1' VARCHAR(50) 'ModifiedBy'"`
+}
 type OilContractItems struct {
 	Items []OilContract
 }

+ 8 - 0
src/dashoo.cn/backend/api/business/oilcontract/contract/contractService.go

@@ -13,4 +13,12 @@ func GetOilContractService(xormEngine *xorm.Engine) *OilContractService {
 	s := new(OilContractService)
 	s.DBE = xormEngine
 	return s
+}
+
+func (s *OilContractService) GetSum(entitiesPtr interface{}, where string) {
+
+	sql := ` select sum(Money) as Money from OilContractMoney`
+	sql += ` where ` + where
+
+	s.DBE.SQL(sql).Get(entitiesPtr)
 }

+ 76 - 0
src/dashoo.cn/backend/api/controllers/oilcontract/contract.go

@@ -831,11 +831,24 @@ func (this *OilContractController) AddEntity() {
 	svc := contract.GetOilContractService(utils.DBE)
 
 	json.Unmarshal(jsonBlob, &model)
+
+	if model.IsYear == 1 && model.IsYearMoney == "" {
+		errinfo.Message = "跨年当年结算金额必填"
+		errinfo.Code = -2
+		this.Data["json"] = &errinfo
+		this.ServeJSON()
+		return
+	}
+	if model.IsYearMoney == "" {
+		model.IsYearMoney = model.PerformAmount
+	}
+	model.ImportStatus = 2
 	model.CreateOn = time.Now()
 	model.CreateBy = this.User.Realname
 	model.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
 	model.SecondUnit = this.User.UnitId
 
+	var model1 contract.OilContractMoney
 	var contract contract.OilContract
 	tempCount, _ := svc.GetCount(&contract, "ContractNo='"+model.ContractNo+"' ")
 	if tempCount > 0 {
@@ -849,6 +862,17 @@ func (this *OilContractController) AddEntity() {
 	_, err := svc.InsertEntityBytbl(OilContractName, &model)
 
 	if err == nil {
+		if model.IsYear == 1 {
+			svc.GetEntityByWhere(OilContractName, "ContractNo = '" + model.ContractNo + "'", &model)
+			svc.GetEntityByWhere("OilContractMoney", "Year = '" + time.Now().Format("2006") + "' and ContractId = " + strconv.Itoa(model.Id), &model1)
+			model1.ContractId = model.Id
+			model1.Money = model.IsYearMoney
+			model1.Year = time.Now().Format("2006")
+			model1.CreateOn = time.Now()
+			model1.CreateBy = this.User.Realname
+			model1.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
+			svc.InsertEntityBytbl("OilContractMoney", &model1)
+		}
 		//新增
 		errinfo.Message = "添加成功!"
 		errinfo.Code = 0
@@ -880,10 +904,20 @@ func (this *OilContractController) UpdateEntity() {
 	}
 
 	var model contract.OilContract
+	var model1 contract.OilContractMoney
 	svc := contract.GetOilContractService(utils.DBE)
 
 	var jsonBlob = this.Ctx.Input.RequestBody
 	json.Unmarshal(jsonBlob, &model)
+
+	if model.IsYear == 1 && model.IsYearMoney == "" {
+		errinfo.Message = "跨年当年结算金额必填"
+		errinfo.Code = -2
+		this.Data["json"] = &errinfo
+		this.ServeJSON()
+		return
+	}
+
 	if model.IsYearMoney == "" {
 		model.IsYearMoney = model.PerformAmount
 	}
@@ -1030,6 +1064,24 @@ func (this *OilContractController) UpdateEntity() {
 
 	err := svc.UpdateEntityBytbl(OilContractName, id, &model, cols)
 	if err == nil {
+		if model.IsYear == 1 && model.IsYearMoney != "" {
+			svc.GetEntityByWhere("OilContractMoney", "Year = '" + time.Now().Format("2006") + "' and ContractId = " + id, &model1)
+			if model1.Id > 0 {
+				model1.Money = model.IsYearMoney
+				model1.ModifiedOn = time.Now()
+				model1.ModifiedBy = this.User.Realname
+				model1.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int()
+				svc.UpdateEntityBytbl("OilContractMoney", model1.Id, &model1, []string{"Money"})
+			} else {
+				model1.ContractId,_ = strconv.Atoi(id)
+				model1.Money = model.IsYearMoney
+				model1.Year = time.Now().Format("2006")
+				model1.CreateOn = time.Now()
+				model1.CreateBy = this.User.Realname
+				model1.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
+				svc.InsertEntityBytbl("OilContractMoney", &model1)
+			}
+		}
 		errinfo.Message = "修改成功!"
 		errinfo.Code = 0
 		this.Data["json"] = &errinfo
@@ -1089,3 +1141,27 @@ func (this *OilContractController) DeleteEntity() {
 		this.ServeJSON()
 	}
 }
+
+// @Title 获取合同结算金额总数
+// @Description
+// @Success 200 {object} ErrorInfo
+// @Failure 403 :id 为空
+// @router /countMoney/:Id [get]
+func (this *OilContractController) CountMoney() {
+	Id := this.Ctx.Input.Param(":Id")
+	var errinfo ErrorInfo
+	if Id == "" {
+		errinfo.Message = "操作失败!请求信息不完整"
+		errinfo.Code = -2
+		this.Data["json"] = &errinfo
+		this.ServeJSON()
+		return
+	}
+
+
+	var model contract.OilContractMoney
+	svc := contract.GetOilContractService(utils.DBE)
+	svc.GetSum(&model, "Year != '" + time.Now().Format("2006")  + "'")
+	this.Data["json"] = &model
+	this.ServeJSON()
+}

+ 6 - 0
src/dashoo.cn/frontend_web/src/api/oilcontract/contract.js

@@ -220,6 +220,12 @@ export default {
       url: `/contract-review/exportword/${id}`,
       method: 'get'
     })
+  },
+  countMoney (id, myAxios) {
+    return myAxios({
+      url: `/contract/countMoney/${id}`,
+      method: 'get'
+    })
   }
 
 }

+ 47 - 8
src/dashoo.cn/frontend_web/src/pages/oilcontract/contract-import/_opera/operation.vue

@@ -83,7 +83,7 @@
             </el-form-item>
           </el-col>
           <el-col :span="8">
-            <el-form-item label="是否跨年" prop="SettleStatus">
+            <el-form-item label="是否跨年" prop="IsYear">
               <el-select v-model="formData.IsYear" placeholder="请选择" style="width: 100%">
                 <el-option label="否" :value=0 key="0"></el-option>
                 <el-option label="是" :value=1 key="1"></el-option>
@@ -678,8 +678,8 @@ export default {
         Id: '',
         SupplierId: '',
         SupplierName: '',
-        Status: '',
-        SettleStatus: '',
+        Status: 1,
+        SettleStatus: '1',
         ProjectName: '',
         ContractNo: '',
         ProjectPlace: '',
@@ -742,6 +742,7 @@ export default {
       },
       SupplierSelectList: [],//企业名称列表
       dictionary: '',//数据字典
+      Money: 0,
 
       //下拉选择项
       //wellNoOptions: [],
@@ -761,18 +762,27 @@ export default {
       console.error(err)
     })
 
-    this.serviceId = this.$route.params.opera;
-    this.getDictOptions();
+    this.serviceId = this.$route.params.opera
+    this.getDictOptions()
     if (this.serviceId != 'add' && this.serviceId > 0) {
-      this.formData.Id = this.serviceId;
-      this.initDatas();
+      this.formData.Id = this.serviceId
+      this.countMoney(this.formData.Id)
+      this.initDatas()
       this.successBoolean = true
     } else {
-      this.formData.Id = 0;
+      this.formData.Id = 0
     }
     this.statusFun()
   },
   methods: {
+    countMoney(id) {
+      api.countMoney(id, this.$axios).then(res => {
+        if (res.data.Money !== '') {
+          this.Money = parseFloat(res.data.Money)
+        }
+        console.log(this.Money, 'this.Money')
+      })
+    },
     dateChange() {
       if (this.formData.OpenDate && this.formData.ContractPeriod) {
         var d = new Date(this.formData.OpenDate)
@@ -912,6 +922,34 @@ export default {
       this.$refs['EntityForm'].validate((valid) => {
         if (valid) {
           //this.formData.WellNo = this.$refs.selectWellNo.selectedLabel + '';
+          if (parseFloat(this.formData.IsYearMoney) > parseFloat(this.formData.Amount)) {
+            this.$message({
+              type: 'warning',
+              message: "结算金额不能大于合同总金额"
+            })
+            return false
+          }
+          if (parseFloat(this.formData.IsYearMoney) > (parseFloat(this.formData.Amount) - this.Money)) {
+            this.$message({
+              type: 'warning',
+              message: "总结算金额不能大于合同总金额"
+            })
+            return false
+          }
+          if (parseFloat(this.formData.PerformAmount) > parseFloat(this.formData.Amount)) {
+            this.$message({
+              type: 'warning',
+              message: "履行金额不能大于合同总金额"
+            })
+            return false
+          }
+          if (parseFloat(this.formData.BudgetAmount) > parseFloat(this.formData.Amount)) {
+            this.$message({
+              type: 'warning',
+              message: "预算金额不能大于合同总金额"
+            })
+            return false
+          }
           if (this.formData.IsYear === 1 && (this.formData.IsYearMoney === '' || this.formData.IsYearMoney === undefined)) {
             this.$message({
               type: 'warning',
@@ -996,6 +1034,7 @@ export default {
     },
 
     updateEntity() {
+      this.formData.PlanFinishDate = new Date(this.msToDate(this.formData.PlanFinishDate))
       console.log('编辑前的数据', this.formData)
       api.updateEntity(this.formData.Id, this.formData, this.$axios).then(res => {
         if (res.data.code === 0) {