抽屉取药、加药;自选取药、加药修改报表
This commit is contained in:
		
							parent
							
								
									013e282189
								
							
						
					
					
						commit
						220272e9ff
					
				| 
						 | 
					@ -239,24 +239,6 @@ namespace DM_Weight.ViewModels
 | 
				
			||||||
                                }).ExecuteCommand();
 | 
					                                }).ExecuteCommand();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                                //保存账册
 | 
					 | 
				
			||||||
                                SqlSugarHelper.Db.Insertable(new AccountBookG2()
 | 
					 | 
				
			||||||
                                {
 | 
					 | 
				
			||||||
                                    DrugId = it.DrugId,
 | 
					 | 
				
			||||||
                                    Type = 1,
 | 
					 | 
				
			||||||
                                    Department = ConfigurationManager.AppSettings["department"].ToString(),
 | 
					 | 
				
			||||||
                                    InvoiceNo = InvoiceId,
 | 
					 | 
				
			||||||
                                    ManuNo = it.ManuNo,
 | 
					 | 
				
			||||||
                                    EffDate = it.EffDate,
 | 
					 | 
				
			||||||
                                    AddQuantity = it.AddQuantity,
 | 
					 | 
				
			||||||
                                    UserId1 = HomeWindowViewModel.Operator?.Id,
 | 
					 | 
				
			||||||
                                    UserId2 = HomeWindowViewModel.Reviewer?.Id,
 | 
					 | 
				
			||||||
                                    MachineId = ConfigurationManager.AppSettings["machineId"].ToString(),
 | 
					 | 
				
			||||||
                                    CreateDate = DateTime.Now.ToString("yyyy-MM-dd"),
 | 
					 | 
				
			||||||
                                    CreateTime = DateTime.Now,
 | 
					 | 
				
			||||||
                                    TotalStock = nowChannels.Sum(itx => itx.Quantity),
 | 
					 | 
				
			||||||
                                    ManuStock = nowChannels.Where(itx => itx.ManuNo == it.ManuNo && itx.EffDate == it.EffDate).Sum(itx => itx.Quantity),
 | 
					 | 
				
			||||||
                                }).ExecuteCommand();
 | 
					 | 
				
			||||||
                                //修改凌晨生成的日结存数据
 | 
					                                //修改凌晨生成的日结存数据
 | 
				
			||||||
                                AccountBookG2 accountBookG2Day = SqlSugarHelper.Db.Queryable<AccountBookG2>()
 | 
					                                AccountBookG2 accountBookG2Day = SqlSugarHelper.Db.Queryable<AccountBookG2>()
 | 
				
			||||||
                                .Where(ab => ab.MachineId.Equals(it.MachineId))
 | 
					                                .Where(ab => ab.MachineId.Equals(it.MachineId))
 | 
				
			||||||
| 
						 | 
					@ -264,11 +246,13 @@ namespace DM_Weight.ViewModels
 | 
				
			||||||
                                .Where(ab => ab.DrugId == it.DrugId)
 | 
					                                .Where(ab => ab.DrugId == it.DrugId)
 | 
				
			||||||
                                .Where(ab => ab.ManuNo == it.ManuNo)
 | 
					                                .Where(ab => ab.ManuNo == it.ManuNo)
 | 
				
			||||||
                                .Where(ab => ab.CreateDate == DateTime.Now.ToString("yyyy-MM-dd")).First();
 | 
					                                .Where(ab => ab.CreateDate == DateTime.Now.ToString("yyyy-MM-dd")).First();
 | 
				
			||||||
 | 
					                                int manuStock = 0;
 | 
				
			||||||
                                if (accountBookG2Day != null)
 | 
					                                if (accountBookG2Day != null)
 | 
				
			||||||
                                {
 | 
					                                {
 | 
				
			||||||
                                    accountBookG2Day.ManuStock = accountBookG2Day.ManuStock + it.AddQuantity;
 | 
					                                    accountBookG2Day.ManuStock = accountBookG2Day.ManuStock + it.AddQuantity;
 | 
				
			||||||
                                    accountBookG2Day.AddQuantity = accountBookG2Day.AddQuantity + it.AddQuantity;
 | 
					                                    accountBookG2Day.AddQuantity = accountBookG2Day.AddQuantity + it.AddQuantity;
 | 
				
			||||||
                                    SqlSugarHelper.Db.Updateable(accountBookG2Day).ExecuteCommand();
 | 
					                                    SqlSugarHelper.Db.Updateable(accountBookG2Day).ExecuteCommand();
 | 
				
			||||||
 | 
					                                    manuStock = accountBookG2Day.ManuStock;
 | 
				
			||||||
                                }
 | 
					                                }
 | 
				
			||||||
                                else
 | 
					                                else
 | 
				
			||||||
                                {
 | 
					                                {
 | 
				
			||||||
| 
						 | 
					@ -295,6 +279,30 @@ namespace DM_Weight.ViewModels
 | 
				
			||||||
                                        logger.Info($"未写入日结存数据{it.DrugId}-{it.ManuNo}-{it.EffDate}-{it.AddQuantity}");
 | 
					                                        logger.Info($"未写入日结存数据{it.DrugId}-{it.ManuNo}-{it.EffDate}-{it.AddQuantity}");
 | 
				
			||||||
                                    }
 | 
					                                    }
 | 
				
			||||||
                                }
 | 
					                                }
 | 
				
			||||||
 | 
					                                //查询上一条账册中的空瓶数
 | 
				
			||||||
 | 
					                                AccountBookG2 accountBookEmpty = SqlSugarHelper.Db.Queryable<AccountBookG2>()
 | 
				
			||||||
 | 
					                                .Where(ab => ab.MachineId.Equals(ConfigurationManager.AppSettings["machineId"].ToString()))
 | 
				
			||||||
 | 
					                                .Where(ab => ab.Type == 1 || ab.Type == 2)
 | 
				
			||||||
 | 
					                                .Where(ab => ab.DrugId == it.DrugId)
 | 
				
			||||||
 | 
					                                .Where(ab => ab.ManuNo == it.ManuNo).OrderByDescending(ab => ab.Id).First();
 | 
				
			||||||
 | 
					                                //保存账册
 | 
				
			||||||
 | 
					                                SqlSugarHelper.Db.Insertable(new AccountBookG2()
 | 
				
			||||||
 | 
					                                {
 | 
				
			||||||
 | 
					                                    DrugId = it.DrugId,
 | 
				
			||||||
 | 
					                                    Type = 1,
 | 
				
			||||||
 | 
					                                    Department = ConfigurationManager.AppSettings["department"].ToString(),
 | 
				
			||||||
 | 
					                                    InvoiceNo = InvoiceId,
 | 
				
			||||||
 | 
					                                    ManuNo = it.ManuNo,
 | 
				
			||||||
 | 
					                                    EffDate = it.EffDate,
 | 
				
			||||||
 | 
					                                    AddQuantity = it.AddQuantity,
 | 
				
			||||||
 | 
					                                    UserId1 = HomeWindowViewModel.Operator?.Id,
 | 
				
			||||||
 | 
					                                    UserId2 = HomeWindowViewModel.Reviewer?.Id,
 | 
				
			||||||
 | 
					                                    MachineId = ConfigurationManager.AppSettings["machineId"].ToString(),
 | 
				
			||||||
 | 
					                                    CreateDate = DateTime.Now.ToString("yyyy-MM-dd"),
 | 
				
			||||||
 | 
					                                    CreateTime = DateTime.Now,
 | 
				
			||||||
 | 
					                                    ManuStock = manuStock > 0 ? manuStock : nowChannels.Sum(it => it.Quantity),
 | 
				
			||||||
 | 
					                                    TotalStock = (accountBookEmpty != null ? (accountBookEmpty.TotalStock > 0 && accountBookEmpty.TotalStock > it.AddQuantity ? accountBookEmpty.TotalStock - it.AddQuantity : 0) : 0)  //负数直接记0
 | 
				
			||||||
 | 
					                                }).ExecuteCommand();
 | 
				
			||||||
                                //修改凌晨生成的总结存数据
 | 
					                                //修改凌晨生成的总结存数据
 | 
				
			||||||
                                AccountBookG2 accountBookG2Total = SqlSugarHelper.Db.Queryable<AccountBookG2>()
 | 
					                                AccountBookG2 accountBookG2Total = SqlSugarHelper.Db.Queryable<AccountBookG2>()
 | 
				
			||||||
                                .Where(ab => ab.MachineId.Equals(it.MachineId))
 | 
					                                .Where(ab => ab.MachineId.Equals(it.MachineId))
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -237,25 +237,6 @@ namespace DM_Weight.ViewModels
 | 
				
			||||||
                                }).ExecuteCommand();
 | 
					                                }).ExecuteCommand();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                                //保存账册
 | 
					 | 
				
			||||||
                                SqlSugarHelper.Db.Insertable(new AccountBookG2()
 | 
					 | 
				
			||||||
                                {
 | 
					 | 
				
			||||||
                                    DrugId = it.DrugId,
 | 
					 | 
				
			||||||
                                    Type = 2,
 | 
					 | 
				
			||||||
                                    Department = ConfigurationManager.AppSettings["department"].ToString(),
 | 
					 | 
				
			||||||
                                    InvoiceNo = InvoiceId,
 | 
					 | 
				
			||||||
                                    ManuNo = it.ManuNo,
 | 
					 | 
				
			||||||
                                    EffDate = it.EffDate,
 | 
					 | 
				
			||||||
                                    OutQuantity = it.TakeQuantity,
 | 
					 | 
				
			||||||
                                    UserId1 = HomeWindowViewModel.Operator?.Id,
 | 
					 | 
				
			||||||
                                    UserId2 = HomeWindowViewModel.Reviewer?.Id,
 | 
					 | 
				
			||||||
                                    MachineId = ConfigurationManager.AppSettings["machineId"].ToString(),
 | 
					 | 
				
			||||||
                                    CreateDate = DateTime.Now.ToString("yyyy-MM-dd"),
 | 
					 | 
				
			||||||
                                    CreateTime = DateTime.Now,
 | 
					 | 
				
			||||||
                                    TotalStock = nowChannels.Sum(itx => itx.Quantity),
 | 
					 | 
				
			||||||
                                    ManuStock = nowChannels.Where(itx => itx.ManuNo == it.ManuNo && itx.EffDate == it.EffDate).Sum(itx => itx.Quantity)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                                }).ExecuteCommand();
 | 
					 | 
				
			||||||
                                //修改凌晨生成的日结存数据
 | 
					                                //修改凌晨生成的日结存数据
 | 
				
			||||||
                                AccountBookG2 accountBookG2Day = SqlSugarHelper.Db.Queryable<AccountBookG2>()
 | 
					                                AccountBookG2 accountBookG2Day = SqlSugarHelper.Db.Queryable<AccountBookG2>()
 | 
				
			||||||
                                .Where(ab => ab.MachineId.Equals(it.MachineId))
 | 
					                                .Where(ab => ab.MachineId.Equals(it.MachineId))
 | 
				
			||||||
