Exemple #1
0
        public static Payslip Calculatepayslip(Salary_Structure salary)
        {
            Payslip payslip = new Payslip();

            payslip.emp_id        = salary.emp_id;
            payslip.payslip_month = DateTime.Now.Month;
            payslip.payslip_year  = DateTime.Now.Year;
            payslip.basic_pay     = salary.basic_pay / 12;
            payslip.HRA           = salary.HRA / 12;
            payslip.FA            = salary.FA / 12;
            payslip.MA            = salary.MA / 12;
            payslip.CA            = salary.CA / 12;
            payslip.PF            = salary.PF / 12;
            payslip.MI            = salary.MI / 12;
            payslip.ESI           = salary.ESI / 12;
            payslip.Gratuity      = salary.Gratuity / 12;
            payslip.SA            = salary.SA / 12;
            payslip.PT            = salary.PT / 12;
            Incometax incometax = IncometaxRepo.GetTaxValueByEmpId(salary.emp_id);

            if (incometax != null)
            {
                payslip.incometax = incometax.income_tax;
            }
            else
            {
                payslip.incometax = 0;
            }
            payslip.arrears = 0;
            return(payslip);
        }
Exemple #2
0
 public static Payslip FirstMonthSalary(DateTime DOJ, Salary_Structure salary)
 {
     if (salary.is_active == 1)
     {
         int     working_days   = (DateTime.DaysInMonth(DOJ.Year, DOJ.Month) - DOJ.Day) + 1;
         Payslip payslip        = new Payslip();
         decimal per_day_salary = (salary.basic_pay / 12) / 30;
         Debug.WriteLine(working_days);
         payslip.emp_id        = salary.emp_id;
         payslip.basic_pay     = per_day_salary * working_days;
         payslip.HRA           = ((salary.HRA / 12) / 30) * working_days;
         payslip.FA            = (Constants.FOOD_ALLOWANCE / 30) * working_days;
         payslip.MA            = (Constants.MEDICAL_ALLOWANCE / 30) * working_days;
         payslip.CA            = (Constants.CONVEYANCE_ALLOWANCE / 30) * working_days;
         payslip.PF            = ((salary.PF / 12) / 30) * working_days;
         payslip.MI            = ((salary.MI / 12) / 30) * working_days;
         payslip.Gratuity      = ((salary.Gratuity / 12) / 30) * working_days;
         payslip.SA            = ((salary.SA / 12) / 30) * working_days;
         payslip.ESI           = ((salary.ESI / 12) / 30) * working_days;
         payslip.PT            = (Constants.PT / 30) * working_days;
         payslip.payslip_month = DOJ.Month;
         payslip.payslip_year  = DOJ.Year;
         return(payslip);
     }
     else
     {
         return(null);
     }
 }
Exemple #3
0
        public HttpResponseMessage GeneratePayslip(int employee_id)//e_id employee_id
        {
            HttpResponseMessage response = null;

            try
            {
                if (employee_id != 0)
                {
                    Salary_Structure salary            = SalaryRepo.GetSalaryStructureByEmpId(employee_id);
                    Payslip          payslip           = SalaryCalculation.Calculatepayslip(salary);
                    Payslip          existing_instance = PayslipRepo.GetExistingPayslip(payslip.emp_id, payslip.payslip_month, payslip.payslip_year);
                    if (payslip != null && existing_instance == null)
                    {
                        PayslipRepo.AddPayslip(payslip);
                        response = Request.CreateResponse(HttpStatusCode.OK, new EMSResponseMessage("EMS_001", "Pay slip generated successfully!", "Pay slip generated successfully!"));
                    }
                    else
                    {
                        response = Request.CreateResponse(HttpStatusCode.OK, new EMSResponseMessage("EMS_603", "Failure : Pay slip generation Error or payslip for specified month is already exists", "Pay slip generation Error or payslip for specified month is already exists"));
                    }
                }
                else
                {
                    response = Request.CreateResponse(HttpStatusCode.OK, new EMSResponseMessage("EMS_102", "Invalid Input", "Please check input Json"));
                }
            }
            catch (Exception exception)
            {
                Debug.WriteLine(exception.Message);
                Debug.WriteLine(exception.GetBaseException());
                response = Request.CreateResponse(HttpStatusCode.OK, new EMSResponseMessage("EMS_101", "Application Error", exception.Message));
            }
            return(response);
        }
