Browse Source

11月9日库存管理

XMLWAN 2 years ago
parent
commit
178bd3b9bb

+ 1 - 1
conf/app.conf View File

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

+ 1 - 1
controllers/his_api_controller.go View File

3141
 					total_count_one += it.StockCount
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
 				goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
3146
 				goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
3147
 				var flush_count int64
3147
 				var flush_count int64

+ 3 - 3
controllers/secondary_order_api_contorller.go View File

278
 		return
278
 		return
279
 	}
279
 	}
280
 	defer func() {
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
 	var storehouse_status, admin_id int64
285
 	var storehouse_status, admin_id int64
1322
 					total_count += it.StockCount
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
 				WarehouseOutDetailId:    lastDrugOutInfo.ID,
789
 				WarehouseOutDetailId:    lastDrugOutInfo.ID,
790
 				OverCount:               sum_count,
790
 				OverCount:               sum_count,
791
 				AdviceId:                advice.ID,
791
 				AdviceId:                advice.ID,
792
+				LastPrice:               warehouse.Price,
792
 			}
793
 			}
793
 
794
 
794
 			CreateDrugFlowOne(drugflow)
795
 			CreateDrugFlowOne(drugflow)
882
 				Status:                  1,
883
 				Status:                  1,
883
 				Ctime:                   time.Now().Unix(),
884
 				Ctime:                   time.Now().Unix(),
884
 				Mtime:                   0,
885
 				Mtime:                   0,
885
-				Price:                   warehouse.Price,
886
+				Price:                   warehouse.RetailPrice,
886
 				WarehousingDetailId:     warehouse.ID,
887
 				WarehousingDetailId:     warehouse.ID,
887
 				WarehouseOutDetailId:    0,
888
 				WarehouseOutDetailId:    0,
888
 				CancelOutDetailId:       lastDrugCancelStock.ID,
889
 				CancelOutDetailId:       lastDrugCancelStock.ID,
892
 				MinUnit:                 "",
893
 				MinUnit:                 "",
893
 				AdviceId:                advice.ID,
894
 				AdviceId:                advice.ID,
894
 				StorehouseId:            storeConfig.DrugStorehouseOut,
895
 				StorehouseId:            storeConfig.DrugStorehouseOut,
896
+				LastPrice:               warehouse.Price,
895
 			}
897
 			}
896
 			CreateDrugFlowOne(flow)
898
 			CreateDrugFlowOne(flow)
897
 			AddCancelSumCountOne(storeConfig.DrugStorehouseOut, advice.DrugId, advice.UserOrgId, flow.Count)
899
 			AddCancelSumCountOne(storeConfig.DrugStorehouseOut, advice.DrugId, advice.UserOrgId, flow.Count)
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
 		if lastDrugOutInfo.ID == 0 {
1372
 		if lastDrugOutInfo.ID == 0 {
1370
 			errOne := AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
1373
 			errOne := AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
1371
 			if errOne != nil {
1374
 			if errOne != nil {
1435
 				WarehouseOutDetailId:    lastDrugOutInfo.ID,
1438
 				WarehouseOutDetailId:    lastDrugOutInfo.ID,
1436
 				OverCount:               sum_count,
1439
 				OverCount:               sum_count,
1437
 				AdviceId:                advice.ID,
1440
 				AdviceId:                advice.ID,
1441
+				LastPrice:               warehouse.Price,
1438
 			}
1442
 			}
1439
 
1443
 
1440
 			CreateDrugFlowOne(drugflow)
1444
 			CreateDrugFlowOne(drugflow)
1528
 				Status:                  1,
1532
 				Status:                  1,
1529
 				Ctime:                   time.Now().Unix(),
1533
 				Ctime:                   time.Now().Unix(),
1530
 				Mtime:                   0,
1534
 				Mtime:                   0,
1531
-				Price:                   warehouse.Price,
1535
+				Price:                   warehouse.RetailPrice,
1532
 				WarehousingDetailId:     warehouse.ID,
1536
 				WarehousingDetailId:     warehouse.ID,
1533
 				WarehouseOutDetailId:    0,
1537
 				WarehouseOutDetailId:    0,
1534
 				CancelOutDetailId:       lastDrugCancelStock.ID,
1538
 				CancelOutDetailId:       lastDrugCancelStock.ID,
1538
 				MinUnit:                 "",
1542
 				MinUnit:                 "",
1539
 				AdviceId:                advice.ID,
1543
 				AdviceId:                advice.ID,
1540
 				StorehouseId:            storeConfig.DrugStorehouseOut,
1544
 				StorehouseId:            storeConfig.DrugStorehouseOut,
1545
+				LastPrice:               warehouse.Price,
1541
 			}
1546
 			}
1542
 			CreateDrugFlowOne(flow)
1547
 			CreateDrugFlowOne(flow)
