Exemplo n.º 1
0
        /// <summary>
        /// 获取批次
        /// </summary>
        /// <param name="storeId">门店</param>
        /// <returns></returns>
        public static string GetBatchAndCategory(string storeId)
        {
            var obj    = WarehouseService.Find(o => o.StoreId == storeId && o.CompanyId == CommonService.CompanyId);
            var prefix = obj.StoreId.PadLeft(2, '0') + DateTime.Now.ToString("yyMMdd");
            var max    = BaseService <TreasuryLocks> .CurrentRepository.QueryEntity.Where(o => o.CheckBatch.StartsWith(prefix) && o.CompanyId == CommonService.CompanyId).Max(o => o.CheckBatch);

            var sns   = obj.CategorySN.Split(',').Where(o => !o.IsNullOrEmpty()).Select(o => int.Parse(o)).ToList();
            var items = ProductCategoryService.GetParentCategorys(false).Select(o => new DropdownItem(o.CategorySN.ToString(), o.Title)).ToList();

            items.Insert(0, new DropdownItem("", "请选择"));
            int num = 1;

            if (!max.IsNullOrEmpty())
            {
                num = int.Parse(max.Replace(prefix, "")) + 1;
            }
            var msg  = new Pharos.Logic.DAL.CommonDAL().StockLockValidMsg(storeId);
            var item = new { batch = prefix + num.ToString("00"), items = items, msg = msg };

            return(item.ToJson());
        }
Exemplo n.º 2
0
        /// <summary>
        /// 适用门店名称
        /// </summary>
        /// <param name="storeId"></param>
        /// <returns></returns>
        public static string GetStoreTitleList(string storeId)
        {
            string storeTitleList = "", storeTitle = "";

            string[] arr = storeId.Split(',');
            for (int i = 0; i < arr.Length; i++)
            {
                if (arr[0] == "")
                {
                    storeTitleList = "全部";
                    break;
                }
                else
                {
                    if (!string.IsNullOrEmpty(arr[i]))
                    {
                        var sId = arr[i];
                        storeTitle = WarehouseService.Find(o => o.CompanyId == CommonService.CompanyId && o.StoreId == sId).Title;
                    }
                    storeTitleList += i > 0 ? ("、" + storeTitle) : storeTitle;
                }
            }
            return(storeTitleList);
        }
Exemplo n.º 3
0
        public static OpResult OutboundImport(ImportSet obj, System.Web.HttpFileCollectionBase httpFiles, string fieldName, string columnName)
        {
            var op    = new OpResult();
            var errLs = new List <string>();
            int count = 0;
            var list  = new List <OutboundList>();

            try
            {
                Dictionary <string, char> fieldCols = null;
                DataTable dt = null;
                op = ImportSetService.ImportSet(obj, httpFiles, fieldName, columnName, ref fieldCols, ref dt);
                if (!op.Successed)
                {
                    return(op);
                }
                var storeId  = System.Web.HttpContext.Current.Request["StoreId"];
                var products = new List <VwProduct>();
                if (!storeId.IsNullOrEmpty())
                {
                    var ware = WarehouseService.Find(o => o.StoreId == storeId && o.CompanyId == CommonService.CompanyId);
                    if (ware != null)
                    {
                        var categorySNs = ware.CategorySN.Split(',').Select(o => int.Parse(o)).ToList();
                        var childs      = ProductCategoryService.GetChildSNs(categorySNs);
                        var pros        = BaseService <VwProduct> .FindList(o => o.CompanyId == CommonService.CompanyId && childs.Contains(o.CategorySN));

                        products.AddRange(pros);
                    }
                }
                var barcodeIdx  = fieldCols.GetValue("Barcode").ToType <int>() - 65;
                var outPriceIdx = fieldCols.GetValue("OutPrice").ToType <int>() - 65;
                var numberIdx   = fieldCols.GetValue("OutboundNumber").ToType <int>() - 65;
                var memoIdx     = fieldCols.GetValue("Memo").ToType <int>() - 65;
                count = dt.Rows.Count;
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    var pos     = i + obj.MinRow;
                    var dr      = dt.Rows[i];
                    var barcode = dr.GetValue(barcodeIdx).ToString().Trim();
                    if (barcode.IsNullOrEmpty())
                    {
                        errLs.Add("行号[" + pos + "]条码为空!");
                        continue;
                    }
                    var pro = products.FirstOrDefault(o => o.Barcode == barcode || ("," + o.Barcodes + ",").Contains("," + barcode + ","));
                    if (pro == null)
                    {
                        errLs.Add("行号[" + pos + "]该门店下无此条码!");
                        continue;
                    }
                    var outPrice = dr.GetValue(outPriceIdx).ToType <decimal?>();
                    if (!outPrice.HasValue && outPriceIdx >= 0)
                    {
                        errLs.Add("行号[" + pos + "]该条码价格为空!");
                        continue;
                    }
                    var number = dr.GetValue(numberIdx).ToType <decimal?>();
                    if (!number.HasValue)
                    {
                        errLs.Add("行号[" + pos + "]该条码出库数量为空!");
                        continue;
                    }

                    list.Add(new OutboundList()
                    {
                        Barcode        = barcode,
                        ProductTitle   = pro.Title,
                        BuyPrice       = pro.BuyPrice,
                        OutboundNumber = number.Value,
                        Unit           = pro.SubUnit,
                        SysPrice       = pro.SysPrice,
                        OutPrice       = outPrice ?? pro.SysPrice,
                        Memo           = dr.GetValue(memoIdx).ToString()
                    });
                }
            }
            catch (Exception ex)
            {
                op.Message   = ex.Message;
                op.Successed = false;
                Log.WriteError(ex);
                errLs.Add("导入出现异常!");
            }
            return(CommonService.GenerateImportHtml(errLs, count, data: list, isSuccess: false));
        }
