Ver código fonte

耗材参数

XMLWAN 3 anos atrás
pai
commit
36cccd6aa9

+ 3 - 0
conf/app.conf Ver arquivo

19
 
19
 
20
 
20
 
21
 
21
 
22
+
23
+
24
+
22
 aes_key = "xuetou-201807319"
25
 aes_key = "xuetou-201807319"
23
 
26
 
24
 wxtoken = gh_ac6cd0cdde3d
27
 wxtoken = gh_ac6cd0cdde3d

+ 156 - 21
controllers/drug_stock_api_contorller.go Ver arquivo

543
 						BatchNumber:      batch_number,
543
 						BatchNumber:      batch_number,
544
 						MaxUnit:          max_unit,
544
 						MaxUnit:          max_unit,
545
 						MinUnit:          min_unit,
545
 						MinUnit:          min_unit,
546
+						StockMaxNumber:   warehousing_count,
546
 					}
547
 					}
547
 					warehousingInfo = append(warehousingInfo, warehouseInfo)
548
 					warehousingInfo = append(warehousingInfo, warehouseInfo)
548
 
549
 
567
 						Dealer:           dealer,
568
 						Dealer:           dealer,
568
 						RetailPrice:      last_price,
569
 						RetailPrice:      last_price,
569
 						RetailTotalPrice: retail_price_total,
570
 						RetailTotalPrice: retail_price_total,
570
-						StockMaxNumber:   warehousing_count,
571
 						MaxUnit:          max_unit,
571
 						MaxUnit:          max_unit,
572
 						MinUnit:          min_unit,
572
 						MinUnit:          min_unit,
573
 						BatchNumber:      batch_number,
573
 						BatchNumber:      batch_number,
576
 
576
 
577
 					drugflow := &models.DrugFlow{
577
 					drugflow := &models.DrugFlow{
578
 						WarehousingOrder: warehousing.WarehousingOrder,
578
 						WarehousingOrder: warehousing.WarehousingOrder,
579
-						WarehousingId:    warehousing.ID,
579
+						WarehousingId:    id,
580
 						DrugId:           drug_id,
580
 						DrugId:           drug_id,
581
 						Number:           number,
581
 						Number:           number,
582
 						ProductDate:      productDates,
582
 						ProductDate:      productDates,
638
 				Total: minNumber,
638
 				Total: minNumber,
639
 			}
639
 			}
640
 			service.UpdateBaseDrug(&lib, item.DrugId)
640
 			service.UpdateBaseDrug(&lib, item.DrugId)
641
+			warehouseInfo, _ := service.FindeLastWarehouseInfo(item.ID)
642
+			fmt.Println("hhhhh23hh32h232332323223", warehouseInfo)
643
+			var total int64
644
+			//比较大小(加)
645
+			if item.WarehousingCount > warehouseInfo.WarehousingCount {
646
+				total = item.WarehousingCount - warehouseInfo.WarehousingCount
647
+			}
648
+			item.StockMaxNumber = warehouseInfo.StockMaxNumber + total
649
+			if item.WarehousingCount < warehouseInfo.WarehousingCount {
650
+				total = warehouseInfo.WarehousingCount - item.WarehousingCount
651
+			}
652
+			item.StockMaxNumber = warehouseInfo.StockMaxNumber - total
653
+			if item.WarehousingCount == warehouseInfo.StockMaxNumber {
654
+
655
+				item.StockMaxNumber = item.WarehousingCount
656
+			}
641
 			errs = service.UpDateDrugWarehousingInfo(item)
657
 			errs = service.UpDateDrugWarehousingInfo(item)
642
-			service.CreateDrugFlow(drugFlow)
658
+
659
+		}
660
+	}
661
+
662
+	if len(drugFlow) > 0 {
663
+		for _, item := range drugFlow {
664
+			flow := models.DrugFlow{
665
+				Count: item.Count,
666
+			}
667
+			parseDateErr := service.UpdateDrugFlow(flow, item.DrugId, item.WarehousingId)
668
+			fmt.Println(parseDateErr)
643
 		}
669
 		}
644
 	}
670
 	}
645
 
671
 
1152
 				remark := items["remark"].(string)
1178
 				remark := items["remark"].(string)
1153
 				max_unit := items["max_unit"].(string)
1179
 				max_unit := items["max_unit"].(string)
1154
 				dealer := int64(items["dealer"].(float64))
1180
 				dealer := int64(items["dealer"].(float64))
1155
-				fmt.Println("dealer2222222222222222222", dealer)
1181
+
1156
 				manufacturer := int64(items["manufacturer"].(float64))
1182
 				manufacturer := int64(items["manufacturer"].(float64))
1157
-				fmt.Println("manufacturer22222222222222", manufacturer)
1183
+
1158
 				number := items["number"].(string)
1184
 				number := items["number"].(string)
1159
 				batch_number := items["batch_number"].(string)
1185
 				batch_number := items["batch_number"].(string)
1186
+
1187
+				warehouse_info_id := int64(items["warehouse_info_id"].(float64))
1160
 				var productDates int64
1188
 				var productDates int64
1161
 				var expiryDates int64
1189
 				var expiryDates int64
1162
 				if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
1190
 				if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
1209
 					Number:                  number,
1237
 					Number:                  number,
1210
 					BatchNumber:             batch_number,
1238
 					BatchNumber:             batch_number,
1211
 					IsSys:                   0,
1239
 					IsSys:                   0,
1240
+					WarehouseInfoId:         warehouse_info_id,
1212
 				}
1241
 				}
1213
 				warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
1242
 				warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
1214
 
1243
 
1242
 	//调用出库逻辑
1271
 	//调用出库逻辑
1243
 	for _, item := range warehousingOutInfo {
1272
 	for _, item := range warehousingOutInfo {
1244
 		//获取药品库存
1273
 		//获取药品库存
1245
-		info, _ := service.GetDrugTotalCount(item.DrugId, item.OrgId)
1274
+		info, _ := service.GetDrugTotalCountOne(item.DrugId, item.OrgId, item.WarehouseInfoId)
1246
 		//查询改药品信息
1275
 		//查询改药品信息
1247
 		medical, _ := service.GetBaseDrugMedical(item.DrugId)
1276
 		medical, _ := service.GetBaseDrugMedical(item.DrugId)
1277
+		total_count = info.StockMaxNumber*medical.MinNumber + info.StockMinNumber
1278
+		//for _, it := range info{
1279
+		//  if medical.MaxUnit == it.MaxUnit{
1280
+		//    it.Count = it.StockMaxNumber * medical.MinNumber
1281
+		//  }
1282
+		//  if medical.MinUnit == it.MinUnit{
1283
+		//    it.Count = it.StockMinNumber
1284
+		//  }
1285
+		//  total_count += it.Count
1286
+		//}
1287
+		fmt.Println("总库存23232323232232332232332223", total_count)
1248
 		//判断单位是否相等
1288
 		//判断单位是否相等
1249
 		if medical.MaxUnit == item.CountUnit {
1289
 		if medical.MaxUnit == item.CountUnit {
1250
 			//转化为最小单位
1290
 			//转化为最小单位
1251
-			total_count = info.Count * medical.MinNumber
1252
 			prescribing_number_total = item.Count * medical.MinNumber
1291
 			prescribing_number_total = item.Count * medical.MinNumber
1253
 		}
1292
 		}
1254
 		if medical.MinUnit == item.CountUnit {
1293
 		if medical.MinUnit == item.CountUnit {
1255
-			total_count = info.Count
1256
 			prescribing_number_total = item.Count
1294
 			prescribing_number_total = item.Count
1257
 		}
1295
 		}
1258
 
1296
 
1521
 				batch_number := items["batch_number"].(string)
1559
 				batch_number := items["batch_number"].(string)
1522
 				number := items["number"].(string)
1560
 				number := items["number"].(string)
1523
 				max_unit := items["count_unit"].(string)
1561
 				max_unit := items["count_unit"].(string)
1524
-
1562
+				warehouse_info_id := int64(items["warehouse_info_id"].(float64))
1525
 				var productDates int64
1563
 				var productDates int64
1526
 				var expiryDates int64
1564
 				var expiryDates int64
1527
 				if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
1565
 				if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
1551
 					}
1589
 					}
1552
 
1590
 
1553
 				}
1591
 				}
1554
-				fmt.Println("生产日期22222222222222222222222222", expiryDates)
1555
-				fmt.Println("生产日期22222222222222222222222222", productDates)
1592
+
1556
 				if id == 0 {
1593
 				if id == 0 {
1557
 					warehouseOutInfo := &models.DrugWarehouseOutInfo{
1594
 					warehouseOutInfo := &models.DrugWarehouseOutInfo{
1558
 						WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
1595
 						WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
1577
 						ProductDate:             productDates,
1614
 						ProductDate:             productDates,
1578
 						ExpiryDate:              expiryDates,
1615
 						ExpiryDate:              expiryDates,
1579
 						CountUnit:               count_unit,
1616
 						CountUnit:               count_unit,
1617
+						WarehouseInfoId:         warehouse_info_id,
1580
 					}
1618
 					}
1581
 					warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
1619
 					warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
1582
 
1620
 
1601
 						Creator:                 adminUserInfo.AdminUser.Id,
1639
 						Creator:                 adminUserInfo.AdminUser.Id,
1602
 						IsSys:                   0,
1640
 						IsSys:                   0,
1603
 						WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
1641
 						WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
1604
-						WarehouseOutId:          warehouseOut.ID,
1642
+						WarehouseOutId:          id,
1605
 					}
1643
 					}
1606
 
1644
 
1607
 					drugFlow = append(drugFlow, drugflow)
1645
 					drugFlow = append(drugFlow, drugflow)
1646
 						ProductDate:             productDates,
1684
 						ProductDate:             productDates,
1647
 						ExpiryDate:              expiryDates,
1685
 						ExpiryDate:              expiryDates,
1648
 						CountUnit:               count_unit,
1686
 						CountUnit:               count_unit,
1687
+						WarehouseInfoId:         warehouse_info_id,
1649
 					}
1688
 					}
1650
 					upDateWarehouseOutInfos = append(upDateWarehouseOutInfos, warehouseOutInfo)
1689
 					upDateWarehouseOutInfos = append(upDateWarehouseOutInfos, warehouseOutInfo)
1651
 
1690
 
2147
 	//扣减库存逻辑
2186
 	//扣减库存逻辑