| 
						 | 
					@ -263,11 +244,13 @@ namespace DM_Weight.ViewModels
 | 
				
			||||||
                                .Where(ab => ab.DrugId == it.DrugId)
 | 
					                                .Where(ab => ab.DrugId == it.DrugId)
 | 
				
			||||||
                                .Where(ab => ab.ManuNo == it.ManuNo)
 | 
					                                .Where(ab => ab.ManuNo == it.ManuNo)
 | 
				
			||||||
                                .Where(ab => ab.CreateDate == DateTime.Now.ToString("yyyy-MM-dd")).First();
 | 
					                                .Where(ab => ab.CreateDate == DateTime.Now.ToString("yyyy-MM-dd")).First();
 | 
				
			||||||
 | 
					                                int manuStock = 0;
 | 
				
			||||||
                                if (accountBookG2Day != null)
 | 
					                                if (accountBookG2Day != null)
 | 
				
			||||||
                                {
 | 
					                                {
 | 
				
			||||||
                                    accountBookG2Day.ManuStock = accountBookG2Day.ManuStock - it.TakeQuantity;
 | 
					                                    accountBookG2Day.ManuStock = accountBookG2Day.ManuStock - it.TakeQuantity;
 | 
				
			||||||
                                    accountBookG2Day.OutQuantity = accountBookG2Day.OutQuantity + accountBookG2Day.OutQuantity;
 | 
					                                    accountBookG2Day.OutQuantity = accountBookG2Day.OutQuantity + accountBookG2Day.OutQuantity;
 | 
				
			||||||
                                    SqlSugarHelper.Db.Updateable(accountBookG2Day).ExecuteCommand();
 | 
					                                    SqlSugarHelper.Db.Updateable(accountBookG2Day).ExecuteCommand();
 | 
				
			||||||
 | 
					                                    manuStock = accountBookG2Day.ManuStock;
 | 
				
			||||||
                                }
 | 
					                                }
 | 
				
			||||||
                                else
 | 
					                                else
 | 
				
			||||||
                                {
 | 
					                                {
 | 
				
			||||||
| 
						 | 
					@ -294,6 +277,31 @@ namespace DM_Weight.ViewModels
 | 
				
			||||||
                                        logger.Info($"未写入日结存数据{it.DrugId}-{it.ManuNo}-{it.EffDate}-{it.AddQuantity}");
 | 
					                                        logger.Info($"未写入日结存数据{it.DrugId}-{it.ManuNo}-{it.EffDate}-{it.AddQuantity}");
 | 
				
			||||||
                                    }
 | 
					                                    }
 | 
				
			||||||
                                }
 | 
					                                }
 | 
				
			||||||
 | 
					                                //查询上一条账册中的空瓶数
 | 
				
			||||||
 | 
					                                AccountBookG2 accountBookEmpty = SqlSugarHelper.Db.Queryable<AccountBookG2>()
 | 
				
			||||||
 | 
					                                .Where(ab => ab.MachineId.Equals(ConfigurationManager.AppSettings["machineId"].ToString()))
 | 
				
			||||||
 | 
					                                .Where(ab => ab.Type == 1 || ab.Type == 2)
 | 
				
			||||||
 | 
					                                .Where(ab => ab.DrugId == it.DrugId)
 | 
				
			||||||
 | 
					                                .Where(ab => ab.ManuNo == it.ManuNo).OrderByDescending(ab => ab.Id).First();
 | 
				
			||||||
 | 
					                                //保存账册
 | 
				
			||||||
 | 
					                                SqlSugarHelper.Db.Insertable(new AccountBookG2()
 | 
				
			||||||
 | 
					                                {
 | 
				
			||||||
 | 
					                                    DrugId = it.DrugId,
 | 
				
			||||||
 | 
					                                    Type = 2,
 | 
				
			||||||
 | 
					                                    Department = ConfigurationManager.AppSettings["department"].ToString(),
 | 
				
			||||||
 | 
					                                    InvoiceNo = InvoiceId,
 | 
				
			||||||
 | 
					                                    ManuNo = it.ManuNo,
 | 
				
			||||||
 | 
					                                    EffDate = it.EffDate,
 | 
				
			||||||
 | 
					                                    OutQuantity = it.TakeQuantity,
 | 
				
			||||||
 | 
					                                    UserId1 = HomeWindowViewModel.Operator?.Id,
 | 
				
			||||||
 | 
					                                    UserId2 = HomeWindowViewModel.Reviewer?.Id,
 | 
				
			||||||
 | 
					                                    MachineId = ConfigurationManager.AppSettings["machineId"].ToString(),
 | 
				
			||||||
 | 
					                                    CreateDate = DateTime.Now.ToString("yyyy-MM-dd"),
 | 
				
			||||||
 | 
					                                    CreateTime = DateTime.Now,
 | 
				
			||||||
 | 
					                                    ManuStock = manuStock > 0 ? manuStock : nowChannels.Sum(it => it.Quantity),
 | 
				
			||||||
 | 
					                                    TotalStock = (accountBookEmpty != null ? (accountBookEmpty.TotalStock > 0 ? accountBookEmpty.TotalStock : 0) : 0) + it.TakeQuantity,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                                }).ExecuteCommand();
 | 
				
			||||||
                                //修改凌晨生成的总结存数据
 | 
					                                //修改凌晨生成的总结存数据
 | 
				
			||||||
                                AccountBookG2 accountBookG2Total = SqlSugarHelper.Db.Queryable<AccountBookG2>()
 | 
					                                AccountBookG2 accountBookG2Total = SqlSugarHelper.Db.Queryable<AccountBookG2>()
 | 
				
			||||||
                                .Where(ab => ab.MachineId.Equals(it.MachineId))
 | 
					                                .Where(ab => ab.MachineId.Equals(it.MachineId))
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -259,10 +259,10 @@ namespace DM_Weight.ViewModels
 | 
				
			||||||
                            }).UpdateColumns(it => new { it.Quantity, it.ManuNo, it.EffDate, it.PosNo }).ExecuteCommand();
 | 
					                            }).UpdateColumns(it => new { it.Quantity, it.ManuNo, it.EffDate, it.PosNo }).ExecuteCommand();
 | 
				
			||||||
                            // 获取更新完库存后的药品库存
 | 
					                            // 获取更新完库存后的药品库存
 | 
				
			||||||
                            List<ChannelStock> nowChannels = SqlSugarHelper.Db.Queryable<ChannelStock>()
 | 
					                            List<ChannelStock> nowChannels = SqlSugarHelper.Db.Queryable<ChannelStock>()
 | 
				
			||||||
                                .Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"]) ||cs.MachineId.Equals(ConfigurationManager.AppSettings["jj_machineId"]))
 | 
					                                .Where(cs => (cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"])&&cs.DrawerType == 1) || cs.MachineId.Equals(ConfigurationManager.AppSettings["jj_machineId"]))
 | 
				
			||||||
                                .Where(cs => cs.DrugId.Equals(it.DrugId))
 | 
					                                .Where(cs => cs.DrugId.Equals(it.DrugId))
 | 
				
			||||||
                                .Where(cs=>cs.ManuNo.Equals(it.ManuNo))
 | 
					                                .Where(cs=>cs.ManuNo.Equals(it.ManuNo))
 | 
				
			||||||
                                .Where(cs => cs.DrawerType == 1)
 | 
					                                //.Where(cs => cs.DrawerType == 1)
 | 
				
			||||||
                                .ToList();
 | 
					                                .ToList();
 | 
				
			||||||
                            // 保存数据 出/入库记录
 | 
					                            // 保存数据 出/入库记录
 | 
				
			||||||
                            SqlSugarHelper.Db.Insertable(new MachineRecord()
 | 
					                            SqlSugarHelper.Db.Insertable(new MachineRecord()
 | 
				
			||||||
| 
						 | 
					@ -279,8 +279,9 @@ namespace DM_Weight.ViewModels
 | 
				
			||||||
                                Quantity = it.AddQuantity,
 | 
					                                Quantity = it.AddQuantity,
 | 
				
			||||||
                                Type = 1,
 | 
					                                Type = 1,
 | 
				
			||||||
                                InvoiceId = InvoiceId
 | 
					                                InvoiceId = InvoiceId
 | 
				
			||||||
                                ,
 | 
					                                //,
 | 
				
			||||||
                                ReturnQuantity1 = nowChannels.Sum(it => it.Quantity)
 | 
					                                //ReturnQuantity1 = nowChannels.Sum(it => it.Quantity)
 | 
				
			||||||
 | 
					                                ,GetId= nowChannels.Sum(it => it.Quantity)
 | 
				
			||||||
                            }).ExecuteCommand();
 | 
					                            }).ExecuteCommand();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                            //查询上一条账册中的空瓶数
 | 
					                            //查询上一条账册中的空瓶数
 | 
				
			||||||
