1)日结存中保存dm_machine_record为总库存数,非批次库存数

2)生成日结存 按钮 点击时 先删除 已生成的日结存,再查询是否有操作记录,如果没有则生成一条记录,生成的“凭证号” 字段列显示为“日结存”字样,“借入数量”与“发出数量”为该药品下所有批次数总和,“总结存”为该药品总库存,显示当时登录的“发药人”、“复核人”字段列,其他不显示,如果有出、入库数则生成一条当日总出、入库数及总结存数的数据。

3)生成日结存 按钮 生成的记录为 药品对应的记录,而非批次对应的记录
4)库存盘点中,盘点时不记录盘点库存为0且盘点后库存仍为0的记录(该批次可能不再用了)
This commit is contained in:
maqiao 2024-03-18 17:19:12 +08:00
parent c580e69347
commit b11a8a479c
2 changed files with 113 additions and 81 deletions

View File

@ -237,8 +237,13 @@ namespace DM_Weight.ViewModels
{ {
try try
{ {
string machineId = ConfigurationManager.AppSettings["machineId"] ?? "DM1";
//查询账册中所有记录,与库存中的记录做比校,如果账册中没有,则添加一条 //根据已生成的日结存记录
int deleteNum = SqlSugarHelper.Db.Deleteable<MachineRecord>()
.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<AccountModel> accountList = _machineRecordService.ReportAccountBook(nowDate, null, 0); List<AccountModel> accountList = _machineRecordService.ReportAccountBook(nowDate, null, 0);
//库存中的记录 //库存中的记录
List<ChannelStockCount> channelStockList = _channelStockService.GetAll(); List<ChannelStockCount> channelStockList = _channelStockService.GetAll();
@ -249,9 +254,21 @@ namespace DM_Weight.ViewModels
for (int i = 0; i < channelStockList.Count; i++) 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) if (Count <= 0)
{ {
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<ChannelStock>()
.Where(cs => cs.DrugId.Equals(channelStockList[i].DrugId)).Sum(it => it.Quantity);
//没有直接插入 //没有直接插入
// 保存数据 出/入库记录 // 保存数据 出/入库记录
string InvoiceId = "Account_" + CurrentTimeMillis(); string InvoiceId = "Account_" + CurrentTimeMillis();
@ -261,21 +278,23 @@ namespace DM_Weight.ViewModels
DrawerNo = 0,//channelStockList[i].DrawerNo, DrawerNo = 0,//channelStockList[i].DrawerNo,
ColNo = 0,// channelStockList[i].ColNo,FV ColNo = 0,// channelStockList[i].ColNo,FV
DrugId = channelStockList[i].DrugId, DrugId = channelStockList[i].DrugId,
ManuNo = channelStockList[i].ManuNo, ManuNo = "",//channelStockList[i].ManuNo,
EffDate = !String.IsNullOrEmpty(channelStockList[i].EffDate) ? DateTime.ParseExact(channelStockList[i].EffDate, "yyyy-MM-dd", System.Globalization.CultureInfo.CurrentCulture) : null, EffDate = null,// !String.IsNullOrEmpty(channelStockList[i].EffDate) ? DateTime.ParseExact(channelStockList[i].EffDate, "yyyy-MM-dd", System.Globalization.CultureInfo.CurrentCulture) : null,
Operator = HomeWindowViewModel.Operator?.Id, Operator = HomeWindowViewModel.Operator?.Id,
Reviewer = HomeWindowViewModel.Reviewer?.Id, Reviewer = HomeWindowViewModel.Reviewer?.Id,
OperationTime = DateTime.Now, OperationTime = DateTime.Now,
Quantity = 0, Quantity = 0,
Type = 5, Type = 5,
InvoiceId = string.Empty,//InvoiceId, InvoiceId = "日结存",//InvoiceId,
StockQuantity = channelStockList[i].Quantity, ReturnQuantity1 = inQuantity, //当日入库量总数
ReturnQuantity2 = outQuantity, //当日出库量总数
StockQuantity = channelStockQuantity,
ManunoQuantity = 0, ManunoQuantity = 0,
SupplierDept = ConfigurationManager.AppSettings["supplierDept"].ToString(), SupplierDept = string.Empty,// ConfigurationManager.AppSettings["supplierDept"].ToString(),
ReceiveDept = ConfigurationManager.AppSettings["receiveDept"].ToString() ReceiveDept = string.Empty,//ConfigurationManager.AppSettings["receiveDept"].ToString()
}).ExecuteCommand(); }).ExecuteCommand();
}
} }
} }
else else
@ -284,6 +303,11 @@ namespace DM_Weight.ViewModels
{ {
//账册中没有记录则把库存中的所有数据都要生成一条账册记录 //账册中没有记录则把库存中的所有数据都要生成一条账册记录
// 保存数据 出/入库记录 // 保存数据 出/入库记录
// 获取药品总库存
int channelStockQuantity = SqlSugarHelper.Db.Queryable<ChannelStock>()
.Where(cs => cs.DrugId.Equals(channelStockList[i].DrugId)).Sum(it => it.Quantity);
string InvoiceId = "Account_" + CurrentTimeMillis(); string InvoiceId = "Account_" + CurrentTimeMillis();
SqlSugarHelper.Db.Insertable(new MachineRecord() SqlSugarHelper.Db.Insertable(new MachineRecord()
{ {
@ -291,18 +315,20 @@ namespace DM_Weight.ViewModels
DrawerNo = 0,//channelStockList[i].DrawerNo, DrawerNo = 0,//channelStockList[i].DrawerNo,
ColNo = 0,//channelStockList[i].ColNo, ColNo = 0,//channelStockList[i].ColNo,
DrugId = channelStockList[i].DrugId, DrugId = channelStockList[i].DrugId,
ManuNo = channelStockList[i].ManuNo, ManuNo = "",// channelStockList[i].ManuNo,
EffDate = !String.IsNullOrEmpty(channelStockList[i].EffDate) ? DateTime.ParseExact(channelStockList[i].EffDate, "yyyy-MM-dd", System.Globalization.CultureInfo.CurrentCulture) : null, EffDate = null,// !String.IsNullOrEmpty(channelStockList[i].EffDate) ? DateTime.ParseExact(channelStockList[i].EffDate, "yyyy-MM-dd", System.Globalization.CultureInfo.CurrentCulture) : null,
Operator = HomeWindowViewModel.Operator?.Id, Operator = HomeWindowViewModel.Operator?.Id,
Reviewer = HomeWindowViewModel.Reviewer?.Id, Reviewer = HomeWindowViewModel.Reviewer?.Id,
OperationTime = DateTime.Now, OperationTime = DateTime.Now,
Quantity = 0, Quantity = 0,
Type = 5, Type = 5,
InvoiceId = string.Empty,//InvoiceId, InvoiceId = "日结存",// string.Empty,//InvoiceId,
StockQuantity = channelStockList[i].Quantity, ReturnQuantity1 = inQuantity, //当日入库量总数
ReturnQuantity2 = outQuantity, //当日出库量总数
StockQuantity = channelStockQuantity,
ManunoQuantity = 0, ManunoQuantity = 0,
SupplierDept = ConfigurationManager.AppSettings["supplierDept"].ToString(), SupplierDept = string.Empty,//ConfigurationManager.AppSettings["supplierDept"].ToString(),
ReceiveDept = ConfigurationManager.AppSettings["receiveDept"].ToString() ReceiveDept = string.Empty,//ConfigurationManager.AppSettings["receiveDept"].ToString()
}).ExecuteCommand(); }).ExecuteCommand();
} }
} }

