Ver código fonte

11月9日库存管理

XMLWAN 2 anos atrás
pai
commit
508f18ee6b

+ 4 - 4
controllers/dialysis_api_controller.go Ver arquivo

@@ -3203,7 +3203,7 @@ func (c *DialysisApiController) GetLongAdviceOne() {
3203 3203
 
3204 3204
 		advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.CurrentOrgId, patient_id, theTime.Unix())
3205 3205
 		advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.CurrentOrgId, patient_id, theTime.Unix())
3206
-		fmt.Println("advice23323232233232233223232332232323322323wodee", theTime.Unix())
3206
+
3207 3207
 		for _, advice := range advices {
3208 3208
 			if advice.FrequencyType == 3 {
3209 3209
 				t := time.Now()
@@ -3296,7 +3296,7 @@ func (c *DialysisApiController) GetLongAdviceTwo() {
3296 3296
 		//groupNo := service.GetMaxLongAdviceGroupID(adminUserInfo.Org.Id, patient_id)
3297 3297
 		advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.CurrentOrgId, patient_id, schedule_date)
3298 3298
 		advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.CurrentOrgId, patient_id, schedule_date)
3299
-		fmt.Println("advice23323232233232233223232332232323322323wodee", schedule_date)
3299
+
3300 3300
 		for _, advice := range advices {
3301 3301
 			if advice.FrequencyType == 3 {
3302 3302
 				t := time.Now()
@@ -3821,7 +3821,7 @@ func (this *DialysisApiController) GetTodayMonitor() {
3821 3821
 				record.UltrafiltrationRate = ultrafiltration_rate
3822 3822
 			}
3823 3823
 
3824
-			if adminInfo.CurrentOrgId == 10395 || adminInfo.CurrentOrgId == 10138 || adminInfo.CurrentOrgId == 10278 || adminInfo.CurrentOrgId == 10340 || adminInfo.CurrentOrgId == 10432 {
3824
+			if adminInfo.CurrentOrgId == 10395 || adminInfo.CurrentOrgId == 10138 || adminInfo.CurrentOrgId == 10278 || adminInfo.CurrentOrgId == 10340 || adminInfo.CurrentOrgId == 10432 || adminInfo.CurrentOrgId == 10441 || adminInfo.CurrentOrgId == 10445 {
3825 3825
 				ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
3826 3826
 
3827 3827
 				record.UltrafiltrationRate = ultrafiltration_rate
@@ -3849,7 +3849,7 @@ func (this *DialysisApiController) GetTodayMonitor() {
3849 3849
 
3850 3850
 	}
3851 3851
 
3852
-	if adminInfo.CurrentOrgId == 10395 || adminInfo.CurrentOrgId == 10138 || adminInfo.CurrentOrgId == 10278 || adminInfo.CurrentOrgId == 10340 || adminInfo.CurrentOrgId == 10432 {
3852
+	if adminInfo.CurrentOrgId == 10395 || adminInfo.CurrentOrgId == 10138 || adminInfo.CurrentOrgId == 10278 || adminInfo.CurrentOrgId == 10340 || adminInfo.CurrentOrgId == 10432 || adminInfo.CurrentOrgId == 10441 || adminInfo.CurrentOrgId == 10445 {
3853 3853
 
3854 3854
 		if ultrafiltration_rate > 0 {
3855 3855
 			ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)

+ 2 - 2
controllers/dialysis_record_api_controller.go Ver arquivo

@@ -1085,7 +1085,7 @@ func (this *DialysisRecordAPIController) StartDialysis() {
1085 1085
 				}
1086 1086
 
1087 1087
 				//针对肇庆三鹤血液透析中心
1088
-				if adminUserInfo.CurrentOrgId == 10215 || template.TemplateId == 43 {
1088
+				if adminUserInfo.CurrentOrgId == 10215 || template.TemplateId == 43 || adminUserInfo.CurrentOrgId == 10441 || adminUserInfo.CurrentOrgId == 10445 {
1089 1089
 
1090 1090
 					if evaluation.ID > 0 {
1091 1091
 						ultrafiltration_rate = math.Ceil(prescription.TargetUltrafiltration / float64(totalMin) * 60)
@@ -1412,7 +1412,7 @@ func (this *DialysisRecordAPIController) FinishDialysis() {
1412 1412
 
1413 1413
 	err := service.UpdateAssessmentAfterDislysisRecord(&tempassessmentAfterDislysis)
1414 1414
 
1415
-	if adminUserInfo.CurrentOrgId == 9671 || adminUserInfo.CurrentOrgId == 9675 || adminUserInfo.CurrentOrgId == 10164 || adminUserInfo.CurrentOrgId == 10340 || adminUserInfo.CurrentOrgId == 10414 || adminUserInfo.CurrentOrgId == 10432 {
1415
+	if adminUserInfo.CurrentOrgId == 9671 || adminUserInfo.CurrentOrgId == 9675 || adminUserInfo.CurrentOrgId == 10164 || adminUserInfo.CurrentOrgId == 10340 || adminUserInfo.CurrentOrgId == 10414 || adminUserInfo.CurrentOrgId == 10432 || adminUserInfo.CurrentOrgId == 10445 {
1416 1416
 
1417 1417
 		evaluation, _ := service.MobileGetPredialysisEvaluationTwo(adminUserInfo.CurrentOrgId, patientID, recordDate.Unix())
1418 1418
 		if evaluation.SystolicBloodPressure == 0 {

+ 1 - 1
controllers/drug_stock_api_contorller.go Ver arquivo

@@ -1403,7 +1403,7 @@ func (c *StockDrugApiController) GetDrugWarehouseOutList() {
1403 1403
 	}
1404 1404
 
1405 1405
 	warehouseOutList, total, err := service.FindAllDrugWarehouseOutListOne(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords, ids, storehouse_id, way_type, check_type)
1406
-	fmt.Println("warehouseOutList232332323232323", warehouseOutList)
1406
+
1407 1407
 	houseList, _ := service.GetAllStoreHouseList(adminUserInfo.CurrentOrgId)
1408 1408
 	fmt.Println(err)
1409 1409
 	if err == nil {

+ 44 - 1
controllers/gobal_config_api_controller.go Ver arquivo

@@ -119,6 +119,8 @@ func GobalConfigRegistRouters() {
119 119
 	beego.Router("/api/changedrugopenconfig", &GobalConfigApiController{}, "Get:ChangeDrugOpenConfig")
120 120
 
121 121
 	beego.Router("/api/changesettleopenconfig", &GobalConfigApiController{}, "Get:ChangeSettleOpenConfig")
122
+
123
+	beego.Router("/api/changegoodoutopen", &GobalConfigApiController{}, "Get:ChangeGoodOutOpen")
122 124
 }
123 125
 
124 126
 //provinces, _ := service.GetDistrictsByUpid(0)21
@@ -164,6 +166,10 @@ func (c *GobalConfigApiController) PostStockConfig() {
164 166
 
165 167
 	}
166 168
 
169
+	if is_open == 1 {
170
+		service.UpdateGobalConfig(org_id)
171
+	}
172
+
167 173
 	c.ServeSuccessJSON(map[string]interface{}{
168 174
 		"is_open": is_open,
169 175
 	})
@@ -1574,6 +1580,8 @@ func (c *GobalConfigApiController) GetAllIsOpenConfig() {
1574 1580
 	drugOutConfig, _ := service.FindDrugOutConfigById(adminUserInfo.CurrentOrgId)
1575 1581
 
1576 1582
 	drugSettleConfig, _ := service.FindeDrugSettleConfigById(adminUserInfo.CurrentOrgId)
1583
+
1584
+	goodOutConfig, _ := service.FindGoodOutConfigById(adminUserInfo.CurrentOrgId)
1577 1585
 	c.ServeSuccessJSON(map[string]interface{}{
1578 1586
 		"is_open_xt_his":         config.IsOpen,
1579 1587
 		"is_open_xt_his_project": project_config.IsOpen,
@@ -1582,6 +1590,7 @@ func (c *GobalConfigApiController) GetAllIsOpenConfig() {
1582 1590
 		"is_prescription_advice": prescriptionConfig.IsOpen,
1583 1591
 		"is_open":                drugOutConfig.IsOpen,
1584 1592
 		"is_seetle_open":         drugSettleConfig.IsOpen,
1593
+		"is_out_open":            goodOutConfig.IsOpen,
1585 1594
 	})
1586 1595
 
1587 1596
 }
@@ -2387,7 +2396,7 @@ func (c *GobalConfigApiController) GetDrugFlow() {
2387 2396
 	stock_type, _ := c.GetInt64("stock_type")
2388 2397
 
2389 2398
 	list, total, _ := service.GetDrugFlow(drug_id, orgId, limit, page, startTime, endTime, stock_type)
2390
-	fmt.Println("listwowoowowowowowo", list)
2399
+
2391 2400
 	manufacturerList, _ := service.GetAllManufacturerList(orgId)
2392 2401
 	dealerList, _ := service.GetAllDealerList(orgId)
2393 2402
 	medical, _ := service.GetBaseDrugMedical(drug_id)
@@ -2548,6 +2557,8 @@ func (this *GobalConfigApiController) ChangeSettleOpenConfig() {
2548 2557
 		service.UpdateDrugOutConfig(orgId, 2)
2549 2558
 		service.UpdateDrugStockAutomaticReduceRecordOne(orgId, 2)
2550 2559
 		service.UpdatePharyConfig(orgId, 2)
2560
+		service.UpdateGoodAutoConfig(orgId)
2561
+		service.UpdateGoodOutConfig(orgId)
2551 2562
 	}
2552 2563
 	openConfig, errcode := service.GetSettleOpenConfig(orgId)
2553 2564
 	if errcode == gorm.ErrRecordNotFound {
@@ -2559,3 +2570,35 @@ func (this *GobalConfigApiController) ChangeSettleOpenConfig() {
2559 2570
 		"msg": 1,
2560 2571
 	})
2561 2572
 }
2573
+
2574
+func (this *GobalConfigApiController) ChangeGoodOutOpen() {
2575
+
2576
+	good_open, _ := this.GetInt64("good_open")
2577
+
2578
+	orgId := this.GetAdminUserInfo().CurrentOrgId
2579
+
2580
+	config, errcode := service.GetGoodOutOpenConfig(orgId)
2581
+
2582
+	outConfig := models.XtGoodOutConfig{
2583
+		UserOrgId: orgId,
2584
+		IsOpen:    good_open,
2585
+		Status:    1,
2586
+		Ctime:     time.Now().Unix(),
2587
+		Mtime:     time.Now().Unix(),
2588
+	}
2589
+
2590
+	if good_open == 1 {
2591
+		service.UpdateGoodAutoConfig(orgId)
2592
+		service.UpdateSettleOpenConfigTwo(orgId, 2)
2593
+	}
2594
+
2595
+	if errcode == gorm.ErrRecordNotFound {
2596
+		service.CreateGoodOutOpenConfig(outConfig)
2597
+	} else if errcode == nil {
2598
+		service.UpdateGoodOutOpenConfig(config.ID, outConfig)
2599
+	}
2600
+
2601
+	this.ServeSuccessJSON(map[string]interface{}{
2602
+		"msg": 1,
2603
+	})
2604
+}

Diferenças do arquivo suprimidas por serem muito extensas
+ 1059 - 428
controllers/his_api_controller.go


+ 2 - 2
controllers/mobile_api_controllers/check_weight_api_controller.go Ver arquivo

@@ -269,7 +269,7 @@ func (c *CheckWeightApiController) SavePatientInfoDialysis() {
269 269
 
270 270
 	template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
271 271
 
272
-	if template.TemplateId == 22 || template.TemplateId == 17 || template.TemplateId == 21 || template.TemplateId == 26 || template.TemplateId == 27 || template.TemplateId == 34 || template.TemplateId == 30 || template.TemplateId == 32 || template.TemplateId == 36 || template.TemplateId == 40 || template.TemplateId == 38 || template.TemplateId == 43 || template.TemplateId == 46 || template.TemplateId == 53 || template.TemplateId == 48 || adminUserInfo.Org.Id == 10345 || adminUserInfo.Org.Id == 10432 {
272
+	if template.TemplateId == 22 || template.TemplateId == 17 || template.TemplateId == 21 || template.TemplateId == 26 || template.TemplateId == 27 || template.TemplateId == 34 || template.TemplateId == 30 || template.TemplateId == 32 || template.TemplateId == 36 || template.TemplateId == 40 || template.TemplateId == 38 || template.TemplateId == 43 || template.TemplateId == 46 || template.TemplateId == 53 || template.TemplateId == 48 || adminUserInfo.Org.Id == 10345 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10441 || adminUserInfo.Org.Id == 10445 {
273 273
 		dewater_amount = dewater_amount * 1000
274 274
 	}
275 275
 
@@ -730,7 +730,7 @@ func (c *CheckWeightApiController) SavePatientInfoDialysis() {
730 730
 			afterevaluation.Fallrisk = assessmentAfterDislysis.Fallrisk
731 731
 		}
732 732
 
733
-		if adminUserInfo.Org.Id == 10307 {
733
+		if adminUserInfo.Org.Id == 10307 || adminUserInfo.Org.Id == 10445 {
734 734
 			afterevaluation.ActualUltrafiltration = weight_loss * 1000 //中能建的计量单位是毫升(ml)
735 735
 		}
736 736
 

+ 14 - 5
controllers/mobile_api_controllers/dialysis_api_controller.go Ver arquivo

@@ -1847,7 +1847,7 @@ func (c *DialysisAPIController) Finish() {
1847 1847
 
1848 1848
 	}
1849 1849
 
1850
-	if adminUserInfo.Org.Id == 10101 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9675 || adminUserInfo.Org.Id == 10215 || adminUserInfo.Org.Id == 10233 || adminUserInfo.Org.Id == 10223 || adminUserInfo.Org.Id == 10243 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10414 || adminUserInfo.Org.Id == 10430 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10223 {
1850
+	if adminUserInfo.Org.Id == 10101 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9675 || adminUserInfo.Org.Id == 10215 || adminUserInfo.Org.Id == 10233 || adminUserInfo.Org.Id == 10223 || adminUserInfo.Org.Id == 10243 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10414 || adminUserInfo.Org.Id == 10430 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10223 {
1851 1851
 		evaluation, _ := service.MobileGetPredialysisEvaluationOne(adminUserInfo.Org.Id, id, recordDate.Unix())
1852 1852
 		if evaluation.SystolicBloodPressure == 0 {
1853 1853
 			evaluation.SystolicBloodPressure = fmonitorRecords.SystolicBloodPressure
@@ -2402,7 +2402,7 @@ func (this *DialysisAPIController) StartDialysis() {
2402 2402
 
2403 2403
 			//针对肇庆三鹤血液透析中心
2404 2404
 
2405
-			if template.TemplateId == 43 || adminUserInfo.Org.Id == 10432 {
2405
+			if template.TemplateId == 43 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10441 || adminUserInfo.Org.Id == 10445 {
2406 2406
 				ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
2407 2407
 			}
2408 2408
 
@@ -2435,7 +2435,7 @@ func (this *DialysisAPIController) StartDialysis() {
2435 2435
 	}
2436 2436
 
2437 2437
 	//只针对广慈医院
2438
-	if template.TemplateId == 26 || template.TemplateId == 25 || template.TemplateId == 28 || adminUserInfo.Org.Id == 9987 || adminUserInfo.Org.Id == 9526 || template.TemplateId == 32 || adminUserInfo.Org.Id == 9918 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 4 || adminUserInfo.Org.Id == 10432 {
2438
+	if template.TemplateId == 26 || template.TemplateId == 25 || template.TemplateId == 28 || adminUserInfo.Org.Id == 9987 || adminUserInfo.Org.Id == 9526 || template.TemplateId == 32 || adminUserInfo.Org.Id == 9918 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 4 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10445 {
2439 2439
 		// 查询病人是否有透前评估数据
2440 2440
 		befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
2441 2441
 
@@ -3074,7 +3074,7 @@ func (this *DialysisAPIController) GetLastMonitorRecordTody() {
3074 3074
 				record.UltrafiltrationRate = ultrafiltration_rate
3075 3075
 			}
3076 3076
 
3077
-			if adminInfo.Org.Id == 10395 || adminInfo.Org.Id == 10138 || adminInfo.Org.Id == 10278 || adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 10432 {
3077
+			if adminInfo.Org.Id == 10395 || adminInfo.Org.Id == 10138 || adminInfo.Org.Id == 10278 || adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 10432 || adminInfo.Org.Id == 10441 || adminInfo.Org.Id == 10445 {
3078 3078
 				ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
3079 3079
 				record.UltrafiltrationRate = ultrafiltration_rate
3080 3080
 			}
@@ -3103,7 +3103,7 @@ func (this *DialysisAPIController) GetLastMonitorRecordTody() {
3103 3103
 		}
3104 3104
 	}
3105 3105
 
3106
-	if adminInfo.Org.Id == 10395 || adminInfo.Org.Id == 10138 || adminInfo.Org.Id == 10278 || adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 10432 {
3106
+	if adminInfo.Org.Id == 10395 || adminInfo.Org.Id == 10138 || adminInfo.Org.Id == 10278 || adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 10432 || adminInfo.Org.Id == 10441 || adminInfo.Org.Id == 10445 {
3107 3107
 
3108 3108
 		if ultrafiltration_rate > 0 {
3109 3109
 			ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
@@ -5573,6 +5573,11 @@ func (c *DialysisAPIController) GetDialysisGoods() {
5573 5573
 	project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
5574 5574
 
5575 5575
 	_, config := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
5576
+
5577
+	outConfig, _ := service.FindGoodOutConfigById(adminUser.Org.Id)
5578
+
5579
+	settleConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.Org.Id)
5580
+
5576 5581
 	//获取当天该病人的透析处方
5577 5582
 	prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
5578 5583
 	good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
@@ -5597,6 +5602,8 @@ func (c *DialysisAPIController) GetDialysisGoods() {
5597 5602
 			"good_info":        good_info,
5598 5603
 			"warehouseOutList": warehouseOutList,
5599 5604
 			"config":           config,
5605
+			"outConfig":        outConfig,
5606
+			"settleConfig":     settleConfig,
5600 5607
 		})
5601 5608
 		return
5602 5609
 
@@ -5624,6 +5631,8 @@ func (c *DialysisAPIController) GetDialysisGoods() {
5624 5631
 				"project":          project,
5625 5632
 				"warehouseOutList": warehouseOutList,
5626 5633
 				"config":           config,
5634
+				"outConfig":        outConfig,
5635
+				"settleConfig":     settleConfig,
5627 5636
 			})
5628 5637
 			return
5629 5638
 

+ 2 - 2
controllers/mobile_api_controllers/patient_api_controller.go Ver arquivo

@@ -1225,8 +1225,8 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1225 1225
 							}
1226 1226
 						}
1227 1227
 					}
1228
-
1229
-					//if config.IsOpen == 1 && item.UserOrgId == 10028 {
1228
+					//
1229
+					//if config.IsOpen == 1 && item.UserOrgId == 10088 {
1230 1230
 					//
1231 1231
 					//	service.HisDrugsDelivery(adminInfo.Org.Id, creater, &advice)
1232 1232
 					//	//更新字典里面的库存

+ 301 - 209
controllers/secondary_order_api_contorller.go Ver arquivo

@@ -1023,6 +1023,7 @@ func (this *SecondaryOrderApiController) CheckSecondOrer() {
1023 1023
 				return
1024 1024
 			}
1025 1025
 		}
1026
+
1026 1027
 	}
1027 1028
 	err := service.UpdateStoreOrderByArray(idArray, orgId, creater)
1028 1029
 	//如果审核成功
@@ -1204,6 +1205,44 @@ func (this *SecondaryOrderApiController) CheckSecondOrer() {
1204 1205
 					service.UpdateBaseDrugSumTwo(item.ProjectId, sum_count, item.UserOrgId)
1205 1206
 				}
1206 1207
 
1208
+				//查询该药品该仓库是否有数据
1209
+				drug, _ := service.GetDrugStockCout(item.ProjectId, item.StorehouseInId, item.UserOrgId)
1210
+				var sum_out_count int64
1211
+				baseDrug, _ := service.GetBaseDrugMedical(item.ProjectId)
1212
+				if item.SencondUnit == baseDrug.MaxUnit && baseDrug.MaxUnit != baseDrug.MinUnit {
1213
+					sum_out_count = item.Count * baseDrug.MinNumber
1214
+				}
1215
+				if item.SencondUnit == baseDrug.MinUnit && baseDrug.MaxUnit != baseDrug.MinUnit {
1216
+					sum_out_count = item.Count
1217
+				}
1218
+
1219
+				if item.SencondUnit == baseDrug.MaxUnit && baseDrug.MaxUnit == baseDrug.MinUnit {
1220
+					sum_out_count = item.Count
1221
+				}
1222
+				if drug.ID == 0 {
1223
+					drugstock := models.XtDrugStockCount{
1224
+						UserOrgId:      orgId,
1225
+						StorehouseId:   item.StorehouseInId,
1226
+						SumInCount:     sum_out_count,
1227
+						SumOutCount:    0,
1228
+						SumCancelCount: 0,
1229
+						DrugId:         item.ProjectId,
1230
+						Ctime:          time.Now().Unix(),
1231
+						Mtime:          0,
1232
+						Status:         1,
1233
+						FlushCount:     sum_out_count,
1234
+						SumActOutCount: 0,
1235
+					}
1236
+					service.CreateDrugStockCount(drugstock)
1237
+				}
1238
+
1239
+				if drug.ID > 0 {
1240
+
1241
+					service.AddDrugStockCount(item.StorehouseInId, item.ProjectId, item.UserOrgId, sum_out_count)
1242
+				}
1243
+
1244
+				//更新出库数据
1245
+				service.ReduceDrugStockCountSix(item.StorehouseOutId, item.ProjectId, item.UserOrgId, sum_out_count)
1207 1246
 			}
1208 1247
 
1209 1248
 			//耗材
@@ -1328,117 +1367,147 @@ func (this *SecondaryOrderApiController) CheckSecondOrer() {
1328 1367
 				}
1329 1368
 				//基础库插入数据
1330 1369
 				service.UpdateGoodInfoSumCountSix(item.ProjectId, total_count, orgId)
1331
-			}
1332
-		}
1333
-	}
1334 1370
 
1335
-	//获取所有的入库仓库
1336
-	druglist, _ := service.GetDrugWarehouseInfoStorehouseList(orgId)
1337
-	for _, item := range druglist {
1338
-		//查询该药品该仓库是否有数据
1339
-		drug, _ := service.GetDrugStockCout(item.DrugId, item.StorehouseId, item.OrgId)
1340
-
1341
-		//查询该仓库该药品的入库数量
1342
-		medical, _ := service.GetBaseDrugMedical(item.DrugId)
1343
-
1344
-		var sum_in_count int64
1345
-		var flush_count int64
1346
-		var sum_out_count int64
1347
-		var cancel_out_count int64
1348
-		//查询入库数量和剩余库存
1349
-		infolist, _ := service.GetDrugWarehouseInfoByStorehouseId(item.StorehouseId, item.DrugId, item.OrgId)
1350
-		for _, it := range infolist {
1351
-			if it.MaxUnit == medical.MaxUnit {
1352
-				it.WarehousingCount = it.WarehousingCount * medical.MinNumber
1353
-				it.StockMaxNumber = it.StockMaxNumber * medical.MinNumber
1354
-			}
1355
-			sum_in_count += it.WarehousingCount
1356
-			flush_count += it.StockMaxNumber + it.StockMinNumber
1357
-		}
1371
+				//查询是否有数据
1372
+				_, errcodes := service.GetStockFlush(item.StorehouseInId, item.ProjectId, item.UserOrgId)
1373
+				if errcodes == gorm.ErrRecordNotFound {
1374
+					good := models.XtGoodStockCount{
1375
+						UserOrgId:        item.UserOrgId,
1376
+						GoodId:           item.ProjectId,
1377
+						StorehouseId:     item.StorehouseInId,
1378
+						Status:           1,
1379
+						Ctime:            time.Now().Unix(),
1380
+						Mtime:            0,
1381
+						StockInCount:     item.Count,
1382
+						StockOutCount:    0,
1383
+						StockCancelCount: 0,
1384
+						FlushCount:       item.Count,
1385
+						StockActOutCount: 0,
1386
+					}
1387
+					service.CreateGoodCountSix(good)
1388
+				} else if errcodes == nil {
1358 1389
 
1359
-		//获取出库数量
1360
-		outinfolist, _ := service.GetDrugFlowStockOutCount(item.StorehouseId, item.DrugId, item.OrgId)
1361
-		for _, it := range outinfolist {
1362
-			if it.MaxUnit == medical.MaxUnit {
1363
-				it.Count = it.Count * medical.MinNumber
1364
-			}
1365
-			sum_out_count += it.Count
1366
-		}
1390
+					service.AddGoodStockCount(item.StorehouseInId, item.ProjectId, item.UserOrgId, item.Count)
1391
+				}
1367 1392
 
1368
-		//获取退库数量
1369
-		cancelinfolist, _ := service.GetDrugFlowStockCancelCount(item.StorehouseId, item.DrugId, item.OrgId)
1370
-		for _, it := range cancelinfolist {
1371
-			if it.MaxUnit == medical.MaxUnit {
1372
-				it.Count = it.Count * medical.MinNumber
1373
-			}
1374
-			cancel_out_count += it.Count
1375
-		}
1393
+				//更新出库数据
1394
+				service.ReduceStockCount(item.StorehouseOutId, item.ProjectId, item.UserOrgId, item.Count)
1376 1395
 
1377
-		//新增
1378
-		if drug.ID == 0 {
1379
-			drugstock := models.XtDrugStockCount{
1380
-				UserOrgId:      orgId,
1381
-				StorehouseId:   item.StorehouseId,
1382
-				SumInCount:     sum_in_count,
1383
-				SumOutCount:    sum_out_count - cancel_out_count,
1384
-				SumCancelCount: cancel_out_count,
1385
-				DrugId:         item.DrugId,
1386
-				Ctime:          time.Now().Unix(),
1387
-				Mtime:          0,
1388
-				Status:         1,
1389
-				FlushCount:     flush_count,
1390
-				SumActOutCount: sum_out_count,
1391 1396
 			}
1392
-			service.CreateDrugStockCount(drugstock)
1393 1397
 		}
1394 1398
 	}
1395 1399
 
1396
-	//获取入库数据
1397
-	goodlist, _ := service.GetSendGoodInformation(orgId)
1398
-	for _, it := range goodlist {
1399
-		//查询是否有数据
1400
-		_, errcode := service.GetStockFlush(it.StorehouseId, it.GoodId, it.OrgId)
1401
-		//获取总退库数量
1402
-		var cancel_count int64
1403
-		var out_count int64
1404
-		var act_count int64
1405
-		//退库总数量
1406
-		cancellist, _ := service.GetAllCancelCount(it.StorehouseId, it.GoodId, it.OrgId)
1407
-		for _, item := range cancellist {
1408
-			cancel_count += item.Count
1409
-		}
1410
-		//出库总数量
1411
-		outlist, _ := service.GetAllStockOutCount(it.StorehouseId, it.GoodId, it.OrgId)
1412
-		for _, item := range outlist {
1413
-			out_count += item.Count
1414
-		}
1415
-
1416
-		//实际出库总数量
1417
-		actlist, _ := service.GetActStockOutCount(it.StorehouseId, it.GoodId, it.OrgId)
1418
-		for _, item := range actlist {
1419
-			act_count += item.Count
1420
-		}
1421
-
1422
-		if errcode == gorm.ErrRecordNotFound {
1423
-			good := models.XtGoodStockCount{
1424
-				UserOrgId:        it.OrgId,
1425
-				GoodId:           it.GoodId,
1426
-				StorehouseId:     it.StorehouseId,
1427
-				Status:           1,
1428
-				Ctime:            time.Now().Unix(),
1429
-				Mtime:            0,
1430
-				StockInCount:     it.WarehousingCount,
1431
-				StockOutCount:    out_count - cancel_count,
1432
-				StockCancelCount: cancel_count,
1433
-				FlushCount:       it.StockCount,
1434
-				StockActOutCount: act_count,
1435
-			}
1436
-			service.CreateGoodCountSix(good)
1437
-		}
1438
-		if errcode == nil {
1439
-			service.UpdateGoodCount(it.WarehousingCount, it.StockCount, out_count, it.StorehouseId, it.GoodId, it.OrgId, cancel_count, act_count)
1440
-		}
1441
-	}
1400
+	//获取所有的入库仓库
1401
+	//druglist, _ := service.GetDrugWarehouseInfoStorehouseList(orgId)
1402
+	//for _, item := range druglist {
1403
+	//	//查询该药品该仓库是否有数据
1404
+	//	drug, _ := service.GetDrugStockCout(item.DrugId, item.StorehouseId, item.OrgId)
1405
+	//
1406
+	//	//查询该仓库该药品的入库数量
1407
+	//	medical, _ := service.GetBaseDrugMedical(item.DrugId)
1408
+	//
1409
+	//	var sum_in_count int64
1410
+	//	var flush_count int64
1411
+	//	var sum_out_count int64
1412
+	//	var cancel_out_count int64
1413
+	//	//查询入库数量和剩余库存
1414
+	//	infolist, _ := service.GetDrugWarehouseInfoByStorehouseId(item.StorehouseId, item.DrugId, item.OrgId)
1415
+	//	for _, it := range infolist {
1416
+	//		if it.MaxUnit == medical.MaxUnit {
1417
+	//			it.WarehousingCount = it.WarehousingCount * medical.MinNumber
1418
+	//			it.StockMaxNumber = it.StockMaxNumber * medical.MinNumber
1419
+	//		}
1420
+	//		sum_in_count += it.WarehousingCount
1421
+	//		flush_count += it.StockMaxNumber + it.StockMinNumber
1422
+	//	}
1423
+	//
1424
+	//	//获取出库数量
1425
+	//	outinfolist, _ := service.GetDrugFlowStockOutCount(item.StorehouseId, item.DrugId, item.OrgId)
1426
+	//	for _, it := range outinfolist {
1427
+	//		if it.MaxUnit == medical.MaxUnit {
1428
+	//			it.Count = it.Count * medical.MinNumber
1429
+	//		}
1430
+	//		sum_out_count += it.Count
1431
+	//	}
1432
+	//
1433
+	//	//获取退库数量
1434
+	//	cancelinfolist, _ := service.GetDrugFlowStockCancelCount(item.StorehouseId, item.DrugId, item.OrgId)
1435
+	//	for _, it := range cancelinfolist {
1436
+	//		if it.MaxUnit == medical.MaxUnit {
1437
+	//			it.Count = it.Count * medical.MinNumber
1438
+	//		}
1439
+	//		cancel_out_count += it.Count
1440
+	//	}
1441
+	//
1442
+	//	//新增
1443
+	//	if drug.ID == 0 {
1444
+	//		drugstock := models.XtDrugStockCount{
1445
+	//			UserOrgId:      orgId,
1446
+	//			StorehouseId:   item.StorehouseId,
1447
+	//			SumInCount:     sum_in_count,
1448
+	//			SumOutCount:    sum_out_count - cancel_out_count,
1449
+	//			SumCancelCount: cancel_out_count,
1450
+	//			DrugId:         item.DrugId,
1451
+	//			Ctime:          time.Now().Unix(),
1452
+	//			Mtime:          0,
1453
+	//			Status:         1,
1454
+	//			FlushCount:     flush_count,
1455
+	//			SumActOutCount: sum_out_count,
1456
+	//		}
1457
+	//		service.CreateDrugStockCount(drugstock)
1458
+	//	}
1459
+	//}
1460
+	//
1461
+	////获取入库数量
1462
+	//
1463
+	//
1464
+	//
1465
+	//////获取入库数据
1466
+	//goodlist, _ := service.GetSendGoodInformation(orgId)
1467
+	//for _, it := range goodlist {
1468
+	//	//查询是否有数据
1469
+	//	_, errcode := service.GetStockFlush(it.StorehouseId, it.GoodId, it.OrgId)
1470
+	//	//获取总退库数量
1471
+	//	var cancel_count int64
1472
+	//	var out_count int64
1473
+	//	var act_count int64
1474
+	//	//退库总数量
1475
+	//	cancellist, _ := service.GetAllCancelCount(it.StorehouseId, it.GoodId, it.OrgId)
1476
+	//	for _, item := range cancellist {
1477
+	//		cancel_count += item.Count
1478
+	//	}
1479
+	//	//出库总数量
1480
+	//	outlist, _ := service.GetAllStockOutCount(it.StorehouseId, it.GoodId, it.OrgId)
1481
+	//	for _, item := range outlist {
1482
+	//		out_count += item.Count
1483
+	//	}
1484
+	//
1485
+	//	//实际出库总数量
1486
+	//	actlist, _ := service.GetActStockOutCount(it.StorehouseId, it.GoodId, it.OrgId)
1487
+	//	for _, item := range actlist {
1488
+	//		act_count += item.Count
1489
+	//	}
1490
+	//
1491
+	//	if errcode == gorm.ErrRecordNotFound {
1492
+	//		good := models.XtGoodStockCount{
1493
+	//			UserOrgId:        it.OrgId,
1494
+	//			GoodId:           it.GoodId,
1495
+	//			StorehouseId:     it.StorehouseId,
1496
+	//			Status:           1,
1497
+	//			Ctime:            time.Now().Unix(),
1498
+	//			Mtime:            0,
1499
+	//			StockInCount:     it.WarehousingCount,
1500
+	//			StockOutCount:    out_count - cancel_count,
1501
+	//			StockCancelCount: cancel_count,
1502
+	//			FlushCount:       it.StockCount,
1503
+	//			StockActOutCount: act_count,
1504
+	//		}
1505
+	//		service.CreateGoodCountSix(good)
1506
+	//	}
1507
+	//	if errcode == nil {
1508
+	//		service.UpdateGoodCountSend(it.WarehousingCount, it.StockCount, out_count, it.StorehouseId, it.GoodId, it.OrgId, cancel_count, act_count)
1509
+	//	}
1510
+	//}
1442 1511
 
1443 1512
 	this.ServeSuccessJSON(map[string]interface{}{
1444 1513
 		"msg": 1,
@@ -1616,6 +1685,24 @@ func (this *SecondaryOrderApiController) ReturnCheckSecondOrder() {
1616 1685
 				sum_count += its.StockMaxNumber + its.StockMinNumber
1617 1686
 			}
1618 1687
 			service.UpdateBaseDrugSumTwo(item.ProjectId, sum_count, item.UserOrgId)
1688
+
1689
+			var sum_out_count int64
1690
+			baseDrug, _ := service.GetBaseDrugMedical(item.ProjectId)
1691
+			if item.SencondUnit == baseDrug.MaxUnit && baseDrug.MaxUnit != baseDrug.MinUnit {
1692
+				sum_out_count = item.Count * baseDrug.MinNumber
1693
+			}
1694
+			if item.SencondUnit == baseDrug.MinUnit && baseDrug.MaxUnit != baseDrug.MinUnit {
1695
+				sum_out_count = item.Count
1696
+			}
1697
+
1698
+			if item.SencondUnit == baseDrug.MaxUnit && baseDrug.MaxUnit == baseDrug.MinUnit {
1699
+				sum_out_count = item.Count
1700
+			}
1701
+			//入库仓库减少
1702
+			service.ReduceDrugStockCountSeven(item.StorehouseInId, item.ProjectId, item.UserOrgId, sum_out_count)
1703
+
1704
+			//出库仓库增加
1705
+			service.AddDrugStockCount(item.StorehouseOutId, item.ProjectId, item.UserOrgId, sum_out_count)
1619 1706
 		}
1620 1707
 
1621 1708
 		//耗材
@@ -1656,116 +1743,121 @@ func (this *SecondaryOrderApiController) ReturnCheckSecondOrder() {
1656 1743
 			//基础库插入数据
1657 1744
 			service.UpdateGoodInfoSumCount(item.ProjectId, total_count, orgId)
1658 1745
 
1659
-		}
1660
-	}
1746
+			//入库仓库减少
1747
+			service.ReduceStockCountTwo(item.StorehouseInId, item.ProjectId, item.UserOrgId, item.Count)
1661 1748
 
1662
-	//获取所有的入库仓库
1663
-	druglist, _ := service.GetDrugWarehouseInfoStorehouseList(orgId)
1664
-	for _, item := range druglist {
1665
-		//查询该药品该仓库是否有数据
1666
-		drug, _ := service.GetDrugStockCout(item.DrugId, item.StorehouseId, item.OrgId)
1667
-
1668
-		//查询该仓库该药品的入库数量
1669
-		medical, _ := service.GetBaseDrugMedical(item.DrugId)
1670
-
1671
-		var sum_in_count int64
1672
-		var flush_count int64
1673
-		var sum_out_count int64
1674
-		var cancel_out_count int64
1675
-		//查询入库数量和剩余库存
1676
-		infolist, _ := service.GetDrugWarehouseInfoByStorehouseId(item.StorehouseId, item.DrugId, item.OrgId)
1677
-		for _, it := range infolist {
1678
-			if it.MaxUnit == medical.MaxUnit {
1679
-				it.WarehousingCount = it.WarehousingCount * medical.MinNumber
1680
-				it.StockMaxNumber = it.StockMaxNumber * medical.MinNumber
1681
-			}
1682
-			sum_in_count += it.WarehousingCount
1683
-			flush_count += it.StockMaxNumber + it.StockMinNumber
1684
-		}
1685
-
1686
-		//获取出库数量
1687
-		outinfolist, _ := service.GetDrugFlowStockOutCount(item.StorehouseId, item.DrugId, item.OrgId)
1688
-		for _, it := range outinfolist {
1689
-			if it.MaxUnit == medical.MaxUnit {
1690
-				it.Count = it.Count * medical.MinNumber
1691
-			}
1692
-			sum_out_count += it.Count
1693
-		}
1694
-
1695
-		//获取退库数量
1696
-		cancelinfolist, _ := service.GetDrugFlowStockCancelCount(item.StorehouseId, item.DrugId, item.OrgId)
1697
-		for _, it := range cancelinfolist {
1698
-			if it.MaxUnit == medical.MaxUnit {
1699
-				it.Count = it.Count * medical.MinNumber
1700
-			}
1701
-			cancel_out_count += it.Count
1702
-		}
1703
-
1704
-		//新增
1705
-		if drug.ID == 0 {
1706
-			drugstock := models.XtDrugStockCount{
1707
-				UserOrgId:      orgId,
1708
-				StorehouseId:   item.StorehouseId,
1709
-				SumInCount:     sum_in_count,
1710
-				SumOutCount:    sum_out_count - cancel_out_count,
1711
-				SumCancelCount: cancel_out_count,
1712
-				DrugId:         item.DrugId,
1713
-				Ctime:          time.Now().Unix(),
1714
-				Mtime:          0,
1715
-				Status:         1,
1716
-				FlushCount:     flush_count,
1717
-				SumActOutCount: sum_out_count,
1718
-			}
1719
-			service.CreateDrugStockCount(drugstock)
1749
+			//出库仓库增加
1750
+			service.AddGoodStockCount(item.StorehouseOutId, item.ProjectId, item.UserOrgId, item.Count)
1720 1751
 		}
1721 1752
 	}
1722 1753
 
1723
-	//获取入库数据
1724
-	goodlist, _ := service.GetSendGoodInformation(orgId)
1725
-	for _, it := range goodlist {
1726
-		//查询是否有数据
1727
-		_, errcode := service.GetStockFlush(it.StorehouseId, it.GoodId, it.OrgId)
1728
-		//获取总退库数量
1729
-		var cancel_count int64
1730
-		var out_count int64
1731
-		var act_count int64
1732
-		//退库总数量
1733
-		cancellist, _ := service.GetAllCancelCount(it.StorehouseId, it.GoodId, it.OrgId)
1734
-		for _, item := range cancellist {
1735
-			cancel_count += item.Count
1736
-		}
1737
-		//出库总数量
1738
-		outlist, _ := service.GetAllStockOutCount(it.StorehouseId, it.GoodId, it.OrgId)
1739
-		for _, item := range outlist {
1740
-			out_count += item.Count
1741
-		}
1742
-
1743
-		//实际出库总数量
1744
-		actlist, _ := service.GetActStockOutCount(it.StorehouseId, it.GoodId, it.OrgId)
1745
-		for _, item := range actlist {
1746
-			act_count += item.Count
1747
-		}
1748
-
1749
-		if errcode == gorm.ErrRecordNotFound {
1750
-			good := models.XtGoodStockCount{
1751
-				UserOrgId:        it.OrgId,
1752
-				GoodId:           it.GoodId,
1753
-				StorehouseId:     it.StorehouseId,
1754
-				Status:           1,
1755
-				Ctime:            time.Now().Unix(),
1756
-				Mtime:            0,
1757
-				StockInCount:     it.WarehousingCount,
1758
-				StockOutCount:    out_count - cancel_count,
1759
-				StockCancelCount: cancel_count,
1760
-				FlushCount:       it.StockCount,
1761
-				StockActOutCount: act_count,
1762
-			}
1763
-			service.CreateGoodCountSix(good)
1764
-		}
1765
-		if errcode == nil {
1766
-			service.UpdateGoodCount(it.WarehousingCount, it.StockCount, out_count, it.StorehouseId, it.GoodId, it.OrgId, cancel_count, act_count)
1767
-		}
1768
-	}
1754
+	////获取所有的入库仓库
1755
+	//druglist, _ := service.GetDrugWarehouseInfoStorehouseList(orgId)
1756
+	//for _, item := range druglist {
1757
+	//	//查询该药品该仓库是否有数据
1758
+	//	drug, _ := service.GetDrugStockCout(item.DrugId, item.StorehouseId, item.OrgId)
1759
+	//
1760
+	//	//查询该仓库该药品的入库数量
1761
+	//	medical, _ := service.GetBaseDrugMedical(item.DrugId)
1762
+	//
1763
+	//	var sum_in_count int64
1764
+	//	var flush_count int64
1765
+	//	var sum_out_count int64
1766
+	//	var cancel_out_count int64
1767
+	//	//查询入库数量和剩余库存
1768
+	//	infolist, _ := service.GetDrugWarehouseInfoByStorehouseId(item.StorehouseId, item.DrugId, item.OrgId)
1769
+	//	for _, it := range infolist {
1770
+	//		if it.MaxUnit == medical.MaxUnit {
1771
+	//			it.WarehousingCount = it.WarehousingCount * medical.MinNumber
1772
+	//			it.StockMaxNumber = it.StockMaxNumber * medical.MinNumber
1773
+	//		}
1774
+	//		sum_in_count += it.WarehousingCount
1775
+	//		flush_count += it.StockMaxNumber + it.StockMinNumber
1776
+	//	}
1777
+	//
1778
+	//	//获取出库数量
1779
+	//	outinfolist, _ := service.GetDrugFlowStockOutCount(item.StorehouseId, item.DrugId, item.OrgId)
1780
+	//	for _, it := range outinfolist {
1781
+	//		if it.MaxUnit == medical.MaxUnit {
1782
+	//			it.Count = it.Count * medical.MinNumber
1783
+	//		}
1784
+	//		sum_out_count += it.Count
1785
+	//	}
1786
+	//
1787
+	//	//获取退库数量
1788
+	//	cancelinfolist, _ := service.GetDrugFlowStockCancelCount(item.StorehouseId, item.DrugId, item.OrgId)
1789
+	//	for _, it := range cancelinfolist {
1790
+	//		if it.MaxUnit == medical.MaxUnit {
1791
+	//			it.Count = it.Count * medical.MinNumber
1792
+	//		}
1793
+	//		cancel_out_count += it.Count
1794
+	//	}
1795
+	//
1796
+	//	//新增
1797
+	//	if drug.ID == 0 {
1798
+	//		drugstock := models.XtDrugStockCount{
1799
+	//			UserOrgId:      orgId,
1800
+	//			StorehouseId:   item.StorehouseId,
1801
+	//			SumInCount:     sum_in_count,
1802
+	//			SumOutCount:    sum_out_count - cancel_out_count,
1803
+	//			SumCancelCount: cancel_out_count,
1804
+	//			DrugId:         item.DrugId,
1805
+	//			Ctime:          time.Now().Unix(),
1806
+	//			Mtime:          0,
1807
+	//			Status:         1,
1808
+	//			FlushCount:     flush_count,
1809
+	//			SumActOutCount: sum_out_count,
1810
+	//		}
1811
+	//		service.CreateDrugStockCount(drugstock)
1812
+	//	}
1813
+	//}
1814
+
1815
+	////获取入库数据
1816
+	//goodlist, _ := service.GetSendGoodInformation(orgId)
1817
+	//for _, it := range goodlist {
1818
+	//	//查询是否有数据
1819
+	//	_, errcode := service.GetStockFlush(it.StorehouseId, it.GoodId, it.OrgId)
1820
+	//	//获取总退库数量
1821
+	//	var cancel_count int64
1822
+	//	var out_count int64
1823
+	//	var act_count int64
1824
+	//	//退库总数量
1825
+	//	cancellist, _ := service.GetAllCancelCount(it.StorehouseId, it.GoodId, it.OrgId)
1826
+	//	for _, item := range cancellist {
1827
+	//		cancel_count += item.Count
1828
+	//	}
1829
+	//	//出库总数量
1830
+	//	outlist, _ := service.GetAllStockOutCount(it.StorehouseId, it.GoodId, it.OrgId)
1831
+	//	for _, item := range outlist {
1832
+	//		out_count += item.Count
1833
+	//	}
1834
+	//
1835
+	//	//实际出库总数量
1836
+	//	actlist, _ := service.GetActStockOutCount(it.StorehouseId, it.GoodId, it.OrgId)
1837
+	//	for _, item := range actlist {
1838
+	//		act_count += item.Count
1839
+	//	}
1840
+	//
1841
+	//	if errcode == gorm.ErrRecordNotFound {
1842
+	//		good := models.XtGoodStockCount{
1843
+	//			UserOrgId:        it.OrgId,
1844
+	//			GoodId:           it.GoodId,
1845
+	//			StorehouseId:     it.StorehouseId,
1846
+	//			Status:           1,
1847
+	//			Ctime:            time.Now().Unix(),
1848
+	//			Mtime:            0,
1849
+	//			StockInCount:     it.WarehousingCount,
1850
+	//			StockOutCount:    out_count - cancel_count,
1851
+	//			StockCancelCount: cancel_count,
1852
+	//			FlushCount:       it.StockCount,
1853
+	//			StockActOutCount: act_count,
1854
+	//		}
1855
+	//		service.CreateGoodCountSix(good)
1856
+	//	}
1857
+	//	if errcode == nil {
1858
+	//		service.UpdateGoodCount(it.WarehousingCount, it.StockCount, out_count, it.StorehouseId, it.GoodId, it.OrgId, cancel_count, act_count)
1859
+	//	}
1860
+	//}
1769 1861
 
1770 1862
 	this.ServeSuccessJSON(map[string]interface{}{
1771 1863
 		"msg": "1",

+ 1 - 0
controllers/stock_in_api_controller.go Ver arquivo

@@ -3774,6 +3774,7 @@ func (this *StockManagerApiController) AddGoodInformation() {
3774 3774
 				IsUser:                      2,
3775 3775
 				PackingUnit:                 item.PackingUnit,
3776 3776
 				PackingPrice:                item.RetailPrice,
3777
+				IsWarehouse:                 1,
3777 3778
 			}
3778 3779
 
3779 3780
 			//查询同种耗材名称同种类型同种规格的耗材是否存在

+ 2 - 0
models/dialysis.go Ver arquivo

@@ -1095,6 +1095,7 @@ type DialysisBeforePrepareGoods struct {
1095 1095
 	SpecificationName string `gorm:"column:specification_name" json:"specification_name" form:"specification_name"`
1096 1096
 	ProjectId         int64  `gorm:"column:project_id" json:"project_id" form:"project_id"`
1097 1097
 	StorehouseId      int64  `gorm:"column:storehouse_id" json:"storehouse_id" form:"storehouse_id"`
1098
+	PatientId         int64  `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
1098 1099
 }
1099 1100
 
1100 1101
 type NewDialysisBeforePrepareGoods struct {
@@ -1109,6 +1110,7 @@ type NewDialysisBeforePrepareGoods struct {
1109 1110
 	RecordDate                         int64                            `gorm:"column:record_date" json:"record_date" form:"record_date"`
1110 1111
 	UserOrgId                          int64                            `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
1111 1112
 	ChildNewDialysisBeforePrepareGoods []*NewDialysisBeforePrepareGoods `gorm:"ForeignKey:GoodId;AssociationForeignKey:GoodId" json:"child"`
1113
+	PatientId                          int64                            `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
1112 1114
 }
1113 1115
 
1114 1116
 type OldDialysisBeforePrepareGoods struct {

+ 5 - 0
models/drug_stock.go Ver arquivo

@@ -128,6 +128,7 @@ type DrugWarehouseOut struct {
128 128
 	StorehouseId            int64         `gorm:"column:storehouse_id" json:"storehouse_id" form:"storehouse_id"`
129 129
 	SecondWarehouseId       int64         `gorm:"column:second_warehouse_id" json:"second_warehouse_id" form:"second_warehouse_id"`
130 130
 	IsCheck                 int64         `gorm:"column:is_check" json:"is_check" form:"is_check"`
131
+	OrderId                 int64         `gorm:"column:order_id" json:"order_id" form:"order_id"`
131 132
 }
132 133
 
133 134
 func (DrugWarehouseOut) TableName() string {
@@ -176,6 +177,7 @@ type DrugWarehouseOutInfo struct {
176 177
 	IsCheck                 int64       `gorm:"column:is_check" json:"is_check" form:"is_check"`
177 178
 	BaseDrugLib             BaseDrugLib `gorm:"ForeignKey:ID;AssociationForeignKey:DrugId"json:"drug" `
178 179
 	OverCount               int64       `gorm:"column:over_count" json:"over_count" form:"over_count"`
180
+	OrderId                 int64       `gorm:"column:order_id" json:"order_id" form:"order_id"`
179 181
 }
180 182
 
181 183
 func (DrugWarehouseOutInfo) TableName() string {
@@ -249,6 +251,7 @@ type DrugCancelStock struct {
249 251
 	DrugCancelStockInfo []*DrugCancelStockInfo `gorm:"ForeignKey:CancelStockId;AssociationForeignKey:ID" json:"drugCancelStockInfo"`
250 252
 	StorehouseId        int64                  `gorm:"column:storehouse_id" json:"storehouse_id" form:"storehouse_id"`
251 253
 	IsCheck             int64                  `gorm:"column:is_check" json:"is_check" form:"is_check"`
254
+	OrderId             int64                  `gorm:"column:order_id" json:"order_id" form:"order_id"`
252 255
 }
253 256
 
254 257
 func (DrugCancelStock) TableName() string {
@@ -284,6 +287,7 @@ type DrugCancelStockInfo struct {
284 287
 	StorehouseId      int64                `gorm:"column:storehouse_id" json:"storehouse_id" form:"storehouse_id"`
285 288
 	IsCheck           int64                `gorm:"column:is_check" json:"is_check" form:"is_check"`
286 289
 	DrugWarehouseInfo []*DrugWarehouseInfo `gorm:"ForeignKey:DrugId;AssociationForeignKey:DrugId"json:"drug_warehouse_info" `
290
+	OrderId           int64                `gorm:"column:order_id" json:"order_id" form:"order_id"`
287 291
 }
288 292
 
289 293
 func (DrugCancelStockInfo) TableName() string {
@@ -435,6 +439,7 @@ type DrugFlow struct {
435 439
 	OverCount                 int64                  `gorm:"column:over_count" json:"over_count" form:"over_count"`
436 440
 	RetailPrice               float64                `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
437 441
 	XtDrugWarehouseOutInfo    XtDrugWarehouseOutInfo `gorm:"ForeignKey:ID;AssociationForeignKey:WarehouseOutDetailId"json:"xt_drug_warehouse_out_info" `
442
+	OrderId                   int64                  `gorm:"column:order_id" json:"order_id" form:"order_id"`
438 443
 }
439 444
 
440 445
 func (DrugFlow) TableName() string {

+ 55 - 0
models/his_models.go Ver arquivo

@@ -2442,3 +2442,58 @@ type HisSettleStockConfig struct {
2442 2442
 func (HisSettleStockConfig) TableName() string {
2443 2443
 	return "his_settle_stock_config"
2444 2444
 }
2445
+
2446
+type XtGoodOutConfig struct {
2447
+	ID        int64 `gorm:"column:id" json:"id" form:"id"`
2448
+	UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
2449
+	IsOpen    int64 `gorm:"column:is_open" json:"is_open" form:"is_open"`
2450
+	Status    int64 `gorm:"column:status" json:"status" form:"status"`
2451
+	Ctime     int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
2452
+	Mtime     int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
2453
+}
2454
+
2455
+func (XtGoodOutConfig) TableName() string {
2456
+	return "xt_good_out_config"
2457
+}
2458
+
2459
+type GoodHisPrescriptionProject struct {
2460
+	ID                   int64   `gorm:"column:id" json:"id" form:"id"`
2461
+	ProjectId            int64   `gorm:"column:project_id" json:"project_id" form:"project_id"`
2462
+	Price                float64 `gorm:"column:price" json:"price" form:"price"`
2463
+	UserOrgId            int64   `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
2464
+	Status               int64   `gorm:"column:status" json:"status" form:"status"`
2465
+	Ctime                int64   `gorm:"column:ctime" json:"ctime" form:"ctime"`
2466
+	Mtime                int64   `gorm:"column:mtime" json:"mtime" form:"mtime"`
2467
+	PatientId            int64   `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
2468
+	HisPatientId         int64   `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
2469
+	RecordDate           int64   `gorm:"column:record_date" json:"record_date" form:"record_date"`
2470
+	PrescriptionId       int64   `gorm:"column:prescription_id" json:"prescription_id" form:"prescription_id"`
2471
+	Count                string  `gorm:"column:count" json:"count" form:"count"`
2472
+	FeedetlSn            string  `gorm:"column:feedetl_sn" json:"feedetl_sn" form:"feedetl_sn"`
2473
+	MedListCodg          string  `gorm:"column:med_list_codg" json:"med_list_codg" form:"med_list_codg"`
2474
+	SingleDose           string  `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
2475
+	DeliveryWay          string  `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
2476
+	ExecutionFrequency   string  `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
2477
+	Day                  string  `gorm:"column:day" json:"day" form:"day"`
2478
+	Remark               string  `gorm:"column:remark" json:"remark" form:"remark"`
2479
+	Unit                 string  `gorm:"column:unit" json:"unit" form:"unit"`
2480
+	Type                 int64   `gorm:"column:type" json:"type" form:"type"`
2481
+	Doctor               int64   `gorm:"column:doctor" json:"doctor" form:"doctor"`
2482
+	ExecutionTime        int64   `gorm:"column:execution_time" json:"execution_time" form:"execution_time"`
2483
+	ExecutionStaff       int64   `gorm:"column:execution_staff" json:"execution_staff" form:"execution_staff"`
2484
+	ExecutionState       int64   `gorm:"column:execution_state" json:"execution_state" form:"execution_state"`
2485
+	CheckTime            int64   `gorm:"column:check_time" json:"check_time" form:"check_time"`
2486
+	CheckState           int64   `gorm:"column:check_state" json:"check_state" form:"check_state"`
2487
+	Checker              int64   `gorm:"column:checker" json:"checker" form:"checker"`
2488
+	StartTime            int64   `gorm:"column:start_time" json:"start_time" form:"start_time"`
2489
+	TeamId               int64   `gorm:"column:team_id" json:"team_id" form:"team_id"`
2490
+	FrequencyType        int64   `gorm:"column:frequency_type" json:"frequency_type" form:"frequency_type"`
2491
+	DayCount             int64   `gorm:"column:day_count" json:"day_count" form:"day_count"`
2492
+	WeekDay              string  `gorm:"column:week_day" json:"week_day" form:"week_day"`
2493
+	ExecutionFrequencyId int64   `gorm:"column:execution_frequency_id" json:"execution_frequency_id" form:"execution_frequency_id"`
2494
+	IsOut                int64   `gorm:"column:is_out" json:"is_out" form:"is_out"`
2495
+}
2496
+
2497
+func (GoodHisPrescriptionProject) TableName() string {
2498
+	return "his_prescription_project"
2499
+}

+ 2 - 0
models/patient_models.go Ver arquivo

@@ -24,6 +24,7 @@ type MSchedualPatientList struct {
24 24
 	UserSysBeforeCount int64  `gorm:"column:user_sys_before_count" json:"user_sys_before_count" form:"user_sys_before_count"`
25 25
 	TrobleShoot        int64  `gorm:"column:troble_shoot" json:"troble_shoot" form:"troble_shoot"`
26 26
 	SchRemark          string `gorm:"column:sch_remark" json:"sch_remark" form:"sch_remark"`
27
+	ScheduleRemark     string `gorm:"column:schedule_remark" json:"schedule_remark" form:"schedule_remark"`
27 28
 }
28 29
 
29 30
 func (MSchedualPatientList) TableName() string {
@@ -48,6 +49,7 @@ type MDialysisOrderForList struct {
48 49
 	EndTime            int64                 `gorm:"column:end_time" json:"end_time" form:"end_time"`
49 50
 	DialysisIrrigation string                `gorm:"column:dialysis_irrigation" json:"dialysis_irrigation" form:"dialysis_irrigation"`
50 51
 	DialysisDialyszers string                `gorm:"column:dialysis_dialyszers" json:"dialysis_dialyszers" form:"dialysis_dialyszers"`
52
+	ScheduleRemark     string                `gorm:"column:schedule_remark" json:"schedule_remark" form:"schedule_remark"`
51 53
 }
52 54
 
53 55
 func (MDialysisOrderForList) TableName() string {

+ 41 - 0
models/stock_models.go Ver arquivo

@@ -219,6 +219,7 @@ type WarehouseOut struct {
219 219
 	StorehouseId            int64        `gorm:"column:storehouse_id" json:"storehouse_id" form:"storehouse_id"`
220 220
 	SecondWarehouseId       int64        `gorm:"column:second_warehouse_id" json:"second_warehouse_id" form:"second_warehouse_id"`
221 221
 	IsCheck                 int64        `gorm:"column:is_check" json:"is_check" form:"is_check"`
222
+	OrderId                 int64        `gorm:"column:order_id" json:"order_id" form:"order_id"`
222 223
 }
223 224
 
224 225
 func (WarehouseOut) TableName() string {
@@ -269,6 +270,7 @@ type WarehouseOutInfo struct {
269 270
 	WarehousingInfo         WarehousingInfo `gorm:"ForeignKey:ID;AssociationForeignKey:WarehouseInfotId" `
270 271
 	VmStockFlow             VmStockFlow     `gorm:"ForeignKey:ID;AssociationForeignKey:WarehouseOutDetailId" json:"stock_flow"`
271 272
 	OverCount               int64           `gorm:"column:over_count" json:"over_count" form:"over_count"`
273
+	OrderId                 int64           `gorm:"column:order_id" json:"order_id" form:"order_id"`
272 274
 }
273 275
 
274 276
 func (WarehouseOutInfo) TableName() string {
@@ -655,6 +657,7 @@ type VmStockFlow struct {
655 657
 	IsRead                    int64           `gorm:"column:is_read" json:"is_read" form:"is_read"`
656 658
 	IsCheck                   int64           `gorm:"column:is_check" json:"is_check" form:"is_check"`
657 659
 	OverCount                 int64           `gorm:"column:over_count" json:"over_count" form:"over_count"`
660
+	OrderId                   int64           `gorm:"column:order_id" json:"order_id" form:"order_id"`
658 661
 }
659 662
 
660 663
 func (VmStockFlow) TableName() string {
@@ -1568,3 +1571,41 @@ type StartDrugWarehouseInfo struct {
1568 1571
 func (StartDrugWarehouseInfo) TableName() string {
1569 1572
 	return "xt_drug_warehouse_info"
1570 1573
 }
1574
+
1575
+type GoodWarehousingInfo struct {
1576
+	ID                        int64   `gorm:"column:id" json:"id"`
1577
+	WarehousingId             int64   `gorm:"column:warehousing_id" json:"warehousing_id"`
1578
+	GoodId                    int64   `gorm:"column:good_id" json:"good_id"`
1579
+	GoodTypeId                int64   `gorm:"column:good_type_id" json:"good_type_id"`
1580
+	Number                    string  `gorm:"column:number" json:"number"`
1581
+	ProductDate               int64   `gorm:"column:product_date" json:"product_date"`
1582
+	ExpiryDate                int64   `gorm:"column:expiry_date" json:"expiry_date"`
1583
+	WarehousingCount          int64   `gorm:"column:warehousing_count" json:"warehousing_count"`
1584
+	WarehousingUnit           string  `gorm:"column:warehousing_unit" json:"warehousing_unit"`
1585
+	Price                     float64 `gorm:"column:price" json:"price"`
1586
+	TotalPrice                float64 `gorm:"column:total_price" json:"total_price"`
1587
+	Dealer                    int64   `gorm:"column:dealer" json:"dealer"`
1588
+	Manufacturer              int64   `gorm:"column:manufacturer" json:"manufacturer"`
1589
+	Remark                    string  `gorm:"column:remark" json:"remark"`
1590
+	Ctime                     int64   `gorm:"column:ctime" json:"ctime"`
1591
+	Mtime                     int64   `gorm:"column:mtime" json:"mtime"`
1592
+	Status                    int64   `gorm:"column:status" json:"status"`
1593
+	OrgId                     int64   `gorm:"column:org_id" json:"org_id"`
1594
+	IsReturn                  int64   `gorm:"column:is_return" json:"is_return"`
1595
+	StockCount                int64   `gorm:"column:stock_count" json:"stock_count" form:"stock_count"`
1596
+	WarehousingOrder          string  `gorm:"column:warehousing_order" json:"warehousing_order"`
1597
+	Type                      int64   `gorm:"column:type" json:"type"`
1598
+	LicenseNumber             string  `gorm:"column:license_number" json:"license_number" form:"license_number"`
1599
+	WarehouseInfoId           int64   `gorm:"column:warehouse_info_id" json:"warehouse_info_id" form:"warehouse_info_id"`
1600
+	PackingPrice              float64 `gorm:"column:packing_price" json:"packing_price" form:"packing_price"`
1601
+	SupplyWarehouseId         int64   `gorm:"column:supply_warehouse_id" json:"supply_warehouse_id" form:"supply_warehouse_id"`
1602
+	SupplyWarehouseDetailInfo int64   `gorm:"column:supply_warehouse_detail_info" json:"supply_warehouse_detail_info" form:"supply_warehouse_detail_info"`
1603
+	StorehouseId              int64   `gorm:"column:storehouse_id" json:"storehouse_id" form:"storehouse_id"`
1604
+	SecondWarehouseInfoId     int64   `gorm:"column:second_warehouse_info_id" json:"second_warehouse_info_id" form:"second_warehouse_info_id"`
1605
+	IsCheck                   int64   `gorm:"column:is_check" json:"is_check" form:"is_check"`
1606
+	RegisterNumber            string  `gorm:"column:register_number" json:"register_number" form:"register_number"`
1607
+}
1608
+
1609
+func (GoodWarehousingInfo) TableName() string {
1610
+	return "xt_warehouse_info"
1611
+}

+ 7 - 0
service/gobal_config_service.go Ver arquivo

@@ -31,6 +31,13 @@ func UpdateAutomaticReduceRecord(config *models.GobalConfig) (err error) {
31 31
 	return
32 32
 }
33 33
 
34
+func UpdateGobalConfig(user_org_id int64) error {
35
+
36
+	config := models.GobalConfig{}
37
+	err := XTWriteDB().Model(&config).Where("org_id = ? and status = 1").Updates(map[string]interface{}{"is_open": 2}).Error
38
+	return err
39
+}
40
+
34 41
 func UpdateDrugStockAutomaticReduceRecord(config *models.DrugStockConfig) (err error) {
35 42
 	err = writeDb.Save(config).Error
36 43
 	return

+ 7 - 0
service/his_service.go Ver arquivo

@@ -2655,3 +2655,10 @@ func GetStockGoodList(good_id int64, org_id int64) (models.XtGoodStockCount, err
2655 2655
 	err = XTReadDB().Where("good_id = ? and user_org_id = ? and status= 1", good_id, org_id).Find(&stockCount).Error
2656 2656
 	return stockCount, err
2657 2657
 }
2658
+
2659
+func GetLastOrderTX(user_org_id int64) (models.HisOrder, error) {
2660
+
2661
+	order := models.HisOrder{}
2662
+	err := XTReadDB().Where("user_org_id = ? and status = 1", user_org_id).Last(&order).Error
2663
+	return order, err
2664
+}

+ 36 - 8
service/manage_center_service.go Ver arquivo

@@ -584,14 +584,24 @@ func DrugAutoAddCancelInfo(advice *models.HisDoctorAdviceInfo, creater int64) er
584 584
 				}
585 585
 				sum_count += its.StockMaxNumber + its.StockMinNumber
586 586
 			}
587
+			var count_one int64
588
+			if advice.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
589
+				count_one = prescribingNumber * drug.MinNumber
590
+			}
591
+			if advice.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
592
+				count_one = prescribingNumber
593
+			}
594
+			if advice.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
595
+				count_one = prescribingNumber * drug.MinNumber
596
+			}
587 597
 			flow := models.DrugFlow{
588 598
 				WarehousingId:           info.WarehouseInfoId,
589 599
 				DrugId:                  info.DrugId,
590 600
 				Number:                  "",
591 601
 				BatchNumber:             info.BatchNumber,
592
-				Count:                   prescribingNumber,
602
+				Count:                   count_one,
593 603
 				UserOrgId:               advice.UserOrgId,
594
-				PatientId:               0,
604
+				PatientId:               advice.PatientId,
595 605
 				SystemTime:              info.SysRecordTime,
596 606
 				ConsumableType:          7,
597 607
 				IsSys:                   0,
@@ -614,7 +624,7 @@ func DrugAutoAddCancelInfo(advice *models.HisDoctorAdviceInfo, creater int64) er
614 624
 				CancelOutDetailId:       0,
615 625
 				ExpireDate:              info.ExpiryDate,
616 626
 				ProductDate:             info.ProductDate,
617
-				MaxUnit:                 advice.PrescribingNumberUnit,
627
+				MaxUnit:                 drug.MinUnit,
618 628
 				MinUnit:                 "",
619 629
 				AdviceId:                info.AdviceId,
620 630
 				StorehouseId:            storeHouseConfig.DrugStorehouseOut,
@@ -694,14 +704,25 @@ func DrugAutoAddCancelInfo(advice *models.HisDoctorAdviceInfo, creater int64) er
694 704
 				sum_count += its.StockMaxNumber + its.StockMinNumber
695 705
 			}
696 706
 
707
+			var count_one int64
708
+			if advice.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
709
+				count_one = prescribingNumber * drug.MinNumber
710
+			}
711
+			if advice.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
712
+				count_one = prescribingNumber
713
+			}
714
+			if advice.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
715
+				count_one = prescribingNumber * drug.MinNumber
716
+			}
717
+
697 718
 			flow := models.DrugFlow{
698 719
 				WarehousingId:           info.WarehouseInfoId,
699 720
 				DrugId:                  info.DrugId,
700 721
 				Number:                  "",
701 722
 				BatchNumber:             info.BatchNumber,
702
-				Count:                   prescribingNumber,
723
+				Count:                   count_one,
703 724
 				UserOrgId:               advice.UserOrgId,
704
-				PatientId:               0,
725
+				PatientId:               advice.PatientId,
705 726
 				SystemTime:              info.SysRecordTime,
706 727
 				ConsumableType:          7,
707 728
 				IsSys:                   0,
@@ -724,7 +745,7 @@ func DrugAutoAddCancelInfo(advice *models.HisDoctorAdviceInfo, creater int64) er
724 745
 				CancelOutDetailId:       0,
725 746
 				ExpireDate:              info.ExpiryDate,
726 747
 				ProductDate:             info.ProductDate,
727
-				MaxUnit:                 advice.PrescribingNumberUnit,
748
+				MaxUnit:                 drug.MinUnit,
728 749
 				MinUnit:                 "",
729 750
 				AdviceId:                info.AdviceId,
730 751
 				StorehouseId:            houseConfig.DrugStorehouseOut,
@@ -871,7 +892,7 @@ func DrugAutoAddCancelInfo(advice *models.HisDoctorAdviceInfo, creater int64) er
871 892
 func GoodAutoAddCancelInfo(good *models.NewDialysisBeforePrepareGoods, creater int64) error {
872 893
 
873 894
 	//查询已经出库数量
874
-	info, _ := GetWareOutInfo(good.GoodId, good.RecordDate, good.UserOrgId)
895
+	info, _ := GetWareOutInfo(good.GoodId, good.RecordDate, good.UserOrgId, good.PatientId)
875 896
 	if len(info) > 0 {
876 897
 		houseConfig, _ := GetAllStoreHouseConfig(good.UserOrgId)
877 898
 
@@ -974,14 +995,21 @@ func GoodAutoAddCancelInfo(good *models.NewDialysisBeforePrepareGoods, creater i
974 995
 
975 996
 			//回退库存
976 997
 			UpDateWarehouseInfoByStockDelete(item.WarehouseInfotId, item.Count, item.PatientId, item.SysRecordTime, item.GoodId)
998
+
977 999
 			//退库数量增加
978 1000
 			UpdateSumAddCancelCount(good.UserOrgId, good.GoodId, houseConfig.StorehouseOutInfo, good.Count)
979 1001
 			//出库数量减少
980 1002
 			UpdateSumCount(good.UserOrgId, houseConfig.StorehouseOutInfo, good.GoodId, good.Count)
981 1003
 			//删除出库表
982 1004
 			DeleteAutoRedeceDetailTen(good.UserOrgId, item.PatientId, item.SysRecordTime, item.GoodId)
1005
+
1006
+			goodListOne, _ := GetSumGoodList(item.OrgId, houseConfig.StorehouseOutInfo, item.GoodId)
1007
+			var flush_count int64
1008
+			for _, it := range goodListOne {
1009
+				flush_count += it.StockCount
1010
+			}
983 1011
 			//更新剩余库存
984
-			UpdateSumGood(good.UserOrgId, houseConfig.StorehouseOutInfo, item.GoodId, over_count)
1012
+			UpdateSumGood(good.UserOrgId, houseConfig.StorehouseOutInfo, item.GoodId, flush_count)
985 1013
 		}
986 1014
 	}
987 1015
 	return err

+ 3 - 1
service/mobile_dialysis_service.go Ver arquivo

@@ -171,6 +171,7 @@ type MSchedualPatientVMList struct {
171 171
 	UserSysBeforeCount int64  `gorm:"column:user_sys_before_count" json:"user_sys_before_count" form:"user_sys_before_count"`
172 172
 	TrobleShoot        int64  `gorm:"column:troble_shoot" json:"troble_shoot" form:"troble_shoot"`
173 173
 	SchRemark          string `gorm:"column:sch_remark" json:"sch_remark" form:"sch_remark"`
174
+	ScheduleRemark     string `gorm:"column:schedule_remark" json:"schedule_remark" form:"schedule_remark"`
174 175
 }
175 176
 
176 177
 func (MSchedualPatientVMList) TableName() string {
@@ -300,6 +301,7 @@ type MDialysisOrderVMList struct {
300 301
 	NucleinDate        int64            `gorm:"column:nuclein_date" json:"nuclein_date" form:"nuclein_date"`
301 302
 	DialysisIrrigation string           `gorm:"column:dialysis_irrigation" json:"dialysis_irrigation" form:"dialysis_irrigation"`
302 303
 	DialysisDialyszers string           `gorm:"column:dialysis_dialyszers" json:"dialysis_dialyszers" form:"dialysis_dialyszers"`
304
+	ScheduleRemark     string           `gorm:"column:schedule_remark" json:"schedule_remark" form:"schedule_remark"`
303 305
 }
304 306
 
305 307
 func (MDialysisOrderVMList) TableName() string {
@@ -626,7 +628,7 @@ func MobileGetReceiverTreatmentAccessRecord(orgID int64, patientID int64, record
626 628
 
627 629
 // 透前评估
628 630
 func MobileGetPredialysisEvaluationOne(orgID int64, patientID int64, recordDate int64) (*models.PredialysisEvaluation, error) {
629
-	fmt.Println("recordDate", recordDate)
631
+
630 632
 	var record models.PredialysisEvaluation
631 633
 	err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
632 634
 	if err != nil {

+ 153 - 4
service/new_stock_service.go Ver arquivo

@@ -124,7 +124,7 @@ func GetSumGoodList(orgid int64, storehouse_id int64, good_id int64) (info []*mo
124 124
 
125 125
 func UpdateSumGood(orgid int64, storehouse_id int64, good_id int64, flush_count int64) error {
126 126
 	db := writeDb.Begin()
127
-	err := db.Model(&models.XtGoodStockCount{}).Where("user_org_id = ? and storehouse_id = ? and good_id = ? and status = 1", orgid, storehouse_id, good_id).Update(map[string]interface{}{"flush_count": flush_count}).Error
127
+	err := db.Model(&models.XtGoodStockCount{}).Where("user_org_id = ? and storehouse_id = ? and good_id = ? and status = 1", orgid, storehouse_id, good_id).Updates(map[string]interface{}{"flush_count": flush_count}).Error
128 128
 	if err != nil {
129 129
 		db.Rollback()
130 130
 		return err
@@ -181,6 +181,16 @@ func UpdateGoodCount(warehousingCount int64, stock_count int64, out_count int64,
181 181
 	return err
182 182
 }
183 183
 
184
+func UpdateGoodCountSend(warehousingCount int64, stock_count int64, out_count int64, storehouse_id int64, good_id int64, orgid int64, cancel_count int64, act_count int64) error {
185
+
186
+	err := XTWriteDB().Model(&models.XtGoodStockCount{}).Where("storehouse_id = ? and good_id = ? and status =1 and user_org_id = ?", storehouse_id, good_id, orgid).Updates(map[string]interface{}{"stock_in_count": warehousingCount}).Error
187
+	err = XTWriteDB().Model(&models.XtGoodStockCount{}).Where("storehouse_id = ? and good_id = ? and status =1 and user_org_id = ?", storehouse_id, good_id, orgid).Update(map[string]interface{}{"stock_out_count": out_count}).Error
188
+	err = XTWriteDB().Model(&models.XtGoodStockCount{}).Where("storehouse_id = ? and good_id = ? and status =1 and user_org_id = ?", storehouse_id, good_id, orgid).Update(map[string]interface{}{"flush_count": stock_count}).Error
189
+	err = XTWriteDB().Model(&models.XtGoodStockCount{}).Where("storehouse_id = ? and good_id = ? and status =1 and user_org_id = ?", storehouse_id, good_id, orgid).Update(map[string]interface{}{"stock_cancel_count": cancel_count}).Error
190
+	err = XTWriteDB().Model(&models.XtGoodStockCount{}).Where("storehouse_id = ? and good_id = ? and status =1 and user_org_id = ?", storehouse_id, good_id, orgid).Update(map[string]interface{}{"stock_act_out_count": act_count}).Error
191
+	return err
192
+}
193
+
184 194
 func GetAllCancelCount(storehouse_id int64, good_id int64, org_id int64) (flow []*models.VmStockFlow, err error) {
185 195
 
186 196
 	err = XTReadDB().Where("storehouse_id = ? and good_id = ? and user_org_id = ? and (consumable_type = 4 or consumable_type= 7) and status = 1", storehouse_id, good_id, org_id).Find(&flow).Error
@@ -189,7 +199,7 @@ func GetAllCancelCount(storehouse_id int64, good_id int64, org_id int64) (flow [
189 199
 
190 200
 func GetAllStockOutCount(storehouse_id int64, good_id int64, org_id int64) (flow []*models.VmStockFlow, err error) {
191 201
 
192
-	err = XTReadDB().Where("storehouse_id = ? and good_id = ? and user_org_id = ? and (consumable_type = 2 or consumable_type= 3) and is_read = 0", storehouse_id, good_id, org_id).Find(&flow).Error
202
+	err = XTReadDB().Where("storehouse_id = ? and good_id = ? and user_org_id = ? and (consumable_type = 2 or consumable_type= 3)", storehouse_id, good_id, org_id).Find(&flow).Error
193 203
 	return flow, err
194 204
 }
195 205
 
@@ -360,8 +370,147 @@ func UpdateLastAutoCount(id int64, count int64) error {
360 370
 	return err
361 371
 }
362 372
 
363
-func GetWareOutInfo(good_id int64, record_date int64, user_org_id int64) (outinfo []*models.WarehouseOutInfo, err error) {
373
+func GetWareOutInfo(good_id int64, record_date int64, user_org_id int64, patient_id int64) (outinfo []*models.WarehouseOutInfo, err error) {
364 374
 
365
-	err = XTReadDB().Where("good_id = ? and sys_record_time = ? and org_id = ? and status = 1", good_id, record_date, user_org_id).Find(&outinfo).Error
375
+	err = XTReadDB().Where("good_id = ? and sys_record_time = ? and org_id = ? and status = 1 and patient_id = ?", good_id, record_date, user_org_id, patient_id).Find(&outinfo).Error
366 376
 	return outinfo, err
367 377
 }
378
+
379
+func AddGoodStockCount(storehouse_id int64, good_id int64, user_org_id int64, count int64) error {
380
+
381
+	db := writeDb.Begin()
382
+	err = db.Model(&models.XtGoodStockCount{}).Where("user_org_id = ? and storehouse_id  = ? and good_id = ? and status = 1", user_org_id, storehouse_id, good_id).UpdateColumn("stock_in_count", gorm.Expr("stock_in_count + ?", count)).Error
383
+	if err != nil {
384
+		db.Rollback()
385
+		return err
386
+	}
387
+	err = db.Model(&models.XtGoodStockCount{}).Where("user_org_id = ? and storehouse_id = ? and good_id = ? and status = 1", user_org_id, storehouse_id, good_id).UpdateColumn("flush_count", gorm.Expr("flush_count + ?", count)).Error
388
+	if err != nil {
389
+		db.Rollback()
390
+		return err
391
+	}
392
+	db.Commit()
393
+	return err
394
+}
395
+
396
+func AddDrugStockCount(storehouse_id int64, drug_id int64, user_org_id int64, count int64) error {
397
+	db := writeDb.Begin()
398
+	err = db.Model(&models.XtDrugStockCount{}).Where("user_org_id = ? and storehouse_id  = ? and drug_id = ? and status = 1", user_org_id, storehouse_id, drug_id).UpdateColumn("sum_in_count", gorm.Expr("sum_in_count + ?", count)).Error
399
+	if err != nil {
400
+		db.Rollback()
401
+		return err
402
+	}
403
+	err = db.Model(&models.XtDrugStockCount{}).Where("user_org_id = ? and storehouse_id = ? and drug_id = ? and status = 1", user_org_id, storehouse_id, drug_id).UpdateColumn("flush_count", gorm.Expr("flush_count + ?", count)).Error
404
+	if err != nil {
405
+		db.Rollback()
406
+		return err
407
+	}
408
+	db.Commit()
409
+	return err
410
+}
411
+
412
+func ReduceStockCount(storehouse_id int64, good_id int64, user_org_id int64, count int64) error {
413
+
414
+	db := writeDb.Begin()
415
+	//err = db.Model(&models.XtGoodStockCount{}).Where("user_org_id = ? and storehouse_id  = ? and good_id = ? and status = 1", user_org_id, storehouse_id, good_id).UpdateColumn("stock_in_count", gorm.Expr("stock_in_count - ?", count)).Error
416
+	//if err != nil {
417
+	//  db.Rollback()
418
+	//  return err
419
+	//}
420
+
421
+	err = db.Model(&models.XtGoodStockCount{}).Where("user_org_id = ? and storehouse_id  = ? and good_id = ? and status = 1", user_org_id, storehouse_id, good_id).UpdateColumn("stock_out_count", gorm.Expr("stock_out_count + ?", count)).Error
422
+	if err != nil {
423
+		db.Rollback()
424
+		return err
425
+	}
426
+
427
+	err = db.Model(&models.XtGoodStockCount{}).Where("user_org_id = ? and storehouse_id  = ? and good_id = ? and status = 1", user_org_id, storehouse_id, good_id).UpdateColumn("stock_act_out_count", gorm.Expr("stock_act_out_count + ?", count)).Error
428
+	if err != nil {
429
+		db.Rollback()
430
+		return err
431
+	}
432
+	err = db.Model(&models.XtGoodStockCount{}).Where("user_org_id = ? and storehouse_id = ? and good_id = ? and status = 1", user_org_id, storehouse_id, good_id).UpdateColumn("flush_count", gorm.Expr("flush_count - ?", count)).Error
433
+	if err != nil {
434
+		db.Rollback()
435
+		return err
436
+	}
437
+	db.Commit()
438
+	return err
439
+}
440
+
441
+func ReduceStockCountTwo(storehouse_id int64, good_id int64, user_org_id int64, count int64) error {
442
+
443
+	db := writeDb.Begin()
444
+
445
+	err = db.Model(&models.XtGoodStockCount{}).Where("user_org_id = ? and storehouse_id  = ? and good_id = ? and status = 1", user_org_id, storehouse_id, good_id).UpdateColumn("stock_out_count", gorm.Expr("stock_out_count + ?", count)).Error
446
+	if err != nil {
447
+		db.Rollback()
448
+		return err
449
+	}
450
+
451
+	err = db.Model(&models.XtGoodStockCount{}).Where("user_org_id = ? and storehouse_id  = ? and good_id = ? and status = 1", user_org_id, storehouse_id, good_id).UpdateColumn("stock_act_out_count", gorm.Expr("stock_act_out_count + ?", count)).Error
452
+	if err != nil {
453
+		db.Rollback()
454
+		return err
455
+	}
456
+	err = db.Model(&models.XtGoodStockCount{}).Where("user_org_id = ? and storehouse_id = ? and good_id = ? and status = 1", user_org_id, storehouse_id, good_id).UpdateColumn("flush_count", gorm.Expr("flush_count - ?", count)).Error
457
+	if err != nil {
458
+		db.Rollback()
459
+		return err
460
+	}
461
+	db.Commit()
462
+	return err
463
+}
464
+
465
+func ReduceDrugStockCountSix(storehouse_id int64, drug_id int64, user_org_id int64, count int64) error {
466
+
467
+	db := writeDb.Begin()
468
+	//err = db.Model(&models.XtDrugStockCount{}).Where("user_org_id = ? and storehouse_id  = ? and drug_id = ? and status = 1", user_org_id, storehouse_id, drug_id).UpdateColumn("sum_in_count", gorm.Expr("sum_in_count - ?", count)).Error
469
+	//if err != nil {
470
+	//  db.Rollback()
471
+	//  return err
472
+	//}
473
+
474
+	err = db.Model(&models.XtDrugStockCount{}).Where("user_org_id = ? and storehouse_id  = ? and drug_id = ? and status = 1", user_org_id, storehouse_id, drug_id).UpdateColumn("sum_out_count", gorm.Expr("sum_out_count + ?", count)).Error
475
+	if err != nil {
476
+		db.Rollback()
477
+		return err
478
+	}
479
+
480
+	err = db.Model(&models.XtDrugStockCount{}).Where("user_org_id = ? and storehouse_id  = ? and drug_id = ? and status = 1", user_org_id, storehouse_id, drug_id).UpdateColumn("sum_act_out_count", gorm.Expr("sum_act_out_count + ?", count)).Error
481
+	if err != nil {
482
+		db.Rollback()
483
+		return err
484
+	}
485
+	err = db.Model(&models.XtDrugStockCount{}).Where("user_org_id = ? and storehouse_id = ? and drug_id = ? and status = 1", user_org_id, storehouse_id, drug_id).UpdateColumn("flush_count", gorm.Expr("flush_count - ?", count)).Error
486
+	if err != nil {
487
+		db.Rollback()
488
+		return err
489
+	}
490
+	db.Commit()
491
+	return err
492
+}
493
+
494
+func ReduceDrugStockCountSeven(storehouse_id int64, drug_id int64, user_org_id int64, count int64) error {
495
+
496
+	db := writeDb.Begin()
497
+
498
+	err = db.Model(&models.XtDrugStockCount{}).Where("user_org_id = ? and storehouse_id  = ? and drug_id = ? and status = 1", user_org_id, storehouse_id, drug_id).UpdateColumn("sum_out_count", gorm.Expr("sum_out_count + ?", count)).Error
499
+	if err != nil {
500
+		db.Rollback()
501
+		return err
502
+	}
503
+
504
+	err = db.Model(&models.XtDrugStockCount{}).Where("user_org_id = ? and storehouse_id  = ? and drug_id = ? and status = 1", user_org_id, storehouse_id, drug_id).UpdateColumn("sum_act_out_count", gorm.Expr("sum_act_out_count + ?", count)).Error
505
+	if err != nil {
506
+		db.Rollback()
507
+		return err
508
+	}
509
+	err = db.Model(&models.XtDrugStockCount{}).Where("user_org_id = ? and storehouse_id = ? and drug_id = ? and status = 1", user_org_id, storehouse_id, drug_id).UpdateColumn("flush_count", gorm.Expr("flush_count - ?", count)).Error
510
+	if err != nil {
511
+		db.Rollback()
512
+		return err
513
+	}
514
+	db.Commit()
515
+	return err
516
+}

+ 727 - 7
service/new_warehouse_service.go Ver arquivo

@@ -90,7 +90,6 @@ func ConsumablesGoodDelivery(orgID int64, patient_id int64, record_time int64, g
90 90
 			warehouseOutInfo.Price = goodsInfo.PackingPrice
91 91
 		}
92 92
 		_, errcodes := GetWarehouseOutInfoIsExistOne(goods.GoodId, patient_id, record_time, goods.ProjectId)
93
-		//fmt.Println("errcodes2333232233232wode3223", errcodes, goods.ProjectId)
94 93
 		if errcodes == gorm.ErrRecordNotFound {
95 94
 			errOne := AddSigleWarehouseOutInfo(warehouseOutInfo)
96 95
 			if errOne != nil {
@@ -99,8 +98,6 @@ func ConsumablesGoodDelivery(orgID int64, patient_id int64, record_time int64, g
99 98
 		} else if errcodes == nil {
100 99
 
101 100
 			outInfoOne, _ := GetWarehouseOutInfoIsExistTwo(goods.GoodId, patient_id, record_time, goods.ProjectId)
102
-			//fmt.Println("goods.cout23323233223232323w", count)
103
-			//fmt.Println("outInfoOnewowowwowowowowowo", outInfoOne.Count)
104 101
 			if count != outInfoOne.Count {
105 102
 				UpdatedWarehouseOutInfo(warehouseOutInfo, goods.GoodId, patient_id, record_time, goods.ProjectId)
106 103
 			}
@@ -121,10 +118,6 @@ func ConsumablesGoodDelivery(orgID int64, patient_id int64, record_time int64, g
121 118
 		for _, item := range flowGoodTwo {
122 119
 			out_count_one += item.Count
123 120
 		}
124
-		//fmt.Println("deliver_number", deliver_number)
125
-		//fmt.Println("out_count", out_count)
126
-		//fmt.Println("count", count)
127
-		//fmt.Println("cancel_out_count2333233", out_count_one)
128 121
 		//如果本次出库数据大于历史出库数据 新增1条流水
129 122
 		if count > (out_count - out_count_one) {
130 123
 
@@ -553,6 +546,13 @@ func FindWarehouseOutInfoByPatientId(patient_id int64, record_time int64, good_i
553 546
 	return outInfo, err
554 547
 }
555 548
 
549
+func FindWarehouseOutInfoByPatientIdTwo(patient_id int64, record_time int64, good_id int64, org_id int64, project_id int64) (models.WarehouseOutInfo, error) {
550
+
551
+	outInfo := models.WarehouseOutInfo{}
552
+	err := XTReadDB().Where("patient_id = ? and sys_record_time = ? and good_id = ? and org_id = ? and status = 1 and project_id = ?", patient_id, record_time, good_id, org_id, project_id).Last(&outInfo).Error
553
+	return outInfo, err
554
+}
555
+
556 556
 func UpdateDrugStockCount(drug_id int64, org_id int64, storehouse_id int64, flush_count int64) error {
557 557
 
558 558
 	drug := models.XtDrugStockCount{}
@@ -2120,3 +2120,723 @@ func UpdateHisPrescriptionProjectStatus(project_id int64, record_time int64, use
2120 2120
 	err := XTWriteDB().Model(&project).Where("project_id  = ? and record_date = ? and user_org_id = ? and patient_id = ? and status = 1", project_id, record_time, user_org_id, patient_id).Update(map[string]interface{}{"is_out": 1}).Error
2121 2121
 	return project, err
2122 2122
 }
2123
+
2124
+// 药品自动出库 递归方式
2125
+func HisSettleDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *models.DrugWarehouseOut, drup *models.BaseDrugLib, advice *models.HisDoctorAdviceInfo) (err error) {
2126
+
2127
+	// 判断处方里药品单位是拆零单位还是包装单位,	如果是包装单位,则根据规格,将包装数量转为拆零数量
2128
+	var deliver_number int64 = 0
2129
+	var stock_number int64 = 0
2130
+
2131
+	prescribingNumber_temp := strconv.FormatFloat(math.Abs(prescribingNumber), 'f', 0, 64)
2132
+	count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
2133
+
2134
+	var drug_price float64
2135
+	if advice.PrescribingNumberUnit == drup.MaxUnit {
2136
+		deliver_number = count * drup.MinNumber
2137
+
2138
+	} else {
2139
+		deliver_number = count
2140
+
2141
+	}
2142
+
2143
+	if advice.PrescribingNumberUnit == drup.MaxUnit {
2144
+		drug_price = drup.RetailPrice
2145
+	}
2146
+	fmt.Println(drug_price)
2147
+
2148
+	if advice.PrescribingNumberUnit == drup.MinUnit {
2149
+		drug_price = drup.MinPrice
2150
+	}
2151
+
2152
+	if advice.PrescribingNumberUnit != drup.MaxUnit || advice.PrescribingNumberUnit != drup.MinUnit {
2153
+		drug_price = drup.RetailPrice
2154
+	}
2155
+
2156
+	// 根据先进先出原则,查询最先入库的批次,进行出库
2157
+	// 如果没有对应的库存,则报错
2158
+	storeConfig, _ := GetAllStoreHouseConfig(advice.UserOrgId)
2159
+	lastWarehouse, _ := FindLastDrugWarehousingInfoByID(advice.DrugId, storeConfig.DrugStorehouseOut)
2160
+	if lastWarehouse.StockMinNumber >= drup.MinNumber {
2161
+		var stockMax int64
2162
+		var stockMin int64
2163
+		stockMax = lastWarehouse.StockMinNumber / drup.MinNumber
2164
+		stockMin = lastWarehouse.StockMinNumber % drup.MinNumber
2165
+
2166
+		ChangeMaxNumber(lastWarehouse.ID, stockMax)
2167
+		UpdateMinNumber(lastWarehouse.ID, stockMin)
2168
+	}
2169
+	warehouse, err := FindLastDrugWarehousingInfoByID(advice.DrugId, storeConfig.DrugStorehouseOut)
2170
+
2171
+	if err != nil {
2172
+
2173
+		return err
2174
+	}
2175
+	// 将该批次的剩余库存数量转换为拆零数量
2176
+	// 将该批次的剩余库存数量转换为拆零数量
2177
+	if warehouse.MaxUnit == drup.MaxUnit && drup.MaxUnit != drup.MinUnit {
2178
+
2179
+		stock_number = warehouse.StockMaxNumber*drup.MinNumber + warehouse.StockMinNumber
2180
+
2181
+	}
2182
+	if warehouse.MaxUnit == drup.MinUnit && drup.MaxUnit != drup.MinUnit {
2183
+
2184
+		stock_number = warehouse.StockMaxNumber + warehouse.StockMinNumber
2185
+
2186
+	}
2187
+	if warehouse.MaxUnit == drup.MaxUnit && drup.MaxUnit == drup.MinUnit {
2188
+
2189
+		stock_number = warehouse.StockMaxNumber*drup.MinNumber + warehouse.StockMinNumber
2190
+
2191
+	}
2192
+
2193
+	// 当库存数量大于或等于出库数量的话,则正常出库该批次
2194
+	if stock_number >= deliver_number {
2195
+
2196
+		var maxNumber int64 = 0
2197
+		var minNumber int64 = 0
2198
+
2199
+		maxNumber = deliver_number / drup.MinNumber
2200
+		minNumber = deliver_number % drup.MinNumber
2201
+
2202
+		if warehouse.StockMaxNumber == 0 && drup.MaxUnit == drup.MinUnit {
2203
+			minNumber = maxNumber
2204
+		}
2205
+
2206
+		if drup.MaxUnit != drup.MinUnit {
2207
+			if warehouse.StockMaxNumber < maxNumber && warehouse.StockMinNumber < minNumber {
2208
+				return errors.New("库存数量不足")
2209
+			}
2210
+		}
2211
+
2212
+		if drup.MinUnit == warehouse.MaxUnit && drup.MaxUnit != drup.MinUnit {
2213
+			warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber*drup.MinNumber
2214
+		}
2215
+		if drup.MaxUnit == warehouse.MaxUnit && drup.MaxUnit != drup.MinUnit {
2216
+			warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
2217
+		}
2218
+		if drup.MaxUnit == warehouse.MaxUnit && drup.MaxUnit == drup.MinUnit {
2219
+			warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
2220
+		}
2221
+
2222
+		if warehouse.StockMaxNumber < 0 {
2223
+			warehouse.StockMaxNumber = 0
2224
+		}
2225
+		if warehouse.StockMinNumber < 0 {
2226
+			warehouse.StockMinNumber = 0
2227
+		}
2228
+
2229
+		warehouse.Mtime = time.Now().Unix()
2230
+
2231
+		fmt.Println("minnU目标而332322323323233223323223我", minNumber)
2232
+		fmt.Println("max_number232232332232322wo", maxNumber)
2233
+		fmt.Println(" warehouse.StockMinNumber", warehouse.StockMinNumber)
2234
+
2235
+		if warehouse.StockMinNumber < minNumber {
2236
+
2237
+			warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
2238
+			if warehouse.MaxUnit != warehouse.MinUnit {
2239
+				warehouse.StockMinNumber = warehouse.StockMinNumber + drup.MinNumber - minNumber
2240
+			}
2241
+		} else {
2242
+			if minNumber > 0 {
2243
+				if (warehouse.StockMinNumber - minNumber) >= 0 {
2244
+					warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
2245
+				}
2246
+
2247
+			}
2248
+
2249
+			if minNumber == 0 && maxNumber != 1 && warehouse.StockMaxNumber <= 0 {
2250
+				if warehouse.StockMinNumber > 0 {
2251
+					if warehouse.StockMinNumber-deliver_number >= 0 {
2252
+						warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
2253
+					}
2254
+
2255
+				}
2256
+
2257
+			}
2258
+
2259
+		}
2260
+
2261
+		if maxNumber == 1 && minNumber == 0 && drup.MaxUnit != drup.MinUnit {
2262
+			if (warehouse.StockMinNumber - deliver_number) >= 0 {
2263
+				warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
2264
+			}
2265
+
2266
+		}
2267
+
2268
+		if drup.MaxUnit != drup.MinUnit {
2269
+			if warehouse.StockMaxNumber < 0 && warehouse.StockMinNumber < 0 {
2270
+				return errors.New("库存数量不足")
2271
+			}
2272
+		}
2273
+		if warehouse.StockMinNumber <= 0 {
2274
+			warehouse.StockMinNumber = 0
2275
+		}
2276
+
2277
+		//扣减库存数据
2278
+		errThree := UpDateDrugWarehouseInfoByStock(&warehouse)
2279
+		if errThree != nil {
2280
+			return errThree
2281
+		}
2282
+
2283
+		//查询剩余库存
2284
+		stockInfo, _ := GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, orgID, advice.DrugId)
2285
+		var sum_count int64
2286
+		for _, its := range stockInfo {
2287
+			if its.MaxUnit == drup.MaxUnit {
2288
+				its.StockMaxNumber = its.StockMaxNumber * drup.MinNumber
2289
+			}
2290
+			sum_count += its.StockMaxNumber + its.StockMinNumber
2291
+		}
2292
+
2293
+		warehouseOutInfo := &models.DrugWarehouseOutInfo{
2294
+			WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
2295
+			WarehouseOutId:          warehouseout.ID,
2296
+			Status:                  1,
2297
+			Ctime:                   time.Now().Unix(),
2298
+			Remark:                  warehouse.Remark,
2299
+			OrgId:                   orgID,
2300
+			Type:                    5,
2301
+			Manufacturer:            warehouse.Manufacturer,
2302
+			Dealer:                  warehouse.Dealer,
2303
+			IsSys:                   1,
2304
+			SysRecordTime:           advice.RecordDate,
2305
+			DrugId:                  advice.DrugId,
2306
+			Number:                  warehouse.Number,
2307
+			BatchNumber:             warehouse.BatchNumber,
2308
+			Price:                   warehouse.RetailPrice,
2309
+			CountUnit:               drup.MinUnit,
2310
+			RetailPrice:             warehouse.RetailPrice,
2311
+			ProductDate:             warehouse.ProductDate,
2312
+			ExpiryDate:              warehouse.ExpiryDate,
2313
+			PatientId:               advice.PatientId,
2314
+			Count:                   deliver_number, //出最小单位
2315
+			WarehouseInfoId:         warehouse.ID,
2316
+			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
2317
+			StorehouseId:            storeConfig.DrugStorehouseOut,
2318
+			IsCheck:                 1,
2319
+			OverCount:               sum_count,
2320
+			AdviceId:                advice.ID,
2321
+			OrderId:                 warehouseout.OrderId,
2322
+		}
2323
+
2324
+		//查询今日该药品该患者是否有出库数据
2325
+		lastDrugOutInfo, _ := GetNewDrugWarehouseOutInfoSix(advice.DrugId, advice.PatientId, advice.RecordDate, advice.UserOrgId, advice.ID, warehouse.ID)
2326
+
2327
+		if lastDrugOutInfo.ID == 0 {
2328
+			errOne := AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
2329
+			if errOne != nil {
2330
+				return errOne
2331
+			}
2332
+		}
2333
+		if lastDrugOutInfo.ID > 0 {
2334
+			var his_count int64
2335
+			if lastDrugOutInfo.CountUnit == drup.MaxUnit {
2336
+				his_count = lastDrugOutInfo.Count * drup.MinNumber
2337
+			}
2338
+			if lastDrugOutInfo.CountUnit == drup.MinUnit {
2339
+				his_count = lastDrugOutInfo.Count
2340
+			}
2341
+			if deliver_number != his_count {
2342
+				errThree := UpdateSigleDrugWarehouseOutInfo(lastDrugOutInfo.ID, warehouseOutInfo)
2343
+				if errThree != nil {
2344
+					return errThree
2345
+				}
2346
+			}
2347
+		}
2348
+
2349
+		var out_count int64
2350
+		var cancel_count int64
2351
+		//查询出库数据
2352
+		infoCountList, _ := FindDrugWarehouseOutInfoCount(advice.DrugId, advice.PatientId, advice.RecordDate, advice.UserOrgId, advice.ID)
2353
+		//查询退库数据
2354
+		cancelInfoList, _ := FindDrugCancelOutInfo(advice.DrugId, advice.PatientId, advice.RecordDate, advice.UserOrgId, advice.ID)
2355
+		for _, item := range infoCountList {
2356
+			out_count += item.Count
2357
+		}
2358
+
2359
+		for _, item := range cancelInfoList {
2360
+			cancel_count += item.Count
2361
+		}
2362
+
2363
+		fmt.Println("deliver_number", deliver_number)
2364
+		fmt.Println("out_count", out_count)
2365
+		fmt.Println("cancel_count", cancel_count)
2366
+		//如果本次出库数据大于历史出库数据 新增1条流水
2367
+		if deliver_number > (out_count - cancel_count) {
2368
+			drugflow := models.DrugFlow{
2369
+				WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
2370
+				WarehouseOutId:          warehouseout.ID,
2371
+				DrugId:                  advice.DrugId,
2372
+				Number:                  warehouse.Number,
2373
+				ProductDate:             warehouse.ProductDate,
2374
+				ExpireDate:              warehouse.ExpiryDate,
2375
+				Count:                   deliver_number - (out_count - cancel_count), //按最小单位计算,
2376
+				Price:                   warehouse.RetailPrice,
2377
+				Status:                  1,
2378
+				Ctime:                   time.Now().Unix(),
2379
+				UserOrgId:               orgID,
2380
+				Manufacturer:            warehouse.Manufacturer,
2381
+				Dealer:                  warehouse.Dealer,
2382
+				BatchNumber:             warehouse.BatchNumber,
2383
+				MaxUnit:                 drup.MinUnit,
2384
+				ConsumableType:          15,
2385
+				IsEdit:                  1,
2386
+				Creator:                 advice.ExecutionStaff,
2387
+				IsSys:                   1,
2388
+				PatientId:               advice.PatientId,
2389
+				SystemTime:              advice.AdviceDate,
2390
+				WarehousingDetailId:     warehouse.ID,
2391
+				SupplyWarehouseId:       warehouse.SupplyWarehouseId,
2392
+				StorehouseId:            storeConfig.DrugStorehouseOut,
2393
+				WarehouseOutDetailId:    lastDrugOutInfo.ID,
2394
+				OverCount:               sum_count,
2395
+				AdviceId:                advice.ID,
2396
+				LastPrice:               warehouse.Price,
2397
+				OrderId:                 warehouseout.OrderId,
2398
+			}
2399
+
2400
+			CreateDrugFlowOne(drugflow)
2401
+			//出库数量相加
2402
+			AddDrugCount(advice.DrugId, orgID, storeConfig.DrugStorehouseOut, drugflow.Count)
2403
+
2404
+		}
2405
+
2406
+		//如果本次出库数据小于历史出库数据 新增1条退库流水
2407
+		if deliver_number < (out_count - cancel_count) {
2408
+
2409
+			operation_time := time.Now().Unix()
2410
+
2411
+			ctime := time.Now().Unix()
2412
+			timeStr := time.Now().Format("2006-01-02")
2413
+			timeArr := strings.Split(timeStr, "-")
2414
+			total, _ := FindAllDrugCancelStockTotal(advice.UserOrgId)
2415
+			total = total + 1
2416
+			orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
2417
+			cancelStock := models.DrugCancelStock{
2418
+				OrderNumber:  orderNumber,
2419
+				OperaTime:    operation_time,
2420
+				OrgId:        advice.UserOrgId,
2421
+				Creater:      advice.ExecutionStaff,
2422
+				Ctime:        ctime,
2423
+				Status:       1,
2424
+				ReturnTime:   advice.AdviceDate,
2425
+				Dealer:       0,
2426
+				Manufacturer: 0,
2427
+				Type:         5,
2428
+				StorehouseId: storeConfig.DrugStorehouseOut,
2429
+				IsCheck:      1,
2430
+				OrderId:      warehouseout.OrderId,
2431
+			}
2432
+
2433
+			_, errCode := FindDrugCancelStock(advice.AdviceDate, advice.UserOrgId)
2434
+			if errCode == gorm.ErrRecordNotFound {
2435
+				AddSigleDrugCancelStock(&cancelStock)
2436
+			}
2437
+			lastDrugCancelStock, _ := FindLastDrugCancelStock(advice.AdviceDate, advice.UserOrgId)
2438
+
2439
+			manufactureName, _ := GetManufactureById(warehouse.Manufacturer)
2440
+			dealer, _ := GetDealerById(warehouse.Dealer)
2441
+			cancelInfo, _ := GetLastDrugCancelStockById(advice.UserOrgId)
2442
+			cancelStockInfo := models.DrugCancelStockInfo{
2443
+				OrderNumber:      cancelInfo.OrderNumber,
2444
+				CancelStockId:    lastDrugCancelStock.ID,
2445
+				DrugId:           advice.DrugId,
2446
+				Count:            (out_count - cancel_count) - deliver_number,
2447
+				Status:           1,
2448
+				Ctime:            ctime,
2449
+				OrgId:            advice.UserOrgId,
2450
+				Type:             5,
2451
+				Manufacturer:     manufactureName.ManufacturerName,
2452
+				Dealer:           dealer.DealerName,
2453
+				Total:            0,
2454
+				RetailPrice:      warehouse.RetailPrice,
2455
+				RetailTotalPrice: warehouse.RetailTotalPrice,
2456
+				Price:            warehouse.Price,
2457
+				RegisterAccount:  "",
2458
+				Remark:           warehouse.Remark,
2459
+				BatchNumber:      warehouse.BatchNumber,
2460
+				MaxUnit:          drup.MinUnit,
2461
+				ProductDate:      warehouse.ProductDate,
2462
+				ExpiryDate:       warehouse.ExpiryDate,
2463
+				BatchNumberId:    warehouse.ID,
2464
+				StorehouseId:     storeConfig.DrugStorehouseOut,
2465
+				IsCheck:          1,
2466
+				OrderId:          warehouseout.OrderId,
2467
+			}
2468
+			CreatedCancelStock(cancelStockInfo)
2469
+			flow := models.DrugFlow{
2470
+				WarehousingId:           warehouse.ID,
2471
+				DrugId:                  warehouse.DrugId,
2472
+				Number:                  "",
2473
+				BatchNumber:             warehouse.BatchNumber,
2474
+				Count:                   out_count - cancel_count - deliver_number,
2475
+				UserOrgId:               advice.UserOrgId,
2476
+				PatientId:               advice.PatientId,
2477
+				SystemTime:              advice.AdviceDate,
2478
+				ConsumableType:          16,
2479
+				IsSys:                   0,
2480
+				WarehousingOrder:        "",
2481
+				WarehouseOutId:          0,
2482
+				WarehouseOutOrderNumber: "",
2483
+				IsEdit:                  0,
2484
+				CancelStockId:           cancelStock.ID,
2485
+				CancelOrderNumber:       cancelStock.OrderNumber,
2486
+				Manufacturer:            warehouse.Manufacturer,
2487
+				Dealer:                  warehouse.Dealer,
2488
+				Creator:                 advice.ExecutionStaff,
2489
+				UpdateCreator:           0,
2490
+				Status:                  1,
2491
+				Ctime:                   time.Now().Unix(),
2492
+				Mtime:                   0,
2493
+				Price:                   warehouse.RetailPrice,
2494
+				WarehousingDetailId:     warehouse.ID,
2495
+				WarehouseOutDetailId:    0,
2496
+				CancelOutDetailId:       lastDrugCancelStock.ID,
2497
+				ExpireDate:              warehouse.ExpiryDate,
2498
+				ProductDate:             warehouse.ProductDate,
2499
+				MaxUnit:                 drup.MinUnit,
2500
+				MinUnit:                 "",
2501
+				AdviceId:                advice.ID,
2502
+				StorehouseId:            storeConfig.DrugStorehouseOut,
2503
+				LastPrice:               warehouse.Price,
2504
+				OverCount:               sum_count,
2505
+				OrderId:                 warehouseout.OrderId,
2506
+			}
2507
+			CreateDrugFlowOne(flow)
2508
+			AddCancelSumCountOne(storeConfig.DrugStorehouseOut, advice.DrugId, advice.UserOrgId, flow.Count)
2509
+			ReduceDrugCountTwo(advice.DrugId, orgID, storeConfig.DrugStorehouseOut, flow.Count)
2510
+		}
2511
+
2512
+		//查询是否存在数据
2513
+		details := &models.DrugAutomaticReduceDetail{
2514
+			WarehouseOutId:          warehouseout.ID,
2515
+			WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
2516
+			PatientId:               advice.PatientId,
2517
+			Ctime:                   time.Now().Unix(),
2518
+			Mtime:                   time.Now().Unix(),
2519
+			Status:                  1,
2520
+			RecordTime:              advice.RecordDate,
2521
+			OrgId:                   orgID,
2522
+			DrugId:                  advice.DrugId,
2523
+			Count:                   deliver_number,
2524
+			CountUnit:               drup.MinUnit,
2525
+			WarehouseInfoId:         warehouse.ID,
2526
+			StorehouseId:            storeConfig.DrugStorehouseOut,
2527
+			AdviceId:                advice.ID,
2528
+		}
2529
+		errTwo := AddSigleDrugAutoReduceRecordInfo(details)
2530
+		if errTwo != nil {
2531
+			return errTwo
2532
+		}
2533
+		return nil
2534
+
2535
+	} else {
2536
+
2537
+		info := models.XtDrugWarehouseInfo{
2538
+			ID:                warehouse.ID,
2539
+			WarehousingId:     warehouse.WarehousingId,
2540
+			DrugId:            warehouse.DrugId,
2541
+			Number:            warehouse.Number,
2542
+			ProductDate:       warehouse.ProductDate,
2543
+			ExpiryDate:        warehouse.ExpiryDate,
2544
+			WarehousingCount:  warehouse.WarehousingCount,
2545
+			Price:             warehouse.RetailPrice,
2546
+			TotalPrice:        warehouse.TotalPrice,
2547
+			Dealer:            warehouse.Dealer,
2548
+			Manufacturer:      warehouse.Manufacturer,
2549
+			Remark:            warehouse.Remark,
2550
+			Ctime:             warehouse.Ctime,
2551
+			Mtime:             warehouse.Mtime,
2552
+			Status:            1,
2553
+			OrgId:             warehouse.OrgId,
2554
+			IsReturn:          warehouse.IsReturn,
2555
+			WarehousingOrder:  warehouse.WarehousingOrder,
2556
+			Type:              warehouse.Type,
2557
+			RetailPrice:       warehouse.RetailPrice,
2558
+			RetailTotalPrice:  warehouse.RetailPrice,
2559
+			StockMaxNumber:    0,
2560
+			StockMinNumber:    0,
2561
+			BatchNumber:       warehouse.BatchNumber,
2562
+			MaxUnit:           warehouse.MaxUnit,
2563
+			WarehousingInfoId: warehouse.WarehousingInfoId,
2564
+			SupplyWarehouseId: warehouse.SupplyWarehouseId,
2565
+			StorehouseId:      storeConfig.DrugStorehouseOut,
2566
+			IsCheck:           1,
2567
+		}
2568
+		//扣减库存
2569
+		errThree := UpDateDrugWarehouseInfoByStock(&info)
2570
+
2571
+		if errThree != nil {
2572
+			return errThree
2573
+		}
2574
+		//查询剩余库存
2575
+		stockInfo, _ := GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, orgID, advice.DrugId)
2576
+		var sum_count int64
2577
+		for _, its := range stockInfo {
2578
+			if its.MaxUnit == drup.MaxUnit {
2579
+				its.StockMaxNumber = its.StockMaxNumber * drup.MinNumber
2580
+			}
2581
+			sum_count += its.StockMaxNumber + its.StockMinNumber
2582
+		}
2583
+
2584
+		// 当该批次的库存数量小于出库数量的话,则先把该批次出库完后,再进行递归出库
2585
+		warehouseOutInfo := &models.DrugWarehouseOutInfo{
2586
+			WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
2587
+			WarehouseOutId:          warehouseout.ID,
2588
+			Status:                  1,
2589
+			Ctime:                   time.Now().Unix(),
2590
+			Remark:                  warehouse.Remark,
2591
+			OrgId:                   orgID,
2592
+			Type:                    5,
2593
+			Manufacturer:            warehouse.Manufacturer,
2594
+			Dealer:                  warehouse.Dealer,
2595
+			IsSys:                   1,
2596
+			SysRecordTime:           advice.RecordDate,
2597
+			DrugId:                  advice.DrugId,
2598
+			Number:                  warehouse.Number,
2599
+			BatchNumber:             warehouse.BatchNumber,
2600
+			Price:                   warehouse.RetailPrice,
2601
+			CountUnit:               drup.MinUnit,
2602
+			ProductDate:             warehouse.ProductDate,
2603
+			ExpiryDate:              warehouse.ExpiryDate,
2604
+			PatientId:               advice.PatientId,
2605
+			Count:                   stock_number,
2606
+			WarehouseInfoId:         warehouse.ID,
2607
+			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
2608
+			StorehouseId:            storeConfig.DrugStorehouseOut,
2609
+			IsCheck:                 1,
2610
+			OverCount:               sum_count,
2611
+			AdviceId:                advice.ID,
2612
+			OrderId:                 warehouseout.OrderId,
2613
+		}
2614
+		//查询是否存在出库数据
2615
+		_, errCode := GetSigleDrugWarehouseOutInfo(advice.PatientId, advice.AdviceDate, orgID)
2616
+		if errCode == gorm.ErrRecordNotFound {
2617
+
2618
+			errOne := AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
2619
+			if errOne != nil {
2620
+				return errOne
2621
+			}
2622
+		}
2623
+		if errCode == nil {
2624
+
2625
+			lastDrugOutInfo, _ := GetSigleDrugWarehouseOutInfoOne(advice.PatientId, advice.AdviceDate, orgID)
2626
+			var his_count int64
2627
+			if lastDrugOutInfo.CountUnit == drup.MaxUnit {
2628
+				his_count = lastDrugOutInfo.Count * drup.MinNumber
2629
+			}
2630
+			if lastDrugOutInfo.CountUnit == drup.MinUnit {
2631
+				his_count = lastDrugOutInfo.Count
2632
+			}
2633
+			if deliver_number != his_count {
2634
+				errThree := UpdateSingleDrugWarehouseOutInfoSix(advice.PatientId, advice.AdviceDate, orgID, warehouseOutInfo, advice.ID)
2635
+				if errThree != nil {
2636
+					return errThree
2637
+				}
2638
+			}
2639
+		}
2640
+
2641
+		lastDrugOutInfo, _ := FindLastDrugWarehouseOutInfo(orgID)
2642
+		details := &models.DrugAutomaticReduceDetail{
2643
+			WarehouseOutId:          warehouseout.ID,
2644
+			WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
2645
+			PatientId:               advice.PatientId,
2646
+			Ctime:                   time.Now().Unix(),
2647
+			Mtime:                   time.Now().Unix(),
2648
+			Status:                  1,
2649
+			RecordTime:              advice.RecordDate,
2650
+			OrgId:                   orgID,
2651
+			DrugId:                  advice.DrugId,
2652
+			Count:                   stock_number,
2653
+			CountUnit:               drup.MinUnit,
2654
+			WarehouseInfoId:         warehouse.ID,
2655
+			StorehouseId:            storeConfig.DrugStorehouseOut,
2656
+			AdviceId:                advice.ID,
2657
+		}
2658
+
2659
+		_, errcodeThree := FindDrugAutoReduceRecordInfo(advice.PatientId, advice.RecordDate, advice.DrugId)
2660
+		if errcodeThree == gorm.ErrRecordNotFound {
2661
+			errTwo := AddSigleDrugAutoReduceRecordInfo(details)
2662
+			if errTwo != nil {
2663
+				return errTwo
2664
+			}
2665
+		}
2666
+		if errcodeThree == nil {
2667
+			UpdateDrugAutoReduceRecordInfo(advice.PatientId, advice.RecordDate, advice.DrugId, details)
2668
+		}
2669
+
2670
+		var out_count int64
2671
+		var cancel_count int64
2672
+		//查询出库数据
2673
+		infoCountList, _ := FindDrugWarehouseOutInfoCount(advice.DrugId, advice.PatientId, advice.RecordDate, advice.UserOrgId, advice.ID)
2674
+		//查询退库数据
2675
+		cancelInfoList, _ := FindDrugCancelOutInfo(advice.DrugId, advice.PatientId, advice.RecordDate, advice.UserOrgId, advice.ID)
2676
+		for _, item := range infoCountList {
2677
+			out_count += item.Count
2678
+		}
2679
+
2680
+		for _, item := range cancelInfoList {
2681
+			cancel_count += item.Count
2682
+		}
2683
+
2684
+		//如果本次出库数据大于历史出库数据 新增1条流水
2685
+		if deliver_number > (out_count - cancel_count) {
2686
+
2687
+			drugflow := models.DrugFlow{
2688
+				WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
2689
+				WarehouseOutId:          warehouseout.ID,
2690
+				DrugId:                  advice.DrugId,
2691
+				Number:                  warehouse.Number,
2692
+				ProductDate:             warehouse.ProductDate,
2693
+				ExpireDate:              warehouse.ExpiryDate,
2694
+				Count:                   stock_number,
2695
+				Price:                   warehouse.RetailPrice,
2696
+				Status:                  1,
2697
+				Ctime:                   time.Now().Unix(),
2698
+				UserOrgId:               orgID,
2699
+				Manufacturer:            warehouse.Manufacturer,
2700
+				Dealer:                  warehouse.Dealer,
2701
+				BatchNumber:             warehouse.BatchNumber,
2702
+				MaxUnit:                 drup.MinUnit,
2703
+				ConsumableType:          15,
2704
+				IsEdit:                  1,
2705
+				Creator:                 advice.ExecutionStaff,
2706
+				IsSys:                   1,
2707
+				PatientId:               advice.PatientId,
2708
+				WarehousingDetailId:     warehouse.ID,
2709
+				SupplyWarehouseId:       warehouse.SupplyWarehouseId,
2710
+				StorehouseId:            storeConfig.DrugStorehouseOut,
2711
+				WarehouseOutDetailId:    lastDrugOutInfo.ID,
2712
+				OverCount:               sum_count,
2713
+				AdviceId:                advice.ID,
2714
+				LastPrice:               warehouse.Price,
2715
+				SystemTime:              advice.AdviceDate,
2716
+				OrderId:                 warehouseout.OrderId,
2717
+			}
2718
+
2719
+			CreateDrugFlowOne(drugflow)
2720
+			//出库数量相加
2721
+			AddDrugCount(advice.DrugId, orgID, storeConfig.DrugStorehouseOut, drugflow.Count)
2722
+		}
2723
+
2724
+		if deliver_number < (out_count - cancel_count) {
2725
+			operation_time := time.Now().Unix()
2726
+
2727
+			ctime := time.Now().Unix()
2728
+			timeStr := time.Now().Format("2006-01-02")
2729
+			timeArr := strings.Split(timeStr, "-")
2730
+			total, _ := FindAllDrugCancelStockTotal(advice.UserOrgId)
2731
+			total = total + 1
2732
+			orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
2733
+			cancelStock := models.DrugCancelStock{
2734
+				OrderNumber:  orderNumber,
2735
+				OperaTime:    operation_time,
2736
+				OrgId:        advice.UserOrgId,
2737
+				Creater:      advice.ExecutionStaff,
2738
+				Ctime:        ctime,
2739
+				Status:       1,
2740
+				ReturnTime:   advice.AdviceDate,
2741
+				Dealer:       0,
2742
+				Manufacturer: 0,
2743
+				Type:         5,
2744
+				StorehouseId: storeConfig.DrugStorehouseOut,
2745
+				IsCheck:      1,
2746
+				OrderId:      warehouseout.OrderId,
2747
+			}
2748
+
2749
+			_, errCode := FindDrugCancelStock(advice.AdviceDate, advice.UserOrgId)
2750
+			if errCode == gorm.ErrRecordNotFound {
2751
+				AddSigleDrugCancelStock(&cancelStock)
2752
+			}
2753
+			lastDrugCancelStock, _ := FindLastDrugCancelStock(advice.AdviceDate, advice.UserOrgId)
2754
+
2755
+			manufactureName, _ := GetManufactureById(warehouse.Manufacturer)
2756
+			dealer, _ := GetDealerById(warehouse.Dealer)
2757
+			cancelInfo, _ := GetLastDrugCancelStockById(advice.UserOrgId)
2758
+			cancelStockInfo := models.DrugCancelStockInfo{
2759
+				OrderNumber:      cancelInfo.OrderNumber,
2760
+				CancelStockId:    lastDrugCancelStock.ID,
2761
+				DrugId:           advice.DrugId,
2762
+				Count:            (out_count - cancel_count) - deliver_number,
2763
+				Status:           1,
2764
+				Ctime:            ctime,
2765
+				OrgId:            advice.UserOrgId,
2766
+				Type:             5,
2767
+				Manufacturer:     manufactureName.ManufacturerName,
2768
+				Dealer:           dealer.DealerName,
2769
+				Total:            0,
2770
+				RetailPrice:      warehouse.RetailPrice,
2771
+				RetailTotalPrice: warehouse.RetailTotalPrice,
2772
+				Price:            warehouse.Price,
2773
+				RegisterAccount:  "",
2774
+				Remark:           warehouse.Remark,
2775
+				BatchNumber:      warehouse.BatchNumber,
2776
+				MaxUnit:          drup.MinUnit,
2777
+				ProductDate:      warehouse.ProductDate,
2778
+				ExpiryDate:       warehouse.ExpiryDate,
2779
+				BatchNumberId:    warehouse.ID,
2780
+				StorehouseId:     storeConfig.DrugStorehouseOut,
2781
+				IsCheck:          1,
2782
+				OrderId:          warehouseout.OrderId,
2783
+			}
2784
+			CreatedCancelStock(cancelStockInfo)
2785
+			flow := models.DrugFlow{
2786
+				WarehousingId:           warehouse.ID,
2787
+				DrugId:                  warehouse.DrugId,
2788
+				Number:                  "",
2789
+				BatchNumber:             warehouse.BatchNumber,
2790
+				Count:                   out_count - cancel_count - deliver_number,
2791
+				UserOrgId:               advice.UserOrgId,
2792
+				PatientId:               advice.PatientId,
2793
+				SystemTime:              advice.AdviceDate,
2794
+				ConsumableType:          16,
2795
+				IsSys:                   0,
2796
+				WarehousingOrder:        "",
2797
+				WarehouseOutId:          0,
2798
+				WarehouseOutOrderNumber: "",
2799
+				IsEdit:                  0,
2800
+				CancelStockId:           cancelStock.ID,
2801
+				CancelOrderNumber:       cancelStock.OrderNumber,
2802
+				Manufacturer:            warehouse.Manufacturer,
2803
+				Dealer:                  warehouse.Dealer,
2804
+				Creator:                 advice.ExecutionStaff,
2805
+				UpdateCreator:           0,
2806
+				Status:                  1,
2807
+				Ctime:                   time.Now().Unix(),
2808
+				Mtime:                   0,
2809
+				Price:                   warehouse.RetailPrice,
2810
+				WarehousingDetailId:     warehouse.ID,
2811
+				WarehouseOutDetailId:    0,
2812
+				CancelOutDetailId:       lastDrugCancelStock.ID,
2813
+				ExpireDate:              warehouse.ExpiryDate,
2814
+				ProductDate:             warehouse.ProductDate,
2815
+				MaxUnit:                 drup.MinUnit,
2816
+				MinUnit:                 "",
2817
+				AdviceId:                advice.ID,
2818
+				StorehouseId:            storeConfig.DrugStorehouseOut,
2819
+				LastPrice:               warehouse.Price,
2820
+				OverCount:               sum_count,
2821
+				OrderId:                 warehouseout.OrderId,
2822
+			}
2823
+			CreateDrugFlowOne(flow)
2824
+
2825
+			//退库数量增加
2826
+			AddCancelSumCountOne(storeConfig.DrugStorehouseOut, advice.DrugId, advice.UserOrgId, flow.Count)
2827
+			ReduceDrugCountTwo(advice.DrugId, orgID, storeConfig.DrugStorehouseOut, flow.Count)
2828
+		}
2829
+
2830
+		// 清零完该库存后,还有剩余出库未出完,进行对应的递归操作
2831
+		prescribingNumber_two_temp := deliver_number - stock_number
2832
+
2833
+		overPlusNumber := float64(prescribingNumber_two_temp)
2834
+
2835
+		advice.PrescribingNumber = float64(prescribingNumber_two_temp)
2836
+		advice.PrescribingNumberUnit = drup.MinUnit
2837
+
2838
+		HisSettleDrugDeliverInfo(orgID, overPlusNumber, warehouseout, drup, advice)
2839
+	}
2840
+
2841
+	return
2842
+}

+ 5 - 5
service/self_drug_service.go Ver arquivo

@@ -2012,7 +2012,7 @@ func GetAddStartFlow(good_id int64, orgid int64, startime int64, endtime int64)
2012 2012
 }
2013 2013
 
2014 2014
 func GetReduceWarehouseInfoList(good_id int64, orgid int64, startime int64, endtime int64) (outinfo []*models.VmStockFlowTwenty, err error) {
2015
-	db := XTReadDB().Model(&outinfo).Where("status = 1 and (consumable_type = 2 or consumable_type = 3)")
2015
+	db := XTReadDB().Model(&outinfo).Where("status = 1 and (consumable_type = 2 or consumable_type = 3 or consumable_type= 15)")
2016 2016
 	if good_id > 0 {
2017 2017
 		db = db.Where("good_id = ?", good_id)
2018 2018
 	}
@@ -2144,7 +2144,7 @@ func FindEndCancelInfo(good_id int64, orgid int64, endtime int64) (info []*model
2144 2144
 
2145 2145
 func FindeWarehouseOutInfo(good_id int64, orgid int64, startime int64) (outinfo []*models.VmStockFlowTwenty, err error) {
2146 2146
 
2147
-	db := XTReadDB().Model(&outinfo).Where("status = 1 and (consumable_type = 2 or consumable_type = 3)")
2147
+	db := XTReadDB().Model(&outinfo).Where("status = 1 and (consumable_type = 2 or consumable_type = 3 or consumable_type = 15)")
2148 2148
 	if good_id > 0 {
2149 2149
 		db = db.Where("good_id = ?", good_id)
2150 2150
 	}
@@ -2261,7 +2261,7 @@ func DrugWarehouseInfoEnd(drug_id int64, orgid int64, endTime int64) (info []*mo
2261 2261
 
2262 2262
 func DrugWarehouseOutInfoEnd(drug_id int64, orgid int64, endTime int64) (info []*models.DrugFlowTwenty, err error) {
2263 2263
 
2264
-	db := XTReadDB().Model(&info).Where("status = 1 and (consumable_type = 2 or consumable_type= 3)")
2264
+	db := XTReadDB().Model(&info).Where("status = 1 and (consumable_type = 2 or consumable_type= 3 or consumable_type= 15)")
2265 2265
 	if drug_id > 0 {
2266 2266
 		db = db.Where("drug_id = ?", drug_id)
2267 2267
 	}
@@ -2309,7 +2309,7 @@ func GetDrugWarehouseStartEnd(drug_id int64, orgid int64, startTime int64, endTi
2309 2309
 }
2310 2310
 
2311 2311
 func FindeDrugWarehouseOutInfo(drug_id int64, orgid int64, startTime int64, endTime int64) (info []*models.DrugFlowTwenty, err error) {
2312
-	db := XTReadDB().Model(&info).Where("status = 1  and (consumable_type = 2 or consumable_type= 3)")
2312
+	db := XTReadDB().Model(&info).Where("status = 1  and (consumable_type = 2 or consumable_type= 3 or consumable_type= 15 )")
2313 2313
 	if drug_id > 0 {
2314 2314
 		db = db.Where("drug_id = ?", drug_id)
2315 2315
 	}
@@ -2398,7 +2398,7 @@ func GetDrugFlowSart(drug_id int64, user_org_id int64, ctime int64) (flow []*mod
2398 2398
 
2399 2399
 func GetDrugFlowOut(drug_id int64, user_org_id int64, ctime int64) (flow []*models.DrugFlowTwenty, err error) {
2400 2400
 
2401
-	db := XTReadDB().Model(&flow).Where("status = 1  and (consumable_type = 2 or consumable_type= 3)")
2401
+	db := XTReadDB().Model(&flow).Where("status = 1  and (consumable_type = 2 or consumable_type= 3 or consumable_type= 15)")
2402 2402
 	if drug_id > 0 {
2403 2403
 		db = db.Where("drug_id = ?", drug_id)
2404 2404
 	}

+ 183 - 6
service/stock_service.go Ver arquivo

@@ -1620,7 +1620,7 @@ func FindAllWarehouseOutListOne(orgId int64, page int64, limit int64, startTime
1620 1620
 		db = db.Where("xt_warehouse_out.storehouse_id = ?", storehouse_id)
1621 1621
 	}
1622 1622
 	if way_type == 0 {
1623
-		db = db.Where("xt_warehouse_out.is_sys = 0 or xt_warehouse_out.is_sys = 1 or xt_warehouse_out.is_sys = 12")
1623
+		db = db.Where("xt_warehouse_out.is_sys = 0 or xt_warehouse_out.is_sys = 1 or xt_warehouse_out.is_sys = 12 or xt_warehouse_out.is_sys = 5")
1624 1624
 	}
1625 1625
 	if way_type == 1 {
1626 1626
 		db = db.Where("xt_warehouse_out.is_sys = 0")
@@ -1631,6 +1631,9 @@ func FindAllWarehouseOutListOne(orgId int64, page int64, limit int64, startTime
1631 1631
 	if way_type == 3 {
1632 1632
 		db = db.Where("xt_warehouse_out.is_sys = 12")
1633 1633
 	}
1634
+	if way_type == 4 {
1635
+		db = db.Where("xt_warehouse_out.is_sys = 5")
1636
+	}
1634 1637
 	if check_type > 0 {
1635 1638
 		db = db.Where("xt_warehouse_out.is_check = ?", check_type)
1636 1639
 	}
@@ -1699,7 +1702,7 @@ func FindAllDrugWarehouseOutListOne(orgId int64, page int64, limit int64, startT
1699 1702
 	}
1700 1703
 
1701 1704
 	if way_type == 0 {
1702
-		db = db.Where("xt_drug_warehouse_out.is_sys = 0 || xt_drug_warehouse_out.is_sys = 1 || xt_drug_warehouse_out.is_sys = 12")
1705
+		db = db.Where("xt_drug_warehouse_out.is_sys = 0 || xt_drug_warehouse_out.is_sys = 1 || xt_drug_warehouse_out.is_sys = 12 || xt_drug_warehouse_out.is_sys = 5")
1703 1706
 	}
1704 1707
 	if way_type == 1 {
1705 1708
 		db = db.Where("xt_drug_warehouse_out.is_sys = 0")
@@ -1710,6 +1713,9 @@ func FindAllDrugWarehouseOutListOne(orgId int64, page int64, limit int64, startT
1710 1713
 	if way_type == 3 {
1711 1714
 		db = db.Where("xt_drug_warehouse_out.is_sys = 12")
1712 1715
 	}
1716
+	if way_type == 4 {
1717
+		db = db.Where("xt_drug_warehouse_out.is_sys = 15")
1718
+	}
1713 1719
 	db = db.Count(&total)
1714 1720
 	offset := (page - 1) * limit
1715 1721
 	if orgId == 10191 {
@@ -3137,6 +3143,12 @@ func FindDrugStockOutByIsSys(org_id int64, is_sys int, record_time int64) (out m
3137 3143
 
3138 3144
 }
3139 3145
 
3146
+func FindDrugSettleStockOutByIsSys(org_id int64, is_sys int, record_time int64) (out models.DrugWarehouseOut, err error) {
3147
+	err = readDb.Model(&models.DrugWarehouseOut{}).Where("is_sys = ? AND status = 1 AND org_id = ? AND warehouse_out_time = ?", is_sys, org_id, record_time).First(&out).Error
3148
+	return
3149
+
3150
+}
3151
+
3140 3152
 func FindLastStockInInfoRecord(good_id int64, org_id int64) (in models.WarehousingInfo, err error) {
3141 3153
 	err = readDb.Model(&models.WarehousingInfo{}).Where("status = 1 AND org_id = ? AND good_id = ?", org_id, good_id).First(&in).Error
3142 3154
 	return
@@ -4243,7 +4255,7 @@ func GetOrderDetialByOrderIdOne(id []string, orgid int64) (out []*models.Warehou
4243 4255
 }
4244 4256
 
4245 4257
 func GetOrderDetailStockFlowByStorehouseById(id []string, orgid int64) (list []*models.VmStockFlow, err error) {
4246
-	db := XTReadDB().Model(&list).Where("status = 1 and (consumable_type = 2 or consumable_type = 3)")
4258
+	db := XTReadDB().Model(&list).Where("status = 1 and (consumable_type = 2 or consumable_type = 3 or consumable_type = 15 or consumable_type = 12)")
4247 4259
 	if len(id) > 0 {
4248 4260
 		db = db.Where("warehouse_out_id in (?)", id)
4249 4261
 	}
@@ -4256,7 +4268,7 @@ func GetOrderDetailStockFlowByStorehouseById(id []string, orgid int64) (list []*
4256 4268
 
4257 4269
 func GetOrderDetailStockFlow(id []string, orgid int64) (list []*models.VmStockFlow, err error) {
4258 4270
 
4259
-	db := XTReadDB().Model(&list).Where("status = 1 and (consumable_type = 2 or consumable_type = 3)")
4271
+	db := XTReadDB().Model(&list).Where("status = 1 and (consumable_type = 2 or consumable_type = 3 or consumable_type = 15 or consumable_type = 12)")
4260 4272
 	if len(id) > 0 {
4261 4273
 		db = db.Where("warehouse_out_id in (?)", id)
4262 4274
 	}
@@ -4308,6 +4320,14 @@ func GetGoodInformationByGoodId(good_id int64) (models.GoodInfo, error) {
4308 4320
 	err := XTReadDB().Where("id = ? and status = 1", good_id).Find(&info).Error
4309 4321
 	return info, err
4310 4322
 }
4323
+
4324
+func GetGoodInformationByGoodIdThirty(good_id int64) (models.GoodInformationThirty, error) {
4325
+
4326
+	info := models.GoodInformationThirty{}
4327
+	err := XTReadDB().Where("id = ? and status = 1", good_id).Find(&info).Error
4328
+	return info, err
4329
+}
4330
+
4311 4331
 func UpdateGoodInfoList(info models.GoodInfo, id int64) error {
4312 4332
 
4313 4333
 	err := XTWriteDB().Model(&info).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"total": info.Total}).Error
@@ -4784,7 +4804,7 @@ func GetStockFlowBatchNumber(id int64, goodid int64) (stock []*models.VmStockFlo
4784 4804
 
4785 4805
 func GetStockFlowBatchNumberOne(id int64, goodid int64) (stock []*models.VmStockFlowOne, err error) {
4786 4806
 
4787
-	db := XTReadDB().Table("xt_stock_flow as x").Where("x.status = 1 and x.count > 0 and (x.consumable_type = 3 or x.consumable_type = 2)")
4807
+	db := XTReadDB().Table("xt_stock_flow as x").Where("x.status = 1 and x.count > 0 and (x.consumable_type = 3 or x.consumable_type = 2 or x.consumable_type = 15)")
4788 4808
 	table := XTReadDB().Table("xt_patients as t").Where("t.status = 1")
4789 4809
 	fmt.Println(table)
4790 4810
 	tableone := XTReadDB().Table("xt_good_information as o").Where("o.status = 1")
@@ -5034,6 +5054,12 @@ func GetStockFlowIsBatchNumber(warehousing_id int64, patient_id int64, record_ti
5034 5054
 	return flow, nil
5035 5055
 }
5036 5056
 
5057
+func GetStockFlowIsBatchNumberSix(patient_id int64, record_time int64, good_id int64, project_id int64) (flow []*models.VmStockFlow, err error) {
5058
+
5059
+	err = XTReadDB().Where("patient_id = ? and system_time = ? and good_id = ? and status = 1 and consumable_type = 3 and project_id = ?", patient_id, record_time, good_id, project_id).Find(&flow).Error
5060
+	return flow, nil
5061
+}
5062
+
5037 5063
 func GetStockFlowIsBatchNumberTwo(patient_id int64, record_time int64, good_id int64) (flow []*models.WarehouseOutInfo, err error) {
5038 5064
 
5039 5065
 	err = XTReadDB().Where("patient_id = ? and sys_record_time = ? and good_id = ? and status = 1 ", patient_id, record_time, good_id).Find(&flow).Error
@@ -5123,6 +5149,9 @@ func GetStockFlowList(limit int64, page int64, consumable_type int64, orgId int6
5123 5149
 		if consumable_type == 13 {
5124 5150
 			db = db.Where(" consumable_type = ?", consumable_type)
5125 5151
 		}
5152
+		if consumable_type == 15 {
5153
+			db = db.Where(" consumable_type = ?", consumable_type)
5154
+		}
5126 5155
 	}
5127 5156
 	if orgId > 0 {
5128 5157
 		db = db.Where("user_org_id = ?", orgId)
@@ -5251,6 +5280,10 @@ func GetDrugFlow(drugid int64, orgid int64, limit int64, page int64, startTime i
5251 5280
 			db = db.Where("consumable_type = 13")
5252 5281
 		}
5253 5282
 
5283
+		if stock_type == 15 {
5284
+			db = db.Where("consumable_type = 15")
5285
+		}
5286
+
5254 5287
 	}
5255 5288
 	err = db.Count(&total).Offset(offset).Limit(limit).Order("id desc").Preload("BaseDrugLib", "status = 1").Preload("DrugWarehouseInfo", "status = 1").Preload("XtDrugWarehouseOutInfo", "status = 1").Find(&drug_flow).Error
5256 5289
 	return drug_flow, total, err
@@ -8132,7 +8165,13 @@ func UpdatePharyConfig(orgid int64, is_open int64) (models.PharmacyConfig, error
8132 8165
 
8133 8166
 func UpdateSettleOpenConfigOne(id int64, is_open int64) error {
8134 8167
 
8135
-	err := XTWriteDB().Model(&models.HisSettleStockConfig{}).Where("id = ? and status = 1", id).Update(map[string]interface{}{"is_open": is_open}).Error
8168
+	err := XTWriteDB().Model(&models.HisSettleStockConfig{}).Where("user_org_id = ? and status = 1", id).Update(map[string]interface{}{"is_open": is_open}).Error
8169
+	return err
8170
+}
8171
+
8172
+func UpdateSettleOpenConfigTwo(id int64, is_open int64) error {
8173
+
8174
+	err := XTWriteDB().Model(&models.HisSettleStockConfig{}).Where("user_org_id = ? and status = 1", id).Update(map[string]interface{}{"is_open": is_open}).Error
8136 8175
 	return err
8137 8176
 }
8138 8177
 
@@ -8163,3 +8202,141 @@ func GetBloodDocById(id int64, orgid int64) (models.DoctorAdvice, error) {
8163 8202
 	err := XTReadDB().Where("id = ? and user_org_id= ? and status = 1", id, orgid).Find(&advice).Error
8164 8203
 	return advice, err
8165 8204
 }
8205
+
8206
+func FindAllSettleWarehouseOut(org_id int64, warehouse_out_time int64, is_sys int64) (models.WarehouseOut, error) {
8207
+
8208
+	out := models.WarehouseOut{}
8209
+	err = readDb.Model(&models.WarehouseOut{}).Where("org_id = ?  and status = 1 and warehouse_out_time = ? and is_sys = ?", org_id, warehouse_out_time, is_sys).Find(&out).Error
8210
+	return out, err
8211
+
8212
+}
8213
+
8214
+func GetGoodOutOpenConfig(user_org_id int64) (*models.XtGoodOutConfig, error) {
8215
+
8216
+	config := models.XtGoodOutConfig{}
8217
+	err := XTReadDB().Where("user_org_id = ? and status = 1", user_org_id).Find(&config).Error
8218
+	if err == gorm.ErrRecordNotFound {
8219
+		return nil, err
8220
+	}
8221
+	if err != nil {
8222
+		return nil, err
8223
+	}
8224
+	return &config, nil
8225
+}
8226
+
8227
+func CreateGoodOutOpenConfig(good models.XtGoodOutConfig) error {
8228
+
8229
+	err := XTWriteDB().Create(&good).Error
8230
+	return err
8231
+}
8232
+
8233
+func UpdateGoodOutOpenConfig(id int64, good models.XtGoodOutConfig) error {
8234
+
8235
+	err := XTWriteDB().Model(&good).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"is_open": good.IsOpen}).Error
8236
+	return err
8237
+}
8238
+
8239
+func FindGoodOutConfigById(user_org_id int64) (models.XtGoodOutConfig, error) {
8240
+
8241
+	config := models.XtGoodOutConfig{}
8242
+	err := XTReadDB().Where("user_org_id = ? and status = 1", user_org_id).Find(&config).Error
8243
+	return config, err
8244
+}
8245
+
8246
+func UpdateGoodAutoConfig(user_org_id int64) error {
8247
+
8248
+	gobalConfig := models.GobalConfig{}
8249
+	err := XTWriteDB().Model(&gobalConfig).Where("org_id = ? and status = 1", user_org_id).Updates(map[string]interface{}{"is_open": 2}).Error
8250
+	return err
8251
+}
8252
+
8253
+func UpdateGoodOutConfig(user_org_id int64) error {
8254
+
8255
+	config := models.XtGoodOutConfig{}
8256
+	err := XTWriteDB().Model(&config).Where("user_org_id = ? and status = 1", user_org_id).Updates(map[string]interface{}{"is_open": 2}).Error
8257
+	return err
8258
+}
8259
+
8260
+func GetHisGoodList(patient_id int64, record_date int64, orgid int64) (info []*models.GoodHisPrescriptionProject, err error) {
8261
+
8262
+	err = XTReadDB().Where("patient_id = ? and record_date = ? and status = 1 and user_org_id = ? AND type = 3", patient_id, record_date, orgid).Find(&info).Error
8263
+	return info, err
8264
+}
8265
+
8266
+func GetLastGoodWarehouseOutInfoByProjectId(good_id int64, patient_id int64, sys_record_time int64, project_id int64) (good []*models.WarehouseOutInfo, err error) {
8267
+
8268
+	err = XTReadDB().Where("good_id = ? and patient_id = ? and sys_record_time = ? and project_id = ? and status = 1", good_id, patient_id, sys_record_time, project_id).Find(&good).Error
8269
+	return good, err
8270
+}
8271
+
8272
+func ModifyGoodWarehouseInfo(good_id int64, warehouse_info_id int64, orgid int64, count int64) error {
8273
+
8274
+	err = XTWriteDB().Model(&models.WarehousingInfo{}).Where("id = ? and org_id = ? and good_id = ? and status = 1", warehouse_info_id, orgid, good_id).UpdateColumn("stock_count", gorm.Expr("stock_count + ?", count)).Error
8275
+	return err
8276
+}
8277
+
8278
+func DeleteGoodWarehouseOutInfo(good_id int64, sys_record_time int64, org_id int64, project_id int64) error {
8279
+
8280
+	err := XTWriteDB().Model(&models.WarehouseOutInfo{}).Where("good_id = ? and sys_record_time = ? and org_id = ? and project_id = ? and status=1", good_id, sys_record_time, org_id, project_id).Updates(map[string]interface{}{"status": 0}).Error
8281
+	return err
8282
+}
8283
+
8284
+func FindPrescriptionWarehouseOut(org_id int64, warehouse_out_time int64) (models.WarehouseOut, error) {
8285
+
8286
+	out := models.WarehouseOut{}
8287
+	err = readDb.Model(&models.WarehouseOut{}).Where("org_id = ?  and status = 1 and warehouse_out_time = ?", org_id, warehouse_out_time).Find(&out).Error
8288
+	return out, err
8289
+
8290
+}
8291
+
8292
+func FindLastPrescriptionWarehouseOut(org_id int64, warehouse_out_time int64) (models.WarehouseOut, error) {
8293
+
8294
+	out := models.WarehouseOut{}
8295
+	err = readDb.Model(&models.WarehouseOut{}).Where("org_id = ?  and status = 1 and warehouse_out_time = ?", org_id, warehouse_out_time).Last(&out).Error
8296
+	return out, err
8297
+
8298
+}
8299
+
8300
+func GetGoodTypeObj(goodid int64, org_id int64) (models.GoodsType, error) {
8301
+
8302
+	goodsType := models.GoodsType{}
8303
+	err := XTReadDB().Where("good_id = ? and org_id = ? and status = 1", goodid, org_id).Find(&goodsType).Error
8304
+	return goodsType, err
8305
+}
8306
+
8307
+func GetSencondeGoodWarehouseInfo(good_id int64, org_id int64) (info []*models.WarehousingInfo, err error) {
8308
+
8309
+	err = XTReadDB().Where("good_id = ? and org_id= ? and status= 1 and is_check = 1", good_id, org_id).Find(&info).Error
8310
+	return info, err
8311
+}
8312
+
8313
+func UpdateGoodSumCountSeven(sum_count int64, good_id int64, orgid int64) error {
8314
+	ut := writeDb.Begin()
8315
+	err := ut.Model(&models.GoodInfo{}).Where("id = ? and org_id = ? and status = 1", good_id, orgid).Updates(map[string]interface{}{"sum_count": sum_count}).Error
8316
+	if err != nil {
8317
+		ut.Rollback()
8318
+		return err
8319
+	}
8320
+	ut.Commit()
8321
+	return err
8322
+}
8323
+
8324
+func GetWarehouseOutInfoIsExistOTwo(good_id int64, patient_id int64, record_time int64, project_id int64) (*models.WarehouseOutInfo, error) {
8325
+
8326
+	info := models.WarehouseOutInfo{}
8327
+	var err error
8328
+	err = XTReadDB().Model(&info).Where("good_id = ? and sys_record_time = ? and status = 1 and patient_id = ? and project_id = ?", good_id, record_time, patient_id, project_id).Find(&info).Error
8329
+	if err == gorm.ErrRecordNotFound {
8330
+		return nil, err
8331
+	}
8332
+	if err != nil {
8333
+		return nil, err
8334
+	}
8335
+	return &info, nil
8336
+}
8337
+
8338
+func GetWarehouseOutInfoIsExistThree(good_id int64, patient_id int64, record_time int64, project_id int64) (models.WarehouseOutInfo, error) {
8339
+	info := models.WarehouseOutInfo{}
8340
+	err := XTReadDB().Where("good_id = ? and sys_record_time = ? and status = 1 and patient_id = ? and project_id = ?", good_id, record_time, patient_id, project_id).Find(&info).Error
8341
+	return info, err
8342
+}

Diferenças do arquivo suprimidas por serem muito extensas
+ 1181 - 0
service/warhouse_service.go