using System; using Payroll.BO; using System.Data; using System.Linq; using Ease.CoreV35.Model; using System.Data.SqlClient; using Ease.CoreV35.DataAccess; using System.Collections.Generic; using Ease.CoreV35.DataAccess.SQL; using Ease.CoreV35.Utility; namespace Payroll.Service { #region BonusProcessDA internal class BonusProcessDA { #region Constructor private BonusProcessDA() { } #endregion #region Insert function internal static void Insert(TransactionContext tc, BonusProcess item,ID PayrollTypeID) { tc.ExecuteNonQuery("INSERT INTO BONUSPROCESS(BonusProcessID, bonusID, bonusMonth, basicOnMonth, disburseDate, remarks, showInWeb, CreatedBy, CreationDate,ISDISBURSEWITHSALARY,IsTaxProcess,UsedProcess,PayrollTypeID,FestivalDate,ReligionID)" + " VALUES(%n, %n, %d, %d, %d, %s, %n, %n, %d,%n,%n,%n,%n,%d,%n)", item.ID.Integer, item.BonusID.Integer, item.BonusMonth, item.BasicOnMonth, item.DisburseDate, item.Remarks, item.ShowInWeb, item.CreatedBy.Integer, DataReader.GetNullValue(item.CreatedDate), item.IsDisburseWithSalary, item.IsTaxProcess, item.UsedProcess, PayrollTypeID.Integer, DataReader.GetNullValue(item.FestivalDate), DataReader.GetNullValue(item.ReligionID, IDType.Integer)); } internal static void Insert(TransactionContext tc, BonusProcess.BonusProcessDetail item) { tc.ExecuteNonQuery("INSERT INTO BONUSPROCESSDETAIL(BonusProcessDetailID, bonusProcessID, bonusID, employeeID, disburseDate, BonusAmount, BasicSalary, ChangeBonusAmount, ChangeTaxAmount, ChangeAdjustAmount,ChangeSalaryItemAmount,CalculatedAdjustAmount,calculatedSalaryItemAmount,TaxAmount)" + " VALUES(%n, %n, %n, %n, %d, %n, %n, %n, %n, %n,%n,%n,%n,%n)", item.ID.Integer, item.BonusProcessID.Integer, item.BonusID.Integer, item.EmployeeID.Integer, item.BonusMonth, item.BonusAmount, item.BasicSalary, item.ChangeBonusAmount, item.ChangeTaxAmount, item.ChangeAdjustAmount, item.ChangeSalaryItemAmount, item.CalculatedAdjustAmount, item.CalculatedSalaryItemAmount, item.TaxAmount); } //internal static void Insert(TransactionContext tc, BonusProcess.BonusProcessDetail.BonusProcessSalaryItem item) //{ // tc.ExecuteNonQuery("INSERT INTO BonusProcessSalaryItem(BonusProcessDetailID,AllowDeductID,Amount,SalaryGroupCode)" + // " VALUES(%n,%n,%n,%n)", item.BonusProcessDetailID.Integer,item.AllowDeductID.Integer,item.Amount,item.SalaryGroupCode); //} //internal static void Insert(TransactionContext tc, BonusProcess.BonusProcessDetail.BonusProcessAdjustItem item) //{ // tc.ExecuteNonQuery("INSERT INTO BonusProcessAdjustItem(BonusProcessDetailID,BonusAdjustID,AdjustAmount)" + // " VALUES(%n,%n,%n)", item.BonusProcessDetailID.Integer, item.BonusAdjustID,item.AdjustAmount); //} //internal static void Insert(TransactionContext tc, BonusEmpCostCenter item) //{ // tc.ExecuteNonQuery("INSERT INTO BonusEmpCostCenter(BonusProcessID, COSTCENTERID, PERCENTAGE, EMPLOYEEID)" + // " VALUES( %n, %n, %n, %n)", item.BonusProcessID.Integer, item.CostCenterID.Integer, item.Percentage, item.EmployeeID.Integer); //} #endregion #region Update function internal static void Update(TransactionContext tc, BonusProcess item) { tc.ExecuteNonQuery("UPDATE BONUSPROCESS SET bonusID=%n, bonusMonth=%d, basicOnMonth=%d, disburseDate=%d, remarks=%s, showInWeb=%b, ModifiedBy=%n, ModifiedDate=%d,ISDISBURSEWITHSALARY=%n,IsTaxProcess=%n,UsedProcess=%n,FestivalDate=%d,ReligionID=%n " + " WHERE BonusProcessID=%n", item.BonusID.Integer, item.BonusMonth, item.BasicOnMonth, item.DisburseDate, item.Remarks, item.ShowInWeb, item.ModifiedBy.Integer, item.ModifiedDate, item.IsDisburseWithSalary, item.IsTaxProcess, item.UsedProcess,DataReader.GetNullValue(item.FestivalDate), DataReader.GetNullValue(item.ReligionID, IDType.Integer), item.ID.Integer); } internal static void Update(TransactionContext tc, BonusProcess.BonusProcessDetail item) { tc.ExecuteNonQuery("UPDATE BONUSPROCESSDETAIL SET bonusProcessID=%n,bonusID=%n, employeeID=%n, disburseDate=%d, BonusAmount=%n, BasicSalary=%n, ChangeBonusAmount=%n, ChangeTaxAmount=%n, ChangeSalaryItemAmount=%n,CalculatedAdjustAmount=%n,calculatedSalaryItemAmount=%n,TaxAmount=%n" + " WHERE BonusProcessDetailID=%n", item.BonusProcessID.Integer, item.BonusID.Integer, item.EmployeeID.Integer, item.BonusMonth, item.BonusAmount, item.BasicSalary, item.ChangeBonusAmount, item.ChangeTaxAmount, item.ChangeSalaryItemAmount, item.CalculatedAdjustAmount, item.CalculatedSalaryItemAmount, item.TaxAmount, item.ID.Integer); } #endregion #region Get Function // GetBonusAmountWithinYear internal static double GetBonusAmount(TransactionContext tc, DateTime bonusMonthFirstDate, ID employeeID, int bonusID, ID PayrollTypeID) { object bonusAmount = tc.ExecuteScalar("select BonusAmount from BonusProcessDetail WHERE EmployeeID =%n AND BonusID=%n AND BonusProcessID = (select BonusProcessID from BonusProcess Where BonusMonth = %d AND PayrollTypeID=%n)", employeeID.Integer, bonusID, bonusMonthFirstDate, PayrollTypeID.Integer); double amount = 0; if (bonusAmount != DBNull.Value) { amount = Convert.ToDouble(bonusAmount); } return amount; } internal static double GetUsedBonusWithinYear(TransactionContext tc, DateTime bonusMonthFirstDate, int bonusID, ID PayrollTypeID) { DateTime firstDateOfYear = Global.DateFunctions.FirstDateOfYear(bonusMonthFirstDate); DateTime lastDateOfYear = Global.DateFunctions.LastDateOfYear(bonusMonthFirstDate); object bonusAmount = tc.ExecuteScalar("select SUM(UsedProcess) from BONUSPROCESS where BONUSID=%n and BONUSMONTH Between %d and %d AND PayrollTypeID=%n", bonusID, firstDateOfYear, lastDateOfYear, PayrollTypeID.Integer); double amount = 0; if (bonusAmount != DBNull.Value) { amount = Convert.ToDouble(bonusAmount); } return amount; } internal static double GetBonusAmountWithinYear(TransactionContext tc, DateTime bonusYearDate, ID employeeID, int bonusID, ID PayrollTypeID) { DateTime firstDateOfYear = Global.DateFunctions.FirstDateOfYear(bonusYearDate); DateTime lastDateOfYear = Global.DateFunctions.LastDateOfYear(bonusYearDate); string strSql = SQLParser.MakeSQL("select SUM(BonusAmount) from BonusProcessDetail" + " WHERE EmployeeID =%n AND BonusID=%n AND BonusProcessID " + " IN (select BonusProcessID from BonusProcess Where BonusMonth BETWEEN %d AND %d AND PayrollTypeID=%n)", employeeID.Integer, bonusID, firstDateOfYear, lastDateOfYear, PayrollTypeID.Integer); object bonusAmount = tc.ExecuteScalar(strSql); double amount = 0; if (bonusAmount != DBNull.Value) { amount = Convert.ToDouble(bonusAmount); } return amount; } internal static double GetBonusPaidAmount(TransactionContext tc, DateTime date1, DateTime date2, ID employeeID, int bonusID) { string strSql = SQLParser.MakeSQL("select SUM(BonusAmount) from BonusProcessDetail" + " WHERE EmployeeID =%n AND BonusID=%n AND BonusProcessID " + " IN (select BonusProcessID from BonusProcess Where BonusMonth BETWEEN %d AND %d )", employeeID.Integer, bonusID, date1, date2); object bonusAmount = tc.ExecuteScalar(strSql); double amount = 0; if (bonusAmount != DBNull.Value) { amount = Convert.ToDouble(bonusAmount); } return amount; } internal static double GetBonusAmountWithinYear(TransactionContext tc, DateTime bonusYearDate, ID employeeID, int bonusID, ID PayrollTypeID, int nRelogionID) { DateTime firstDateOfYear = Global.DateFunctions.FirstDateOfYear(bonusYearDate); DateTime lastDateOfYear = Global.DateFunctions.LastDateOfYear(bonusYearDate); //string strSql = SQLParser.MakeSQL("select SUM(BonusAmount) from BonusProcessDetail" // + " WHERE EmployeeID =%n AND BonusID=%n AND BonusProcessID " // + " IN (select BonusProcessID from BonusProcess Where BonusMonth BETWEEN %d AND %d AND PayrollTypeID=%n and RELIGIONID=%n)", employeeID.Integer, bonusID, firstDateOfYear, lastDateOfYear, PayrollTypeID.Integer,nRelogionID); string strSql = SQLParser.MakeSQL("select SUM(BonusAmount) from BonusProcessDetail" + " WHERE EmployeeID =%n AND BonusID=%n AND BonusProcessID " + " IN (select BonusProcessID from BonusProcess Where BonusMonth BETWEEN %d AND %d AND PayrollTypeID=%n )", employeeID.Integer, bonusID, firstDateOfYear, lastDateOfYear, PayrollTypeID.Integer); object bonusAmount = tc.ExecuteScalar(strSql); double amount = 0; if (bonusAmount != DBNull.Value) { amount = Convert.ToDouble(bonusAmount); } return amount; } internal static double GetKPIBonusAmountWithinYear(TransactionContext tc, DateTime bonusYearDate, ID employeeID, int bonusID, ID PayrollTypeID, int nRelogionID) { DateTime firstDateOfYear = Global.DateFunctions.FirstDateOfYear(bonusYearDate); DateTime lastDateOfYear = Global.DateFunctions.LastDateOfYear(bonusYearDate); string strSql = SQLParser.MakeSQL(@"SELECT SUM(bpd.BonusAmount) FROM BONUSPROCESS bp, bonusprocessdetail bpd, bonusprocessadjustitem ai WHERE bp.BONUSPROCESSID=bpd.BonusProcessID AND bpd.BonusProcessDetailID=ai.BonusProcessDetailID and bpd.EmployeeID=%n And bp.BonusID=%n AND BonusMonth between %d and %d AND PayrollTypeID=%n AND ai.BonusAdjustID=%n", employeeID.Integer, bonusID, firstDateOfYear, lastDateOfYear, PayrollTypeID.Integer, nRelogionID); object bonusAmount = tc.ExecuteScalar(strSql); double amount = 0; if (bonusAmount != DBNull.Value) { amount = Convert.ToDouble(bonusAmount); } return amount; } internal static double GetPreviousKPIBonusAmount(TransactionContext tc, ID employeeID, int bonusID, string bonusProcessIDs, ID PayrollTypeID) { string strSql = SQLParser.MakeSQL(@"SELECT SUM(bpd.BonusAmount) FROM BONUSPROCESS bp, bonusprocessdetail bpd WHERE bp.BONUSPROCESSID=bpd.BonusProcessID and bpd.EmployeeID=%n And bp.BonusID=%n AND bp.PayrollTypeID=%n AND bp.BONUSPROCESSID in (%q)", employeeID.Integer, bonusID, PayrollTypeID.Integer, bonusProcessIDs); object bonusAmount = tc.ExecuteScalar(strSql); double amount = 0; if (bonusAmount != DBNull.Value) { amount = Convert.ToDouble(bonusAmount); } return amount; } internal static double GetKPIBonusAmountWithinYearPercent(TransactionContext tc, DateTime bonusYearDate, ID employeeID, int bonusID, ID PayrollTypeID, int nRelogionID) { DateTime firstDateOfYear = Global.DateFunctions.FirstDateOfYear(bonusYearDate); DateTime lastDateOfYear = Global.DateFunctions.LastDateOfYear(bonusYearDate); string strSql = SQLParser.MakeSQL(@"SELECT AdjustAmount FROM BONUSPROCESS bp, bonusprocessdetail bpd, bonusprocessadjustitem ai WHERE bp.BONUSPROCESSID=bpd.BonusProcessID AND bpd.BonusProcessDetailID=ai.BonusProcessDetailID and bpd.EmployeeID=%n And bp.BonusID=%n AND BonusMonth between %d and %d AND PayrollTypeID=%n AND ai.BonusAdjustID=%n", employeeID.Integer, bonusID, firstDateOfYear, lastDateOfYear, PayrollTypeID.Integer, nRelogionID); object bonusAmount = tc.ExecuteScalar(strSql); double amount = 0; if (bonusAmount != DBNull.Value) { amount = Convert.ToDouble(bonusAmount); } return amount; } internal static IDataReader Get(TransactionContext tc, EnumStatus status, ID PayrollTypeID) { if (EnumStatus.Active == status || EnumStatus.Inactive == status) { return tc.ExecuteReader("SELECT * FROM BONUSPROCESS Where Status=%n AND PayrollTypeID=%n Order By SequenceNo", status, PayrollTypeID.Integer); } else { return tc.ExecuteReader("SELECT * FROM BONUSPROCESS Where PayrollTypeID=%n Order By SequenceNo", PayrollTypeID.Integer); } } internal static IDataReader GetProcess(TransactionContext tc, ID PayrollTypeID) { return tc.ExecuteReader("SELECT * FROM BONUSPROCESS Where PayrollTypeID=%n", PayrollTypeID.Integer); } internal static IDataReader GetProcess(TransactionContext tc, DateTime dBonusMonth, ID PayrollTypeID) { return tc.ExecuteReader("SELECT * FROM BONUSPROCESS Where BonusMonth=%d AND PayrollTypeID=%n", dBonusMonth, PayrollTypeID.Integer); } internal static IDataReader GetProcess(TransactionContext tc, ID nBonusID, DateTime dBonusMonth, ID PayrollTypeID) { return tc.ExecuteReader("SELECT * FROM BONUSPROCESS WHERE BonusID=%n AND DisburseDate between %d and %d AND PayrollTypeID=%n", nBonusID.Integer,GlobalFunctions.FirstDateOfMonth(dBonusMonth),GlobalFunctions.LastDateOfMonth(dBonusMonth), PayrollTypeID.Integer); //return tc.ExecuteReader("SELECT * FROM BONUSPROCESS Where BonusMonth=%d AND PayrollTypeID=%n", dBonusMonth, Payroll.BO.SystemInformation.CurrentSysInfo.PayrollTypeID.Integer); } internal static IDataReader Get(TransactionContext tc, ID nID, ID PayrollTypeID) { return tc.ExecuteReader("SELECT * FROM BONUSPROCESS WHERE BonusProcessID=%n AND PayrollTypeID=%n", nID.Integer, PayrollTypeID.Integer); } internal static IDataReader Get(TransactionContext tc, ID bonusID, DateTime bonusMonth, ID PayrollTypeID) { return tc.ExecuteReader("SELECT * FROM BONUSPROCESS WHERE BonusID=%n AND DisburseDate between %d and %d AND PayrollTypeID=%n", bonusID.Integer, GlobalFunctions.FirstDateOfMonth(bonusMonth), GlobalFunctions.LastDateOfMonth(bonusMonth), PayrollTypeID.Integer); } internal static IDataReader Get(TransactionContext tc, ID bonusID, DateTime bonusMonth, ID PayrollTypeID,int nQuarterID) { // return tc.ExecuteReader(@" SELECT TOP 1 bp.* FROM BONUSPROCESS bp, bonusprocessdetail bpd, bonusprocessadjustitem ai // WHERE bp.BONUSPROCESSID=bpd.BonusProcessID // AND bpd.BonusProcessDetailID=ai.BonusProcessDetailID and // bp.BonusID=%n // AND bp.DisburseDate between %d and %d AND PayrollTypeID=%n // AND ai.BonusAdjustID=%n", // bonusID.Integer, GlobalFunctions.FirstDateOfMonth(bonusMonth), GlobalFunctions.LastDateOfMonth(bonusMonth), PayrollTypeID.Integer, nQuarterID); if (nQuarterID > 0) { return tc.ExecuteReader(@" SELECT TOP 1 bp.* FROM BONUSPROCESS bp, bonusprocessdetail bpd WHERE bp.BONUSPROCESSID=bpd.BonusProcessID and bp.BonusID=%n And ReligionID=%n AND bp.DisburseDate between %d and %d AND PayrollTypeID=%n", bonusID.Integer, nQuarterID, GlobalFunctions.FirstDateOfMonth(bonusMonth), GlobalFunctions.LastDateOfMonth(bonusMonth), PayrollTypeID.Integer); } else { return tc.ExecuteReader(@" SELECT TOP 1 bp.* FROM BONUSPROCESS bp, bonusprocessdetail bpd WHERE bp.BONUSPROCESSID=bpd.BonusProcessID and bp.BonusID=%n AND bp.DisburseDate between %d and %d AND PayrollTypeID=%n", bonusID.Integer, GlobalFunctions.FirstDateOfMonth(bonusMonth), GlobalFunctions.LastDateOfMonth(bonusMonth), PayrollTypeID.Integer); } } internal static IDataReader GetBonusDetails(TransactionContext tc, ID nID, ID PayrollTypeID) { return tc.ExecuteReader("SELECT * FROM BONUSPROCESSDETAIL WHERE BonusProcessID=(Select BonusProcessID from BonusProcess where BonusProcessID=%n AND PayrollTypeID=%n)", nID.Integer, PayrollTypeID.Integer); } internal static IDataReader GetBonusDetailsByBonID(TransactionContext tc, ID nID, DateTime dBonusMonth) { return tc.ExecuteReader("SELECT * FROM BONUSPROCESSDETAIL WHERE BonusID=(Select Distinct BonusID from BONUSPROCESS where BonusID=%n AND PayrollTypeID=%n) and DisburseDate=%d", nID.Integer, Payroll.BO.SystemInformation.CurrentSysInfo.PayrollTypeID.Integer, GlobalFunctions.LastDateOfMonth(dBonusMonth)); } internal static IDataReader GetBonusDetails(TransactionContext tc, DateTime dMonth, ID PayrollTypeID) { return tc.ExecuteReader("Select BPD.* from BONUSPROCESS BP,BONUSPROCESSDETAIL BPD " + "WHERE BP.BonusProcessID = BPD.BonusProcessID AND BP.BonusMonth = %d " + "AND BP.PayrollTypeID=%n", dMonth, PayrollTypeID.Integer); } internal static IDataReader GetBonusDetails(TransactionContext tc, int nID) { return tc.ExecuteReader("Select * from BONUSPROCESSDETAIL BPD " + "WHERE BPD.BonusProcessID = %n", nID); } internal static IDataReader GetBonusDetails(TransactionContext tc, DateTime dMonth, bool bPayWithSalary, ID PayrollTypeID) { return tc.ExecuteReader("Select BPD.* from BONUSPROCESS BP,BONUSPROCESSDETAIL BPD " + "WHERE BP.BonusProcessID = BPD.BonusProcessID AND BP.bonusmonth = %d " + " AND BP.PayrollTypeID=%n", dMonth, PayrollTypeID.Integer); } internal static IDataReader GetBonusDetails(TransactionContext tc, DateTime dMonth, bool bPayWithSalary, ID PayrollTypeID,int nEmpID) { return tc.ExecuteReader("Select BPD.* from BONUSPROCESS BP,BONUSPROCESSDETAIL BPD " + "WHERE BP.BonusProcessID = BPD.BonusProcessID AND BP.disburseDate = %d " + " AND BP.PayrollTypeID=%n AND BPD.Employeeid=%n", dMonth, PayrollTypeID.Integer,nEmpID); } internal static IDataReader GetBonusDetails(TransactionContext tc, DateTime dMonth, int nEmpID, int nBonusID) { return tc.ExecuteReader("Select BPD.* from BONUSPROCESS BP,BONUSPROCESSDETAIL BPD " + "WHERE BP.BonusID=%n AND BP.BonusProcessID = BPD.BonusProcessID AND BP.disburseDate between %d AND %d " + " AND BPD.Employeeid=%n", nBonusID,GlobalFunctions.FirstDateOfYear(dMonth), dMonth, nEmpID); } internal static IDataReader GetSumOfBonusDetails(TransactionContext tc, DateTime fromMonth, DateTime toMonth, ID PayrollTypeID) { return tc.ExecuteReader("Select BPD.bonusID, employeeID, SUM(ChangeBonusAmount-ChangeTaxAmount) BonusAmount, count(*) Count from BONUSPROCESS BP,BONUSPROCESSDETAIL BPD " + "WHERE BP.BonusProcessID = BPD.BonusProcessID AND BP.BonusMonth BETWEEN %d AND %d " + " AND BP.PayrollTypeID=%n group by EmployeeID, BPD.BonusID ", fromMonth, toMonth, PayrollTypeID.Integer); } //internal static IDataReader GetBProcessSalaryItem(TransactionContext tc, ID nBonusProID) //{ // return tc.ExecuteReader("Select * FROM BonusProcessSalaryItem WHERE BonusProcessDetailID IN ( Select BONUSPROCESSDETAILID " // + " from BonusProcessDetail WHERE BonusProcessID=%n)", nBonusProID.Integer); //} //internal static IDataReader GetBProcessAdjust(TransactionContext tc, ID nBonusProID) //{ // return tc.ExecuteReader("Select * FROM BonusProcessAdjustItem WHERE BonusProcessDetailID IN ( Select BONUSPROCESSDETAILID " // + " from BonusProcessDetail WHERE BonusProcessID=%n)", nBonusProID.Integer); //} //internal static IDataReader GetEmpCostCenter(TransactionContext tc, ID nID) //{ // return tc.ExecuteReader("SELECT * FROM BonusEmpCostCenter WHERE BonusProcessID=%n", nID.Integer); //} internal static DataSet GetBonusRegisterCarFuel(TransactionContext tc, DateTime dBonusMonth, string sEmpID) { DataSet oBankAdvices = new DataSet(); try { string sSQL = SQLParser.MakeSQL(@"SELECT e.EmployeeNo,e.Name,od.AccountNo, e.GROSSSALARY,e.JOININGDATE,e.BASICSALARY,odi.TaxAmount,odi.ChangeNetAmount, Sum(odi.ChangeNetAmount) AS Amount FROM Employee e Left Join CarFuelProcessDetail od on e.EmployeeID = od.EmployeeID LEFT JOIN CarFuelProcess o ON od.CarFuelProcessID = o.CarFuelProcessID LEFT JOIN CarFuelProcessDetailItem odi ON od.CarFuelProcessDetailID = odi.CarFuelProcessDetailID LEFT JOIN BANKS AS b ON b.BANKID=od.BankID WHERE o.CarFuelMonth = %d AND odi.CarFuelType = %n AND od.EmployeeID IN(%q) GROUP BY e.EmployeeNo,e.Name,od.AccountNo, e.GROSSSALARY,e.JOININGDATE,e.BASICSALARY,odi.TaxAmount,odi.ChangeNetAmount", dBonusMonth, (int)EnumCarFuelType.Payment, sEmpID); oBankAdvices = tc.ExecuteDataSet(sSQL); } catch (Exception ex) { throw new Exception(ex.Message); } return oBankAdvices; } internal static DataSet GetBonusRegister(TransactionContext tc, ID BonusID, DateTime dBonusMonth, string sEmpID, ID PayrollTypeID) { DataSet oBonusRegs = new DataSet(); oBonusRegs = tc.ExecuteDataSet(@"SELECT Emp.EMPLOYEENO,Emp.NAME,Emp.GROSSSALARY,Emp.JOININGDATE,BP.BONUSMONTH,BPD.BasicSalary,BPD.ChangeBonusAmount,BPD.ChangeTaxAmount, datediff(yy,Emp.JOININGDATE,BPD.DisburseDate) ServiceLength, ACCOUNTNO FROM EMPLOYEE AS Emp,BonusProcessDetail AS BPD,BONUSPROCESS as BP WHERE Emp.EMPLOYEEID =BPD.EmployeeID AND bp.BonusProcessID=bpd.BonusProcessID and BPD.BonusID=BP.BonusID AND BP.BonusID=%n AND BP.PayrollTypeID=%n AND BPD.DisburseDate between %d and %d AND Emp.EMPLOYEEID IN (%q) Order By Emp.EMPLOYEENO", BonusID.Integer, PayrollTypeID.Integer, dBonusMonth, GlobalFunctions.LastDateOfMonth(dBonusMonth), sEmpID); return oBonusRegs; } internal static DataSet GetBonusBankAdvice(TransactionContext tc, ID BonusID, DateTime dBonusMonth, string sEmpID, ID PayrollTypeID) { DataSet oBonusRegs = new DataSet(); string sBonus = SQLParser.MakeSQL(@"SELECT distinct Emp.EMPLOYEENO,Emp.NAME,Emp.ACCOUNTNO,Emp.EMAILADDRESS, (BPD.ChangeBonusAmount-BPD.ChangeTaxAmount) as Amount,'' AS CostCenter FROM EMPLOYEE AS Emp,BonusProcessDetail AS BPD WHERE Emp.EMPLOYEEID =BPD.EmployeeID AND BPD.BonusID=(Select Distinct BonusID from BONUSPROCESS where BonusID=%n AND PayrollTypeID=%n) AND BPD.DisburseDate between %d and %d AND Emp.EMPLOYEEID IN (%q) AND Emp.ACCOUNTNO<>'' Order By Emp.EMPLOYEENO", BonusID.Integer, PayrollTypeID.Integer, GlobalFunctions.FirstDateOfMonth(dBonusMonth), GlobalFunctions.LastDateOfMonth(dBonusMonth), sEmpID); oBonusRegs = tc.ExecuteDataSet(sBonus); return oBonusRegs; } internal static DataSet GetBonusPaySlip(TransactionContext tc, ID BonusID, DateTime dBonusMonth, string sEmpID, ID PayrollTypeID) { DataSet oBonusPaySlip = new DataSet(); oBonusPaySlip = tc.ExecuteDataSet("SELECT Emp.EMPLOYEENO,Emp.accountno,Emp.branchid,Emp.NAME,Emp.PAYMENTMODE,Dept.DESCRIPTION as Department,Degs.NAME as Designation,BPD.BasicSalary,BPD.BonusAmount,BPD.TaxAmount" + " FROM EMPLOYEE AS Emp,BonusProcessDetail AS BPD,DEPARTMENT as Dept,DESIGNATION as Degs" + " WHERE Emp.EMPLOYEEID =BPD.EmployeeID" + " AND Emp.DEPARTMENTID =Dept.DEPARTMENTID" + " AND Emp.DESIGNATIONID =Degs.DESIGNATIONID" + " AND BPD.BonusID=(Select Distinct BonusID from BONUSPROCESS where BonusID=%n AND PayrollTypeID=%n)" + " AND BPD.DisburseDate between %d and %d AND Emp.EMPLOYEEID IN (%q) Order By Emp.EMPLOYEENO", BonusID.Integer, PayrollTypeID.Integer, dBonusMonth, GlobalFunctions.LastDateOfMonth(dBonusMonth), sEmpID); return oBonusPaySlip; } internal static DataSet GetOldBonusPaySlip(TransactionContext tc, ID BonusID, DateTime dBonusMonth, string sEmpID, ID PayrollTypeID) { DataSet oBonusPaySlip = new DataSet(); oBonusPaySlip = tc.ExecuteDataSet("SELECT Emp.EMPLOYEENO,Emp.accountno,Emp.branchid,Emp.NAME,Emp.PAYMENTMODE,Dept.DESCRIPTION as Department,Degs.NAME as Designation,BPD.BasicSalary,BPD.BonusAmount,BPD.TaxAmount" + " FROM GP_EMPLOYEE AS Emp, BonusProcessDetail AS BPD, GP_DEPARTMENT as Dept, GP_DESIGNATION as Degs" + " WHERE Emp.EMPLOYEEID =BPD.EmployeeID" + " AND Emp.DEPARTMENTID =Dept.DEPARTMENTID" + " AND Emp.DESIGNATIONID =Degs.DESIGNATIONID" + " AND BPD.BonusID=(Select Distinct BonusID from BONUSPROCESS where BonusID=%n AND PayrollTypeID=%n)" + " AND BPD.DisburseDate between %d and %d AND Emp.EMPLOYEEID IN (%q) Order By Emp.EMPLOYEENO", BonusID.Integer, PayrollTypeID.Integer, dBonusMonth, GlobalFunctions.LastDateOfMonth(dBonusMonth), sEmpID); return oBonusPaySlip; } internal static DataSet GetOldBonusRegister(TransactionContext tc, ID BonusID, DateTime dBonusMonth, string sEmpID, ID PayrollTypeID) { DataSet oBonusRegs = new DataSet(); oBonusRegs = tc.ExecuteDataSet("SELECT Emp.EMPLOYEENO, Emp.Accountno, Emp.Branchid, Emp.NAME, Emp.PAYMENTMODE, Emp.JOININGDATE, BPD.EMPBASIC, BPD.AMOUNT, BPD.TAXAMOUNT, datediff(yy,Emp.JOININGDATE,BPD.PAYDATE) ServiceLength, ACCOUNTNO " + " FROM GP_EMPLOYEE AS Emp, GP_BonusPayDetail AS BPD " + " WHERE Emp.EMPLOYEEID = BPD.EmployeeID " + " AND BPD.PAYDATE between %d and %d AND Emp.EMPLOYEEID IN (%q) Order By Emp.EMPLOYEENO ", dBonusMonth, GlobalFunctions.LastDateOfMonth(dBonusMonth), sEmpID); return oBonusRegs; } internal static int GetForNoOfPaid(TransactionContext tc, DateTime bonusYear, int nID, ID PayrollTypeID) { DateTime firstDateOfYear = Global.DateFunctions.FirstDateOfYear(bonusYear); DateTime lastDateOfYear = Global.DateFunctions.LastDateOfYear(bonusYear); object oPaidItem = tc.ExecuteScalar("Select count(*) from BONUSPROCESS where BONUSMONTH between %d and %d and BONUSID=%n AND PayrollTypeID=%n", firstDateOfYear, lastDateOfYear, nID, PayrollTypeID.Integer); int nPaidItem = 0; if (oPaidItem != DBNull.Value) { nPaidItem = Convert.ToInt32(oPaidItem); } return nPaidItem; } internal static int GetForNoOfPaidForEmp(TransactionContext tc, DateTime bonusYear, int nID, int EmpID, ID PayrollTypeID) { DateTime firstDateOfYear = Global.DateFunctions.FirstDateOfYear(bonusYear); DateTime lastDateOfYear = Global.DateFunctions.LastDateOfYear(bonusYear); object oPaidItem = tc.ExecuteScalar(@"SELECT COUNT (*) FROM BONUSPROCESSDETAIL b WHERE b.EmployeeID=%n AND b.BonusProcessID IN (Select bonusProcessID from BONUSPROCESS where BONUSMONTH between %d and %d and BONUSID=%n AND PayrollTypeID=%n)",EmpID, firstDateOfYear, lastDateOfYear, nID, PayrollTypeID.Integer); int nPaidItem = 0; if (oPaidItem != DBNull.Value) { nPaidItem = Convert.ToInt32(oPaidItem); } return nPaidItem; } internal static void Insert(TransactionContext tc, BonusProcess.BonusProcessDetail.BonusProcessAdjustItem item) { tc.ExecuteNonQuery("INSERT INTO BonusProcessAdjustItem(BonusProcessDetailID,BonusAdjustID,AdjustAmount)" + " VALUES(%n,%n,%n)", item.BonusProcessDetailID.Integer, item.BonusAdjustID, item.AdjustAmount); } #endregion internal static IDataReader GetBProcessAdjust(TransactionContext tc, ID nBonusProDetailID) { return tc.ExecuteReader("Select * FROM BonusProcessAdjustItem WHERE BonusProcessDetailID=%n ", nBonusProDetailID.Integer); } internal static void DeletePAdjustItemByProcessDetailID(TransactionContext tc, ID nBonusProcesesID) { tc.ExecuteNonQuery("delete from BonusProcessAdjustItem where BonusProcessDetailID in(Select BonusProcessDetailID from BONUSPROCESSDETAIL where BonusProcessID=%n)", nBonusProcesesID.Integer); } #region Delete function internal static void Delete(TransactionContext tc, ID nID) { tc.ExecuteNonQuery("DELETE FROM [BONUSPROCESS] WHERE BonusProcessID=%n AND PayrollTypeID=%n", nID.Integer, Payroll.BO.SystemInformation.CurrentSysInfo.PayrollTypeID.Integer); } internal static void DeleteTax(TransactionContext tc, string sEmpID) { tc.ExecuteNonQuery("DELETE FROM INCOMETAXTEMP WHERE Employeeid in(%q) ", sEmpID); } internal static void DeleteBonusProcrss(TransactionContext tc, ID nbonusID, DateTime dBMonthDate, ID PayrollTypeID) { tc.ExecuteNonQuery("DELETE FROM [BONUSPROCESS] WHERE BONUSID=%n AND BONUSMONTH=%d AND PayrollTypeID=%n", nbonusID.Integer, GlobalFunctions.LastDateOfMonth(dBMonthDate), PayrollTypeID.Integer); } internal static void DeleteProcessDetailByProcessID(TransactionContext tc, ID nbonusID, ID nbonusProcessID, ID PayrollTypeID) { tc.ExecuteNonQuery("DELETE FROM [BonusProcessDetail] WHERE BonusID=%n AND BonusProcessID=(Select BonusProcessID from BonusProcess where BonusProcessID=%n AND PayrollTypeID=%n)", nbonusID.Integer, nbonusProcessID.Integer, PayrollTypeID.Integer); } //internal static void DeletePAdjustItemByProcessDetailID(TransactionContext tc, ID nBonusProcesesID) //{ // tc.ExecuteNonQuery("delete from BonusProcessAdjustItem where BonusProcessDetailID in(Select BonusProcessDetailID from BONUSPROCESSDETAIL where BonusProcessID=%n)", nBonusProcesesID.Integer); //} //internal static void DeletePSalaryItemByProcessDetailID(TransactionContext tc, ID nBonusProcessID) //{ // tc.ExecuteNonQuery("delete from BonusProcessSalaryItem where BonusProcessDetailID in(Select BonusProcessDetailID from BONUSPROCESSDETAIL where BonusProcessID=%n)", nBonusProcessID.Integer); //} //internal static void DeleteSalaryEmpCC(TransactionContext tc, ID nID) //{ // tc.ExecuteNonQuery("DELETE FROM BonusEmpCostCenter WHERE BonusProcessID=%n", nID.Integer); //} internal static void UndoProcess(TransactionContext tc, BonusProcess oBonusPro, ID PayrollTypeID) { // tc.ExecuteNonQuery("DELETE FROM BonusEmpCostCenter WHERE BonusProcessID=%n", oBonusPro.ID.Integer); //tc.ExecuteNonQuery("DELETE FROM BonusProcessAdjustItem WHERE BonusProcessDetailID IN ( Select BONUSPROCESSDETAILID " // + " from BonusProcessDetail WHERE BonusProcessID=%n)", oBonusPro.ID.Integer); //tc.ExecuteNonQuery("DELETE FROM BonusProcessSalaryItem WHERE BonusProcessDetailID IN ( Select BONUSPROCESSDETAILID " // + " from BonusProcessDetail WHERE BonusProcessID=%n)", oBonusPro.ID.Integer); tc.ExecuteNonQuery("DELETE FROM BonusProcessAdjustItem WHERE BonusProcessDetailID IN ( Select BONUSPROCESSDETAILID " + " from BonusProcessDetail WHERE BonusProcessID=%n)", oBonusPro.ID.Integer); tc.ExecuteNonQuery("DELETE FROM BonusProcessDetail WHERE BonusProcessID=(Select BonusProcessID from BONUSPROCESS where BonusProcessID=%n AND PayrollTypeID=%n)", oBonusPro.ID.Integer, PayrollTypeID.Integer); tc.ExecuteNonQuery("DELETE FROM BONUSPROCESS WHERE BonusProcessID=%n AND PayrollTypeID=%n", oBonusPro.ID.Integer, PayrollTypeID.Integer); } #endregion internal static DataSet GetMontlyProdBonus(TransactionContext tc, DateTime dBonusMonth) { DataSet oPrdBonus = new DataSet(); oPrdBonus = tc.ExecuteDataSet(@"SELECT e.EMPLOYEENO,e.[NAME],e.DEPARTMENTID,dpt.[DESCRIPTION] Department,dsg.[NAME] Designation,Sum(pbpe.Amount) Amount FROM ProdBonusProcessEmp pbpe, ProdBonusProcess pbp,Employee e, DESIGNATION dsg, DEPARTMENT dpt WHERE pbpe.ProdBonusProcessID=pbp.ProdBonusProcessID AND pbpe.EmployeeID=e.EMPLOYEEID AND e.DEPARTMENTID=dpt.DEPARTMENTID AND e.DESIGNATIONID=dsg.DESIGNATIONID AND pbp.SalaryMonth BETWEEN %d and %d Group By e.EMPLOYEENO,e.[NAME],e.DEPARTMENTID,dpt.[DESCRIPTION],dsg.[NAME] Order By e.EMPLOYEENO", GlobalFunctions.FirstDateOfMonth(dBonusMonth),GlobalFunctions.LastDateOfMonth(dBonusMonth)); return oPrdBonus; } internal static DataSet GetProdBonusDetail(TransactionContext tc, int designID) { DataSet oPrdBonus = new DataSet(); oPrdBonus = tc.ExecuteDataSet(@"SELECT e.EMPLOYEENO,e.[NAME],e.DEPARTMENTID,dpt.[DESCRIPTION] Department,dsg.[NAME] Designation,pbpe.Amount,pbpe.WorkingHour,pbpe.OTHour,pbl.ScheduledHour FROM ProdBonusProcessItem pbpe,ProdBonusLine pbl, ProdBonusProcess pbp,Employee e, DESIGNATION dsg, DEPARTMENT dpt WHERE pbl.ProdBonusLineID= pbpe.ProdBonusLineID AND pbpe.ProdBonusProcessID=pbp.ProdBonusProcessID AND pbpe.EmployeeID=e.EMPLOYEEID AND e.DEPARTMENTID=dpt.DEPARTMENTID AND e.DESIGNATIONID=dsg.DESIGNATIONID AND pbpe.ProdBonusSetupID=%n Order By e.EMPLOYEENO", designID ); return oPrdBonus; } internal static DataSet EmpDesignWiseProdBonus(TransactionContext tc, DateTime dBonusMonth) { DataSet oPrdBonus = new DataSet(); oPrdBonus = tc.ExecuteDataSet(@"SELECT pbs.DesignNo,pbs.FromDate StartDate,pbs.ToDate EndDate, e.EMPLOYEENO,e.[NAME],e.DEPARTMENTID,dpt.[DESCRIPTION] Department,dsg.[NAME] Designation,SUM(pbpe.Amount) Amount,pbpe.WorkingHour,pbpe.OTHour,pbl.ScheduledHour FROM ProductionBonusSetup pbs, ProdBonusProcessItem pbpe,ProdBonusLine pbl, ProdBonusProcess pbp,Employee e, DESIGNATION dsg, DEPARTMENT dpt WHERE pbs.ProductionBonusSetupID=pbpe.ProdBonusSetupID AND pbs.ProductionBonusSetupID=pbl.ProdBonusSetupID AND pbl.ProdBonusLineID= pbpe.ProdBonusLineID AND pbpe.ProdBonusProcessID=pbp.ProdBonusProcessID AND pbpe.EmployeeID=e.EMPLOYEEID AND e.DEPARTMENTID=dpt.DEPARTMENTID AND e.DESIGNATIONID=dsg.DESIGNATIONID AND pbp.SalaryMonth BETWEEN %d and %d GROUP BY pbs.DesignNo,pbs.FromDate ,pbs.ToDate , e.EMPLOYEENO,e.[NAME],e.DEPARTMENTID,dpt.[DESCRIPTION],dsg.[NAME],pbpe.WorkingHour,pbpe.OTHour,pbl.ScheduledHour Order By e.EMPLOYEENO", GlobalFunctions.FirstDateOfMonth(dBonusMonth), GlobalFunctions.LastDateOfMonth(dBonusMonth)); return oPrdBonus; } internal static IDataReader GetProcess(TransactionContext tc, DateTime fromMonth, DateTime toDate, ID religionID, ID bonusID, int payrollTypeID) { return tc.ExecuteReader("SELECT * FROM BONUSPROCESS WHERE BonusID=%n AND DisburseDate between %d AND %d AND ReligionID=%n AND PayrollTypeID=%n", bonusID.Integer, fromMonth,toDate,religionID, payrollTypeID); } } #endregion }