瀏覽代碼

11月8日库存管理

XMLWAN 3 年之前
父節點
當前提交
a785cb4ff9

+ 1 - 1
conf/app.conf 查看文件

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

+ 12 - 10
controllers/mobile_api_controllers/dialysis_api_controller.go 查看文件

3911
 						err = ConsumablesDeliveryTotalSeven(adminInfo.Org.Id, patient_id, record_time, beforePrepares, adminInfo.AdminUser.Id, item.Count)
3911
 						err = ConsumablesDeliveryTotalSeven(adminInfo.Org.Id, patient_id, record_time, beforePrepares, adminInfo.AdminUser.Id, item.Count)
3912
 						break
3912
 						break
3913
 					}
3913
 					}
3914
+
3914
 					var last_total int64
3915
 					var last_total int64
3915
 
3916
 
3916
 					//如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
3917
 					//如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
4580
 //当前数据比上一次出库数据少
4581
 //当前数据比上一次出库数据少
4581
 func ConsumablesDeliveryTotalSeven(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, creater int64, count int64) (err error) {
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
 	goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
4585
 	goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
4586
 	// 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
4586
 	// 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
4619
 
4619
 
4620
 	// goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
4620
 	// goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
4621
 	// goods 这个数据就是需要出库的耗材的数据(新增的数据)
4621
 	// goods 这个数据就是需要出库的耗材的数据(新增的数据)
4622
-	fmt.Println("goodsy999999999999", goods_yc)
4623
 
4622
 
4624
 	//退库
4623
 	//退库
4625
 	if len(goods_yc) > 0 {
4624
 	if len(goods_yc) > 0 {
4635
 //耗材出库删除
4634
 //耗材出库删除
4636
 func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
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
 	warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
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
 	if err != nil {
4640
 	if err != nil {
4644
 		return err
4641
 		return err
4740
 				PatientId:               patient_id,
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
 		if errOne != nil {
4743
 		if errOne != nil {
4807
 				PatientId:               patient_id,
4804
 				PatientId:               patient_id,
4808
 				ReturnCount:             delete_count,
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
 	// 删除出库完成后,要增加对应批次的库存数量
4839
 	// 删除出库完成后,要增加对应批次的库存数量
4842
 	fmt.Println("deletecount2323232323232323232323232323", delete_count)
4840
 	fmt.Println("deletecount2323232323232323232323232323", delete_count)
4843
 	errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count)
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
 	if errThree != nil {
4844
 	if errThree != nil {
4846
 		return errThree
4845
 		return errThree
4847
 	}
4846
 	}
4994
 		stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
4993
 		stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
4995
 		warehouseOutInfo.Price = stockInInfo.Price
4994
 		warehouseOutInfo.Price = stockInInfo.Price
4996
 		errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
4995
 		errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
4996
+
4997
 		if errOne != nil {
4997
 		if errOne != nil {
4998
 			return errOne
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
 		errThree := service.UpDateWarehouseInfoByStockDelete(ware.WarehouseInfotId, delete_count)
5007
 		errThree := service.UpDateWarehouseInfoByStockDelete(ware.WarehouseInfotId, delete_count)
5006
 
5008
 
5007
 		if errThree != nil {
5009
 		if errThree != nil {

+ 1 - 1
service/mobile_dialysis_service.go 查看文件

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)
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
 		Preload("AutomaticReduceDetail", func(db *gorm.DB) *gorm.DB {
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
 		}).Where("sch.status = 1 AND sch.user_org_id = ?", orgID)
1880
 		}).Where("sch.status = 1 AND sch.user_org_id = ?", orgID)
1881
 	if scheduleDate != 0 {
1881
 	if scheduleDate != 0 {
1882
 		db = db.Where("schedule_date = ?", scheduleDate)
1882
 		db = db.Where("schedule_date = ?", scheduleDate)

+ 1 - 1
service/patient_schedule_template_service.go 查看文件

422
 	nextMonday, _ := utils.GetMondayAndSundayOfWeekDate(&nextWeek)
422
 	nextMonday, _ := utils.GetMondayAndSundayOfWeekDate(&nextWeek)
423
 	nextSecWeek := now.AddDate(0, 0, 14)
423
 	nextSecWeek := now.AddDate(0, 0, 14)
424
 	_, nextSecSunday := utils.GetMondayAndSundayOfWeekDate(&nextSecWeek)
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
 	if disableErr != nil {
426
 	if disableErr != nil {
427
 		tx.Rollback()
427
 		tx.Rollback()
428
 		return disableErr
428
 		return disableErr

+ 1 - 1
service/patient_service.go 查看文件

67
 
67
 
68
 	offset := (page - 1) * limit
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
 	return
71
 	return
72
 }
72
 }
73
 
73
 

+ 14 - 2
service/stock_service.go 查看文件

3268
 func DeleteAutoRedeceDetailTwo(orgid int64, patient_id int64, recordtime int64, goodid int64, goodtypeid int64) error {
3268
 func DeleteAutoRedeceDetailTwo(orgid int64, patient_id int64, recordtime int64, goodid int64, goodtypeid int64) error {
3269
 
3269
 
3270
 	detail := models.BloodAutomaticReduceDetail{}
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
 	return err
3272
 	return err
3273
 }
3273
 }
3274
 
3274
 
3277
 	return err
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
 func UpDateWarehouseInfoByStockDeleteOne(id int64, count int64) (err error) {
3286
 func UpDateWarehouseInfoByStockDeleteOne(id int64, count int64) (err error) {
3281
 	err = writeDb.Model(&models.WarehousingInfo{}).Where("id = ?", id).UpdateColumn("stock_count", gorm.Expr("stock_count - ?", count)).Error
3287
 	err = writeDb.Model(&models.WarehousingInfo{}).Where("id = ?", id).UpdateColumn("stock_count", gorm.Expr("stock_count - ?", count)).Error
3282
 	return err
3288
 	return err
3957
 
3963
 
3958
 func GetStockFlowBatchNumberOne(id int64, goodid int64) (stock []*models.VmStockFlowOne, err error) {
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
 	table := XTReadDB().Table("xt_patients as t").Where("t.status = 1")
3967
 	table := XTReadDB().Table("xt_patients as t").Where("t.status = 1")
3962
 	fmt.Println(table)
3968
 	fmt.Println(table)
3963
 	tableone := XTReadDB().Table("xt_good_information as o").Where("o.status = 1")
3969
 	tableone := XTReadDB().Table("xt_good_information as o").Where("o.status = 1")
4118
 	return err
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
 func GetStockFlowIsExsit(warehousing_id int64, patient_id int64, record_time int64, good_id int64) (*models.VmStockFlow, error) {
4133
 func GetStockFlowIsExsit(warehousing_id int64, patient_id int64, record_time int64, good_id int64) (*models.VmStockFlow, error) {
4122
 
4134
 
4123
 	stock := models.VmStockFlow{}
4135
 	stock := models.VmStockFlow{}

+ 10 - 10
service/warhouse_service.go 查看文件

1080
 //耗材出库
1080
 //耗材出库
1081
 func ConsumablesDelivery(orgID int64, patient_id int64, record_time int64, goods *models.DialysisBeforePrepare, warehouseOut *models.WarehouseOut, count int64) (err error) {
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
 	var deliver_number int64 = 0
1083
 	var deliver_number int64 = 0
1087
 	var stock_number int64 = 0
1084
 	var stock_number int64 = 0
1088
 	var maxNumber int64 = 0
1085
 	var maxNumber int64 = 0
1098
 		return errors.New("库存数量不足")
1095
 		return errors.New("库存数量不足")
1099
 	}
1096
 	}
1100
 
1097
 
1101
-	// 将该批次的剩余库存数量转换为拆零数量
1102
 	stock_number = warehouse.StockCount
1098
 	stock_number = warehouse.StockCount
1103
 
1099
 
1104
 	//获取耗材信息
1100
 	//获取耗材信息
1186
 				PatientId:               patient_id,
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
 			fmt.Println("什么数据233232323", errflow)
1187
 			fmt.Println("什么数据233232323", errflow)
1192
 			if errflow == gorm.ErrRecordNotFound {
1188
 			if errflow == gorm.ErrRecordNotFound {
1221
 					PatientId:               patient_id,
1217
 					PatientId:               patient_id,
1222
 					ReturnCount:             exsit.Count + (exsit.Count + deliver_number),
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
 				if errFour != nil {
1222
 				if errFour != nil {
1226
 					return errFour
1223
 					return errFour
1227
 				}
1224
 				}
1253
 				PatientId:               patient_id,
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
 			if errflow == gorm.ErrRecordNotFound {
1255
 			if errflow == gorm.ErrRecordNotFound {
1259
 				CreateStockFlowOne(flow)
1256
 				CreateStockFlowOne(flow)
1286
 					PatientId:               patient_id,
1283
 					PatientId:               patient_id,
1287
 					ReturnCount:             exsit.Count + (exsit.Count + deliver_number),
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
 				DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, goods.GoodId, goods.GoodTypeId)
1288
 				DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, goods.GoodId, goods.GoodTypeId)
1291
 				CreateAutoReduceRecord(&details)
1289
 				CreateAutoReduceRecord(&details)
1292
 			}
1290
 			}
1404
 					PatientId:               patient_id,
1402
 					PatientId:               patient_id,
1405
 					ReturnCount:             exsit.Count + (exsit.Count + deliver_number),
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
 		} else if errcodes == nil {
1409
 		} else if errcodes == nil {
1469
 					IsSys:                   1,
1468
 					IsSys:                   1,
1470
 					PatientId:               patient_id,
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