Exemple #4
0
        public static Salary_Structure CalculateSalaryStructure(decimal ctc)
        {
            Salary_Structure salarypobj = new Salary_Structure();

            salarypobj.ctc       = ctc;
            salarypobj.basic_pay = ((salarypobj.ctc * 40) / (100));//basic pay = 40% of ctc
            salarypobj.HRA       = salarypobj.basic_pay / 2;
            salarypobj.MA        = Constants.MEDICAL_ALLOWANCE * 12;
            salarypobj.CA        = Constants.CONVEYANCE_ALLOWANCE * 12;
            salarypobj.PT        = Constants.PT * 12;
            salarypobj.PF        = ((salarypobj.basic_pay * 12) / 100);

            #region FA calculation
            if (salarypobj.ctc < 252000)
            {
                salarypobj.FA = 0;  // CTC Less than 252000 NO need of Food Allowance
            }
            else
            {
                salarypobj.FA = Constants.FOOD_ALLOWANCE * 12;
            }
            #endregion

            salarypobj.SA = salarypobj.ctc - (salarypobj.basic_pay + salarypobj.HRA + salarypobj.MA + salarypobj.CA + salarypobj.FA + salarypobj.PF + salarypobj.Gratuity);
            if (salarypobj.SA < 0)
            {
                salarypobj.SA = 0;
            }
            salarypobj.MI       = 0;
            salarypobj.Gratuity = 0;

            #region ESI calculation
            //ESI Calculation starts
            if (salarypobj.ctc < 252000)
            {
                decimal temp = (salarypobj.basic_pay + salarypobj.HRA + salarypobj.MA + salarypobj.CA + salarypobj.FA + salarypobj.SA + salarypobj.PF);
                salarypobj.ESI = (temp * 475) / 10000;
            }
            else
            {
                salarypobj.ESI = 0;
            }
            #endregion

            return(salarypobj);
        }
Exemple #5
0
        public HttpResponseMessage UpdateSalaryStructure(int employee_id, decimal ctc)
        {
            HttpResponseMessage response = null;

            try
            {
                if (employee_id != 0 && EmployeeRepo.GetEmployeeStatusById(employee_id) != 0 && ctc != 0)
                {
                    Salary_Structure active_instance = SalaryRepo.GetSalaryStructureByEmpId(employee_id);
                    if (active_instance != null)
                    {
                        active_instance.is_active = 0;
                        active_instance.to_date   = DateTime.Now;
                        SalaryRepo.UpdateSalaryStructure(active_instance);

                        Salary_Structure new_sal_structure = new Salary_Structure();
                        new_sal_structure           = SalaryCalculation.CalculateSalaryStructure(ctc);
                        new_sal_structure.emp_id    = employee_id;
                        new_sal_structure.is_active = 1;
                        new_sal_structure.from_date = DateTime.Now;
                        new_sal_structure.to_date   = null;
                        SalaryRepo.CreateSalaryStructure(new_sal_structure);
                        response = Request.CreateResponse(HttpStatusCode.OK, new EMSResponseMessage("EMS_001", "Salary structure successfully updated", "Salary structure successfully updated"));
                    }
                    else
                    {
                        response = Request.CreateResponse(HttpStatusCode.OK, new EMSResponseMessage("EMS_401", "No active Salary Structure", "No active Salary Structure - unable to find active record "));
                    }
                }
                else
                {
                    response = Request.CreateResponse(HttpStatusCode.OK, new EMSResponseMessage("EMS_102", "Invalid Input", "Please check input Json"));
                }
            }
            catch (Exception exception)
            {
                Debug.WriteLine(exception.Message);
                Debug.WriteLine(exception.GetBaseException());
                response = Request.CreateResponse(HttpStatusCode.OK, new EMSResponseMessage("EMS_101", "Application Error", exception.Message));
            }
            return(response);
        }
Exemple #6
0
        public static void UpdateSalaryStructure(Salary_Structure salary)
        {
            EMSEntities datacontext = new EMSEntities();

            try
            {
                datacontext.Entry(salary).State = EntityState.Modified;
                datacontext.SaveChanges();
            }
            catch (Exception exception)
            {
                Debug.WriteLine(exception.Message);
                Debug.WriteLine(exception.GetBaseException());
                throw exception;
            }
            finally
            {
                datacontext.Dispose();
            }
        }
