Browse Source

11月9日库存管理

XMLWAN 2 years ago
parent
commit
178bd3b9bb

+ 1 - 1
conf/app.conf View File

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

+ 1 - 1
controllers/his_api_controller.go View File

@@ -3141,7 +3141,7 @@ func (c *HisApiController) DeleteProject() {
3141 3141
 					total_count_one += it.StockCount
3142 3142
 				}
3143 3143
 				//基础库插入数据
3144
-				service.UpdateGoodInfoSumCount(project.ProjectId, total_count_one, project.UserOrgId)
3144
+				service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
3145 3145
 
3146 3146
 				goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
3147 3147
 				var flush_count int64

+ 3 - 3
controllers/secondary_order_api_contorller.go View File

@@ -278,8 +278,8 @@ func (this *SecondaryOrderApiController) AddStorehouse() {
278 278
 		return
279 279
 	}
280 280
 	defer func() {
281
-		if err != nil{
282
-			service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId,this.Ctx.Input,err)
281
+		if err != nil {
282
+			service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
283 283
 		}
284 284
 	}()
285 285
 	var storehouse_status, admin_id int64
@@ -1322,7 +1322,7 @@ func (this *SecondaryOrderApiController) CheckSecondOrer() {
1322 1322
 					total_count += it.StockCount
1323 1323
 				}
1324 1324
 				//基础库插入数据
1325
-				service.UpdateGoodInfoSumCount(item.ProjectId, total_count, orgId)
1325
+				service.UpdateGoodInfoSumCountSix(item.ProjectId, total_count, orgId)
1326 1326
 			}
1327 1327
 		}
1328 1328
 	}

+ 16 - 8
service/new_warehouse_service.go View File

@@ -789,6 +789,7 @@ func BloodDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *
789 789
 				WarehouseOutDetailId:    lastDrugOutInfo.ID,
790 790
 				OverCount:               sum_count,
791 791
 				AdviceId:                advice.ID,
792
+				LastPrice:               warehouse.Price,
792 793
 			}
793 794
 
794 795
 			CreateDrugFlowOne(drugflow)
@@ -882,7 +883,7 @@ func BloodDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *
882 883
 				Status:                  1,
883 884
 				Ctime:                   time.Now().Unix(),
884 885
 				Mtime:                   0,
885
-				Price:                   warehouse.Price,
886
+				Price:                   warehouse.RetailPrice,
886 887
 				WarehousingDetailId:     warehouse.ID,
887 888
 				WarehouseOutDetailId:    0,
888 889
 				CancelOutDetailId:       lastDrugCancelStock.ID,
@@ -892,6 +893,7 @@ func BloodDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *
892 893
 				MinUnit:                 "",
893 894
 				AdviceId:                advice.ID,
894 895
 				StorehouseId:            storeConfig.DrugStorehouseOut,
896
+				LastPrice:               warehouse.Price,
895 897
 			}
896 898
 			CreateDrugFlowOne(flow)
897 899
 			AddCancelSumCountOne(storeConfig.DrugStorehouseOut, advice.DrugId, advice.UserOrgId, flow.Count)
@@ -1365,7 +1367,8 @@ func BloodHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseou
1365 1367
 		}
1366 1368
 
1367 1369
 		//查询今日该药品该患者是否有出库数据
1368
-		lastDrugOutInfo, _ := GetNewDrugWarehouseOutInfoSix(advice.DrugId, advice.PatientId, advice.RecordDate, advice.UserOrgId, advice.ID)
1370
+		lastDrugOutInfo, _ := GetNewDrugWarehouseOutInfoSix(advice.DrugId, advice.PatientId, advice.RecordDate, advice.UserOrgId, advice.ID, warehouse.ID)
1371
+		fmt.Println("lastDrugOutInfowwowowowoowowowowowowowowo", lastDrugOutInfo.ID)
1369 1372
 		if lastDrugOutInfo.ID == 0 {
1370 1373
 			errOne := AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
1371 1374
 			if errOne != nil {
@@ -1435,6 +1438,7 @@ func BloodHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseou
1435 1438
 				WarehouseOutDetailId:    lastDrugOutInfo.ID,
1436 1439
 				OverCount:               sum_count,
1437 1440
 				AdviceId:                advice.ID,
1441
+				LastPrice:               warehouse.Price,
1438 1442
 			}
1439 1443
 
1440 1444
 			CreateDrugFlowOne(drugflow)
@@ -1528,7 +1532,7 @@ func BloodHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseou
1528 1532
 				Status:                  1,
1529 1533
 				Ctime:                   time.Now().Unix(),
1530 1534
 				Mtime:                   0,
1531
-				Price:                   warehouse.Price,
1535
+				Price:                   warehouse.RetailPrice,
1532 1536
 				WarehousingDetailId:     warehouse.ID,
1533 1537
 				WarehouseOutDetailId:    0,
1534 1538
 				CancelOutDetailId:       lastDrugCancelStock.ID,
@@ -1538,6 +1542,7 @@ func BloodHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseou
1538 1542
 				MinUnit:                 "",
1539 1543
 				AdviceId:                advice.ID,
1540 1544
 				StorehouseId:            storeConfig.DrugStorehouseOut,
1545
+				LastPrice:               warehouse.Price,
1541 1546
 			}