Exemplo n.º 4
0
        public static OpResult InboundImport(ImportSet obj, System.Web.HttpFileCollectionBase httpFiles, string fieldName, string columnName)
        {
            var op    = new OpResult();
            var errLs = new List <string>();
            int count = 0;
            var list  = new List <InboundList>();

            try
            {
                Dictionary <string, char> fieldCols = null;
                DataTable dt = null;
                op = ImportSetService.ImportSet(obj, httpFiles, fieldName, columnName, ref fieldCols, ref dt);
                if (!op.Successed)
                {
                    return(op);
                }
                var supplierId       = System.Web.HttpContext.Current.Request["SupplierID"];
                var storeId          = System.Web.HttpContext.Current.Request["StoreId"];
                var supplierBarcodes = new List <string>();
                var storeBarcodes    = new List <string>();
                var products         = new List <VwProduct>();
                if (!supplierId.IsNullOrEmpty())
                {
                    var bars = BaseService <ProductMultSupplier> .FindList(o => o.SupplierId == supplierId).Select(o => o.Barcode).Distinct().ToList();

                    var pros = BaseService <VwProduct> .FindList(o => o.SupplierId == supplierId || bars.Contains(o.Barcode));

                    products.AddRange(pros);
                    supplierBarcodes = pros.Select(o => o.Barcode).ToList();
                    supplierBarcodes.AddRange(pros.Where(o => !o.Barcodes.IsNullOrEmpty()).SelectMany(o => o.Barcodes.Split(',')));
                }
                if (!storeId.IsNullOrEmpty())
                {
                    var ware = WarehouseService.Find(o => o.StoreId == storeId && o.CompanyId == CommonService.CompanyId);
                    if (ware != null)
                    {
                        var categorySNs = ware.CategorySN.Split(',').Select(o => int.Parse(o)).ToList();
                        var childs      = ProductCategoryService.GetChildSNs(categorySNs);
                        var pros        = BaseService <VwProduct> .FindList(o => o.CompanyId == CommonService.CompanyId && childs.Contains(o.CategorySN));

                        storeBarcodes = pros.Select(o => o.Barcode).ToList();
                        storeBarcodes.AddRange(pros.Where(o => !o.Barcodes.IsNullOrEmpty()).SelectMany(o => o.Barcodes.Split(',')));
                        products.AddRange(pros);
                    }
                }
                var barcodeIdx  = fieldCols.GetValue("Barcode").ToType <int>() - 65;
                var buyPriceIdx = fieldCols.GetValue("BuyPrice").ToType <int>() - 65;
                var numberIdx   = fieldCols.GetValue("InboundNumber").ToType <int>() - 65;
                var proDateIdx  = fieldCols.GetValue("ProducedDate").ToType <int>() - 65;
                var giftIdx     = fieldCols.GetValue("IsGift").ToType <int>() - 65;
                var memoIdx     = fieldCols.GetValue("Memo").ToType <int>() - 65;
                count = dt.Rows.Count;
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    var pos     = i + obj.MinRow;
                    var dr      = dt.Rows[i];
                    var barcode = dr.GetValue(barcodeIdx).ToString().Trim();
                    if (barcode.IsNullOrEmpty())
                    {
                        errLs.Add("行号[" + pos + "]条码为空!");
                        continue;
                    }
                    if (!supplierBarcodes.Any(o => o == barcode))
                    {
                        errLs.Add("行号[" + pos + "]该供应单位下无此条码!");
                        continue;
                    }
                    if (!storeBarcodes.Any(o => o == barcode))
                    {
                        errLs.Add("行号[" + pos + "]该门店下无此条码!");
                        continue;
                    }
                    var buyPrice = dr.GetValue(buyPriceIdx).ToType <decimal?>();
                    if (!buyPrice.HasValue)
                    {
                        errLs.Add("行号[" + pos + "]该条码进价为空!");
                        continue;
                    }
                    var number = dr.GetValue(numberIdx).ToType <decimal?>();
                    if (!number.HasValue)
                    {
                        errLs.Add("行号[" + pos + "]该条码入库数量为空!");
                        continue;
                    }
                    var      gift    = dr.GetValue(giftIdx).ToString();
                    var      proDate = dr.GetValue(proDateIdx).ToString().Trim();
                    DateTime t       = DateTime.Now;
                    if (!proDate.IsNullOrEmpty() && DateTime.TryParse(proDate, out t))
                    {
                        proDate = t.ToString("yyyy-MM-dd");
                    }
                    else
                    {
                        proDate = string.Empty;
                    }
                    var pro = products.FirstOrDefault(o => o.Barcode == barcode || ("," + o.Barcodes + ",").Contains("," + barcode + ","));
                    list.Add(new InboundList()
                    {
                        Barcode       = barcode,
                        ProductTitle  = pro.Title,
                        BuyPrice      = buyPrice.Value,
                        InboundNumber = number.Value,
                        Unit          = pro.SubUnit,
                        ProducedDate  = proDate,
                        SysPrice      = pro.SysPrice,
                        Memo          = dr.GetValue(memoIdx).ToString(),
                        IsGift        = (short)(gift == "赠品"?1:0)
                    });
                }
            }
            catch (Exception ex)
            {
                op.Message   = ex.Message;
                op.Successed = false;
                Log.WriteError(ex);
                errLs.Add("导入出现异常!");
            }
            return(CommonService.GenerateImportHtml(errLs, count, data: list, isSuccess: false));
        }