| 
						 | 
					@ -289,25 +290,6 @@ namespace DM_Weight.ViewModels
 | 
				
			||||||
                            .Where(ab => ab.Type == 1 || ab.Type == 2)
 | 
					                            .Where(ab => ab.Type == 1 || ab.Type == 2)
 | 
				
			||||||
                            .Where(ab => ab.DrugId == it.DrugId)
 | 
					                            .Where(ab => ab.DrugId == it.DrugId)
 | 
				
			||||||
                            .Where(ab => ab.ManuNo == it.ManuNo).OrderByDescending(ab => ab.Id).First();
 | 
					                            .Where(ab => ab.ManuNo == it.ManuNo).OrderByDescending(ab => ab.Id).First();
 | 
				
			||||||
                            //保存账册
 | 
					 | 
				
			||||||
                            SqlSugarHelper.Db.Insertable(new AccountBookG2()
 | 
					 | 
				
			||||||
                            {
 | 
					 | 
				
			||||||
                                DrugId = it.DrugId,
 | 
					 | 
				
			||||||
                                Type = 1,
 | 
					 | 
				
			||||||
                                Department = ConfigurationManager.AppSettings["department"].ToString(),
 | 
					 | 
				
			||||||
                                InvoiceNo = InvoiceId,
 | 
					 | 
				
			||||||
                                ManuNo = it.ManuNo,
 | 
					 | 
				
			||||||
                                EffDate = it.EffDate,
 | 
					 | 
				
			||||||
                                AddQuantity = it.AddQuantity,
 | 
					 | 
				
			||||||
                                UserId1 = HomeWindowViewModel.Operator?.Id,
 | 
					 | 
				
			||||||
                                UserId2 = HomeWindowViewModel.Reviewer?.Id,
 | 
					 | 
				
			||||||
                                MachineId = ConfigurationManager.AppSettings["machineId"].ToString(),
 | 
					 | 
				
			||||||
                                CreateDate = DateTime.Now.ToString("yyyy-MM-dd"),
 | 
					 | 
				
			||||||
                                CreateTime = DateTime.Now,
 | 
					 | 
				
			||||||
                                ManuStock= nowChannels.Sum(it => it.Quantity),
 | 
					 | 
				
			||||||
                                TotalStock= (accountBookEmpty!=null?(accountBookEmpty.TotalStock>0&& accountBookEmpty.TotalStock>it.AddQuantity ? accountBookEmpty.TotalStock - it.AddQuantity : 0):0)  //负数直接记0
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                            }).ExecuteCommand();
 | 
					 | 
				
			||||||
                            //修改凌晨生成的日结存数据
 | 
					                            //修改凌晨生成的日结存数据
 | 
				
			||||||
                            AccountBookG2 accountBookG2Day = SqlSugarHelper.Db.Queryable<AccountBookG2>()
 | 
					                            AccountBookG2 accountBookG2Day = SqlSugarHelper.Db.Queryable<AccountBookG2>()
 | 
				
			||||||
                            .Where(ab => ab.MachineId.Equals(it.MachineId))
 | 
					                            .Where(ab => ab.MachineId.Equals(it.MachineId))
 | 
				
			||||||