1543
 			AddCancelSumCountOne(storeConfig.DrugStorehouseOut, advice.DrugId, advice.UserOrgId, flow.Count)
1548
 			AddCancelSumCountOne(storeConfig.DrugStorehouseOut, advice.DrugId, advice.UserOrgId, flow.Count)
1645
 		//查询是否存在出库数据
1650
 		//查询是否存在出库数据
1646
 		_, errCode := GetSigleDrugWarehouseOutInfo(advice.PatientId, advice.AdviceDate, orgID)
1651
 		_, errCode := GetSigleDrugWarehouseOutInfo(advice.PatientId, advice.AdviceDate, orgID)
1647
 		if errCode == gorm.ErrRecordNotFound {
1652
 		if errCode == gorm.ErrRecordNotFound {
1653
+			fmt.Println("j你俩3233223323232323233wo")
1648
 			errOne := AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
1654
 			errOne := AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
1649
 			if errOne != nil {
1655
 			if errOne != nil {
1650
 				return errOne
1656
 				return errOne
1741
 				WarehouseOutDetailId:    lastDrugOutInfo.ID,
1747
 				WarehouseOutDetailId:    lastDrugOutInfo.ID,
1742
 				OverCount:               sum_count,
1748
 				OverCount:               sum_count,
1743
 				AdviceId:                advice.ID,
1749
 				AdviceId:                advice.ID,
1750
+				LastPrice:               warehouse.Price,
1744
 			}
1751
 			}
1745
 
1752
 
1746
 			CreateDrugFlowOne(drugflow)
1753
 			CreateDrugFlowOne(drugflow)
1831
 				Status:                  1,
1838
 				Status:                  1,
1832
 				Ctime:                   time.Now().Unix(),
1839
 				Ctime:                   time.Now().Unix(),
1833
 				Mtime:                   0,
1840
 				Mtime:                   0,
1834
-				Price:                   warehouse.Price,
1841
+				Price:                   warehouse.RetailPrice,
1835
 				WarehousingDetailId:     warehouse.ID,
1842
 				WarehousingDetailId:     warehouse.ID,
1836
 				WarehouseOutDetailId:    0,
1843
 				WarehouseOutDetailId:    0,
1837
 				CancelOutDetailId:       lastDrugCancelStock.ID,
1844
 				CancelOutDetailId:       lastDrugCancelStock.ID,
1841
 				MinUnit:                 "",
1848
 				MinUnit:                 "",
1842
 				AdviceId:                advice.ID,
1849
 				AdviceId:                advice.ID,
1843
 				StorehouseId:            storeConfig.DrugStorehouseOut,
1850
 				StorehouseId:            storeConfig.DrugStorehouseOut,
1851
+				LastPrice:               warehouse.Price,
1844
 			}
1852
 			}
1845
 			CreateDrugFlowOne(flow)
1853
 			CreateDrugFlowOne(flow)
1846
 
1854
 
1881
 
1889
 
1882
 	info := models.XtDrugWarehouseOutInfo{}
1890
 	info := models.XtDrugWarehouseOutInfo{}
1883
 	var err error
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
 	if err == gorm.ErrRecordNotFound {
1893
 	if err == gorm.ErrRecordNotFound {
1886
 		return nil, err
1894
 		return nil, err
1887
 	}
1895
 	}
1914
 
1922
 
1915
 	detail := models.DrugAutomaticReduceDetail{}
1923
 	detail := models.DrugAutomaticReduceDetail{}
1916
 	var err error
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
 	if err == gorm.ErrRecordNotFound {
1926
 	if err == gorm.ErrRecordNotFound {
1919
 		return nil, err
1927
 		return nil, err
1920
 	}
1928
 	}
1930
 	return err
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
 	info := models.DrugWarehouseOutInfo{}
1943
 	info := models.DrugWarehouseOutInfo{}
1936
 	var err error
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
 	return info, err
1947
 	return info, err
1940
 }
1948
 }

+ 2 - 0
service/self_drug_service.go View File

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

+ 7 - 1
service/stock_service.go View File

4784
 
4784
 
