|
|
@@ -804,7 +804,7 @@ func StockIn_Edit_StockMonth(T_date string, T_depot_id int, allProductList []int
|
|
|
// return nil
|
|
|
//}
|
|
|
//T_month := date.Format("2006-01")
|
|
|
- months := generateMonthList(date)
|
|
|
+ months := generateMonthList(date, "in")
|
|
|
o := orm.NewOrm()
|
|
|
StockOutDao := Stock.NewStockOut(o)
|
|
|
StockMonthDao := Stock.NewStockMonth(o)
|
|
|
@@ -1961,6 +1961,8 @@ func (c *StockController) StockOut_Add() {
|
|
|
T_signer_phone: T_signer_phone,
|
|
|
T_signer_date: T_signer_date,
|
|
|
T_courier_number: T_courier_number,
|
|
|
+
|
|
|
+ T_state: Stock.StockOutAlreadyOut,
|
|
|
}
|
|
|
|
|
|
StockOutProductDao := Stock.NewStockOutProduct(o)
|
|
|
@@ -2041,6 +2043,7 @@ func (c *StockController) StockOut_Add() {
|
|
|
T_num: num, // 出库数量
|
|
|
T_date: T_date, // 出库数量
|
|
|
T_relation_sn: T_relation_sn,
|
|
|
+ T_state: 1,
|
|
|
}
|
|
|
_, err = StockOutProductDao.Add_StockOutProduct(stockOutProduct)
|
|
|
if err != nil {
|
|
|
@@ -2217,16 +2220,17 @@ func (c *StockController) StockOut_Edit() {
|
|
|
DeviceDao := Stock.NewDevice(o)
|
|
|
IotCardDao := Property.NewIotCard(&o)
|
|
|
|
|
|
- // 查询入库信息
|
|
|
+ // 查询出库信息
|
|
|
StockOut, err := StockOutDao.Read_StockOut_ByT_number(T_number)
|
|
|
- T_old_date := StockOut.T_date
|
|
|
+
|
|
|
if err != nil {
|
|
|
o.Rollback()
|
|
|
c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败!"}
|
|
|
c.ServeJSON()
|
|
|
return
|
|
|
}
|
|
|
- // 查询入库产品信息
|
|
|
+ T_old_date := StockOut.T_date
|
|
|
+ // 查询出库产品信息
|
|
|
productOldList := StockOutProductDao.Read_StockOutProduct_List(StockOut.T_number)
|
|
|
|
|
|
var oldProductList []dto.StockProduct
|
|
|
@@ -2363,6 +2367,7 @@ func (c *StockController) StockOut_Edit() {
|
|
|
T_num: v.T_num, // 入库数量
|
|
|
T_date: StockOut.T_date, // 入库日期
|
|
|
T_relation_sn: strings.Join(v.T_relation_sn, ","),
|
|
|
+ T_state: 1,
|
|
|
}
|
|
|
_, err = StockOutProductDao.Add_StockOutProduct(StockOutProduct)
|
|
|
if err != nil {
|
|
|
@@ -2392,6 +2397,7 @@ func (c *StockController) StockOut_Edit() {
|
|
|
T_depot_id: StockOut.T_depot_id,
|
|
|
T_num: productNewMap[v.T_product_id].T_num, // 入库数量
|
|
|
T_date: StockOut.T_date, // 入库日期
|
|
|
+ T_state: 1,
|
|
|
}
|
|
|
// 出库数量比之前多,减少库存
|
|
|
var T_type int
|
|
|
@@ -2503,6 +2509,7 @@ func (c *StockController) StockOut_Edit() {
|
|
|
T_num: productNewMap[diff.T_product_id].T_num, // 入库数量
|
|
|
T_date: StockOut.T_date, // 入库日期
|
|
|
T_relation_sn: strings.Join(productNewMap[diff.T_product_id].T_relation_sn, ","),
|
|
|
+ T_state: 1,
|
|
|
}
|
|
|
// 更新产品库存表
|
|
|
err = StockOutProductDao.Update_StockOutProduct(StockOutProduct)
|
|
|
@@ -3014,7 +3021,7 @@ func StockOut_Edit_StockMonth(T_date string, T_depot_id int, allProductList []in
|
|
|
// return nil
|
|
|
//}
|
|
|
//T_month := date.Format("2006-01")
|
|
|
- months := generateMonthList(date)
|
|
|
+ months := generateMonthList(date, "out")
|
|
|
o := orm.NewOrm()
|
|
|
StockOutDao := Stock.NewStockOut(o)
|
|
|
StockMonthDao := Stock.NewStockMonth(o)
|
|
|
@@ -3151,12 +3158,627 @@ func Cron_StockMonth_Add() {
|
|
|
|
|
|
}
|
|
|
|
|
|
-func generateMonthList(startMonth time.Time) []string {
|
|
|
+func generateMonthList(startMonth time.Time, t_type string) []string {
|
|
|
var months []string
|
|
|
- endMonth := time.Now().AddDate(0, 1, 0)
|
|
|
+ endMonth := time.Now()
|
|
|
+ if t_type == "in" {
|
|
|
+ endMonth = endMonth.AddDate(0, 1, 0)
|
|
|
+ }
|
|
|
for month := startMonth; month.Before(endMonth); month = month.AddDate(0, 1, 0) {
|
|
|
fmt.Println("=========================", month.Format("2006-01"))
|
|
|
months = append(months, month.Format("2006-01"))
|
|
|
}
|
|
|
return months
|
|
|
}
|
|
|
+
|
|
|
+// 出库申请
|
|
|
+func (c *StockController) StockOut_Apply() {
|
|
|
+
|
|
|
+ rand_x := 0
|
|
|
+ T_number := ""
|
|
|
+ o := orm.NewOrm()
|
|
|
+
|
|
|
+ StockOutDao := Stock.NewStockOut(o)
|
|
|
+ for true {
|
|
|
+ T_number = "CK-" + lib.GetRandstring(8, "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", int64(rand_x))
|
|
|
+ _, err := StockOutDao.Read_StockOut_ByT_number(T_number)
|
|
|
+ if err != nil && err.Error() == orm.ErrNoRows.Error() {
|
|
|
+ break
|
|
|
+ }
|
|
|
+ rand_x += 1
|
|
|
+ }
|
|
|
+
|
|
|
+ T_contract_number := c.GetString("T_contract_number")
|
|
|
+ T_depot_id, _ := c.GetInt("T_depot_id")
|
|
|
+ T_product := c.GetString("T_product")
|
|
|
+ T_remark := c.GetString("T_remark")
|
|
|
+ //T_date := c.GetString("T_date")
|
|
|
+ T_project := c.GetString("T_project")
|
|
|
+ T_company_name := c.GetString("T_company_name")
|
|
|
+ T_payment_method := c.GetString("T_payment_method")
|
|
|
+ if len(T_company_name) == 0 {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 202, Msg: "公司名称不能为空"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if len(T_payment_method) == 0 {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 202, Msg: "付款方式不能为空"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ var_ := Stock.StockOut{
|
|
|
+ T_number: T_number,
|
|
|
+ T_contract_number: T_contract_number,
|
|
|
+ T_depot_id: T_depot_id,
|
|
|
+ T_type: 1,
|
|
|
+ //T_date: T_date,
|
|
|
+ T_receive: c.User.T_uuid,
|
|
|
+ T_remark: T_remark,
|
|
|
+ T_project: T_project,
|
|
|
+ T_submit: c.User.T_uuid,
|
|
|
+ T_state: Stock.StockOutWaitAudit,
|
|
|
+ T_company_name: T_company_name,
|
|
|
+ T_payment_method: T_payment_method,
|
|
|
+ }
|
|
|
+
|
|
|
+ o.Begin()
|
|
|
+ StockOutProductDao := Stock.NewStockOutProduct(o)
|
|
|
+ StockDao := Stock.NewStock(o)
|
|
|
+
|
|
|
+ _, err := StockOutDao.Add_StockOut(var_)
|
|
|
+ if err != nil {
|
|
|
+ o.Rollback()
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 203, Msg: "出库失败"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 1、添加出库单
|
|
|
+
|
|
|
+ if len(T_product) == 0 {
|
|
|
+ o.Rollback()
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 202, Msg: "产品明细不能为空"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ productList := lib.SplitString(T_product, "|")
|
|
|
+ allProductList := []int{}
|
|
|
+ for _, v := range productList {
|
|
|
+ product_id, _ := strconv.Atoi(strings.Split(v, "-")[0])
|
|
|
+ allProductList = append(allProductList, product_id)
|
|
|
+ product, _ := Basic.Read_Product_ById(product_id)
|
|
|
+
|
|
|
+ num, _ := strconv.Atoi(strings.Split(v, "-")[1])
|
|
|
+ // 2、添加出库产品清单
|
|
|
+ stockOutProduct := Stock.StockOutProduct{
|
|
|
+ T_number: T_number,
|
|
|
+ T_product_id: product_id,
|
|
|
+ T_depot_id: T_depot_id,
|
|
|
+ T_num: num, // 出库数量
|
|
|
+ T_state: 2,
|
|
|
+ }
|
|
|
+ _, err = StockOutProductDao.Add_StockOutProduct(stockOutProduct)
|
|
|
+ if err != nil {
|
|
|
+ o.Rollback()
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 203, Msg: "申请出库失败"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 3、更新产品库存列表
|
|
|
+ _, err = StockDao.AddOrUpdate_Occupy_Stock(T_depot_id, product.Id, product.T_class, product.T_name, product.T_model, num, 2)
|
|
|
+ if err != nil {
|
|
|
+ o.Rollback()
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 203, Msg: "更新占用库存失败" + err.Error()}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ o.Commit()
|
|
|
+
|
|
|
+ NatsServer.AddUserLogs(c.User.T_uuid, "出库申请", "出库申请", var_)
|
|
|
+
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_number}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// 修改出库申请
|
|
|
+func (c *StockController) StockOut_Apply_Edit() {
|
|
|
+
|
|
|
+ T_number := c.GetString("T_number") // 出库单号
|
|
|
+ //T_depot_id, _ := c.GetInt("T_depot_id")
|
|
|
+ T_date := c.GetString("T_date")
|
|
|
+ T_receive := c.GetString("T_receive")
|
|
|
+ T_project := c.GetString("T_project")
|
|
|
+ T_product := c.GetString("T_product")
|
|
|
+ T_remark := c.GetString("T_remark")
|
|
|
+ _, is := lib.DateStrToTime(T_date)
|
|
|
+ if !is {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 202, Msg: "日期格式错误!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ NatsServer.AddUserLogs(c.User.T_uuid, "仓库管理", "修改出库", T_product)
|
|
|
+ o := orm.NewOrm()
|
|
|
+ o.Begin()
|
|
|
+ StockOutDao := Stock.NewStockOut(o)
|
|
|
+ StockOutProductDao := Stock.NewStockOutProduct(o)
|
|
|
+ StockDao := Stock.NewStock(o)
|
|
|
+
|
|
|
+ // 查询入库信息
|
|
|
+ StockOut, err := StockOutDao.Read_StockOut_ByT_number(T_number)
|
|
|
+ if err != nil {
|
|
|
+ o.Rollback()
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ T_old_date := StockOut.T_date
|
|
|
+ // 查询入库产品信息
|
|
|
+ productOldList := StockOutProductDao.Read_StockOutProduct_List(StockOut.T_number)
|
|
|
+
|
|
|
+ var oldProductList []dto.StockProduct
|
|
|
+ var newProductList []dto.StockProduct
|
|
|
+ productOldMap := map[int]dto.StockProduct{}
|
|
|
+
|
|
|
+ allProductListMap := make(map[int]struct{})
|
|
|
+ for _, product := range productOldList {
|
|
|
+ stockProduct := dto.StockProduct{
|
|
|
+ T_product_id: product.T_product_id,
|
|
|
+ T_num: product.T_num,
|
|
|
+ T_relation_sn: lib.SplitString(product.T_relation_sn, ","),
|
|
|
+ }
|
|
|
+ oldProductList = append(oldProductList, stockProduct)
|
|
|
+ productOldMap[product.T_product_id] = stockProduct
|
|
|
+ if _, ok := allProductListMap[product.T_product_id]; !ok {
|
|
|
+ allProductListMap[product.T_product_id] = struct{}{}
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ productNewList := lib.SplitString(T_product, "|")
|
|
|
+ productNewMap := map[int]dto.StockProduct{}
|
|
|
+ for _, v := range productNewList {
|
|
|
+ product_id, _ := strconv.Atoi(strings.Split(v, "-")[0])
|
|
|
+ num, _ := strconv.Atoi(strings.Split(v, "-")[1])
|
|
|
+ T_relation_sn := strings.Split(v, "-")[2]
|
|
|
+ stockProduct := dto.StockProduct{
|
|
|
+ T_product_id: product_id,
|
|
|
+ T_num: num,
|
|
|
+ T_relation_sn: lib.SplitString(T_relation_sn, ","),
|
|
|
+ }
|
|
|
+ newProductList = append(newProductList, stockProduct)
|
|
|
+ productNewMap[product_id] = stockProduct
|
|
|
+ if _, ok := allProductListMap[product_id]; !ok {
|
|
|
+ allProductListMap[product_id] = struct{}{}
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 判断产品列表信息是否相同
|
|
|
+ StockProductListIsEqual, needDelete, needAdd, needEdit, _ := dto.StockProductListsEqual(oldProductList, newProductList)
|
|
|
+ // 两次提交的数据相同,则不用修改
|
|
|
+ if !StockProductListIsEqual {
|
|
|
+ if len(needDelete) > 0 {
|
|
|
+ // 删除入库产品列表
|
|
|
+ for _, v := range needDelete {
|
|
|
+ product, _ := Basic.Read_Product_ById(v.T_product_id)
|
|
|
+ // 删除入库产品列表
|
|
|
+ err = StockOutProductDao.Delete_StockOutProduct(StockOut.T_number, StockOut.T_depot_id, v.T_product_id)
|
|
|
+ if err != nil {
|
|
|
+ o.Rollback()
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除产品入库信息失败!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ 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: "更新库存信息失败"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if len(needAdd) > 0 {
|
|
|
+ // 新增入库产品列表
|
|
|
+ for _, v := range needAdd {
|
|
|
+ product, _ := Basic.Read_Product_ById(v.T_product_id)
|
|
|
+
|
|
|
+ StockOutProduct := Stock.StockOutProduct{
|
|
|
+ T_number: T_number,
|
|
|
+ T_product_id: v.T_product_id,
|
|
|
+ T_depot_id: StockOut.T_depot_id,
|
|
|
+ T_num: v.T_num, // 出库数量
|
|
|
+ T_state: 1,
|
|
|
+ }
|
|
|
+ _, err = StockOutProductDao.Add_StockOutProduct(StockOutProduct)
|
|
|
+ if err != nil {
|
|
|
+ o.Rollback()
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 203, Msg: "入库失败"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 减少库存
|
|
|
+ _, err = StockDao.AddOrUpdate_Occupy_Stock(StockOut.T_depot_id, product.Id, product.T_class, product.T_name, product.T_model, v.T_num, 2)
|
|
|
+ if err != nil {
|
|
|
+ o.Rollback()
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 203, Msg: "增加库存失败"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if len(needEdit) > 0 {
|
|
|
+ for _, v := range needEdit {
|
|
|
+ product, _ := Basic.Read_Product_ById(v.T_product_id)
|
|
|
+ StockOutProduct := Stock.StockOutProduct{
|
|
|
+ T_number: StockOut.T_number,
|
|
|
+ T_product_id: v.T_product_id,
|
|
|
+ T_depot_id: StockOut.T_depot_id,
|
|
|
+ T_num: productNewMap[v.T_product_id].T_num, // 入库数量
|
|
|
+ T_state: 1,
|
|
|
+ }
|
|
|
+ // 出库数量比之前多,减少库存
|
|
|
+ var T_type int
|
|
|
+ var T_num int
|
|
|
+
|
|
|
+ if productNewMap[v.T_product_id].T_num > productOldMap[v.T_product_id].T_num {
|
|
|
+ // 减少库存
|
|
|
+ T_type = 2
|
|
|
+ T_num = productNewMap[v.T_product_id].T_num - productOldMap[v.T_product_id].T_num
|
|
|
+ } else {
|
|
|
+ // 增加库存
|
|
|
+ T_type = 1
|
|
|
+ T_num = productOldMap[v.T_product_id].T_num - productNewMap[v.T_product_id].T_num
|
|
|
+ }
|
|
|
+
|
|
|
+ _, err = StockDao.AddOrUpdate_Occupy_Stock(StockOut.T_depot_id, product.Id, product.T_class, product.T_name, product.T_model, T_num, T_type)
|
|
|
+ if err != nil {
|
|
|
+ o.Rollback()
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 203, Msg: err.Error()}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 更新产品表
|
|
|
+ err = StockOutProductDao.Update_StockOutProduct(StockOutProduct)
|
|
|
+ if err != nil {
|
|
|
+ o.Rollback()
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 203, Msg: "修改出库产品信息失败"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ if len(T_remark) > 0 {
|
|
|
+ StockOut.T_remark = T_remark
|
|
|
+ }
|
|
|
+ if len(T_receive) > 0 {
|
|
|
+ StockOut.T_receive = T_receive
|
|
|
+ }
|
|
|
+ if len(T_project) > 0 {
|
|
|
+ StockOut.T_project = T_project
|
|
|
+ }
|
|
|
+
|
|
|
+ if len(T_date) > 0 {
|
|
|
+ StockOut.T_date = T_date
|
|
|
+ }
|
|
|
+
|
|
|
+ err = StockOutDao.Update_StockOut(StockOut, "T_remark", "T_receive", "T_project", "T_date")
|
|
|
+ if err != nil {
|
|
|
+ o.Rollback()
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 203, Msg: "修改入库失败"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ o.Commit()
|
|
|
+ if len(T_date) > 0 && T_old_date != T_date {
|
|
|
+ // 修改出库产品日期
|
|
|
+ StockOutProductDao.Update_StockOutProduct_T_date(StockOut.T_number, T_date)
|
|
|
+ }
|
|
|
+
|
|
|
+ NatsServer.AddUserLogs(c.User.T_uuid, "出库申请", "修改", StockOut)
|
|
|
+
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_number}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// 财务
|
|
|
+func (c *StockController) StockOut_Finance_List() {
|
|
|
+ // 分页参数 初始化
|
|
|
+ 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_depot_id, _ := c.GetInt("T_depot_id")
|
|
|
+ T_contract_number := c.GetString("T_contract_number")
|
|
|
+ T_start_date := c.GetString("T_start_date")
|
|
|
+ T_end_date := c.GetString("T_end_date")
|
|
|
+ T_name := c.GetString("T_name")
|
|
|
+
|
|
|
+ userList, _ := NatsServer.Read_User_List_All()
|
|
|
+ Account.Read_User_All_Map(userList)
|
|
|
+ Basic.Read_Depot_All_Map()
|
|
|
+
|
|
|
+ StockOutDao := Stock.NewStockOut(orm.NewOrm())
|
|
|
+ R_List, R_cnt := StockOutDao.Read_StockOut_Audit_List(T_name, Stock.StockOutTypeFinance, T_depot_id, T_contract_number, T_start_date, T_end_date, 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 (c *StockController) StockOut_Manager_List() {
|
|
|
+ // 分页参数 初始化
|
|
|
+ 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_depot_id, _ := c.GetInt("T_depot_id")
|
|
|
+ T_contract_number := c.GetString("T_contract_number")
|
|
|
+ T_start_date := c.GetString("T_start_date")
|
|
|
+ T_end_date := c.GetString("T_end_date")
|
|
|
+ T_name := c.GetString("T_name")
|
|
|
+
|
|
|
+ userList, _ := NatsServer.Read_User_List_All()
|
|
|
+ Account.Read_User_All_Map(userList)
|
|
|
+ Basic.Read_Depot_All_Map()
|
|
|
+
|
|
|
+ StockOutDao := Stock.NewStockOut(orm.NewOrm())
|
|
|
+ R_List, R_cnt := StockOutDao.Read_StockOut_Audit_List(T_name, Stock.StockOutTypeManager, T_depot_id, T_contract_number, T_start_date, T_end_date, 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 (c *StockController) StockOut_Warehouse_List() {
|
|
|
+ // 分页参数 初始化
|
|
|
+ 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_depot_id, _ := c.GetInt("T_depot_id")
|
|
|
+ T_contract_number := c.GetString("T_contract_number")
|
|
|
+ T_start_date := c.GetString("T_start_date")
|
|
|
+ T_end_date := c.GetString("T_end_date")
|
|
|
+ T_name := c.GetString("T_name")
|
|
|
+
|
|
|
+ userList, _ := NatsServer.Read_User_List_All()
|
|
|
+ Account.Read_User_All_Map(userList)
|
|
|
+ Basic.Read_Depot_All_Map()
|
|
|
+
|
|
|
+ StockOutDao := Stock.NewStockOut(orm.NewOrm())
|
|
|
+ R_List, R_cnt := StockOutDao.Read_StockOut_Audit_List(T_name, Stock.StockOutTypeWarehouse, T_depot_id, T_contract_number, T_start_date, T_end_date, 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 (c *StockController) StockOut_Audit() {
|
|
|
+
|
|
|
+ T_number := c.GetString("T_number") // 出库单号
|
|
|
+ //T_depot_id, _ := c.GetInt("T_depot_id")
|
|
|
+ T_audit, _ := c.GetInt("T_audit") // 审核 2财务通过 3财务不通过 4总经理通过 5总经理不通过 6已出库
|
|
|
+ T_approval_opinion := c.GetString("T_approval_opinion") // 审批意见
|
|
|
+ T_type := c.GetString("T_type") // 类型 Finance Manager
|
|
|
+
|
|
|
+ o := orm.NewOrm()
|
|
|
+ o.Begin()
|
|
|
+ StockOutDao := Stock.NewStockOut(o)
|
|
|
+ StockDao := Stock.NewStock(o)
|
|
|
+ StockOutProductDao := Stock.NewStockOutProduct(o)
|
|
|
+ StockOut, err := StockOutDao.Read_StockOut_ByT_number(T_number)
|
|
|
+ if err != nil {
|
|
|
+ o.Rollback()
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ StockOut.T_state = T_audit
|
|
|
+ if T_type == Stock.StockOutTypeFinance {
|
|
|
+ StockOut.T_finance_approval_opinion = T_approval_opinion
|
|
|
+ } else {
|
|
|
+ StockOut.T_manager_approval_opinion = T_approval_opinion
|
|
|
+ }
|
|
|
+
|
|
|
+ if T_audit == Stock.StockOutAuditFinanceUnPass || T_audit == Stock.StockOutAuditManagerUnPass {
|
|
|
+ productList := StockOutProductDao.Read_StockOutProduct_List(StockOut.T_number)
|
|
|
+ for _, v := range productList {
|
|
|
+ product, _ := Basic.Read_Product_ById(v.T_product_id)
|
|
|
+ _, 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
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ err = StockOutDao.Update_StockOut(StockOut, "T_state", "T_finance_approval_opinion", "T_manager_approval_opinion")
|
|
|
+ if err != nil {
|
|
|
+ o.Rollback()
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 203, Msg: "出库审批失败"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ o.Commit()
|
|
|
+ NatsServer.AddUserLogs(c.User.T_uuid, "出库申请", "审批", StockOut)
|
|
|
+
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_number}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// 仓管出库
|
|
|
+func (c *StockController) StockOut_Warehouse() {
|
|
|
+
|
|
|
+ T_number := c.GetString("T_number") // 出库单号
|
|
|
+ T_date := c.GetString("T_date")
|
|
|
+ date, is := lib.DateStrToTime(T_date)
|
|
|
+ if !is {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 202, Msg: "日期格式错误!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ NatsServer.AddUserLogs(c.User.T_uuid, "仓库管理", "确认出库", T_number)
|
|
|
+
|
|
|
+ o := orm.NewOrm()
|
|
|
+ o.Begin()
|
|
|
+ StockOutDao := Stock.NewStockOut(o)
|
|
|
+ StockOutProductDao := Stock.NewStockOutProduct(o)
|
|
|
+ DeviceDao := Stock.NewDevice(o)
|
|
|
+ StockDao := Stock.NewStock(o)
|
|
|
+
|
|
|
+ // 查询入库信息
|
|
|
+ StockOut, err := StockOutDao.Read_StockOut_ByT_number(T_number)
|
|
|
+ if err != nil {
|
|
|
+ o.Rollback()
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ T_product := c.GetString("T_product")
|
|
|
+ productList := lib.SplitString(T_product, "|")
|
|
|
+ allProductList := []int{}
|
|
|
+ for _, v := range productList {
|
|
|
+ product_id, _ := strconv.Atoi(strings.Split(v, "-")[0])
|
|
|
+ allProductList = append(allProductList, product_id)
|
|
|
+ product, _ := Basic.Read_Product_ById(product_id)
|
|
|
+
|
|
|
+ num, _ := strconv.Atoi(strings.Split(v, "-")[1])
|
|
|
+ T_relation_sn := strings.Split(v, "-")[2]
|
|
|
+ if T_relation_sn == "" && product.T_relation_sn == 1 {
|
|
|
+ o.Rollback()
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 202, Msg: fmt.Sprintf("%s关联SN,请先添加SN!", product.T_name)}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 2、更新设备状态为已出库
|
|
|
+ if len(T_relation_sn) > 0 {
|
|
|
+ snList := strings.Split(T_relation_sn, ",")
|
|
|
+ for _, sn := range snList {
|
|
|
+ mqtt := Stock.Read_MqttUser(sn)
|
|
|
+ device := Stock.Device{
|
|
|
+ T_contract_number: StockOut.T_contract_number,
|
|
|
+ T_product_id: product_id,
|
|
|
+ T_out_number: T_number,
|
|
|
+ T_sn: sn,
|
|
|
+ T_iccid: mqtt.Iccid,
|
|
|
+ T_imei: mqtt.Imei,
|
|
|
+ T_State: 1,
|
|
|
+ T_project: StockOut.T_project,
|
|
|
+ CreateTime: date,
|
|
|
+ }
|
|
|
+ _, err = DeviceDao.AddOrUpdate_Device(device, 1)
|
|
|
+ if err != nil {
|
|
|
+ o.Rollback()
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 202, Msg: "出库失败"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3、添加出库产品清单
|
|
|
+ stockOutProduct := Stock.StockOutProduct{
|
|
|
+ T_number: T_number,
|
|
|
+ T_product_id: product_id,
|
|
|
+ T_depot_id: StockOut.T_depot_id,
|
|
|
+ T_num: num, // 出库数量
|
|
|
+ T_date: T_date, // 出库数量
|
|
|
+ T_relation_sn: T_relation_sn,
|
|
|
+ T_state: 2,
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新产品表
|
|
|
+ err = StockOutProductDao.Update_StockOutProduct(stockOutProduct)
|
|
|
+ if err != nil {
|
|
|
+ o.Rollback()
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 203, Msg: "修改出库产品信息失败"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 5、更新产品库存列表
|
|
|
+ _, err = StockDao.Stock_Warehouse(StockOut.T_depot_id, product.Id, product.T_class, product.T_name, product.T_model, num)
|
|
|
+ if err != nil {
|
|
|
+ o.Rollback()
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 203, Msg: err.Error()}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ StockOut.T_state = Stock.StockOutAlreadyOut
|
|
|
+ err = StockOutDao.Update_StockOut(StockOut, "T_state")
|
|
|
+ if err != nil {
|
|
|
+ o.Rollback()
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 203, Msg: "出库审批失败"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ o.Commit()
|
|
|
+ StockOut_Edit_StockMonth(StockOut.T_date, StockOut.T_depot_id, allProductList)
|
|
|
+
|
|
|
+ NatsServer.AddUserLogs(c.User.T_uuid, "出库申请", "修改", StockOut)
|
|
|
+
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_number}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+}
|