Exemplo n.º 1
0
        public object GetCheckBillMaster()
        {
            var checkBillMaster = CheckBillMasterRepository.GetQueryable()
                                  .Where(i => i.Status == "2" || i.Status == "3")
                                  .Select(i => new { BillNo = i.BillNo, BillType = "4" })
                                  .ToArray();

            return(checkBillMaster);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 盘点反审
        /// </summary>
        /// <param name="billNo">单据号</param>
        /// <returns></returns>
        public bool AntiTrial(string billNo)
        {
            bool result = false;
            var  outbm  = CheckBillMasterRepository.GetQueryable().FirstOrDefault(i => i.BillNo == billNo);

            if (outbm != null && outbm.Status == "2")
            {
                outbm.Status         = "1";
                outbm.VerifyDate     = null;
                outbm.UpdateTime     = DateTime.Now;
                outbm.VerifyPersonID = null;
                CheckBillMasterRepository.SaveChanges();
                result = true;
            }
            return(result);
        }
Exemplo n.º 3
0
        public bool Delete(string BillNo)
        {
            var checkbm = CheckBillMasterRepository.GetQueryable().FirstOrDefault(i => i.BillNo == BillNo && i.Status == "1");

            if (checkbm != null)
            {
                //Del(OutBillDetailRepository, ibm.OutBillAllots);
                foreach (var item in checkbm.CheckBillDetails.ToArray())
                {
                    item.Storage.IsLock = "0";
                }
                Del(CheckBillDetailRepository, checkbm.CheckBillDetails);
                CheckBillMasterRepository.Delete(checkbm);
                CheckBillMasterRepository.SaveChanges();
            }
            return(true);
        }
Exemplo n.º 4
0
        public object GetCheckBillMaster()
        {
            string str             = "";
            var    checkBillDetail = CheckBillDetailRepository.GetQueryable().Where(i => i.Status != "2").Select(b => b.BillNo).ToArray();

            for (int i = 0; i < checkBillDetail.Length; i++)
            {
                str += checkBillDetail[i];
            }
            var checkBillMaster = CheckBillMasterRepository.GetQueryable().ToArray().Where(i => str.Contains(i.BillNo) && i.Status != "5")
                                  .Distinct()
                                  .OrderByDescending(t => t.BillDate)
                                  .Select(i => new
            {
                BillNo = i.BillNo
            });

            return(checkBillMaster);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 盘点审核
        /// </summary>
        /// <param name="billNo">单据号</param>
        /// <param name="userName">登陆用户</param>
        /// <returns></returns>
        public bool Audit(string billNo, string userName)
        {
            bool result   = false;
            var  checkbm  = CheckBillMasterRepository.GetQueryable().FirstOrDefault(i => i.BillNo == billNo);
            var  employee = EmployeeRepository.GetQueryable().FirstOrDefault(i => i.UserName == userName);

            if (employee != null)
            {
                if (checkbm != null && checkbm.Status == "1")
                {
                    checkbm.Status         = "2";
                    checkbm.VerifyDate     = DateTime.Now;
                    checkbm.UpdateTime     = DateTime.Now;
                    checkbm.VerifyPersonID = employee.ID;
                    CheckBillMasterRepository.SaveChanges();
                    result = true;
                }
            }
            return(result);
        }
Exemplo n.º 6
0
        public bool Delete(string billNo)
        {
            var checkbm = CheckBillMasterRepository.GetQueryable().FirstOrDefault(i => i.BillNo == billNo && i.Status == "1");

            if (checkbm != null)
            {
                foreach (var item in checkbm.CheckBillDetails.ToArray())
                {
                    item.Storage.IsLock = "0";
                }
                using (var scope = new TransactionScope())
                {
                    CheckBillMasterRepository.SaveChanges();
                    CheckBillDetailRepository.GetObjectSet().DeleteEntity(d => d.BillNo == billNo);
                    CheckBillMasterRepository.GetObjectSet().DeleteEntity(c => c.BillNo == billNo);
                    scope.Complete();
                }
            }
            return(true);
        }
Exemplo n.º 7
0
        /// <summary>
        /// 生成盘点的主表ID
        /// </summary>
        /// <returns></returns>
        public object GetCheckBillNo()
        {
            IQueryable <CheckBillMaster> CheckMasterQuery = CheckBillMasterRepository.GetQueryable();
            string sysTime      = System.DateTime.Now.ToString("yyMMdd");
            var    inBillMaster = CheckMasterQuery.Where(i => i.BillNo.Contains(sysTime)).ToArray().OrderBy(i => i.BillNo).Select(i => new { i.BillNo }.BillNo);

            if (inBillMaster.Count() == 0)
            {
                return(System.DateTime.Now.ToString("yyMMdd") + "0001" + "CH");
            }
            else
            {
                string billNoStr = inBillMaster.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;
                }
                return(System.DateTime.Now.ToString("yyMMdd") + newcode + "CH");
            }
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
0
        public object GetDetails(int page, int rows, string BillNo, string beginDate, string endDate, string OperatePersonCode, string CheckPersonCode, string Status, string IsActive)
        {
            IQueryable <CheckBillMaster> CheckBillMasterQuery = CheckBillMasterRepository.GetQueryable();
            //var checkBillMasters = CheckBillMasterQuery.Where(i => i.BillNo.Contains(BillNo) && i.OperatePerson.EmployeeName.Contains(OperatePersonCode));
            var checkBillMasters = CheckBillMasterQuery.Where(i => i.BillNo.Contains(BillNo) &&
                                                              i.Status != "5")
                                   .OrderByDescending(t => t.BillDate)
                                   .OrderByDescending(t => t.BillNo)
                                   .Select(i => i);

            if (!BillNo.Equals(string.Empty) && BillNo != null)
            {
                checkBillMasters = checkBillMasters.Where(i => i.BillNo.Contains(BillNo));
            }
            if (!beginDate.Equals(string.Empty))
            {
                DateTime begin = Convert.ToDateTime(beginDate);
                checkBillMasters = checkBillMasters.Where(i => Convert.ToDateTime(i.BillDate) >= begin);
            }
            if (!endDate.Equals(string.Empty))
            {
                DateTime end = Convert.ToDateTime(endDate);
                checkBillMasters = checkBillMasters.Where(i => Convert.ToDateTime(i.BillDate) <= end);
            }
            if (!OperatePersonCode.Equals(string.Empty) && OperatePersonCode != null)
            {
                checkBillMasters = checkBillMasters.Where(i => i.OperatePerson.EmployeeCode.Contains(OperatePersonCode));
            }
            if (!Status.Equals(string.Empty))
            {
                checkBillMasters = checkBillMasters.Where(i => i.Status.Contains(Status));
            }
            if (!IsActive.Equals(string.Empty))
            {
                checkBillMasters = checkBillMasters.Where(i => i.IsActive.Contains(IsActive));
            }
            if (!CheckPersonCode.Equals(string.Empty))
            {
                checkBillMasters = checkBillMasters.Where(i => i.VerifyPerson.EmployeeCode == CheckPersonCode);
            }

            int total = checkBillMasters.Count();

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

            var temp = checkBillMasters.ToArray().AsEnumerable().Select(i => new
            {
                i.BillNo,
                BillDate = i.BillDate.ToString("yyyy-MM-dd hh:mm:ss"),
                i.Warehouse.WarehouseCode,
                i.Warehouse.WarehouseName,
                OperatePersonCode = i.OperatePerson.EmployeeCode,
                OperatePersonName = i.OperatePerson.EmployeeName,
                VerifyPersonCode  = i.VerifyPersonID == null ? string.Empty : i.VerifyPerson.EmployeeCode,
                VerifyPersonName  = i.VerifyPersonID == null ? string.Empty : i.VerifyPerson.EmployeeName,
                BillTypeCode      = i.BillType.BillTypeCode,
                BillTypeName      = i.BillType.BillTypeName,
                VerifyDate        = i.VerifyDate == null ? string.Empty : ((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() });
        }
Exemplo n.º 10
0
        public bool Add(DateTime datetime, out string strResult)
        {
            bool result = false;

            strResult = string.Empty;

            var checkBillMaster = CheckBillMasterRepository.GetQueryable().Where(i => i.BillDate <= datetime);
            var checkBillDetail = CheckBillDetailRepository.GetQueryable().Where(i => i.CheckBillMaster.BillDate <= datetime);

            if (checkBillMaster.Any())
            {
                #region 主表移入历史表
                try
                {
                    foreach (var item in checkBillMaster.ToArray())
                    {
                        CheckBillMasterHistory history = new CheckBillMasterHistory();

                        history.BillNo          = item.BillNo;
                        history.BillDate        = item.BillDate;
                        history.BillTypeCode    = item.BillTypeCode;
                        history.WarehouseCode   = item.WarehouseCode;
                        history.OperatePersonID = item.OperatePersonID;
                        history.Status          = item.Status;
                        history.VerifyPersonID  = item.VerifyPersonID;
                        history.VerifyDate      = item.VerifyDate;
                        history.Description     = item.Description;
                        history.IsActive        = item.IsActive;
                        history.UpdateTime      = item.UpdateTime;

                        CheckBillMasterHistoryRepository.Add(history);
                    }
                    result = true;
                }
                catch (Exception e)
                {
                    strResult = "主库单:" + e.InnerException.ToString();
                    result    = false;
                }
                #endregion

                if (checkBillDetail.Any())
                {
                    #region 细表移入历史表
                    try
                    {
                        foreach (var item in checkBillDetail.ToArray())
                        {
                            CheckBillDetailHistory history = new CheckBillDetailHistory();
                            history.BillNo          = item.BillNo;
                            history.CellCode        = item.CellCode;
                            history.StorageCode     = item.StorageCode;
                            history.ProductCode     = item.ProductCode;
                            history.UnitCode        = item.UnitCode;
                            history.Quantity        = item.Quantity;
                            history.RealProductCode = item.ProductCode;
                            history.RealUnitCode    = item.RealUnitCode;
                            history.RealQuantity    = item.Quantity;
                            history.Status          = item.Status;

                            CheckBillDetailHistoryRepository.Add(history);
                        }
                        result = true;
                    }
                    catch (Exception e)
                    {
                        strResult = "细库单:" + e.InnerException.ToString();;
                    }
                    #endregion
                }
                if (result == true)
                {
                    #region  除主细分配表
                    try
                    {
                        foreach (var item in checkBillMaster.ToList())
                        {
                            Del(CheckBillDetailRepository, item.CheckBillDetails);
                            CheckBillMasterRepository.Delete(item);
                            result = true;
                        }
                    }
                    catch (Exception e)
                    {
                        strResult = "删除情况:" + e.InnerException.ToString();
                    }
                    CheckBillMasterHistoryRepository.SaveChanges();
                    #endregion
                }
            }
            else
            {
                strResult = "数据不存在!";
            }
            return(result);
        }