223 lines
13 KiB
C#
223 lines
13 KiB
C#
|
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;
|
|||
|
|
|||
|
namespace Payroll.Service
|
|||
|
{
|
|||
|
#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)" +
|
|||
|
" VALUES(%n, %d, %d, %s, %n, %s, "
|
|||
|
+" %d, %n, %b, %n, %n, %d,%d)",
|
|||
|
item.ID.Integer, item.SalaryMonth , item.ProcessDate, item.ProcessCode , item.ShowInDesktops,item.Remarks,
|
|||
|
DataReader.GetNullValue(item.PaymentDate), item.WorkDays, item.IsFinalized, item.PayrollTypeID.Integer , item.CreatedBy.Integer, item.CreatedDate,DataReader.GetNullValue(item.MonthEndDate));
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Update function
|
|||
|
|
|||
|
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.Integer, item.ModifiedBy.Integer, item.ModifiedDate,item.MonthEndDate, item.ID.Integer);
|
|||
|
}
|
|||
|
|
|||
|
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.Integer);
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Get Function
|
|||
|
|
|||
|
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, ID 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);
|
|||
|
bShowInDesktop = Convert.ToInt32(obj) > 0 ? true : false;
|
|||
|
return bShowInDesktop;
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Delete function
|
|||
|
|
|||
|
internal static void Delete(TransactionContext tc, ID nID)
|
|||
|
{
|
|||
|
tc.ExecuteNonQuery("DELETE FROM [SalaryProcess] WHERE SalaryProcessID=%n", nID.Integer);
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
internal static void MonthEnd(TransactionContext tc, DateTime salaryMonth, int payrollTypeID)
|
|||
|
{
|
|||
|
tc.ExecuteNonQuery("UPDATE SalaryProcess SET ISFINALIZED =%b WHERE SalaryMonth=%d AND PayrollTypeID=%n", true, 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.Integer );
|
|||
|
|
|||
|
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 PAYROLLTYPE SET NEXTPAYPROCESSDATE= %d WHERE PayrollTypeId=%n",
|
|||
|
GlobalFunctions.LastDateOfMonth(salaryMonth.AddMonths(1)), payrollTypeID);
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Undo salary
|
|||
|
|
|||
|
internal static void UndoSalary(TransactionContext tc, ID id)
|
|||
|
{
|
|||
|
#region Delete Unauthorized Leave
|
|||
|
tc.ExecuteNonQuery("update UnPaidLeave set BasicUnpaidDays=BasicCurrentDeduct where Employeeid in(select Employeeid from SALARYMONTHLY where SalaryProcessID=%n)", id.Integer);
|
|||
|
tc.ExecuteNonQuery("update UnPaidLeave set OtherUnpaidDays=OtherCurrentDeduct where Employeeid in(select Employeeid from SALARYMONTHLY where SalaryProcessID=%n)", id.Integer);
|
|||
|
tc.ExecuteNonQuery("update UnPaidLeave set BasicPaidDays=BasicPaidDays-BasicCurrentDeduct where Employeeid in(select Employeeid from SALARYMONTHLY where SalaryProcessID=%n)", id.Integer);
|
|||
|
tc.ExecuteNonQuery("update UnPaidLeave set TotalUnAuthorizedDays=BasicPaidDays where Employeeid in(select Employeeid from SALARYMONTHLY where SalaryProcessID=%n)", id.Integer);
|
|||
|
tc.ExecuteNonQuery("update UnPaidLeave set OtherPaidDays=OtherPaidDays-OtherCurrentDeduct where Employeeid in(select Employeeid from SALARYMONTHLY where SalaryProcessID=%n)", id.Integer);
|
|||
|
tc.ExecuteNonQuery("update UnPaidLeave set BasicCurrentDeduct=0 where Employeeid in(select Employeeid from SALARYMONTHLY where SalaryProcessID=%n)", id.Integer);
|
|||
|
tc.ExecuteNonQuery("update UnPaidLeave set OtherCurrentDeduct=0 where Employeeid in(select Employeeid from SALARYMONTHLY where SalaryProcessID=%n)", id.Integer);
|
|||
|
#endregion
|
|||
|
tc.ExecuteNonQuery("DELETE FROM SalaryEmpCostCenter WHERE SalaryMonthlyID in( Select SalaryMonthlyID from SalaryMonthly Where SalaryProcessID=%n)", id.Integer);
|
|||
|
tc.ExecuteNonQuery("DELETE FROM SalaryTempIT WHERE EmployeeID in (Select EmployeeID from SalaryMonthly Where SalaryProcessID=%n)", id.Integer);
|
|||
|
tc.ExecuteNonQuery("DELETE FROM SalaryMonthlyDetail WHERE SalaryMonthlyID in( Select SalaryMonthlyID from SalaryMonthly Where SalaryProcessID=%n)", id.Integer);
|
|||
|
tc.ExecuteNonQuery("DELETE FROM SalaryMonthly WHERE SalaryProcessID=%n", id.Integer);
|
|||
|
tc.ExecuteNonQuery("DELETE FROM SalaryProcess WHERE SalaryProcessID=%n", id.Integer);
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
internal static void UndoMonthlySalaryByEmpIDs(TransactionContext tc, string ids, DateTime salaryMonth)
|
|||
|
{
|
|||
|
#region Delete Unauthorized Leave
|
|||
|
tc.ExecuteNonQuery("update UnPaidLeave set BasicUnpaidDays=BasicCurrentDeduct where Employeeid in(%q)", ids);
|
|||
|
tc.ExecuteNonQuery("update UnPaidLeave set OtherUnpaidDays=OtherCurrentDeduct where Employeeid in(%q)", ids);
|
|||
|
tc.ExecuteNonQuery("update UnPaidLeave set BasicPaidDays=BasicPaidDays-BasicCurrentDeduct where Employeeid in(%q)", ids);
|
|||
|
tc.ExecuteNonQuery("update UnPaidLeave set OtherPaidDays=OtherPaidDays-OtherCurrentDeduct where Employeeid in(%q)", ids);
|
|||
|
tc.ExecuteNonQuery("update UnPaidLeave set BasicCurrentDeduct=0 where Employeeid in(%q)", ids);
|
|||
|
tc.ExecuteNonQuery("update UnPaidLeave set OtherCurrentDeduct=0 where Employeeid in(%q)", ids);
|
|||
|
#endregion
|
|||
|
|
|||
|
tc.ExecuteNonQuery(@"DELETE FROM SalaryEmpCostCenter
|
|||
|
WHERE SalaryMonthlyID in(SELECT SALARYMONTHLYID FROM SALARYMONTHLY
|
|||
|
WHERE EMPLOYEEID in(%q) AND Salarymonth = %d)", ids, salaryMonth.LastDateOfMonth());
|
|||
|
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.LastDateOfMonth());
|
|||
|
tc.ExecuteNonQuery(@"DELETE FROM SalaryMonthly WHERE SalaryMonthlyID in(SELECT SALARYMONTHLYID FROM SALARYMONTHLY
|
|||
|
WHERE EMPLOYEEID in(%q) AND Salarymonth = %d)", ids, salaryMonth.LastDateOfMonth());
|
|||
|
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
internal static int GetProcessID(TransactionContext tc, DateTime nextPayProcessDate, int payrollTypeID)
|
|||
|
{
|
|||
|
string sql = SQLParser.MakeSQL("SELECT COUNT(SalaryProcessID) FROM SalaryProcess Where PayrollTypeID=%n and SalaryMonth=%d", payrollTypeID, nextPayProcessDate);
|
|||
|
int processID = 0;
|
|||
|
object obj = tc.ExecuteScalar(sql);
|
|||
|
|
|||
|
if (obj != null)
|
|||
|
{
|
|||
|
processID = Convert.ToInt32(obj);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
processID = 0;
|
|||
|
}
|
|||
|
return processID;
|
|||
|
}
|
|||
|
|
|||
|
internal static IDataReader GetAllProcess(TransactionContext tc, DateTime nextPayProcessDate, int payrollTypeID)
|
|||
|
{
|
|||
|
return tc.ExecuteReader("SELECT * FROM SalaryProcess Where PayrollTypeID=%n and SalaryMonth=%d", payrollTypeID, nextPayProcessDate);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|