1542 1547
 			CreateDrugFlowOne(flow)
1543 1548
 			AddCancelSumCountOne(storeConfig.DrugStorehouseOut, advice.DrugId, advice.UserOrgId, flow.Count)
@@ -1645,6 +1650,7 @@ func BloodHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseou
1645 1650
 		//查询是否存在出库数据
1646 1651
 		_, errCode := GetSigleDrugWarehouseOutInfo(advice.PatientId, advice.AdviceDate, orgID)
1647 1652
 		if errCode == gorm.ErrRecordNotFound {
1653
+			fmt.Println("j你俩3233223323232323233wo")
1648 1654
 			errOne := AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
1649 1655
 			if errOne != nil {
1650 1656
 				return errOne
@@ -1741,6 +1747,7 @@ func BloodHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseou
1741 1747
 				WarehouseOutDetailId:    lastDrugOutInfo.ID,
1742 1748
 				OverCount:               sum_count,
1743 1749
 				AdviceId:                advice.ID,
1750
+				LastPrice:               warehouse.Price,
1744 1751
 			}
1745 1752
 
1746 1753
 			CreateDrugFlowOne(drugflow)
@@ -1831,7 +1838,7 @@ func BloodHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseou
1831 1838
 				Status:                  1,
1832 1839
 				Ctime:                   time.Now().Unix(),
1833 1840
 				Mtime:                   0,
1834
-				Price:                   warehouse.Price,
1841
+				Price:                   warehouse.RetailPrice,
1835 1842
 				WarehousingDetailId:     warehouse.ID,
1836 1843
 				WarehouseOutDetailId:    0,
1837 1844
 				CancelOutDetailId:       lastDrugCancelStock.ID,
@@ -1841,6 +1848,7 @@ func BloodHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseou
1841 1848
 				MinUnit:                 "",
1842 1849
 				AdviceId:                advice.ID,
1843 1850
 				StorehouseId:            storeConfig.DrugStorehouseOut,
1851
+				LastPrice:               warehouse.Price,
1844 1852
 			}
1845 1853
 			CreateDrugFlowOne(flow)
1846 1854
 
