Browse Source

11月8日库存管理

XMLWAN 3 years ago
parent
commit
8daa5fa67a

+ 2 - 2
conf/app.conf View File

@@ -1,6 +1,6 @@
1 1
 appname = 血透
2
-httpport = 9531
3
-runmode = prod
2
+httpport = 9529
3
+runmode = dev
4 4
 
5 5
 #
6 6
 copyrequestbody = true

+ 32 - 14
controllers/drug_stock_api_contorller.go View File

@@ -587,8 +587,8 @@ func (c *StockDrugApiController) EditDrugWarehouse() {
587 587
 						StockMaxNumber:   warehousing_count,
588 588
 					}
589 589
 					if max_unit == min_unit {
590
-						warehouseInfo.StockMaxNumber = 0
591
-						warehouseInfo.StockMinNumber = warehousing_count
590
+						warehouseInfo.StockMaxNumber = warehousing_count
591
+						warehouseInfo.StockMinNumber = 0
592 592
 						warehouseInfo.MaxUnit = min_unit
593 593
 					}
594 594
 					warehousingInfo = append(warehousingInfo, warehouseInfo)
@@ -620,8 +620,8 @@ func (c *StockDrugApiController) EditDrugWarehouse() {
620 620
 						BatchNumber:      batch_number,
621 621
 					}
622 622
 					if max_unit == min_unit {
623
-						warehouseInfo.StockMaxNumber = 0
624
-						warehouseInfo.StockMinNumber = warehousing_count
623
+						warehouseInfo.StockMaxNumber = warehousing_count
624
+						warehouseInfo.StockMinNumber = 0
625 625
 						warehouseInfo.MaxUnit = min_unit
626 626
 					}
627 627
 
