public async Task <MonthFinance> SaveMonthFinance([FromBody] MonthFinance monthFinances)
        {
            var documents = (await _financialTimes.Get()).ToArray();
            var entity    = documents.Where(x => x.Name == monthFinances.Name).FirstOrDefault();

            if (entity.Name != null)
            {
                var entityExpense = new Expense {
                    ListItemsExpense = monthFinances.MonthExpense.ListItemsExpense
                };

                var entityEarning = new Earning
                {
                    ListItemsEarning = monthFinances.MonthEarning.ListItemsEarning
                };

                var entityInvestment = new Investment
                {
                    ListItemsInvestment = monthFinances.MonthInvestment.ListItemsInvestment
                };

                entity.MonthEarning    = entityEarning;
                entity.MonthExpense    = entityExpense;
                entity.MonthInvestment = entityInvestment;

                await _financialTimes.Persist(entity);
            }
            return(entity);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> PostEarning([FromBody] Earning earning)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                // Get the points value from the Rules table
                var points = (from r in _context.Rules
                              where r.RuleId == earning.RuleId
                              select r.Value
                              ).FirstOrDefault();

                // Set the points on the passed-in object
                earning.Points = Convert.ToInt32(points);

                _context.Earnings.Add(earning);
                await _context.SaveChangesAsync();

                return(CreatedAtAction("GetEarning", new { id = earning.EarningId }, earning));
            }
            catch (Exception e)
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError, e.Message));
            }
        }
Ejemplo n.º 3
0
        private void btnCreate_Click(object sender, RoutedEventArgs e)
        {
            using (var db = new MSPAccountingContext())
            {
                var earning = new Earning()
                {
                    Date     = dtDate.Value == null ? DateTime.Now : (DateTime)dtDate.Value,
                    Amount   = Decimal.Parse(txtbxAmount.Text),
                    Client   = db.Client.Single(x => x.ID == ((Client)cmbbxClient.SelectedItem).ID),
                    Comments = txtbxComments.Text
                };

                var errors = earning.GetModelErrors();

                if (errors.Count > 0)
                {
                    new ErrorDisplay(errors).ShowDialog();
                }
                else
                {
                    db.Earning.Add(earning);
                    db.SaveChanges();

                    MessageBox.Show("Earning Created!");
                    Close();
                }
            }
        }
Ejemplo n.º 4
0
        public JsonResult CreateIncome(string income)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    Earning incomeObj = JsonConvert.DeserializeObject <Earning>(income);
                    incomeObj.CreatedBy   = "admin";
                    incomeObj.CreatedDate = DateTime.Now;
                    incomeObj.LastUpdBy   = "admin";
                    incomeObj.LastUpdDate = DateTime.Now;
                    incomeObj.CompanyId   = "ABC";

                    // TODO: Add update logic here
                    //_context.Update(user);
                    _context.Add(incomeObj);
                    _context.SaveChanges();
                }

                return(Json(new { Success = true }));
            }
            catch
            {
                throw;
            }
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> PutEarning([FromRoute] int id, [FromBody] Earning earning)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != earning.EarningId)
            {
                return(BadRequest());
            }

            _context.Entry(earning).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!EarningExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Ejemplo n.º 6
0
 public ActionResult AcceptRequest(int Id)
 {
     if (Request.Cookies["user"] != null)
     {
         Request request = new LearningHandler().GetRequest(Id);
         request.RequestStatusId = 6;
         request.RequestStatus   = new LearningHandler().GetRequestStatus(6);
         new LearningHandler().UpdateRequest(request);
         Earning earning = new Earning();
         earning.RequestId = Id;
         earning.TeacherId = request.Teacher.Id;
         earning.Cost      = request.Cost;
         new LearningHandler().AddEarnings(earning);
         List <Earning> earnings = new LearningHandler().GetAllEarnings(Convert.ToInt32(Request.Cookies["user"]["Id"]));
         int            cost     = 0;
         foreach (var item in earnings)
         {
             cost += item.Cost;
         }
         Session["TotalEarnings"]   = cost;
         Session["UpdateRequestId"] = request.Id;
         return(RedirectToAction("Dashboard"));
     }
     return(RedirectToAction("Login", "Account"));
 }