@@ -1881,7 +1889,7 @@ func GetSigleDrugWarehouseOutInfo(patient_id int64, advice_date int64, orgid int
1881 1889
 
1882 1890
 	info := models.XtDrugWarehouseOutInfo{}
1883 1891
 	var err error
1884
-	err = XTReadDB().Where("patient_id = ? and advice_date = ? and org_id = ? and status = 1", patient_id, advice_date, orgid).Find(&info).Error
1892
+	err = XTReadDB().Where("patient_id = ? and sys_record_time = ? and org_id = ? and status = 1", patient_id, advice_date, orgid).Find(&info).Error
1885 1893
 	if err == gorm.ErrRecordNotFound {
1886 1894
 		return nil, err
1887 1895
 	}
@@ -1914,7 +1922,7 @@ func FindDrugAutoReduceRecordInfo(patient_id int64, advice_date int64, orgid int
1914 1922
 
1915 1923
 	detail := models.DrugAutomaticReduceDetail{}
1916 1924
 	var err error
1917
-	err = XTReadDB().Where("patient_id = ? and advice_date = ? and org_id = ?", patient_id, advice_date, orgid).Find(&detail).Error
1925
+	err = XTReadDB().Where("patient_id = ? and record_time = ? and org_id = ?", patient_id, advice_date, orgid).Find(&detail).Error
1918 1926
 	if err == gorm.ErrRecordNotFound {
1919 1927
 		return nil, err
1920 1928
 	}
@@ -1930,11 +1938,11 @@ func UpdateDrugAutoReduceRecordInfo(patient_id int64, record_date int64, drug_id
1930 1938
 	return err
1931 1939
 }
1932 1940
 
1933
-func GetNewDrugWarehouseOutInfoSix(drugid int64, patient_id int64, record_date int64, org_id int64, advice_id int64) (models.DrugWarehouseOutInfo, error) {
1941
+func GetNewDrugWarehouseOutInfoSix(drugid int64, patient_id int64, record_date int64, org_id int64, advice_id int64, warehouse_info_id int64) (models.DrugWarehouseOutInfo, error) {
1934 1942
 
1935 1943
 	info := models.DrugWarehouseOutInfo{}
1936 1944
 	var err error
1937
-	err = XTReadDB().Where("drug_id = ? and patient_id = ? and sys_record_time = ? and org_id = ? and status = 1 and advice_id = ?", drugid, patient_id, record_date, org_id, advice_id).Find(&info).Error
1945
+	err = XTReadDB().Where("drug_id = ? and patient_id = ? and sys_record_time = ? and org_id = ? and status = 1 and advice_id = ? and warehouse_info_id = ?", drugid, patient_id, record_date, org_id, advice_id, warehouse_info_id).Find(&info).Error
1938 1946
 
1939 1947
 	return info, err
1940 1948
 }

+ 2 - 0
service/self_drug_service.go View File

@@ -1835,11 +1835,13 @@ func GetDrugStockCountList(orgId int64, storehouse_id int64, good_type int64, ke
1835 1835
 			db = db.Where("storehouse_id = ?", storehouse_id)
1836 1836
 		}
1837 1837
 		return db.Where("status = 1 and user_org_id = ?", orgId)
1838
+
1838 1839
 	}).Preload("DrugStockCount", func(db *gorm.DB) *gorm.DB {
1839 1840
 		if storehouse_id > 0 {
1840 1841
 			db = db.Where("storehouse_id = ?", storehouse_id)
1841 1842
 		}
1842 1843
 		return db.Where("status = 1 and user_org_id = ?", orgId).Group("drug_id,storehouse_id")
1844
+
1843 1845
 	}).Count(&total).Offset(offset).Limit(limit).Order("x.ctime desc").Find(&drug).Error
1844 1846
 
1845 1847
 	return drug, total, err

+ 7 - 1
service/stock_service.go View File

@@ -4784,7 +4784,7 @@ func GetStockFlowBatchNumber(id int64, goodid int64) (stock []*models.VmStockFlo
4784 4784
 
4785 4785
 func GetStockFlowBatchNumberOne(id int64, goodid int64) (stock []*models.VmStockFlowOne, err error) {
4786 4786
 
4787
-	db := XTReadDB().Table("xt_stock_flow as x").Where("x.status = 1 and x.count > 0 and (x.consumable_type = 3 or x.consumable_type = 2")
4787
+	db := XTReadDB().Table("xt_stock_flow as x").Where("x.status = 1 and x.count > 0 and (x.consumable_type = 3 or x.consumable_type = 2)")
4788 4788
 	table := XTReadDB().Table("xt_patients as t").Where("t.status = 1")
4789 4789
 	fmt.Println(table)
4790 4790
 	tableone := XTReadDB().Table("xt_good_information as o").Where("o.status = 1")
@@ -7560,6 +7560,12 @@ func UpdateGoodInfoSumCount(goodid int64, sum_count int64, orgid int64) error {
7560 7560
 	return err
7561 7561
 }
7562 7562
 
7563
+func UpdateGoodInfoSumCountSix(goodid int64, sum_count int64, orgid int64) error {
7564
+
7565
+	err := XTWriteDB().Model(&models.GoodInfo{}).Where("id = ? and org_id = ? and status = 1", goodid, orgid).Update(map[string]interface{}{"sum_count": sum_count}).Error
7566
+	return err
7567
+}
7568
+
7563 7569
 func UpdateGoodInfoReduceSumCount(goodid int64, sum_count int64, orgid int64) error {
7564 7570
 	tx := XTWriteDB().Begin()
7565 7571
 	err = tx.Model(&models.GoodInfo{}).Where("id = ? and org_id = ? and status = 1", goodid, orgid).Update(map[string]interface{}{"sum_count": sum_count}).Error

+ 7 - 30
service/warhouse_service.go View File

@@ -200,6 +200,7 @@ func DrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *model
200 200
 			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
201 201
 			StorehouseId:            storeConfig.DrugStorehouseOut,
202 202
 			WarehouseOutDetailId:    lastDrugOutInfo.ID,
203
+			LastPrice:               warehouse.Price,
203 204
 		}
204 205
 
205 206
 		CreateDrugFlowOne(drugflow)
@@ -413,6 +414,7 @@ func DrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *model
413 414
 			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
414 415
 			StorehouseId:            storeConfig.DrugStorehouseOut,
415 416
 			WarehouseOutDetailId:    lastDrugOutInfo.ID,
417
+			LastPrice:               warehouse.Price,
416 418
 		}
417 419
 
418 420
 		CreateDrugFlowOne(drugflow)
@@ -614,6 +616,7 @@ func HisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *mo
614 616
 			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
615 617
 			StorehouseId:            storeConfig.DrugStorehouseOut,
616 618
 			IsCheck:                 1,
619
+			LastPrice:               warehouse.Price,
617 620
 		}
618 621
 		errOne := AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
619 622
 		lastDrugOutInfo, _ := FindLastDrugWarehouseOutInfo(orgID)
@@ -647,6 +650,7 @@ func HisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *mo
647 650
 			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
648 651
 			StorehouseId:            storeConfig.DrugStorehouseOut,
649 652
 			WarehouseOutDetailId:    lastDrugOutInfo.ID,
653
+			LastPrice:               warehouse.Price,
650 654
 		}
