public void Remove(BenefitPlan benefitPlan)
 {
     if (Context.Entry(benefitPlan).State == EntityState.Detached)
     {
         context.BenefitPlans.Attach(benefitPlan);
     }
     context.BenefitPlans.Remove(benefitPlan);
 }
Exemplo n.º 2
0
        public ActionResult SetCost(decimal ServiceCost, int ParentId, DateTime issueDate, int EmpId, int BeneficiaryId)
        {
            int         benefitplanId  = _hrUnitOfWork.MedicalRepository.GetBenefitPlanId(ParentId, EmpId, BeneficiaryId);
            int         SubperiodId    = _hrUnitOfWork.MedicalRepository.GetMedicalPeriodId(benefitplanId, issueDate);
            BenefitPlan benefitPlanObj = _hrUnitOfWork.Repository <BenefitPlan>().Where(a => a.Id == benefitplanId).FirstOrDefault();
            decimal?    Dragged        = 0;

            if (benefitPlanObj.CompAmount != 0 && benefitPlanObj.EmpAmount != 0)
            {
                if (SubperiodId > 0)
                {
                    Dragged = _hrUnitOfWork.Repository <BenefitRequest>().Where(a => a.SubPeriodId == SubperiodId && a.EmpId == EmpId && a.BeneficiaryId == BeneficiaryId && a.BenefitId == benefitPlanObj.BenefitId).Sum(a => a.CompanyCost);
                }
                else
                {
                    Dragged = _hrUnitOfWork.Repository <BenefitRequest>().Where(a => a.SubPeriodId == null && a.EmpId == EmpId && a.BeneficiaryId == BeneficiaryId && a.BenefitId == benefitPlanObj.BenefitId).Sum(a => a.CompanyCost);
                }

                var credit = (decimal)benefitPlanObj.CoverAmount - Dragged;

                if (credit > benefitPlanObj.CompAmount)
                {
                    return(Json(new { EmployeeCost = ServiceCost - benefitPlanObj.CompAmount <0 ? 0 : ServiceCost - benefitPlanObj.CompAmount, CompanyCost = benefitPlanObj.CompAmount> ServiceCost ? ServiceCost :benefitPlanObj.CompAmount }, JsonRequestBehavior.AllowGet));
                }

                else if (credit < benefitPlanObj.CompAmount)
                {
                    return(Json(new { EmployeeCost = ServiceCost - credit, CompanyCost = credit }, JsonRequestBehavior.AllowGet));
                }
            }
            else if (benefitPlanObj.CompPercent != 0 && benefitPlanObj.EmpPercent != 0)
            {
                if (SubperiodId > 0)
                {
                    Dragged = _hrUnitOfWork.Repository <BenefitRequest>().Where(a => a.SubPeriodId == SubperiodId && a.EmpId == EmpId && a.BeneficiaryId == BeneficiaryId && a.BenefitId == benefitPlanObj.BenefitId).Sum(a => a.CompanyCost);
                }
                else
                {
                    Dragged = _hrUnitOfWork.Repository <BenefitRequest>().Where(a => a.SubPeriodId == null && a.EmpId == EmpId && a.BeneficiaryId == BeneficiaryId && a.BenefitId == benefitPlanObj.BenefitId).Sum(a => a.CompanyCost);
                }
                var CompCost = benefitPlanObj.CoverAmount * (decimal)benefitPlanObj.CompPercent / 100;
                var EmpCost  = benefitPlanObj.CoverAmount * (decimal)benefitPlanObj.EmpPercent / 100;

                var credit = (decimal)benefitPlanObj.CoverAmount - Dragged;
                if (credit < CompCost)
                {
                    return(Json(new { EmployeeCost = ServiceCost - credit, CompanyCost = credit }, JsonRequestBehavior.AllowGet));
                }

                else if (credit > CompCost)
                {
                    return(Json(new { EmployeeCost = ServiceCost - CompCost <0 ? 0 : ServiceCost - CompCost, CompanyCost = CompCost> ServiceCost ? ServiceCost : CompCost }, JsonRequestBehavior.AllowGet));
                }
            }

            return(Json(null, JsonRequestBehavior.AllowGet));
        }
 public static BenefitPlan CreateBenefitPlan(string plan, long deductionPriority, decimal defaultContributionLimitAmount, decimal defaultDeductionLimitAmount, global::Microsoft.Dynamics.DataEntities.Currency currency)
 {
     BenefitPlan benefitPlan = new BenefitPlan();
     benefitPlan.Plan = plan;
     benefitPlan.DeductionPriority = deductionPriority;
     benefitPlan.DefaultContributionLimitAmount = defaultContributionLimitAmount;
     benefitPlan.DefaultDeductionLimitAmount = defaultDeductionLimitAmount;
     if ((currency == null))
     {
         throw new global::System.ArgumentNullException("currency");
     }
     benefitPlan.Currency = currency;
     return benefitPlan;
 }