2148
 	for _, item := range cancelStockInfos {
2187
 	for _, item := range cancelStockInfos {
2149
 		var total_number int64
2188
 		var total_number int64
2189
+		var out_number int64
2190
+		var can_number int64
2150
 		medical, _ := service.GetBaseDrugMedical(item.DrugId)
2191
 		medical, _ := service.GetBaseDrugMedical(item.DrugId)
2151
 		//将当前退库数转为最小单位
2192
 		//将当前退库数转为最小单位
2152
 		if item.MaxUnit == medical.MaxUnit {
2193
 		if item.MaxUnit == medical.MaxUnit {
2163
 		total_count = infoWareInfo.StockMaxNumber*medical.MinNumber + infoWareInfo.StockMinNumber
2204
 		total_count = infoWareInfo.StockMaxNumber*medical.MinNumber + infoWareInfo.StockMinNumber
2164
 		fmt.Println("当前批次总库存", total_count)
2205
 		fmt.Println("当前批次总库存", total_count)
2165
 
2206
 
2207
+		//查询该批次的出库数量
2208
+		outInfo, _ := service.GetDrugWarehouseOutInfo(item.BatchNumberId, item.DrugId)
2209
+		//查询该批次总的退库数量
2210
+
2211
+		canInfo, _ := service.GetCancelDrugStockOutInfo(item.BatchNumberId, item.DrugId)
2212
+		for _, item := range canInfo {
2213
+			if item.MaxUnit == medical.MaxUnit {
2214
+				item.Count = item.Count * medical.MinNumber
2215
+			}
2216
+			if item.MaxUnit == medical.MinUnit {
2217
+				item.Count = item.Count
2218
+			}
2219
+		}
2220
+		for _, item := range canInfo {
2221
+			can_number += item.Count
2222
+		}
2223
+
2224
+		for _, item := range outInfo {
2225
+			if item.CountUnit == medical.MaxUnit {
2226
+				item.Count = item.Count * medical.MinNumber
2227
+			}
2228
+			if item.CountUnit == medical.MinUnit {
2229
+				item.Count = item.Count
2230
+			}
2231
+		}
2232
+		for _, item := range outInfo {
2233
+			out_number += item.Count
2234
+		}
2235
+		fmt.Println("出库数量23232232323222332", out_number)
2236
+
2166
 		//判断退库数量是否大于总入库数量
2237
 		//判断退库数量是否大于总入库数量
2167
-		if total_number > total_count {
2238
+		if total_number > out_number {
2239
+			service.UpdateDrugCancel(item.CancelStockId)
2240
+			c.ServeSuccessJSON(map[string]interface{}{
2241
+				"msg": "4",
2242
+			})
2243
+			return
2244
+		}
2245
+
2246
+		//判断总退库数量是否大于出库数量
2247
+		fmt.Println("hhhhhhhhhhh", can_number+total_number)
2248
+		if can_number+total_number > out_number {
2249
+			service.UpdateDrugCancel(item.CancelStockId)
2168
 			c.ServeSuccessJSON(map[string]interface{}{
2250
 			c.ServeSuccessJSON(map[string]interface{}{
2169
 				"msg": "2",
2251
 				"msg": "2",
2170
 			})
2252
 			})
2171
 			return
2253
 			return
2172
 		}
2254
 		}
2255
+
2173
 		//正常退库
2256
 		//正常退库
2174
-		if total_number <= total_count {
2257
+		if total_number <= out_number {
2175
 			//创建退库详情
2258
 			//创建退库详情
2176
 			errs := service.CreateDrugCancelStockInfo(cancelStockInfos)
2259
 			errs := service.CreateDrugCancelStockInfo(cancelStockInfos)
2177
 			//创建库存明细
2260
 			//创建库存明细
2558
 			infoWareInfo, _ := service.GetDrugWarehouseInfo(item.BatchNumberId)
2641
 			infoWareInfo, _ := service.GetDrugWarehouseInfo(item.BatchNumberId)
2559
 			fmt.Println("hhh2h3h2hh3233", item.MaxUnit, medical.MaxUnit)
2642
 			fmt.Println("hhh2h3h2hh3233", item.MaxUnit, medical.MaxUnit)
2560
 			var total_count int64
2643
 			var total_count int64
2644
+			var cancel_count int64
2645
+			var out_count int64
2561
 			total_count = infoWareInfo.StockMaxNumber*medical.MinNumber + infoWareInfo.StockMinNumber
2646
 			total_count = infoWareInfo.StockMaxNumber*medical.MinNumber + infoWareInfo.StockMinNumber
2562
 			//转化为最小单位
2647
 			//转化为最小单位
2563
 			var total_number int64
2648
 			var total_number int64
2567
 			if item.MaxUnit == medical.MinUnit {
2652
 			if item.MaxUnit == medical.MinUnit {
2568
 				total_number = item.Count
2653
 				total_number = item.Count
2569
 			}
2654
 			}
2570
-			//if item.MaxUnit == medical.MaxUnit {
2571
-			//	total_count = infoWareInfo.WarehousingCount
2572
-			//}
2573
-			////转化为最小库存
2574
-			//if item.MaxUnit == medical.MinUnit {
2575
-			//	total_count = infoWareInfo.WarehousingCount * medical.MinNumber
2576
-			//}
2655
+
2656
+			//统计该批次的总出库数
2657
+			outInfo, _ := service.GetDrugWarehouseOutInfo(item.BatchNumberId, item.DrugId)
2658
+			for _, item := range outInfo {
2659
+				if item.CountUnit == medical.MaxUnit {
2660
+					item.Count = item.Count * medical.MinNumber
2661
+				}
2662
+				if item.CountUnit == medical.MinUnit {
2663
+					item.Count = item.Count
2664
+				}
2665
+			}
2666
+
2667
+			for _, item := range outInfo {
2668
+				out_count += item.Count
2669
+			}
2670
+			fmt.Println("out_count232233332232323223", out_count)
2671
+
2672
+			//判断退库数量是否大于出库数量
2673
+			cancelInfo, _ := service.GetCancelDrugStockOutInfo(item.BatchNumberId, item.DrugId)
2674
+			for _, item := range cancelInfo {
2675
+				if item.MaxUnit == medical.MaxUnit {
2676
+					item.Count = item.Count * medical.MinNumber
2677
+				}
2678
+				if item.MaxUnit == medical.MinUnit {
2679
+					item.Count = item.Count
2680
+				}
2681
+			}
2682
+
2683
+			for _, item := range cancelInfo {
2684
+				cancel_count += item.Count
2685
+			}
2686
+			fmt.Println("cancel_count", cancel_count)
2687
+			fmt.Println("hhhhhh23h2h332322323232", total_number+cancel_count)
2688
+			if total_number+cancel_count > out_count {
2689
+				c.ServeSuccessJSON(map[string]interface{}{
2690
+					"msg": "4",
2691
+				})
2692
+				return
2693
+			}
2694
+
2577
 			//判断退库数量是否大于总入库数量
2695
 			//判断退库数量是否大于总入库数量
2578
 			if total_number > total_count {
2696
 			if total_number > total_count {
2579
 				c.ServeSuccessJSON(map[string]interface{}{
2697
 				c.ServeSuccessJSON(map[string]interface{}{
2655
 
2773
 
2656
 	if len(upDateCancelStockInfos) > 0 {
2774
 	if len(upDateCancelStockInfos) > 0 {
2657
 		var total int64
2775
 		var total int64
2776
+		var out_count int64
2658
 		for _, item := range upDateCancelStockInfos {
2777
 		for _, item := range upDateCancelStockInfos {
2659
 			errs = service.UpDateDrugCancelStockInfo(item)
2778
 			errs = service.UpDateDrugCancelStockInfo(item)
2660
 			//查询该批次最后一条退库记录
2779
 			//查询该批次最后一条退库记录
2661
 			info, _ := service.GetLastCancelStockInfo(id)
2780
 			info, _ := service.GetLastCancelStockInfo(id)
2662
 			//查询该药品的信息
2781
 			//查询该药品的信息
2663
 			medical, _ := service.GetBaseDrugMedical(item.DrugId)
2782
 			medical, _ := service.GetBaseDrugMedical(item.DrugId)
2783
+			//统计该批次的总出库数
2784
+			outInfo, _ := service.GetDrugWarehouseOutInfo(item.BatchNumberId, item.DrugId)
2785
+			for _, item := range outInfo {
2786
+				if item.CountUnit == medical.MaxUnit {
2787
+					item.Count = item.Count * medical.MinNumber
2788
+				}
2789
+				if item.CountUnit == medical.MinUnit {
2790
+					item.Count = item.Count
2791
+				}
2792
+			}
2793
+
2794
+			for _, item := range outInfo {
2795
+				out_count += item.Count
2796
+			}
2797
+
2798
+			fmt.Println("out_count232233332232323223", out_count)
2664
 
2799
 
2665
 			if item.MaxUnit == medical.MaxUnit {
2800
 			if item.MaxUnit == medical.MaxUnit {
2666
 				item.Count = item.Count * medical.MinNumber
2801
 				item.Count = item.Count * medical.MinNumber

+ 13 - 6
controllers/gobal_config_api_controller.go Ver arquivo

1851
 	adminUserInfo := c.GetAdminUserInfo()
1851
 	adminUserInfo := c.GetAdminUserInfo()
1852
 
1852
 
1853
 	//查询入库数量
1853
 	//查询入库数量
1854
-	list, total, err := service.GetDrugStockList(page, limit, keyword, drug_type, startTime, endTime, adminUserInfo.CurrentOrgId)
1854
+	//list, total, err := service.GetDrugStockList(page, limit, keyword, drug_type, startTime, endTime, adminUserInfo.CurrentOrgId)
1855
+
1856
+	list, total, err := service.GetAllBaseDurgListCount(page, limit, keyword, drug_type, startTime, endTime, adminUserInfo.CurrentOrgId)
1857
+	fmt.Println("total232323232323232232323", total)
1855
 	manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
1858
 	manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
1856
 	if err != nil {
1859
 	if err != nil {
1857
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
1860
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
2007
 	orgId := c.GetAdminUserInfo().CurrentOrgId
2010
 	orgId := c.GetAdminUserInfo().CurrentOrgId
2008
 	list, err := service.GetDrugCountList(startTime, endTime, orgId)
2011
 	list, err := service.GetDrugCountList(startTime, endTime, orgId)
2009
 	countList, err := service.GetMinCountList(startTime, endTime, orgId)
2012
 	countList, err := service.GetMinCountList(startTime, endTime, orgId)
2010
-	outCountList, _ := service.GetOutDrugCountList(startTime, endTime, orgId)
2011
-	auCountList, err := service.GetAutoDrugCountList(startTime, endTime, orgId)
2013
+	//outCountList, _ := service.GetOutDrugCountList(startTime, endTime, orgId)
2014
+	//auCountList, err := service.GetAutoDrugCountList(startTime, endTime, orgId)
2012
 	info, _ := service.GetDrugWarehouOrderInfo(startTime, endTime, orgId)
2015
 	info, _ := service.GetDrugWarehouOrderInfo(startTime, endTime, orgId)
2013
 	cancelCountList, _ := service.GetCancelDrugCountList(startTime, endTime, orgId)
2016
 	cancelCountList, _ := service.GetCancelDrugCountList(startTime, endTime, orgId)
2017
+	//service.GetAllCountList(startTime,endTime,orgId)
2014
 	if err != nil {
2018
 	if err != nil {
2015
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
2019
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
2016
 		return
2020
 		return
2017
 	}
2021
 	}
2018
 	c.ServeSuccessJSON(map[string]interface{}{
2022
 	c.ServeSuccessJSON(map[string]interface{}{
2019
-		"countList":       list,
2020
-		"outCountList":    outCountList,
2021
-		"auCountList":     auCountList,
2023
+		"countList": list,
2024
+		//"outCountList":    outCountList,
2025
+		//"auCountList":     auCountList,
2022
 		"minCount":        countList,
2026
 		"minCount":        countList,
2023
 		"info":            info,
2027
 		"info":            info,
2024
 		"cancelCountList": cancelCountList,
2028
 		"cancelCountList": cancelCountList,
2028
 func (c *GobalConfigApiController) GetSingleOrderDetail() {
2032
 func (c *GobalConfigApiController) GetSingleOrderDetail() {
2029
 
2033
 
2030
 	id, _ := c.GetInt64("id")
2034
 	id, _ := c.GetInt64("id")
2035
+	start_time, _ := c.GetInt64("start_time")
2031
 	orgId := c.GetAdminUserInfo().CurrentOrgId
2036
 	orgId := c.GetAdminUserInfo().CurrentOrgId
2032
 	list, err := service.GetSingleOrderDetail(id, orgId)
2037
 	list, err := service.GetSingleOrderDetail(id, orgId)
2033
 	outList, err := service.GetAllSingleDrugDetail(id, orgId)
2038
 	outList, err := service.GetAllSingleDrugDetail(id, orgId)
2034
 	dealerList, err := service.GetAllDealerList(orgId)
2039
 	dealerList, err := service.GetAllDealerList(orgId)
2035
 	manufacturerList, err := service.GetAllManufacturerList(orgId)
2040
 	manufacturerList, err := service.GetAllManufacturerList(orgId)
2041
+	drugFlowList, _ := service.GetDrugStockFlowDetail(start_time, orgId)
2036
 	if err != nil {
2042
 	if err != nil {
2037
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
2043
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
2038
 		return
2044
 		return
2042
 		"dealerList":       dealerList,
2048
 		"dealerList":       dealerList,
2043
 		"manufacturerList": manufacturerList,
2049
 		"manufacturerList": manufacturerList,
2044
 		"outList":          outList,
2050
 		"outList":          outList,
2051
+		"drugFlowList":     drugFlowList,
2045
 	})
2052
 	})
2046
 }
2053
 }
2047
 
2054
 

+ 75 - 6
controllers/mobile_api_controllers/dialysis_api_controller.go Ver arquivo

3866
 					if err != nil {
3866
 					if err != nil {
3867
 						goodObj, _ := service.GetGoodInformationByGoodId(it.GoodId)
3867
 						goodObj, _ := service.GetGoodInformationByGoodId(it.GoodId)
3868
 						c.ServeSuccessJSON(map[string]interface{}{
3868
 						c.ServeSuccessJSON(map[string]interface{}{
3869
-							"message":            "1",
3869
+							"message":            "2",
3870
 							"good_name":          goodObj.GoodName,
3870
 							"good_name":          goodObj.GoodName,
3871
 							"specification_name": goodObj.SpecificationName,
3871
 							"specification_name": goodObj.SpecificationName,
3872
 						})
3872
 						})
4591
 			UpdateCreator:           creater,
4591
 			UpdateCreator:           creater,
4592
 			PatientId:               patient_id,
4592
 			PatientId:               patient_id,
4593
 		}
4593
 		}
4594
-		//创建流水表
4595
-		err := service.CreateStockFlowOne(stockFlow)
4596
-		fmt.Println("h2h3h2323342i24i242i4u2i4242u42424", err)
4594
+		exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
4595
+		if errflow == gorm.ErrRecordNotFound {
4596
+			//创建流水表
4597
+			err := service.CreateStockFlowOne(stockFlow)
4598
+			fmt.Println("h2h3h2323342i24i242i4u2i4242u42424", err)
4599
+		} else if errflow == nil {
4600
+			//插入详情明细表
4601
+			stockFlow := models.VmStockFlow{
4602
+				ID:                      exsit.ID,
4603
+				WarehousingId:           warehouseOutInfos.WarehouseInfotId,
4604
+				WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
4605
+				WarehouseOutId:          warehouseOut.ID,
4606
+				GoodId:                  good_yc.GoodId,
4607
+				Number:                  warehouseOutInfos.Number,
4608
+				ProductDate:             stockInInfo.ProductDate,
4609
+				ExpireDate:              stockInInfo.ExpiryDate,
4610
+				Count:                   exsit.Count - delete_count,
4611
+				Price:                   stockInInfo.Price,
4612
+				Status:                  1,
4613
+				Ctime:                   time.Now().Unix(),
4614
+				UserOrgId:               good_yc.OrgId,
4615
+				Manufacturer:            stockInInfo.Manufacturer,
4616
+				Dealer:                  stockInInfo.Dealer,
4617
+				LicenseNumber:           stockInInfo.LicenseNumber,
4618
+				IsEdit:                  2,
4619
+				Creator:                 creater,
4620
+				SystemTime:              record_time,
4621
+				ConsumableType:          3,
4622
+				WarehousingDetailId:     0,
4623
+				IsSys:                   1,
4624
+				UpdateCreator:           creater,
4625
+				PatientId:               patient_id,
4626
+			}
4627
+
4628
+			service.UpdatedStockFlow(stockFlow)
4629
+		}
4630
+
4597
 		if errOne != nil {
4631
 		if errOne != nil {
4598
 			return errOne
4632
 			return errOne
4599
 		}
4633
 		}
4601
 		service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time)
4635
 		service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time)
4602
 		//插入详情明细表
4636
 		//插入详情明细表
4603
 		stockFlow := models.VmStockFlow{
4637
 		stockFlow := models.VmStockFlow{
4638
+			WarehousingId:           warehouseOutInfos.WarehouseInfotId,
4604
 			WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
4639
 			WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
4605
 			WarehouseOutId:          warehouseOut.ID,
4640
 			WarehouseOutId:          warehouseOut.ID,
4606
 			GoodId:                  good_yc.GoodId,
4641
 			GoodId:                  good_yc.GoodId,
4623
 			IsSys:                   1,
4658
 			IsSys:                   1,
4624
 			UpdateCreator:           creater,
4659
 			UpdateCreator:           creater,
4625
 			PatientId:               patient_id,
4660
 			PatientId:               patient_id,
4661
+			ReturnCount:             delete_count,
4626
 		}
4662
 		}
4627
-		//创建流水表
4628
-		service.CreateStockFlowOne(stockFlow)
4663
+		exsit, errflows := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
4664
+		if errflows == gorm.ErrRecordNotFound {
4665
+			//创建流水表
4666
+			service.CreateStockFlowOne(stockFlow)
4667
+		} else if errflows == nil {
4668
+			stockFlow := models.VmStockFlow{
4669
+				WarehousingId:           warehouseOutInfos.WarehouseInfotId,
4670
+				ID:                      exsit.ID,
4671
+				WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
4672
+				WarehouseOutId:          warehouseOut.ID,
4673
+				GoodId:                  good_yc.GoodId,
4674
+				Number:                  warehouseOutInfos.Number,
4675
+				ProductDate:             stockInInfo.ProductDate,
4676
+				ExpireDate:              stockInInfo.ExpiryDate,
4677
+				Count:                   exsit.Count - delete_count,
4678
+				Price:                   stockInInfo.Price,
4679
+				Status:                  1,
4680
+				Ctime:                   time.Now().Unix(),
4681
+				UserOrgId:               good_yc.OrgId,
4682
+				Manufacturer:            stockInInfo.Manufacturer,
4683
+				Dealer:                  stockInInfo.Dealer,
4684
+				LicenseNumber:           stockInInfo.LicenseNumber,
4685
+				IsEdit:                  2,
4686
+				Creator:                 creater,
4687
+				SystemTime:              record_time,
4688
+				ConsumableType:          3,
4689
+				WarehousingDetailId:     0,
4690
+				IsSys:                   1,
4691
+				UpdateCreator:           creater,
4692
+				PatientId:               patient_id,
4693
+				ReturnCount:             delete_count,
4694
+			}
4695
+			service.UpdatedStockFlow(stockFlow)
4696
+		}
4697
+
4629
 	}
4698
 	}
4630
 
4699
 
4631
 	//更改自动出库的表格
4700
 	//更改自动出库的表格

+ 37 - 8
controllers/stock_in_api_controller.go Ver arquivo

554
 					stockFlow = append(stockFlow, flow)
554
 					stockFlow = append(stockFlow, flow)
555
 
555
 
556
 				} else {
556
 				} else {
557
+					fmt.Println("id23233232323232323232323223", id)
557
 					warehouseInfo := &models.WarehousingInfo{
558
 					warehouseInfo := &models.WarehousingInfo{
558
 						ID:               id,
559
 						ID:               id,
559
 						WarehousingOrder: warehouse.WarehousingOrder,
560
 						WarehousingOrder: warehouse.WarehousingOrder,
573
 						Type:             types,
574
 						Type:             types,
574
 						Manufacturer:     manufacturer,
575
 						Manufacturer:     manufacturer,
575
 						Dealer:           dealer,
576
 						Dealer:           dealer,
576
-						StockCount:       warehousing_count,
577
 						LicenseNumber:    license_number,
577
 						LicenseNumber:    license_number,
578
 					}
578
 					}
579
 					upDateWarehousingInfo = append(upDateWarehousingInfo, warehouseInfo)
579
 					upDateWarehousingInfo = append(upDateWarehousingInfo, warehouseInfo)
580
 
580
 
581
 					flow := &models.VmStockFlow{
581
 					flow := &models.VmStockFlow{
582
 						WarehousingOrder:    warehousing.WarehousingOrder,
582
 						WarehousingOrder:    warehousing.WarehousingOrder,
583
-						WarehousingId:       warehousing.ID,
583
+						WarehousingId:       id,
584
 						GoodId:              good_id,
584
 						GoodId:              good_id,
585
 						Number:              number,
585
 						Number:              number,
586
 						ProductDate:         productDates,
586
 						ProductDate:         productDates,
614
 	if len(upDateWarehousingInfo) > 0 {
614
 	if len(upDateWarehousingInfo) > 0 {
615
 
615
 
616
 		for _, item := range upDateWarehousingInfo {
616
 		for _, item := range upDateWarehousingInfo {
617
+
617
 			var total int64
618
 			var total int64
618
 			var all_total int64
619
 			var all_total int64
619
 			//获取该批次该型号的库存
620
 			//获取该批次该型号的库存
620
-			info, _ := service.GetLastWarehousingById(item.WarehousingId, item.GoodId)
621
-
621
+			info, _ := service.GetLastWarehousingByIdOne(item.ID, item.GoodId)
622
+			fmt.Println("oooooooooo", info.WarehousingCount)
622
 			//判断 该批次的入库数量
623
 			//判断 该批次的入库数量
623
 			total = item.WarehousingCount - info.WarehousingCount
624
 			total = item.WarehousingCount - info.WarehousingCount
624
-
625
+			fmt.Println("total232323322332232332", total)
625
 			all_total = info.StockCount + total
626
 			all_total = info.StockCount + total
626
 
627
 
627
 			item.StockCount = all_total
628
 			item.StockCount = all_total
629
+			fmt.Println("hhhhhhhhhhhhh", item.StockCount)
630
+
628
 			errs = service.UpDateWarehousingInfo(item)
631
 			errs = service.UpDateWarehousingInfo(item)
632
+		}
633
+	}
629
 
634
 
630
-			service.CreateStockFlow(stockFlow)
635
+	if len(stockFlow) > 0 {
636
+		for _, item := range stockFlow {
637
+			flow := models.VmStockFlow{
638
+				Count: item.Count,
639
+			}
640
+			parseDateErr := service.UpdateStockFlow(flow, item.GoodId, item.WarehousingId)
641
+			fmt.Println(parseDateErr)
631
 		}
642
 		}
632
 	}
643
 	}
633
 
644
 
1930
 		//统计该耗材的出库数量
1941
 		//统计该耗材的出库数量
1931
 		info, _ := service.GetWarehoureOrderInfoCount(item.GoodId, item.OrgId)
1942
 		info, _ := service.GetWarehoureOrderInfoCount(item.GoodId, item.OrgId)
1932
 		if item.Count > info.Count {
1943
 		if item.Count > info.Count {
1944
+			service.UpdateCancelInfo(item.CancelStockId)
1933
 			c.ServeSuccessJSON(map[string]interface{}{
1945
 			c.ServeSuccessJSON(map[string]interface{}{
1934
 				"msg": "2",
1946
 				"msg": "2",
1935
 			})
1947
 			})
1958
 				return
1970
 				return
1959
 			}
1971
 			}
1960
 
1972
 
1973
+			//查询该批次的剩余库存
1974
+			wareouseinfo, _ := service.GetWarehouseInfoById(item.WarehouseInfoId)
1975
+			if (wareouseinfo.StockCount + item.Count) > wareouseinfo.WarehousingCount {
1976
+				c.ServeSuccessJSON(map[string]interface{}{
1977
+					"msg": "5",
1978
+				})
1979
+				return
1980
+			}
1961
 			//更改入库数量
1981
 			//更改入库数量
1962
 			errs = service.UpdateWareInfoById(item.WarehouseInfoId, item.Count)
1982
 			errs = service.UpdateWareInfoById(item.WarehouseInfoId, item.Count)
1963
 
1983
 
2365
 				errs = service.UpDateCancelStockInfo(item)
2385
 				errs = service.UpDateCancelStockInfo(item)
2366
 
2386
 
2367
 				service.CreateStockFlow(stockFlow)
2387
 				service.CreateStockFlow(stockFlow)
2388
+				warehouseinfo, _ := service.GetWarehouseInfoById(item.WarehouseInfoId)
2389
+				if (warehouseinfo.StockCount + total) > warehouseinfo.StockCount {
2390
+					c.ServeSuccessJSON(map[string]interface{}{
2391
+						"msg": "5",
2392
+					})
2393
+					return
2394
+				}
2368
 				parseDateErr := service.UpdateWareInfoById(item.WarehouseInfoId, total)
2395
 				parseDateErr := service.UpdateWareInfoById(item.WarehouseInfoId, total)
2369
 				if parseDateErr != nil {
2396
 				if parseDateErr != nil {
2370
 					utils.ErrorLog(errs.Error())
2397
 					utils.ErrorLog(errs.Error())
2386
 				}
2413
 				}
2387
 				if item.Count <= infolist.WarehousingCount {
2414
 				if item.Count <= infolist.WarehousingCount {
2388
 					var total_count = info.Count - item.Count
2415
 					var total_count = info.Count - item.Count
2416
+
2389
 					parseDateErr := service.UpdateWareInfoById(item.WarehouseInfoId, total_count)
2417
 					parseDateErr := service.UpdateWareInfoById(item.WarehouseInfoId, total_count)
2390
 					if parseDateErr != nil {
2418
 					if parseDateErr != nil {
2391
 						utils.ErrorLog(errs.Error())
2419
 						utils.ErrorLog(errs.Error())
4281
 	adminUserInfo := this.GetAdminUserInfo()
4309
 	adminUserInfo := this.GetAdminUserInfo()
4282
 	orgId := adminUserInfo.CurrentOrgId
4310
 	orgId := adminUserInfo.CurrentOrgId
4283
 
4311
 
4284
-	list, total, _ := service.GetAllStockList(page, limit, startTime, endTime, types, keywords, orgId)
4312
+	list, total, _ := service.GetAllGoodInfoStockList(page, limit, startTime, endTime, types, keywords, orgId)
4313
+	fmt.Println("耗材总计23323232232323232323", total)
4285
 	manufacturerList, _ := service.GetAllManufacturerList(orgId)
4314
 	manufacturerList, _ := service.GetAllManufacturerList(orgId)
4286
 	this.ServeSuccessJSON(map[string]interface{}{
4315
 	this.ServeSuccessJSON(map[string]interface{}{
4287
 		"list":             list,
4316
 		"list":             list,
4440
 	//手动出库
4469
 	//手动出库
4441
 	info, _ := service.GetWarehouseOutInfoById(id, good_id)
4470
 	info, _ := service.GetWarehouseOutInfoById(id, good_id)
4442
 
4471
 
4443
-	stockFlowList, err := service.GetStockFlowBatchNumber(id, good_id)
4472
+	stockFlowList, err := service.GetStockFlowBatchNumberOne(id, good_id)
4444
 	if err == nil {
4473
 	if err == nil {
4445
 		this.ServeSuccessJSON(map[string]interface{}{
4474
 		this.ServeSuccessJSON(map[string]interface{}{
4446
 			"list":          userDetails,
4475
 			"list":          userDetails,

+ 1 - 0
models/drug_stock.go Ver arquivo

279
 	Count          int64  `gorm:"column:count" json:"count" form:"count"`
279
 	Count          int64  `gorm:"column:count" json:"count" form:"count"`
280
 	MaxUnit        string `gorm:"column:max_unit" json:"max_unit" form:"max_unit"`
280
 	MaxUnit        string `gorm:"column:max_unit" json:"max_unit" form:"max_unit"`
281
 	MinUnit        string `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
281
 	MinUnit        string `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
282
+	CountUnit      string `gorm:"column:count_unit" json:"count_unit" form:"count_unit"`
282
 	StockMinNumber int64  `gorm:"column:stock_min_number" json:"stock_min_number" form:"stock_min_number"`
283
 	StockMinNumber int64  `gorm:"column:stock_min_number" json:"stock_min_number" form:"stock_min_number"`
283
 	StockMaxNumber int64  `gorm:"column:stock_max_number" json:"stock_max_number" form:"stock_max_number"`
284
 	StockMaxNumber int64  `gorm:"column:stock_max_number" json:"stock_max_number" form:"stock_max_number"`
284
 }
285
 }

+ 2 - 1
models/good_models.go Ver arquivo

77
 	DefaultCountUnit            string               `gorm:"column:default_count_unit" json:"default_count_unit" form:"default_count_unit"`
77
 	DefaultCountUnit            string               `gorm:"column:default_count_unit" json:"default_count_unit" form:"default_count_unit"`
78
 	MinUnit                     string               `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
78
 	MinUnit                     string               `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
79
 	Total                       float64              `gorm:"column:total" json:"total" form:"total"`
79
 	Total                       float64              `gorm:"column:total" json:"total" form:"total"`
80
-	StWarehousingInfo           []*StWarehousingInfo `gorm:"ForeignKey:good_id;AssociationForeignKey:ID" json:"xt_warehouse_info"`
80
+	StWarehousingInfo           []*StWarehousingInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"xt_warehouse_info"`
81
+	CancelStockInfo             []*CancelStockInfo   `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"cancel_stock_info"`
81
 }
82
 }
82
 
83
 
83
 func (GoodInfo) TableName() string {
84
 func (GoodInfo) TableName() string {

+ 2 - 2
models/self_drug_models.go Ver arquivo

365
 	Status                  int64  `gorm:"column:status" json:"status" form:"status"`
365
 	Status                  int64  `gorm:"column:status" json:"status" form:"status"`
366
 	RecordTime              int64  `gorm:"column:record_time" json:"record_time" form:"record_time"`
366
 	RecordTime              int64  `gorm:"column:record_time" json:"record_time" form:"record_time"`
367
 	OrgId                   int64  `gorm:"column:org_id" json:"org_id" form:"org_id"`
367
 	OrgId                   int64  `gorm:"column:org_id" json:"org_id" form:"org_id"`
368
-	GoodId                  int64  `gorm:"column:good_id" json:"good_id" form:"good_id"`
369
-	GoodTypeId              int64  `gorm:"column:good_type_id" json:"good_type_id" form:"good_type_id"`
368
+	DrugId                  int64  `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
370
 	Count                   int64  `gorm:"column:count" json:"count" form:"count"`
369
 	Count                   int64  `gorm:"column:count" json:"count" form:"count"`
370
+	CountUnit               string `gorm:"column:count_unit" json:"count_unit" form:"count_unit"`
371
 }
371
 }
372
 
372
 
373
 func (XtDrugAutomaticReduceDetail) TableName() string {
373
 func (XtDrugAutomaticReduceDetail) TableName() string {

+ 193 - 0
models/stock_models.go Ver arquivo

520
 	CancelOutDetailId       int64   `gorm:"column:cancel_out_detail_id" json:"cancel_out_detail_id" form:"cancel_out_detail_id"`
520
 	CancelOutDetailId       int64   `gorm:"column:cancel_out_detail_id" json:"cancel_out_detail_id" form:"cancel_out_detail_id"`
521
 	ProductDate             int64   `gorm:"column:product_date" json:"product_date" form:"product_date"`
521
 	ProductDate             int64   `gorm:"column:product_date" json:"product_date" form:"product_date"`
522
 	ExpireDate              int64   `gorm:"column:expire_date" json:"expire_date" form:"expire_date"`
522
 	ExpireDate              int64   `gorm:"column:expire_date" json:"expire_date" form:"expire_date"`
523
+	ReturnCount             int64   `gorm:"column:return_count" json:"return_count" form:"return_count"`
523
 }
524
 }
524
 
525
 
525
 func (VmStockFlow) TableName() string {
526
 func (VmStockFlow) TableName() string {
555
 func (CancelStockInfo) TableName() string {
556
 func (CancelStockInfo) TableName() string {
556
 	return "xt_cancel_stock_info"
557
 	return "xt_cancel_stock_info"
557
 }
558
 }
559
+
560
+type VmBaseDrug struct {
561
+	ID                          int64                     `gorm:"column:id" json:"id" form:"id"`
562
+	DrugName                    string                    `gorm:"column:drug_name" json:"drug_name" form:"drug_name"`
563
+	Pinyin                      string                    `gorm:"column:pinyin" json:"pinyin" form:"pinyin"`
564
+	Wubi                        string                    `gorm:"column:wubi" json:"wubi" form:"wubi"`
565
+	DrugAlias                   string                    `gorm:"column:drug_alias" json:"drug_alias" form:"drug_alias"`
566
+	DrugAliasPinyin             string                    `gorm:"column:drug_alias_pinyin" json:"drug_alias_pinyin" form:"drug_alias_pinyin"`
567
+	DrugAliasWubi               string                    `gorm:"column:drug_alias_wubi" json:"drug_alias_wubi" form:"drug_alias_wubi"`
568
+	DrugCategory                int64                     `gorm:"column:drug_category" json:"drug_category" form:"drug_category"`
569
+	DrugSpec                    string                    `gorm:"column:drug_spec" json:"drug_spec" form:"drug_spec"`
570
+	DrugType                    int64                     `gorm:"column:drug_type" json:"drug_type" form:"drug_type"`
571
+	DrugStockLimit              string                    `gorm:"column:drug_stock_limit" json:"drug_stock_limit" form:"drug_stock_limit"`
572
+	DrugOriginPlace             string                    `gorm:"column:drug_origin_place" json:"drug_origin_place" form:"drug_origin_place"`
573
+	DrugDosageForm              int64                     `gorm:"column:drug_dosage_form" json:"drug_dosage_form" form:"drug_dosage_form"`
574
+	MedicalInsuranceLevel       int64                     `gorm:"column:medical_insurance_level" json:"medical_insurance_level" form:"medical_insurance_level"`
575
+	MaxUnit                     string                    `gorm:"column:max_unit" json:"max_unit" form:"max_unit"`
576
+	MinNumber                   int64                     `gorm:"column:min_number" json:"min_number" form:"min_number"`
577
+	MinUnit                     string                    `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
578
+	Dose                        float64                   `gorm:"column:dose" json:"dose" form:"dose"`
579
+	DoseUnit                    string                    `gorm:"column:dose_unit" json:"dose_unit" form:"dose_unit"`
580
+	UnitMatrixing               string                    `gorm:"column:unit_matrixing" json:"unit_matrixing" form:"unit_matrixing"`
581
+	RetailPrice                 float64                   `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
582
+	MinPrice                    float64                   `gorm:"column:min_price" json:"min_price" form:"min_price"`
583
+	LastPrice                   float64                   `gorm:"column:last_price" json:"last_price" form:"last_price"`
584
+	DrugControl                 int64                     `gorm:"column:drug_control" json:"drug_control" form:"drug_control"`
585
+	Number                      string                    `gorm:"column:number" json:"number" form:"number"`
586
+	DrugClassify                string                    `gorm:"column:drug_classify" json:"drug_classify" form:"drug_classify"`
587
+	DrugDose                    float64                   `gorm:"column:drug_dose" json:"drug_dose" form:"drug_dose"`
588
+	DrugDoseUnit                int64                     `gorm:"column:drug_dose_unit" json:"drug_dose_unit" form:"drug_dose_unit"`
589
+	MedicalInsuranceNumber      string                    `gorm:"column:medical_insurance_number" json:"medical_insurance_number" form:"medical_insurance_number"`
590
+	Manufacturer                int64                     `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
591
+	PharmacologyCategory        int64                     `gorm:"column:pharmacology_category" json:"pharmacology_category" form:"pharmacology_category"`
592
+	StatisticsCategory          int64                     `gorm:"column:statistics_category" json:"statistics_category" form:"statistics_category"`
593
+	Code                        string                    `gorm:"column:code" json:"code" form:"code"`
594
+	IsSpecialDiseases           int64                     `gorm:"column:is_special_diseases" json:"is_special_diseases" form:"is_special_diseases"`
595
+	IsRecord                    int64                     `gorm:"column:is_record" json:"is_record" form:"is_record"`
596
+	Agent                       string                    `gorm:"column:agent" json:"agent" form:"agent"`
597
+	DrugStatus                  string                    `gorm:"column:drug_status" json:"drug_status" form:"drug_status"`
598
+	LimitRemark                 string                    `gorm:"column:limit_remark" json:"limit_remark" form:"limit_remark"`
599
+	DeliveryWay                 string                    `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
600
+	ExecutionFrequency          string                    `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
601
+	SingleDose                  float64                   `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
602
+	PrescribingNumber           float64                   `gorm:"column:prescribing_number" json:"prescribing_number" form:"prescribing_number"`
603
+	Label                       int64                     `gorm:"column:label" json:"label" form:"label"`
604
+	Sort                        int64                     `gorm:"column:sort" json:"sort" form:"sort"`
605
+	IsUseDoctorAdvice           int64                     `gorm:"column:is_use_doctor_advice" json:"is_use_doctor_advice" form:"is_use_doctor_advice"`
606
+	IsDefault                   int64                     `gorm:"column:is_default" json:"is_default" form:"is_default"`
607
+	IsChargePredict             int64                     `gorm:"column:is_charge_predict" json:"is_charge_predict" form:"is_charge_predict"`
608
+	IsStatisticsWork            int64                     `gorm:"column:is_statistics_work" json:"is_statistics_work" form:"is_statistics_work"`
609
+	IsChargeUse                 int64                     `gorm:"column:is_charge_use" json:"is_charge_use" form:"is_charge_use"`
610
+	Status                      int64                     `gorm:"column:status" json:"status" form:"status"`
611
+	Ctime                       int64                     `gorm:"column:ctime" json:"ctime" form:"ctime"`
612
+	Mtime                       int64                     `gorm:"column:mtime" json:"mtime" form:"mtime"`
613
+	OrgId                       int64                     `gorm:"column:org_id" json:"org_id" form:"org_id"`
614
+	DrugCode                    string                    `gorm:"column:drug_code" json:"drug_code" form:"drug_code"`
615
+	Dealer                      int64                     `gorm:"column:dealer" json:"dealer" form:"dealer"`
616
+	PrescriptionMark            int64                     `gorm:"column:prescription_mark" json:"prescription_mark" form:"prescription_mark"`
617
+	RecordDate                  int64                     `gorm:"column:record_date" json:"record_date" form:"record_date"`
618
+	DrugRemark                  string                    `gorm:"column:drug_remark" json:"drug_remark" form:"drug_remark"`
619
+	SocialSecurityDirectoryCode string                    `gorm:"column:social_security_directory_code" json:"social_security_directory_code" form:"social_security_directory_code"`
620
+	DoseCode                    string                    `gorm:"column:dose_code" json:"dose_code" form:"dose_code"`
621
+	IsMark                      int64                     `gorm:"column:is_mark" json:"is_mark" form:"is_mark"`
622
+	HospApprFlag                int64                     `gorm:"column:hosp_appr_flag" json:"hosp_appr_flag" form:"hosp_appr_flag"`
623
+	LmtUsedFlag                 int64                     `gorm:"column:lmt_used_flag" json:"lmt_used_flag" form:"lmt_used_flag"`
624
+	DrugDay                     string                    `gorm:"column:drug_day" json:"drug_day" form:"drug_day"`
625
+	Total                       float64                   `gorm:"column:total" json:"total" form:"total"`
626
+	PrescribingNumberUnit       string                    `gorm:"column:prescribing_number_unit" json:"prescribing_number_unit" form:"prescribing_number_unit"`
627
+	DrugWarehouseInfo           []*VsDrugWarehouseInfo    `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"drug_warehouse_info"`
628
+	DrugCancelStockInfo         []*VsDrugCancelStockInfo  `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"drug_cancel_stock_info"`
629
+	DrugWarehouseOutInfo        []*VsDrugWarehouseOutInfo `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"drug_warehouse_out"`
630
+}
631
+
632
+func (VmBaseDrug) TableName() string {
633
+	return "xt_base_drug"
634
+}
635
+
636
+type VsDrugWarehouseInfo struct {
637
+	ID               int64   `gorm:"column:id" json:"id" form:"id"`
638
+	WarehousingId    int64   `gorm:"column:warehousing_id" json:"warehousing_id" form:"warehousing_id"`
639
+	DrugId           int64   `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
640
+	Number           string  `gorm:"column:number" json:"number" form:"number"`
641
+	ProductDate      int64   `gorm:"column:product_date" json:"product_date" form:"product_date"`
642
+	ExpiryDate       int64   `gorm:"column:expiry_date" json:"expiry_date" form:"expiry_date"`
643
+	WarehousingCount int64   `gorm:"column:warehousing_count" json:"warehousing_count" form:"warehousing_count"`
644
+	WarehouseingUnit string  `gorm:"column:warehouseing_unit" json:"warehouseing_unit" form:"warehouseing_unit"`
645
+	MaxUnit          string  `gorm:"column:max_unit" json:"max_unit" form:"max_unit"`
646
+	MinUnit          string  `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
647
+	StockMaxNumber   int64   `gorm:"column:stock_max_number" json:"stock_max_number" form:"stock_max_number"`
648
+	StockMinNumber   int64   `gorm:"column:stock_min_number" json:"stock_min_number" form:"stock_min_number"`
649
+	Price            float64 `gorm:"column:price" json:"price" form:"price"`
650
+	TotalPrice       float64 `gorm:"column:total_price" json:"total_price" form:"total_price"`
651
+	Dealer           int64   `gorm:"column:dealer" json:"dealer" form:"dealer"`
652
+	Manufacturer     int64   `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
653
+	Remark           string  `gorm:"column:remark" json:"remark" form:"remark"`
654
+	Ctime            int64   `gorm:"column:ctime" json:"ctime" form:"ctime"`
655
+	Mtime            int64   `gorm:"column:mtime" json:"mtime" form:"mtime"`
656
+	Status           int64   `gorm:"column:status" json:"status" form:"status"`
657
+	OrgId            int64   `gorm:"column:org_id" json:"org_id" form:"org_id"`
658
+	IsReturn         int64   `gorm:"column:is_return" json:"is_return" form:"is_return"`
659
+	WarehousingOrder string  `gorm:"column:warehousing_order" json:"warehousing_order" form:"warehousing_order"`
660
+	Type             int64   `gorm:"column:type" json:"type" form:"type"`
661
+	RetailPrice      float64 `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
662
+	RetailTotalPrice float64 `gorm:"column:retail_total_price" json:"retail_total_price" form:"retail_total_price"`
663
+	BatchNumber      string  `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
664
+}
665
+
666
+func (VsDrugWarehouseInfo) TableName() string {
667
+	return "xt_drug_warehouse_info"
668
+}
669
+
670
+type VsDrugCancelStockInfo struct {
671
+	ID               int64       `gorm:"column:id" json:"id" form:"id"`
672
+	DrugId           int64       `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
673
+	CancelStockId    int64       `gorm:"column:cancel_stock_id" json:"cancel_stock_id" form:"cancel_stock_id"`
674
+	Count            int64       `gorm:"column:count" json:"count" form:"count"`
675
+	Price            float64     `gorm:"column:price" json:"price" form:"price"`
676
+	Total            float64     `gorm:"column:total" json:"total" form:"total"`
677
+	ProductDate      int64       `gorm:"column:product_date" json:"product_date" form:"product_date"`
678
+	ExpiryDate       int64       `gorm:"column:expiry_date" json:"expiry_date" form:"expiry_date"`
679
+	Ctime            int64       `gorm:"column:ctime" json:"ctime" form:"ctime"`
680
+	Mtime            int64       `gorm:"column:mtime" json:"mtime" form:"mtime"`
681
+	Status           int64       `gorm:"column:status" json:"status" form:"status"`
682
+	OrgId            int64       `gorm:"column:org_id" json:"org_id" form:"org_id"`
683
+	OrderNumber      string      `gorm:"column:order_number" json:"order_number" form:"order_number"`
684
+	Type             int64       `gorm:"column:type" json:"type" form:"type"`
685
+	Dealer           string      `gorm:"column:dealer" json:"dealer" form:"dealer"`
686
+	Manufacturer     string      `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
687
+	RetailPrice      float64     `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
688
+	RetailTotalPrice float64     `gorm:"column:retail_total_price" json:"retail_total_price" form:"retail_total_price"`
689
+	Number           string      `gorm:"column:number" json:"number" form:"number"`
690
+	RegisterAccount  string      `gorm:"column:register_account" json:"register_account" form:"register_account"`
691
+	Remark           string      `gorm:"column:remark" json:"remark" form:"remark"`
692
+	BatchNumber      string      `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
693
+	MaxUnit          string      `gorm:"column:max_unit" json:"max_unit" form:"max_unit"`
694
+	BaseDrugLib      BaseDrugLib `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" `
695
+}
696
+
697
+func (VsDrugCancelStockInfo) TableName() string {
698
+	return "xt_drug_cancel_stock_info"
699
+}
700
+
701
+type VsDrugWarehouseOutInfo struct {
702
+	ID                      int64   `gorm:"column:id" json:"id" form:"id"`
703
+	WarehouseOutId          int64   `gorm:"column:warehouse_out_id" json:"warehouse_out_id" form:"warehouse_out_id"`
704
+	DrugId                  int64   `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
705
+	WarehousingOutTarget    int64   `gorm:"column:warehousing_out_target" json:"warehousing_out_target" form:"warehousing_out_target"`
706
+	Count                   int64   `gorm:"column:count" json:"count" form:"count"`
707
+	Price                   float64 `gorm:"column:price" json:"price" form:"price"`
708
+	TotalPrice              float64 `gorm:"column:total_price" json:"total_price" form:"total_price"`
709
+	ProductDate             int64   `gorm:"column:product_date" json:"product_date" form:"product_date"`
710
+	ExpiryDate              int64   `gorm:"column:expiry_date" json:"expiry_date" form:"expiry_date"`
711
+	Mtime                   int64   `gorm:"column:mtime" json:"mtime" form:"mtime"`
712
+	Ctime                   int64   `gorm:"column:ctime" json:"ctime" form:"ctime"`
713
+	Status                  int64   `gorm:"column:status" json:"status" form:"status"`
714
+	OrgId                   int64   `gorm:"column:org_id" json:"org_id" form:"org_id"`
715
+	Remark                  string  `gorm:"column:remark" json:"remark" form:"remark"`
716
+	IsCancel                int64   `gorm:"column:is_cancel" json:"is_cancel" form:"is_cancel"`
717
+	WarehouseOutOrderNumber string  `gorm:"column:warehouse_out_order_number" json:"warehouse_out_order_number" form:"warehouse_out_order_number"`
718
+	Type                    int64   `gorm:"column:type" json:"type" form:"type"`
719
+	Dealer                  int64   `gorm:"column:dealer" json:"dealer" form:"dealer"`
720
+	Manufacturer            int64   `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
721
+	IsSys                   int64   `gorm:"column:is_sys" json:"is_sys" form:"is_sys"`
722
+	SysRecordTime           int64   `gorm:"column:sys_record_time" json:"sys_record_time" form:"sys_record_time"`
723
+	RetailPrice             float64 `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
724
+	RetailTotalPrice        float64 `gorm:"column:retail_total_price" json:"retail_total_price" form:"retail_total_price"`
725
+	CountUnit               string  `gorm:"column:count_unit" json:"count_unit" form:"count_unit"`
726
+}
727
+
728
+func (VsDrugWarehouseOutInfo) TableName() string {
729
+	return "xt_drug_warehouse_out_info"
730
+}
731
+
732
+type VmStockFlowOne struct {
733
+	ID                      int64   `gorm:"column:id" json:"id" form:"id"`
734
+	WarehousingId           int64   `gorm:"column:warehousing_id" json:"warehousing_id" form:"warehousing_id"`
735
+	GoodId                  int64   `gorm:"column:good_id" json:"good_id" form:"good_id"`
736
+	Number                  string  `gorm:"column:number" json:"number" form:"number"`
737
+	Count                   int64   `gorm:"column:count" json:"count" form:"count"`
738
+	PatientId               int64   `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
739
+	SystemTime              int64   `gorm:"column:system_time" json:"system_time" form:"system_time"`
740
+	IsSys                   int64   `gorm:"column:is_sys" json:"is_sys" form:"is_sys"`
741
+	WarehousingOrder        string  `gorm:"column:warehousing_order" json:"warehousing_order" form:"warehousing_order"`
742
+	WarehouseOutId          int64   `gorm:"column:warehouse_out_id" json:"warehouse_out_id" form:"warehouse_out_id"`
743
+	WarehouseOutOrderNumber string  `gorm:"column:warehouse_out_order_number" json:"warehouse_out_order_number" form:"warehouse_out_order_number"`
744
+	Price                   float64 `gorm:"column:price" json:"price" form:"price"`
745
+	ProductDate             int64   `gorm:"column:product_date" json:"product_date" form:"product_date"`
746
+	ExpireDate              int64   `gorm:"column:expire_date" json:"expire_date" form:"expire_date"`
747
+	PackingUnit             string  `gorm:"column:packing_unit" json:"packing_unit" form:"packing_unit"`
748
+	Ctime                   int64   `gorm:"column:ctime" json:"ctime" form:"ctime"`
749
+	Name                    string  `gorm:"column:name" json:"name" form:"name"`
750
+}

+ 45 - 4
service/gobal_config_service.go Ver arquivo

499
 func GetDrugStockList(page int64, limit int64, keyword string, drugcategory int64, startime int64, endtime int64, orgid int64) (list []*models.StDrugWarehouseInfo, total int64, err error) {
499
 func GetDrugStockList(page int64, limit int64, keyword string, drugcategory int64, startime int64, endtime int64, orgid int64) (list []*models.StDrugWarehouseInfo, total int64, err error) {
500
 	offset := (page - 1) * limit
500
 	offset := (page - 1) * limit
501
 	db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status = 1")
501
 	db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status = 1")
502
-
503
 	likeKey := "%" + keyword + "%"
502
 	likeKey := "%" + keyword + "%"
504
 	if orgid > 0 {
503
 	if orgid > 0 {
505
 		db = db.Where("x.org_id = ?", orgid)
504
 		db = db.Where("x.org_id = ?", orgid)
537
 	return list, total, err
536
 	return list, total, err
538
 }
537
 }
539
 
538
 
539
+func GetAllBaseDurgListCount(page int64, limit int64, keyword string, drugcategory int64, startime int64, endtime int64, orgid int64) (drug []*models.VmBaseDrug, total int64, err error) {
540
+
541
+	offset := (page - 1) * limit
542
+	db := XTReadDB().Table("xt_base_drug").Where("status = 1")
543
+	likeKey := "%" + keyword + "%"
544
+	if orgid > 0 {
545
+		db = db.Where("org_id = ?", orgid)
546
+	}
547
+	if drugcategory > 0 {
548
+		db = db.Where("drug_type = ?", drugcategory)
549
+	}
550
+
551
+	if len(keyword) > 0 {
552
+		db = db.Where("drug_name like ?", likeKey)
553
+	}
554
+
555
+	err = db.Count(&total).Offset(offset).Limit(limit).Order("ctime desc").Preload("DrugWarehouseInfo", "status=1 and org_id = ? and ctime >=? and ctime<=?", orgid, startime, endtime).Preload("DrugCancelStockInfo", "status=1 and org_id = ? and ctime >=? and ctime<=?", orgid, startime, endtime).Preload("DrugWarehouseOutInfo", "status=1 and org_id = ? and ctime >=? and ctime<=?", orgid, startime, endtime).Find(&drug).Error
556
+	return drug, total, err
557
+}
558
+
540
 func GetDrugStockFlow(drugid int64, startime int64, endtime int64, page int64, limit int64, orgid int64) (list []*models.StDrugWarehouseInfo, total int64, err error) {
559
 func GetDrugStockFlow(drugid int64, startime int64, endtime int64, page int64, limit int64, orgid int64) (list []*models.StDrugWarehouseInfo, total int64, err error) {
541
 
560
 
542
 	db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status = 1")
561
 	db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status = 1")
643
 	if orgid > 0 {
662
 	if orgid > 0 {
644
 		db = db.Where("x.org_id = ?", orgid)
663
 		db = db.Where("x.org_id = ?", orgid)
645
 	}
664
 	}
646
-	err = db.Select("sum(x.count) as count,x.drug_id").Group("x.drug_id").Scan(&info).Error
665
+	err = db.Select("x.count,x.drug_id,x.count_unit").Find(&info).Error
647
 	return info, err
666
 	return info, err
648
 }
667
 }
649
 
668
 
659
 	if orgid > 0 {
678
 	if orgid > 0 {
660
 		db = db.Where("x.org_id = ?", orgid)
679
 		db = db.Where("x.org_id = ?", orgid)
661
 	}
680
 	}
662
-	err = db.Select("sum(x.count) as count,x.drug_id").Group("x.drug_id").Scan(&info).Error
681
+	err = db.Select("x.count,x.drug_id,x.count_unit").Find(&info).Error
663
 	return info, err
682
 	return info, err
664
 
683
 
665
 }
684
 }
681
 	return info, err
700
 	return info, err
682
 }
701
 }
683
 
702
 
703
+func GetAllCountList(startime int64, endtime int64, orgid int64) (info []*models.DrugWarehouseInfo, err error) {
704
+	db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status = 1")
705
+
706
+	if startime > 0 {
707
+		db = db.Where("x.ctime >=?", startime)
708
+	}
709
+	if endtime > 0 {
710
+		db = db.Where("x.ctime<=?", endtime)
711
+	}
712
+	if orgid > 0 {
713
+		db = db.Where("x.org_id = ?", orgid)
714
+	}
715
+	err = db.Find(&info).Error
716
+	return info, err
717
+}
718
+
684
 func GetSingleOrderDetail(id int64, orgid int64) (info []*models.VmDrugWarehouseOutInfo, err error) {
719
 func GetSingleOrderDetail(id int64, orgid int64) (info []*models.VmDrugWarehouseOutInfo, err error) {
685
 
720
 
686
 	db := XTReadDB().Table("xt_drug_warehouse_out_info as x").Where("x.status = 1")
721
 	db := XTReadDB().Table("xt_drug_warehouse_out_info as x").Where("x.status = 1")
697
 	return info, err
732
 	return info, err
698
 }
733
 }
699
 
734
 
735
+func GetDrugStockFlowDetail(id int64, orgid int64) (drugflow []*models.XtDrugAutomaticReduceDetail, err error) {
736
+
737
+	err = XTReadDB().Where("record_time = ? and org_id = ? and status = 1", id, orgid).Find(&drugflow).Error
738
+	return drugflow, err
739
+}
740
+
700
 func GetAllSingleDrugDetail(id int64, orgid int64) (outInfo []*models.VmDrugWarehouseOutInfo, err error) {
741
 func GetAllSingleDrugDetail(id int64, orgid int64) (outInfo []*models.VmDrugWarehouseOutInfo, err error) {
701
 
742
 
702
 	db := XTReadDB().Table("xt_drug_warehouse_out_info as x").Where("x.status = 1")
743
 	db := XTReadDB().Table("xt_drug_warehouse_out_info as x").Where("x.status = 1")
734
 
775
 
735
 func GetDrugFlowBatch(ware_out_id int64, drug_id int64, orgid int64) (flow []*models.DrugFlow, err error) {
776
 func GetDrugFlowBatch(ware_out_id int64, drug_id int64, orgid int64) (flow []*models.DrugFlow, err error) {
736
 
777
 
737
-	err = XTReadDB().Where("warehouse_out_id = ? and drug_id = ? and user_org_id = ? and status = 1", ware_out_id, drug_id, orgid).Group("number").Find(&flow).Error
778
+	err = XTReadDB().Where("warehouse_out_id = ? and drug_id = ? and user_org_id = ? and status = 1", ware_out_id, drug_id, orgid).Find(&flow).Error
738
 	return flow, err
779
 	return flow, err
739
 }
780
 }

+ 1 - 1
service/mobile_dialysis_service.go Ver arquivo

521
 
521
 
522
 	err := readDb.
522
 	err := readDb.
523
 		Model(&models.DoctorAdvice{}).
523
 		Model(&models.DoctorAdvice{}).
524
-		Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ? and advice_type = 2", patientID, orgID, recordDate).
524
+		Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ? and (advice_type = 2 || advice_type = 3)", patientID, orgID, recordDate).
525
 		Select("id, user_org_id, patient_id, advice_type, advice_date, record_date, start_time, advice_name,advice_desc, reminder_date, drug_spec, drug_spec_unit, single_dose, single_dose_unit, prescribing_number, prescribing_number_unit, delivery_way, execution_frequency, advice_doctor, status, created_time,updated_time, advice_affirm, remark, stop_time, stop_reason, stop_doctor, stop_state, parent_id, execution_time, execution_staff, execution_state, checker, check_state, check_time, groupno,way,drug_id,drug_name_id, IF(parent_id > 0, parent_id, id) as advice_order").
525
 		Select("id, user_org_id, patient_id, advice_type, advice_date, record_date, start_time, advice_name,advice_desc, reminder_date, drug_spec, drug_spec_unit, single_dose, single_dose_unit, prescribing_number, prescribing_number_unit, delivery_way, execution_frequency, advice_doctor, status, created_time,updated_time, advice_affirm, remark, stop_time, stop_reason, stop_doctor, stop_state, parent_id, execution_time, execution_staff, execution_state, checker, check_state, check_time, groupno,way,drug_id,drug_name_id, IF(parent_id > 0, parent_id, id) as advice_order").
526
 		Order("start_time asc, groupno desc, advice_order desc, id asc").
526
 		Order("start_time asc, groupno desc, advice_order desc, id asc").
527
 		Scan(&records).Error
527
 		Scan(&records).Error

+ 147 - 0
service/stock_service.go Ver arquivo

505
 	err := XTWriteDB().Model(&lib).Where("id = ?", id).Updates(map[string]interface{}{"total": lib.Total}).Error
505
 	err := XTWriteDB().Model(&lib).Where("id = ?", id).Updates(map[string]interface{}{"total": lib.Total}).Error
506
 	return err
506
 	return err
507
 }
507
 }
508
+func FindeLastWarehouseInfo(id int64) (models.DrugWarehouseInfo, error) {
509
+	info := models.DrugWarehouseInfo{}
510
+	err := XTReadDB().Model(&info).Where("id=? and status = 1", id).Find(&info).Error
511
+	return info, err
512
+}
508
 
513
 
509
 func CreateDrugFlow(drugflow []*models.DrugFlow) (err error) {
514
 func CreateDrugFlow(drugflow []*models.DrugFlow) (err error) {
510
 	if len(drugflow) > 0 {
515
 	if len(drugflow) > 0 {
1397
 	Number                  string  `gorm:"column:number" json:"number" form:"number"`
1402
 	Number                  string  `gorm:"column:number" json:"number" form:"number"`
1398
 	BatchNumber             string  `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
1403
 	BatchNumber             string  `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
1399
 	Drug                    *Drug   `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"drug"`
1404
 	Drug                    *Drug   `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"drug"`
1405
+	WarehouseInfoId         int64   `gorm:"column:warehouse_info_id" json:"warehouse_info_id" form:"warehouse_info_id"`
1400
 }
1406
 }
1401
 
1407
 
1402
 func (DrugWarehouseOutInfo) TableName() string {
1408
 func (DrugWarehouseOutInfo) TableName() string {
1799
 	return info, err
1805
 	return info, err
1800
 }
1806
 }
1801
 
1807
 
1808
+func GetLastWarehousingByIdOne(warehousing_id int64, orgid int64) (models.WarehousingInfo, error) {
1809
+
1810
+	info := models.WarehousingInfo{}
1811
+	err = XTReadDB().Model(&info).Where("id = ? and good_id = ? and status = 1", warehousing_id, orgid).Find(&info).Error
1812
+	return info, err
1813
+}
1814
+
1802
 func UpDateWarehousingInfo(info *models.WarehousingInfo) (err error) {
1815
 func UpDateWarehousingInfo(info *models.WarehousingInfo) (err error) {
1803
 	err = writeDb.Save(&info).Error
1816
 	err = writeDb.Save(&info).Error
1804
 	return err
1817
 	return err
3168
 	return info, total, err
3181
 	return info, total, err
3169
 }
3182
 }
3170
 
3183
 
3184
+func GetAllGoodInfoStockList(page int64, limit int64, startime int64, endtime int64, good_type int64, keyword string, orgid int64) (info []*models.GoodInfo, total int64, err error) {
3185
+
3186
+	offset := (page - 1) * limit
3187
+	db := XTReadDB().Table("xt_good_information as x").Where("x.status= 1")
3188
+
3189
+	likeKey := "%" + keyword + "%"
3190
+	if len(likeKey) > 0 {
3191
+		db = db.Where("x.good_name like ?", likeKey)
3192
+	}
3193
+	if orgid > 0 {
3194
+		db = db.Where("x.org_id = ?", orgid)
3195
+	}
3196
+	if good_type > 0 {
3197
+		db = db.Where("x.good_type_id = ?", good_type)
3198
+	}
3199
+
3200
+	err = db.Count(&total).Offset(offset).Limit(limit).Order("x.ctime desc").Preload("StWarehousingInfo", "status= 1 and org_id =? and ctime>=? and ctime<=?", orgid, startime, endtime).Preload("CancelStockInfo", "status= 1 and org_id =? and ctime>=? and ctime<=?", orgid, startime, endtime).Find(&info).Error
3201
+	return info, total, err
3202
+}
3203
+
3171
 func GetStockListById(good_id int64, orgid int64, limit int64, page int64, startime int64, endtime int64) (info []*models.VmWarehousingInfo, total int64, err error) {
3204
 func GetStockListById(good_id int64, orgid int64, limit int64, page int64, startime int64, endtime int64) (info []*models.VmWarehousingInfo, total int64, err error) {
3172
 
3205
 
3173
 	offset := (page - 1) * limit
3206
 	offset := (page - 1) * limit
3514
 	return info, err
3547
 	return info, err
3515
 }
3548
 }
3516
 
3549
 
3550
+func GetDrugTotalCountSwx(id int64, orgid int64) (info models.VmDrugWarehouseInfo, err error) {
3551
+
3552
+	db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status = 1")
3553
+	if id > 0 {
3554
+		db = db.Where("x.id = ?", id)
3555
+	}
3556
+	if orgid > 0 {
3557
+		db = db.Where("x.org_id = ?", orgid)
3558
+	}
3559
+	err = db.Select("x.drug_id,sum(x.stock_max_number) as count,sum(x.stock_min_number) as stock_min_number,x.max_unit,x.min_unit").Find(&info).Error
3560
+	return info, err
3561
+}
3562
+
3563
+func GetDrugTotalCountOne(drugid int64, orgid int64, id int64) (models.VmDrugWarehouseInfo, error) {
3564
+	info := models.VmDrugWarehouseInfo{}
3565
+	db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status = 1")
3566
+	if id == 0 {
3567
+		db = db.Where("id = ?", id)
3568
+	}
3569
+	if drugid > 0 {
3570
+		db = db.Where("x.drug_id = ?", drugid)
3571
+	}
3572
+	if orgid > 0 {
3573
+		db = db.Where("x.org_id = ?", orgid)
3574
+	}
3575
+	err = db.Select("x.drug_id,x.stock_max_number,x.stock_min_number,x.max_unit,x.min_unit").Find(&info).Error
3576
+	return info, err
3577
+}
3578
+
3517
 func GetDrugByGoodId(drugid int64) (models.BaseDrugLib, error) {
3579
 func GetDrugByGoodId(drugid int64) (models.BaseDrugLib, error) {
3518
 
3580
 
3519
 	lib := models.BaseDrugLib{}
3581
 	lib := models.BaseDrugLib{}
3668
 	return info, err
3730
 	return info, err
3669
 }
3731
 }
3670
 
3732
 
3733
+func UpdateCancelInfo(id int64) (models.CancelStock, error) {
3734
+	stock := models.CancelStock{}
3735
+	err := XTWriteDB().Model(&stock).Where("id=? and status = 1", id).Updates(map[string]interface{}{"status": 0}).Error
3736
+	return stock, err
3737
+}
3738
+
3671
 func GetStockBatchNumber(id int64, orgid int64) (info []*models.WarehousingInfo, err error) {
3739
 func GetStockBatchNumber(id int64, orgid int64) (info []*models.WarehousingInfo, err error) {
3672
 
3740
 
3673
 	err = XTReadDB().Model(&info).Where("good_id = ? and org_id = ? and status = 1 and number <> ''", id, orgid).Group("number").Find(&info).Error
3741
 	err = XTReadDB().Model(&info).Where("good_id = ? and org_id = ? and status = 1 and number <> ''", id, orgid).Group("number").Find(&info).Error
3686
 	return stock, err
3754
 	return stock, err
3687
 }
3755
 }
3688
 
3756
 
3757
+func GetStockFlowBatchNumberOne(id int64, goodid int64) (stock []*models.VmStockFlowOne, err error) {
3758
+
3759
+	db := XTReadDB().Table("xt_stock_flow as x").Where("x.status = 1")
3760
+	table := XTReadDB().Table("xt_patients as t").Where("t.status = 1")
3761
+	fmt.Println(table)
3762
+	tableone := XTReadDB().Table("xt_good_information as o").Where("o.status = 1")
3763
+	fmt.Println(tableone)
3764
+	if id > 0 {
3765
+		db = db.Where("x.warehouse_out_id = ?", id)
3766
+	}
3767
+	if goodid > 0 {
3768
+		db = db.Where("x.good_id = ?", goodid)
3769
+	}
3770
+
3771
+	err = db.Select("x.id,x.warehousing_id,x.good_id,x.number,x.count,x.patient_id,x.system_time,x.is_sys,x.warehousing_order,x.warehouse_out_id,x.warehouse_out_order_number,x.price,x.product_date,x.expire_date,x.ctime,o.packing_unit,t.name").Joins("left join xt_patients as t on t.id = x.patient_id").Joins("left join xt_good_information as o on o.id = x.good_id").Scan(&stock).Error
3772
+	//err = XTReadDB().Model(&stock).Where("warehouse_out_id = ? and good_id = ? and status = 1", id, goodid).Find(&stock).Error
3773
+	return stock, err
3774
+}
3775
+
3689
 func GetDrugBatchNumber(drug_id int64, orgid int64) (info []*models.DrugWarehouseInfo, err error) {
3776
 func GetDrugBatchNumber(drug_id int64, orgid int64) (info []*models.DrugWarehouseInfo, err error) {
3690
 
3777
 
3691
 	err = XTReadDB().Model(&info).Where("drug_id = ? and org_id = ? and status = 1 and batch_number <>''", drug_id, orgid).Find(&info).Error
3778
 	err = XTReadDB().Model(&info).Where("drug_id = ? and org_id = ? and status = 1 and batch_number <>''", drug_id, orgid).Find(&info).Error
3814
 	return err
3901
 	return err
3815
 }
3902
 }
3816
 
3903
 
3904
+func UpdatedStockFlow(flow models.VmStockFlow) error {
3905
+	err := XTWriteDB().Save(&flow).Error
3906
+	return err
3907
+}
3908
+
3909
+func GetStockFlowIsExsit(warehousing_id int64, patient_id int64, record_time int64, good_id int64) (*models.VmStockFlow, error) {
3910
+
3911
+	flow := models.VmStockFlow{}
3912
+	var err error
3913
+	err = XTReadDB().Model(&flow).Where("warehousing_id = ? and patient_id = ? and system_time = ? and good_id = ? and status = 1", warehousing_id, patient_id, record_time, good_id).Find(&flow).Error
3914
+	if err == gorm.ErrRecordNotFound {
3915
+		return nil, err
3916
+	}
3917
+	if err != nil {
3918
+		return nil, err
3919
+	}
3920
+	return &flow, nil
3921
+}
3922
+
3817
 func GetWarehouseOutInfoIsExist(id int64) (*models.WarehouseOutInfo, error) {
3923
 func GetWarehouseOutInfoIsExist(id int64) (*models.WarehouseOutInfo, error) {
3818
 
3924
 
3819
 	info := models.WarehouseOutInfo{}
3925
 	info := models.WarehouseOutInfo{}
4119
 	err := XTReadDB().Model(&info).Where("warehouse_info_id  = ? and good_id = ? and status = 1", id, goodid).Find(&info).Error
4225
 	err := XTReadDB().Model(&info).Where("warehouse_info_id  = ? and good_id = ? and status = 1", id, goodid).Find(&info).Error
4120
 	return info, err
4226
 	return info, err
4121
 }
4227
 }
4228
+
4229
+func UpdateStockFlow(flow models.VmStockFlow, goodid int64, warehousing_id int64) error {
4230
+
4231
+	err := XTWriteDB().Model(&flow).Where("good_id = ? and warehousing_id= ? and status = 1", goodid, warehousing_id).Updates(map[string]interface{}{"count": flow.Count}).Error
4232
+	return err
4233
+}
4234
+
4235
+func UpdateDrugFlow(flow models.DrugFlow, drugid int64, warehousing_id int64) error {
4236
+
4237
+	drugFlow := models.DrugFlow{}
4238
+	err := XTWriteDB().Model(&drugFlow).Where("drug_id = ? and warehousing_id= ? and status = 1", drugid, warehousing_id).Updates(map[string]interface{}{"count": flow.Count}).Error
4239
+	return err
4240
+}
4241
+
4242
+func UpdateDrugCancel(id int64) (models.DrugCancelStock, error) {
4243
+
4244
+	stock := models.DrugCancelStock{}
4245
+
4246
+	err := XTWriteDB().Model(&stock).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"status": 0}).Error
4247
+	return stock, err
4248
+}
4249
+
4250
+func GetDrugWarehouseOutInfo(warehouse_info_id int64, drug_id int64) (info []*models.DrugWarehouseOutInfo, err error) {
4251
+
4252
+	db := XTReadDB().Model(&info)
4253
+	if warehouse_info_id > 0 {
4254
+		db = db.Where("warehouse_info_id = ?", warehouse_info_id)
4255
+	}
4256
+	if drug_id > 0 {
4257
+		db = db.Where("drug_id = ? and status =1", drug_id)
4258
+	}
4259
+
4260
+	err = db.Find(&info).Error
4261
+	return info, err
4262
+}
4263
+
4264
+func GetCancelDrugStockOutInfo(warehouse_info_id int64, drug_id int64) (info []*models.DrugCancelStockInfo, err error) {
4265
+
4266
+	err = XTReadDB().Model(&info).Where("batch_number_id =? and drug_id = ? and status = 1", warehouse_info_id, drug_id).Find(&info).Error
4267
+	return info, err
4268
+}

+ 218 - 44
service/warhouse_service.go Ver arquivo

141
 			ExpiryDate:              warehouse.ExpiryDate,
141
 			ExpiryDate:              warehouse.ExpiryDate,
142
 			PatientId:               advice.PatientId,
142
 			PatientId:               advice.PatientId,
143
 			Count:                   count,
143
 			Count:                   count,
144
+			WarehouseInfoId:         warehouse.ID,
144
 		}
145
 		}
145
 
146
 
146
 		fmt.Println("单据号2232322323232323232323232323232323", warehouseout.WarehouseOutOrderNumber)
147
 		fmt.Println("单据号2232322323232323232323232323232323", warehouseout.WarehouseOutOrderNumber)
181
 			UpdatedDrugWarehouseOutInfo(warehouseOutInfo, advice.DrugId, advice.PatientId, advice.RecordDate, advice.UserOrgId)
182
 			UpdatedDrugWarehouseOutInfo(warehouseOutInfo, advice.DrugId, advice.PatientId, advice.RecordDate, advice.UserOrgId)
182
 		}
183
 		}
183
 		details := &models.DrugAutomaticReduceDetail{
184
 		details := &models.DrugAutomaticReduceDetail{
184
-			WarehouseOutId:          warehouseOutInfo.ID,
185
-			WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
185
+			WarehouseOutId:          warehouseout.ID,
186
+			WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
186
 			PatientId:               advice.PatientId,
187
 			PatientId:               advice.PatientId,
187
 			Ctime:                   time.Now().Unix(),
188
 			Ctime:                   time.Now().Unix(),
188
 			Mtime:                   time.Now().Unix(),
189
 			Mtime:                   time.Now().Unix(),
256
 			ExpiryDate:              warehouse.ExpiryDate,
257
 			ExpiryDate:              warehouse.ExpiryDate,
257
 			PatientId:               advice.PatientId,
258
 			PatientId:               advice.PatientId,
258
 			Count:                   count,
259
 			Count:                   count,
260
+			WarehouseInfoId:         warehouse.ID,
259
 		}
261
 		}
260
-
261
-		errOne := AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
262
-		if errOne != nil {
263
-			return errOne
264
-		} else {
265
-			details := &models.DrugAutomaticReduceDetail{
266
-				WarehouseOutId:          warehouseOutInfo.ID,
267
-				WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
268
-				PatientId:               advice.PatientId,
269
-				Ctime:                   time.Now().Unix(),
270
-				Mtime:                   time.Now().Unix(),
271
-				Status:                  1,
272
-				RecordTime:              advice.RecordDate,
273
-				OrgId:                   orgID,
274
-				DrugId:                  advice.DrugId,
275
-				Count:                   count,
276
-				CountUnit:               advice.PrescribingNumberUnit,
277
-			}
278
-			errTwo := AddSigleDrugAutoReduceRecordInfo(details)
279
-			if errTwo != nil {
280
-				return errTwo
262
+		//查询是否存在数据
263
+		_, errcodes := GetDrugWarehouseOutInfoIsExit(advice.DrugId, advice.PatientId, advice.RecordDate)
264
+		if errcodes == gorm.ErrRecordNotFound {
265
+			errOne := AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
266
+			if errOne != nil {
267
+				return errOne
281
 			}
268
 			}
269
+		} else if errcodes == nil {
270
+			UpdatedDrugWarehouseOutInfo(warehouseOutInfo, advice.DrugId, advice.PatientId, advice.RecordDate, advice.UserOrgId)
282
 		}
271
 		}
272
+
273
+		details := &models.DrugAutomaticReduceDetail{
274
+			WarehouseOutId:          warehouseout.ID,
275
+			WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
276
+			PatientId:               advice.PatientId,
277
+			Ctime:                   time.Now().Unix(),
278
+			Mtime:                   time.Now().Unix(),
279
+			Status:                  1,
280
+			RecordTime:              advice.RecordDate,
281
+			OrgId:                   orgID,
282
+			DrugId:                  advice.DrugId,
283
+			Count:                   stock_number,
284
+			CountUnit:               advice.PrescribingNumberUnit,
285
+		}
286
+		errTwo := AddSigleDrugAutoReduceRecordInfo(details)
287
+		if errTwo != nil {
288
+			return errTwo
289
+		}
290
+
283
 		// 出库完成后,要将该批次库存清零
291
 		// 出库完成后,要将该批次库存清零
284
 		warehouse.StockMaxNumber = 0
292
 		warehouse.StockMaxNumber = 0
285
 		warehouse.StockMinNumber = 0
293
 		warehouse.StockMinNumber = 0
286
 		warehouse.Mtime = time.Now().Unix()
294
 		warehouse.Mtime = time.Now().Unix()
287
 		errThree := UpDateDrugWarehouseInfoByStock(&warehouse)
295
 		errThree := UpDateDrugWarehouseInfoByStock(&warehouse)
296
+
288
 		if errThree != nil {
297
 		if errThree != nil {
289
 			return errThree
298
 			return errThree
290
 		}
299
 		}
300
+
301
+		drugflow := models.DrugFlow{
302
+			WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
303
+			WarehouseOutId:          warehouseout.ID,
304
+			DrugId:                  advice.DrugId,
305
+			Number:                  warehouse.Number,
306
+			ProductDate:             warehouse.ProductDate,
307
+			ExpireDate:              warehouse.ExpiryDate,
308
+			Count:                   stock_number,
309
+			Price:                   baseInfo.RetailPrice,
310
+			Status:                  1,
311
+			Ctime:                   time.Now().Unix(),
312
+			UserOrgId:               orgID,
313
+			Manufacturer:            warehouse.Manufacturer,
314
+			Dealer:                  warehouse.Dealer,
315
+			BatchNumber:             warehouse.BatchNumber,
316
+			MaxUnit:                 advice.PrescribingNumberUnit,
317
+			ConsumableType:          3,
318
+			IsEdit:                  1,
319
+			Creator:                 advice.ExecutionStaff,
320
+			IsSys:                   1,
321
+			PatientId:               advice.PatientId,
322
+		}
323
+
324
+		CreateDrugFlowOne(drugflow)
291
 		// 清零完该库存后,还有剩余出库未出完,进行对应的递归操作
325
 		// 清零完该库存后,还有剩余出库未出完,进行对应的递归操作
292
 		prescribingNumber_two_temp := deliver_number - stock_number
326
 		prescribingNumber_two_temp := deliver_number - stock_number
293
 		overPlusNumber := float64(prescribingNumber_two_temp)
327
 		overPlusNumber := float64(prescribingNumber_two_temp)
419
 			ProductDate:             warehouse.ProductDate,
453
 			ProductDate:             warehouse.ProductDate,
420
 			ExpiryDate:              warehouse.ExpiryDate,
454
 			ExpiryDate:              warehouse.ExpiryDate,
421
 			PatientId:               advice.PatientId,
455
 			PatientId:               advice.PatientId,
456
+			WarehouseInfoId:         warehouse.ID,
422
 		}
457
 		}
423
 
458
 
424
 		warehouseOutInfo.Count = count
459
 		warehouseOutInfo.Count = count
461
 		}
496
 		}
462
 
497
 
463
 		details := &models.DrugAutomaticReduceDetail{
498
 		details := &models.DrugAutomaticReduceDetail{
464
-			WarehouseOutId:          warehouseOutInfo.ID,
465
-			WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
499
+			WarehouseOutId:          warehouseout.ID,
500
+			WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
466
 			PatientId:               advice.PatientId,
501
 			PatientId:               advice.PatientId,
467
 			Ctime:                   time.Now().Unix(),
502
 			Ctime:                   time.Now().Unix(),
468
 			Mtime:                   time.Now().Unix(),
503
 			Mtime:                   time.Now().Unix(),
535
 			ProductDate:             warehouse.ProductDate,
570
 			ProductDate:             warehouse.ProductDate,
536
 			ExpiryDate:              warehouse.ExpiryDate,
571
 			ExpiryDate:              warehouse.ExpiryDate,
537
 			PatientId:               advice.PatientId,
572
 			PatientId:               advice.PatientId,
573
+			WarehouseInfoId:         warehouse.ID,
538
 		}
574
 		}
539
 
575
 
540
 		warehouseOutInfo.Count = count
576
 		warehouseOutInfo.Count = count
548
 			Number:                  warehouse.Number,
584
 			Number:                  warehouse.Number,
549
 			ProductDate:             warehouse.ProductDate,
585
 			ProductDate:             warehouse.ProductDate,
550
 			ExpireDate:              warehouse.ExpiryDate,
586
 			ExpireDate:              warehouse.ExpiryDate,
551
-			Count:                   count,
587
+			Count:                   stock_number,
552
 			Price:                   baseInfo.RetailPrice,
588
 			Price:                   baseInfo.RetailPrice,
553
 			Status:                  1,
589
 			Status:                  1,
554
 			Ctime:                   time.Now().Unix(),
590
 			Ctime:                   time.Now().Unix(),
577
 			UpdatedDrugWarehouseOutInfo(warehouseOutInfo, advice.DrugId, advice.PatientId, advice.RecordDate, advice.UserOrgId)
613
 			UpdatedDrugWarehouseOutInfo(warehouseOutInfo, advice.DrugId, advice.PatientId, advice.RecordDate, advice.UserOrgId)
578
 		}
614
 		}
579
 		details := &models.DrugAutomaticReduceDetail{
615
 		details := &models.DrugAutomaticReduceDetail{
580
-			WarehouseOutId:          warehouseOutInfo.ID,
581
-			WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
616
+			WarehouseOutId:          warehouseout.ID,
617
+			WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
582
 			PatientId:               advice.PatientId,
618
 			PatientId:               advice.PatientId,
583
 			Ctime:                   time.Now().Unix(),
619
 			Ctime:                   time.Now().Unix(),
584
 			Mtime:                   time.Now().Unix(),
620
 			Mtime:                   time.Now().Unix(),
668
 			Count:                   advice.Count,
704
 			Count:                   advice.Count,
669
 			RetailPrice:             advice.RetailPrice,
705
 			RetailPrice:             advice.RetailPrice,
670
 			Price:                   advice.Price,
706
 			Price:                   advice.Price,
707
+			WarehouseInfoId:         advice.WarehouseInfoId,
671
 		}
708
 		}
672
 
709
 
673
 		warehouseOutInfo.Count = prescribingNumber
710
 		warehouseOutInfo.Count = prescribingNumber
872
 func ConsumablesDelivery(orgID int64, patient_id int64, record_time int64, goods *models.DialysisBeforePrepare, warehouseOut *models.WarehouseOut, count int64) (err error) {
909
 func ConsumablesDelivery(orgID int64, patient_id int64, record_time int64, goods *models.DialysisBeforePrepare, warehouseOut *models.WarehouseOut, count int64) (err error) {
873
 
910
 
874
 	fmt.Println("count23232323232323232323232323", count)
911
 	fmt.Println("count23232323232323232323232323", count)
912
+	fmt.Println("hhhh2h3h3h2h23h32hh23h32h23", goods.Count)
875
 	// 判断处方里药品单位是拆零单位还是包装单位,	如果是包装单位,则根据规格,将包装数量转为拆零数量
913
 	// 判断处方里药品单位是拆零单位还是包装单位,	如果是包装单位,则根据规格,将包装数量转为拆零数量
876
 	var deliver_number int64 = 0
914
 	var deliver_number int64 = 0
877
 	var stock_number int64 = 0
915
 	var stock_number int64 = 0
885
 	warehouse, err := FindFirstWarehousingInfoByStock(goods.GoodId, goods.GoodTypeId)
923
 	warehouse, err := FindFirstWarehousingInfoByStock(goods.GoodId, goods.GoodTypeId)
886
 	if err != nil {
924
 	if err != nil {
887
 
925
 
888
-		fmt.Println("进来232323232323234343434343434343434343", warehouse.StockCount)
889
-
890
 		return errors.New("库存数量不足")
926
 		return errors.New("库存数量不足")
891
 	}
927
 	}
892
 
928
 
897
 	info, _ := GetGoodInformationByGoodId(goods.GoodId)
933
 	info, _ := GetGoodInformationByGoodId(goods.GoodId)
898
 	// 当库存数量大于或等于出库数量的话,则正常出库该批次
934
 	// 当库存数量大于或等于出库数量的话,则正常出库该批次
899
 	if stock_number >= deliver_number {
935
 	if stock_number >= deliver_number {
936
+		fmt.Println("进来22323232323232323232233223323223322323")
900
 		warehouseOutInfo := &models.WarehouseOutInfo{
937
 		warehouseOutInfo := &models.WarehouseOutInfo{
901
 			WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
938
 			WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
902
 			WarehouseOutId:          warehouseOut.ID,
939
 			WarehouseOutId:          warehouseOut.ID,
974
 				IsSys:                   1,
1011
 				IsSys:                   1,
975
 				PatientId:               patient_id,
1012
 				PatientId:               patient_id,
976
 			}
1013
 			}
977
-			CreateStockFlowOne(flow)
1014
+			//查询流水是否存在
1015
+			exsit, errflow := GetStockFlowIsExsit(warehouseOut.ID, patient_id, record_time, goods.GoodId)
1016
+			fmt.Println("8888232322332323222332323223322332233232323232322323233223232332", exsit.Count+goods.Count)
1017
+
1018
+			if errflow == gorm.ErrRecordNotFound {
1019
+				CreateStockFlowOne(flow)
1020
+			} else if errflow == nil {
1021
+				flow := models.VmStockFlow{
1022
+					ID:                      exsit.ID,
1023
+					WarehouseOutId:          warehouseOut.ID,
1024
+					WarehousingId:           warehouse.ID,
1025
+					GoodId:                  goods.GoodId,
1026
+					Number:                  warehouse.Number,
1027
+					ProductDate:             warehouse.ProductDate,
1028
+					ExpireDate:              warehouse.ExpiryDate,
1029
+					Count:                   exsit.Count + goods.Count,
1030
+					Price:                   info.PackingPrice,
1031
+					Status:                  1,
1032
+					Ctime:                   time.Now().Unix(),
1033
+					UserOrgId:               orgID,
1034
+					Manufacturer:            info.Manufacturer,
1035
+					Dealer:                  info.Dealer,
1036
+					LicenseNumber:           warehouse.LicenseNumber,
1037
+					IsEdit:                  2,
1038
+					Creator:                 warehouseOut.Creater,
1039
+					SystemTime:              record_time,
1040
+					ConsumableType:          3,
1041
+					WarehouseOutDetailId:    warehouseOutInfo.ID,
1042
+					WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
1043
+					IsSys:                   1,
1044
+					PatientId:               patient_id,
1045
+					ReturnCount:             exsit.Count + (exsit.Count + deliver_number),
1046
+				}
1047
+				UpdatedStockFlow(flow)
1048
+			}
978
 			if errTwo != nil {
1049
 			if errTwo != nil {
979
 				return errTwo
1050
 				return errTwo
980
 			}
1051
 			}
981
 		} else if errcode == nil {
1052
 		} else if errcode == nil {
982
-			DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, goods.GoodId, goods.GoodTypeId)
983
-			CreateAutoReduceRecord(&details)
984
-			//插入库存流水表
1053
+
1054
+			fmt.Println("wodeeeeeeeeeeewewewewewewewewweewewewewewweewewew")
985
 			flow := models.VmStockFlow{
1055
 			flow := models.VmStockFlow{
986
 				WarehouseOutId:          warehouseOut.ID,
1056
 				WarehouseOutId:          warehouseOut.ID,
987
 				WarehousingId:           warehouse.ID,
1057
 				WarehousingId:           warehouse.ID,
1006
 				IsSys:                   1,
1076
 				IsSys:                   1,
1007
 				PatientId:               patient_id,
1077
 				PatientId:               patient_id,
1008
 			}
1078
 			}
1009
-			CreateStockFlowOne(flow)
1079
+			//查询流水是否存在
1080
+			exsit, errflow := GetStockFlowIsExsit(warehouseOut.ID, patient_id, record_time, goods.GoodId)
1081
+			fmt.Println("8888232322332323222332323223322332233232323232322323233223232332", exsit.Count+goods.Count)
1082
+
1083
+			if errflow == gorm.ErrRecordNotFound {
1084
+				CreateStockFlowOne(flow)
1085
+			} else if errflow == nil {
1086
+				flow := models.VmStockFlow{
1087
+					ID:                      exsit.ID,
1088
+					WarehouseOutId:          warehouseOut.ID,
1089
+					WarehousingId:           warehouse.ID,
1090
+					GoodId:                  goods.GoodId,
1091
+					Number:                  warehouse.Number,
1092
+					ProductDate:             warehouse.ProductDate,
1093
+					ExpireDate:              warehouse.ExpiryDate,
1094
+					Count:                   exsit.Count + goods.Count,
1095
+					Price:                   info.PackingPrice,
1096
+					Status:                  1,
1097
+					Ctime:                   time.Now().Unix(),
1098
+					UserOrgId:               orgID,
1099
+					Manufacturer:            info.Manufacturer,
1100
+					Dealer:                  info.Dealer,
1101
+					LicenseNumber:           warehouse.LicenseNumber,
1102
+					IsEdit:                  2,
1103
+					Creator:                 warehouseOut.Creater,
1104
+					SystemTime:              record_time,
1105
+					ConsumableType:          3,
1106
+					WarehouseOutDetailId:    warehouseOutInfo.ID,
1107
+					WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
1108
+					IsSys:                   1,
1109
+					PatientId:               patient_id,
1110
+					ReturnCount:             exsit.Count + (exsit.Count + deliver_number),
1111
+				}
1112
+				UpdatedStockFlow(flow)
1113
+			}
1114
+			DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, goods.GoodId, goods.GoodTypeId)
1115
+			CreateAutoReduceRecord(&details)
1116
+
1010
 		}
1117
 		}
1011
 
1118
 
1012
 		maxNumber = goods.Count
1119
 		maxNumber = goods.Count
1029
 
1136
 
1030
 		return nil
1137
 		return nil
1031
 	} else {
1138
 	} else {
1032
-
1139
+		fmt.Println("不进来22323232323232323232233223323223322323")
1033
 		// 当刚批次的库存数量小于出库数量的话,则先把该批次出库完后,再进行递归出库
1140
 		// 当刚批次的库存数量小于出库数量的话,则先把该批次出库完后,再进行递归出库
1034
 		warehouseOutInfo := &models.WarehouseOutInfo{
1141
 		warehouseOutInfo := &models.WarehouseOutInfo{
1035
 			WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
1142
 			WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
1056
 		warehouseOutInfo.Count = stock_number
1163
 		warehouseOutInfo.Count = stock_number
1057
 
1164
 
1058
 		_, errcodes := GetWarehouseOutInfoIsExistOne(goods.GoodId, goods.PatientId, record_time)
1165
 		_, errcodes := GetWarehouseOutInfoIsExistOne(goods.GoodId, goods.PatientId, record_time)
1059
-
1166
+		fmt.Println("hhhhh2h323233223232323", errcodes)
1060
 		if errcodes == gorm.ErrRecordNotFound {
1167
 		if errcodes == gorm.ErrRecordNotFound {
1061
 			errOne := AddSigleWarehouseOutInfo(warehouseOutInfo)
1168
 			errOne := AddSigleWarehouseOutInfo(warehouseOutInfo)
1062
 
1169
 
1072
 				ProductDate:             warehouse.ProductDate,
1179
 				ProductDate:             warehouse.ProductDate,
1073
 				ExpireDate:              warehouse.ExpiryDate,
1180
 				ExpireDate:              warehouse.ExpiryDate,
1074
 				Count:                   stock_number,
1181
 				Count:                   stock_number,
1075
-				Price:                   warehouse.Price,
1182
+				Price:                   info.PackingPrice,
1076
 				Status:                  1,
1183
 				Status:                  1,
1077
 				Ctime:                   time.Now().Unix(),
1184
 				Ctime:                   time.Now().Unix(),
1078
 				UserOrgId:               orgID,
1185
 				UserOrgId:               orgID,
1088
 				IsSys:                   1,
1195
 				IsSys:                   1,
1089
 				PatientId:               patient_id,
1196
 				PatientId:               patient_id,
1090
 			}
1197
 			}
1091
-			CreateStockFlowOne(flow)
1198
+			//查询流水是否存在
1199
+			exsit, errflows := GetStockFlowIsExsit(warehouse.ID, patient_id, record_time, goods.GoodId)
1200
+
1201
+			if errflows == gorm.ErrRecordNotFound {
1202
+				CreateStockFlowOne(flow)
1203
+			} else if errflows == nil {
1204
+				flow := models.VmStockFlow{
1205
+					ID:                      exsit.ID,
1206
+					WarehouseOutId:          warehouseOut.ID,
1207
+					WarehousingId:           warehouse.ID,
1208
+					GoodId:                  goods.GoodId,
1209
+					Number:                  warehouse.Number,
1210
+					ProductDate:             warehouse.ProductDate,
1211
+					ExpireDate:              warehouse.ExpiryDate,
1212
+					Count:                   exsit.Count + goods.Count,
1213
+					Price:                   info.PackingPrice,
1214
+					Status:                  1,
1215
+					Ctime:                   time.Now().Unix(),
1216
+					UserOrgId:               orgID,
1217
+					Manufacturer:            info.Manufacturer,
1218
+					Dealer:                  info.Dealer,
1219
+					LicenseNumber:           warehouse.LicenseNumber,
1220
+					IsEdit:                  2,
1221
+					Creator:                 warehouseOut.Creater,
1222
+					SystemTime:              record_time,
1223
+					ConsumableType:          3,
1224
+					WarehouseOutDetailId:    warehouseOutInfo.ID,
1225
+					WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
1226
+					IsSys:                   1,
1227
+					PatientId:               patient_id,
1228
+					ReturnCount:             exsit.Count + (exsit.Count + deliver_number),
1229
+				}
1230
+				UpdatedStockFlow(flow)
1231
+			}
1232
+
1092
 		} else if errcodes == nil {
1233
 		} else if errcodes == nil {
1234
+			fmt.Println("尽力3323232322323232323232323232323")
1093
 			goods.Count = deliver_number - stock_number
1235
 			goods.Count = deliver_number - stock_number
1094
-			//更新数量为  刚批次剩余数量  + 还有未出的数量
1095
-			warehouseOutInfo.Count = goods.Count + stock_number
1236
+			//更新数量为  批次剩余数量  + 还有未出的数量
1237
+			warehouseOutInfo.Count = stock_number
1096
 			UpdatedWarehouseOutInfo(warehouseOutInfo, goods.GoodId, goods.PatientId, record_time)
1238
 			UpdatedWarehouseOutInfo(warehouseOutInfo, goods.GoodId, goods.PatientId, record_time)
1097
 			//插入库存流水表
1239
 			//插入库存流水表
1098
 			flow := models.VmStockFlow{
1240
 			flow := models.VmStockFlow{
1102
 				Number:                  warehouse.Number,
1244
 				Number:                  warehouse.Number,
1103
 				ProductDate:             warehouse.ProductDate,
1245
 				ProductDate:             warehouse.ProductDate,
1104
 				ExpireDate:              warehouse.ExpiryDate,
1246
 				ExpireDate:              warehouse.ExpiryDate,
1105
-				Count:                   goods.Count + stock_number,
1106
-				Price:                   warehouse.Price,
1247
+				Count:                   stock_number,
1248
+				Price:                   info.PackingPrice,
1107
 				Status:                  1,
1249
 				Status:                  1,
1108
 				Ctime:                   time.Now().Unix(),
1250
 				Ctime:                   time.Now().Unix(),
1109
 				UserOrgId:               orgID,
1251
 				UserOrgId:               orgID,
1119
 				IsSys:                   1,
1261
 				IsSys:                   1,
1120
 				PatientId:               patient_id,
1262
 				PatientId:               patient_id,
1121
 			}
1263
 			}
1122
-			CreateStockFlowOne(flow)
1264
+			//查询流水是否存在
1265
+			exsit, errflows := GetStockFlowIsExsit(warehouse.ID, patient_id, record_time, goods.GoodId)
1266
+			if errflows == gorm.ErrRecordNotFound {
1267
+				CreateStockFlowOne(flow)
1268
+			} else if errflows == nil {
1269
+				fmt.Println("尽力3323232322323232323232323232323", exsit.Count+goods.Count)
1270
+				flow := models.VmStockFlow{
1271
+					ID:                      exsit.ID,
1272
+					WarehouseOutId:          warehouseOut.ID,
1273
+					WarehousingId:           warehouse.ID,
1274
+					GoodId:                  goods.GoodId,
1275
+					Number:                  warehouse.Number,
1276
+					ProductDate:             warehouse.ProductDate,
1277
+					ExpireDate:              warehouse.ExpiryDate,
1278
+					Count:                   exsit.Count + goods.Count,
1279
+					Price:                   info.PackingPrice,
1280
+					Status:                  1,
1281
+					Ctime:                   time.Now().Unix(),
1282
+					UserOrgId:               orgID,
1283
+					Manufacturer:            info.Manufacturer,
1284
+					Dealer:                  info.Dealer,
1285
+					LicenseNumber:           warehouse.LicenseNumber,
1286
+					IsEdit:                  2,
1287
+					Creator:                 warehouseOut.Creater,
1288
+					SystemTime:              record_time,
1289
+					ConsumableType:          3,
1290
+					WarehouseOutDetailId:    warehouseOutInfo.ID,
1291
+					WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
1292
+					IsSys:                   1,
1293
+					PatientId:               patient_id,
1294
+				}
1295
+				UpdatedStockFlow(flow)
1296
+			}
1123
 		}
1297
 		}
1124
 
1298
 
1125
 		// 出库完成后,要将该批次库存清零
1299
 		// 出库完成后,要将该批次库存清零