Browse Source

耗材参数

XMLWAN 3 years ago
parent
commit
fd561937a1
4 changed files with 79 additions and 14 deletions
  1. 9 2
      controllers/stock_in_api_controller.go
  2. 2 2
      main.go
  3. 62 10
      service/auto_create_stock.go
  4. 6 0
      service/stock_service.go

+ 9 - 2
controllers/stock_in_api_controller.go View File

@@ -1173,6 +1173,7 @@ func (c *StockManagerApiController) CreateWarehouseOut() {
1173 1173
 
1174 1174
 				expiry_date := items["expiry_date"].(string)
1175 1175
 
1176
+				warehouse_info_id := int64(items["warehouse_info_id"].(float64))
1176 1177
 				timeLayout := "2006-01-02"
1177 1178
 				loc, _ := time.LoadLocation("Local")
1178 1179
 				var expiryDate int64
@@ -1216,6 +1217,7 @@ func (c *StockManagerApiController) CreateWarehouseOut() {
1216 1217
 					ProductDate:             productDate,
1217 1218
 					Dealer:                  dealer,
1218 1219
 					LicenseNumber:           license_number,
1220
+					WarehouseInfotId:        warehouse_info_id,
1219 1221
 				}
1220 1222
 				warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
1221 1223
 
@@ -1240,9 +1242,13 @@ func (c *StockManagerApiController) CreateWarehouseOut() {
1240 1242
 	//出库逻辑
1241 1243
 	for _, item := range warehousingOutInfo {
1242 1244
 		//查询库存
1243
-		warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId)
1245
+		//warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId)
1246
+		//查询该批次的库存
1244 1247
 
1245
-		if item.Count > warehouse.Count {
1248
+		warehouseOne, _ := service.FindWarehousingInfoByIdSeven(item.WarehouseInfotId)
1249
+		fmt.Println("数据232323232323232323323232", warehouseOne)
1250
+		fmt.Println("库存查询23322332233232233232322323232323", warehouseOne.StockCount)
1251
+		if item.Count > warehouseOne.StockCount {
1246 1252
 			goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
1247 1253
 			c.ServeSuccessJSON(map[string]interface{}{
1248 1254
 				"msg":                "1",
@@ -1250,6 +1256,7 @@ func (c *StockManagerApiController) CreateWarehouseOut() {
1250 1256
 				"specification_name": goodObj.SpecificationName,
1251 1257
 			})
1252 1258
 			return
1259
+
1253 1260
 		} else {
1254 1261
 
1255 1262
 			_, errcodes := service.FindStockOutByIsSys(adminUserInfo.CurrentOrgId, 0, operation_time)

+ 2 - 2
main.go View File

@@ -16,8 +16,8 @@ func main() {
16 16
 	//service.BeginAutoCreatePlanJob()
17 17
 	//service.AutoClearSchedules()
18 18
 	//service.BeginAutoCreateStaffScheduleJob()
19
-	// service.BeginAutoCreateDrugJob()
20
-	// service.BeginAutoCreateStockJob()
19
+	//service.BeginAutoCreateDrugJob()
20
+	service.BeginAutoCreateStockJob()
21 21
 	beego.BConfig.WebConfig.Session.SessionGCMaxLifetime = 60
22 22
 	beego.Run()
23 23
 }

+ 62 - 10
service/auto_create_stock.go View File

@@ -44,17 +44,36 @@ func AutoCreateStockJob() {
44 44
 
45 45
 		information, _ := FindAlLGoodInformation(item.UserOrgId)
46 46
 		for _, ite := range information {
47
-			countList, _ := FindAllGoodInformationTotalCount(ite.ID)
48
-			for _, it := range countList {
49
-				if ite.ID == it.GoodId {
50
-					formatInt := strconv.FormatInt(it.StockCount, 10)
51
-					total, _ := strconv.ParseFloat(formatInt, 64)
52
-					info := models.GoodInfo{
53
-						Total: total,
54
-					}
55
-					UpdateStockTotal(it.GoodId, info)
56
-				}
47
+			//countList, _ := FindAllGoodInformationTotalCount(ite.ID)
48
+			//查询入库数量
49
+			warehouseInfo, _ := FindAllGoodWarehouseInfoCount(ite.ID)
50
+
51
+			//查询自动出库数量
52
+			autoWarehouseOut, _ := FindAutoGoodWarehouseInfoCount(ite.ID)
53
+
54
+			//查询手动出库
55
+			warehouseOut, _ := FindGoodWarehouseOutCount(ite.ID)
56
+
57
+			var total int64
58
+
59
+			total = warehouseInfo.WarehousingCount - autoWarehouseOut.Count - warehouseOut.Count
60
+			formatInt := strconv.FormatInt(total, 10)
61
+			totalfloat, _ := strconv.ParseFloat(formatInt, 64)
62
+			info := models.GoodInfo{
63
+				Total: totalfloat,
57 64
 			}
65
+			UpdateStockTotal(ite.ID, info)
66
+
67
+			//for _, it := range countList {
68
+			//	if ite.ID == it.GoodId {
69
+			//		formatInt := strconv.FormatInt(it.StockCount, 10)
70
+			//		total, _ := strconv.ParseFloat(formatInt, 64)
71
+			//		info := models.GoodInfo{
72
+			//			Total: total,
73
+			//		}
74
+			//		UpdateStockTotal(it.GoodId, info)
75
+			//	}
76
+			//}
58 77
 		}
59 78
 
60 79
 	}
@@ -85,3 +104,36 @@ func UpdateStockTotal(id int64, lib models.GoodInfo) error {
85 104
 	err := XTWriteDB().Model(&lib).Where("id=? and status = 1", id).Updates(map[string]interface{}{"total": lib.Total}).Error
86 105
 	return err
87 106
 }
107
+
108
+func FindAllGoodWarehouseInfoCount(good_id int64) (models.WarehousingInfo, error) {
109
+
110
+	info := models.WarehousingInfo{}
111
+	db := XTReadDB().Table("xt_warehouse_info as x").Where("x.status = 1")
112
+	if good_id > 0 {
113
+		db = db.Where("x.good_id = ? and x.warehousing_count <> 0", good_id)
114
+	}
115
+	err = db.Select("x.good_id,sum(x.warehousing_count) as warehousing_count").Find(&info).Error
116
+	return info, err
117
+}
118
+
119
+func FindAutoGoodWarehouseInfoCount(good_id int64) (models.AutomaticReduceDetail, error) {
120
+
121
+	detail := models.AutomaticReduceDetail{}
122
+	db := XTReadDB().Table("xt_automatic_reduce_detail as x").Where("x.status = 1")
123
+	if good_id > 0 {
124
+		db = db.Where("x.good_id = ? and x.count<> 0", good_id)
125
+	}
126
+	err := db.Select("x.good_id,sum(x.count) as count").Find(&detail).Error
127
+	return detail, err
128
+}
129
+
130
+func FindGoodWarehouseOutCount(good_id int64) (models.WarehouseOutInfo, error) {
131
+
132
+	out := models.WarehouseOutInfo{}
133
+	db := XTReadDB().Table("xt_warehouse_out_info as x").Where("x.status = 1")
134
+	if good_id > 0 {
135
+		db = db.Where("x.good_id = ? and x.is_sys = 0 and x.count<> 0", good_id)
136
+	}
137
+	err := db.Select("x.good_id,sum(x.count) as count").Find(&out).Error
138
+	return out, err
139
+}

+ 6 - 0
service/stock_service.go View File

@@ -623,6 +623,12 @@ func FindFirstWarehousingInfoByStockTwo(good_id int64, good_type_id int64) (info
623 623
 	return info, err
624 624
 }
625 625
 
626
+func FindWarehousingInfoByIdSeven(id int64) (models.WarehousingInfo, error) {
627
+	info := models.WarehousingInfo{}
628
+	err := XTReadDB().Model(&info).Where("id= ? and status = 1", id).Find(&info).Error
629
+	return info, err
630
+}
631
+
626 632
 //药品先进先出,找出最先入库的批次
627 633
 
628 634
 func FindLastDrugWarehousingInfoByID(drug_id int64) (info models.XtDrugWarehouseInfo, err error) {