Exemplo n.º 1
0
        public ActionResult Details(int id = 0)
        {
            return(Error(Loc.Dic.Error_NoPermission));

            if (Authorized(RoleType.SystemManager))
            {
                Budgets_Expenses expense;
                using (BudgetsExpensesRepository expensesRep = new BudgetsExpensesRepository())
                {
                    expense = expensesRep.GetEntity(id, "Budget", "Projects_ParentProject", "Projects_SubProject");
                }

                if (expense != null)
                {
                    if (expense.CompanyId == CurrentUser.CompanyId)
                    {
                        return(View(expense));
                    }
                    else
                    {
                        return(Error(Loc.Dic.error_no_permission));
                    }
                }
                else
                {
                    return(Error(Loc.Dic.error_expenses_get_error));
                }
            }
            else
            {
                return(Error(Loc.Dic.error_no_permission));
            }
        }
        public ActionResult Edit(int id = 0)
        {
            return(Error(Loc.Dic.error_no_permission));

            if (Authorized(RoleType.SystemManager))
            {
                Budgets_Allocations     allocation;
                List <SelectListItemDB> incomesList;
                List <SelectListItemDB> expensesList;

                using (AllocationRepository allocationRep = new AllocationRepository(CurrentUser.CompanyId))
                    using (BudgetsRepository budgetsRep = new BudgetsRepository(CurrentUser.CompanyId))
                        using (BudgetsIncomesRepository incomesRep = new BudgetsIncomesRepository())
                            using (BudgetsExpensesRepository expensesRep = new BudgetsExpensesRepository())
                            {
                                allocation = allocationRep.GetEntity(id);

                                if (allocation != null)
                                {
                                    if (allocation.CompanyId == CurrentUser.CompanyId)
                                    {
                                        incomesList = incomesRep.GetList()
                                                      .Where(income => income.CompanyId == CurrentUser.CompanyId && income.BudgetId == allocation.BudgetId)
                                                      .Select(x => new SelectListItemDB()
                                        {
                                            Id = x.Id, Name = x.CustomName
                                        })
                                                      .ToList();

                                        expensesList = expensesRep.GetList()
                                                       .Where(expense => expense.CompanyId == CurrentUser.CompanyId && expense.BudgetId == allocation.BudgetId)
                                                       .Select(x => new SelectListItemDB()
                                        {
                                            Id = x.Id, Name = x.CustomName
                                        })
                                                       .ToList();

                                        ViewBag.IncomeId  = new SelectList(incomesList, "Id", "Name", allocation.IncomeId);
                                        ViewBag.ExpenseId = new SelectList(expensesList, "Id", "Name", allocation.ExpenseId);

                                        return(View(allocation));
                                    }
                                    else
                                    {
                                        return(Error(Loc.Dic.error_no_permission));
                                    }
                                }
                                else
                                {
                                    return(Error(Loc.Dic.error_database_error));
                                }
                            }
            }
            else
            {
                return(Error(Loc.Dic.error_no_permission));
            }
        }
        public ActionResult Create(int id = 0)
        {
            return Error(Loc.Dic.error_no_permission);
            if (Authorized(RoleType.SystemManager))
            {
                Budget budget;
                List<SelectListItemDB> incomesList;
                List<SelectListItemDB> expensesList;

                using (BudgetsRepository budgetsRep = new BudgetsRepository(CurrentUser.CompanyId))
                using (BudgetsIncomesRepository incomesRep = new BudgetsIncomesRepository())
                using (BudgetsExpensesRepository expensesRep = new BudgetsExpensesRepository())
                {
                    budget = budgetsRep.GetEntity(id);

                    if (budget != null)
                    {
                        if (budget.CompanyId == CurrentUser.CompanyId)
                        {
                            incomesList = incomesRep.GetList()
                                .Where(income => income.CompanyId == CurrentUser.CompanyId && income.BudgetId == budget.Id)
                                .Select(x => new SelectListItemDB() { Id = x.Id, Name = x.CustomName })
                                .ToList();

                            expensesList = expensesRep.GetList()
                                .Where(expense => expense.CompanyId == CurrentUser.CompanyId && expense.BudgetId == budget.Id)
                                .Select(x => new SelectListItemDB() { Id = x.Id, Name = x.CustomName })
                                .ToList();

                            ViewBag.BudgetId = id;
                            ViewBag.IncomeId = new SelectList(incomesList, "Id", "Name");
                            ViewBag.ExpenseId = new SelectList(expensesList, "Id", "Name");

                            return View();
                        }
                        else
                        {
                            return Error(Loc.Dic.error_no_permission);
                        }
                    }
                    else
                    {
                        return Error(Loc.Dic.error_database_error);
                    }
                }
            }
            else
            {
                return Error(Loc.Dic.error_no_permission);
            }
        }
Exemplo n.º 4
0
        public ActionResult Create()
        {
            return(Error(Loc.Dic.Error_NoPermission));

            if (Authorized(RoleType.SystemManager))
            {
                using (BudgetsRepository budgetRep = new BudgetsRepository(CurrentUser.CompanyId))
                    using (BudgetsExpensesRepository expensesRep = new BudgetsExpensesRepository())
                        using (ParentProjectsRepository projectsRep = new ParentProjectsRepository())
                            using (SubProjectsRepository subProjectsRep = new SubProjectsRepository())
                            {
                                List <SelectListItemDB> budgetsList = budgetRep.GetList()
                                                                      .Where(budget => budget.CompanyId == CurrentUser.CompanyId && budget.Year >= (DateTime.Now.Year - 1))
                                                                      .Select(a => new { Id = a.Id, Name = a.Year })
                                                                      .AsEnumerable()
                                                                      .Select(x => new SelectListItemDB()
                                {
                                    Id = x.Id, Name = x.Name.ToString()
                                })
                                                                      .ToList();

                                List <SelectListItemDB> projectsList = projectsRep.GetList()
                                                                       .Where(project => project.CompanyId == CurrentUser.CompanyId && project.IsActive)
                                                                       .Select(x => new SelectListItemDB()
                                {
                                    Id = x.Id, Name = x.Name
                                })
                                                                       .ToList();

                                List <SelectListItemDB> subProjectsList = subProjectsRep.GetList()
                                                                          .Where(subProject => subProject.CompanyId == CurrentUser.CompanyId && subProject.IsActive)
                                                                          .Select(x => new SelectListItemDB()
                                {
                                    Id = x.Id, Name = x.Name
                                })
                                                                          .ToList();

                                ViewBag.BudgetId        = new SelectList(budgetsList, "Id", "Name");
                                ViewBag.ParentProjectId = new SelectList(projectsList, "Id", "Name");
                                ViewBag.SubProjectId    = new SelectList(subProjectsList, "Id", "Name");
                            }

                return(View());
            }
            else
            {
                return(Error(Loc.Dic.error_no_permission));
            }
        }