| 
						 | 
					@ -315,11 +297,13 @@ namespace DM_Weight.ViewModels
 | 
				
			||||||
                            .Where(ab => ab.DrugId == it.DrugId)
 | 
					                            .Where(ab => ab.DrugId == it.DrugId)
 | 
				
			||||||
                            .Where(ab => ab.ManuNo == it.ManuNo)
 | 
					                            .Where(ab => ab.ManuNo == it.ManuNo)
 | 
				
			||||||
                            .Where(ab => ab.CreateDate == DateTime.Now.ToString("yyyy-MM-dd")).First();
 | 
					                            .Where(ab => ab.CreateDate == DateTime.Now.ToString("yyyy-MM-dd")).First();
 | 
				
			||||||
 | 
					                            int manuStock = 0;
 | 
				
			||||||
                            if (accountBookG2Day != null)
 | 
					                            if (accountBookG2Day != null)
 | 
				
			||||||
                            {
 | 
					                            {
 | 
				
			||||||
                                accountBookG2Day.ManuStock = accountBookG2Day.ManuStock + it.AddQuantity;
 | 
					                                accountBookG2Day.ManuStock = accountBookG2Day.ManuStock + it.AddQuantity;
 | 
				
			||||||
                                accountBookG2Day.AddQuantity = accountBookG2Day.AddQuantity + it.AddQuantity;
 | 
					                                accountBookG2Day.AddQuantity = accountBookG2Day.AddQuantity + it.AddQuantity;
 | 
				
			||||||
                                SqlSugarHelper.Db.Updateable(accountBookG2Day).ExecuteCommand();
 | 
					                                SqlSugarHelper.Db.Updateable(accountBookG2Day).ExecuteCommand();
 | 
				
			||||||
 | 
					                                manuStock= accountBookG2Day.ManuStock;
 | 
				
			||||||
                            }
 | 
					                            }
 | 
				
			||||||
                            else
 | 
					                            else
 | 
				
			||||||
                            {
 | 
					                            {
 | 
				
			||||||
| 
						 | 
					@ -346,6 +330,25 @@ namespace DM_Weight.ViewModels
 | 
				
			||||||
                                    logger.Info($"未写入日结存数据{it.DrugId}-{it.ManuNo}-{it.EffDate}-{it.AddQuantity}");
 | 
					                                    logger.Info($"未写入日结存数据{it.DrugId}-{it.ManuNo}-{it.EffDate}-{it.AddQuantity}");
 | 
				
			||||||
                                }
 | 
					                                }
 | 
				
			||||||
                            }
 | 
					                            }
 | 
				
			||||||
 | 
					                            //保存账册
 | 
				
			||||||
 | 
					                            SqlSugarHelper.Db.Insertable(new AccountBookG2()
 | 
				
			||||||
 | 
					                            {
 | 
				
			||||||
 | 
					                                DrugId = it.DrugId,
 | 
				
			||||||
 | 
					                                Type = 1,
 | 
				
			||||||
 | 
					                                Department = ConfigurationManager.AppSettings["department"].ToString(),
 | 
				
			||||||
 | 
					                                InvoiceNo = InvoiceId,
 | 
				
			||||||
 | 
					                                ManuNo = it.ManuNo,
 | 
				
			||||||
 | 
					                                EffDate = it.EffDate,
 | 
				
			||||||
 | 
					                                AddQuantity = it.AddQuantity,
 | 
				
			||||||
 | 
					                                UserId1 = HomeWindowViewModel.Operator?.Id,
 | 
				
			||||||
 | 
					                                UserId2 = HomeWindowViewModel.Reviewer?.Id,
 | 
				
			||||||
 | 
					                                MachineId = ConfigurationManager.AppSettings["machineId"].ToString(),
 | 
				
			||||||
 | 
					                                CreateDate = DateTime.Now.ToString("yyyy-MM-dd"),
 | 
				
			||||||
 | 
					                                CreateTime = DateTime.Now,
 | 
				
			||||||
 | 
					                                ManuStock= manuStock>0? manuStock: nowChannels.Sum(it => it.Quantity),
 | 
				
			||||||
 | 
					                                TotalStock= (accountBookEmpty!=null?(accountBookEmpty.TotalStock>0&& accountBookEmpty.TotalStock>it.AddQuantity ? accountBookEmpty.TotalStock - it.AddQuantity : 0):0)  //负数直接记0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                            }).ExecuteCommand();
 | 
				
			||||||
                            //修改凌晨生成的总结存数据
 | 
					                            //修改凌晨生成的总结存数据
 | 
				
			||||||
                            AccountBookG2 accountBookG2Total = SqlSugarHelper.Db.Queryable<AccountBookG2>()
 | 
					                            AccountBookG2 accountBookG2Total = SqlSugarHelper.Db.Queryable<AccountBookG2>()
 | 
				
			||||||
                            .Where(ab => ab.MachineId.Equals(it.MachineId))
 | 
					                            .Where(ab => ab.MachineId.Equals(it.MachineId))
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -258,6 +258,7 @@ namespace DM_Weight.ViewModels
 | 
				
			||||||
                            invoice.quantity = invoice.Units == "盒" ? invoice.quantity * invoice.DrugInfo.ConvertRatio : invoice.quantity;
 | 
					                            invoice.quantity = invoice.Units == "盒" ? invoice.quantity * invoice.DrugInfo.ConvertRatio : invoice.quantity;
 | 
				
			||||||
                            item.AddQuantity = invoice.quantity;
 | 
					                            item.AddQuantity = invoice.quantity;
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
 | 
					                        invoice.DrugInfo = invoice.DrugInfo == null ? item.DrugInfo : null;
 | 
				
			||||||
                        item.Invoice = invoice;
 | 
					                        item.Invoice = invoice;
 | 
				
			||||||
                        i.Add(item);
 | 
					                        i.Add(item);
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -338,26 +338,6 @@ namespace DM_Weight.ViewModels
 | 
				
			||||||
                                //,StockQuantity = nowChannels.Sum(it => it.Quantity)
 | 
					                                //,StockQuantity = nowChannels.Sum(it => it.Quantity)
 | 
				
			||||||
                            }).ExecuteCommand();
 | 
					                            }).ExecuteCommand();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                            //保存账册
 | 
					 | 
				
			||||||
                            SqlSugarHelper.Db.Insertable(new AccountBookG2()
 | 
					 | 
				
			||||||
                            {
 | 
					 | 
				
			||||||
                                DrugId = it.DrugId,
 | 
					 | 
				
			||||||
                                Type = 1,
 | 
					 | 
				
			||||||
                                Department = ConfigurationManager.AppSettings["department"].ToString(),
 | 
					 | 
				
			||||||
                                InvoiceNo = InvoiceId,
 | 
					 | 
				
			||||||
                                ManuNo = it.ManuNo,
 | 
					 | 
				
			||||||
                                EffDate = it.EffDate,
 | 
					 | 
				
			||||||
                                AddQuantity = it.ReturnQuantity,
 | 
					 | 
				
			||||||
                                UserId1 = HomeWindowViewModel.Operator?.Id,
 | 
					 | 
				
			||||||
                                UserId2 = HomeWindowViewModel.Reviewer?.Id,
 | 
					 | 
				
			||||||
                                MachineId = ConfigurationManager.AppSettings["machineId"].ToString(),
 | 
					 | 
				
			||||||
                                CreateDate = DateTime.Now.ToString("yyyy-MM-dd"),
 | 
					 | 
				
			||||||
                                CreateTime = DateTime.Now,
 | 
					 | 
				
			||||||
                                TotalStock = nowChannels.Sum(itx => itx.Quantity),
 | 
					 | 
				
			||||||
                                ManuStock = nowChannels.Where(itx => itx.ManuNo == it.ManuNo && itx.EffDate == it.EffDate).Sum(itx => itx.Quantity)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                            }).ExecuteCommand();
 | 
					 | 
				
			||||||
                            //修改凌晨生成的日结存数据
 | 
					                            //修改凌晨生成的日结存数据
 | 
				
			||||||
                            AccountBookG2 accountBookG2Day = SqlSugarHelper.Db.Queryable<AccountBookG2>()
 | 
					                            AccountBookG2 accountBookG2Day = SqlSugarHelper.Db.Queryable<AccountBookG2>()
 | 
				
			||||||
                            .Where(ab => ab.MachineId.Equals(it.MachineId))
 | 
					                            .Where(ab => ab.MachineId.Equals(it.MachineId))
 | 
				
			||||||
