Ejemplo n.º 1
0
        public PaySlipResultModel GetPaySlip(PaySlipModel model)
        {
            #region Negative values validations

            if (model.AnnualSalary <= 0)
            {
                throw new Exception("Salary should be positive value");
            }

            if (model.SuperRate < 0)
            {
                throw new Exception("Super Rate should be positive value");
            }

            #endregion

            var annualSalary = model.AnnualSalary;
            var grossIncome  = annualSalary.CalculateGrossIncome();
            var incomeTax    = annualSalary.GetTaxSlabAmount();
            var netIncome    = (grossIncome - incomeTax).RoundOffDoller();
            var superAmount  = (grossIncome * model.SuperRate / 100).RoundOffDoller();

            var viewModel = new PaySlipResultModel
            {
                Name        = $"{model.FirstName} {model.LastName}",
                NetIncome   = netIncome,
                GrossIncome = grossIncome,
                IncomeTax   = incomeTax,
                PayPeriod   = model.StartDate,
                SuperAmount = superAmount
            };

            return(viewModel);
        }
        public ActionResult GenerateSalarySlip(long UserId = 0)
        {
            PaySlipModel model = new PaySlipModel();

            if (UserId > 0)
            {
                model = (PaySlipModel)Session["PaySlip"];
                if (model == null)
                {
                    model = new PaySlipModel();
                    var client = new HttpClient();
                    client.BaseAddress = new Uri(HttpContext.Request.Url.AbsoluteUri);
                    var result = client.GetAsync(BaseURL + "/api/Management/GetEmployeeDataById?UserId=" + UserId).Result;
                    if (result.StatusCode == HttpStatusCode.OK)
                    {
                        var contents = result.Content.ReadAsStringAsync().Result;
                        var Response = new JavaScriptSerializer().Deserialize <EmployeeModel>(contents);
                        model.EmployeeID    = Response.UserId;
                        model.DateOfJoining = Response.DateOfJoining;
                        model.DepartmentId  = Response.DepartmentId;
                        model.DesignationId = Response.DesignationId;
                    }
                }
            }
            model.listEmployees   = GetEmployeeList();
            model.listDepartments = GetDepartments();
            if (model.DepartmentId > 0)
            {
                model.listDesignations = GetDesignations(model.DepartmentId);
            }
            ViewBag.Class = "display-hide";
            return(View(model));
        }
 public ActionResult GenerateSalarySlip(PaySlipModel model)
 {
     ViewBag.Class = "display-hide";
     try
     {
         if (ModelState.IsValid)
         {
             model.CreatedBy = UserManager.user.UserId;
             string month = model.PaySlipMonth.Substring(0, 2);
             model.PaySlipMonthName = DateTimeFormatInfo.CurrentInfo.GetMonthName(Convert.ToInt32(month));
             model.PaySlipYear      = model.PaySlipMonth.Substring(3, 4);
             model.PaySlipMonth     = model.PaySlipMonthName + " " + model.PaySlipYear;
             //model.DateOfBirth = Convert.ToDateTime(model.DOB);
             var serialized = new JavaScriptSerializer().Serialize(model);
             var client     = new HttpClient();
             var content    = new StringContent(serialized, System.Text.Encoding.UTF8, "application/json");
             client.BaseAddress = new Uri(HttpContext.Request.Url.AbsoluteUri);
             var result = client.PostAsync(BaseURL + "/api/Management/AddUpdateEmployeePaySlip", content).Result;
             if (result.StatusCode == HttpStatusCode.OK)
             {
                 var contents = result.Content.ReadAsStringAsync().Result;
                 var Response = new JavaScriptSerializer().Deserialize <PaySlipModel>(contents);
                 //ModelState.Clear();
                 //ModelState.AddModelError("CustomError", Response.response);
                 //ViewBag.AlertType = "alert-success";
                 //ViewBag.Class = null;
                 //model = new PaySlipModel();
                 Session["PaySlip"] = Response;
                 return(View("PaySlip", Response));
             }
             else if (result.StatusCode == HttpStatusCode.Unauthorized)
             {
                 var contents = result.Content.ReadAsStringAsync().Result;
                 var Response = new JavaScriptSerializer().Deserialize <PaySlipModel>(contents);
                 ModelState.AddModelError("CustomError", Response.response);
                 ViewBag.Class = "alert-danger";
             }
             else
             {
                 ModelState.AddModelError("CustomError", "Error occurred");
                 ViewBag.Class = "alert-danger";
             }
         }
     }
     catch (Exception ex)
     {
         ModelState.AddModelError("CustomError", ex.Message);
         ViewBag.Class = "alert-danger";
     }
     model.listEmployees   = GetEmployeeList();
     model.listDepartments = GetDepartments();
     model.listDepartments = model.listDepartments.Where(s => s.IsActive == true).ToList();
     if (model.DepartmentId > 0)
     {
         model.listDesignations = GetDesignations(model.DepartmentId);
     }
     return(View(model));
 }
Ejemplo n.º 4
0
        public bool ValidateModel(PaySlipModel paySlipModel)
        {
            if (paySlipModel.AnnualSalary <= 0 || paySlipModel.SuperRate <= 0)
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 5
0
        static string CreateSlipFile(PaySlipModel paySlipModel, string fileName)
        {
            var filePath = Path.Combine(Program.TemporaryFileDirectory, fileName);
            var slip     = new PaySlip
            {
                PaySlipInformation = paySlipModel
            };

            slip.ExportToPdf(filePath);
            return(filePath);
        }
        public IHttpActionResult GeneratePaySlip(PaySlipModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            if (!_paySlipService.ValidateModel(model))
            {
                return(BadRequest());
            }

            var viewModel = _paySlipService.GetPaySlip(model);

            return(Ok(viewModel));
        }
Ejemplo n.º 7
0
        public void Test_GeneratePaySlip_SuperRateNotPassed()
        {
            //Arrange
            var model = new PaySlipModel
            {
                FirstName = "David",
                LastName = "Miller",
                AnnualSalary = 188000,
                StartDate = "01 March – 31 March"
            };

            //Act
            var paySlipService = Resolve<IPaySlipService>();
            var result = paySlipService.ValidateModel(model);

            //Assert
            Assert.IsFalse(result);
        }
Ejemplo n.º 8
0
        public void Test_GeneratePaySlip_With_TaxSlab1()
        {
            //Arrange
            var model = new PaySlipModel
            {
                FirstName = "David",
                LastName = "Miller",
                AnnualSalary = 18000,
                StartDate = "01 March – 31 March",
                SuperRate = 10
            };

            //Act
            var paySlipService = Resolve<IPaySlipService>();
            var result = paySlipService.GetPaySlip(model);

            //Assert
            Assert.AreEqual(0, result.IncomeTax);
            Assert.AreEqual(1500, result.GrossIncome);
            Assert.AreEqual(1500, result.NetIncome);
            Assert.AreEqual(150, result.SuperAmount);
        }
Ejemplo n.º 9
0
 public PaySlip(PaySlipModel paySlipModel)
 {
     InitializeComponent();
     PaySlipInformation = paySlipModel;
 }