Exemplo n.º 5
0
        /// <summary>
        /// 库存查询列表
        /// </summary>
        /// <param name="nvl"></param>
        /// <param name="recordCount"></param>
        /// <returns></returns>
        public static DataTable QueryInventoryPageList(NameValueCollection nvl, out int recordCount, ref object footer)
        {
            var nl = new NameValueCollection()
            {
                nvl
            };
            DataTable dt = null;

            if (Sys.CurrentUser.IsStore)
            {
                nl["store"] = Sys.CurrentUser.StoreId;
                var store  = WarehouseService.Find(o => o.CompanyId == CommonService.CompanyId && o.StoreId == Sys.CurrentUser.StoreId);
                var childs = ProductCategoryService.GetChildSNs(store.CategorySN.Split(',').Select(o => int.Parse(o)).ToList(), true);
                if (!nl["parentType"].IsNullOrEmpty())
                {
                    var childs2 = ProductCategoryService.GetChildSNs(new List <int>()
                    {
                        int.Parse(nl["parentType"])
                    }, true);
                    childs = childs.Where(o => childs2.Contains(o)).ToList();
                }
                nl["parentType"] = childs.Any() ? string.Join(",", childs) : "";
                //dt = dal.QueryStoreInventorys(nl, out recordCount);
                dt = dal.QueryInventorys(nl);
            }
            else
            {
                if (!nl["store"].IsNullOrEmpty())
                {
                    var storeId = nl["store"];
                    var store   = WarehouseService.Find(o => o.CompanyId == CommonService.CompanyId && o.StoreId == storeId);
                    var childs  = ProductCategoryService.GetChildSNs(store.CategorySN.Split(',').Select(o => int.Parse(o)).ToList(), true);
                    if (!nl["parentType"].IsNullOrEmpty())
                    {
                        var childs2 = ProductCategoryService.GetChildSNs(new List <int>()
                        {
                            int.Parse(nl["parentType"])
                        }, true);
                        childs = childs.Where(o => childs2.Contains(o)).ToList();
                    }
                    nl["parentType"] = childs.Any() ? string.Join(",", childs) : "0";
                }
                else if (!nl["parentType"].IsNullOrEmpty())
                {
                    var childs = ProductCategoryService.GetChildSNs(new List <int>()
                    {
                        int.Parse(nl["parentType"])
                    }, true);
                    nl["parentType"] = string.Join(",", childs);
                }
                dt = dal.QueryInventorys(nl);
            }
            recordCount = 0;
            if (nl["ispage"] != "0")//分页
            {
                if (dt.Rows.Count > 0)
                {
                    recordCount = Convert.ToInt32(dt.Rows[0]["RecordTotal"]);
                }
            }
            decimal stockNumbers = 0, saleAmounts = 0, stockAmounts = 0;

            if (dt.Rows.Count > 0)
            {
                var dr = dt.Rows[0];
                stockNumbers += Convert.ToDecimal(dr["StockNumbers"]);
                saleAmounts  += Convert.ToDecimal(dr["SaleAmounts"]);
                stockAmounts += Convert.ToDecimal(dr["StockAmounts"]);
            }
            footer = new List <object>()
            {
                new { StockNumber = stockNumbers, SaleAmount = saleAmounts, StockAmount = stockAmounts, Title = "合计:" }
            };
            ProductService.SetSysPrice(nl["store"], dt);
            return(dt);
        }
