CEL_Payroll/Payroll.BO/Tax/TaxMergeMaster.cs

458 lines
12 KiB
C#
Raw Normal View History

2024-09-17 14:30:13 +06:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ease.CoreV35;
using Ease.CoreV35.Model;
using Ease.CoreV35.Caching;
using System.Data.Linq.Mapping;
namespace Payroll.BO
{
#region TaxMergeMaster
[Serializable]
public class TaxMergeMaster : AuditTrailBase
{
#region Cache Stores
private static Cache _cache = new Cache(typeof(TaxMergeMaster));
#endregion
#region Constructor
public TaxMergeMaster()
{
_taxParameterID = null;
_itemGroup = EnumIncomeTaxItemGroup.Basic_Salary;
_description = string.Empty;
_position = 0;
_itemId = 0;
_type = EnumTaxMergeType.Allowance;
}
#endregion
#region Properties
#region TaxParameterID : ID
private ID _taxParameterID;
public ID TaxParameterID
{
get { return _taxParameterID; }
set
{
base.OnPropertyChange<ID>("TaxParameterID", _taxParameterID, value);
_taxParameterID = value;
}
}
#endregion
#region itemCode : string
private EnumIncomeTaxItemGroup _itemGroup;
public EnumIncomeTaxItemGroup ItemGroup
{
get { return _itemGroup; }
set
{
_itemGroup = value;
}
}
#endregion
#region headID : int
private int _itemId;
public int ItemID
{
get { return _itemId; }
set
{
_itemId = value;
}
}
#endregion
#region description : string
private string _description;
public string Description
{
get { return _description; }
set
{
base.OnPropertyChange<string >("description", _description, value);
_description = value;
}
}
#endregion
#region position : int
private int _position;
public int Position
{
get { return _position; }
set
{
base.OnPropertyChange<int>("position", _position, value);
_position = value;
}
}
#endregion
#region Type : EnumTaxMergeType
private EnumTaxMergeType _type;
public EnumTaxMergeType Type
{
get { return _type; }
set
{
base.OnPropertyChange<short>("Type", (short)_type, (short)value);
_type = value;
}
}
#endregion
#region TaxMergeDetail : TaxMergeDetail
private ObjectsTemplate<TaxMergeDetail> _TaxMergeDetails = null;
public ObjectsTemplate<TaxMergeDetail> TaxMergeDetails
{
get
{
if (_taxParameterID == null && !this.ID.IsUnassigned && this.ID.Integer > 0)
{
TaxMergeMaster ms = TaxMergeMaster.Get(this.ID);
_TaxMergeDetails = ms.TaxMergeDetails;
}
return this._TaxMergeDetails;
}
set
{
_TaxMergeDetails = value;
}
}
#endregion
#region Service Factory ITaxMergeMasterService : ITaxMergeMasterService
internal static ITaxMergeMasterService Service
{
get { return Services.Factory.CreateService<ITaxMergeMasterService>(typeof(ITaxMergeMasterService)); }
}
#endregion
#endregion
#region Functions
public static TaxMergeMaster Get(ID nID)
{
TaxMergeMaster oTaxMergeMaster = null;
#region Cache Header
oTaxMergeMaster = (TaxMergeMaster)_cache["Get", nID];
if (oTaxMergeMaster != null)
return oTaxMergeMaster;
#endregion
oTaxMergeMaster = TaxMergeMaster.Service.Get(nID);
#region Cache Footer
_cache.Add(oTaxMergeMaster, "Get", nID);
#endregion
return oTaxMergeMaster;
}
public static ObjectsTemplate<TaxMergeMaster> GetbyTaxParameter(ID TaxParameterID)
{
#region Cache Header
ObjectsTemplate<TaxMergeMaster> taxMergeMasters = _cache["Get"] as ObjectsTemplate<TaxMergeMaster>;
if (taxMergeMasters != null)
return taxMergeMasters;
#endregion
try
{
taxMergeMasters = Service.GetbyTaxParameter(TaxParameterID);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(taxMergeMasters, "Get");
#endregion
return taxMergeMasters;
}
public static IncomeTax Extract(ObjectsTemplate<TaxMergeMaster> mergeItems,
EnumTaxMergeType type, int itemID)
{
IncomeTax tax = null;
foreach (TaxMergeMaster master in mergeItems)
{
foreach (TaxMergeMaster.TaxMergeDetail detail in master.TaxMergeDetails)
{
if (detail.Type == type && detail.ItemID == itemID)
{
tax = new IncomeTax();
tax.ItemGroup = master.ItemGroup;;
tax.ItemID = master.ItemID;
tax.Description = master.Description;
//tax.Position = master.Position;
return tax;
}
}
}
return null;
}
public static IncomeTax Extract(ObjectsTemplate<TaxMergeMaster> mergeItems,
EnumIncomeTaxItemGroup groupcode)
{
IncomeTax tax = null;
foreach (TaxMergeMaster master in mergeItems)
{
foreach (TaxMergeMaster.TaxMergeDetail detail in master.TaxMergeDetails)
{
if (detail.ItemGroup == groupcode && detail.Type == EnumTaxMergeType.NONE)
{
tax = new IncomeTax();
tax.ItemGroup = master.ItemGroup; ;
tax.ItemID = master.ItemID;
tax.Description = master.Description;
tax.Position = master.Position;
return tax;
}
}
}
return null;
}
public static IncomeTax Get(ObjectsTemplate<TaxMergeMaster> mergeItems,
EnumIncomeTaxItemGroup groupcode)
{
IncomeTax tax = null;
foreach (TaxMergeMaster master in mergeItems)
{
foreach (TaxMergeMaster.TaxMergeDetail detail in master.TaxMergeDetails)
{
if (detail.ItemGroup == groupcode)
{
tax = new IncomeTax();
tax.ItemGroup = master.ItemGroup; ;
tax.ItemID = master.ItemID;
tax.Description = master.Description;
tax.Position = master.Position;
return tax;
}
}
}
return null;
}
//public static ObjectsTemplate<TaxMergeMaster> Get()
//{
// #region Cache Header
// ObjectsTemplate<TaxMergeMaster> taxMergeMasters = _cache["Get"] as ObjectsTemplate<TaxMergeMaster>;
// if (taxMergeMasters != null)
// return taxMergeMasters;
// #endregion
// try
// {
// taxMergeMasters = Service.Get();
// }
// catch (ServiceException e)
// {
// throw new Exception(e.Message, e);
// }
// #region Cache Footer
// _cache.Add(taxMergeMasters, "Get");
// #endregion
// return taxMergeMasters;
//}
public static bool IsExist(ObjectsTemplate<TaxMergeMaster> masters, EnumTaxMergeType ntype, int nItemId)
{
foreach (TaxMergeMaster masterItem in masters)
{
foreach (TaxMergeDetail item in masterItem.TaxMergeDetails)
{
if (item.Type == ntype && item.ItemID == nItemId)
{
return true;
}
}
}
return false;
}
public ID Save()
{
this.SetAuditTrailProperties();
return TaxMergeMaster.Service.Save(this);
}
public void Delete()
{
TaxMergeMaster.Service.Delete(ID);
}
#endregion
#endregion
#region TaxMergeDetail
[Serializable]
public class TaxMergeDetail : ObjectTemplate
{
#region Cache Store
private static Cache _cache = new Cache(typeof(TaxMergeDetail));
#endregion
#region Constructor
public TaxMergeDetail()
{
_taxMergeID = null;
_taxParameterID = null;
_itemGroup = EnumIncomeTaxItemGroup.Tax_Deducted;
_itemID = 0;
_type = EnumTaxMergeType.Allowance;
_description = "";
}
#endregion
#region Properties
#region TaxMergeID : ID
private ID _taxMergeID;
public ID TaxMergeID
{
get { return _taxMergeID; }
set
{
base.OnPropertyChange<ID>("TaxMergeID", _taxMergeID, value);
_taxMergeID = value;
}
}
#endregion
#region TaxParameterID : ID
private ID _taxParameterID;
public ID TaxParameterID
{
get { return _taxParameterID; }
set
{
base.OnPropertyChange<ID>("TaxParameterID", _taxParameterID, value);
_taxParameterID = value;
}
}
#endregion
#region ItemGroup : EnumIncomeTaxItemGroup
private EnumIncomeTaxItemGroup _itemGroup;
public EnumIncomeTaxItemGroup ItemGroup
{
get { return _itemGroup; }
set
{
_itemGroup = value;
}
}
#endregion
#region Description : string
private string _description;
public string Description
{
get { return _description; }
set
{
_description = value;
}
}
#endregion
#region ItemID : int
private int _itemID;
public int ItemID
{
get { return _itemID; }
set
{
base.OnPropertyChange<int>("ItemGroup", (short)_itemID, value);
_itemID = value;
}
}
#endregion
#region Type : EnumTaxMergeType
private EnumTaxMergeType _type;
public EnumTaxMergeType Type
{
get { return _type; }
set
{
base.OnPropertyChange<short>("Type", (short)_type, (short)value);
_type = value;
}
}
#endregion
#endregion
}
#endregion
}
#region ITaxMergeMaster Service
public interface ITaxMergeMasterService
{
TaxMergeMaster Get(ID id);
ObjectsTemplate<TaxMergeMaster> GetbyTaxParameter(ID TaxParameterID);
//ObjectsTemplate<TaxMergeMaster> Get();
ID Save(TaxMergeMaster item);
void Delete(ID id);
}
#endregion
}