Browse Source

耗材参数

XMLWAN 3 years ago
parent
commit
d102e08974

+ 1 - 1
controllers/data_api_controller.go View File

@@ -400,7 +400,7 @@ func configFormData(dataconfig *models.Dataconfig, data []byte) (code int) {
400 400
 	}
401 401
 	dataconfig.Module = module
402 402
 
403
-	if module == "education" || module == "summary" || module == "course_disease" || module == "rescue_record" || module == "nursing_record" || module == "special_record" || module == "special_treatment" {
403
+	if module == "education" || module == "summary" || module == "course_disease" || module == "rescue_record" || module == "nursing_record" || module == "special_record" || module == "special_treatment" || module == "template_summary" || module == "template_plan" {
404 404
 		if configBody["title"] == nil || reflect.TypeOf(configBody["title"]).String() != "string" {
405 405
 			utils.ErrorLog("title")
406 406
 			code = enums.ErrorCodeParamWrong

+ 339 - 39
controllers/drug_stock_api_contorller.go View File

@@ -1237,12 +1237,42 @@ func (c *StockDrugApiController) CreateDrugWarehouseOut() {
1237 1237
 			}
1238 1238
 		}
1239 1239
 	}
1240
-
1240
+	var total_count int64
1241
+	var prescribing_number_total int64
1241 1242
 	//调用出库逻辑
1242 1243
 	for _, item := range warehousingOutInfo {
1243 1244
 		//获取药品库存
1244 1245
 		info, _ := service.GetDrugTotalCount(item.DrugId, item.OrgId)
1245
-		if item.Count > info.Count {
1246
+		//查询改药品信息
1247
+		medical, _ := service.GetBaseDrugMedical(item.DrugId)
1248
+		//判断单位是否相等
1249
+		if medical.MaxUnit == item.CountUnit {
1250
+			//转化为最小单位
1251
+			total_count = info.Count * medical.MinNumber
1252
+			prescribing_number_total = item.Count * medical.MinNumber
1253
+		}
1254
+		if medical.MinUnit == item.CountUnit {
1255
+			total_count = info.Count
1256
+			prescribing_number_total = item.Count
1257
+		}
1258
+
1259
+		fmt.Println("数量一", prescribing_number_total)
1260
+		fmt.Println("数量二", total_count)
1261
+		//判断单位
1262
+		if total_count == 0 {
1263
+			goodObj, _ := service.GetDrugByGoodId(item.DrugId)
1264
+			c.ServeSuccessJSON(map[string]interface{}{
1265
+				"msg":        "1",
1266
+				"drug_name":  goodObj.DrugName,
1267
+				"dose":       goodObj.Dose,
1268
+				"dose_unit":  goodObj.DoseUnit,
1269
+				"min_number": goodObj.MinNumber,
1270
+				"min_unit":   goodObj.MinUnit,
1271
+				"max_unit":   goodObj.MaxUnit,
1272
+			})
1273
+			return
1274
+		}
1275
+		if prescribing_number_total > total_count {
1246 1276
 
1247 1277
 			goodObj, _ := service.GetDrugByGoodId(item.DrugId)
1248 1278
 			c.ServeSuccessJSON(map[string]interface{}{
@@ -1269,14 +1299,6 @@ func (c *StockDrugApiController) CreateDrugWarehouseOut() {
1269 1299
 
1270 1300
 	}
1271 1301
 
1272
-	//errs := service.CreateDrugWarehousingOutInfo(warehousingOutInfo)
1273
-	//info, _ := service.FindLastDrugWarehousingOutInfo(warehouseOut.WarehouseOutOrderNumber)
1274
-	//if errs != nil {
1275
-	//	utils.ErrorLog(errs.Error())
1276
-	//	c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockOutFail)
1277
-	//	return
1278
-	//}
1279
-
1280 1302
 	c.ServeSuccessJSON(map[string]interface{}{
1281 1303
 		"msg":        "2",
1282 1304
 		"drug_name":  "",
@@ -1442,7 +1464,8 @@ func (c *StockDrugApiController) EditDrugWarehouseOut() {
1442 1464
 
1443 1465
 	var warehousingOutInfo []*models.DrugWarehouseOutInfo
1444 1466
 	var upDateWarehouseOutInfos []*models.DrugWarehouseOutInfo
1445
-	//var drugFlow  []*models.DrugFlow
1467
+
1468
+	var drugFlow []*models.DrugFlow
1446 1469
 	if dataBody["stockOut"] != nil && reflect.TypeOf(dataBody["stockOut"]).String() == "[]interface {}" {
1447 1470
 		thisStockOut, _ := dataBody["stockOut"].([]interface{})
1448 1471
 		if len(thisStockOut) > 0 {
@@ -1497,6 +1520,7 @@ func (c *StockDrugApiController) EditDrugWarehouseOut() {
1497 1520
 
1498 1521
 				batch_number := items["batch_number"].(string)
1499 1522
 				number := items["number"].(string)
1523
+				max_unit := items["count_unit"].(string)
1500 1524
 
1501 1525
 				var productDates int64
1502 1526
 				var expiryDates int64
@@ -1527,6 +1551,8 @@ func (c *StockDrugApiController) EditDrugWarehouseOut() {
1527 1551
 					}
1528 1552
 
1529 1553
 				}
1554
+				fmt.Println("生产日期22222222222222222222222222", expiryDates)
1555
+				fmt.Println("生产日期22222222222222222222222222", productDates)
1530 1556
 				if id == 0 {
1531 1557
 					warehouseOutInfo := &models.DrugWarehouseOutInfo{
1532 1558
 						WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
@@ -1554,30 +1580,31 @@ func (c *StockDrugApiController) EditDrugWarehouseOut() {
1554 1580
 					}
1555 1581
 					warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
1556 1582
 
1557
-					//drugflow := &models.DrugFlow{
1558
-					//  WarehousingOrder: warehousing.WarehousingOrder,
1559
-					//  WarehousingId:    warehousing.ID,
1560
-					//  DrugId:           drug_id,
1561
-					//  Number:           number,
1562
-					//  ProductDate:      productDates,
1563
-					//  ExpireDate:       expiryDates,
1564
-					//  Count:            warehousing_count,
1565
-					//  Price:            last_price,
1566
-					//  Status:           1,
1567
-					//  Ctime:            ctime,
1568
-					//  UserOrgId:        adminUserInfo.CurrentOrgId,
1569
-					//  Manufacturer:     manufacturer,
1570
-					//  Dealer:           dealer,
1571
-					//  BatchNumber:      batch_number,
1572
-					//  MaxUnit:          max_unit,
1573
-					//  MinUnit:          min_unit,
1574
-					//  ConsumableType:   1,
1575
-					//  IsEdit:           1,
1576
-					//  Creator:          adminUserInfo.AdminUser.Id,
1577
-					//  IsSys:0,
1578
-					//}
1579
-					//
1580
-					//drugFlow = append(drugFlow,drugflow)
1583
+					drugflow := &models.DrugFlow{
1584
+						WarehousingOrder:        "",
1585
+						WarehousingId:           0,
1586
+						DrugId:                  drug_id,
1587
+						Number:                  number,
1588
+						ProductDate:             productDates,
1589
+						ExpireDate:              expiryDates,
1590
+						Count:                   count,
1591
+						Price:                   price,
1592
+						Status:                  1,
1593
+						Ctime:                   ctime,
1594
+						UserOrgId:               adminUserInfo.CurrentOrgId,
1595
+						Manufacturer:            manufacturer,
1596
+						Dealer:                  dealer,
1597
+						BatchNumber:             batch_number,
1598
+						MaxUnit:                 max_unit,
1599
+						ConsumableType:          1,
1600
+						IsEdit:                  1,
1601
+						Creator:                 adminUserInfo.AdminUser.Id,
1602
+						IsSys:                   0,
1603
+						WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
1604
+						WarehouseOutId:          warehouseOut.ID,
1605
+					}
1606
+
1607
+					drugFlow = append(drugFlow, drugflow)
1581 1608
 
1582 1609
 				} else {
1583 1610
 					if items["is_sys"] == nil || reflect.TypeOf(items["is_sys"]).String() != "float64" {
@@ -1621,18 +1648,283 @@ func (c *StockDrugApiController) EditDrugWarehouseOut() {
1621 1648
 						CountUnit:               count_unit,
1622 1649
 					}
1623 1650
 					upDateWarehouseOutInfos = append(upDateWarehouseOutInfos, warehouseOutInfo)
1651
+
1652
+					drugflow := &models.DrugFlow{
1653
+						WarehousingOrder:        "",
1654
+						WarehousingId:           0,
1655
+						DrugId:                  drug_id,
1656
+						Number:                  number,
1657
+						ProductDate:             productDates,
1658
+						ExpireDate:              expiryDates,
1659
+						Count:                   count,
1660
+						Price:                   price,
1661
+						Status:                  1,
1662
+						Ctime:                   ctime,
1663
+						UserOrgId:               adminUserInfo.CurrentOrgId,
1664
+						Manufacturer:            manufacturer,
1665
+						Dealer:                  dealer,
1666
+						BatchNumber:             batch_number,
1667
+						MaxUnit:                 max_unit,
1668
+						ConsumableType:          1,
1669
+						IsEdit:                  1,
1670
+						Creator:                 adminUserInfo.AdminUser.Id,
1671
+						IsSys:                   0,
1672
+						WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
1673
+						WarehouseOutId:          warehouseOut.ID,
1674
+					}
1675
+
1676
+					drugFlow = append(drugFlow, drugflow)
1624 1677
 				}
1625 1678
 			}
1626 1679
 		}
1627 1680
 	}
1628 1681
 	var errs error
1629 1682
 	if len(warehousingOutInfo) > 0 {
1630
-		errs = service.CreateDrugWarehousingOutInfo(warehousingOutInfo)
1683
+
1684
+		var total_count int64
1685
+		var prescribing_number_total int64
1686
+		//调用出库逻辑
1687
+		for _, item := range warehousingOutInfo {
1688
+			//获取药品库存
1689
+			info, _ := service.GetDrugTotalCount(item.DrugId, item.OrgId)
1690
+			//查询改药品信息
1691
+			medical, _ := service.GetBaseDrugMedical(item.DrugId)
1692
+			//判断单位是否相等
1693
+			if medical.MaxUnit == item.CountUnit {
1694
+				//转化为最小单位
1695
+				total_count = info.Count * medical.MinNumber
1696
+				prescribing_number_total = item.Count * medical.MinNumber
1697
+			}
1698
+			if medical.MinUnit == item.CountUnit {
1699
+				total_count = info.Count
1700
+				prescribing_number_total = item.Count
1701
+			}
1702
+
1703
+			fmt.Println("数量一", prescribing_number_total)
1704
+			fmt.Println("数量二", total_count)
1705
+			//判断单位
1706
+			if total_count == 0 {
1707
+				goodObj, _ := service.GetDrugByGoodId(item.DrugId)
1708
+				c.ServeSuccessJSON(map[string]interface{}{
1709
+					"msg":        "1",
1710
+					"drug_name":  goodObj.DrugName,
1711
+					"dose":       goodObj.Dose,
1712
+					"dose_unit":  goodObj.DoseUnit,
1713
+					"min_number": goodObj.MinNumber,
1714
+					"min_unit":   goodObj.MinUnit,
1715
+					"max_unit":   goodObj.MaxUnit,
1716
+				})
1717
+				return
1718
+			}
1719
+			if prescribing_number_total > total_count {
1720
+
1721
+				goodObj, _ := service.GetDrugByGoodId(item.DrugId)
1722
+				c.ServeSuccessJSON(map[string]interface{}{
1723
+					"msg":        "1",
1724
+					"drug_name":  goodObj.DrugName,
1725
+					"dose":       goodObj.Dose,
1726
+					"dose_unit":  goodObj.DoseUnit,
1727
+					"min_number": goodObj.MinNumber,
1728
+					"min_unit":   goodObj.MinUnit,
1729
+					"max_unit":   goodObj.MaxUnit,
1730
+				})
1731
+				return
1732
+			} else {
1733
+				errs = service.CreateDrugWarehousingOutInfo(warehousingOutInfo)
1734
+				service.CreateDrugFlow(drugFlow)
1735
+				// 出库流程
1736
+				// 1.查询改药品在药品库的规格信息,并将处方里的规格进行换算(尽量将拆零单位转换成包装单位)
1737
+				drup, _ := service.FindBaseDrugLibRecord(item.OrgId, item.DrugId)
1738
+				if drup.ID > 0 {
1739
+					prescribingNumber := item.Count
1740
+					service.AutoDrugDeliverInfo(item.OrgId, prescribingNumber, &tempWarehouseOut, &drup, item)
1741
+				}
1742
+			}
1743
+
1744
+		}
1631 1745
 	}
1632 1746
 
1633 1747
 	if len(upDateWarehouseOutInfos) > 0 {
1634 1748
 		for _, item := range upDateWarehouseOutInfos {
1635
-			errs = service.UpDateDrugWarehouseOutInfo(item)
1749
+			//获取药品库存
1750
+			info, _ := service.GetDrugTotalCount(item.DrugId, item.OrgId)
1751
+			//查询改药品信息
1752
+			medical, _ := service.GetBaseDrugMedical(item.DrugId)
1753
+			//查询最后一次出库记录
1754
+			outInfo, _ := service.GetLastDrugWarehouseOutInfo(item.DrugId, item.WarehouseOutId, item.OrgId)
1755
+			var min_number int64 //最后一次库存
1756
+			var max_number int64 //当前库存
1757
+			var all_number int64 //总库存
1758
+			var cha_number int64 //库存差
1759
+			var maxNumber int64
1760
+			var minNumber int64
1761
+
1762
+			if medical.MaxUnit == outInfo.CountUnit {
1763
+				//转为最小单位
1764
+				min_number = outInfo.Count * medical.MinNumber
1765
+			}
1766
+
1767
+			if medical.MinUnit == outInfo.CountUnit {
1768
+				min_number = outInfo.Count
1769
+			}
1770
+
1771
+			fmt.Println("单位1", medical.MaxUnit)
1772
+			fmt.Println("单位2", item.CountUnit)
1773
+			if medical.MaxUnit == item.CountUnit {
1774
+				max_number = item.Count * medical.MinNumber
1775
+			}
1776
+
1777
+			if medical.MinUnit == item.CountUnit {
1778
+				max_number = outInfo.Count
1779
+			}
1780
+
1781
+			all_number = info.Count*medical.MinNumber + info.StockMinNumber
1782
+			fmt.Println("总库存223232", all_number)
1783
+			fmt.Println("当前库存", max_number)
1784
+			////比较当前出库数量 和 最后一次出库数量,正常出库
1785
+			if max_number <= min_number {
1786
+				errs = service.UpDateDrugWarehouseOutInfo(item)
1787
+				cha_number = min_number - max_number
1788
+				fmt.Println("差库存", cha_number)
1789
+				fmt.Println("最后一次库存", min_number)
1790
+				if item.CountUnit == medical.MaxUnit {
1791
+					maxNumber = cha_number / medical.MinNumber
1792
+					parseDateErr := service.UpdateWarehouseInfo(maxNumber, item.DrugId, item.OrgId)
1793
+					if parseDateErr != nil {
1794
+						utils.ErrorLog(errs.Error())
1795
+						c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockOutFail)
1796
+						return
1797
+					}
1798
+
1799
+					c.ServeSuccessJSON(map[string]interface{}{
1800
+						"msg":        "2",
1801
+						"drug_name":  "",
1802
+						"dose":       "",
1803
+						"dose_unit":  "",
1804
+						"min_number": "",
1805
+						"min_unit":   "",
1806
+						"max_unit":   "",
1807
+					})
1808
+					minNumber = cha_number % medical.MinNumber
1809
+					parseDateErr = service.UpdateWarehouseInfoOne(minNumber, item.DrugId, item.OrgId)
1810
+					if parseDateErr != nil {
1811
+						utils.ErrorLog(errs.Error())
1812
+						c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockOutFail)
1813
+						return
1814
+					}
1815
+
1816
+					c.ServeSuccessJSON(map[string]interface{}{
1817
+						"msg":        "2",
1818
+						"drug_name":  "",
1819
+						"dose":       "",
1820
+						"dose_unit":  "",
1821
+						"min_number": "",
1822
+						"min_unit":   "",
1823
+						"max_unit":   "",
1824
+					})
1825
+				}
1826
+				if item.CountUnit == medical.MinUnit {
1827
+					parseDateErr := service.UpdateWarehouseInfoOne(cha_number, item.DrugId, item.OrgId)
1828
+					if parseDateErr != nil {
1829
+						utils.ErrorLog(errs.Error())
1830
+						c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockOutFail)
1831
+						return
1832
+					}
1833
+
1834
+					c.ServeSuccessJSON(map[string]interface{}{
1835
+						"msg":        "2",
1836
+						"drug_name":  "",
1837
+						"dose":       "",
1838
+						"dose_unit":  "",
1839
+						"min_number": "",
1840
+						"min_unit":   "",
1841
+						"max_unit":   "",
1842
+					})
1843
+				}
1844
+
1845
+			}
1846
+
1847
+			//退库操作
1848
+			if max_number > min_number {
1849
+				cha_number = min_number - max_number
1850
+				//如果总库存大于差,正常出库
1851
+				if all_number >= cha_number {
1852
+					fmt.Println("金立2323323322323233232323", all_number, cha_number)
1853
+					errs = service.UpDateDrugWarehouseOutInfo(item)
1854
+					fmt.Println("232322332233232", item.CountUnit, medical.MaxUnit)
1855
+					if item.CountUnit == medical.MaxUnit {
1856
+						maxNumber = cha_number / medical.MinNumber
1857
+						fmt.Println("maxNumber232323232323232232", maxNumber)
1858
+						parseDateErr := service.UpdateWarehouseInfo(maxNumber, item.DrugId, item.OrgId)
1859
+						fmt.Println("parseDateErr9999999999999999999999", parseDateErr)
1860
+						if parseDateErr != nil {
1861
+							utils.ErrorLog(errs.Error())
1862
+							c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockOutFail)
1863
+							return
1864
+						}
1865
+
1866
+						c.ServeSuccessJSON(map[string]interface{}{
1867
+							"msg":        "2",
1868
+							"drug_name":  "",
1869
+							"dose":       "",
1870
+							"dose_unit":  "",
1871
+							"min_number": "",
1872
+							"min_unit":   "",
1873
+							"max_unit":   "",
1874
+						})
1875
+						minNumber = cha_number % medical.MinNumber
1876
+						parseDateErr = service.UpdateWarehouseInfoOne(minNumber, item.DrugId, item.OrgId)
1877
+						if parseDateErr != nil {
1878
+							utils.ErrorLog(errs.Error())
1879
+							c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockOutFail)
1880
+							return
1881
+						}
1882
+
1883
+						c.ServeSuccessJSON(map[string]interface{}{
1884
+							"msg":        "2",
1885
+							"drug_name":  "",
1886
+							"dose":       "",
1887
+							"dose_unit":  "",
1888
+							"min_number": "",
1889
+							"min_unit":   "",
1890
+							"max_unit":   "",
1891
+						})
1892
+					}
1893
+					if item.CountUnit == medical.MinUnit {
1894
+						parseDateErr := service.UpdateWarehouseInfoOne(cha_number, item.DrugId, item.OrgId)
1895
+						if parseDateErr != nil {
1896
+							utils.ErrorLog(errs.Error())
1897
+							c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockOutFail)
1898
+							return
1899
+						}
1900
+
1901
+						c.ServeSuccessJSON(map[string]interface{}{
1902
+							"msg":        "2",
1903
+							"drug_name":  "",
1904
+							"dose":       "",
1905
+							"dose_unit":  "",
1906
+							"min_number": "",
1907
+							"min_unit":   "",
1908
+							"max_unit":   "",
1909
+						})
1910
+					}
1911
+				}
1912
+
1913
+				if all_number < cha_number {
1914
+					goodObj, _ := service.GetDrugByGoodId(item.DrugId)
1915
+					c.ServeSuccessJSON(map[string]interface{}{
1916
+						"msg":        "1",
1917
+						"drug_name":  goodObj.DrugName,
1918
+						"dose":       goodObj.Dose,
1919
+						"dose_unit":  goodObj.DoseUnit,
1920
+						"min_number": goodObj.MinNumber,
1921
+						"min_unit":   goodObj.MinUnit,
1922
+						"max_unit":   goodObj.MaxUnit,
1923
+					})
1924
+					return
1925
+				}
1926
+			}
1927
+
1636 1928
 		}
1637 1929
 	}
1638 1930
 
@@ -1643,7 +1935,13 @@ func (c *StockDrugApiController) EditDrugWarehouseOut() {
1643 1935
 	}
1644 1936
 
1645 1937
 	c.ServeSuccessJSON(map[string]interface{}{
1646
-		"msg": "编辑成功",
1938
+		"msg":        "2",
1939
+		"drug_name":  "",
1940
+		"dose":       "",
1941
+		"dose_unit":  "",
1942
+		"min_number": "",
1943
+		"min_unit":   "",
1944
+		"max_unit":   "",
1647 1945
 	})
1648 1946
 
1649 1947
 }
@@ -2239,9 +2537,11 @@ func (c *StockDrugApiController) EditDrugCancelStock() {
2239 2537
 			}
2240 2538
 		}
2241 2539
 	}
2540
+	fmt.Println("cancelStockInfos232323223323223322323223", cancelStockInfos)
2541
+	fmt.Println("cancelStockInfos232323223323223322323223", upDateCancelStockInfos)
2542
+
2242 2543
 	var errs error
2243 2544
 	if len(cancelStockInfos) > 0 {
2244
-		errs = service.CreateDrugCancelStockInfo(cancelStockInfos)
2245 2545
 
2246 2546
 		//扣减库存逻辑
2247 2547
 		for _, item := range cancelStockInfos {

+ 6 - 3
controllers/gobal_config_api_controller.go View File

@@ -2055,14 +2055,17 @@ func (c *GobalConfigApiController) GetAutoDrugDetail() {
2055 2055
 	list, err, total := service.FindDrugStockUserDetailByIdThree(id, record_time, orgId)
2056 2056
 	//获取手动出库
2057 2057
 	outList, err := service.FindeDrugWarehouserInfo(warehouse_out_id, id, orgId)
2058
+
2059
+	batchNumber, err := service.GetDrugFlowBatch(warehouse_out_id, id, orgId)
2058 2060
 	if err != nil {
2059 2061
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
2060 2062
 		return
2061 2063
 	}
2062 2064
 	c.ServeSuccessJSON(map[string]interface{}{
2063
-		"list":    list,
2064
-		"total":   total,
2065
-		"outList": outList,
2065
+		"list":        list,
2066
+		"total":       total,
2067
+		"outList":     outList,
2068
+		"batchNumber": batchNumber,
2066 2069
 	})
2067 2070
 }
2068 2071
 

+ 23 - 5
controllers/mobile_api_controllers/dialysis_api_controller.go View File

@@ -3353,7 +3353,8 @@ func (c *DialysisAPIController) CreateConsumables() {
3353 3353
 			}
3354 3354
 		}
3355 3355
 
3356
-		fmt.Println("dialysisBefor9999999999999999999", dialysisBefor)
3356
+		fmt.Println("dialysisBefor9999999999999999999", dialysisBefor, active)
3357
+
3357 3358
 		//新增
3358 3359
 		if active == 1 && len(goods) > 0 {
3359 3360
 			for _, item := range dialysisBefor {
@@ -3376,7 +3377,8 @@ func (c *DialysisAPIController) CreateConsumables() {
3376 3377
 			}
3377 3378
 			if err == nil {
3378 3379
 				c.ServeSuccessJSON(map[string]interface{}{
3379
-					"msg": "保存成功",
3380
+					"msg":     "保存成功",
3381
+					"message": "2",
3380 3382
 				})
3381 3383
 				return
3382 3384
 
@@ -3810,7 +3812,20 @@ func (c *DialysisAPIController) EditConsumables() {
3810 3812
 
3811 3813
 						//查询该批次剩余库存
3812 3814
 						lastInfo, _ := service.GetLastStockOut(goodInfo.WarehouseInfotId)
3815
+						if lastInfo.StockCount == 0 {
3816
+							//查询该耗材的总库存
3817
+							wareinfo, _ := service.GetStockGoodCount(item.GoodId)
3818
+							if wareinfo.StockCount == 0 {
3819
+								goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
3820
+								c.ServeSuccessJSON(map[string]interface{}{
3821
+									"message":            "1",
3822
+									"good_name":          goodObj.GoodName,
3823
+									"specification_name": goodObj.SpecificationName,
3824
+								})
3825
+								return
3826
+							}
3813 3827
 
3828
+						}
3814 3829
 						//比较剩余库存 和 当前相差的数量,库存剩余量大于则正常出库
3815 3830
 						fmt.Println("剩余库存", lastInfo.StockCount)
3816 3831
 						fmt.Println("差", last_total)
@@ -4509,6 +4524,7 @@ func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *mode
4509 4524
 	// 先根据相关信息查询当天该耗材的出库信息
4510 4525
 	warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
4511 4526
 	fmt.Println("errr232323232323232323232323232", err)
4527
+
4512 4528
 	if err != nil {
4513 4529
 		return err
4514 4530
 	}
@@ -4541,7 +4557,7 @@ func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *mode
4541 4557
 	warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
4542 4558
 	warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
4543 4559
 	warehouseOutInfo.ProductDate = stockInInfo.ProductDate
4544
-	warehouseOutInfo.Number = stockInInfo.Number
4560
+	warehouseOutInfo.Number = warehouseOutInfos.Number
4545 4561
 	warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
4546 4562
 	warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
4547 4563
 	//查找当天是否存在出库记录
@@ -4555,7 +4571,7 @@ func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *mode
4555 4571
 			WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
4556 4572
 			WarehouseOutId:          warehouseOut.ID,
4557 4573
 			GoodId:                  good_yc.GoodId,
4558
-			Number:                  stockInInfo.Number,
4574
+			Number:                  warehouseOutInfos.Number,
4559 4575
 			ProductDate:             stockInInfo.ProductDate,
4560 4576
 			ExpireDate:              stockInInfo.ExpiryDate,
4561 4577
 			Count:                   count,
@@ -4573,6 +4589,7 @@ func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *mode
4573 4589
 			WarehousingDetailId:     0,
4574 4590
 			IsSys:                   1,
4575 4591
 			UpdateCreator:           creater,
4592
+			PatientId:               patient_id,
4576 4593
 		}
4577 4594
 		//创建流水表
4578 4595
 		err := service.CreateStockFlowOne(stockFlow)
@@ -4587,7 +4604,7 @@ func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *mode
4587 4604
 			WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
4588 4605
 			WarehouseOutId:          warehouseOut.ID,
4589 4606
 			GoodId:                  good_yc.GoodId,
4590
-			Number:                  stockInInfo.Number,
4607
+			Number:                  warehouseOutInfos.Number,
4591 4608
 			ProductDate:             stockInInfo.ProductDate,
4592 4609
 			ExpireDate:              stockInInfo.ExpiryDate,
4593 4610
 			Count:                   count,
@@ -4605,6 +4622,7 @@ func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *mode
4605 4622
 			WarehousingDetailId:     0,
4606 4623
 			IsSys:                   1,
4607 4624
 			UpdateCreator:           creater,
4625
+			PatientId:               patient_id,
4608 4626
 		}
4609 4627
 		//创建流水表
4610 4628
 		service.CreateStockFlowOne(stockFlow)

+ 53 - 6
controllers/mobile_api_controllers/patient_api_controller.go View File

@@ -887,18 +887,57 @@ func (c *PatientApiController) ExecDoctorAdvice() {
887 887
 			if drugStockConfig.IsOpen == 1 {
888 888
 				advice, _ := service.FindHisDoctorAdviceById(adminInfo.Org.Id, advice_id)
889 889
 				//查询该药品是否有库存
890
+				//  list, _ := service.GetDrugTotalCount(advice.DrugId, advice.UserOrgId)
891
+				//  prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
892
+				//  count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
893
+				//  if list.Count == 0 {
894
+				//    c.ServeSuccessJSON(map[string]interface{}{
895
+				//      "msg":    "1",
896
+				//      "advice": advice,
897
+				//      "ids":    ids,
898
+				//    })
899
+				//    return
900
+				//  }
901
+				//  if count > list.Count {
902
+				//    c.ServeSuccessJSON(map[string]interface{}{
903
+				//      "msg":    "2",
904
+				//      "advice": advice,
905
+				//      "ids":    ids,
906
+				//    })
907
+				//    return
908
+				//}
909
+				var total int64
910
+				var prescribing_number_total int64
911
+				//查询该药品是否有库存
890 912
 				list, _ := service.GetDrugTotalCount(advice.DrugId, advice.UserOrgId)
891
-				prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
892
-				count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
913
+
914
+				//查询改药品信息
915
+				medical, _ := service.GetBaseDrugMedical(advice.DrugId)
916
+				//判断单位是否相等
917
+				if medical.MaxUnit == advice.PrescribingNumberUnit {
918
+					prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
919
+					count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
920
+					//转化为最小单位
921
+					total = list.Count * medical.MinNumber
922
+					prescribing_number_total = count * medical.MinNumber
923
+				}
924
+				if medical.MinUnit == advice.PrescribingNumberUnit {
925
+					total = list.Count
926
+					prescribing_number_total = list.Count
927
+				}
928
+
929
+				fmt.Println("数量一", prescribing_number_total)
930
+				fmt.Println("数量二", total)
931
+
893 932
 				if list.Count == 0 {
894 933
 					c.ServeSuccessJSON(map[string]interface{}{
895
-						"msg":    "1",
934
+						"msg":    "3",
896 935
 						"advice": advice,
897 936
 						"ids":    ids,
898 937
 					})
899 938
 					return
900 939
 				}
901
-				if count > list.Count {
940
+				if prescribing_number_total > total {
902 941
 					c.ServeSuccessJSON(map[string]interface{}{
903 942
 						"msg":    "2",
904 943
 						"advice": advice,
@@ -906,8 +945,15 @@ func (c *PatientApiController) ExecDoctorAdvice() {
906 945
 					})
907 946
 					return
908 947
 				}
909
-
910
-				service.HisDrugsDelivery(adminInfo.Org.Id, creater, &advice)
948
+				if prescribing_number_total <= total {
949
+					service.HisDrugsDelivery(adminInfo.Org.Id, creater, &advice)
950
+					c.ServeSuccessJSON(map[string]interface{}{
951
+						"msg":    "1",
952
+						"advice": advice,
953
+						"ids":    ids,
954
+					})
955
+					return
956
+				}
911 957
 			}
912 958
 			c.ServeSuccessJSON(map[string]interface{}{
913 959
 				"msg":    "ok",
@@ -1124,6 +1170,7 @@ func (c *PatientApiController) CheckDoctorAdvice() {
1124 1170
 			"advice": advice,
1125 1171
 		})
1126 1172
 	} else if origin == 2 {
1173
+		fmt.Println("金鳌地方 大房贷首付地方阿凡达阿方")
1127 1174
 		adminInfo := c.GetMobileAdminUserInfo()
1128 1175
 		advice_id, _ := c.GetInt64("advice_id")
1129 1176
 		advices, _ := service.FindHisDoctorAdviceById(adminInfo.Org.Id, advice_id)

+ 32 - 15
controllers/stock_in_api_controller.go View File

@@ -1539,6 +1539,8 @@ func (c *StockManagerApiController) EditWarehouseOut() {
1539 1539
 
1540 1540
 			//1.查询该耗材该批次的最后一次出库记录
1541 1541
 			lastGood, _ := service.GetLastGoodInformationByGoodId(item.GoodId, item.WarehouseInfotId, adminUserInfo.CurrentOrgId)
1542
+			fmt.Println("lastGood", lastGood.Count)
1543
+			fmt.Println("item2323232", item.Count)
1542 1544
 
1543 1545
 			// 退库的库存和该耗材该批次最后一次出库数量进行比较
1544 1546
 			//如果退库数量大于 最后一次批次的数量(要么要进行出库)
@@ -1622,7 +1624,7 @@ func (c *StockManagerApiController) EditWarehouseOut() {
1622 1624
 								return
1623 1625
 							}
1624 1626
 							c.ServeSuccessJSON(map[string]interface{}{
1625
-								"msg": "编辑成功",
1627
+								"msg": "1",
1626 1628
 							})
1627 1629
 						} else if errcode == nil {
1628 1630
 							service.UpDateWarehouseOutInfo(item)
@@ -1695,7 +1697,7 @@ func (c *StockManagerApiController) EditWarehouseOut() {
1695 1697
 							return
1696 1698
 						}
1697 1699
 						c.ServeSuccessJSON(map[string]interface{}{
1698
-							"msg": "编辑成功",
1700
+							"msg": "1",
1699 1701
 						})
1700 1702
 					} else if errcode == nil {
1701 1703
 						service.UpDateWarehouseOutInfo(item)
@@ -1713,6 +1715,14 @@ func (c *StockManagerApiController) EditWarehouseOut() {
1713 1715
 
1714 1716
 			if item.Count == lastGood.Count {
1715 1717
 				errs = service.UpDateWarehouseOutInfo(item)
1718
+				if errs != nil {
1719
+					utils.ErrorLog(errs.Error())
1720
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
1721
+					return
1722
+				}
1723
+				c.ServeSuccessJSON(map[string]interface{}{
1724
+					"msg": "1",
1725
+				})
1716 1726
 			}
1717 1727
 
1718 1728
 		}
@@ -2287,8 +2297,11 @@ func (c *StockManagerApiController) EditCancelStock() {
2287 2297
 		}
2288 2298
 	}
2289 2299
 	var errs error
2300
+	fmt.Println("出库22322333223", cancelStockInfos)
2301
+	fmt.Println("更新23232323232323233", upDateCancelStockInfos)
2290 2302
 	if len(cancelStockInfos) > 0 {
2291 2303
 		errs = service.CreateCancelStockInfo(cancelStockInfos)
2304
+
2292 2305
 		service.CreateStockFlow(stockFlow)
2293 2306
 		// 改变入库单的值
2294 2307
 		for _, item := range cancelStockInfos {
@@ -2316,17 +2329,17 @@ func (c *StockManagerApiController) EditCancelStock() {
2316 2329
 			//调用退库的方法
2317 2330
 			parseDateErr := service.UpdateCancelOut(list, item.Count)
2318 2331
 			fmt.Println("999999999999", parseDateErr)
2319
-
2320
-			if parseDateErr != nil {
2321
-				utils.ErrorLog(errs.Error())
2322
-				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
2323
-				return
2324
-			}
2325
-
2326
-			c.ServeSuccessJSON(map[string]interface{}{
2327
-				"msg": "编辑成功",
2328
-			})
2332
+			break
2333
+		}
2334
+		if errs != nil {
2335
+			utils.ErrorLog(errs.Error())
2336
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
2337
+			return
2329 2338
 		}
2339
+
2340
+		c.ServeSuccessJSON(map[string]interface{}{
2341
+			"msg": "编辑成功",
2342
+		})
2330 2343
 	}
2331 2344
 
2332 2345
 	if errs != nil {
@@ -4359,13 +4372,17 @@ func (this *StockManagerApiController) GetOrderDetailById() {
4359 4372
 	orgId := this.GetAdminUserInfo().CurrentOrgId
4360 4373
 	//自动出库
4361 4374
 	userDetails, err, total := service.FindUserDetailByIdOne(good_id, record_time, orgId)
4375
+
4362 4376
 	//手动出库
4363 4377
 	info, _ := service.GetWarehouseOutInfoById(id, good_id)
4378
+
4379
+	stockFlowList, err := service.GetStockFlowBatchNumber(id, good_id)
4364 4380
 	if err == nil {
4365 4381
 		this.ServeSuccessJSON(map[string]interface{}{
4366
-			"list":  userDetails,
4367
-			"total": total,
4368
-			"info":  info,
4382
+			"list":          userDetails,
4383
+			"total":         total,
4384
+			"info":          info,
4385
+			"stockFlowList": stockFlowList,
4369 4386
 		})
4370 4387
 	} else {
4371 4388
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)

+ 6 - 2
models/drug_stock.go View File

@@ -275,8 +275,12 @@ type VmDrugAutomaticReduceDetail struct {
275 275
 }
276 276
 
277 277
 type VmDrugWarehouseInfo struct {
278
-	DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
279
-	Count  int64 `gorm:"column:count" json:"count" form:"count"`
278
+	DrugId         int64  `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
279
+	Count          int64  `gorm:"column:count" json:"count" form:"count"`
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"`
282
+	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"`
280 284
 }
281 285
 
282 286
 type StDrugWarehouseOutInfo struct {

+ 10 - 2
models/self_drug_models.go View File

@@ -345,6 +345,10 @@ type XtDrugWarehouseOutInfo struct {
345 345
 	SysRecordTime           int64   `gorm:"column:sys_record_time" json:"sys_record_time" form:"sys_record_time"`
346 346
 	RetailPrice             float64 `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
347 347
 	RetailTotalPrice        float64 `gorm:"column:retail_total_price" json:"retail_total_price" form:"retail_total_price"`
348
+	CountUnit               string  `gorm:"column:count_unit" json:"count_unit" form:"count_unit"`
349
+	WarehouseInfoId         int64   `gorm:"column:warehouse_info_id" json:"warehouse_info_id" form:"warehouse_info_id"`
350
+	Number                  string  `gorm:"column:number" json:"number" form:"number"`
351
+	BatchNumber             string  `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
348 352
 }
349 353
 
350 354
 func (XtDrugWarehouseOutInfo) TableName() string {
@@ -476,8 +480,8 @@ type BloodDrugCancelStockInfo struct {
476 480
 	OrgId            int64   `gorm:"column:org_id" json:"org_id" form:"org_id"`
477 481
 	OrderNumber      string  `gorm:"column:order_number" json:"order_number" form:"order_number"`
478 482
 	Type             int64   `gorm:"column:type" json:"type" form:"type"`
479
-	Dealer           int64   `gorm:"column:dealer" json:"dealer" form:"dealer"`
480
-	Manufacturer     int64   `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
483
+	Dealer           string  `gorm:"column:dealer" json:"dealer" form:"dealer"`
484
+	Manufacturer     string  `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
481 485
 	RetailPrice      float64 `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
482 486
 	RetailTotalPrice float64 `gorm:"column:retail_total_price" json:"retail_total_price" form:"retail_total_price"`
483 487
 	Number           string  `gorm:"column:number" json:"number" form:"number"`
@@ -486,6 +490,10 @@ type BloodDrugCancelStockInfo struct {
486 490
 	DrugSpec         string  `gorm:"column:drug_spec" json:"drug_spec" form:"drug_spec"`
487 491
 	Creater          int64   `gorm:"column:creater" json:"creater" form:"creater"`
488 492
 	MinUnit          string  `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
493
+	MaxUnit          string  `json:"max_unit"`
494
+	MinNumber        int64   `json:"min_number"`
495
+	Dose             float64 `json:"dose"`
496
+	DoseUnit         string  `json:"dose_unit"`
489 497
 }
490 498
 
491 499
 type BloodDrugSalesReturnInfo struct {

+ 8 - 2
service/gobal_config_service.go View File

@@ -364,9 +364,9 @@ func GetDrugCancelOrder(startime int64, endtime int64, orgid int64, orderType in
364 364
 	}
365 365
 
366 366
 	if manufacturerId > 0 {
367
-		err = db.Select("x.id,x.drug_id,x.cancel_stock_id,x.count,x.price,x.total,x.product_date,x.expiry_date,x.ctime,x.org_id,x.order_number,x.type,x.dealer,x.manufacturer,x.retail_price,x.retail_total_price,x.number,s.drug_name,s.drug_type,s.drug_spec,s.min_unit,t.creater").Joins("left join xt_base_drug as s on s.id = x.drug_id and s.org_id = ? and s.status = 1", orgid).Joins("left join xt_drug_cancel_stock as t on t.id = x.cancel_stock_id and t.org_id = ? and t.status =1", orgid).Where("t.manufacturer = ?", manufacturerId).Order("x.ctime desc").Count(&total).Offset(offset).Limit(limit).Scan(&cancel).Error
367
+		err = db.Select("x.id,x.drug_id,x.cancel_stock_id,x.count,x.price,x.total,x.product_date,x.expiry_date,x.ctime,x.org_id,x.order_number,x.type,x.dealer,x.manufacturer,x.retail_price,x.retail_total_price,x.number,s.drug_name,s.drug_type,s.drug_spec,s.min_unit,t.creater,s.dose,s.dose_unit,s.min_number,s.max_unit").Joins("left join xt_base_drug as s on s.id = x.drug_id and s.org_id = ? and s.status = 1", orgid).Joins("left join xt_drug_cancel_stock as t on t.id = x.cancel_stock_id and t.org_id = ? and t.status =1", orgid).Where("t.manufacturer = ?", manufacturerId).Order("x.ctime desc").Count(&total).Offset(offset).Limit(limit).Scan(&cancel).Error
368 368
 	} else {
369
-		err = db.Select("x.id,x.drug_id,x.cancel_stock_id,x.count,x.price,x.total,x.product_date,x.expiry_date,x.ctime,x.org_id,x.order_number,x.type,x.dealer,x.manufacturer,x.retail_price,x.retail_total_price,x.number,s.drug_name,s.drug_type,s.drug_spec,s.min_unit,t.creater").Joins("left join xt_base_drug as s on s.id = x.drug_id and s.org_id = ? and s.status = 1", orgid).Joins("left join xt_drug_cancel_stock as t on t.id = x.cancel_stock_id and t.org_id = ? and t.status =1", orgid).Order("x.ctime desc").Count(&total).Offset(offset).Limit(limit).Scan(&cancel).Error
369
+		err = db.Select("x.id,x.drug_id,x.cancel_stock_id,x.count,x.price,x.total,x.product_date,x.expiry_date,x.ctime,x.org_id,x.order_number,x.type,x.dealer,x.manufacturer,x.retail_price,x.retail_total_price,x.number,s.drug_name,s.drug_type,s.drug_spec,s.min_unit,t.creater,s.dose,s.dose_unit,s.min_number,s.max_unit").Joins("left join xt_base_drug as s on s.id = x.drug_id and s.org_id = ? and s.status = 1", orgid).Joins("left join xt_drug_cancel_stock as t on t.id = x.cancel_stock_id and t.org_id = ? and t.status =1", orgid).Order("x.ctime desc").Count(&total).Offset(offset).Limit(limit).Scan(&cancel).Error
370 370
 	}
371 371
 
372 372
 	return cancel, total, err
@@ -731,3 +731,9 @@ func FindeDrugWarehouserInfo(ware_out_id int64, drug_id int64, orgid int64) (out
731 731
 
732 732
 	return outInfo, err
733 733
 }
734
+
735
+func GetDrugFlowBatch(ware_out_id int64, drug_id int64, orgid int64) (flow []*models.DrugFlow, err error) {
736
+
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
738
+	return flow, err
739
+}

+ 9 - 0
service/self_drug_service.go View File

@@ -799,3 +799,12 @@ func GetSelfOutStockQuery(startTime int64, endTime int64, orgid int64) (selfouts
799 799
 	err = db.Select("x.drug_name_id,Sum(x.outstore_number) as count").Group("x.drug_name").Scan(&selfoutstock).Error
800 800
 	return selfoutstock, err
801 801
 }
802
+
803
+func GetLastDrugWarehouseOutInfo(drugid int64, warehouseOutId int64, orgid int64) (models.XtDrugWarehouseOutInfo, error) {
804
+
805
+	info := models.XtDrugWarehouseOutInfo{}
806
+
807
+	err = XTReadDB().Model(&info).Where("drug_id = ? and  warehouse_out_id = ? and org_id = ? and status = 1", drugid, warehouseOutId, orgid).Last(&info).Error
808
+
809
+	return info, err
810
+}

+ 36 - 6
service/stock_service.go View File

@@ -2454,7 +2454,7 @@ func FindDrugStockOutByIsSys(org_id int64, is_sys int, record_time int64) (out m
2454 2454
 }
2455 2455
 
2456 2456
 func FindLastStockInInfoRecord(good_id int64, org_id int64) (in models.WarehousingInfo, err error) {
2457
-	err = readDb.Model(&models.WarehousingInfo{}).Where("status = 1 AND org_id = ? AND good_id = ?", org_id, good_id).Last(&in).Error
2457
+	err = readDb.Model(&models.WarehousingInfo{}).Where("status = 1 AND org_id = ? AND good_id = ?", org_id, good_id).First(&in).Error
2458 2458
 	return
2459 2459
 }
2460 2460
 
@@ -3509,7 +3509,7 @@ func GetDrugTotalCount(drugid int64, orgid int64) (info models.VmDrugWarehouseIn
3509 3509
 	if orgid > 0 {
3510 3510
 		db = db.Where("x.org_id = ?", orgid)
3511 3511
 	}
3512
-	err = db.Select("x.drug_id,sum(x.stock_max_number) as count").Find(&info).Error
3512
+	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
3513 3513
 	return info, err
3514 3514
 }
3515 3515
 
@@ -3538,7 +3538,7 @@ func GetWarehoureOrderInfoList(goodid int64, orgid int64) (info []*models.Wareho
3538 3538
 
3539 3539
 func UpdateWarehousingCount(info *models.WarehousingInfo, goodid int64, orgid int64, warehousingId int64) error {
3540 3540
 
3541
-	err := XTWriteDB().Model(&info).Where("good_id = ? and org_id = ? and status =1 and warehousing_id = ?", goodid, orgid, warehousingId).Updates(map[string]interface{}{"stock_count": info.StockCount}).Error
3541
+	err := XTWriteDB().Model(models.WarehousingInfo{}).Where("good_id = ? and org_id = ? and status = 1 and warehousing_id = ?", goodid, orgid, warehousingId).Updates(map[string]interface{}{"stock_count": info.StockCount}).Error
3542 3542
 	return err
3543 3543
 }
3544 3544
 
@@ -3561,8 +3561,9 @@ func UpdateCancelOut(list []*models.WarehousingInfo, count int64) error {
3561 3561
 				WarehousingId: item.WarehousingId,
3562 3562
 				StockCount:    item.StockCount + count,
3563 3563
 			}
3564
-			UpdateWarehousingCount(&info, item.GoodId, item.OrgId, item.WarehousingId)
3565
-			break
3564
+			err2 := UpdateWarehousingCount(&info, item.GoodId, item.OrgId, item.WarehousingId)
3565
+			fmt.Println("2323233232323232323232323232323", err2)
3566
+			return err
3566 3567
 		}
3567 3568
 
3568 3569
 		if (item.WarehousingCount - item.StockCount) < count {
@@ -3678,6 +3679,12 @@ func GetWarehouseOutInfoById(id int64, goodid int64) (info []*models.WarehouseOu
3678 3679
 	return info, err
3679 3680
 }
3680 3681
 
3682
+func GetStockFlowBatchNumber(id int64, goodid int64) (stock []*models.VmStockFlow, err error) {
3683
+
3684
+	err = XTReadDB().Model(&stock).Where("warehouse_out_id = ? and good_id = ? and status = 1", id, goodid).Group("patient_id,number").Find(&stock).Error
3685
+	return stock, err
3686
+}
3687
+
3681 3688
 func GetDrugBatchNumber(drug_id int64, orgid int64) (info []*models.DrugWarehouseInfo, err error) {
3682 3689
 
3683 3690
 	err = XTReadDB().Model(&info).Where("drug_id = ? and org_id = ? and status = 1 and batch_number <>''", drug_id, orgid).Find(&info).Error
@@ -3919,6 +3926,16 @@ func GetLastStockOut(id int64) (models.WarehousingInfo, error) {
3919 3926
 	return info, err
3920 3927
 }
3921 3928
 
3929
+func GetStockGoodCount(good_id int64) (models.WarehousingInfo, error) {
3930
+	info := models.WarehousingInfo{}
3931
+	db := XTReadDB().Model(&info)
3932
+	if good_id > 0 {
3933
+		db = db.Where("good_id = ? and status = 1", good_id)
3934
+	}
3935
+	err := db.Select("sum(stock_count) as stock_count").Find(&info).Error
3936
+	return info, err
3937
+}
3938
+
3922 3939
 func GetDrugFlow(drugid int64, orgid int64, limit int64, page int64, startTime int64, endTime int64, stock_type int64) (drug_flow []*models.DrugFlow, total int64, err error) {
3923 3940
 
3924 3941
 	offset := (page - 1) * limit
@@ -4061,6 +4078,19 @@ func UpdatedDrugInfo(id int64, count int64) (err error) {
4061 4078
 
4062 4079
 func UpdatedDrugInfoOne(id int64, count int64) (err error) {
4063 4080
 
4064
-	err = writeDb.Model(&models.DrugWarehousingInfo{}).Where("id = ?", id).UpdateColumn("stock_min_number", gorm.Expr("stock_min_number + ?", count)).Error
4081
+	err = writeDb.Model(&models.XtDrugWarehouseInfo{}).Where("id = ?", id).UpdateColumn("stock_min_number", gorm.Expr("stock_min_number + ?", count)).Error
4082
+	return err
4083
+}
4084
+
4085
+func UpdateWarehouseInfo(count int64, drugid int64, orgid int64) error {
4086
+
4087
+	err := writeDb.Model(&models.XtDrugWarehouseInfo{}).Where("drug_id = ?  and org_id = ? and status = 1", drugid, orgid).UpdateColumn("stock_max_number", gorm.Expr("stock_max_number + ?", count)).Error
4088
+
4089
+	return err
4090
+}
4091
+
4092
+func UpdateWarehouseInfoOne(count int64, drugid int64, orgid int64) error {
4093
+
4094
+	err := writeDb.Model(&models.XtDrugWarehouseInfo{}).Where("drug_id = ?  and org_id = ? and status = 1", drugid, orgid).UpdateColumn("stock_min_number", gorm.Expr("stock_min_number + ?", count)).Error
4065 4095
 	return err
4066 4096
 }

+ 11 - 7
service/warhouse_service.go View File

@@ -957,8 +957,8 @@ func ConsumablesDelivery(orgID int64, patient_id int64, record_time int64, goods
957 957
 				Number:                  warehouse.Number,
958 958
 				ProductDate:             warehouse.ProductDate,
959 959
 				ExpireDate:              warehouse.ExpiryDate,
960
-				Count:                   count,
961
-				Price:                   warehouse.Price,
960
+				Count:                   deliver_number,
961
+				Price:                   info.PackingPrice,
962 962
 				Status:                  1,
963 963
 				Ctime:                   time.Now().Unix(),
964 964
 				UserOrgId:               orgID,
@@ -972,6 +972,7 @@ func ConsumablesDelivery(orgID int64, patient_id int64, record_time int64, goods
972 972
 				WarehouseOutDetailId:    warehouseOutInfo.ID,
973 973
 				WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
974 974
 				IsSys:                   1,
975
+				PatientId:               patient_id,
975 976
 			}
976 977
 			CreateStockFlowOne(flow)
977 978
 			if errTwo != nil {
@@ -988,8 +989,8 @@ func ConsumablesDelivery(orgID int64, patient_id int64, record_time int64, goods
988 989
 				Number:                  warehouse.Number,
989 990
 				ProductDate:             warehouse.ProductDate,
990 991
 				ExpireDate:              warehouse.ExpiryDate,
991
-				Count:                   count,
992
-				Price:                   warehouse.Price,
992
+				Count:                   deliver_number,
993
+				Price:                   info.PackingPrice,
993 994
 				Status:                  1,
994 995
 				Ctime:                   time.Now().Unix(),
995 996
 				UserOrgId:               orgID,
@@ -1003,6 +1004,7 @@ func ConsumablesDelivery(orgID int64, patient_id int64, record_time int64, goods
1003 1004
 				WarehouseOutDetailId:    warehouseOutInfo.ID,
1004 1005
 				WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
1005 1006
 				IsSys:                   1,
1007
+				PatientId:               patient_id,
1006 1008
 			}
1007 1009
 			CreateStockFlowOne(flow)
1008 1010
 		}
@@ -1069,7 +1071,7 @@ func ConsumablesDelivery(orgID int64, patient_id int64, record_time int64, goods
1069 1071
 				Number:                  warehouse.Number,
1070 1072
 				ProductDate:             warehouse.ProductDate,
1071 1073
 				ExpireDate:              warehouse.ExpiryDate,
1072
-				Count:                   count,
1074
+				Count:                   stock_number,
1073 1075
 				Price:                   warehouse.Price,
1074 1076
 				Status:                  1,
1075 1077
 				Ctime:                   time.Now().Unix(),
@@ -1084,6 +1086,7 @@ func ConsumablesDelivery(orgID int64, patient_id int64, record_time int64, goods
1084 1086
 				WarehouseOutDetailId:    warehouseOutInfo.ID,
1085 1087
 				WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
1086 1088
 				IsSys:                   1,
1089
+				PatientId:               patient_id,
1087 1090
 			}
1088 1091
 			CreateStockFlowOne(flow)
1089 1092
 		} else if errcodes == nil {
@@ -1099,7 +1102,7 @@ func ConsumablesDelivery(orgID int64, patient_id int64, record_time int64, goods
1099 1102
 				Number:                  warehouse.Number,
1100 1103
 				ProductDate:             warehouse.ProductDate,
1101 1104
 				ExpireDate:              warehouse.ExpiryDate,
1102
-				Count:                   count,
1105
+				Count:                   goods.Count + stock_number,
1103 1106
 				Price:                   warehouse.Price,
1104 1107
 				Status:                  1,
1105 1108
 				Ctime:                   time.Now().Unix(),
@@ -1114,6 +1117,7 @@ func ConsumablesDelivery(orgID int64, patient_id int64, record_time int64, goods
1114 1117
 				WarehouseOutDetailId:    warehouseOutInfo.ID,
1115 1118
 				WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
1116 1119
 				IsSys:                   1,
1120
+				PatientId:               patient_id,
1117 1121
 			}
1118 1122
 			CreateStockFlowOne(flow)
1119 1123
 		}
@@ -1610,7 +1614,7 @@ func ConsumablesDeliveryTwo(orgID int64, goods *models.WarehouseOutInfo, count i
1610 1614
 }
1611 1615
 
1612 1616
 func DeleteWarehouseInfo(id int64) error {
1613
-	err := XTWriteDB().Where("id = ? and status = 1", id).Updates(map[string]interface{}{"stock_count": 0}).Error
1617
+	err := XTWriteDB().Model(models.WarehousingInfo{}).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"stock_count": 0}).Error
1614 1618
 	return err
1615 1619
 }
1616 1620