CEL_Payroll/Payroll.BO/Assets/AssetInventory.cs

682 lines
21 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.Model;
using Ease.CoreV35.Caching;
using System.Data.Linq.Mapping;
namespace Payroll.BO
{
#region AssetInventory
[Serializable]
public class AssetInventory : BasicBaseObject
{
#region Cache Store
private static Cache _cache = new Cache(typeof(AssetInventory));
#endregion
#region Constructor
public AssetInventory()
{
_assetID = null;
_assignedUserID = null;
_assignedDate = DateTime.Now;
_assignRemarks = string.Empty;
_assignUserID = null;
_isEmpConfirmed = false;
_empConfirmDate = DateTime.Now;
_empConfirmRemarks = string.Empty;
_retainUserID = null;
_retainDate = DateTime.Now;
_retainRemarks = string.Empty;
_isempRetained = false;
}
#endregion
#region Properties
#region AssetID : ID
private ID _assetID;
public ID AssetID
{
get { return _assetID; }
set
{
base.OnPropertyChange<ID>("assetID", _assetID, value);
_assetID = value;
}
}
#endregion
#region AssignedUserID : ID
private ID _assignedUserID;
public ID ReceiveEmployeeID
{
get { return _assignedUserID; }
set
{
base.OnPropertyChange<ID>("assignedUserID", _assignedUserID, value);
_assignedUserID = value;
}
}
#endregion
#region AssignedDate : DateTime
private DateTime _assignedDate;
public DateTime AssignedDate
{
get { return _assignedDate; }
set
{
base.OnPropertyChange<DateTime>("assignedDate", _assignedDate, value);
_assignedDate = value;
}
}
#endregion
#region AssignedRemarks : string
private string _assignRemarks;
public string AssignedRemarks
{
get { return _assignRemarks; }
set
{
base.OnPropertyChange<string>("assignedRemarks", _assignRemarks, value);
_assignRemarks = value;
}
}
#endregion
#region AssignUserID : ID
private ID _assignUserID;
public ID AssignUserID
{
get { return _assignUserID; }
set
{
base.OnPropertyChange<ID>("assignUserID", _assignUserID, value);
_assignUserID = value;
}
}
#endregion
#region IsEmpConfirmed : Boolean
private bool _isEmpConfirmed;
public bool IsEmpConfirmed
{
get { return _isEmpConfirmed; }
set
{
base.OnPropertyChange<bool>("isEmpConfirmed", _isEmpConfirmed, value);
_isEmpConfirmed = value;
}
}
#endregion
#region empConfirmDate : DateTime
private DateTime _empConfirmDate;
public DateTime empConfirmDate
{
get { return _empConfirmDate; }
set
{
base.OnPropertyChange<DateTime>("empConfirmDate", _empConfirmDate, value);
_empConfirmDate = value;
}
}
#endregion
#region EmpConfirmRemarks : string
private string _empConfirmRemarks;
public string EmpConfirmRemarks
{
get { return _empConfirmRemarks; }
set
{
base.OnPropertyChange<string>("empConfirmRemarks", _empConfirmRemarks, value);
_empConfirmRemarks = value;
}
}
#endregion
#region RetainUserID : ID
private ID _retainUserID;
public ID RetainUserID
{
get { return _retainUserID; }
set
{
base.OnPropertyChange<ID>("retainUserID", _retainUserID, value);
_retainUserID = value;
}
}
#endregion
#region RetainDate : DateTime
private DateTime _retainDate;
public DateTime RetainDate
{
get { return _retainDate; }
set
{
base.OnPropertyChange<DateTime>("retainDate", _retainDate, value);
_retainDate = value;
}
}
#endregion
#region RetainRemarks : string
private string _retainRemarks;
public string RetainRemarks
{
get { return _retainRemarks; }
set
{
base.OnPropertyChange<string>("retainRemarks", _retainRemarks, value);
_retainRemarks = value;
}
}
#endregion
#region IsEmpRetained : Boolean
private bool _isempRetained;
public bool IsEmpRetained
{
get { return _isempRetained; }
set
{
base.OnPropertyChange<bool>("isEmpRetained", _isempRetained, value);
_isempRetained = value;
}
}
private Asset _asset;
public Asset Asset
{
get
{
if (_asset == null)
_asset = Asset.Get(_assetID);
return _asset;
}
set
{
_asset = value;
}
}
#endregion
#endregion
#region Service Factory IAssetInventoryService : IAssetInventoryService
internal static IAssetInventoryService Service
{
get { return Services.Factory.CreateService<IAssetInventoryService>(typeof(IAssetInventoryService)); }
}
#endregion
#region Functions
public string GetStatus()
{
string sCurrstatus="";
if (this.IsEmpConfirmed == false)
{
sCurrstatus = "Employee Receipt confirmation pending";
}
else sCurrstatus = "Employee Received";
if (this.IsEmpRetained == true)
{
sCurrstatus = "Employee Returned ";
}
if(this.ID.IsUnassigned==true && this.Asset.AssetType == EnumAssetInventoryType.OtherItem)
sCurrstatus = "Exit Clearance Item";
return sCurrstatus;
}
public static AssetInventory Get(ID nID)
{
AssetInventory assetInventory = null;
#region Cache Header
assetInventory = (AssetInventory)_cache["Get", nID];
if (assetInventory != null)
return assetInventory;
#endregion
assetInventory = AssetInventory.Service.Get(nID);
#region Cache Footer
_cache.Add(assetInventory, "Get", nID);
#endregion
return assetInventory;
}
public static ObjectsTemplate<AssetInventory> Get()
{
#region Cache Header
ObjectsTemplate<AssetInventory> assetInventorys = _cache["Get"] as ObjectsTemplate<AssetInventory>;
if (assetInventorys != null)
return assetInventorys;
#endregion
try
{
assetInventorys = Service.Get();
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(assetInventorys, "Get");
#endregion
return assetInventorys;
}
public static ObjectsTemplate<AssetInventory> ReceivableItems(int ReceiveEmpid, int assignByEmpid)
{
ObjectsTemplate<AssetInventory> Items = new ObjectsTemplate<AssetInventory>();
Items = AssetInventory.GetAllAsset(ReceiveEmpid, assignByEmpid);
OrganogramBasic oBasic = OrganogramBasic.GetbyEmployeeid(ID.FromInteger(ReceiveEmpid));
if (oBasic != null && oBasic.Parent != null && oBasic.Parent.EmployeeAssigned == true
&& oBasic.Parent.GetAssignedEmployee().ID.Integer == assignByEmpid)
{
ObjectsTemplate<Asset> LineMngAssets = Asset.GetLineManagerItem();
if (Items == null) Items = new ObjectsTemplate<AssetInventory>();
foreach (Asset item in LineMngAssets)
{
AssetInventory containItem = Items.Find(delegate(AssetInventory param) { return param.AssetID.Integer == item.ID.Integer; });
if (containItem == null)
{
AssetInventory newITem = new AssetInventory();
newITem.AssetID = item.ID;
newITem.AssignedDate = DateTime.Today;
newITem.ReceiveEmployeeID = ID.FromInteger(ReceiveEmpid);
newITem.AssignUserID = oBasic.Parent.GetAssignedEmployee().ID;
newITem.RetainDate = DateTime.Today;
newITem.RetainUserID = ID.FromInteger(assignByEmpid);
newITem.IsEmpConfirmed = true;
newITem.IsEmpRetained = false;
newITem.Asset = item;
Items.Add(newITem);
}
}
}
Employee oEmp = Employee.Get(ID.FromInteger(assignByEmpid));
ObjectsTemplate<Asset> papersItems = Asset.Get(oEmp, EnumAssetInventoryType.OtherItem);
foreach (Asset item in papersItems)
{
if (item.IsLinemanager == true) continue;
AssetInventory containItem = Items.Find(delegate(AssetInventory param) { return param.AssetID.Integer == item.ID.Integer; });
if (containItem == null)
{
AssetInventory newITem = new AssetInventory();
newITem.AssetID = item.ID;
newITem.AssignedDate = DateTime.Today;
newITem.ReceiveEmployeeID = ID.FromInteger(ReceiveEmpid);
newITem.AssignUserID = ID.FromInteger(assignByEmpid);
newITem.RetainDate = DateTime.Today;
newITem.RetainUserID = ID.FromInteger(assignByEmpid);
newITem.IsEmpConfirmed = true;
newITem.IsEmpRetained = false;
newITem.Asset = item;
Items.Add(newITem);
}
}
// List<AssetInventory> oList = Items.FindAll(x => x.IsEmpRetained == true);
ObjectsTemplate<AssetInventory> notRetainItems = new ObjectsTemplate<AssetInventory>();
foreach (AssetInventory item in Items)
{
if (item.IsEmpRetained == false)
notRetainItems.Add(item);
}
Items = notRetainItems;
return Items;
}
public static ObjectsTemplate<AssetInventory> MyReturnableItems(int employeeID)
{
ObjectsTemplate<AssetInventory> Items = new ObjectsTemplate<AssetInventory>();
Items = AssetInventory.GetReceivedItems(employeeID);
// Return to Line manager Items
ObjectsTemplate<AssetInventory> ReturnsItems = new ObjectsTemplate<AssetInventory>();
ReturnsItems = AssetInventory.GetReceivedItems(employeeID);
OrganogramBasic oBasic = OrganogramBasic.GetbyEmployeeid(ID.FromInteger(employeeID));
if (oBasic != null && oBasic.Parent != null && oBasic.Parent.EmployeeAssigned == true)
{
ObjectsTemplate<Asset> LineMngAssets = Asset.GetLineManagerItem();
if (Items == null) Items = new ObjectsTemplate<AssetInventory>();
foreach (Asset item in LineMngAssets)
{
AssetInventory containItem = Items.Find(delegate(AssetInventory param) { return param.AssetID.Integer == item.ID.Integer; });
AssetInventory returnitm = ReturnsItems.Find(delegate(AssetInventory param) { return param.AssetID.Integer == item.ID.Integer; });
if (containItem == null && returnitm == null)
{
AssetInventory newITem = new AssetInventory();
newITem.AssetID = item.ID;
newITem.AssignedDate = DateTime.Today;
newITem.ReceiveEmployeeID = ID.FromInteger(employeeID);
newITem.AssignUserID = oBasic.Parent.GetAssignedEmployee().ID;
newITem.RetainDate = DateTime.Today;
newITem.RetainUserID = ID.FromInteger(employeeID);
newITem.IsEmpConfirmed = true;
newITem.IsEmpRetained = false;
newITem.Asset = item;
Items.Add(newITem);
}
}
}
ObjectsTemplate<Asset> papersItems = Asset.Get(EnumAssetInventoryType.OtherItem);
foreach (Asset item in papersItems)
{
if (item.IsLinemanager == true) continue;
AssetInventory containItem = Items.Find(delegate(AssetInventory param) { return param.AssetID.Integer == item.ID.Integer; });
AssetInventory returnitm = ReturnsItems.Find(delegate(AssetInventory param) { return param.AssetID.Integer == item.ID.Integer; });
if (containItem == null && returnitm ==null)
{
Employee oEmp = Employee.Get(item.AssignUserId1);
if(oEmp==null)
oEmp = Employee.Get(item.AssignUserId2);
if (oEmp == null) continue;
AssetInventory newITem = new AssetInventory();
newITem.AssetID = item.ID;
newITem.AssignedDate = DateTime.Today;
newITem.ReceiveEmployeeID = ID.FromInteger(employeeID);
newITem.AssignUserID = oEmp.ID;
newITem.RetainDate = DateTime.Today;
newITem.RetainUserID = oEmp.ID;
newITem.IsEmpConfirmed = true;
newITem.IsEmpRetained = false;
newITem.Asset = item;
Items.Add(newITem);
}
}
// List<AssetInventory> oList = Items.FindAll(x => x.IsEmpRetained == true);
ObjectsTemplate<AssetInventory> notRetainItems = new ObjectsTemplate<AssetInventory>();
foreach (AssetInventory item in Items)
{
if (item.IsEmpRetained == false)
notRetainItems.Add(item);
}
Items = notRetainItems;
return Items;
}
public static ObjectsTemplate<AssetInventory> GetAllAsset(int ReceiveEmployeeID, int assignUserID)
{
#region Cache Header
ObjectsTemplate<AssetInventory> assetInventorys = _cache["GetAllAsset"] as ObjectsTemplate<AssetInventory>;
if (assetInventorys != null)
return assetInventorys;
#endregion
try
{
assetInventorys = Service.GetAllAsset(ReceiveEmployeeID, assignUserID);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(assetInventorys, "GetAllAsset");
#endregion
return assetInventorys;
}
public static ObjectsTemplate<AssetInventory> GetAssets(int assignedUserID, bool isEmpConfirmed, int assignUserID)
{
#region Cache Header
ObjectsTemplate<AssetInventory> assetInventorys = _cache["GetAssets"] as ObjectsTemplate<AssetInventory>;
if (assetInventorys != null)
return assetInventorys;
#endregion
try
{
assetInventorys = Service.GetAssets(assignedUserID, isEmpConfirmed, assignUserID);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(assetInventorys, "GetAssets");
#endregion
return assetInventorys;
}
public ID Save()
{
base.SetAuditTrailProperties();
return AssetInventory.Service.Save(this);
}
public void Delete()
{
AssetInventory.Service.Delete(ID);
}
public static void Save(ObjectsTemplate<AssetInventory> inventories)
{
// base.SetAuditTrailProperties();
foreach (var item in inventories)
{
item.SetAuditTrailProperties();
}
AssetInventory.Service.Save(inventories);
}
public ID UpdateEmpConfirm()
{
base.SetAuditTrailProperties();
return AssetInventory.Service.UpdateEmpConfirm(this);
}
public ID UpdateRetainAsset()
{
base.SetAuditTrailProperties();
return AssetInventory.Service.UpdateRetainAsset(this);
}
#endregion
public void Delete(int nID)
{
AssetInventory.Service.Delete(nID);
}
public static ObjectsTemplate<AssetInventory> GetReceivedItems(int receiveEmployeeID)
{
#region Cache Header
ObjectsTemplate<AssetInventory> assetInventorys = _cache["GetAllAssignedAsset"] as ObjectsTemplate<AssetInventory>;
if (assetInventorys != null)
return assetInventorys;
#endregion
try
{
assetInventorys = Service.GetReceivedItems(receiveEmployeeID);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(assetInventorys, "GetAllAssignedAsset");
#endregion
return assetInventorys;
}
public static ObjectsTemplate<AssetInventory> GetAllAsset(int AssID)
{
#region Cache Header
ObjectsTemplate<AssetInventory> assetInventorys = _cache["GetAllAsset"] as ObjectsTemplate<AssetInventory>;
if (assetInventorys != null)
return assetInventorys;
#endregion
try
{
assetInventorys = Service.GetAllAsset(AssID);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(assetInventorys, "GetAllAsset");
#endregion
return assetInventorys;
}
public static ObjectsTemplate<AssetInventory> GetReturnedAssets(int assignUserID)
{
#region Cache Header
ObjectsTemplate<AssetInventory> assetInventorys = _cache["GetReturnedAssets"] as ObjectsTemplate<AssetInventory>;
if (assetInventorys != null)
return assetInventorys;
#endregion
try
{
assetInventorys = Service.GetReceivedItems(assignUserID);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(assetInventorys, "GetReturnedAssets");
#endregion
return assetInventorys;
}
public static ObjectsTemplate<AssetInventory> GetEmpAssignedNotReceiveConfirm(int receiveEmployeeID)
{
ObjectsTemplate<AssetInventory> assetInventorys = null;
try
{
assetInventorys = Service.GetEmpAssignedNotReceiveConfirm(receiveEmployeeID);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
return assetInventorys;
}
}
#endregion
#region IAssetInventoryService
public interface IAssetInventoryService
{
AssetInventory Get(ID id);
ObjectsTemplate<AssetInventory> Get();
ObjectsTemplate<AssetInventory> GetAllAsset(int assignedUserID, int assignUserID);
ObjectsTemplate<AssetInventory> GetAssets(int assignedUserID, bool isEmpConfirmed, int assignUserID);
ID Save(AssetInventory item);
void Save(ObjectsTemplate<AssetInventory> inventories);
void Delete(ID id);
ID UpdateEmpConfirm(AssetInventory item);
ID UpdateRetainAsset(AssetInventory item);
void Delete(int nID);
ObjectsTemplate<AssetInventory> GetAllAsset(int AssID);
ObjectsTemplate<AssetInventory> GetEmpAssignedNotReceiveConfirm(int receiveEmpID);
ObjectsTemplate<AssetInventory> GetReceivedItems(int receiveEmployeeID);
ObjectsTemplate<AssetInventory> GetReturnedItems(int receiveEmployeeID);
}
#endregion
}