Browse Source

11月9日库存管理

XMLWAN 1 year ago
parent
commit
99369a3ae9

+ 2 - 2
conf/app.conf View File

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

+ 0 - 1
controllers/his_api_controller.go View File

6645
 			infos = append(infos, &info.HisDoctorAdviceInfo)
6645
 			infos = append(infos, &info.HisDoctorAdviceInfo)
6646
 		}
6646
 		}
6647
 		if info.ProjectId > 0 && info.AdviceId == 0 {
6647
 		if info.ProjectId > 0 && info.AdviceId == 0 {
6648
-			fmt.Println("info232323233232233", order_id)
6649
 			if info.HisPrescriptionProject.Type == 3 {
6648
 			if info.HisPrescriptionProject.Type == 3 {
6650
 				var good models.DialysisBeforePrepareGoods
6649
 				var good models.DialysisBeforePrepareGoods
6651
 				var newGood models.NewDialysisBeforePrepareGoods
6650
 				var newGood models.NewDialysisBeforePrepareGoods

+ 0 - 3
controllers/patient_api_controller.go View File

4526
 	limit, _ := c.GetInt64("limit", 10)
4526
 	limit, _ := c.GetInt64("limit", 10)
4527
 	adminUserInfo := c.GetAdminUserInfo()
4527
 	adminUserInfo := c.GetAdminUserInfo()
4528
 	total, patients, _ := service.GetAllWaitRemindPatient(adminUserInfo.CurrentOrgId, page, limit)
4528
 	total, patients, _ := service.GetAllWaitRemindPatient(adminUserInfo.CurrentOrgId, page, limit)
4529
-	fmt.Println("机构ID2222222222222", c.GetAdminUserInfo().CurrentOrgId)
4530
-
4531
 	_, errcode := service.GetOrgFollowIsExist(c.GetAdminUserInfo().CurrentOrgId)
4529
 	_, errcode := service.GetOrgFollowIsExist(c.GetAdminUserInfo().CurrentOrgId)
4532
-	fmt.Println("机构ID2222222222222", errcode)
4533
 	if errcode == gorm.ErrRecordNotFound {
4530
 	if errcode == gorm.ErrRecordNotFound {
4534
 		information, err := service.GetAdminUserRoleInformation(0)
4531
 		information, err := service.GetAdminUserRoleInformation(0)
4535
 		if err != nil {
4532
 		if err != nil {

+ 0 - 1
controllers/self_drug_api_congtroller.go View File

3410
 	for _, it := range drug {
3410
 	for _, it := range drug {
3411
 		var sum_count int64
3411
 		var sum_count int64
3412
 		var limit_count int64
3412
 		var limit_count int64
3413
-		fmt.Println("it233323323232323223", it.DrugName)
3414
 		drugInfo, _ := service.GetDrugWarehouseInfoName(it.ID, orgId)
3413
 		drugInfo, _ := service.GetDrugWarehouseInfoName(it.ID, orgId)
3415
 		for _, item := range drugInfo {
3414
 		for _, item := range drugInfo {
3416
 
3415
 

+ 57 - 0
controllers/stock_in_api_controller.go View File

154
 	beego.Router("/api/settle/stock", &StockManagerApiController{}, "Get:HandleSettleStock")
154
 	beego.Router("/api/settle/stock", &StockManagerApiController{}, "Get:HandleSettleStock")
155
 	beego.Router("/api/settle/cancelstock", &StockManagerApiController{}, "Get:HandleRefundStock")
155
 	beego.Router("/api/settle/cancelstock", &StockManagerApiController{}, "Get:HandleRefundStock")
156
 
156
 
157
+	beego.Router("/api/stock/getnewgoodwarehouseinfo", &StockManagerApiController{}, "Get:GetNewGoodWarehouseInfo")
158
+
157
 }
159
 }
158
 func (c *StockManagerApiController) HandleRefundStock() {
160
 func (c *StockManagerApiController) HandleRefundStock() {
159
 	order_id, _ := c.GetInt64("order_id", 0)
161
 	order_id, _ := c.GetInt64("order_id", 0)
663
 				manufacturer := int64(items["manufacturer"].(float64))
665
 				manufacturer := int64(items["manufacturer"].(float64))
664
 				dealer := int64(items["dealer"].(float64))
666
 				dealer := int64(items["dealer"].(float64))
665
 				license_number, _ := items["license_number"].(string)
667
 				license_number, _ := items["license_number"].(string)
668
+				register_number, _ := items["register_number"].(string)
666
 				if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
669
 				if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
667
 					utils.ErrorLog("id")
670
 					utils.ErrorLog("id")
668
 					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
671
 					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
694
 						PackingPrice:     packing_price,
697
 						PackingPrice:     packing_price,
695
 						StorehouseId:     storehouse_id,
698
 						StorehouseId:     storehouse_id,
696
 						IsCheck:          2,
699
 						IsCheck:          2,
700
+						RegisterNumber:   register_number,
697
 					}
701
 					}
698
 					warehousingInfo = append(warehousingInfo, warehouseInfo)
702
 					warehousingInfo = append(warehousingInfo, warehouseInfo)
699
 
703
 
721
 						LicenseNumber:    license_number,
725
 						LicenseNumber:    license_number,
722
 						PackingPrice:     packing_price,
726
 						PackingPrice:     packing_price,
723
 						StorehouseId:     storehouse_id,
727
 						StorehouseId:     storehouse_id,
728
+						RegisterNumber:   register_number,
724
 					}
729
 					}
725
 					upDateWarehousingInfo = append(upDateWarehousingInfo, warehouseInfo)
730
 					upDateWarehousingInfo = append(upDateWarehousingInfo, warehouseInfo)
726
 
731
 
745
 						ConsumableType:      1,
750
 						ConsumableType:      1,
746
 						WarehousingDetailId: warehouseInfo.ID,
751
 						WarehousingDetailId: warehouseInfo.ID,
747
 						StorehouseId:        storehouse_id,
752
 						StorehouseId:        storehouse_id,
753
+						RegisterNumber:      register_number,
748
 					}
754
 					}
749
 
755
 
750
 					stockFlow = append(stockFlow, flow)
756
 					stockFlow = append(stockFlow, flow)
7801
 		"dealerList":       dealerList,
7807
 		"dealerList":       dealerList,
7802
 	})
7808
 	})
7803
 }
7809
 }
