示例#1
0
        /// <summary>
        /// 对损益主单进行加锁
        /// </summary>
        /// <param name="BillNo">损益单号</param>
        /// <param name="strResult">提示信息文本</param>
        /// <returns></returns>
        public bool LockBillMaster(string BillNo)
        {
            bool result = false;
            var  pbm    = ProfitLossBillMasterRepository.GetQueryable().FirstOrDefault(p => p.BillNo == BillNo && p.Status == "1");

            if (pbm != null)
            {
                if (string.IsNullOrEmpty(pbm.LockTag))
                {
                    pbm.LockTag = BillNo;
                    ProfitLossBillMasterRepository.SaveChanges();
                    result = true;
                }
                else
                {
                    resultStr = "当前订单其他人正在操作,请稍候重试!";
                    result    = false;
                }
            }
            else
            {
                resultStr = "当前单据的状态不是已录入状态或者该单据已被删除无法编辑,请刷新页面!";
                result    = false;
            }
            return(result);
        }
示例#2
0
        /// <summary>
        /// 生成损益主单单号
        /// </summary>
        /// <param name="userName">用户名</param>
        /// <returns></returns>
        public object GenProfitLossBillNo(string userName)
        {
            IQueryable <ProfitLossBillMaster> profitLossBillMasterQuery = ProfitLossBillMasterRepository.GetQueryable();
            string sysTime              = System.DateTime.Now.ToString("yyMMdd");
            string billNo               = "";
            var    employee             = EmployeeRepository.GetQueryable().FirstOrDefault(i => i.UserName == userName);
            var    profitLossBillMaster = profitLossBillMasterQuery.Where(i => i.BillNo.Contains(sysTime)).ToArray().OrderBy(i => i.BillNo).Select(i => new { i.BillNo }.BillNo);

            if (profitLossBillMaster.Count() == 0)
            {
                billNo = System.DateTime.Now.ToString("yyMMdd") + "0001" + "PL";
            }
            else
            {
                string billNoStr = profitLossBillMaster.Last(b => b.Contains(sysTime));
                int    i         = Convert.ToInt32(billNoStr.ToString().Substring(6, 4));
                i++;
                string newcode = i.ToString();
                for (int j = 0; j < 4 - i.ToString().Length; j++)
                {
                    newcode = "0" + newcode;
                }
                billNo = System.DateTime.Now.ToString("yyMMdd") + newcode + "PL";
            }

            return(billNo);
        }
        /// <summary>
        /// 损益主单审核
        /// </summary>
        /// <param name="BillNo">损益单号</param>
        /// <param name="userName">用户名</param>
        /// <returns></returns>
        public bool Audit(string BillNo, string userName, out string strResult)
        {
            bool result   = false;
            var  pbm      = ProfitLossBillMasterRepository.GetQueryable().FirstOrDefault(i => i.BillNo == BillNo && i.Status == "1");
            var  employee = EmployeeRepository.GetQueryable().FirstOrDefault(i => i.UserName == userName);

            if (LockBillMaster(BillNo))
            {
                if (pbm != null)
                {
                    ChangeStorages(pbm);
                    pbm.Status         = "2";
                    pbm.VerifyDate     = DateTime.Now;
                    pbm.UpdateTime     = DateTime.Now;
                    pbm.VerifyPersonID = employee.ID;

                    pbm.LockTag = string.Empty;
                    ProfitLossBillMasterRepository.SaveChanges();
                    result = true;
                }
            }
            else
            {
                result = false;
            }
            strResult = resultStr;
            return(result);
        }
