174 lines
7.4 KiB
C#
174 lines
7.4 KiB
C#
using System;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using Ease.Core.DataAccess;
|
|
using HRM.BO;
|
|
|
|
namespace HRM.DA
|
|
{
|
|
public class GLDA
|
|
{
|
|
#region Constructor
|
|
|
|
public GLDA()
|
|
{
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Insert function
|
|
|
|
public static void Insert(TransactionContext tc, GL oItem)
|
|
{
|
|
string sql = SQLParser.MakeSQL("INSERT INTO FM_GL(GLID, GLCode, GLDescription, GLType, GLHeadType, OwnerID, TierNo, POSITIONNO, LegacyCode, IsActive, CreatedBy, CreateDate, UserObjectID, FundTypeID)" +
|
|
" VALUES(%n, %s, %s, %n, %n, %n, %n, %n, %s, %n, %n, %d, %n, %n)", oItem.ID, oItem.GLCode,
|
|
oItem.GLDescription, oItem.GLType, oItem.GLHeadType, oItem.OwnerID, oItem.TierNo, oItem.PositionNo,
|
|
oItem.LegacyCode, oItem.IsActive, oItem.CreatedBy, oItem.CreatedDate, oItem.UserObjectID, oItem.FundTypeID);
|
|
tc.ExecuteNonQuery(sql);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Update function
|
|
|
|
public static void Update(TransactionContext tc, GL oItem)
|
|
{
|
|
string sql = SQLParser.MakeSQL("UPDATE FM_GL SET GLCode=%s, GLDescription=%s, GLType=%n, GLHeadType=%n, OwnerID=%n, TierNo=%n,PositionNo=%n ,LegacyCode=%s, IsActive=%n, Modifiedby=%n, ModifiedDate=%d, UserObjectID =%n, FundTypeID=%n" +
|
|
" WHERE GLID=%n", oItem.GLCode,
|
|
oItem.GLDescription, oItem.GLType, oItem.GLHeadType, oItem.OwnerID, oItem.TierNo, oItem.PositionNo,
|
|
oItem.LegacyCode, oItem.IsActive, oItem.ModifiedBy, oItem.ModifiedDate, oItem.UserObjectID, oItem.FundTypeID, oItem.ID);
|
|
tc.ExecuteNonQuery(sql);
|
|
}
|
|
|
|
public static void UpdateHeaType(TransactionContext tc, GL gl)
|
|
{
|
|
tc.ExecuteNonQuery("UPDATE FM_GL SET GLHeadType=%n WHERE GLID=%n", gl.GLHeadType, gl.ID);
|
|
}
|
|
|
|
public static void UpdatePositionNo(TransactionContext tc, int glID, int positionNo)
|
|
{
|
|
tc.ExecuteNonQuery("UPDATE FM_GL SET PositionNo=%n WHERE GLID=%n", positionNo, glID);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Get Function
|
|
|
|
public static IDataReader GetGLByUserObjectID(TransactionContext tc, int userObjectID, int FundTypeID)
|
|
{
|
|
return tc.ExecuteReader("Select* From FM_GL Where UserObjectID =%n and FundTypeID = %n ", userObjectID, FundTypeID);
|
|
}
|
|
|
|
public static bool IsTranExist(TransactionContext tc, string bottomMostChildKeys)
|
|
{
|
|
object count = tc.ExecuteScalar("SELECT COUNT(*) FROM FM_GLTranDetail WHERE GLID in (%q)",
|
|
bottomMostChildKeys);
|
|
if (count == null || count == DBNull.Value || Convert.ToInt32(count) <= 0)
|
|
{
|
|
object countOpen = tc.ExecuteScalar("SELECT COUNT(*) FROM FM_OpenGLTranDetail WHERE GLID in (%q)",
|
|
bottomMostChildKeys);
|
|
if (countOpen == null || countOpen == DBNull.Value || Convert.ToInt32(countOpen) <= 0)
|
|
{
|
|
return false;
|
|
}
|
|
else
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
|
|
public static IDataReader GetByFundTypeID(TransactionContext tc, int fundTypeID)
|
|
{
|
|
return tc.ExecuteReader("SELECT * FROM FM_GL WHERE FUNDTYPEID=%n ORDER BY GLCode, PositionNo", fundTypeID);
|
|
}
|
|
|
|
public static IDataReader Get(TransactionContext tc, int id)
|
|
{
|
|
return tc.ExecuteReader("SELECT * FROM FM_GL WHERE GLID=%n", id);
|
|
}
|
|
|
|
public static IDataReader Get(TransactionContext tc, string code)
|
|
{
|
|
return tc.ExecuteReader("SELECT * FROM FM_GL WHERE GLCode=%s", code);
|
|
}
|
|
|
|
public static IDataReader GetRoot(TransactionContext tc)
|
|
{
|
|
return tc.ExecuteReader("SELECT * FROM FM_GL WHERE OwnerID IS NULL ");
|
|
}
|
|
|
|
public static IDataReader GetByOwnerID(TransactionContext tc, int nOwnerID)
|
|
{
|
|
return tc.ExecuteReader("SELECT * FROM FM_GL WHERE OwnerID=%n Order By PositionNo", nOwnerID);
|
|
}
|
|
|
|
public static IDataReader GetByTierNo(TransactionContext tc, int tierNo, int fundTypeID)
|
|
{
|
|
return tc.ExecuteReader("SELECT * FROM FM_GL WHERE TierNo=%n And FundTypeID=%n ORDER BY GLCode,PositionNo", tierNo, fundTypeID);
|
|
}
|
|
public static IDataReader Get(TransactionContext tc, EnumGLType type, int tierNo, int fundtypeid)
|
|
{
|
|
return tc.ExecuteReader("SELECT * FROM FM_GL WHERE GLType=%n and TierNo=%n " +
|
|
"and fundtypeid=%n ORDER BY GLCode,PositionNo", type, tierNo, fundtypeid);
|
|
}
|
|
public static IDataReader GetByTierNoFundType(TransactionContext tc, int tierNo, int fundTypeID)
|
|
{
|
|
return tc.ExecuteReader("SELECT * FROM FM_GL WHERE TierNo=%n and fundTypeID=%n ORDER BY GLCode,PositionNo", tierNo, fundTypeID);
|
|
}
|
|
|
|
public static DataSet GetGLs(TransactionContext tc, string sqlStr)
|
|
{
|
|
return tc.ExecuteDataSet(sqlStr);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Delete function
|
|
|
|
public static void Delete(TransactionContext tc, int nGLID)
|
|
{
|
|
tc.ExecuteNonQuery("DELETE FROM FM_GL WHERE GLID=%n", nGLID);
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
internal static DataSet GetCheckList(TransactionContext tc, DateTime fromVoucherDate, DateTime toVoucherDate, int voucherType, int fundTypeID)
|
|
{
|
|
|
|
string sql = "where gt.gltranid = gtd.gltranid "
|
|
+ "and gtd.glid=gl.glid";
|
|
|
|
sql = SQLParser.TagSQL(sql) + SQLParser.MakeSQL("gt.voucherdate between %d and %d", fromVoucherDate, toVoucherDate);
|
|
|
|
if (voucherType != 0)
|
|
sql = SQLParser.TagSQL(sql) + SQLParser.MakeSQL("gt.gltrantype=%n", voucherType);
|
|
|
|
|
|
|
|
string query = SQLParser.MakeSQL("select partial2.*,(ur2.field1 + ' ' + ur2.field2) SubsidaryHead2 from "
|
|
+ "(select partial1.*, (ur1.field1 + ' ' + ur1.field2) SubsidaryHead1 from (select transac.*,gtur.userrecord1id,gtur.userrecord2id,gtur.amount SubAmount, gtur.description SubDescription from "
|
|
+ "(select gt.voucherdate VoucherDate, gt.gltrantype VoucherType, gt.voucherNo VoucherNo, "
|
|
+ "gtd.costcenterid , "
|
|
+ "gtd.detailparamid, gl.glcode PostingCode, gl.glDescription PostingHead, gtd.description Description, gtd.transide TranSide, gtd.amount Amount, gtd.gltrandetailid "
|
|
+ "from FM_GLTRAN gt, FM_GLTRANDETAIL gtd, FM_GL gl "
|
|
+ " %q and gt.FundTypeID = %n) transac left outer join FM_GLTRANUSERRECORD gtur "
|
|
+ "on transac.gltrandetailid = gtur.gltrandetailid ) partial1 left outer join FM_USERRECORD ur1 on partial1.userrecord1id = ur1.userrecordid) partial2 "
|
|
+ "left outer join FM_USERRECORD ur2 on partial2.userrecord2id = ur2.userrecordid", sql, fundTypeID);
|
|
|
|
return tc.ExecuteDataSet(query);
|
|
|
|
}
|
|
public static string GetMaxGLCodeByParent(TransactionContext tc, int id)
|
|
{
|
|
return tc.ExecuteScalar("SELECT MAX(CAST([GLCode] AS BIGINT)) + 1 AS NextGLCode FROM fm_gl WHERE OWNERID = %n AND ISNUMERIC([GLCode]) = 1", id).ToString();
|
|
}
|
|
}
|
|
|
|
} |