288 lines
7.9 KiB
C#
288 lines
7.9 KiB
C#
///////////////////////////////////////////////////////////
|
|
// WorkorderServiceBillableList.cs
|
|
// Implementation of Class WorkorderServiceBillableList
|
|
// CSLA type: Read only collection
|
|
// Created on: 24-Feb-2006
|
|
// Object design: John
|
|
// Coded: 24-Feb-2006
|
|
///////////////////////////////////////////////////////////
|
|
|
|
using System;
|
|
using System.Data;
|
|
using GZTW.Data;
|
|
using CSLA.Data;
|
|
using CSLA;
|
|
|
|
namespace GZTW.AyaNova.BLL
|
|
{
|
|
#pragma warning disable 1591
|
|
/// <summary>
|
|
/// Read only list of <see cref="WorkorderServiceBillableList.WorkorderServiceBillableListInfo"/> objects representing
|
|
/// service work orders that are invoiceable. Used by accounting integration plugins.
|
|
/// </summary>
|
|
[Serializable]
|
|
public class WorkorderServiceBillableList : ReadOnlyCollectionBase
|
|
{
|
|
#region Data structure
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
[Serializable]
|
|
public struct WorkorderServiceBillableListInfo
|
|
{
|
|
|
|
internal Guid mID;
|
|
internal Guid mClientID;
|
|
internal string mClientName;
|
|
internal string mWorkorderStatusName;
|
|
internal int mServiceNumber;
|
|
internal SmartDate mServiceDate;
|
|
internal int mStatusARGB;
|
|
internal string mProjectName;
|
|
|
|
|
|
/// <summary>
|
|
/// Work order internal ID
|
|
/// </summary>
|
|
public Guid ID {get{return mID;}}
|
|
|
|
/// <summary>
|
|
/// Client internal ID
|
|
/// </summary>
|
|
public Guid ClientID {get{return mClientID;}}
|
|
|
|
/// <summary>
|
|
/// Client name
|
|
/// </summary>
|
|
public string Client {get{return mClientName;}}
|
|
|
|
/// <summary>
|
|
/// Workorder status
|
|
/// </summary>
|
|
public string Status {get{return mWorkorderStatusName;}}
|
|
|
|
/// <summary>
|
|
/// Visible sequential workorder number
|
|
/// </summary>
|
|
public int ServiceNumber {get{return mServiceNumber;}}
|
|
|
|
/// <summary>
|
|
/// Date of service
|
|
/// </summary>
|
|
public object ServiceDate {get{return mServiceDate.DBValue;}}
|
|
|
|
/// <summary>
|
|
/// Status color in ARGB integer format
|
|
/// </summary>
|
|
public int StatusARGB {get{return mStatusARGB;}}
|
|
|
|
/// <summary>
|
|
/// Workorder project
|
|
/// </summary>
|
|
public string Project {get{return mProjectName;}}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public bool Equals(WorkorderServiceBillableListInfo obj)
|
|
{
|
|
return this.mID.Equals(obj.mID);
|
|
}
|
|
|
|
}//end WorkorderServiceBillableListInfo
|
|
#endregion
|
|
|
|
#region Constructor
|
|
|
|
protected WorkorderServiceBillableList()
|
|
{
|
|
// AllowSort=false;
|
|
// AllowFind=true;
|
|
// AllowEdit=false;
|
|
// AllowNew=false;
|
|
// AllowRemove=false;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Business properties and methods
|
|
|
|
/// <summary>
|
|
/// Get item by index
|
|
/// </summary>
|
|
/// <param name="Item"></param>
|
|
public WorkorderServiceBillableListInfo this[int Item]
|
|
{
|
|
|
|
get
|
|
{
|
|
return (WorkorderServiceBillableListInfo) List[Item];
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Returns WorkorderServiceBillableListInfo item that matches passed in itemid value
|
|
/// </summary>
|
|
/// <param name="ItemID"></param>
|
|
public WorkorderServiceBillableListInfo this[Guid ItemID]
|
|
{
|
|
|
|
get
|
|
{
|
|
foreach (WorkorderServiceBillableListInfo child in List)
|
|
{
|
|
if(child.mID==ItemID) return child;
|
|
}
|
|
throw new ArgumentException("WorkorderServiceBillableList: ID not found:\r\n"+ItemID.ToString());
|
|
|
|
}
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
#region contains
|
|
/// <summary>
|
|
/// Check if item in collection
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public bool Contains(WorkorderServiceBillableListInfo obj)
|
|
{
|
|
foreach (WorkorderServiceBillableListInfo child in List)
|
|
{
|
|
if(child.Equals(obj)) return true;
|
|
}
|
|
return false;
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region Static methods
|
|
/// <summary>
|
|
/// Get all billable work orders
|
|
/// Work orders are considered billable if they are set to ServiceCompleted=true
|
|
/// and Closed=true
|
|
/// Update: And considered billable if they are in the current users region
|
|
///
|
|
/// </summary>
|
|
/// <param name="WorkorderStatusID">Filter by status or Guid.Empty for any status</param>
|
|
/// <param name="Regional">Filter by current user region</param>
|
|
/// <returns>list of <see cref="WorkorderServiceBillableList.WorkorderServiceBillableListInfo"/> objects</returns>
|
|
public static WorkorderServiceBillableList GetList(Guid WorkorderStatusID, bool Regional)
|
|
{
|
|
return (WorkorderServiceBillableList) DataPortal.Fetch(new Criteria(WorkorderStatusID, Regional));
|
|
}
|
|
|
|
|
|
public static WorkorderServiceBillableList GetEmptyList()
|
|
{
|
|
return new WorkorderServiceBillableList();
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
#region DAL DATA ACCESS
|
|
///
|
|
/// <param name="Criteria"></param>
|
|
protected override void DataPortal_Fetch(object Criteria)
|
|
{
|
|
Criteria crit = (Criteria)Criteria;
|
|
SafeDataReader dr = null;
|
|
try
|
|
{
|
|
string q="SELECT " +
|
|
" AWORKORDER.AID,AWORKORDER.ACLIENTID, " +
|
|
" ACLIENT.ANAME AS ACLIENTNAME, aClient.aRegionID, " +//case 58
|
|
" AWORKORDERSTATUS.ANAME AS ASTATUSNAME, " +
|
|
" AWORKORDERSTATUS.AARGB, " +
|
|
" AWORKORDERSERVICE.ASERVICENUMBER, " +
|
|
" AWORKORDERSERVICE.ASERVICEDATE, " +
|
|
" APROJECT.ANAME AS APROJECTNAME " +
|
|
"FROM " +
|
|
" AWORKORDER " +
|
|
" INNER JOIN ACLIENT ON (AWORKORDER.ACLIENTID = ACLIENT.AID) " +
|
|
" INNER JOIN AWORKORDERSERVICE ON (AWORKORDER.AID = AWORKORDERSERVICE.AWORKORDERID) " +
|
|
" LEFT OUTER JOIN AWORKORDERSTATUS ON (AWORKORDERSERVICE.AWORKORDERSTATUSID = AWORKORDERSTATUS.AID) " +
|
|
" LEFT OUTER JOIN APROJECT ON (AWORKORDER.APROJECTID = APROJECT.AID) " +
|
|
"WHERE " +
|
|
" (AWORKORDER.AWORKORDERTYPE = @aTrue) AND " +
|
|
" (AWORKORDER.ASERVICECOMPLETED = @aTrue) AND " +
|
|
" (AWORKORDER.ACLOSED = @aFalse) AND (AWORKORDERSERVICE.AINVOICENUMBER=@AEMPTYSTRING) ";
|
|
|
|
if(crit.WorkorderStatusID!=Guid.Empty)
|
|
q=q+"AND (AWORKORDERSERVICE.AWORKORDERSTATUSID=@ASTATUSID )";
|
|
|
|
DBCommandWrapper cm = DBUtil.DB.GetSqlStringCommandWrapper(DBUtil.AddRegionFilter(//case 58
|
|
q,"aClient","aRegionID",crit.Regional
|
|
)
|
|
);
|
|
|
|
cm.AddInParameter("@aTrue",DbType.Boolean,true);
|
|
cm.AddInParameter("@aFalse",DbType.Boolean,false);
|
|
cm.AddInParameter("@AEMPTYSTRING",DbType.String,"");
|
|
|
|
if(crit.WorkorderStatusID!=Guid.Empty)
|
|
cm.AddInParameter("@ASTATUSID",DbType.Guid,crit.WorkorderStatusID);
|
|
|
|
dr = new SafeDataReader(DBUtil.DB.ExecuteReader(cm));
|
|
|
|
|
|
|
|
while(dr.Read())
|
|
{
|
|
//*******************************************
|
|
WorkorderServiceBillableListInfo info=new WorkorderServiceBillableListInfo();
|
|
info.mID=dr.GetGuid("aID");
|
|
info.mClientID=dr.GetGuid("aClientID");
|
|
info.mClientName=dr.GetString("aClientName");
|
|
info.mProjectName=dr.GetString("aProjectName");
|
|
info.mServiceDate=DBUtil.ToLocal(dr.GetSmartDate("aServicedate"));
|
|
info.mServiceNumber=dr.GetInt32("aServiceNumber");
|
|
info.mStatusARGB=dr.GetInt32("aargb");
|
|
info.mWorkorderStatusName=dr.GetString("aStatusName");
|
|
InnerList.Add(info);
|
|
//*******************************************
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
if(dr!=null) dr.Close();
|
|
}
|
|
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region criteria
|
|
/// <summary>
|
|
/// Criteria for identifying existing object
|
|
/// </summary>
|
|
[Serializable]
|
|
private class Criteria
|
|
{
|
|
|
|
|
|
public Guid WorkorderStatusID;
|
|
public bool Regional;
|
|
public Criteria(Guid _WorkorderStatusID, bool _Regional )
|
|
{
|
|
WorkorderStatusID=_WorkorderStatusID;
|
|
Regional = _Regional;
|
|
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
|
|
}//end WorkorderServiceBillableList
|
|
#pragma warning restore 1591
|
|
}//end namespace GZTW.AyaNova.BLL |