示例#4
0
        /// <summary>
        /// 删除损益单主单
        /// </summary>
        /// <param name="BillNo">损益单号</param>
        /// <returns></returns>
        public bool Delete(string BillNo, out string strResult)
        {
            strResult = string.Empty;
            bool result = false;
            var  pbm    = ProfitLossBillMasterRepository.GetQueryable().FirstOrDefault(i => i.BillNo == BillNo && i.Status == "1");

            if (LockBillMaster(BillNo))
            {
                if (pbm != null)
                {
                    try
                    {
                        DeleteProfitLossBillDetail(pbm);
                        ProfitLossBillMasterRepository.Delete(pbm);
                        ProfitLossBillMasterRepository.SaveChanges();
                        result = true;
                    }
                    catch (Exception ex)
                    {
                        strResult = "删除失败,原因:" + ex.Message;
                    }
                }
                else
                {
                    strResult = "删除失败,未找到该条数据!";
                    result    = false;
                }
            }
            else
            {
                strResult = resultStr;
                result    = false;
            }
            return(result);
        }
        /// <summary>
        /// 保存损益单主单
        /// </summary>
        /// <param name="profitLossBillMaster">损益单主单</param>
        /// <returns></returns>
        public bool Save(ProfitLossBillMaster profitLossBillMaster, out string strResult)
        {
            bool result = false;
            var  pbm    = ProfitLossBillMasterRepository.GetQueryable().FirstOrDefault(i => i.BillNo == profitLossBillMaster.BillNo && i.Status == "1");

            if (LockBillMaster(profitLossBillMaster.BillNo))
            {
                if (pbm != null)
                {
                    pbm.BillDate        = profitLossBillMaster.BillDate;
                    pbm.BillTypeCode    = profitLossBillMaster.BillTypeCode;
                    pbm.WarehouseCode   = profitLossBillMaster.WarehouseCode;
                    pbm.OperatePersonID = profitLossBillMaster.OperatePersonID;
                    pbm.Status          = "1";
                    pbm.VerifyPersonID  = profitLossBillMaster.VerifyPersonID;
                    pbm.VerifyDate      = profitLossBillMaster.VerifyDate;
                    pbm.Description     = profitLossBillMaster.Description;
                    //pbm.IsActive = profitLossBillMaster.IsActive;
                    pbm.IsActive   = "1";
                    pbm.UpdateTime = DateTime.Now;

                    pbm.LockTag = string.Empty;
                    ProfitLossBillMasterRepository.SaveChanges();
                    result = true;
                }
            }
            else
            {
                result = false;
            }
            strResult = resultStr;
            return(result);
        }
        /// <summary>
        /// 新增损益单主单
        /// </summary>
        /// <param name="profitLossBillMaster">损益单主单</param>
        /// <param name="userName">用户名</param>
        /// <returns></returns>
        public bool Add(ProfitLossBillMaster profitLossBillMaster, string userName)
        {
            bool result   = false;
            var  pbm      = new ProfitLossBillMaster();
            var  employee = EmployeeRepository.GetQueryable().FirstOrDefault(i => i.UserName == userName);

            if (employee != null)
            {
                pbm.BillNo          = profitLossBillMaster.BillNo;
                pbm.BillDate        = profitLossBillMaster.BillDate;
                pbm.BillTypeCode    = profitLossBillMaster.BillTypeCode;
                pbm.WarehouseCode   = profitLossBillMaster.WarehouseCode;
                pbm.OperatePersonID = employee.ID;
                pbm.Status          = "1";
                pbm.VerifyPersonID  = profitLossBillMaster.VerifyPersonID;
                pbm.VerifyDate      = profitLossBillMaster.VerifyDate;
                pbm.Description     = profitLossBillMaster.Description;
                //pbm.IsActive = profitLossBillMaster.IsActive;
                pbm.IsActive   = "1";
                pbm.UpdateTime = DateTime.Now;

                ProfitLossBillMasterRepository.Add(pbm);
                ProfitLossBillMasterRepository.SaveChanges();
                result = true;
            }
            return(result);
        }