7810
+
7811
+func (this *StockManagerApiController) GetNewGoodWarehouseInfo() {
7812
+
7813
+	timeLayout := "2006-01-02"
7814
+	loc, _ := time.LoadLocation("Local")
7815
+	start_time := this.GetString("start_time")
7816
+	end_time := this.GetString("end_time")
7817
+	var startTime int64
7818
+	if len(start_time) > 0 {
7819
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
7820
+		if err != nil {
7821
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
7822
+			return
7823
+		}
7824
+		startTime = theTime.Unix()
7825
+
7826
+	}
7827
+	var endTime int64
7828
+	if len(end_time) > 0 {
7829
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
7830
+		if err != nil {
7831
+			utils.ErrorLog(err.Error())
7832
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
7833
+			return
7834
+		}
7835
+		endTime = theTime.Unix()
7836
+	}
7837
+	storehouse_id, _ := this.GetInt64("storehouse_id")
7838
+
7839
+	keywords := this.GetString("keywords")
7840
+
7841
+	orgId := this.GetAdminUserInfo().CurrentOrgId
7842
+
7843
+	var goodids []int64
7844
+	//查询商品名称
7845
+	if len(keywords) > 0 {
7846
+		//查询商品名称
7847
+		list, _ := service.GetGoodInforByGoodName(keywords, orgId)
7848
+		for _, item := range list {
7849
+			goodids = append(goodids, item.ID)
7850
+			//入库详情但里面查询
7851
+		}
7852
+	}
7853
+
7854
+	list, _ := service.GetNewGoodWarehouseInfo(startTime, endTime, orgId, goodids, storehouse_id)
7855
+	this.ServeSuccessJSON(map[string]interface{}{
7856
+		"list": list,
7857
+		//"manufacturerList": manufacturerList,
7858
+		//"dealerList":       dealerList,
7859
+	})
7860
+}

+ 11 - 6
service/manage_center_service.go View File

461
 			var sum_count int64  //该批次总库存
461
 			var sum_count int64  //该批次总库存
462
 			var over_count int64 //剩余数量
462
 			var over_count int64 //剩余数量
463
 
463
 
464
-			over_count = druginfo.StockMaxNumber*drug.MinNumber + druginfo.StockMinNumber
464
+			if druginfo.MaxUnit != druginfo.MinUnit {
465
+				over_count = druginfo.StockMaxNumber*drug.MinNumber + druginfo.StockMinNumber
466
+			}
467
+			if druginfo.MaxUnit == druginfo.MinUnit {
468
+				over_count = druginfo.StockMaxNumber + druginfo.StockMinNumber
469
+			}
470
+
465
 			if infos.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
471
 			if infos.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
466
-				out_count = info.Count * drug.MinNumber
472
+				out_count = infos.Count * drug.MinNumber
467
 
473
 
468
 			}
474
 			}
469
 			if infos.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
475
 			if infos.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
491
 			fmt.Println("g该批次总库存wowowoowow", sum_count)
497
 			fmt.Println("g该批次总库存wowowoowow", sum_count)
