CEL_Payroll/Payroll.BO/Workflow/WFSetupRule.cs
2024-09-17 14:30:13 +06:00

598 lines
22 KiB
C#

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
{
[Serializable]
public class WFSetupRule : BasicBaseObject
{
#region Cache Store
private static Cache _cache = new Cache(typeof(WFSetupRule));
#endregion
#region Constructor & Private Declarations
public WFSetupRule()
{
_wfSetupId = null;
_stAuthorityLevel = 0;
_priority = 0;
_wfRuleType = EnumWFRuleType.FixedOGNode;
_levelDepth = 0;
_reqAppAll = false;
_autoNotificationNode = null;
_finalDestinationNode = null;
_bIsRAuthority = false;
}
#endregion
#region Properties
#region WfSetupId : ID
private ID _wfSetupId;
public ID WFSetupId
{
get { return _wfSetupId; }
set { _wfSetupId = value; }
}
#endregion
#region StAuthorityLevel : int
private int _stAuthorityLevel;
public int StAuthorityLevel
{
get { return _stAuthorityLevel; }
set { _stAuthorityLevel = value; }
}
#endregion
#region Priority : int
private int _priority;
public int Priority
{
get { return _priority; }
set { _priority = value; }
}
#endregion
#region Property WFRuleType : EnumWFRuleType
private EnumWFRuleType _wfRuleType;
public EnumWFRuleType WFRuleType
{
get { return _wfRuleType; }
set { _wfRuleType = value; }
}
#endregion
#region LevelDepth : int
private int _levelDepth;
public int LevelDepth
{
get { return _levelDepth; }
set { _levelDepth = value; }
}
#endregion
#region ReqAppAll : Boolean
private bool _reqAppAll;
public bool ReqAppAll
{
get { return _reqAppAll; }
set { _reqAppAll = value; }
}
private string _name;
public string Name
{
get { return _name; }
set { _name = value; }
}
#endregion
#region AutoNotificationNode : ID
private ID _autoNotificationNode;
public ID AutoNotificationNode
{
get { return _autoNotificationNode; }
set { _autoNotificationNode = value; }
}
#endregion
#region FinalDestinationNode : int
private ID _finalDestinationNode;
public ID FinalDestinationNode
{
get { return _finalDestinationNode; }
set { _finalDestinationNode = value; }
}
#endregion
#region IsRAuthority : Boolean
private bool _bIsRAuthority;
public bool IsRAuthority
{
get { return _bIsRAuthority; }
set { _bIsRAuthority = value; }
}
#endregion
#region WFRuleDeatilDesignations
private ObjectsTemplate<WFRuleDetailDesignation> _wFRuleDeatilDesignations;
public ObjectsTemplate<WFRuleDetailDesignation> WFRuleDeatilDesignations
{
get
{
if (_wFRuleDeatilDesignations == null && this.ID != null && this.ID.IsUnassigned == false)
_wFRuleDeatilDesignations = WFSetup.Get4WFRuleDD(this.ID);
return _wFRuleDeatilDesignations;
}
set { _wFRuleDeatilDesignations = value; }
}
#endregion
#region WFRuleDeatilOSs
private ObjectsTemplate<WFRuleDetailOS> _wFRuleDeatilOSs;
public ObjectsTemplate<WFRuleDetailOS> WFRuleDeatilOSs
{
get
{
if (_wFRuleDeatilOSs == null) _wFRuleDeatilOSs = new ObjectsTemplate<WFRuleDetailOS>();
return _wFRuleDeatilOSs;
}
set { _wFRuleDeatilOSs = value; }
}
#endregion
#region WFRuleDetailNodes
private ObjectsTemplate<WFRuleDetailNode> _wFRuleDetailNodes;
public ObjectsTemplate<WFRuleDetailNode> WFRuleDetailNodes
{
get
{
if (_wFRuleDetailNodes == null && this.ID != null && this.ID.IsUnassigned == false)
_wFRuleDetailNodes = WFSetup.Get4WFRuleNode(this.ID);
return _wFRuleDetailNodes;
}
set { _wFRuleDetailNodes = value; }
}
#endregion
#region WFRuleDetailNodes
private ObjectsTemplate<WFRuleDetailManual> _wFRuleDetailManual;
public ObjectsTemplate<WFRuleDetailManual> WFRuleDetailManual
{
get
{
if (_wFRuleDetailManual == null && this.ID != null && this.ID.IsUnassigned == false)
_wFRuleDetailManual = WFSetup.Get4WFRuleManual(this.ID);
return _wFRuleDetailManual;
}
set { _wFRuleDetailManual = value; }
}
#endregion
#endregion
#region Functions
public bool IsNextTier(int nNextTier)
{
switch (this.WFRuleType)
{
case EnumWFRuleType.StraightAuthority:
break;
case EnumWFRuleType.FixedOGNode:
foreach (WFRuleDetailNode oItem in this.WFRuleDetailNodes)
{
if (oItem.SequenceId == nNextTier)
{
return true;
}
}
return false;
break;
case EnumWFRuleType.Designation:
foreach (WFRuleDetailDesignation oItem in this.WFRuleDeatilDesignations)
if (oItem.SequenceId == nNextTier)
return true;
break;
case EnumWFRuleType.OrganizationStructure:
foreach (WFRuleDetailOS oItem in this.WFRuleDeatilOSs)
if (oItem.SequenceId == nNextTier)
return true;
break;
case EnumWFRuleType.Manual:
foreach (WFRuleDetailManual oItem in this.WFRuleDetailManual)
if (oItem.SequenceId == nNextTier)
return true;
break;
default:
break;
}
return false;
}
public bool HasNextApprovar(OrganogramBasic Node, int nTier)
{
// following block is Only to capture IDLC Exception
if (WFRuleType == EnumWFRuleType.StraightAuthority && this.WFSetupId.Integer == 1)
{
if (nTier == 3)
{
if (Node.Parent == null) return false;
if (Node.Parent.Parent == null) return false;
}
}
bool bNext = false;
if (nTier <= this.LevelDepth)
{
bNext = true;
}
return bNext;
}
public bool xHasNextApprovar(int nTier)
{
bool bNext = false;
if (nTier <= this.LevelDepth)
{
bNext = true;
}
return bNext;
}
public ObjectsTemplate<WFRuleDetailManual> RemoveaSequence(ObjectsTemplate<WFRuleDetailManual> oRuleDetailManual, int nSquenceID)
{
ObjectsTemplate<WFRuleDetailManual> truleDetailmn = new ObjectsTemplate<WFRuleDetailManual>();
foreach (WFRuleDetailManual oItem in oRuleDetailManual)
{
if (oItem.SequenceId != nSquenceID)
{
truleDetailmn.Add(oItem);
}
}
oRuleDetailManual.Clear();
foreach (WFRuleDetailManual oItem in truleDetailmn)
{
oRuleDetailManual.Add(oItem);
}
return oRuleDetailManual;
}
public ObjectsTemplate<WFRuleDetailNode> RemoveaSequence(ObjectsTemplate<WFRuleDetailNode> oRuleDetailNodes, int nSquenceID)
{
ObjectsTemplate<WFRuleDetailNode> truleDetailNodes = new ObjectsTemplate<WFRuleDetailNode>();
foreach (WFRuleDetailNode oItem in oRuleDetailNodes)
{
if (oItem.SequenceId != nSquenceID)
{
truleDetailNodes.Add(oItem);
}
}
oRuleDetailNodes.Clear();
foreach (WFRuleDetailNode oItem in truleDetailNodes)
{
oRuleDetailNodes.Add(oItem);
}
return oRuleDetailNodes;
}
public ObjectsTemplate<WFRuleDetailDesignation> RemoveaSequence(ObjectsTemplate<WFRuleDetailDesignation> oRuledesignations, int nSquenceID)
{
ObjectsTemplate<WFRuleDetailDesignation> truledesignations = new ObjectsTemplate<WFRuleDetailDesignation>();
foreach (WFRuleDetailDesignation oItem in oRuledesignations)
{
if (oItem.SequenceId != nSquenceID)
{
truledesignations.Add(oItem);
}
}
oRuledesignations.Clear();
foreach (WFRuleDetailDesignation oItem in truledesignations)
{
oRuledesignations.Add(oItem);
}
return oRuledesignations;
}
private ObjectsTemplate<OrganogramBasic> GetApprover(OrganogramBasic oNode, int nTier)
{
ObjectsTemplate<OrganogramBasic> opprovers = new ObjectsTemplate<OrganogramBasic>();
int nCount = 0;
int nTop = 0;
switch (this.WFRuleType)
{
case EnumWFRuleType.StraightAuthority:
break;
case EnumWFRuleType.FixedOGNode:
foreach (WFRuleDetailNode oItem in this.WFRuleDetailNodes)
{
if (oItem.SequenceId == nTier)
{
OrganogramBasic obasic = OrganogramBasic.Get(oItem.NodeId);
opprovers.Add(obasic);
}
}
break;
case EnumWFRuleType.Designation:
#region Designation workflow
nCount = 0;
foreach (WFRuleDetailDesignation oItem in this.WFRuleDeatilDesignations)
if (oItem.SequenceId == nTier)
nCount = nCount + 1;
int[] designationIDs = new int[nCount];
nTop = 0;
for (int i = 0; i < this.WFRuleDeatilDesignations.Count; i++)
{
if (this.WFRuleDeatilDesignations[i].SequenceId == nTier)
{
designationIDs[nTop] = this.WFRuleDeatilDesignations[i].DesignationId.Integer;
nTop = nTop + 1;
}
}
if (designationIDs.Length == 0)
throw new ServiceException("Approver not found in the Organogram setup, Contact your System Administrator");
OrganogramBasic oApprover = oNode;
bool bBreak = false;
while (oApprover.Parent != null && bBreak != true)
{
oApprover = oApprover.Parent;
if (oApprover.EmployeeAssigned == true)
{
for (int i = 0; i < nTop; i++)
{
if (designationIDs[i] == oApprover.DesignationID.Integer)
{
opprovers.Add(oApprover);
bBreak = true;
break;
}
}
}
}
#endregion Designation workflow
break;
case EnumWFRuleType.OrganizationStructure:
#region Department Workflow
foreach (WFRuleDetailOS oItem in this.WFRuleDeatilOSs)
if (oItem.SequenceId == nTier)
nCount = nCount + 1;
int[] depIDs = new int[nCount];
nTop = 0;
for (int i = 0; i < this.WFRuleDeatilOSs.Count; i++)
{
if (this.WFRuleDeatilOSs[i].SequenceId == nTier)
{
depIDs[nTop] = this.WFRuleDeatilOSs[i].OsID.Integer;
nTop = nTop + 1;
}
}
if (depIDs.Length == 0)
throw new ServiceException("Approver not found in the Organogram setup, Contact your System Administrator");
OrganogramBasic oogApprover;
oogApprover = oNode;
bool bogBreak = false;
while (oogApprover.Parent != null && bogBreak != true)
{
oogApprover = oogApprover.Parent;
if (oogApprover.EmployeeAssigned == true)
{
for (int i = 0; i < nTop; i++)
{
if (depIDs[i] == oogApprover.DepartmentID.Integer)
{
opprovers.Add(oogApprover);
bogBreak = true;
break;
}
}
}
}
#endregion Department Workflow
break;
case EnumWFRuleType.Manual:
#region Department Workflow
opprovers = new ObjectsTemplate<OrganogramBasic>();
foreach (WFRuleDetailManual oItem in this.WFRuleDetailManual)
{
if (oItem.SequenceId == nTier)
{
switch (oItem.RuleType)
{
case enumWFRuleManual.Employee:
break;
case enumWFRuleManual.Line_Manager:
if (oNode.ParentID != null)
{
OrganogramBasic lm = OrganogramBasic.Get(oNode.ParentID);
if (lm != null)
opprovers.Add(lm);
}
break;
case enumWFRuleManual.Positions_type:
opprovers = OrganogramBasic.GetbyPositionTypeid(Ease.CoreV35.Model.ID.FromInteger(oItem.ObjectID));
if (opprovers != null && opprovers.Count > 1)
{
ObjectsTemplate<OrganogramBasic> lineApps = new ObjectsTemplate<OrganogramBasic>();
OrganogramBasic oparent = oNode.Parent;
while (true)
{
if (oparent == null) break;
OrganogramBasic obasic = opprovers.Find(delegate(OrganogramBasic ft) { return ft.ID.Integer == oparent.ID.Integer; });
if (obasic != null)
{
lineApps.Add(obasic);
break;
}
oparent = oparent.Parent;
}
opprovers = lineApps;
}
break;
case enumWFRuleManual.Og_Nodes:
if (oNode.ParentID != null)
{
OrganogramBasic og = OrganogramBasic.Get(ID.FromInteger(oItem.ObjectID));
if (og != null)
opprovers.Add(og);
}
break;
default:
break;
}
}
}
if (opprovers == null || opprovers.Count == 0)
throw new ServiceException("Approver not found in the Organogram setup, Contact your System Administrator");
#endregion Department Workflow
break;
default:
break;
}
if (opprovers.Count == 0)
throw new ServiceException("Approver not found for the node:" + oNode.PositionName);
return opprovers;
}
public ObjectsTemplate<OrganogramBasic> Approver(OrganogramBasic oNode, int nTier)
{
ObjectsTemplate<OrganogramBasic> oApprovers = null;
switch (this.WFRuleType)
{
case EnumWFRuleType.StraightAuthority:
break;
case EnumWFRuleType.OrganizationStructure:
if (this.IsNextTier(nTier)) oApprovers = this.GetApprover(oNode, nTier);
else throw new ServiceException("Approver not found for the node :" + oNode.PositionName + "; Rule: Dynamic");
break;
case EnumWFRuleType.FixedOGNode:
if (this.IsNextTier(nTier)) oApprovers = this.GetApprover(oNode, nTier);
else throw new ServiceException("Approver not found for the node:" + oNode.PositionName + "; Rule: Fixed node");
break;
case EnumWFRuleType.Designation:
if (this.IsNextTier(nTier)) oApprovers = this.GetApprover(oNode, nTier);
else throw new ServiceException("Approver not found for the node:" + oNode.PositionName + "; Rule: Designation");
break;
case EnumWFRuleType.Manual:
if (this.IsNextTier(nTier)) oApprovers = this.GetApprover(oNode, nTier);
else throw new ServiceException("Approver not found for the node:" + oNode.PositionName + "; Rule: Designation");
break;
default:
throw new ServiceException("Approver not found for the node:" + oNode.PositionName);
break;
}
return oApprovers;
}
public string GetRuleDetailDesignationDescription(int nSequenceID)
{
string desc = string.Empty;
foreach (WFRuleDetailDesignation oItem in this.WFRuleDeatilDesignations)
if (oItem.SequenceId == nSequenceID) desc = desc + oItem.Designation.Name + ", ";
if (WFRuleDeatilDesignations.Count >= 1) desc = desc.Substring(0, desc.Length - 2);
return desc;
}
public string GetRuleDetailOSDescription(int nSequenceID)
{
string desc = string.Empty;
foreach (WFRuleDetailOS oItem in this.WFRuleDeatilOSs)
if (oItem.SequenceId == nSequenceID) desc = desc + oItem.Department.Name + ", ";
if (WFRuleDeatilOSs.Count >= 1) desc = desc.Substring(0, desc.Length - 2);
return desc;
}
public string GetRuleDetailNodeDescription(int nSequenceID)
{
string desc = string.Empty;
foreach (WFRuleDetailNode oItem in WFRuleDetailNodes)
if (oItem.SequenceId == nSequenceID) desc = desc + oItem.OrganogramBasic.PositionName + ", ";
if (WFRuleDetailNodes.Count >= 1) desc = desc.Substring(0, desc.Length - 2);
return desc;
}
public string GetRuleDetailManual(int nSequenceID)
{
string desc = string.Empty;
foreach (WFRuleDetailManual oItem in WFRuleDetailManual)
{
if (oItem.SequenceId == nSequenceID)
{
if (oItem.RuleType == enumWFRuleManual.Employee)
desc = desc + " Any Employee" + ", ";
else if (oItem.RuleType == enumWFRuleManual.Line_Manager)
desc = desc + " Lime Manager" + ", ";
else if (oItem.RuleType == enumWFRuleManual.Og_Nodes)
{
OrganogramBasic obasic = OrganogramBasic.Get(ID.FromInteger(oItem.ObjectID));
if (obasic == null)
desc = desc + " (Error), ";
else desc = desc + obasic.PositionName + ", ";
}
else
{
OGPositionType obasic = OGPositionType.Get(ID.FromInteger(oItem.ObjectID));
desc = desc + obasic.Name + ", ";
}
}
}
if (WFRuleDetailManual.Count >= 1) desc = desc.Substring(0, desc.Length - 2);
return desc;
}
#endregion
}
}