Browse Source

11月8日库存管理

XMLWAN 3 years ago
parent
commit
6c7adae72a

+ 99 - 25
controllers/drug_stock_api_contorller.go View File

@@ -756,8 +756,18 @@ func (c *StockDrugApiController) EditDrugWarehouse() {
756 756
 
757 757
 			if item.WarehousingCount == warehouseInfo.WarehousingCount {
758 758
 				item.OrgId = item.OrgId
759
-
760
-				errs = service.UpDateDrugWarehousingInfoTwo(item.ID, item)
759
+				warehouseinfo := &models.DrugWarehouseInfo{
760
+					Number:       item.Number,
761
+					ProductDate:  item.ProductDate,
762
+					ExpiryDate:   item.ExpiryDate,
763
+					Price:        item.Price,
764
+					TotalPrice:   item.TotalPrice,
765
+					Dealer:       item.Dealer,
766
+					Manufacturer: item.Manufacturer,
767
+					Remark:       item.Remark,
768
+					BatchNumber:  item.BatchNumber,
769
+				}
770
+				errs = service.UpDateDrugWarehousingInfoTwo(item.ID, warehouseinfo)
761 771
 			}
762 772
 		}
763 773
 	}
@@ -1575,9 +1585,10 @@ func (c *StockDrugApiController) EditDrugWarehouseOut() {
1575 1585
 	warehouseOut, _ := service.FindDrugWareHouseOutById(id, adminUserInfo.CurrentOrgId)
1576 1586
 
1577 1587
 	tempWarehouseOut := models.DrugWarehouseOut{
1578
-		ID:               warehouseOut.ID,
1579
-		Mtime:            mtime,
1580
-		WarehouseOutTime: warehouseOutDate.Unix(),
1588
+		ID:                      warehouseOut.ID,
1589
+		Mtime:                   mtime,
1590
+		WarehouseOutTime:        warehouseOutDate.Unix(),
1591
+		WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
1581 1592
 	}
1582 1593
 
1583 1594
 	service.EditDrugWarehouseOut(tempWarehouseOut)
@@ -1859,8 +1870,8 @@ func (c *StockDrugApiController) EditDrugWarehouseOut() {
1859 1870
 				})
1860 1871
 				return
