public object SearchCheckBillDetail(string billNo, int page, int rows)
        {
            var allotQuery = CheckBillDetailRepository.GetQueryable();
            var query      = allotQuery.Where(a => a.BillNo == billNo && a.Status != "2")
                             .OrderByDescending(a => a.Status == "1").Select(i => i);
            int total = query.Count();

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

            var temp = query.ToArray().Select(a => new
            {
                a.ID,
                a.BillNo,
                a.ProductCode,
                a.Product.ProductName,
                a.CellCode,
                a.Cell.CellName,
                CellType = "盘点",
                a.StorageCode,
                a.UnitCode,
                a.Unit.UnitName,
                PieceQuantity = Math.Floor(a.RealQuantity / a.Product.UnitList.Unit01.Count),
                RealQuantity  = Math.Floor(a.RealQuantity % a.Product.UnitList.Unit01.Count / a.Product.UnitList.Unit02.Count),
                Status        = WhatStatus(a.Status),
                a.Operator
            });

            return(new { total, rows = temp.ToArray() });
        }
Exemple #2
0
        private bool FinishCheckBillTask(Task task)
        {
            var checkDetail = CheckBillDetailRepository.GetQueryable()
                              .Where(i => i.BillNo == task.OrderID &&
                                     i.ID == task.AllotID &&
                                     i.Status == "1")
                              .FirstOrDefault();

            if (checkDetail != null &&
                (checkDetail.CheckBillMaster.Status == "2" ||
                 checkDetail.CheckBillMaster.Status == "3"))
            {
                decimal quantity = checkDetail.Quantity;

                checkDetail.Status                 = "2";
                checkDetail.RealQuantity           = quantity;
                checkDetail.Storage.IsLock         = "0";
                checkDetail.CheckBillMaster.Status = "3";
                checkDetail.FinishTime             = DateTime.Now;
                if (checkDetail.CheckBillMaster.CheckBillDetails.All(c => c.Status == "2"))
                {
                    checkDetail.CheckBillMaster.Status = "4";
                }
                CheckBillDetailRepository.SaveChanges();
                return(true);
            }
            else
            {
                //"需确认盘点的数据查询为空或者主单状态不对,完成出错!";
                return(false);
            }
        }
        public bool EditDetail(string id, string status, string operater, out string strResult)
        {
            strResult = string.Empty;
            bool result = false;

            string[]        ids    = id.Split(',');
            string          strId  = "";
            CheckBillDetail detail = null;

            var employee = EmployeeRepository.GetQueryable().FirstOrDefault(e => e.UserName == operater);

            for (int i = 0; i < ids.Length; i++)
            {
                strId  = ids[i].ToString();
                detail = CheckBillDetailRepository.GetQueryable().ToArray().FirstOrDefault(a => strId == a.ID.ToString());
                if (detail != null)
                {
                    if (detail.Status == "0" && status == "1" ||
                        detail.Status == "1" && status == "0" ||
                        detail.Status == "1" && status == "2")
                    {
                        try
                        {
                            detail.Status = status;
                            if (operater != "")
                            {
                                detail.Operator = employee.EmployeeName;
                            }
                            else
                            {
                                detail.Operator = "";
                            }
                            CheckBillDetailRepository.SaveChanges();
                            result = true;
                        }
                        catch (Exception ex)
                        {
                            strResult = "原因:" + ex.Message;
                        }
                    }
                    else
                    {
                        strResult = "原因:操作错误!";
                    }
                }
                else
                {
                    strResult = "原因:未找到该记录!";
                }
            }
            return(result);
        }
        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);
        }
        public object GetDetails(int page, int rows, string BillNo)
        {
            IQueryable <CheckBillDetail> checkBillDetailQuery = CheckBillDetailRepository.GetQueryable();

            if (BillNo != null && BillNo != string.Empty)
            {
                var checkBillDetail = checkBillDetailQuery.Where(i => i.BillNo.Contains(BillNo)).OrderBy(i => i.BillNo).Select(i => i);
                int total           = checkBillDetail.Count();
                checkBillDetail = checkBillDetail.Skip((page - 1) * rows).Take(rows);

                var temp = checkBillDetail.ToArray().AsEnumerable().Select(i => new
                {
                    i.ID,
                    i.BillNo,
                    i.Cell.CellCode,
                    i.Cell.CellName,
                    i.StorageCode,
                    i.Product.ProductCode,
                    i.Product.ProductName,
                    i.Unit.UnitCode,
                    i.Unit.UnitName,
                    Quantity          = i.Quantity / i.Unit.Count,
                    RealProductCode   = i.RealProduct.ProductCode,
                    RealProductName   = i.RealProduct.ProductName,
                    RealUnitCode      = i.RealUnit.UnitCode,
                    RealUnitName      = i.RealUnit.UnitName,
                    OperatePersonCode = i.OperatePersonID == null ? string.Empty : i.OperatePerson.EmployeeCode,
                    OperatePersonName = i.OperatePersonID == null ? string.Empty : i.OperatePerson.EmployeeName,
                    StartTime         = i.StartTime == null ? string.Empty : i.StartTime.ToString(),
                    FinishTime        = i.FinishTime == null ? string.Empty : i.FinishTime.ToString(),
                    Status            = WhatStatus(i.Status)
                });
                return(new { total, rows = temp.ToArray() });
            }
            return("");
        }
        /// <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);
        }
        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);
        }
        /// <summary>获得盘点细单信息</summary>
        public System.Data.DataTable GetCheckBillDetail(int page, int rows, string BillNo)
        {
            System.Data.DataTable        dt = new System.Data.DataTable();
            IQueryable <CheckBillDetail> checkBillDetailQuery = CheckBillDetailRepository.GetQueryable();

            if (BillNo != null && BillNo != string.Empty)
            {
                var checkBillDetail = checkBillDetailQuery.Where(i => i.BillNo.Contains(BillNo)).OrderBy(i => i.BillNo).Select(i => new
                {
                    i.BillNo,
                    i.Cell.CellCode,
                    i.Cell.CellName,
                    i.StorageCode,
                    i.Product.ProductCode,
                    i.Product.ProductName,
                    i.Unit.UnitCode,
                    i.Unit.UnitName,
                    Quantity          = i.Quantity / i.Unit.Count,
                    RealProductCode   = i.RealProduct.ProductCode,
                    RealProductName   = i.RealProduct.ProductName,
                    RealUnitCode      = i.RealUnit.UnitCode,
                    RealUnitName      = i.RealUnit.UnitName,
                    OperatePersonCode = i.OperatePersonID == null ? string.Empty : i.OperatePerson.EmployeeCode,
                    OperatePersonName = i.OperatePersonID == null ? string.Empty : i.OperatePerson.EmployeeName,
                    i.StartTime,
                    i.FinishTime,
                    Status = i.Status == "0" ? "未开始" : i.Status == "1" ? "已申请" : i.Status == "2" ? "已完成" : "空"
                });
                dt.Columns.Add("盘点单号", typeof(string));
                //dt.Columns.Add("货位编码", typeof(string));
                dt.Columns.Add("货位名称", typeof(string));
                //dt.Columns.Add("储存名称", typeof(string));
                dt.Columns.Add("产品编码", typeof(string));
                dt.Columns.Add("产品名称", typeof(string));
                dt.Columns.Add("单位编码", typeof(string));
                dt.Columns.Add("单位名称", typeof(string));
                dt.Columns.Add("数量", typeof(string));
                dt.Columns.Add("作业人员", typeof(string));
                dt.Columns.Add("开始时间", typeof(string));
                dt.Columns.Add("结束时间", typeof(string));
                dt.Columns.Add("完成状态", typeof(string));
                foreach (var c in checkBillDetail)
                {
                    dt.Rows.Add
                    (
                        c.BillNo
                        //, c.CellCode
                        , c.CellName
                        //, c.StorageCode
                        , c.ProductCode
                        , c.ProductName
                        , c.UnitCode
                        , c.UnitName
                        , c.Quantity
                        , c.OperatePersonName
                        , c.StartTime
                        , c.FinishTime
                        , c.Status
                    );
                }
            }
            return(dt);
        }