public SalarySlip CreateObject(string Code, string Name, int SalarySign, int SalaryStatus, bool IsMainSalary, bool IsDetailSalary, bool IsEnabled, bool IsPTKP, bool IsPPH21, ISalaryItemService _salaryItemService) { SalarySlip salarySlip = new SalarySlip { Code = Code, Name = Name, SalarySign = SalarySign, IsMainSalary = IsMainSalary, IsDetailSalary = IsDetailSalary, IsEnabled = IsEnabled, IsPTKP = IsPTKP, IsPPH21 = IsPPH21, }; SalaryItem salaryItem = _salaryItemService.GetObjectByCode(Code); if (salaryItem != null) { salarySlip.Errors = new Dictionary <string, string>(); salarySlip.Errors.Add("Code", "SalaryItem dengan Code ini sudah ada"); return(salarySlip); } salaryItem = _salaryItemService.CreateObject(Code, Name, SalarySign, (int)Constant.SalaryItemType.SalarySlip, SalaryStatus, IsMainSalary, IsDetailSalary, false); if (salaryItem == null) { salarySlip.Errors = new Dictionary <string, string>(); salarySlip.Errors.Add("Code", "Tidak dapat membuat SalaryItem dengan Code ini"); return(salarySlip); } salarySlip.SalaryItemId = salaryItem.Id; return(this.CreateObject(salarySlip, _salaryItemService)); }
public SalarySlip CreateObject(SalarySlip salarySlip, ISalaryItemService _salaryItemService) { salarySlip.Errors = new Dictionary <String, String>(); SalaryItem salaryItem = _salaryItemService.GetObjectById(salarySlip.SalaryItemId.GetValueOrDefault()); if (salaryItem == null) { salaryItem = _salaryItemService.GetObjectByCode(salarySlip.Code); if (salaryItem != null) { salarySlip.Errors = new Dictionary <string, string>(); salarySlip.Errors.Add("Code", "SalaryItem dengan Code ini sudah ada"); return(salarySlip); } salaryItem = _salaryItemService.CreateObject(salarySlip.Code, salarySlip.Name, salarySlip.SalarySign, (int)Constant.SalaryItemType.SalarySlip, (int)Constant.SalaryItemStatus.Monthly, salarySlip.IsMainSalary, salarySlip.IsDetailSalary, false); if (salaryItem == null) { salarySlip.Errors = new Dictionary <string, string>(); salarySlip.Errors.Add("Code", "Tidak dapat membuat SalaryItem dengan Code ini"); return(salarySlip); } salarySlip.SalaryItemId = salaryItem.Id; } if (_validator.ValidCreateObject(salarySlip, this, _salaryItemService)) { salarySlip.Index = GetQueryable().Count() + 1; _repository.CreateObject(salarySlip); } ; return(salarySlip); }
public dynamic Insert(SalarySlip model) { try { if (!AuthenticationModel.IsAllowed("Create", Core.Constants.Constant.MenuName.SalarySlip, Core.Constants.Constant.MenuGroupName.Master)) { Dictionary <string, string> Errors = new Dictionary <string, string>(); Errors.Add("Generic", "You are Not Allowed to Add record"); return(Json(new { Errors }, JsonRequestBehavior.AllowGet)); } model = _salarySlipService.CreateObject(model, _salaryItemService); } catch (Exception ex) { LOG.Error("Insert Failed", ex); Dictionary <string, string> Errors = new Dictionary <string, string>(); Errors.Add("Generic", "Error " + ex); return(Json(new { Errors }, JsonRequestBehavior.AllowGet)); } return(Json(new { model.Errors })); }
public SalarySlip UpdateObject(SalarySlip salarySlip, ISalaryItemService _salaryItemService) { if (_validator.ValidUpdateObject(salarySlip, this, _salaryItemService)) { SalaryItem salaryItem = _salaryItemService.GetObjectById(salarySlip.SalaryItemId.GetValueOrDefault()); if (salaryItem == null) { salaryItem = _salaryItemService.CreateObject(salarySlip.Code, salarySlip.Name, salarySlip.SalarySign, (int)Constant.SalaryItemType.SalarySlip, (int)Constant.SalaryItemStatus.Monthly, salarySlip.IsMainSalary, salarySlip.IsDetailSalary, false); salarySlip.SalaryItemId = salaryItem.Id; } else { salaryItem.Code = salarySlip.Code; salaryItem.Name = salarySlip.Name; _salaryItemService.UpdateObject(salaryItem); if (salaryItem.Errors.Any()) { salarySlip.Errors.Clear(); salarySlip.Errors.Add("Code", "Tidak dapat mengubah SalaryItem dengan Code ini"); } } _repository.UpdateObject(salarySlip); } return(salarySlip); }
public dynamic GetDefaultInfo() { SalarySlip model = new SalarySlip(); try { model = _salarySlipService.GetQueryable().FirstOrDefault(); } catch (Exception ex) { LOG.Error("GetInfo", ex); Dictionary <string, string> Errors = new Dictionary <string, string>(); Errors.Add("Generic", "Error " + ex); return(Json(new { Errors }, JsonRequestBehavior.AllowGet)); } return(Json(new { model.Id, model.Index, model.Code, model.Name, model.SalaryItemId, model.SalarySign, model.IsEnabled, model.IsMainSalary, model.IsDetailSalary, model.Errors }, JsonRequestBehavior.AllowGet)); }
public SalarySlip VHasValidSign(SalarySlip salarySlip) { if (salarySlip.SalarySign == 0) { salarySlip.Errors.Add("SalarySign", "Tidak valid"); } return(salarySlip); }
public SalarySlipDetail VHasSalarySlip(SalarySlipDetail salarySlipDetail, ISalarySlipService _salarySlipService) { SalarySlip salarySlip = _salarySlipService.GetObjectById(salarySlipDetail.SalarySlipId); if (salarySlip == null) { salarySlipDetail.Errors.Add("SalarySlip", "Tidak ada"); } return(salarySlipDetail); }
public SalarySlip VHasSalaryItem(SalarySlip salarySlip, ISalaryItemService _salaryItemService) { SalaryItem salaryItem = _salaryItemService.GetObjectById(salarySlip.SalaryItemId.GetValueOrDefault()); if (salaryItem == null) { salarySlip.Errors.Add("SalaryItem", "Tidak ada"); } return(salarySlip); }
public void generate_a_monthly_salary_slip_for_the_employee(Employee employee, SalarySlip expectedSalarySlip) { SalarySlip salarySlip = SalarySlipGenerator.GenerateFor(employee); Assert.AreEqual(expectedSalarySlip.EmployeeId, salarySlip.EmployeeId); Assert.AreEqual(expectedSalarySlip.EmployeeName, salarySlip.EmployeeName); Assert.AreEqual(expectedSalarySlip.MonthlyGrossSalary, salarySlip.MonthlyGrossSalary); Assert.AreEqual(expectedSalarySlip.NationalInsurance, salarySlip.NationalInsurance); Assert.AreEqual(expectedSalarySlip.TaxfreeAllowance, salarySlip.TaxfreeAllowance); Assert.AreEqual(expectedSalarySlip.TaxableIncome, salarySlip.TaxableIncome); Assert.AreEqual(expectedSalarySlip.TaxPayable, salarySlip.TaxPayable); }
public SalarySlip VHasUniqueCode(SalarySlip salarySlip, ISalarySlipService _salarySlipService) { if (String.IsNullOrEmpty(salarySlip.Code) || salarySlip.Code.Trim() == "") { salarySlip.Errors.Add("Code", "Tidak boleh kosong"); } else if (_salarySlipService.IsCodeDuplicated(salarySlip)) { salarySlip.Errors.Add("Code", "Tidak boleh ada duplikasi"); } return(salarySlip); }
public SalarySlip SoftDeleteObject(SalarySlip salarySlip, ISalaryItemService _salaryItemService) { if (_validator.ValidDeleteObject(salarySlip)) { SalaryItem salaryItem = _salaryItemService.GetObjectById(salarySlip.SalaryItemId.GetValueOrDefault()); _repository.SoftDeleteObject(salarySlip); if (salaryItem != null) { _salaryItemService.SoftDeleteObject(salaryItem); } } return(salarySlip); }
public string PrintError(SalarySlip obj) { string erroroutput = ""; KeyValuePair <string, string> first = obj.Errors.ElementAt(0); erroroutput += first.Key + "," + first.Value; foreach (KeyValuePair <string, string> pair in obj.Errors.Skip(1)) { erroroutput += Environment.NewLine; erroroutput += pair.Key + "," + pair.Value; } return(erroroutput); }
public void Return_SalarySlip_With_National_Insurance_Contribution() { // Arrange var employee = new Employee(12345, "John J Doe", 9060M); // Act SalarySlip salarySlip = _salarySlipGenerator.GenerateFor(employee); // Assert salarySlip.Id.Should().Be(12345); salarySlip.Name.Should().Be("John J Doe"); salarySlip.GrossSalary.Should().Be(755M); salarySlip.NationalInsurance.Should().Be(10M); }
public void Return_SalarySlip_With_GrossSalary() { // Arrange var employee = new Employee(12345, "John J Doe", 5000M); // Act SalarySlip salarySlip = _salarySlipGenerator.GenerateFor(employee); // Assert salarySlip.Id.Should().Be(12345); salarySlip.Name.Should().Be("John J Doe"); salarySlip.GrossSalary.Should().Be(416.67M); salarySlip.NationalInsurance.Should().Be(0); }
public bool ValidCreateObject(SalarySlip salarySlip, ISalarySlipService _salarySlipService, ISalaryItemService _salaryItemService) { VHasUniqueCode(salarySlip, _salarySlipService); if (!isValid(salarySlip)) { return(false); } VHasSalaryItem(salarySlip, _salaryItemService); if (!isValid(salarySlip)) { return(false); } VHasValidSign(salarySlip); return(isValid(salarySlip)); }
public static SalarySlip GenerateFor(Employee employee) { var monthlyCalculations = new MonthlyCalculations(employee.AnnualGrossSalary); var salarySlip = new SalarySlip( employeeId: employee.Id, employeeName: employee.Name, monthlyGrossSalary: monthlyCalculations.GrossSalary, nationalInsurance: monthlyCalculations.NationalInsurance, taxfreeAllowance: monthlyCalculations.TaxfreeAllowance, taxableIncome: monthlyCalculations.TaxableIncome, taxPayable: monthlyCalculations.TaxPayable ); return(salarySlip); }
public void GenerateSalaryForJohnDoeWithAnnualGrosSalaryOf_5000pound() { Employee johnDoe = new Employee() { ID = 12345, Name = "John Doe", AnnualGrossSalary = 5000.00m }; ISalarySlipGenerator generator = new SalarySlipGenerator(); SalarySlip salarySlip = generator.GenerateFor(johnDoe); Assert.NotNull(salarySlip); Assert.AreEqual(12345, salarySlip.EmployeeID); Assert.AreEqual("John Doe", salarySlip.EmployeeName); Assert.AreEqual(416.67, salarySlip.MonthlyGrossSalary); }
public void Return_SalarySlip_With_HigherRate_Taxes() { // Arrange var employee = new Employee(12345, "John J Doe", 45000); // Act SalarySlip salarySlip = _salarySlipGenerator.GenerateFor(employee); // Assert salarySlip.Id.Should().Be(12345); salarySlip.Name.Should().Be("John J Doe"); salarySlip.GrossSalary.Should().Be(3750M); salarySlip.NationalInsurance.Should().Be(352.73M); salarySlip.TaxFree.Should().Be(916.67M); salarySlip.TaxableIncome.Should().Be(83.33M); salarySlip.TaxPayable.Should().Be(16.67M); }
/// <summary> /// The primary button control that generates the salary breakdown in a display grid. /// 1) It checks whether the salary input is not empty, populates a model called initialData with the values associated with the employee. /// 2) Collects the addition and the deduction components that the user has added from the UI(form) in userAdditionComponents and userDeductionComponents /// lists respectively and adds them to the initialData model. /// 3) The SalarySlipProcess() method of FormInput is then invoked to start the salary slip computation process. /// 4) The computedRules property of initialData model is used to populate the grid shown to the user. /// 5) The method PopulateGrid() is responsible for filling the display grid with the calculated components (salary Breakdown) that is displayed to the user. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void generateButton_Click(object sender, EventArgs e) { InitialData initialData = null; ICollection <Rules> userAdditionComponents = null; ICollection <Rules> userDeductionComponents = null; SalarySlip objSalarySlip = null; //Setup if (salary.Text.ToString() != string.Empty) { initialData = new InitialData(); decimal salaryAmount = Convert.ToDecimal(salary.Text); initialData.AssociateCode = associateCode.Text.ToString(); initialData.EmployeeName = requiredName.Text.ToString(); initialData.DateOfJoining = dateOfJoining.Text.ToString(); initialData.PanNumber = pan.Text.ToString(); initialData.AccountNumber = accountNumber.Text.ToString(); initialData.Designation = designation.Text.ToString(); initialData.Salary = salary.Text.ToString(); initialData.EmailId = email.Text.ToString(); initialData.Month = month.SelectedItem.ToString(); initialData.Year = year.SelectedItem.ToString(); if (addComponentNumber.Text != string.Empty) { List <Rules> userRules = new List <Rules>(); userRules = SegregateComponents(addComponentNumber, ComputationVariety.ADDITION, userRules); userAdditionComponents = FetchUserComponents(addOuterPanel.Controls, ComputationVariety.ADDITION, userRules); initialData.UserAdditionComponents = userAdditionComponents; } if (deductComponentNumber.Text != string.Empty) { List <Rules> userRules = new List <Rules>(); userRules = SegregateComponents(deductComponentNumber, ComputationVariety.SUBTRACTION, userRules); userDeductionComponents = FetchUserComponents(deductOuterPanel.Controls, ComputationVariety.SUBTRACTION, userRules); initialData.UserDeductionComponents = userDeductionComponents; } objSalarySlip = new FormInput(initialData); objSalarySlip.SalarySlipProcess(); ICollection <Rules> computedRules = initialData.ComputedRules; ICollection <Rules> finalResults = PopulateGrid(computedRules, userAdditionComponents, userDeductionComponents); } }
public dynamic Update(SalarySlip model) { try { if (!AuthenticationModel.IsAllowed("Edit", Core.Constants.Constant.MenuName.SalarySlip, Core.Constants.Constant.MenuGroupName.Master)) { Dictionary <string, string> Errors = new Dictionary <string, string>(); Errors.Add("Generic", "You are Not Allowed to Edit record"); return(Json(new { Errors }, JsonRequestBehavior.AllowGet)); } var data = _salarySlipService.GetObjectById(model.Id); data.Index = model.Index; data.Code = model.Code; data.Name = model.Name; //data.SalaryItemId = model.SalaryItemId; data.SalarySign = model.SalarySign; data.IsEnabled = model.IsEnabled; data.IsMainSalary = model.IsMainSalary; data.IsDetailSalary = model.IsDetailSalary; model = _salarySlipService.UpdateObject(data, _salaryItemService); } catch (Exception ex) { LOG.Error("Update Failed", ex); Dictionary <string, string> Errors = new Dictionary <string, string>(); Errors.Add("Generic", "Error " + ex); return(Json(new { Errors }, JsonRequestBehavior.AllowGet)); } return(Json(new { model.Errors })); }
public IPaySlipDetails GetPaySlip(ITaxStructure taxStructure) { IPaySlipDetails paySlipDetails = null; try { var employee = _mapper.Map <IEmployeeDetails, IEmployee>(_employeeDetails); var salarySlip = SalarySlip.CreateSalarySlip(employee.Salary, taxStructure); salarySlip.TaxPeriod = _employeeDetails.TaxPeriod; employee.SalarySlips.Add(salarySlip); paySlipDetails = _mapper.Map <IEmployee, IPaySlipDetails>(employee); } catch (Exception ex) { _employeeMonthlyPayslipAppContext.AddError( new EmployeeMonthlyPayslipAppError("EmployeePayDetailsService:GetPaySlip", new EmployeeMonthlyPayslipAppException("Error occured while processing pay slip", ex)) ); } return(paySlipDetails); }
public dynamic Delete(SalarySlip model) { try { if (!AuthenticationModel.IsAllowed("Delete", Core.Constants.Constant.MenuName.SalarySlip, Core.Constants.Constant.MenuGroupName.Master)) { Dictionary <string, string> Errors = new Dictionary <string, string>(); Errors.Add("Generic", "You are Not Allowed to Delete Record"); return(Json(new { Errors }, JsonRequestBehavior.AllowGet)); } var data = _salarySlipService.GetObjectById(model.Id); model = _salarySlipService.SoftDeleteObject(data, _salaryItemService); } catch (Exception ex) { LOG.Error("Delete Failed", ex); Dictionary <string, string> Errors = new Dictionary <string, string>(); Errors.Add("Generic", "Error " + ex); return(Json(new { Errors }, JsonRequestBehavior.AllowGet)); } return(Json(new { model.Errors })); }
public bool IsCodeDuplicated(SalarySlip salarySlip) { IQueryable <SalarySlip> salarySlips = _repository.FindAll(x => x.Code == salarySlip.Code && !x.IsDeleted && x.Id != salarySlip.Id); return(salarySlips.Count() > 0 ? true : false); }
public bool isValid(SalarySlip obj) { bool isValid = !obj.Errors.Any(); return(isValid); }
public bool ValidDeleteObject(SalarySlip salarySlip) { salarySlip.Errors.Clear(); return(isValid(salarySlip)); }
public bool ValidUpdateObject(SalarySlip salarySlip, ISalarySlipService _salarySlipService, ISalaryItemService _salaryItemService) { salarySlip.Errors.Clear(); ValidCreateObject(salarySlip, _salarySlipService, _salaryItemService); return(isValid(salarySlip)); }