示例#7
0
        /// <summary>
        /// 查询损益单主单明细
        /// </summary>
        /// <param name="page"></param>
        /// <param name="rows"></param>
        /// <param name="BillNo">损益单号</param>
        /// <param name="BillDate">损益单日期</param>
        /// <param name="OperatePersonCode">操作员</param>
        /// <param name="Status">状态</param>
        /// <param name="IsActive">是否可用</param>
        /// <returns></returns>
        public object GetDetails(int page, int rows, string BillNo, string WareHouseCode, string BeginDate, string EndDate, string OperatePersonCode, string CheckPersonCode, string Status, string IsActive)
        {
            IQueryable <ProfitLossBillMaster> ProfitLossBillMasterQuery = ProfitLossBillMasterRepository.GetQueryable();
            var ProfitLossBillMaster = ProfitLossBillMasterQuery.Where(i => i.BillNo.Contains(BillNo) &&
                                                                       i.Status != "2" &&
                                                                       i.WarehouseCode.Contains(WareHouseCode) &&
                                                                       i.OperatePerson.EmployeeCode.Contains(OperatePersonCode) &&
                                                                       i.Status.Contains(Status))
                                       .OrderByDescending(t => t.BillDate)
                                       .OrderByDescending(t => t.BillNo)
                                       .Select(p => p);

            if (!BeginDate.Equals(string.Empty))
            {
                DateTime begin = Convert.ToDateTime(BeginDate);
                ProfitLossBillMaster = ProfitLossBillMaster.Where(i => i.BillDate >= begin);
            }

            if (!EndDate.Equals(string.Empty))
            {
                DateTime end = Convert.ToDateTime(EndDate).AddDays(1);
                ProfitLossBillMaster = ProfitLossBillMaster.Where(i => i.BillDate <= end);
            }

            if (!CheckPersonCode.Equals(string.Empty))
            {
                ProfitLossBillMaster = ProfitLossBillMaster.Where(i => i.VerifyPerson.EmployeeCode == CheckPersonCode);
            }

            int total = ProfitLossBillMaster.Count();

            ProfitLossBillMaster = ProfitLossBillMaster.Skip((page - 1) * rows).Take(rows);

            var temp = ProfitLossBillMaster.ToArray().AsEnumerable().Select(i => new
            {
                i.BillNo,
                BillDate = i.BillDate.ToString("yyyy-MM-dd HH:mm:ss"),
                i.OperatePersonID,
                i.WarehouseCode,
                i.BillTypeCode,
                i.BillType.BillTypeName,
                i.CheckBillNo,
                i.Warehouse.WarehouseName,
                OperatePersonCode = i.OperatePerson.EmployeeCode,
                OperatePersonName = i.OperatePerson.EmployeeName,
                VerifyPersonID    = i.VerifyPersonID == null ? string.Empty : i.VerifyPerson.EmployeeCode,
                VerifyPersonName  = i.VerifyPersonID == null ? string.Empty : i.VerifyPerson.EmployeeName,
                VerifyDate        = (i.VerifyDate == null ? "" : ((DateTime)i.VerifyDate).ToString("yyyy-MM-dd HH:mm:ss")),
                Status            = WhatStatus(i.Status),
                IsActive          = i.IsActive == "1" ? "可用" : "不可用",
                Description       = i.Description,
                UpdateTime        = i.UpdateTime.ToString("yyyy-MM-dd HH:mm:ss")
            });

            return(new { total, rows = temp.ToArray() });
        }
