diff --git a/DM_Weight/ViewModels/CheckOrderNewWindowViewModel.cs b/DM_Weight/ViewModels/CheckOrderNewWindowViewModel.cs index 4051b0b..245f8b0 100644 --- a/DM_Weight/ViewModels/CheckOrderNewWindowViewModel.cs +++ b/DM_Weight/ViewModels/CheckOrderNewWindowViewModel.cs @@ -511,11 +511,11 @@ namespace DM_Weight.ViewModels continue; } cs.Quantity = cs.Quantity - oi._OrderDetail.Quantity; - cs.NeedNum = cs.NeedNum>0? cs.NeedNum + oi._OrderDetail.Quantity: oi._OrderDetail.Quantity; + cs.NeedNum = cs.NeedNum > 0 ? cs.NeedNum + oi._OrderDetail.Quantity : oi._OrderDetail.Quantity; logger.Info($"更新手术间{cs.DrawerNo}药品{cs.DrugId}批次{cs.ManuNo}库存为{cs.Quantity},需补药数量为{cs.NeedNum}"); // 更新数据 库存信息 SqlSugarHelper.Db.Updateable(cs).UpdateColumns(it => new { it.Quantity, it.NeedNum }).ExecuteCommand(); - + // 获取更新完库存后的药品库存 List nowChannels = SqlSugarHelper.Db.Queryable() .Where(it => it.MachineId.Equals(ConfigurationManager.AppSettings["machineId"]) || it.MachineId.Equals(ConfigurationManager.AppSettings["dm_machineId"])) @@ -523,159 +523,157 @@ namespace DM_Weight.ViewModels .Where(it => it.ManuNo.Equals(cs.ManuNo)) .Where(it => it.DrawerType == 1) .ToList(); - if (cs != null) + + SqlSugarHelper.Db.Insertable(new MachineRecord() { + MachineId = ConfigurationManager.AppSettings["dm_machineId"].ToString(), + DrawerNo = cs.DrawerNo, + ColNo = cs.ColNo, + DrugId = cs.DrugId, + ManuNo = cs.ManuNo, + EffDate = !String.IsNullOrEmpty(cs.EffDate) ? DateTime.ParseExact(cs.EffDate, "yyyy-MM-dd", System.Globalization.CultureInfo.CurrentCulture) : null, + Operator = HomeWindowViewModel.Operator?.Id, + Reviewer = HomeWindowViewModel.Reviewer?.Id, + OperationTime = DateTime.Now, + Quantity = oi._OrderDetail.Quantity, + Type = 2, + InvoiceId = oi.OrderNo + //, StockQuantity = nowChannels.Sum(it => it.Quantity) + }).ExecuteCommand(); - SqlSugarHelper.Db.Insertable(new MachineRecord() - { - MachineId = ConfigurationManager.AppSettings["dm_machineId"].ToString(), - DrawerNo = cs.DrawerNo, - ColNo = cs.ColNo, - DrugId = cs.DrugId, - ManuNo = cs.ManuNo, - EffDate = !String.IsNullOrEmpty(cs.EffDate) ? DateTime.ParseExact(cs.EffDate, "yyyy-MM-dd", System.Globalization.CultureInfo.CurrentCulture) : null, - Operator = HomeWindowViewModel.Operator?.Id, - Reviewer = HomeWindowViewModel.Reviewer?.Id, - OperationTime = DateTime.Now, - Quantity = oi._OrderDetail.Quantity, - Type = 2, - InvoiceId = oi.OrderNo - //, StockQuantity = nowChannels.Sum(it => it.Quantity) - }).ExecuteCommand(); + #region 记录 注射剂使用与交接记录报表 + //查询发药时间 + //MachineRecord SendMachineRecord = SqlSugarHelper.Db.Queryable().Where(mr => mr.DrawerNo == cs.DrawerNo && mr.Type == 2) + //.OrderByDescending(mr => mr.OperationTime) + //.First(); + //string retUser = SqlSugarHelper.Db.Queryable().Where(cl => cl.MachineId == (ConfigurationManager.AppSettings["machineId"] ?? "DM5") && cl.DrawerNo == cs.DrawerNo) + //.Select(cl => cl.BelongUser).First(); - #region 记录 注射剂使用与交接记录报表 - //查询发药时间 - //MachineRecord SendMachineRecord = SqlSugarHelper.Db.Queryable().Where(mr => mr.DrawerNo == cs.DrawerNo && mr.Type == 2) - //.OrderByDescending(mr => mr.OperationTime) - //.First(); - //string retUser = SqlSugarHelper.Db.Queryable().Where(cl => cl.MachineId == (ConfigurationManager.AppSettings["machineId"] ?? "DM5") && cl.DrawerNo == cs.DrawerNo) - //.Select(cl => cl.BelongUser).First(); + RejectionReport rejectionReport = SqlSugarHelper.Db.Queryable().Where(rp => rp.DrugId == cs.DrugId && rp.DrawerNo == cs.DrawerNo).OrderByDescending(rp => rp.SendDate).First(); + if (rejectionReport != null) + { + //发药信息 + //RejectionReport rejectionReport = new RejectionReport(); + //rejectionReport.SendDate = SendMachineRecord.OperationTime; + //rejectionReport.SendUser = SendMachineRecord.Operator.ToString(); + //rejectionReport.ReceiveUser = retUser; + rejectionReport.RealNum = cs.BaseQuantity; - RejectionReport rejectionReport = SqlSugarHelper.Db.Queryable().Where(rp => rp.DrugId == cs.DrugId && rp.DrawerNo == cs.DrawerNo).OrderByDescending(rp => rp.SendDate).First(); - if (rejectionReport != null) - { - //发药信息 - //RejectionReport rejectionReport = new RejectionReport(); - //rejectionReport.SendDate = SendMachineRecord.OperationTime; - //rejectionReport.SendUser = SendMachineRecord.Operator.ToString(); - //rejectionReport.ReceiveUser = retUser; - rejectionReport.RealNum = cs.BaseQuantity; + //还药信息 + rejectionReport.InfactNum = cs.BaseQuantity - oi._OrderDetail.Quantity; + rejectionReport.EmptyNum = oi._OrderDetail.Quantity; + rejectionReport.ReturnTime = DateTime.Now.ToString(); + rejectionReport.ReturnUser = rejectionReport.SendUser; + rejectionReport.ReturnReceiveUser = rejectionReport.ReceiveUser;// SendMachineRecord.Operator.ToString(); + rejectionReport.DrugId = oi._OrderDetail.DrugId; + rejectionReport.DrugName = oi._OrderDetail.DrugInfo.DrugName; + rejectionReport.DrugSpec = oi._OrderDetail.DrugInfo.DrugSpec; - //还药信息 - rejectionReport.InfactNum = cs.BaseQuantity - oi._OrderDetail.Quantity; - rejectionReport.EmptyNum = oi._OrderDetail.Quantity; - rejectionReport.ReturnTime = DateTime.Now.ToString(); - rejectionReport.ReturnUser = rejectionReport.SendUser; - rejectionReport.ReturnReceiveUser = rejectionReport.ReceiveUser;// SendMachineRecord.Operator.ToString(); - rejectionReport.DrugId = oi._OrderDetail.DrugId; - rejectionReport.DrugName = oi._OrderDetail.DrugInfo.DrugName; - rejectionReport.DrugSpec = oi._OrderDetail.DrugInfo.DrugSpec; + rejectionReport.OperationTime = DateTime.Now; - rejectionReport.OperationTime = DateTime.Now; + int iRejectionReport = SqlSugarHelper.Db.Updateable(rejectionReport).ExecuteCommand(); + } + #endregion - int iRejectionReport = SqlSugarHelper.Db.Updateable(rejectionReport).ExecuteCommand(); - } - #endregion - - //} - //查询上一条账册中的空瓶数 - AccountBookG2 accountBookEmpty = SqlSugarHelper.Db.Queryable() - .Where(ab => ab.MachineId.Equals(ConfigurationManager.AppSettings["dm_machineId"].ToString())) - .Where(ab => ab.Type == 1 || ab.Type == 2) - .Where(ab => ab.DrugId == oi._OrderDetail.DrugId) - .Where(ab => ab.ManuNo == cs.ManuNo).OrderByDescending(ab => ab.Id).First(); - //保存账册 - int iInsertResult = SqlSugarHelper.Db.Insertable(new AccountBookG2() + //} + //修改凌晨生成的日结存与总结存数据 + AccountBookG2 accountBookG2Day = SqlSugarHelper.Db.Queryable() + .Where(ab => ab.MachineId.Equals(ConfigurationManager.AppSettings["dm_machineId"].ToString())) + .Where(ab => ab.Type == 3) + .Where(ab => ab.DrugId == oi._OrderDetail.DrugId) + .Where(ab => ab.ManuNo == cs.ManuNo) + .Where(ab => ab.CreateDate == DateTime.Now.ToString("yyyy-MM-dd")).First(); + int manuStock = 0; + if (accountBookG2Day != null) + { + accountBookG2Day.ManuStock = accountBookG2Day.ManuStock - oi._OrderDetail.Quantity; + accountBookG2Day.OutQuantity = accountBookG2Day.OutQuantity + oi._OrderDetail.Quantity; + SqlSugarHelper.Db.Updateable(accountBookG2Day).ExecuteCommand(); + manuStock = accountBookG2Day.ManuStock; + } + else + { + //生成日结存时可能没有该库位的绑定信息,需要写入日结存 + int iDayResult = SqlSugarHelper.Db.Insertable(new AccountBookG2() { DrugId = oi._OrderDetail.DrugId, - Type = 2, - Department = oi.DeptName, - OrderNo = oi.OrderNo, + Type = 3, ManuNo = cs.ManuNo, EffDate = cs.EffDate, - OutQuantity = oi._OrderDetail.Quantity, + YQuantity = 0, + ManuStock = nowChannels.Sum(it => it.Quantity), //oi._OrderDetail.Quantity, + TotalStock = oi._OrderDetail.Quantity, UserId1 = HomeWindowViewModel.Operator?.Id, UserId2 = HomeWindowViewModel.Reviewer?.Id, MachineId = ConfigurationManager.AppSettings["dm_machineId"].ToString(), CreateDate = DateTime.Now.ToString("yyyy-MM-dd"), CreateTime = DateTime.Now, - InvoiceNo = oi.OrderNo, - ManuStock = nowChannels.Sum(it => it.Quantity), - TotalStock = (accountBookEmpty != null ? (accountBookEmpty.TotalStock > 0 ? accountBookEmpty.TotalStock : 0) : 0) + oi._OrderDetail.Quantity, - ShoushuJian= drawerNo.ToString() + InvoiceNo = "日结存", + OutQuantity = oi._OrderDetail.Quantity, }).ExecuteCommand(); - //修改凌晨生成的日结存与总结存数据 - AccountBookG2 accountBookG2Day = SqlSugarHelper.Db.Queryable() - .Where(ab => ab.MachineId.Equals(ConfigurationManager.AppSettings["dm_machineId"].ToString())) - .Where(ab => ab.Type == 3) - .Where(ab => ab.DrugId == oi._OrderDetail.DrugId) - .Where(ab => ab.ManuNo == cs.ManuNo) - .Where(ab => ab.CreateDate == DateTime.Now.ToString("yyyy-MM-dd")).First(); - if (accountBookG2Day != null) + if (iDayResult <= 0) { - accountBookG2Day.ManuStock = accountBookG2Day.ManuStock - oi._OrderDetail.Quantity; - accountBookG2Day.OutQuantity= accountBookG2Day.OutQuantity + oi._OrderDetail.Quantity; - SqlSugarHelper.Db.Updateable(accountBookG2Day).ExecuteCommand(); + logger.Info($"未写入日结存数据{oi._OrderDetail.DrugId}-{cs.ManuNo}-{cs.EffDate}-{cs.Quantity}"); } - else + } + //查询上一条账册中的空瓶数 + AccountBookG2 accountBookEmpty = SqlSugarHelper.Db.Queryable() + .Where(ab => ab.MachineId.Equals(ConfigurationManager.AppSettings["dm_machineId"].ToString())) + .Where(ab => ab.Type == 1 || ab.Type == 2) + .Where(ab => ab.DrugId == oi._OrderDetail.DrugId) + .Where(ab => ab.ManuNo == cs.ManuNo).OrderByDescending(ab => ab.Id).First(); + //保存账册 + int iInsertResult = SqlSugarHelper.Db.Insertable(new AccountBookG2() + { + DrugId = oi._OrderDetail.DrugId, + Type = 2, + Department = oi.DeptName, + OrderNo = oi.OrderNo, + ManuNo = cs.ManuNo, + EffDate = cs.EffDate, + OutQuantity = oi._OrderDetail.Quantity, + UserId1 = HomeWindowViewModel.Operator?.Id, + UserId2 = HomeWindowViewModel.Reviewer?.Id, + MachineId = ConfigurationManager.AppSettings["dm_machineId"].ToString(), + CreateDate = DateTime.Now.ToString("yyyy-MM-dd"), + CreateTime = DateTime.Now, + InvoiceNo = oi.OrderNo, + ManuStock = manuStock > 0 ? manuStock : nowChannels.Sum(it => it.Quantity), + TotalStock = (accountBookEmpty != null ? (accountBookEmpty.TotalStock > 0 ? accountBookEmpty.TotalStock : 0) : 0) + oi._OrderDetail.Quantity, + ShoushuJian = drawerNo.ToString() + }).ExecuteCommand(); + //修改凌晨生成的日结存与总结存数据 + AccountBookG2 accountBookG2Total = SqlSugarHelper.Db.Queryable() + .Where(ab => ab.MachineId.Equals(ConfigurationManager.AppSettings["dm_machineId"].ToString())) + .Where(ab => ab.Type == 4) + .Where(ab => ab.DrugId == oi._OrderDetail.DrugId) + .Where(ab => ab.CreateDate == DateTime.Now.ToString("yyyy-MM-dd")).First(); + if (accountBookG2Total != null) + { + accountBookG2Total.TotalStock = accountBookG2Total.TotalStock - oi._OrderDetail.Quantity; + SqlSugarHelper.Db.Updateable(accountBookG2Total).ExecuteCommand(); + } + else + { + //生成总结存时可能没有该库位的绑定信息,需要写入总结存 + int iTotalResult = SqlSugarHelper.Db.Insertable(new AccountBookG2() { - //生成日结存时可能没有该库位的绑定信息,需要写入日结存 - int iDayResult = SqlSugarHelper.Db.Insertable(new AccountBookG2() - { - DrugId = oi._OrderDetail.DrugId, - Type = 3, - ManuNo = cs.ManuNo, - EffDate = cs.EffDate, - YQuantity = 0, - ManuStock =nowChannels.Sum(it => it.Quantity), //oi._OrderDetail.Quantity, - TotalStock = oi._OrderDetail.Quantity, - UserId1 = HomeWindowViewModel.Operator?.Id, - UserId2 = HomeWindowViewModel.Reviewer?.Id, - MachineId = ConfigurationManager.AppSettings["dm_machineId"].ToString(), - CreateDate = DateTime.Now.ToString("yyyy-MM-dd"), - CreateTime=DateTime.Now, - InvoiceNo = "日结存", - OutQuantity = oi._OrderDetail.Quantity, - }).ExecuteCommand(); - if (iDayResult <= 0) - { - logger.Info($"未写入日结存数据{oi._OrderDetail.DrugId}-{cs.ManuNo}-{cs.EffDate}-{cs.Quantity}"); - } - } - //修改凌晨生成的日结存与总结存数据 - AccountBookG2 accountBookG2Total = SqlSugarHelper.Db.Queryable() - .Where(ab => ab.MachineId.Equals(ConfigurationManager.AppSettings["dm_machineId"].ToString())) - .Where(ab => ab.Type == 4) - .Where(ab => ab.DrugId == oi._OrderDetail.DrugId) - .Where(ab => ab.CreateDate == DateTime.Now.ToString("yyyy-MM-dd")).First(); - if (accountBookG2Total != null) + DrugId = oi._OrderDetail.DrugId, + Type = 4, + YQuantity = 0, + ManuStock = oi._OrderDetail.Quantity, + TotalStock = oi._OrderDetail.Quantity, + UserId1 = HomeWindowViewModel.Operator?.Id, + UserId2 = HomeWindowViewModel.Reviewer?.Id, + MachineId = ConfigurationManager.AppSettings["dm_machineId"].ToString(), + CreateDate = DateTime.Now.ToString("yyyy-MM-dd"), + CreateTime = DateTime.Now, + InvoiceNo = "总结存" + }).ExecuteCommand(); + if (iTotalResult <= 0) { - accountBookG2Total.TotalStock = accountBookG2Total.TotalStock - oi._OrderDetail.Quantity; - SqlSugarHelper.Db.Updateable(accountBookG2Total).ExecuteCommand(); + logger.Info($"未写入总结存数据{oi._OrderDetail.DrugId}-{oi._OrderDetail.Quantity}"); } - else - { - //生成总结存时可能没有该库位的绑定信息,需要写入总结存 - int iTotalResult = SqlSugarHelper.Db.Insertable(new AccountBookG2() - { - DrugId = oi._OrderDetail.DrugId, - Type = 4, - YQuantity = 0, - ManuStock = oi._OrderDetail.Quantity, - TotalStock = oi._OrderDetail.Quantity, - UserId1 = HomeWindowViewModel.Operator?.Id, - UserId2 = HomeWindowViewModel.Reviewer?.Id, - MachineId = ConfigurationManager.AppSettings["dm_machineId"].ToString(), - CreateDate = DateTime.Now.ToString("yyyy-MM-dd"), - CreateTime = DateTime.Now, - InvoiceNo = "总结存" - }).ExecuteCommand(); - if (iTotalResult <= 0) - { - logger.Info($"未写入总结存数据{oi._OrderDetail.DrugId}-{oi._OrderDetail.Quantity}"); - } - } - } } if (!string.IsNullOrEmpty(empChannelStock))