Exemple #7
0
        public HttpResponseMessage EmployeeUpdate(EmployeeModel employee_details)
        {
            HttpResponseMessage Response = null;

            try
            {
                if (employee_details != null)
                {
                    Employee existingInstance = EmployeeRepo.GetEmployeeById(employee_details.id);
                    if (existingInstance == null)
                    {
                        Response = Request.CreateResponse(HttpStatusCode.OK, new EMSResponseMessage("EMS_403", "Employee record doesnot exists!", "Employee record doesnot exists!"));
                    }
                    else//(if existingInstance != null)
                    {
                        Employee employee = new Employee();
                        employee.id                       = employee_details.id;
                        employee.first_name               = employee_details.first_name;
                        employee.last_name                = employee_details.last_name;
                        employee.email                    = employee_details.email;
                        employee.date_of_birth            = employee_details.date_of_birth;
                        employee.date_of_joining          = employee_details.date_of_joining;
                        employee.contact_no               = employee_details.contact_no;
                        employee.reporting_to             = employee_details.reporting_to;
                        employee.year_of_experience       = Decimal.Parse(employee_details.Year_of_experience);
                        employee.gender                   = employee_details.gender;
                        employee.pan_no                   = employee_details.pan_no;
                        employee.bank_account_no          = employee_details.bank_account_no;
                        employee.emergency_contact_no     = employee_details.emergency_contact_no;
                        employee.emergency_contact_person = employee_details.emergency_contact_person;
                        employee.PF_no                    = employee_details.PF_no;
                        employee.medical_insurance_no     = employee_details.medical_insurance_no;
                        employee.blood_group              = employee_details.blood_group;
                        employee.designation              = employee_details.designation_id;
                        employee.created_on               = existingInstance.created_on;

                        employee.user_id = existingInstance.user_id;

                        User_role userrole_instance = EmployeeRepo.GetUserRoleByUserid(employee.user_id);
                        userrole_instance.role_id = employee_details.role_id;
                        EmployeeRepo.UpdateUserRole(userrole_instance);

                        Salary_Structure active_sal_instance = SalaryRepo.GetSalaryStructureByEmpId(employee.id);

                        if (active_sal_instance != null && active_sal_instance.ctc != employee_details.ctc)
                        {
                            active_sal_instance.is_active = 0;
                            active_sal_instance.to_date   = DateTime.Now;
                            SalaryRepo.UpdateSalaryStructure(active_sal_instance);

                            Salary_Structure new_sal_structure = new Salary_Structure();
                            new_sal_structure           = SalaryCalculation.CalculateSalaryStructure(employee_details.ctc);
                            new_sal_structure.emp_id    = employee.id;
                            new_sal_structure.is_active = 1;
                            new_sal_structure.from_date = DateTime.Now;
                            new_sal_structure.to_date   = null;
                            SalaryRepo.CreateSalaryStructure(new_sal_structure);
                        }
                        EmployeeRepo.EditEmployee(employee);
                        Response = Request.CreateResponse(HttpStatusCode.OK, new EMSResponseMessage("EMS_001", "Employee details updated successfully!", "Employee details updated successfully!"));
                    } //(existingInstance != null) ELSE PART
                }     //employee_details != null IF PART
                else  //IF employee_details == null
                {
                    Response = Request.CreateResponse(HttpStatusCode.OK, new EMSResponseMessage("EMS_102", "Invalid Input", "Please check input Json"));
                }
            }
            catch (Exception exception)
            {
                Debug.WriteLine(exception.Message);
                Debug.WriteLine(exception.GetBaseException());
                Response = Request.CreateResponse(HttpStatusCode.OK, new EMSResponseMessage("EMS_101", "Application Error", exception.Message));
            }
            return(Response);
        }