Ejemplo n.º 7
0
        public async Task <JsonResult> EditIncome(string income)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    Earning incomeEntity   = JsonConvert.DeserializeObject <Earning>(income);
                    var     incomeToUpdate = _context.Earning.Where(u => u.EarningId == incomeEntity.EarningId).FirstOrDefault();

                    incomeToUpdate.TranDate              = incomeEntity.TranDate;
                    incomeToUpdate.Amount                = incomeEntity.Amount;
                    incomeToUpdate.RecurStart            = incomeEntity.RecurStart;
                    incomeToUpdate.RecurEnd              = incomeEntity.RecurEnd;
                    incomeToUpdate.Frequency             = incomeEntity.Frequency;
                    _context.Entry(incomeToUpdate).State = EntityState.Modified;

                    //_context.Entry(loanToUpdate).CurrentValues.SetValues(loanObj);

                    // TODO: Add update logic here
                    await _context.SaveChangesAsync();
                }

                return(Json(new { Success = true }));
            }
            catch
            {
                throw;
            }
        }
        public bool SaveMonthFinance([FromBody] MonthFinanceModel monthFinances)
        {
            //var entity = monthFinances.ToModelToEntity();

            var entityExpense = new Expense {
                ListItemsExpense = monthFinances.Expense.ListItemsExpenseModel.Select(x => x.ModelToEntity())
            };

            var entityEarning = new Earning
            {
                ListItemsEarning = monthFinances.Earning.ListItemsEarningModel.Select(x => x.ModelToEntity())
            };

            var entityInvestment = new Investment
            {
                ListItemsInvestment = monthFinances.Investment.ListItemsInvestmentModel.Select(x => x.ModelToEntity())
            };

            var entity = new MonthFinance
            {
                Name            = monthFinances.Name,
                MonthExpense    = entityExpense,
                MonthEarning    = entityEarning,
                MonthInvestment = entityInvestment
            };

            entity.Id = Guid.Parse("efede5a3-0b4c-4d41-a054-55d1b97ae35e");
            monthFinanceConfPer.Persist(entity);

            return(true);
        }
Ejemplo n.º 9
0
        private void btnCreate_Click(object sender, RoutedEventArgs e)
        {
            using (var db = new MSPAccountingContext())
            {
                var earning = new Earning()
                {
                    Date = dtDate.Value == null ? DateTime.Now : (DateTime)dtDate.Value,
                    Amount = Decimal.Parse(txtbxAmount.Text),
                    Client = db.Client.Single(x => x.ID == ((Client)cmbbxClient.SelectedItem).ID),
                    Comments = txtbxComments.Text
                };

                var errors = earning.GetModelErrors();

                if(errors.Count > 0)
                {
                    new ErrorDisplay(errors).ShowDialog();
                }
                else
                {
                    db.Earning.Add(earning);
                    db.SaveChanges();

                    MessageBox.Show("Earning Created!");
                    Close();
                }
            }
        }
Ejemplo n.º 10
0
        private void dgvCashflow_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0)
            {
                var cashflowId = getCashflowIdDgv(e.RowIndex);
                if (cashflowId.Equals(null) || !(cashflowId > 0))
                {
                    return;
                }
                var cashflow = cashflowService.GetById(getCashflowIdDgv(e.RowIndex));
                loadCashflowData(cashflow);

                if (cashflow.EarningId == null)
                {
                    Payment payment = paymentService.GetById(Convert.ToInt64(cashflow.PaymentId));
                    refreshDataGridViewEarningPayment(payment);

                    Storage storage = storageService.GetById(Convert.ToInt64(payment.StorageId));
                    refreshDataGridViewSaleStorage(payment);

                    refreshDataGridViewProductExam(storage);
                }

                else if (cashflow.PaymentId == null)
                {
                    Earning earning = earningService.GetById(Convert.ToInt64(cashflow.EarningId));
                    refreshDataGridViewEarningPayment(earning);

                    Sale sale = saleService.GetById(Convert.ToInt64(earning.SaleId));
                    refreshDataGridViewSaleStorage(earning);

                    refreshDataGridViewProductExam(sale);
                }
            }
        }
Ejemplo n.º 11
0
        private void btnInsert_Click(object sender, EventArgs e)
        {
            if (!txtId.Text.Equals(String.Empty))
            {
                MessageBox.Show("O campo id deve estar vazio para fazer um novo registro de venda, resete o formulário para limpar os campos e tente novamente.");
            }
            else
            {
                var newSale = new Sale(dtSale.Value, dtExpiration.Value);
                newSale.ExpirationDate = dtExpiration.Value;
                saleService.Insert(newSale);

                var newEarning = new Earning(0, newSale.Date, newSale.ExpirationDate, newSale.SaleId);
                earningService.Insert(newEarning);

                var newCashflow = new Cashflow()
                {
                    EarningId = newEarning.EarningId,
                    PaymentId = null
                };

                cashflowService.Insert(newCashflow);

                resetForm();
            }
        }
