CEL_Payroll/Payroll.BO/Workflow/WFSetup.cs

689 lines
23 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.Caching;
using Ease.CoreV35.Model;
using Ease.CoreV35.Utility;
namespace Payroll.BO
{
#region WFSetup
[Serializable]
public class WFSetup : BasicBaseObject
{
#region Cache Store
private static Cache _cache = new Cache(typeof(WFSetup));
#endregion
#region Constructor
public WFSetup()
{
_wfTypeId = null;
_wfSetupRules = null;
}
#endregion
#region Property
//#region Property WFSetupID : ID
//private ID _wfSetupId;
//public ID WFSetupID
//{
// get { return _wfSetupId; }
// set { _wfSetupId = value; }
//}
//#endregion
#region Property WFTypeId : ID
private ID _wfTypeId;
public ID WFTypeId
{
get { return _wfTypeId; }
set { _wfTypeId = value; }
}
#endregion
#region WFRuleDetailDesignation : WFRuleDetailDesignation
//private ObjectsTemplate<WFRuleDetailDesignation> _wfDetailDesigs;
//public ObjectsTemplate<WFRuleDetailDesignation> WFDetailDesigs
//{
// get
// {
// if (_wfDetailDesigs == null)
// _wfDetailDesigs = Service.Get4WFRuleDD(this.ID);
// return _wfDetailDesigs;
// }
// set
// {
// _wfDetailDesigs = value;
// }
//}
#endregion
#region WFRuleDetailNode : WFRuleDetailNode
//private ObjectsTemplate<WFRuleDetailNode> _wfRuleNodes;
//public ObjectsTemplate<WFRuleDetailNode> WFRuleNodes
//{
// get
// {
// if (_wfRuleNodes == null)
// _wfRuleNodes = Service.Get4WFRuleNode(this.ID);
// return _wfRuleNodes;
// }
// set
// {
// _wfRuleNodes = value;
// }
//}
#endregion
#region WFRuleDetailOS : WFRuleDetailOS
//private ObjectsTemplate<WFRuleDetailOS> _wfRuleDOSs;
//public ObjectsTemplate<WFRuleDetailOS> WFRuleDOSs
//{
// get
// {
// if (_wfRuleDOSs == null )
// {
// _wfRuleDOSs = Service.Get4WFRuleDetailOS(this.ID);
// }
// return _wfRuleDOSs;
// }
// set
// {
// _wfRuleDOSs = value;
// }
//}
#endregion
#region WFSetupRule : WFSetupRule
private ObjectsTemplate<WFSetupRule> _wfSetupRules;
public ObjectsTemplate<WFSetupRule> WFSetupRules
{
get
{
if (_wfSetupRules == null && this.ID != null && this.ID.IsUnassigned == false)
{
_wfSetupRules = Service.Get4WFSetupRule(this.ID);
}
return _wfSetupRules;
}
set
{
_wfSetupRules = value;
}
}
#endregion
#region WFType : WFType
private WFType _wfType;
public WFType WFType
{
get
{
if (_wfType == null) _wfType = WFType.Get(_wfTypeId);
return _wfType;
}
set
{
_wfType = value;
}
}
#endregion
#endregion
#region Functions
#region Save
public ID Save()
{
base.SetAuditTrailProperties();
return WFSetup.Service.Save(this);
}
#endregion
#region Delete
public void Delete()
{
WFSetup.Service.Delete(ID);
}
#endregion
public bool IsInitiator(OrganogramBasic ogNode)
{
return (this.GetNodeRules(ogNode).Count > 0);
}
#region Get
public WFSetupRule GetNodeRule(OrganogramBasic ogNode)
{
ObjectsTemplate<WFSetupRule> oRules = this.GetNodeRules(ogNode);
WFSetupRule oRule = null;
int nMaxPriority = -1;
foreach (WFSetupRule oItem in oRules)
{
if (oItem.Priority > nMaxPriority)
{
oRule = oItem;
nMaxPriority = oItem.Priority;
}
}
return oRule;
}
public WFSetupRule GetRule(ID RuleID)
{
WFSetupRule oRule = null;
foreach (WFSetupRule oItem in this.WFSetupRules)
{
if (oItem.ID.Integer == RuleID.Integer)
{
return oItem;
}
}
return oRule;
}
public ObjectsTemplate<OrganogramBasic>[] GetFullPath(WFSetupRule oRule, int nTier, OrganogramBasic ogNode)
{
ObjectsTemplate<OrganogramBasic>[] oPaths = null;
switch (oRule.WFRuleType)
{
case EnumWFRuleType.StraightAuthority:
if (oRule.StAuthorityLevel - nTier > 0)
{
oPaths = new ObjectsTemplate<OrganogramBasic>[oRule.StAuthorityLevel - (nTier + 1)];
oPaths[0] = new ObjectsTemplate<OrganogramBasic>();
oPaths[0].Add(ogNode);
for (int i = 1; i < oRule.StAuthorityLevel - nTier; i++)
{
oPaths[i] = new ObjectsTemplate<OrganogramBasic>();
oPaths[i].Add(oPaths[i - 1][0].Parent);
}
}
break;
case EnumWFRuleType.FixedOGNode:
case EnumWFRuleType.Designation:
case EnumWFRuleType.OrganizationStructure:
ObjectsTemplate<OrganogramBasic> oP;
oPaths = new ObjectsTemplate<OrganogramBasic>[oRule.LevelDepth - (nTier + 1)];
oPaths[0].Add(ogNode);
for (int i = nTier; i <= oRule.LevelDepth - (nTier + 1); i++)
{
oP = Approvers(oRule, ogNode, i);
foreach (OrganogramBasic oItem in oP)
{
oPaths[i].Add(oItem);
}
}
break;
default:
break;
}
return oPaths;
}
public ObjectsTemplate<OrganogramBasic>[] GetFullPath(OrganogramBasic ogNode)
{
WFSetupRule oRule = this.GetNodeRule(ogNode);
ObjectsTemplate<OrganogramBasic>[] oPaths = null; // = new HR.BO.OrgChart.RAHierarchyNodes();
switch (oRule.WFRuleType)
{
case EnumWFRuleType.StraightAuthority:
oPaths = new ObjectsTemplate<OrganogramBasic>[oRule.StAuthorityLevel + 1];
oPaths[0] = new ObjectsTemplate<OrganogramBasic>();
oPaths[0].Add(ogNode);
for (int i = 1; i <= oRule.StAuthorityLevel; i++)
{
oPaths[i] = new ObjectsTemplate<OrganogramBasic>();
oPaths[i].Add(oPaths[i - 1][0].Parent);
}
break;
case EnumWFRuleType.FixedOGNode:
case EnumWFRuleType.Designation:
case EnumWFRuleType.OrganizationStructure:
ObjectsTemplate<OrganogramBasic> oP;
oPaths = new ObjectsTemplate<OrganogramBasic>[oRule.LevelDepth + 1];
oPaths[0] = new ObjectsTemplate<OrganogramBasic>();
oPaths[0].Add(ogNode);
for (int i = 1; i <= oRule.LevelDepth; i++)
{
oP = Approvers(oRule, ogNode, i);
foreach (OrganogramBasic oItem in oP)
{
oPaths[i] = new ObjectsTemplate<OrganogramBasic>();
oPaths[i].Add(oItem);
}
}
break;
case EnumWFRuleType.Manual:
oPaths = new ObjectsTemplate<OrganogramBasic>[oRule.LevelDepth + 1];
oPaths[0] = new ObjectsTemplate<OrganogramBasic>();
oPaths[0].Add(ogNode);
for (int i = 1; i < oRule.LevelDepth; i++)
{
ObjectsTemplate<OrganogramBasic> oPM = Approvers(oRule, oPaths[i - 1][0], i+1);
oPaths[i] = new ObjectsTemplate<OrganogramBasic>();
foreach (OrganogramBasic oItem in oPM)
{
oPaths[i].Add(oItem);
}
}
break;
default:
break;
}
return oPaths;
}
public ObjectsTemplate<OrganogramBasic>[] GetFullPathOnTier(WFSetupRule oRule, int nTier, OrganogramBasic ogNode)
{
ObjectsTemplate<OrganogramBasic>[] oPaths;
if (nTier > 0)
{
oPaths = new ObjectsTemplate<OrganogramBasic>[nTier];
oPaths[0] = new ObjectsTemplate<OrganogramBasic>();
oPaths[0].Add(ogNode);
for (int i = 1; i < nTier; i++)
{
oPaths[i] = new ObjectsTemplate<OrganogramBasic>();
oPaths[i].Add(oPaths[i - 1][0].Parent);
}
}
else
{
ObjectsTemplate<OrganogramBasic> oP = null;
oPaths = new ObjectsTemplate<OrganogramBasic>[oRule.LevelDepth - 1];
oPaths[0].Add(ogNode);
for (int i = nTier; i <= oRule.LevelDepth; i++)
{
oP = Approvers(oRule, ogNode, i);
foreach (OrganogramBasic oItem in oP)
{
oPaths[i].Add(oItem);
}
}
}
return oPaths;
}
public OrganogramBasic InitiatorToTierNode(OrganogramBasic oInitiatorNode, WFSetupRule oRule, int nTier)
{
ObjectsTemplate<OrganogramBasic>[] oPaths = null;
switch (oRule.WFRuleType)
{
case EnumWFRuleType.StraightAuthority:
oPaths = new ObjectsTemplate<OrganogramBasic>[nTier];
oPaths[0] = new ObjectsTemplate<OrganogramBasic>();
oPaths[0].Add(oInitiatorNode);
for (int i = 1; i < nTier; i++)
{
oPaths[i] = new ObjectsTemplate<OrganogramBasic>();
oPaths[i].Add(oPaths[i - 1][0].Parent);
}
break;
case EnumWFRuleType.FixedOGNode:
case EnumWFRuleType.Designation:
case EnumWFRuleType.OrganizationStructure:
case EnumWFRuleType.Manual:
ObjectsTemplate<OrganogramBasic> oP;
oPaths = new ObjectsTemplate<OrganogramBasic>[nTier];
oPaths[0] = new ObjectsTemplate<OrganogramBasic>();
oPaths[0].Add(oInitiatorNode);
for (int i = 1; i < nTier; i++)
{
oP = Approvers(oRule, oPaths[i - 1][0], i);
oPaths[i] = new ObjectsTemplate<OrganogramBasic>();
foreach (OrganogramBasic oItem in oP)
{
oPaths[i].Add(oItem);
}
}
break;
default:
break;
}
return oPaths[nTier - 1][0];
}
public ObjectsTemplate<OrganogramBasic> Approvers(WFSetupRule oRule, OrganogramBasic ogNode, int ntier)
{
ObjectsTemplate<OrganogramBasic> oApprovarNodes = new ObjectsTemplate<OrganogramBasic>();
switch (oRule.WFRuleType)
{
case EnumWFRuleType.StraightAuthority:
if (oRule.IsRAuthority == false)
{
if (ogNode.Parent == null) throw new ServiceException("Approver Organogram position/node is vacant. please assign an employee at the postion first.");
oApprovarNodes.Add(ogNode.Parent);
}
else
{
ObjectsTemplate<OrganogramBasic> rpau = ogNode.GetAthorities(EnumAuthorityType.Reporting);
foreach (OrganogramBasic og in rpau)
{
oApprovarNodes.Add(og);
}
}
break;
case EnumWFRuleType.OrganizationStructure:
oApprovarNodes = oRule.Approver(ogNode, ntier);
break;
case EnumWFRuleType.FixedOGNode:
oApprovarNodes = oRule.Approver(ogNode, ntier);
break;
case EnumWFRuleType.Designation:
oApprovarNodes = oRule.Approver(ogNode, ntier);
break;
case EnumWFRuleType.Manual:
oApprovarNodes = oRule.Approver(ogNode, ntier);
break;
default:
break;
}
return oApprovarNodes;
}
public ObjectsTemplate<WFSetupRule> GetNodeRules(OrganogramBasic ogNode)
{
ObjectsTemplate<WFSetupRule> oselectedRules = new ObjectsTemplate<WFSetupRule>();
foreach (WFSetupRule oItem in this.WFSetupRules)
{
switch (oItem.WFRuleType)
{
case EnumWFRuleType.StraightAuthority:
if (oItem.WFRuleDeatilDesignations.Count > 0 && oItem.WFRuleDeatilOSs.Count > 0)
{
if (WFRuleDetailDesignation.IsInitiator(oItem.WFRuleDeatilDesignations, ogNode.DesignationID) == true &&
WFRuleDetailOS.IsInitiator(oItem.WFRuleDeatilOSs, ogNode.DepartmentID) == true)
{
oselectedRules.Add(oItem);
}
}
else if (oItem.WFRuleDeatilDesignations.Count > 0)
{
if (WFRuleDetailDesignation.IsInitiator(oItem.WFRuleDeatilDesignations,
ogNode.DesignationID) == true) oselectedRules.Add(oItem);
}
else if (oItem.WFRuleDeatilOSs.Count > 0)
{
if (WFRuleDetailOS.IsInitiator(oItem.WFRuleDeatilOSs,
ogNode.DepartmentID) == true) oselectedRules.Add(oItem);
}
else oselectedRules.Add(oItem);
break;
case EnumWFRuleType.OrganizationStructure:
if (WFRuleDetailOS.IsInitiator(oItem.WFRuleDeatilOSs, ogNode.DesignationID) == true)
{
oselectedRules.Add(oItem);
}
break;
case EnumWFRuleType.Designation:
if (WFRuleDetailDesignation.IsInitiator(oItem.WFRuleDeatilDesignations, ogNode.DesignationID) == true)
{
oselectedRules.Add(oItem);
}
break;
case EnumWFRuleType.FixedOGNode:
if (WFRuleDetailNode.IsInitiator(oItem.WFRuleDetailNodes, ogNode.ID))
{
oselectedRules.Add(oItem);
}
break;
case EnumWFRuleType.Manual:
if (WFRuleDetailManual.IsInitiator(oItem.WFRuleDetailManual, ogNode.ID))
{
oselectedRules.Add(oItem);
}
break;
default:
break;
}
}
return oselectedRules;
}
public static WFSetup GetByWFTypeID(ID nType)
{
WFSetup WFSetup = null;
#region Cache Header
WFSetup = (WFSetup)_cache["Get", nType];
if (WFSetup != null)
return WFSetup;
#endregion
WFSetup = WFSetup.Service.GetByWFTypeID(nType);
#region Cache Footer
_cache.Add(WFSetup, "Get", nType);
#endregion
return WFSetup;
}
public static WFSetup Get(ID nID)
{
WFSetup wfSetup = null;
#region Cache Header
wfSetup = (WFSetup)_cache["Get", nID];
if (wfSetup != null)
return wfSetup;
#endregion
wfSetup = WFSetup.Service.Get(nID);
#region Cache Footer
_cache.Add(wfSetup, "Get", nID);
#endregion
return wfSetup;
}
public static ObjectsTemplate<WFSetup> Get()
{
#region Cache Header
ObjectsTemplate<WFSetup> wfSetup = _cache["Get"] as ObjectsTemplate<WFSetup>;
if (wfSetup != null)
return wfSetup;
#endregion
try
{
wfSetup = Service.Get();
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(wfSetup, "Get");
#endregion
return wfSetup;
}
public static ObjectsTemplate<WFRuleDetailDesignation> Get4WFRuleDD(ID wfRuleDetailID)
{
#region Cache Header
ObjectsTemplate<WFRuleDetailDesignation> oWFRuleDetailDesignation = _cache["Get4WFRuleDD", wfRuleDetailID] as ObjectsTemplate<WFRuleDetailDesignation>;
if (oWFRuleDetailDesignation != null)
return oWFRuleDetailDesignation;
#endregion
try
{
oWFRuleDetailDesignation = Service.Get4WFRuleDD(wfRuleDetailID);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(oWFRuleDetailDesignation, "Get4WFRuleDD", wfRuleDetailID);
#endregion
return oWFRuleDetailDesignation;
}
public static ObjectsTemplate<WFRuleDetailNode> Get4WFRuleNode(ID wfRuleNodeID)
{
#region Cache Header
ObjectsTemplate<WFRuleDetailNode> oWFRuleNode = _cache["Get4WFRuleNode", wfRuleNodeID] as ObjectsTemplate<WFRuleDetailNode>;
if (oWFRuleNode != null)
return oWFRuleNode;
#endregion
try
{
oWFRuleNode = Service.Get4WFRuleNode(wfRuleNodeID);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(oWFRuleNode, "Get4WFRuleNode", wfRuleNodeID);
#endregion
return oWFRuleNode;
}
public static ObjectsTemplate<WFRuleDetailManual> Get4WFRuleManual(ID wfRuleNodeID)
{
ObjectsTemplate<WFRuleDetailManual> oWFRuleNode = null;
try
{
oWFRuleNode = Service.Get4WFRuleDetailManual(wfRuleNodeID);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
return oWFRuleNode;
}
public static ObjectsTemplate<WFSetupRule> Get4WFSetupRule(ID wfSetupRuleID)
{
#region Cache Header
ObjectsTemplate<WFSetupRule> oWFSetupRule = _cache["Get4WFSetupRule", wfSetupRuleID] as ObjectsTemplate<WFSetupRule>;
if (oWFSetupRule != null)
return oWFSetupRule;
#endregion
try
{
oWFSetupRule = Service.Get4WFSetupRule(wfSetupRuleID);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(oWFSetupRule, "Get4WFSetupRule", wfSetupRuleID);
#endregion
return oWFSetupRule;
}
public static ObjectsTemplate<WFRuleDetailOS> Get4WFRuleDetailOS(ID osID)
{
#region Cache Header
ObjectsTemplate<WFRuleDetailOS> oWFRuleDetailOS = _cache["Get4WFRuleDetailOS", osID] as ObjectsTemplate<WFRuleDetailOS>;
if (oWFRuleDetailOS != null)
return oWFRuleDetailOS;
#endregion
try
{
oWFRuleDetailOS = Service.Get4WFRuleDetailOS(osID);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(oWFRuleDetailOS, "Get4WFRuleDetailOS", osID);
#endregion
return oWFRuleDetailOS;
}
#endregion
public bool CheckPriority(int PriorityLevel)
{
foreach (WFSetupRule oItem in this.WFSetupRules)
{
if (oItem.Priority == PriorityLevel)
{
return true;
}
}
return false;
}
#endregion
#region Service Factory
internal static IWFSetupService Service
{
get { return Services.Factory.CreateService<IWFSetupService>(typeof(IWFSetupService)); }
}
#endregion
}
#endregion
#region Interface
public interface IWFSetupService
{
ID Save(WFSetup item);
void Delete(ID Id);
WFSetup Get(ID id);
WFSetup GetByWFTypeID(ID nType);
ObjectsTemplate<WFSetup> Get();
ObjectsTemplate<WFRuleDetailDesignation> Get4WFRuleDD(ID ruleid);
ObjectsTemplate<WFRuleDetailNode> Get4WFRuleNode(ID ruleId);
ObjectsTemplate<WFSetupRule> Get4WFSetupRule(ID id);
ObjectsTemplate<WFRuleDetailOS> Get4WFRuleDetailOS(ID ruleid);
ObjectsTemplate<WFRuleDetailManual> Get4WFRuleDetailManual(ID ruleid);
}
#endregion
}