示例#8
0
        /// <summary>
        /// 新增损益单主单
        /// </summary>
        /// <param name="profitLossBillMaster">损益单主单</param>
        /// <param name="userName">用户名</param>
        /// <returns></returns>
        public bool Add(ProfitLossBillMaster profitLossBillMaster, string userName, out string strResult)
        {
            strResult = string.Empty;
            bool result   = false;
            var  pbm      = new ProfitLossBillMaster();
            var  employee = EmployeeRepository.GetQueryable().FirstOrDefault(i => i.UserName == userName);

            if (employee != null)
            {
                try
                {
                    pbm.BillNo          = profitLossBillMaster.BillNo;
                    pbm.BillDate        = profitLossBillMaster.BillDate;
                    pbm.BillTypeCode    = profitLossBillMaster.BillTypeCode;
                    pbm.WarehouseCode   = profitLossBillMaster.WarehouseCode;
                    pbm.OperatePersonID = employee.ID;
                    pbm.Status          = "1";
                    pbm.VerifyPersonID  = profitLossBillMaster.VerifyPersonID;
                    pbm.VerifyDate      = profitLossBillMaster.VerifyDate;
                    pbm.Description     = profitLossBillMaster.Description;
                    //pbm.IsActive = profitLossBillMaster.IsActive;
                    pbm.IsActive   = "1";
                    pbm.UpdateTime = DateTime.Now;

                    ProfitLossBillMasterRepository.Add(pbm);
                    ProfitLossBillMasterRepository.SaveChanges();
                    result = true;
                }
                catch (Exception ex)
                {
                    strResult = "新增失败,原因:" + ex.Message;
                }
            }
            else
            {
                strResult = "找不到当前登陆用户!请重新登陆!";
            }
            return(result);
        }
        /// <summary>
        /// 删除损益单主单
        /// </summary>
        /// <param name="BillNo">损益单号</param>
        /// <returns></returns>
        public bool Delete(string BillNo, out string strResult)
        {
            bool result = false;
            var  pbm    = ProfitLossBillMasterRepository.GetQueryable().FirstOrDefault(i => i.BillNo == BillNo && i.Status == "1");

            if (LockBillMaster(BillNo))
            {
                if (pbm != null)
                {
                    DeleteProfitLossBillDetail(pbm);
                    ProfitLossBillMasterRepository.Delete(pbm);
                    ProfitLossBillMasterRepository.SaveChanges();
                    result = true;
                }
            }
            else
            {
                result = false;
            }
            strResult = resultStr;
            return(result);
        }
示例#10
0
        /// <summary>
        /// 盘点确认
        /// </summary>
        /// <param name="billNo">单据号</param>
        /// <returns></returns>
        public bool confirmCheck(string billNo, string userName, out string errorInfo)
        {
            bool result = false;

            errorInfo = string.Empty;
            var checkbm     = CheckBillMasterRepository.GetQueryable().FirstOrDefault(i => i.BillNo == billNo);
            var checkDetail = CheckBillDetailRepository.GetQueryable().Where(c => c.BillNo == checkbm.BillNo &&
                                                                             c.ProductCode == c.RealProductCode &&
                                                                             c.Quantity != c.RealQuantity &&
                                                                             c.Status == "2");

            using (var scope = new TransactionScope())
            {
                try
                {
                    if (checkDetail.Count() > 0)
                    {
                        string billno = GenProfitLossBillNo(userName).ToString();
                        //添加损益主表
                        var pbm      = new ProfitLossBillMaster();
                        var employee = EmployeeRepository.GetQueryable().FirstOrDefault(i => i.UserName == userName);
                        if (employee != null)
                        {
                            pbm.BillNo          = billno;
                            pbm.BillDate        = DateTime.Now;
                            pbm.BillTypeCode    = "5002";
                            pbm.WarehouseCode   = checkbm.WarehouseCode;
                            pbm.OperatePersonID = employee.ID;
                            pbm.Status          = "1";
                            pbm.IsActive        = "1";
                            pbm.UpdateTime      = DateTime.Now;

                            ProfitLossBillMasterRepository.Add(pbm);
                            ProfitLossBillMasterRepository.SaveChanges();
                        }

                        //添加损益细表
                        foreach (var item in checkDetail.ToArray())
                        {
                            decimal differQuantity = item.RealQuantity - item.Quantity;        //损益数量
                            if (Locker.LockNoEmptyStorage(item.Storage, item.Product) != null) //锁库存
                            {
                                var pbd = new ProfitLossBillDetail();
                                pbd.BillNo      = billno;
                                pbd.CellCode    = item.CellCode;
                                pbd.StorageCode = item.StorageCode;
                                pbd.ProductCode = item.ProductCode;
                                pbd.UnitCode    = item.UnitCode;
                                pbd.Price       = item.Product != null ? item.Product.CostPrice : 0;
                                pbd.Quantity    = differQuantity;

                                if (differQuantity > 0)
                                {
                                    item.Storage.InFrozenQuantity += differQuantity;
                                }
                                else
                                {
                                    item.Storage.OutFrozenQuantity += Math.Abs(differQuantity);
                                }
                                ProfitLossBillDetailRepository.Add(pbd);
                                item.Storage.LockTag = string.Empty;
                                ProfitLossBillDetailRepository.SaveChanges();
                            }
                            scope.Complete();
                        }
                    }

                    var checkBillDetail = CheckBillDetailRepository.GetQueryable().Where(c => c.BillNo == checkbm.BillNo);//解锁盘点锁定
                    foreach (var item in checkBillDetail.ToArray())
                    {
                        item.Storage.IsLock = "0";
                    }
                    if (checkbm != null && checkbm.Status == "4")
                    {
                        checkbm.Status     = "5";
                        checkbm.VerifyDate = DateTime.Now;
                        checkbm.UpdateTime = DateTime.Now;
                        CheckBillMasterRepository.SaveChanges();
                        result = true;
                    }
                }
                catch (Exception e)
                {
                    errorInfo = "确认盘点损益失败!原因:" + e.Message;
                }
                scope.Complete();
            }
            return(result);
        }