| 
						 | 
					@ -365,11 +345,13 @@ namespace DM_Weight.ViewModels
 | 
				
			||||||
                            .Where(ab => ab.DrugId == it.DrugId)
 | 
					                            .Where(ab => ab.DrugId == it.DrugId)
 | 
				
			||||||
                            .Where(ab => ab.ManuNo == it.ManuNo)
 | 
					                            .Where(ab => ab.ManuNo == it.ManuNo)
 | 
				
			||||||
                            .Where(ab => ab.CreateDate == DateTime.Now.ToString("yyyy-MM-dd")).First();
 | 
					                            .Where(ab => ab.CreateDate == DateTime.Now.ToString("yyyy-MM-dd")).First();
 | 
				
			||||||
 | 
					                            int manuStock = 0;
 | 
				
			||||||
                            if (accountBookG2Day != null)
 | 
					                            if (accountBookG2Day != null)
 | 
				
			||||||
                            {
 | 
					                            {
 | 
				
			||||||
                                accountBookG2Day.ManuStock = accountBookG2Day.ManuStock + it.ReturnQuantity;
 | 
					                                accountBookG2Day.ManuStock = accountBookG2Day.ManuStock + it.ReturnQuantity;
 | 
				
			||||||
                                accountBookG2Day.AddQuantity = accountBookG2Day.AddQuantity + it.ReturnQuantity;
 | 
					                                accountBookG2Day.AddQuantity = accountBookG2Day.AddQuantity + it.ReturnQuantity;
 | 
				
			||||||
                                SqlSugarHelper.Db.Updateable(accountBookG2Day).ExecuteCommand();
 | 
					                                SqlSugarHelper.Db.Updateable(accountBookG2Day).ExecuteCommand();
 | 
				
			||||||
 | 
					                                manuStock = accountBookG2Day.ManuStock;
 | 
				
			||||||
                            }
 | 
					                            }
 | 
				
			||||||
                            else
 | 
					                            else
 | 
				
			||||||
                            {
 | 
					                            {
 | 
				
			||||||
| 
						 | 
					@ -396,6 +378,33 @@ namespace DM_Weight.ViewModels
 | 
				
			||||||
                                    logger.Info($"未写入日结存数据{it.DrugId}-{it.ManuNo}-{it.EffDate}-{it.AddQuantity}");
 | 
					                                    logger.Info($"未写入日结存数据{it.DrugId}-{it.ManuNo}-{it.EffDate}-{it.AddQuantity}");
 | 
				
			||||||
                                }
 | 
					                                }
 | 
				
			||||||
                            }
 | 
					                            }
 | 
				
			||||||
 | 
					                            //查询上一条账册中的空瓶数
 | 
				
			||||||
 | 
					                            AccountBookG2 accountBookEmpty = SqlSugarHelper.Db.Queryable<AccountBookG2>()
 | 
				
			||||||
 | 
					                            .Where(ab => ab.MachineId.Equals(ConfigurationManager.AppSettings["machineId"].ToString()))
 | 
				
			||||||
 | 
					                            .Where(ab => ab.Type == 1 || ab.Type == 2)
 | 
				
			||||||
 | 
					                            .Where(ab => ab.DrugId == it.DrugId)
 | 
				
			||||||
 | 
					                            .Where(ab => ab.ManuNo == it.ManuNo).OrderByDescending(ab => ab.Id).First();
 | 
				
			||||||
 | 
					                            //保存账册
 | 
				
			||||||
 | 
					                            SqlSugarHelper.Db.Insertable(new AccountBookG2()
 | 
				
			||||||
 | 
					                            {
 | 
				
			||||||
 | 
					                                DrugId = it.DrugId,
 | 
				
			||||||
 | 
					                                Type = 1,
 | 
				
			||||||
 | 
					                                Department = ConfigurationManager.AppSettings["department"].ToString(),
 | 
				
			||||||
 | 
					                                InvoiceNo = InvoiceId,
 | 
				
			||||||
 | 
					                                ManuNo = it.ManuNo,
 | 
				
			||||||
 | 
					                                EffDate = it.EffDate,
 | 
				
			||||||
 | 
					                                AddQuantity = it.ReturnQuantity,
 | 
				
			||||||
 | 
					                                UserId1 = HomeWindowViewModel.Operator?.Id,
 | 
				
			||||||
 | 
					                                UserId2 = HomeWindowViewModel.Reviewer?.Id,
 | 
				
			||||||
 | 
					                                MachineId = ConfigurationManager.AppSettings["machineId"].ToString(),
 | 
				
			||||||
 | 
					                                CreateDate = DateTime.Now.ToString("yyyy-MM-dd"),
 | 
				
			||||||
 | 
					                                CreateTime = DateTime.Now,
 | 
				
			||||||
 | 
					                                TotalStock = manuStock > 0 ? manuStock : nowChannels.Sum(it => it.Quantity),//nowChannels.Sum(itx => itx.Quantity),
 | 
				
			||||||
 | 
					                                ManuStock = (accountBookEmpty != null ? (accountBookEmpty.TotalStock > 0 && accountBookEmpty.TotalStock > it.ReturnQuantity ? accountBookEmpty.TotalStock - it.ReturnQuantity : 0) : 0)  //
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                            }).ExecuteCommand();
 | 
				
			||||||
                            //修改凌晨生成的总结存数据
 | 
					                            //修改凌晨生成的总结存数据
 | 
				
			||||||
                            AccountBookG2 accountBookG2Total = SqlSugarHelper.Db.Queryable<AccountBookG2>()
 | 
					                            AccountBookG2 accountBookG2Total = SqlSugarHelper.Db.Queryable<AccountBookG2>()
 | 
				
			||||||
                            .Where(ab => ab.MachineId.Equals(it.MachineId))
 | 
					                            .Where(ab => ab.MachineId.Equals(it.MachineId))
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -269,27 +269,6 @@ namespace DM_Weight.ViewModels
 | 
				
			||||||
                        GetId = MachineRecord.Id
 | 
					                        GetId = MachineRecord.Id
 | 
				
			||||||
                        //,StockQuantity = nowChannels.Sum(it => it.Quantity)
 | 
					                        //,StockQuantity = nowChannels.Sum(it => it.Quantity)
 | 
				
			||||||
                    }).ExecuteCommand();
 | 
					                    }).ExecuteCommand();
 | 
				
			||||||
 | 
					 | 
				
			||||||
                    //保存账册
 | 
					 | 
				
			||||||
                    SqlSugarHelper.Db.Insertable(new AccountBookG2()
 | 
					 | 
				
			||||||
                    {
 | 
					 | 
				
			||||||
                        DrugId = ChannelStock.DrugId,
 | 
					 | 
				
			||||||
                        Type = 1,
 | 
					 | 
				
			||||||
                        Department = ConfigurationManager.AppSettings["department"].ToString(),
 | 
					 | 
				
			||||||
                        InvoiceNo = InvoiceId,
 | 
					 | 
				
			||||||
                        ManuNo = ChannelStock.ManuNo,
 | 
					 | 
				
			||||||
                        EffDate = ChannelStock.EffDate,
 | 
					 | 
				
			||||||
                        AddQuantity = ReturnQuantity,
 | 
					 | 
				
			||||||
                        UserId1 = HomeWindowViewModel.Operator?.Id,
 | 
					 | 
				
			||||||
                        UserId2 = HomeWindowViewModel.Reviewer?.Id,
 | 
					 | 
				
			||||||
                        MachineId = ConfigurationManager.AppSettings["machineId"].ToString(),
 | 
					 | 
				
			||||||
                        CreateDate = DateTime.Now.ToString("yyyy-MM-dd"),
 | 
					 | 
				
			||||||
                        CreateTime = DateTime.Now,
 | 
					 | 
				
			||||||
                        TotalStock = nowChannels.Sum(itx => itx.Quantity),
 | 
					 | 
				
			||||||
                        ManuStock = nowChannels.Where(itx => itx.ManuNo == ChannelStock.ManuNo && itx.EffDate == ChannelStock.EffDate).Sum(itx => itx.Quantity)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                    }).ExecuteCommand();
 | 
					 | 
				
			||||||
                    //修改凌晨生成的日结存数据
 | 
					                    //修改凌晨生成的日结存数据
 | 
				
			||||||
                    AccountBookG2 accountBookG2Day = SqlSugarHelper.Db.Queryable<AccountBookG2>()
 | 
					                    AccountBookG2 accountBookG2Day = SqlSugarHelper.Db.Queryable<AccountBookG2>()
 | 
				
			||||||
                    .Where(ab => ab.MachineId.Equals(ChannelStock.MachineId))
 | 
					                    .Where(ab => ab.MachineId.Equals(ChannelStock.MachineId))
 | 
				
			||||||
