810 lines
22 KiB
C#
810 lines
22 KiB
C#
///////////////////////////////////////////////////////////
|
|
// WorkorderItemMiscExpense.cs
|
|
// Implementation of Class WorkorderItemMiscExpense
|
|
// CSLA type: Editable Child
|
|
// Created on: 07-Jun-2004 8:41:48 AM
|
|
// Object design: Joyce
|
|
// Coded: John 21-July-2004
|
|
///////////////////////////////////////////////////////////
|
|
|
|
using System;
|
|
using System.Data;
|
|
using CSLA.Data;
|
|
using GZTW.Data;
|
|
using CSLA;
|
|
using System.Threading;
|
|
using CSLA.Security;
|
|
|
|
namespace GZTW.AyaNova.BLL
|
|
{
|
|
/// <summary>
|
|
/// Expense object for <see cref="WorkorderItem"/> object's <see cref="WorkorderItemMiscExpenses"/> collection
|
|
///
|
|
/// </summary>
|
|
[Serializable]
|
|
public class WorkorderItemMiscExpense : BusinessBase {
|
|
|
|
#region Attributes
|
|
|
|
private bool bReadOnly;
|
|
private Guid mID;
|
|
private SmartDate mCreated;
|
|
private SmartDate mModified;
|
|
private Guid mCreator;
|
|
private Guid mModifier;
|
|
|
|
/// <summary>
|
|
/// Guid ID of root object (WorkorderItem)
|
|
/// </summary>
|
|
private Guid mWorkorderItemID;
|
|
/// <summary>
|
|
/// Descriptive name for miscelaneous expense
|
|
/// </summary>
|
|
private string mName="";
|
|
/// <summary>
|
|
/// Description regarding this miscellaneous expense such as explanation i.e Hotel
|
|
/// overnight, store bought as part out of stock, etc
|
|
/// </summary>
|
|
private string mDescription="";
|
|
/// <summary>
|
|
/// Actual total cost dollar amount including taxes if any of item
|
|
/// </summary>
|
|
private decimal mTotalCost;
|
|
/// <summary>
|
|
/// Tax dollar portion of TotalCost If company needs to separate taxes paid on it
|
|
/// (i.e tech purchased part from a store for use at the client site, need to
|
|
/// identify sales tax separately from cost of item for accounting purposes)
|
|
/// </summary>
|
|
private decimal mTaxPaid;
|
|
/// <summary>
|
|
/// Retail amount to charge client Can be null
|
|
/// </summary>
|
|
private decimal mChargeAmount;
|
|
/// <summary>
|
|
/// If true, than ChargeAmount is to be charged back to customer If false, than
|
|
/// internal data only
|
|
/// </summary>
|
|
private bool mChargeToClient;
|
|
/// <summary>
|
|
/// ID of tax code for this item Identifies the tax to be applied to the expense if
|
|
/// to be charged to the client
|
|
/// </summary>
|
|
private Guid mChargeTaxCodeID;
|
|
/// <summary>
|
|
/// TotalCost was paid by schedulable User and they need to be reimbursed
|
|
/// </summary>
|
|
private bool mReimburseUser;
|
|
/// <summary>
|
|
/// GUID of schedulable and active User to be reimbursed
|
|
/// If displaying historical information, would show a N/A (non-active) next to the
|
|
/// displayed name, but would not be able to reselect an active and schedulable
|
|
/// user
|
|
/// Can assign to a scheduleable User without setting a scheduled time and date -
|
|
/// for those that let tech decide when to schedule User can be null (unassigned)
|
|
/// </summary>
|
|
private Guid mUserID;
|
|
#endregion
|
|
|
|
#region Constructor
|
|
|
|
/// <summary>
|
|
/// Private constructor to prevent direct instantiation
|
|
/// </summary>
|
|
private WorkorderItemMiscExpense()
|
|
{
|
|
//Set to read / write initially so that properties
|
|
//can be set
|
|
bReadOnly=false;
|
|
|
|
//Child object
|
|
MarkAsChild();
|
|
|
|
//New ID
|
|
mID = Guid.NewGuid();
|
|
|
|
//Set record history to defaults
|
|
mCreated = new SmartDate(DBUtil.CurrentWorkingDateTime);
|
|
mModified=new SmartDate();
|
|
mCreator=Guid.Empty;
|
|
mModifier=Guid.Empty;
|
|
|
|
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Business properties
|
|
|
|
/// <summary>
|
|
/// Get internal id number Read only property because it's set internally, not
|
|
/// externally
|
|
/// </summary>
|
|
public Guid ID
|
|
{
|
|
get
|
|
{
|
|
return mID;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get created date
|
|
///
|
|
///
|
|
/// </summary>
|
|
public string Created
|
|
{
|
|
get
|
|
{
|
|
return mCreated.ToString();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get modified date
|
|
///
|
|
///
|
|
/// </summary>
|
|
public string Modified
|
|
{
|
|
get
|
|
{
|
|
return mModified.ToString();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get user record ID of person who created this record
|
|
///
|
|
///
|
|
/// </summary>
|
|
public Guid Creator
|
|
{
|
|
get
|
|
{
|
|
return mCreator;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get user ID of person who modified this record
|
|
///
|
|
///
|
|
/// </summary>
|
|
public Guid Modifier
|
|
{
|
|
get
|
|
{
|
|
return mModifier;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Description regarding this miscellaneous expense such as explanation i.e Hotel
|
|
/// overnight, store bought as part out of stock, etc
|
|
/// </summary>
|
|
public string Description
|
|
{
|
|
get
|
|
{
|
|
return mDescription;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mDescription!=value)
|
|
{
|
|
mDescription = value;
|
|
//Added 2-Aug-2006
|
|
BrokenRules.Assert("DescriptionLength",
|
|
"Error.Object.FieldLengthExceeded255,WorkorderItemMiscExpense.Label.Description",
|
|
"Description", value.Length > 255);
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// GUID of schedulable and active User to be reimbursed
|
|
/// </summary>
|
|
public Guid UserID
|
|
{
|
|
get
|
|
{
|
|
return mUserID;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mUserID!=value)
|
|
{
|
|
mUserID = value;
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Guid ID of parent <see cref="WorkorderItem"/> object
|
|
/// </summary>
|
|
public Guid WorkorderItemID
|
|
{
|
|
get
|
|
{
|
|
return mWorkorderItemID;
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// TotalCost was paid by schedulable User and they need to be reimbursed
|
|
/// </summary>
|
|
public bool ReimburseUser
|
|
{
|
|
get
|
|
{
|
|
return mReimburseUser;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mReimburseUser!=value)
|
|
{
|
|
mReimburseUser = value;
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// Retail amount to charge client Can be null
|
|
/// </summary>
|
|
public decimal ChargeAmount
|
|
{
|
|
get
|
|
{
|
|
return mChargeAmount;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mChargeAmount!=value)
|
|
{
|
|
mChargeAmount = value;
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// ID of <see cref="TaxCode"/> for this item Identifies the tax to be applied to the expense if
|
|
/// to be charged to the client
|
|
/// </summary>
|
|
public Guid ChargeTaxCodeID
|
|
{
|
|
get
|
|
{
|
|
return mChargeTaxCodeID;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mChargeTaxCodeID!=value)
|
|
{
|
|
mChargeTaxCodeID = value;
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// If true, than ChargeAmount is to be charged back to customer If false, than
|
|
/// internal data only
|
|
/// </summary>
|
|
public bool ChargeToClient
|
|
{
|
|
get
|
|
{
|
|
return mChargeToClient;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mChargeToClient!=value)
|
|
{
|
|
mChargeToClient = value;
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Descriptive name for miscellaneous expense
|
|
/// </summary>
|
|
public string Name
|
|
{
|
|
get
|
|
{
|
|
return mName;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mName!=value)
|
|
{
|
|
mName = value;
|
|
//Added 2-Aug-2006
|
|
BrokenRules.Assert("NameLength",
|
|
"Error.Object.FieldLengthExceeded255,WorkorderItemMiscExpense.Label.Name",
|
|
"Name", value.Length > 255);
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// Tax dollar portion of TotalCost If company needs to separate taxes paid on it
|
|
/// (i.e tech purchased part from a store for use at the client site, need to
|
|
/// identify sales tax separately from cost of item for accounting purposes)
|
|
/// </summary>
|
|
public decimal TaxPaid
|
|
{
|
|
get
|
|
{
|
|
return mTaxPaid;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mTaxPaid!=value)
|
|
{
|
|
mTaxPaid = value;
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Actual total cost dollar amount including taxes if any of item
|
|
/// </summary>
|
|
public decimal TotalCost
|
|
{
|
|
get
|
|
{
|
|
return mTotalCost;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mTotalCost!=value)
|
|
{
|
|
mTotalCost = value;
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// Called by parent collection object
|
|
/// when called in turn by workorder object that is read only due to
|
|
/// security or closed or service completed
|
|
/// </summary>
|
|
/// <param name="RO">Either true or the rights allowed for the current user</param>
|
|
public void SetReadOnly(bool RO)
|
|
{
|
|
bReadOnly=RO;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Throw an error when a read only user
|
|
/// tries to set a property
|
|
/// (this should normally never be called unless someone is using the developer api since the UI
|
|
/// should prevent it from happening initially)
|
|
/// </summary>
|
|
private void ThrowSetError()
|
|
{
|
|
throw new System.Security.SecurityException
|
|
(
|
|
string.Format
|
|
(
|
|
LocalizedTextTable.GetLocalizedTextDirect("Error.Security.NotAuthorizedToChange"),
|
|
LocalizedTextTable.GetLocalizedTextDirect("O.WorkorderItemMiscExpense")
|
|
)
|
|
);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region System.object overrides
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public override string ToString()
|
|
{
|
|
return "WorkorderItemMiscExpense" + mID.ToString();
|
|
}
|
|
|
|
///
|
|
/// <param name="obj"></param>
|
|
public override bool Equals(Object obj)
|
|
{
|
|
if ( obj == null || GetType ( ) != obj.GetType ( ) ) return false;
|
|
WorkorderItemMiscExpense c=(WorkorderItemMiscExpense)obj;
|
|
return mID==c.mID;
|
|
}
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public override int GetHashCode()
|
|
{
|
|
return ("WorkorderItemMiscExpense"+mID).GetHashCode();
|
|
}
|
|
#endregion
|
|
|
|
#region Searching
|
|
|
|
/// <summary>
|
|
/// Returns a search result object based on search terms
|
|
/// for the ID specified
|
|
/// </summary>
|
|
/// <param name="ID"></param>
|
|
/// <param name="searchTerms"></param>
|
|
/// <returns></returns>
|
|
public static SearchResult GetSearchResult(Guid ID, string[]searchTerms)
|
|
{
|
|
//case 1387
|
|
if (Workorder.RightsToWorkorder(WorkorderIDFetcher.GetWorkorderByRelative(RootObjectTypes.WorkorderItemMiscExpense, ID)) < SecurityLevelTypes.ReadOnly)
|
|
return new SearchResult();
|
|
SearchResult sr=new SearchResult();
|
|
|
|
System.Text.StringBuilder sb = new System.Text.StringBuilder();
|
|
SafeDataReader dr = null;
|
|
try
|
|
{
|
|
|
|
//Changed: 2-Oct-2006
|
|
//wrong query was here, was querying the Client table instead
|
|
//must have been copied and pasted
|
|
//Case 88
|
|
//"SELECT aCreated, aModified, aCreator, aModifier, aName, " +
|
|
// "aDescription, aName FROM aWorkorderItemMiscExpense WHERE (aID = @ID)"
|
|
dr=DBUtil.GetReaderFromSQLString(
|
|
|
|
//Case 88
|
|
"SELECT AWORKORDERITEMMISCEXPENSE.aID, AWORKORDERITEMMISCEXPENSE.aCreator, " +
|
|
" AWORKORDERITEMMISCEXPENSE.aModifier, AWORKORDERITEMMISCEXPENSE.aCreated, " +
|
|
" AWORKORDERITEMMISCEXPENSE.aModified, AWORKORDERITEMMISCEXPENSE.aName, AWORKORDERITEMMISCEXPENSE.aDescription," +
|
|
"AWORKORDERSERVICE.ASERVICENUMBER, " +
|
|
" AWORKORDERQUOTE.AQUOTENUMBER, AWORKORDERPREVENTIVEMAINTENANCE.APREVENTIVEMAINTENANCENUMBER, " +
|
|
" ACLIENT.ANAME AS ACLIENTNAME, aClient.aRegionID AS ACLIENTREGION, AWORKORDER.aWorkorderType " +
|
|
"FROM AWORKORDERITEMMISCEXPENSE INNER JOIN AWORKORDERITEM " +
|
|
"ON AWORKORDERITEMMISCEXPENSE.AWORKORDERITEMID = AWORKORDERITEM.AID " +
|
|
"LEFT OUTER " +
|
|
"JOIN AWORKORDER ON AWORKORDERITEM.AWORKORDERID = " +
|
|
"AWORKORDER.AID LEFT OUTER JOIN ACLIENT ON AWORKORDER.ACLIENTID " +
|
|
"= ACLIENT.AID LEFT OUTER JOIN AWORKORDERPREVENTIVEMAINTENANCE " +
|
|
"ON AWORKORDER.AID = " +
|
|
"AWORKORDERPREVENTIVEMAINTENANCE.AWORKORDERID LEFT OUTER JOIN " +
|
|
"AWORKORDERQUOTE ON AWORKORDER.AID = AWORKORDERQUOTE.AWORKORDERID " +
|
|
"LEFT OUTER JOIN AWORKORDERSERVICE " +
|
|
"ON AWORKORDER.AID = AWORKORDERSERVICE.AWORKORDERID " +
|
|
"WHERE (AWORKORDERITEMMISCEXPENSE.aID = @ID)"
|
|
|
|
|
|
,ID);
|
|
|
|
if(!dr.Read())
|
|
return new SearchResult();//DBUtil.ThrowFetchError("SearchResult for WorkorderItemMiscExpenseID: " + ID.ToString());
|
|
|
|
if (!AyaBizUtils.InYourRegion(dr.GetGuid("ACLIENTREGION"))) return new SearchResult();//case 58
|
|
|
|
WorkorderTypes workorderType = (WorkorderTypes)dr.GetInt16("aWorkorderType");
|
|
switch (workorderType)
|
|
{
|
|
case WorkorderTypes.Service:
|
|
sr.Description = LocalizedTextTable.GetLocalizedTextDirect("O.WorkorderService") + " " + dr.GetInt32("aServiceNumber").ToString() + " " + dr.GetString("ACLIENTNAME");
|
|
break;
|
|
case WorkorderTypes.Quote:
|
|
sr.Description = LocalizedTextTable.GetLocalizedTextDirect("O.WorkorderQuote") + " " + dr.GetInt32("AQUOTENUMBER").ToString() + " " + dr.GetString("ACLIENTNAME");
|
|
break;
|
|
case WorkorderTypes.PreventiveMaintenance:
|
|
sr.Description = LocalizedTextTable.GetLocalizedTextDirect("O.WorkorderPreventiveMaintenance") + " " + dr.GetInt32("APREVENTIVEMAINTENANCENUMBER").ToString() + " " + dr.GetString("ACLIENTNAME");
|
|
break;
|
|
}
|
|
|
|
//Case 88
|
|
//was using Name for description field, since above is now description
|
|
//moved it into regular extract text instead
|
|
sb.Append(dr.GetString("aName"));
|
|
sb.Append(" ");
|
|
sb.Append(dr.GetString("aDescription"));
|
|
|
|
sr.Created=DBUtil.ToLocal(dr.GetSmartDate("aCreated"));
|
|
sr.Modified=DBUtil.ToLocal(dr.GetSmartDate("aModified"));
|
|
sr.Creator=dr.GetGuid("aCreator");
|
|
sr.Modifier=dr.GetGuid("aModifier");
|
|
|
|
|
|
|
|
|
|
}
|
|
finally
|
|
{
|
|
if(dr!=null) dr.Close();
|
|
}
|
|
|
|
|
|
|
|
|
|
//Formulate results
|
|
ExtractAndRank er = new ExtractAndRank();
|
|
er.Process(sb.ToString().Trim(),searchTerms);
|
|
sr.Extract=er.Extract;
|
|
sr.Rank=er.Ranking;
|
|
sr.AncestorRootObjectID=ID;
|
|
sr.AncestorRootObjectType=RootObjectTypes.WorkorderItemMiscExpense;
|
|
|
|
return sr;
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Static methods
|
|
|
|
|
|
/// <summary>
|
|
/// New item
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
/// <returns></returns>
|
|
internal static WorkorderItemMiscExpense NewItem(WorkorderItem obj)
|
|
{
|
|
|
|
//case 1387
|
|
if (AyaBizUtils.IsGenerator || ((obj.mHeaderRights > SecurityLevelTypes.ReadOnly) &&
|
|
(AyaBizUtils.Right("Object.WorkorderItemMiscExpense") > (int)SecurityLevelTypes.ReadOnly)))
|
|
{
|
|
WorkorderItemMiscExpense child = new WorkorderItemMiscExpense();
|
|
child.mWorkorderItemID=obj.ID;
|
|
return child;
|
|
}
|
|
else
|
|
throw new System.Security.SecurityException(
|
|
string.Format(
|
|
LocalizedTextTable.GetLocalizedTextDirect("Error.Security.NotAuthorizedToCreate"),
|
|
LocalizedTextTable.GetLocalizedTextDirect("O.WorkorderItemMiscExpense")));
|
|
|
|
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get Item
|
|
/// </summary>
|
|
/// <param name="dr"></param>
|
|
/// <param name="obj"></param>
|
|
/// <returns></returns>
|
|
internal static WorkorderItemMiscExpense GetItem(SafeDataReader dr, WorkorderItem obj)
|
|
{
|
|
//case 1387
|
|
if ((obj.mHeaderRights > SecurityLevelTypes.NoAccess) &&
|
|
(AyaBizUtils.Right("Object.WorkorderItemMiscExpense") > (int)SecurityLevelTypes.NoAccess))
|
|
{
|
|
WorkorderItemMiscExpense child = new WorkorderItemMiscExpense();
|
|
child.Fetch(dr);
|
|
return child;
|
|
}
|
|
else
|
|
throw new System.Security.SecurityException(
|
|
string.Format(
|
|
LocalizedTextTable.GetLocalizedTextDirect("Error.Security.NotAuthorizedToRetrieve"),
|
|
LocalizedTextTable.GetLocalizedTextDirect("O.WorkorderItemMiscExpense")));
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
#region DAL DATA ACCESS
|
|
|
|
#region Fetch
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="dr"></param>
|
|
protected void Fetch(SafeDataReader dr)
|
|
{
|
|
|
|
//Standard fields
|
|
mCreated=DBUtil.ToLocal(dr.GetSmartDate("aCreated"));
|
|
mModified=DBUtil.ToLocal(dr.GetSmartDate("aModified"));
|
|
mCreator=dr.GetGuid("aCreator");
|
|
mModifier=dr.GetGuid("aModifier");
|
|
mID=dr.GetGuid("aID");
|
|
|
|
//WorkorderItemMiscExpense fields
|
|
mDescription=dr.GetString("aDescription");
|
|
mUserID=dr.GetGuid("aUserID");
|
|
mWorkorderItemID=dr.GetGuid("aWorkorderItemID");
|
|
mChargeAmount=dr.GetDecimal("aChargeAmount");
|
|
mChargeTaxCodeID=dr.GetGuid("aChargeTaxCodeID");
|
|
mChargeToClient=dr.GetBoolean("aChargeToClient");
|
|
mName=dr.GetString("aName");
|
|
mReimburseUser=dr.GetBoolean("aReimburseUser");
|
|
mTaxPaid=dr.GetDecimal("aTaxPaid");
|
|
mTotalCost=dr.GetDecimal("aTotalCost");
|
|
|
|
//Get access rights level
|
|
bReadOnly=AyaBizUtils.Right("Object.WorkorderItemMiscExpense")<(int)SecurityLevelTypes.ReadWrite;
|
|
|
|
MarkOld();
|
|
|
|
}
|
|
#endregion fetch
|
|
|
|
#region Add / Update
|
|
|
|
/// <summary>
|
|
/// Update child
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
/// <param name="tr"></param>
|
|
internal void Update(WorkorderItem obj,IDbTransaction tr)
|
|
{
|
|
//No need to update if there is nothing changed
|
|
if(!this.IsDirty) return;
|
|
|
|
|
|
// If not a new record, check if record was modified
|
|
//by another user since original retrieval:
|
|
if(!IsNew)
|
|
DBUtil.CheckSafeToUpdateInsideTransaction(this.mModified.Date, this.mID, "aWorkorderItemMiscExpense", tr);//case 1960
|
|
|
|
#region Delete
|
|
if(IsDeleted)
|
|
{
|
|
if(!IsNew)
|
|
{
|
|
DBCommandWrapper cmDelete = DBUtil.GetCommandFromSQL("DELETE FROM aWorkorderItemMiscExpense WHERE aID=@ID;");
|
|
cmDelete.AddInParameter("@ID",DbType.Guid,this.mID);
|
|
DBUtil.DB.ExecuteNonQuery(cmDelete, tr);
|
|
DBUtil.RemoveKeywords(tr,RootObjectTypes.WorkorderItemMiscExpense,this.mID);
|
|
|
|
}
|
|
MarkNew();
|
|
return;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Add / Update
|
|
//get modification time temporarily, if update succeeds then
|
|
//set to this time
|
|
System.DateTime dtModified = DBUtil.CurrentWorkingDateTime;
|
|
|
|
DBCommandWrapper cm = null;
|
|
if(IsNew)//Add or update?
|
|
cm=DBUtil.GetCommandFromSQL(
|
|
"INSERT INTO aWorkorderItemMiscExpense (aWorkorderItemID, " +
|
|
"aID, aTotalCost, aChargeAmount, aDescription, " +
|
|
"aTaxPaid, aChargeTaxCodeID, aName, aReimburseUser, " +
|
|
"aUserID, aChargeToClient, aCreated,aModified,aCreator,aModifier) " +
|
|
"VALUES (@WorkorderItemID,@ID,@TotalCost,@ChargeAmount, " +
|
|
"@Description,@TaxPaid, @ChargeTaxCodeID,@Name, " +
|
|
"@ReimburseUser,@UserID,@ChargeToClient,@Created,@Modified,@CurrentUserID, " +
|
|
"@CurrentUserID)"
|
|
);
|
|
|
|
else
|
|
cm=DBUtil.GetCommandFromSQL(
|
|
"UPDATE aWorkorderItemMiscExpense SET aWorkorderItemID=@WorkorderItemID, " +
|
|
"aID=@ID, aTotalCost=@TotalCost, " +
|
|
"aChargeAmount=@ChargeAmount, aDescription=@Description, " +
|
|
"aTaxPaid=@TaxPaid, aChargeTaxCodeID=@ChargeTaxCodeID, " +
|
|
"aName=@Name, aReimburseUser=@ReimburseUser, " +
|
|
"aUserID=@UserID, aChargeToClient=@ChargeToClient, " +
|
|
"aModifier=@CurrentUserID, aModified=@Modified " +
|
|
"WHERE aID=@ID"
|
|
);
|
|
|
|
//WorkorderItemMiscExpense specific
|
|
cm.AddInParameter("@ID",DbType.Guid,mID);
|
|
cm.AddInParameter("@WorkorderItemID",DbType.Guid,mWorkorderItemID);
|
|
cm.AddLargeStringInParameter("@Description",mDescription);
|
|
cm.AddInParameter("@UserID",DbType.Guid,mUserID);
|
|
cm.AddInParameter("@ChargeAmount",DbType.Decimal,mChargeAmount);
|
|
cm.AddInParameter("@ChargeTaxCodeID",DbType.Guid,mChargeTaxCodeID);
|
|
cm.AddInParameter("@ChargeToClient",DbType.Boolean,mChargeToClient);
|
|
cm.AddInParameter("@Name",DbType.String,mName);
|
|
cm.AddInParameter("@ReimburseUser",DbType.Boolean,mReimburseUser);
|
|
cm.AddInParameter("@TaxPaid",DbType.Decimal,mTaxPaid);
|
|
cm.AddInParameter("@TotalCost",DbType.Decimal,mTotalCost);
|
|
|
|
//standard parameters
|
|
cm.AddInParameter("@CurrentUserID",DbType.Guid, CurrentUserID);
|
|
cm.AddInParameter("@Created",DbType.DateTime, DBUtil.ToUTC(mCreated.Date));
|
|
cm.AddInParameter("@Modified",DbType.DateTime, DBUtil.ToUTC(dtModified));
|
|
|
|
|
|
DBUtil.DB.ExecuteNonQuery(cm, tr);
|
|
|
|
//Process keywords
|
|
DBUtil.ProcessKeywords(tr,this.mID,RootObjectTypes.WorkorderItemMiscExpense,IsNew,AyaBizUtils.Break(false,mDescription,mName));
|
|
|
|
MarkOld();//db is now synched with object
|
|
|
|
//Successful update so
|
|
//change modification time to match
|
|
this.mModified.Date=dtModified;
|
|
#endregion
|
|
|
|
}
|
|
#endregion add/update
|
|
|
|
#endregion
|
|
|
|
}//end WorkorderItemMiscExpense
|
|
|
|
}//end namespace GZTW.AyaNova.BLL |