4785
 func GetStockFlowBatchNumberOne(id int64, goodid int64) (stock []*models.VmStockFlowOne, err error) {
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
 	table := XTReadDB().Table("xt_patients as t").Where("t.status = 1")
4788
 	table := XTReadDB().Table("xt_patients as t").Where("t.status = 1")
4789
 	fmt.Println(table)
4789
 	fmt.Println(table)
4790
 	tableone := XTReadDB().Table("xt_good_information as o").Where("o.status = 1")
4790
 	tableone := XTReadDB().Table("xt_good_information as o").Where("o.status = 1")
7560
 	return err
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
 func UpdateGoodInfoReduceSumCount(goodid int64, sum_count int64, orgid int64) error {
7569
 func UpdateGoodInfoReduceSumCount(goodid int64, sum_count int64, orgid int64) error {
7564
 	tx := XTWriteDB().Begin()
7570
 	tx := XTWriteDB().Begin()
7565
 	err = tx.Model(&models.GoodInfo{}).Where("id = ? and org_id = ? and status = 1", goodid, orgid).Update(map[string]interface{}{"sum_count": sum_count}).Error
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
 			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
200
 			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
201
 			StorehouseId:            storeConfig.DrugStorehouseOut,
201
 			StorehouseId:            storeConfig.DrugStorehouseOut,
202
 			WarehouseOutDetailId:    lastDrugOutInfo.ID,
202
 			WarehouseOutDetailId:    lastDrugOutInfo.ID,
203
+			LastPrice:               warehouse.Price,
203
 		}
204
 		}
204
 
205
 
205
 		CreateDrugFlowOne(drugflow)
206
 		CreateDrugFlowOne(drugflow)
413
 			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
414
 			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
414
 			StorehouseId:            storeConfig.DrugStorehouseOut,
415
 			StorehouseId:            storeConfig.DrugStorehouseOut,
415
 			WarehouseOutDetailId:    lastDrugOutInfo.ID,
416
 			WarehouseOutDetailId:    lastDrugOutInfo.ID,
417
+			LastPrice:               warehouse.Price,
416
 		}
418
 		}
417
 
419
 
418
 		CreateDrugFlowOne(drugflow)
420
 		CreateDrugFlowOne(drugflow)
614
 			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
616
 			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
615
 			StorehouseId:            storeConfig.DrugStorehouseOut,
617
 			StorehouseId:            storeConfig.DrugStorehouseOut,
616
 			IsCheck:                 1,
618
 			IsCheck:                 1,
619
+			LastPrice:               warehouse.Price,
617
 		}
620
 		}
618
 		errOne := AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
621
 		errOne := AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
619
 		lastDrugOutInfo, _ := FindLastDrugWarehouseOutInfo(orgID)
622
 		lastDrugOutInfo, _ := FindLastDrugWarehouseOutInfo(orgID)
647
 			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
650
 			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
648
 			StorehouseId:            storeConfig.DrugStorehouseOut,
651
 			StorehouseId:            storeConfig.DrugStorehouseOut,
649
 			WarehouseOutDetailId:    lastDrugOutInfo.ID,
652
 			WarehouseOutDetailId:    lastDrugOutInfo.ID,
653
+			LastPrice:               warehouse.Price,
650
 		}
654
 		}
651
 
655
 
652
 		CreateDrugFlowOne(drugflow)
656
 		CreateDrugFlowOne(drugflow)
832
 			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
836
 			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
833
 			StorehouseId:            storeConfig.DrugStorehouseOut,
837
 			StorehouseId:            storeConfig.DrugStorehouseOut,
834
 			WarehouseOutDetailId:    lastDrugOutInfo.ID,
838
 			WarehouseOutDetailId:    lastDrugOutInfo.ID,
839
+			LastPrice:               warehouse.Price,
835
 		}
840
 		}
836
 
841
 
837
 		CreateDrugFlowOne(drugflow)
842
 		CreateDrugFlowOne(drugflow)
896
 			return errThree
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
 		prescribingNumber_two_temp := deliver_number - stock_number
905
 		prescribingNumber_two_temp := deliver_number - stock_number
929
 
906
 
5588
 			ProductDate:             advice.ProductDate,
5565
 			ProductDate:             advice.ProductDate,
5589
 			ExpireDate:              advice.ExpiryDate,
5566
 			ExpireDate:              advice.ExpiryDate,
5590
 			Count:                   deliver_number,
5567
 			Count:                   deliver_number,
5591
-			Price:                   advice.Price,
5568
+			Price:                   warehouse.RetailPrice,
5592
 			Status:                  1,
5569
 			Status:                  1,
5593
 			Ctime:                   time.Now().Unix(),
5570
 			Ctime:                   time.Now().Unix(),
5594
 			UserOrgId:               advice.OrgId,
5571
 			UserOrgId:               advice.OrgId,
5651
 			ProductDate:             advice.ProductDate,
5628
 			ProductDate:             advice.ProductDate,
5652
 			ExpireDate:              advice.ExpiryDate,
5629
 			ExpireDate:              advice.ExpiryDate,
5653
 			Count:                   stock_number,
5630
 			Count:                   stock_number,
5654
-			Price:                   advice.Price,
5631
+			Price:                   warehouse.RetailPrice,
5655
 			Status:                  1,
5632
 			Status:                  1,
5656
 			Ctime:                   time.Now().Unix(),
5633
 			Ctime:                   time.Now().Unix(),
5657
 			UserOrgId:               advice.OrgId,
5634
 			UserOrgId:               advice.OrgId,