EchoTex_Payroll/HRM.Report/Class/rptEmpMaternityReport.cs

788 lines
42 KiB
C#
Raw Permalink Normal View History

2024-10-14 10:01:49 +06:00
using HRM.BO;
using HRM.DA.Fund;
using HRM.DA;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using iTextSharp.text.pdf.codec;
using Microsoft.Reporting.NETCore;
namespace HRM.Report
{
public class rptEmpMaternityReport
{
public byte[] getEmployeeMaternityLeaveReport(int empId, string EmpShift, int payrollTypeId)
{
DataRow dRow = null;
DataSet loanApplicationData = null;
DataSet resultDataSet = new DataSet();
HREmployee hrEmp = null;
DateTime dtBirthDate = DateTime.MinValue;
string birthCertificate = string.Empty;
DateTime dTimeTemp = DateTime.MinValue;
DateTime dTimeTemp2 = DateTime.MinValue;
DateTime dTimeTemp3 = DateTime.MinValue;
DateTime dFirstDate = DateTime.MinValue;
DateTime dLastDate = DateTime.MinValue;
List<Leave> _oLeaves = new LeaveService().Get();
DataTable dTable = new EmployeeService().GetMaternityLeaveEmployeeBasicInfo(empId);
dTable.Columns.Add("AfterLeaveJoinDate", typeof(string));
dTable.Columns.Add("Department", typeof(string));
dTable.Columns.Add("AccountNo", typeof(string));
dTable.Columns.Add("Male", typeof(string));
dTable.Columns.Add("Female", typeof(string));
dTable.Columns.Add("CL", typeof(string));
dTable.Columns.Add("SL", typeof(string));
dTable.Columns.Add("EL", typeof(string));
string sEmpID = empId.ToString();
DataTable dTblEmps = new EmployeeService().GetAllEmpBasicInfo(sEmpID).Tables[0];
//_rImageManager = new RemoteImageManager();
string empImage = null;//_rImageManager.GetImage(oemp.PhotoPath);
List<SalaryMonthly> oSalaryMonthlys = new List<SalaryMonthly>();
SalaryMonthly oSalaryMonthly = null;
List<AllowanceDeduction> oAllDeducts = new AllowanceDeductionService().Get(EnumStatus.Regardless);
double tiffinBill = 0;
double lunchBill = 0;
int presentDays = 0;
int totalPresentDays = 0;
int leaveDays = 0;
int abscentDays = 0;
double netPay = 0;
double halfPayment = 0;
double pfAmount = 0;
double subTotal = 0;
double basicEarned, houserentEarned, conveyanceEarned, medicalEarned, foodEarned, grossEarned, pf = 0, deductBasic, deductSalaryAdvance, deductPF, conductBonusDeduct, grossDeduct;
List<TermParameter> oAllTermParameters = new TermParameterService().Get(true, payrollTypeId);
bool isEchoTex = new SystemConfigarationService().GetconfigBooleanValue(EnumConfigurationType.Logic, "attendence", "echotexprocess");
List<DailyAttnProcess> dAttnProcessess = new List<DailyAttnProcess>();
foreach (DataRow item in dTable.Rows)
{
string[] strArrs = item["LeavePeriodFrom"].ToString().Split('/', '-', ' ');
dTimeTemp = Convert.ToDateTime(item["LeavePeriodFrom"].ToString()); //new DateTime(Convert.ToInt32(strArrs[2]), Convert.ToInt32(strArrs[0]), Convert.ToInt32(strArrs[1]));
string[] strArrs2 = item["LeavePeriodTo"].ToString().Split('/', '-', ' ');
dTimeTemp2 = Convert.ToDateTime(item["LeavePeriodTo"].ToString()); //new DateTime(Convert.ToInt32(strArrs2[2]), Convert.ToInt32(strArrs2[0]), Convert.ToInt32(strArrs2[1]));
string[] strArrs3 = item["AfterLeaveNextDate"].ToString().Split('/', '-', ' ');
dTimeTemp3 = Convert.ToDateTime(item["AfterLeaveNextDate"].ToString()); //new DateTime(Convert.ToInt32(strArrs3[2]), Convert.ToInt32(strArrs3[0]), Convert.ToInt32(strArrs3[1]));
HolidayCalendar oHoliCal = new HolidayCalendarService().GetByDate(dTimeTemp3);
while (oHoliCal != null)
{
dTimeTemp3 = dTimeTemp3.AddDays(1);
oHoliCal = new HolidayCalendarService().GetByDate(dTimeTemp3);
}
item["AfterLeaveJoinDate"] = dTimeTemp3.ToString("dd MMM yyyy");
Employee oemp = new EmployeeService().Get(empId);
DataTable dep = null;
if (isEchoTex)
dep = new EmployeeService().GetDepartmentName(empId, true);
else
dep = new EmployeeService().GetDepartmentName(empId, false);
item["Department"] = (dep != null && dep.Rows.Count > 0) ? (dep.Rows[0]["Department"] != DBNull.Value ? dep.Rows[0]["Department"].ToString() : string.Empty) : string.Empty;
item["AccountNo"] = oemp.AccountNo != null ? oemp.AccountNo : string.Empty;
int male = 0;
int female = 0;
hrEmp = new HREmployeeService().Get(empId);
if (hrEmp != null)
{
if (hrEmp.ChildrenList != null && hrEmp.ChildrenList.Count > 0)
{
foreach (EmpChildren child in hrEmp.ChildrenList)
{
if (child.Gender == EnumGender.Male)
male++;
else if (child.Gender == EnumGender.Female)
female++;
dtBirthDate = child.BirthDate;
// birthCertificate = child.BirthCertificateNo;
}
}
}
item["Male"] = male.ToString();
item["Female"] = female.ToString();
}
DataSet dSet = new DataSet();
dTable.TableName = "dsEmpLeaveLedger_MLPayment";
dSet.Tables.Add(dTable.Copy());
if (dTimeTemp != DateTime.MinValue)
{
dTimeTemp = dTimeTemp.AddMonths(-3).LastDateOfMonth();
for (int i = 0; i < 3; i++)
{
oSalaryMonthly = new SalaryMonthlyService().Get(empId, dTimeTemp);
if (oSalaryMonthly != null)
{
oSalaryMonthlys.Add(oSalaryMonthly);
dTimeTemp = dTimeTemp.AddMonths(1).LastDateOfMonth();
}
}
}
dTable = new PayrollDataSet.dsEmpLeaveLedger.MLBenefitDataTable();
foreach (SalaryMonthly itemMonthly in oSalaryMonthlys)
{
SalaryMonthlyService itemMonthlyService = new SalaryMonthlyService();
grossEarned = basicEarned = houserentEarned = conveyanceEarned = medicalEarned = foodEarned = pf = deductBasic = deductSalaryAdvance = deductPF = conductBonusDeduct = grossDeduct = 0;
DataRow drEmp = dTblEmps.AsEnumerable().FirstOrDefault(x => itemMonthly.EmployeeID == x.Field<int>("EmployeeID"));
TermParameter oEmpTermParameter = null;
if (drEmp != null && drEmp["GradeID"] != DBNull.Value && !string.IsNullOrWhiteSpace(drEmp["GradeID"].ToString()))
{
oEmpTermParameter = oAllTermParameters.FirstOrDefault(x => x.SetupDetails.Any(y => y.TranID == drEmp.Field<int>("GradeID")));
}
dLastDate = itemMonthly.SalaryMonth.LastDateOfMonth();
dFirstDate = itemMonthly.SalaryMonth.FirstDateOfMonth();
dAttnProcessess = new DailyAttnProcessService().GetNew(itemMonthly.EmployeeID, dFirstDate, dLastDate);
presentDays = 0;
leaveDays = 0;
abscentDays = 0;
double cl = 0;
double sl = 0;
double el = 0;
if (!(dAttnProcessess == null || dAttnProcessess.Count <= 0))
{
foreach (DailyAttnProcess dAttnProcess in dAttnProcessess)
{
switch (dAttnProcess.AttenType)
{
case EnumAttendanceType.Present:
case EnumAttendanceType.Delay:
case EnumAttendanceType.Early:
case EnumAttendanceType.Late:
presentDays++;
break;
case EnumAttendanceType.Leave:
Leave oLeave = _oLeaves.FirstOrDefault(x => x.ID == dAttnProcess.ReferenceID);
if (oLeave != null && oLeave.Code.Trim().ToLower() == "cl")
{
cl++;
}
else if (oLeave != null && oLeave.Code.Trim().ToLower() == "sl")
{
sl++;
}
else if (oLeave != null && oLeave.Code.Trim().ToLower() == "el")
{
el++;
}
leaveDays++;
break;
case EnumAttendanceType.Absent:
abscentDays++;
break;
default:
break;
}
}
}
List<HolidayCalendar> oHolidayCalender = new HolidayCalendarService().GetbyDateRange(dFirstDate, dLastDate);
int monthHoliday = new HolidayCalendarService().GetTotalMonthlyHolidays(dFirstDate, dLastDate);
DataRow dr = dTable.NewRow();
dr["Month"] = itemMonthly.SalaryMonth.ToString("MMM yy");
dr["ActualWorkingDays"] = presentDays.ToString();
totalPresentDays = totalPresentDays + presentDays;
dr["LeaveDays"] = leaveDays.ToString();
dr["AbscentDays"] = abscentDays.ToString();
dr["CL"] = cl.ToString();
dr["SL"] = sl.ToString();
dr["EL"] = el.ToString();
dr["TotalWorkingDays"] = dFirstDate.TotalDaysInMonth() - monthHoliday;
if (isEchoTex)
{
#region Gross Payment
basicEarned = itemMonthlyService.GetAmount(EnumSalaryGroup.Gross, EnumSalaryItemCode.Basic_Salary, itemMonthly)
+ itemMonthlyService.GetAmount(EnumSalaryGroup.Arrear, EnumSalaryItemCode.Basic_Salary, itemMonthly);
// House rent code: 008
AllowanceDeduction oAllDeduct = oAllDeducts.FirstOrDefault(x => x.AllowOrDeductType == EnumAllowOrDeduct.Allowance && x.Code.Trim() == "008");
if (oAllDeduct != null)
{
houserentEarned = itemMonthlyService.GetAmount(EnumSalaryGroup.Gross, EnumSalaryItemCode.Allowance, itemMonthly, oAllDeduct.ID)
+ itemMonthlyService.GetAmount(EnumSalaryGroup.Arrear, EnumSalaryItemCode.Allowance, itemMonthly, oAllDeduct.ID);
}
else
{
houserentEarned = 0;
}
// medical code: 011
oAllDeduct = oAllDeducts.FirstOrDefault(x => x.AllowOrDeductType == EnumAllowOrDeduct.Allowance && x.Code.Trim() == "011");
if (oAllDeduct != null)
{
medicalEarned = itemMonthlyService.GetAmount(EnumSalaryGroup.Gross, EnumSalaryItemCode.Allowance, itemMonthly, oAllDeduct.ID)
+ itemMonthlyService.GetAmount(EnumSalaryGroup.Arrear, EnumSalaryItemCode.Allowance, itemMonthly, oAllDeduct.ID);
}
else
{
medicalEarned = 0;
}
// Conveyance code: 010
oAllDeduct = oAllDeducts.FirstOrDefault(x => x.AllowOrDeductType == EnumAllowOrDeduct.Allowance && x.Code.Trim() == "010");
if (oAllDeduct != null)
{
conveyanceEarned = itemMonthlyService.GetAmount(EnumSalaryGroup.Gross, EnumSalaryItemCode.Allowance, itemMonthly, oAllDeduct.ID)
+ itemMonthlyService.GetAmount(EnumSalaryGroup.Arrear, EnumSalaryItemCode.Allowance, itemMonthly, oAllDeduct.ID);
}
else
{
conveyanceEarned = 0;
}
// FoodAllowance code: 006
oAllDeduct = oAllDeducts.FirstOrDefault(x => x.AllowOrDeductType == EnumAllowOrDeduct.Allowance && x.Code.Trim() == "006");
if (oAllDeduct != null)
{
foodEarned = itemMonthlyService.GetAmount(EnumSalaryGroup.Gross, EnumSalaryItemCode.Allowance, itemMonthly, oAllDeduct.ID)
+ itemMonthlyService.GetAmount(EnumSalaryGroup.Arrear, EnumSalaryItemCode.Allowance, itemMonthly, oAllDeduct.ID);
}
else
{
foodEarned = 0;
}
grossEarned = basicEarned +
houserentEarned +
medicalEarned +
conveyanceEarned +
foodEarned;
#endregion
#region Deductions
pf = itemMonthlyService.GetAmount(EnumSalaryGroup.Deductions, EnumSalaryItemCode.PF_Contribution, itemMonthly);
deductBasic = itemMonthlyService.GetAmount(EnumSalaryGroup.UnauthLeave, EnumSalaryItemCode.Basic_Salary, itemMonthly);
deductSalaryAdvance = itemMonthlyService.GetAmount(EnumSalaryGroup.Deductions, EnumSalaryItemCode.Loan_Monthly_Installment, itemMonthly);
deductPF = Math.Round(Convert.ToDouble(pf), 0);
// Deduct Conduct Bonus code: 005
oAllDeduct = oAllDeducts.FirstOrDefault(x => x.AllowOrDeductType == EnumAllowOrDeduct.Deduction && x.Code.Trim() == "005");
if (oAllDeduct != null)
{
conductBonusDeduct = itemMonthlyService.GetAmount(EnumSalaryGroup.Deductions, EnumSalaryItemCode.Deduction, itemMonthly, oAllDeduct.ID)
+ itemMonthlyService.GetAmount(EnumSalaryGroup.Arrear, EnumSalaryItemCode.Deduction, itemMonthly, oAllDeduct.ID);
}
else
{
conductBonusDeduct = 0;
}
grossDeduct = deductBasic;// + deductSalaryAdvance + deductPF + conductBonusDeduct;
#endregion
dr["GrossWagesTaka"] = Math.Round(grossEarned - grossDeduct);
#region Overtime
//otHour = itemMonthly.GetAmount(EnumSalaryGroup.Miscellaneous, EnumSalaryItemCode.Over_Time_Hours);
//double otPayment = itemMonthly.GetAmount(EnumSalaryGroup.Gross, EnumSalaryItemCode.Over_Time_Amount);
//otPayment = GlobalFunctions.Round(otPayment);
//if (Convert.ToDouble(otHour) > 0)
//{
// otRate = Math.Round(Convert.ToDouble(otPayment) / Convert.ToDouble(otHour), 2);
//}
//else
//{
// if (oEmpTermParameter != null)
// {
// //otRate = Math.Round(oEmpTermParameter.GetOTRate(oEmp.BasicSalary, _SalaryMonth.LastDateOfMonth()), 2);
// otRate = Math.Round(oEmpTermParameter.GetOTRate(Convert.ToDouble(drEmp["BasicSalary"].ToString()), _SalaryMonth.LastDateOfMonth()), 2);
// }
// else
// {
// otRate = 0.00;
// }
//}
#endregion
double otPayment = itemMonthlyService.GetAmount(EnumSalaryGroup.Gross, EnumSalaryItemCode.Over_Time_Amount, itemMonthly);
dr["TotalOTTaka"] = GlobalFunctions.Round(otPayment);
// Attendence Bonus code: 010
oAllDeduct = oAllDeducts.FirstOrDefault(x => x.Code.Trim() == "001");
if (oAllDeduct != null)
dr["AttnBonus"] = GlobalFunctions.Round(itemMonthlyService.GetAmount(EnumSalaryGroup.Gross, EnumSalaryItemCode.Allowance, itemMonthly, oAllDeduct.ID)
+ itemMonthlyService.GetAmount(EnumSalaryGroup.Arrear, EnumSalaryItemCode.Allowance, itemMonthly, oAllDeduct.ID));
else
dr["AttnBonus"] = 0;
// Conduct Bonus code: 011
oAllDeduct = oAllDeducts.FirstOrDefault(x => x.Code.Trim() == "002");
if (oAllDeduct != null)
dr["ConductBonus"] = GlobalFunctions.Round(itemMonthlyService.GetAmount(EnumSalaryGroup.Gross, EnumSalaryItemCode.Allowance, itemMonthly, oAllDeduct.ID)
+ itemMonthlyService.GetAmount(EnumSalaryGroup.Arrear, EnumSalaryItemCode.Allowance, itemMonthly, oAllDeduct.ID));
else
dr["ConductBonus"] = 0;
// Production Bonus code: 013
oAllDeduct = oAllDeducts.FirstOrDefault(x => x.Code.Trim() == "013");
if (oAllDeduct != null)
dr["ProBonus"] = GlobalFunctions.Round(itemMonthly.Details.Where(x => x.itemGroupCode == EnumSalaryGroup.Gross && x.ItemCode == EnumSalaryItemCode.Allowance && x.ItemID == oAllDeduct.ID).Sum(x => x.ChangedAmount)
+ itemMonthly.Details.Where(x => x.itemGroupCode == EnumSalaryGroup.Arrear && x.ItemCode == EnumSalaryItemCode.Allowance && x.ItemID == oAllDeduct.ID).Sum(x => x.ChangedAmount));
else
dr["ProBonus"] = 0;
// Sp. Food Allowance (Ramadan) Bonus code: 012
oAllDeduct = oAllDeducts.FirstOrDefault(x => x.Code.Trim() == "012");
if (oAllDeduct != null)
dr["SPFoodAllowance"] = GlobalFunctions.Round(itemMonthly.Details.Where(x => x.itemGroupCode == EnumSalaryGroup.Gross && x.ItemCode == EnumSalaryItemCode.Allowance && x.ItemID == oAllDeduct.ID).Sum(x => x.ChangedAmount)
+ itemMonthly.Details.Where(x => x.itemGroupCode == EnumSalaryGroup.Arrear && x.ItemCode == EnumSalaryItemCode.Allowance && x.ItemID == oAllDeduct.ID).Sum(x => x.ChangedAmount));
else
dr["SPFoodAllowance"] = 0;
// Lunch Bonus code: 015
oAllDeduct = oAllDeducts.FirstOrDefault(x => x.Code.Trim() == "015");
lunchBill = GlobalFunctions.Round(itemMonthly.Details.Where(x => x.itemGroupCode == EnumSalaryGroup.Gross && x.ItemCode == EnumSalaryItemCode.Allowance && x.ItemID == oAllDeduct.ID).Sum(x => x.ChangedAmount)
+ itemMonthly.Details.Where(x => x.itemGroupCode == EnumSalaryGroup.Arrear && x.ItemCode == EnumSalaryItemCode.Allowance && x.ItemID == oAllDeduct.ID).Sum(x => x.ChangedAmount));
// Tiffin Bonus code: 016
oAllDeduct = oAllDeducts.FirstOrDefault(x => x.Code.Trim() == "016");
tiffinBill = GlobalFunctions.Round(itemMonthly.Details.Where(x => x.itemGroupCode == EnumSalaryGroup.Gross && x.ItemCode == EnumSalaryItemCode.Allowance && x.ItemID == oAllDeduct.ID).Sum(x => x.ChangedAmount)
+ itemMonthly.Details.Where(x => x.itemGroupCode == EnumSalaryGroup.Arrear && x.ItemCode == EnumSalaryItemCode.Allowance && x.ItemID == oAllDeduct.ID).Sum(x => x.ChangedAmount));
dr["TiffinLunchBill"] = lunchBill;
dr["Tiffin"] = tiffinBill;
dr["EidBonus"] = itemMonthlyService.GetAmount(EnumSalaryGroup.Gross, EnumSalaryItemCode.Bonus, itemMonthly);
dr["Total"] = Math.Round(Convert.ToDouble(dr["GrossWagesTaka"]) +
Convert.ToDouble(dr["TotalOTTaka"]) +
Convert.ToDouble(dr["AttnBonus"]) +
Convert.ToDouble(dr["ConductBonus"]) +
Convert.ToDouble(dr["ProBonus"]) +
Convert.ToDouble(dr["SPFoodAllowance"]) +
Convert.ToDouble(dr["TiffinLunchBill"]) +
Convert.ToDouble(dr["Tiffin"]) +
Convert.ToDouble(dr["EidBonus"]));
dr["NetPayment"] = dr["Total"];
netPay = netPay + Convert.ToDouble(dr["NetPayment"]);
dr["PF"] = pf * 2;
dTable.Rows.Add(dr);
}
else
{
#region Dupliicate
//grossEarned = basicEarned = houserentEarned = conveyanceEarned = medicalEarned = foodEarned = pf = deductBasic = deductSalaryAdvance = deductPF = conductBonusDeduct = grossDeduct = 0;
//DataRow drEmp = dTblEmps.AsEnumerable().FirstOrDefault(x => itemMonthly.EmployeeID == x.Field<int>("EmployeeID"));
//TermParameter oEmpTermParameter = null;
//if (drEmp != null && drEmp["GradeID"] != DBNull.Value && !string.IsNullOrWhiteSpace(drEmp["GradeID"].ToString()))
//{
// oEmpTermParameter = oAllTermParameters.FirstOrDefault(x => x.SetupDetails.Any(y => y.TranID == drEmp.Field<int>("GradeID")));
//}
//dLastDate = itemMonthly.SalaryMonth.LastDateOfMonth();
//dFirstDate = itemMonthly.SalaryMonth.FirstDateOfMonth();
//dAttnProcessess = new DailyAttnProcessService().GetNew(itemMonthly.EmployeeID, dFirstDate, dLastDate);
//presentDays = 0;
//leaveDays = 0;
//abscentDays = 0;
//double cl = 0;
//double sl = 0;
//double el = 0;
//if (!(dAttnProcessess == null || dAttnProcessess.Count <= 0))
//{
// foreach (DailyAttnProcess dAttnProcess in dAttnProcessess)
// {
// switch (dAttnProcess.AttenType)
// {
// case EnumAttendanceType.Present:
// case EnumAttendanceType.Delay:
// case EnumAttendanceType.Early:
// case EnumAttendanceType.Late:
// presentDays++;
// break;
// case EnumAttendanceType.Leave:
// Leave oLeave = _oLeaves.FirstOrDefault(x => x.ID == dAttnProcess.ReferenceID);
// if (oLeave != null && oLeave.Code.Trim().ToLower() == "cl")
// {
// cl++;
// }
// else if (oLeave != null && oLeave.Code.Trim().ToLower() == "sl")
// {
// sl++;
// }
// else if (oLeave != null && oLeave.Code.Trim().ToLower() == "el")
// {
// el++;
// }
// leaveDays++;
// break;
// case EnumAttendanceType.Absent:
// abscentDays++;
// break;
// default:
// break;
// }
// }
//}
//List<HolidayCalendar> oHolidayCalender = new HolidayCalendarService().GetbyDateRange(dFirstDate, dLastDate);
//int monthHoliday = new HolidayCalendarService().GetTotalMonthlyHolidays(dFirstDate, dLastDate);
//DataRow dr = dTable.NewRow();
//dr["Month"] = itemMonthly.SalaryMonth.ToString("MMM yy");
//dr["ActualWorkingDays"] = presentDays.ToString();
//totalPresentDays = totalPresentDays + presentDays;
//dr["LeaveDays"] = leaveDays.ToString();
//dr["AbscentDays"] = abscentDays.ToString();
//dr["CL"] = cl.ToString();
//dr["SL"] = sl.ToString();
//dr["EL"] = el.ToString();
//dr["TotalWorkingDays"] = dFirstDate.TotalDaysInMonth() - monthHoliday;
#endregion dupliicate
#region Gross Payment
basicEarned = itemMonthly.GetGrossAmount(EnumSalaryItemCode.Basic_Salary, itemMonthly.ID);
//basicEarned = itemMonthly.GetAmount(EnumSalaryGroup.Gross, EnumSalaryItemCode.Basic_Salary)
// + itemMonthly.GetAmount(EnumSalaryGroup.Arrear, EnumSalaryItemCode.Basic_Salary);
// House rent code: 008
AllowanceDeduction oAllDeduct = oAllDeducts.FirstOrDefault(x => x.AllowOrDeductType == EnumAllowOrDeduct.Allowance && x.Code.Trim() == "008");
if (oAllDeduct != null)
{
houserentEarned = itemMonthlyService.GetAmount(EnumSalaryGroup.Gross, EnumSalaryItemCode.Allowance, itemMonthly, oAllDeduct.ID)
+ itemMonthlyService.GetAmount(EnumSalaryGroup.Arrear, EnumSalaryItemCode.Allowance, itemMonthly, oAllDeduct.ID);
//itemMonthly.GetAmount(EnumSalaryGroup.Gross, EnumSalaryItemCode.Allowance, oAllDeduct.ID)
// + itemMonthly.GetAmount(EnumSalaryGroup.Arrear, EnumSalaryItemCode.Allowance, oAllDeduct.ID);
}
else
{
houserentEarned = 0;
}
// medical code: 011
oAllDeduct = oAllDeducts.FirstOrDefault(x => x.AllowOrDeductType == EnumAllowOrDeduct.Allowance && x.Code.Trim() == "011");
if (oAllDeduct != null)
{
medicalEarned = itemMonthlyService.GetAmount(EnumSalaryGroup.Gross, EnumSalaryItemCode.Allowance, itemMonthly, oAllDeduct.ID)
+ itemMonthlyService.GetAmount(EnumSalaryGroup.Arrear, EnumSalaryItemCode.Allowance, itemMonthly, oAllDeduct.ID);
//itemMonthly.GetAmount(EnumSalaryGroup.Gross, EnumSalaryItemCode.Allowance, oAllDeduct.ID)
//+ itemMonthly.GetAmount(EnumSalaryGroup.Arrear, EnumSalaryItemCode.Allowance, oAllDeduct.ID);
}
else
{
medicalEarned = 0;
}
// Conveyance code: 010
oAllDeduct = oAllDeducts.FirstOrDefault(x => x.AllowOrDeductType == EnumAllowOrDeduct.Allowance && x.Code.Trim() == "010");
if (oAllDeduct != null)
{
conveyanceEarned = itemMonthlyService.GetAmount(EnumSalaryGroup.Gross, EnumSalaryItemCode.Allowance, itemMonthly, oAllDeduct.ID)
+ itemMonthlyService.GetAmount(EnumSalaryGroup.Arrear, EnumSalaryItemCode.Allowance, itemMonthly, oAllDeduct.ID);
//itemMonthly.GetAmount(EnumSalaryGroup.Gross, EnumSalaryItemCode.Allowance, oAllDeduct.ID)
// + itemMonthly.GetAmount(EnumSalaryGroup.Arrear, EnumSalaryItemCode.Allowance, oAllDeduct.ID);
}
else
{
conveyanceEarned = 0;
}
// FoodAllowance code: 006
oAllDeduct = oAllDeducts.FirstOrDefault(x => x.AllowOrDeductType == EnumAllowOrDeduct.Allowance && x.Code.Trim() == "006");
if (oAllDeduct != null)
{
foodEarned = itemMonthlyService.GetAmount(EnumSalaryGroup.Gross, EnumSalaryItemCode.Allowance, itemMonthly, oAllDeduct.ID)
+ itemMonthlyService.GetAmount(EnumSalaryGroup.Arrear, EnumSalaryItemCode.Allowance, itemMonthly, oAllDeduct.ID);
// itemMonthly.GetAmount(EnumSalaryGroup.Gross, EnumSalaryItemCode.Allowance, oAllDeduct.ID)
// + itemMonthly.GetAmount(EnumSalaryGroup.Arrear, EnumSalaryItemCode.Allowance, oAllDeduct.ID);
}
else
{
foodEarned = 0;
}
grossEarned = basicEarned +
houserentEarned +
medicalEarned +
conveyanceEarned +
foodEarned;
#endregion
#region Deductions
pf = itemMonthlyService.GetAmount(EnumSalaryGroup.Deductions, EnumSalaryItemCode.PF_Contribution, itemMonthly);
deductBasic = itemMonthlyService.GetAmount(EnumSalaryGroup.UnauthLeave, EnumSalaryItemCode.Basic_Salary, itemMonthly);
deductSalaryAdvance = itemMonthlyService.GetAmount(EnumSalaryGroup.Deductions, EnumSalaryItemCode.Loan_Monthly_Installment, itemMonthly);
deductPF = Math.Round(Convert.ToDouble(pf), 0);
// Deduct Conduct Bonus code: 005
oAllDeduct = oAllDeducts.FirstOrDefault(x => x.AllowOrDeductType == EnumAllowOrDeduct.Deduction && x.Code.Trim() == "005");
if (oAllDeduct != null)
{
conductBonusDeduct = itemMonthlyService.GetAmount(EnumSalaryGroup.Deductions, EnumSalaryItemCode.Deduction, itemMonthly, oAllDeduct.ID)
+ itemMonthlyService.GetAmount(EnumSalaryGroup.Arrear, EnumSalaryItemCode.Deduction, itemMonthly, oAllDeduct.ID);
//itemMonthly.GetAmount(EnumSalaryGroup.Deductions, EnumSalaryItemCode.Deduction, oAllDeduct.ID)
// + itemMonthly.GetAmount(EnumSalaryGroup.Arrear, EnumSalaryItemCode.Deduction, oAllDeduct.ID);
}
else
{
conductBonusDeduct = 0;
}
grossDeduct = deductBasic;// + deductSalaryAdvance + deductPF + conductBonusDeduct;
#endregion
dr["GrossWagesTaka"] = Math.Round(grossEarned - grossDeduct);
double otPayment = itemMonthlyService.GetAmount(EnumSalaryGroup.Gross, EnumSalaryItemCode.Over_Time_Amount, itemMonthly);
dr["TotalOTTaka"] = GlobalFunctions.Round(otPayment);
// Attendence Bonus code: 010
oAllDeduct = oAllDeducts.FirstOrDefault(x => x.Code.Trim() == "001");
if (oAllDeduct != null)
dr["AttnBonus"] = GlobalFunctions.Round(itemMonthlyService.GetAmount(EnumSalaryGroup.Gross, EnumSalaryItemCode.Allowance, itemMonthly, oAllDeduct.ID)
+ itemMonthlyService.GetAmount(EnumSalaryGroup.Arrear, EnumSalaryItemCode.Allowance, itemMonthly, oAllDeduct.ID));
else
dr["AttnBonus"] = 0;
// Conduct Bonus code: 011
oAllDeduct = oAllDeducts.FirstOrDefault(x => x.Code.Trim() == "002");
if (oAllDeduct != null)
dr["ConductBonus"] = GlobalFunctions.Round(itemMonthlyService.GetAmount(EnumSalaryGroup.Gross, EnumSalaryItemCode.Allowance, itemMonthly, oAllDeduct.ID)
+ itemMonthlyService.GetAmount(EnumSalaryGroup.Arrear, EnumSalaryItemCode.Allowance, itemMonthly, oAllDeduct.ID));
else
dr["ConductBonus"] = 0;
// Production Bonus code: 013
oAllDeduct = oAllDeducts.FirstOrDefault(x => x.Code.Trim() == "013");
if (oAllDeduct != null)
dr["ProBonus"] = GlobalFunctions.Round(itemMonthly.Details.Where(x => x.itemGroupCode == EnumSalaryGroup.Gross && x.ItemCode == EnumSalaryItemCode.Allowance && x.ItemID == oAllDeduct.ID).Sum(x => x.ChangedAmount)
+ itemMonthly.Details.Where(x => x.itemGroupCode == EnumSalaryGroup.Arrear && x.ItemCode == EnumSalaryItemCode.Allowance && x.ItemID == oAllDeduct.ID).Sum(x => x.ChangedAmount));
else
dr["ProBonus"] = 0;
// Sp. Food Allowance (Ramadan) Bonus code: 012
oAllDeduct = oAllDeducts.FirstOrDefault(x => x.Code.Trim() == "012");
if (oAllDeduct != null)
dr["SPFoodAllowance"] = GlobalFunctions.Round(itemMonthly.Details.Where(x => x.itemGroupCode == EnumSalaryGroup.Gross && x.ItemCode == EnumSalaryItemCode.Allowance && x.ItemID == oAllDeduct.ID).Sum(x => x.ChangedAmount)
+ itemMonthly.Details.Where(x => x.itemGroupCode == EnumSalaryGroup.Arrear && x.ItemCode == EnumSalaryItemCode.Allowance && x.ItemID == oAllDeduct.ID).Sum(x => x.ChangedAmount));
else
dr["SPFoodAllowance"] = 0;
// Lunch Bonus code: 015
oAllDeduct = oAllDeducts.FirstOrDefault(x => x.Code.Trim() == "015");
if(oAllDeduct != null)
lunchBill = GlobalFunctions.Round(itemMonthly.Details.Where(x => x.itemGroupCode == EnumSalaryGroup.Gross && x.ItemCode == EnumSalaryItemCode.Allowance && x.ItemID == oAllDeduct.ID).Sum(x => x.ChangedAmount)
+ itemMonthly.Details.Where(x => x.itemGroupCode == EnumSalaryGroup.Arrear && x.ItemCode == EnumSalaryItemCode.Allowance && x.ItemID == oAllDeduct.ID).Sum(x => x.ChangedAmount));
// Tiffin Bonus code: 016
oAllDeduct = oAllDeducts.FirstOrDefault(x => x.Code.Trim() == "016");
if (oAllDeduct != null)
tiffinBill = GlobalFunctions.Round(itemMonthly.Details.Where(x => x.itemGroupCode == EnumSalaryGroup.Gross && x.ItemCode == EnumSalaryItemCode.Allowance && x.ItemID == oAllDeduct.ID).Sum(x => x.ChangedAmount)
+ itemMonthly.Details.Where(x => x.itemGroupCode == EnumSalaryGroup.Arrear && x.ItemCode == EnumSalaryItemCode.Allowance && x.ItemID == oAllDeduct.ID).Sum(x => x.ChangedAmount));
dr["TiffinLunchBill"] = lunchBill;
dr["Tiffin"] = tiffinBill;
dr["EidBonus"] = itemMonthlyService.GetAmount(EnumSalaryGroup.Gross, EnumSalaryItemCode.Bonus, itemMonthly);
dr["Total"] = Math.Round(Convert.ToDouble(dr["GrossWagesTaka"]) +
Convert.ToDouble(dr["TotalOTTaka"]) +
Convert.ToDouble(dr["AttnBonus"]) +
Convert.ToDouble(dr["ConductBonus"]) +
Convert.ToDouble(dr["ProBonus"]) +
Convert.ToDouble(dr["SPFoodAllowance"]) +
Convert.ToDouble(dr["TiffinLunchBill"]) +
Convert.ToDouble(dr["Tiffin"]) +
Convert.ToDouble(dr["EidBonus"]));
dr["NetPayment"] = dr["Total"];
netPay = netPay + Convert.ToDouble(dr["NetPayment"]);
dr["PF"] = pf * 2;
dTable.Rows.Add(dr);
}
}
dTable.TableName = "dsEmpLeaveLedger_MLBenefit";
dSet.Tables.Add(dTable.Copy());
//dTable.TableName = "dsEmpLeaveLedger_MLBenefit";
//dSet.Tables.Add(dTable.Copy());
halfPayment = ((netPay * 112) / totalPresentDays) / 2;
string amountInWords = NumWordsWrapper(Math.Round(halfPayment));
LeaveEntry le = new LeaveEntryService().GetMaternityLeave(empId, "ML");
List<ReportParameter> parameters = new List<ReportParameter>();
parameters.Add(new ReportParameter("EmpImage", empImage));
parameters.Add(new ReportParameter("AmountInWords", amountInWords));
parameters.Add(new ReportParameter("PFAmount", (pf * 2).ToString()));
parameters.Add(new ReportParameter("FromDate", le.ApprovedFromDate.ToString("dd MMM yyyy")));
//parameters.Add(new ReportParameter("ToDate", le.PaymentDate != null ? le.PaymentDate.ToString("dd MMM yyyy") : string.Empty));
parameters.Add(new ReportParameter("ToDate", DateTime.Now.ToString("dd MMM yyyy")));// Test
parameters.Add(new ReportParameter("DeliveryDate", le.ApprovedFromDate != null ? le.ApprovedFromDate.AddDays(56).ToString("dd MMM yyyy") : string.Empty));
parameters.Add(new ReportParameter("LastChildBirthDate", dtBirthDate != DateTime.MinValue ? dtBirthDate.ToString("dd MMM yyyy") : string.Empty));
parameters.Add(new ReportParameter("LastChildBirthCertificate", birthCertificate));
parameters.Add(new ReportParameter("PFMonth", le.ApprovedFromDate.ToString("MMMM,yyyy") + " - " + le.ApprovedFromDate.AddMonths(1).ToString("MMMM,yyyy")));
string RDLC = null;
if (EmpShift == "First Half")
{
RDLC = "MLFirstPayment.rdlc";
}
else
{
RDLC = "MLSecondPayment.rdlc";
}
ReportProcessor reportProcessor = new ReportProcessor();
return reportProcessor.CommonReportViewForReports(null, dSet, null, RDLC, parameters, true, payrollTypeId, "PDF");
//return reportProcessor.CommonReportView(null, RDLC, dSet, null, parameters, true, 1, "PDF");
//return null;
}
#region wrapper
public static String NumWordsWrapper(double value)
{
string words = "";
double intPart;
double decPart = 0;
if (value == 0)
return "zero";
try
{
string[] splitter = value.ToString().Split('.');
intPart = double.Parse(splitter[0]);
if (splitter.Length > 1)
{
decPart = double.Parse(splitter[1]);
}
}
catch
{
intPart = value;
}
words = NumWords(Convert.ToInt32(intPart));
if (decPart > 0)
{
if (words != "")
words += " and ";
int counter = decPart.ToString().Length;
switch (counter)
{
case 1: words += NumWords(Convert.ToInt32(decPart)) + ""; break;// tenths
case 2: words += NumWords(Convert.ToInt32(decPart)) + ""; break;// hundredths
case 3: words += NumWords(Convert.ToInt32(decPart)) + ""; break;// thousandths
case 4: words += NumWords(Convert.ToInt32(decPart)) + ""; break;// ten-thousandths
case 5: words += NumWords(Convert.ToInt32(decPart)) + ""; break;// hundred-thousandths
case 6: words += NumWords(Convert.ToInt32(decPart)) + ""; break;// millionths
case 7: words += NumWords(Convert.ToInt32(decPart)) + ""; break;// ten-millionths
}
}
return words + " Taka Only";
}
private static string NumWords(int Num)
{
string[] Below20 = { "", "One ", "Two ", "Three ", "Four ",
"Five ", "Six " , "Seven ", "Eight ", "Nine ", "Ten ", "Eleven ",
"Twelve " , "Thirteen ", "Fourteen ","Fifteen ",
"Sixteen " , "Seventeen ","Eighteen " , "Nineteen " };
string[] Below100 = { "", "", "Twenty ", "Thirty ",
"Forty ", "Fifty ", "Sixty ", "Seventy ", "Eighty ", "Ninety " };
string InWords = "";
if (Num >= 1 && Num < 20)
InWords += Below20[Num];
if (Num >= 20 && Num <= 99)
InWords += Below100[Num / 10] + Below20[Num % 10];
if (Num >= 100 && Num <= 999)
InWords += NumWords(Num / 100) + " Hundred " + NumWords(Num % 100);
if (Num >= 1000 && Num <= 99999)
InWords += NumWords(Num / 1000) + " Thousand " + NumWords(Num % 1000);
if (Num >= 100000 && Num <= 9999999)
InWords += NumWords(Num / 100000) + " Lac " + NumWords(Num % 100000);
if (Num >= 10000000)
InWords += NumWords(Num / 10000000) + " Crore " + NumWords(Num % 10000000);
return InWords;
}
#endregion
}
}