Exemplo n.º 5
0
        public ActionResult Delete(int id = 0)
        {
            return(Error(Loc.Dic.Error_NoPermission));

            if (Authorized(RoleType.SystemManager))
            {
                Budgets_Expenses expense;
                using (OrdersRepository ordersRep = new OrdersRepository(CurrentUser.CompanyId))
                    using (BudgetsExpensesRepository expensesRep = new BudgetsExpensesRepository())
                    {
                        expense = expensesRep.GetEntity(id, "Budget", "Projects_ParentProject", "Projects_SubProject");

                        if (expense != null)
                        {
                            if (expense.CompanyId == CurrentUser.CompanyId)
                            {
                                if (
                                    !ordersRep.GetList()
                                    .Where(x => x.CompanyId == expense.Id) //.Where(x => x.Budgets_Allocations.ExpenseId == expense.Id)
                                    .Any(o => o.StatusId >= (int)StatusType.ApprovedPendingInvoice)
                                    )
                                {
                                    return(View(expense));
                                }
                                else
                                {
                                    return(Error(Loc.Dic.error_expenses_delete_has_approved_orders));
                                }
                            }
                            else
                            {
                                return(Error(Loc.Dic.error_no_permission));
                            }
                        }
                        else
                        {
                            return(Error(Loc.Dic.error_expenses_get_error));
                        }
                    }
            }
            else
            {
                return(Error(Loc.Dic.error_no_permission));
            }
        }
Exemplo n.º 6
0
        public ActionResult Create()
        {
            return Error(Loc.Dic.Error_NoPermission);
            if (Authorized(RoleType.SystemManager))
            {
                using (BudgetsRepository budgetRep = new BudgetsRepository(CurrentUser.CompanyId))
                using (BudgetsExpensesRepository expensesRep = new BudgetsExpensesRepository())
                using (ParentProjectsRepository projectsRep = new ParentProjectsRepository())
                using (SubProjectsRepository subProjectsRep = new SubProjectsRepository())
                {
                    List<SelectListItemDB> budgetsList = budgetRep.GetList()
                        .Where(budget => budget.CompanyId == CurrentUser.CompanyId && budget.Year >= (DateTime.Now.Year - 1))
                        .Select(a => new { Id = a.Id, Name = a.Year })
                        .AsEnumerable()
                        .Select(x => new SelectListItemDB() { Id = x.Id, Name = x.Name.ToString() })
                        .ToList();

                    List<SelectListItemDB> projectsList = projectsRep.GetList()
                        .Where(project => project.CompanyId == CurrentUser.CompanyId && project.IsActive)
                        .Select(x => new SelectListItemDB() { Id = x.Id, Name = x.Name })
                        .ToList();

                    List<SelectListItemDB> subProjectsList = subProjectsRep.GetList()
                       .Where(subProject => subProject.CompanyId == CurrentUser.CompanyId && subProject.IsActive)
                       .Select(x => new SelectListItemDB() { Id = x.Id, Name = x.Name })
                       .ToList();

                    ViewBag.BudgetId = new SelectList(budgetsList, "Id", "Name");
                    ViewBag.ParentProjectId = new SelectList(projectsList, "Id", "Name");
                    ViewBag.SubProjectId = new SelectList(subProjectsList, "Id", "Name");
                }

                return View();
            }
            else
            {
                return Error(Loc.Dic.error_no_permission);
            }
        }
Exemplo n.º 7
0
        public ActionResult Edit(Budgets_Expenses budgets_expenses)
        {
            return Error(Loc.Dic.Error_NoPermission);
            if (Authorized(RoleType.SystemManager))
            {
                if (ModelState.IsValid)
                {
                    Budgets_Expenses expenseFromDB;
                    Budget budget;
                    Projects_ParentProject project;
                    Projects_SubProject subProject;

                    using (BudgetsExpensesRepository expensesRep = new BudgetsExpensesRepository())
                    using (BudgetsRepository budgetRep = new BudgetsRepository(CurrentUser.CompanyId))
                    using (ParentProjectsRepository projectsRep = new ParentProjectsRepository())
                    using (SubProjectsRepository subProjectsRep = new SubProjectsRepository())
                    {
                        expenseFromDB = expensesRep.GetEntity(budgets_expenses.Id);

                        budget = budgetRep.GetEntity(budgets_expenses.BudgetId);
                        project = projectsRep.GetEntity(budgets_expenses.ParentProjectId.Value);
                        subProject = subProjectsRep.GetEntity(budgets_expenses.SubProjectId.Value);

                        if (expenseFromDB != null)
                        {
                            if (budget != null && project != null && subProject != null)
                            {
                                if (budget.CompanyId == CurrentUser.CompanyId && project.CompanyId == CurrentUser.CompanyId && subProject.CompanyId == CurrentUser.CompanyId)
                                {
                                    if (project.IsActive && subProject.IsActive)
                                    {
                                        if (budgets_expenses.Amount < expenseFromDB.Amount)
                                        {
                                            decimal? allocatedToExpense;
                                            using (AllocationRepository allocationsRep = new AllocationRepository(CurrentUser.CompanyId))
                                            {
                                                allocatedToExpense = allocationsRep.GetList()
                                                    .Where(x => x.ExpenseId == expenseFromDB.Id)
                                                    .Sum(allocation => (decimal?)allocation.CompanyId); //.Sum(allocation => (decimal?)allocation.Amount);
                                            }

                                            if (allocatedToExpense.HasValue && allocatedToExpense > budgets_expenses.Amount)
                                                return Error(Loc.Dic.error_expenses_allocations_exeeds_amount);
                                        }

                                        expenseFromDB.BudgetId = budgets_expenses.BudgetId;
                                        expenseFromDB.ParentProjectId = budgets_expenses.ParentProjectId;
                                        expenseFromDB.SubProjectId = budgets_expenses.SubProjectId;
                                        expenseFromDB.Amount = budgets_expenses.Amount;
                                        expenseFromDB.CustomName = budgets_expenses.CustomName;

                                        Budgets_Expenses update = expensesRep.Update(expenseFromDB);

                                        if (update != null)
                                            return RedirectToAction("Index");
                                        else
                                            return Error(Loc.Dic.error_expenses_create_error);
                                    }
                                    else
                                    {
                                        return Error(Loc.Dic.error_invalid_form);
                                    }
                                }
                                else
                                {
                                    return Error(Loc.Dic.error_no_permission);
                                }
                            }
                            else
                            {
                                return Error(Loc.Dic.error_database_error);
                            }
                        }
                        else
                        {
                            return Error(Loc.Dic.error_expenses_get_error);
                        }
                    }
                }
                else
                {
                    return Error(ModelState);
                }
            }
            else
            {
                return Error(Loc.Dic.error_no_permission);
            }
        }
Exemplo n.º 8
0
        public ActionResult Edit(int id = 0)
        {
            return Error(Loc.Dic.Error_NoPermission);
            if (Authorized(RoleType.SystemManager))
            {
                Budgets_Expenses expense;

                using (BudgetsExpensesRepository expensesRep = new BudgetsExpensesRepository())
                using (BudgetsRepository budgetRep = new BudgetsRepository(CurrentUser.CompanyId))
                using (ParentProjectsRepository projectsRep = new ParentProjectsRepository())
                using (SubProjectsRepository subProjectsRep = new SubProjectsRepository())
                {
                    expense = expensesRep.GetEntity(id);

                    if (expense != null)
                    {
                        if (expense.CompanyId == CurrentUser.CompanyId)
                        {
                            List<SelectListItemDB> budgetsList;
                            List<SelectListItemDB> projectsList;
                            List<SelectListItemDB> subProjectsList;

                            try
                            {
                                budgetsList = budgetRep.GetList()
                                    .Where(budget => budget.CompanyId == CurrentUser.CompanyId && budget.Year >= (DateTime.Now.Year - 1))
                                    .Select(a => new { Id = a.Id, Name = a.Year })
                                    .AsEnumerable()
                                    .Select(x => new SelectListItemDB() { Id = x.Id, Name = x.Name.ToString() })
                                    .ToList();

                                projectsList = projectsRep.GetList()
                                    .Where(type => type.CompanyId == CurrentUser.CompanyId)
                                    .Select(x => new SelectListItemDB() { Id = x.Id, Name = x.Name })
                                    .ToList();

                                subProjectsList = subProjectsRep.GetList()
                                   .Where(type => type.CompanyId == CurrentUser.CompanyId)
                                   .Select(x => new SelectListItemDB() { Id = x.Id, Name = x.Name })
                                   .ToList();
                            }
                            catch
                            {
                                return Error(Loc.Dic.error_database_error);
                            }

                            ViewBag.BudgetId = new SelectList(budgetsList, "Id", "Name", expense.BudgetId);
                            ViewBag.ParentProjectId = new SelectList(projectsList, "Id", "Name", expense.ParentProjectId);
                            ViewBag.SubProjectId = new SelectList(subProjectsList, "Id", "Name", expense.SubProjectId);

                            return View(expense);
                        }
                        else
                        {
                            return Error(Loc.Dic.error_no_permission);
                        }
                    }
                    else
                    {
                        return Error(Loc.Dic.error_income_get_error);
                    }
                }
            }
            else
            {
                return Error(Loc.Dic.error_no_permission);
            }
        }
Exemplo n.º 9
0
        public ActionResult Details(int id = 0)
        {
            return Error(Loc.Dic.Error_NoPermission);
            if (Authorized(RoleType.SystemManager))
            {
                Budgets_Expenses expense;
                using (BudgetsExpensesRepository expensesRep = new BudgetsExpensesRepository())
                {
                    expense = expensesRep.GetEntity(id, "Budget", "Projects_ParentProject", "Projects_SubProject");
                }

                if (expense != null)
                {
                    if (expense.CompanyId == CurrentUser.CompanyId)
                    {
                        return View(expense);
                    }
                    else
                    {
                        return Error(Loc.Dic.error_no_permission);
                    }
                }
                else
                {
                    return Error(Loc.Dic.error_expenses_get_error);
                }
            }
            else
            {
                return Error(Loc.Dic.error_no_permission);
            }
        }
Exemplo n.º 10
0
        public ActionResult DeleteConfirmed(int id)
        {
            return Error(Loc.Dic.Error_NoPermission);
            if (Authorized(RoleType.SystemManager))
            {
                Budgets_Expenses expense;
                using (BudgetsExpensesRepository expensesRep = new BudgetsExpensesRepository())
                using (OrdersRepository ordersRep = new OrdersRepository(CurrentUser.CompanyId))
                using (AllocationRepository allocationsRep = new AllocationRepository(CurrentUser.CompanyId))
                using (BasketsToAllocationsRepository permissionAllocationsRep = new BasketsToAllocationsRepository())
                {
                    expense = expensesRep.GetEntity(id, "Budget", "Budgets_Incomes_types", "Budgets_Incomes_Institutions");

                    if (expense != null)
                    {
                        if (expense.CompanyId == CurrentUser.CompanyId)
                        {
                            List<Budgets_Allocations> expenseAllocations;
                            List<Budgets_BasketsToAllocation> expensePermissions;
                            List<Order> expenseOrders = ordersRep.GetList().Where(x => x.CompanyId == expense.Id).ToList(); //List<Order> expenseOrders = ordersRep.GetList().Where(x => x.Budgets_Allocations.ExpenseId == expense.Id).ToList();

                            if (!expenseOrders.Any(o => o.StatusId >= (int)StatusType.ApprovedPendingInvoice))
                            {
                                try
                                {
                                    expenseAllocations = allocationsRep.GetList().Where(x => x.ExpenseId == expense.Id).ToList();
                                    expensePermissions = permissionAllocationsRep.GetList().Where(x => x.Budgets_Allocations.ExpenseId == expense.Id).ToList();

                                    foreach (var item in expenseOrders)
                                    {
                                        ordersRep.Delete(item.Id);
                                    }

                                    foreach (var item in expensePermissions)
                                    {
                                        permissionAllocationsRep.Delete(item.Id);
                                    }

                                    foreach (var item in expenseAllocations)
                                    {
                                        allocationsRep.Delete(item.Id);
                                    }

                                    expensesRep.Delete(expense.Id);
                                }
                                catch
                                {
                                    return Error(Loc.Dic.error_database_error);
                                }

                                return RedirectToAction("Index");
                            }
                            else
                            {
                                return Error(Loc.Dic.error_expenses_delete_has_approved_orders);
                            }
                        }
                        else
                        {
                            return Error(Loc.Dic.error_no_permission);
                        }
                    }
                    else
                    {
                        return Error(Loc.Dic.error_expenses_get_error);
                    }
                }
            }
            else
            {
                return Error(Loc.Dic.error_no_permission);
            }
        }
        public ActionResult Edit(Budgets_Allocations Budgets_Allocations)
        {
            return Error(Loc.Dic.error_no_permission);
            if (Authorized(RoleType.SystemManager))
            {
                if (ModelState.IsValid)
                {
                    Budgets_Allocations allocation;
                    Budgets_Incomes income;
                    Budgets_Expenses expense;

                    using (BudgetsRepository budgetsRep = new BudgetsRepository(CurrentUser.CompanyId))
                    using (BudgetsIncomesRepository incomesRep = new BudgetsIncomesRepository())
                    using (BudgetsExpensesRepository expensesRep = new BudgetsExpensesRepository())
                    using (AllocationRepository allocationsRep = new AllocationRepository(CurrentUser.CompanyId))
                    using (OrdersRepository ordersRep = new OrdersRepository(CurrentUser.CompanyId))
                    {
                        allocation = allocationsRep.GetEntity(Budgets_Allocations.Id);

                        if (allocation != null)
                        {
                            if (allocation.CompanyId == CurrentUser.CompanyId)
                            {
                                income = incomesRep.GetEntity(Budgets_Allocations.IncomeId.Value);
                                expense = expensesRep.GetEntity(Budgets_Allocations.ExpenseId.Value);

                                if (income != null && expense != null)
                                {
                                    if (income.BudgetId == allocation.BudgetId && expense.BudgetId == allocation.BudgetId)
                                    {
                                        decimal? totalUsed;
                                        decimal? allocatedToExpense;
                                        decimal? allocatedToIncome;

                                        totalUsed = 0; //totalUsed = ordersRep.GetList()
                                        //    .Where(order => order.BudgetAllocationId == Budgets_Allocations.Id && order.StatusId >= (int)StatusType.ApprovedPendingInvoice)
                                        //    .Sum(x => (decimal?)x.Price);

                                        if ((totalUsed ?? 0) > Budgets_Allocations.CompanyId)//if ((totalUsed ?? 0) > Budgets_Allocations.Amount)
                                            return Error(Loc.Dic.error_allocations_amount_is_used);

                                        allocatedToIncome = allocationsRep.GetList()
                                             .Where(x => x.IncomeId == income.Id && x.Id != Budgets_Allocations.Id)
                                             .Sum(alloc => (decimal?)alloc.CompanyId);//.Sum(alloc => (decimal?)alloc.Amount);

                                        if ((allocatedToIncome ?? 0) + Budgets_Allocations.CompanyId > income.Amount)//if ((allocatedToIncome ?? 0) + Budgets_Allocations.Amount > income.Amount)
                                            return Error(Loc.Dic.error_income_full_allocation);

                                        allocatedToExpense = allocationsRep.GetList()
                                            .Where(x => x.ExpenseId == expense.Id && x.Id != Budgets_Allocations.Id)
                                            .Sum(alloc => (decimal?)alloc.CompanyId);//.Sum(alloc => (decimal?)alloc.Amount);

                                        if ((allocatedToExpense ?? 0) + Budgets_Allocations.CompanyId > expense.Amount)//if ((allocatedToExpense ?? 0) + Budgets_Allocations.Amount > expense.Amount)
                                            return Error(Loc.Dic.error_expenses_full_allocation);

                                        allocation.IncomeId = Budgets_Allocations.IncomeId;
                                        allocation.ExpenseId = Budgets_Allocations.ExpenseId;
                                        allocation.CompanyId = Budgets_Allocations.CompanyId;//allocation.Amount = Budgets_Allocations.Amount;

                                        Budgets_Allocations update = allocationsRep.Update(allocation);

                                        if (update != null)
                                            return RedirectToAction("Index");
                                        else
                                            return Error(Loc.Dic.error_allocations_get_error);
                                    }
                                    else
                                    {
                                        return Error(Loc.Dic.error_invalid_form);

                                    }
                                }
                                else
                                {
                                    return Error(Loc.Dic.error_database_error);
                                }
                            }
                            else
                            {
                                return Error(Loc.Dic.error_no_permission);
                            }
                        }
                        else
                        {
                            return Error(Loc.Dic.error_allocations_get_error);
                        }
                    }
                }
                else
                {
                    return Error(ModelState);
                }
            }
            else
            {
                return Error(Loc.Dic.error_no_permission);
            }
        }
Exemplo n.º 12
0
        public ActionResult DeleteConfirmed(int id)
        {
            return(Error(Loc.Dic.Error_NoPermission));

            if (Authorized(RoleType.SystemManager))
            {
                Budgets_Expenses expense;
                using (BudgetsExpensesRepository expensesRep = new BudgetsExpensesRepository())
                    using (OrdersRepository ordersRep = new OrdersRepository(CurrentUser.CompanyId))
                        using (AllocationRepository allocationsRep = new AllocationRepository(CurrentUser.CompanyId))
                            using (BasketsToAllocationsRepository permissionAllocationsRep = new BasketsToAllocationsRepository())
                            {
                                expense = expensesRep.GetEntity(id, "Budget", "Budgets_Incomes_types", "Budgets_Incomes_Institutions");

                                if (expense != null)
                                {
                                    if (expense.CompanyId == CurrentUser.CompanyId)
                                    {
                                        List <Budgets_Allocations>         expenseAllocations;
                                        List <Budgets_BasketsToAllocation> expensePermissions;
                                        List <Order> expenseOrders = ordersRep.GetList().Where(x => x.CompanyId == expense.Id).ToList(); //List<Order> expenseOrders = ordersRep.GetList().Where(x => x.Budgets_Allocations.ExpenseId == expense.Id).ToList();

                                        if (!expenseOrders.Any(o => o.StatusId >= (int)StatusType.ApprovedPendingInvoice))
                                        {
                                            try
                                            {
                                                expenseAllocations = allocationsRep.GetList().Where(x => x.ExpenseId == expense.Id).ToList();
                                                expensePermissions = permissionAllocationsRep.GetList().Where(x => x.Budgets_Allocations.ExpenseId == expense.Id).ToList();

                                                foreach (var item in expenseOrders)
                                                {
                                                    ordersRep.Delete(item.Id);
                                                }

                                                foreach (var item in expensePermissions)
                                                {
                                                    permissionAllocationsRep.Delete(item.Id);
                                                }

                                                foreach (var item in expenseAllocations)
                                                {
                                                    allocationsRep.Delete(item.Id);
                                                }

                                                expensesRep.Delete(expense.Id);
                                            }
                                            catch
                                            {
                                                return(Error(Loc.Dic.error_database_error));
                                            }

                                            return(RedirectToAction("Index"));
                                        }
                                        else
                                        {
                                            return(Error(Loc.Dic.error_expenses_delete_has_approved_orders));
                                        }
                                    }
                                    else
                                    {
                                        return(Error(Loc.Dic.error_no_permission));
                                    }
                                }
                                else
                                {
                                    return(Error(Loc.Dic.error_expenses_get_error));
                                }
                            }
            }
            else
            {
                return(Error(Loc.Dic.error_no_permission));
            }
        }
Exemplo n.º 13
0
        public ActionResult Edit(Budgets_Expenses budgets_expenses)
        {
            return(Error(Loc.Dic.Error_NoPermission));

            if (Authorized(RoleType.SystemManager))
            {
                if (ModelState.IsValid)
                {
                    Budgets_Expenses       expenseFromDB;
                    Budget                 budget;
                    Projects_ParentProject project;
                    Projects_SubProject    subProject;

                    using (BudgetsExpensesRepository expensesRep = new BudgetsExpensesRepository())
                        using (BudgetsRepository budgetRep = new BudgetsRepository(CurrentUser.CompanyId))
                            using (ParentProjectsRepository projectsRep = new ParentProjectsRepository())
                                using (SubProjectsRepository subProjectsRep = new SubProjectsRepository())
                                {
                                    expenseFromDB = expensesRep.GetEntity(budgets_expenses.Id);

                                    budget     = budgetRep.GetEntity(budgets_expenses.BudgetId);
                                    project    = projectsRep.GetEntity(budgets_expenses.ParentProjectId.Value);
                                    subProject = subProjectsRep.GetEntity(budgets_expenses.SubProjectId.Value);

                                    if (expenseFromDB != null)
                                    {
                                        if (budget != null && project != null && subProject != null)
                                        {
                                            if (budget.CompanyId == CurrentUser.CompanyId && project.CompanyId == CurrentUser.CompanyId && subProject.CompanyId == CurrentUser.CompanyId)
                                            {
                                                if (project.IsActive && subProject.IsActive)
                                                {
                                                    if (budgets_expenses.Amount < expenseFromDB.Amount)
                                                    {
                                                        decimal?allocatedToExpense;
                                                        using (AllocationRepository allocationsRep = new AllocationRepository(CurrentUser.CompanyId))
                                                        {
                                                            allocatedToExpense = allocationsRep.GetList()
                                                                                 .Where(x => x.ExpenseId == expenseFromDB.Id)
                                                                                 .Sum(allocation => (decimal?)allocation.CompanyId); //.Sum(allocation => (decimal?)allocation.Amount);
                                                        }

                                                        if (allocatedToExpense.HasValue && allocatedToExpense > budgets_expenses.Amount)
                                                        {
                                                            return(Error(Loc.Dic.error_expenses_allocations_exeeds_amount));
                                                        }
                                                    }

                                                    expenseFromDB.BudgetId        = budgets_expenses.BudgetId;
                                                    expenseFromDB.ParentProjectId = budgets_expenses.ParentProjectId;
                                                    expenseFromDB.SubProjectId    = budgets_expenses.SubProjectId;
                                                    expenseFromDB.Amount          = budgets_expenses.Amount;
                                                    expenseFromDB.CustomName      = budgets_expenses.CustomName;

                                                    Budgets_Expenses update = expensesRep.Update(expenseFromDB);

                                                    if (update != null)
                                                    {
                                                        return(RedirectToAction("Index"));
                                                    }
                                                    else
                                                    {
                                                        return(Error(Loc.Dic.error_expenses_create_error));
                                                    }
                                                }
                                                else
                                                {
                                                    return(Error(Loc.Dic.error_invalid_form));
                                                }
                                            }
                                            else
                                            {
                                                return(Error(Loc.Dic.error_no_permission));
                                            }
                                        }
                                        else
                                        {
                                            return(Error(Loc.Dic.error_database_error));
                                        }
                                    }
                                    else
                                    {
                                        return(Error(Loc.Dic.error_expenses_get_error));
                                    }
                                }
                }
                else
                {
                    return(Error(ModelState));
                }
            }
            else
            {
                return(Error(Loc.Dic.error_no_permission));
            }
        }
Exemplo n.º 14
0
        public ActionResult Edit(int id = 0)
        {
            return(Error(Loc.Dic.Error_NoPermission));

            if (Authorized(RoleType.SystemManager))
            {
                Budgets_Expenses expense;

                using (BudgetsExpensesRepository expensesRep = new BudgetsExpensesRepository())
                    using (BudgetsRepository budgetRep = new BudgetsRepository(CurrentUser.CompanyId))
                        using (ParentProjectsRepository projectsRep = new ParentProjectsRepository())
                            using (SubProjectsRepository subProjectsRep = new SubProjectsRepository())
                            {
                                expense = expensesRep.GetEntity(id);

                                if (expense != null)
                                {
                                    if (expense.CompanyId == CurrentUser.CompanyId)
                                    {
                                        List <SelectListItemDB> budgetsList;
                                        List <SelectListItemDB> projectsList;
                                        List <SelectListItemDB> subProjectsList;

                                        try
                                        {
                                            budgetsList = budgetRep.GetList()
                                                          .Where(budget => budget.CompanyId == CurrentUser.CompanyId && budget.Year >= (DateTime.Now.Year - 1))
                                                          .Select(a => new { Id = a.Id, Name = a.Year })
                                                          .AsEnumerable()
                                                          .Select(x => new SelectListItemDB()
                                            {
                                                Id = x.Id, Name = x.Name.ToString()
                                            })
                                                          .ToList();

                                            projectsList = projectsRep.GetList()
                                                           .Where(type => type.CompanyId == CurrentUser.CompanyId)
                                                           .Select(x => new SelectListItemDB()
                                            {
                                                Id = x.Id, Name = x.Name
                                            })
                                                           .ToList();

                                            subProjectsList = subProjectsRep.GetList()
                                                              .Where(type => type.CompanyId == CurrentUser.CompanyId)
                                                              .Select(x => new SelectListItemDB()
                                            {
                                                Id = x.Id, Name = x.Name
                                            })
                                                              .ToList();
                                        }
                                        catch
                                        {
                                            return(Error(Loc.Dic.error_database_error));
                                        }

                                        ViewBag.BudgetId        = new SelectList(budgetsList, "Id", "Name", expense.BudgetId);
                                        ViewBag.ParentProjectId = new SelectList(projectsList, "Id", "Name", expense.ParentProjectId);
                                        ViewBag.SubProjectId    = new SelectList(subProjectsList, "Id", "Name", expense.SubProjectId);

                                        return(View(expense));
                                    }
                                    else
                                    {
                                        return(Error(Loc.Dic.error_no_permission));
                                    }
                                }
                                else
                                {
                                    return(Error(Loc.Dic.error_income_get_error));
                                }
                            }
            }
            else
            {
                return(Error(Loc.Dic.error_no_permission));
            }
        }
Exemplo n.º 15
0
        public ActionResult Create(Budgets_Expenses budgets_expenses)
        {
            return(Error(Loc.Dic.Error_NoPermission));

            if (Authorized(RoleType.SystemManager))
            {
                if (ModelState.IsValid)
                {
                    Budget budget;
                    Projects_ParentProject project;
                    Projects_SubProject    subProject;

                    using (BudgetsRepository budgetRep = new BudgetsRepository(CurrentUser.CompanyId))
                        using (ParentProjectsRepository projectsRep = new ParentProjectsRepository())
                            using (SubProjectsRepository subProjectsRep = new SubProjectsRepository())
                            {
                                budget     = budgetRep.GetEntity(budgets_expenses.BudgetId);
                                project    = projectsRep.GetEntity(budgets_expenses.ParentProjectId.Value);
                                subProject = subProjectsRep.GetEntity(budgets_expenses.SubProjectId.Value);
                            }

                    if (budget != null && project != null && subProject != null)
                    {
                        if (budget.CompanyId == CurrentUser.CompanyId && project.CompanyId == CurrentUser.CompanyId && subProject.CompanyId == CurrentUser.CompanyId)
                        {
                            if (project.IsActive && subProject.IsActive)
                            {
                                bool wasCreated;
                                budgets_expenses.CompanyId = CurrentUser.CompanyId;

                                using (BudgetsExpensesRepository expensesRep = new BudgetsExpensesRepository())
                                {
                                    wasCreated = expensesRep.Create(budgets_expenses);
                                }

                                if (wasCreated)
                                {
                                    return(RedirectToAction("Index"));
                                }
                                else
                                {
                                    return(Error(Loc.Dic.error_expenses_create_error));
                                }
                            }
                            else
                            {
                                return(Error(Loc.Dic.error_invalid_form));
                            }
                        }
                        else
                        {
                            return(Error(Loc.Dic.error_no_permission));
                        }
                    }
                    else
                    {
                        return(Error(Loc.Dic.error_database_error));
                    }
                }
                else
                {
                    return(Error(ModelState));
                }
            }
            else
            {
                return(Error(Loc.Dic.error_no_permission));
            }
        }
Exemplo n.º 16
0
        public ActionResult Create(Budgets_Expenses budgets_expenses)
        {
            return Error(Loc.Dic.Error_NoPermission);
            if (Authorized(RoleType.SystemManager))
            {
                if (ModelState.IsValid)
                {
                    Budget budget;
                    Projects_ParentProject project;
                    Projects_SubProject subProject;

                    using (BudgetsRepository budgetRep = new BudgetsRepository(CurrentUser.CompanyId))
                    using (ParentProjectsRepository projectsRep = new ParentProjectsRepository())
                    using (SubProjectsRepository subProjectsRep = new SubProjectsRepository())
                    {
                        budget = budgetRep.GetEntity(budgets_expenses.BudgetId);
                        project = projectsRep.GetEntity(budgets_expenses.ParentProjectId.Value);
                        subProject = subProjectsRep.GetEntity(budgets_expenses.SubProjectId.Value);
                    }

                    if (budget != null && project != null && subProject != null)
                    {
                        if (budget.CompanyId == CurrentUser.CompanyId && project.CompanyId == CurrentUser.CompanyId && subProject.CompanyId == CurrentUser.CompanyId)
                        {
                            if (project.IsActive && subProject.IsActive)
                            {
                                bool wasCreated;
                                budgets_expenses.CompanyId = CurrentUser.CompanyId;

                                using (BudgetsExpensesRepository expensesRep = new BudgetsExpensesRepository())
                                {
                                    wasCreated = expensesRep.Create(budgets_expenses);
                                }

                                if (wasCreated)
                                    return RedirectToAction("Index");
                                else
                                    return Error(Loc.Dic.error_expenses_create_error);
                            }
                            else
                            {
                                return Error(Loc.Dic.error_invalid_form);
                            }
                        }
                        else
                        {
                            return Error(Loc.Dic.error_no_permission);
                        }
                    }
                    else
                    {
                        return Error(Loc.Dic.error_database_error);
                    }
                }
                else
                {
                    return Error(ModelState);
                }
            }
            else
            {
                return Error(Loc.Dic.error_no_permission);
            }
        }
        public ActionResult Create(Budgets_Allocations Budgets_Allocations, int id = 0)
        {
            return(Error(Loc.Dic.error_no_permission));

            if (Authorized(RoleType.SystemManager))
            {
                if (ModelState.IsValid)
                {
                    Budget           budget;
                    Budgets_Incomes  income;
                    Budgets_Expenses expense;

                    using (BudgetsRepository budgetsRep = new BudgetsRepository(CurrentUser.CompanyId))
                        using (BudgetsIncomesRepository incomesRep = new BudgetsIncomesRepository())
                            using (BudgetsExpensesRepository expensesRep = new BudgetsExpensesRepository())
                                using (AllocationRepository allocationsRep = new AllocationRepository(CurrentUser.CompanyId))
                                {
                                    budget = budgetsRep.GetEntity(id);

                                    if (budget != null)
                                    {
                                        if (budget.CompanyId == CurrentUser.CompanyId)
                                        {
                                            income  = incomesRep.GetEntity(Budgets_Allocations.IncomeId.Value);
                                            expense = expensesRep.GetEntity(Budgets_Allocations.ExpenseId.Value);

                                            if (income != null && expense != null)
                                            {
                                                if (income.BudgetId == budget.Id && expense.BudgetId == budget.Id)
                                                {
                                                    decimal?allocatedToExpense;
                                                    decimal?allocatedToIncome;

                                                    allocatedToIncome = allocationsRep.GetList()
                                                                        .Where(x => x.IncomeId == income.Id)
                                                                        .Sum(allocation => (decimal?)allocation.CompanyId);       //.Sum(allocation => (decimal?)allocation.Amount);

                                                    if ((allocatedToIncome ?? 0) + Budgets_Allocations.CompanyId > income.Amount) //if ((allocatedToIncome ?? 0) + Budgets_Allocations.Amount > income.Amount)
                                                    {
                                                        return(Error(Loc.Dic.error_income_full_allocation));
                                                    }

                                                    allocatedToExpense = allocationsRep.GetList()
                                                                         .Where(x => x.ExpenseId == expense.Id)
                                                                         .Sum(allocation => (decimal?)allocation.CompanyId);        //.Sum(allocation => (decimal?)allocation.Amount);

                                                    if ((allocatedToExpense ?? 0) + Budgets_Allocations.CompanyId > expense.Amount) //if ((allocatedToExpense ?? 0) + Budgets_Allocations.Amount > expense.Amount)
                                                    {
                                                        return(Error(Loc.Dic.error_expenses_full_allocation));
                                                    }

                                                    Budgets_Allocations.CompanyId = CurrentUser.CompanyId;
                                                    Budgets_Allocations.BudgetId  = budget.Id;
                                                    Budgets_Allocations.CompanyId = CurrentUser.CompanyId;

                                                    if (allocationsRep.Create(Budgets_Allocations))
                                                    {
                                                        return(RedirectToAction("Index"));
                                                    }
                                                    else
                                                    {
                                                        return(Error(Loc.Dic.error_database_error));
                                                    }
                                                }
                                                else
                                                {
                                                    return(Error(Loc.Dic.error_invalid_form));
                                                }
                                            }
                                            else
                                            {
                                                return(Error(Loc.Dic.error_database_error));
                                            }
                                        }
                                        else
                                        {
                                            return(Error(Loc.Dic.error_no_permission));
                                        }
                                    }
                                    else
                                    {
                                        return(Error(Loc.Dic.error_database_error));
                                    }
                                }
                }
                else
                {
                    return(Error(ModelState));
                }
            }
            else
            {
                return(Error(Loc.Dic.error_no_permission));
            }
        }
Exemplo n.º 18
0
        public ActionResult Delete(int id = 0)
        {
            return Error(Loc.Dic.Error_NoPermission);
            if (Authorized(RoleType.SystemManager))
            {
                Budgets_Expenses expense;
                using (OrdersRepository ordersRep = new OrdersRepository(CurrentUser.CompanyId))
                using (BudgetsExpensesRepository expensesRep = new BudgetsExpensesRepository())
                {
                    expense = expensesRep.GetEntity(id, "Budget", "Projects_ParentProject", "Projects_SubProject");

                    if (expense != null)
                    {
                        if (expense.CompanyId == CurrentUser.CompanyId)
                        {

                            if (
                                !ordersRep.GetList()
                                .Where(x => x.CompanyId == expense.Id) //.Where(x => x.Budgets_Allocations.ExpenseId == expense.Id)
                                .Any(o => o.StatusId >= (int)StatusType.ApprovedPendingInvoice)
                                )
                            {
                                return View(expense);
                            }
                            else
                            {
                                return Error(Loc.Dic.error_expenses_delete_has_approved_orders);
                            }
                        }
                        else
                        {
                            return Error(Loc.Dic.error_no_permission);
                        }
                    }
                    else
                    {
                        return Error(Loc.Dic.error_expenses_get_error);
                    }
                }
            }
            else
            {
                return Error(Loc.Dic.error_no_permission);
            }
        }
        public ActionResult Edit(Budgets_Allocations Budgets_Allocations)
        {
            return(Error(Loc.Dic.error_no_permission));

            if (Authorized(RoleType.SystemManager))
            {
                if (ModelState.IsValid)
                {
                    Budgets_Allocations allocation;
                    Budgets_Incomes     income;
                    Budgets_Expenses    expense;

                    using (BudgetsRepository budgetsRep = new BudgetsRepository(CurrentUser.CompanyId))
                        using (BudgetsIncomesRepository incomesRep = new BudgetsIncomesRepository())
                            using (BudgetsExpensesRepository expensesRep = new BudgetsExpensesRepository())
                                using (AllocationRepository allocationsRep = new AllocationRepository(CurrentUser.CompanyId))
                                    using (OrdersRepository ordersRep = new OrdersRepository(CurrentUser.CompanyId))
                                    {
                                        allocation = allocationsRep.GetEntity(Budgets_Allocations.Id);

                                        if (allocation != null)
                                        {
                                            if (allocation.CompanyId == CurrentUser.CompanyId)
                                            {
                                                income  = incomesRep.GetEntity(Budgets_Allocations.IncomeId.Value);
                                                expense = expensesRep.GetEntity(Budgets_Allocations.ExpenseId.Value);

                                                if (income != null && expense != null)
                                                {
                                                    if (income.BudgetId == allocation.BudgetId && expense.BudgetId == allocation.BudgetId)
                                                    {
                                                        decimal?totalUsed;
                                                        decimal?allocatedToExpense;
                                                        decimal?allocatedToIncome;

                                                        totalUsed = 0; //totalUsed = ordersRep.GetList()
                                                        //    .Where(order => order.BudgetAllocationId == Budgets_Allocations.Id && order.StatusId >= (int)StatusType.ApprovedPendingInvoice)
                                                        //    .Sum(x => (decimal?)x.Price);

                                                        if ((totalUsed ?? 0) > Budgets_Allocations.CompanyId)//if ((totalUsed ?? 0) > Budgets_Allocations.Amount)
                                                        {
                                                            return(Error(Loc.Dic.error_allocations_amount_is_used));
                                                        }

                                                        allocatedToIncome = allocationsRep.GetList()
                                                                            .Where(x => x.IncomeId == income.Id && x.Id != Budgets_Allocations.Id)
                                                                            .Sum(alloc => (decimal?)alloc.CompanyId);                 //.Sum(alloc => (decimal?)alloc.Amount);

                                                        if ((allocatedToIncome ?? 0) + Budgets_Allocations.CompanyId > income.Amount) //if ((allocatedToIncome ?? 0) + Budgets_Allocations.Amount > income.Amount)
                                                        {
                                                            return(Error(Loc.Dic.error_income_full_allocation));
                                                        }

                                                        allocatedToExpense = allocationsRep.GetList()
                                                                             .Where(x => x.ExpenseId == expense.Id && x.Id != Budgets_Allocations.Id)
                                                                             .Sum(alloc => (decimal?)alloc.CompanyId);                  //.Sum(alloc => (decimal?)alloc.Amount);

                                                        if ((allocatedToExpense ?? 0) + Budgets_Allocations.CompanyId > expense.Amount) //if ((allocatedToExpense ?? 0) + Budgets_Allocations.Amount > expense.Amount)
                                                        {
                                                            return(Error(Loc.Dic.error_expenses_full_allocation));
                                                        }

                                                        allocation.IncomeId  = Budgets_Allocations.IncomeId;
                                                        allocation.ExpenseId = Budgets_Allocations.ExpenseId;
                                                        allocation.CompanyId = Budgets_Allocations.CompanyId;//allocation.Amount = Budgets_Allocations.Amount;

                                                        Budgets_Allocations update = allocationsRep.Update(allocation);

                                                        if (update != null)
                                                        {
                                                            return(RedirectToAction("Index"));
                                                        }
                                                        else
                                                        {
                                                            return(Error(Loc.Dic.error_allocations_get_error));
                                                        }
                                                    }
                                                    else
                                                    {
                                                        return(Error(Loc.Dic.error_invalid_form));
                                                    }
                                                }
                                                else
                                                {
                                                    return(Error(Loc.Dic.error_database_error));
                                                }
                                            }
                                            else
                                            {
                                                return(Error(Loc.Dic.error_no_permission));
                                            }
                                        }
                                        else
                                        {
                                            return(Error(Loc.Dic.error_allocations_get_error));
                                        }
                                    }
                }
                else
                {
                    return(Error(ModelState));
                }
            }
            else
            {
                return(Error(Loc.Dic.error_no_permission));
            }
        }
        public ActionResult Create(Budgets_Allocations Budgets_Allocations, int id = 0)
        {
            return Error(Loc.Dic.error_no_permission);
            if (Authorized(RoleType.SystemManager))
            {
                if (ModelState.IsValid)
                {
                    Budget budget;
                    Budgets_Incomes income;
                    Budgets_Expenses expense;

                    using (BudgetsRepository budgetsRep = new BudgetsRepository(CurrentUser.CompanyId))
                    using (BudgetsIncomesRepository incomesRep = new BudgetsIncomesRepository())
                    using (BudgetsExpensesRepository expensesRep = new BudgetsExpensesRepository())
                    using (AllocationRepository allocationsRep = new AllocationRepository(CurrentUser.CompanyId))
                    {
                        budget = budgetsRep.GetEntity(id);

                        if (budget != null)
                        {
                            if (budget.CompanyId == CurrentUser.CompanyId)
                            {

                                income = incomesRep.GetEntity(Budgets_Allocations.IncomeId.Value);
                                expense = expensesRep.GetEntity(Budgets_Allocations.ExpenseId.Value);

                                if (income != null && expense != null)
                                {
                                    if (income.BudgetId == budget.Id && expense.BudgetId == budget.Id)
                                    {
                                        decimal? allocatedToExpense;
                                        decimal? allocatedToIncome;

                                        allocatedToIncome = allocationsRep.GetList()
                                             .Where(x => x.IncomeId == income.Id)
                                             .Sum(allocation => (decimal?)allocation.CompanyId);//.Sum(allocation => (decimal?)allocation.Amount);

                                        if ((allocatedToIncome ?? 0) + Budgets_Allocations.CompanyId > income.Amount)//if ((allocatedToIncome ?? 0) + Budgets_Allocations.Amount > income.Amount)
                                            return Error(Loc.Dic.error_income_full_allocation);

                                        allocatedToExpense = allocationsRep.GetList()
                                            .Where(x => x.ExpenseId == expense.Id)
                                            .Sum(allocation => (decimal?)allocation.CompanyId);//.Sum(allocation => (decimal?)allocation.Amount);

                                        if ((allocatedToExpense ?? 0) + Budgets_Allocations.CompanyId > expense.Amount)//if ((allocatedToExpense ?? 0) + Budgets_Allocations.Amount > expense.Amount)
                                            return Error(Loc.Dic.error_expenses_full_allocation);

                                        Budgets_Allocations.CompanyId = CurrentUser.CompanyId;
                                        Budgets_Allocations.BudgetId = budget.Id;
                                        Budgets_Allocations.CompanyId = CurrentUser.CompanyId;

                                        if (allocationsRep.Create(Budgets_Allocations))
                                            return RedirectToAction("Index");
                                        else
                                            return Error(Loc.Dic.error_database_error);
                                    }
                                    else
                                    {
                                        return Error(Loc.Dic.error_invalid_form);
                                    }
                                }
                                else
                                {
                                    return Error(Loc.Dic.error_database_error);

                                }
                            }
                            else
                            {
                                return Error(Loc.Dic.error_no_permission);
                            }
                        }
                        else
                        {
                            return Error(Loc.Dic.error_database_error);
                        }
                    }
                }
                else
                {
                    return Error(ModelState);
                }
            }
            else
            {
                return Error(Loc.Dic.error_no_permission);
            }
        }