Ejemplo n.º 12
0
 private void refreshDataGridViewSaleStorage(Earning earning)
 {
     dgvSaleStorage.DataSource = null;
     if (saleService.ShowAll().Where(s => s.SaleId == earning.SaleId) != null)
     {
         dgvSaleStorage.DataSource = saleService.ShowAll().Where(s => s.SaleId == earning.SaleId).ToList();
     }
 }
Ejemplo n.º 13
0
        // GET: Earnings
        public ActionResult AddEarning(Guid?employeeId)
        {
            Earning  earning  = new Earning();
            Employee employee = _db.Employees.Find(employeeId);

            earning.EmployeeId = employee.EmployeeId;
            return(View(earning));
        }
Ejemplo n.º 14
0
        public ActionResult DeleteEarning(int id)
        {
            Earning earn = db.Earnings.Find(id);

            db.Earnings.Remove(earn);
            db.SaveChanges();
            return(RedirectToAction("MonthHistory", "Histories", new { id = earn.Date, months = earn.Month }));
        }
Ejemplo n.º 15
0
        private static List <Earning> GetEarningListFromEarnedDayDecimalList(IEnumerable <EarnedDayDecimal> sortedTransactionsByDayOfWeek)
        {
            List <Earning> sortedEarnedDayModel = new List <Earning>();

            foreach (EarnedDayDecimal earnedDayDecimal in sortedTransactionsByDayOfWeek)
            {
                sortedEarnedDayModel.Add(Earning.ConvertFromDecimal(earnedDayDecimal));
            }
            return(sortedEarnedDayModel);
        }
Ejemplo n.º 16
0
        public override MatchResult Match(List <Commitment> commitments, Earning priceEpisode, List <Account> dasAccounts, MatchResult matchResult)
        {
            var commitmentsToMatch = commitments.Where(c => priceEpisode.Uln.HasValue && c.Uln == priceEpisode.Uln.Value).ToList();

            if (!commitmentsToMatch.Any())
            {
                matchResult.ErrorCodes.Add(DataLockErrorCodes.MismatchingUln);
            }

            matchResult.Commitments = commitmentsToMatch.ToArray();
            return(ExecuteNextHandler(commitmentsToMatch, priceEpisode, dasAccounts, matchResult));
        }
Ejemplo n.º 17
0
        public ActionResult AddEarning(Earning earning)
        {
            var employeeId = earning.EmployeeId;

            if (ModelState.IsValid)
            {
                _db.Earnings.Add(earning);
                _db.SaveChanges();
                return(RedirectToAction("Details", "Employees", new { id = employeeId }));
            }
            return(View(earning));
        }
Ejemplo n.º 18
0
        public async Task AddEarningWithoutDescription()
        {
            var model = new Earning()
            {
                Date   = default(System.DateTime),
                Value  = 1000,
                UserId = 1
            };
            var result = await Post("/api/Earning", model, model.UserId);

            TestErrors(model, result, "O campo 'Descrição' é obrigatório.");
        }
Ejemplo n.º 19
0
        private async Task CreateStatistics(decimal moneyToAppend, string userId)
        {
            Earning earning = new Earning
            {
                Date   = DateTime.Now,
                Money  = moneyToAppend,
                UserId = userId
            };

            _earningsRepository.Insert(earning);
            await _earningsRepository.Save();
        }
        public override MatchResult Match(List <Commitment> commitments, Earning priceEpisode, List <Account> dasAccounts, MatchResult matchResult)
        {
            var commitment    = commitments.FirstOrDefault();
            var accountsMatch = dasAccounts.Where(a => commitments.Any(c => c.Id == a.Id && a.IsLevyPayer == true));

            if (!accountsMatch.Any())
            {
                matchResult.ErrorCodes.Add(DataLockErrorCodes.NotLevyPayer);
            }


            return(ExecuteNextHandler(commitments, priceEpisode, dasAccounts, matchResult));
        }
