瀏覽代碼

add:回款明细

zoie 1 年之前
父節點
當前提交
627d1b7ee1
共有 5 個文件被更改,包括 191 次插入53 次删除
  1. 2 2
      conf/app.conf
  2. 75 5
      controllers/Contract.go
  3. 1 0
      main.go
  4. 109 45
      models/Contract/Contract.go
  5. 4 1
      routers/Contract.go

+ 2 - 2
conf/app.conf

@@ -12,7 +12,7 @@ NatsServer_Url = "175.178.229.79:4222"
 
 
 # Mysql 线上
-MysqlServer_UrlPort = "192.168.192.251:3306"
+MysqlServer_UrlPort = "127.0.0.1:3316"
 MysqlServer_Database = "erp_storage_test"
 MysqlServer_Username = "erp_storage_test"
 MysqlServer_Password = "cHFeFmxFhZJdijDn"
@@ -28,7 +28,7 @@ MysqlMqtt_MaxIdleConnections = 100
 MysqlMqtt_MaxOpenConnections = 200
 
 # Redis
-Redis_address = "192.168.192.251:6379"
+Redis_address = "127.0.0.1:6378"
 Redis_password = ""
 Redis_dbNum = "2"
 

+ 75 - 5
controllers/Contract.go

@@ -184,6 +184,9 @@ func (c *ContractController) Contract_Add() {
 		T_invoice:    T_invoice,
 	}
 
+	_, var_.T_recoveries_money = Contract.ContractToContractFinance_R(T_recoveries)
+	_, var_.T_invoice_money = Contract.ContractToContractFinance_R(T_invoice)
+
 	o := orm.NewOrm()
 	o.Begin()
 	ContractDao := Contract.NewContract(o)