@@ -1470,11 +1470,7 @@ func (c *StockDrugApiController) CreateDrugWarehouseOut() {
1470 1470
 			return
1471 1471
 		} else {
1472 1472
 			service.AddSigleDrugWarehouseOut(&warehouseOut)
1473
-			//list, _ := service.GetLastWarehouseOut(adminUserInfo.CurrentOrgId)
1474
-			//for _, item := range drugFlow {
1475
-			//	item.WarehouseOutId = list.ID
1476
-			//}
1477
-			//service.CreateDrugFlow(drugFlow)
1473
+
1478 1474
 			// 出库流程
1479 1475
 			// 1.查询改药品在药品库的规格信息,并将处方里的规格进行换算(尽量将拆零单位转换成包装单位)
1480 1476
 			drup, _ := service.FindBaseDrugLibRecord(item.OrgId, item.DrugId)
@@ -1592,14 +1588,24 @@ func (c *StockDrugApiController) DeleteDrugWarehouseOut() {
1592 1588
 }
1593 1589
 func (this *StockDrugApiController) DeleteDrugWarehouseOutInfo() {
1594 1590
 	id, _ := this.GetInt64("id", 0)
1595
-	fmt.Println(id)
1596 1591
 	if id == 0 {
1597 1592
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1598 1593
 		return
1599 1594
 	}
1595
+	//查询详情
1596
+	info, _ := service.GetDrugWarehosueOutInfo(id)
1597
+	drug, _ := service.GetBaseDrugMedical(info.DrugId)
1600 1598
 
1599
+	if info.CountUnit == drug.MaxUnit {
1600
+		//回退库存
1601
+		service.ModeifyDrugWarehosueInfo(info.WarehouseInfoId, info.Count)
1602
+	}
1603
+	if info.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
1604
+		service.ModeFyStockMinById(info.WarehouseInfoId, info.Count)
1605
+	}
1606
+	//删除流水
1607
+	service.DeleteDrugWarehouseOutInfoById(info.ID)
1601 1608
 	err := service.UpDateDrugWarehouseOutStatus(id)
1602
-	service.DeleteDrugWarehouseOutInfoById(id)
1603 1609
 	if err != nil {
1604 1610
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
1605 1611
 	} else {
@@ -2695,7 +2701,7 @@ func (this *StockDrugApiController) DeleteDrugCancelStock() {
2695 2701
 			//回退库存
2696 2702
 			service.ModifyDrugWarehouseByInfoId(item.CancelStockId, item.Count)
2697 2703
 		}
2698
-		if item.MaxUnit == medical.MinUnit {
2704
+		if item.MaxUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
2699 2705
 			service.ModifyDrugWarehouseByStockMin(item.CancelStockId, item.Count)
2700 2706
 		}
2701 2707
 	}
@@ -2716,9 +2722,21 @@ func (this *StockDrugApiController) DeleteDrugCancelStockInfo() {
2716 2722
 		return
2717 2723
 	}
2718 2724
 
2719
-	err := service.UpDateDrugCancleStockStatus(id)
2725
+	//查询
2726
+	cancelinfo, _ := service.GetDrugCancelById(id)
2720 2727
 
2721
-	service.UpDateDrugCancelStockById(id)
2728
+	drug, _ := service.GetBaseDrugMedical(cancelinfo.DrugId)
2729
+	if drug.MaxUnit == cancelinfo.MaxUnit {
2730
+		service.ModeFyDrugWareseInfo(cancelinfo.BatchNumberId, cancelinfo.Count)
2731
+	}
2732
+	if drug.MinUnit == cancelinfo.MaxUnit && drug.MaxUnit != drug.MinUnit {
2733
+		service.ModeFyDrugWarehouseMin(cancelinfo.BatchNumberId, cancelinfo.Count)
2734
+	}
2735
+	//扣减库存
2736
+
2737
+	err := service.UpDateDrugCancleStockStatus(id)
2738
+	//删除流水
2739
+	service.UpDateDrugCancelStockById(cancelinfo.ID)
2722 2740
 	if err != nil {
2723 2741
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteFail)
2724 2742
 	} else {

+ 1 - 12
controllers/schedule_api_controller.go View File

@@ -1417,27 +1417,16 @@ func (this *ScheduleApiController) ExportSchedule() {
1417 1417
 			schedule_date := time.Now().Format("2006-01-02")
1418 1418
 			date, _ := utils.ParseTimeStringToTime("2006-01-02", schedule_date)
1419 1419
 			clear_schedule_date := date.Unix() //根据日期去清除,该日期未来的排班数据
1420
-			//	err := service.UpdateScheduleStatus(clear_schedule_date, this.GetAdminUserInfo().CurrentOrgId)
1421 1420
 			if err == nil {
1422
-				//清除该机构的排班
1423
-				//if delete_type == 1 {
1424
-				//  service.ModeScheduleByTimeOne(theTimeStart.Unix(), theTimeEnd.Unix(), this.GetAdminUserInfo().CurrentOrgId)
1425
-				//}
1426
-				//if delete_type == 0 {
1427
-				//  service.ModeScheduleByTime(theTimeStart.Unix(), theTimeEnd.Unix(), this.GetAdminUserInfo().CurrentOrgId)
1428
-				//}
1429 1421
 
1430 1422
 				for _, item := range schedules {
1431
-					// fmt.Println("clear_schedule_date3232232332232332232323",clear_schedule_date)
1432 1423
 					if item.ScheduleDate > clear_schedule_date {
1433
-						//删除当天的以后日期排班
1434
-						// service.DeleteScheduleExist(item.ScheduleDate, item.UserOrgId)
1435 1424
 						//查找当天日期是否存在
1436 1425
 						_, errcode := service.GetTodayScheduleIsExistOne(item.PatientId, item.ScheduleDate, item.UserOrgId)
1437 1426
 						if errcode == gorm.ErrRecordNotFound {
1438 1427
 
1439 1428
 							//清除当天该床位已有的患者
1440
-							service.ModeFyScheduleById(item.ScheduleDate, item.BedId, item.ScheduleType)
1429
+							service.ModeFyScheduleById(item.ScheduleDate, item.BedId, item.ScheduleType, item.UserOrgId)
1441 1430
 							service.CreateSchedule(item)
1442 1431
 						} else if errcode == nil {
1443 1432
 							schedule := models.XtSchedule{

+ 10 - 5
service/gobal_config_service.go View File

@@ -260,7 +260,9 @@ func GetDrugInOrderDetail(startime int64, endtime int64, orgid int64, orderType
260 260
 	db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status = 1")
261 261
 	dbOne := XTReadDB().Table("xt_base_drug as t").Where("t.status =1")
262 262
 	dbTwo := XTReadDB().Table("xt_drug_warehouse as s").Where("s.status = 1")
263
-	fmt.Print(dbOne, dbTwo)
263
+	dbThree := UserReadDB().Table("sgj_user_admin_role as r").Where("r.status = 1")
264
+
265
+	fmt.Print(dbOne, dbTwo, dbThree)
264 266
 	if startime > 0 {
265 267
 		db = db.Where("x.ctime >=?", startime)
266 268
 	}
@@ -275,8 +277,8 @@ func GetDrugInOrderDetail(startime int64, endtime int64, orgid int64, orderType
275 277
 	}
276 278
 
277 279
 	if len(keyword) > 0 {
278
-
279
-		db = db.Where("x.warehousing_order like ? or t.drug_name like ? or s.creater like ?", likeKey, likeKey, likeKey)
280
+		db = db.Joins("left join sgj_xt.xt_drug_warehouse as o on o.id = x.warehousing_id  left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = o.creater").Group("s.id")
281
+		db = db.Where("x.warehousing_order like ? or t.drug_name like ? or r.user_name like ? ", likeKey, likeKey, likeKey)
280 282
 
281 283
 	}
282 284
 
@@ -347,7 +349,8 @@ func GetDrugOutOrder(startime int64, endtime int64, orgid int64, orderType int64
347 349
 	}
348 350
 
349 351
 	if len(keyword) > 0 {
350
-		db = db.Where("x.warehouse_out_order_number like ? or b.drug_name like ? or t.creater like ?", likeKey, likeKey, likeKey)
352
+		db = db.Joins("left join sgj_xt.xt_drug_warehouse_out as o on o.id = x.warehouse_out_id  left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = o.creater").Group("x.id")
353
+		db = db.Where("x.warehouse_out_order_number like ? or b.drug_name like ?  or r.user_name like ?", likeKey, likeKey, likeKey)
351 354
 	}
352 355
 
353 356
 	if manufacturerId > 0 {
@@ -411,7 +414,9 @@ func GetDrugCancelOrder(startime int64, endtime int64, orgid int64, orderType in
411 414
 		db = db.Where("x.type = ? ", orderType)
412 415
 	}
413 416
 	if len(keyword) > 0 {
414
-		db = db.Where("x.order_number like ? or s.drug_spec like ? or t.creater like ?", likeKey, likeKey, likeKey)
417
+		db = db.Joins("left join sgj_xt.xt_drug_cancel_stock as o on o.id = x.cancel_stock_id  left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = o.creater").Group("o.id")
418
+
419
+		db = db.Where("x.order_number like ? or s.drug_spec like ? or r.user_name like ? or s.drug_name like ?", likeKey, likeKey, likeKey, likeKey)
415 420
 	}
416 421
 
417 422
 	if manufacturerId > 0 {

+ 2 - 2
service/schedule_service.go View File

@@ -199,10 +199,10 @@ func GetTodayScheduleIsExistOne(patientid int64, schedudate int64, orgid int64)
199 199
 	return &scheudle, nil
200 200
 }
201 201
 
202
-func ModeFyScheduleById(schedule_date int64, bedid int64, scheduletype int64) error {
202
+func ModeFyScheduleById(schedule_date int64, bedid int64, scheduletype int64, orgid int64) error {
203 203
 
204 204
 	schedule := models.XtSchedule{}
205
-	err := XTWriteDB().Model(&schedule).Where("schedule_date = ? and bed_id =? and schedule_type = ? and status = 1", schedule_date, bedid, scheduletype).Updates(map[string]interface{}{"status": 0}).Error
205
+	err := XTWriteDB().Model(&schedule).Where("schedule_date = ? and bed_id =? and schedule_type = ? and status = 1 and user_org_id = ?", schedule_date, bedid, scheduletype, orgid).Updates(map[string]interface{}{"status": 0}).Error
206 206
 	return err
207 207
 }
208 208
 

+ 37 - 6
service/stock_service.go View File

@@ -2323,20 +2323,20 @@ func UpDateWarehouseInfoByStock(info *models.WarehousingInfo) (err error) {
2323 2323
 	return err
2324 2324
 }
2325 2325
 
2326
-//func UpDateWarehouseInfoByStockDelete(id int64,count int64) (err error) {
2327
-//	err = DB.Model(&models.WarehousingInfo{}).Where("id = ?",info.ID).UpdateColumn("stock_count", gorm.Expr("stock_count + ?", count)).Error
2328
-//	return err
2329
-//}
2330
-
2331 2326
 func UpDateDrugWarehouseOutStatus(id int64) (err error) {
2332 2327
 	err = readDb.Model(&models.DrugWarehouseOutInfo{}).Where("id = ? AND status = 1", id).Update(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
2333 2328
 	return
2334 2329
 }
2335 2330
 
2336 2331
 func DeleteDrugWarehouseOutInfoById(id int64) (err error) {
2337
-	err = XTWriteDB().Model(&models.DrugFlow{}).Where("warehouse_out_detail_id = ? and satus = 1", id).Updates(map[string]interface{}{"status": 0}).Error
2332
+	err = XTWriteDB().Model(&models.DrugFlow{}).Where("warehouse_out_detail_id = ? and status = 1", id).Updates(map[string]interface{}{"status": 0}).Error
2338 2333
 	return
2339 2334
 }
2335
+func GetDrugWarehosueOutInfo(id int64) (models.DrugWarehouseOutInfo, error) {
2336
+	info := models.DrugWarehouseOutInfo{}
2337
+	err := XTReadDB().Where("id = ? and status = 1", id).Find(&info).Error
2338
+	return info, err
2339
+}
2340 2340
 
2341 2341
 func EditWarehouseOut(warehouseOut models.WarehouseOut) {
2342 2342
 	err = readDb.Model(&models.WarehouseOut{}).Where("id = ? AND status = 1", warehouseOut.ID).Update(map[string]interface{}{"mtime": time.Now().Unix(), "warehouse_out_time": warehouseOut.WarehouseOutTime, "dealer": warehouseOut.Dealer, "manufacturer": warehouseOut.Manufacturer}).Error
@@ -5674,3 +5674,34 @@ func ModifyDrugWarehouse(id int64, stock_max_number int64, stock_min_number int6
5674 5674
 	err = XTWriteDB().Model(&info).Where("id = ?", id).UpdateColumn("stock_min_number", gorm.Expr("stock_min_number + ?", stock_min_number)).Error
5675 5675
 	return info, err
5676 5676
 }
5677
+
5678
+func ModeifyDrugWarehosueInfo(id int64, stock_max_number int64) error {
5679
+
5680
+	err := XTWriteDB().Model(models.DrugWarehouseInfo{}).Where("id = ?", id).UpdateColumn("stock_max_number", gorm.Expr("stock_max_number + ?", stock_max_number)).Error
5681
+	return err
5682
+}
5683
+
5684
+func ModeFyStockMinById(id int64, stock_min_number int64) error {
5685
+	info := models.DrugWarehouseInfo{}
5686
+	err = XTWriteDB().Model(&info).Where("id = ?", id).UpdateColumn("stock_min_number", gorm.Expr("stock_min_number + ?", stock_min_number)).Error
5687
+	return err
5688
+}
5689
+
5690
+func GetDrugCancelById(id int64) (models.DrugCancelStockInfo, error) {
5691
+
5692
+	info := models.DrugCancelStockInfo{}
5693
+	err := XTReadDB().Where("id = ? and status = 1", id).Find(&info).Error
5694
+	return info, err
5695
+}
5696
+
5697
+func ModeFyDrugWareseInfo(id int64, stock_max_number int64) error {
5698
+	info := models.DrugWarehouseInfo{}
5699
+	err = XTWriteDB().Model(&info).Where("id = ?", id).UpdateColumn("stock_max_number", gorm.Expr("stock_max_number - ?", stock_max_number)).Error
5700
+	return err
5701
+}
5702
+
5703
+func ModeFyDrugWarehouseMin(id int64, stock_min_number int64) error {
5704
+	info := models.DrugWarehouseInfo{}
5705
+	err = XTWriteDB().Model(&info).Where("id = ?", id).UpdateColumn("stock_min_number", gorm.Expr("stock_min_number - ?", stock_min_number)).Error
5706
+	return err
5707
+}

+ 2 - 2
service/warhouse_service.go View File

@@ -806,7 +806,7 @@ func AutoDrugDeliverInfo(orgID int64, prescribingNumber int64, warehouseout *mod
806 806
 			WarehouseOutId:          warehouseout.ID,
807 807
 			Status:                  1,
808 808
 			Ctime:                   time.Now().Unix(),
809
-			Remark:                  warehouse.Remark,
809
+			Remark:                  advice.Remark,
810 810
 			OrgId:                   orgID,
811 811
 			Type:                    1,
812 812
 			Manufacturer:            advice.Manufacturer,
@@ -903,7 +903,7 @@ func AutoDrugDeliverInfo(orgID int64, prescribingNumber int64, warehouseout *mod
903 903
 			WarehouseOutId:          warehouseout.ID,
904 904
 			Status:                  1,
905 905
 			Ctime:                   time.Now().Unix(),
906
-			Remark:                  warehouse.Remark,
906
+			Remark:                  advice.Remark,
907 907
 			OrgId:                   orgID,
908 908
 			Type:                    1,
909 909
 			Manufacturer:            advice.Manufacturer,