Ejemplo n.º 21
0
        public ActionResult EditEarning(Earning earning)
        {
            int userid = (int)Session["UserId"];

            earning.RegistrationId = userid;
            if (ModelState.IsValid)
            {
                db.Entry(earning).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("MonthHistory", "Histories", new { id = earning.Date, months = earning.Month }));
            }
            return(View(earning));
        }
        public static List <Earning> CreateEarningsFromLearners(IFundingOutputs fundingOutputs = null, string collectionPeriod = "1718-R11")
        {
            var deliveryPeriodPrefix = collectionPeriod.Substring(0, 6);

            var result = new List <Earning>();

            if (fundingOutputs == null)
            {
                fundingOutputs = Create1000Learners();
            }

            var ukprnIncrement = 0;

            foreach (var learner in fundingOutputs.Learners)
            {
                if (++ukprnIncrement >= Configuration.NumberOfProviders)
                {
                    ukprnIncrement = 0;
                }

                foreach (var learningDeliveryAttribute in learner.LearningDeliveryAttributes)
                {
                    var earnings = new Earning[12];

                    for (var i = 1; i < 13; i++)
                    {
                        var earning = new Earning
                        {
                            Ukprn = fundingOutputs.Global.UKPRN + ukprnIncrement,
                            LearnerReferenceNumber = learner.LearnRefNumber,
                            DeliveryPeriod         = deliveryPeriodPrefix + i.ToString("d2"),
                            Uln = new Random(100000).Next()
                        };

                        foreach (var attribute in learningDeliveryAttribute.LearningDeliveryPeriodisedAttributes)
                        {
                            if (attribute.AttributeName.EndsWith("Payment"))
                            {
                                earning.Amount += GetAttributeValue(attribute, i);
                            }
                        }

                        earnings[i - 1] = earning;
                    }

                    result.AddRange(earnings);
                }
            }

            return(result);
        }
Ejemplo n.º 23
0
        public async Task UpdateEarningWithoutDescription()
        {
            var model = new Earning()
            {
                Id     = 2,
                Date   = DateTime.Now,
                Value  = 1000,
                UserId = 1,
                Type   = EarningType.Benefit
            };
            var result = await Put("/api/Earning", model, model.UserId);

            TestErrors(model, result, "O campo 'Descrição' é obrigatório.");
        }
Ejemplo n.º 24
0
        public async Task UpdateEarningNotFound()
        {
            var model = new Earning()
            {
                Id          = 99,
                Description = "Salário",
                Date        = new DateTime(2020, 4, 1),
                Value       = 1000,
                UserId      = 1
            };
            var result = await Put("/api/Earning", model, model.UserId);

            TestErrors(model, result, "Benefício/Salário não encontrado(a).");
        }
Ejemplo n.º 25
0
        public async Task AddSalaryWithValueNoMoreThenZero()
        {
            var model = new Earning()
            {
                Date        = DateTime.Now,
                Value       = 0,
                UserId      = 1,
                Type        = EarningType.MonthyBenefit,
                Description = "Salário"
            };
            var result = await Post("/api/Earning", model, model.UserId);

            TestErrors(model, result, "O campo 'Valor' deve ser maior que 0.");
        }
Ejemplo n.º 26
0
        public async Task AddCurrentEarningWithInvalidType()
        {
            var model = new Earning()
            {
                Date        = new DateTime(2021, 4, 1),
                Value       = 1000,
                UserId      = 2,
                Type        = (EarningType)99,
                Description = "Salário"
            };
            var result = await Post("/api/Earning", model, model.UserId);

            TestErrors(model, result, "Tipo inválido.");
        }
Ejemplo n.º 27
0
        public async Task AddCurrentEarningOk()
        {
            var model = new Earning()
            {
                Date        = new DateTime(2021, 4, 1),
                Value       = 1000,
                UserId      = 2,
                Type        = EarningType.MonthyBenefit,
                Description = "Salário"
            };
            var result = await Post("/api/Earning", model, model.UserId);

            TestErrors(model, result);
        }
Ejemplo n.º 28
0
        public async Task UpdateEarningWithDefaultDate()
        {
            var model = new Earning()
            {
                Date        = default(System.DateTime),
                Value       = 1000,
                UserId      = 1,
                Id          = 2,
                Description = "Salário"
            };
            var result = await Put("/api/Earning", model, model.UserId);

            TestErrors(model, result, "O campo 'Data' é obrigatório.");
        }
