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 _wFRuleDeatilDesignations; public ObjectsTemplate 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 _wFRuleDeatilOSs; public ObjectsTemplate WFRuleDeatilOSs { get { if (_wFRuleDeatilOSs == null) _wFRuleDeatilOSs = new ObjectsTemplate(); return _wFRuleDeatilOSs; } set { _wFRuleDeatilOSs = value; } } #endregion #region WFRuleDetailNodes private ObjectsTemplate _wFRuleDetailNodes; public ObjectsTemplate 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; public ObjectsTemplate 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 RemoveaSequence(ObjectsTemplate oRuleDetailManual, int nSquenceID) { ObjectsTemplate truleDetailmn = new ObjectsTemplate(); 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 RemoveaSequence(ObjectsTemplate oRuleDetailNodes, int nSquenceID) { ObjectsTemplate truleDetailNodes = new ObjectsTemplate(); 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 RemoveaSequence(ObjectsTemplate oRuledesignations, int nSquenceID) { ObjectsTemplate truledesignations = new ObjectsTemplate(); 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 GetApprover(OrganogramBasic oNode, int nTier) { ObjectsTemplate opprovers = new ObjectsTemplate(); 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(); 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 lineApps = new ObjectsTemplate(); 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 Approver(OrganogramBasic oNode, int nTier) { ObjectsTemplate 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 } }