Exemplo n.º 4
0
        private void SeedEmployees()
        {
            BenefitPlan plan  = _context.BenefitPlans.First();
            PayCycle    cycle = _context.PayCycles.First();

            _context.Employees.Add(
                new Employee
            {
                FirstName    = "John",
                LastName     = "Smith",
                BenefitPlan  = plan,
                PayCycle     = cycle,
                MonthlyGross = 2000
            });

            _context.Employees.Add(
                new Employee
            {
                FirstName    = "Jill",
                LastName     = "Werner",
                BenefitPlan  = plan,
                PayCycle     = cycle,
                MonthlyGross = 2000
            });

            _context.Employees.Add(
                new Employee
            {
                FirstName    = "Derek",
                LastName     = "Jeter",
                BenefitPlan  = plan,
                PayCycle     = cycle,
                MonthlyGross = 2000
            });

            _context.Employees.Add(
                new Employee
            {
                FirstName    = "Robert",
                LastName     = "Barone",
                BenefitPlan  = plan,
                PayCycle     = cycle,
                MonthlyGross = 2000
            });
            _context.SaveChanges();
        }
 public DbEntityEntry <BenefitPlan> Entry(BenefitPlan benefitPlan)
 {
     return(Context.Entry(benefitPlan));
 }
 public void Attach(BenefitPlan benefitPlan)
 {
     context.BenefitPlans.Attach(benefitPlan);
 }
 public void Add(BenefitPlan benefitPlan)
 {
     context.BenefitPlans.Add(benefitPlan);
 }
        private List <Error> SaveGrid(BenefitPlanVM grid1, IEnumerable <KeyValuePair <string, ModelState> > state, Benefit benefit)
        {
            List <Error> errors = new List <Error>();

            // Deleted
            if (grid1.deleted != null)
            {
                foreach (BenefitPlanViewModel model in grid1.deleted)
                {
                    var benefitplan = new BenefitPlan
                    {
                        Id = model.Id
                    };
                    AutoMapper(new Models.AutoMapperParm
                    {
                        Source     = benefitplan,
                        ObjectName = "Benefit",
                        Transtype  = TransType.Delete
                    });

                    _hrUnitOfWork.BenefitsRepository.Remove(benefitplan);
                }
            }

            // Exclude delete models from sever side validations
            if (ServerValidationEnabled)
            {
                var modified = Models.Utils.GetModifiedRows(state.Where(a => !a.Key.Contains("deleted")));
                if (modified.Count > 0)
                {
                    errors = _hrUnitOfWork.CompanyRepository.Check(new CheckParm
                    {
                        CompanyId  = CompanyId,
                        ObjectName = "BenefitPlans",
                        Columns    = Models.Utils.GetModifiedRows(state.Where(a => !a.Key.Contains("deleted"))),
                        Culture    = Language
                    });

                    if (errors.Count() > 0)
                    {
                        return(errors);
                    }
                }
            }

            // updated records
            if (grid1.updated != null)
            {
                foreach (BenefitPlanViewModel model in grid1.updated)
                {
                    var benefitplan = new BenefitPlan();
                    _hrUnitOfWork.BenefitsRepository.BenefitServs(model.BenefitServs, model.Id);
                    AutoMapper(new Models.AutoMapperParm {
                        Destination = benefitplan, Source = model, Transtype = TransType.Update
                    });
                    benefitplan.ModifiedTime = DateTime.Now;
                    benefitplan.ModifiedUser = UserName;
                    _hrUnitOfWork.BenefitsRepository.Attach(benefitplan);
                    _hrUnitOfWork.BenefitsRepository.Entry(benefitplan).State = EntityState.Modified;
                }
            }

            // inserted records
            if (grid1.inserted != null)
            {
                foreach (BenefitPlanViewModel model in grid1.inserted)
                {
                    var benefitplan = new BenefitPlan();
                    AutoMapper(new Models.AutoMapperParm {
                        Destination = benefitplan, Source = model, Transtype = TransType.Insert
                    });
                    benefitplan.Benefit     = benefit;
                    benefitplan.CreatedTime = DateTime.Now;
                    benefitplan.CreatedUser = UserName;
                    var ids             = _hrUnitOfWork.Repository <BenefitServ>().Where(a => model.BenefitServs.Contains(a.Name)).Select(a => a.Id).ToList();
                    var benfitServPlans = new List <BenefitServPlans>();
                    ids.ForEach(delegate(int id)
                    {
                        benfitServPlans.Add(new BenefitServPlans {
                            BenefitPlan = benefitplan, BenefitServId = id
                        });
                    });
                    _hrUnitOfWork.BenefitsRepository.AddRange(benfitServPlans);
                    _hrUnitOfWork.BenefitsRepository.Add(benefitplan);
                }
            }

            return(errors);
        }
Exemplo n.º 9
0
 public BenefitCalculator(BenefitPlan plan, PayCycle cycle, IDiscount discount)
 {
     _plan     = plan;
     _cycle    = cycle;
     _discount = discount;
 }