using System; using System.Collections.Generic; using System.Linq; using System.Text; using Ease.CoreV35; using Ease.CoreV35.Model; using Ease.CoreV35.Caching; using System.Data.Linq.Mapping; using System.Data; namespace Payroll.BO { #region CarFuelProcessDetail [Serializable] public class CarFuelProcessDetail : BasicBaseObject { private ObjectsTemplate _employees; private ObjectsTemplate _processDetails; private ObjectsTemplate _CarFuelParameters; private ObjectsTemplate _CarFuelItems; private DataSet _dsCarFuelRegister; private ObjectsTemplate _processItems; private List _processStatuses; public DateTime _processMonth; public event ProcessStatus ProcessStatus; public event ProgressStatus ProgressStatus; #region Cache Store private static Cache _cache = new Cache(typeof(CarFuelProcessDetail)); #endregion #region Constructor public CarFuelProcessDetail() { _accountNo = string.Empty; _bankID = null; _branchID = null; _categoryID = null; _departmentID = null; _designationID = null; _employeeID = null; _gender = EnumGender.None; _gradeID = null; _isConfirmed = false; _isFinalize = false; _locationID = null; _CarFuelProcessID = null; _payrollTypeID = null; _pfMemberType = EnumPFMembershipType.Live; _religionID = null; _remarks = string.Empty; _CarFuelProcessDetailItems = null; _gradeSalaries = null; _employee = null; _arreargradeSalaries = null; _arrearPaidgradeSalaries = null; } #endregion #region Properties #region AccountNo : string private string _accountNo; public string AccountNo { get { return _accountNo; } set { base.OnPropertyChange("AccountNo", _accountNo, value); _accountNo = value; } } #endregion #region BankID : ID private ID _bankID; public ID BankID { get { return _bankID; } set { base.OnPropertyChange("BankID", _bankID, value); _bankID = value; } } #endregion #region BranchID : ID private ID _branchID; public ID BranchID { get { return _branchID; } set { base.OnPropertyChange("BranchID", _branchID, value); _branchID = value; } } #endregion #region CategoryID : ID private ID _categoryID; public ID CategoryID { get { return _categoryID; } set { base.OnPropertyChange("CategoryID", _categoryID, value); _categoryID = value; } } #endregion #region DepartmentID : ID private ID _departmentID; public ID DepartmentID { get { return _departmentID; } set { base.OnPropertyChange("DepartmentID", _departmentID, value); _departmentID = value; } } #endregion #region DesignationID : ID private ID _designationID; public ID DesignationID { get { return _designationID; } set { base.OnPropertyChange("DesignationID", _designationID, value); _designationID = value; } } #endregion #region EmployeeID : ID private ID _employeeID; public ID EmployeeID { get { return _employeeID; } set { base.OnPropertyChange("EmployeeID", _employeeID, value); _employeeID = value; } } #endregion #region Gender : EnumGender private EnumGender _gender; public EnumGender Gender { get { return _gender; } set { base.OnPropertyChange("Gender", (short)_gender, (short)value); _gender = value; } } #endregion #region GradeID : ID private ID _gradeID; public ID GradeID { get { return _gradeID; } set { base.OnPropertyChange("GradeID", _gradeID, value); _gradeID = value; } } #endregion #region IsConfirmed : bool private bool _isConfirmed; public bool IsConfirmed { get { return _isConfirmed; } set { base.OnPropertyChange("IsConfirmed", _isConfirmed, value); _isConfirmed = value; } } #endregion #region IsFinalize : bool private bool _isFinalize; public bool IsFinalize { get { return _isFinalize; } set { base.OnPropertyChange("IsFinalize", _isFinalize, value); _isFinalize = value; } } #endregion #region LocationID : ID private ID _locationID; public ID LocationID { get { return _locationID; } set { base.OnPropertyChange("LocationID", _locationID, value); _locationID = value; } } #endregion #region CarFuelProcessID : ID private ID _CarFuelProcessID; public ID CarFuelProcessID { get { return _CarFuelProcessID; } set { base.OnPropertyChange("CarFuelProcessID", _CarFuelProcessID, value); _CarFuelProcessID = value; } } #endregion #region PayrollTypeID : ID private ID _payrollTypeID; public ID PayrollTypeID { get { return _payrollTypeID; } set { base.OnPropertyChange("PayrollTypeID", _payrollTypeID, value); _payrollTypeID = value; } } #endregion #region PFMemberType : EnumPFMembershipType private EnumPFMembershipType _pfMemberType; public EnumPFMembershipType PFMemberType { get { return _pfMemberType; } set { base.OnPropertyChange("PFMemberType", (short)_pfMemberType, (short)value); _pfMemberType = value; } } #endregion #region ReligionID : ID private ID _religionID; public ID ReligionID { get { return _religionID; } set { base.OnPropertyChange("ReligionID", _religionID, value); _religionID = value; } } #endregion #region Remarks : string private string _remarks; public string Remarks { get { return _remarks; } set { base.OnPropertyChange("Remarks", _remarks, value); _remarks = value; } } #endregion #region CarFuelProcessDetailItem private ObjectsTemplate _CarFuelProcessDetailItems; public ObjectsTemplate CarFuelProcessDetailItems { get { //Do not change this property if (_CarFuelProcessDetailItems == null ) { _CarFuelProcessDetailItems = new ObjectsTemplate(); } return this._CarFuelProcessDetailItems; } set { _CarFuelProcessDetailItems = value; } } #endregion #region Employee : Employee private Employee _employee; public Employee Employee { get { if (_employeeID.Integer > 0 && _employee == null) { _employee = new Employee(); _employee = Payroll.BO.Employee.Get(_employeeID); } return this._employee; } set { _employee = value; } } #endregion #region Grade Salaries : ObjectsTemplate private ObjectsTemplate _gradeSalaries; public ObjectsTemplate GradeSalaries { get { if (_gradeSalaries == null) { throw new ServiceException("Grade Salary not yet set"); } return _gradeSalaries; } set { _gradeSalaries = value; } } #endregion #region Arrear Grade Salaries : ObjectsTemplate private ObjectsTemplate _arreargradeSalaries; public ObjectsTemplate ArrearGradeSalaries { get { if (_arreargradeSalaries == null) { // throw new ServiceException("Arrear Grade Salary not yet set"); _arreargradeSalaries = new ObjectsTemplate(); } return _arreargradeSalaries; } set { _arreargradeSalaries = value; } } #endregion #region Arrear Paid Grade Salaries : ObjectsTemplate private ObjectsTemplate _arrearPaidgradeSalaries; public ObjectsTemplate ArrearPaidGradeSalaries { get { if (_arrearPaidgradeSalaries == null) { _arrearPaidgradeSalaries = new ObjectsTemplate(); } return _arrearPaidgradeSalaries; } set { _arrearPaidgradeSalaries = value; } } #endregion #region Service Factory ICarFuelProcessDetailService : ICarFuelProcessDetailService internal static ICarFuelProcessDetailService Service { get { return Services.Factory.CreateService(typeof(ICarFuelProcessDetailService)); } } #endregion public List Errors { get { return _processStatuses; } } #endregion #region Functions public static CarFuelProcessDetail Get(ID nCarFuelProcessDetailID) { CarFuelProcessDetail oCarFuelProcessDetail = null; #region Cache Header oCarFuelProcessDetail = (CarFuelProcessDetail)_cache["Get", nCarFuelProcessDetailID]; if (oCarFuelProcessDetail != null) return oCarFuelProcessDetail; #endregion oCarFuelProcessDetail = CarFuelProcessDetail.Service.Get(nCarFuelProcessDetailID); #region Cache Footer _cache.Add(oCarFuelProcessDetail, "Get", nCarFuelProcessDetailID); #endregion return oCarFuelProcessDetail; } public static ObjectsTemplate Get() { #region Cache Header ObjectsTemplate oCarFuelProcessDetails = _cache["Get"] as ObjectsTemplate; if (oCarFuelProcessDetails != null) return oCarFuelProcessDetails; #endregion try { oCarFuelProcessDetails = Service.Get(); } catch (ServiceException e) { throw new Exception(e.Message, e); } #region Cache Footer _cache.Add(oCarFuelProcessDetails, "Get"); #endregion return oCarFuelProcessDetails; } public ID Save() { this.SetAuditTrailProperties(); return CarFuelProcessDetail.Service.Save(this); } public void Delete(ID id) { CarFuelProcessDetail.Service.Delete(id); } #region ProgressBar private void UpdateprocessStatus(string statusString) { if (ProcessStatus != null) ProcessStatus(statusString); } private void UpdateProgressStatus(EnumProcessStatus status) { if (ProgressStatus != null) ProgressStatus(status); } #endregion public ObjectsTemplate Process(ObjectsTemplate employees, DateTime processMonth) { //SalaryException oSException = new SalaryException(); _employees = employees; _processMonth = processMonth; UpdateprocessStatus("Collecting Employee basic information...."); //this.Initialize(); this.AddEmployeeToProcessDetail(); //if (_processStatuses.Count > 0) return; UpdateprocessStatus("Calculating Employee basic Salary...."); this.BasicSalary(); UpdateprocessStatus("Calculating Employees benifits and deduction...."); this.CarFuelItems(); //this.LeavePrepare(oSException.GetEmpLeaveStatus()); return _processDetails; } private void AddEmployeeToProcessDetail() { _processDetails = new ObjectsTemplate(); UpdateProgressStatus(EnumProcessStatus.Start); foreach (Employee employee in _employees) { UpdateProgressStatus(EnumProcessStatus.PerformStep); GlobalFunctions.UpdateStatus(" Collecting information for the employee " + employee.Name + " ( " + employee.EmployeeNo + ")"); CarFuelProcessDetail procDetail = new CarFuelProcessDetail(); procDetail.CategoryID = employee.CategoryID; procDetail.EmployeeID = employee.ID; procDetail.Gender = employee.Gender; procDetail.IsConfirmed = employee.IsConfirmed; procDetail.PayrollTypeID = employee.PayrollTypeID; procDetail.PFMemberType = employee.PFMemberType; procDetail.ReligionID = employee.ReligionID; procDetail.GradeID = employee.GradeID; procDetail.DepartmentID = employee.DepartmentID; procDetail.DesignationID = employee.DesignationID; procDetail.LocationID = employee.LocationID; if (employee.PaymentMode == EnumPaymentMode.BankTransfer) { procDetail.BranchID = employee.BranchID; Branch branch = new Branch(); branch = Branch.Get(employee.BranchID); procDetail.BankID = branch.BankID; procDetail.AccountNo = employee.AccountNo; } else { procDetail.BranchID = ID.FromInteger(0); procDetail.BankID = ID.FromInteger(0); } procDetail.Employee = employee; _processDetails.Add(procDetail); } UpdateProgressStatus(EnumProcessStatus.End); } private void AddProcessStatus(Employee employee, string remarks) { SalaryProcessStatus status = new SalaryProcessStatus(); status.EmployeeNo = employee.EmployeeNo; status.Name = employee.Name; status.Remarks = remarks; _processStatuses.Add(status); } private void BasicSalary() { //GetCurrentMonthSalaryItems function return current month's employee grade, salary and effect date. //effect date must sorted, otherwise error will be generated from next function. #region Calculate Normal Salary ObjectsTemplate gradeSalaryItems = EmployeeGradeSalary.Service.GetCurrMonthSalaryItems(SystemInformation.CurrentSysInfo.NextPayProcessDate); foreach (CarFuelProcessDetail CarFuelProcess in _processDetails ) { CarFuelProcess.GradeSalaries = EmployeeGradeSalary.Get(gradeSalaryItems, CarFuelProcess.EmployeeID); if (CarFuelProcess.GradeSalaries.Count == 0) continue; EmployeeGradeSalary.PrepareDataForCurrentSalary(CarFuelProcess.Employee, CarFuelProcess.GradeSalaries); } #endregion Calculate Normal Salary #region calculate arrear amount ObjectsTemplate arrearItems = EmployeeGradeSalary.Service.GetArrearItems(); foreach (CarFuelProcessDetail CarFuelProcess in _processDetails) { CarFuelProcess.ArrearGradeSalaries = EmployeeGradeSalary.Get(arrearItems, CarFuelProcess.EmployeeID); if (CarFuelProcess.ArrearGradeSalaries.Count > 0) { DateTime arrearPaidFrom = CarFuelProcess.ArrearGradeSalaries[0].EffectDate; CarFuelProcess.ArrearPaidGradeSalaries = EmployeeGradeSalary.Service.GetArrearPaidItems(CarFuelProcess.EmployeeID, arrearPaidFrom); } } #endregion calculate arrear amount } private void CarFuelItems() { _CarFuelParameters = CarFuelParameter.Get(EnumStatus.Active); if (_CarFuelParameters == null || _CarFuelParameters.Count == 0) return; ObjectsTemplate CarFuelIndividuals = CarFuelParameterIndividual.Service.Get( GlobalFunctions.FirstDateOfMonth(_processMonth), GlobalFunctions.LastDateOfMonth(_processMonth)); CarFuelParameter paramter = new CarFuelParameter(); ObjectsTemplate paramters; foreach (CarFuelProcessDetail detail in _processDetails) { // Regular Grade defined parameters paramters = paramter.ApplicableParameters(detail.Employee, detail, _CarFuelParameters, detail.GradeSalaries); this.GradeDefinedCarFuelItem(detail, detail.GradeSalaries, paramters); // Arrear Grade defined parameters paramters = paramter.ApplicableParameters(detail.Employee, detail, _CarFuelParameters, detail.ArrearGradeSalaries); this.GradeDefinedCarFuelItem(detail, detail.GradeSalaries, paramters); // Arrear already paid parameters paramters = paramter.ApplicableParameters(detail.Employee, detail, _CarFuelParameters, detail.ArrearPaidGradeSalaries); this.GradeDefinedCarFuelItem(detail, detail.GradeSalaries, paramters); //this.IndividualCarFuelItem(detail, CarFuelIndividuals); } } private void Add(CarFuelProcessDetail processDetail, CarFuelProcessDetailItem item) { CarFuelProcessDetailItem existItem = processDetail.CarFuelProcessDetailItems.Find(delegate(CarFuelProcessDetailItem fItem) { return fItem.CarFuelItemID == item.CarFuelItemID; }); if (existItem == null) { processDetail.CarFuelProcessDetailItems.Add(item); } else { existItem.NetAmount = existItem.NetAmount + item.NetAmount; existItem.ChangeNetAmount = existItem.ChangeNetAmount + item.ChangeNetAmount; existItem.Description = item.Description; } } private void GradeDefinedCarFuelItem(CarFuelProcessDetail detail, ObjectsTemplate gradeSalaries, ObjectsTemplate paramters) { double amount = 0, totalAmount = 0, paidAmount = 0, remainingAmount, indvAmnt = 0, fractionAmount = 0; int totalMonth = 12, paidMonth = 0, remainingMonth = 0; //int randomEmployee = (new Random()).Next(1, _employees.Count); int empNumber = 1; foreach (EmployeeGradeSalary empGradeSalary in gradeSalaries) { foreach (CarFuelParameter parameter in paramters) { if (parameter.EntitleType == EnumEntitleType.Grade) { //amount = parameter.GetGradeDefinedAmount(detail.Employee, empGradeSalary.BasicSalary, empGradeSalary.GrossSalary); if (parameter.IsFlatAmount == true) amount = amount * empGradeSalary.FractionofFromTo; } else continue; CarFuelProcessDetailItem opdItem = new CarFuelProcessDetailItem(); switch (parameter.CarFuelPeriodicity) { case EnumCarFuelPeriodicity.Monthly: opdItem.NetAmount = amount; opdItem.ChangeNetAmount = amount; //opdItem.TaxAmount = break; case EnumCarFuelPeriodicity.OnceOff: opdItem.NetAmount = amount; opdItem.ChangeNetAmount = amount; //opdItem.TaxAmount = break; case EnumCarFuelPeriodicity.Annual: paidMonth = Convert.ToInt32(Payroll.BO.SystemInformation.CurrentSysInfo.NextPayProcessDate.Date.Month); remainingMonth = totalMonth - (paidMonth); totalAmount = amount * totalMonth; paidAmount = paidMonth * amount; remainingAmount = totalAmount - paidAmount; opdItem.NetAmount = remainingAmount / remainingMonth; opdItem.ChangeNetAmount = remainingAmount / remainingMonth; //opdItem.TaxAmount = break; //case EnumCarFuelPeriodicity.AveragePayment: // break; //case EnumCarFuelPeriodicity.OnAmount: // indvAmnt = amount / _processDetails.Count; // fractionAmount = (indvAmnt - Math.Round(indvAmnt, 0)) * _processDetails.Count; // if (empNumber == gradeSalaries.Count) // { // opdItem.NetAmount = Math.Round(indvAmnt, 0) + fractionAmount; // opdItem.ChangeNetAmount = Math.Round(indvAmnt, 0) + fractionAmount; // } // else // { // opdItem.NetAmount = Math.Round(indvAmnt, 0); // opdItem.ChangeNetAmount = Math.Round(indvAmnt, 0); // } // //opdItem.TaxAmount = // break; default: break; } opdItem.Description = parameter.CarFuelItem.Name; opdItem.CarFuelItemID = parameter.CarFuelItemID; opdItem.CarFuelProcessDetailID = this.ID; opdItem.CarFuelType = parameter.CarFuelItem.CarFuelType; _CarFuelItems = CarFuelItem.Get(); if (_CarFuelItems != null && _CarFuelItems.Count > 0) opdItem.Sequence = _CarFuelItems.GetItem(parameter.CarFuelItem.ID).Sequence; this.Add(detail, opdItem); // add the item in the collection } empNumber++; } } private void IndividualCarFuelItem(CarFuelProcessDetail detail, ObjectsTemplate CarFuelIndividuals) { //double amount = 0; //EnumSalaryGroup groupCode = EnumSalaryGroup.Gross; //#region Individual Allowance //List items = CarFuelIndividuals.FindAll(delegate(CarFuelParameterIndividual item) //{ // return item.EmployeeId.Integer == detail.Employee.ID.Integer && item.IndividualType == EnumCarFuelIndivdualType.AppliedToIndividual; //}); //foreach (CarFuelParameterIndividual item in items) //{ // amount = 0; // CarFuelParameter parameter = _CarFuelParameters.GetItem(item.CarFuelParameterID); // amount = parameter.GetIndividualAmount(detail.Employee, _processMonth, item, // detail.Employee.GrossSalary, detail.GetGrossAmount(EnumSalaryItemCode.Basic_Salary, (int)EnumSalaryItemCode.Basic_Salary)); // EnumSalaryItemCode itemCode = EnumSalaryItemCode.Allowance; // groupCode = EnumSalaryGroup.Gross; // if (parameter.AllowOrDeductType == EnumAllowOrDeduct.Deduction) // { // itemCode = EnumSalaryItemCode.Deduction; // groupCode = EnumSalaryGroup.Deductions; // } // if (item.Arreartype == EnumArrearType.ToCalculate) groupCode = EnumSalaryGroup.Arrear; // SalaryMonthlyDetail detail = salary.GetDetail(groupCode, itemCode, parameter.AllowDeductID.Integer); // if (detail == null) // detail = this.AddDetail(salary, groupCode, itemCode, parameter.AllowDeductID.Integer, parameter.ID.Integer, parameter.AllowanceDeduction.Name, amount); // else // { // detail.CalculatedAmount = detail.CalculatedAmount + amount; // detail.CalculatedAmount = GlobalFunctions.Round(detail.CalculatedAmount); // detail.ChangedAmount = detail.CalculatedAmount; // } // detail.Position = item.AllowDeduct.Sequence + 1; //} //#endregion Individual Allowance } #endregion public static ObjectsTemplate GetDetail(DateTime _SalaryMonth) { #region Cache Header ObjectsTemplate oCarFuelProcessDetails = _cache["Get"] as ObjectsTemplate; if (oCarFuelProcessDetails != null) return oCarFuelProcessDetails; #endregion try { oCarFuelProcessDetails = Service.Get(_SalaryMonth); } catch (ServiceException e) { throw new Exception(e.Message, e); } #region Cache Footer _cache.Add(oCarFuelProcessDetails, "Get"); #endregion return oCarFuelProcessDetails; } } #endregion #region ICarFuelProcessDetail Service public interface ICarFuelProcessDetailService { CarFuelProcessDetail Get(ID id); ObjectsTemplate Get(); ID Save(CarFuelProcessDetail item); void Save(CarFuelProcess oProcess, ObjectsTemplate oPDetails); void Delete(ID id); ObjectsTemplate Get(DateTime _SalaryMonth); } #endregion }