Exemplo n.º 1
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.º 2
0
        public ActionResult Create(Inventory inventory)
        {
            if (ModelState.IsValid)
            {
                inventory.CompanyId = CurrentUser.CompanyId;
                inventory.AddedBy = CurrentUser.UserId;
                inventory.RemainingQuantity = inventory.OriginalQuantity;
                inventory.CreationDate = DateTime.Now;

                using (InventoryRepository inventoryRepository = new InventoryRepository(CurrentUser.CompanyId))
                {
                    if(inventoryRepository.Create(inventory))
                        return RedirectToAction("Index");
                    return Error(Loc.Dic.Error_DatabaseError);
                }

            }

            //using (OrderItemsRepository orderItemsRepository = new OrderItemsRepository())
            using (LocationsRepository locationsRepository = new LocationsRepository(CurrentUser.CompanyId))
            //using (InventoryRepository inventoryRepository = new InventoryRepository())
            {
                //ViewBag.RelatedInventoryItem = new SelectList(orderItemsRepository.GetList(), "Id", "Title" + "SubTitle");
                ViewBag.LocationId = new SelectList(locationsRepository.GetList().Where(x => x.CompanyId == CurrentUser.CompanyId), "Id", "Name");
            }
            return View(inventory);
        }
Exemplo n.º 3
0
        public ActionResult Create(Inventory inventory)
        {
            if (ModelState.IsValid)
            {
                inventory.CompanyId         = CurrentUser.CompanyId;
                inventory.AddedBy           = CurrentUser.UserId;
                inventory.RemainingQuantity = inventory.OriginalQuantity;
                inventory.CreationDate      = DateTime.Now;

                using (InventoryRepository inventoryRepository = new InventoryRepository(CurrentUser.CompanyId))
                {
                    if (inventoryRepository.Create(inventory))
                    {
                        return(RedirectToAction("Index"));
                    }
                    return(Error(Loc.Dic.Error_DatabaseError));
                }
            }

            //using (OrderItemsRepository orderItemsRepository = new OrderItemsRepository())
            using (LocationsRepository locationsRepository = new LocationsRepository(CurrentUser.CompanyId))
            //using (InventoryRepository inventoryRepository = new InventoryRepository())
            {
                //ViewBag.RelatedInventoryItem = new SelectList(orderItemsRepository.GetList(), "Id", "Title" + "SubTitle");
                ViewBag.LocationId = new SelectList(locationsRepository.GetList().Where(x => x.CompanyId == CurrentUser.CompanyId), "Id", "Name");
            }
            return(View(inventory));
        }
Exemplo n.º 4
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.º 5
0
        public ActionResult Index(int page = FIRST_PAGE, string sortby = DEFAULT_SORT, string order = DEFAULT_DESC_ORDER)
        {
            if (!Authorized(RoleType.InventoryManager))
            {
                return(Error(Loc.Dic.error_no_permission));
            }

            IEnumerable <Location> locations;

            using (LocationsRepository locationsRep = new LocationsRepository(CurrentUser.CompanyId))
            {
                locations = locationsRep.GetList().Where(x => x.CompanyId == CurrentUser.CompanyId);

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

                return(View(locations.ToList()));
            }
        }
Exemplo n.º 6
0
        public ActionResult AddToInventory(int id = 0)
        {
            if (!Authorized(RoleType.InventoryManager)) return Error(Loc.Dic.error_no_permission);

            Order order;
            List<Location> locations = null;
            AddToInventoryModel model = new AddToInventoryModel();

            using (OrdersRepository orderRep = new OrdersRepository(CurrentUser.CompanyId))
            using (LocationsRepository locationsRep = new LocationsRepository(CurrentUser.CompanyId))
            {
                order = orderRep.GetEntity(id, "Supplier", "Orders_OrderToItem", "Orders_OrderToItem.Orders_Items");
                if (order == null) return Error(Loc.Dic.error_order_not_found);
                if (order.StatusId < (int)StatusType.InvoiceApprovedByOrderCreatorPendingFileExport) return Error(Loc.Dic.error_order_not_approved);

                locations = locationsRep.GetList().OrderBy(x => x.Name).ToList();
                if (locations == null || locations.Count == 0) return Error(Loc.Dic.error_no_locations_found);
            }

            model.OrderId = order.Id;
            model.OrderItems = order.Orders_OrderToItem.ToList();
            model.LocationsList = new SelectList(locations, "Id", "Name");
            return View(model);
        }
