EchoTex_Payroll/HRM.DA/Service/Leave/MaternityLeaveService.cs

832 lines
45 KiB
C#
Raw Normal View History

2024-10-14 10:01:49 +06:00
using Ease.Core.DataAccess;
using Ease.Core.Model;
using Ease.Core.Utility;
using HRM.BO;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HRM.DA
{
public class MaternityLeaveService : ServiceTemplate, IMaternityLeaveService
{
#region Private and Protected functions
private void MapObject(MaternityLeave oMaternityLeave, DataReader oReader)
{
base.SetObjectID(oMaternityLeave, oReader.GetInt32("MaternityLeaveID").Value);
oMaternityLeave.EmployeeID = oReader.GetInt32("EmployeeID").Value;
oMaternityLeave.ApplicationDate = oReader.GetDateTime("ApplicationDate").Value;
oMaternityLeave.LeaveFromDate = oReader.GetDateTime("LeaveFromDate").Value;
oMaternityLeave.LeaveToDate = oReader.GetDateTime("LeaveToDate").Value;
oMaternityLeave.DateOfApproval = oReader.GetDateTime("DateOfApproval") == null ? null : oReader.GetDateTime("DateOfApproval").Value;
oMaternityLeave.ApproveDays = oReader.GetInt32("ApproveDays") == null ? 0 : oReader.GetInt32("ApproveDays").Value;
oMaternityLeave.CurrentStatus = oReader.GetInt32("CurrentStatus").Value;
oMaternityLeave.DailyAvgEarning = oReader.GetDouble("DailyAvgEarning").Value;
oMaternityLeave.MaternityBenifit = oReader.GetDouble("MaternityBenifit").Value;
oMaternityLeave.TaxAmount = oReader.GetDouble("TaxAmount").Value;
oMaternityLeave.NetAmount = oReader.GetDouble("NetAmount").Value;
oMaternityLeave.PaidAmount = oReader.GetDouble("PaidAmount") == null ? 0 : oReader.GetDouble("PaidAmount").Value;
oMaternityLeave.CreatedBy = oReader.GetInt32("CreatedBy").Value;
oMaternityLeave.CreatedDate = oReader.GetDateTime("CreatedDate").Value;
oMaternityLeave.ModifiedBy = oReader.GetInt32("ModifiedBy");
oMaternityLeave.ModifiedDate = oReader.GetDateTime("ModifiedDate");
this.SetObjectState(oMaternityLeave, Ease.Core.ObjectState.Saved);
}
private void MapMItemDetailObject(MaternityLeave.MaternityItemDetail oMaternityItemDetail, DataReader oReader)
{
base.SetObjectID(oMaternityItemDetail, oReader.GetInt32("MaternityItemDetailID").Value);
oMaternityItemDetail.MaternityLeaveID = oReader.GetInt32("MaternityLeaveID").Value;
oMaternityItemDetail.ItemType = (EnumMaternityItemDetailType)oReader.GetInt16("ItemType").Value;
oMaternityItemDetail.Amount = oReader.GetDouble("Amount").Value;
oMaternityItemDetail.Description = oReader.GetString("Description");
oMaternityItemDetail.MonthDate = oReader.GetDateTime("MonthDate").Value;
if (oReader.GetInt16("IncomeTaxItemType") != null)
{
oMaternityItemDetail.IncomeTaxItemType = (enumIncomeTaxItemType)oReader.GetInt16("IncomeTaxItemType").Value;
}
else
{
oMaternityItemDetail.IncomeTaxItemType = enumIncomeTaxItemType.None;
}
oMaternityItemDetail.SalaryComponentID = oReader.GetInt16("SalaryComponentID").Value; // oReader.GetInt16("SalaryComponentID") == null ? oReader.GetInt16("SalaryComponentID").Value : 0;
oMaternityItemDetail.CreatedBy = oReader.GetInt32("CreatedBy").Value;
oMaternityItemDetail.CreatedDate = oReader.GetDateTime("CreatedDate").Value;
oMaternityItemDetail.ModifiedBy = oReader.GetInt32("ModifiedBy");
oMaternityItemDetail.ModifiedDate = oReader.GetDateTime("ModifiedDate");
this.SetObjectState(oMaternityItemDetail, Ease.Core.ObjectState.Saved);
}
private void MapMStatusDetailObject(MaternityLeave.MaternityStatusDetail oMaternityStatusDetail, DataReader oReader)
{
base.SetObjectID(oMaternityStatusDetail, oReader.GetInt32("MaternityStatusDetailID").Value);
oMaternityStatusDetail.MaternityLeaveID = oReader.GetInt32("MaternityLeaveID").Value;
oMaternityStatusDetail.Status = (EnumMaternityLeaveStatus)oReader.GetInt32("Status").Value;
oMaternityStatusDetail.PaymentDate = oReader.GetDateTime("PaymentDate") == null ? null : oReader.GetDateTime("PaymentDate").Value;
oMaternityStatusDetail.Amount = oReader.GetDouble("Amount").Value;
oMaternityStatusDetail.PaymentDays = oReader.GetInt32("PaymentDays").Value;
oMaternityStatusDetail.CreatedBy = oReader.GetInt32("CreatedBy").Value;
oMaternityStatusDetail.CreatedDate = oReader.GetDateTime("CreatedDate").Value;
oMaternityStatusDetail.ModifiedBy = oReader.GetInt32("ModifiedBy");
oMaternityStatusDetail.ModifiedDate = oReader.GetDateTime("ModifiedDate");
this.SetObjectState(oMaternityStatusDetail, Ease.Core.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
MaternityLeave oMaternityLeave = new MaternityLeave();
MapObject(oMaternityLeave, oReader);
return oMaternityLeave as T;
}
protected MaternityLeave CreateObject(DataReader oReader)
{
MaternityLeave oMaternityLeave = new MaternityLeave();
MapObject(oMaternityLeave, oReader);
return oMaternityLeave;
}
protected MaternityLeave.MaternityItemDetail CreateMItemDetailObject(DataReader oReader)
{
MaternityLeave.MaternityItemDetail oMaternityItemDetail = new MaternityLeave.MaternityItemDetail();
MapMItemDetailObject(oMaternityItemDetail, oReader);
return oMaternityItemDetail;
}
protected MaternityLeave.MaternityStatusDetail CreateMStatusDetailObject(DataReader oReader)
{
MaternityLeave.MaternityStatusDetail oMaternityStatusDetail = new MaternityLeave.MaternityStatusDetail();
MapMStatusDetailObject(oMaternityStatusDetail, oReader);
return oMaternityStatusDetail;
}
#endregion Private and Protected functions
#region IMaternityLeaveService Members
#region Get methods
public List<MaternityLeave> Get()
{
List<MaternityLeave> oMaternityLeaveColl = new List<MaternityLeave>();
#region Cache Header
//oMaternityLeaveColl = _cache["Get"] as List<MaternityLeave>;
//if (oMaternityLeaveColl != null)
// return oMaternityLeaveColl;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(MaternityLeaveDA.Get(tc));
while (oreader.Read())
{
MaternityLeave oMaternityLeave = new MaternityLeave();
oMaternityLeave = this.CreateObject<MaternityLeave>(oreader);
oMaternityLeaveColl.Add(oMaternityLeave);
}
oreader.Close();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
#region Cache Footer
//_cache.Add(oMaternityLeaveColl, "Get");
#endregion
return oMaternityLeaveColl;
}
public List<MaternityLeave> Get(Employee oEmployee)
{
List<MaternityLeave> oMaternityLeaveColl = new List<MaternityLeave>();
#region Cache Header
//oMaternityLeaveColl = _cache["Get"] as List<MaternityLeave>;
//if (oMaternityLeaveColl != null)
// return oMaternityLeaveColl;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(MaternityLeaveDA.Get(tc, oEmployee));
while (oreader.Read())
{
MaternityLeave oMaternityLeave = new MaternityLeave();
oMaternityLeave = this.CreateObject<MaternityLeave>(oreader);
oMaternityLeaveColl.Add(oMaternityLeave);
}
oreader.Close();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
#region Cache Footer
//_cache.Add(oMaternityLeaveColl, "Get");
#endregion
return oMaternityLeaveColl;
}
public MaternityLeave Get(int id)
{
MaternityLeave oMaternityLeave = new MaternityLeave();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(MaternityLeaveDA.Get(tc, id));
if (oreader.Read())
{
oMaternityLeave = this.CreateObject<MaternityLeave>(oreader);
}
oreader.Close();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return oMaternityLeave;
}
public List<MaternityLeave.MaternityItemDetail> GetMItemDetail(int parentID)
{
List<MaternityLeave.MaternityItemDetail> oMaternityItemDetailColl = new List<MaternityLeave.MaternityItemDetail>();
#region Cache Header
//oMaternityItemDetailColl = _cache["GetMItemDetail"] as List<MaternityLeave.MaternityItemDetail>;
//if (oMaternityItemDetailColl != null)
// return oMaternityItemDetailColl;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(MaternityLeaveDA.GetMItemDetailByParent(tc, parentID));
while (oreader.Read())
{
MaternityLeave.MaternityItemDetail oMaternityItemDetail = new MaternityLeave.MaternityItemDetail();
oMaternityItemDetail = this.CreateMItemDetailObject(oreader);
oMaternityItemDetailColl.Add(oMaternityItemDetail);
}
oreader.Close();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
#region Cache Footer
//_cache.Add(oMaternityItemDetailColl, "GetMItemDetail");
#endregion
return oMaternityItemDetailColl;
}
public List<MaternityLeave.MaternityStatusDetail> GetMStatusDetail(int parentID)
{
List<MaternityLeave.MaternityStatusDetail> oMaternityStatusDetailColl = new List<MaternityLeave.MaternityStatusDetail>();
#region Cache Header
//oMaternityStatusDetailColl = _cache["GetMStatusDetail"] as List<MaternityLeave.MaternityStatusDetail>;
//if (oMaternityStatusDetailColl != null)
// return oMaternityStatusDetailColl;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(MaternityLeaveDA.GetMStatusDetailByParent(tc, parentID));
while (oreader.Read())
{
MaternityLeave.MaternityStatusDetail oMaternityStatusDetail = new MaternityLeave.MaternityStatusDetail();
oMaternityStatusDetail = this.CreateMStatusDetailObject(oreader);
oMaternityStatusDetailColl.Add(oMaternityStatusDetail);
}
oreader.Close();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
#region Cache Footer
//_cache.Add(oMaternityStatusDetailColl, "GetMStatusDetail");
#endregion
return oMaternityStatusDetailColl;
}
public int GetTotalMonthlyHolidays(int loactionNumber, DateTime firstDateOfMonth, DateTime lastDateOfMonth)
{
int totalMonthlyHolidays = 0;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
totalMonthlyHolidays = MaternityLeaveDA.GetTotalMonthlyHolidays(tc, loactionNumber, firstDateOfMonth, lastDateOfMonth);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return totalMonthlyHolidays;
}
#endregion Get methods
public void Save(MaternityLeave maternityLeave, User CurrentUser)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (maternityLeave.IsNew)
{
int id = tc.GenerateID("MaternityLeave", "MaternityLeaveID");
base.SetObjectID(maternityLeave, id);
maternityLeave.CreatedBy = CurrentUser.ID;
//maternityLeave.CreatedDate = GlobalFunctionDA.GetOperationDate(tc);
maternityLeave.CreatedDate = DateTime.Now;
MaternityLeaveDA.Save(tc, maternityLeave);
foreach (MaternityLeave.MaternityItemDetail item in maternityLeave.MaternityItemDetailColl)
{
int idChild = tc.GenerateID("MaternityItemDetail", "MaternityItemDetailID");
base.SetObjectID(item, idChild);
item.MaternityLeaveID = maternityLeave.ID;
item.CreatedBy = CurrentUser.ID;
//item.CreatedDate = GlobalFunctionDA.GetOperationDate(tc);
item.CreatedDate = DateTime.Now;
MaternityLeaveDA.SaveMItemDetail(tc, item);
}
foreach (MaternityLeave.MaternityStatusDetail item in maternityLeave.MaternityStatusDetailColl)
{
int idChild = tc.GenerateID("MaternityStatusDetail", "MaternityStatusDetailID");
base.SetObjectID(item, idChild);
item.MaternityLeaveID = maternityLeave.ID;
item.CreatedBy = CurrentUser.ID;
//item.CreatedDate = GlobalFunctionDA.GetOperationDate(tc);
item.CreatedDate = DateTime.Now;
MaternityLeaveDA.SaveMStatusDetail(tc, item);
}
IncomeTaxService incomeTaxService = new IncomeTaxService();
if(maternityLeave.IncomeTaxColl != null)// This Condition is added because IncomeTax Calculation is not Completed yet till 10 Jan 2023
incomeTaxService.Save(tc, maternityLeave.IncomeTaxColl, EnumIncomeTaxDataFrom.ProcessTempData);
}
else if (/*maternityLeave.IsModified*/ !maternityLeave.IsNew)
{
maternityLeave.ModifiedBy = CurrentUser.ID;
//maternityLeave.ModifiedDate = GlobalFunctionDA.GetOperationDate(tc);
maternityLeave.ModifiedDate = DateTime.Now;
MaternityLeaveDA.Update(tc, maternityLeave);
MaternityLeaveDA.DeleteMItemDetailByParent(tc, maternityLeave.ID);
foreach (MaternityLeave.MaternityItemDetail item in maternityLeave.MaternityItemDetailColl)
{
int idChild = tc.GenerateID("MaternityItemDetail", "MaternityItemDetailID");
base.SetObjectID(item, idChild);
item.MaternityLeaveID = maternityLeave.ID;
item.CreatedBy = CurrentUser.ID;
//item.CreatedDate = GlobalFunctionDA.GetOperationDate(tc);
item.CreatedDate = DateTime.Now;
MaternityLeaveDA.SaveMItemDetail(tc, item);
}
MaternityLeaveDA.DeleteMStatusDetailByParent(tc, maternityLeave.ID);
foreach (MaternityLeave.MaternityStatusDetail item in maternityLeave.MaternityStatusDetailColl)
{
int idChild = tc.GenerateID("MaternityStatusDetail", "MaternityStatusDetailID");
base.SetObjectID(item, idChild);
item.MaternityLeaveID = maternityLeave.ID;
item.CreatedBy = CurrentUser.ID;
//item.CreatedDate = GlobalFunctionDA.GetOperationDate(tc);
item.CreatedDate = DateTime.Now;
MaternityLeaveDA.SaveMStatusDetail(tc, item);
}
}
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public void Delete(MaternityLeave maternityLeave)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
MaternityLeaveDA.DeleteMItemDetailByParent(tc, maternityLeave.ID);
MaternityLeaveDA.DeleteMStatusDetailByParent(tc, maternityLeave.ID);
IncomeTaxService incomeTaxService = new IncomeTaxService();
incomeTaxService.Save(tc, maternityLeave.IncomeTaxColl, EnumIncomeTaxDataFrom.ProcessTempData);
MaternityLeaveDA.Delete(tc, maternityLeave.ID);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
#endregion
public List<MaternityLeave.MaternityItemDetail> PrepareMaternityItemDetails(MaternityLeave _maternityLeave, Employee _employee, DateTime monthLastDate, int payrollTypeId, out double totalEarning, out int totalWorkingDays)
{
try
{
//DateTime monthLastDate = GlobalFunctions.LastDateOfMonth(dtpApprovalDate.Value);
//DateTime monthLastDate = GlobalFunctions.LastDateOfMonth(dtpFromDate);// Payroll.BO.SystemInformation.CurrentSysInfo.NextPayProcessDate);
if (_maternityLeave == null)
{
_maternityLeave = new MaternityLeave();
}
else
{
_maternityLeave.MaternityItemDetailColl.Clear();
}
List<GrossDefination> oGrossDefinationColl = new GrossDefinationService().Get();
double _totalEarning = 0;
int _totalWorkingDays = 0;
int gridViewColumnIndex = 0;
List<TaxRawItem> _taxRawItems = new List<TaxRawItem>();
double ntempAmount = 0;
for (int threeMonth = 3; threeMonth >= 1; threeMonth--)
{
double columnTotal = 0;
DateTime month = monthLastDate.AddMonths(-1 * threeMonth);
gridViewColumnIndex++;
//dgvMaternityItemDetails.Columns[gridViewColumnIndex].HeaderText = month.ToString("MMM yyyy");
SalaryMonthly salaryMonthly = new SalaryMonthly();
double grossAmount = 0;
foreach (GrossDefination grossDefination in oGrossDefinationColl)
{
if (grossDefination.SalaryComponentType == EnumSalaryComponent.Basic)
{
ntempAmount = new SalaryMonthlyService().GetAmountOnRange(_employee, GlobalFunctions.FirstDateOfMonth(month), GlobalFunctions.LastDateOfMonth(month), EnumSalaryGroup.Gross, EnumSalaryItemCode.Basic_Salary, (int)EnumSalaryItemCode.Basic_Salary, payrollTypeId);
ntempAmount = ntempAmount + new SalaryMonthlyService().GetAmountOnRange(_employee, GlobalFunctions.FirstDateOfMonth(month), GlobalFunctions.LastDateOfMonth(month), EnumSalaryGroup.Arrear, EnumSalaryItemCode.Basic_Salary, (int)EnumSalaryItemCode.Basic_Salary, payrollTypeId);
grossAmount += ntempAmount;
TaxRawItem taxRawItemBS = TaxRawItem.Create("Basic Salary", ntempAmount, enumIncomeTaxItemType.Basic_Salary, (int)EnumIncomeTaxItemGroup.Basic_Salary);
MaternityLeave.MaternityItemDetail oMaternityItemDetailGross = new MaternityLeave.MaternityItemDetail();
oMaternityItemDetailGross.ItemType = EnumMaternityItemDetailType.GrossSalary;
oMaternityItemDetailGross.Description = "Gross Salary";
oMaternityItemDetailGross.Amount = ntempAmount;
oMaternityItemDetailGross.MonthDate = month;
oMaternityItemDetailGross.IncomeTaxItemType = enumIncomeTaxItemType.Basic_Salary;
oMaternityItemDetailGross.SalaryComponentID = (int)EnumIncomeTaxItemGroup.Basic_Salary;
oMaternityItemDetailGross.TaxRawItemObject = taxRawItemBS;
_maternityLeave.MaternityItemDetailColl.Add(oMaternityItemDetailGross);
//_taxRawItems.Add(taxRawItemBS);
}
else
{
ntempAmount = new SalaryMonthlyService().GetAmountOnRange(_employee, GlobalFunctions.FirstDateOfMonth(month), GlobalFunctions.LastDateOfMonth(month), EnumSalaryGroup.Gross, EnumSalaryItemCode.Allowance, grossDefination.ComponentID, payrollTypeId);
ntempAmount = ntempAmount + new SalaryMonthlyService().GetAmountOnRange(_employee, GlobalFunctions.FirstDateOfMonth(month), GlobalFunctions.LastDateOfMonth(month), EnumSalaryGroup.Arrear, EnumSalaryItemCode.Allowance, grossDefination.ComponentID, payrollTypeId);
grossAmount += ntempAmount;
TaxRawItem taxRawItemOthers = TaxRawItem.Create("Gross Component", ntempAmount, enumIncomeTaxItemType.Allowance, grossDefination.ComponentID);
//_taxRawItems.Add(taxRawItemOthers);
MaternityLeave.MaternityItemDetail oMaternityItemDetailGross = new MaternityLeave.MaternityItemDetail();
oMaternityItemDetailGross.ItemType = EnumMaternityItemDetailType.GrossSalary;
oMaternityItemDetailGross.Description = "Gross Salary";
oMaternityItemDetailGross.Amount = ntempAmount;
oMaternityItemDetailGross.MonthDate = month;
oMaternityItemDetailGross.IncomeTaxItemType = enumIncomeTaxItemType.Allowance;
oMaternityItemDetailGross.SalaryComponentID = grossDefination.ComponentID;
oMaternityItemDetailGross.TaxRawItemObject = taxRawItemOthers;
_maternityLeave.MaternityItemDetailColl.Add(oMaternityItemDetailGross);
}
}
_totalEarning += grossAmount;
columnTotal += grossAmount;
List<Term> terms = new TermService().Get(EnumStatus.Active, payrollTypeId);
double overTime = 0;
foreach (Term item in terms)
{
ntempAmount = new SalaryMonthlyService().GetAmountOnRange(_employee, GlobalFunctions.FirstDateOfMonth(month), GlobalFunctions.LastDateOfMonth(month), EnumSalaryGroup.Gross, EnumSalaryItemCode.Over_Time_Amount, item.ID, payrollTypeId);
overTime += ntempAmount;
//_taxRawItems.Add( TaxRawItem.Create("OT" ,ntempAmount, enumIncomeTaxItemType.OT, item.ID.Integer));
}
_totalEarning += overTime;
columnTotal += overTime;
MaternityLeave.MaternityItemDetail oMaternityItemDetailOverTime = new MaternityLeave.MaternityItemDetail();
oMaternityItemDetailOverTime.ItemType = EnumMaternityItemDetailType.OT;
oMaternityItemDetailOverTime.Description = "OT";
oMaternityItemDetailOverTime.Amount = overTime;
oMaternityItemDetailOverTime.MonthDate = month;
oMaternityItemDetailOverTime.IncomeTaxItemType = enumIncomeTaxItemType.OT;
oMaternityItemDetailOverTime.SalaryComponentID = terms[0].ID;
_maternityLeave.MaternityItemDetailColl.Add(oMaternityItemDetailOverTime);
MaternityLeave.MaternityItemDetail oMaternityItemDetailEWA = new MaternityLeave.MaternityItemDetail();
oMaternityItemDetailEWA.ItemType = EnumMaternityItemDetailType.ExtraWorkAllowance;
oMaternityItemDetailEWA.Description = "Extra Work Allowance"; // EWA= Extra Work Allowance";
int extraWAllowanceGetFromDB = 13; // if change in database this value not realize// 13 005 Extra Work Allowance 1 13 1 3
ntempAmount = new SalaryMonthlyService().GetAmountOnRange(_employee, GlobalFunctions.FirstDateOfMonth(month), GlobalFunctions.LastDateOfMonth(month), EnumSalaryGroup.Gross, EnumSalaryItemCode.Allowance, extraWAllowanceGetFromDB, payrollTypeId);
oMaternityItemDetailEWA.Amount = ntempAmount;
_totalEarning += oMaternityItemDetailEWA.Amount;
columnTotal += oMaternityItemDetailEWA.Amount;
oMaternityItemDetailEWA.MonthDate = month;
oMaternityItemDetailEWA.IncomeTaxItemType = enumIncomeTaxItemType.Allowance;
oMaternityItemDetailEWA.SalaryComponentID = extraWAllowanceGetFromDB;
TaxRawItem taxRawItemEWA = TaxRawItem.Create("Extra Work Alloance", ntempAmount, enumIncomeTaxItemType.Allowance, extraWAllowanceGetFromDB);
oMaternityItemDetailEWA.TaxRawItemObject = taxRawItemEWA;
_maternityLeave.MaternityItemDetailColl.Add(oMaternityItemDetailEWA);
//_taxRawItems.Add(taxRawItemEWA);
MaternityLeave.MaternityItemDetail oMaternityItemDetailBonusDress = new MaternityLeave.MaternityItemDetail();
oMaternityItemDetailBonusDress.ItemType = EnumMaternityItemDetailType.BonusDressAllowance;
oMaternityItemDetailBonusDress.Description = "Bonus(Dress Allowance)";
// get from Bonus table 2 4 2010-08-18 00:00:00.000 2010-08-18 00:00:00.000 1 2010-09-09 00:00:00.000 NULL NULL 2010-08-01 00:00:00.000 0 0
int bonusDressID = 2;
ntempAmount = new BonusProcessService().GetBonusAmount(GlobalFunctions.LastDateOfMonth(month), _employee.ID, bonusDressID, payrollTypeId);
oMaternityItemDetailBonusDress.Amount = ntempAmount;
_totalEarning += oMaternityItemDetailBonusDress.Amount;
columnTotal += oMaternityItemDetailBonusDress.Amount;
oMaternityItemDetailBonusDress.MonthDate = month;
oMaternityItemDetailBonusDress.IncomeTaxItemType = enumIncomeTaxItemType.Bonus;
oMaternityItemDetailBonusDress.SalaryComponentID = bonusDressID;
TaxRawItem taxRawItemBD = TaxRawItem.Create("Bonus(Dress Allowance)", ntempAmount, enumIncomeTaxItemType.Bonus, bonusDressID);
oMaternityItemDetailBonusDress.TaxRawItemObject = taxRawItemBD;
_maternityLeave.MaternityItemDetailColl.Add(oMaternityItemDetailBonusDress);
//_taxRawItems.Add(taxRawItemBD);
// if change in database this value not realize// 1 4 2010-08-18 00:00:00.000 2010-08-18 00:00:00.000 1 2010-09-09 00:00:00.000 NULL NULL 2010-08-01 00:00:00.000 0 0
int bonusFestivalID = 1;
MaternityLeave.MaternityItemDetail oMaternityItemDetailBonusFestival = new MaternityLeave.MaternityItemDetail();
oMaternityItemDetailBonusFestival.ItemType = EnumMaternityItemDetailType.BonusFestival;
oMaternityItemDetailBonusFestival.Description = "Bonus(Festival)";
ntempAmount = new BonusProcessService().GetBonusAmount(GlobalFunctions.LastDateOfMonth(month), _employee.ID, bonusFestivalID, payrollTypeId);
oMaternityItemDetailBonusFestival.Amount = ntempAmount;
_totalEarning += oMaternityItemDetailBonusFestival.Amount;
columnTotal += oMaternityItemDetailBonusFestival.Amount;
oMaternityItemDetailBonusFestival.MonthDate = month;
oMaternityItemDetailBonusFestival.IncomeTaxItemType = enumIncomeTaxItemType.Bonus;
oMaternityItemDetailBonusFestival.SalaryComponentID = bonusFestivalID;
TaxRawItem taxRawItemFestival = TaxRawItem.Create("Bonus(Festival)", ntempAmount, enumIncomeTaxItemType.Bonus, bonusFestivalID);
oMaternityItemDetailBonusFestival.TaxRawItemObject = taxRawItemFestival;
_maternityLeave.MaternityItemDetailColl.Add(oMaternityItemDetailBonusFestival);
//_taxRawItems.Add(taxRawItemFestival); ;
MaternityLeave.MaternityItemDetail oMaternityItemDetailMedA = new MaternityLeave.MaternityItemDetail();
oMaternityItemDetailMedA.ItemType = EnumMaternityItemDetailType.MedicalAllowance;
oMaternityItemDetailMedA.Description = "Medical Allowance";
int medicalAllowanceGetFromDB = 16; // if change in database this value not realize// //16 008 Medical Allowance
ntempAmount = new SalaryMonthlyService().GetAmountOnRange(_employee, GlobalFunctions.FirstDateOfMonth(month), GlobalFunctions.LastDateOfMonth(month), EnumSalaryGroup.Gross, EnumSalaryItemCode.Allowance, medicalAllowanceGetFromDB, payrollTypeId);
oMaternityItemDetailMedA.Amount = ntempAmount;
_totalEarning += oMaternityItemDetailMedA.Amount;
columnTotal += oMaternityItemDetailMedA.Amount;
oMaternityItemDetailMedA.MonthDate = month;
oMaternityItemDetailMedA.IncomeTaxItemType = enumIncomeTaxItemType.Allowance;
oMaternityItemDetailMedA.SalaryComponentID = medicalAllowanceGetFromDB;
TaxRawItem taxRawItemMedA = TaxRawItem.Create("Medical Allowance", ntempAmount, enumIncomeTaxItemType.Allowance, medicalAllowanceGetFromDB);
oMaternityItemDetailMedA.TaxRawItemObject = taxRawItemMedA;
_maternityLeave.MaternityItemDetailColl.Add(oMaternityItemDetailMedA);
//Medical allowance is not taxable for SGS 31 may 2012
// _taxRawItems.Add(taxRawItemMedA);
MaternityLeave.MaternityItemDetail oMaterItmDtlSplConAoll = new MaternityLeave.MaternityItemDetail();
oMaterItmDtlSplConAoll.ItemType = EnumMaternityItemDetailType.SpecialConveyanceAllowance;
oMaterItmDtlSplConAoll.Description = "Special Conveyance Allowance";
// ALLOWDEDUCTID CODE NAME ALLOWORDEDUCT SequenceNO Status CreatedBy CreationDate ModifiedBy ModifiedDate
//17 009 Special Conveyance Allowance 1 17 1 2 2010-12-20 00:00:00.000 NULL NULL
int specialConAllowGetFromDB = 17;
ntempAmount = new SalaryMonthlyService().GetAmountOnRange(_employee, GlobalFunctions.FirstDateOfMonth(month), GlobalFunctions.LastDateOfMonth(month), EnumSalaryGroup.Gross, EnumSalaryItemCode.Allowance, specialConAllowGetFromDB, payrollTypeId);
oMaterItmDtlSplConAoll.Amount = ntempAmount;
_totalEarning += oMaterItmDtlSplConAoll.Amount;
columnTotal += oMaterItmDtlSplConAoll.Amount;
oMaterItmDtlSplConAoll.MonthDate = month;
oMaterItmDtlSplConAoll.IncomeTaxItemType = enumIncomeTaxItemType.Allowance;
oMaterItmDtlSplConAoll.SalaryComponentID = specialConAllowGetFromDB;
TaxRawItem taxRawItemDSCA = TaxRawItem.Create("Special Conveyance Allowance", ntempAmount, enumIncomeTaxItemType.Allowance, specialConAllowGetFromDB);
oMaterItmDtlSplConAoll.TaxRawItemObject = taxRawItemDSCA;
_maternityLeave.MaternityItemDetailColl.Add(oMaterItmDtlSplConAoll);
//Special Conveyance allowance is not taxable for SGS 31 may 2012
// _taxRawItems.Add(taxRawItemDSCA);
MaternityLeave.MaternityItemDetail oMaternityItemDetailTotal = new MaternityLeave.MaternityItemDetail();
oMaternityItemDetailTotal.ItemType = EnumMaternityItemDetailType.Total;
oMaternityItemDetailTotal.Description = "Total";
oMaternityItemDetailTotal.Amount = columnTotal;
oMaternityItemDetailTotal.MonthDate = month;
_maternityLeave.MaternityItemDetailColl.Add(oMaternityItemDetailTotal);
MaternityLeave.MaternityItemDetail oMaternityItemDetailWorkDay = new MaternityLeave.MaternityItemDetail();
oMaternityItemDetailWorkDay.ItemType = EnumMaternityItemDetailType.Days;
oMaternityItemDetailWorkDay.Description = "Actual Working Days";
oMaternityItemDetailWorkDay.Amount = month.Day - new MaternityLeaveService().GetTotalMonthlyHolidays((int)_employee.LocationID, GlobalFunctions.FirstDateOfMonth(month), GlobalFunctions.LastDateOfMonth(month));
_totalWorkingDays += (int)oMaternityItemDetailWorkDay.Amount;
oMaternityItemDetailWorkDay.MonthDate = month;
_maternityLeave.MaternityItemDetailColl.Add(oMaternityItemDetailWorkDay);
}
totalEarning = _totalEarning;
totalWorkingDays = _totalWorkingDays;
return _maternityLeave.MaternityItemDetailColl;
}
catch (Exception e)
{
if (e.InnerException == null)
{
throw new Exception(e.Message);
}
else
{
throw new Exception(e.Message, e.InnerException);
}
}
return null;
}
public DataTable RefreshGridAllowanceMaternityLeave(MaternityLeave _maternityLeave, DateTime monthLastDate, out List<MaternityLeave.MaternityItemDetail> _maternityItemDetailOut)
{
try
{
DataTable dgvMaternityItemDetails = new DataTable();
//dgvMaternityItemDetails.Columns.Add("clnParticulars", typeof(string));
//try
//{
// dgvMaternityItemDetails.Rows.Clear();
//}
int gridViewColumnIndex = 0;
string Before3Month = null, Before2Month = null, Before1Month = null;
dgvMaternityItemDetails.Columns.Add("Particulars", typeof(string));
//for (int threeMonth = 3; threeMonth >= 1; threeMonth--)
//{
// DateTime month = monthLastDate.AddMonths(-1 * threeMonth);
// gridViewColumnIndex++;
// dgvMaternityItemDetails.Columns.Add(month.ToString("MMM yyyy"), typeof(double));
// 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;
// }
//}
dgvMaternityItemDetails.Columns.Add("Before3Month", typeof(double));
dgvMaternityItemDetails.Columns.Add("Before2Month", typeof(double));
dgvMaternityItemDetails.Columns.Add("Before1Month", typeof(double));
dgvMaternityItemDetails.Columns.Add("Total", typeof(double));
dgvMaternityItemDetails.Columns.Add("ItemType", typeof(int));
int rowIndex = 0;
int cellIndex = 0;
int totalThreeMonth = 3;
int minusThreeGross = 3;
//dgvMaternityItemDetails.Rows.Clear();
int numberOfRow = _maternityLeave.MaternityItemDetailColl.Count / totalThreeMonth;
if (_maternityLeave != null)
{
EnumMaternityItemDetailType itemDetailType = EnumMaternityItemDetailType.Others;
foreach (MaternityLeave.MaternityItemDetail oMaternityItemDetail in _maternityLeave.MaternityItemDetailColl)
{
if (numberOfRow - minusThreeGross > rowIndex)
{
if (itemDetailType != EnumMaternityItemDetailType.GrossSalary)
{
itemDetailType = oMaternityItemDetail.ItemType;
dgvMaternityItemDetails.Rows.Add();
dgvMaternityItemDetails.Rows[rowIndex]["Particulars"] = oMaternityItemDetail.Description;
dgvMaternityItemDetails.Rows[rowIndex]["ItemType"] = (int)oMaternityItemDetail.ItemType;
//dgvMaternityItemDetails.Rows[rowIndex]["clnParticulars"] = oMaternityItemDetail;
rowIndex++;
}
else
{
itemDetailType = oMaternityItemDetail.ItemType;
if (oMaternityItemDetail.ItemType != EnumMaternityItemDetailType.GrossSalary)
{
itemDetailType = oMaternityItemDetail.ItemType;
dgvMaternityItemDetails.Rows.Add();
dgvMaternityItemDetails.Rows[rowIndex]["Particulars"] = oMaternityItemDetail.Description;
dgvMaternityItemDetails.Rows[rowIndex]["ItemType"] = (int)oMaternityItemDetail.ItemType;
//dgvMaternityItemDetails.Rows[rowIndex]["clnParticulars"] = oMaternityItemDetail;
rowIndex++;
}
}
}
else
{
break;
}
}
const int fourGrossOject = 4;
//int cc = 1;
int indexOfObject = 0;
for (int objectCounter = 0; objectCounter < (_maternityLeave.MaternityItemDetailColl.Count - minusThreeGross * minusThreeGross) / rowIndex; objectCounter++)
{
cellIndex++;
double cellAmount = 0;
int counterUptoFour = 0;
for (int counter = 0; counter < rowIndex; counter++)
{
if (_maternityLeave.MaternityItemDetailColl[indexOfObject].ItemType == EnumMaternityItemDetailType.GrossSalary)
{
for (int gross = 0; gross < 4; gross++)
{
cellAmount += _maternityLeave.MaternityItemDetailColl[indexOfObject].Amount;
indexOfObject++;
counterUptoFour++;
}
}
if (fourGrossOject == counterUptoFour)
{
//string sHeaderText = dgvMaternityItemDetails.Columns[cc].HeaderText;
dgvMaternityItemDetails.Rows[counter][cellIndex]= cellAmount.ToString("N2");
//dgvMaternityItemDetails.Rows[counter][cellIndex] = _maternityLeave.MaternityItemDetailColl[indexOfObject - 1];
counterUptoFour = 0;
//cc++;
}
else
{
dgvMaternityItemDetails.Rows[counter][cellIndex] = _maternityLeave.MaternityItemDetailColl[indexOfObject].Amount.ToString("N2");
//dgvMaternityItemDetails.Rows[counter][cellIndex] = _maternityLeave.MaternityItemDetailColl[indexOfObject];
indexOfObject++;
}
}
}
//lblTotal.Text = "Total : " + rowIndex.ToString();
//foreach (DataTable gridRow in dgvMaternityItemDetails.Rows)
foreach (DataRow gridRow in dgvMaternityItemDetails.Rows)
{
double rowSum = 0;
//rowSum += Convert.ToDouble(gridRow[Before3Month]) + Convert.ToDouble(gridRow[Before2Month]) + Convert.ToDouble(gridRow[Before1Month]);
rowSum += Convert.ToDouble(gridRow["Before3Month"]) + Convert.ToDouble(gridRow["Before2Month"]) + Convert.ToDouble(gridRow["Before1Month"]);
gridRow["total"] = rowSum.ToString("N2");
}
}
_maternityItemDetailOut = _maternityLeave.MaternityItemDetailColl;
return dgvMaternityItemDetails;
}
catch (Exception e)
{
if (e.InnerException == null)
{
throw new Exception(e.Message);
}
else
{
throw new Exception(e.Message, e.InnerException);
}
}
}
public MaternityLeave RefreshGridPaymentMaternityLeave(MaternityLeave _maternityLeave, out int numPaymentDays)
{
int totalPaymentDays = 0;
try
{
_maternityLeave.MaternityStatusDetailColl = new MaternityLeaveService().GetMStatusDetail(_maternityLeave.ID);
if (_maternityLeave.MaternityStatusDetailColl.Count > 0)
{
foreach (MaternityLeave.MaternityStatusDetail statusDetail in _maternityLeave.MaternityStatusDetailColl)
{
totalPaymentDays += statusDetail.PaymentDays;
}
}
if (_maternityLeave.ApproveDays - totalPaymentDays >= 0)
{
numPaymentDays = _maternityLeave.ApproveDays - totalPaymentDays;
}
else
{
numPaymentDays = _maternityLeave.ApproveDays;
}
}
catch (Exception e)
{
if (e.InnerException == null)
{
throw new Exception(e.Message);
}
else
{
throw new Exception(e.Message, e.InnerException);
}
}
//numPaymentDays = totalPaymentDays;
return _maternityLeave;
}
}
}