| 
						 | 
					@ -297,11 +276,13 @@ namespace DM_Weight.ViewModels
 | 
				
			||||||
                    .Where(ab => ab.DrugId == ChannelStock.DrugId)
 | 
					                    .Where(ab => ab.DrugId == ChannelStock.DrugId)
 | 
				
			||||||
                    .Where(ab => ab.ManuNo == ChannelStock.ManuNo)
 | 
					                    .Where(ab => ab.ManuNo == ChannelStock.ManuNo)
 | 
				
			||||||
                    .Where(ab => ab.CreateDate == DateTime.Now.ToString("yyyy-MM-dd")).First();
 | 
					                    .Where(ab => ab.CreateDate == DateTime.Now.ToString("yyyy-MM-dd")).First();
 | 
				
			||||||
 | 
					                    int manuStock = 0;
 | 
				
			||||||
                    if (accountBookG2Day != null)
 | 
					                    if (accountBookG2Day != null)
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        accountBookG2Day.ManuStock = accountBookG2Day.ManuStock + ChannelStock.ReturnQuantity;
 | 
					                        accountBookG2Day.ManuStock = accountBookG2Day.ManuStock + ChannelStock.ReturnQuantity;
 | 
				
			||||||
                        accountBookG2Day.AddQuantity = accountBookG2Day.AddQuantity + ChannelStock.ReturnQuantity;
 | 
					                        accountBookG2Day.AddQuantity = accountBookG2Day.AddQuantity + ChannelStock.ReturnQuantity;
 | 
				
			||||||
                        SqlSugarHelper.Db.Updateable(accountBookG2Day).ExecuteCommand();
 | 
					                        SqlSugarHelper.Db.Updateable(accountBookG2Day).ExecuteCommand();
 | 
				
			||||||
 | 
					                        manuStock = accountBookG2Day.ManuStock;
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                    else
 | 
					                    else
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
| 
						 | 
					@ -328,6 +309,33 @@ namespace DM_Weight.ViewModels
 | 
				
			||||||
                            logger.Info($"未写入日结存数据{ChannelStock.DrugId}-{ChannelStock.ManuNo}-{ChannelStock.EffDate}-{ChannelStock.AddQuantity}");
 | 
					                            logger.Info($"未写入日结存数据{ChannelStock.DrugId}-{ChannelStock.ManuNo}-{ChannelStock.EffDate}-{ChannelStock.AddQuantity}");
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
 | 
					                    //查询上一条账册中的空瓶数
 | 
				
			||||||
 | 
					                    AccountBookG2 accountBookEmpty = SqlSugarHelper.Db.Queryable<AccountBookG2>()
 | 
				
			||||||
 | 
					                    .Where(ab => ab.MachineId.Equals(ConfigurationManager.AppSettings["machineId"].ToString()))
 | 
				
			||||||
 | 
					                    .Where(ab => ab.Type == 1 || ab.Type == 2)
 | 
				
			||||||
 | 
					                    .Where(ab => ab.DrugId == ChannelStock.DrugId)
 | 
				
			||||||
 | 
					                    .Where(ab => ab.ManuNo == ChannelStock.ManuNo).OrderByDescending(ab => ab.Id).First();
 | 
				
			||||||
 | 
					                    //保存账册
 | 
				
			||||||
 | 
					                    SqlSugarHelper.Db.Insertable(new AccountBookG2()
 | 
				
			||||||
 | 
					                    {
 | 
				
			||||||
 | 
					                        DrugId = ChannelStock.DrugId,
 | 
				
			||||||
 | 
					                        Type = 1,
 | 
				
			||||||
 | 
					                        Department = ConfigurationManager.AppSettings["department"].ToString(),
 | 
				
			||||||
 | 
					                        InvoiceNo = InvoiceId,
 | 
				
			||||||
 | 
					                        ManuNo = ChannelStock.ManuNo,
 | 
				
			||||||
 | 
					                        EffDate = ChannelStock.EffDate,
 | 
				
			||||||
 | 
					                        AddQuantity = ReturnQuantity,
 | 
				
			||||||
 | 
					                        UserId1 = HomeWindowViewModel.Operator?.Id,
 | 
				
			||||||
 | 
					                        UserId2 = HomeWindowViewModel.Reviewer?.Id,
 | 
				
			||||||
 | 
					                        MachineId = ConfigurationManager.AppSettings["machineId"].ToString(),
 | 
				
			||||||
 | 
					                        CreateDate = DateTime.Now.ToString("yyyy-MM-dd"),
 | 
				
			||||||
 | 
					                        CreateTime = DateTime.Now,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                        TotalStock = manuStock > 0 ? manuStock : nowChannels.Sum(it => it.Quantity),//nowChannels.Sum(itx => itx.Quantity),
 | 
				
			||||||
 | 
					                        ManuStock = (accountBookEmpty != null ? (accountBookEmpty.TotalStock > 0 && accountBookEmpty.TotalStock > ChannelStock.ReturnQuantity ? accountBookEmpty.TotalStock - ChannelStock.ReturnQuantity : 0) : 0)  //
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    }).ExecuteCommand();
 | 
				
			||||||
                    //修改凌晨生成的总结存数据
 | 
					                    //修改凌晨生成的总结存数据
 | 
				
			||||||
                    AccountBookG2 accountBookG2Total = SqlSugarHelper.Db.Queryable<AccountBookG2>()
 | 
					                    AccountBookG2 accountBookG2Total = SqlSugarHelper.Db.Queryable<AccountBookG2>()
 | 
				
			||||||
                    .Where(ab => ab.MachineId.Equals(ChannelStock.MachineId))
 | 
					                    .Where(ab => ab.MachineId.Equals(ChannelStock.MachineId))
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -267,27 +267,12 @@ namespace DM_Weight.ViewModels
 | 
				
			||||||
                                InvoiceId = InvoiceId
 | 
					                                InvoiceId = InvoiceId
 | 
				
			||||||
                                //,StockQuantity = nowChannels.Sum(it => it.Quantity)
 | 
					                                //,StockQuantity = nowChannels.Sum(it => it.Quantity)
 | 
				
			||||||
                            }).ExecuteCommand();
 | 
					                            }).ExecuteCommand();
 | 
				
			||||||
 | 
					                            //查询上一条账册中的空瓶数
 | 
				
			||||||
 | 
					                            AccountBookG2 accountBookEmpty = SqlSugarHelper.Db.Queryable<AccountBookG2>()
 | 
				
			||||||
                            //保存账册
 | 
					                            .Where(ab => ab.MachineId.Equals(ConfigurationManager.AppSettings["machineId"].ToString()))
 | 
				
			||||||
                            SqlSugarHelper.Db.Insertable(new AccountBookG2()
 | 
					                            .Where(ab => ab.Type == 1 || ab.Type == 2)
 | 
				
			||||||
                            {
 | 
					                            .Where(ab => ab.DrugId == it.DrugId)
 | 
				
			||||||
                                DrugId = it.DrugId,
 | 
					                            .Where(ab => ab.ManuNo == it.ManuNo).OrderByDescending(ab => ab.Id).First();
 | 
				
			||||||
                                Type = 1,
 | 
					 | 
				
			||||||
                                Department = ConfigurationManager.AppSettings["department"].ToString(),
 | 
					 | 
				
			||||||
                                InvoiceNo = InvoiceId,
 | 
					 | 
				
			||||||
                                ManuNo = it.ManuNo,
 | 
					 | 
				
			||||||
                                EffDate = it.EffDate,
 | 
					 | 
				
			||||||
                                AddQuantity = it.AddQuantity,
 | 
					 | 
				
			||||||
                                UserId1 = HomeWindowViewModel.Operator?.Id,
 | 
					 | 
				
			||||||
                                UserId2 = HomeWindowViewModel.Reviewer?.Id,
 | 
					 | 
				
			||||||
                                MachineId = ConfigurationManager.AppSettings["machineId"].ToString(),
 | 
					 | 
				
			||||||
                                CreateDate = DateTime.Now.ToString("yyyy-MM-dd"),
 | 
					 | 
				
			||||||
                                CreateTime = DateTime.Now,
 | 
					 | 
				
			||||||
                                TotalStock = nowChannels.Sum(itx => itx.Quantity),
 | 
					 | 
				
			||||||
                                ManuStock = nowChannels.Where(itx => itx.ManuNo == it.ManuNo && itx.EffDate == it.EffDate).Sum(itx => itx.Quantity)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                            }).ExecuteCommand();
 | 
					 | 
				
			||||||
                            //修改凌晨生成的日结存数据
 | 
					                            //修改凌晨生成的日结存数据
 | 
				
			||||||
                            AccountBookG2 accountBookG2Day = SqlSugarHelper.Db.Queryable<AccountBookG2>()
 | 
					                            AccountBookG2 accountBookG2Day = SqlSugarHelper.Db.Queryable<AccountBookG2>()
 | 
				
			||||||
                            .Where(ab => ab.MachineId.Equals(it.MachineId))
 | 
					                            .Where(ab => ab.MachineId.Equals(it.MachineId))
 | 
				
			||||||
