public Payslip fetchPayslipById(int payslipId) { Payslip payslip = new Payslip(); Employee employee = new Employee(); sqlCon.Open(); sqlCmd.CommandText = "SELECT * From Payroll WHERE id = @payslipId"; sqlCmd.Parameters.AddWithValue("@payslipId", payslipId); sqlDataReader = sqlCmd.ExecuteReader(); if (sqlDataReader.HasRows) { while (sqlDataReader.Read()) { payslip.id = Int32.Parse(sqlDataReader["id"].ToString()); employee.id = Int32.Parse(sqlDataReader["employeeId"].ToString()); payslip.employee = employee; payslip.dateCreated = Convert.ToDateTime(sqlDataReader["dateCreated"].ToString()); payslip.startDatePeriod = Convert.ToDateTime(sqlDataReader["startDate"].ToString()); payslip.endDatePeriod = Convert.ToDateTime(sqlDataReader["endDate"].ToString()); payslip.basePay = Convert.ToDecimal(sqlDataReader["basePay"].ToString()); payslip.taxDeduction = Convert.ToDecimal(sqlDataReader["taxDeduction"].ToString()); payslip.totalBenefits = Convert.ToDecimal(sqlDataReader["totalBenefits"].ToString()); payslip.totalDeduction = Convert.ToDecimal(sqlDataReader["totalDeduction"].ToString()); payslip.netPay = Convert.ToDecimal(sqlDataReader["netPay"].ToString()); payslip.sssDeduction = Convert.ToDecimal(sqlDataReader["sssDeduction"].ToString()); payslip.pagIbigDeduction = Convert.ToDecimal(sqlDataReader["pagIbigDeduction"].ToString()); payslip.philHealthDeduction = Convert.ToDecimal(sqlDataReader["philHealthDeduction"].ToString()); } } sqlCmd.Parameters.Clear(); sqlCon.Close(); List <int> requestIds = fetchRequestIdsByPayslipId(payslip.id); List <int> miscellaneousIds = fetchMiscellaneousIdsByPayslipId(payslip.id); payslip.miscellaneous = new List <Miscellaneous>(); payslip.requests = new List <Request>(); RequestServiceInterface requestService = new RequestService(); foreach (int requestId in requestIds) { payslip.requests.Add(requestService.fetchById(requestId)); } MiscellaneousServiceInterface miscellaneousService = new MiscellaneousService(); foreach (int miscellaneousId in miscellaneousIds) { payslip.miscellaneous.Add(miscellaneousService.fetchById(miscellaneousId)); } //payslip.requests = requestService. return(payslip); }
public Employee saveEmployee(Employee employee) { UserServiceInterface userService = new UserService(); User user = userService.createUser(employee.userAccount); if (user.id > 0) { sqlCon.Open(); sqlCmd.CommandText = "INSERT into [Employee] (employeeId, userAccountId, fullName, " + "birthDate, gender, civilStatus, dependents, address, contactNumber, tin, " + "sssId, philHealthId, pagIbigId, dateEmployed, jobPositionId) " + "values(@employeeId, @userAccountId, @fullName, " + "@birthDate, @gender, @civilStatus, @dependents, " + "@address, @contactNumber, @tin, @sssId, @philHealthId, @pagIbigId, " + "@dateEmployed, @jobPositionId);SELECT CAST(scope_identity() AS int)"; sqlCmd.Parameters.AddWithValue("@employeeId", employee.employeeId); sqlCmd.Parameters.AddWithValue("@userAccountId", user.id); sqlCmd.Parameters.AddWithValue("@fullName", employee.fullName); sqlCmd.Parameters.AddWithValue("@birthDate", employee.birthDate); sqlCmd.Parameters.AddWithValue("@gender", employee.gender); sqlCmd.Parameters.AddWithValue("@civilStatus", employee.civilStatus); sqlCmd.Parameters.AddWithValue("@dependents", employee.dependents); sqlCmd.Parameters.AddWithValue("@address", employee.address); sqlCmd.Parameters.AddWithValue("@contactNumber", employee.contactNumber); sqlCmd.Parameters.AddWithValue("@tin", employee.tin); sqlCmd.Parameters.AddWithValue("@sssId", employee.sssId); sqlCmd.Parameters.AddWithValue("@philHealthId", employee.philHealthId); sqlCmd.Parameters.AddWithValue("@pagIbigId", employee.pagIbigId); sqlCmd.Parameters.AddWithValue("@dateEmployed", employee.dateEmployed); sqlCmd.Parameters.AddWithValue("@jobPositionId", employee.jobPosition.id); employee.id = (int)sqlCmd.ExecuteScalar(); sqlCon.Close(); LeaveCreditServiceInterface leaveCreditsService = new LeaveCreditService(); EmployeeLeaveCredits employeeLeaveCredits = leaveCreditsService.createEmployeeLeaveCredits(employee); MiscellaneousServiceInterface miscellaneousService = new MiscellaneousService(); Miscellaneous thirteenMonthBenefit = miscellaneousService.createThirteenMonthBenefit(employee); return(employee); } return(null); }