799 lines
34 KiB
C#
799 lines
34 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;
|
|
using System.Text.RegularExpressions;
|
|
|
|
namespace Payroll.BO
|
|
{
|
|
[Serializable]
|
|
public class WFManager<T> where T : IworkflowInterface
|
|
{
|
|
#region class variable
|
|
private OrganogramBasic _ogNode;
|
|
private Employee _employee = null;
|
|
private WFSetup _wfSetup = null;
|
|
private WFMovementTran _MoveTran = null;
|
|
private T _wfinterface;
|
|
|
|
#endregion class variable
|
|
|
|
#region constructor
|
|
public WFManager(T ob, Employee oEmployee)
|
|
{
|
|
_wfinterface = ob;
|
|
_employee = oEmployee;
|
|
ObjectsTemplate<OrganogramEmployee> emps = OrganogramEmployee.GetByEmp(oEmployee.ID);
|
|
if (emps == null || emps.Count == 0)
|
|
{
|
|
throw new Exception("Employee is not posted in Organ-O-Gram.");
|
|
}
|
|
else _ogNode = OrganogramBasic.Get(emps[0].NodeID);
|
|
_wfSetup = WFSetup.Get(_wfinterface.SetupID);
|
|
}
|
|
private T ConvertToT<T>(IworkflowInterface oTran) where T : IworkflowInterface
|
|
{
|
|
return (T)oTran;
|
|
}
|
|
public WFManager(int nTranID, Employee oEmployee)
|
|
{
|
|
_MoveTran = WFMovementTran.Get(ID.FromInteger(nTranID));
|
|
_wfinterface = this.ConvertToT<T>(_MoveTran);
|
|
|
|
_employee = oEmployee;
|
|
ObjectsTemplate<OrganogramEmployee> oganogramNode = OrganogramEmployee.GetByEmp(_employee.ID);
|
|
if (oganogramNode == null || oganogramNode.Count == 0)
|
|
{
|
|
throw new Exception("Employee is not yet assinged in Organ-O-Gram.");
|
|
}
|
|
else _ogNode = OrganogramBasic.Get(oganogramNode[0].NodeID);
|
|
|
|
_wfSetup = WFSetup.Get(_MoveTran.SetupID);
|
|
_MoveTran.WFSetup = _wfSetup;
|
|
}
|
|
#endregion constructor
|
|
public bool IsInitiator(int ntranID)
|
|
{
|
|
OrganogramBasic oNode = WFMovementTran.Service.InitiatorNode(_MoveTran.Uniquenumber);
|
|
if (oNode != null)
|
|
{
|
|
if (oNode.ID.Integer == _ogNode.ID.Integer)
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
public bool IsInitiator()
|
|
{
|
|
return _wfSetup.IsInitiator(_ogNode);
|
|
}
|
|
|
|
public ObjectsTemplate<OrganogramBasic>[] Path()
|
|
{
|
|
ObjectsTemplate<OrganogramBasic>[] oPath = _wfSetup.GetFullPath(_ogNode);
|
|
return oPath;
|
|
}
|
|
public ObjectsTemplate<OrganogramBasic>[] Path(WFMovementTran wfTran)
|
|
{
|
|
ObjectsTemplate<OrganogramBasic>[] oPath = _wfSetup.GetFullPath(_wfSetup.GetRule(wfTran.WFRuleID), wfTran.Tier, _ogNode);
|
|
return oPath;
|
|
}
|
|
|
|
public void InitiateProcess(int nObjectID, string sRemarks)
|
|
{
|
|
try
|
|
{
|
|
string sTaskRemrks = "";
|
|
WFSetupRule oRule;
|
|
WFMovementTran oTran = new WFMovementTran();
|
|
|
|
oTran.WFSetup = _wfSetup;
|
|
oTran.FromNodeID = _ogNode.ID;
|
|
oTran.FromEmployeeID = _employee.ID;
|
|
|
|
oTran.Remarks = sRemarks;
|
|
oTran.SetupID = _wfSetup.ID;
|
|
if (oTran.Remarks == "Cancel request")
|
|
oTran.Status = enumwfStatus.Cancel_Request;
|
|
else
|
|
oTran.Status = enumwfStatus.Received;
|
|
|
|
oRule = _wfSetup.GetNodeRule(_ogNode);
|
|
oTran.WFRuleID = oRule.ID;
|
|
|
|
ObjectsTemplate<WFMovementNext> onextItems = new ObjectsTemplate<WFMovementNext>();
|
|
|
|
onextItems = Approvers(oRule, workflowConstants.WF_Initiator_Tier + 1);
|
|
|
|
oTran.WFMNexts = new ObjectsTemplate<WFMovementNext>();
|
|
WFMovementNext oNext = new WFMovementNext();
|
|
oNext.Status = enumwfStatus.Passed;
|
|
oNext.Description = onextItems[0].Description;
|
|
oNext.EmployeeID = oTran.FromEmployeeID;
|
|
oNext.NodeID = oTran.FromNodeID;
|
|
oNext.ReceiveStatus = EnumWFReceiveStatus.ALREADY_OPENED;
|
|
oNext.Remarks = sRemarks;
|
|
oTran.WFMNexts.Add(oNext);
|
|
oTran.WFMNexts.AddRange(onextItems);
|
|
|
|
oTran.Tier = oTran.Tier + 1;
|
|
oTran.Uniquenumber = WFMovementTran.Service.GetUniqueNumber();
|
|
oTran.ObjectID = ID.FromInteger(nObjectID);
|
|
oTran.Senttime = DateTime.Now;
|
|
oTran.ObjectDescription = _wfinterface.ObjectDescription; // get the object description from interface
|
|
oTran.SetSourceObjectStatus();
|
|
sTaskRemrks = oTran.ObjectDescription;
|
|
// sTaskRemrks = "(" + _employee.EmployeeNo + ") " + _employee.Name
|
|
//+ " has submitted a " + _wfSetup.WFType.Name + " Application";
|
|
|
|
_MoveTran = oTran;
|
|
oTran.WFMTasks = this.MoveMentTasks(oTran.WFMNexts, oRule, workflowConstants.WF_Initiator_Tier, 0, enumwfStatus.Received, sTaskRemrks);
|
|
|
|
|
|
oTran.Save();
|
|
SendMail(oTran);
|
|
}
|
|
catch (MailSenderException ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new ServiceException(ex.Message);
|
|
}
|
|
}
|
|
public void Submit(int nTranID, string Remarks)
|
|
{
|
|
WFMovementTran oNextApprovar = null;
|
|
WFSetupRule oRule = _wfSetup.GetRule(_MoveTran.WFRuleID);
|
|
string sTaskRemrks = "";
|
|
try
|
|
{
|
|
|
|
_MoveTran.UpdateStatus(_ogNode, Remarks, enumwfStatus.Approve);
|
|
|
|
if (_MoveTran.IsReadytoMoveNextTier(oRule) && oRule.HasNextApprovar(_ogNode, _MoveTran.Tier + 1))
|
|
{
|
|
oNextApprovar = new WFMovementTran();
|
|
|
|
|
|
oNextApprovar.FromNodeID = _ogNode.ID;
|
|
oNextApprovar.FromEmployeeID = _employee.ID;
|
|
oNextApprovar.Remarks = _MoveTran.GetRemarks();
|
|
oNextApprovar.SetupID = _wfSetup.ID;
|
|
oNextApprovar.WFRuleID = oRule.ID;
|
|
oNextApprovar.Uniquenumber = _MoveTran.Uniquenumber;
|
|
oNextApprovar.ObjectID = _MoveTran.ObjectID;
|
|
|
|
oNextApprovar.Tier = _MoveTran.Tier + 1;
|
|
oNextApprovar.WFMNexts = this.Approvers(oRule, _MoveTran.Tier + 1);
|
|
|
|
// In Rule manual,
|
|
if (oRule.WFRuleType == EnumWFRuleType.Manual && oNextApprovar.WFMNexts.Count == 1)
|
|
{
|
|
if (oNextApprovar.WFMNexts[0].EmployeeID == _employee.ID)
|
|
{
|
|
_MoveTran.Tier = _MoveTran.Tier + 1;
|
|
Submit(_MoveTran.ID.Integer, Remarks);
|
|
return;
|
|
}
|
|
}
|
|
oNextApprovar.Status = enumwfStatus.Received;
|
|
|
|
if (_MoveTran.Status == enumwfStatus.Cancel_Request)
|
|
{
|
|
_MoveTran.Status = enumwfStatus.Cancel_Request;
|
|
}
|
|
else
|
|
_MoveTran.Status = enumwfStatus.Passed;
|
|
|
|
|
|
oNextApprovar.ObjectDescription = oNextApprovar.GetSourceObjectDescription(); // get the object description from interface
|
|
sTaskRemrks = _wfSetup.WFType.Name + " Application has already been approved by " + " "
|
|
+ _employee.Name + ", " + _employee.DescriptionText + "";
|
|
|
|
|
|
oNextApprovar.WFMTasks = this.MoveMentTasks(oNextApprovar.WFMNexts, oRule, _MoveTran.Tier, _MoveTran.Uniquenumber, enumwfStatus.Passed, sTaskRemrks);
|
|
|
|
oNextApprovar.SetSourceObjectStatus();
|
|
|
|
oNextApprovar.Submit(_MoveTran);
|
|
|
|
SendMail(oNextApprovar);
|
|
}
|
|
else
|
|
{
|
|
if (_MoveTran.Remarks == "Cancel request" || _MoveTran.Status == enumwfStatus.Cancel_Request)
|
|
_MoveTran.Status = enumwfStatus.Cancel;
|
|
else
|
|
_MoveTran.Status = enumwfStatus.End;
|
|
_MoveTran.Remarks = sTaskRemrks;
|
|
_MoveTran.SetSourceObjectStatus();
|
|
|
|
|
|
foreach (WFMovementNext otran in _MoveTran.WFMNexts)
|
|
otran.Status = enumwfStatus.End;
|
|
|
|
sTaskRemrks = _wfSetup.WFType.Name + " Application has been approved by " + " " + _employee.Name + ", " + _employee.DescriptionText +
|
|
" and completed approval process successfully.";
|
|
_MoveTran.WFMTasks = this.MoveMentTasks(_MoveTran.WFMNexts, oRule, _MoveTran.Tier, _MoveTran.Uniquenumber, enumwfStatus.End, sTaskRemrks);
|
|
|
|
|
|
_MoveTran.Save();
|
|
if (_MoveTran.WFMTasks != null)
|
|
{
|
|
SendMail(_MoveTran);
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
catch (MailSenderException ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
catch (Exception Ex)
|
|
{
|
|
throw new ServiceException(Ex.Message);
|
|
}
|
|
}
|
|
public void Decline(int nTranID, string Remarks)
|
|
{
|
|
string sTaskRemrks = "";
|
|
try
|
|
{
|
|
WFSetupRule oRule = _wfSetup.GetRule(_MoveTran.WFRuleID);
|
|
_MoveTran.UpdateStatus(_ogNode, Remarks, enumwfStatus.Decline);
|
|
|
|
|
|
if (_MoveTran.IsReadytoMoveNextTier(oRule))
|
|
{
|
|
if (_MoveTran.Remarks == "Cancel request" || _MoveTran.Status == enumwfStatus.Cancel_Request)
|
|
{
|
|
_MoveTran.Status = enumwfStatus.End;
|
|
sTaskRemrks = _wfSetup.WFType.Name + " Cancel request has been Declined by " + " " + _employee.Name + ", " + _employee.DescriptionText;
|
|
}
|
|
else
|
|
{
|
|
_MoveTran.Status = enumwfStatus.Decline;
|
|
sTaskRemrks = _wfSetup.WFType.Name + " Application has been Declined by " + " " + _employee.Name + ", " + _employee.DescriptionText;
|
|
}
|
|
}
|
|
_MoveTran.WFMTasks = this.MoveMentTasks(_MoveTran.WFMNexts, oRule, _MoveTran.Tier, _MoveTran.Uniquenumber, enumwfStatus.Decline, sTaskRemrks);
|
|
_MoveTran.Remarks = sTaskRemrks;
|
|
|
|
_MoveTran.SetSourceObjectStatus();
|
|
|
|
_MoveTran.Save();
|
|
SendMail(_MoveTran);
|
|
|
|
}
|
|
catch (MailSenderException ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
catch (Exception Ex)
|
|
{
|
|
throw new ServiceException(Ex.Message);
|
|
}
|
|
}
|
|
public void RevertSubmit(int nTranID, string Remarks)
|
|
{
|
|
WFMovementTran oNextApprovar = null;
|
|
string sTaskRemrks = "";
|
|
try
|
|
{
|
|
WFSetupRule oRule = _wfSetup.GetRule(_MoveTran.WFRuleID);
|
|
_MoveTran.UpdateStatus(_ogNode, Remarks, enumwfStatus.Revert);
|
|
if (_MoveTran.IsReadytoMoveNextTier(oRule))
|
|
{
|
|
oNextApprovar = new WFMovementTran();
|
|
|
|
oNextApprovar.FromNodeID = _ogNode.ID;
|
|
oNextApprovar.FromEmployeeID = _employee.ID;
|
|
oNextApprovar.Remarks = _MoveTran.GetRemarks(); //_employee.Name + ": " + Remarks;
|
|
|
|
oNextApprovar.SetupID = _wfSetup.ID;
|
|
oNextApprovar.WFRuleID = oRule.ID;
|
|
oNextApprovar.Uniquenumber = _MoveTran.Uniquenumber;
|
|
/*For Initiator Tier will be one*/
|
|
oNextApprovar.Tier = _MoveTran.Tier > workflowConstants.WF_Initiator_Tier ? _MoveTran.Tier - 1 : _MoveTran.Tier;
|
|
oNextApprovar.ObjectID = _MoveTran.ObjectID;
|
|
oNextApprovar.WFMNexts = this.RevertApprovers();
|
|
sTaskRemrks = _wfSetup.WFType.Name + " Application has been reverted to sender by " + " " + _employee.Name + ", " + _employee.DescriptionText;
|
|
oNextApprovar.WFMTasks = this.MoveMentTasks(oNextApprovar.WFMNexts, oRule, _MoveTran.Tier, _MoveTran.Uniquenumber, enumwfStatus.Revert, sTaskRemrks);
|
|
oNextApprovar.Status = enumwfStatus.Received;
|
|
oNextApprovar.ObjectDescription = _wfinterface.ObjectDescription; // get the object description from interface
|
|
_MoveTran.Status = enumwfStatus.Passed;
|
|
|
|
oNextApprovar.SetSourceObjectStatus();
|
|
|
|
oNextApprovar.Submit(_MoveTran);
|
|
SendMail(oNextApprovar);
|
|
}
|
|
else
|
|
{
|
|
_MoveTran.Status = enumwfStatus.Exception;
|
|
_MoveTran.SetSourceObjectStatus();
|
|
|
|
_MoveTran.Save();
|
|
}
|
|
}
|
|
catch (MailSenderException ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
catch (Exception Ex)
|
|
{
|
|
throw new ServiceException(Ex.Message);
|
|
}
|
|
}
|
|
|
|
private ObjectsTemplate<WFMovementNext> Approvers(WFSetupRule oWFRule, int nTier)
|
|
{
|
|
ObjectsTemplate<WFMovementNext> oNextApps = new ObjectsTemplate<WFMovementNext>();
|
|
WFSetupRule oRule = oWFRule;
|
|
ObjectsTemplate<OrganogramBasic> oApprovarNodes = _wfSetup.Approvers(oRule, _ogNode, nTier);
|
|
foreach (OrganogramBasic oItem in oApprovarNodes)
|
|
{
|
|
foreach (OrganogramEmployee oemp in oItem.OrganEmployees)
|
|
{
|
|
WFMovementNext oNextApp = new WFMovementNext();
|
|
oNextApp.Status = enumwfStatus.Received;
|
|
oNextApp.NodeID = oItem.ID;
|
|
oNextApp.EmployeeID = oemp.EmployeeID;
|
|
oNextApp.Description = "(" + _employee.EmployeeNo + ") " + _employee.Name + ", " + _employee.DescriptionText + " has applied " + _wfSetup.WFType.Name + " Application";
|
|
oNextApps.Add(oNextApp);
|
|
}
|
|
}
|
|
|
|
if (oNextApps.Count == 0)
|
|
throw new ServiceException("Approver node/Position (" + _ogNode.PositionName + ") is Vacant.");
|
|
return oNextApps;
|
|
}
|
|
private ObjectsTemplate<WFMovementNext> RevertApprovers()
|
|
{
|
|
|
|
ObjectsTemplate<WFMovementNext> oNextApps = new ObjectsTemplate<WFMovementNext>();
|
|
WFMovementNext oNextApp = new WFMovementNext();
|
|
|
|
OrganogramBasic InitiatorNode = WFMovementTran.Service.InitiatorNode(_MoveTran.Uniquenumber);
|
|
WFSetupRule oRule = _wfSetup.GetRule(_MoveTran.WFRuleID);
|
|
OrganogramBasic oNode = _wfSetup.InitiatorToTierNode(InitiatorNode, oRule, _MoveTran.Tier - 1);
|
|
|
|
oNextApp.NodeID = oNode.ID;
|
|
Employee emp = oNode.GetAssignedEmployee();
|
|
oNextApp.EmployeeID = emp.ID;
|
|
oNextApp.Status = enumwfStatus.Received;
|
|
oNextApp.Description = "(" + _employee.EmployeeNo + ") " + _employee.Name + ", " + _employee.DescriptionText + " revert your " + _wfSetup.WFType.Name + " Application";
|
|
oNextApps.Add(oNextApp);
|
|
return oNextApps;
|
|
}
|
|
|
|
private WFMovementTask RefreshMovementTaskObj(ID empID, ID nodeID, EnumWFNotifyType notifyType, bool status, string Remarks, enumMailSendType mailSendType)
|
|
{
|
|
WFMovementTask oDTask = new WFMovementTask();
|
|
oDTask.EmployeeID = empID;
|
|
oDTask.NodeID = nodeID;
|
|
oDTask.TasksType = notifyType;
|
|
oDTask.Status = status;
|
|
oDTask.Description = Remarks;
|
|
oDTask.MailSendType = mailSendType;
|
|
oDTask.SentTime = DateTime.Today;
|
|
return oDTask;
|
|
}
|
|
|
|
private ObjectsTemplate<WFMovementTask> MoveMentTasks(ObjectsTemplate<WFMovementNext> WFnexts, WFSetupRule rule, int nTier, int uniqueNumber, enumwfStatus ntrantype, string sTaskRemarks)
|
|
{
|
|
ObjectsTemplate<WFMovementTask> oWFTasks = new ObjectsTemplate<WFMovementTask>();
|
|
|
|
try
|
|
{
|
|
#region find the doted line and include them into cc
|
|
if (workflowConstants.WF_Initiator_Tier == nTier)
|
|
{
|
|
ObjectsTemplate<OrganogramBasic> oDLines = _ogNode.GetAthorities(EnumAuthorityType.Doted);
|
|
if (oDLines != null)
|
|
{
|
|
foreach (OrganogramBasic oNode in oDLines)
|
|
{
|
|
if (oNode.EmployeeAssigned == true)
|
|
{
|
|
Employee emp = oNode.GetAssignedEmployee();
|
|
//System notification
|
|
oWFTasks.Add(RefreshMovementTaskObj(emp.ID, oNode.ID, EnumWFNotifyType.SysNotification, false, sTaskRemarks, enumMailSendType.CC));
|
|
//Email notification
|
|
oWFTasks.Add(RefreshMovementTaskObj(emp.ID, oNode.ID, EnumWFNotifyType.Email, false, sTaskRemarks, enumMailSendType.CC));
|
|
}
|
|
}
|
|
}
|
|
|
|
// Send mail to Matrix line authority
|
|
|
|
ObjectsTemplate<OrganogramBasic> oMLines = _ogNode.GetAthorities(EnumAuthorityType.Reporting);
|
|
if (oDLines != null)
|
|
{
|
|
foreach (OrganogramBasic oNode in oMLines)
|
|
{
|
|
if (oNode.EmployeeAssigned == true)
|
|
{
|
|
Employee emp = oNode.GetAssignedEmployee();
|
|
//System notification
|
|
WFMovementTask otst = RefreshMovementTaskObj(emp.ID, oNode.ID, EnumWFNotifyType.SysNotification, false, sTaskRemarks, enumMailSendType.CC);
|
|
oWFTasks.Add(otst);
|
|
otst.Description = _MoveTran.ObjectDescription;
|
|
//Email notification
|
|
WFMovementTask otsts = RefreshMovementTaskObj(emp.ID, oNode.ID, EnumWFNotifyType.Email, false, sTaskRemarks, enumMailSendType.CC);
|
|
oWFTasks.Add(otsts);
|
|
otsts.Description = _MoveTran.ObjectDescription;
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
|
|
|
|
#region find straight line and include them into to
|
|
if (nTier > workflowConstants.WF_Initiator_Tier)
|
|
{
|
|
OrganogramBasic oBasic = WFMovementTran.Service.InitiatorNode(uniqueNumber);
|
|
if (oBasic.EmployeeAssigned == true)
|
|
{
|
|
foreach (OrganogramEmployee enodeemp in oBasic.OrganEmployees)
|
|
{
|
|
//System notification
|
|
|
|
string sapprover = "";
|
|
if (_MoveTran.Status != enumwfStatus.End && _MoveTran.Status != enumwfStatus.Decline)
|
|
{
|
|
sapprover = " and waiting for Approval of ";
|
|
foreach (WFMovementNext onext in WFnexts)
|
|
{
|
|
if (onext.Status == enumwfStatus.Received)
|
|
{
|
|
Employee oemp = Employee.Get(onext.EmployeeID);
|
|
sapprover = sapprover + oemp.Name + ", " + oemp.DescriptionText;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
WFMovementTask otst = RefreshMovementTaskObj(enodeemp.EmployeeID, oBasic.ID, EnumWFNotifyType.SysNotification, false, sTaskRemarks, enumMailSendType.To);
|
|
if (oWFTasks.GetItem(otst) == null)
|
|
{
|
|
|
|
|
|
oWFTasks.Add(otst);
|
|
otst.Description = "Your " + sTaskRemarks + sapprover + ".";
|
|
//Email notification
|
|
WFMovementTask otsts = RefreshMovementTaskObj(enodeemp.EmployeeID, oBasic.ID, EnumWFNotifyType.Email, false, sTaskRemarks, enumMailSendType.To);
|
|
oWFTasks.Add(otsts);
|
|
otsts.Description = "Your " + sTaskRemarks + sapprover + ".";
|
|
}
|
|
}
|
|
}
|
|
|
|
foreach (WFMovementNext onext in WFnexts)
|
|
{
|
|
if (onext.Status == enumwfStatus.Received)
|
|
{
|
|
WFMovementTask otst = RefreshMovementTaskObj(onext.EmployeeID, onext.NodeID, EnumWFNotifyType.Email, false, sTaskRemarks, enumMailSendType.To);
|
|
if (oWFTasks.GetItem(otst) == null)
|
|
{
|
|
otst.Description = _MoveTran.ObjectDescription + " " + sTaskRemarks + ". Your approval is also required. ";
|
|
oWFTasks.Add(otst);
|
|
}
|
|
}
|
|
}
|
|
|
|
#region if application decline notify to all approver sequence
|
|
if (ntrantype == enumwfStatus.Decline)
|
|
{
|
|
ObjectsTemplate<OrganogramBasic>[] oPaths = _wfSetup.GetFullPathOnTier(rule, nTier - 1, WFMovementTran.Service.InitiatorNode(uniqueNumber));
|
|
for (int i = 0; i < oPaths.Length; i++)
|
|
{
|
|
foreach (OrganogramBasic oNode in oPaths[i])
|
|
{
|
|
if (oNode.EmployeeAssigned == false) continue;
|
|
foreach (OrganogramEmployee enodeemp in oNode.OrganEmployees)
|
|
{
|
|
//System notification
|
|
WFMovementTask otst = RefreshMovementTaskObj(enodeemp.EmployeeID, oNode.ID, EnumWFNotifyType.SysNotification, false, sTaskRemarks, enumMailSendType.To);
|
|
if (oWFTasks.GetItem(otst) == null)
|
|
{
|
|
oWFTasks.Add(otst);
|
|
//Email notification
|
|
oWFTasks.Add(RefreshMovementTaskObj(enodeemp.EmployeeID, oNode.ID, EnumWFNotifyType.Email, false, sTaskRemarks, enumMailSendType.To));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
#endregion if application decline notify to all approver sequence
|
|
|
|
}
|
|
else
|
|
{
|
|
foreach (WFMovementNext onext in WFnexts)
|
|
{
|
|
if (onext.EmployeeID != _employee.ID) // For Initatior don't need send mail
|
|
{
|
|
WFMovementTask otst = RefreshMovementTaskObj(onext.EmployeeID, onext.NodeID, EnumWFNotifyType.Email, false, sTaskRemarks, enumMailSendType.To);
|
|
if (oWFTasks.GetItem(otst) == null)
|
|
{
|
|
otst.Description = otst.Description + " Your approval is required.";
|
|
oWFTasks.Add(otst);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new ServiceException(ex.Message);
|
|
}
|
|
return oWFTasks;
|
|
}
|
|
|
|
public void SendMail(WFMovementTran oTran)
|
|
{
|
|
MailSender sender = null;
|
|
|
|
try
|
|
{
|
|
sender = new MailSender();
|
|
|
|
|
|
//Send Email With Link
|
|
Employee nextemployee = null;
|
|
foreach (WFMovementTask next in oTran.WFMTasks)
|
|
{
|
|
string sbody = "";
|
|
if (next.TasksType == EnumWFNotifyType.SysNotification) continue;
|
|
nextemployee = new Employee();
|
|
nextemployee = Employee.Get(next.EmployeeID);
|
|
|
|
sender = new MailSender();
|
|
sender.AddTo(nextemployee.EmailAddress);
|
|
sbody = next.Description + "";
|
|
sender.Body = sbody;
|
|
sender.Link = Ease.CoreV35.Utility.ConfigUtility.GetAppSettings("WebAddress");
|
|
//sender.Body = sender.Body.Replace("<br>", Environment.NewLine);
|
|
sender.Subject = _wfSetup.WFType.Name + " approval work-flow mail.";
|
|
string checkSendMail = Ease.CoreV35.Utility.ConfigUtility.GetAppSettings("SendMethod");
|
|
if (checkSendMail != "")
|
|
{
|
|
sender.SendMail();
|
|
oTran.UpdateSysNotification(next.ID , true);
|
|
}
|
|
}
|
|
|
|
}
|
|
catch (MailSenderException ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new ServiceException(ex.Message);
|
|
//throw new Exception("Your application has been sent to Approvar but system can't send e-mail. you don't need to submit again.");
|
|
}
|
|
|
|
}
|
|
|
|
public string IntApproversNames()
|
|
{
|
|
string sApprovars = "";
|
|
try
|
|
{
|
|
ObjectsTemplate<WFMovementNext> oNextApps = Approvers(_wfSetup.GetNodeRule(_ogNode), workflowConstants.WF_Initiator_Tier + 1);
|
|
foreach (WFMovementNext onext in oNextApps)
|
|
{
|
|
OrganogramBasic obasic = OrganogramBasic.Get(onext.NodeID);
|
|
if (obasic.EmployeeAssigned == false) continue;
|
|
foreach (OrganogramEmployee enemp in obasic.OrganEmployees)
|
|
{
|
|
sApprovars = sApprovars + "(" + enemp.Employee.EmployeeNo + ") " + enemp.Employee.Name;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
sApprovars = ex.Message;
|
|
}
|
|
|
|
return sApprovars;
|
|
}
|
|
public string ApproversNames(int nTranID)
|
|
{
|
|
string sApprovars = "";
|
|
try
|
|
{
|
|
WFSetupRule oRule = _wfSetup.GetRule(_MoveTran.WFRuleID);
|
|
if (oRule.HasNextApprovar(_ogNode, _MoveTran.Tier + 1))
|
|
{
|
|
ObjectsTemplate<WFMovementNext> oNextApps = Approvers(oRule, _MoveTran.Tier + 1);
|
|
|
|
// there is a posiblity in rule manual, approvar and next approvar are same person.
|
|
// so there is no need to flow two time same person.
|
|
// for example emplaoyee is Department head and HR manager and work flow defined Emloyee >> LM >> Department Head >> HR Manager
|
|
// while Department head approve work flow will be completed.
|
|
if (oRule.WFRuleType == EnumWFRuleType.Manual && oNextApps.Count == 1)
|
|
{
|
|
if (oNextApps[0].EmployeeID == _employee.ID)
|
|
{
|
|
if (oRule.HasNextApprovar(_ogNode, _MoveTran.Tier + 2))
|
|
{
|
|
oNextApps = this.Approvers(oRule, _MoveTran.Tier + 2);
|
|
}
|
|
else sApprovars = "After your approval Work flow will be completed";
|
|
}
|
|
}
|
|
|
|
|
|
foreach (WFMovementNext onext in oNextApps)
|
|
{
|
|
OrganogramBasic obasic = OrganogramBasic.Get(onext.NodeID);
|
|
if (obasic.EmployeeAssigned == false) continue;
|
|
foreach (OrganogramEmployee enemp in obasic.OrganEmployees)
|
|
{
|
|
sApprovars = sApprovars + "(" + enemp.Employee.EmployeeNo + ") " + enemp.Employee.Name;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
sApprovars = "After your approval Work flow will be completed";
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
sApprovars = ex.Message;
|
|
}
|
|
|
|
return sApprovars;
|
|
}
|
|
|
|
public string RevertNodeName(int nTranID)
|
|
{
|
|
string sSender = "";
|
|
try
|
|
{
|
|
|
|
OrganogramBasic InitiatorNode = WFMovementTran.Service.InitiatorNode(_MoveTran.Uniquenumber);
|
|
WFSetupRule oRule = _wfSetup.GetRule(_MoveTran.WFRuleID);
|
|
OrganogramBasic oNode = _wfSetup.InitiatorToTierNode(InitiatorNode, oRule, _MoveTran.Tier - 1);
|
|
sSender = "(" + oNode.GetAssignedEmployee().EmployeeNo + ")" + oNode.GetAssignedEmployee().Name;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
sSender = "Error has been detected during looking for revert employee, Contract to system administrator; Error:" + ex.Message;
|
|
}
|
|
|
|
return sSender;
|
|
}
|
|
public string NotifiableNodes()
|
|
{
|
|
string sDotedNodes = "";
|
|
try
|
|
{
|
|
HashSet<int> ohset = new HashSet<int>();
|
|
ObjectsTemplate<OrganogramBasic> oDLines = _ogNode.GetAthorities(EnumAuthorityType.Doted);
|
|
if (workflowConstants.WF_Initiator_Tier == _MoveTran.Tier)
|
|
{
|
|
if (oDLines != null)
|
|
{
|
|
foreach (OrganogramBasic dline in oDLines)
|
|
{
|
|
if (dline.EmployeeAssigned == true)
|
|
{
|
|
Employee emp = dline.GetAssignedEmployee();
|
|
sDotedNodes = "(" + emp.EmployeeNo + ")" + emp.Name;
|
|
ohset.Add(emp.ID.Integer);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
ObjectsTemplate<OrganogramBasic> oMLines = _ogNode.GetAthorities(EnumAuthorityType.Reporting);
|
|
if (oDLines != null)
|
|
{
|
|
foreach (OrganogramBasic oNode in oMLines)
|
|
{
|
|
if (oNode.EmployeeAssigned == true)
|
|
{
|
|
Employee emp = oNode.GetAssignedEmployee();
|
|
sDotedNodes = "(" + emp.EmployeeNo + ")" + emp.Name;
|
|
ohset.Add(emp.ID.Integer);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//if (_MoveTran != null && _MoveTran.Tier > workflowConstants.WF_Initiator_Tier)
|
|
//{
|
|
// WFSetupRule rule = _wfSetup.GetRule(_MoveTran.WFRuleID);
|
|
// ObjectsTemplate<OrganogramBasic>[] oPaths = null;
|
|
// oPaths = _wfSetup.GetFullPathOnTier(rule, _MoveTran.Tier - 1, WFMovementTran.Service.InitiatorNode(_MoveTran.Uniquenumber));
|
|
// for (int i = 0; i < oPaths.Length; i++)
|
|
// {
|
|
// //if ((_MoveTran.Tier - 2) == i) continue; //to employee doesn't need to include in cc
|
|
|
|
// foreach (OrganogramBasic og in oPaths[i])
|
|
// {
|
|
|
|
// if (og.EmployeeAssigned == true && og.ID.Integer != _ogNode.ID.Integer)
|
|
// {
|
|
// Employee emp = og.GetAssignedEmployee();
|
|
// if(ohset.Contains(emp.ID.Integer)==false)
|
|
// sDotedNodes = sDotedNodes + " (" + emp.EmployeeNo + ")" + emp.Name;
|
|
// }
|
|
// }
|
|
// }
|
|
//}
|
|
|
|
|
|
#region find straight line and include them into to
|
|
if (_MoveTran != null && _MoveTran.Tier > workflowConstants.WF_Initiator_Tier)
|
|
{
|
|
OrganogramBasic oBasic = WFMovementTran.Service.InitiatorNode(_MoveTran.Uniquenumber);
|
|
if (oBasic.EmployeeAssigned == true)
|
|
{
|
|
Employee emp = oBasic.GetAssignedEmployee();
|
|
//System notification
|
|
if (ohset.Contains(emp.ID.Integer) == false)
|
|
sDotedNodes = sDotedNodes + " (" + emp.EmployeeNo + ")" + emp.Name;
|
|
}
|
|
|
|
|
|
}
|
|
#endregion
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
|
|
sDotedNodes = "Error has been detected during looking for doted-line employee(s), Contract to system administrator; Error:" + ex.Message;
|
|
}
|
|
|
|
return sDotedNodes;
|
|
}
|
|
|
|
public static WFMovementTran GetWFMovementTran(int nTranID)
|
|
{
|
|
try
|
|
{
|
|
WFMovementTran oMTran = WFMovementTran.Service.Get(ID.FromInteger(nTranID));
|
|
|
|
return oMTran;
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
return null;
|
|
}
|
|
public static int ObjectID(int nTranID)
|
|
{
|
|
string sDescription = string.Empty;
|
|
try
|
|
{
|
|
WFMovementTran oMTran = WFMovementTran.Service.Get(ID.FromInteger(nTranID));
|
|
return oMTran.ObjectID.Integer;
|
|
}
|
|
catch
|
|
{
|
|
sDescription = "Error on getting WF Type. Contact your administrator.";
|
|
}
|
|
return -1;
|
|
}
|
|
}
|
|
}
|