using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; using Ease.Core.DataAccess; using HRM.BO; using Microsoft.Data.SqlClient; namespace HRM.DA.DA.Tax { internal class TaxReturnDA { #region Insert function internal static void Insert(TransactionContext tc, TaxReturn item) { tc.ExecuteNonQuery("INSERT INTO TaxReturn(TaxReturnID, EmployeeID, TaxParamID, Circle, TaxZone, Serial, CreatedBy, CreationDate, ReturnSubmissionDate, TimeExtensionDate, TaxUnit, Reason)" + " VALUES(%n, %n, %n, %s, %s, %s, %n, %d, %d, %d, %s, %s)", item.ID, item.EmployeeID, item.TaxParamID, item.Circle, item.TaxZone, item.Serial, item.CreatedBy, item.CreatedDate, DataReader.GetNullValue(item.ReturnSubmissionDate), DataReader.GetNullValue(item.TimeExtension), item.TaxUnit, DataReader.GetNullValue(item.Reason)); } #endregion #region Update function internal static void Update(TransactionContext tc, TaxReturn item) { tc.ExecuteNonQuery("UPDATE TaxReturn SET EmployeeID=%s, TaxParamID=%s, Circle=%s, TaxZone=%s, Serial = %s, ModifiedBy=%n, ModifiedDate=%d, ReturnSubmissionDate=%d, TimeExtensionDate=%d, TaxUnit=%s " + "WHERE TaxReturnID=%n", item.EmployeeID, item.TaxParamID, item.Circle, item.TaxZone, item.Serial, item.ModifiedBy, item.ModifiedDate, DataReader.GetNullValue(item.ReturnSubmissionDate), DataReader.GetNullValue(item.TimeExtension), item.TaxUnit, item.ID); } internal static void UpdateTaxReturnStatus(TransactionContext tc, TaxReturn item) { tc.ExecuteNonQuery("UPDATE TaxReturn SET ReturnStatus = %n, Reason = %s, AcknowledgedBy=%n, AcknowledgedDate=%d, ModifiedBy=%n, ModifiedDate=%d " + "WHERE TaxReturnID=%n", (int)item.ReturnStatus, DataReader.GetNullValue(item.Reason), item.AcknowledgedBy, item.AcknowledgedDate, item.ModifiedBy, item.ModifiedDate, item.ID); } #endregion #region Get Function internal static IDataReader Get(TransactionContext tc) { return tc.ExecuteReader("SELECT * FROM TaxReturn"); } internal static IDataReader Get(TransactionContext tc, int empId, int taxParamId) { return tc.ExecuteReader("SELECT * FROM TaxReturn where employeeId = %n and taxParamId = %n", empId, taxParamId); } internal static DataSet GetTaxReturnByEmpId(TransactionContext tc, int empId) { //return tc.ExecuteReader("SELECT * FROM TaxReturn where employeeId = %n order by RETURNSUBMISSIONDATE desc ", empId); DataSet ds = new DataSet(); string sql = SQLParser.MakeSQL(@"select t.taxReturnId,tp.FiscalYear, t.employeeId, e.employeeNo, e.name, dg.Name Designation, dp.Description Department, e.tinNo, e.EMAILADDRESS Email, t.circle, t.taxZone, t.TaxUnit, t.ReturnSubmissionDate, t.CreationDate, t.serial,t.ReturnStatus, IIF(a.taxReturnAttachmentId is null, 0, 1) flag from taxReturn t inner join employee e on t.employeeId = e.EMPLOYEEID left join designation dg on dg.DESIGNATIONID = e.DESIGNATIONID left join DEPARTMENT dp on dp.DEPARTMENTID = e.DEPARTMENTID left join taxReturnAttachments a on a.empId = t.employeeId AND a.fileType = 1 AND a.referenceId = t.TaxReturnID left join TAXPARAMETER tp on tp.TAXPARAMID = t.TAXPARAMID where t.EMPLOYEEID = %n order by RETURNSUBMISSIONDATE desc", empId); ds = tc.ExecuteDataSet(sql); return ds; } internal static IDataReader Get(TransactionContext tc, int nID) { return tc.ExecuteReader("SELECT * FROM TaxReturn Where TaxReturnID=%n", nID); } internal static DataSet GetByTaxParamId(TransactionContext tc, int taxParamId) { DataSet ds = new DataSet(); string sql = SQLParser.MakeSQL(@"select t.taxReturnId, t.employeeId, e.employeeNo, e.name, dg.Name Designation, dp.Description Department, e.tinNo, e.EMAILADDRESS Email, t.circle, t.taxZone, t.TaxUnit, t.ReturnSubmissionDate, t.CreationDate, t.serial, IIF(a.taxReturnAttachmentId is null, 0, 1) flag from taxReturn t inner join employee e on t.employeeId = e.EMPLOYEEID left join designation dg on dg.DESIGNATIONID = e.DESIGNATIONID left join DEPARTMENT dp on dp.DEPARTMENTID = e.DEPARTMENTID left join taxReturnAttachments a on a.empId = t.employeeId AND a.fileType = 1 AND a.referenceId = t.TaxReturnID where t.TaxParamID = %n", taxParamId); ds = tc.ExecuteDataSet(sql); return ds; } internal static DataSet GetByTaxParamId(TransactionContext tc, int taxParamId, EnumReturnStatus returnStatus) { DataSet ds = new DataSet(); string sql = SQLParser.MakeSQL(@"select t.taxReturnId, t.employeeId, e.employeeNo, e.name, dg.Name Designation, dp.Description Department, e.tinNo, e.EMAILADDRESS Email, t.circle, t.taxZone, t.TaxUnit, t.ReturnSubmissionDate, t.CreationDate, t.serial, t.ReturnStatus, IIF(a.taxReturnAttachmentId is null, 0, 1) flag from taxReturn t inner join employee e on t.employeeId = e.EMPLOYEEID left join designation dg on dg.DESIGNATIONID = e.DESIGNATIONID left join DEPARTMENT dp on dp.DEPARTMENTID = e.DEPARTMENTID left join taxReturnAttachments a on a.empId = t.employeeId AND a.fileType = 1 AND a.referenceId = t.TaxReturnID where t.TaxParamID = %n and t.ReturnStatus = %n", taxParamId, (int)returnStatus); ds = tc.ExecuteDataSet(sql); return ds; } #endregion #region Delete function internal static void Delete(TransactionContext tc, int nID) { tc.ExecuteNonQuery("DELETE FROM TaxReturn Where EmployeeID=%n", nID); } internal static void DeleteByEmployeeAndTaxParamId(TransactionContext tc, int eid, int taxParamId) { tc.ExecuteNonQuery("DELETE FROM TaxReturn Where EmployeeID=%n and TaxParamID=%n", eid, taxParamId); } internal static DataTable Get108AReport(TransactionContext tc, string sEmpNo, int nTaxParamID) { DataSet ds = new DataSet(); string sql = SQLParser.MakeSQL(@"SELECT e.Name, dsg.Name Designation, e.TINNO, t.TaxZone, t.Circle, t.ReturnSubmissionDate, t.Serial FROM TaxReturn t LEFT JOIN EMPLOYEE e ON e.EMPLOYEEID = t.EmployeeID LEFT JOIN DESIGNATION dsg ON dsg.DESIGNATIONID = e.DESIGNATIONID WHERE t.EmployeeID IN (%q) AND t.TaxParamID = %n", sEmpNo, nTaxParamID); ds = tc.ExecuteDataSet(sql); return ds.Tables[0]; } public static IDataReader GetFile(TransactionContext tc, int empId, int referenceId, EnumTaxAttachmentType type) { string sql = SQLParser.MakeSQL( "select * from taxReturnAttachments where empId=%n and referenceId = %n and fileType = %n", empId, referenceId, (int)type); return tc.ExecuteReader(sql); } public static IDataReader GetAllFileByReferenceIds(TransactionContext tc, string referenceIds) { string sql = SQLParser.MakeSQL("select * from taxReturnAttachments where referenceId in (%q) and fileType = 1", referenceIds); return tc.ExecuteReader(sql); } public static void UploadFile(TransactionContext tc, TaxReturnAttachment item, byte[] fileinByte) { tc.ExecuteNonQuery(@"delete from taxReturnAttachments where empid =%n and referenceid =%n and fileType =%n", item.EmployeeID, item.ReferenceID, item.FileType); string strQuery = @"insert into taxReturnAttachments( empid, referenceid, fileType, fileData, fileName) values (@empid, @referenceid, @fileType, @fileData, @fileName)"; SqlCommand cmd = new SqlCommand(strQuery, (SqlConnection)tc.Connection); cmd.Parameters.Add("@empid", SqlDbType.Int).Value = item.EmployeeID; cmd.Parameters.Add("@referenceid", SqlDbType.Int).Value = item.ReferenceID; cmd.Parameters.Add("@fileType", SqlDbType.Int).Value = item.FileType; cmd.Parameters.Add("@fileData", SqlDbType.Binary).Value = fileinByte; cmd.Parameters.Add("@fileName", SqlDbType.VarChar).Value = item.FileName; cmd.ExecuteNonQuery(); } public static void UploadFile(TransactionContext tc, TaxReturnAttachment item) { tc.ExecuteNonQuery(@"delete from taxReturnAttachments where empid =%n and referenceid =%n and fileType =%n", item.EmployeeID, item.ReferenceID, item.FileType); string strQuery = @"insert into taxReturnAttachments( empid, referenceid, fileType, fileData, fileName) values (@empid, @referenceid, @fileType, @fileData, @fileName)"; SqlCommand cmd = new SqlCommand(strQuery, (SqlConnection)tc.Connection); cmd.Parameters.Add("@empid", SqlDbType.Int).Value = item.EmployeeID; cmd.Parameters.Add("@referenceid", SqlDbType.Int).Value = item.ReferenceID; cmd.Parameters.Add("@fileType", SqlDbType.Int).Value = item.FileType; cmd.Parameters.Add("@fileData", SqlDbType.Binary).Value = item.FileData; cmd.Parameters.Add("@fileName", SqlDbType.VarChar).Value = item.FileName; cmd.ExecuteNonQuery(); } #endregion } }