更新核对时出库账册的批次库存数
This commit is contained in:
parent
500974a947
commit
d8d08559f3
|
|
@ -511,11 +511,11 @@ namespace DM_Weight.ViewModels
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
cs.Quantity = cs.Quantity - oi._OrderDetail.Quantity;
|
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}");
|
logger.Info($"更新手术间{cs.DrawerNo}药品{cs.DrugId}批次{cs.ManuNo}库存为{cs.Quantity},需补药数量为{cs.NeedNum}");
|
||||||
// 更新数据 库存信息
|
// 更新数据 库存信息
|
||||||
SqlSugarHelper.Db.Updateable(cs).UpdateColumns(it => new { it.Quantity, it.NeedNum }).ExecuteCommand();
|
SqlSugarHelper.Db.Updateable(cs).UpdateColumns(it => new { it.Quantity, it.NeedNum }).ExecuteCommand();
|
||||||
|
|
||||||
// 获取更新完库存后的药品库存
|
// 获取更新完库存后的药品库存
|
||||||
List<ChannelStock> nowChannels = SqlSugarHelper.Db.Queryable<ChannelStock>()
|
List<ChannelStock> nowChannels = SqlSugarHelper.Db.Queryable<ChannelStock>()
|
||||||
.Where(it => it.MachineId.Equals(ConfigurationManager.AppSettings["machineId"]) || it.MachineId.Equals(ConfigurationManager.AppSettings["dm_machineId"]))
|
.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.ManuNo.Equals(cs.ManuNo))
|
||||||
.Where(it => it.DrawerType == 1)
|
.Where(it => it.DrawerType == 1)
|
||||||
.ToList();
|
.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()
|
#region 记录 注射剂使用与交接记录报表
|
||||||
{
|
//查询发药时间
|
||||||
MachineId = ConfigurationManager.AppSettings["dm_machineId"].ToString(),
|
//MachineRecord SendMachineRecord = SqlSugarHelper.Db.Queryable<MachineRecord>().Where(mr => mr.DrawerNo == cs.DrawerNo && mr.Type == 2)
|
||||||
DrawerNo = cs.DrawerNo,
|
//.OrderByDescending(mr => mr.OperationTime)
|
||||||
ColNo = cs.ColNo,
|
//.First();
|
||||||
DrugId = cs.DrugId,
|
//string retUser = SqlSugarHelper.Db.Queryable<ChannelList>().Where(cl => cl.MachineId == (ConfigurationManager.AppSettings["machineId"] ?? "DM5") && cl.DrawerNo == cs.DrawerNo)
|
||||||
ManuNo = cs.ManuNo,
|
//.Select(cl => cl.BelongUser).First();
|
||||||
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 记录 注射剂使用与交接记录报表
|
RejectionReport rejectionReport = SqlSugarHelper.Db.Queryable<RejectionReport>().Where(rp => rp.DrugId == cs.DrugId && rp.DrawerNo == cs.DrawerNo).OrderByDescending(rp => rp.SendDate).First();
|
||||||
//查询发药时间
|
if (rejectionReport != null)
|
||||||
//MachineRecord SendMachineRecord = SqlSugarHelper.Db.Queryable<MachineRecord>().Where(mr => mr.DrawerNo == cs.DrawerNo && mr.Type == 2)
|
{
|
||||||
//.OrderByDescending(mr => mr.OperationTime)
|
//发药信息
|
||||||
//.First();
|
//RejectionReport rejectionReport = new RejectionReport();
|
||||||
//string retUser = SqlSugarHelper.Db.Queryable<ChannelList>().Where(cl => cl.MachineId == (ConfigurationManager.AppSettings["machineId"] ?? "DM5") && cl.DrawerNo == cs.DrawerNo)
|
//rejectionReport.SendDate = SendMachineRecord.OperationTime;
|
||||||
//.Select(cl => cl.BelongUser).First();
|
//rejectionReport.SendUser = SendMachineRecord.Operator.ToString();
|
||||||
|
//rejectionReport.ReceiveUser = retUser;
|
||||||
|
rejectionReport.RealNum = cs.BaseQuantity;
|
||||||
|
|
||||||
RejectionReport rejectionReport = SqlSugarHelper.Db.Queryable<RejectionReport>().Where(rp => rp.DrugId == cs.DrugId && rp.DrawerNo == cs.DrawerNo).OrderByDescending(rp => rp.SendDate).First();
|
//还药信息
|
||||||
if (rejectionReport != null)
|
rejectionReport.InfactNum = cs.BaseQuantity - oi._OrderDetail.Quantity;
|
||||||
{
|
rejectionReport.EmptyNum = oi._OrderDetail.Quantity;
|
||||||
//发药信息
|
rejectionReport.ReturnTime = DateTime.Now.ToString();
|
||||||
//RejectionReport rejectionReport = new RejectionReport();
|
rejectionReport.ReturnUser = rejectionReport.SendUser;
|
||||||
//rejectionReport.SendDate = SendMachineRecord.OperationTime;
|
rejectionReport.ReturnReceiveUser = rejectionReport.ReceiveUser;// SendMachineRecord.Operator.ToString();
|
||||||
//rejectionReport.SendUser = SendMachineRecord.Operator.ToString();
|
rejectionReport.DrugId = oi._OrderDetail.DrugId;
|
||||||
//rejectionReport.ReceiveUser = retUser;
|
rejectionReport.DrugName = oi._OrderDetail.DrugInfo.DrugName;
|
||||||
rejectionReport.RealNum = cs.BaseQuantity;
|
rejectionReport.DrugSpec = oi._OrderDetail.DrugInfo.DrugSpec;
|
||||||
|
|
||||||
//还药信息
|
rejectionReport.OperationTime = DateTime.Now;
|
||||||
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;
|
int iRejectionReport = SqlSugarHelper.Db.Updateable(rejectionReport).ExecuteCommand();
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
int iRejectionReport = SqlSugarHelper.Db.Updateable(rejectionReport).ExecuteCommand();
|
//}
|
||||||
}
|
//修改凌晨生成的日结存与总结存数据
|
||||||
#endregion
|
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)
|
||||||
AccountBookG2 accountBookEmpty = SqlSugarHelper.Db.Queryable<AccountBookG2>()
|
.Where(ab => ab.ManuNo == cs.ManuNo)
|
||||||
.Where(ab => ab.MachineId.Equals(ConfigurationManager.AppSettings["dm_machineId"].ToString()))
|
.Where(ab => ab.CreateDate == DateTime.Now.ToString("yyyy-MM-dd")).First();
|
||||||
.Where(ab => ab.Type == 1 || ab.Type == 2)
|
int manuStock = 0;
|
||||||
.Where(ab => ab.DrugId == oi._OrderDetail.DrugId)
|
if (accountBookG2Day != null)
|
||||||
.Where(ab => ab.ManuNo == cs.ManuNo).OrderByDescending(ab => ab.Id).First();
|
{
|
||||||
//保存账册
|
accountBookG2Day.ManuStock = accountBookG2Day.ManuStock - oi._OrderDetail.Quantity;
|
||||||
int iInsertResult = SqlSugarHelper.Db.Insertable(new AccountBookG2()
|
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,
|
DrugId = oi._OrderDetail.DrugId,
|
||||||
Type = 2,
|
Type = 3,
|
||||||
Department = oi.DeptName,
|
|
||||||
OrderNo = oi.OrderNo,
|
|
||||||
ManuNo = cs.ManuNo,
|
ManuNo = cs.ManuNo,
|
||||||
EffDate = cs.EffDate,
|
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,
|
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"),
|
||||||
CreateTime = DateTime.Now,
|
CreateTime = DateTime.Now,
|
||||||
InvoiceNo = oi.OrderNo,
|
InvoiceNo = "日结存",
|
||||||
ManuStock = nowChannels.Sum(it => it.Quantity),
|
OutQuantity = oi._OrderDetail.Quantity,
|
||||||
TotalStock = (accountBookEmpty != null ? (accountBookEmpty.TotalStock > 0 ? accountBookEmpty.TotalStock : 0) : 0) + oi._OrderDetail.Quantity,
|
|
||||||
ShoushuJian= drawerNo.ToString()
|
|
||||||
}).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)
|
|
||||||
{
|
{
|
||||||
accountBookG2Day.ManuStock = accountBookG2Day.ManuStock - oi._OrderDetail.Quantity;
|
logger.Info($"未写入日结存数据{oi._OrderDetail.DrugId}-{cs.ManuNo}-{cs.EffDate}-{cs.Quantity}");
|
||||||
accountBookG2Day.OutQuantity= accountBookG2Day.OutQuantity + oi._OrderDetail.Quantity;
|
|
||||||
SqlSugarHelper.Db.Updateable(accountBookG2Day).ExecuteCommand();
|
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
|
//查询上一条账册中的空瓶数
|
||||||
|
AccountBookG2 accountBookEmpty = SqlSugarHelper.Db.Queryable<AccountBookG2>()
|
||||||
|
.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<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,
|
||||||
int iDayResult = SqlSugarHelper.Db.Insertable(new AccountBookG2()
|
Type = 4,
|
||||||
{
|
YQuantity = 0,
|
||||||
DrugId = oi._OrderDetail.DrugId,
|
ManuStock = oi._OrderDetail.Quantity,
|
||||||
Type = 3,
|
TotalStock = oi._OrderDetail.Quantity,
|
||||||
ManuNo = cs.ManuNo,
|
UserId1 = HomeWindowViewModel.Operator?.Id,
|
||||||
EffDate = cs.EffDate,
|
UserId2 = HomeWindowViewModel.Reviewer?.Id,
|
||||||
YQuantity = 0,
|
MachineId = ConfigurationManager.AppSettings["dm_machineId"].ToString(),
|
||||||
ManuStock =nowChannels.Sum(it => it.Quantity), //oi._OrderDetail.Quantity,
|
CreateDate = DateTime.Now.ToString("yyyy-MM-dd"),
|
||||||
TotalStock = oi._OrderDetail.Quantity,
|
CreateTime = DateTime.Now,
|
||||||
UserId1 = HomeWindowViewModel.Operator?.Id,
|
InvoiceNo = "总结存"
|
||||||
UserId2 = HomeWindowViewModel.Reviewer?.Id,
|
}).ExecuteCommand();
|
||||||
MachineId = ConfigurationManager.AppSettings["dm_machineId"].ToString(),
|
if (iTotalResult <= 0)
|
||||||
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<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;
|
logger.Info($"未写入总结存数据{oi._OrderDetail.DrugId}-{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"),
|
|
||||||
CreateTime = DateTime.Now,
|
|
||||||
InvoiceNo = "总结存"
|
|
||||||
}).ExecuteCommand();
|
|
||||||
if (iTotalResult <= 0)
|
|
||||||
{
|
|
||||||
logger.Info($"未写入总结存数据{oi._OrderDetail.DrugId}-{oi._OrderDetail.Quantity}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!string.IsNullOrEmpty(empChannelStock))
|
if (!string.IsNullOrEmpty(empChannelStock))
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue