diff --git a/DM_Weight/ViewModels/AccountWindowViewModel.cs b/DM_Weight/ViewModels/AccountWindowViewModel.cs index 848db2f..0fcd484 100644 --- a/DM_Weight/ViewModels/AccountWindowViewModel.cs +++ b/DM_Weight/ViewModels/AccountWindowViewModel.cs @@ -237,8 +237,13 @@ namespace DM_Weight.ViewModels { try { - - //查询账册中所有记录,与库存中的记录做比校,如果账册中没有,则添加一条 + string machineId = ConfigurationManager.AppSettings["machineId"] ?? "DM1"; + //根据已生成的日结存记录 + int deleteNum = SqlSugarHelper.Db.Deleteable() + .Where(cs => cs.Type.Equals(5) && cs.OperationTime.ToString("yyyy-MM-dd") == DateTime.Now.ToString("yyyy-MM-dd") && cs.MachineId.Equals(machineId)).ExecuteCommand(); + int inQuantity = 0; //当日入库量 + int outQuantity = 0; //当日出库量 + //查询账册中所有记录,与库存中的记录做比校,如果账册中没有,则添加一条,有则添加一条总日结存 List accountList = _machineRecordService.ReportAccountBook(nowDate, null, 0); //库存中的记录 List channelStockList = _channelStockService.GetAll(); @@ -249,33 +254,47 @@ namespace DM_Weight.ViewModels for (int i = 0; i < channelStockList.Count; i++) { - int Count = accountList.Where(cs => cs.DrugId == channelStockList[i].DrugId && cs.ManuNo == channelStockList[i].ManuNo).Count(); + int Count = accountList.Where(cs => cs.DrugId == channelStockList[i].DrugId).Count(); + if (Count <= 0) { - //没有直接插入 - // 保存数据 出/入库记录 - string InvoiceId = "Account_" + CurrentTimeMillis(); - SqlSugarHelper.Db.Insertable(new MachineRecord() - { - MachineId = channelStockList[i].MachineId, - DrawerNo = 0,//channelStockList[i].DrawerNo, - ColNo = 0,// channelStockList[i].ColNo,FV - DrugId = channelStockList[i].DrugId, - ManuNo = channelStockList[i].ManuNo, - EffDate = !String.IsNullOrEmpty(channelStockList[i].EffDate) ? DateTime.ParseExact(channelStockList[i].EffDate, "yyyy-MM-dd", System.Globalization.CultureInfo.CurrentCulture) : null, - Operator = HomeWindowViewModel.Operator?.Id, - Reviewer = HomeWindowViewModel.Reviewer?.Id, - OperationTime = DateTime.Now, - Quantity = 0, - Type = 5, - InvoiceId = string.Empty,//InvoiceId, - StockQuantity = channelStockList[i].Quantity, - ManunoQuantity = 0, - SupplierDept = ConfigurationManager.AppSettings["supplierDept"].ToString(), - ReceiveDept = ConfigurationManager.AppSettings["receiveDept"].ToString() - }).ExecuteCommand(); - + inQuantity = 0; + outQuantity = 0; } + else + { + inQuantity = accountList.Where(cs => cs.DrugId == channelStockList[i].DrugId).Sum(cs => cs.InQuantity); + outQuantity = accountList.Where(cs => cs.DrugId == channelStockList[i].DrugId).Sum(cs => cs.OutQuantity); + } + // 获取药品总库存 + int channelStockQuantity = SqlSugarHelper.Db.Queryable() + .Where(cs => cs.DrugId.Equals(channelStockList[i].DrugId)).Sum(it => it.Quantity); + //没有直接插入 + // 保存数据 出/入库记录 + string InvoiceId = "Account_" + CurrentTimeMillis(); + SqlSugarHelper.Db.Insertable(new MachineRecord() + { + MachineId = channelStockList[i].MachineId, + DrawerNo = 0,//channelStockList[i].DrawerNo, + ColNo = 0,// channelStockList[i].ColNo,FV + DrugId = channelStockList[i].DrugId, + ManuNo = "",//channelStockList[i].ManuNo, + EffDate = null,// !String.IsNullOrEmpty(channelStockList[i].EffDate) ? DateTime.ParseExact(channelStockList[i].EffDate, "yyyy-MM-dd", System.Globalization.CultureInfo.CurrentCulture) : null, + Operator = HomeWindowViewModel.Operator?.Id, + Reviewer = HomeWindowViewModel.Reviewer?.Id, + OperationTime = DateTime.Now, + Quantity = 0, + Type = 5, + InvoiceId = "日结存",//InvoiceId, + ReturnQuantity1 = inQuantity, //当日入库量总数 + ReturnQuantity2 = outQuantity, //当日出库量总数 + StockQuantity = channelStockQuantity, + ManunoQuantity = 0, + SupplierDept = string.Empty,// ConfigurationManager.AppSettings["supplierDept"].ToString(), + ReceiveDept = string.Empty,//ConfigurationManager.AppSettings["receiveDept"].ToString() + }).ExecuteCommand(); + + } } else @@ -284,6 +303,11 @@ namespace DM_Weight.ViewModels { //账册中没有记录则把库存中的所有数据都要生成一条账册记录 // 保存数据 出/入库记录 + // 获取药品总库存 + int channelStockQuantity = SqlSugarHelper.Db.Queryable() + .Where(cs => cs.DrugId.Equals(channelStockList[i].DrugId)).Sum(it => it.Quantity); + + string InvoiceId = "Account_" + CurrentTimeMillis(); SqlSugarHelper.Db.Insertable(new MachineRecord() { @@ -291,18 +315,20 @@ namespace DM_Weight.ViewModels DrawerNo = 0,//channelStockList[i].DrawerNo, ColNo = 0,//channelStockList[i].ColNo, DrugId = channelStockList[i].DrugId, - ManuNo = channelStockList[i].ManuNo, - EffDate = !String.IsNullOrEmpty(channelStockList[i].EffDate) ? DateTime.ParseExact(channelStockList[i].EffDate, "yyyy-MM-dd", System.Globalization.CultureInfo.CurrentCulture) : null, + ManuNo = "",// channelStockList[i].ManuNo, + EffDate = null,// !String.IsNullOrEmpty(channelStockList[i].EffDate) ? DateTime.ParseExact(channelStockList[i].EffDate, "yyyy-MM-dd", System.Globalization.CultureInfo.CurrentCulture) : null, Operator = HomeWindowViewModel.Operator?.Id, Reviewer = HomeWindowViewModel.Reviewer?.Id, OperationTime = DateTime.Now, Quantity = 0, Type = 5, - InvoiceId = string.Empty,//InvoiceId, - StockQuantity = channelStockList[i].Quantity, + InvoiceId = "日结存",// string.Empty,//InvoiceId, + ReturnQuantity1 = inQuantity, //当日入库量总数 + ReturnQuantity2 = outQuantity, //当日出库量总数 + StockQuantity = channelStockQuantity, ManunoQuantity = 0, - SupplierDept = ConfigurationManager.AppSettings["supplierDept"].ToString(), - ReceiveDept = ConfigurationManager.AppSettings["receiveDept"].ToString() + SupplierDept = string.Empty,//ConfigurationManager.AppSettings["supplierDept"].ToString(), + ReceiveDept = string.Empty,//ConfigurationManager.AppSettings["receiveDept"].ToString() }).ExecuteCommand(); } } diff --git a/DM_Weight/ViewModels/CheckStockNewWindowViewModel.cs b/DM_Weight/ViewModels/CheckStockNewWindowViewModel.cs index b6c7f6f..f7997de 100644 --- a/DM_Weight/ViewModels/CheckStockNewWindowViewModel.cs +++ b/DM_Weight/ViewModels/CheckStockNewWindowViewModel.cs @@ -317,16 +317,15 @@ namespace DM_Weight.ViewModels IGrouping grouping = enumerator.Current; //int DrawerNo =Convert.ToInt32(grouping.Key.Substring(0,grouping.Key.IndexOf('-'))); int DrawerNo = grouping.Key; - List channelStocks = grouping.ToList(); - channelStocks.ForEach(it => it.process = 1); + List Stocks = grouping.ToList(); + Stocks.ForEach(it => it.process = 1); _portUtil.SpeakAsync("正在打开" + DrawerNo + "号抽屉"); List singleChannels = new List(); - for (int i = 0; i < channelStocks.Count; i++) + for (int i = 0; i < Stocks.Count; i++) { - ChannelStock copy = TransExpV2.Trans(channelStocks[i]); + ChannelStock copy = TransExpV2.Trans(Stocks[i]); singleChannels.Add(copy); } - singleChannels = singleChannels.GroupBy(it => new { it.DrawerNo, @@ -334,8 +333,8 @@ namespace DM_Weight.ViewModels }).Select(it => { var ret = it.First(); - ret.Quantity = it.Sum(itx => itx.Quantity); - ret.AddQuantity = it.Sum(itx => itx.AddQuantity); + //ret.Quantity = it.Sum(itx => itx.Quantity); + //ret.AddQuantity = it.Sum(itx => itx.AddQuantity); return ret; }).ToList().FindAll(it => it.BoardType != 1); @@ -361,7 +360,7 @@ namespace DM_Weight.ViewModels _portUtil.Operate = true; _portUtil.BoardType = singleChannels.Count > 0 ? singleChannels[0].BoardType : 1; _portUtil.ColNos = singleChannels.Select(it => it.ColNo).ToArray(); - _portUtil.Stocks = singleChannels.Select(it => it.Quantity).ToArray(); + //_portUtil.Stocks = singleChannels.Select(it => it.Quantity).ToArray(); _portUtil.DrawerNo = DrawerNo; _portUtil.Start(); } @@ -401,28 +400,32 @@ namespace DM_Weight.ViewModels .Where(cs => cs.DrawerType == 1) .ToList(); - // 保存数据 盘点记录 - SqlSugarHelper.Db.Insertable(new MachineRecord() + //盘点时不记录盘点库存为0且盘点后库存仍为0的记录(该批次可能不再用了) + if (!it.Quantity.Equals(0) || !it.CheckQuantity.Equals(0)) { - MachineId = it.MachineId, - DrawerNo = it.DrawerNo, - ColNo = it.ColNo, - DrugId = it.DrugId, - ManuNo = it.ManuNo, - EffDate = !String.IsNullOrEmpty(it.EffDate) ? DateTime.ParseExact(it.EffDate, "yyyy-MM-dd", System.Globalization.CultureInfo.CurrentCulture) : null, - Operator = HomeWindowViewModel.Operator?.Id, - Reviewer = HomeWindowViewModel.Reviewer?.Id, - OperationTime = DateTime.Now, - Quantity = it.CheckQuantity - it.Quantity, - Type = 4, - InvoiceId = InvoiceId, - StockQuantity = nowChannels.Sum(it => it.Quantity), - CheckQuantity = it.CheckQuantity, - ManunoQuantity = nowChannels.FindAll(it2 => it2.ManuNo == it.ManuNo).Sum(it => it.Quantity) - }).ExecuteCommand(); + // 保存数据 盘点记录 + SqlSugarHelper.Db.Insertable(new MachineRecord() + { + MachineId = it.MachineId, + DrawerNo = it.DrawerNo, + ColNo = it.ColNo, + DrugId = it.DrugId, + ManuNo = it.ManuNo, + EffDate = !String.IsNullOrEmpty(it.EffDate) ? DateTime.ParseExact(it.EffDate, "yyyy-MM-dd", System.Globalization.CultureInfo.CurrentCulture) : null, + Operator = HomeWindowViewModel.Operator?.Id, + Reviewer = HomeWindowViewModel.Reviewer?.Id, + OperationTime = DateTime.Now, + Quantity = it.CheckQuantity - it.Quantity, + Type = 4, + InvoiceId = InvoiceId, + StockQuantity = nowChannels.Sum(it => it.Quantity), + CheckQuantity = it.CheckQuantity, + ManunoQuantity = nowChannels.FindAll(it2 => it2.ManuNo == it.ManuNo).Sum(it => it.Quantity) + }).ExecuteCommand(); + logger.Info($"库存盘点->库位【{it.DrawerNo}-{it.ColNo}】药品【{it.DrugInfo.DrugName}】盘点前库存【{it.Quantity}】,更改后【{it.CheckQuantity}】"); - logger.Info($"库存盘点->库位【{it.DrawerNo}-{it.ColNo}】药品【{it.DrugInfo.DrugName}】盘点前库存【{it.Quantity}】,更改后【{it.CheckQuantity}】"); + } } //Task.Factory.StartNew(()=> SaveCheckRecord()); @@ -454,28 +457,31 @@ namespace DM_Weight.ViewModels for (int j = 0; j < insertList.Count; j++) { - - CheckRecordStock cStock = insertList[j]; - // 保存数据 盘点后药品总库存及批次库存数 - SqlSugarHelper.Db.Insertable(new CheckRecordStock() + //盘点时不记录盘点库存为0且盘点后库存仍为0的记录(该批次可能不再用了) + if (!insertList[j].quantity.Equals(0)) { - rowNo = cStock.rowNo, - colNo = cStock.colNo, - ManuQuantity = checkRecordStockList.Where(it => it.drugId == cStock.drugId && it.manuNo == cStock.manuNo).Sum(it => it.quantity), - manuNo = cStock.manuNo, - effDate = cStock.effDate, - drugName = cStock.drugName, - manufactory = cStock.manufactory, - drugSpec = cStock.drugSpec, - packUnit = cStock.packUnit, - maxStock = cStock.maxStock, - drugId = cStock.drugId, - MachineId = cStock.MachineId, - quantity = checkRecordStockList.Where(it => it.drugId == cStock.drugId).Sum(it => it.quantity), - optdate = DateTime.Now.ToString(), - operatorUser = HomeWindowViewModel.Operator?.Id.ToString(), - reviewerUser = HomeWindowViewModel.Reviewer?.Id.ToString() - }).ExecuteCommand(); + CheckRecordStock cStock = insertList[j]; + // 保存数据 盘点后药品总库存及批次库存数 + SqlSugarHelper.Db.Insertable(new CheckRecordStock() + { + rowNo = cStock.rowNo, + colNo = cStock.colNo, + ManuQuantity = checkRecordStockList.Where(it => it.drugId == cStock.drugId && it.manuNo == cStock.manuNo).Sum(it => it.quantity), + manuNo = cStock.manuNo, + effDate = cStock.effDate, + drugName = cStock.drugName, + manufactory = cStock.manufactory, + drugSpec = cStock.drugSpec, + packUnit = cStock.packUnit, + maxStock = cStock.maxStock, + drugId = cStock.drugId, + MachineId = cStock.MachineId, + quantity = checkRecordStockList.Where(it => it.drugId == cStock.drugId).Sum(it => it.quantity), + optdate = DateTime.Now.ToString(), + operatorUser = HomeWindowViewModel.Operator?.Id.ToString(), + reviewerUser = HomeWindowViewModel.Reviewer?.Id.ToString() + }).ExecuteCommand(); + } } } logger.Info("已完成-保存数据 盘点后药品总库存及批次库存数"); @@ -612,7 +618,7 @@ namespace DM_Weight.ViewModels }); } - public bool KeepAlive => true; + public bool KeepAlive => false; private void DoDialogResult(IDialogResult dialogResult) {