Exemple #8
0
        public HttpResponseMessage CreateNewEmployee(EmployeeModel employee_details)
        {
            HttpResponseMessage Response = null;

            try
            {
                if (employee_details != null && employee_details.role_id != 0 /*&& employee_details.ctc != 0*/ && employee_details.id != 0 && employee_details.reporting_to != 0 && employee_details.designation_id != 0)
                {
                    Employee        existingInstance = EmployeeRepo.GetEmployeeById(employee_details.id);
                    List <Employee> employeeByMailid = EmployeeRepo.GetEmployeeByMailId(employee_details.email);
                    if (existingInstance != null)
                    {
                        Response = Request.CreateResponse(HttpStatusCode.OK, new EMSResponseMessage("EMS_402", "Employee ID already exists", "Employee ID already exists"));
                        return(Response);
                    }
                    if (employeeByMailid.Count != 0)
                    {
                        Response = Request.CreateResponse(HttpStatusCode.OK, new EMSResponseMessage("EMS_402", "Mail ID already exists", "Mail ID already exists"));
                        return(Response);
                    }

                    Employee employee = new Employee();
                    employee.id                       = employee_details.id;
                    employee.first_name               = employee_details.first_name;
                    employee.last_name                = employee_details.last_name;
                    employee.email                    = employee_details.email;
                    employee.date_of_birth            = employee_details.date_of_birth;
                    employee.date_of_joining          = employee_details.date_of_joining;
                    employee.contact_no               = employee_details.contact_no;
                    employee.reporting_to             = employee_details.reporting_to;
                    employee.year_of_experience       = Decimal.Parse(employee_details.Year_of_experience);
                    employee.gender                   = employee_details.gender;
                    employee.pan_no                   = employee_details.pan_no;
                    employee.bank_account_no          = employee_details.bank_account_no;
                    employee.emergency_contact_no     = employee_details.emergency_contact_no;
                    employee.emergency_contact_person = employee_details.emergency_contact_person;
                    employee.PF_no                    = employee_details.PF_no;
                    employee.medical_insurance_no     = employee_details.medical_insurance_no;
                    employee.blood_group              = employee_details.blood_group;
                    employee.designation              = employee_details.designation_id;
                    employee.created_on               = DateTime.Now;

                    bool isEmail = Regex.IsMatch(employee.email,
                                                 @"^([0-9a-zA-Z]" +            //Start with a digit or alphabetical
                                                 @"([\+\-_\.][0-9a-zA-Z]+)*" + // No continuous or ending +-_. chars in email
                                                 @")+" +
                                                 @"@(([0-9a-zA-Z][-\w]*[0-9a-zA-Z]*\.)+[a-zA-Z0-9]{2,17})$"
                                                 , RegexOptions.IgnoreCase);
                    if (isEmail != true)
                    {
                        Response = Request.CreateResponse(HttpStatusCode.OK, new EMSResponseMessage("EMS_402", "Enter valid MailId", "Enter valid MailId"));
                    }
                    else if ((employee.date_of_birth.Year > (DateTime.Now.Year - 21)))
                    {
                        Response = Request.CreateResponse(HttpStatusCode.OK, new EMSResponseMessage("EMS_402", "Employee age is below 21 years", "Employee age is below 21 years"));
                    }
                    else
                    {
                        User user = new User();
                        user.user_name = employee.email;
                        string Temp_password = PasswordGenerator.GeneratePassword();
                        //Debug.WriteLine(Temp_password);
                        user.password = EncryptPassword.CalculateHash(Temp_password);
                        //Debug.WriteLine(user.password);
                        user.is_active = 1;
                        EmployeeRepo.CreateNewUser(user);
                        employee.user_id = user.id;
                        EmployeeRepo.CreateNewEmployee(employee);
                        User_role user_role = new User_role();
                        user_role.user_id = user.id;
                        user_role.role_id = employee_details.role_id;
                        EmployeeRepo.AssignEmployeeRole(user_role);
                        if (employee.gender.ToLower() == "male")
                        {
                            EmployeeRepo.InsertLeaveBalance(employee, Constants.MALE_LEAVE_TYPES);
                        }
                        else
                        {
                            EmployeeRepo.InsertLeaveBalance(employee, Constants.FEMALE_LEAVE_TYPES);
                        }

                        Salary_Structure salary = new Salary_Structure();
                        salary           = SalaryCalculation.CalculateSalaryStructure(employee_details.ctc);
                        salary.emp_id    = employee_details.id;
                        salary.is_active = 1;
                        salary.from_date = DateTime.Now;
                        salary.to_date   = null;
                        SalaryRepo.CreateSalaryStructure(salary);

                        Payslip payslip = new Payslip();
                        payslip = SalaryCalculation.FirstMonthSalary(employee_details.date_of_joining, salary);
                        if (payslip != null)
                        {
                            PayslipRepo.AddPayslip(payslip);
                        }
                        else
                        {
                            Response = Request.CreateResponse(HttpStatusCode.OK, new EMSResponseMessage("EMS_401", "Error in salary structure generation or payslip generation", "Error in salary structure generation or payslip generation"));
                            return(Response);
                        }
                        string username = employee.first_name + " " + employee.last_name;
                        MailHandler.PasswordMailingFunction(username, employee.email, Temp_password);
                        Response = Request.CreateResponse(HttpStatusCode.OK, new EMSResponseMessage("EMS_001", "Employee added Successfully", "Employee added Successfully"));
                    }
                }
                else
                {
                    Response = Request.CreateResponse(HttpStatusCode.OK, new EMSResponseMessage("EMS_190", "Invalid Input - check the fileds", "Invalid Input - check the fileds"));
                }
            }
            catch (DbEntityValidationException DBexception)
            {
                Debug.WriteLine(DBexception.Message);
                Debug.WriteLine(DBexception.GetBaseException());
                Response = Request.CreateResponse(HttpStatusCode.OK, new EMSResponseMessage("EMS_190", "Mandatory fields missing or Type mismatch", DBexception.Message));
            }
            catch (Exception exception)
            {
                Debug.WriteLine(exception.Message);
                Debug.WriteLine(exception.GetBaseException());
                Response = Request.CreateResponse(HttpStatusCode.OK, new EMSResponseMessage("EMS_101", "Application Error", exception.Message));
            }
            return(Response);
        }