Kaynağa Gözat

耗材参数

XMLWAN 3 yıl önce
ebeveyn
işleme
5c0cf9dcea

+ 265 - 25
controllers/self_drug_api_congtroller.go Dosyayı Görüntüle

@@ -78,6 +78,7 @@ func SelfDrugRouters() {
78 78
 	beego.Router("/api/drug/getdruginventoryprintlist", &SelfDrugApiController{}, "Get:GetDrugInventoryPrintList")
79 79
 	beego.Router("/api/drug/getinventorydetaillist", &SelfDrugApiController{}, "Get:GetDrugInventoryDetailList")
80 80
 	beego.Router("/api/drug/savedrugproofinventory", &SelfDrugApiController{}, "Get:SaveDrugProofInventory")
81
+	beego.Router("/api/drug/getdrugwarehouseinfototal", &StockManagerApiController{}, "Get:GetDrugWarehouseInfoTotal")
81 82
 }
82 83
 
83 84
 func (this *SelfDrugApiController) GetCurrentPatient() {
@@ -959,7 +960,7 @@ func (this *SelfDrugApiController) PostSearchDrugWarehouseList() {
959 960
 }
960 961
 
961 962
 func (this *SelfDrugApiController) SaveDrugPrice() {
962
-	fmt.Println("999999999999999999999")
963
+
963 964
 	timeLayout := "2006-01-02"
964 965
 	loc, _ := time.LoadLocation("Local")
965 966
 	dataBody := make(map[string]interface{}, 0)
@@ -1020,12 +1021,12 @@ func (this *SelfDrugApiController) SaveDrugPrice() {
1020 1021
 			}
1021 1022
 			manufacturer := items["manufacturer"].(string)
1022 1023
 
1023
-			//if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
1024
-			//  utils.ErrorLog("specification_name")
1025
-			//  this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1026
-			//  return
1027
-			//}
1028
-			//specification_name := items["specification_name"].(string)
1024
+			if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
1025
+				utils.ErrorLog("specification_name")
1026
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1027
+				return
1028
+			}
1029
+			specification_name := items["specification_name"].(string)
1029 1030
 
1030 1031
 			if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
1031 1032
 				utils.ErrorLog("remark")
@@ -1047,13 +1048,6 @@ func (this *SelfDrugApiController) SaveDrugPrice() {
1047 1048
 				return
1048 1049
 			}
1049 1050
 			last_price, _ := strconv.ParseFloat(items["last_price"].(string), 64)
1050
-			//
1051
-			//if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "float64" {
1052
-			//	utils.ErrorLog("count")
1053
-			//	this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1054
-			//	return
1055
-			//}
1056
-			//count := int64(items["count"].(float64))
1057 1051
 
1058 1052
 			if items["new_price"] == nil || reflect.TypeOf(items["new_price"]).String() != "string" {
1059 1053
 				utils.ErrorLog("new_price")
@@ -1090,7 +1084,7 @@ func (this *SelfDrugApiController) SaveDrugPrice() {
1090 1084
 
1091 1085
 			drugAdjust := models.XtDrugAdjustPrice{
1092 1086
 				DrugName:          drug_name,
1093
-				SpecificationName: "",
1087
+				SpecificationName: specification_name,
1094 1088
 				WarehousingUnit:   warehousing_unit,
1095 1089
 				LastPrice:         last_price,
1096 1090
 				RetailPrice:       retail_price,
@@ -1199,7 +1193,8 @@ func (this *SelfDrugApiController) SaveCheckDrugPrice() {
1199 1193
 	list, _ := service.GetDrugAdjuestPrice(ids)
1200 1194
 	for _, item := range list {
1201 1195
 		drug := models.BaseDrugLib{
1202
-			RetailPrice: item.RetailPrice,
1196
+			RetailPrice: item.NewPrice,
1197
+			LastPrice:   item.NewPrice,
1203 1198
 		}
1204 1199
 		service.UpdateBaseDrugOne(drug, item.DrugId)
1205 1200
 	}
@@ -1221,7 +1216,6 @@ func (this *SelfDrugApiController) SaveDrugDamage() {
1221 1216
 		for _, item := range tableData {
1222 1217
 			items := item.(map[string]interface{})
1223 1218
 			drug_name := items["drug_name"].(string)
1224
-			fmt.Println("durg_nae232333223332232323323223232323", drug_name)
1225 1219
 			if items["drug_name"] == nil || reflect.TypeOf(items["drug_name"]).String() != "string" {
1226 1220
 				utils.ErrorLog("drug_name")
1227 1221
 				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
@@ -1360,6 +1354,26 @@ func (this *SelfDrugApiController) SaveDrugDamage() {
1360 1354
 			orgId := this.GetAdminUserInfo().CurrentOrgId
1361 1355
 			Creater := this.GetAdminUserInfo().AdminUser.Id
1362 1356
 
1357
+			if items["stock_max_number"] == nil || reflect.TypeOf(items["stock_max_number"]).String() != "float64" {
1358
+				utils.ErrorLog("stock_max_number")
1359
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1360
+				return
1361
+			}
1362
+			stock_max_number := int64(items["stock_max_number"].(float64))
1363
+
1364
+			if items["stock_min_number"] == nil || reflect.TypeOf(items["stock_min_number"]).String() != "float64" {
1365
+				utils.ErrorLog("stock_min_number")
1366
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1367
+				return
1368
+			}
1369
+			stock_min_number := int64(items["stock_min_number"].(float64))
1370
+
1371
+			if items["total"] == nil || reflect.TypeOf(items["total"]).String() != "string" {
1372
+				utils.ErrorLog("total")
1373
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1374
+				return
1375
+			}
1376
+			total := items["total"].(string)
1363 1377
 			drugDamage := models.XtDrugDamage{
1364 1378
 				DrugName:          drug_name,
1365 1379
 				SpecificationName: specification_name,
@@ -1387,6 +1401,9 @@ func (this *SelfDrugApiController) SaveDrugDamage() {
1387 1401
 				ProductDate:       product_date,
1388 1402
 				WarehousingInfoId: warehousing_info_id,
1389 1403
 				DrugOriginPlace:   drug_origin_place,
1404
+				StockMaxNumber:    stock_max_number,
1405
+				StockMinNumber:    stock_min_number,
1406
+				Total:             total,
1390 1407
 			}
1391 1408
 
1392 1409
 			err := service.CreateDrugDamage(drugDamage)
@@ -1407,7 +1424,7 @@ func (this *SelfDrugApiController) GetDrugDamageList() {
1407 1424
 	fmt.Println(err)
1408 1425
 	orgId := this.GetAdminUserInfo().CurrentOrgId
1409 1426
 	keyword := this.GetString("keyword")
1410
-	fmt.Println("keywoer2r2r32rwrwr", keyword)
1427
+
1411 1428
 	start_time := this.GetString("start_time")
1412 1429
 	end_time := this.GetString("end_time")
1413 1430
 	var startTime int64
@@ -1564,6 +1581,12 @@ func (this *SelfDrugApiController) SaveDrugDamagePrice() {
1564 1581
 		service.CreateWareHouseOutInfo(&warehouseOutInfo)
1565 1582
 		service.CreateDrugFlowOne(drugflow)
1566 1583
 
1584
+		info, _ := service.GetDrugByWarehouseInfo(item.WarehousingInfoId)
1585
+		//扣减库存
1586
+		warehouseInfo := models.XtDrugWarehouseInfo{
1587
+			StockMaxNumber: info.StockMaxNumber - info.StockMaxNumber,
1588
+		}
1589
+		service.UpdateDrugWarehouseingInfo(item.WarehousingInfoId, warehouseInfo)
1567 1590
 	}
1568 1591
 	this.ServeSuccessJSON(map[string]interface{}{
1569 1592
 		"damage": damage,
@@ -1583,6 +1606,10 @@ func (this *SelfDrugApiController) GetDrugModifyPrice() {
1583 1606
 func (this *SelfDrugApiController) ModifyDrugPrice() {
1584 1607
 
1585 1608
 	drug_name := this.GetString("drug_name")
1609
+	specification_name := this.GetString("specification_name")
1610
+	warehousing_unit := this.GetString("warehousing_unit")
1611
+	manufacturer := this.GetString("manufacturer")
1612
+	number := this.GetString("number")
1586 1613
 	retailPrice := this.GetString("retail_price")
1587 1614
 	retail_price, _ := strconv.ParseFloat(retailPrice, 64)
1588 1615
 	newPrice := this.GetString("new_price")
@@ -1590,12 +1617,18 @@ func (this *SelfDrugApiController) ModifyDrugPrice() {
1590 1617
 	count, _ := this.GetInt64("count")
1591 1618
 	remark := this.GetString("remark")
1592 1619
 	id, _ := this.GetInt64("id")
1620
+	drug_id, _ := this.GetInt64("drug_id")
1593 1621
 	adjustPrice := models.XtDrugAdjustPrice{
1594
-		DrugName:    drug_name,
1595
-		Count:       count,
1596
-		RetailPrice: retail_price,
1597
-		NewPrice:    new_price,
1598
-		Remark:      remark,
1622
+		DrugName:          drug_name,
1623
+		Count:             count,
1624
+		RetailPrice:       retail_price,
1625
+		NewPrice:          new_price,
1626
+		Remark:            remark,
1627
+		SpecificationName: specification_name,
1628
+		WarehousingUnit:   warehousing_unit,
1629
+		Manufacturer:      manufacturer,
1630
+		Number:            number,
1631
+		DrugId:            drug_id,
1599 1632
 	}
1600 1633
 	err := service.ModifyDrugPrice(id, adjustPrice)
1601 1634
 	fmt.Println(err)
@@ -1629,7 +1662,7 @@ func (this *SelfDrugApiController) ModifyDrugDamage() {
1629 1662
 	id, _ := this.GetInt64("id")
1630 1663
 	drug_id, _ := this.GetInt64("drug_id")
1631 1664
 	drug_name := this.GetString("drug_name")
1632
-	//drug_origin_place := this.GetString("drug_origin_place")
1665
+	drug_origin_place := this.GetString("drug_origin_place")
1633 1666
 	lastPrice := this.GetString("last_price")
1634 1667
 	last_price, _ := strconv.ParseFloat(lastPrice, 64)
1635 1668
 	newPrice := this.GetString("new_price")
@@ -1641,7 +1674,9 @@ func (this *SelfDrugApiController) ModifyDrugDamage() {
1641 1674
 	remark := this.GetString("remark")
1642 1675
 	count, _ := this.GetInt64("count")
1643 1676
 	warehousing_unit := this.GetString("warehousing_unit")
1644
-
1677
+	stock_max_number, _ := this.GetInt64("stock_max_number")
1678
+	stock_min_number, _ := this.GetInt64("stock_min_number")
1679
+	warehousing_info_id, _ := this.GetInt64("warehousing_info_id")
1645 1680
 	damage := models.XtDrugDamage{
1646 1681
 		DrugName:          drug_name,
1647 1682
 		SpecificationName: "",
@@ -1655,6 +1690,10 @@ func (this *SelfDrugApiController) ModifyDrugDamage() {
1655 1690
 		Remark:            remark,
1656 1691
 		DrugId:            drug_id,
1657 1692
 		Number:            number,
1693
+		StockMaxNumber:    stock_max_number,
1694
+		StockMinNumber:    stock_min_number,
1695
+		WarehousingInfoId: warehousing_info_id,
1696
+		DrugOriginPlace:   drug_origin_place,
1658 1697
 	}
1659 1698
 	err := service.ModifyDrugDamage(id, damage)
1660 1699
 	fmt.Println(err)
@@ -1967,6 +2006,190 @@ func (this *SelfDrugApiController) SaveDrugCheckInventory() {
1967 2006
 	}
1968 2007
 	err = service.UpdateDrugInventory(ids, inventory)
1969 2008
 	fmt.Println(err)
2009
+
2010
+	list, _ := service.GetDrugInventoryListByIds(ids)
2011
+
2012
+	adminUserInfo := this.GetAdminUserInfo()
2013
+	var stock_total int64
2014
+	var proof_count int64
2015
+	var maxNumber int64
2016
+	var minNumber int64
2017
+	for _, item := range list {
2018
+
2019
+		//查询库存信息
2020
+		drug, _ := service.GetDrugDetailByDrugId(item.DrugId)
2021
+
2022
+		//查询库存
2023
+		info, _ := service.GetDrugWareInfoById(item.WarehouseInfoId)
2024
+
2025
+		//获取最晚的库存数量
2026
+		lastInfo, _ := service.GetLastDrugWarehouseInfo(item.DrugId)
2027
+		firstInfo, _ := service.GetFirstDrugWarehouseInfo(item.DrugId)
2028
+		stock_total = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
2029
+		proof_count = item.StockMaxNumber*drug.MinNumber + item.StockMinNumber
2030
+
2031
+		//判断 如果库存数量 大于盘点库存,则出库
2032
+		if stock_total > proof_count {
2033
+			minNumber = (stock_total - proof_count) % drug.MinNumber
2034
+			maxNumber = (stock_total - proof_count) / drug.MinNumber
2035
+
2036
+			ctime := time.Now().Unix()
2037
+
2038
+			timeStr := time.Now().Format("2006-01-02")
2039
+			timeArr := strings.Split(timeStr, "-")
2040
+			total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.CurrentOrgId)
2041
+
2042
+			total = total + 1
2043
+			warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
2044
+			number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
2045
+			number = number + total
2046
+			warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
2047
+			operation_time := time.Now().Unix()
2048
+			creater := adminUserInfo.AdminUser.Id
2049
+
2050
+			warehouseOut := models.DrugWarehouseOut{
2051
+				WarehouseOutOrderNumber: warehousing_out_order,
2052
+				OperationTime:           operation_time,
2053
+				OrgId:                   adminUserInfo.CurrentOrgId,
2054
+				Creater:                 creater,
2055
+				Ctime:                   ctime,
2056
+				Status:                  1,
2057
+				WarehouseOutTime:        ctime,
2058
+				Type:                    1,
2059
+			}
2060
+
2061
+			warehouseOutInfo := models.DrugWarehouseOutInfo{
2062
+				WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
2063
+				WarehouseOutId:          warehouseOut.ID,
2064
+				DrugId:                  firstInfo.DrugId,
2065
+				Count:                   maxNumber,
2066
+				Price:                   firstInfo.Price,
2067
+				TotalPrice:              firstInfo.TotalPrice,
2068
+				Status:                  1,
2069
+				Ctime:                   ctime,
2070
+				Remark:                  item.Remark,
2071
+				OrgId:                   adminUserInfo.CurrentOrgId,
2072
+				Type:                    1,
2073
+				Manufacturer:            firstInfo.Manufacturer,
2074
+				Dealer:                  firstInfo.Dealer,
2075
+				RetailPrice:             firstInfo.RetailPrice,
2076
+				RetailTotalPrice:        firstInfo.RetailTotalPrice,
2077
+				CountUnit:               drug.MaxUnit,
2078
+				ExpiryDate:              firstInfo.ExpiryDate,
2079
+				ProductDate:             firstInfo.ProductDate,
2080
+				Number:                  firstInfo.Number,
2081
+				BatchNumber:             firstInfo.BatchNumber,
2082
+				IsSys:                   0,
2083
+				WarehouseInfoId:         firstInfo.ID,
2084
+			}
2085
+
2086
+			drugflow := models.DrugFlow{
2087
+				WarehouseOutId:          warehouseOut.ID,
2088
+				WarehouseOutOrderNumber: warehousing_out_order,
2089
+				DrugId:                  firstInfo.DrugId,
2090
+				Number:                  firstInfo.Number,
2091
+				ProductDate:             firstInfo.ProductDate,
2092
+				ExpireDate:              firstInfo.ExpiryDate,
2093
+				Count:                   maxNumber,
2094
+				Price:                   firstInfo.Price,
2095
+				Status:                  1,
2096
+				Ctime:                   ctime,
2097
+				UserOrgId:               adminUserInfo.CurrentOrgId,
2098
+				Manufacturer:            firstInfo.Manufacturer,
2099
+				Dealer:                  firstInfo.Dealer,
2100
+				BatchNumber:             firstInfo.BatchNumber,
2101
+				MaxUnit:                 drug.MaxUnit,
2102
+				ConsumableType:          2,
2103
+				IsEdit:                  1,
2104
+				Creator:                 adminUserInfo.AdminUser.Id,
2105
+				IsSys:                   0,
2106
+			}
2107
+
2108
+			service.AddSigleDrugWarehouseOut(&warehouseOut)
2109
+			service.CreateDrugWarehouseOutInfo(warehouseOutInfo)
2110
+			service.CreateDrugFlowOne(drugflow)
2111
+
2112
+		}
2113
+
2114
+		//判断 如果库存数量 小于于盘点库存,则入库
2115
+		if stock_total < proof_count {
2116
+
2117
+			maxNumber = (proof_count - stock_total) / drug.MinNumber
2118
+			minNumber = (proof_count - stock_total) % drug.MinNumber
2119
+			ctime := time.Now().Unix()
2120
+
2121
+			timeStr := time.Now().Format("2006-01-02")
2122
+			timeArr := strings.Split(timeStr, "-")
2123
+			total, _ := service.FindAllWarehouseTotalOne(adminUserInfo.CurrentOrgId)
2124
+			total = total + 1
2125
+			fmt.Println("total2323232323232", total)
2126
+			warehousing_order := "YPRKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
2127
+
2128
+			operation_time := time.Now().Unix()
2129
+			creater := adminUserInfo.AdminUser.Id
2130
+			warehousing := models.DrugWarehouse{
2131
+				WarehousingOrder: warehousing_order,
2132
+				OperationTime:    operation_time,
2133
+				OrgId:            adminUserInfo.CurrentOrgId,
2134
+				Creater:          creater,
2135
+				Ctime:            ctime,
2136
+				Status:           1,
2137
+				WarehousingTime:  ctime,
2138
+				Type:             1,
2139
+			}
2140
+
2141
+			warehouseInfo := models.DrugWarehouseInfo{
2142
+				WarehousingOrder: warehousing.WarehousingOrder,
2143
+				WarehousingId:    warehousing.ID,
2144
+				DrugId:           lastInfo.DrugId,
2145
+				Number:           lastInfo.Number,
2146
+				ProductDate:      lastInfo.ProductDate,
2147
+				ExpiryDate:       lastInfo.ExpiryDate,
2148
+				WarehousingCount: lastInfo.WarehousingCount,
2149
+				Price:            lastInfo.Price,
2150
+				TotalPrice:       lastInfo.TotalPrice,
2151
+				Status:           1,
2152
+				Ctime:            ctime,
2153
+				Remark:           item.Remark,
2154
+				OrgId:            adminUserInfo.CurrentOrgId,
2155
+				Type:             1,
2156
+				Manufacturer:     lastInfo.Manufacturer,
2157
+				Dealer:           lastInfo.Dealer,
2158
+				StockMaxNumber:   maxNumber,
2159
+				StockMinNumber:   minNumber,
2160
+				RetailTotalPrice: lastInfo.RetailTotalPrice,
2161
+				BatchNumber:      lastInfo.BatchNumber,
2162
+				MaxUnit:          drug.MaxUnit,
2163
+				MinUnit:          drug.MinUnit,
2164
+			}
2165
+
2166
+			drugflow := models.DrugFlow{
2167
+				WarehousingOrder: warehousing.WarehousingOrder,
2168
+				WarehousingId:    warehousing.ID,
2169
+				DrugId:           lastInfo.DrugId,
2170
+				Number:           lastInfo.Number,
2171
+				ProductDate:      lastInfo.ProductDate,
2172
+				ExpireDate:       lastInfo.ExpiryDate,
2173
+				Count:            maxNumber,
2174
+				Price:            lastInfo.Price,
2175
+				Status:           1,
2176
+				Ctime:            ctime,
2177
+				UserOrgId:        adminUserInfo.CurrentOrgId,
2178
+				Manufacturer:     lastInfo.Manufacturer,
2179
+				Dealer:           lastInfo.Dealer,
2180
+				BatchNumber:      lastInfo.BatchNumber,
2181
+				MaxUnit:          drug.MaxUnit,
2182
+				MinUnit:          drug.MinUnit,
2183
+				ConsumableType:   1,
2184
+				IsEdit:           1,
2185
+				Creator:          adminUserInfo.AdminUser.Id,
2186
+				IsSys:            0,
2187
+			}
2188
+			service.AddSigleDrugWarehouse(&warehousing)
2189
+			service.CreateDrugWarehouseInfo(warehouseInfo)
2190
+			service.CreateDrugFlowOne(drugflow)
2191
+		}
2192
+	}
1970 2193
 	returnData := make(map[string]interface{}, 0)
1971 2194
 	returnData["msg"] = "ok"
1972 2195
 	this.ServeSuccessJSON(returnData)
@@ -2004,6 +2227,10 @@ func (this *SelfDrugApiController) ModifyInventory() {
2004 2227
 	last_price, _ := strconv.ParseFloat(lastPrice, 64)
2005 2228
 	count, _ := this.GetInt64("count")
2006 2229
 	drug_origin_place := this.GetString("drug_origin_place")
2230
+
2231
+	stock_max_number, _ := this.GetInt64("stock_max_number")
2232
+	stock_min_number, _ := this.GetInt64("stock_min_number")
2233
+	warehouse_info_id, _ := this.GetInt64("warehouse_info_id")
2007 2234
 	inventory := models.XtDrugInventory{
2008 2235
 		DrugName:          drug_name,
2009 2236
 		SpecificationName: specification_name,
@@ -2018,6 +2245,9 @@ func (this *SelfDrugApiController) ModifyInventory() {
2018 2245
 		Number:            number,
2019 2246
 		Total:             total,
2020 2247
 		DrugOriginPlace:   drug_origin_place,
2248
+		StockMaxNumber:    stock_max_number,
2249
+		StockMinNumber:    stock_min_number,
2250
+		WarehouseInfoId:   warehouse_info_id,
2021 2251
 	}
2022 2252
 	err := service.ModifyDrugInventory(id, inventory)
2023 2253
 	if err != nil {
@@ -2106,3 +2336,13 @@ func (this *SelfDrugApiController) SaveDrugProofInventory() {
2106 2336
 		"inventory": inventory,
2107 2337
 	})
2108 2338
 }
2339
+
2340
+func (this *StockManagerApiController) GetDrugWarehouseInfoTotal() {
2341
+
2342
+	id, _ := this.GetInt64("id")
2343
+	list, _ := service.GetDrugWarehouseInfoTotal(id)
2344
+
2345
+	this.ServeSuccessJSON(map[string]interface{}{
2346
+		"list": list,
2347
+	})
2348
+}

+ 201 - 1
controllers/stock_in_api_controller.go Dosyayı Görüntüle

@@ -127,6 +127,7 @@ func StockManagerApiRegistRouters() {
127 127
 	beego.Router("/api/drug/deletedrugprice", &StockManagerApiController{}, "Get:DeleteDrugPrice")
128 128
 	beego.Router("/api/stock/getgoodwarehouselist", &StockManagerApiController{}, "Get:GetGoodWarehouseList")
129 129
 	beego.Router("/api/stock/proofinventory", &StockManagerApiController{}, "Get:ProofInventory")
130
+	beego.Router("/api/stock/getwarehousetotal", &StockManagerApiController{}, "Get:GetWarehouseTotal")
130 131
 
131 132
 }
132 133
 
@@ -1993,7 +1994,7 @@ func (c *StockManagerApiController) CreateCancelStock() {
1993 1994
 		}
1994 1995
 
1995 1996
 		//查询该批次入库的值
1996
-		infolist, _ := service.GetWarehouseInfoById(item.WarehouseInfoId)
1997
+		infolist, _ := service.GetWarehouseInfoByIdSeven(item.WarehouseInfoId)
1997 1998
 
1998 1999
 		if item.Count > infolist.WarehousingCount {
1999 2000
 			c.ServeSuccessJSON(map[string]interface{}{
@@ -4975,6 +4976,7 @@ func (this *StockManagerApiController) SaveCheckPrice() {
4975 4976
 	for _, item := range list {
4976 4977
 		info := models.GoodInfo{
4977 4978
 			PackingPrice: item.NewPrice,
4979
+			BuyPrice:     item.BuyPrice,
4978 4980
 		}
4979 4981
 		err = service.UpdateAdjustCheckPrice(&info, item.GoodId)
4980 4982
 		fmt.Println(err)
@@ -5659,7 +5661,196 @@ func (this *StockManagerApiController) SaveCheckInventory() {
5659 5661
 		CheckerStatus: 1,
5660 5662
 		CheckerTime:   checkTime,
5661 5663
 	}
5664
+	adminUserInfo := this.GetAdminUserInfo()
5662 5665
 	err = service.UpdateCheckInventory(ids, inventory)
5666
+	manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
5667
+	dealerList, _ := service.GetAllDealerList(adminUserInfo.CurrentOrgId)
5668
+	var manufactuer_id int64
5669
+	var dealer_id int64
5670
+	//查询耗材信息
5671
+	list, _ := service.GetInventoryDetailById(ids)
5672
+	for _, item := range list {
5673
+		for _, it := range manufacturerList {
5674
+			if item.Manufacturer == it.ManufacturerName {
5675
+				manufactuer_id = it.ID
5676
+			}
5677
+		}
5678
+
5679
+		for _, its := range dealerList {
5680
+			if item.Dealer == its.DealerName {
5681
+				dealer_id = its.ID
5682
+			}
5683
+		}
5684
+		//查寻该批次的库存量
5685
+		list, _ := service.GetWarehouseInfoById(item.WarehousingInfoId)
5686
+
5687
+		//查询该耗材最后1条批次
5688
+		info, _ := service.GetLastWarehouseInfo(item.GoodId)
5689
+		fmt.Println("总共", item.Count)
5690
+		fmt.Println("数据", list.StockCount)
5691
+		//盘点盘点库存和et实际库存的大小
5692
+		// 如果盘点库存大于实际库存,怎需要入库
5693
+		if item.Count > list.StockCount {
5694
+
5695
+			ctime := time.Now().Unix()
5696
+
5697
+			timeStr := time.Now().Format("2006-01-02")
5698
+			timeArr := strings.Split(timeStr, "-")
5699
+			total, _ := service.FindAllWarehouseTotal(adminUserInfo.CurrentOrgId)
5700
+			total = total + 1
5701
+			warehousing_order := "RKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
5702
+			operation_time := time.Now().Unix()
5703
+			creater := adminUserInfo.AdminUser.Id
5704
+			warehousing := models.Warehousing{
5705
+				WarehousingOrder: warehousing_order,
5706
+				OperationTime:    operation_time,
5707
+				OrgId:            adminUserInfo.CurrentOrgId,
5708
+				Creater:          creater,
5709
+				Ctime:            ctime,
5710
+				Status:           1,
5711
+				WarehousingTime:  ctime,
5712
+				Type:             1,
5713
+			}
5714
+			service.AddSigleWarehouse(&warehousing)
5715
+
5716
+			//获取最
5717
+			//入库单表格
5718
+			warehouseInfo := models.WarehousingInfo{
5719
+				WarehousingOrder: warehousing.WarehousingOrder,
5720
+				WarehousingId:    warehousing.ID,
5721
+				GoodId:           item.GoodId,
5722
+				Number:           info.Number,
5723
+				ProductDate:      info.ProductDate,
5724
+				ExpiryDate:       info.ExpiryDate,
5725
+				WarehousingCount: item.Count - list.StockCount,
5726
+				Price:            info.Price,
5727
+				Status:           1,
5728
+				Ctime:            ctime,
5729
+				Remark:           item.Remark,
5730
+				OrgId:            adminUserInfo.CurrentOrgId,
5731
+				Type:             1,
5732
+				Manufacturer:     manufactuer_id,
5733
+				StockCount:       item.Count - list.StockCount,
5734
+				Dealer:           dealer_id,
5735
+				LicenseNumber:    info.LicenseNumber,
5736
+			}
5737
+
5738
+			flow := models.VmStockFlow{
5739
+				WarehousingOrder:    warehousing.WarehousingOrder,
5740
+				WarehousingId:       warehousing.ID,
5741
+				GoodId:              item.GoodId,
5742
+				Number:              info.Number,
5743
+				ProductDate:         info.ProductDate,
5744
+				ExpireDate:          info.ExpiryDate,
5745
+				Count:               item.Count - list.StockCount,
5746
+				Price:               item.BuyPrice,
5747
+				Status:              1,
5748
+				Ctime:               ctime,
5749
+				UserOrgId:           adminUserInfo.CurrentOrgId,
5750
+				Manufacturer:        info.Manufacturer,
5751
+				Dealer:              info.Dealer,
5752
+				LicenseNumber:       info.LicenseNumber,
5753
+				IsEdit:              1,
5754
+				Creator:             adminUserInfo.AdminUser.Id,
5755
+				SystemTime:          operation_time,
5756
+				ConsumableType:      1,
5757
+				WarehousingDetailId: warehouseInfo.ID,
5758
+			}
5759
+
5760
+			service.CreateWarehouseInfo(warehouseInfo)
5761
+			service.CreateStockFlowOne(flow)
5762
+		}
5763
+
5764
+		//如果盘点库存小于实际库存,需要出库
5765
+		if item.Count < list.StockCount {
5766
+			timeStr := time.Now().Format("2006-01-02")
5767
+			timeArr := strings.Split(timeStr, "-")
5768
+			total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
5769
+
5770
+			total = total + 1
5771
+			warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
5772
+			number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
5773
+			number = number + total
5774
+			warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
5775
+			operation_time := time.Now().Unix()
5776
+			creater := adminUserInfo.AdminUser.Id
5777
+
5778
+			//查询最早的1条批次
5779
+			warehouseInfo, _ := service.GetFirstWarehouseInfo(item.GoodId)
5780
+			warehouseOut := models.WarehouseOut{
5781
+				WarehouseOutOrderNumber: warehousing_out_order,
5782
+				OperationTime:           operation_time,
5783
+				OrgId:                   adminUserInfo.CurrentOrgId,
5784
+				Creater:                 creater,
5785
+				Ctime:                   time.Now().Unix(),
5786
+				Status:                  1,
5787
+				WarehouseOutTime:        time.Now().Unix(),
5788
+				Type:                    1,
5789
+			}
5790
+			err = service.CreateWarehouseOut(warehouseOut)
5791
+			fmt.Println(err)
5792
+			warehouseOutInfo := &models.WarehouseOutInfo{
5793
+				WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
5794
+				WarehouseOutId:          warehouseOut.ID,
5795
+				GoodId:                  warehouseInfo.GoodId,
5796
+				Count:                   list.StockCount - item.Count,
5797
+				Price:                   warehouseInfo.Price,
5798
+				Status:                  1,
5799
+				Ctime:                   time.Now().Unix(),
5800
+				Remark:                  item.Remark,
5801
+				OrgId:                   adminUserInfo.CurrentOrgId,
5802
+				Type:                    1,
5803
+				Manufacturer:            manufactuer_id,
5804
+				Number:                  warehouseInfo.Number,
5805
+				ExpiryDate:              warehouseInfo.ExpiryDate,
5806
+				ProductDate:             warehouseInfo.ProductDate,
5807
+				Dealer:                  dealer_id,
5808
+				LicenseNumber:           warehouseInfo.LicenseNumber,
5809
+			}
5810
+
5811
+			stockFlow := models.VmStockFlow{
5812
+				WarehousingId:           item.WarehousingInfoId,
5813
+				GoodId:                  warehouseInfo.GoodId,
5814
+				Number:                  warehouseInfo.Number,
5815
+				LicenseNumber:           warehouseInfo.LicenseNumber,
5816
+				Count:                   list.StockCount - item.Count,
5817
+				UserOrgId:               warehouseInfo.OrgId,
5818
+				PatientId:               0,
5819
+				SystemTime:              0,
5820
+				ConsumableType:          2,
5821
+				IsSys:                   2,
5822
+				WarehousingOrder:        "",
5823
+				WarehouseOutId:          warehouseOut.ID,
5824
+				WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
5825
+				IsEdit:                  1,
5826
+				CancelStockId:           0,
5827
+				CancelOrderNumber:       "",
5828
+				Manufacturer:            manufactuer_id,
5829
+				Dealer:                  dealer_id,
5830
+				Creator:                 adminUserInfo.AdminUser.Id,
5831
+				UpdateCreator:           0,
5832
+				Status:                  1,
5833
+				Ctime:                   time.Now().Unix(),
5834
+				Mtime:                   0,
5835
+				Price:                   warehouseInfo.Price,
5836
+				WarehousingDetailId:     0,
5837
+				WarehouseOutDetailId:    warehouseOutInfo.ID,
5838
+				CancelOutDetailId:       0,
5839
+				ProductDate:             warehouseInfo.ProductDate,
5840
+				ExpireDate:              warehouseInfo.ExpiryDate,
5841
+			}
5842
+			errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
5843
+			fmt.Println(errOne)
5844
+			//创建出库明细
5845
+			service.CreateStockFlowOne(stockFlow)
5846
+
5847
+			//更改库存
5848
+			warehousingInfos := models.WarehousingInfo{
5849
+				StockCount: item.Count,
5850
+			}
5851
+			service.UpdateStockOut(item.WarehousingInfoId, warehousingInfos)
5852
+		}
5853
+	}
5663 5854
 	fmt.Println(err)
5664 5855
 	this.ServeSuccessJSON(map[string]interface{}{
5665 5856
 		"inventory": inventory,
@@ -5935,3 +6126,12 @@ func (this *StockManagerApiController) ProofInventory() {
5935 6126
 		"list": info,
5936 6127
 	})
5937 6128
 }
6129
+
6130
+func (this *StockManagerApiController) GetWarehouseTotal() {
6131
+
6132
+	id, _ := this.GetInt64("id")
6133
+	list, _ := service.GetWarehouseTotal(id)
6134
+	this.ServeSuccessJSON(map[string]interface{}{
6135
+		"list": list,
6136
+	})
6137
+}

+ 5 - 0
models/self_drug_models.go Dosyayı Görüntüle

@@ -756,6 +756,9 @@ type XtDrugDamage struct {
756 756
 	DrugOriginPlace   string  `gorm:"column:drug_origin_place" json:"drug_origin_place" form:"drug_origin_place"`
757 757
 	WarehousingInfoId int64   `gorm:"column:warehousing_info_id" json:"warehousing_info_id" form:"warehousing_info_id"`
758 758
 	BatchNumber       string  `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
759
+	StockMaxNumber    int64   `gorm:"column:stock_max_number" json:"stock_max_number" form:"stock_max_number"`
760
+	StockMinNumber    int64   `gorm:"column:stock_min_number" json:"stock_min_number" form:"stock_min_number"`
761
+	Total             string  `gorm:"column:total" json:"total" form:"total"`
759 762
 }
760 763
 
761 764
 func (XtDrugDamage) TableName() string {
@@ -794,6 +797,8 @@ type XtDrugInventory struct {
794 797
 	DrugOriginPlace   string  `gorm:"column:drug_origin_place" json:"drug_origin_place" form:"drug_origin_place"`
795 798
 	WarehouseInfoId   int64   `gorm:"column:warehouse_info_id" json:"warehouse_info_id" form:"warehouse_info_id"`
796 799
 	ProofCount        int64   `gorm:"column:proof_count" json:"proof_count" form:"proof_count"`
800
+	StockMaxNumber    int64   `gorm:"column:stock_max_number" json:"stock_max_number" form:"stock_max_number"`
801
+	StockMinNumber    int64   `gorm:"column:stock_min_number" json:"stock_min_number" form:"stock_min_number"`
797 802
 }
798 803
 
799 804
 func (XtDrugInventory) TableName() string {

+ 1 - 1
service/dialysis_service.go Dosyayı Görüntüle

@@ -1230,6 +1230,6 @@ func SaveHisProject(advice *models.HisPrescriptionProject) (err error) {
1230 1230
 }
1231 1231
 
1232 1232
 func FindAllHisProjectById(orgID int64, patient_id int64, record_time int64) (advice []*models.HisPrescriptionProject, err error) {
1233
-	err = readDb.Model(&models.HisPrescriptionProject{}).Where("user_org_id=? and status=1 and patient_id = ? AND record_date = ?", orgID, patient_id, record_time).Find(&advice).Error
1233
+	err = readDb.Model(&models.HisPrescriptionProject{}).Preload("HisProject", "status = 1").Where("user_org_id=? and status=1 and patient_id = ? AND record_date = ?", orgID, patient_id, record_time).Find(&advice).Error
1234 1234
 	return
1235 1235
 }

+ 1 - 1
service/patientmanage_service.go Dosyayı Görüntüle

@@ -1668,7 +1668,7 @@ func GetInspectionItemlist(patientid int64, inspect_date []string, projectid []s
1668 1668
 	table := XTReadDB().Table("xt_inspection_reference as s").Where("s.status = 1")
1669 1669
 	fmt.Println(table)
1670 1670
 	if patientid > 0 {
1671
-		db = db.Where("x.patient_id = ?", patientid)
1671
+		db = db.Where("x.patient_id = ? and x.inspect_value <> ''", patientid)
1672 1672
 	}
1673 1673
 	if len(inspect_date) > 0 {
1674 1674
 		db = db.Where("x.inspect_date in(?)", inspect_date)

+ 7 - 0
service/print_data_service/schedule_dialysis/print_schedule_dialysis_models.go Dosyayı Görüntüle

@@ -210,6 +210,7 @@ type PrescriptionVM struct {
210 210
 	PunctureNeedleCount        float64 `gorm:"column:puncture_needle_count" json:"puncture_needle_count" form:"puncture_needle_count"`
211 211
 	Epo                        string  `gorm:"column:epo" json:"epo" form:"epo"`
212 212
 	EpoCount                   float64 `gorm:"column:epo_count" json:"epo_count" form:"epo_count"`
213
+	MaxUltrafiltrationRate     float64 `gorm:"column:max_ultrafiltration_rate" json:"max_ultrafiltration_rate" form:"max_ultrafiltration_rate"`
213 214
 }
214 215
 
215 216
 func (PrescriptionVM) TableName() string {
@@ -354,6 +355,7 @@ type AssessmentAfterDislysisVM struct {
354 355
 	BloodFlow                       int64   `gorm:"column:blood_flow" json:"blood_flow" form:"blood_flow"`
355 356
 	SealingFluidDispose             string  `gorm:"column:sealing_fluid_dispose" json:"sealing_fluid_dispose" form:"sealing_fluid_dispose"`
356 357
 	SealingFluidSpecial             string  `gorm:"column:sealing_fluid_special" json:"sealing_fluid_special" form:"sealing_fluid_special"`
358
+	MachineRun                      string  `gorm:"column:machine_run" json:"machine_run" form:"machine_run"`
357 359
 }
358 360
 
359 361
 func (AssessmentAfterDislysisVM) TableName() string {
@@ -525,6 +527,11 @@ type MonitoringRecordVM struct {
525 527
 	Modify                    int64   `gorm:"column:modify" json:"modify" form:"modify"`
526 528
 	Heparin                   float64 `gorm:"column:heparin" json:"heparin" form:"heparin"`
527 529
 	DialysateFlow             float64 `gorm:"column:dialysate_flow" json:"dialysate_flow" form:"dialysate_flow"`
530
+	AccumulatedBloodVolume    float64 `gorm:"column:accumulated_blood_volume" json:"accumulated_blood_volume" form:"accumulated_blood_volume"`
531
+	BloodTemperature          float64 `gorm:"column:blood_temperature" json:"blood_temperature" form:"blood_temperature"`
532
+	UreaMonitoring            float64 `gorm:"column:urea_monitoring" json:"urea_monitoring" form:"urea_monitoring"`
533
+	BloodThickness            float64 `gorm:"column:blood_thickness" json:"blood_thickness" form:"blood_thickness"`
534
+	BloodMonitor              float64 `gorm:"column:blood_monitor" json:"blood_monitor" form:"blood_monitor"`
528 535
 }
529 536
 
530 537
 func (MonitoringRecordVM) TableName() string {

+ 69 - 14
service/self_drug_service.go Dosyayı Görüntüle

@@ -817,7 +817,7 @@ func PostSearchDrugWarehouseList(keyword string, orgid int64) (info []*models.Bl
817 817
 	if orgid > 0 {
818 818
 		db = db.Where("x.org_id = ?", orgid)
819 819
 	}
820
-	err = db.Select("x.id,x.warehousing_id,x.drug_id,x.number,x.product_date,x.expiry_date,x.warehousing_count,x.price,x.total_price,x.dealer,x.remark,x.warehousing_order,x.warehouseing_unit,x.stock_max_number,x.stock_min_number,x.batch_number,t.drug_origin_place,t.drug_name,t.min_unit,x.manufacturer,t.retail_price,t.max_unit,t.min_number,t.dose,t.dose_unit,t.last_price,t.drug_origin_place").Joins("left join xt_base_drug as t on t.id = x.drug_id").Where("t.drug_name like ? and t.org_id = ?", likeKey, orgid).Order("x.ctime desc").Scan(&info).Error
820
+	err = db.Group("x.drug_id").Select("x.id,x.warehousing_id,x.drug_id,t.number,x.product_date,x.expiry_date,x.warehousing_count,x.price,x.total_price,x.dealer,x.remark,x.warehousing_order,x.warehouseing_unit,x.stock_max_number,x.stock_min_number,x.batch_number,t.drug_origin_place,t.drug_name,t.min_unit,x.manufacturer,t.retail_price,t.max_unit,t.min_number,t.dose,t.dose_unit,t.last_price,t.drug_origin_place").Joins("left join xt_base_drug as t on t.id = x.drug_id").Where("t.drug_name like ? and t.org_id = ?", likeKey, orgid).Order("x.ctime desc").Scan(&info).Error
821 821
 	return info, err
822 822
 
823 823
 }
@@ -889,20 +889,23 @@ func CreateDrugDamage(damage models.XtDrugDamage) error {
889 889
 func GetDrugDamageList(startime int64, endtime int64, orgId int64, keyword string, limit int64, page int64) (adjust []*models.XtDrugDamage, total int64, err error) {
890 890
 	likeKey := "%" + keyword + "%"
891 891
 	offset := (page - 1) * limit
892
-	db := XTReadDB().Model(&adjust).Where("status = 1")
893
-	if startime > 0 {
894
-		db = db.Where("ctime >=?", startime)
895
-	}
896
-	if endtime > 0 {
897
-		db = db.Where("ctime<=?", endtime)
892
+	db := XTReadDB().Table("xt_drug_damage as x").Where("x.status = 1")
893
+	table := XTReadDB().Table("xt_base_drug as t").Where("t.status = 1")
894
+	tab := UserReadDB().Table("sgj_user_admin_role as r").Where("r.status = 1")
895
+	fmt.Println(table, tab)
896
+	if len(keyword) > 0 {
897
+		db = db.Where("x.warehousing_order = ? or r.user_name like ?", keyword, likeKey)
898 898
 	}
899 899
 	if orgId > 0 {
900
-		db = db.Where("user_org_id = ?", orgId)
900
+		db = db.Where("x.user_org_id = ?", orgId)
901 901
 	}
902
-	if len(keyword) > 0 {
903
-		db = db.Where("warehousing_order like ?", likeKey)
902
+	if startime > 0 {
903
+		db = db.Where("x.ctime >=?", startime)
904 904
 	}
905
-	err = db.Count(&total).Offset(offset).Limit(limit).Find(&adjust).Error
905
+	if endtime > 0 {
906
+		db = db.Where("x.ctime <=?", endtime)
907
+	}
908
+	err = db.Group("x.id").Select("x.id,x.drug_name,x.specification_name,x.warehousing_unit,x.count,x.last_price,x.retail_price,x.new_price,x.manufacturer,x.dealer,x.remark,x.drug_id,x.warehousing_order,x.start_time,x.creater,x.checker,x.checker_status,x.checker_time,x.number,x.drug_origin_place,x.warehousing_info_id,x.batch_number,x.stock_max_number,x.stock_min_number").Joins("left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.creater").Joins("left join xt_base_drug as t on t.id =x.drug_id").Count(&total).Offset(offset).Limit(limit).Scan(&adjust).Error
906 909
 	return adjust, total, err
907 910
 }
908 911
 
@@ -920,7 +923,7 @@ func GetDrugModifyPrice(id int64) (models.XtDrugAdjustPrice, error) {
920 923
 
921 924
 func ModifyDrugPrice(id int64, adjust models.XtDrugAdjustPrice) error {
922 925
 
923
-	err := XTWriteDB().Model(&adjust).Where("id=? and status = 1", id).Updates(map[string]interface{}{"drug_name": adjust.DrugName, "retail_price": adjust.RetailPrice, "new_price": adjust.NewPrice, "count": adjust.Count, "remark": adjust.Remark}).Error
926
+	err := XTWriteDB().Model(&adjust).Where("id=? and status = 1", id).Updates(map[string]interface{}{"drug_name": adjust.DrugName, "retail_price": adjust.RetailPrice, "new_price": adjust.NewPrice, "count": adjust.Count, "remark": adjust.Remark, "specification_name": adjust.SpecificationName, "warehousing_unit": adjust.WarehousingUnit, "manufacturer": adjust.Manufacturer, "number": adjust.Number, "drug_id": adjust.DrugId}).Error
924 927
 	return err
925 928
 }
926 929
 
@@ -939,7 +942,7 @@ func GetDrugDamageDetail(id int64) (models.XtDrugDamage, error) {
939 942
 
940 943
 func ModifyDrugDamage(id int64, damage models.XtDrugDamage) error {
941 944
 
942
-	err := XTWriteDB().Model(&damage).Where("id=? and status = 1", id).Updates(map[string]interface{}{"drug_name": damage.DrugName, "warehousing_unit": damage.WarehousingUnit, "count": damage.Count, "last_price": damage.LastPrice, "retail_price": damage.RetailPrice, "new_price": damage.NewPrice, "manufacturer": damage.Manufacturer, "remark": damage.Remark, "number": damage.Number, "drug_id": damage.DrugId}).Error
945
+	err := XTWriteDB().Model(&damage).Where("id=? and status = 1", id).Updates(map[string]interface{}{"drug_name": damage.DrugName, "warehousing_unit": damage.WarehousingUnit, "count": damage.Count, "last_price": damage.LastPrice, "retail_price": damage.RetailPrice, "new_price": damage.NewPrice, "manufacturer": damage.Manufacturer, "remark": damage.Remark, "number": damage.Number, "drug_id": damage.DrugId, "stock_max_number": damage.StockMaxNumber, "stock_min_number": damage.StockMinNumber, "warehousing_info_id": damage.WarehousingInfoId, "drug_origin_place": damage.DrugOriginPlace}).Error
943 946
 	return err
944 947
 }
945 948
 
@@ -997,6 +1000,39 @@ func UpdateDrugInventory(ids []string, inventory models.XtDrugInventory) error {
997 1000
 	return err
998 1001
 }
999 1002
 
1003
+func GetDrugInventoryListByIds(ids []string) (inventory []*models.XtDrugInventory, err error) {
1004
+
1005
+	err = XTReadDB().Model(&inventory).Where("id in(?) and status = 1", ids).Find(&inventory).Error
1006
+	return inventory, err
1007
+}
1008
+
1009
+func GetDrugDetailByDrugId(drug_id int64) (models.XtBaseDrug, error) {
1010
+
1011
+	drug := models.XtBaseDrug{}
1012
+	err := XTReadDB().Model(&drug).Where("id = ? and status = 1", drug_id).Find(&drug).Error
1013
+	return drug, err
1014
+}
1015
+
1016
+func GetDrugWareInfoById(id int64) (models.XtDrugWarehouseInfo, error) {
1017
+	info := models.XtDrugWarehouseInfo{}
1018
+	err := XTReadDB().Model(&info).Where("id = ? and status = 1", id).Find(&info).Error
1019
+	return info, err
1020
+}
1021
+
1022
+func GetLastDrugWarehouseInfo(drugid int64) (models.XtDrugWarehouseInfo, error) {
1023
+
1024
+	info := models.XtDrugWarehouseInfo{}
1025
+	err := XTReadDB().Model(&info).Where("id=? and status = 1", drugid).Last(&info).Error
1026
+	return info, err
1027
+}
1028
+
1029
+func GetFirstDrugWarehouseInfo(drugid int64) (models.XtDrugWarehouseInfo, error) {
1030
+
1031
+	info := models.XtDrugWarehouseInfo{}
1032
+	err := XTReadDB().Model(&info).Where("id=? and status = 1", drugid).First(&info).Error
1033
+	return info, err
1034
+}
1035
+
1000 1036
 func GetDrugInventoryDetail(id int64) (models.XtDrugInventory, error) {
1001 1037
 
1002 1038
 	inventory := models.XtDrugInventory{}
@@ -1006,7 +1042,7 @@ func GetDrugInventoryDetail(id int64) (models.XtDrugInventory, error) {
1006 1042
 
1007 1043
 func ModifyDrugInventory(id int64, info models.XtDrugInventory) error {
1008 1044
 
1009
-	err := XTWriteDB().Model(&info).Where("id=? and status = 1", id).Updates(map[string]interface{}{"drug_name": info.DrugName, "specification_name": info.SpecificationName, "warehousing_unit": info.WarehousingUnit, "count": info.Count, "last_price": info.LastPrice, "manufacturer": info.Manufacturer, "remark": info.Remark, "drug_id": info.DrugId, "warehousing_order": info.WarehousingOrder, "number": info.Number, "total": info.Number, "drug_origin_place": info.DrugOriginPlace}).Error
1045
+	err := XTWriteDB().Model(&info).Where("id=? and status = 1", id).Updates(map[string]interface{}{"drug_name": info.DrugName, "specification_name": info.SpecificationName, "warehousing_unit": info.WarehousingUnit, "count": info.Count, "last_price": info.LastPrice, "manufacturer": info.Manufacturer, "remark": info.Remark, "drug_id": info.DrugId, "warehousing_order": info.WarehousingOrder, "number": info.Number, "total": info.Number, "drug_origin_place": info.DrugOriginPlace, "stock_max_number": info.StockMaxNumber, "stock_min_number": info.StockMinNumber, "warehouse_info_id": info.WarehouseInfoId}).Error
1010 1046
 	return err
1011 1047
 }
1012 1048
 
@@ -1051,3 +1087,22 @@ func UpdateDrugWarehouseInfoById(id int64, inventory *models.XtDrugWarehouseInfo
1051 1087
 	err := XTWriteDB().Model(&inventory).Where("id = ?", id).Updates(map[string]interface{}{"stock_max_number": inventory.StockMaxNumber}).Error
1052 1088
 	return err
1053 1089
 }
1090
+
1091
+func GetDrugWarehouseInfoTotal(id int64) (models.XtDrugWarehouseInfo, error) {
1092
+
1093
+	info := models.XtDrugWarehouseInfo{}
1094
+	err := XTReadDB().Where("id = ? and status = 1", id).Preload("XtBaseDrug", "status = 1").Find(&info).Error
1095
+	return info, err
1096
+}
1097
+
1098
+func CreateDrugWarehouseInfo(info models.DrugWarehouseInfo) error {
1099
+
1100
+	err := XTWriteDB().Create(&info).Error
1101
+	return err
1102
+}
1103
+
1104
+func CreateDrugWarehouseOutInfo(info models.DrugWarehouseOutInfo) error {
1105
+
1106
+	err := XTWriteDB().Create(&info).Error
1107
+	return err
1108
+}

+ 81 - 17
service/stock_service.go Dosyayı Görüntüle

@@ -508,7 +508,7 @@ func UpdateBaseDrug(lib *models.BaseDrugLib, id int64) error {
508 508
 
509 509
 func UpdateBaseDrugOne(lib models.BaseDrugLib, id int64) error {
510 510
 
511
-	err := XTWriteDB().Model(&lib).Where("id = ?", id).Updates(map[string]interface{}{"retail_price": lib.RetailPrice}).Error
511
+	err := XTWriteDB().Model(&lib).Where("id = ?", id).Updates(map[string]interface{}{"retail_price": lib.RetailPrice, "last_price": lib.LastPrice}).Error
512 512
 	return err
513 513
 }
514 514
 func FindeLastWarehouseInfo(id int64) (models.DrugWarehouseInfo, error) {
@@ -571,6 +571,20 @@ func CreateDrugFlow(drugflow []*models.DrugFlow) (err error) {
571 571
 	return
572 572
 }
573 573
 
574
+func GetDrugByWarehouseInfo(id int64) (models.XtDrugWarehouseInfo, error) {
575
+
576
+	info := models.XtDrugWarehouseInfo{}
577
+	err := XTReadDB().Where("id=? and status = 1", id).Find(&info).Error
578
+	return info, err
579
+}
580
+
581
+func UpdateDrugWarehouseingInfo(id int64, info models.XtDrugWarehouseInfo) error {
582
+
583
+	warehouseInfo := models.XtDrugWarehouseInfo{}
584
+	err := XTReadDB().Model(&warehouseInfo).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"stock_max_number": info.StockMaxNumber}).Error
585
+	return err
586
+}
587
+
574 588
 func CreateDrugFlowOne(flow models.DrugFlow) error {
575 589
 
576 590
 	err := XTWriteDB().Create(&flow).Error
@@ -2542,6 +2556,12 @@ func AddSigleWarehouseOutInfo(info *models.WarehouseOutInfo) error {
2542 2556
 
2543 2557
 }
2544 2558
 
2559
+func UpdateStockOut(warehouseinfoid int64, info models.WarehousingInfo) error {
2560
+
2561
+	err := XTWriteDB().Model(&info).Where("id=? and status = 1", warehouseinfoid).Updates(map[string]interface{}{"stock_count": info.StockCount}).Error
2562
+	return err
2563
+}
2564
+
2545 2565
 func AddSigleDrugWarehouseOutInfo(info *models.DrugWarehouseOutInfo) error {
2546 2566
 	ut := writeDb.Begin()
2547 2567
 	err := ut.Create(&info).Error
@@ -3299,17 +3319,19 @@ func GetAutoDiallysisBefor(startime int64, endtime int64, orgid int64) (info []*
3299 3319
 
3300 3320
 func GetOutStockTotalCountFour(startime int64, endtime int64, orgid int64) (autoMatic []*models.NewXtAutomaticReduceDetail, err error) {
3301 3321
 
3302
-	if startime > 0 {
3303
-		err = XTReadDB().Raw("SELECT good_id,SUM(b.count) as count FROM (SELECT DISTINCT x.patient_id,x.good_id,x.count FROM xt_automatic_reduce_detail as x WHERE x.org_id = ? and x.record_time >=?  and `status` = 1)  as b GROUP BY good_id", orgid, startime).Scan(&autoMatic).Error
3304
-	} else {
3305
-		err = XTReadDB().Raw("SELECT good_id,SUM(b.count) as count FROM (SELECT DISTINCT x.patient_id,x.good_id,x.count FROM xt_automatic_reduce_detail as x WHERE x.org_id = ? and `status` = 1)  as b GROUP BY good_id", orgid).Scan(&autoMatic).Error
3306
-	}
3322
+	//if startime > 0 {
3323
+	//	err = XTReadDB().Raw("SELECT good_id,SUM(b.count) as count FROM (SELECT DISTINCT x.patient_id,x.good_id,x.count FROM xt_automatic_reduce_detail as x WHERE x.org_id = ? and x.record_time >=?  and `status` = 1)  as b GROUP BY good_id", orgid, startime).Scan(&autoMatic).Error
3324
+	//} else {
3325
+	//	err = XTReadDB().Raw("SELECT good_id,SUM(b.count) as count FROM (SELECT DISTINCT x.patient_id,x.good_id,x.count FROM xt_automatic_reduce_detail as x WHERE x.org_id = ? and `status` = 1)  as b GROUP BY good_id", orgid).Scan(&autoMatic).Error
3326
+	//}
3327
+	//
3328
+	//if endtime > 0 {
3329
+	//	err = XTReadDB().Raw("SELECT good_id,SUM(b.count) as count FROM (SELECT DISTINCT x.patient_id,x.good_id,x.count FROM xt_automatic_reduce_detail as x WHERE x.org_id = ? and x.record_time <=?  and `status` = 1)  as b GROUP BY good_id", orgid, endtime).Scan(&autoMatic).Error
3330
+	//} else {
3331
+	//	err = XTReadDB().Raw("SELECT good_id,SUM(b.count) as count FROM (SELECT DISTINCT x.patient_id,x.good_id,x.count FROM xt_automatic_reduce_detail as x WHERE x.org_id = ? and `status` = 1)  as b GROUP BY good_id", orgid).Scan(&autoMatic).Error
3332
+	//}
3307 3333
 
3308
-	if endtime > 0 {
3309
-		err = XTReadDB().Raw("SELECT good_id,SUM(b.count) as count FROM (SELECT DISTINCT x.patient_id,x.good_id,x.count FROM xt_automatic_reduce_detail as x WHERE x.org_id = ? and x.record_time <=?  and `status` = 1)  as b GROUP BY good_id", orgid, endtime).Scan(&autoMatic).Error
3310
-	} else {
3311
-		err = XTReadDB().Raw("SELECT good_id,SUM(b.count) as count FROM (SELECT DISTINCT x.patient_id,x.good_id,x.count FROM xt_automatic_reduce_detail as x WHERE x.org_id = ? and `status` = 1)  as b GROUP BY good_id", orgid).Scan(&autoMatic).Error
3312
-	}
3334
+	err = XTReadDB().Raw("SELECT good_id,SUM(b.count) as count FROM (SELECT DISTINCT x.patient_id,x.good_id,x.record_time,x.count FROM xt_automatic_reduce_detail as x WHERE x.org_id = ? and x.record_time >= ? and x.record_time<=? and `status` = 1)  as b GROUP BY good_id", orgid, startime, endtime).Scan(&autoMatic).Error
3313 3335
 
3314 3336
 	return autoMatic, err
3315 3337
 
@@ -4223,13 +4245,38 @@ func UpdateWarehouseInfoOne(count int64, drugid int64, orgid int64) error {
4223 4245
 	return err
4224 4246
 }
4225 4247
 
4226
-func GetWarehouseInfoById(id int64) (models.WarehousingInfo, error) {
4248
+func GetWarehouseInfoByIdSeven(id int64) (models.WarehousingInfo, error) {
4227 4249
 
4228 4250
 	info := models.WarehousingInfo{}
4229 4251
 	err := XTReadDB().Model(&info).Where("id = ? and status = 1", id).Find(&info).Error
4230 4252
 	return info, err
4231 4253
 }
4232 4254
 
4255
+func GetLastWarehouseInfo(goodid int64) (models.WarehousingInfo, error) {
4256
+
4257
+	info := models.WarehousingInfo{}
4258
+	err := XTReadDB().Model(&info).Where("good_id = ? and status = 1", goodid).Last(&info).Error
4259
+	return info, err
4260
+}
4261
+
4262
+func GetFirstWarehouseInfo(goodid int64) (models.WarehousingInfo, error) {
4263
+	info := models.WarehousingInfo{}
4264
+	err := XTReadDB().Model(&info).Where("good_id = ? and status = 1", goodid).First(&info).Error
4265
+	return info, err
4266
+}
4267
+
4268
+func CreateWarehouseOut(out models.WarehouseOut) error {
4269
+
4270
+	err := XTWriteDB().Create(&out).Error
4271
+	return err
4272
+}
4273
+
4274
+func CreateWarehouseInfo(info models.WarehousingInfo) error {
4275
+
4276
+	err := XTReadDB().Create(&info).Error
4277
+	return err
4278
+}
4279
+
4233 4280
 func UpdateGoodWarehouseInfo(id int64, info models.WarehousingInfo) error {
4234 4281
 
4235 4282
 	err := XTWriteDB().Model(&info).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"stock_count": info.StockCount}).Error
@@ -4352,7 +4399,7 @@ func UpdateAdjustPrice(ids []string, info models.XtStockAdjustPrice) error {
4352 4399
 
4353 4400
 func UpdateAdjustCheckPrice(info *models.GoodInfo, id int64) error {
4354 4401
 
4355
-	err := XTWriteDB().Model(&info).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"packing_price": info.PackingPrice}).Error
4402
+	err := XTWriteDB().Model(&info).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"packing_price": info.PackingPrice, "buy_price": info.BuyPrice}).Error
4356 4403
 	return err
4357 4404
 }
4358 4405
 
@@ -4430,11 +4477,9 @@ func GetInventorylist(startime int64, endtime int64, page int64, limit int64, in
4430 4477
 		db = db.Where("x.end_time<=?", endtime)
4431 4478
 	}
4432 4479
 	if len(keyword) > 0 {
4433
-		db = db.Where("x.warehousing_order like ?", likeKey)
4434
-	}
4435
-	if len(keyword) > 0 {
4436
-		db = db.Where("r.user_name like ?", likeKey)
4480
+		db = db.Where("x.warehousing_order like ? or r.user_name like ?", likeKey, likeKey)
4437 4481
 	}
4482
+
4438 4483
 	if orgid > 0 {
4439 4484
 		db = db.Where("x.user_org_id = ?", orgid)
4440 4485
 	}
@@ -4457,6 +4502,19 @@ func GetModifyPriceDetail(id int64) (models.XtStockAdjustPrice, error) {
4457 4502
 	return info, err
4458 4503
 }
4459 4504
 
4505
+func GetInventoryDetailById(id []string) (list []*models.XtStockInventory, err error) {
4506
+
4507
+	err = XTReadDB().Model(&list).Where("id in(?) and status = 1", id).Find(&list).Error
4508
+	return list, err
4509
+}
4510
+
4511
+func GetWarehouseInfoById(id int64) (models.WarehousingInfo, error) {
4512
+
4513
+	info := models.WarehousingInfo{}
4514
+	err := XTReadDB().Model(&info).Where("id = ? and status = 1", id).Find(&info).Error
4515
+	return info, err
4516
+}
4517
+
4460 4518
 func UpdateStockPrice(info models.XtStockAdjustPrice, id int64) error {
4461 4519
 
4462 4520
 	err := XTWriteDB().Model(&info).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"new_price": info.NewPrice, "good_name": info.GoodName, "packing_price": info.PackingPrice, "good_id": info.GoodId, "remark": info.Remark, "manufacturer": info.Manufacturer, "dealer": info.Dealer}).Error
@@ -4578,3 +4636,9 @@ func CeateStockCorrectRecord(record models.XtStockCorrectRecord) error {
4578 4636
 	err := XTWriteDB().Create(&record).Error
4579 4637
 	return err
4580 4638
 }
4639
+
4640
+func GetWarehouseTotal(id int64) (models.WarehousingInfo, error) {
4641
+	info := models.WarehousingInfo{}
4642
+	err := XTReadDB().Where("id=? and status = 1", id).Find(&info).Error
4643
+	return info, err
4644
+}