修改一个处方对应多个药品信息
This commit is contained in:
parent
ece3d477a2
commit
25ec8fb290
|
@ -499,156 +499,161 @@ namespace DM_Weight.ViewModels
|
||||||
|
|
||||||
//Expression<Func<ChannelStock, bool>> updateExp = it => it.ManuNo == oi._OrderDetail.SetManuNo && it.EffDate == oi._OrderDetail.SetEffDate;
|
//Expression<Func<ChannelStock, bool>> updateExp = it => it.ManuNo == oi._OrderDetail.SetManuNo && it.EffDate == oi._OrderDetail.SetEffDate;
|
||||||
|
|
||||||
ChannelStock cs = SqlSugarHelper.Db.Queryable<ChannelStock>()
|
for (int j = 0; j < oi.OrderDetailList.Count; j++)
|
||||||
.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)
|
|
||||||
{
|
{
|
||||||
empChannelStock += $"{oi.OrderNo},{oi._OrderDetail.DrugId},{oi._OrderDetail.SetManuNo},{oi._OrderDetail.SetEffDate}";
|
oi._OrderDetail = oi.OrderDetailList[j];
|
||||||
continue;
|
ChannelStock cs = SqlSugarHelper.Db.Queryable<ChannelStock>()
|
||||||
}
|
.Where(cs => cs.DrugId == oi._OrderDetail.DrugId
|
||||||
cs.Quantity = cs.Quantity - oi._OrderDetail.Quantity;
|
&& cs.ManuNo == oi._OrderDetail.SetManuNo
|
||||||
// 更新数据 库存信息
|
&& cs.EffDate == oi._OrderDetail.SetEffDate
|
||||||
SqlSugarHelper.Db.Updateable(cs).UpdateColumns(it => new { it.Quantity }).ExecuteCommand();
|
&& cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM5")
|
||||||
|
&& cs.DrawerNo == DrawerNo+1).First();
|
||||||
if (cs != null)
|
if (cs == null)
|
||||||
{
|
|
||||||
|
|
||||||
SqlSugarHelper.Db.Insertable(new MachineRecord()
|
|
||||||
{
|
{
|
||||||
MachineId = ConfigurationManager.AppSettings["dm_machineId"].ToString(),
|
empChannelStock += $"{oi.OrderNo},{oi._OrderDetail.DrugId},{oi._OrderDetail.SetManuNo},{oi._OrderDetail.SetEffDate};";
|
||||||
DrawerNo = cs.DrawerNo,
|
continue;
|
||||||
ColNo = cs.ColNo,
|
}
|
||||||
DrugId = cs.DrugId,
|
cs.Quantity = cs.Quantity - oi._OrderDetail.Quantity;
|
||||||
ManuNo = cs.ManuNo,
|
// 更新数据 库存信息
|
||||||
EffDate = !String.IsNullOrEmpty(cs.EffDate) ? DateTime.ParseExact(cs.EffDate, "yyyy-MM-dd", System.Globalization.CultureInfo.CurrentCulture) : null,
|
SqlSugarHelper.Db.Updateable(cs).UpdateColumns(it => new { it.Quantity }).ExecuteCommand();
|
||||||
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 记录 注射剂使用与交接记录报表
|
if (cs != null)
|
||||||
//查询发药时间
|
{
|
||||||
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;
|
|
||||||
|
|
||||||
//还药信息
|
SqlSugarHelper.Db.Insertable(new MachineRecord()
|
||||||
rejectionReport.InfactNum = cs.BaseQuantity - oi._OrderDetail.Quantity;
|
{
|
||||||
rejectionReport.EmptyNum = oi._OrderDetail.Quantity;
|
MachineId = ConfigurationManager.AppSettings["dm_machineId"].ToString(),
|
||||||
rejectionReport.ReturnTime = DateTime.Now;
|
DrawerNo = cs.DrawerNo,
|
||||||
rejectionReport.ReturnUser = retUser;
|
ColNo = cs.ColNo,
|
||||||
rejectionReport.ReturnReceiveUser = SendMachineRecord.Operator.ToString();
|
DrugId = cs.DrugId,
|
||||||
rejectionReport.DrugId = oi._OrderDetail.DrugId;
|
ManuNo = cs.ManuNo,
|
||||||
rejectionReport.DrugName = oi._OrderDetail.DrugInfo.DrugName;
|
EffDate = !String.IsNullOrEmpty(cs.EffDate) ? DateTime.ParseExact(cs.EffDate, "yyyy-MM-dd", System.Globalization.CultureInfo.CurrentCulture) : null,
|
||||||
rejectionReport.DrugSpec = oi._OrderDetail.DrugInfo.DrugSpec;
|
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 iRejectionReport = SqlSugarHelper.Db.Insertable(rejectionReport).ExecuteCommand();
|
||||||
//保存账册
|
|
||||||
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
|
|
||||||
|
|
||||||
}).ExecuteCommand();
|
#endregion
|
||||||
//修改凌晨生成的日结存与总结存数据
|
|
||||||
AccountBookG2 accountBookG2Day = SqlSugarHelper.Db.Queryable<AccountBookG2>()
|
}
|
||||||
.Where(ab => ab.MachineId.Equals(ConfigurationManager.AppSettings["dm_machineId"].ToString()))
|
//保存账册
|
||||||
.Where(ab => ab.Type == 3)
|
int iInsertResult = SqlSugarHelper.Db.Insertable(new AccountBookG2()
|
||||||
.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()
|
|
||||||
{
|
{
|
||||||
DrugId = oi._OrderDetail.DrugId,
|
DrugId = oi._OrderDetail.DrugId,
|
||||||
Type = 3,
|
Type = 2,
|
||||||
|
Department = oi.DeptName,
|
||||||
|
OrderNo = oi.OrderNo,
|
||||||
ManuNo = cs.ManuNo,
|
ManuNo = cs.ManuNo,
|
||||||
EffDate = cs.EffDate,
|
EffDate = cs.EffDate,
|
||||||
YQuantity = 0,
|
OutQuantity = oi._OrderDetail.Quantity,
|
||||||
ManuStock = oi._OrderDetail.Quantity,
|
|
||||||
TotalStock = oi._OrderDetail.Quantity,
|
|
||||||
UserId1 = HomeWindowViewModel.Operator?.Id,
|
UserId1 = HomeWindowViewModel.Operator?.Id,
|
||||||
UserId2 = HomeWindowViewModel.Reviewer?.Id,
|
UserId2 = HomeWindowViewModel.Reviewer?.Id,
|
||||||
MachineId = ConfigurationManager.AppSettings["dm_machineId"].ToString(),
|
MachineId = ConfigurationManager.AppSettings["dm_machineId"].ToString(),
|
||||||
CreateDate = DateTime.Now.ToString("yyyy-MM-dd"),
|
CreateDate = DateTime.Now.ToString("yyyy-MM-dd"),
|
||||||
InvoiceNo = "日结存"
|
CreateTime = DateTime.Now,
|
||||||
|
InvoiceNo = oi.OrderNo
|
||||||
|
|
||||||
}).ExecuteCommand();
|
}).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();
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
//修改凌晨生成的日结存与总结存数据
|
|
||||||
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,
|
int iDayResult = SqlSugarHelper.Db.Insertable(new AccountBookG2()
|
||||||
YQuantity = 0,
|
{
|
||||||
ManuStock = oi._OrderDetail.Quantity,
|
DrugId = oi._OrderDetail.DrugId,
|
||||||
TotalStock = oi._OrderDetail.Quantity,
|
Type = 3,
|
||||||
UserId1 = HomeWindowViewModel.Operator?.Id,
|
ManuNo = cs.ManuNo,
|
||||||
UserId2 = HomeWindowViewModel.Reviewer?.Id,
|
EffDate = cs.EffDate,
|
||||||
MachineId = ConfigurationManager.AppSettings["dm_machineId"].ToString(),
|
YQuantity = 0,
|
||||||
CreateDate = DateTime.Now.ToString("yyyy-MM-dd"),
|
ManuStock = oi._OrderDetail.Quantity,
|
||||||
InvoiceNo = "总结存"
|
TotalStock = oi._OrderDetail.Quantity,
|
||||||
}).ExecuteCommand();
|
UserId1 = HomeWindowViewModel.Operator?.Id,
|
||||||
if (iTotalResult <= 0)
|
UserId2 = HomeWindowViewModel.Reviewer?.Id,
|
||||||
{
|
MachineId = ConfigurationManager.AppSettings["dm_machineId"].ToString(),
|
||||||
logger.Info($"未写入总结存数据{oi._OrderDetail.DrugId}-{oi._OrderDetail.Quantity}");
|
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))
|
if (!string.IsNullOrEmpty(empChannelStock))
|
||||||
|
@ -660,7 +665,7 @@ namespace DM_Weight.ViewModels
|
||||||
};
|
};
|
||||||
_eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);
|
_eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);
|
||||||
logger.Info($"所选处方对应药品批次效期无库存{empChannelStock}");
|
logger.Info($"所选处方对应药品批次效期无库存{empChannelStock}");
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue