示例#1
0
        public async Task <IActionResult> Edit(int id, [Bind("IncomeSourceId,IncomeName,Comment")] IncomeSource source)
        {
            if (id != source.IncomeSourceId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    context.Update(source);
                    await context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!IncomeSourceExists(source.IncomeSourceId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }

            return(View(source));
        }
示例#2
0
        private bool hasEnoughMoney(IncomeSource incomeSource, int valueToInsert, QueryData paramContainer)
        {
            if (incomeSource == IncomeSource.GENERAL_INCOMES)
            {
                //Getting the total value for each budget element
                int totalIncomes = getTotalValueForSelectedElement(BudgetItemType.INCOME, sqlStatementSingleMonthIncomes, paramContainer);
                //int totalExpenses = getTotalValueForSelectedElement(BudgetItemType.EXPENSE, sqlStatementSingleMonthExpenses, paramContainer);
                int totalExpenses = getTotalValueForSelectedElement(BudgetItemType.GENERAL_EXPENSE, sqlStatementSingleMonthExpenses, paramContainer);
                int totalDebts    = getTotalValueForSelectedElement(BudgetItemType.DEBT, sqlStatementSingleMonthDebts, paramContainer);
                int totalSavings  = getTotalValueForSelectedElement(BudgetItemType.SAVING, sqlStatementSingleMonthSavings, paramContainer);

                //Calculating the amount left to spend
                int amountLeft = getAvailableAmount(totalIncomes, totalExpenses, totalDebts, totalSavings);

                if (valueToInsert <= amountLeft)
                {
                    return(true);
                }
            }
            else if (incomeSource == IncomeSource.SAVING_ACCOUNT)
            {
                //Getting the current balance of the saving acount
                int currentBalance = getSavingAccountCurrentBalance(sqlStatementGetSavingAccountBalance, paramContainer);

                if (valueToInsert <= currentBalance)
                {
                    return(true);
                }
            }

            return(false);
        }
        public int execute(QueryData paramContainer)
        {
            //Data retrieval from the container object
            IncomeSource incomeSource  = paramContainer.IncomeSource;
            int          userID        = paramContainer.UserID;
            String       expenseName   = paramContainer.ItemName;
            int          expenseTypeID = DataInsertionUtils.getID(sqlStatementSelectExpenseTypeID, paramContainer.TypeName);
            int          expenseValue  = paramContainer.ItemValue;
            String       expenseDate   = paramContainer.ItemCreationDate;

            int          executionResult         = -1;
            MySqlCommand expenseInsertionCommand = null;

            if (incomeSource == IncomeSource.GENERAL_INCOMES)
            {
                expenseInsertionCommand = SQLCommandBuilder.getInsertCommandForMultipleTypeItem(sqlStatementInsertGeneralIncomesExpense, userID, expenseName, expenseTypeID, expenseValue, expenseDate);
                executionResult         = DBConnectionManager.insertData(expenseInsertionCommand);;//Uses the SQL statement that inserts the expense in the expenses table of the DB
            }
            else if (incomeSource == IncomeSource.SAVING_ACCOUNT)
            {
                expenseInsertionCommand = SQLCommandBuilder.getInsertCommandForMultipleTypeItem(sqlStatementInsertSavingAccountExpense, userID, expenseName, expenseTypeID, expenseValue, expenseDate);
                executionResult         = DBConnectionManager.insertData(expenseInsertionCommand);//Uses SQL statement that inserts the expense in the saving_account_expenses table of the DB
            }


            return(executionResult);
        }
示例#4
0
        public async Task <IActionResult> CreateIncome()
        {
            var user = await _userManager.GetUserAsync(HttpContext.User);

            var userId = user?.Id;
            List <IncomeSource> incomeSources = _db.IncomeSources.Where(x => x.UserId == userId).ToList();

            if (incomeSources.Count == 0)
            {
                IncomeSource newIncomeSource = new IncomeSource
                {
                    UserId       = userId,
                    Description  = "Pago externo a salario",
                    CreationDate = DateTime.Now
                };
                await _db.IncomeSources.AddAsync(newIncomeSource);

                await _db.SaveChangesAsync();

                incomeSources = _db.IncomeSources.Where(x => x.UserId == userId).ToList();
            }
            SelectList incomeSourcesSelectList = new SelectList(incomeSources, "Id", "Description");
            Income     income = new Income();

            income.CreationDate   = DateTime.Now;
            ViewBag.incomeSources = incomeSourcesSelectList;
            return(View(income));
        }
示例#5
0
 public IncomeSourceEditContentPageModel(ApplicationInstanceData applicationInstanceData, IncomeSource incomeSource)
 {
     IsCreate        = false;
     SaveCommandVerb = applicationInstanceData.SelectedLocalization.Translations[@"Save"];
     Title           = applicationInstanceData.SelectedLocalization.Translations[@"EditIncomeSource"];
     IncomeSource    = incomeSource;
     Init(applicationInstanceData);
 }
        public ActionResult DeleteConfirmed(int id)
        {
            IncomeSource incomeSource = db.IncomeSources.Find(id);

            db.IncomeSources.Remove(incomeSource);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
示例#7
0
 public IncomeSourceViewContentPageModel(ApplicationInstanceData applicationInstanceData, IncomeSource incomeSource)
 {
     ApplicationInstanceData = applicationInstanceData;
     IncomeSource            = incomeSource;
     EditCommand             = new Command(ExecuteEditCommand);
     DeleteCommand           = new Command(ExecuteDeleteCommand);
     AllowEditDelete         = !incomeSource.HasExternalId;
     EditDeleteRowHeight     = AllowEditDelete ? 80 : 0;
 }
 public void DeleteIncome(Object parameter)
 {
     if (ConfirmDialog.Confirm($"Удалить доход {SelectedIncome.Sum} ({SelectedIncome.Source_of_income.Name}) от {SelectedIncome.Date}?"))
     {
         db.Income.Local.Remove(SelectedIncome);
         IncomeSource.Remove(SelectedIncome);
         db.SaveChanges();
     }
 }
        public void DeleteIncomeSource(IncomeSource delIncomeSource)
        {
            var curIncomeSource = dbContext.IncomeSources.FirstOrDefault(o => o.Id == delIncomeSource.Id);

            if (curIncomeSource != null)
            {
                curIncomeSource.IsDeleted = true;
                dbContext.SaveChanges();
            }
        }
 public ActionResult Edit([Bind(Include = "Id,Name,Description")] IncomeSource incomeSource)
 {
     if (ModelState.IsValid)
     {
         db.Entry(incomeSource).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(incomeSource));
 }
示例#11
0
    static void registerExtraIncome(EventInfo info)
    {
        ExtraIncomeInfo extra        = (ExtraIncomeInfo)info;
        IncomeSource    incomeSource = new IncomeSource(extra.extraIncomeAmount, true);

        incomeSources().Add(incomeSource);

        TaxationSystem.getIncomeafterMandatoryPayments(getAllIncomeSourceGrossTotals(12));

        OnNewIncome.Invoke();
    }
        public ActionResult Create([Bind(Include = "Id,Description,Amount,EffectiveDate,ChangeType,IncomeSourceId")] IncomeSource incomeSource)
        {
            if (ModelState.IsValid)
            {
                db.IncomeSources.Add(incomeSource);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(incomeSource));
        }
示例#13
0
        public async Task <IActionResult> Create([Bind("IncomeSourceId,IncomeName,Comment")] IncomeSource source)
        {
            if (ModelState.IsValid)
            {
                context.Add(source);
                await context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            return(View(source));
        }
示例#14
0
 public bool AddUpdateJob([FromUri] bool addUpdateJob, [FromBody] IncomeSource inputJob, [FromUri] int incomeSourceId = -1)
 {
     if (incomeSourceId == -1)
     {
         var jobToAddUpdate = new IncomeSource
         {
             ActiveJob       = true,
             EstimatedIncome = inputJob.EstimatedIncome,
             JobOf           = inputJob.JobOf,
             PayFrequency    = inputJob.PayFrequency,
             PositionName    = inputJob.PositionName,
             SourceName      = inputJob.SourceName
         };
         try
         {
             _db.IncomeSources.Add(inputJob);
             _db.SaveChanges();
             return(true);
         }
         catch (Exception e)
         {
             return(false);
         }
     }
     else
     {
         var jobToAddUpdate = new IncomeSource
         {
             ActiveJob       = true,
             EstimatedIncome = inputJob.EstimatedIncome,
             JobOf           = inputJob.JobOf,
             PayFrequency    = inputJob.PayFrequency,
             PositionName    = inputJob.PositionName,
             SourceName      = inputJob.SourceName
         };
         try
         {
             _db.IncomeSources.Find(incomeSourceId).ActiveJob       = jobToAddUpdate.ActiveJob;
             _db.IncomeSources.Find(incomeSourceId).EstimatedIncome = jobToAddUpdate.EstimatedIncome;
             _db.IncomeSources.Find(incomeSourceId).JobOf           = jobToAddUpdate.JobOf;
             _db.IncomeSources.Find(incomeSourceId).PayFrequency    = jobToAddUpdate.PayFrequency;
             _db.IncomeSources.Find(incomeSourceId).PositionName    = jobToAddUpdate.PositionName;
             _db.IncomeSources.Find(incomeSourceId).SourceName      = jobToAddUpdate.SourceName;
             _db.SaveChanges();
             return(true);
         }
         catch (Exception e)
         {
             return(false);
         }
     }
 }
示例#15
0
 public void SaveIncomeSource(IncomeSource newIncomeSource)
 {
     if (newIncomeSource.Id == 0)
     {
         dbContext.IncomeSources.Add(newIncomeSource);
     }
     else
     {
         var curIncomeSource = dbContext.IncomeSources.Single(o => o.Id == newIncomeSource.Id);
         curIncomeSource.Source = newIncomeSource.Source;
     }
     dbContext.SaveChanges();
 }
示例#16
0
 public IncomeSourceDetailVM(IncomeSource source, AccountDetailVM baseAccount, Schedule accountSchedule) : base(baseAccount.AccountType)
 {
     AccountName          = baseAccount.AccountName;
     Notes                = baseAccount.Notes;
     IncomeSourceId       = source.LocalId;
     AccountId            = baseAccount.AccountId;
     DateTime_Created     = baseAccount.DateTime_Created;
     DateTime_Deactivated = baseAccount.DateTime_Deactivated;
     DefaultToAccountId   = source.DefaultToAccountId;
     ExpectedAmount       = source.ExpectedAmount;
     Schedule             = accountSchedule == null ? null : new Schedule_Base(accountSchedule);
     TotalFromSource      = source.TotalFromSource;
 }
        // GET: IncomeSources/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            IncomeSource incomeSource = db.IncomeSources.Find(id);

            if (incomeSource == null)
            {
                return(HttpNotFound());
            }
            return(View(incomeSource));
        }
示例#18
0
        internal IncomeSourceDetailVM SaveAccount(IncomeSourceDetailVM account)
        {
            AccountDetailVM baseAccount = SaveAccount((AccountDetailVM)account);

            account.AccountId = baseAccount.AccountId;
            IncomeSource result          = Repo.SaveAccount(new IncomeSource(account));
            Schedule     accountSchedule = null;

            if (result.ScheduleId.HasValue)
            {
                accountSchedule = Repo.GetSchedule(result.ScheduleId.Value);
            }

            return(new IncomeSourceDetailVM(result, baseAccount, accountSchedule));
        }
        public ActionResult SaveIncomeSource(IncomeSourceModel newIncome)
        {
            if (ModelState.IsValid)
            {
                var saveIncomeSource = new IncomeSource
                {
                    Id     = newIncome.Id,
                    Source = newIncome.Source
                };

                incomeSourceService.SaveIncomeSource(saveIncomeSource);
                return(RedirectToAction("Index"));
            }

            return(View("EditIncomeSource", newIncome));
        }
示例#20
0
        //Method for retrieving the user selected income source
        private IncomeSource getIncomeSource()
        {
            //Setting the default value for the income source
            IncomeSource incomeSource = IncomeSource.UNDEFINED;

            if (generalIncomesRadioButton.Checked == true)
            {
                incomeSource = IncomeSource.GENERAL_INCOMES;//Income source representing the active/passive incomes
            }
            else if (savingAccountRadioButton.Checked == true)
            {
                incomeSource = IncomeSource.SAVING_ACCOUNT;//Income source representing the savings that the user currently owns
            }

            return(incomeSource);
        }
        public IActionResult AddNewIncomeSource([FromBody] IncomeSource incomeSource)
        {
            try
            {
                if (incomeSource == null)
                {
                    return(BadRequest());
                }
                incomeSourceBL.AddNewIncomeSource(incomeSource);
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception in getting Add new incomeSource", e);
            }

            return(CreatedAtRoute("GetIncomeSource", new { id = incomeSource.ID }, incomeSource));
        }
        public bool UpdateIncomeSource(long id, IncomeSource incomeSource)
        {
            int result             = 0;
            var updateIncomeSource = GetIncomeSourceById(id);

            if (updateIncomeSource == null)
            {
                return(false);
            }
            updateIncomeSource.SourceName = incomeSource.SourceName;
            _context.IncomeSources.Update(updateIncomeSource);
            result = _context.SaveChanges();
            if (result == 0)
            {
                return(false);
            }
            return(true);
        }
        public IActionResult GetById(long id)
        {
            IncomeSource incomeSourceObj = null;

            try
            {
                incomeSourceObj = new IncomeSource();
                incomeSourceObj = incomeSourceBL.GetIncomeSourceById(id);
                if (incomeSourceObj == null)
                {
                    return(NotFound());
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception in getting Get IncomeSource by id", e);
            }
            return(new ObjectResult(incomeSourceObj));
        }
示例#24
0
 public IActionResult EditActor(IncomeSource a)
 {
     if (ModelState.IsValid)
     {
         IncomeSource t = new IncomeSource();
         t.IncomeId            = a.IncomeId;
         t.StudentAdmissionFee = a.StudentAdmissionFee;
         t.StudentSessionFee   = a.StudentSessionFee;
         t.StudentTuitionFee   = a.StudentTuitionFee;
         t.ExaminationFee      = a.ExaminationFee;
         t.FormFillUp          = a.FormFillUp;
         t.StationarySell      = a.StationarySell;
         t.Donation            = a.Donation;
         t.TotalIncome         = (t.StudentAdmissionFee + t.StudentSessionFee + t.StudentTuitionFee + t.ExaminationFee + t.FormFillUp + t.StationarySell + t.Donation);
         db.IncomeSource.Update(t);
         db.SaveChanges();
     }
     return(RedirectToAction("ViewActorList"));
 }
        public IActionResult Update(long id, [FromBody] IncomeSource incomeSource)
        {
            bool result = false;

            try
            {
                if (incomeSource == null || incomeSource.ID != id)
                {
                    return(BadRequest());
                }
                result = incomeSourceBL.UpdateIncomeSource(id, incomeSource);
                if (result == false)
                {
                    return(NotFound());
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception in getting Update incomeSource", e);
            }
            return(new NoContentResult());
        }
示例#26
0
        public void SetupAndGetIncome(bool isFixed)
        {
            var incomeSource = isFixed ? IncomeSource.Fixed("Monobits") : IncomeSource.Variable("Monobits");

            var today = DateTime.Today;

            incomeSource.StartDate  = today.FirstDayOfMonth();
            incomeSource.EndDate    = today.LastDayOfMonth();
            incomeSource.Recurrence = Recurrence.Weekly;
            incomeSource.Concepts   = new List <Concept>
            {
                new Concept
                {
                    Amount      = 3300,
                    Destination = FakeRepository.First(MoneyAccount.Type.Debit),
                    PayDay      = DayOfWeek.Thursday,
                    Description = "Sueldo"
                },
                new Concept
                {
                    Amount      = 700,
                    Destination = FakeRepository.First(MoneyAccount.Type.Debit),
                    PayDay      = DayOfWeek.Friday,
                    Description = "Sueldo"
                },
                new Concept
                {
                    Amount      = 200,
                    Destination = FakeRepository.First(MoneyAccount.Type.Cash),
                    PayDay      = DayOfWeek.Friday,
                    Description = "Sueldo"
                }
            };

            var incomes = incomeSource.MakeIncome();

            Assert.Equal(14, incomes.Count);
            Assert.True(incomes.All(x => x.IsFixed == isFixed));
        }
        internal IncomeSource SaveAccount(IncomeSource account)
        {
            IncomeSource record = context.IncomeSources.FirstOrDefault(a => a.AccountId == account.AccountId);

            if (record == null)
            {
                record = account;
                context.IncomeSources.Add(record);
                context.Entry(record).State = EntityState.Added;
            }
            else
            {
                record.DefaultToAccountId = account.DefaultToAccountId;
                record.ExpectedAmount     = account.ExpectedAmount;
                record.ScheduleId         = account.ScheduleId;

                context.Entry(record).State = EntityState.Modified;
            }

            context.SaveChanges();

            return(record);
        }
        private void Init(ApplicationInstanceData applicationInstanceData)
        {
            ApplicationInstanceData = applicationInstanceData;
            if (isCreate)
            {
                IncomeSource = new IncomeSource
                {
                    ProductServiceName      = @"",
                    EstimatedVolumeProduced = 0,
                    EstimatedVolumeSold     = 0,
                    UnitOfMeasure           = @"",
                    EstimatedIncome         = 0.0m,
                    Currency = @""
                };
            }

            // set temp/locally cached properties to support save/cancel
            ProductServiceName      = IncomeSource.ProductServiceName;
            EstimatedVolumeProduced = (IncomeSource.EstimatedVolumeProduced == null) ? 0 : (int)IncomeSource.EstimatedVolumeProduced;
            EstimatedVolumeSold     = (IncomeSource.EstimatedVolumeSold == null) ? 0 : (int)IncomeSource.EstimatedVolumeSold;
            UnitOfMeasure           = IncomeSource.UnitOfMeasure;
            EstimatedIncome         = (IncomeSource.EstimatedIncome == null) ? 0.0m : (decimal)IncomeSource.EstimatedIncome;
            Currency = IncomeSource.Currency;
        }
 public IncomeSourceEditContentViewModel(ApplicationInstanceData applicationInstanceData, IncomeSource incomeSource)
 {
     IncomeSource = incomeSource;
     isCreate     = false;
     Init(applicationInstanceData);
 }
示例#30
0
            public Builder addIncomeSource(IncomeSource incomeSource)
            {
                this.incomeSource = incomeSource;

                return(this);
            }