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("assetID", _assetID, value); _assetID = value; } } #endregion #region AssignedUserID : ID private ID _assignedUserID; public ID ReceiveEmployeeID { get { return _assignedUserID; } set { base.OnPropertyChange("assignedUserID", _assignedUserID, value); _assignedUserID = value; } } #endregion #region AssignedDate : DateTime private DateTime _assignedDate; public DateTime AssignedDate { get { return _assignedDate; } set { base.OnPropertyChange("assignedDate", _assignedDate, value); _assignedDate = value; } } #endregion #region AssignedRemarks : string private string _assignRemarks; public string AssignedRemarks { get { return _assignRemarks; } set { base.OnPropertyChange("assignedRemarks", _assignRemarks, value); _assignRemarks = value; } } #endregion #region AssignUserID : ID private ID _assignUserID; public ID AssignUserID { get { return _assignUserID; } set { base.OnPropertyChange("assignUserID", _assignUserID, value); _assignUserID = value; } } #endregion #region IsEmpConfirmed : Boolean private bool _isEmpConfirmed; public bool IsEmpConfirmed { get { return _isEmpConfirmed; } set { base.OnPropertyChange("isEmpConfirmed", _isEmpConfirmed, value); _isEmpConfirmed = value; } } #endregion #region empConfirmDate : DateTime private DateTime _empConfirmDate; public DateTime empConfirmDate { get { return _empConfirmDate; } set { base.OnPropertyChange("empConfirmDate", _empConfirmDate, value); _empConfirmDate = value; } } #endregion #region EmpConfirmRemarks : string private string _empConfirmRemarks; public string EmpConfirmRemarks { get { return _empConfirmRemarks; } set { base.OnPropertyChange("empConfirmRemarks", _empConfirmRemarks, value); _empConfirmRemarks = value; } } #endregion #region RetainUserID : ID private ID _retainUserID; public ID RetainUserID { get { return _retainUserID; } set { base.OnPropertyChange("retainUserID", _retainUserID, value); _retainUserID = value; } } #endregion #region RetainDate : DateTime private DateTime _retainDate; public DateTime RetainDate { get { return _retainDate; } set { base.OnPropertyChange("retainDate", _retainDate, value); _retainDate = value; } } #endregion #region RetainRemarks : string private string _retainRemarks; public string RetainRemarks { get { return _retainRemarks; } set { base.OnPropertyChange("retainRemarks", _retainRemarks, value); _retainRemarks = value; } } #endregion #region IsEmpRetained : Boolean private bool _isempRetained; public bool IsEmpRetained { get { return _isempRetained; } set { base.OnPropertyChange("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(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 Get() { #region Cache Header ObjectsTemplate assetInventorys = _cache["Get"] as ObjectsTemplate; 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 ReceivableItems(int ReceiveEmpid, int assignByEmpid) { ObjectsTemplate Items = new ObjectsTemplate(); 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 LineMngAssets = Asset.GetLineManagerItem(); if (Items == null) Items = new ObjectsTemplate(); 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 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 oList = Items.FindAll(x => x.IsEmpRetained == true); ObjectsTemplate notRetainItems = new ObjectsTemplate(); foreach (AssetInventory item in Items) { if (item.IsEmpRetained == false) notRetainItems.Add(item); } Items = notRetainItems; return Items; } public static ObjectsTemplate MyReturnableItems(int employeeID) { ObjectsTemplate Items = new ObjectsTemplate(); Items = AssetInventory.GetReceivedItems(employeeID); // Return to Line manager Items ObjectsTemplate ReturnsItems = new ObjectsTemplate(); ReturnsItems = AssetInventory.GetReceivedItems(employeeID); OrganogramBasic oBasic = OrganogramBasic.GetbyEmployeeid(ID.FromInteger(employeeID)); if (oBasic != null && oBasic.Parent != null && oBasic.Parent.EmployeeAssigned == true) { ObjectsTemplate LineMngAssets = Asset.GetLineManagerItem(); if (Items == null) Items = new ObjectsTemplate(); 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 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 oList = Items.FindAll(x => x.IsEmpRetained == true); ObjectsTemplate notRetainItems = new ObjectsTemplate(); foreach (AssetInventory item in Items) { if (item.IsEmpRetained == false) notRetainItems.Add(item); } Items = notRetainItems; return Items; } public static ObjectsTemplate GetAllAsset(int ReceiveEmployeeID, int assignUserID) { #region Cache Header ObjectsTemplate assetInventorys = _cache["GetAllAsset"] as ObjectsTemplate; 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 GetAssets(int assignedUserID, bool isEmpConfirmed, int assignUserID) { #region Cache Header ObjectsTemplate assetInventorys = _cache["GetAssets"] as ObjectsTemplate; 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 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 GetReceivedItems(int receiveEmployeeID) { #region Cache Header ObjectsTemplate assetInventorys = _cache["GetAllAssignedAsset"] as ObjectsTemplate; 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 GetAllAsset(int AssID) { #region Cache Header ObjectsTemplate assetInventorys = _cache["GetAllAsset"] as ObjectsTemplate; 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 GetReturnedAssets(int assignUserID) { #region Cache Header ObjectsTemplate assetInventorys = _cache["GetReturnedAssets"] as ObjectsTemplate; 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 GetEmpAssignedNotReceiveConfirm(int receiveEmployeeID) { ObjectsTemplate 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 Get(); ObjectsTemplate GetAllAsset(int assignedUserID, int assignUserID); ObjectsTemplate GetAssets(int assignedUserID, bool isEmpConfirmed, int assignUserID); ID Save(AssetInventory item); void Save(ObjectsTemplate inventories); void Delete(ID id); ID UpdateEmpConfirm(AssetInventory item); ID UpdateRetainAsset(AssetInventory item); void Delete(int nID); ObjectsTemplate GetAllAsset(int AssID); ObjectsTemplate GetEmpAssignedNotReceiveConfirm(int receiveEmpID); ObjectsTemplate GetReceivedItems(int receiveEmployeeID); ObjectsTemplate GetReturnedItems(int receiveEmployeeID); } #endregion }