public JsonResult GetEmployessby(PagingInfo pageinfo)
        {
            var Messaging = new RenderMessaging <Channel_Paging <EmployeeModel> > ();

            try
            {
                if (User == null || User.ChannelId <= 0)
                {
                    Messaging.isError   = true;
                    Messaging.messaging = "Vui lòng đăng nhập lại!";
                }

                Channel_Paging <EmployeeModel> lstInfo = new Channel_Paging <EmployeeModel>();

                int count, min = 0;

                var rs = _IEmployessBusiness.GetEmployessby(pageinfo, out count, out min);

                lstInfo.startItem = min;

                lstInfo.totalItems = count;

                lstInfo.listTable = rs;

                Messaging.Data = lstInfo;

                Messaging.Data = lstInfo;
            }
            catch (Exception ex)
            {
                Messaging.isError   = true;
                Messaging.messaging = "Hiển thị danh sách nhân viên không thành công!";
            }
            return(Json(Messaging, JsonRequestBehavior.AllowGet));
        }
        public JsonResult GetCatalogby(PagingInfo pageinfo)
        {
            var Messaging = new RenderMessaging <Channel_Paging <CatalogModel> >();

            try
            {
                if (User == null || User.ChannelId <= 0)
                {
                    Messaging.isError   = true;
                    Messaging.messaging = "Vui lòng đăng nhập lại!";
                }

                Channel_Paging <CatalogModel> lstInfo = new Channel_Paging <CatalogModel>();

                int count, min = 0;

                var rs = catalogBus.GetCatalog(pageinfo, out count, out min);

                lstInfo.startItem = min;

                lstInfo.totalItems = count;

                lstInfo.listTable = rs;

                Messaging.Data = lstInfo;
            }
            catch
            {
                Messaging.isError   = true;
                Messaging.messaging = "Hiển thị Nhóm sản phẩm có lỗi!";
            }
            return(Json(Messaging, JsonRequestBehavior.AllowGet));
        }
Beispiel #3
0
        public JsonResult GetCustomerby(PagingInfo pageinfo)
        {
            var Messaging = new RenderMessaging();

            try
            {
                if (User == null || User.ChannelId <= 0)
                {
                    Messaging.isError   = true;
                    Messaging.messaging = "Vui lòng đăng nhập lại!";
                }

                Channel_Paging <CustomerModel> lstInfo = new Channel_Paging <CustomerModel>();

                int count, min = 0;

                var rs = _customerBus.GetCustomer(pageinfo, out count, out min);

                lstInfo.startItem = min;

                lstInfo.totalItems = count;

                lstInfo.listTable = rs;

                Messaging.Data = lstInfo;
            }
            catch
            {
                Messaging.isError   = true;
                Messaging.messaging = "Hiển thị danh sách khách hàng không thành công!";
            }
            return(Json(Messaging, JsonRequestBehavior.AllowGet));
        }
Beispiel #4
0
        public JsonResult Get_ProductsSwitch(PagingInfo pageinfo)
        {
            var Messaging = new RenderMessaging();

            try
            {
                if (User == null || User.ChannelId <= 0)
                {
                    Messaging.isError   = true;
                    Messaging.messaging = "Vui lòng đăng nhập lại!";
                }

                var clientMatters = _context.soft_Order.Where(o =>
                                                              o.TypeOrder == (int)TypeOrder.Switch &&
                                                              o.Id_To.HasValue && o.Id_To == User.BranchesId &&
                                                              o.Id_From.HasValue && o.Id_From == User.BranchesId
                                                              )
                                    .OrderByDescending(o => o.DateCreate);

                var lstTmp = clientMatters.AsEnumerable().Select(o => new OrderModel
                {
                    Id             = o.Id,
                    EmployeeCreate = o.EmployeeCreate,
                    EmployeeUpdate = o.EmployeeUpdate,
                    DateUpdate     = o.DateUpdate,
                    DateCreate     = o.DateCreate,
                    Id_From        = o.Id_From.HasValue ? o.Id_From.Value : 0,
                    Id_To          = o.Id_To.HasValue ? o.Id_To.Value : 0,
                    Note           = o.Note,
                    Status         = o.Status,
                    Total          = o.Total.HasValue ? (int)o.Total.Value : 0,
                    Detail         = Mapper.Map <List <Order_DetialModel> >(o.soft_Order_Child)
                });

                #region Fillter
                if (pageinfo.filterby != null && pageinfo.filterby.Count > 0)
                {
                    foreach (var item in pageinfo.filterby)
                    {
                        switch (item.Fiter)
                        {
                        case "Time_To_From":
                            var StartDate = new DateTime(item.StartDate.Year, item.StartDate.Month, item.StartDate.Day, 0, 0, 0, 0); //item.StartDate.Date;
                            var EndDate   = new DateTime(item.EndDate.Year, item.EndDate.Month, item.EndDate.Day, 23, 59, 59, 999);  // item.EndDate.Date.AddDays(1);
                            lstTmp = lstTmp.Where(o => o.DateCreate >= StartDate && o.DateCreate <= EndDate);
                            break;
                        }
                    }
                }
                #endregion

                #region Sort
                if (!string.IsNullOrEmpty(pageinfo.sortby))
                {
                    switch (pageinfo.sortby)
                    {
                    case "DateCreate":
                        if (pageinfo.sortbydesc)
                        {
                            lstTmp = lstTmp.OrderByDescending(o => o.DateCreate);
                        }
                        else
                        {
                            lstTmp = lstTmp.OrderBy(o => o.DateCreate);
                        }
                        break;

                    case "Total":
                        if (pageinfo.sortbydesc)
                        {
                            lstTmp = lstTmp.OrderByDescending(o => o.Total);
                        }
                        else
                        {
                            lstTmp = lstTmp.OrderBy(o => o.Total);
                        }
                        break;
                    }
                }
                #endregion

                Channel_Paging <OrderModel> lstInfo = new Channel_Paging <OrderModel>();

                lstInfo.totalItems = lstTmp.Count();

                int min = Helpers.FindMin(pageinfo.pageindex, pageinfo.pagesize);

                var orderSwitch = lstTmp.Skip(min).Take(pageinfo.pagesize).ToList();

                lstInfo.listTable = orderSwitch;

                var sys_Employee = _context.sys_Employee.ToList();

                foreach (var item in lstInfo.listTable)
                {
                    var userCreate = sys_Employee.FirstOrDefault(o => o.Id == item.EmployeeCreate);
                    item.EmployeeNameCreate = userCreate.Name + "(" + userCreate.Email + ")";
                }

                lstInfo.startItem = min;

                Messaging.Data = lstInfo;
            }
            catch (Exception ex)
            {
                Messaging.isError   = true;
                Messaging.messaging = "Hiển thị danh sách phiếu điều chỉnh không thành công!";
            }
            return(Json(Messaging, JsonRequestBehavior.AllowGet));
        }
        public JsonResult GetOrder_Suppliers(PagingInfo pageinfo)
        {
            var Messaging = new RenderMessaging();

            try
            {
                if (User == null || User.ChannelId <= 0)
                {
                    Messaging.isError   = true;
                    Messaging.messaging = "Vui lòng đăng nhập lại!";
                }

                var clientMatters = _context.soft_Order.Where(o =>
                                                              o.TypeOrder == (int)TypeOrder.OrderProduct && o.Id_From.HasValue && o.Id_From == User.BranchesId)
                                    .OrderByDescending(o => o.DateCreate);


                var lstTmp = clientMatters.AsEnumerable().Select(o => new OrderModel
                {
                    Id             = o.Id,
                    EmployeeCreate = o.EmployeeCreate,
                    EmployeeUpdate = o.EmployeeUpdate,
                    DateUpdate     = o.DateUpdate,
                    DateCreate     = o.DateCreate,
                    Id_From        = o.Id_From.HasValue ? o.Id_From.Value : 0,
                    Id_To          = o.Id_To.HasValue ? o.Id_To.Value : 0,
                    Note           = o.Note,
                    Status         = o.Status,
                    Total          = o.Total.HasValue ? (int)o.Total.Value : 0,
                    Detail         = Mapper.Map <List <Order_DetialModel> >(o.soft_Order_Child)
                });

                #region Fillter
                if (pageinfo.filterby != null && pageinfo.filterby.Count > 0)
                {
                    foreach (var item in pageinfo.filterby)
                    {
                        var key = 0;
                        switch (item.Fiter)
                        {
                        case "Status":
                            key    = int.Parse(item.Value);
                            lstTmp = lstTmp.Where(o => o.Status > 0 && o.Status.Equals(key));
                            break;

                        case "Time_To_From":
                            var StartDate = new DateTime(item.StartDate.Year, item.StartDate.Month, item.StartDate.Day, 0, 0, 0, 0); //item.StartDate.Date;
                            var EndDate   = new DateTime(item.EndDate.Year, item.EndDate.Month, item.EndDate.Day, 23, 59, 59, 999);  // item.EndDate.Date.AddDays(1);
                            lstTmp = lstTmp.Where(o => o.DateCreate >= StartDate && o.DateCreate <= EndDate);
                            break;

                        case "Suppliers":
                            key = int.Parse(item.Value);
                            var producIds_suppliers = _context.shop_sanpham.Where(o => o.soft_Suppliers.SuppliersId == key).Select(o => (long)o.id);
                            var orderChild          = _context.soft_Order_Child.Where(o => producIds_suppliers.Contains(o.ProductId.Value)).Select(o => o.OrderId);
                            lstTmp = lstTmp.Where(o => orderChild.Contains(o.Id));
                            break;
                        }
                    }
                }

                #endregion

                #region Sort
                if (!string.IsNullOrEmpty(pageinfo.sortby))
                {
                    switch (pageinfo.sortby)
                    {
                    case "ChannelsTo":
                        if (pageinfo.sortbydesc)
                        {
                            lstTmp = lstTmp.OrderByDescending(o => o.Id_To);
                        }
                        else
                        {
                            lstTmp = lstTmp.OrderBy(o => o.Id_To);
                        }
                        break;

                    case "ChannelsFrom":
                        if (pageinfo.sortbydesc)
                        {
                            lstTmp = lstTmp.OrderByDescending(o => o.Id_From);
                        }
                        else
                        {
                            lstTmp = lstTmp.OrderBy(o => o.Id_From);
                        }
                        break;

                    case "DateCreate":
                        if (pageinfo.sortbydesc)
                        {
                            lstTmp = lstTmp.OrderByDescending(o => o.DateCreate);
                        }
                        else
                        {
                            lstTmp = lstTmp.OrderBy(o => o.DateCreate);
                        }
                        break;

                    case "Total":
                        if (pageinfo.sortbydesc)
                        {
                            lstTmp = lstTmp.OrderByDescending(o => o.Total);
                        }
                        else
                        {
                            lstTmp = lstTmp.OrderBy(o => o.Total);
                        }
                        break;

                    case "Status":
                        if (pageinfo.sortbydesc)
                        {
                            lstTmp = lstTmp.OrderByDescending(o => o.Status);
                        }
                        else
                        {
                            lstTmp = lstTmp.OrderBy(o => o.Status);
                        }
                        break;

                    case "Id":
                        if (pageinfo.sortbydesc)
                        {
                            lstTmp = lstTmp.OrderByDescending(o => o.Id);
                        }
                        else
                        {
                            lstTmp = lstTmp.OrderBy(o => o.Id);
                        }
                        break;
                    }
                }
                #endregion

                Channel_Paging <OrderModel> lstInfo = new Channel_Paging <OrderModel>();

                lstInfo.totalItems = lstTmp.Count();

                int min = Helpers.FindMin(pageinfo.pageindex, pageinfo.pagesize);

                var orderSuppliers = lstTmp.Skip(min).Take(pageinfo.pagesize).ToList();

                foreach (var item in orderSuppliers)
                {
                    var lstSup = new List <int>();

                    foreach (var pro in item.Detail)
                    {
                        if (pro.Product != null && pro.Product.soft_Suppliers != null)
                        {
                            var checkHas = lstSup.FirstOrDefault(o => o == pro.Product.soft_Suppliers.SuppliersId);
                            if (checkHas <= 0)
                            {
                                item.Name_To += " - " + pro.Product.soft_Suppliers.Name;

                                lstSup.Add(pro.Product.soft_Suppliers.SuppliersId);
                            }
                        }
                    }
                }

                lstInfo.listTable = orderSuppliers;
                lstInfo.startItem = min;

                Messaging.Data = lstInfo;
            }
            catch
            {
                Messaging.isError   = true;
                Messaging.messaging = "Hiển thị danh sách phiếu đặt hàng nhà phân phối không thành công!";
            }
            return(Json(Messaging, JsonRequestBehavior.AllowGet));
        }
        public JsonResult GetOrder(PagingInfo pageinfo)
        {
            var Messaging = new RenderMessaging();

            try
            {
                if (User == null || User.ChannelId <= 0)
                {
                    Messaging.isError   = true;
                    Messaging.messaging = "Vui lòng đăng nhập lại!";
                }

                Channel_Paging <OrderModel> lstInfo = new Channel_Paging <OrderModel>();

                int count, min = 0;

                double totalMoney = 0;

                var lstOrder = _IOrderBus.GetOrder_Sale(pageinfo, User.ChannelId, out count, out min, out totalMoney);

                var a = lstOrder.Select(o => o.id).ToList();

                lstInfo.totalItems = count;

                lstInfo.listTable = Mapper.Map <List <OrderModel> >(lstOrder);

                lstInfo.startItem = min;

                var sys_Employee = _unitOW.EmployeeRepository.GetAll().ToList();

                var soft_Branches = _unitOW.BrachesRepository.GetAll().ToList();

                var soft_Channel = _unitOW.ChannelRepository.GetAll().ToList();

                foreach (var item in lstInfo.listTable)
                {
                    if (item.Id_From > 0)
                    {
                        var channel = soft_Channel.FirstOrDefault(o => o.Id == item.Id_From);
                        if (channel != null)
                        {
                            item.Name_From = channel.Channel;
                        }
                    }


                    var userCreate = sys_Employee.FirstOrDefault(o => o.Id == item.EmployeeCreate);

                    if (userCreate != null)
                    {
                        item.EmployeeNameCreate = userCreate.Name + " (" + userCreate.Email + ")";
                    }

                    if (item.EmployeeShip > 0)
                    {
                        var userShip = sys_Employee.FirstOrDefault(o => o.Id == item.EmployeeShip);
                        if (userShip != null)
                        {
                            item.EmployeeNameShip = userShip.Name;
                        }
                    }

                    if (item.EmployeeUpdate.HasValue)
                    {
                        var userUpdate = sys_Employee.FirstOrDefault(o => o.Id == item.EmployeeUpdate);
                        item.EmployeeNameUpdate = userUpdate.Name + "(" + userUpdate.Email + ")";
                    }
                }

                lstInfo.Total = totalMoney;

                Messaging.Data = lstInfo;
            }
            catch (Exception ex)
            {
                Messaging.isError   = true;
                Messaging.messaging = "Hiển thị danh sách đơn hàng không thành công!";
            }
            return(Json(Messaging, JsonRequestBehavior.AllowGet));
        }
        public JsonResult GetProductby(PagingInfo pageinfo)
        {
            var Messaging = new RenderMessaging();

            try
            {
                if (User == null || User.ChannelId <= 0)
                {
                    Messaging.isError = true;
                }

                //  var lstTmp = from product in _context.shop_sanpham select product;


                var lstTmp = _context.shop_sanpham.Select(o => new ProductSampleModel
                {
                    Barcode       = o.Barcode,
                    tensp         = o.tensp,
                    masp          = o.masp,
                    CatalogId     = o.CatalogId.HasValue ? o.CatalogId.Value : 0,
                    SuppliersId   = o.SuppliersId.HasValue ? o.SuppliersId.Value : 0,
                    id            = o.id,
                    Img           = o.shop_image.FirstOrDefault().url,
                    PriceBase     = o.PriceBase.HasValue ? o.PriceBase.Value : 0,
                    PriceCompare  = o.PriceCompare.HasValue ? o.PriceCompare.Value : 0,
                    PriceInput    = o.PriceInput.HasValue ? o.PriceInput.Value : 0,
                    PriceBase_Old = o.PriceBase_Old.HasValue ? o.PriceBase_Old.Value : 0,
                    Status        = o.Status.HasValue ? o.Status.Value : 0,
                    StatusVAT     = o.StatusVAT.HasValue ? o.StatusVAT.Value : 0,
                    DateCreate    = o.DateCreate,
                    //PriceWholesale = o.PriceWholesale.HasValue ? o.PriceWholesale.Value : 0,
                    Stock_Sum = o.soft_Branches_Product_Stock.Any() ? o.soft_Branches_Product_Stock.Sum(p => p.Stock_Total) : 0
                });

                // IQueryable<shop_sanpham> lstTmp = _context.shop_sanpham;

                #region Fillter
                if (pageinfo.filterby != null && pageinfo.filterby.Count > 0)
                {
                    foreach (var item in pageinfo.filterby)
                    {
                        var key = 0;
                        if (item.Fiter.Equals("Price") || item.Fiter.Equals("Stock"))
                        {
                            key = int.Parse(item.Name);
                        }
                        else
                        {
                            key = int.Parse(item.Value);
                        }

                        switch (item.Fiter)
                        {
                        case "Catalog":
                            lstTmp = lstTmp.Where(o => o.CatalogId > 0 && o.CatalogId.Equals(key));
                            break;

                        case "Suppliers":
                            lstTmp = lstTmp.Where(o => o.SuppliersId > 0 && o.SuppliersId.Equals(key));
                            break;

                        case "Status":
                            lstTmp = lstTmp.Where(o => o.Status > 0 && o.Status.Equals(key));
                            break;

                        case "VAT":
                            lstTmp = lstTmp.Where(o => o.StatusVAT > 0 && o.StatusVAT.Equals(key));
                            break;

                        case "Price":
                            if (item.Value == "Equals")
                            {
                                var soft_Prices = _context.soft_Channel_Product_Price.Where(o => o.Price == key &&
                                                                                            o.ChannelId == User.ChannelId).Select(o => o.ProductId);

                                lstTmp = lstTmp.Where(o => soft_Prices.Contains(o.id));
                            }
                            if (item.Value == "LessThan")
                            {
                                var soft_Prices = _context.soft_Channel_Product_Price.Where(o => o.Price < key &&
                                                                                            o.ChannelId == User.ChannelId).Select(o => o.ProductId);

                                lstTmp = lstTmp.Where(o => soft_Prices.Contains(o.id));
                            }
                            if (item.Value == "MoreThan")
                            {
                                var soft_Prices = _context.soft_Channel_Product_Price.Where(o => o.Price > key &&
                                                                                            o.ChannelId == User.ChannelId).Select(o => o.ProductId);

                                lstTmp = lstTmp.Where(o => soft_Prices.Contains(o.id));
                            }
                            break;

                        case "Stock":
                            var branchesId = int.Parse(item.Value2.ToString());
                            if (branchesId > 0)
                            {
                                if (item.Value == "Equals")
                                {
                                    var soft_Stock = _context.soft_Branches_Product_Stock.Where(o => o.Stock_Total == key &&
                                                                                                o.BranchesId == branchesId).Select(o => o.ProductId);

                                    if (key == 0)
                                    {
                                        var soft_StockNull = _context.soft_Branches_Product_Stock.Where(o => o.BranchesId == User.BranchesId).Select(o => o.ProductId);

                                        lstTmp = lstTmp.Where(o => soft_Stock.Contains(o.id) || !soft_StockNull.Contains(o.id));
                                    }
                                    else
                                    {
                                        lstTmp = lstTmp.Where(o => soft_Stock.Contains(o.id));
                                    }
                                }
                                if (item.Value == "LessThan")
                                {
                                    var soft_Stock = _context.soft_Branches_Product_Stock.Where(o => o.Stock_Total < key &&
                                                                                                o.BranchesId == branchesId).Select(o => o.ProductId);

                                    lstTmp = lstTmp.Where(o => soft_Stock.Contains(o.id));
                                }
                                if (item.Value == "MoreThan")
                                {
                                    var soft_Stock = _context.soft_Branches_Product_Stock.Where(o => o.Stock_Total > key &&
                                                                                                o.BranchesId == branchesId).Select(o => o.ProductId);

                                    lstTmp = lstTmp.Where(o => soft_Stock.Contains(o.id));
                                }
                            }
                            else
                            {
                                var sum_Stock = _context.soft_Branches_Product_Stock.GroupBy(o => o.ProductId).Select(o => new
                                {
                                    productid = o.Key,
                                    total     = o.Sum(i => i.Stock_Total)
                                });

                                if (item.Value == "MoreThan")
                                {
                                    var MoreThan = sum_Stock.Where(o => o.total > key).Select(o => o.productid);

                                    lstTmp = lstTmp.Where(o => MoreThan.Contains(o.id));
                                }
                                if (item.Value == "LessThan")
                                {
                                    var LessThan = sum_Stock.Where(o => o.total < key).Select(o => o.productid);

                                    lstTmp = lstTmp.Where(o => LessThan.Contains(o.id));
                                }
                                if (item.Value == "Equals")
                                {
                                    var Equals = sum_Stock.Where(o => o.total == key).Select(o => o.productid);

                                    lstTmp = lstTmp.Where(o => Equals.Contains(o.id));
                                }
                            }
                            break;
                        }
                    }
                }
                #endregion
                #region Sort
                if (!string.IsNullOrEmpty(pageinfo.sortby))
                {
                    switch (pageinfo.sortby)
                    {
                    case "DateCreate":
                        if (pageinfo.sortbydesc)
                        {
                            lstTmp = lstTmp.OrderByDescending(o => o.DateCreate);
                        }
                        else
                        {
                            lstTmp = lstTmp.OrderBy(o => o.DateCreate);
                        }
                        break;

                    case "Id":
                        if (pageinfo.sortbydesc)
                        {
                            lstTmp = lstTmp.OrderByDescending(o => o.id);
                        }
                        else
                        {
                            lstTmp = lstTmp.OrderBy(o => o.id);
                        }
                        break;

                    case "Barcode":
                        if (pageinfo.sortbydesc)
                        {
                            lstTmp = lstTmp.OrderByDescending(o => o.Barcode);
                        }
                        else
                        {
                            lstTmp = lstTmp.OrderBy(o => o.Barcode);
                        }
                        break;

                    case "PriceBase":
                        if (pageinfo.sortbydesc)
                        {
                            lstTmp = lstTmp.OrderByDescending(o => o.PriceBase);
                        }
                        else
                        {
                            lstTmp = lstTmp.OrderBy(o => o.PriceBase);
                        }
                        break;

                    case "PriceBase_Old":
                        if (pageinfo.sortbydesc)
                        {
                            lstTmp = lstTmp.OrderByDescending(o => o.PriceBase_Old);
                        }
                        else
                        {
                            lstTmp = lstTmp.OrderBy(o => o.PriceBase_Old);
                        }
                        break;

                    case "PriceCompare":
                        if (pageinfo.sortbydesc)
                        {
                            lstTmp = lstTmp.OrderByDescending(o => o.PriceCompare);
                        }
                        else
                        {
                            lstTmp = lstTmp.OrderBy(o => o.PriceCompare);
                        }
                        break;

                    case "PriceInput":
                        if (pageinfo.sortbydesc)
                        {
                            lstTmp = lstTmp.OrderByDescending(o => o.PriceInput);
                        }
                        else
                        {
                            lstTmp = lstTmp.OrderBy(o => o.PriceInput);
                        }
                        break;

                    case "ProductName":
                        if (pageinfo.sortbydesc)
                        {
                            lstTmp = lstTmp.OrderByDescending(o => o.tensp);
                        }
                        else
                        {
                            lstTmp = lstTmp.OrderBy(o => o.tensp);
                        }
                        break;

                    case "Code":
                        if (pageinfo.sortbydesc)
                        {
                            lstTmp = lstTmp.OrderByDescending(o => o.CatalogId);
                        }
                        else
                        {
                            lstTmp = lstTmp.OrderBy(o => o.CatalogId);
                        }
                        break;

                    case "StatusVAT":
                        if (pageinfo.sortbydesc)
                        {
                            lstTmp = lstTmp.OrderByDescending(o => o.StatusVAT);
                        }
                        else
                        {
                            lstTmp = lstTmp.OrderBy(o => o.StatusVAT);
                        }
                        break;

                    case "Stock_Sum":
                        if (pageinfo.sortbydesc)
                        {
                            lstTmp = lstTmp.OrderByDescending(o => o.Stock_Sum);
                        }
                        else
                        {
                            lstTmp = lstTmp.OrderBy(o => o.Stock_Sum);
                        }
                        break;
                    }
                }
                #endregion
                var products = new List <ProductSampleModel>();

                #region Search
                if (!string.IsNullOrEmpty(pageinfo.keyword))
                {
                    pageinfo.keyword = pageinfo.keyword.ToLower();
                    lstTmp           = lstTmp.Where(o =>
                                                    (!string.IsNullOrEmpty(o.tensp) && o.tensp.Contains(pageinfo.keyword)) ||
                                                    (!string.IsNullOrEmpty(o.Barcode) && o.Barcode.Contains(pageinfo.keyword)) ||
                                                    (!string.IsNullOrEmpty(o.masp) && o.masp.Contains(pageinfo.keyword))
                                                    );

                    //lstTmp = lstTmp.Where(o =>
                    //     (!string.IsNullOrEmpty(o.tensp) && Helpers.convertToUnSign3(o.tensp.ToLower()).Contains(pageinfo.keyword))
                    //     || (!string.IsNullOrEmpty(o.Barcode) && Helpers.convertToUnSign3(o.Barcode.ToLower()).Contains(pageinfo.keyword))
                    //     || (!string.IsNullOrEmpty(o.masp) && Helpers.convertToUnSign3(o.masp.ToLower()).Contains(pageinfo.keyword))
                    //    );
                }
                #endregion
                Channel_Paging <Prodcut_Branches_PriceChannel> lstInfo = new Channel_Paging <Prodcut_Branches_PriceChannel>();

                int min = Helpers.FindMin(pageinfo.pageindex, pageinfo.pagesize);

                lstInfo.totalItems = lstTmp.Count();
                int quantity = Helpers.GetQuantity(lstInfo.totalItems, pageinfo.pageindex, pageinfo.pagesize);
                // if (pageinfo.pagesize <= lstTmp.Count())
                if (quantity > 0)
                {
                    if (string.IsNullOrEmpty(pageinfo.sortby))
                    {
                        products = Mapper.Map <List <ProductSampleModel> >(lstTmp.OrderBy(o => o.tensp).ThenBy(o => o.masp).Skip(min).Take(quantity));
                    }
                    else
                    {
                        products = Mapper.Map <List <ProductSampleModel> >(lstTmp.Skip(min).Take(quantity));
                    }
                }

                // products = products.GetRange(min, quantity);

                lstInfo.listTable = new List <Prodcut_Branches_PriceChannel>();
                lstInfo.startItem = min;

                foreach (var item in products)
                {
                    var stocks = Mapper.Map <List <Product_StockModel> >(_context.soft_Branches_Product_Stock.Where(o => o.ProductId == item.id).ToList());
                    var stock  = stocks.FirstOrDefault(o => o.BranchesId == User.BranchesId);
                    if (stock != null)
                    {
                        item.Stock_Total = stock.Stock_Total;
                    }

                    item.Stock_Sum = stocks.Sum(o => o.Stock_Total);

                    var productInfo = new Prodcut_Branches_PriceChannel
                    {
                        //product_price = price ?? price,
                        product_stock  = stock ?? stock,
                        product        = item,
                        product_stocks = stocks
                    };

                    var prices = _context.soft_Channel_Product_Price.Where(o => o.ProductId == item.id).ToList();

                    if (prices != null && prices.Count > 0)
                    {
                        var PriceMainStore = prices.FirstOrDefault(o => o.soft_Channel.Type == (int)TypeChannel.IsMainStore);
                        if (PriceMainStore != null)
                        {
                            item.PriceMainStore = PriceMainStore.Price;
                        }

                        var PriceSi = prices.FirstOrDefault(o => o.soft_Channel.Type == (int)TypeChannel.IsChannelWholesale);
                        if (PriceSi != null)
                        {
                            item.PriceWholesale = PriceSi.Price;
                        }


                        var price = Mapper.Map <Product_PriceModel>(prices.FirstOrDefault(o => o.ChannelId == User.ChannelId));
                        productInfo.product_price = price;
                    }

                    lstInfo.listTable.Add(productInfo);
                }

                Messaging.Data = lstInfo;
            }
            catch (Exception ex)
            {
                Messaging.isError   = true;
                Messaging.messaging = "Hiển thị danh sách sản phẩm không thành công!";
            }
            return(Json(Messaging, JsonRequestBehavior.AllowGet));
        }
        public JsonResult GetOrder_Branches(PagingInfo pageinfo)
        {
            var Messaging = new RenderMessaging();

            try
            {
                if (User == null || User.ChannelId <= 0)
                {
                    Messaging.isError   = true;
                    Messaging.messaging = "Vui lòng đăng nhập lại!";
                }

                Channel_Paging <OrderModel> lstInfo = new Channel_Paging <OrderModel>();

                int count, min = 0;

                lstInfo.listTable = _IOrderBus.GetOrder_Branches(pageinfo, User.BranchesId, out count, out min);

                lstInfo.totalItems = count;

                lstInfo.startItem = min;

                var sys_Employee = _unitOW.EmployeeRepository.GetAll().ToList();

                var soft_Branches = _unitOW.BrachesRepository.GetAll().ToList();

                foreach (var item in lstInfo.listTable)
                {
                    var userCreate = sys_Employee.FirstOrDefault(o => o.Id == item.EmployeeCreate);
                    item.EmployeeNameCreate = userCreate.Name + "(" + userCreate.Email + ")";

                    if (item.EmployeeUpdate.HasValue)
                    {
                        var userUpdate = sys_Employee.FirstOrDefault(o => o.Id == item.EmployeeUpdate);
                        item.EmployeeNameUpdate = userUpdate.Name + "(" + userUpdate.Email + ")";
                    }

                    if (item.Id_From > 0)
                    {
                        var branch = soft_Branches.FirstOrDefault(o => o.BranchesId == item.Id_From);
                        if (branch != null)
                        {
                            item.Name_From = branch.BranchesName;
                        }
                    }

                    if (item.Id_To > 0)
                    {
                        var branch = soft_Branches.FirstOrDefault(o => o.BranchesId == item.Id_To);
                        if (branch != null)
                        {
                            item.Name_To = branch.BranchesName;
                        }
                    }
                }

                Messaging.Data = lstInfo;
            }
            catch
            {
                Messaging.isError   = true;
                Messaging.messaging = "Hiển thị đơn hàng nhập không thành công!";
            }
            return(Json(Messaging, JsonRequestBehavior.AllowGet));
        }
        public JsonResult GetOrder_Inside(PagingInfo pageinfo)
        {
            var Messaging = new RenderMessaging();

            try
            {
                if (User == null || User.ChannelId <= 0)
                {
                    Messaging.isError   = true;
                    Messaging.messaging = "Vui lòng đăng nhập lại!";
                }

                Channel_Paging <OrderModel> lstInfo = new Channel_Paging <OrderModel>();

                int count, min = 0;

                lstInfo.listTable = _IOrderBus.GetOrder_Input(pageinfo, User.BranchesId, out count, out min);

                lstInfo.totalItems = count;

                lstInfo.startItem = min;

                var sys_Employee = _unitOW.EmployeeRepository.GetAll().ToList();

                var soft_Branches = _unitOW.BrachesRepository.GetAll().ToList();

                foreach (var item in lstInfo.listTable)
                {
                    var userCreate = sys_Employee.FirstOrDefault(o => o.Id == item.EmployeeCreate);
                    item.EmployeeNameCreate = userCreate.Name + "(" + userCreate.Email + ")";

                    if (item.EmployeeUpdate.HasValue)
                    {
                        var userUpdate = sys_Employee.FirstOrDefault(o => o.Id == item.EmployeeUpdate);
                        item.EmployeeNameUpdate = userUpdate.Name + "(" + userUpdate.Email + ")";
                    }

                    var lstSup = new List <int>();

                    if (item.Id_From > 0)
                    {
                        var branch = soft_Branches.FirstOrDefault(o => o.BranchesId == item.Id_From);
                        if (branch != null)
                        {
                            item.Name_From = branch.BranchesName;
                        }
                        else
                        {
                            var orderSuppliers = _unitOW.OrderInputRepository.FindBy(o => o.Id == item.Id_From).FirstOrDefault();
                            if (orderSuppliers != null)
                            {
                                item.Name_From = "ĐH NPP";
                                foreach (var pro in item.Detail)
                                {
                                    if (pro.Product != null && pro.Product.soft_Suppliers != null)
                                    {
                                        var checkHas = lstSup.FirstOrDefault(o => o == pro.Product.soft_Suppliers.SuppliersId);
                                        if (checkHas <= 0)
                                        {
                                            item.Name_From += " - " + pro.Product.soft_Suppliers.Name;

                                            lstSup.Add(pro.Product.soft_Suppliers.SuppliersId);
                                        }
                                    }
                                }
                            }
                        }
                    }

                    if (item.Id_To > 0)
                    {
                        var branch = soft_Branches.FirstOrDefault(o => o.BranchesId == item.Id_To);
                        if (branch != null)
                        {
                            item.Name_To = branch.BranchesName;
                        }
                    }
                }

                Messaging.Data = lstInfo;
            }
            catch
            {
                Messaging.isError   = true;
                Messaging.messaging = "Hiển thị đơn hàng nhập không thành công!";
            }
            return(Json(Messaging, JsonRequestBehavior.AllowGet));
        }
Beispiel #10
0
        public JsonResult GetOrder_Output(PagingInfo pageinfo)
        {
            var Messaging = new RenderMessaging();

            try
            {
                if (User == null || User.ChannelId <= 0)
                {
                    Messaging.isError   = true;
                    Messaging.messaging = "Vui lòng đăng nhập lại!";
                }
                //var lstTmp = from order in _context.soft_Order where order.TypeOrder == (int)TypeOrder.Output && order.Id_From == User.BranchesId orderby order.DateCreate descending select order;

                var clientMatters = _context.soft_Order.Where(o =>
                                                              o.TypeOrder == (int)TypeOrder.Output && o.Id_From.HasValue && o.Id_From == User.BranchesId)
                                    .OrderByDescending(o => o.DateCreate);


                var lstTmp = clientMatters.AsEnumerable().Select(o => new OrderModel
                {
                    Id             = o.Id,
                    EmployeeCreate = o.EmployeeCreate,
                    EmployeeUpdate = o.EmployeeUpdate,
                    DateUpdate     = o.DateUpdate,
                    DateCreate     = o.DateCreate,
                    Id_From        = o.Id_From.HasValue ? o.Id_From.Value : 0,
                    Id_To          = o.Id_To.HasValue ? o.Id_To.Value : 0,
                    Note           = o.Note,
                    Status         = o.Status,
                    Total          = o.Total.HasValue ? (int)o.Total.Value : 0,
                    Detail         = Mapper.Map <List <Order_DetialModel> >(o.soft_Order_Child)
                });

                #region Fillter
                if (pageinfo.filterby != null && pageinfo.filterby.Count > 0)
                {
                    foreach (var item in pageinfo.filterby)
                    {
                        var key = 0;
                        switch (item.Fiter)
                        {
                        case "Status":
                            key    = int.Parse(item.Value);
                            lstTmp = lstTmp.Where(o => o.Status > 0 && o.Status.Equals(key));
                            break;

                        case "Brach_From":
                            key    = int.Parse(item.Value);
                            lstTmp = lstTmp.Where(o => o.Id_From > 0 && o.Id_From.Equals(key));
                            break;

                        case "Brach_To":
                            key    = int.Parse(item.Value);
                            lstTmp = lstTmp.Where(o => o.Id_To > 0 && o.Id_To.Equals(key));
                            break;

                        case "Time_To_From":
                            var StartDate = new DateTime(item.StartDate.Year, item.StartDate.Month, item.StartDate.Day, 0, 0, 0, 0); //item.StartDate.Date;
                            var EndDate   = new DateTime(item.EndDate.Year, item.EndDate.Month, item.EndDate.Day, 23, 59, 59, 999);  // item.EndDate.Date.AddDays(1);
                            lstTmp = lstTmp.Where(o => o.DateCreate >= StartDate && o.DateCreate <= EndDate);
                            break;
                        }
                    }
                }
                #endregion

                #region Sort
                if (!string.IsNullOrEmpty(pageinfo.sortby))
                {
                    switch (pageinfo.sortby)
                    {
                    case "ChannelsTo":
                        if (pageinfo.sortbydesc)
                        {
                            lstTmp = lstTmp.OrderByDescending(o => o.Id_To);
                        }
                        else
                        {
                            lstTmp = lstTmp.OrderBy(o => o.Id_To);
                        }
                        break;

                    case "ChannelsFrom":
                        if (pageinfo.sortbydesc)
                        {
                            lstTmp = lstTmp.OrderByDescending(o => o.Id_From);
                        }
                        else
                        {
                            lstTmp = lstTmp.OrderBy(o => o.Id_From);
                        }
                        break;

                    case "DateCreate":
                        if (pageinfo.sortbydesc)
                        {
                            lstTmp = lstTmp.OrderByDescending(o => o.DateCreate);
                        }
                        else
                        {
                            lstTmp = lstTmp.OrderBy(o => o.DateCreate);
                        }
                        break;

                    case "Total":
                        if (pageinfo.sortbydesc)
                        {
                            lstTmp = lstTmp.OrderByDescending(o => o.Total);
                        }
                        else
                        {
                            lstTmp = lstTmp.OrderBy(o => o.Total);
                        }
                        break;

                    case "Status":
                        if (pageinfo.sortbydesc)
                        {
                            lstTmp = lstTmp.OrderByDescending(o => o.Status);
                        }
                        else
                        {
                            lstTmp = lstTmp.OrderBy(o => o.Status);
                        }
                        break;

                    case "Id":
                        if (pageinfo.sortbydesc)
                        {
                            lstTmp = lstTmp.OrderByDescending(o => o.Id);
                        }
                        else
                        {
                            lstTmp = lstTmp.OrderBy(o => o.Id);
                        }
                        break;
                    }
                }
                #endregion

                Channel_Paging <OrderModel> lstInfo = new Channel_Paging <OrderModel>();

                lstInfo.totalItems = lstTmp.Count();

                int min = Helpers.FindMin(pageinfo.pageindex, pageinfo.pagesize);

                var orderOutput = lstTmp.Skip(min).Take(pageinfo.pagesize).ToList();

                var soft_Branches = _context.soft_Branches.ToList();

                var sys_Employee = _context.sys_Employee.ToList();

                foreach (var item in orderOutput)
                {
                    if (item.Id_From > 0)
                    {
                        var branch = soft_Branches.FirstOrDefault(o => o.BranchesId == item.Id_From);
                        if (branch != null)
                        {
                            item.Name_From = branch.BranchesName;
                        }
                    }
                    if (item.Id_To > 0)
                    {
                        var branch = soft_Branches.FirstOrDefault(o => o.BranchesId == item.Id_To);
                        if (branch != null)
                        {
                            item.Name_To = branch.BranchesName;
                        }
                    }

                    var userCreate = sys_Employee.FirstOrDefault(o => o.Id == item.EmployeeCreate);
                    item.EmployeeNameCreate = userCreate.Name + "(" + userCreate.Email + ")";

                    if (item.EmployeeUpdate.HasValue)
                    {
                        var userUpdate = sys_Employee.FirstOrDefault(o => o.Id == item.EmployeeUpdate);
                        item.EmployeeNameUpdate = userUpdate.Name + "(" + userUpdate.Email + ")";
                    }
                }

                lstInfo.listTable = orderOutput;

                lstInfo.startItem = min;

                #region addproduct
                #endregion
                Messaging.Data = lstInfo;
            }
            catch
            {
                Messaging.isError   = true;
                Messaging.messaging = "Hiển thị danh sách phiếu xuất không thành công!";
            }
            return(Json(Messaging, JsonRequestBehavior.AllowGet));
        }