Exemplo n.º 6
0
        public static OpResult AddStockLock(TreasuryLocks obj)
        {
            var op = new OpResult();

            try
            {
                obj.LockStoreID.IsNullThrow();
                var xh = obj.CheckBatch.Substring(obj.CheckBatch.Length - 2);
                if (int.Parse(xh) > 20)
                {
                    op.Message = "每月最多只能锁定20次"; return(op);
                }
                var selectBarcodes = HttpContext.Current.Request["selectBarcodes"];
                var barcodes       = new string[] { };
                if (selectBarcodes.IsNullOrEmpty())
                {
                    List <int> childsns = null;
                    if (!obj.LockCategorySN.IsNullOrEmpty())
                    {
                        var parsns = obj.LockCategorySN.Split(',').Select(o => int.Parse(o)).ToList();
                        childsns = ProductCategoryService.GetChildSNs(parsns, true);
                    }
                    else
                    {
                        var ware   = WarehouseService.Find(o => o.StoreId == obj.LockStoreID && o.CompanyId == CommonService.CompanyId);
                        var parsns = ware.CategorySN.Split(',').Where(o => !o.IsNullOrEmpty()).Select(o => int.Parse(o)).ToList();
                        childsns = ProductCategoryService.GetChildSNs(parsns);
                    }
                    barcodes = ProductService.FindList(o => childsns.Contains(o.CategorySN) && o.CompanyId == CommonService.CompanyId).Select(o => o.Barcode).Distinct().ToArray();
                }
                else
                {
                    barcodes = selectBarcodes.Split(',');
                }

                var dt = dal.GetInventoryBalanceLast(CommonService.CompanyId, obj.LockStoreID, string.Join(",", barcodes));
                if (dt == null || dt.Rows.Count <= 0)
                {
                    op.Message = "该门店暂无库存信息";
                }
                else
                {
                    obj.LockDate  = DateTime.Now;
                    obj.LockUID   = Sys.CurrentUser.UID;
                    obj.CompanyId = CommonService.CompanyId;
                    var stocks = new List <StockTaking>();
                    foreach (DataRow dr in dt.Rows)
                    {
                        if (stocks.Any(o => o.Barcode == dr["Barcode"].ToString()))
                        {
                            continue;
                        }
                        stocks.Add(new StockTaking()
                        {
                            Barcode    = dr["Barcode"].ToString(),
                            LockNumber = dr["Number"].ToType <decimal>(),
                            CheckBatch = obj.CheckBatch,
                            CreateDT   = obj.LockDate,
                            CreateUID  = obj.LockUID,
                            CompanyId  = obj.CompanyId
                        });
                    }
                    BaseService <TreasuryLocks> .Add(obj, false);

                    op = AddRange(stocks);
                }
            }
            catch (Exception ex)
            {
                op.Message = ex.Message;
                Log.WriteError(ex);
            }
            return(op);
        }