Forráskód Böngészése

update:验证合同新增公司名称查询,取消合同时间判断,时间交叉也可以添加多份合同

zoie 3 hete
szülő
commit
76a4c59f93
3 módosított fájl, 102 hozzáadás és 40 törlés
  1. 64 25
      controllers/Contract.go
  2. 9 7
      controllers/Stock.go
  3. 29 8
      models/Contract/Contract.go

+ 64 - 25
controllers/Contract.go

@@ -10,6 +10,13 @@ import (
 	"ERP_storage/models/Contract"
 	"ERP_storage/models/Stock"
 	"fmt"
+	"math"
+	"net/url"
+	"os"
+	"strconv"
+	"strings"
+	"time"
+
 	"github.com/beego/beego/v2/adapter/orm"
 	beego "github.com/beego/beego/v2/server/web"
 	"github.com/robfig/cron/v3"
@@ -17,12 +24,6 @@ import (
 	natslibs "gogs.baozhida.cn/zoie/ERP_libs/Nats"
 	userlibs "gogs.baozhida.cn/zoie/ERP_libs/User"
 	"gogs.baozhida.cn/zoie/ERP_libs/lib"
-	"math"
-	"net/url"
-	"os"
-	"strconv"
-	"strings"
-	"time"
 )
 
 type ContractController struct {
@@ -593,15 +594,16 @@ func (c *ContractController) VerifyContract_List() {
 		page_z = conf.Page_size
 	}
 	T_customer_id := c.GetString("T_customer_id")
+	T_customer_name := c.GetString("T_customer_name")
 
 	// 查询
 	T_name := c.GetString("T_name")
 
 	userList, _ := NatsServer.Read_User_List_All()
 	Account.Read_User_All_Map(userList)
-
+	Contract.Read_VerifyContract_All_Map()
 	ContractDao := Contract.NewContract(orm.NewOrm())
-	R_List, R_cnt := ContractDao.Read_VerifyContract_List(T_name, T_customer_id, page, page_z)
+	R_List, R_cnt := ContractDao.Read_VerifyContract_List(T_name, T_customer_id, T_customer_name, page, page_z)
 
 	var r_jsons lib.R_JSONS
 	r_jsons.Num = R_cnt
@@ -660,14 +662,15 @@ func (c *ContractController) VerifyContract_Add() {
 	ContractDao := Contract.NewContract(o)
 	ContractProductDao := Contract.NewContractProduct(o)
 
-	_, err := ContractDao.Read_Contract_ByT_date(T_customer_id, T_start_date, T_end_date)
-	if err == nil {
-		o.Rollback()
-		c.Data["json"] = lib.JSONS{Code: 202, Msg: "合同签约时间重复!"}
-		c.ServeJSON()
-		return
-	}
-	_, err = ContractDao.Read_Contract_ByT_number(T_number)
+	// 暂时屏蔽验证合同时间检查
+	//_, err := ContractDao.Read_Contract_ByT_date(T_customer_id, T_start_date, T_end_date)
+	//if err == nil {
+	//	o.Rollback()
+	//	c.Data["json"] = lib.JSONS{Code: 202, Msg: "合同签约时间重复!"}
+	//	c.ServeJSON()
+	//	return
+	//}
+	_, err := ContractDao.Read_Contract_ByT_number(T_number)
 	if err == nil {
 		o.Rollback()
 		c.Data["json"] = lib.JSONS{Code: 202, Msg: "合同编号重复!"}
@@ -1136,9 +1139,47 @@ func Update_VerifyContract_State(T_customer_id, flag string) error {
 	VerifyContractDao := Contract.NewVerifyContract(o)
 	vcn := ContractDao.Read_VerifyContract_Newest(T_customer_id)
 	vc, err := VerifyContractDao.Read_VerifyContract_ByT_customer_id(T_customer_id)
+
 	if err != nil {
 		return err
 	}
+
+	contractList, _ := ContractDao.Read_VerifyContract_List("", T_customer_id, "", 1, 9999)
+	var (
+		earliestStart    time.Time
+		latestEnd        time.Time
+		earliestStartStr string
+		latestEndStr     string
+		hasStart         bool
+		hasEnd           bool
+	)
+	for _, info := range contractList {
+		if len(info.T_start_date) > 0 {
+			if startTime, ok := lib.DateStrToTime(info.T_start_date); ok {
+				if !hasStart || startTime.Before(earliestStart) {
+					hasStart = true
+					earliestStart = startTime
+					earliestStartStr = info.T_start_date
+				}
+			}
+		}
+		if len(info.T_end_date) > 0 {
+			if endTime, ok := lib.DateStrToTime(info.T_end_date); ok {
+				if !hasEnd || endTime.After(latestEnd) {
+					hasEnd = true
+					latestEnd = endTime
+					latestEndStr = info.T_end_date
+				}
+			}
+		}
+	}
+
+	if len(earliestStartStr) > 0 {
+		vc.T_start_date = earliestStartStr
+	}
+	if len(latestEndStr) > 0 {
+		vc.T_end_date = latestEndStr
+	}
 	if vcn.Id == 0 {
 		vc.T_sign_times = 0
 		vc.T_start_date = ""
@@ -1152,15 +1193,13 @@ func Update_VerifyContract_State(T_customer_id, flag string) error {
 	} else if flag == "DELETE" {
 		vc.T_sign_times -= 1
 	}
-	if len(vc.T_start_date) == 0 {
-		vc.T_start_date = vcn.T_start_date
-	}
-	if vc.T_end_date != vcn.T_end_date {
-		vc.T_end_date = vcn.T_end_date
-	}
 	nowTime := time.Now()
 	now := time.Date(nowTime.Year(), nowTime.Month(), nowTime.Day(), 0, 0, 0, 0, time.Local)
-	end, _ := lib.DateStrToTime(vcn.T_end_date)
+	targetEndDate := vc.T_end_date
+	if len(targetEndDate) == 0 {
+		targetEndDate = vcn.T_end_date
+	}
+	end, _ := lib.DateStrToTime(targetEndDate)
 	now2Month := now.AddDate(0, 2, 0)
 	// 1-未签约 2-已作废 3-已签约 4-即将到期
 	state := 1
@@ -1551,7 +1590,7 @@ func Cron_VerifyContract_ChangeState() {
 func UpdateVerifyContract_RecoveriesInvoice_Money() {
 	ContractDao := Contract.NewContract(orm.NewOrm())
 
-	R_List, _ := ContractDao.Read_VerifyContract_List("", "", 0, 9999)
+	R_List, _ := ContractDao.Read_VerifyContract_List("", "", "", 0, 9999)
 
 	for _, verify := range R_List {
 		R := Contract.Contract{Id: verify.Id}
@@ -1567,7 +1606,7 @@ func UpdateVerifyContract_RecoveriesInvoice_Money() {
 func UpdateVerifyContract_RecoveriesInvoice_Time() {
 	ContractDao := Contract.NewContract(orm.NewOrm())
 
-	R_List, _ := ContractDao.Read_VerifyContract_List("", "", 0, 9999)
+	R_List, _ := ContractDao.Read_VerifyContract_List("", "", "", 0, 9999)
 
 	for _, verify := range R_List {
 		R := Contract.Contract{Id: verify.Id}

+ 9 - 7
controllers/Stock.go

@@ -4519,13 +4519,15 @@ func (c *StockController) StockOut_Apply_Del() {
 			return
 		}
 
-		// 减少占用库存
-		_, err = StockDao.AddOrUpdate_Occupy_Stock(stockOut.T_depot_id, product.Id, product.T_class, product.T_name, product.T_model, v.T_num, 1)
-		if err != nil {
-			o.Rollback()
-			c.Data["json"] = lib.JSONS{Code: 203, Msg: "更新占用库存失败" + err.Error()}
-			c.ServeJSON()
-			return
+		// 只有在未被财务/总经理驳回的状态下才减少占用库存,避免重复扣减
+		if stockOut.T_state != Stock.StockOutAuditFinanceUnPass && stockOut.T_state != Stock.StockOutAuditManagerUnPass {
+			_, err = StockDao.AddOrUpdate_Occupy_Stock(stockOut.T_depot_id, product.Id, product.T_class, product.T_name, product.T_model, v.T_num, 1)
+			if err != nil {
+				o.Rollback()
+				c.Data["json"] = lib.JSONS{Code: 203, Msg: "更新占用库存失败" + err.Error()}
+				c.ServeJSON()
+				return
+			}
 		}
 	}
 

+ 29 - 8
models/Contract/Contract.go

@@ -4,13 +4,14 @@ import (
 	"ERP_storage/logs"
 	"ERP_storage/models/Account"
 	"fmt"
-	orm2 "github.com/beego/beego/v2/client/orm"
-	"gogs.baozhida.cn/zoie/ERP_libs/lib"
 	"strconv"
 	"strings"
 	"sync"
 	"time"
 
+	orm2 "github.com/beego/beego/v2/client/orm"
+	"gogs.baozhida.cn/zoie/ERP_libs/lib"
+
 	_ "github.com/astaxie/beego/cache/redis"
 	"github.com/beego/beego/v2/adapter/orm"
 	_ "github.com/go-sql-driver/mysql"
@@ -150,6 +151,7 @@ type ContractFinance_R struct {
 type Contract_Verify struct {
 	Id                 int
 	T_number           string
+	T_customer         string  // 客户名称
 	T_money            float32 // 合同金额
 	T_discount         float32 // 合同优惠价
 	T_date             string  // 签订时间
@@ -200,9 +202,6 @@ func ContractToContract_R(t Contract) (r Contract_R) {
 	r.Id = t.Id
 	r.T_number = t.T_number
 	r.T_customer = t.T_customer
-	if len(t.T_customer_id) > 0 {
-		r.T_customer = Read_VerifyContract_Get(t.T_customer_id)
-	}
 	r.T_money = t.T_money
 	r.T_discount = t.T_discount
 	r.T_type = t.T_type
@@ -322,6 +321,9 @@ func ContractToContract_Verify(t Contract) (r Contract_Verify) {
 	r.T_end_date = t.T_end_date
 	r.T_stamping_date = t.T_stamping_date
 	r.T_payment_method = t.T_payment_method
+	if len(t.T_customer_id) > 0 {
+		r.T_customer = Read_VerifyContract_Get(t.T_customer_id)
+	}
 	nowTime := time.Now()
 	now := time.Date(nowTime.Year(), nowTime.Month(), nowTime.Day(), 0, 0, 0, 0, time.Local)
 	end, _ := lib.DateStrToTime(t.T_end_date)
@@ -457,7 +459,7 @@ func (dao *ContractDaoImpl) Read_Contract_List(T_submit, T_name string, T_state,
 }
 
 // 获取列表
-func (dao *ContractDaoImpl) Read_VerifyContract_List(T_name, T_customer_id string, page, page_z int) (r_ []Contract_Verify, cnt int64) {
+func (dao *ContractDaoImpl) Read_VerifyContract_List(T_name, T_customer_id, T_customer_name string, page, page_z int) (r_ []Contract_Verify, cnt int64) {
 	// 也可以直接使用 Model 结构体作为表名
 	qs := dao.orm.QueryTable(new(Contract))
 	var offset int64
@@ -473,14 +475,33 @@ func (dao *ContractDaoImpl) Read_VerifyContract_List(T_name, T_customer_id strin
 	if len(T_customer_id) > 0 {
 		cond1 = cond1.And("T_customer_id", T_customer_id)
 	}
+	if len(T_customer_name) > 0 {
+		var verifyList []VerifyContract
+		_, err := dao.orm.QueryTable(new(VerifyContract)).
+			Filter("T_State__gt", 0).
+			Filter("T_customer__icontains", T_customer_name).
+			All(&verifyList)
+		if err != nil {
+			logs.Error(lib.FuncName(), err)
+			return nil, 0
+		}
+		if len(verifyList) == 0 {
+			return nil, 0
+		}
+		var ids []string
+		for _, verify := range verifyList {
+			ids = append(ids, verify.T_customer_id)
+		}
+		cond1 = cond1.And("T_customer_id__in", ids)
+	}
 	if len(T_name) > 0 {
-		cond1 = cond1.AndCond(cond.Or("T_number__icontains", T_name).Or("T_customer__icontains", T_name))
+		cond1 = cond1.And("T_number__icontains", T_name)
 	}
 
 	// 查询
 	var r []Contract
 	var err error
-	if page_z == 9999 || len(T_customer_id) == 0 {
+	if page_z == 9999 {
 		_, err = qs.SetCond((*orm2.Condition)(cond1)).OrderBy("-T_end_date").All(&r)
 	} else {
 		_, err = qs.Limit(page_z, offset).SetCond((*orm2.Condition)(cond1)).OrderBy("-T_end_date").All(&r)