EchoTex_Payroll/HRM.Report/Class/MultipleEmpLeaveBalance.cs

115 lines
5.4 KiB
C#
Raw Normal View History

2024-10-14 10:01:49 +06:00
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using HRM.BO;
using HRM.DA;
using Microsoft.Reporting.NETCore;
namespace HRM.Report
{
public class MultipleEmpLeaveBalance
{
List<Department> departments = new List<Department>();
List<Leave> leaves = new List<Leave>();
List<Designation> designations = new List<Designation>();
List<Category> categories = new List<Category>();
private List<Employee> employees = new List<Employee>();
private List<EmpLeaveStatus> balance = new List<EmpLeaveStatus>();
private LeaveYear leaveYear = new LeaveYear();
Leave leave = null;
DataRow dr = null;
Department dept = null;
Designation desig = null;
DataSet leaveApprover = new DataSet();
public byte[] ShowMultipleEmpLeaveBalance(int leaveYearId, int payrollTypeId, string empIds, string reportType)
{
departments = new DepartmentService().GetAll();
leaves = new LeaveService().Get(EnumStatus.Regardless, payrollTypeId);
designations = new DesignationService().GetAll();
employees = new EmployeeService().GetByEmpIDs(empIds);
leaveYear = new LeaveYearService().Get(leaveYearId);
//balance = new LeaveProcessService().CurrentYearStatus(employees, leaveYear, payrollTypeId);
List<SearchEmployee> emps = new SearchEmployeeService().GetByEmpIDIn(empIds);
LeaveYear lyy = new LeaveYear();
lyy = new LeaveYearService().Get(leaveYear.ID);
List<Leave> oleaves = new LeaveService().Get(EnumStatus.Regardless, payrollTypeId);
LeaveYear cly = new LeaveYearService().GetCurrentYear(payrollTypeId);
if (cly == lyy)
{
balance = new LeaveProcessService().GetLeaveBalance(employees, leaveYear, payrollTypeId);
balance = balance.OrderBy(item => item.EmpId).ToList(); // must for the row sequence
}
else
{
balance =new LeaveProcessService().GetByEmpIDs(SearchEmployee.getEmpID(emps), lyy.ID);
}
categories = new CategoryService().GetAll();
int count = 1;
PayrollDataSet.dsEmpLeaveLedger.MultipleEmployeeLeaveDataTable mulLeaveBalance = new PayrollDataSet.dsEmpLeaveLedger.MultipleEmployeeLeaveDataTable();
Employee oPreviousEmp = null;
foreach (EmpLeaveStatus olevestatus in balance)
{
Employee oemp = employees.Find(oem => oem.ID == olevestatus.EmpId);
leave = leaves.Find(x => x.ID == olevestatus.LeaveId);
Category category = categories.Find(x => x.ID == oemp.CategoryID);
dr = mulLeaveBalance.NewRow();
//leaveApprover = Employee.GetLineManager(oemp.ID.Integer);
// workLocation = employeeLocations.FirstOrDefault(n => n.EmployeeLocationID.Integer == olevestatus.EmpId);
dr["EmpNo"] = oemp.EmployeeNo;
dr["Name"] = oemp.Name;
dr["JoiningDate"] = oemp.JoiningDate.ToString("dd-MMM-yy");
dr["DateOfConfirmation"] = oemp.ConfirDate != null ? oemp.ConfirDate.Value.ToString("dd-MMM-yy") : "";
dr["JobStatus"] = category != null ? category.Name : "";
dept = departments.Find(o => o.ID == oemp.DepartmentID);
desig = designations.Find(o => o.ID == oemp.DesignationID);
dr["Designation"] = desig == null ? "" : desig.Name;
dr["Department"] = dept == null ? "" : dept.Name;
//dr["LeaveName"] = leave.Description;
dr["LeaveName"] = leave != null ? leave.Description : "";
dr["OpeningBalance"] = olevestatus.OpeningBalance;
dr["WORKLOCATION"] = "";
dr["CFDays"] = olevestatus.CFDays;
dr["Consumed"] = olevestatus.LeaveAvailed;
dr["ClosingBalance"] = olevestatus.ClosingBalance;
dr["RowSequence"] = oPreviousEmp == null ? count : oemp.ID != oPreviousEmp.ID ? ++count : count;
dr["LeaveNotifier"] = oemp.Name;
dr["LeaveYear"] = leaveYearId.ToString();
mulLeaveBalance.Rows.Add(dr);
oPreviousEmp = oemp;
}
//}
//var sortedData = from DataRow odr in mulLeaveBalance.Rows orderby dr["EmpNo"], dr["RowSequence"] ascending select odr;
//foreach (DataRow odr in sortedData)
//{
// DataRow nDr = dTLeaveBalance.NewRow();
// nDr.ItemArray = odr.ItemArray;
// dTLeaveBalance.Rows.Add(nDr);
//}
DataSet dSet = new DataSet();
mulLeaveBalance.TableName = "dsEmpLeaveLedger_MultipleEmployeeLeave";
dSet.Tables.Add(mulLeaveBalance);
ReportProcessor reportProcessor = new ReportProcessor();
List<ReportParameter> oReportParameter = new List<ReportParameter>();
oReportParameter.Add(new ReportParameter("LeaveYear", leaveYear.Name));
return reportProcessor.CommonReportView(null, "HRM.Report.RDLC.MultipleLeaveEmp.rdlc", dSet, null, oReportParameter, true, payrollTypeId, reportType);
//return reportProcessor.ShowMultipleEmpLeaveBalance(null, dSet, "MultipleLeaveEmp.rdlc", leaveYear.Name, payrollTypeId, reportType);
}
}
}