修改一个处方对应多个药品信息

This commit is contained in:
maqiao 2024-09-20 11:26:33 +08:00
parent ece3d477a2
commit 25ec8fb290
1 changed files with 134 additions and 129 deletions

View File

@ -499,156 +499,161 @@ namespace DM_Weight.ViewModels
//Expression<Func<ChannelStock, bool>> updateExp = it => it.ManuNo == oi._OrderDetail.SetManuNo && it.EffDate == oi._OrderDetail.SetEffDate;
ChannelStock cs = SqlSugarHelper.Db.Queryable<ChannelStock>()
.Where(cs => cs.DrugId == oi._OrderDetail.DrugId
&& cs.ManuNo == oi._OrderDetail.SetManuNo
&& cs.EffDate == oi._OrderDetail.SetEffDate
&& cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM5")
&& cs.DrawerNo == DrawerNo).First();
if (cs == null)
for (int j = 0; j < oi.OrderDetailList.Count; j++)
{
empChannelStock += $"{oi.OrderNo},{oi._OrderDetail.DrugId},{oi._OrderDetail.SetManuNo},{oi._OrderDetail.SetEffDate}";
continue;
}
cs.Quantity = cs.Quantity - oi._OrderDetail.Quantity;
// 更新数据 库存信息
SqlSugarHelper.Db.Updateable(cs).UpdateColumns(it => new { it.Quantity }).ExecuteCommand();
if (cs != null)
{
SqlSugarHelper.Db.Insertable(new MachineRecord()
oi._OrderDetail = oi.OrderDetailList[j];
ChannelStock cs = SqlSugarHelper.Db.Queryable<ChannelStock>()
.Where(cs => cs.DrugId == oi._OrderDetail.DrugId
&& cs.ManuNo == oi._OrderDetail.SetManuNo
&& cs.EffDate == oi._OrderDetail.SetEffDate
&& cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM5")
&& cs.DrawerNo == DrawerNo+1).First();
if (cs == null)
{
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();
empChannelStock += $"{oi.OrderNo},{oi._OrderDetail.DrugId},{oi._OrderDetail.SetManuNo},{oi._OrderDetail.SetEffDate};";
continue;
}
cs.Quantity = cs.Quantity - oi._OrderDetail.Quantity;
// 更新数据 库存信息
SqlSugarHelper.Db.Updateable(cs).UpdateColumns(it => new { it.Quantity }).ExecuteCommand();
#region 使
//查询发药时间
MachineRecord SendMachineRecord = SqlSugarHelper.Db.Queryable<MachineRecord>().Where(mr => mr.DrawerNo == cs.DrawerNo && mr.Type == 2)
.OrderByDescending(mr => mr.OperationTime)
.First();
string retUser = SqlSugarHelper.Db.Queryable<ChannelList>().Where(cl => cl.MachineId == (ConfigurationManager.AppSettings["machineId"] ?? "DM5") && cl.DrawerNo == cs.DrawerNo)
.Select(cl => cl.BelongUser).First();
//发药信息
RejectionReport rejectionReport = new RejectionReport();
rejectionReport.SendDate = SendMachineRecord.OperationTime;
rejectionReport.SendUser = SendMachineRecord.Operator.ToString();
rejectionReport.ReceiveUser = retUser;
rejectionReport.RealNum = cs.BaseQuantity;
if (cs != null)
{
//还药信息
rejectionReport.InfactNum = cs.BaseQuantity - oi._OrderDetail.Quantity;
rejectionReport.EmptyNum = oi._OrderDetail.Quantity;
rejectionReport.ReturnTime = DateTime.Now;
rejectionReport.ReturnUser = retUser;
rejectionReport.ReturnReceiveUser = SendMachineRecord.Operator.ToString();
rejectionReport.DrugId = oi._OrderDetail.DrugId;
rejectionReport.DrugName = oi._OrderDetail.DrugInfo.DrugName;
rejectionReport.DrugSpec = oi._OrderDetail.DrugInfo.DrugSpec;
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();
rejectionReport.OperationTime = DateTime.Now;
#region 使
//查询发药时间
MachineRecord SendMachineRecord = SqlSugarHelper.Db.Queryable<MachineRecord>().Where(mr => mr.DrawerNo == cs.DrawerNo && mr.Type == 2)
.OrderByDescending(mr => mr.OperationTime)
.First();
string retUser = SqlSugarHelper.Db.Queryable<ChannelList>().Where(cl => cl.MachineId == (ConfigurationManager.AppSettings["machineId"] ?? "DM5") && cl.DrawerNo == cs.DrawerNo)
.Select(cl => cl.BelongUser).First();
//发药信息
RejectionReport rejectionReport = new RejectionReport();
rejectionReport.SendDate = SendMachineRecord.OperationTime;
rejectionReport.SendUser = SendMachineRecord.Operator.ToString();
rejectionReport.ReceiveUser = retUser;
rejectionReport.RealNum = cs.BaseQuantity;
int iRejectionReport = SqlSugarHelper.Db.Insertable(rejectionReport).ExecuteCommand();
//还药信息
rejectionReport.InfactNum = cs.BaseQuantity - oi._OrderDetail.Quantity;
rejectionReport.EmptyNum = oi._OrderDetail.Quantity;
rejectionReport.ReturnTime = DateTime.Now;
rejectionReport.ReturnUser = retUser;
rejectionReport.ReturnReceiveUser = SendMachineRecord.Operator.ToString();
rejectionReport.DrugId = oi._OrderDetail.DrugId;
rejectionReport.DrugName = oi._OrderDetail.DrugInfo.DrugName;
rejectionReport.DrugSpec = oi._OrderDetail.DrugInfo.DrugSpec;
#endregion
rejectionReport.OperationTime = DateTime.Now;
}
//保存账册
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
int iRejectionReport = SqlSugarHelper.Db.Insertable(rejectionReport).ExecuteCommand();
}).ExecuteCommand();
//修改凌晨生成的日结存与总结存数据
AccountBookG2 accountBookG2Day = SqlSugarHelper.Db.Queryable<AccountBookG2>()
.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)
{
accountBookG2Day.ManuStock = accountBookG2Day.ManuStock - oi._OrderDetail.Quantity;
SqlSugarHelper.Db.Updateable(accountBookG2Day).ExecuteCommand();
}
else
{
//生成日结存时可能没有该库位的绑定信息,需要写入日结存
int iDayResult = SqlSugarHelper.Db.Insertable(new AccountBookG2()
#endregion
}
//保存账册
int iInsertResult = SqlSugarHelper.Db.Insertable(new AccountBookG2()
{
DrugId = oi._OrderDetail.DrugId,
Type = 3,
Type = 2,
Department = oi.DeptName,
OrderNo = oi.OrderNo,
ManuNo = cs.ManuNo,
EffDate = cs.EffDate,
YQuantity = 0,
ManuStock = oi._OrderDetail.Quantity,
TotalStock = oi._OrderDetail.Quantity,
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"),
InvoiceNo = "日结存"
CreateTime = DateTime.Now,
InvoiceNo = oi.OrderNo
}).ExecuteCommand();
if (iDayResult <= 0)
//修改凌晨生成的日结存与总结存数据
AccountBookG2 accountBookG2Day = SqlSugarHelper.Db.Queryable<AccountBookG2>()
.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)
{
logger.Info($"未写入日结存数据{oi._OrderDetail.DrugId}-{cs.ManuNo}-{cs.EffDate}-{cs.Quantity}");
accountBookG2Day.ManuStock = accountBookG2Day.ManuStock - oi._OrderDetail.Quantity;
SqlSugarHelper.Db.Updateable(accountBookG2Day).ExecuteCommand();
}
}
//修改凌晨生成的日结存与总结存数据
AccountBookG2 accountBookG2Total = SqlSugarHelper.Db.Queryable<AccountBookG2>()
.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()
else
{
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"),
InvoiceNo = "总结存"
}).ExecuteCommand();
if (iTotalResult <= 0)
{
logger.Info($"未写入总结存数据{oi._OrderDetail.DrugId}-{oi._OrderDetail.Quantity}");
//生成日结存时可能没有该库位的绑定信息,需要写入日结存
int iDayResult = SqlSugarHelper.Db.Insertable(new AccountBookG2()
{
DrugId = oi._OrderDetail.DrugId,
Type = 3,
ManuNo = cs.ManuNo,
EffDate = cs.EffDate,
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"),
InvoiceNo = "日结存"
}).ExecuteCommand();
if (iDayResult <= 0)
{
logger.Info($"未写入日结存数据{oi._OrderDetail.DrugId}-{cs.ManuNo}-{cs.EffDate}-{cs.Quantity}");
}
}
//修改凌晨生成的日结存与总结存数据
AccountBookG2 accountBookG2Total = SqlSugarHelper.Db.Queryable<AccountBookG2>()
.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()
{
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"),
InvoiceNo = "总结存"
}).ExecuteCommand();
if (iTotalResult <= 0)
{
logger.Info($"未写入总结存数据{oi._OrderDetail.DrugId}-{oi._OrderDetail.Quantity}");
}
}
}
}
if (!string.IsNullOrEmpty(empChannelStock))
@ -660,7 +665,7 @@ namespace DM_Weight.ViewModels
};
_eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);
logger.Info($"所选处方对应药品批次效期无库存{empChannelStock}");
return false;
}
return true;
});