EchoTex_Payroll/HRM.Report/Class/rptLeave.cs
2024-10-14 10:01:49 +06:00

864 lines
47 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using Payroll.BO;
using Ease.CoreV35;
using Ease.Core.Model;
using Ease.Core.Utility;
using System.Windows.Forms;
using HRM.BO;
using HRM.DA;
using HRM.Report;
using System.IO;
using HRM.Service;
using Microsoft.Reporting.NETCore;
using static HRM.Report.PayrollDataSet.dsEmpLeaveLedger;
namespace HRM.Report
{
public class rptLeave
{
//ReportParameter rParam = null;
private List<ReportParameter> reportParameters = new List<ReportParameter>();
public byte[] ShowEmployeeWiseLeaveLedger(string sEmpID, /*DateTime fromDate, DateTime toDate,*/ int leaveYearId, int payrollTypeId, string reportType)
{
if (!string.IsNullOrEmpty(sEmpID))
{
List<Employee> oEmployees = new EmployeeService().GetByEmpIDs(sEmpID);
//return AllLeaveLedger(oEmployees, fromDate, toDate, leaveId, payrollTypeId, reportType);
return AllLeaveLedger(oEmployees, leaveYearId, payrollTypeId, reportType);
}
return null;
}
public byte[] ShowCCWiseLeaveEncashmentReturn(int leaveYearId, int payrollTypeId, string reportType)
{
DataRow dr = null;
PayrollDataSet.dsEmpLeaveLedger.CCWiseLeaveEncashDataTable mulLeaveBalance = new PayrollDataSet.dsEmpLeaveLedger.CCWiseLeaveEncashDataTable();
DataTable dt = new LeaveEncashmentService().GetData(leaveYearId);
foreach (DataRow dr1 in dt.Rows)
{
dr = mulLeaveBalance.NewRow();
dr["Name"] = dr1[0].ToString();
dr["Amount"] = Convert.ToDouble(dr1[1].ToString());
mulLeaveBalance.Rows.Add(dr);
}
DataSet dSet = new DataSet();
mulLeaveBalance.TableName = "dsEmpLeaveLedger_CCWiseLeaveEncash";
dSet.Tables.Add(mulLeaveBalance);
string RDLC = "HRM.Report.RDLC.rptCCWiseEncashSummary.rdlc";
return new ReportProcessor().CommonReportView(null, RDLC, dSet, null, null, true, payrollTypeId, reportType);
return null;
}
public byte[] ShowLeaveEncashmentReports(string sEmpIDs, int leaveYearId, string selectedReport, int payrollTypeId, string reportType)
{
DataRow dr = null;
List<Employee> employees = new List<Employee>();
EmployeeService employeeService = new EmployeeService();
LeaveYearService leaveYearService = new LeaveYearService();
LeaveYear oLeaveYear = leaveYearService.Get(leaveYearId);
employees = employeeService.GetByEmpIDs(sEmpIDs);
if (selectedReport == "EmployeeWise Encashment")
{
DataSet oEmpDetails = employeeService.GetEncashmentReport(sEmpIDs, oLeaveYear.Name);
if (oEmpDetails.Tables.Count > 0)
{
LeaveEntry le = null;
List<EmpLeaveStatus> statuses = new LeaveProcessService().GetLeaveBalance(oLeaveYear.ID, payrollTypeId, sEmpIDs);
List<LeaveEntry> les = new LeaveEntryService().Get(sEmpIDs, oLeaveYear.ID, EnumLeaveStatus.OnApproval);
les = les.Where(x => x.LeaveID == 1).ToList();
GlobalFunctions.bDataFound = true;
PayrollDataSet.PayrollDataSet.dtEncashmentReportDataTable dTEmpDetail = new PayrollDataSet.PayrollDataSet.dtEncashmentReportDataTable();
int i = 0;
foreach (DataRow oDRow in oEmpDetails.Tables[0].Rows)
{
EmpLeaveStatus status = statuses.FirstOrDefault(x => x.EmpId.ToString() == oDRow["EMPLOYEEID"].ToString());
le = les.FirstOrDefault(x => x.EmpID.ToString() == oDRow["EMPLOYEEID"].ToString());
int appliedLeave = (int) les.FindAll
(x => x.EmpID.ToString() == oDRow["EMPLOYEEID"].ToString() && x.LeaveID == 1)
.Sum(x => x.ApprovedTotalDays); // 1 for annual leave
dr = dTEmpDetail.NewRow();
dr["EmpID"] = oDRow["EMPLOYEENO"];
dr["Name"] = oDRow["Name"];
dr["EncashmentDays"] = oDRow["ENCASHDAYS"];
dr["EncashmentAmount"] = oDRow["ENCASHAMOUNT"];
dr["DailyAmount"] = Convert.ToDouble(oDRow["ENCASHAMOUNT"]) / Convert.ToDouble(oDRow["ENCASHDAYS"]);
dr["LeaveType"] = oDRow["LeaveType"];
dr["grossSalary"] = Convert.ToDouble(oDRow["GROSSSALARY"].ToString());
dr["Department"] = oDRow["Department"];
dr["Designation"] = oDRow["Designation"];
dr["Location"] = oDRow["Location"];
dr["JOININGDATE"] = Convert.ToDateTime(oDRow["JOININGDATE"]).ToString("dd MMM yyyy");
dr["CC"] = oDRow["CC"];
dr["LeaveBalance"] = oDRow["LeaveBalance"];
dr["Grade"] = oDRow["Grade"];
dr["Category"] = oDRow["Category"].ToString() == "Expats" ? "Expats" : "Local";
if (status != null)
{
dr["Opening"] = status.OpeningBalance;
dr["Availed"] = status.LeaveAvailed; // - Convert.ToDouble(oDRow["ENCASHDAYS"])
}
if (le != null)
{
//dr["OnApprovedLeave"] = le.AppliedTotalDays;
dr["OnApprovedLeave"] = appliedLeave;
}
else
{
dr["OnApprovedLeave"] = 0;
}
i++;
dr["Sl"] = i.ToString();
dTEmpDetail.Rows.Add(dr);
}
//form.ShowDlgForTrainingSummaryReport(dTEmpDetail);
DataSet dSet = new DataSet();
dTEmpDetail.TableName = "PayrollDataSet_dtEncashmentReport";
dSet.Tables.Add(dTEmpDetail);
List<ReportParameter> parameters = new List<ReportParameter>();
ReportParameter rParam = new ReportParameter("LeaveYear", oLeaveYear.Name);
parameters.Add(rParam);
string RDLC = "HRM.Report.RDLC.EncashmentReport.rdlc";
return new ReportProcessor().CommonReportView(null, RDLC, dSet, null, parameters, true, payrollTypeId, reportType);
}
}
else if (selectedReport == "Bank Advice")
{
DataSet oEmpDetails = employeeService.GetBankAdviceReport(sEmpIDs, oLeaveYear.Name);
if (oEmpDetails.Tables.Count > 0)
{
GlobalFunctions.bDataFound = true;
PayrollDataSet.PayrollDataSet.dtBankAdviceDataTable dTEmpDetail = new PayrollDataSet.PayrollDataSet.dtBankAdviceDataTable();
int i = 0;
foreach (DataRow oDRow in oEmpDetails.Tables[0].Rows)
{
dr = dTEmpDetail.NewRow();
dr["ID"] = oDRow["EMPLOYEENO"];
dr["Name"] = oDRow["Name"];
dr["ACNo"] = oDRow["ACCOUNTNO"];
dr["Amount"] = GlobalFunctions.TakaFormat(Convert.ToDouble(oDRow["ENCASHAMOUNT"].ToString()));
i++;
dr["Sl"] = i.ToString();
dr["Remarks"] = "Leave Encashment";
dTEmpDetail.Rows.Add(dr);
}
//form.ShowDlgForTrainingSummaryReport(dTEmpDetail);
DataSet dSet = new DataSet();
dTEmpDetail.TableName = "PayrollDataSet_dtBankAdvice";
dSet.Tables.Add(dTEmpDetail);
string RDLC = "HRM.Report.RDLC.Advice.rdlc";
return new ReportProcessor().CommonReportView(null, RDLC, dSet, null, null, true, payrollTypeId, reportType);
}
}
else if (selectedReport == "Payslip")
{
DataSet oEmpDetails = employeeService.GetEncashPayslip(sEmpIDs, oLeaveYear.Name);
DataSet tempDataSet = new DataSet();
if (oEmpDetails.Tables.Count > 0)
{
GlobalFunctions.bDataFound = true;
PayrollDataSet.dsEmpLeaveLedger.BonusPaySlipDataTable dPaySlipData = new PayrollDataSet.dsEmpLeaveLedger.BonusPaySlipDataTable();
int i = 0;
foreach (DataRow oDRow in oEmpDetails.Tables[0].Rows)
{
dr = dPaySlipData.NewRow();
dr["EmpNo"] = oDRow["EMPLOYEENO"];
dr["Name"] = oDRow["NAME"];
dr["Basic"] = oDRow["BasicSalary"];
dr["BonusAmount"] = oDRow["ENCASHAMOUNT"];
dr["TaxAmount"] = oDRow["TaxAmount"];
dr["Department"] = oDRow["Department"];
dr["Designation"] = oDRow["Designation"];
//dr["BonusMonth"] = cboLeaveYear.Text;
dr["GrossSalary"] = oDRow["GROSSSALARY"];
//oDR["NetBonus"]=oDRow["PAYMENTMODE"];
dr["PAYMENTMODE"] = oLeaveYear.Name;
//oDR["SLNo"] = count;
dPaySlipData.Rows.Add(dr);
i++;
}
//form.ShowDlgForTrainingSummaryReport(dTEmpDetail);
dPaySlipData.TableName = "PayrollDataSet_BonusPaySlip";
tempDataSet.Tables.Add(dPaySlipData);
string RDLC = "HRM.Report.RDLC.EncashPaySlip.rdlc";
return new ReportProcessor().CommonReportView(null, RDLC, tempDataSet, null, null, true, payrollTypeId, reportType);
}
else
GlobalFunctions.bDataFound = false;
}
else if (selectedReport == "Cash Advice")
{
DataSet leaveCashAdvice = employeeService.GetLeaveCashAdvice(sEmpIDs, oLeaveYear.Name);
if (leaveCashAdvice.Tables.Count > 0)
{
GlobalFunctions.bDataFound = true;
PayrollDataSet.dsEmpLeaveLedger.LeaveCashAdviceDataTable dTEmpDetail = new PayrollDataSet.dsEmpLeaveLedger.LeaveCashAdviceDataTable();
foreach (DataRow oDRow in leaveCashAdvice.Tables[0].Rows)
{
dr = dTEmpDetail.NewRow();
dr["EmpNo"] = oDRow["EMPLOYEENO"].ToString();
dr["Name"] = oDRow["NAME"].ToString();
dr["grossSalary"] = Convert.ToDouble(oDRow["GROSSSALARY"].ToString());
dr["EncashmentAmount"] = Convert.ToDouble(oDRow["ENCASHAMOUNT"].ToString());
dTEmpDetail.Rows.Add(dr);
}
DataSet dSet = new DataSet();
dTEmpDetail.TableName = "dsEmpLeaveLedger_LeaveCashAdvice";
dSet.Tables.Add(dTEmpDetail);
List<ReportParameter> paramList = new List<ReportParameter>();
ReportParameter tempParam = new ReportParameter("LeaveYear", oLeaveYear.Name);
paramList.Add(tempParam);
string RDLC = "HRM.Report.RDLC.LeaveCashAdvice.rdlc";
return new ReportProcessor().CommonReportView(null, RDLC, dSet, null, paramList, true, payrollTypeId, reportType);
}
else
{
GlobalFunctions.bDataFound = false;
}
}
return null;
}
public static byte[] AllLeaveLedger(List<Employee> employees, int leaveYearId, /*DateTime fromDate, DateTime toDate, int leaveType,*/ int payrollTypeId, string reportType)
{
DataSet rptDS = new DataSet();
DataSet rptSubDS = new DataSet();
PayrollDataSet.dsEmpLeaveLedger.TeamLeaveEmpInfoDataTable dt1 = new PayrollDataSet.dsEmpLeaveLedger.TeamLeaveEmpInfoDataTable();
PayrollDataSet.dsEmpLeaveLedger.TeamLeaveTypeDataTable dt2 = new PayrollDataSet.dsEmpLeaveLedger.TeamLeaveTypeDataTable();
PayrollDataSet.dsEmpLeaveLedger.TeamLeaveDetailsDataTable dt3 = new PayrollDataSet.dsEmpLeaveLedger.TeamLeaveDetailsDataTable();
DataTable dt = new DataTable();
List<LeaveYear> leaveYear = new LeaveYearService().Get();
//LeaveYear curLeaveYear = LeaveYear.GetCurrentYear();
//LeaveYear curLeaveYear = leaveYear.Find(x => fromDate.Date >= x.StartDate.Date && toDate.Date <= x.EndDate.Date);
LeaveYear curLeaveYear = leaveYear.Find(x => x.ID == leaveYearId);
List<LeaveEntry> oLeaveEntrys = new List<LeaveEntry>();
List<OrganogramBasic> oOrgBasics = new OrganogramService().Get(EnumStatus.Regardless);
List<OrganogramAuthority> oOrgAuthorities = new OrganogramService().GetAllOrganAuthority();
List<OrganogramEmployee> oOrgEmployees = new OrganogramEmployeeService().Get();
List<Employee> oEmployees = new EmployeeService().Get();
string sEmpIDs = employees.CommaSeparatedIDs();
//oLeaveEntrys = new LeaveEntryService().GetEmployeeWiseLeaveDetailReport(sEmpIDs, fromDate, toDate);
oLeaveEntrys = new LeaveEntryService().GetEmployeeWiseLeaveDetailReport(sEmpIDs, curLeaveYear.StartDate, curLeaveYear.EndDate);
List<LeaveEncashment> leaveEncashments = new LeaveEncashmentService().Get(curLeaveYear.ID);
LeaveEntry leaveEntry = null;
//if (leaveType != 0)
// oLeaveEntrys = oLeaveEntrys.Where(x => x.LeaveID == leaveType).ToList();
DataRow oRow = null;
DataRow odr1 = null;
DataRow odr2 = null;
DataRow odr3 = null;
DataTable dtBasic = new EmployeeService().GetBasic(sEmpIDs);
List<Leave> _oLeaves = new LeaveService().Get(EnumStatus.Active, payrollTypeId);
List<Designation> designations = new DesignationService().GetAll();
List<Department> departments = new DepartmentService().GetAll();
#region Basic
foreach (Employee empTemp in employees)
{
//string query = string.Format(@"SELECT Employee.Name FROM Employee,
// (SELECT EmployeeID FROM OrganEmployee oe WHERE oe.NodeID =
// (
// SELECT ParentID FROM Organogram o WHERE o.OrganogramID=
// (SELECT NodeID FROM OrganEmployee oe WHERE EmployeeID={0}))) tab1
// WHERE Employee.EMPLOYEEID=tab1.EmployeeID", empTemp.ID);
DataTable orgEmpDT = null;
try
{
orgEmpDT = dtBasic.AsEnumerable().Where(x => x["employeeid"].ToString() == empTemp.ID.ToString()).CopyToDataTable(); //GlobalFunctions.GetDataTable(query);
}
catch (Exception)
{
}
odr1 = dt1.NewRow();
odr1["EmpNo"] = empTemp.EmployeeNo;
odr1["EmpName"] = empTemp.Name;
Designation dsg = designations.Find(des => des.ID == empTemp.DesignationID);
odr1["Designation"] = dsg != null ? dsg.Name : string.Empty;
Department dpt = departments.Find(dept => dept.ID == empTemp.DepartmentID);
odr1["Department"] = dpt != null ? dpt.Name : string.Empty;
odr1["LeavePeriod"] = curLeaveYear.Name;
odr1["LeaveApprover"] = (orgEmpDT != null && orgEmpDT.Rows.Count > 0) ? orgEmpDT.Rows[0]["approverName"] : string.Empty;
List<Employee> oNotifierEmpoloyees = new OrganogramService().GetOrganogramAutoriyEmployee(oEmployees, oOrgEmployees, oOrgBasics, oOrgAuthorities, EnumAuthorityType.Doted, empTemp);
string notifierNames = oNotifierEmpoloyees.Aggregate(new StringBuilder(), (acc, x) => acc.AppendFormat("{0},", x.Name),
acc => acc.ToString().Trim(','));
odr1["LeaveNotifier"] = notifierNames;
dt1.Rows.Add(odr1);
}
dt1.TableName = "TeamLeaveEmpInfo";
rptDS.Tables.Add(dt1);
#endregion
#region Status
List<EmpLeaveStatus> oEmpLeaveStatus = new LeaveProcessService().CurrentYearStatus(employees, curLeaveYear, payrollTypeId);
foreach (EmpLeaveStatus eLStatus in oEmpLeaveStatus)
{
Employee emp = oEmployees.FirstOrDefault(x => x.ID == eLStatus.EmpId);
//emp = new EmployeeService().Get(eLStatus.EmpId);
LeaveYear lYear = leaveYear.Where(x => x.ID == eLStatus.LeaveYearID).FirstOrDefault();
odr2 = dt2.NewRow();
odr2["EmpNo"] = emp.EmployeeNo;
Leave lv = _oLeaves.Where(x => x.ID == eLStatus.LeaveId).FirstOrDefault();
odr2["LeaveType"] = lv != null ? lv.Description : string.Empty;
odr2["OpeningBalance"] = eLStatus.OpeningBalance - eLStatus.CFDays;
odr2["CFdays"] = eLStatus.CFDays;
odr2["Consumed"] = eLStatus.LeaveAvailed;
odr2["ClosingBalance"] = eLStatus.ClosingBalance;
odr2["Applied"] = eLStatus.ApplyDays;
dt2.Rows.Add(odr2);
}
dt2.TableName = "TeamLeaveType";
rptSubDS.Tables.Add(dt2);
#endregion
#region Leave Encashment
foreach (LeaveEncashment leaveEncashment in leaveEncashments)
{
if (leaveEncashment != null && employees.Any(x => x.ID == leaveEncashment.EmployeeID))
{
leaveEntry = new LeaveEntry();
leaveEntry.EmpID = leaveEncashment.EmployeeID;
leaveEntry.LeaveID = leaveEncashment.LeaveID;
leaveEntry.ApprovedFromDate = leaveEncashment.CreatedDate;
leaveEntry.ApprovedToDate = leaveEncashment.CreatedDate;
leaveEntry.ApprovedTotalDays = leaveEncashment.EncashmentDays;
leaveEntry.Remarks = "Leave Encashment";
leaveEntry.AppliedLeaveDate = leaveEncashment.CreatedDate;
leaveEntry.ApprovedLeaveDate = leaveEncashment.CreatedDate;
leaveEntry.LeaveStatus = EnumLeaveStatus.Approved;
oLeaveEntrys.Add(leaveEntry);
}
}
#endregion
#region Leave Details
foreach (LeaveEntry le in oLeaveEntrys)
{
Employee emp = employees.Where(x => x.ID == le.EmpID).FirstOrDefault();
if (emp == null)
{
continue;
}
odr3 = dt3.NewRow();
odr3["EmpNo"] = emp.EmployeeNo;
odr3["LeaveFrom"] = le.ApprovedFromDate.ToString("dd MMM yyyy");
odr3["LeaveTo"] = le.ApprovedToDate.ToString("dd MMM yyyy");
odr3["TotalDays"] = le.ApprovedTotalDays;
Leave lv = _oLeaves.Where(x => x.ID == le.LeaveID).FirstOrDefault();
odr3["LeaveType"] = lv != null ? lv.Description : string.Empty;
odr3["DateApplied"] = le.AppliedLeaveDate.ToString("dd MMM yyyy");
odr3["DateApproved"] = le.LeaveStatus == EnumLeaveStatus.Approved ? le.ApprovedLeaveDate.ToString("dd MMM yyyy") : "";
odr3["LeaveStatus"] = le.LeaveStatus.GetFriendlyNames();
odr3["LeaveReason"] = le.Remarks;
dt3.Rows.Add(odr3);
}
dt3.TableName = "TeamLeaveDetails";
rptSubDS.Tables.Add(dt3);
#endregion
//_employee = SessionManager.CurrentEmployee;
//leaveYear = LeaveYear.Get();
//curLeaveYear = LeaveYear.GetCurrentYear();
List<ReportParameter> _parameters = new List<ReportParameter>();
_parameters.Add(new ReportParameter("FromDate", curLeaveYear.StartDate.ToString("dd MMM yyyy")));
_parameters.Add(new ReportParameter("ToDate", curLeaveYear.EndDate.ToString("dd MMM yyyy")));
string RDLC = "LeaveLedgers.rdlc";
return new ReportProcessor().CommonReportView(null, rptDS, rptSubDS, RDLC, _parameters, true, payrollTypeId, reportType);
}
public byte[] ShowLeaveRegister(string sEmpID, int leaveYearId, int leaveId, int payrollTypeId, string reportType)
{
List<Designation> designations = new DesignationService().Get(EnumStatus.Active, payrollTypeId);
List<Department> departments = new DepartmentService().Get(EnumStatus.Active, payrollTypeId);
DataRow dr = null;
DataSet leaveApprover = new DataSet();
List<Leave> _oLeaves = new LeaveService().Get(EnumStatus.Active, payrollTypeId);
Leave _oLeave;
_oLeave = _oLeaves.FirstOrDefault(x => x.ID == leaveId);
string sDatecheck = string.Empty;
List<LeaveYear> leaveYear = new LeaveYearService().Get();
LeaveYear lyy = new LeaveYear();
lyy = leaveYear.FirstOrDefault(x => x.ID == leaveYearId);
List<Employee> oEmployees = new EmployeeService().GetAllEmps();
List<Employee> oemps = new EmployeeService().GetByEmpIDs(sEmpID);
List<OrganogramBasic> oOrgBasics = new OrganogramService().Get(EnumStatus.Regardless);
List<OrganogramAuthority> oOrgAuthorities = new OrganogramService().GetAllOrganAuthority();
List<OrganogramEmployee> oOrgEmployees = new OrganogramEmployeeService().Get();
//List<ObjectsTemplate<EmpLeaveStatus>> obalance = EmpLeaveStatus.CurrentYearStatusForReport(oemps, lyy);+
List<EmpLeaveStatus> obalance = new LeaveProcessService().CurrentYearStatus(oemps, lyy, payrollTypeId);
sDatecheck = lyy.Name;
if (_oLeave != null)
{
obalance = obalance.Where(x => x.LeaveId == _oLeave.ID).ToList();
}
string empID = string.Empty;
int count = 1;
DataTable appliedLeavs = new LeaveEntryService().GetTotalLeaveAmountInYear(lyy.ID, EnumLeaveStatus.OnApproval);
PayrollDataSet.dsEmpLeaveLedger.MultipleEmployeeLeaveDataTable mulLeaveBalance = new PayrollDataSet.dsEmpLeaveLedger.MultipleEmployeeLeaveDataTable();
PayrollDataSet.dsEmpLeaveLedger.MultipleEmployeeLeaveDataTable dTLeaveBalance = new PayrollDataSet.dsEmpLeaveLedger.MultipleEmployeeLeaveDataTable();
PayrollDataSet.dsEmpLeaveLedger.LeaveBalanceDataTable dtBalance = new PayrollDataSet.dsEmpLeaveLedger.LeaveBalanceDataTable();
//foreach (ObjectsTemplate<EmpLeaveStatus> oempList in obalance)
//{
foreach (EmpLeaveStatus olevestatus in obalance)
{
Employee oemp = oemps.Find(delegate (Employee oem) { return oem.ID == olevestatus.EmpId; });
Designation designation = designations.FirstOrDefault(x => x.ID == oemp.DesignationID);
Department department = departments.FirstOrDefault(x => x.ID == oemp.DepartmentID);
dr = mulLeaveBalance.NewRow();
leaveApprover = new DataSet();//new EmployeeService().GetLineManagerFromOrg(oemp.ID);
dr["EmpNo"] = oemp.EmployeeNo;
dr["Name"] = oemp.Name;
dr["JoiningDate"] = oemp.JoiningDate.ToString("dd-MMM-yy");
dr["Designation"] = designation != null ? designation.Name : string.Empty;
dr["Department"] = department != null ? department.Name : string.Empty;
dr["LeaveName"] = olevestatus.Leave.Description;
dr["OpeningBalance"] = olevestatus.OpeningBalance - olevestatus.CFDays;
dr["CFDays"] = olevestatus.CFDays;
dr["Consumed"] = olevestatus.LeaveAvailed;
dr["ClosingBalance"] = olevestatus.ClosingBalance;
DataRow[] foundRows = appliedLeavs.Select("Empid=" + oemp.ID + " AND LeaveId=" +olevestatus.LeaveId);
if(foundRows!=null && foundRows.Count() >0)
{
dr["Applied"] = Convert.ToDouble(foundRows[0]["Days"]);
}
// dr["Applied"] = olevestatus.ApplyDays;
dr["RowSequence"] = count++;
//if (leaveApprover.Tables[0].Rows.Count != 0)
//{
// dr["LeaveApprover"] = leaveApprover.Tables[0].Rows[0]["Name"];
//}
//else
//{
// dr["LeaveApprover"] = "";
//}
//List<Employee> oNotifierEmpoloyees = new OrganogramService().GetOrganogramAutoriyEmployee(oEmployees, oOrgEmployees, oOrgBasics, oOrgAuthorities, EnumAuthorityType.Doted, oemp);
string notifierNames = ""; // oNotifierEmpoloyees.Aggregate(new StringBuilder(), (acc, x) => acc.AppendFormat("{0},", x.Name),
//acc => acc.ToString().Trim(','));
dr["LeaveNotifier"] = notifierNames;
dr["LeaveYear"] = lyy.Name;
mulLeaveBalance.Rows.Add(dr);
}
//}
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();
dSet.Tables.Add(dTLeaveBalance);
ReportParameter parameter = new ReportParameter("LeaveYear", sDatecheck);
reportParameters.Add(parameter);
//dTLeaveBalance.TableName = "dsEmpLeaveLedger_LeaveBalance";
dTLeaveBalance.TableName = "dsEmpLeaveLedger_MultipleEmployeeLeave";
//form.ShowMultipleEmpLeaveBalance(null, dSet, "Payroll.Report.RDLC.MultipleLeaveEmp.rdlc", sDatecheck);
string RDLCName = "HRM.Report.RDLC.LeaveRegisterNew.rdlc";
// return new ReportProcessor().ShowMultipleEmpLeaveRegister(null, dSet, RDLC, sDatecheck, payrollTypeId, reportType);
return new ReportProcessor().CommonReportView(null, RDLCName, dSet, null, reportParameters, true, payrollTypeId, reportType);
}
private DataSet RefreshPreviousDayApprovedLeaveReportDataSetForMailSender(string toEmail, DateTime leaveApprovedDate, EnumLeaveStatus leaveStatus)
{
PayrollDataSet.dsEmpLeaveLedger.LeaveEntrysForSchedularDataTable leaveEntryData = new PayrollDataSet.dsEmpLeaveLedger.LeaveEntrysForSchedularDataTable();
List<LeaveEntryDetailsMailSenderReport> leaveEntrys = new LeaveEntryService().GetPreviousDateApprovedLeaveEntry(leaveApprovedDate, toEmail, leaveStatus);
foreach (LeaveEntryDetailsMailSenderReport item in leaveEntrys)
{
DataRow dRow = leaveEntryData.NewRow();
dRow["EMPLOYEEID"] = item.EmployeeId;
dRow["EMPLOYEENO"] = item.EmployeeNo;
dRow["NAME"] = item.Name;
dRow["DESIGNATION"] = item.Designation;
dRow["DEPARTMENT"] = item.Department;
dRow["LeaveEntryID"] = item.LeaveEntryID;
dRow["LEAVESTATUS"] = item.LeaveStatus;
dRow["APPFROMDATE"] = item.FromDate.ToString("dd MMM yyyy");
dRow["APPTODATE"] = item.ToDate.ToString("dd MMM yyyy");
dRow["Reason"] = item.Reason;
dRow["LOCATION"] = item.LocationName;
dRow["LeaveName"] = item.LeaveName;
leaveEntryData.Rows.Add(dRow);
}
DataSet LeaveentryMailSenderReportDs = new DataSet();
leaveEntryData.TableName = "dsEmpLeaveLedger_LeaveEntrysForSchedular";
LeaveentryMailSenderReportDs.Tables.Add(leaveEntryData);
return LeaveentryMailSenderReportDs;
}
public byte[] getLeaveApplication(int sEmpIDs, int payrolltypeid, DateTime NextPayProcessDate)
{
Employee employee = new EmployeeService().Get(sEmpIDs);
LeaveYear lyy = new LeaveYearService().GetCurrentYear(payrolltypeid);
DateTime operationDate = new GlobalFunctionService().GetOperationDate();
if (operationDate.Date > lyy.EndDate.Date)
{
operationDate = lyy.EndDate.Date;
}
List<EmpLeaveStatus> dcurrentStatus = new EmpLeaveStatusService().CurrentYearStatus(new List<Employee> { employee }, lyy, operationDate, EnumLeaveStatus.Approved, NextPayProcessDate);
DataTable dEmpLeaveApplication = new HRM.Report.PayrollDataSet.dsEmpLeaveLedger.LeaveApplicationDataTable();
if (dcurrentStatus.Count() > 0)
{
DataSet ds = new DataSet();
DataRow dr = dEmpLeaveApplication.NewRow();
DataTable dtEmpBasicInfo = new EmployeeService().GetAllEmpBasicInfo(employee.ID.ToString())
.Tables[0]
.AsEnumerable()
.CopyToDataTable();
foreach (DataRow drBasic in dtEmpBasicInfo.Rows)
{
dr["Name"] = drBasic["BanglaName"];
dr["Designation"] = drBasic["BanglaDesignation"];
AccessCard acc = new AccessCardService().Get(drBasic["CardID"] is DBNull ? 0 : Convert.ToInt32(drBasic["CardID"].ToString()));
if (acc != null)
{
dr["CardNo"] = acc.CardNumber;
}
dr["Department"] = drBasic["DepartmentBangla"];
dr["Section"] = drBasic["SectionBangla"];
dr["Unit"] = drBasic["FloorBangla"];
}
foreach (EmpLeaveStatus item in dcurrentStatus)
{
item.Leave = new LeaveService().Get(item.LeaveId);
switch (item.Leave.Code)
{
case "CL":
dr["CLOpen"] = (int)item.OpeningBalance;
dr["CLAvailed"] = (int)item.LeaveAvailed;
dr["CLClose"] = (int)item.ClosingBalance;
break;
case "SL":
dr["MLOpen"] = (int)item.OpeningBalance;
dr["MLAvailed"] = (int)item.LeaveAvailed;
dr["MLClosing"] = (int)item.ClosingBalance;
break;
case "EL":
dr["ELOpen"] = (int)item.OpeningBalance;
dr["ELAvailed"] = (int)item.LeaveAvailed;
dr["ELClosing"] = (int)item.ClosingBalance;
break;
case "ML":
dr["MatLOpen"] = (int)item.OpeningBalance;
dr["MatLAvailed"] = (int)item.LeaveAvailed;
dr["MatLClosing"] = (int)item.ClosingBalance;
break;
case "PL":
dr["PatLOpen"] = (int)item.OpeningBalance;
dr["PatLAvailed"] = (int)item.LeaveAvailed;
dr["PatLClosing"] = (int)item.ClosingBalance;
break;
default:
break;
}
}
dEmpLeaveApplication.Rows.Add(dr);
dEmpLeaveApplication.TableName = "dsEmpLeaveLedger_LeaveApplication";
ds.Tables.Add(dEmpLeaveApplication);
List<ReportParameter> oParameters = new List<ReportParameter>();
ReportParameter rParam = new ReportParameter("LeaveYear", string.Format("{0} - {1}", lyy.StartDate.ToString("dd MMM yyyy"), lyy.EndDate.ToString("dd MMM yyyy")));
oParameters.Add(rParam);
string RDLCName = "HRM.Report.RDLC.LeaveApplication.rdlc";
return new ReportProcessor().CommonReportView(null, RDLCName, ds, null, oParameters, true, payrolltypeid, "PDF");
//fViewer.CommonReportView(null, ds, "Payroll.Report.RDLC.LeaveApplication.rdlc", oParameters);
}
return null;
}
public byte[] GetPreviousDayApprovedLeaveReport(string toEmail, DateTime leaveApprovedDate, EnumLeaveStatus leaveStatus, string fileFormate)
{
ReportProcessor reportProcessor = new ReportProcessor();
string rdlcName = "HRM.Report.RDLC.PreviousDayApprovedLeaveReportForMailSender.rdlc"; // build action of this rdlc has to be embedded resource
string reportTitle = "Approved Leave Report of Sales : (" + leaveApprovedDate.ToString("dd MMM yyyy") + ")";
DataSet tempDataSet = RefreshPreviousDayApprovedLeaveReportDataSetForMailSender(toEmail, leaveApprovedDate, leaveStatus);
return reportProcessor.ShowReportForSchedular(null, rdlcName, tempDataSet, null, true, reportTitle, fileFormate);
}
public byte[] GetMaternityLeaveReport(MaternityLeave oMaternityLeave, int payrollTypeId)
{
ReportProcessor reportProcessor = new ReportProcessor();
string RDLC = "MaternityLeaveAfter.rdlc";
//string rdlcName = "HRM.Report.RDLC.PreviousDayApprovedLeaveReportForMailSender.rdlc"; // build action of this rdlc has to be embedded resource
//string reportTitle = "Approved Leave Report of Sales : (" + leaveApprovedDate.ToString("dd MMM yyyy") + ")";
//DataSet tempDataSet = RefreshPreviousDayApprovedLeaveReportDataSetForMailSender(toEmail, leaveApprovedDate, leaveStatus);
HRM.Report.PayrollDataSet.dsEmpLeaveLedger.MaternityLeaveDataTable oMaternityLeaveDataTable = new HRM.Report.PayrollDataSet.dsEmpLeaveLedger.MaternityLeaveDataTable();
HRM.Report.PayrollDataSet.dsEmpLeaveLedger.MaternityStatusDetailDataTable oMaternityStatusDetailDataTable = new HRM.Report.PayrollDataSet.dsEmpLeaveLedger.MaternityStatusDetailDataTable();
try
{
int counter = 0;
MaternityLeave maternityLeave = oMaternityLeave;
DataTable dt = null;
MaternityLeaveService maternityLeaveService = new MaternityLeaveService();
if (maternityLeave != null)
{
maternityLeave.MaternityItemDetailColl = maternityLeaveService.GetMItemDetail(maternityLeave.ID);
maternityLeave.MaternityStatusDetailColl = maternityLeaveService.GetMStatusDetail(maternityLeave.ID);
List<MaternityLeave.MaternityItemDetail> MaternityItemDetailOut = new List<MaternityLeave.MaternityItemDetail>();
//RefreshGridAllowance(maternityLeave);
dt = maternityLeaveService.RefreshGridAllowanceMaternityLeave(maternityLeave, GlobalFunctions.LastDateOfMonth(maternityLeave.LeaveFromDate), out MaternityItemDetailOut);
Employee employee = new EmployeeService().Get(maternityLeave.EmployeeID);
employee.Designation = new DesignationService().Get((int)employee.DesignationID);
employee.Department = new DepartmentService().Get((int)employee.DepartmentID);
//RefreshGridAllowance(maternityLeave);
string serviceLength = Global.DateFunctions.DateDiff(employee.JoiningDate, (DateTime)maternityLeave.DateOfApproval);
string status = string.Empty;
double paidAmount = 0;
int totalPaidDays = 0;
DateTime? lastPaidDate = null;
bool IsSameDate = false;
DateTime dtDateCheck = new DateTime();
if (maternityLeave.MaternityStatusDetailColl.Count == 2)
dtDateCheck = (DateTime)maternityLeave.MaternityStatusDetailColl[0].PaymentDate;
foreach (MaternityLeave.MaternityStatusDetail statusDetail in maternityLeave.MaternityStatusDetailColl)
{
if (dtDateCheck == statusDetail.PaymentDate)
{
IsSameDate = true;
}
else
{
dtDateCheck = (DateTime)statusDetail.PaymentDate;
IsSameDate = false;
}
}
foreach (MaternityLeave.MaternityStatusDetail statusDetail in maternityLeave.MaternityStatusDetailColl)
{
if (maternityLeave.NetAmount == maternityLeave.PaidAmount)
status = Enum.GetName(typeof(EnumMaternityLeaveStatus), EnumMaternityLeaveStatus.FullPayment);
else
status = Enum.GetName(typeof(EnumMaternityLeaveStatus), statusDetail.Status);
lastPaidDate = (DateTime)statusDetail.PaymentDate;
totalPaidDays += statusDetail.PaymentDays;
paidAmount += statusDetail.Amount;
if (IsSameDate)
{
totalPaidDays = statusDetail.PaymentDays * 2;
paidAmount = statusDetail.Amount * 2;
status = Enum.GetName(typeof(EnumMaternityLeaveStatus), EnumMaternityLeaveStatus.FullPayment);
string strStatus2 = "Net Amount payable to the Employee";
//oMaternityStatusDetailDataTable.Rows.Add(statusDetail.Status, statusDetail.PaymentDate.ToString("dd MMM yyyy"), statusDetail.PaymentDays, statusDetail.Amount.ToString("N2"));
oMaternityStatusDetailDataTable.Rows.Add(strStatus2, statusDetail.PaymentDate.Value.ToString("dd MMM yyyy") , statusDetail.PaymentDays, (statusDetail.Amount * 2).ToString("N2"));
break;
}
else
{
if (maternityLeave.MaternityStatusDetailColl.Count == 1)
{
counter++;
string strStatus = "";
if (maternityLeave.NetAmount == maternityLeave.PaidAmount)
strStatus = "Less: Already paid as on " + statusDetail.PaymentDate.Value.ToString("dd MMM yyyy");
else
strStatus = "Net Maternity Benefit(50%) Payable to The Employee";
//oMaternityStatusDetailDataTable.Rows.Add(statusDetail.Status, statusDetail.PaymentDate.ToString("dd MMM yyyy"), statusDetail.PaymentDays, statusDetail.Amount.ToString("N2"));
oMaternityStatusDetailDataTable.Rows.Add(strStatus, statusDetail.PaymentDate.Value.ToString("dd MMM yyyy"), statusDetail.PaymentDays, statusDetail.Amount.ToString("N2"));
}
else if (maternityLeave.MaternityStatusDetailColl.Count == 2)
{
if (counter == 0)
{
string strStatus1 = "Less: Already paid as on " + statusDetail.PaymentDate.Value.ToString("dd MMM yyyy");
//oMaternityStatusDetailDataTable.Rows.Add(statusDetail.Status, statusDetail.PaymentDate.ToString("dd MMM yyyy"), statusDetail.PaymentDays, statusDetail.Amount.ToString("N2"));
oMaternityStatusDetailDataTable.Rows.Add(strStatus1, statusDetail.PaymentDate.Value.ToString("dd MMM yyyy"), statusDetail.PaymentDays, statusDetail.Amount.ToString("N2"));
}
else if (counter == 1)
{
string strStatus2 = "Net Amount payable to the Employee";
//oMaternityStatusDetailDataTable.Rows.Add(statusDetail.Status, statusDetail.PaymentDate.ToString("dd MMM yyyy"), statusDetail.PaymentDays, statusDetail.Amount.ToString("N2"));
oMaternityStatusDetailDataTable.Rows.Add(strStatus2, statusDetail.PaymentDate.Value.ToString("dd MMM yyyy"), statusDetail.PaymentDays, statusDetail.Amount.ToString("N2"));
}
counter++;
}
}
}
string Before3Month = null, Before2Month = null, Before1Month = null;
for (int threeMonth = 3; threeMonth >= 1; threeMonth--)
{
DateTime month = GlobalFunctions.LastDateOfMonth(maternityLeave.LeaveFromDate).AddMonths(-1 * threeMonth);
switch (threeMonth)
{
case 3:
Before3Month = month.ToString("MMM yyyy");
break;
case 2:
Before2Month = month.ToString("MMM yyyy");
break;
case 1:
Before1Month = month.ToString("MMM yyyy");
break;
default:
break;
}
}
oMaternityLeaveDataTable.Rows.Add(employee.Name, employee.EmployeeNo,
employee.Designation.Name, employee.Department.Name,
"N/A", employee.JoiningDate.ToString("dd MMM yyyy"),
serviceLength, maternityLeave.ApproveDays, maternityLeave.DateOfApproval.Value.ToString("dd MMM yyyy"),
totalPaidDays, dt.Columns[0].ColumnName,
Before3Month,
Before2Month,
Before1Month,
dt.Columns[4].ColumnName,
maternityLeave.DailyAvgEarning.ToString("N2"), status, maternityLeave.NetAmount.ToString("N2"),
maternityLeave.LeaveToDate.ToString("dd MMM yyyy"),
maternityLeave.LeaveFromDate.ToString("dd MMM yyyy"), lastPaidDate != null ? lastPaidDate.Value.ToString("dd MMM yyyy") : "", totalPaidDays, paidAmount.ToString("N2"),
maternityLeave.TaxAmount.ToString("N2"), maternityLeave.MaternityBenifit.ToString("N2"));
foreach (DataRow row in dt.Rows)
{
oMaternityLeaveDataTable.Rows.Add(employee.Name, employee.EmployeeNo,
employee.Designation.Name, employee.Department.Name, "N/A", employee.JoiningDate.ToString("dd MMM yyyy"),
serviceLength, maternityLeave.ApproveDays, maternityLeave.DateOfApproval.Value.ToString("dd MMM yyyy"),
totalPaidDays, row["Particulars"],
Convert.ToInt32(row["Before3Month"]).ToString("N2"),
Convert.ToInt32(row["Before2Month"]).ToString("N2"),
Convert.ToInt32(row["Before1Month"]).ToString("N2"),
Convert.ToInt32(row["Total"]).ToString("N2"),
maternityLeave.DailyAvgEarning.ToString("N2"), status, maternityLeave.NetAmount.ToString("N2"),
maternityLeave.LeaveToDate.ToString("dd MMM yyyy"),
maternityLeave.LeaveFromDate.ToString("dd MMM yyyy"), lastPaidDate.Value.ToString("dd MMM yyyy"), totalPaidDays,
paidAmount.ToString("N2"), maternityLeave.TaxAmount.ToString("N2"), maternityLeave.MaternityBenifit.ToString("N2"));
}
}
//else
//{
// //MessageBox.Show("Not available data for this search.", "Data Not Found", MessageBoxButtons.OK, MessageBoxIcon.Information);
// return ;
//}
//Payroll.Report.fReportViewer fViewer = new Payroll.Report.fReportViewer();
//fViewer.ShowDlg("Payroll.Report.MaternityLeave.RDLC.MaternityLeave.rdlc", "dsEmpLeaveLedger_MaternityLeave", oMaternityLeaveDataTable, "dsEmpLeaveLedger_MaternityStatusDetail", oMaternityStatusDetailDataTable);
//if (counter == 1)
//{
// fViewer.ShowDlg("Payroll.Report.MaternityLeave.RDLC.MaternityLeaveBefore.rdlc", "dsEmpLeaveLedger_MaternityLeave", oMaternityLeaveDataTable, "dsEmpLeaveLedger_MaternityStatusDetail", oMaternityStatusDetailDataTable);
//}
//else if (counter == 2)
//{
//fViewer.ShowDlg("Payroll.Report.MaternityLeave.RDLC.MaternityLeaveAfter.rdlc", "dsEmpLeaveLedger_MaternityLeave", oMaternityLeaveDataTable, "dsEmpLeaveLedger_MaternityStatusDetail", oMaternityStatusDetailDataTable);
//}
}
catch (Exception e)
{
if (e.InnerException == null)
{
throw new Exception(e.Message);
}
else
{
throw new Exception(e.Message, e.InnerException);
}
}
DataSet dSet = new DataSet();
oMaternityLeaveDataTable.TableName = "dsEmpLeaveLedger_MaternityLeave";
oMaternityStatusDetailDataTable.TableName = "dsEmpLeaveLedger_MaternityStatusDetail";
dSet.Tables.Add(oMaternityLeaveDataTable);
dSet.Tables.Add(oMaternityStatusDetailDataTable);
return reportProcessor.CommonReportViewForReports(null, dSet, null, RDLC, null, true, payrollTypeId, "PDF");
}
}
}