Esempio n. 1
0
        public static void ReSaveStock(string storeId, string checkBatch, string checkUID, string barcode, decimal?number, short sure)
        {
            if (string.IsNullOrWhiteSpace(storeId))
            {
                throw new MessageException("门店号为空!");
            }
            if (string.IsNullOrWhiteSpace(checkBatch))
            {
                throw new MessageException("盘点批次为空!");
            }
            if (string.IsNullOrWhiteSpace(checkUID))
            {
                throw new MessageException("盘点员为空!");
            }
            if (string.IsNullOrWhiteSpace(barcode))
            {
                throw new MessageException("条码为空!");
            }
            if (!number.HasValue)
            {
                throw new MessageException("实盘数量为空!");
            }

            var query = from a in BaseService <StockTaking> .CurrentRepository.QueryEntity
                        join b in BaseService <TreasuryLocks> .CurrentRepository.QueryEntity on new { a.CheckBatch, a.CompanyId } equals new { b.CheckBatch, b.CompanyId }
            where a.CompanyId == Sys.SysCommonRules.CompanyId && b.LockStoreID == storeId && a.CheckBatch == checkBatch && a.Barcode == barcode
            select new
            {
                a,
                a.Barcode,
                a.ActualNumber,
                a.CheckBatch,
                b.State,
                a.CompanyId,
                SysPrice = ProductService.CurrentRepository.QueryEntity.Where(o => o.CompanyId == a.CompanyId &&
                                                                              (o.Barcode == a.Barcode || ("," + o.Barcodes + ",").Contains("," + a.Barcode + ","))).Select(o => o.SysPrice).FirstOrDefault()
            };
            var stock = query.FirstOrDefault();

            if (stock == null)
            {
                throw new MessageException("批次或条码不存在!");
            }
            if (stock.State == 1)
            {
                throw new MessageException("该批次已通过审核,不能再盘点!");
            }

            var user = UserInfoService.Find(o => o.CompanyId == Sys.SysCommonRules.CompanyId && o.UserCode == checkUID);

            if (user == null)
            {
                throw new MessageException("用户编码不存在!");
            }
            stock.a.Sure = (short)(sure == 0?0:1);
            //var st= BaseService<StockTaking>.Find(o => o.CompanyId == stock.CompanyId && o.CheckBatch == stock.CheckBatch && o.Barcode == stock.Barcode);
            var log = new StockTakingLog()
            {
                Barcode    = stock.Barcode,
                CheckBatch = stock.CheckBatch,
                CheckUID   = user.UID,
                CreateUID  = user.UID,
                CreateDT   = DateTime.Now,
                ActualDate = DateTime.Now,
                SysPrice   = stock.SysPrice,
                Number     = number.GetValueOrDefault(),
                State      = 1,
                Source     = 2,
                CompanyId  = Sys.SysCommonRules.CompanyId
            };

            BaseService <StockTakingLog> .Add(log);
        }
Esempio n. 2
0
        public static void SaveStock(string storeId, string checkBatch, string checkUID, Dictionary <string, decimal?> barnums)
        {
            if (string.IsNullOrWhiteSpace(storeId))
            {
                throw new MessageException("门店号为空!");
            }
            if (string.IsNullOrWhiteSpace(checkBatch))
            {
                throw new MessageException("盘点批次为空!");
            }
            if (string.IsNullOrWhiteSpace(checkUID))
            {
                throw new MessageException("盘点员为空!");
            }
            if (!barnums.Any())
            {
                throw new MessageException("盘点内容为空!");
            }

            var barcodes = barnums.Keys.ToList();
            var query    = from a in BaseService <StockTaking> .CurrentRepository.QueryEntity
                           join b in BaseService <TreasuryLocks> .CurrentRepository.QueryEntity on new { a.CheckBatch, a.CompanyId } equals new { b.CheckBatch, b.CompanyId }
            where a.CompanyId == Sys.SysCommonRules.CompanyId && b.LockStoreID == storeId && a.CheckBatch == checkBatch && barcodes.Contains(a.Barcode)
            select new
            {
                a.Barcode,
                a.ActualNumber,
                a.CheckBatch,
                b.State,
                SysPrice = ProductService.CurrentRepository.QueryEntity.Where(o => o.CompanyId == a.CompanyId &&
                                                                              (o.Barcode == a.Barcode || ("," + o.Barcodes + ",").Contains("," + a.Barcode + ","))).Select(o => o.SysPrice).FirstOrDefault()
            };
            var stocks = query.ToList();

            if (!stocks.Any())
            {
                throw new MessageException("批次或条码不存在!");
            }
            if (stocks.Any(o => o.State == 1))
            {
                throw new MessageException("该批次已通过审核,不能再盘点!");
            }
            var user = UserInfoService.Find(o => o.CompanyId == Sys.SysCommonRules.CompanyId && o.UserCode == checkUID);

            if (user == null)
            {
                throw new MessageException("用户编码不存在!");
            }
            var stocklogs = BaseService <StockTakingLog> .FindList(o => o.CompanyId == Sys.SysCommonRules.CompanyId && barcodes.Contains(o.Barcode) && o.CheckBatch == checkBatch && o.State == 1);

            var insertLog = new List <StockTakingLog>();
            var date      = DateTime.Now;

            foreach (var de in barnums)
            {
                var sk = stocks.FirstOrDefault(o => o.Barcode == de.Key);
                if (sk == null)
                {
                    throw new MessageException("条码[" + de.Key + "]不存在!");
                }
                if (stocklogs.Any(o => o.Barcode == de.Key))
                {
                    throw new MessageException("条码[" + de.Key + "]条码已复盘!");
                }
                if (!de.Value.HasValue)
                {
                    continue;
                }
                insertLog.Add(new StockTakingLog()
                {
                    Barcode    = sk.Barcode,
                    CheckBatch = sk.CheckBatch,
                    CheckUID   = user.UID,
                    CreateDT   = date,
                    CreateUID  = user.UID,
                    ActualDate = date,
                    Number     = de.Value.Value,
                    SysPrice   = sk.SysPrice,
                    Source     = 2,
                    CompanyId  = Sys.SysCommonRules.CompanyId
                });
            }
            if (insertLog.Any())
            {
                BaseService <StockTakingLog> .AddRange(insertLog);
            }
        }