492
 			if (over_count + out_count) <= sum_count {
498
 			if (over_count + out_count) <= sum_count {
493
 				if its.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
499
 				if its.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
494
-
500
+					fmt.Print("itscoutn233232223999wi", its.Count)
495
 					//退库
501
 					//退库
496
 					warehouseInfo := models.DrugWarehouseInfo{
502
 					warehouseInfo := models.DrugWarehouseInfo{
497
 						StockMinNumber: its.Count,
503
 						StockMinNumber: its.Count,
505
 
511
 
506
 				}
512
 				}
507
 				if its.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
513
 				if its.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
508
-
514
+					fmt.Print("itscoutn999888", its.Count)
509
 					warehouseInfo := models.DrugWarehouseInfo{
515
 					warehouseInfo := models.DrugWarehouseInfo{
510
 						StockMaxNumber: its.Count,
516
 						StockMaxNumber: its.Count,
511
 					}
517
 					}
518
 				}
524
 				}
519
 
525
 
520
 				if its.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
526
 				if its.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
521
-
527
+					fmt.Print("itscoutnwohhhhwhw", its.Count)
522
 					warehouseInfo := models.DrugWarehouseInfo{
528
 					warehouseInfo := models.DrugWarehouseInfo{
523
 						StockMaxNumber: its.Count,
529
 						StockMaxNumber: its.Count,
524
 					}
530
 					}
906
 
912
 
