CEL_Payroll/Payroll.BO/Workflow/WFMovementTran.cs

721 lines
22 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;
using System.Data;
namespace Payroll.BO
{
#region WFMovementTran
[Serializable]
public class WFMovementTran : ObjectTemplate, IworkflowInterface
{
#region Cache Store
private static Cache _cache = new Cache(typeof(WFMovementTran));
#endregion
#region Constructor
public WFMovementTran()
{
_WFMovementTranID = null;
_FromEmployeeID = null;
_FromNodeID = null;
_WFSetupID = null;
_WFRuleID = null;
_ObjectID = null;
_IsActive = true;
_Senttime = DateTime.Now;
_Status = enumwfStatus.Received;
_Uniquenumber = 0;
_Remarks = "";
_Tier = 1;
_objectDescription = "";
}
#endregion
#region Property(s)
#region Property WFMovementTranID : ID
private ID _WFMovementTranID;
public ID WFMovementTranID
{
get { return _WFMovementTranID; }
set { _WFMovementTranID = value; }
}
#endregion
#region Property FromEmployeeID : int
private ID _FromEmployeeID;
public ID FromEmployeeID
{
get { return _FromEmployeeID; }
set { _FromEmployeeID = value; }
}
#endregion
#region FromNodeID : int
private ID _FromNodeID;
public ID FromNodeID
{
get { return _FromNodeID; }
set { _FromNodeID = value; }
}
#endregion
#region Property WFSetupID : int
private ID _WFSetupID;
public ID SetupID
{
get { return _WFSetupID; }
set { _WFSetupID = value; }
}
#endregion
#region Property WFRuleID : int
private ID _WFRuleID;
public ID WFRuleID
{
get { return _WFRuleID; }
set { _WFRuleID = value; }
}
#endregion
#region Property ObjectID : int
private ID _ObjectID;
public ID ObjectID
{
get { return _ObjectID; }
set { _ObjectID = value; }
}
#endregion
#region Property IsActive : bool
private bool _IsActive;
public bool IsActive
{
get { return _IsActive; }
set { _IsActive = value; }
}
#endregion
#region Property Senttime : DateTime
private DateTime _Senttime;
public DateTime Senttime
{
get { return _Senttime; }
set { _Senttime = value; }
}
#endregion
#region Property Status : Enum
private enumwfStatus _Status;
public enumwfStatus Status
{
get { return _Status; }
set { _Status = value; }
}
#endregion
#region Property Uniquenumber : int
private int _Uniquenumber;
public int Uniquenumber
{
get { return _Uniquenumber; }
set { _Uniquenumber = value; }
}
#endregion
#region Property Remarks : string
private string _Remarks;
public string Remarks
{
get { return _Remarks; }
set { _Remarks = value; }
}
#endregion
#region Tier : int
private int _Tier;
public int Tier
{
get { return _Tier; }
set { _Tier = value; }
}
#endregion
#region Property ObjectDescription : string
private string _objectDescription;
public string ObjectDescription
{
get { return _objectDescription; }
set { _objectDescription = value; }
}
#endregion
#region WFMovementTask : WFMovementTask
private ObjectsTemplate<WFMovementTask> _wfMTasks;
public ObjectsTemplate<WFMovementTask> WFMTasks
{
get
{
if (_wfMTasks == null) _wfMTasks = new ObjectsTemplate<WFMovementTask>();
return _wfMTasks;
}
set
{
_wfMTasks = value;
}
}
#endregion
#region WFMovementNext : WFMovementNext
private ObjectsTemplate<WFMovementNext> _wfMNexts;
public ObjectsTemplate<WFMovementNext> WFMNexts
{
get
{
if (_wfMNexts == null)
_wfMNexts = WFMovementTran.Get4WFMovementNext(this.ID);
return _wfMNexts;
}
set
{
_wfMNexts = value;
}
}
#endregion
#region WFMovementNext : WFMovementNext
private WFSetup _wfsetup;
public WFSetup WFSetup
{
get
{
if (_wfsetup == null) _wfsetup = WFSetup.Get(_WFSetupID);
return _wfsetup;
}
set
{
_wfsetup = value;
}
}
#endregion
#endregion
#region Function
#region Save
public ID Save()
{
return WFMovementTran.Service.Save(this);
}
#endregion
//#region Delete
//public void Delete()
//{
// WFMovementTran.Service.Delete(ID);
//}
//#endregion
//public bool IsException(WFReceiveStatus nStatus)
//{
// foreach (WFMovementNext oItem in this.WFMNexts)
// {
// if (oItem.ReceiveStatus != EnumWFReceiveStatus.NOT_YET_OPEN)
// {
// if (oItem.Status != nStatus)
// {
// return false;
// }
// }
// }
// return true;
//}
public void SetSourceObjectStatus()
{
object nstatus = null;
Type ty = null;
ConfigurationManager omanager = new ConfigurationManager();
ty = System.Reflection.Assembly.GetCallingAssembly().GetType("Payroll.BO." + this.WFSetup.WFType.SourceObjectName.Trim());
object sourceObject = System.Activator.CreateInstance(ty);
if (sourceObject == null) throw new ServiceException("unable to create object instance from object name:" + this.WFSetup.WFType.SourceObjectName
+ ". please check availability of the object in the Payroll.Report assembly.");
System.Type[] pararemterTypes = new System.Type[1];
pararemterTypes[0] = ID.GetType();
System.Reflection.MethodInfo methodInfoDel = (sourceObject.GetType()).GetMethod("Get", pararemterTypes);
object[] parameterValue = new object[1];
parameterValue[0] = this.ObjectID;
if (methodInfoDel != null)
sourceObject = methodInfoDel.Invoke(sourceObject, parameterValue);
else throw new ServiceException("function: Get(ID) is not exist in the object:" + this.WFSetup.WFType.SourceObjectName);
parameterValue[0] = this.Status;
System.Reflection.MethodInfo sourceStatusMenthod = (sourceObject.GetType()).GetMethod("GetStatusbyWf");
if (sourceStatusMenthod != null)
nstatus = sourceStatusMenthod.Invoke(sourceObject, parameterValue);
else throw new ServiceException("function: GetStatusbyWf is not exist in the object:" + this.WFSetup.WFType.SourceObjectName);
this.WFSetup.WFType.SourceObjectStatus = (int)nstatus;
}
public string GetSourceObjectDescription()
{
object nstatus = null;
Type ty = null;
ConfigurationManager omanager = new ConfigurationManager();
ty = System.Reflection.Assembly.GetCallingAssembly().GetType("Payroll.BO." + this.WFSetup.WFType.SourceObjectName.Trim());
object ofrm = System.Activator.CreateInstance(ty);
if (ofrm == null) throw new ServiceException("unable to create object instance from object name:" + this.WFSetup.WFType.SourceObjectName
+ ". please check availability of the object in the Payroll.Report assembly.");
System.Type[] pararemterTypes = new System.Type[1];
pararemterTypes[0] = ID.GetType();
System.Reflection.MethodInfo methodInfoDel = (ofrm.GetType()).GetMethod("Get", pararemterTypes);
object[] parameterValue = new object[1];
parameterValue[0] = this.ObjectID;
object sourceObject = null;
if (methodInfoDel != null)
sourceObject = methodInfoDel.Invoke(ofrm, parameterValue);
else throw new ServiceException("function: Get(ID) is not exist in the object:" + this.WFSetup.WFType.SourceObjectName);
System.Reflection.MethodInfo sourceStatusMenthod = (sourceObject.GetType()).GetMethod("WFDesciption");
if (sourceStatusMenthod != null)
nstatus = sourceStatusMenthod.Invoke(sourceObject, null);
else throw new ServiceException("function: GetStatusbyWf is not exist in the object:" + this.WFSetup.WFType.SourceObjectName);
return nstatus.ToString();
}
public string GetStatusString()
{
string sStatus = "";
switch (this.Status)
{
case enumwfStatus.Received:
sStatus = "Initiate";
break;
case enumwfStatus.Passed:
sStatus = "Approved";
break;
case enumwfStatus.Decline:
sStatus = "Decline";
break;
case enumwfStatus.Revert:
sStatus = "revert";
break;
case enumwfStatus.End:
sStatus = "Approved and Completed";
break;
case enumwfStatus.Exception:
sStatus = "raise error";
break;
default:
sStatus = "raise error";
break;
}
return sStatus;
}
public static string GetStatusForNotify(enumwfStatus fstatus)
{
string sStatus = "";
switch (fstatus)
{
case enumwfStatus.Received:
sStatus = "Received";
break;
case enumwfStatus.Passed:
sStatus = "Approved";
break;
case enumwfStatus.Decline:
sStatus = "Decline";
break;
case enumwfStatus.Revert:
sStatus = "revert";
break;
case enumwfStatus.Approve:
sStatus = "Approved";
break;
case enumwfStatus.End:
sStatus = "Approved & Completed";
break;
case enumwfStatus.Exception:
sStatus = "raise error";
break;
default:
sStatus = "raise error";
break;
}
return sStatus;
}
public void UpdateStatus(OrganogramBasic oNode, string sRemarks, enumwfStatus nstatus)
{
foreach (WFMovementNext oItem in this.WFMNexts)
{
if (oNode.ID.Integer == oItem.NodeID.Integer)
{
oItem.Status = nstatus;
oItem.Remarks = sRemarks;
oItem.ReceiveStatus = EnumWFReceiveStatus.ALREADY_OPENED;
}
}
}
public bool IsReadytoMoveNextTier(WFSetupRule oRule)
{
#region Not Required all approvar approval
if (oRule.ReqAppAll == false)
{
foreach (WFMovementNext oItem in this.WFMNexts)
{
if (oItem.ReceiveStatus == EnumWFReceiveStatus.ALREADY_OPENED)
{
return true;
}
}
}
#endregion Not Required all approvar approval
#region Required all approvar approval
else
{
int nCount = 0;
foreach (WFMovementNext oItem in this.WFMNexts)
{
if (oItem.ReceiveStatus == EnumWFReceiveStatus.ALREADY_OPENED)
{
nCount = nCount + 1;
}
}
if (nCount == this.WFMNexts.Count)
{
return true;
}
}
#endregion Required all approvar approval
return false;
}
public string GetRemarks()
{
string sApprovars = "";
foreach (WFMovementNext oItem in this.WFMNexts)
{
sApprovars = sApprovars + oItem.Remarks + " ";
}
return sApprovars;
}
#region Get
public static WFMovementTran Get(ID WFMovementId)
{
WFMovementTran wfMovementTran = null;
#region Cache Header
wfMovementTran = (WFMovementTran)_cache["Get", WFMovementId];
if (wfMovementTran != null)
return wfMovementTran;
#endregion
wfMovementTran = WFMovementTran.Service.Get(WFMovementId);
#region Cache Footer
_cache.Add(wfMovementTran, "Get", WFMovementId);
#endregion
return wfMovementTran;
}
public static WFMovementNext GetReceivedWFNext(int wfsetupid, int objectID)
{
WFMovementNext wfMovementTran = null;
wfMovementTran = WFMovementTran.Service.GetReceivedWFNext(wfsetupid, objectID);
return wfMovementTran;
}
public static ObjectsTemplate<WFMovementTran> Get()
{
#region Cache Header
ObjectsTemplate<WFMovementTran> wfMovementTran = _cache["Get"] as ObjectsTemplate<WFMovementTran>;
if (wfMovementTran != null)
return wfMovementTran;
#endregion
try
{
wfMovementTran = Service.Get();
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(wfMovementTran, "Get");
#endregion
return wfMovementTran;
}
public static ObjectsTemplate<WFMovementTask> Get4WFMovementTask(ID wftranid)
{
#region Cache Header
ObjectsTemplate<WFMovementTask> oWFMovementTask = _cache["Get4WFMovementTask", wftranid] as ObjectsTemplate<WFMovementTask>;
if (oWFMovementTask != null)
return oWFMovementTask;
#endregion
try
{
oWFMovementTask = Service.Get4WFMovementTask(wftranid);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(oWFMovementTask, "Get4WFMovementTask", wftranid);
#endregion
return oWFMovementTask;
}
public static ObjectsTemplate<WFMovementTask> GetWFMovementTasks()
{
#region Cache Header
ObjectsTemplate<WFMovementTask> oWFMovementTask = _cache["GetWFMovementTasks"] as ObjectsTemplate<WFMovementTask>;
if (oWFMovementTask != null)
return oWFMovementTask;
#endregion
try
{
oWFMovementTask = Service.GetWFMovementTasks();
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(oWFMovementTask, "GetWFMovementTasks");
#endregion
return oWFMovementTask;
}
public static ObjectsTemplate<WFMovementTask> GetEMployeeNotification(ID employeeID)
{
return Service.GetNotificationItems(employeeID);
}
public static ObjectsTemplate<WFMovementNext> Get4WFMovementNext(ID wftranid)
{
#region Cache Header
ObjectsTemplate<WFMovementNext> oWFMovementNext = _cache["Get4WFMovementNext", wftranid] as ObjectsTemplate<WFMovementNext>;
if (oWFMovementNext != null)
return oWFMovementNext;
#endregion
try
{
oWFMovementNext = Service.Get4WFMovementNext(wftranid);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(oWFMovementNext, "Get4WFMovementNext", wftranid);
#endregion
return oWFMovementNext;
}
public static ObjectsTemplate<WFMovementNext> Get4WFMovementNext(int UniqueNumber)
{
#region Cache Header
ObjectsTemplate<WFMovementNext> oWFMovementNext = _cache["Get4WFMovementNext", UniqueNumber] as ObjectsTemplate<WFMovementNext>;
if (oWFMovementNext != null)
return oWFMovementNext;
#endregion
try
{
oWFMovementNext = Service.Get4WFMovementNext(UniqueNumber);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(oWFMovementNext, "Get4WFMovementNext", UniqueNumber);
#endregion
return oWFMovementNext;
}
public static WFMovementTask GetWFMovementTask(ID movementraskid)
{
WFMovementTask oWFMovementNext = null;
try
{
oWFMovementNext = Service.GetWFMovementTask(movementraskid);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
return oWFMovementNext;
}
public static ObjectsTemplate<WFMovementTran> GetWFMovementByWFType(ID wfFTypeID)
{
#region Cache Header
ObjectsTemplate<WFMovementTran> wfMovementTran = _cache["Get"] as ObjectsTemplate<WFMovementTran>;
if (wfMovementTran != null)
return wfMovementTran;
#endregion
try
{
wfMovementTran = Service.GetWFMovementByWFType(wfFTypeID);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(wfMovementTran, "Get");
#endregion
return wfMovementTran;
}
#endregion
public static ObjectsTemplate<WFMovementTran> ReceivedItems(ID employeeid)
{
return WFMovementTran.Service.ReceivedItems(employeeid);
}
public static ObjectsTemplate<WFMovementTran> GetAllItems(int uniqueNumber)
{
return WFMovementTran.Service.GetAllItems(uniqueNumber);
}
public static int GetReceivedItemsCount(ID employeeid)
{
return WFMovementTran.Service.ReceivedItemsCount(employeeid);
}
public static int GetNotificationItemsCount(ID employeeid)
{
return WFMovementTran.Service.GetNotificationItemCount(employeeid);
}
public void Update_MovementNext(ID tranID, ID newEmployeeID, ID empID, ID NodeID, string remarks)
{
WFMovementTran.Service.Update_MovementNext(tranID, newEmployeeID, empID, NodeID, remarks);
}
public void Submit(WFMovementTran PrvTran)
{
WFMovementTran.Service.Submit(PrvTran, this);
}
public void UpdateSysNotification(ID movementTaskID, bool bstatus)
{
WFMovementTran.Service.UpdateSysNotification(movementTaskID, bstatus);
}
#endregion
#region Service Factory
internal static IWFMovementTranService Service
{
get { return Services.Factory.CreateService<IWFMovementTranService>(typeof(IWFMovementTranService)); }
}
#endregion
}
#endregion
#region Interface
public interface IWFMovementTranService
{
ID Save(WFMovementTran wfMovementTran);
void Delete(ID WFMovementTranId);
WFMovementTran Get(ID id);
WFMovementNext GetReceivedWFNext(int wfsetupid, int objectID);
ObjectsTemplate<WFMovementTran> Get();
WFMovementTask GetWFMovementTask(ID movemantTaskID);
ObjectsTemplate<WFMovementTask> Get4WFMovementTask(ID id);
ObjectsTemplate<WFMovementNext> Get4WFMovementNext(ID tranid);
ObjectsTemplate<WFMovementNext> Get4WFMovementNext(int UniqueNumber);
OrganogramBasic InitiatorNode(int uniquenumber);
void Submit(WFMovementTran PrvTran, WFMovementTran NextTran);
void UpdateSysNotification(ID movementTaskID, bool status);
int GetUniqueNumber();
ObjectsTemplate<WFMovementTran> ReceivedItems(ID employeeid);
int ReceivedItemsCount(ID employeeid);
ObjectsTemplate<WFMovementNext> GetPendingItems(ID employeeid);
ObjectsTemplate<WFMovementTask> GetNotificationItems(ID employeeid);
int GetNotificationItemCount(ID employeeid);
void Update_MovementNext(ID tranID, ID newEmployeeID, ID empID, ID NodeID, string remarks);
ObjectsTemplate<WFMovementTran> GetAllItems(int nUniqueNumber);
ObjectsTemplate<WFMovementTask> GetWFMovementTasks();
ObjectsTemplate<WFMovementTran> GetWFMovementByWFType(ID wFTypeID);
}
#endregion
}