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
{
//查询账册中所有记录,与库存中的记录做比校,如果账册中没有,则添加一条
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<ChannelStockCount> channelStockList = _channelStockService.GetAll();
@ -249,33 +254,47 @@ namespace DM_Weight.ViewModels
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)
{
//没有直接插入
// 保存数据 出/入库记录
string InvoiceId = "Account_" + CurrentTimeMillis();
SqlSugarHelper.Db.Insertable(new MachineRecord()
{
MachineId = channelStockList[i].MachineId,
DrawerNo = 0,//channelStockList[i].DrawerNo,
ColNo = 0,// channelStockList[i].ColNo,FV
DrugId = channelStockList[i].DrugId,
ManuNo = channelStockList[i].ManuNo,
EffDate = !String.IsNullOrEmpty(channelStockList[i].EffDate) ? DateTime.ParseExact(channelStockList[i].EffDate, "yyyy-MM-dd", System.Globalization.CultureInfo.CurrentCulture) : null,
Operator = HomeWindowViewModel.Operator?.Id,
Reviewer = HomeWindowViewModel.Reviewer?.Id,
OperationTime = DateTime.Now,
Quantity = 0,
Type = 5,
InvoiceId = string.Empty,//InvoiceId,
StockQuantity = channelStockList[i].Quantity,
ManunoQuantity = 0,
SupplierDept = ConfigurationManager.AppSettings["supplierDept"].ToString(),
ReceiveDept = ConfigurationManager.AppSettings["receiveDept"].ToString()
}).ExecuteCommand();
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();
SqlSugarHelper.Db.Insertable(new MachineRecord()
{
MachineId = channelStockList[i].MachineId,
DrawerNo = 0,//channelStockList[i].DrawerNo,
ColNo = 0,// channelStockList[i].ColNo,FV
DrugId = channelStockList[i].DrugId,
ManuNo = "",//channelStockList[i].ManuNo,
EffDate = null,// !String.IsNullOrEmpty(channelStockList[i].EffDate) ? DateTime.ParseExact(channelStockList[i].EffDate, "yyyy-MM-dd", System.Globalization.CultureInfo.CurrentCulture) : null,
Operator = HomeWindowViewModel.Operator?.Id,
Reviewer = HomeWindowViewModel.Reviewer?.Id,
OperationTime = DateTime.Now,
Quantity = 0,
Type = 5,
InvoiceId = "日结存",//InvoiceId,
ReturnQuantity1 = inQuantity, //当日入库量总数
ReturnQuantity2 = outQuantity, //当日出库量总数
StockQuantity = channelStockQuantity,
ManunoQuantity = 0,
SupplierDept = string.Empty,// ConfigurationManager.AppSettings["supplierDept"].ToString(),
ReceiveDept = string.Empty,//ConfigurationManager.AppSettings["receiveDept"].ToString()
}).ExecuteCommand();
}
}
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();
SqlSugarHelper.Db.Insertable(new MachineRecord()
{
@ -291,18 +315,20 @@ namespace DM_Weight.ViewModels
DrawerNo = 0,//channelStockList[i].DrawerNo,
ColNo = 0,//channelStockList[i].ColNo,
DrugId = channelStockList[i].DrugId,
ManuNo = channelStockList[i].ManuNo,
EffDate = !String.IsNullOrEmpty(channelStockList[i].EffDate) ? DateTime.ParseExact(channelStockList[i].EffDate, "yyyy-MM-dd", System.Globalization.CultureInfo.CurrentCulture) : null,
ManuNo = "",// channelStockList[i].ManuNo,
EffDate = null,// !String.IsNullOrEmpty(channelStockList[i].EffDate) ? DateTime.ParseExact(channelStockList[i].EffDate, "yyyy-MM-dd", System.Globalization.CultureInfo.CurrentCulture) : null,
Operator = HomeWindowViewModel.Operator?.Id,
Reviewer = HomeWindowViewModel.Reviewer?.Id,
OperationTime = DateTime.Now,
Quantity = 0,
Type = 5,
InvoiceId = string.Empty,//InvoiceId,
StockQuantity = channelStockList[i].Quantity,
InvoiceId = "日结存",// string.Empty,//InvoiceId,
ReturnQuantity1 = inQuantity, //当日入库量总数
ReturnQuantity2 = outQuantity, //当日出库量总数
StockQuantity = channelStockQuantity,
ManunoQuantity = 0,
SupplierDept = ConfigurationManager.AppSettings["supplierDept"].ToString(),
ReceiveDept = ConfigurationManager.AppSettings["receiveDept"].ToString()
SupplierDept = string.Empty,//ConfigurationManager.AppSettings["supplierDept"].ToString(),
ReceiveDept = string.Empty,//ConfigurationManager.AppSettings["receiveDept"].ToString()
}).ExecuteCommand();
}
}

View File