907
 func GoodAutoAddCancelInfo(good *models.NewDialysisBeforePrepareGoods, creater int64) error {
913
 func GoodAutoAddCancelInfo(good *models.NewDialysisBeforePrepareGoods, creater int64) error {
908
 
914
 
909
-	fmt.Print("order_id223233232323223323223wo", good.OrderId)
910
 	//查询已经出库数量
915
 	//查询已经出库数量
911
 	info, _ := GetWareOutInfo(good.GoodId, good.RecordDate, good.UserOrgId, good.PatientId, good.OrderId)
916
 	info, _ := GetWareOutInfo(good.GoodId, good.RecordDate, good.UserOrgId, good.PatientId, good.OrderId)
912
 	if len(info) > 0 {
917
 	if len(info) > 0 {

+ 111 - 39
service/new_warehouse_service.go View File

1848
 			AddDrugCount(advice.DrugId, orgID, storeConfig.DrugStorehouseOut, drugflow.Count)
1848
 			AddDrugCount(advice.DrugId, orgID, storeConfig.DrugStorehouseOut, drugflow.Count)
1849
 		}
1849
 		}
1850
 
1850
 
1851
+		fmt.Println("libai", out_count)
1852
+		fmt.Println("cancel", cancel_count)
1853
+		fmt.Println("deliver_number", deliver_number)
1851
 		if deliver_number < (out_count - cancel_count) {
1854
 		if deliver_number < (out_count - cancel_count) {
1852
 			operation_time := time.Now().Unix()
1855
 			operation_time := time.Now().Unix()
1853
 
1856
 
2002
 
2005
 
2003
 func UpdateSingleDrugWarehouseOutInfoSix(patient_id int64, advice_date int64, orgid int64, info *models.DrugWarehouseOutInfo, advice_id int64) error {
2006
 func UpdateSingleDrugWarehouseOutInfoSix(patient_id int64, advice_date int64, orgid int64, info *models.DrugWarehouseOutInfo, advice_id int64) error {
2004
 
2007
 
2005
-	err := XTWriteDB().Model(&models.XtDrugWarehouseOutInfo{}).Where("patient_id = ? and sys_record_time = ? and org_id = ? and advice_id = ?", patient_id, advice_date, orgid, advice_id).Update(map[string]interface{}{"count": info.Count, "price": info.Price, "total_price": info.TotalPrice, "product_date": info.ProductDate, "expiry_date": info.ExpiryDate, "remark": info.Remark, "dealer": info.Dealer, "manufacturer": info.Manufacturer, "retail_price": info.RetailPrice, "number": info.Number, "batch_number": info.BatchNumber, "count_unit": info.CountUnit, "warehouse_info_id": info.WarehouseInfoId, "storehouse_id": info.StorehouseId}).Error
2008
+	err := XTWriteDB().Model(&models.XtDrugWarehouseOutInfo{}).Where("patient_id = ? and sys_record_time = ? and org_id = ? and advice_id = ? and status= 1", patient_id, advice_date, orgid, advice_id).Update(map[string]interface{}{"count": info.Count, "price": info.Price, "total_price": info.TotalPrice, "product_date": info.ProductDate, "expiry_date": info.ExpiryDate, "remark": info.Remark, "dealer": info.Dealer, "manufacturer": info.Manufacturer, "retail_price": info.RetailPrice, "number": info.Number, "batch_number": info.BatchNumber, "count_unit": info.CountUnit, "warehouse_info_id": info.WarehouseInfoId, "storehouse_id": info.StorehouseId}).Error
2006
 	return err
2009
 	return err
2007
 }
2010
 }
2008
 
2011
 
2083
 
2086
 
2084
 	stock := models.DrugCancelStock{}
2087
 	stock := models.DrugCancelStock{}
2085
 	var err error
2088
 	var err error
2086
-	err = XTReadDB().Where("return_date = ? and org_id = ? and status = 1", return_date, org_id).Find(&stock).Error
2089
+	err = XTReadDB().Where("return_time = ? and org_id = ? and status = 1", return_date, org_id).Find(&stock).Error
2087
 	if err == gorm.ErrRecordNotFound {
2090
 	if err == gorm.ErrRecordNotFound {
2088
 		return nil, err
2091
 		return nil, err
2089
 	}
2092
 	}
2096
 func FindLastDrugCancelStock(advice_date int64, org_id int64) (models.DrugCancelStock, error) {
2099
 func FindLastDrugCancelStock(advice_date int64, org_id int64) (models.DrugCancelStock, error) {
2097
 
2100
 
2098
 	cancelStock := models.DrugCancelStock{}
2101
 	cancelStock := models.DrugCancelStock{}
2099
-	err := XTReadDB().Where("return_date = ? and org_id = ? and status = 1", advice_date, org_id).Find(&cancelStock).Error
2102
+	err := XTReadDB().Where("return_time = ? and org_id = ? and status = 1", advice_date, org_id).Find(&cancelStock).Error
2100
 	return cancelStock, err
2103
 	return cancelStock, err
2101
 }
2104
 }
2102
 
2105
 
2127
 }
2130
 }
2128
 
2131
 
2129
 // 药品自动出库 递归方式
2132
 // 药品自动出库 递归方式
2130
-func HisSettleDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *models.DrugWarehouseOut, drup *models.BaseDrugLib, advice *models.HisDoctorAdviceInfo) (err error) {
2133
+func HisSettleDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *models.DrugWarehouseOut, drup *models.BaseDrugLib, advice *models.HisDoctorAdviceInfo, prescribingCount float64) (err error) {
2131
 
2134
 
2132
 	// 判断处方里药品单位是拆零单位还是包装单位,	如果是包装单位,则根据规格,将包装数量转为拆零数量
2135
 	// 判断处方里药品单位是拆零单位还是包装单位,	如果是包装单位,则根据规格,将包装数量转为拆零数量
2133
 	var deliver_number int64 = 0
2136
 	var deliver_number int64 = 0
2137
+	var deliver_number_one int64 = 0
2134
 	var stock_number int64 = 0
2138
 	var stock_number int64 = 0
2135
 
2139
 
2136
 	prescribingNumber_temp := strconv.FormatFloat(math.Abs(prescribingNumber), 'f', 0, 64)
2140
 	prescribingNumber_temp := strconv.FormatFloat(math.Abs(prescribingNumber), 'f', 0, 64)
2137
 	count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
2141
 	count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
2138
 
2142
 
2143
+	prescribingCount_temp := strconv.FormatFloat(math.Abs(prescribingCount), 'f', 0, 64)
2144
+	prescribe_count, _ := strconv.ParseInt(prescribingCount_temp, 10, 64)
2145
+
2139
 	var drug_price float64
2146
 	var drug_price float64
2140
 	if advice.PrescribingNumberUnit == drup.MaxUnit {
2147
 	if advice.PrescribingNumberUnit == drup.MaxUnit {
2141
 		deliver_number = count * drup.MinNumber
2148
 		deliver_number = count * drup.MinNumber
2145
 
2152
 
2146
 	}
2153
 	}
2147
 
2154
 
2155
+	if advice.PrescribingNumberUnit == drup.MaxUnit {
2156
+		deliver_number_one = prescribe_count * drup.MinNumber
2157
+
2158
+	} else {
2159
+		deliver_number_one = prescribe_count
2160
+
2161
+	}
2162
+
2148
 	if advice.PrescribingNumberUnit == drup.MaxUnit {
2163
 	if advice.PrescribingNumberUnit == drup.MaxUnit {
2149
 		drug_price = drup.RetailPrice
2164
 		drug_price = drup.RetailPrice
2150
 	}
2165
 	}
2162
 	// 如果没有对应的库存,则报错
2177
 	// 如果没有对应的库存,则报错
2163
 	storeConfig, _ := GetAllStoreHouseConfig(advice.UserOrgId)
2178
 	storeConfig, _ := GetAllStoreHouseConfig(advice.UserOrgId)
2164
 	lastWarehouse, _ := FindLastDrugWarehousingInfoByID(advice.DrugId, storeConfig.DrugStorehouseOut)
2179
 	lastWarehouse, _ := FindLastDrugWarehousingInfoByID(advice.DrugId, storeConfig.DrugStorehouseOut)
2165
-	if lastWarehouse.StockMinNumber >= drup.MinNumber {
2180
+
2181
+	if lastWarehouse.StockMinNumber >= drup.MinNumber && lastWarehouse.MaxUnit != lastWarehouse.MinUnit {
2166
 		var stockMax int64
2182
 		var stockMax int64
2167
 		var stockMin int64
2183
 		var stockMin int64
2168
 		stockMax = lastWarehouse.StockMinNumber / drup.MinNumber
2184
 		stockMax = lastWarehouse.StockMinNumber / drup.MinNumber
2174
 	warehouse, err := FindLastDrugWarehousingInfoByID(advice.DrugId, storeConfig.DrugStorehouseOut)
2190
 	warehouse, err := FindLastDrugWarehousingInfoByID(advice.DrugId, storeConfig.DrugStorehouseOut)
2175
 
2191
 
2176
 	if err != nil {
2192
 	if err != nil {
2177
-
2178
 		return err
2193
 		return err
2179
 	}
2194
 	}
2180
 	// 将该批次的剩余库存数量转换为拆零数量
2195
 	// 将该批次的剩余库存数量转换为拆零数量
2196
 	}
2211
 	}
2197
 
2212
 
2198
 	// 当库存数量大于或等于出库数量的话,则正常出库该批次
2213
 	// 当库存数量大于或等于出库数量的话,则正常出库该批次
2199
-	fmt.Println("stock_nbumber3223323232", stock_number)
2200
-	fmt.Println("deliver_number", deliver_number)
2214
+	fmt.Println("剩余库存2332233223232323", stock_number)
2215
+	fmt.Println("出库数量233232332323232", deliver_number)
2201
 	if stock_number >= deliver_number {
2216
 	if stock_number >= deliver_number {
2202
 
2217
 
2203
 		var maxNumber int64 = 0
2218
 		var maxNumber int64 = 0
2235
 
2250
 
2236
 		warehouse.Mtime = time.Now().Unix()
2251
 		warehouse.Mtime = time.Now().Unix()
2237
 
2252
 
2238
-		fmt.Println("minnU目标而332322323323233223323223我", minNumber)
2239
-		fmt.Println("max_number232232332232322wo", maxNumber)
2240
-		fmt.Println(" warehouse.StockMinNumber", warehouse.StockMinNumber)
2253
+		//fmt.Println("minnU目标而332322323323233223323223我", minNumber)
2254
+		//fmt.Println("max_number232232332232322wo", maxNumber)
2255
+		//fmt.Println(" warehouse.StockMinNumber", warehouse.StockMinNumber)
2241
 
2256
 
2242
-		if warehouse.StockMinNumber < minNumber {
2257
+		if warehouse.MaxUnit != warehouse.MinUnit {
2258
+			if warehouse.StockMinNumber < minNumber {
2243
 
2259
 
2244
-			warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
2245
-			if warehouse.MaxUnit != warehouse.MinUnit {
2246
-				warehouse.StockMinNumber = warehouse.StockMinNumber + drup.MinNumber - minNumber
2247
-			}
2248
-		} else {
2249
-			if minNumber > 0 {
2250
-				if (warehouse.StockMinNumber - minNumber) >= 0 {
2251
-					warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
2260
+				warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
2261
+				if warehouse.MaxUnit != warehouse.MinUnit {
2262
+					warehouse.StockMinNumber = warehouse.StockMinNumber + drup.MinNumber - minNumber
2252
 				}
2263
 				}
2264
+			} else {
2265
+				if minNumber > 0 {
2266
+					if (warehouse.StockMinNumber - minNumber) >= 0 {
2267
+						warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
2268
+					}
2253
 
2269
 
2254
-			}
2270
+				}
2255
 
2271
 
2256
-			if minNumber == 0 && maxNumber != 1 && warehouse.StockMaxNumber <= 0 {
2257
-				if warehouse.StockMinNumber > 0 {
2258
-					if warehouse.StockMinNumber-deliver_number >= 0 {
2272
+				if minNumber == 0 && maxNumber != 1 && warehouse.StockMaxNumber <= 0 {
2273
+					if warehouse.StockMinNumber > 0 {
2274
+						if warehouse.StockMinNumber-deliver_number >= 0 {
2275
+							warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
2276
+						}
2277
+
2278
+					}
2279
+
2280
+				}
2281
+
2282
+				if maxNumber == 1 && minNumber == 0 && drup.MaxUnit != drup.MinUnit {
2283
+					if (warehouse.StockMinNumber - deliver_number) >= 0 {
2259
 						warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
2284
 						warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
2260
 					}
2285
 					}
2261
 
2286
 
2262
 				}
2287
 				}
2263
 
2288
 
2264
 			}
2289
 			}
2265
-
2266
 		}
2290
 		}
2267
 
2291
 
2268
-		if maxNumber == 1 && minNumber == 0 && drup.MaxUnit != drup.MinUnit {
2269
-			if (warehouse.StockMinNumber - deliver_number) >= 0 {
2270
-				warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
2292
+		if warehouse.MinUnit == warehouse.MaxUnit {
2293
+			//fmt.Println("minNUMBER233223233223322323",minNumber)
2294
+			//fmt.Println("warehouse.StockMinNumber",warehouse.StockMinNumber)
2295
+			//fmt.Println("warehouse.StockMaxNumber",warehouse.StockMaxNumber)
2296
+			if warehouse.StockMaxNumber > 0 && warehouse.StockMinNumber == 0 && warehouse.StockMaxNumber >= minNumber {
2297
+				warehouse.StockMaxNumber = warehouse.StockMaxNumber - minNumber
2298
+
2271
 			}
2299
 			}
2272
 
2300
 
2301
+			if warehouse.StockMaxNumber == 0 && warehouse.StockMinNumber > 0 && warehouse.StockMinNumber >= minNumber {
2302
+				warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
2303
+			}
2304
+
2305
+			if warehouse.StockMaxNumber > 0 && warehouse.StockMinNumber > 0 && (warehouse.StockMaxNumber+warehouse.StockMinNumber) > minNumber {
2306
+
2307
+				var out_false int64 = 0
2308
+				if warehouse.StockMinNumber >= minNumber {
2309
+					warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
2310
+					out_false = 1
2311
+				}
2312
+				fmt.Println("out_false233223233223wo", out_false)
2313
+				if warehouse.StockMinNumber < minNumber && out_false == 0 {
2314
+
2315
+					var over_total int64
2316
+					over_total = warehouse.StockMinNumber
2317
+					warehouse.StockMinNumber = 0
2318
+					warehouse.StockMaxNumber = warehouse.StockMaxNumber - (minNumber - over_total)
2319
+				}
2320
+			}
2321
+
2322
+			//if warehouse.StockMaxNumber < minNumber && warehouse.StockMaxNumber < minNumber && (warehouse.StockMaxNumber + warehouse.StockMinNumber) > minNumber {
2323
+			//  var over_count int64
2324
+			//  over_count = warehouse.StockMinNumber
2325
+			//  warehouse.StockMinNumber = 0
2326
+			//  warehouse.StockMaxNumber = warehouse.StockMaxNumber - (minNumber -over_count)
2327
+			//
2328
+			//}
2329
+
2273
 		}
2330
 		}
2274
 
2331
 
2275
 		if drup.MaxUnit != drup.MinUnit {
2332
 		if drup.MaxUnit != drup.MinUnit {
2330
 
2387
 
2331
 		//查询今日该药品该患者是否有出库数据
2388
 		//查询今日该药品该患者是否有出库数据
2332
 		lastDrugOutInfo, _ := GetNewDrugWarehouseOutInfoSix(advice.DrugId, advice.PatientId, advice.RecordDate, advice.UserOrgId, advice.ID, warehouse.ID)
2389
 		lastDrugOutInfo, _ := GetNewDrugWarehouseOutInfoSix(advice.DrugId, advice.PatientId, advice.RecordDate, advice.UserOrgId, advice.ID, warehouse.ID)
2333
-
2390
+		fmt.Println("lastDrugOutInfo0000000293293292392392393293239239", lastDrugOutInfo)
2334
 		if lastDrugOutInfo.ID == 0 {
2391
 		if lastDrugOutInfo.ID == 0 {
2335
 			errOne := AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
2392
 			errOne := AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
2336
 			if errOne != nil {
2393
 			if errOne != nil {
2345
 			if lastDrugOutInfo.CountUnit == drup.MinUnit {
2402
 			if lastDrugOutInfo.CountUnit == drup.MinUnit {
2346
 				his_count = lastDrugOutInfo.Count
2403
 				his_count = lastDrugOutInfo.Count
2347
 			}
2404
 			}
2405
+			fmt.Println("deliver_numberwode8888888823832832832832832832823823-------------------------", deliver_number)
2406
+			fmt.Println("his_countnide-------------------------------------------------------", his_count)
2348
 			if deliver_number != his_count {
2407
 			if deliver_number != his_count {
2408
+				//warehouseOutInfo.Count = deliver_number_one
2349
 				errThree := UpdateSigleDrugWarehouseOutInfo(lastDrugOutInfo.ID, warehouseOutInfo)
2409
 				errThree := UpdateSigleDrugWarehouseOutInfo(lastDrugOutInfo.ID, warehouseOutInfo)
2350
 				if errThree != nil {
2410
 				if errThree != nil {
2351
 					return errThree
2411
 					return errThree
2367
 			cancel_count += item.Count
2427
 			cancel_count += item.Count
2368
 		}
2428
 		}
2369
 
2429
 
2370
-		fmt.Println("deliver_number", deliver_number)
2430
+		fmt.Println("deliver_number_one", deliver_number)
2371
 		fmt.Println("out_count", out_count)
2431
 		fmt.Println("out_count", out_count)
2372
 		fmt.Println("cancel_count", cancel_count)
2432
 		fmt.Println("cancel_count", cancel_count)
2373
 		//如果本次出库数据大于历史出库数据 新增1条流水
2433
 		//如果本次出库数据大于历史出库数据 新增1条流水
2374
-		if deliver_number > (out_count - cancel_count) {
2434
+		if deliver_number_one > (out_count - cancel_count) {
2375
 			drugflow := models.DrugFlow{
2435
 			drugflow := models.DrugFlow{
2376
 				WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
2436
 				WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
2377
 				WarehouseOutId:          warehouseout.ID,
2437
 				WarehouseOutId:          warehouseout.ID,
2379
 				Number:                  warehouse.Number,
2439
 				Number:                  warehouse.Number,
2380
 				ProductDate:             warehouse.ProductDate,
2440
 				ProductDate:             warehouse.ProductDate,
2381
 				ExpireDate:              warehouse.ExpiryDate,
2441
 				ExpireDate:              warehouse.ExpiryDate,
2382
-				Count:                   deliver_number - (out_count - cancel_count), //按最小单位计算,
2442
+				Count:                   deliver_number_one - (out_count - cancel_count), //按最小单位计算,
2383
 				Price:                   warehouse.RetailPrice,
2443
 				Price:                   warehouse.RetailPrice,
2384
 				Status:                  1,
2444
 				Status:                  1,
2385
 				Ctime:                   time.Now().Unix(),
2445
 				Ctime:                   time.Now().Unix(),
2450
 		}
2510
 		}
2451
 
2511
 
2452
 		//如果本次出库数据小于历史出库数据 新增1条退库流水
2512
 		//如果本次出库数据小于历史出库数据 新增1条退库流水
2453
-		if deliver_number < (out_count - cancel_count) {
2513
+		if deliver_number_one < (out_count - cancel_count) {
2454
 
2514
 
2455
 			operation_time := time.Now().Unix()
2515
 			operation_time := time.Now().Unix()
2456
 
2516
 
2484
 
2544
 
2485
 			manufactureName, _ := GetManufactureById(warehouse.Manufacturer)
2545
 			manufactureName, _ := GetManufactureById(warehouse.Manufacturer)
2486
 			dealer, _ := GetDealerById(warehouse.Dealer)
2546
 			dealer, _ := GetDealerById(warehouse.Dealer)
2487
-			cancelInfo, _ := GetLastDrugCancelStockById(advice.UserOrgId)
2547
+			//cancelInfo, _ := GetLastDrugCancelStockById(advice.UserOrgId)
2488
 			cancelStockInfo := models.DrugCancelStockInfo{
2548
 			cancelStockInfo := models.DrugCancelStockInfo{
2489
-				OrderNumber:      cancelInfo.OrderNumber,
2549
+				OrderNumber:      lastDrugCancelStock.OrderNumber,
2490
 				CancelStockId:    lastDrugCancelStock.ID,
2550
 				CancelStockId:    lastDrugCancelStock.ID,
2491
 				DrugId:           advice.DrugId,
2551
 				DrugId:           advice.DrugId,
2492
 				Count:            (out_count - cancel_count) - deliver_number,
2552
 				Count:            (out_count - cancel_count) - deliver_number,
2658
 			OrderId:                 warehouseout.OrderId,
2718
 			OrderId:                 warehouseout.OrderId,
2659
 		}
2719
 		}
2660
 		//查询是否存在出库数据
2720
 		//查询是否存在出库数据
2661
-		_, errCode := GetSigleDrugWarehouseOutInfo(advice.PatientId, advice.AdviceDate, orgID)
2662
-		if errCode == gorm.ErrRecordNotFound {
2721
+
2722
+		lastDrugOutInfoTwo, _ := GetNewDrugWarehouseOutInfoSix(advice.DrugId, advice.PatientId, advice.RecordDate, advice.UserOrgId, advice.ID, warehouse.ID)
2723
+		//_, errCode := GetSigleDrugWarehouseOutInfo(advice.PatientId, advice.AdviceDate, orgID)
2724
+		//fmt.Println("errcoedee232233223233232323232323233223232323322323232323232323",errCode)
2725
+		if lastDrugOutInfoTwo.ID == 0 {
2663
 
2726
 
2664
 			errOne := AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
2727
 			errOne := AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
2665
 			if errOne != nil {
2728
 			if errOne != nil {
2666
 				return errOne
2729
 				return errOne
2667
 			}
2730
 			}
2668
 		}
2731
 		}
2669
-		if errCode == nil {
2732
+		if lastDrugOutInfoTwo.ID > 0 {
2670
 
2733
 
2671
 			lastDrugOutInfo, _ := GetSigleDrugWarehouseOutInfoOne(advice.PatientId, advice.AdviceDate, orgID)
2734
 			lastDrugOutInfo, _ := GetSigleDrugWarehouseOutInfoOne(advice.PatientId, advice.AdviceDate, orgID)
2735
+			fmt.Println("中国人民肌肤32323223332332232322323喔", lastDrugOutInfo)
2672
 			var his_count int64
2736
 			var his_count int64
2673
 			if lastDrugOutInfo.CountUnit == drup.MaxUnit {
2737
 			if lastDrugOutInfo.CountUnit == drup.MaxUnit {
2674
 				his_count = lastDrugOutInfo.Count * drup.MinNumber
2738
 				his_count = lastDrugOutInfo.Count * drup.MinNumber
2676
 			if lastDrugOutInfo.CountUnit == drup.MinUnit {
2740
 			if lastDrugOutInfo.CountUnit == drup.MinUnit {
2677
 				his_count = lastDrugOutInfo.Count
2741
 				his_count = lastDrugOutInfo.Count
2678
 			}
2742
 			}
2743
+			fmt.Println("deliver_number3232323232wowooww", deliver_number)
2744
+			fmt.Println("his_count99999992i2222wo", his_count)
2679
 			if deliver_number != his_count {
2745
 			if deliver_number != his_count {
2746
+
2680
 				errThree := UpdateSingleDrugWarehouseOutInfoSix(advice.PatientId, advice.AdviceDate, orgID, warehouseOutInfo, advice.ID)
2747
 				errThree := UpdateSingleDrugWarehouseOutInfoSix(advice.PatientId, advice.AdviceDate, orgID, warehouseOutInfo, advice.ID)
2681
 				if errThree != nil {
2748
 				if errThree != nil {
2682
 					return errThree
2749
 					return errThree
2727
 			cancel_count += item.Count
2794
 			cancel_count += item.Count
2728
 		}
2795
 		}
2729
 
2796
 
2797
+		fmt.Println("出库数量", deliver_number)
2798
+		fmt.Println("out_coutn233232322323wo", cancel_count)
2799
+		fmt.Println("out_count99988233232", out_count)
2730
 		//如果本次出库数据大于历史出库数据 新增1条流水
2800
 		//如果本次出库数据大于历史出库数据 新增1条流水
2731
 		if deliver_number > (out_count - cancel_count) {
2801
 		if deliver_number > (out_count - cancel_count) {
2732
 
2802
 
2768
 		}
2838
 		}
2769
 
2839
 
2770
 		if deliver_number < (out_count - cancel_count) {
2840
 		if deliver_number < (out_count - cancel_count) {
2841
+			fmt.Println("即那里3232232323")
2771
 			operation_time := time.Now().Unix()
2842
 			operation_time := time.Now().Unix()
2772
 
2843
 
2773
 			ctime := time.Now().Unix()
2844
 			ctime := time.Now().Unix()
2880
 
2951
 
2881
 		advice.PrescribingNumber = float64(prescribingNumber_two_temp)
2952
 		advice.PrescribingNumber = float64(prescribingNumber_two_temp)
2882
 		advice.PrescribingNumberUnit = drup.MinUnit
2953
 		advice.PrescribingNumberUnit = drup.MinUnit
2954
+		fmt.Println("剩余库存9999999233232", overPlusNumber)
2883
 
2955
 
2884
-		HisSettleDrugDeliverInfo(orgID, overPlusNumber, warehouseout, drup, advice)
2956
+		HisSettleDrugDeliverInfo(orgID, overPlusNumber, warehouseout, drup, advice, prescribingCount)
2885
 	}
2957
 	}
2886
 
2958
 
2887
 	return
2959
 	return

+ 23 - 0
service/stock_service.go View File

8380
 	}
8380
 	}
8381
 	return &info, nil
8381
 	return &info, nil
8382
 }
8382
 }
8383
+
8384
+func GetNewGoodWarehouseInfo(startime int64, endtime int64, orgid int64, good_id []int64, storehouse_id int64) (info []*models.WarehousingInfo, err error) {
8385
+
8386
+	db := XTReadDB().Model(&info).Where("status = 1")
8387
+
8388
+	if startime > 0 {
8389
+		db = db.Where("ctime>=?", startime)
8390
+	}
8391
+	if endtime > 0 {
8392
+		db = db.Where("ctime<=?", endtime)
8393
+	}
8394
+	if orgid > 0 {
8395
+		db = db.Where("org_id = ?", orgid)
8396
+	}
8397
+	if len(good_id) > 0 {
8398
+		db = db.Where("good_id in(?)", good_id)
8399
+	}
8400
+	if storehouse_id > 0 {
8401
+		db = db.Where("storehouse_id = ?", storehouse_id)
8402
+	}
8403
+	err = db.Find(&info).Error
8404
+	return info, err
8405
+}

+ 1 - 1
service/warhouse_service.go View File

12219
 		if drup.ID > 0 {
12219
 		if drup.ID > 0 {
12220
 			prescribingNumber := advice.PrescribingNumber
12220
 			prescribingNumber := advice.PrescribingNumber
12221
 
12221
 
12222
-			HisSettleDrugDeliverInfo(orgID, prescribingNumber, &out, &drup, advice)
12222
+			HisSettleDrugDeliverInfo(orgID, prescribingNumber, &out, &drup, advice, prescribingNumber)
12223
 
12223
 
12224
 		} else {
12224
 		} else {
12225
 			return errors.New("药品信息不存在")
12225
 			return errors.New("药品信息不存在")