Ejemplo n.º 29
0
        public bool SaveEarning(Earning earning)
        {
            var earnings = _database.GetCollection <Item>(EARNING_COLLECTION);

            try
            {
                earnings.Save(earning);
            }
            catch
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 30
0
        private void refreshDataGridViewEarningPayment(Earning earning)
        {
            dgvEarningPayment.DataSource = null;
            List <Earning> earnings = null;

            if (earningService.ShowAll().Where(e => e.EarningId == earning.EarningId) != null)
            {
                earnings = earningService.ShowAll().Where(e => e.EarningId == earning.EarningId).ToList();
                foreach (var earn in earnings)
                {
                    earn.Sale = saleService.GetById(earn.SaleId);
                }
            }
            dgvEarningPayment.DataSource = earnings;
        }
        public void Setup()
        {
            paymentHistory = new List <Payment>();

            testEarning = new Earning
            {
                Amount = 50,
                PriceEpisodeIdentifier    = string.Empty,
                SfaContributionPercentage = 0,
                EarningType = EarningType.Levy,
            };

            sut            = new RequiredPaymentProcessor(new PaymentDueProcessor(), new RefundService());
            expectedAmount = 50;
        }
Ejemplo n.º 32
0
        public static Earning SingleEarning(int id, bool isAchievement)
        {
            UnitOfWork work = new UnitOfWork();
            JustPressPlayDBEntities _dbContext = new JustPressPlayDBEntities();

            Earning earning = new Earning();
            var loggedInID = WebSecurity.CurrentUserId;
            var loggedInIsAdmin = Roles.IsUserInRole(JPPConstants.Roles.FullAdmin);

            if (isAchievement)
            {
                var achievement = _dbContext.achievement_instance.Find(id);
                var user = achievement.user;
                var template = achievement.achievement_template;

                earning.CommentsDisabled = WebSecurity.IsAuthenticated ? achievement.comments_disabled : true;
                earning.DisplayName = user.display_name;
                earning.EarnedDate = achievement.achieved_date;
                earning.EarningID = achievement.id;
                earning.EarningIsAchievement = true;
                earning.Image = template.icon;
                earning.PlayerID = user.id;
                earning.PlayerImage = user.image;
                earning.TemplateID = template.id;
                earning.Title = template.title;

                if (achievement.has_user_content)
                {
                    var content = _dbContext.achievement_user_content.Find(achievement.user_content_id);
                    earning.ContentPhoto = content.image;
                    earning.ContentText = content.text;
                    earning.ContentURL = content.url;
                }
                if (achievement.has_user_story)
                {
                    var story = _dbContext.achievement_user_story.Find(achievement.user_story_id);
                    earning.StoryPhoto = story.image;
                    earning.StoryText = story.text;
                }

            }
            else
            {
               var quest =  _dbContext.quest_instance.Find(id);
               var user = quest.user;
               var template = quest.quest_template;

                earning.CommentsDisabled = WebSecurity.IsAuthenticated ? quest.comments_disabled : true;
               earning.DisplayName = user.display_name;
               earning.EarnedDate = quest.completed_date;
               earning.EarningID = quest.id;
               earning.EarningIsAchievement = false;
               earning.Image = template.icon;
               earning.PlayerID = user.id;
               earning.PlayerImage = user.image;
               earning.TemplateID = template.id;
               earning.Title = template.title;
            }

            // Get comments
            if (!earning.CommentsDisabled)
            {
                earning.Comments = from c in work.EntityContext.comment
                                   where c.location_id == earning.EarningID &&
                                   ((earning.EarningIsAchievement && c.location_type == (int)JPPConstants.CommentLocation.Achievement) ||
                                    (!earning.EarningIsAchievement && c.location_type == (int)JPPConstants.CommentLocation.Quest))
                                   select new EarningComment()
                                   {
                                       ID = c.id,
                                       PlayerID = c.deleted ? c.last_modified_by_id : c.user_id,
                                       // Replace comment text if deleted and not admin
                                       Text = c.deleted ? (JPPConstants.SiteSettings.DeletedCommentText + c.last_modified_by.display_name) : c.text,
                                       PlayerImage = c.deleted ? null : c.user.image,
                                       DisplayName = c.deleted ? null : c.user.display_name,
                                       Deleted = c.deleted,
                                       CommentDate = c.date,
                                       CurrentUserCanEdit = (loggedInID == c.user_id || loggedInIsAdmin) && !c.deleted,
                                       CurrentUserCanDelete = (loggedInID == c.user_id || loggedInID == earning.PlayerID || loggedInIsAdmin) && !c.deleted
                                   };
            }

            earning.CurrentUserCanAddStory = earning.EarningIsAchievement && loggedInID == earning.PlayerID;
            earning.CurrentUserCanEditStory = earning.EarningIsAchievement && ( loggedInID == earning.PlayerID || loggedInIsAdmin );

            return earning;
        }