@@ -282,6 +285,7 @@ func (c *ContractController) Contract_Edit() {
 	T_number := c.GetString("T_number")
 	T_customer := c.GetString("T_customer")
 	T_money, _ := c.GetFloat("T_money")
+	T_discount, _ := c.GetFloat("T_discount") // 优惠价
 	T_date := c.GetString("T_date")
 	T_product := c.GetString("T_product")
 	T_remark := c.GetString("T_remark")
@@ -310,6 +314,9 @@ func (c *ContractController) Contract_Edit() {
 	if T_money > 0 {
 		contract.T_money = float32(T_money)
 	}
+	if T_discount > 0 {
+		contract.T_discount = float32(T_discount)
+	}
 	if len(T_date) > 0 {
 		contract.T_date = T_date
 	}
@@ -324,9 +331,11 @@ func (c *ContractController) Contract_Edit() {
 	}
 	if len(T_recoveries) > 0 {
 		contract.T_recoveries = T_recoveries
+		_, contract.T_recoveries_money = Contract.ContractToContractFinance_R(T_recoveries)
 	}
 	if len(T_invoice) > 0 {
 		contract.T_invoice = T_invoice
+		_, contract.T_invoice_money = Contract.ContractToContractFinance_R(T_invoice)
 	}
 	if len(T_submit) > 0 {
 		contract.T_submit = T_submit
@@ -337,7 +346,8 @@ func (c *ContractController) Contract_Edit() {
 		contract.T_State = 3
 	}
 
-	err = ContractDao.Update_Contract(contract, "T_customer", "T_money", "T_date", "T_remark", "T_pdf", "T_State", "T_project", "T_recoveries", "T_invoice", "T_submit")
+	err = ContractDao.Update_Contract(contract, "T_customer", "T_money", "T_discount", "T_date", "T_remark", "T_pdf", "T_State",
+		"T_project", "T_recoveries", "T_recoveries_money", "T_invoice", "T_invoice_money", "T_submit")
 	if err != nil {
 		o.Rollback()
 		c.Data["json"] = lib.JSONS{Code: 203, Msg: "添加失败"}
@@ -687,7 +697,8 @@ func (c *ContractController) VerifyContract_Add() {
 		T_start_date:  T_start_date,
 		T_end_date:    T_end_date,
 	}
-
+	_, var_.T_recoveries_money = Contract.ContractToContractFinance_R(T_recoveries)
+	_, var_.T_invoice_money = Contract.ContractToContractFinance_R(T_invoice)
 	o := orm.NewOrm()
 	o.Begin()
 	ContractDao := Contract.NewContract(o)
@@ -734,7 +745,7 @@ func (c *ContractController) VerifyContract_Add() {
 			T_product_id:      product_id,
 			T_product_total:   num,
 			T_product_out:     0,              // 已出库数量
-			T_price:           float32(price), // 已出库数量
+			T_price:           float32(price), // 价格
 			T_State:           1,              // 1-未出库 2-已部分出库 3-已全部出库
 		}
 		if product.T_class < 0 {
@@ -824,9 +835,11 @@ func (c *ContractController) VerifyContract_Edit() {
 	}
 	if len(T_recoveries) > 0 {
 		contract.T_recoveries = T_recoveries
+		_, contract.T_recoveries_money = Contract.ContractToContractFinance_R(T_recoveries)
 	}
 	if len(T_invoice) > 0 {
 		contract.T_invoice = T_invoice
+		_, contract.T_invoice_money = Contract.ContractToContractFinance_R(T_invoice)
 	}
 	if len(T_start_date) > 0 {
 		contract.T_start_date = T_start_date
@@ -838,7 +851,8 @@ func (c *ContractController) VerifyContract_Edit() {
 		contract.T_submit = T_submit
 	}
 
-	err = ContractDao.Update_Contract(contract, "T_money", "T_date", "T_remark", "T_pdf", "T_State", "T_project", "T_recoveries", "T_invoice", "T_start_date", "T_end_date", "T_submit")
+	err = ContractDao.Update_Contract(contract, "T_money", "T_date", "T_remark", "T_pdf", "T_State", "T_project",
+		"T_recoveries", "T_recoveries_money", "T_invoice", "T_invoice_money", "T_start_date", "T_end_date", "T_submit")
 	if err != nil {
 		o.Rollback()
 		c.Data["json"] = lib.JSONS{Code: 203, Msg: "添加失败"}
@@ -879,6 +893,7 @@ func (c *ContractController) VerifyContract_Edit() {
 	for _, v := range productList {
 		product_id, _ := strconv.Atoi(strings.Split(v, ",")[0])
 		num, _ := strconv.Atoi(strings.Split(v, ",")[1])
+		price := lib.StringToFloat64TwoDecimal(strings.Split(v, ",")[2])
 		oldContractProduct, ok := allList[product_id]
 		if !ok {
 			contractProduct := Contract.ContractProduct{
@@ -905,7 +920,11 @@ func (c *ContractController) VerifyContract_Edit() {
 		if oldNum == num {
 			continue
 		}
-		cp := Contract.ContractProduct{Id: contractProductId, T_product_total: num}
+		cp := Contract.ContractProduct{
+			Id:              contractProductId,
+			T_product_total: num,
+			T_price:         float32(price), // 价格
+		}
 		err = ContractProductDao.Update_ContractProduct(cp, "T_product_total")
 		if err != nil {
 			o.Rollback()
@@ -1132,6 +1151,41 @@ func (c *ContractController) VerifyContract_Customer_List() {
 	return
 }
 
+// 合同回款明细列表
+func (c *ContractController) Contract_List_RecoveriesMoney() {
+
+	// 分页参数 初始化
+	page, _ := c.GetInt("page")
+	if page < 1 {
+		page = 1
+	}
+	page_z, _ := c.GetInt("page_z")
+	if page_z < 1 {
+		page_z = conf.Page_size
+	}
+
+	// 查询
+	T_name := c.GetString("T_name")
+	T_recoveries_state, _ := c.GetInt("T_recoveries_state") // 回款状态 1 未回款 2 部分回款 3 全部回款
+	T_invoice_state, _ := c.GetInt("T_invoice_state")       // 开票状态 1 未开票 2 部分开票 3 全部开票
+
+	userList, _ := NatsServer.Read_User_List_All()
+	Account.Read_User_All_Map(userList)
+
+	ContractDao := Contract.NewContract(orm.NewOrm())
+	R_List, R_cnt := ContractDao.Read_Contract_List_For_RecoveriesAndInvoice(T_name, T_recoveries_state, T_invoice_state, page, page_z)
+
+	var r_jsons lib.R_JSONS
+	r_jsons.Num = R_cnt
+	r_jsons.Data = R_List
+	r_jsons.Page = page
+	r_jsons.Page_size = int(math.Ceil(float64(R_cnt) / float64(page_z)))
+
+	c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
+	c.ServeJSON()
+	return
+}
+
 func Cron_VerifyContract() {
 
 	//创建一个定时任务对象
@@ -1163,3 +1217,19 @@ func Cron_VerifyContract_ChangeState() {
 		}
 	}
 }
+
+// 修改回款金额及开票金额
+func UpdateVerifyContract_RecoveriesInvoice_Money() {
+	ContractDao := Contract.NewContract(orm.NewOrm())
+
+	R_List, _ := ContractDao.Read_VerifyContract_List("", "", 0, 9999)
+
+	for _, verify := range R_List {
+		R := Contract.Contract{Id: verify.Id}
+
+		_, R.T_recoveries_money = Contract.ContractToContractFinance_R(verify.T_recoveries)
+		_, R.T_invoice_money = Contract.ContractToContractFinance_R(verify.T_invoice)
+
+		ContractDao.Update_Contract(R, "T_recoveries_money", "T_invoice_money")
+	}
+}

+ 1 - 0
main.go

@@ -73,6 +73,7 @@ func main() {
 	go controllers.Cron_StockMonth()      // 库存明细详情定时任务
 	go controllers.Cron_VerifyContract()  // 验证合同状态修改定时任务
 	go controllers.CheckPowerUniformity() // 检查角色是否与用户系统一致,不存在则添加
+	go controllers.UpdateVerifyContract_RecoveriesInvoice_Money()
 	beego.Run()
 
 }

+ 109 - 45
models/Contract/Contract.go

@@ -15,23 +15,25 @@ import (
 
 // 合同
 type Contract struct {
-	Id            int     `orm:"column(ID);size(11);auto;pk"`
-	T_number      string  `orm:"size(256);null"`         // 合同编号
-	T_customer    string  `orm:"size(256);null"`         // 客户名称
-	T_customer_id string  `orm:"size(256);null"`         // 客户id
-	T_money       float32 `orm:"digits(12);decimals(2)"` // 合同金额
-	T_discount    float32 `orm:"digits(12);decimals(2)"` // 合同优惠价
-	T_project     string  `orm:"size(256);null"`         // 项目
-	T_type        int     `orm:"size(2);default(1)"`     // 合同类型 1-销售合同 2-验证合同
-	T_date        string  `orm:"size(256);null"`         // 签订时间
-	T_out         int     `orm:"size(2);default(1)"`     // 出库状态  1-未出库 2-部分出库 3-已出库
-	T_State       int     `orm:"size(2);default(1)"`     // 0 删除(伪删除)  1-已通过 2-未通过 3-待审核 审核状态
-	T_pdf         string  `orm:"size(256);null"`         // 附件
-	T_remark      string  `orm:"type(text);null"`        // 备注
-	T_recoveries  string  `orm:"type(text);null"`        // 回款信息 回款时间,回款金额|回款时间,回款金额|
-	T_invoice     string  `orm:"type(text);null"`        // 开票信息 开票时间,开票金额|开票时间,开票金额|
-	T_start_date  string  `orm:"size(256);null"`         // 起始时间
-	T_end_date    string  `orm:"size(256);null"`         // 终止时间
+	Id                 int     `orm:"column(ID);size(11);auto;pk"`
+	T_number           string  `orm:"size(256);null"`         // 合同编号
+	T_customer         string  `orm:"size(256);null"`         // 客户名称
+	T_customer_id      string  `orm:"size(256);null"`         // 客户id
+	T_money            float32 `orm:"digits(12);decimals(2)"` // 合同金额
+	T_discount         float32 `orm:"digits(12);decimals(2)"` // 合同优惠价
+	T_project          string  `orm:"size(256);null"`         // 项目
+	T_type             int     `orm:"size(2);default(1)"`     // 合同类型 1-销售合同 2-验证合同
+	T_date             string  `orm:"size(256);null"`         // 签订时间
+	T_out              int     `orm:"size(2);default(1)"`     // 出库状态  1-未出库 2-部分出库 3-已出库
+	T_State            int     `orm:"size(2);default(1)"`     // 0 删除(伪删除)  1-已通过 2-未通过 3-待审核 审核状态
+	T_pdf              string  `orm:"size(256);null"`         // 附件
+	T_remark           string  `orm:"type(text);null"`        // 备注
+	T_recoveries       string  `orm:"type(text);null"`        // 回款信息 回款时间,回款金额|回款时间,回款金额|
+	T_recoveries_money float32 `orm:"digits(12);decimals(2)"` // 回款总金额
+	T_invoice          string  `orm:"type(text);null"`        // 开票信息 开票时间,开票金额|开票时间,开票金额|
+	T_invoice_money    float32 `orm:"digits(12);decimals(2)"` // 开票总金额
+	T_start_date       string  `orm:"size(256);null"`         // 起始时间
+	T_end_date         string  `orm:"size(256);null"`         // 终止时间
 
 	T_submit   string `orm:"size(256);null"` // 合同提交人员
 	T_approver string `orm:"size(256);null"` // 审批人
@@ -58,20 +60,23 @@ func init() {
 }
 
 type Contract_R struct {
-	Id              int
-	T_number        string  // 合同编号
-	T_customer      string  // 客户名称
-	T_money         float32 // 合同金额
-	T_discount      float32 // 合同优惠价
-	T_type          int     // 合同类型 1-销售合同 2-验证合同
-	T_date          string  // 签订时间
-	T_out           int     // 出库状态  1-未出库 2-已部分出库 3-已全部出库
-	T_submit        string  // 合同提交人员uuid
-	T_submit_name   string  // 合同提交人员名称
-	T_approver      string  // 合同审批人员uuid
-	T_approver_name string  // 合同审批人员名称
-	T_pdf           string  // 附件
-	T_State         int     // 1-已通过 2-未通过 3-待审核 审核状态
+	Id                 int
+	T_number           string  // 合同编号
+	T_customer         string  // 客户名称
+	T_money            float32 // 合同金额
+	T_discount         float32 // 合同优惠价 验证合同才有优惠价
+	T_type             int     // 合同类型 1-销售合同 2-验证合同
+	T_date             string  // 签订时间
+	T_out              int     // 出库状态  1-未出库 2-已部分出库 3-已全部出库
+	T_submit           string  // 合同提交人员uuid
+	T_submit_name      string  // 合同提交人员名称
+	T_approver         string  // 合同审批人员uuid
+	T_approver_name    string  // 合同审批人员名称
+	T_pdf              string  // 附件
+	T_State            int     // 1-已通过 2-未通过 3-待审核 审核状态
+	T_recoveries_money float32 // 回款总金额
+	T_invoice_money    float32 // 开票总金额
+
 }
 
 type Contract_Detail struct {
@@ -113,6 +118,8 @@ type Contract_Verify struct {
 	T_start_date   string  // 起始时间
 	T_end_date     string  // 终止时间
 	T_verify_state int     // 1-未签约 2-已作废 3-已签约 4-即将到期
+	T_recoveries   string  // 回款信息
+	T_invoice      string  // 开票信息
 }
 
 func ContractToContractFinance_R(T_detail string) (r []ContractFinance_R, money float32) {
@@ -138,23 +145,11 @@ func ContractToContractFinance_R(T_detail string) (r []ContractFinance_R, money
 func ContractToContract_R(t Contract) (r Contract_R) {
 	// 1-未出库 2-已部分出库 3-已全部出库
 	r.T_out = t.T_out
-	// 1-已通过 2-未通过 3-待审核
-	//if t.T_State == 1 {
-	//	r.T_out = 2
-	//	state := Read_ContractProduct_T_State_List(t.T_number)
-	//	if len(state) == 1 {
-	//		if state[0] == 1 {
-	//			r.T_out = 1
-	//		}
-	//		if state[0] == 3 {
-	//			r.T_out = 3
-	//		}
-	//	}
-	//}
 	r.Id = t.Id
 	r.T_number = t.T_number
 	r.T_customer = t.T_customer
 	r.T_money = t.T_money
+	r.T_discount = t.T_discount
 	r.T_type = t.T_type
 	r.T_date = t.T_date
 	r.T_State = t.T_State
@@ -163,6 +158,8 @@ func ContractToContract_R(t Contract) (r Contract_R) {
 	r.T_submit_name = Account.Read_User_T_name_Get(t.T_submit)
 	r.T_approver = t.T_approver
 	r.T_approver_name = Account.Read_User_T_name_Get(t.T_approver)
+	r.T_recoveries_money = t.T_recoveries_money
+	r.T_invoice_money = t.T_invoice_money
 	return r
 }
 
@@ -232,6 +229,8 @@ func ContractToContract_Verify(t Contract) (r Contract_Verify) {
 	}
 
 	r.T_verify_state = state
+	r.T_recoveries = t.T_recoveries
+	r.T_invoice = t.T_invoice
 
 	return r
 }
@@ -355,7 +354,10 @@ func (dao *ContractDaoImpl) Read_VerifyContract_List(T_name, T_customer_id strin
 
 	// 过滤
 	cond := orm.NewCondition()
-	cond1 := cond.And("T_State__gt", 0).And("T_type", 2).And("T_customer_id", T_customer_id)
+	cond1 := cond.And("T_State__gt", 0).And("T_type", 2)
+	if len(T_customer_id) > 0 {
+		cond1 = cond1.And("T_customer_id", T_customer_id)
+	}
 	if len(T_name) > 0 {
 		cond1 = cond1.AndCond(cond.Or("T_number__icontains", T_name).Or("T_customer__icontains", T_name))
 	}
@@ -387,6 +389,68 @@ func (dao *ContractDaoImpl) Read_VerifyContract_List(T_name, T_customer_id strin
 	return r_, cnt
 }
 
+func (dao *ContractDaoImpl) Read_Contract_List_For_RecoveriesAndInvoice(T_name string, T_recoveries_state, T_invoice_state, page, page_z int) (r_ []Contract_R, cnt int64) {
+	// 也可以直接使用 Model 结构体作为表名
+	qs := dao.orm.QueryTable(new(Contract))
+	var offset int64
+	if page <= 1 {
+		offset = 0
+	} else {
+		offset = int64((page - 1) * page_z)
+	}
+
+	// 过滤
+	cond := orm2.NewCondition()
+	cond = cond.And("T_State", 1)
+	// 回款状态 1 未回款 2 部分回款 3 全部回款
+	// 开票状态 1 未开票 2 部分开票 3 全部开票
+	if len(T_name) > 0 {
+		cond = cond.AndCond(cond.Or("T_number__icontains", T_name).Or("T_customer__icontains", T_name))
+	}
+	qs = qs.SetCond(cond)
+
+	if T_recoveries_state == 1 {
+		qs = qs.FilterRaw("t_recoveries_money", " = 0")
+	}
+	if T_recoveries_state == 2 {
+		qs = qs.FilterRaw("t_recoveries_money", " < t_discount").FilterRaw("t_recoveries_money", " > 0")
+	}
+	if T_recoveries_state == 3 {
+		qs = qs.FilterRaw("t_recoveries_money", " = t_discount")
+	}
+
+	if T_invoice_state == 1 {
+		qs = qs.FilterRaw("t_invoice_money", " = 0")
+	}
+	if T_invoice_state == 2 {
+		qs = qs.FilterRaw("t_invoice_money", " < t_discount").FilterRaw("t_invoice_money", " > 0")
+	}
+	if T_invoice_state == 3 {
+		qs = qs.FilterRaw("t_invoice_money", " = t_discount")
+	}
+	cond = qs.GetCond()
+	// 查询
+	var r []Contract
+	_, err := qs.Limit(page_z, offset).SetCond(cond).OrderBy("-Id").All(&r)
+
+	if err != nil {
+		logs.Error(lib.FuncName(), err)
+		return
+	}
+
+	cnt, err = qs.SetCond(cond).Count()
+	if err != nil {
+		logs.Error(lib.FuncName(), err)
+		return
+	}
+
+	for _, v := range r {
+		r_ = append(r_, ContractToContract_R(v))
+	}
+
+	return r_, cnt
+}
+
 // 获取最新的验证合同
 func (dao *ContractDaoImpl) Read_VerifyContract_Newest(T_customer_id string) (r_ Contract) {
 	// 也可以直接使用 Model 结构体作为表名

+ 4 - 1
routers/Contract.go

@@ -28,5 +28,8 @@ func init() {
 		beego.NSRouter("/Add_Customer", &controllers.ContractController{}, "*:VerifyContract_Add_Customer"),       // 添加客户
 		beego.NSRouter("/Update_Customer", &controllers.ContractController{}, "*:VerifyContract_Update_Customer"), // 编辑客户
 	)
-	beego.AddNamespace(contract, verifyContract)
+	recoveriesContract := beego.NewNamespace("/RecoveriesContract",
+		beego.NSRouter("/List", &controllers.ContractController{}, "*:Contract_List_RecoveriesMoney"), // 回款明细列表
+	)
+	beego.AddNamespace(contract, verifyContract, recoveriesContract)
 }