@ -317,16 +317,15 @@ namespace DM_Weight.ViewModels
IGrouping<int, ChannelStock> grouping = enumerator.Current;
//int DrawerNo =Convert.ToInt32(grouping.Key.Substring(0,grouping.Key.IndexOf('-')));
int DrawerNo = grouping.Key;
List<ChannelStock> channelStocks = grouping.ToList();
channelStocks.ForEach(it => it.process = 1);
List<ChannelStock> Stocks = grouping.ToList();
Stocks.ForEach(it => it.process = 1);
_portUtil.SpeakAsync("正在打开" + DrawerNo + "号抽屉");
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 = singleChannels.GroupBy(it => new
{
it.DrawerNo,
@ -334,8 +333,8 @@ namespace DM_Weight.ViewModels
}).Select(it =>
{
var ret = it.First();
ret.Quantity = it.Sum(itx => itx.Quantity);
ret.AddQuantity = it.Sum(itx => itx.AddQuantity);
//ret.Quantity = it.Sum(itx => itx.Quantity);
//ret.AddQuantity = it.Sum(itx => itx.AddQuantity);
return ret;
}).ToList().FindAll(it => it.BoardType != 1);
@ -361,7 +360,7 @@ namespace DM_Weight.ViewModels
_portUtil.Operate = true;
_portUtil.BoardType = singleChannels.Count > 0 ? singleChannels[0].BoardType : 1;
_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.Start();
}
@ -401,28 +400,32 @@ namespace DM_Weight.ViewModels
.Where(cs => cs.DrawerType == 1)
.ToList();
// 保存数据 盘点记录
SqlSugarHelper.Db.Insertable(new MachineRecord()
//盘点时不记录盘点库存为0且盘点后库存仍为0的记录该批次可能不再用了
if (!it.Quantity.Equals(0) || !it.CheckQuantity.Equals(0))
{
MachineId = it.MachineId,
DrawerNo = it.DrawerNo,
ColNo = it.ColNo,
DrugId = it.DrugId,
ManuNo = it.ManuNo,
EffDate = !String.IsNullOrEmpty(it.EffDate) ? DateTime.ParseExact(it.EffDate, "yyyy-MM-dd", System.Globalization.CultureInfo.CurrentCulture) : null,
Operator = HomeWindowViewModel.Operator?.Id,
Reviewer = HomeWindowViewModel.Reviewer?.Id,
OperationTime = DateTime.Now,
Quantity = it.CheckQuantity - it.Quantity,
Type = 4,
InvoiceId = InvoiceId,
StockQuantity = nowChannels.Sum(it => it.Quantity),
CheckQuantity = it.CheckQuantity,
ManunoQuantity = nowChannels.FindAll(it2 => it2.ManuNo == it.ManuNo).Sum(it => it.Quantity)
}).ExecuteCommand();
// 保存数据 盘点记录
SqlSugarHelper.Db.Insertable(new MachineRecord()
{
MachineId = it.MachineId,
DrawerNo = it.DrawerNo,
ColNo = it.ColNo,
DrugId = it.DrugId,
ManuNo = it.ManuNo,
EffDate = !String.IsNullOrEmpty(it.EffDate) ? DateTime.ParseExact(it.EffDate, "yyyy-MM-dd", System.Globalization.CultureInfo.CurrentCulture) : null,
Operator = HomeWindowViewModel.Operator?.Id,
Reviewer = HomeWindowViewModel.Reviewer?.Id,
OperationTime = DateTime.Now,
Quantity = it.CheckQuantity - it.Quantity,
Type = 4,
InvoiceId = InvoiceId,
StockQuantity = nowChannels.Sum(it => it.Quantity),
CheckQuantity = it.CheckQuantity,
ManunoQuantity = nowChannels.FindAll(it2 => it2.ManuNo == it.ManuNo).Sum(it => it.Quantity)
}).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());
@ -454,28 +457,31 @@ namespace DM_Weight.ViewModels
for (int j = 0; j < insertList.Count; j++)
{
CheckRecordStock cStock = insertList[j];
// 保存数据 盘点后药品总库存及批次库存数
SqlSugarHelper.Db.Insertable(new CheckRecordStock()
//盘点时不记录盘点库存为0且盘点后库存仍为0的记录该批次可能不再用了
if (!insertList[j].quantity.Equals(0))
{
rowNo = cStock.rowNo,
colNo = cStock.colNo,
ManuQuantity = checkRecordStockList.Where(it => it.drugId == cStock.drugId && it.manuNo == cStock.manuNo).Sum(it => it.quantity),
manuNo = cStock.manuNo,
effDate = cStock.effDate,
drugName = cStock.drugName,
manufactory = cStock.manufactory,
drugSpec = cStock.drugSpec,
packUnit = cStock.packUnit,
maxStock = cStock.maxStock,
drugId = cStock.drugId,
MachineId = cStock.MachineId,
quantity = checkRecordStockList.Where(it => it.drugId == cStock.drugId).Sum(it => it.quantity),
optdate = DateTime.Now.ToString(),
operatorUser = HomeWindowViewModel.Operator?.Id.ToString(),
reviewerUser = HomeWindowViewModel.Reviewer?.Id.ToString()
}).ExecuteCommand();
CheckRecordStock cStock = insertList[j];
// 保存数据 盘点后药品总库存及批次库存数
SqlSugarHelper.Db.Insertable(new CheckRecordStock()
{
rowNo = cStock.rowNo,
colNo = cStock.colNo,
ManuQuantity = checkRecordStockList.Where(it => it.drugId == cStock.drugId && it.manuNo == cStock.manuNo).Sum(it => it.quantity),
manuNo = cStock.manuNo,
effDate = cStock.effDate,
drugName = cStock.drugName,
manufactory = cStock.manufactory,
drugSpec = cStock.drugSpec,
packUnit = cStock.packUnit,
maxStock = cStock.maxStock,
drugId = cStock.drugId,
MachineId = cStock.MachineId,
quantity = checkRecordStockList.Where(it => it.drugId == cStock.drugId).Sum(it => it.quantity),
optdate = DateTime.Now.ToString(),
operatorUser = HomeWindowViewModel.Operator?.Id.ToString(),
reviewerUser = HomeWindowViewModel.Reviewer?.Id.ToString()
}).ExecuteCommand();
}
}
}
logger.Info("已完成-保存数据 盘点后药品总库存及批次库存数");
@ -612,7 +618,7 @@ namespace DM_Weight.ViewModels
});
}
public bool KeepAlive => true;
public bool KeepAlive => false;
private void DoDialogResult(IDialogResult dialogResult)
{