Exemplo n.º 7
0
        public ActionResult Edit(int id = 0)
        {
            Inventory        inventory;
            List <Inventory> relatedInventoryItemList;
            List <Location>  locationsList;

            using (InventoryRepository inventoryRep = new InventoryRepository(CurrentUser.CompanyId))
                using (LocationsRepository locationsRep = new LocationsRepository(CurrentUser.CompanyId))
                {
                    inventory = inventoryRep.GetEntity(id);

                    if (inventory == null)
                    {
                        return(Error(Loc.Dic.error_inventory_item_not_found));
                    }

                    locationsList            = locationsRep.GetList().ToList();
                    relatedInventoryItemList = inventoryRep.GetList("Orders_Items").ToList();
                }

            ViewBag.RelatedInventoryItem = new SelectList(relatedInventoryItemList, "Id", "Orders_Items.Title", inventory.RelatedInventoryItem);
            ViewBag.LocationId           = new SelectList(locationsList, "Id", "Name", inventory.LocationId);
            return(View(inventory));
        }
Exemplo n.º 8
0
        public ActionResult AddToInventory(AddToInventoryModel model)
        {
            if (!Authorized(RoleType.InventoryManager)) return Error(Loc.Dic.error_no_permission);

            Order order;
            List<Inventory> createdItems = new List<Inventory>();
            List<Location> locations;
            bool noCreationErrors = true;

            using (InventoryRepository inventoryRep = new InventoryRepository(CurrentUser.CompanyId))
            using (LocationsRepository locationsRep = new LocationsRepository(CurrentUser.CompanyId))
            using (OrdersRepository ordersRep = new OrdersRepository(CurrentUser.CompanyId))
            {
                order = ordersRep.GetEntity(model.OrderId, "Supplier", "Orders_OrderToItem", "Orders_OrderToItem.Orders_Items");

                if (order == null) return Error(Loc.Dic.error_order_get_error);
                if (order.WasAddedToInventory) return Error(Loc.Dic.error_order_was_added_to_inventory);
                if (order.StatusId < (int)StatusType.InvoiceApprovedByOrderCreatorPendingFileExport) return Error(Loc.Dic.error_invoice_not_scanned_and_approved);

                locations = locationsRep.GetList().ToList();
                if (locations == null || locations.Count == 0) return Error(Loc.Dic.error_no_locations_found);

                foreach (SplittedInventoryItem splitedItem in model.InventoryItems)
                {
                    if (!noCreationErrors) break;
                    if (!splitedItem.AddToInventory) continue;

                    int? itemId = splitedItem.ItemsToAdd[0].ItemId;
                    Orders_OrderToItem originalItem = order.Orders_OrderToItem.FirstOrDefault(x => x.Id == itemId);
                    bool isValidList = originalItem != null && splitedItem.ItemsToAdd.All(x => x.ItemId == itemId);

                    if (!isValidList) { noCreationErrors = false; break; }

                    if (splitedItem.ItemsToAdd.Count == 1)
                    {
                        Inventory listItem = splitedItem.ItemsToAdd[0];
                        if (!locations.Any(x => x.Id == listItem.LocationId)) return Error(Loc.Dic.error_invalid_form);

                        Inventory newItem = new Inventory()
                        {
                            AssignedTo = listItem.AssignedTo,
                            LocationId = listItem.LocationId,
                            Notes = listItem.Notes,
                            SerialNumber = listItem.SerialNumber,
                            Status = listItem.Status,
                            WarrentyPeriodStart = listItem.WarrentyPeriodStart,
                            WarrentyPeriodEnd = listItem.WarrentyPeriodEnd,
                            ItemId = originalItem.ItemId,
                            OrderId = order.Id,
                            CompanyId = CurrentUser.CompanyId,
                            IsOutOfInventory = false,
                            OriginalQuantity = originalItem.Quantity,
                            RemainingQuantity = originalItem.Quantity
                        };

                        if (!inventoryRep.Create(newItem)) { noCreationErrors = false; break; }
                        createdItems.Add(newItem);
                    }
                    else if (originalItem.Quantity == splitedItem.ItemsToAdd.Count)
                    {
                        foreach (var item in splitedItem.ItemsToAdd)
                        {
                            if (!locations.Any(x => x.Id == item.LocationId)) { noCreationErrors = false; break; }

                            item.ItemId = originalItem.ItemId;
                            item.OrderId = order.Id;
                            item.CompanyId = CurrentUser.CompanyId;
                            item.IsOutOfInventory = false;

                            if (!inventoryRep.Create(item)) { noCreationErrors = false; break; }
                            createdItems.Add(item);
                        }
                    }
                    else { noCreationErrors = false; break; }
                }

                if (!noCreationErrors)
                {
                    foreach (var item in createdItems)
                    {
                        inventoryRep.Delete(item.Id);
                    }

                    return Error(Loc.Dic.error_inventory_create_error);
                }

                order.WasAddedToInventory = true;
                order.LastStatusChangeDate = DateTime.Now;
                if (ordersRep.Update(order) == null) return Error(Loc.Dic.error_database_error);

                bool hasInventoryItems = model.InventoryItems.Any(x => x.AddToInventory);
                string notes = hasInventoryItems ? Loc.Dic.AddToInventory_with_inventory_items : Loc.Dic.AddToInventory_no_inventory_items;

                int? historyActionId = null;
                historyActionId = (int)HistoryActions.AddedToInventory;
                Orders_History orderHistory = new Orders_History();
                using (OrdersHistoryRepository ordersHistoryRep = new OrdersHistoryRepository(CurrentUser.CompanyId, CurrentUser.UserId, order.Id))
                    if (historyActionId.HasValue) ordersHistoryRep.Create(orderHistory, historyActionId.Value, notes);

                return RedirectToAction("PendingInventory");
            }
        }
Exemplo n.º 9
0
        public ActionResult Index(int page = FIRST_PAGE, string sortby = DEFAULT_SORT, string order = DEFAULT_DESC_ORDER)
        {
            if (!Authorized(RoleType.InventoryManager))
                return Error(Loc.Dic.error_no_permission);

            IEnumerable<Location> locations;
            using (LocationsRepository locationsRep = new LocationsRepository(CurrentUser.CompanyId))
            {
                locations = locationsRep.GetList().Where(x => x.CompanyId == CurrentUser.CompanyId);

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

                return View(locations.ToList());
            }
        }
Exemplo n.º 10
0
        public ActionResult Edit(int id = 0)
        {
            Inventory inventory;
            List<Inventory> relatedInventoryItemList;
            List<Location> locationsList;
            using (InventoryRepository inventoryRep = new InventoryRepository(CurrentUser.CompanyId))
            using (LocationsRepository locationsRep = new LocationsRepository(CurrentUser.CompanyId))
            {
                inventory = inventoryRep.GetEntity(id);

                if (inventory == null) return Error(Loc.Dic.error_inventory_item_not_found);

                locationsList = locationsRep.GetList().ToList();
                relatedInventoryItemList = inventoryRep.GetList("Orders_Items").ToList();
            }

            ViewBag.RelatedInventoryItem = new SelectList(relatedInventoryItemList, "Id", "Orders_Items.Title", inventory.RelatedInventoryItem);
            ViewBag.LocationId = new SelectList(locationsList, "Id", "Name", inventory.LocationId);
            return View(inventory);
        }