Browse Source

11月8日库存管理

XMLWAN 3 years ago
parent
commit
a785cb4ff9

+ 1 - 1
conf/app.conf View File

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

+ 12 - 10
controllers/mobile_api_controllers/dialysis_api_controller.go View File

@@ -3911,6 +3911,7 @@ func (c *DialysisAPIController) EditConsumables() {
3911 3911
 						err = ConsumablesDeliveryTotalSeven(adminInfo.Org.Id, patient_id, record_time, beforePrepares, adminInfo.AdminUser.Id, item.Count)
3912 3912
 						break
3913 3913
 					}
3914
+
3914 3915
 					var last_total int64
3915 3916
 
3916 3917
 					//如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
@@ -4580,7 +4581,6 @@ func (c *DialysisAPIController) UpdateStockGoods() {
4580 4581
 //当前数据比上一次出库数据少
4581 4582
 func ConsumablesDeliveryTotalSeven(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, creater int64, count int64) (err error) {
4582 4583
 
4583
-	fmt.Println("w我的中国馆公共区发电房阿道夫安抚安抚安抚安抚安抚安抚阿道夫阿道夫阿凡达阿道夫a", count)
4584 4584
 	//查询该患者当天已经出库的耗材信息
4585 4585
 	goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
4586 4586
 	// 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
@@ -4619,7 +4619,6 @@ func ConsumablesDeliveryTotalSeven(orgID int64, patient_id int64, record_time in
4619 4619
 
4620 4620
 	// goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
4621 4621
 	// goods 这个数据就是需要出库的耗材的数据(新增的数据)
4622
-	fmt.Println("goodsy999999999999", goods_yc)
4623 4622
 
4624 4623
 	//退库
4625 4624
 	if len(goods_yc) > 0 {
@@ -4635,10 +4634,8 @@ func ConsumablesDeliveryTotalSeven(orgID int64, patient_id int64, record_time in
4635 4634
 //耗材出库删除
4636 4635
 func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
4637 4636
 
4638
-	fmt.Println("count2323223884584854854854u5454785487547845785478758487545475475487,count", count)
4639 4637
 	// 先根据相关信息查询当天该耗材的出库信息
4640 4638
 	warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
4641
-	fmt.Println("errr232323232323232323232323232", err)
4642 4639
 
4643 4640
 	if err != nil {
4644 4641
 		return err
@@ -4740,7 +4737,7 @@ func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *mode
4740 4737
 				PatientId:               patient_id,
4741 4738
 			}
4742 4739
 
4743
-			service.UpdatedStockFlow(stockFlow)
4740
+			service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
4744 4741
 		}
4745 4742
 
4746 4743
 		if errOne != nil {
@@ -4807,7 +4804,8 @@ func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *mode
4807 4804
 				PatientId:               patient_id,
4808 4805
 				ReturnCount:             delete_count,
4809 4806
 			}
4810
-			service.UpdatedStockFlow(stockFlow)
4807
+			//service.UpdatedStockFlow(stockFlow)
4808
+			service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
4811 4809
 		}
4812 4810
 
4813 4811
 	}
@@ -4841,7 +4839,8 @@ func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *mode
4841 4839
 	// 删除出库完成后,要增加对应批次的库存数量
4842 4840
 	fmt.Println("deletecount2323232323232323232323232323", delete_count)
4843 4841
 	errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count)
4844
-
4842
+	errOne := service.UpDateWarehouStockFlowByStockDelete(warehouseOutInfos.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
4843
+	fmt.Println("erron2332323232323232232323", errOne)
4845 4844
 	if errThree != nil {
4846 4845
 		return errThree
4847 4846
 	}
@@ -4994,14 +4993,17 @@ func ConsumablesDeliveryDeleteThree(orgID int64, record_time int64, good_yc *mod
4994 4993
 		stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
4995 4994
 		warehouseOutInfo.Price = stockInInfo.Price
4996 4995
 		errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
4996
+
4997 4997
 		if errOne != nil {
4998 4998
 			return errOne
4999 4999
 		}
5000 5000
 
5001
-		//更改自动出库的表格
5002
-
5003 5001
 		// 删除出库完成后,要增加对应批次的库存数量
5004
-		fmt.Println("deletecount2323232323232323232323232323", delete_count)
5002
+		fmt.Println("时间人秘股呢换药2232323223323223322323232323232323232323232323", delete_count)
5003
+
5004
+		// 删除出库完成后,要改变流水库存
5005
+		errOne = service.UpDateWarehouStockFlowByStockDelete(ware.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
5006
+		fmt.Println("erron2332323232323232232323", errOne)
5005 5007
 		errThree := service.UpDateWarehouseInfoByStockDelete(ware.WarehouseInfotId, delete_count)
5006 5008
 
5007 5009
 		if errThree != nil {

+ 1 - 1
service/mobile_dialysis_service.go View File

@@ -1876,7 +1876,7 @@ func MobileGetDialysisGoods(orgID int64, scheduleDate int64, schedule_type int64
1876 1876
 			return db.Preload("VMGoodInfo", "status = 1 AND org_id = ?", orgID).Preload("GoodsType", "status = 1 AND (org_id = ? OR org_id = 0) ", orgID).Where("status = 1 AND user_org_id = ? AND record_date = ?  AND count > 0 ", orgID, scheduleDate)
1877 1877
 		}).
1878 1878
 		Preload("AutomaticReduceDetail", func(db *gorm.DB) *gorm.DB {
1879
-			return db.Preload("VMGoodInfo", "status = 1 AND org_id = ? ", orgID).Preload("GoodsType", "status = 1 AND (org_id = ? OR org_id = 0)  ", orgID).Where("status = 1 AND org_id = ? AND count > 0 AND record_time >= ? AND record_time <= ?  ", orgID, scheduleDate, end_time).Group("patient_id,good_id")
1879
+			return db.Preload("VMGoodInfo", "status = 1 AND org_id = ?  ", orgID).Preload("GoodsType", "status = 1 AND (org_id = ? OR org_id = 0)  ", orgID).Where("status = 1 AND org_id = ? AND count > 0 AND record_time >= ? AND record_time <= ?  ", orgID, scheduleDate, end_time).Group("patient_id,good_id")
1880 1880
 		}).Where("sch.status = 1 AND sch.user_org_id = ?", orgID)
1881 1881
 	if scheduleDate != 0 {
1882 1882
 		db = db.Where("schedule_date = ?", scheduleDate)

+ 1 - 1
service/patient_schedule_template_service.go View File

@@ -422,7 +422,7 @@ func SavePatientScheduleTemplateModeAndClearNextTwoWeekSchedules(templateMode *m
422 422
 	nextMonday, _ := utils.GetMondayAndSundayOfWeekDate(&nextWeek)
423 423
 	nextSecWeek := now.AddDate(0, 0, 14)
424 424
 	_, nextSecSunday := utils.GetMondayAndSundayOfWeekDate(&nextSecWeek)
425
-	disableErr := tx.Model(&models.Schedule{}).Where("user_org_id = ? AND status = 1 AND schedule_date >= ? AND schedule_date <= ?", templateMode.OrgID, nextMonday.Unix(), nextSecSunday.Unix()).Updates(map[string]interface{}{"status": 0, "mtime": now.Unix()}).Error
425
+	disableErr := tx.Model(&models.Schedule{}).Where("user_org_id = ? AND status = 1 AND schedule_date >= ? AND schedule_date <= ?", templateMode.OrgID, nextMonday.Unix(), nextSecSunday.Unix()).Updates(map[string]interface{}{"status": 0, "updated_time": now.Unix()}).Error
426 426
 	if disableErr != nil {
427 427
 		tx.Rollback()
428 428
 		return disableErr

+ 1 - 1
service/patient_service.go View File

@@ -67,7 +67,7 @@ func GetPatientList(orgID int64, keywords string, page, limit, schedulType, bind
67 67
 
68 68
 	offset := (page - 1) * limit
69 69
 
70
-	err = db.Order("p.id desc").Select(" p.id, p.user_org_id, p.user_id, p.patient_type, p.dialysis_no, p.admission_number, p.source, p.lapseto, p.partition_id, p.bed_id, p.name, p.alias, p.gender, p.marital_status, p.id_card_no, p.birthday, p.reimbursement_way_id, p.health_care_type, p.health_care_no, p.health_care_due_date, p.height, p.blood_type, p.rh, p.health_care_due_alert_date, p.education_level, p.profession, p.phone, p.home_telephone, p.relative_phone, p.relative_relations, p.home_address, p.work_unit, p.unit_address, p.children, p.receiving_date, p.is_hospital_first_dialysis, p.first_dialysis_date, p.first_dialysis_hospital, p.induction_period, p.initial_dialysis, p.total_dialysis, p.attending_doctor_id, p.head_nurse_id, p.evaluate, p.diagnose, p.remark, p.registrars_id, p.registrars, p.qr_code, p.binding_state, p.status, p.created_time, p.updated_time,p.user_sys_before_count,p.out_reason,p.death_time").Group("p.id").Count(&total).Offset(offset).Limit(limit).Find(&patients).Error
70
+	err = db.Order("p.id desc").Select(" p.id, p.user_org_id, p.user_id, p.patient_type, p.dialysis_no, p.admission_number, p.source, p.lapseto, p.partition_id, p.bed_id, p.name, p.alias, p.gender, p.marital_status, p.id_card_no, p.birthday, p.reimbursement_way_id, p.health_care_type, p.health_care_no, p.health_care_due_date, p.height, p.blood_type, p.rh, p.health_care_due_alert_date, p.education_level, p.profession, p.phone, p.home_telephone, p.relative_phone, p.relative_relations, p.home_address, p.work_unit, p.unit_address, p.children, p.receiving_date, p.is_hospital_first_dialysis, p.first_dialysis_date, p.first_dialysis_hospital, p.induction_period, p.initial_dialysis, p.total_dialysis, p.attending_doctor_id, p.head_nurse_id, p.evaluate, p.diagnose, p.remark, p.registrars_id, p.registrars, p.qr_code, p.binding_state, p.status, p.created_time, p.updated_time,p.user_sys_before_count,p.out_reason,p.death_time,p.is_infectious").Group("p.id").Count(&total).Offset(offset).Limit(limit).Find(&patients).Error
71 71
 	return
72 72
 }
73 73
 

+ 14 - 2
service/stock_service.go View File

@@ -3268,7 +3268,7 @@ func GetAutoMaticReduceDetail(orgid int64, patient_id int64, recordtime int64, g
3268 3268
 func DeleteAutoRedeceDetailTwo(orgid int64, patient_id int64, recordtime int64, goodid int64, goodtypeid int64) error {
3269 3269
 
3270 3270
 	detail := models.BloodAutomaticReduceDetail{}
3271
-	err := XTWriteDB().Model(&detail).Where("org_id = ? and patient_id = ? and record_time = ? and status =1 and good_id = ? and good_type_id = ?", orgid, patient_id, recordtime, goodid, goodtypeid).Updates(map[string]interface{}{"status": 0}).Error
3271
+	err := XTWriteDB().Model(&detail).Where("org_id = ? and patient_id = ? and record_time = ? and status =1 and good_id = ? and good_type_id = ?", orgid, patient_id, recordtime, goodid, goodtypeid).Updates(map[string]interface{}{"status": 0, "count": 0}).Error
3272 3272
 	return err
3273 3273
 }
3274 3274
 
@@ -3277,6 +3277,12 @@ func UpDateWarehouseInfoByStockDelete(id int64, count int64) (err error) {
3277 3277
 	return err
3278 3278
 }
3279 3279
 
3280
+func UpDateWarehouStockFlowByStockDelete(id int64, recordtime int64, good_id int64, count int64, patient_id int64) (err error) {
3281
+
3282
+	err = writeDb.Model(&models.VmStockFlow{}).Where("warehousing_id = ? and system_time = ? and good_id = ? and patient_id = ?", id, recordtime, good_id, patient_id).UpdateColumn("count", gorm.Expr("count - ?", count)).Error
3283
+	return err
3284
+}
3285
+
3280 3286
 func UpDateWarehouseInfoByStockDeleteOne(id int64, count int64) (err error) {
3281 3287
 	err = writeDb.Model(&models.WarehousingInfo{}).Where("id = ?", id).UpdateColumn("stock_count", gorm.Expr("stock_count - ?", count)).Error
3282 3288
 	return err
@@ -3957,7 +3963,7 @@ func GetStockFlowBatchNumber(id int64, goodid int64) (stock []*models.VmStockFlo
3957 3963
 
3958 3964
 func GetStockFlowBatchNumberOne(id int64, goodid int64) (stock []*models.VmStockFlowOne, err error) {
3959 3965
 
3960
-	db := XTReadDB().Table("xt_stock_flow as x").Where("x.status = 1")
3966
+	db := XTReadDB().Table("xt_stock_flow as x").Where("x.status = 1 and count > 0")
3961 3967
 	table := XTReadDB().Table("xt_patients as t").Where("t.status = 1")
3962 3968
 	fmt.Println(table)
3963 3969
 	tableone := XTReadDB().Table("xt_good_information as o").Where("o.status = 1")
@@ -4118,6 +4124,12 @@ func UpdatedStockFlow(flow models.VmStockFlow) error {
4118 4124
 	return err
4119 4125
 }
4120 4126
 
4127
+func UpdatedStockFlowOne(flow models.VmStockFlow, warehousing_id int64, patient_id int64, record_time int64, good_id int64) error {
4128
+
4129
+	err = XTWriteDB().Model(&flow).Where("warehousing_id = ? and patient_id = ? and system_time = ? and good_id = ? and status = 1", warehousing_id, patient_id, record_time, good_id).Updates(map[string]interface{}{"number": flow.Number, "license_number": flow.LicenseNumber, "count": flow.Count, "expire_date": flow.ExpireDate, "product_date": flow.ProductDate, "price": flow.Price, "manufacturer": flow.Manufacturer, "dealer": flow.Dealer}).Error
4130
+	return err
4131
+}
4132
+
4121 4133
 func GetStockFlowIsExsit(warehousing_id int64, patient_id int64, record_time int64, good_id int64) (*models.VmStockFlow, error) {
4122 4134
 
4123 4135
 	stock := models.VmStockFlow{}

+ 10 - 10
service/warhouse_service.go View File

@@ -1080,9 +1080,6 @@ func ConsumablesDeliveryTotal(orgID int64, patient_id int64, record_time int64,
1080 1080
 //耗材出库
1081 1081
 func ConsumablesDelivery(orgID int64, patient_id int64, record_time int64, goods *models.DialysisBeforePrepare, warehouseOut *models.WarehouseOut, count int64) (err error) {
1082 1082
 
1083
-	fmt.Println("count23232323232323232323232323", count)
1084
-	fmt.Println("hhhh2h3h3h2h23h32hh23h32h23", goods.Count)
1085
-	// 判断处方里药品单位是拆零单位还是包装单位,	如果是包装单位,则根据规格,将包装数量转为拆零数量
1086 1083
 	var deliver_number int64 = 0
1087 1084
 	var stock_number int64 = 0
1088 1085
 	var maxNumber int64 = 0
@@ -1098,7 +1095,6 @@ func ConsumablesDelivery(orgID int64, patient_id int64, record_time int64, goods
1098 1095
 		return errors.New("库存数量不足")
1099 1096
 	}
1100 1097
 
1101
-	// 将该批次的剩余库存数量转换为拆零数量
1102 1098
 	stock_number = warehouse.StockCount
1103 1099
 
1104 1100
 	//获取耗材信息
@@ -1186,7 +1182,7 @@ func ConsumablesDelivery(orgID int64, patient_id int64, record_time int64, goods
1186 1182
 				PatientId:               patient_id,
1187 1183
 			}
1188 1184
 			//查询流水是否存在
1189
-			exsit, errflow := GetStockFlowIsExsit(warehouseOut.ID, patient_id, record_time, goods.GoodId)
1185
+			exsit, errflow := GetStockFlowIsExsit(warehouse.ID, patient_id, record_time, goods.GoodId)
1190 1186
 
1191 1187
 			fmt.Println("什么数据233232323", errflow)
1192 1188
 			if errflow == gorm.ErrRecordNotFound {
@@ -1221,7 +1217,8 @@ func ConsumablesDelivery(orgID int64, patient_id int64, record_time int64, goods
1221 1217
 					PatientId:               patient_id,
1222 1218
 					ReturnCount:             exsit.Count + (exsit.Count + deliver_number),
1223 1219
 				}
1224
-				errFour := UpdatedStockFlow(flow)
1220
+
1221
+				errFour := UpdatedStockFlowOne(flow, warehouse.ID, patient_id, record_time, goods.GoodId)
1225 1222
 				if errFour != nil {
1226 1223
 					return errFour
1227 1224
 				}
@@ -1253,7 +1250,7 @@ func ConsumablesDelivery(orgID int64, patient_id int64, record_time int64, goods
1253 1250
 				PatientId:               patient_id,
1254 1251
 			}
1255 1252
 			//查询流水是否存在
1256
-			exsit, errflow := GetStockFlowIsExsit(warehouseOut.ID, patient_id, record_time, goods.GoodId)
1253
+			exsit, errflow := GetStockFlowIsExsit(warehouse.ID, patient_id, record_time, goods.GoodId)
1257 1254
 
1258 1255
 			if errflow == gorm.ErrRecordNotFound {
1259 1256
 				CreateStockFlowOne(flow)
@@ -1286,7 +1283,8 @@ func ConsumablesDelivery(orgID int64, patient_id int64, record_time int64, goods
1286 1283
 					PatientId:               patient_id,
1287 1284
 					ReturnCount:             exsit.Count + (exsit.Count + deliver_number),
1288 1285
 				}
1289
-				UpdatedStockFlow(flow)
1286
+				//UpdatedStockFlow(flow)
1287
+				UpdatedStockFlowOne(flow, warehouse.ID, patient_id, record_time, goods.GoodId)
1290 1288
 				DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, goods.GoodId, goods.GoodTypeId)
1291 1289
 				CreateAutoReduceRecord(&details)
1292 1290
 			}
@@ -1404,7 +1402,8 @@ func ConsumablesDelivery(orgID int64, patient_id int64, record_time int64, goods
1404 1402
 					PatientId:               patient_id,
1405 1403
 					ReturnCount:             exsit.Count + (exsit.Count + deliver_number),
1406 1404
 				}
1407
-				UpdatedStockFlow(flow)
1405
+				//UpdatedStockFlow(flow)
1406
+				UpdatedStockFlowOne(flow, warehouse.ID, patient_id, record_time, goods.GoodId)
1408 1407
 			}
1409 1408
 
1410 1409
 		} else if errcodes == nil {
@@ -1469,7 +1468,8 @@ func ConsumablesDelivery(orgID int64, patient_id int64, record_time int64, goods
1469 1468
 					IsSys:                   1,
1470 1469
 					PatientId:               patient_id,
1471 1470
 				}
1472
-				UpdatedStockFlow(flow)
1471
+				//UpdatedStockFlow(flow)
1472
+				UpdatedStockFlowOne(flow, warehouse.ID, patient_id, record_time, goods.GoodId)
1473 1473
 			}
1474 1474
 		}
1475 1475