651 655
 
652 656
 		CreateDrugFlowOne(drugflow)
@@ -832,6 +836,7 @@ func HisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *mo
832 836
 			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
833 837
 			StorehouseId:            storeConfig.DrugStorehouseOut,
834 838
 			WarehouseOutDetailId:    lastDrugOutInfo.ID,
839
+			LastPrice:               warehouse.Price,
835 840
 		}
836 841
 
837 842
 		CreateDrugFlowOne(drugflow)
@@ -896,34 +901,6 @@ func HisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *mo
896 901
 			return errThree
897 902
 		}
898 903
 
899
-		drugInfoList, _ := FindDrugWarehouseInfoList(advice.DrugId, orgID)
900
-		var drug_max_number int64
901
-		var drug_min_number int64
902
-		for _, item := range drugInfoList {
903
-			drug_max_number += item.StockMaxNumber
904
-			drug_min_number += item.StockMinNumber
905
-		}
906
-		drugFlushInfo := models.XtDrugWarehouseFlushInfo{
907
-			DrugMaxNumber:           drug_max_number,
908
-			UserOrgId:               orgID,
909
-			WarehouseOutId:          warehouseout.ID,
910
-			Type:                    1,
911
-			SystemTime:              advice.RecordDate,
912
-			PatientId:               advice.PatientId,
913
-			Ctime:                   time.Now().Unix(),
914
-			Mtime:                   0,
915
-			BatchNumberId:           warehouse.ID,
916
-			DrugId:                  advice.DrugId,
917
-			Count:                   stock_number,
918
-			WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
919
-			Creater:                 warehouseout.Creater,
920
-			DrugMinNumber:           drug_min_number,
921
-			Unit:                    drup.MinUnit,
922
-			AdviceId:                advice.ID,
923
-			Status:                  1,
924
-			WarehouseOutDetailId:    lastDrugOutInfo.ID,
925
-		}
926
-		CreatedDrugFlushInfo(drugFlushInfo)
927 904
 		// 清零完该库存后,还有剩余出库未出完,进行对应的递归操作
928 905
 		prescribingNumber_two_temp := deliver_number - stock_number
929 906
 
@@ -5588,7 +5565,7 @@ func AutoDrugDeliverInfoFourtyOne(orgID int64, prescribingNumber int64, warehous
5588 5565
 			ProductDate:             advice.ProductDate,
5589 5566
 			ExpireDate:              advice.ExpiryDate,
5590 5567
 			Count:                   deliver_number,
5591
-			Price:                   advice.Price,
5568
+			Price:                   warehouse.RetailPrice,
5592 5569
 			Status:                  1,
5593 5570
 			Ctime:                   time.Now().Unix(),
5594 5571
 			UserOrgId:               advice.OrgId,
@@ -5651,7 +5628,7 @@ func AutoDrugDeliverInfoFourtyOne(orgID int64, prescribingNumber int64, warehous
5651 5628
 			ProductDate:             advice.ProductDate,
5652 5629
 			ExpireDate:              advice.ExpiryDate,
5653 5630
 			Count:                   stock_number,
5654
-			Price:                   advice.Price,
5631
+			Price:                   warehouse.RetailPrice,
5655 5632
 			Status:                  1,
5656 5633
 			Ctime:                   time.Now().Unix(),
5657 5634
 			UserOrgId:               advice.OrgId,