260 lines
13 KiB
C#
260 lines
13 KiB
C#
using HRM.BO;
|
|
using Ease.Core.DataAccess;
|
|
using System;
|
|
using System.Data;
|
|
|
|
|
|
namespace HRM.DA
|
|
{
|
|
#region SalaryProcessDA
|
|
|
|
internal class SalaryProcessDA
|
|
{
|
|
#region Constructor
|
|
|
|
private SalaryProcessDA()
|
|
{
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Insert function
|
|
|
|
internal static void Insert(TransactionContext tc, SalaryProcess item)
|
|
{
|
|
tc.ExecuteNonQuery(
|
|
"INSERT INTO SalaryProcess(SalaryProcessID, SalaryMonth, ProcessDate, ProcessCode,ShowInDeskTop,"
|
|
+ " Remarks, PaymentDate, WorkDays, IsFinalized, PayrollTypeID,"
|
|
+ " CreatedBy, CreationDate,MONTHENDDATE,userid)" +
|
|
" VALUES(%n, %d, %d, %s, %n, %s, "
|
|
+ " %d, %n, %b, %n, %n, %d,%d,%n)",
|
|
item.ID, item.SalaryMonth, item.ProcessDate, item.ProcessCode, item.ShowInDesktops, item.Remarks,
|
|
DataReader.GetNullValue(item.PaymentDate), item.WorkDays, item.IsFinalized, item.PayrollTypeID,
|
|
item.CreatedBy, item.CreatedDate, DataReader.GetNullValue(item.MonthEndDate), item.CreatedBy);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Update function
|
|
|
|
internal static DataTable SalaryHeadCount(TransactionContext tc, DateTime salaryMonth, int payrolltypeID)
|
|
{
|
|
return tc.ExecuteDataTable(
|
|
@"select count(e.employeeid), (select count(s.employeeid) from SALARYMONTHLY s where s.SALARYMONTH =%d and s.PAYROLLTYPEID=%n)
|
|
from employee e where e.STATUS = 1 and e.PAYROLLTYPEID=%n", salaryMonth, payrolltypeID,payrolltypeID );
|
|
}
|
|
|
|
internal static void Update(TransactionContext tc, SalaryProcess item)
|
|
{
|
|
tc.ExecuteNonQuery(
|
|
"UPDATE SalaryProcess SET SalaryMonth=%d, ProcessDate=%d, ProcessCode=%s, Remarks=%s, PaymentDate=%d, WorkDays=%n, ISFINALIZED=%b, PayrollTypeID=%n, ModifiedBy=%n, ModifiedDate=%d,MONTHENDDATE=%d" +
|
|
" WHERE SalaryProcessID=%n", item.SalaryMonth, item.ProcessDate, item.ProcessCode, item.Remarks,
|
|
item.PaymentDate, item.WorkDays, item.IsFinalized, item.PayrollTypeID, item.ModifiedBy,
|
|
item.ModifiedDate, item.MonthEndDate, item.ID);
|
|
}
|
|
|
|
internal static void SPApprove(TransactionContext tc, SalaryProcess oSProcess)
|
|
{
|
|
tc.ExecuteNonQuery("UPDATE SalaryProcess SET SHOWINDESKTOP=%n,ShowInDesktopDate=%d" +
|
|
" WHERE SalaryMonth=%d and SalaryProcessID=%n", oSProcess.ShowInDesktops,
|
|
oSProcess.ShowInDesktopDate, oSProcess.SalaryMonth, oSProcess.ID);
|
|
}
|
|
|
|
internal static void ApproveSalary(TransactionContext tc, DateTime salaryMonth, int payrollTypeid)
|
|
{
|
|
tc.ExecuteNonQuery("UPDATE SalaryProcess SET SHOWINDESKTOP=%b, ShowInDesktopDate=%D" +
|
|
" WHERE SalaryMonth=%d and payrollTypeID=%n", true,
|
|
DateTime.Today, salaryMonth, payrollTypeid);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Get Function
|
|
|
|
internal static IDataReader GetUnApprovedSalaries(TransactionContext tc, DateTime dMonthDate, int payrollTypeID)
|
|
{
|
|
return tc.ExecuteReader("SELECT *, (select Count(*) Count From SalaryMonthly where SalaryProcessID=SalaryProcess.SalaryProcessID) Count FROM SalaryProcess Where IsFinalized=%b and SalaryMonth = %d And PayrollTypeID=%n",
|
|
false, dMonthDate, payrollTypeID);
|
|
}
|
|
internal static IDataReader Get(TransactionContext tc, DateTime dMonthDate, int payrollTypeID)
|
|
{
|
|
return tc.ExecuteReader("SELECT * FROM SalaryProcess Where SalaryMonth = %d And PayrollTypeID=%n",
|
|
dMonthDate, payrollTypeID);
|
|
}
|
|
internal static IDataReader Get(TransactionContext tc)
|
|
{
|
|
return tc.ExecuteReader("SELECT * FROM SalaryProcess");
|
|
}
|
|
|
|
internal static IDataReader Get(TransactionContext tc, int nID)
|
|
{
|
|
return tc.ExecuteReader("SELECT * FROM SalaryProcess WHERE SalaryProcessID=%n", nID);
|
|
}
|
|
|
|
internal static bool GetBySMonth(TransactionContext tc, DateTime dSMonth, int payrollTypeID)
|
|
{
|
|
bool bShowInDesktop = false;
|
|
object obj =
|
|
tc.ExecuteScalar("Select SHOWINDESKTOP from SALARYPROCESS where SALARYMONTH=%d AND PAYROLLTYPEID=%n",
|
|
dSMonth, payrollTypeID);
|
|
if (obj == DBNull.Value) return false;
|
|
bShowInDesktop = Convert.ToInt32(obj) > 0 ? true : false;
|
|
return bShowInDesktop;
|
|
}
|
|
|
|
|
|
internal static bool MonthEndStatus(TransactionContext tc, DateTime dSMonth, int payrollTypeID)
|
|
{
|
|
bool bShowInDesktop = false;
|
|
object obj =
|
|
tc.ExecuteScalar("Select ISFINALIZED from SALARYPROCESS where SALARYMONTH=%d AND PAYROLLTYPEID=%n",
|
|
dSMonth, payrollTypeID);
|
|
if (obj == DBNull.Value) return false;
|
|
bShowInDesktop = Convert.ToInt32(obj) > 0 ? true : false;
|
|
return bShowInDesktop;
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
#region Delete function
|
|
|
|
internal static void Delete(TransactionContext tc, int nID)
|
|
{
|
|
tc.ExecuteNonQuery("DELETE FROM SalaryProcess WHERE SalaryProcessID=%n", nID);
|
|
}
|
|
|
|
|
|
internal static void MonthEnd(TransactionContext tc, DateTime salaryMonth, int payrollTypeID, int userid)
|
|
{
|
|
tc.ExecuteNonQuery("UPDATE SalaryProcess SET ISFINALIZED =%b, MonthEndDate=%D, UserID=%n WHERE SalaryMonth=%d AND PayrollTypeID=%n",
|
|
true, DateTime.Now, userid, salaryMonth, payrollTypeID);
|
|
//tc.ExecuteNonQuery("UPDATE SalaryMonthly SET ISFINALIZED =%b WHERE SalaryMonth=%d AND PayrollTypeID=%n",
|
|
// true, salaryMonth, payrollTypeID);
|
|
tc.ExecuteNonQuery(
|
|
"Update GradeSalaryAssignment Set ArrearInfo = %n Where ArrearInfo = %n AND GradeSalaryAssignment.EmployeeID IN "
|
|
+ " (SELECT Employee.EmployeeID FROM Employee WHERE PayrollTypeID=%n)",
|
|
EnumArrearType.Paid, EnumArrearType.ToCalculate, payrollTypeID);
|
|
|
|
tc.ExecuteNonQuery("DELETE FROM INCOMETAXTEMP WHERE INCOMETAXTEMP.EMPLOYEEID IN "
|
|
+ " (SELECT SALARYMONTHLY.EMPLOYEEID FROM SALARYMONTHLY"
|
|
+ " WHERE SALARYMONTHLY.PAYROLLTYPEID= %n AND"
|
|
+ " SALARYMONTHLY.SALARYMONTH= %d)", payrollTypeID, salaryMonth);
|
|
|
|
tc.ExecuteNonQuery("INSERT INTO INCOMETAXTEMP(EMPLOYEEID, ITEMCODE,HeadID,ITEMID, DESCRIPTION,"
|
|
+ " THISYEARTOTAL, PREVIOUSAMOUNT, THISMONTHAMOUNT, PROJECTEDAMOUNT,"
|
|
+ " SIDE, POSITION)"
|
|
+ " (SELECT SALARYTEMPIT.EMPLOYEEID, SALARYTEMPIT.ITEMCODE,SALARYTEMPIT.HeadID, SALARYTEMPIT.ITEMID,"
|
|
+ " SALARYTEMPIT.DESCRIPTION, SALARYTEMPIT.THISYEARTOTAL, "
|
|
+ " SALARYTEMPIT.PREVIOUSAMOUNT, SALARYTEMPIT.THISMONTHAMOUNT, "
|
|
+ " SALARYTEMPIT.PROJECTEDAMOUNT, SALARYTEMPIT.SIDE, SALARYTEMPIT.POSITION "
|
|
+ " "
|
|
+ " FROM SALARYTEMPIT WHERE SALARYTEMPIT.EMPLOYEEID IN "
|
|
+ " (SELECT DISTINCT SALARYMONTHLY.EMPLOYEEID FROM SALARYMONTHLY "
|
|
+ " WHERE SALARYMONTHLY.PAYROLLTYPEID= %n AND "
|
|
+ " SALARYMONTHLY.SALARYMONTH= %d ))", payrollTypeID, salaryMonth);
|
|
|
|
tc.ExecuteNonQuery("DELETE FROM SALARYTEMPIT WHERE SALARYTEMPIT.EMPLOYEEID IN "
|
|
+ " (SELECT SALARYMONTHLY.EMPLOYEEID FROM SALARYMONTHLY "
|
|
+ " WHERE SALARYMONTHLY.PAYROLLTYPEID= %n AND "
|
|
+ " SALARYMONTHLY.SALARYMONTH= %d)", payrollTypeID, salaryMonth);
|
|
|
|
// In previous payroll (VB6), we always delete individual allowance which expired/ end date complte
|
|
// Employee history report can't be seen on previous month, if delete this data.
|
|
//
|
|
//tc.ExecuteNonQuery("Delete From ADParameterEmployee Where TillDate <= %d AND ADParameterEmployee.EmployeeID IN"
|
|
// + " (SELECT Employee.EmployeeID FROM Employee WHERE Employee.PayrollTypeID=%n)",
|
|
// salaryMonth, SystemInformation.CurrentSysInfo.PayrollTypeID );
|
|
|
|
tc.ExecuteNonQuery(
|
|
"Update ADParameterEmployee SET ArrearInfo=%n Where TillDate <= %d AND ADParameterEmployee.EmployeeID IN"
|
|
+ " (SELECT Employee.EmployeeID FROM Employee WHERE Employee.PayrollTypeID=%n)", EnumArrearType.Paid,
|
|
salaryMonth, payrollTypeID);
|
|
|
|
tc.ExecuteNonQuery(
|
|
"Update GradeSalaryAssignment Set ArrearInfo = %n Where ArrearInfo = %n AND GradeSalaryAssignment.EmployeeID IN "
|
|
+ " (SELECT Employee.EmployeeID FROM Employee WHERE PayrollTypeID=%n)",
|
|
EnumArrearType.Paid, EnumArrearType.ToCalculate,
|
|
payrollTypeID);
|
|
|
|
tc.ExecuteNonQuery("Update Employee Set Status=MonthStatusUpdate WHERE "
|
|
+ " PayrollTypeId=%n and STATUS != MonthStatusUpdate AND MonthStatusUpdate>1 "
|
|
+ " AND ENDOFCONTRACTDATE IS NOT null", payrollTypeID);
|
|
|
|
// update PF member ship date, there is many thing to do for secondy emloyee
|
|
tc.ExecuteNonQuery("Update Employee Set PFMEMBERTYPE=%n WHERE "
|
|
+ " PayrollTypeId=%n and STATUS != MonthStatusUpdate AND MonthStatusUpdate>1"
|
|
+ " AND ENDOFCONTRACTDATE IS NOT null", EnumPFMembershipType.DiscontinuedfromPayroll,
|
|
payrollTypeID);
|
|
|
|
tc.ExecuteNonQuery(@"Update LOANSCHEDULE set PAYMENTDATE = %d, PAYMENTMODE = 2 where LOANSCHEDULEID in(select supportid from SALARYMONTHLYDETAIL sd, SALARYMONTHLY s where s.SALARYMONTH = %d and s.SALARYMONTHLYID = sd.SALARYMONTHLYID
|
|
and sd.ITEMCODE = %n and s.PAYROLLTYPEID = %n)", salaryMonth, salaryMonth, (int)EnumSalaryItemCode.Loan_Monthly_Installment, payrollTypeID);
|
|
|
|
tc.ExecuteNonQuery("UPDATE PAYROLLTYPE SET NEXTPAYPROCESSDATE= %d WHERE PayrollTypeId=%n",
|
|
PayrollGlobalFunctions.PayrollLastDateOfMonth(salaryMonth.AddMonths(1)), payrollTypeID);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Undo salary
|
|
|
|
internal static void UndoSalary(TransactionContext tc, int id, int employeeCount)
|
|
{
|
|
//if (employeeCount > 0)
|
|
//{
|
|
tc.CommandTimeOut = 10000;
|
|
tc.ExecuteNonQuery(
|
|
"DELETE FROM SalaryEmpCostCenter WHERE SalaryMonthlyID in( Select SalaryMonthlyID from SalaryMonthly Where SalaryProcessID=%n)",
|
|
id);
|
|
tc.ExecuteNonQuery(
|
|
"DELETE FROM SalaryTempIT WHERE EmployeeID in (Select distinct EmployeeID from SalaryMonthly Where SalaryProcessID=%n)",
|
|
id);
|
|
tc.ExecuteNonQuery(
|
|
"DELETE FROM SalaryMonthlyDetail WHERE SalaryMonthlyID in( Select SalaryMonthlyID from SalaryMonthly Where SalaryProcessID=%n)",
|
|
id);
|
|
tc.ExecuteNonQuery("DELETE FROM SalaryMonthly WHERE SalaryProcessID=%n", id);
|
|
//}
|
|
tc.ExecuteNonQuery("DELETE FROM SalaryProcess WHERE SalaryProcessID=%n", id);
|
|
}
|
|
|
|
internal static void UndoMonthlySalaryByIDs(TransactionContext tc, string ids)
|
|
{
|
|
tc.ExecuteNonQuery("DELETE FROM SalaryEmpCostCenter WHERE SalaryMonthlyID in(%q)", ids);
|
|
tc.ExecuteNonQuery(
|
|
"DELETE FROM SalaryTempIT WHERE EmployeeID in (Select EmployeeID from SalaryMonthly Where SalaryMonthlyID in(%q))",
|
|
ids);
|
|
tc.ExecuteNonQuery("DELETE FROM SalaryMonthlyDetail WHERE SalaryMonthlyID in(%q)", ids);
|
|
tc.ExecuteNonQuery("DELETE FROM SalaryMonthly WHERE SalaryMonthlyID in(%q)", ids);
|
|
}
|
|
|
|
|
|
internal static void UndoMonthlySalaryByEmpIDs(TransactionContext tc, string ids, DateTime salaryMonth)
|
|
{
|
|
tc.ExecuteNonQuery(@"DELETE FROM SalaryEmpCostCenter
|
|
WHERE SalaryMonthlyID in(SELECT SALARYMONTHLYID FROM SALARYMONTHLY
|
|
WHERE EMPLOYEEID in(%q) AND Salarymonth = %d)", ids,
|
|
salaryMonth.PayrollLastDateOfMonth());
|
|
tc.ExecuteNonQuery(@"DELETE FROM SalaryTempIT
|
|
WHERE EmployeeID in (%q)", ids);
|
|
tc.ExecuteNonQuery(
|
|
@"DELETE FROM SalaryMonthlyDetail WHERE SalaryMonthlyID in(SELECT SALARYMONTHLYID FROM SALARYMONTHLY
|
|
WHERE EMPLOYEEID in(%q) AND Salarymonth = %d)", ids,
|
|
salaryMonth.PayrollLastDateOfMonth());
|
|
tc.ExecuteNonQuery(
|
|
@"DELETE FROM SalaryMonthly WHERE SalaryMonthlyID in(SELECT SALARYMONTHLYID FROM SALARYMONTHLY
|
|
WHERE EMPLOYEEID in(%q) AND Salarymonth = %d)", ids,
|
|
salaryMonth.PayrollLastDateOfMonth());
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
internal static IDataReader GetAllProcess(TransactionContext tc, int payrollTypeID, DateTime nextPayProcessDate)
|
|
{
|
|
return tc.ExecuteReader("SELECT * FROM SalaryProcess Where PayrollTypeID=%n and SalaryMonth=%d",
|
|
payrollTypeID, nextPayProcessDate);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
} |