| 
						 | 
					@ -295,11 +280,13 @@ namespace DM_Weight.ViewModels
 | 
				
			||||||
                            .Where(ab => ab.DrugId == it.DrugId)
 | 
					                            .Where(ab => ab.DrugId == it.DrugId)
 | 
				
			||||||
                            .Where(ab => ab.ManuNo == it.ManuNo)
 | 
					                            .Where(ab => ab.ManuNo == it.ManuNo)
 | 
				
			||||||
                            .Where(ab => ab.CreateDate == DateTime.Now.ToString("yyyy-MM-dd")).First();
 | 
					                            .Where(ab => ab.CreateDate == DateTime.Now.ToString("yyyy-MM-dd")).First();
 | 
				
			||||||
 | 
					                            int manuStock = 0;
 | 
				
			||||||
                            if (accountBookG2Day != null)
 | 
					                            if (accountBookG2Day != null)
 | 
				
			||||||
                            {
 | 
					                            {
 | 
				
			||||||
                                accountBookG2Day.ManuStock = accountBookG2Day.ManuStock + it.AddQuantity;
 | 
					                                accountBookG2Day.ManuStock = accountBookG2Day.ManuStock + it.AddQuantity;
 | 
				
			||||||
                                accountBookG2Day.AddQuantity = accountBookG2Day.AddQuantity + it.AddQuantity;
 | 
					                                accountBookG2Day.AddQuantity = accountBookG2Day.AddQuantity + it.AddQuantity;
 | 
				
			||||||
                                SqlSugarHelper.Db.Updateable(accountBookG2Day).ExecuteCommand();
 | 
					                                SqlSugarHelper.Db.Updateable(accountBookG2Day).ExecuteCommand();
 | 
				
			||||||
 | 
					                                manuStock = accountBookG2Day.ManuStock;
 | 
				
			||||||
                            }
 | 
					                            }
 | 
				
			||||||
                            else
 | 
					                            else
 | 
				
			||||||
                            {
 | 
					                            {
 | 
				
			||||||
| 
						 | 
					@ -326,6 +313,27 @@ namespace DM_Weight.ViewModels
 | 
				
			||||||
                                    logger.Info($"未写入日结存数据{it.DrugId}-{it.ManuNo}-{it.EffDate}-{it.AddQuantity}");
 | 
					                                    logger.Info($"未写入日结存数据{it.DrugId}-{it.ManuNo}-{it.EffDate}-{it.AddQuantity}");
 | 
				
			||||||
                                }
 | 
					                                }
 | 
				
			||||||
                            }
 | 
					                            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                            //保存账册
 | 
				
			||||||
 | 
					                            SqlSugarHelper.Db.Insertable(new AccountBookG2()
 | 
				
			||||||
 | 
					                            {
 | 
				
			||||||
 | 
					                                DrugId = it.DrugId,
 | 
				
			||||||
 | 
					                                Type = 1,
 | 
				
			||||||
 | 
					                                Department = ConfigurationManager.AppSettings["department"].ToString(),
 | 
				
			||||||
 | 
					                                InvoiceNo = InvoiceId,
 | 
				
			||||||
 | 
					                                ManuNo = it.ManuNo,
 | 
				
			||||||
 | 
					                                EffDate = it.EffDate,
 | 
				
			||||||
 | 
					                                AddQuantity = it.AddQuantity,
 | 
				
			||||||
 | 
					                                UserId1 = HomeWindowViewModel.Operator?.Id,
 | 
				
			||||||
 | 
					                                UserId2 = HomeWindowViewModel.Reviewer?.Id,
 | 
				
			||||||
 | 
					                                MachineId = ConfigurationManager.AppSettings["machineId"].ToString(),
 | 
				
			||||||
 | 
					                                CreateDate = DateTime.Now.ToString("yyyy-MM-dd"),
 | 
				
			||||||
 | 
					                                CreateTime = DateTime.Now,
 | 
				
			||||||
 | 
					                                ManuStock = manuStock > 0 ? manuStock : nowChannels.Sum(it => it.Quantity),
 | 
				
			||||||
 | 
					                                TotalStock = (accountBookEmpty != null ? (accountBookEmpty.TotalStock > 0 && accountBookEmpty.TotalStock > it.AddQuantity ? accountBookEmpty.TotalStock - it.AddQuantity : 0) : 0)  //负数直接记0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                            }).ExecuteCommand();
 | 
				
			||||||
                            //修改凌晨生成的总结存数据
 | 
					                            //修改凌晨生成的总结存数据
 | 
				
			||||||
                            AccountBookG2 accountBookG2Total = SqlSugarHelper.Db.Queryable<AccountBookG2>()
 | 
					                            AccountBookG2 accountBookG2Total = SqlSugarHelper.Db.Queryable<AccountBookG2>()
 | 
				
			||||||
                            .Where(ab => ab.MachineId.Equals(it.MachineId))
 | 
					                            .Where(ab => ab.MachineId.Equals(it.MachineId))
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -246,26 +246,6 @@ namespace DM_Weight.ViewModels
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                            //保存账册
 | 
					 | 
				
			||||||
                            SqlSugarHelper.Db.Insertable(new AccountBookG2()
 | 
					 | 
				
			||||||
                            {
 | 
					 | 
				
			||||||
                                DrugId = it.DrugId,
 | 
					 | 
				
			||||||
                                Type = 2,
 | 
					 | 
				
			||||||
                                Department = ConfigurationManager.AppSettings["department"].ToString(),
 | 
					 | 
				
			||||||
                                InvoiceNo = InvoiceId,
 | 
					 | 
				
			||||||
                                ManuNo = it.ManuNo,
 | 
					 | 
				
			||||||
                                EffDate = it.EffDate,
 | 
					 | 
				
			||||||
                                OutQuantity = it.TakeQuantity,
 | 
					 | 
				
			||||||
                                UserId1 = HomeWindowViewModel.Operator?.Id,
 | 
					 | 
				
			||||||
                                UserId2 = HomeWindowViewModel.Reviewer?.Id,
 | 
					 | 
				
			||||||
                                MachineId = ConfigurationManager.AppSettings["machineId"].ToString(),
 | 
					 | 
				
			||||||
                                CreateDate = DateTime.Now.ToString("yyyy-MM-dd"),
 | 
					 | 
				
			||||||
                                CreateTime = DateTime.Now,
 | 
					 | 
				
			||||||
                                TotalStock = nowChannels.Sum(itx => itx.Quantity),
 | 
					 | 
				
			||||||
                                ManuStock = nowChannels.Where(itx => itx.ManuNo == it.ManuNo && itx.EffDate == it.EffDate).Sum(itx => itx.Quantity)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                            }).ExecuteCommand();
 | 
					 | 
				
			||||||
                            //修改凌晨生成的日结存数据
 | 
					                            //修改凌晨生成的日结存数据
 | 
				
			||||||
                            AccountBookG2 accountBookG2Day = SqlSugarHelper.Db.Queryable<AccountBookG2>()
 | 
					                            AccountBookG2 accountBookG2Day = SqlSugarHelper.Db.Queryable<AccountBookG2>()
 | 
				
			||||||
                            .Where(ab => ab.MachineId.Equals(it.MachineId))
 | 
					                            .Where(ab => ab.MachineId.Equals(it.MachineId))
 | 
				
			||||||
| 
						 | 
					@ -273,11 +253,13 @@ namespace DM_Weight.ViewModels
 | 
				
			||||||
                            .Where(ab => ab.DrugId == it.DrugId)
 | 
					                            .Where(ab => ab.DrugId == it.DrugId)
 | 
				
			||||||
                            .Where(ab => ab.ManuNo == it.ManuNo)
 | 
					                            .Where(ab => ab.ManuNo == it.ManuNo)
 | 
				
			||||||
                            .Where(ab => ab.CreateDate == DateTime.Now.ToString("yyyy-MM-dd")).First();
 | 
					                            .Where(ab => ab.CreateDate == DateTime.Now.ToString("yyyy-MM-dd")).First();
 | 
				
			||||||
 | 
					                            int manuStock = 0;
 | 
				
			||||||
                            if (accountBookG2Day != null)
 | 
					                            if (accountBookG2Day != null)
 | 
				
			||||||
                            {
 | 
					                            {
 | 
				
			||||||
                                accountBookG2Day.ManuStock = accountBookG2Day.ManuStock - it.TakeQuantity;
 | 
					                                accountBookG2Day.ManuStock = accountBookG2Day.ManuStock - it.TakeQuantity;
 | 
				
			||||||
                                accountBookG2Day.OutQuantity = accountBookG2Day.OutQuantity - it.TakeQuantity;
 | 
					                                accountBookG2Day.OutQuantity = accountBookG2Day.OutQuantity + it.TakeQuantity;
 | 
				
			||||||
                                SqlSugarHelper.Db.Updateable(accountBookG2Day).ExecuteCommand();
 | 
					                                SqlSugarHelper.Db.Updateable(accountBookG2Day).ExecuteCommand();
 | 
				
			||||||
 | 
					                                manuStock = accountBookG2Day.ManuStock;
 | 
				
			||||||
                            }
 | 
					                            }
 | 
				
			||||||
                            else
 | 
					                            else
 | 
				
			||||||
                            {
 | 
					                            {
 | 
				
			||||||
| 
						 | 
					@ -304,6 +286,30 @@ namespace DM_Weight.ViewModels
 | 
				
			||||||
                                    logger.Info($"未写入日结存数据{it.DrugId}-{it.ManuNo}-{it.EffDate}-{it.AddQuantity}");
 | 
					                                    logger.Info($"未写入日结存数据{it.DrugId}-{it.ManuNo}-{it.EffDate}-{it.AddQuantity}");
 | 
				
			||||||
                                }
 | 
					                                }
 | 
				
			||||||
                            }
 | 
					                            }
 | 
				
			||||||
 | 
					                            //查询上一条账册中的空瓶数
 | 
				
			||||||
 | 
					                            AccountBookG2 accountBookEmpty = SqlSugarHelper.Db.Queryable<AccountBookG2>()
 | 
				
			||||||
 | 
					                            .Where(ab => ab.MachineId.Equals(ConfigurationManager.AppSettings["machineId"].ToString()))
 | 
				
			||||||
 | 
					                            .Where(ab => ab.Type == 1 || ab.Type == 2)
 | 
				
			||||||
 | 
					                            .Where(ab => ab.DrugId == it.DrugId)
 | 
				
			||||||
 | 
					                            .Where(ab => ab.ManuNo == it.ManuNo).OrderByDescending(ab => ab.Id).First();
 | 
				
			||||||
 | 
					                            //保存账册
 | 
				
			||||||
 | 
					                            SqlSugarHelper.Db.Insertable(new AccountBookG2()
 | 
				
			||||||
 | 
					                            {
 | 
				
			||||||
 | 
					                                DrugId = it.DrugId,
 | 
				
			||||||
 | 
					                                Type = 2,
 | 
				
			||||||
 | 
					                                Department = ConfigurationManager.AppSettings["department"].ToString(),
 | 
				
			||||||
 | 
					                                InvoiceNo = InvoiceId,
 | 
				
			||||||
 | 
					                                ManuNo = it.ManuNo,
 | 
				
			||||||
 | 
					                                EffDate = it.EffDate,
 | 
				
			||||||
 | 
					                                OutQuantity = it.TakeQuantity,
 | 
				
			||||||
 | 
					                                UserId1 = HomeWindowViewModel.Operator?.Id,
 | 
				
			||||||
 | 
					                                UserId2 = HomeWindowViewModel.Reviewer?.Id,
 | 
				
			||||||
 | 
					                                MachineId = ConfigurationManager.AppSettings["machineId"].ToString(),
 | 
				
			||||||
 | 
					                                CreateDate = DateTime.Now.ToString("yyyy-MM-dd"),
 | 
				
			||||||
 | 
					                                CreateTime = DateTime.Now,
 | 
				
			||||||
 | 
					                                ManuStock = manuStock > 0 ? manuStock : nowChannels.Sum(it => it.Quantity),
 | 
				
			||||||
 | 
					                                TotalStock = (accountBookEmpty != null ? (accountBookEmpty.TotalStock > 0 ? accountBookEmpty.TotalStock : 0) : 0) + it.TakeQuantity,
 | 
				
			||||||
 | 
					                            }).ExecuteCommand();
 | 
				
			||||||
                            //修改凌晨生成的总结存数据
 | 
					                            //修改凌晨生成的总结存数据
 | 
				
			||||||
                            AccountBookG2 accountBookG2Total = SqlSugarHelper.Db.Queryable<AccountBookG2>()
 | 
					                            AccountBookG2 accountBookG2Total = SqlSugarHelper.Db.Queryable<AccountBookG2>()
 | 
				
			||||||
                            .Where(ab => ab.MachineId.Equals(it.MachineId))
 | 
					                            .Where(ab => ab.MachineId.Equals(it.MachineId))
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -44,9 +44,23 @@ namespace DM_Weight.util
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            else
 | 
					            else
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                var count = (Environment.TickCount & Int32.MaxValue) - (long)vLastInputInfo.dwTime;
 | 
					                //var count = (Environment.TickCount & Int32.MaxValue) - (long)vLastInputInfo.dwTime;
 | 
				
			||||||
                var icount = count / 1000;
 | 
					                //var icount = count / 1000;
 | 
				
			||||||
                return icount;
 | 
					                //return icount;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                // 使用 64 位 TickCount 避免回绕问题
 | 
				
			||||||
 | 
					                long currentTick = Environment.TickCount64;
 | 
				
			||||||
 | 
					                long lastInputTick = vLastInputInfo.dwTime;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                // 处理可能的回绕(虽然使用 64 位后极不可能发生)
 | 
				
			||||||
 | 
					                if (currentTick < lastInputTick)
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    // 发生了回绕,调整计算
 | 
				
			||||||
 | 
					                    lastInputTick -= uint.MaxValue + 1L;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                long elapsedMilliseconds = currentTick - lastInputTick;
 | 
				
			||||||
 | 
					                return Math.Max(0, elapsedMilliseconds / 1000);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue