Exemplo n.º 1
0
        public ActionResult Create()
        {
            if (Authorized(RoleType.OrdersWriter))
            {
                List<Supplier> allSuppliers;
                using (SuppliersRepository suppliersRep = new SuppliersRepository(CurrentUser.CompanyId))
                {
                    allSuppliers = suppliersRep.GetList().ToList();
                }

                if (allSuppliers != null)
                {
                    ViewBag.SupplierId = new SelectList(allSuppliers, "Id", "Name");
                    return View();
                }
                else
                {
                    return Error(Loc.Dic.error_suppliers_get_error);
                }
            }
            else
            {
                return Error(Loc.Dic.error_no_permission);
            }
        }
Exemplo n.º 2
0
        public JsonResult GetAll(bool firstNull = false)
        {
            if (Authorized(RoleType.OrdersWriter))
            {
                List <AjaxSupplier> allSuppliers;
                using (SuppliersRepository suppRep = new SuppliersRepository(CurrentUser.CompanyId))
                {
                    allSuppliers = suppRep.GetList()
                                   .Where(x => x.CompanyId == CurrentUser.CompanyId)
                                   .Select(
                        supp => new AjaxSupplier()
                    {
                        Id               = supp.Id,
                        Name             = supp.Name,
                        VAT_Number       = supp.VAT_Number.HasValue ? supp.VAT_Number.Value : 0,
                        Phone_Number     = supp.Phone_Number,
                        Activity_Hours   = supp.Activity_Hours,
                        Additional_Phone = supp.Additional_Phone,
                        Address          = supp.Address,
                        Branch_Line      = supp.Branch_line,
                        City             = supp.City,
                        Crew_Number      = supp.Crew_Number,
                        Customer_Number  = supp.Customer_Number,
                        EMail            = supp.EMail,
                        Fax              = supp.Fax,
                        Presentor_name   = supp.Presentor_name,
                        Notes            = supp.Notes,
                        CreationDate     = supp.CreationDate
                    })
                                   .ToList();
                }

                if (firstNull)
                {
                    allSuppliers.Insert(0, new AjaxSupplier()
                    {
                        Id = null, Name = Loc.Dic.SelectNone
                    });
                }

                if (allSuppliers != null)
                {
                    return(Json(new { gotData = true, data = allSuppliers, message = String.Empty }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    return(Json(new { gotData = false, message = Loc.Dic.error_suppliers_get_error }, JsonRequestBehavior.AllowGet));
                }
            }
            else
            {
                return(Json(new { gotData = false, message = Loc.Dic.error_no_permission }, JsonRequestBehavior.AllowGet));
            }
        }
Exemplo n.º 3
0
        public ActionResult Index()
        {
            IList <Supplier> suppliers = _suppliersRepository.GetList();

            int totalSuppliers = suppliers.Count();

            var viewModel = new SuppliersBaseViewModel()
            {
                Suppliers      = suppliers,
                TotalSuppliers = totalSuppliers
            };

            return(View(viewModel));
        }
 /// <summary>
 /// Initializes the view model.
 /// </summary>
 public void Init(ProductTypesRepository productTypesRepository,
                  SuppliersRepository suppliersRepository,
                  UnitsRepository unitsRepository,
                  string userId)
 {
     ProductTypesSelectListItems = new SelectList(
         productTypesRepository.GetList(),
         "Id", "Name");
     SuppliersSelectListItems = new SelectList(
         suppliersRepository.GetList(),
         "Id", "Name");
     UnitsSelectListItems = new SelectList(
         unitsRepository.GetList(),
         "Id", "Name", "Quantity");
 }
Exemplo n.º 5
0
        public ActionResult Index(int page = FIRST_PAGE, string sortby = DEFAULT_SORT, string order = DEFAULT_DESC_ORDER)
        {
            if (!Authorized(RoleType.SystemManager))
            {
                return(Error(Loc.Dic.error_no_permission));
            }

            IEnumerable <Supplier> suppliers;

            using (SuppliersRepository suppliersRep = new SuppliersRepository(CurrentUser.CompanyId))
            {
                suppliers = suppliersRep.GetList().Where(x => x.CompanyId == CurrentUser.CompanyId);

                suppliers = Pagination(suppliers, page, sortby, order);

                return(View(suppliers.ToList()));
            }
        }
Exemplo n.º 6
0
        public ActionResult Create()
        {
            using (SuppliersRepository suppliersRepository = new SuppliersRepository(CurrentUser.CompanyId))
            using (LocationsRepository locationsRepository = new LocationsRepository(CurrentUser.CompanyId))
            using (InventoryRepository inventoryRepository = new InventoryRepository(CurrentUser.CompanyId))
            {
                ViewBag.RelatedInventoryItem = new SelectList(inventoryRepository.GetList("Orders_Items")
                                  .Select( x => new { Id = x.Id, InventarNumber = x.InventarNumber, Title = x.Orders_Items.Title, SubTitle = x.Orders_Items.SubTitle })
                                  .ToList()
                  .Select(x => new SelectListItemDB() { Id = x.Id, Name = x.InventarNumber + " - " + x.Title + " " + x.SubTitle })
                  .OrderBy(x => x.Name)
                  .ToList(), "Id", "Name");

                if (locationsRepository.GetList().Where(x => x.CompanyId == CurrentUser.CompanyId).Count() == 0)
                    return Error(Loc.Dic.error_no_location_exist);
                ViewBag.LocationId = new SelectList(locationsRepository.GetList().Where(x => x.CompanyId == CurrentUser.CompanyId).OrderBy(x => x.Name).ToList(), "Id", "Name");
                ViewBag.Suppliers = new SelectList(suppliersRepository.GetList().Where(x => x.CompanyId == CurrentUser.CompanyId).OrderBy(x=>x.Name).ToList(), "Id", "Name");
            }

            return View();
        }
Exemplo n.º 7
0
        public ActionResult Create()
        {
            if (!Authorized(RoleType.OrdersWriter)) return Error(Loc.Dic.error_no_permission);

            using (SuppliersRepository suppliersRep = new SuppliersRepository(CurrentUser.CompanyId))
            using (BudgetsRepository budgetsRep = new BudgetsRepository(CurrentUser.CompanyId))
            using (AllocationRepository allocationsRep = new AllocationRepository(CurrentUser.CompanyId))
            {
                List<Supplier> allSuppliers = suppliersRep.GetList().Where(x => x.ExternalId != null).OrderBy(s => s.Name).ToList();
                if (!allSuppliers.Any()) return Error(Loc.Dic.error_no_suppliers_for_order);

                ViewBag.SupplierId = new SelectList(allSuppliers, "Id", "Name");

                Budget activeBudget = budgetsRep.GetList().SingleOrDefault(x => x.IsActive);
                if (activeBudget == null) return Error(Loc.Dic.error_no_active_budget);

                ViewBag.Allocations = allocationsRep.GetUserAllocations(CurrentUser.UserId, activeBudget.Id);
                if (!((List<Budgets_Allocations>)ViewBag.Allocations).Any()) return Error(Loc.Dic.error_user_have_no_allocations);
                ViewBag.BudgetYear = activeBudget.Year;
                return View();
            }
        }
Exemplo n.º 8
0
        public ActionResult SearchForm(OrdersSearchValuesModel model, bool isExpanding, bool isCollapsed, int? userId = null, int? statusId = null, int? supplierId = null, bool hideUserField = false, bool hideStatusField = false, bool hideSupplierField = false)
        {
            if (model == null) model = new OrdersSearchValuesModel();

            using (UsersRepository usersRep = new UsersRepository(CurrentUser.CompanyId))
            using (BudgetsRepository budgetsRep = new BudgetsRepository(CurrentUser.CompanyId))
            using (SuppliersRepository suppliersRep = new SuppliersRepository(CurrentUser.CompanyId))
            using (OrderStatusesRepository statusesRep = new OrderStatusesRepository())
            using (AllocationRepository allocationsRep = new AllocationRepository(CurrentUser.CompanyId))
            {
                List<SelectListItemDB> usersAsSelectItems = new List<SelectListItemDB>() { new SelectListItemDB() { Id = -1, Name = Loc.Dic.AllUsersOption } };
                usersAsSelectItems.AddRange(usersRep.GetList().Select(x => new SelectListItemDB() { Id = x.Id, Name = x.FirstName + " " + x.LastName }));
                model.UsersList = new SelectList(usersAsSelectItems, "Id", "Name");

                List<SelectListItemDB> budgetsAsSelectItems = new List<SelectListItemDB>() { new SelectListItemDB() { Id = -1, Name = Loc.Dic.AllBudgetsOption } };
                budgetsAsSelectItems.AddRange(budgetsRep.GetList().AsEnumerable().Select(x => new SelectListItemDB() { Id = x.Id, Name = "(" + x.Year + ") " + x.Name }));
                model.BudgetsList = new SelectList(budgetsAsSelectItems, "Id", "Name");

                List<Supplier> suppliersSelectList = new List<Supplier>() { new Supplier() { Id = -1, Name = Loc.Dic.AllSuppliersOption } };
                suppliersSelectList.AddRange(suppliersRep.GetList().OrderByDescending(x => x.Name).ToList());
                model.SuppliersList = new SelectList(suppliersSelectList, "Id", "Name");

                List<Orders_Statuses> statusesSelectList = new List<Orders_Statuses>() { new Orders_Statuses() { Id = -1, Name = Loc.Dic.AllStatusesOption } };
                statusesSelectList.AddRange(statusesRep.GetList().ToList());
                model.StatusesList = new SelectList(statusesSelectList, "Id", "Name");

                List<SelectListStringItem> allocationsSelectList = new List<SelectListStringItem>() { new SelectListStringItem() { Id = "-1", Name = Loc.Dic.AllAllocationsOption } };
                allocationsSelectList.AddRange(allocationsRep.GetList().GroupBy(x => x.ExternalId).AsEnumerable().Select(x => new SelectListStringItem() { Id = x.First().ExternalId, Name = x.First().DisplayName }).ToList());
                model.AllocationsList = new SelectList(allocationsSelectList, "Id", "Name");
            }

            ViewBag.IsExpanding = isExpanding;
            ViewBag.IsCollapsed = isCollapsed;
            ViewBag.UserId = userId;
            ViewBag.StatusId = statusId;
            ViewBag.SupplierId = supplierId;
            ViewBag.HideUserField = hideUserField;
            ViewBag.HideStatusField = hideStatusField;
            ViewBag.HideSupplierField = hideSupplierField;
            return PartialView(model);
        }
Exemplo n.º 9
0
        public ActionResult SuppliersEntrence(int page = FIRST_PAGE, string sortby = NO_SORT_BY, string order = DEFAULT_DESC_ORDER, int VAT_Number = 0)
        {
            CultureInfo ci = new CultureInfo("He");

            System.Threading.Thread.CurrentThread.CurrentUICulture = ci;
            System.Threading.Thread.CurrentThread.CurrentCulture   =
                CultureInfo.CreateSpecificCulture(ci.Name);

            using (SuppliersRepository supRep = new SuppliersRepository(CurrentUser.CompanyId))
                using (OrdersRepository orderRep = new OrdersRepository(CurrentUser.CompanyId))
                {
                    Supplier supplier = supRep.GetList().SingleOrDefault(x => x.VAT_Number == VAT_Number);

                    IEnumerable <Order> orders;

                    orders = orderRep.GetList("Orders_Statuses", "Supplier", "User").Where(x => x.SupplierId == supplier.Id);

                    if (orders != null)
                    {
                        int numberOfItems = orders.Count();
                        int numberOfPages = numberOfItems / ITEMS_PER_PAGE;
                        if (numberOfItems % ITEMS_PER_PAGE != 0)
                        {
                            numberOfPages++;
                        }

                        if (page <= 0)
                        {
                            page = FIRST_PAGE;
                        }
                        if (page > numberOfPages)
                        {
                            page = numberOfPages;
                        }

                        if (sortby != NO_SORT_BY)
                        {
                            Func <Func <Order, dynamic>, IEnumerable <Order> > orderFunction;

                            if (order == DEFAULT_DESC_ORDER)
                            {
                                orderFunction = x => orders.OrderByDescending(x);
                            }
                            else
                            {
                                orderFunction = x => orders.OrderBy(x);
                            }

                            switch (sortby)
                            {
                            case "username":
                            default:
                                orders = orderFunction(x => x.User.FirstName + " " + x.User.LastName);
                                break;

                            case "number":
                                orders = orderFunction(x => x.OrderNumber);
                                break;

                            case "creation":
                                orders = orderFunction(x => x.CreationDate);
                                break;

                            case "supplier":
                                orders = orderFunction(x => x.Supplier.Name);
                                break;

                            case "status":
                                orders = orderFunction(x => x.StatusId);
                                break;

                            case "price":
                                orders = orderFunction(x => x.Price);
                                break;
                            }
                        }

                        orders = orders
                                 .Skip((page - 1) * ITEMS_PER_PAGE)
                                 .Take(ITEMS_PER_PAGE)
                                 .ToList();

                        ViewBag.Sortby        = sortby;
                        ViewBag.Order         = order;
                        ViewBag.CurrPage      = page;
                        ViewBag.NumberOfPages = numberOfPages;

                        return(View(orders.ToList()));
                    }
                    else
                    {
                        return(Error(Loc.Dic.error_order_get_error));
                    }
                }
        }
 public void Init(SuppliersRepository suppliersRepository)
 {
     SuppliersSelectListItems = new SelectList(
         suppliersRepository.GetList(), "Name", "WebSite");
 }
Exemplo n.º 11
0
        public static string ImportSuppliers(Stream stream, int companyId)
        {
            const int       EXTERNALID     = 0;
            const int       NAME           = 1;
            List <Supplier> toAddSuppliers = new List <Supplier>();

            byte[] fileBytes = new byte[stream.Length];
            stream.Read(fileBytes, 0, Convert.ToInt32(stream.Length));
            string fileContent = System.Text.Encoding.Default.GetString(fileBytes);

            string[] fileLines       = fileContent.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
            int      firstValuesLine = 0;
            bool     noErros         = true;
            string   errorType       = String.Empty;

            using (SuppliersRepository suppliersRep = new SuppliersRepository(companyId))
            {
                for (int i = firstValuesLine; i < fileLines.Length; i++)
                {
                    string[] lineValues = fileLines[i].Split('\t');
                    for (int vIndex = 0; vIndex < lineValues.Length; vIndex++)
                    {
                        lineValues[vIndex] = lineValues[vIndex].Replace("\"", "");
                    }

                    Supplier newSupplier;
                    if (!(int.Parse(lineValues[EXTERNALID]) > 0))
                    {
                        errorType = Loc.Dic.error_invalid_form;
                        break;
                    }
                    if (lineValues[NAME] == null)
                    {
                        errorType = Loc.Dic.error_invalid_form;
                        break;
                    }
                    try
                    {
                        newSupplier = new Supplier()
                        {
                            CompanyId  = companyId,
                            ExternalId = lineValues[EXTERNALID],
                            Name       = lineValues[NAME],
                        };
                    }
                    catch
                    {
                        noErros   = false;
                        errorType = Loc.Dic.Error_FileParseError;
                        break;
                    }
                    List <Supplier> existingSuppliers = suppliersRep.GetList().Where(x => x.CompanyId == companyId && x.ExternalId == newSupplier.ExternalId).ToList();
                    if (existingSuppliers.Count == 0)
                    {
                        toAddSuppliers.Add(newSupplier);
                    }
                    else
                    {
                        foreach (Supplier supplier in existingSuppliers)
                        {
                            supplier.Name = lineValues[NAME];
                            suppliersRep.Update(supplier);
                        }
                    }
                }
                if (!suppliersRep.AddList(toAddSuppliers))
                {
                    noErros   = false;
                    errorType = Loc.Dic.error_database_error;
                }
            }
            if (!noErros)
            {
                return(errorType);
            }
            return("OK");
        }
Exemplo n.º 12
0
        public static string ImportSuppliers(Stream stream, int companyId)
        {
            const int EXTERNALID = 0;
            const int NAME = 1;
            List<Supplier> toAddSuppliers = new List<Supplier>();
            byte[] fileBytes = new byte[stream.Length];
            stream.Read(fileBytes, 0, Convert.ToInt32(stream.Length));
            string fileContent = System.Text.Encoding.Default.GetString(fileBytes);

            string[] fileLines = fileContent.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
            int firstValuesLine = 0;
            bool noErros = true;
            string errorType = String.Empty;
            using (SuppliersRepository suppliersRep = new SuppliersRepository(companyId))
            {
                for (int i = firstValuesLine; i < fileLines.Length; i++)
                {
                    string[] lineValues = fileLines[i].Split('\t');
                    for (int vIndex = 0; vIndex < lineValues.Length; vIndex++)
                    {
                        lineValues[vIndex] = lineValues[vIndex].Replace("\"", "");
                    }

                    Supplier newSupplier;
                    if (!(int.Parse(lineValues[EXTERNALID]) > 0))
                    {
                        errorType = Loc.Dic.error_invalid_form;
                        break;
                    }
                    if (lineValues[NAME] == null)
                    {
                        errorType = Loc.Dic.error_invalid_form;
                        break;
                    }
                    try
                    {
                        newSupplier = new Supplier()
                        {
                            CompanyId = companyId,
                            ExternalId = lineValues[EXTERNALID],
                            Name = lineValues[NAME],
                        };
                    }
                    catch
                    {
                        noErros = false;
                        errorType = Loc.Dic.Error_FileParseError;
                        break;
                    }
                    List<Supplier> existingSuppliers = suppliersRep.GetList().Where(x => x.CompanyId == companyId && x.ExternalId == newSupplier.ExternalId).ToList();
                    if (existingSuppliers.Count == 0) toAddSuppliers.Add(newSupplier);
                    else
                    {
                        foreach (Supplier supplier in existingSuppliers)
                        {
                            supplier.Name = lineValues[NAME];
                            suppliersRep.Update(supplier);
                        }
                    }
                }
                if (!suppliersRep.AddList(toAddSuppliers))
                {
                    noErros = false;
                    errorType = Loc.Dic.error_database_error;
                }
            }
            if (!noErros) return errorType;
            return "OK";
        }
Exemplo n.º 13
0
        public ActionResult SuppliersEntrence(int page = FIRST_PAGE, string sortby = NO_SORT_BY, string order = DEFAULT_DESC_ORDER, int VAT_Number = 0)
        {
            CultureInfo ci = new CultureInfo("He");
            System.Threading.Thread.CurrentThread.CurrentUICulture = ci;
            System.Threading.Thread.CurrentThread.CurrentCulture =
            CultureInfo.CreateSpecificCulture(ci.Name);

            using (SuppliersRepository supRep = new SuppliersRepository(CurrentUser.CompanyId))
            using (OrdersRepository orderRep = new OrdersRepository(CurrentUser.CompanyId))
            {
                Supplier supplier = supRep.GetList().SingleOrDefault(x => x.VAT_Number == VAT_Number);

                IEnumerable<Order> orders;

                orders = orderRep.GetList("Orders_Statuses", "Supplier", "User").Where(x => x.SupplierId == supplier.Id);

                if (orders != null)
                {
                    int numberOfItems = orders.Count();
                    int numberOfPages = numberOfItems / ITEMS_PER_PAGE;
                    if (numberOfItems % ITEMS_PER_PAGE != 0)
                        numberOfPages++;

                    if (page <= 0)
                        page = FIRST_PAGE;
                    if (page > numberOfPages)
                        page = numberOfPages;

                    if (sortby != NO_SORT_BY)
                    {
                        Func<Func<Order, dynamic>, IEnumerable<Order>> orderFunction;

                        if (order == DEFAULT_DESC_ORDER)
                            orderFunction = x => orders.OrderByDescending(x);
                        else
                            orderFunction = x => orders.OrderBy(x);

                        switch (sortby)
                        {
                            case "username":
                            default:
                                orders = orderFunction(x => x.User.FirstName + " " + x.User.LastName);
                                break;
                            case "number":
                                orders = orderFunction(x => x.OrderNumber);
                                break;
                            case "creation":
                                orders = orderFunction(x => x.CreationDate);
                                break;
                            case "supplier":
                                orders = orderFunction(x => x.Supplier.Name);
                                break;
                            case "status":
                                orders = orderFunction(x => x.StatusId);
                                break;
                            case "price":
                                orders = orderFunction(x => x.Price);
                                break;
                        }
                    }

                    orders = orders
                        .Skip((page - 1) * ITEMS_PER_PAGE)
                        .Take(ITEMS_PER_PAGE)
                        .ToList();

                    ViewBag.Sortby = sortby;
                    ViewBag.Order = order;
                    ViewBag.CurrPage = page;
                    ViewBag.NumberOfPages = numberOfPages;

                    return View(orders.ToList());
                }
                else
                {
                    return Error(Loc.Dic.error_order_get_error);
                }
            }
        }
Exemplo n.º 14
0
        public ActionResult Index(int page = FIRST_PAGE, string sortby = DEFAULT_SORT, string order = DEFAULT_DESC_ORDER)
        {
            if (!Authorized(RoleType.SystemManager))
                return Error(Loc.Dic.error_no_permission);

            IEnumerable<Supplier> suppliers;
            using (SuppliersRepository suppliersRep = new SuppliersRepository(CurrentUser.CompanyId))
            {
                suppliers = suppliersRep.GetList().Where(x => x.CompanyId == CurrentUser.CompanyId);

                suppliers = Pagination(suppliers, page, sortby, order);

                return View(suppliers.ToList());
            }
        }
Exemplo n.º 15
0
        public JsonResult GetAll(bool firstNull = false)
        {
            if (Authorized(RoleType.OrdersWriter))
            {
                List<AjaxSupplier> allSuppliers;
                using (SuppliersRepository suppRep = new SuppliersRepository(CurrentUser.CompanyId))
                {
                    allSuppliers = suppRep.GetList()
                        .Where(x => x.CompanyId == CurrentUser.CompanyId)
                        .Select(
                            supp => new AjaxSupplier()
                            {
                                Id = supp.Id,
                                Name = supp.Name,
                                VAT_Number = supp.VAT_Number.HasValue ? supp.VAT_Number.Value : 0,
                                Phone_Number = supp.Phone_Number,
                                Activity_Hours = supp.Activity_Hours,
                                Additional_Phone = supp.Additional_Phone,
                                Address = supp.Address,
                                Branch_Line = supp.Branch_line,
                                City = supp.City,
                                Crew_Number = supp.Crew_Number,
                                Customer_Number = supp.Customer_Number,
                                EMail = supp.EMail,
                                Fax = supp.Fax,
                                Presentor_name = supp.Presentor_name,
                                Notes = supp.Notes,
                                CreationDate = supp.CreationDate
                            })
                        .ToList();
                }

                if (firstNull)
                    allSuppliers.Insert(0, new AjaxSupplier() { Id = null, Name = Loc.Dic.SelectNone });

                if (allSuppliers != null)
                {
                    return Json(new { gotData = true, data = allSuppliers, message = String.Empty }, JsonRequestBehavior.AllowGet);
                }
                else
                {
                    return Json(new { gotData = false, message = Loc.Dic.error_suppliers_get_error }, JsonRequestBehavior.AllowGet);
                }
            }
            else
            {
                return Json(new { gotData = false, message = Loc.Dic.error_no_permission }, JsonRequestBehavior.AllowGet);
            }
        }