1861 1872
 			} else {
1862
-				errs = service.CreateDrugWarehousingOutInfo(warehousingOutInfo)
1863
-				service.CreateDrugFlow(drugFlow)
1873
+				//errs = service.CreateDrugWarehousingOutInfo(warehousingOutInfo)
1874
+				//service.CreateDrugFlow(drugFlow)
1864 1875
 				// 出库流程
1865 1876
 				// 1.查询改药品在药品库的规格信息,并将处方里的规格进行换算(尽量将拆零单位转换成包装单位)
1866 1877
 				drup, _ := service.FindBaseDrugLibRecord(item.OrgId, item.DrugId)
@@ -1975,7 +1986,7 @@ func (c *StockDrugApiController) EditDrugWarehouseOut() {
1975 1986
 
1976 1987
 				cha_number = min_number - max_number
1977 1988
 				//如果总库存大于差,正常出库
1978
-				if all_number >= cha_number {
1989
+				if all_number > cha_number {
1979 1990
 
1980 1991
 					errs = service.UpDateDrugWarehouseOutInfo(item)
1981 1992
 
@@ -2036,7 +2047,36 @@ func (c *StockDrugApiController) EditDrugWarehouseOut() {
2036 2047
 						})
2037 2048
 					}
2038 2049
 				}
2050
+				if all_number == cha_number {
2051
+					warehouseInfo := models.XtDrugWarehouseInfo{
2052
+						Number:       item.Number,
2053
+						ProductDate:  item.ProductDate,
2054
+						ExpiryDate:   item.ExpiryDate,
2055
+						Price:        item.Price,
2056
+						TotalPrice:   item.TotalPrice,
2057
+						Dealer:       item.Dealer,
2058
+						Manufacturer: item.Manufacturer,
2059
+						Remark:       item.Remark,
2060
+						BatchNumber:  item.BatchNumber,
2061
+						MaxUnit:      item.CountUnit,
2062
+					}
2063
+					parseDateErr := service.UpdateDrugWarehouseingInfoSix(item.ID, warehouseInfo)
2064
+					if parseDateErr != nil {
2065
+						utils.ErrorLog(errs.Error())
2066
+						c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockOutFail)
2067
+						return
2068
+					}
2039 2069
 
2070
+					c.ServeSuccessJSON(map[string]interface{}{
2071
+						"msg":        "2",
2072
+						"drug_name":  "",
2073
+						"dose":       "",
2074
+						"dose_unit":  "",
2075
+						"min_number": "",
2076
+						"min_unit":   "",
2077
+						"max_unit":   "",
2078
+					})
2079
+				}
2040 2080
 				if all_number < cha_number {
2041 2081
 					goodObj, _ := service.GetDrugByGoodId(item.DrugId)
2042 2082
 					c.ServeSuccessJSON(map[string]interface{}{
@@ -2305,29 +2345,29 @@ func (c *StockDrugApiController) CreateDrugCancelStock() {
2305 2345
 		//查询该批次总的退库数量
2306 2346
 		canInfo, _ := service.GetCancelDrugStockOutInfo(item.BatchNumberId, item.DrugId)
2307 2347
 
2308
-		for _, item := range canInfo {
2309
-			if item.MaxUnit == medical.MaxUnit {
2310
-				item.Count = item.Count * medical.MinNumber
2348
+		for _, it := range canInfo {
2349
+			if it.MaxUnit == medical.MaxUnit {
2350
+				it.Count = it.Count * medical.MinNumber
2311 2351
 			}
2312
-			if item.MaxUnit == medical.MinUnit {
2313
-				item.Count = item.Count
2352
+			if it.MaxUnit == medical.MinUnit {
2353
+				it.Count = it.Count
2314 2354
 			}
2315 2355
 		}
2316 2356
 
2317
-		for _, item := range canInfo {
2318
-			can_number += item.Count
2357
+		for _, it := range canInfo {
2358
+			can_number += it.Count
2319 2359
 		}
2320 2360
 
2321
-		for _, item := range outInfo {
2322
-			if item.CountUnit == medical.MaxUnit {
2323
-				item.Count = item.Count * medical.MinNumber
2361
+		for _, it := range outInfo {
2362
+			if it.CountUnit == medical.MaxUnit {
2363
+				it.Count = it.Count * medical.MinNumber
2324 2364
 			}
2325
-			if item.CountUnit == medical.MinUnit {
2326
-				item.Count = item.Count
2365
+			if it.CountUnit == medical.MinUnit {
2366
+				it.Count = it.Count
2327 2367
 			}
2328 2368
 		}
2329
-		for _, item := range outInfo {
2330
-			out_number += item.Count
2369
+		for _, it := range outInfo {
2370
+			out_number += it.Count
2331 2371
 		}
2332 2372
 
2333 2373
 		if out_number == 0 {
@@ -2338,7 +2378,7 @@ func (c *StockDrugApiController) CreateDrugCancelStock() {
2338 2378
 			return
2339 2379
 		}
2340 2380
 
2341
-		fmt.Println("hhhh233323232322323", total_number, total_count)
2381
+		fmt.Println("时间任命323332233232", total_number, total_count)
2342 2382
 
2343 2383
 		//判断退库数量是否大于总入库数量
2344 2384
 		if total_number > total_count {
@@ -2366,9 +2406,42 @@ func (c *StockDrugApiController) CreateDrugCancelStock() {
2366 2406
 		//正常退库
2367 2407
 		if total_number <= out_number {
2368 2408
 			//创建退库详情
2369
-			errs := service.CreateDrugCancelStockInfo(cancelStockInfos)
2409
+			errs := service.CreateCancelStockInfoTwo(item)
2370 2410
 			//创建库存明细
2371
-			errs = service.CreateDrugFlow(drugFlow)
2411
+			flows := models.DrugFlow{
2412
+				WarehousingId:           0,
2413
+				DrugId:                  item.DrugId,
2414
+				Number:                  "",
2415
+				BatchNumber:             item.BatchNumber,
2416
+				Count:                   item.Count,
2417
+				UserOrgId:               adminUserInfo.CurrentOrgId,
2418
+				PatientId:               0,
2419
+				SystemTime:              ctime,
2420
+				ConsumableType:          4,
2421
+				IsSys:                   0,
2422
+				WarehousingOrder:        infoWareInfo.WarehousingOrder,
2423
+				WarehouseOutId:          0,
2424
+				WarehouseOutOrderNumber: "",
2425
+				IsEdit:                  0,
2426
+				CancelStockId:           cancelStock.ID,
2427
+				CancelOrderNumber:       cancelStock.OrderNumber,
2428
+				Manufacturer:            manufacturer_id,
2429
+				Dealer:                  dealer_id,
2430
+				Creator:                 adminUserInfo.AdminUser.Id,
2431
+				UpdateCreator:           0,
2432
+				Status:                  1,
2433
+				Ctime:                   time.Now().Unix(),
2434
+				Mtime:                   0,
2435
+				Price:                   item.Price,
2436
+				WarehousingDetailId:     0,
2437
+				WarehouseOutDetailId:    0,
2438
+				CancelOutDetailId:       0,
2439
+				ExpireDate:              item.ExpiryDate,
2440
+				ProductDate:             item.ProductDate,
2441
+				MaxUnit:                 item.MaxUnit,
2442
+				MinUnit:                 "",
2443
+			}
2444
+			errs = service.CreateDrugFlowOne(flows)
2372 2445
 
2373 2446
 			var total int64
2374 2447
 
@@ -2407,6 +2480,7 @@ func (c *StockDrugApiController) CreateDrugCancelStock() {
2407 2480
 				})
2408 2481
 			}
2409 2482
 		}
2483
+
2410 2484
 	}
2411 2485
 }
2412 2486
 func (c *StockDrugApiController) GetDrugCancelStockInfoList() {

+ 13 - 5
controllers/stock_in_api_controller.go View File

@@ -2121,10 +2121,11 @@ func (c *StockManagerApiController) CreateCancelStock() {
2121 2121
 				service.AddSigleCancelStock(&cancelStock)
2122 2122
 			}
2123 2123
 			listcancel, _ := service.GetLastCancelStockById(adminUserInfo.CurrentOrgId)
2124
-			for _, it := range cancelStockInfos {
2125
-				it.CancelStockId = listcancel.ID
2126
-			}
2127
-			errs := service.CreateCancelStockInfo(cancelStockInfos)
2124
+
2125
+			fmt.Println("2332323232323232323", cancelStockInfos)
2126
+			item.CancelStockId = listcancel.ID
2127
+			errs := service.CreateCancelStockInfoOne(item)
2128
+
2128 2129
 			if len(stockFLow) > 0 {
2129 2130
 				service.CreateStockFlow(stockFLow)
2130 2131
 			}
@@ -2144,6 +2145,11 @@ func (c *StockManagerApiController) CreateCancelStock() {
2144 2145
 			}
2145 2146
 			//更改入库数量
2146 2147
 			errs = service.UpdateWareInfoById(item.WarehouseInfoId, item.Count)
2148
+			if err != nil {
2149
+				utils.ErrorLog(err.Error())
2150
+				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
2151
+				return
2152
+			}
2147 2153
 		}
2148 2154
 	}
2149 2155
 
@@ -4603,9 +4609,11 @@ func (this *StockManagerApiController) GetOrderDetialByOrderId() {
4603 4609
 	ids := this.GetString("id")
4604 4610
 	idsArray := strings.Split(ids, ",")
4605 4611
 	orgId := this.GetAdminUserInfo().CurrentOrgId
4612
+	order, _ := service.GetWarehouseOutOrder(idsArray, orgId)
4606 4613
 	list, _ := service.GetOrderDetialByOrderIdOne(idsArray, orgId)
4607 4614
 	this.ServeSuccessJSON(map[string]interface{}{
4608
-		"list": list,
4615
+		"list":  list,
4616
+		"order": order,
4609 4617
 	})
4610 4618
 }
4611 4619
 

+ 1 - 1
models/dialysis.go View File

@@ -863,7 +863,7 @@ type XtDialysisOrders struct {
863 863
 	FinishModifier int64  `gorm:"column:finish_modifier" json:"finish_modifier" form:"finish_modifier"`
864 864
 	SchedualType   int64  `gorm:"column:schedual_type" json:"schedual_type" form:"schedual_type"`
865 865
 	Number         string `gorm:"column:number" json:"number" form:"number"`
866
-	UserName       int64  `gorm:"column:user_name" json:"user_name" form:"user_name"`
866
+	UserName       string `gorm:"column:user_name" json:"user_name" form:"user_name"`
867 867
 	WashpipeNurse  int64  `gorm:"column:washpipe_nurse" json:"washpipe_nurse" form:"washpipe_nurse"`
868 868
 	ModeId         int64  `gorm:"column:mode_id" json:"mode_id" form:"mode_id"`
869 869
 }

+ 1 - 0
models/drug_stock.go View File

@@ -325,6 +325,7 @@ type StDrugWarehouseOutInfo struct {
325 325
 	LastPrice               string  `json:"last_price"`
326 326
 	PackingUnit             string  `json:"packing_unit"`
327 327
 	Dosage                  int64   `json:"dosage"`
328
+	ExpireDate              int64   `json:"expire_date"`
328 329
 }
329 330
 
330 331
 type DrugFlow struct {

+ 23 - 4
service/stock_service.go View File

@@ -604,7 +604,7 @@ func GetDrugByWarehouseInfo(id int64) (models.XtDrugWarehouseInfo, error) {
604 604
 func UpdateDrugWarehouseingInfo(id int64, info models.XtDrugWarehouseInfo) error {
605 605
 
606 606
 	warehouseInfo := models.XtDrugWarehouseInfo{}
607
-	err := XTReadDB().Model(&warehouseInfo).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"stock_max_number": info.StockMaxNumber}).Error
607
+	err := XTWriteDB().Model(&warehouseInfo).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"stock_max_number": info.StockMaxNumber}).Error
608 608
 	return err
609 609
 }
610 610
 
@@ -1605,6 +1605,18 @@ func CreateCancelStockInfo(cancelStockInfo []*models.CancelStockInfo) (err error
1605 1605
 
1606 1606
 }
1607 1607
 
1608
+func CreateCancelStockInfoTwo(info *models.DrugCancelStockInfo) error {
1609
+
1610
+	err := XTWriteDB().Create(&info).Error
1611
+	return err
1612
+}
1613
+
1614
+func CreateCancelStockInfoOne(info *models.CancelStockInfo) error {
1615
+
1616
+	err := XTWriteDB().Create(&info).Error
1617
+	return err
1618
+}
1619
+
1608 1620
 func CreateDrugCancelStockInfo(cancelStockInfo []*models.DrugCancelStockInfo) (err error) {
1609 1621
 	if len(cancelStockInfo) > 0 {
1610 1622
 		utx := writeDb.Begin()
@@ -1913,7 +1925,7 @@ func UpDateDrugWarehousingInfo(info *models.DrugWarehouseInfo) (err error) {
1913 1925
 }
1914 1926
 
1915 1927
 func UpDateDrugWarehousingInfoTwo(id int64, info *models.DrugWarehouseInfo) (err error) {
1916
-	err = writeDb.Model(&info).Where("id= ? and status = 1", id).Updates(map[string]interface{}{"org_id": info.OrgId}).Error
1928
+	err = writeDb.Model(&info).Where("id= ? and status = 1", id).Updates(map[string]interface{}{"number": info.Number, "product_date": info.ProductDate, "expiry_date": info.ExpiryDate, "price": info.Price, "total_price": info.TotalPrice, "dealer": info.Dealer, "manufacturer": info.Manufacturer, "remark": info.Remark, "batch_number": info.BatchNumber}).Error
1917 1929
 	return err
1918 1930
 }
1919 1931
 
@@ -3516,7 +3528,7 @@ func FindUserDetailByIdOne(good_id int64, record_time int64, org_id int64) (user
3516 3528
 	db = db.Preload("GoodsType", "status = 1")
3517 3529
 	db = db.Preload("Patients", "user_org_id = ? AND status = 1", org_id)
3518 3530
 	db = db.Preload("WarehouseOutInfo", "org_id = ? and status = 1 and good_id = ? and sys_record_time = ?", org_id, good_id, record_time)
3519
-	db = db.Where("status = 1 AND org_id = ? AND good_id = ? AND record_time = ? ", org_id, good_id, record_time)
3531
+	db = db.Where("status = 1 AND org_id = ? AND good_id = ? AND record_time = ? and count<> 0 ", org_id, good_id, record_time)
3520 3532
 	db = db.Count(&total)
3521 3533
 	err = db.Find(&user).Error
3522 3534
 
@@ -4000,7 +4012,7 @@ func GetExportOutOrderDrugListOne(warehouse_out_id []string) (out []*models.StDr
4000 4012
 	if len(warehouse_out_id) > 0 {
4001 4013
 		db = db.Where("x.warehouse_out_id in(?)", warehouse_out_id)
4002 4014
 	}
4003
-	err = db.Select("x.id,x.warehouse_out_id,x.drug_id,x.count,x.max_unit as count_unit,x.price,x.product_date,x.expire_date as expire_date,x.warehouse_out_order_number,x.dealer,x.manufacturer,x.is_sys,x.number,x.batch_number,x.patient_id,b.dose,b.dose_unit,b.min_number,b.min_unit,b.max_unit,b.drug_name,b.drug_type,b.min_price").Joins("left join xt_base_drug as b on b.id = x.drug_id").Scan(&out).Error
4015
+	err = db.Select("x.id,x.warehouse_out_id,x.drug_id,x.count,x.max_unit as count_unit,x.price,x.product_date,x.expire_date,x.warehouse_out_order_number,x.dealer,x.manufacturer,x.is_sys,x.number,x.batch_number,x.patient_id,b.dose,b.dose_unit,b.min_number,b.min_unit,b.max_unit,b.drug_name,b.drug_type,b.min_price").Joins("left join xt_base_drug as b on b.id = x.drug_id").Scan(&out).Error
4004 4016
 	return out, err
4005 4017
 }
4006 4018
 
@@ -5057,3 +5069,10 @@ func GetDrugWarehouseingInfo(id int64) (models.XtDrugWarehouseInfo, error) {
5057 5069
 	err := XTReadDB().Where("id=? and status = 1", id).Find(&info).Error
5058 5070
 	return info, err
5059 5071
 }
5072
+
5073
+func UpdateDrugWarehouseingInfoSix(id int64, info models.XtDrugWarehouseInfo) error {
5074
+
5075
+	warehouseInfo := models.XtDrugWarehouseInfo{}
5076
+	err := XTWriteDB().Model(&warehouseInfo).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"number": info.Number, "product_date": info.ProductDate, "expiry_date": info.ExpiryDate, "price": info.Price, "total_price": info.TotalPrice, "dealer": info.Dealer, "manufacturer": info.Manufacturer, "remark": info.Remark, "batch_number": info.BatchNumber, "max_unit": info.MaxUnit}).Error
5077
+	return err
5078
+}

+ 9 - 8
service/warhouse_service.go View File

@@ -836,14 +836,15 @@ func AutoDrugDeliverInfo(orgID int64, prescribingNumber int64, warehouseout *mod
836 836
 		if errOne != nil {
837 837
 			return errOne
838 838
 		}
839
-		list, _ := GetLastWarehouseOut(drup.OrgId)
839
+		fmt.Println("hh233223323223232323233223232323233223232323", warehouseout.ID, warehouseout.WarehouseOutOrderNumber)
840
+		//list, _ := GetLastWarehouseOut(drup.OrgId)
840 841
 		drugflow := models.DrugFlow{
841
-			WarehouseOutId:          list.ID,
842
+			WarehouseOutId:          warehouseout.ID,
842 843
 			WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
843 844
 			DrugId:                  advice.DrugId,
844 845
 			Number:                  warehouse.Number,
845
-			ProductDate:             warehouse.ProductDate,
846
-			ExpireDate:              warehouse.ExpiryDate,
846
+			ProductDate:             advice.ProductDate,
847
+			ExpireDate:              advice.ExpiryDate,
847 848
 			Count:                   deliver_number,
848 849
 			Price:                   advice.Price,
849 850
 			Status:                  1,
@@ -929,14 +930,14 @@ func AutoDrugDeliverInfo(orgID int64, prescribingNumber int64, warehouseout *mod
929 930
 		if errOne != nil {
930 931
 			return errOne
931 932
 		}
932
-		list, _ := GetLastWarehouseOut(drup.OrgId)
933
+		//list, _ := GetLastWarehouseOut(drup.OrgId)
933 934
 		drugflow := models.DrugFlow{
934
-			WarehouseOutId:          list.ID,
935
+			WarehouseOutId:          warehouseout.ID,
935 936
 			WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
936 937
 			DrugId:                  advice.DrugId,
937 938
 			Number:                  warehouse.Number,
938
-			ProductDate:             warehouse.ProductDate,
939
-			ExpireDate:              warehouse.ExpiryDate,
939
+			ProductDate:             advice.ProductDate,
940
+			ExpireDate:              advice.ExpiryDate,
940 941
 			Count:                   deliver_number,
941 942
 			Price:                   advice.Price,
942 943
 			Status:                  1,