示例#11
0
        public bool Add(DateTime datetime, out string strResult)
        {
            bool result = false;

            strResult = string.Empty;

            var profitLossBillMaster = ProfitLossBillMasterRepository.GetQueryable().Where(i => i.BillDate <= datetime);
            var profitLossBillDetail = ProfitLossBillDetailRepository.GetQueryable().Where(i => i.ProfitLossBillMaster.BillDate <= datetime);

            if (profitLossBillMaster.Any())
            {
                #region 主表移入历史表
                try
                {
                    foreach (var item in profitLossBillMaster.ToArray())
                    {
                        ProfitLossBillMasterHistory history = new ProfitLossBillMasterHistory();
                        history.BillNo          = item.BillNo;
                        history.BillDate        = item.BillDate;
                        history.BillTypeCode    = item.BillTypeCode;
                        history.CheckBillNo     = "";
                        history.WarehouseCode   = item.WarehouseCode;
                        history.Status          = item.Status;
                        history.VerifyPersonID  = item.VerifyPersonID;
                        history.VerifyDate      = item.VerifyDate;
                        history.Description     = item.Description;
                        history.IsActive        = item.IsActive;
                        history.UpdateTime      = item.UpdateTime;
                        history.OperatePersonID = item.OperatePersonID;
                        history.LockTag         = item.LockTag;
                        history.RowVersion      = item.RowVersion;
                        ProfitLossBillMasterHistoryRepository.Add(history);
                    }
                    result = true;
                }
                catch (Exception e)
                {
                    strResult = "主库单:" + e.InnerException.ToString();
                    result    = false;
                }
                #endregion

                if (profitLossBillDetail.Any())
                {
                    #region 细表移入历史表
                    try
                    {
                        foreach (var item in profitLossBillDetail.ToArray())
                        {
                            ProfitLossBillDetailHistory history = new ProfitLossBillDetailHistory();
                            history.BillNo      = item.BillNo;
                            history.CellCode    = item.CellCode;
                            history.StorageCode = item.StorageCode;
                            history.ProductCode = item.ProductCode;
                            history.UnitCode    = item.UnitCode;
                            history.Price       = item.Price;
                            history.Quantity    = item.Quantity;
                            history.Description = item.Description;
                            ProfitLossBillDetailHistoryRepository.Add(history);
                        }
                        result = true;
                    }
                    catch (Exception e)
                    {
                        strResult = "细库单:" + e.InnerException.ToString();;
                    }
                    #endregion
                }
                if (result == true)
                {
                    #region  除主细分配表
                    try
                    {
                        foreach (var item in profitLossBillMaster.ToList())
                        {
                            Del(ProfitLossBillDetailRepository, item.ProfitLossBillDetails);
                            ProfitLossBillMasterRepository.Delete(item);
                            result = true;
                        }
                    }
                    catch (Exception e)
                    {
                        strResult = "删除情况:" + e.InnerException.ToString();
                    }

                    ProfitLossBillMasterHistoryRepository.SaveChanges();
                    #endregion
                }
            }
            else
            {
                strResult = "数据不存在!";
            }
            return(result);
        }