View File

@ -317,16 +317,15 @@ namespace DM_Weight.ViewModels
IGrouping<int, ChannelStock> grouping = enumerator.Current; IGrouping<int, ChannelStock> grouping = enumerator.Current;
//int DrawerNo =Convert.ToInt32(grouping.Key.Substring(0,grouping.Key.IndexOf('-'))); //int DrawerNo =Convert.ToInt32(grouping.Key.Substring(0,grouping.Key.IndexOf('-')));
int DrawerNo = grouping.Key; int DrawerNo = grouping.Key;
List<ChannelStock> channelStocks = grouping.ToList(); List<ChannelStock> Stocks = grouping.ToList();
channelStocks.ForEach(it => it.process = 1); Stocks.ForEach(it => it.process = 1);
_portUtil.SpeakAsync("正在打开" + DrawerNo + "号抽屉"); _portUtil.SpeakAsync("正在打开" + DrawerNo + "号抽屉");
List<ChannelStock> singleChannels = new List<ChannelStock>(); List<ChannelStock> singleChannels = new List<ChannelStock>();
for (int i = 0; i < channelStocks.Count; i++) for (int i = 0; i < Stocks.Count; i++)
{ {
ChannelStock copy = TransExpV2<ChannelStock, ChannelStock>.Trans(channelStocks[i]); ChannelStock copy = TransExpV2<ChannelStock, ChannelStock>.Trans(Stocks[i]);
singleChannels.Add(copy); singleChannels.Add(copy);
} }
singleChannels = singleChannels.GroupBy(it => new singleChannels = singleChannels.GroupBy(it => new
{ {
it.DrawerNo, it.DrawerNo,
@ -334,8 +333,8 @@ namespace DM_Weight.ViewModels
}).Select(it => }).Select(it =>
{ {
var ret = it.First(); var ret = it.First();
ret.Quantity = it.Sum(itx => itx.Quantity); //ret.Quantity = it.Sum(itx => itx.Quantity);
ret.AddQuantity = it.Sum(itx => itx.AddQuantity); //ret.AddQuantity = it.Sum(itx => itx.AddQuantity);
return ret; return ret;
}).ToList().FindAll(it => it.BoardType != 1); }).ToList().FindAll(it => it.BoardType != 1);
@ -361,7 +360,7 @@ namespace DM_Weight.ViewModels
_portUtil.Operate = true; _portUtil.Operate = true;
_portUtil.BoardType = singleChannels.Count > 0 ? singleChannels[0].BoardType : 1; _portUtil.BoardType = singleChannels.Count > 0 ? singleChannels[0].BoardType : 1;
_portUtil.ColNos = singleChannels.Select(it => it.ColNo).ToArray(); _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.DrawerNo = DrawerNo;
_portUtil.Start(); _portUtil.Start();
} }
@ -401,6 +400,9 @@ namespace DM_Weight.ViewModels
.Where(cs => cs.DrawerType == 1) .Where(cs => cs.DrawerType == 1)
.ToList(); .ToList();
//盘点时不记录盘点库存为0且盘点后库存仍为0的记录该批次可能不再用了
if (!it.Quantity.Equals(0) || !it.CheckQuantity.Equals(0))
{
// 保存数据 盘点记录 // 保存数据 盘点记录
SqlSugarHelper.Db.Insertable(new MachineRecord() SqlSugarHelper.Db.Insertable(new MachineRecord()
{ {
@ -421,8 +423,9 @@ namespace DM_Weight.ViewModels
ManunoQuantity = nowChannels.FindAll(it2 => it2.ManuNo == it.ManuNo).Sum(it => it.Quantity) ManunoQuantity = nowChannels.FindAll(it2 => it2.ManuNo == it.ManuNo).Sum(it => it.Quantity)
}).ExecuteCommand(); }).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()); //Task.Factory.StartNew(()=> SaveCheckRecord());
@ -454,7 +457,9 @@ namespace DM_Weight.ViewModels
for (int j = 0; j < insertList.Count; j++) for (int j = 0; j < insertList.Count; j++)
{ {
//盘点时不记录盘点库存为0且盘点后库存仍为0的记录该批次可能不再用了
if (!insertList[j].quantity.Equals(0))
{
CheckRecordStock cStock = insertList[j]; CheckRecordStock cStock = insertList[j];
// 保存数据 盘点后药品总库存及批次库存数 // 保存数据 盘点后药品总库存及批次库存数
SqlSugarHelper.Db.Insertable(new CheckRecordStock() SqlSugarHelper.Db.Insertable(new CheckRecordStock()
@ -478,6 +483,7 @@ namespace DM_Weight.ViewModels
}).ExecuteCommand(); }).ExecuteCommand();
} }
} }
}
logger.Info("已完成-保存数据 盘点后药品总库存及批次库存数"); logger.Info("已完成-保存数据 盘点后药品总库存及批次库存数");
return true; return true;
}); });
@ -612,7 +618,7 @@ namespace DM_Weight.ViewModels
}); });
} }
public bool KeepAlive => true; public bool KeepAlive => false;
private void DoDialogResult(IDialogResult dialogResult) private void DoDialogResult(IDialogResult dialogResult)
{ {