625 lines
14 KiB
C#
625 lines
14 KiB
C#
///////////////////////////////////////////////////////////
|
|
// PurchaseOrderReceiptItem.cs
|
|
// Implementation of Class PurchaseOrderReceiptItem
|
|
// CSLA type: Editable Child
|
|
// Created on: 17-Nov-2004
|
|
// Object design: Joyce & John
|
|
// Coded: John 17-Nov-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>
|
|
/// Item received on <see cref="PurchaseOrderReceipt"/>
|
|
/// </summary>
|
|
[Serializable]
|
|
public class PurchaseOrderReceiptItem : BusinessBase
|
|
{
|
|
|
|
#region Attributes
|
|
|
|
private bool bReadOnly;
|
|
|
|
private Guid mID;
|
|
private Guid mCreator;
|
|
private Guid mModifier;
|
|
private SmartDate mCreated;
|
|
private SmartDate mModified;
|
|
|
|
private Guid mPurchaseOrderReceiptID;
|
|
private Guid mPartID;
|
|
private Guid mPartWarehouseID;
|
|
private Guid mPurchaseOrderID;
|
|
private Guid mPurchaseOrderItemID;
|
|
private decimal mReceiptCost;
|
|
private decimal mQuantityReceived;
|
|
|
|
private PartSerials mSerialNumbers;
|
|
|
|
//Read only fields
|
|
|
|
// //From the poitem:
|
|
// internal decimal mQuantityOrdered;
|
|
// internal decimal mPurchaseOrderCost;
|
|
// internal int mWorkorderNumber;
|
|
//
|
|
// internal Guid mPurchaseTaxCodeID;
|
|
// internal Guid mWorkorderItemPartRequestID;
|
|
// internal Guid mPartRequestedByID;
|
|
//
|
|
// //From the PO header:
|
|
// internal string mPOReferenceNumber;
|
|
// internal SmartDate mOrderedDate;
|
|
// internal SmartDate mExpectedReceiveDate;
|
|
|
|
|
|
//case 1086
|
|
internal Guid mPartRequestID;//used internally only
|
|
|
|
#endregion
|
|
|
|
#region Constructor
|
|
private PurchaseOrderReceiptItem()
|
|
{
|
|
//Set to read / write initially so that properties
|
|
//can be set
|
|
bReadOnly=false;
|
|
|
|
//Child object
|
|
MarkAsChild();
|
|
|
|
//New ID
|
|
mID = Guid.NewGuid();
|
|
mSerialNumbers=PartSerials.NewItems();
|
|
|
|
//Set record history to defaults
|
|
mCreated = new SmartDate(DBUtil.CurrentWorkingDateTime);
|
|
mModified=new SmartDate();
|
|
mCreator=Guid.Empty;
|
|
mModifier=Guid.Empty;
|
|
|
|
//break the zero quantity rule in advance
|
|
QuantityReceived=0;
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region BusinessProperties
|
|
|
|
//---Common properties
|
|
/// <summary>
|
|
/// Initial created date of this object
|
|
/// </summary>
|
|
public string Created
|
|
{
|
|
get
|
|
{
|
|
return mCreated.ToString();
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// User ID of who initially created this object
|
|
/// </summary>
|
|
public Guid Creator
|
|
{
|
|
get
|
|
{
|
|
return mCreator;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Last modified date of this object
|
|
/// </summary>
|
|
public string Modified
|
|
{
|
|
get
|
|
{
|
|
return mModified.ToString();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// User ID of who last modified this object
|
|
/// </summary>
|
|
public Guid Modifier
|
|
{
|
|
get
|
|
{
|
|
return mModifier;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Unique ID of this object
|
|
/// </summary>
|
|
public Guid ID
|
|
{
|
|
get
|
|
{
|
|
return mID;
|
|
}
|
|
}
|
|
|
|
|
|
//---PurchaseOrderReceiptItem specific properties
|
|
|
|
/// <summary>
|
|
/// Serial numbers collection for received part, 0 to many
|
|
/// </summary>
|
|
public PartSerials SerialNumbers
|
|
{
|
|
get
|
|
{
|
|
return mSerialNumbers;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// ID of parent
|
|
/// </summary>
|
|
public Guid PurchaseOrderReceiptID
|
|
{
|
|
get
|
|
{
|
|
return mPurchaseOrderReceiptID;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mPurchaseOrderReceiptID!=value)
|
|
{
|
|
mPurchaseOrderReceiptID = value;
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Part Guid
|
|
/// </summary>
|
|
public Guid PartID
|
|
{
|
|
get
|
|
{
|
|
return mPartID;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mPartID!=value)
|
|
{
|
|
mPartID = value;
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Warehouse guid
|
|
/// </summary>
|
|
public Guid PartWarehouseID
|
|
{
|
|
get
|
|
{
|
|
return mPartWarehouseID;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mPartWarehouseID!=value)
|
|
{
|
|
mPartWarehouseID = value;
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// ID of PurchaseOrder
|
|
/// </summary>
|
|
public Guid PurchaseOrderID
|
|
{
|
|
get
|
|
{
|
|
return mPurchaseOrderID;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mPurchaseOrderID!=value)
|
|
{
|
|
mPurchaseOrderID = value;
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// ID of PurchaseOrderItem
|
|
/// </summary>
|
|
public Guid PurchaseOrderItemID
|
|
{
|
|
get
|
|
{
|
|
return mPurchaseOrderItemID;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mPurchaseOrderItemID!=value)
|
|
{
|
|
mPurchaseOrderItemID = value;
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Actual vendor cost of item when received
|
|
///
|
|
/// </summary>
|
|
public decimal ReceiptCost
|
|
{
|
|
get
|
|
{
|
|
return mReceiptCost;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mReceiptCost!=value)
|
|
{
|
|
mReceiptCost = value;
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Actual quantity received
|
|
///
|
|
/// </summary>
|
|
public decimal QuantityReceived
|
|
{
|
|
get
|
|
{
|
|
return mQuantityReceived;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mQuantityReceived!=value)
|
|
{
|
|
mQuantityReceived = value;
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
//Read only UI helper fields
|
|
|
|
// public int WorkorderNumber
|
|
// {
|
|
// get
|
|
// {
|
|
// return mWorkorderNumber;
|
|
// }
|
|
//
|
|
// }
|
|
//
|
|
//
|
|
//
|
|
//
|
|
//
|
|
//
|
|
//
|
|
// public string ReferenceNumber
|
|
// {
|
|
// get
|
|
// {
|
|
// return this.mPOReferenceNumber;
|
|
// }
|
|
// }
|
|
|
|
|
|
//***************************************************************************
|
|
|
|
|
|
|
|
|
|
/// <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.PurchaseOrderReceiptItem")
|
|
)
|
|
);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region System.object overrides
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public override string ToString()
|
|
{
|
|
return "PurchaseOrderReceiptItem" + mID.ToString();
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
/// <returns></returns>
|
|
public override bool Equals(Object obj)
|
|
{
|
|
if ( obj == null || GetType ( ) != obj.GetType ( ) ) return false;
|
|
PurchaseOrderReceiptItem c=(PurchaseOrderReceiptItem)obj;
|
|
return mID==c.mID;
|
|
}
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public override int GetHashCode()
|
|
{
|
|
return ("PurchaseOrderReceiptItem" + mID).GetHashCode();
|
|
}
|
|
#endregion
|
|
|
|
#region Static methods
|
|
/// <summary>
|
|
/// Create item
|
|
/// </summary>
|
|
/// <param name="obj">Parent ID</param>
|
|
/// <returns>New Item</returns>
|
|
internal static PurchaseOrderReceiptItem NewItem(PurchaseOrderReceipt obj)
|
|
{
|
|
|
|
if(AyaBizUtils.Right("Object.PurchaseOrder")>(int)SecurityLevelTypes.ReadOnly)
|
|
{
|
|
PurchaseOrderReceiptItem child=new PurchaseOrderReceiptItem();
|
|
child.mPurchaseOrderReceiptID=obj.ID;
|
|
return child;
|
|
}
|
|
else
|
|
throw new System.Security.SecurityException(
|
|
string.Format(
|
|
LocalizedTextTable.GetLocalizedTextDirect("Error.Security.NotAuthorizedToCreate"),
|
|
LocalizedTextTable.GetLocalizedTextDirect("O.PurchaseOrderReceiptItem")));
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Retrieve item
|
|
/// </summary>
|
|
/// <param name="dr">Data reader</param>
|
|
/// <returns>item from database</returns>
|
|
internal static PurchaseOrderReceiptItem GetItem(SafeDataReader dr)
|
|
{
|
|
|
|
|
|
if(AyaBizUtils.Right("Object.PurchaseOrder")>(int)SecurityLevelTypes.NoAccess)
|
|
{
|
|
PurchaseOrderReceiptItem child = new PurchaseOrderReceiptItem();
|
|
child.Fetch(dr);
|
|
return child;
|
|
}
|
|
else
|
|
throw new System.Security.SecurityException(
|
|
string.Format(
|
|
LocalizedTextTable.GetLocalizedTextDirect("Error.Security.NotAuthorizedToRetrieve"),
|
|
LocalizedTextTable.GetLocalizedTextDirect("O.PurchaseOrderReceiptItem")));
|
|
}
|
|
#endregion
|
|
|
|
#region DAL DATA ACCESS
|
|
|
|
#region Fetch
|
|
/// <summary>
|
|
/// Fetch from db
|
|
/// </summary>
|
|
/// <param name="dr"></param>
|
|
private void Fetch(SafeDataReader dr)
|
|
{
|
|
//Standard items
|
|
mCreated=DBUtil.ToLocal(dr.GetSmartDate("aCreated"));
|
|
mCreator=dr.GetGuid("aCreator");
|
|
mModified=DBUtil.ToLocal(dr.GetSmartDate("aModified"));
|
|
mModifier=dr.GetGuid("aModifier");
|
|
mID=dr.GetGuid("aID");
|
|
|
|
//PurchaseOrderReceiptItem specific parameters
|
|
mPurchaseOrderReceiptID=dr.GetGuid("aPurchaseOrderReceiptID");
|
|
mPartID=dr.GetGuid("aPartID");
|
|
mPartWarehouseID=dr.GetGuid("aPartWarehouseID");
|
|
mPurchaseOrderID=dr.GetGuid("aPurchaseOrderID");
|
|
mPurchaseOrderItemID=dr.GetGuid("aPurchaseOrderItemID");
|
|
mReceiptCost=dr.GetDecimal("aReceiptCost");
|
|
mQuantityReceived=dr.GetDecimal("aQuantityReceived");
|
|
|
|
// mWorkorderNumber=dr.GetInt32("aWorkorderNumber");
|
|
//
|
|
//
|
|
|
|
// mPOReferenceNumber=dr.GetString("aReferenceNumber");
|
|
//
|
|
|
|
//Populate child serial numbers collection
|
|
//Since SerialNumbers is a grandchild collection
|
|
//will be loaded by the SerialNumbers collection
|
|
//object who will do the database call based on
|
|
//the ID of this object and it's root object type
|
|
mSerialNumbers=PartSerials.GetItems(RootObjectTypes.PurchaseOrder,mID);
|
|
|
|
//Get access rights level
|
|
bReadOnly=AyaBizUtils.Right("Object.PurchaseOrder")<(int)SecurityLevelTypes.ReadWrite;
|
|
|
|
|
|
MarkOld();
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region Update
|
|
|
|
/// <summary>
|
|
/// Persist object to database
|
|
/// </summary>
|
|
/// <param name="obj">Parent object</param>
|
|
/// <param name="tr">Parents transaction object</param>
|
|
internal void Update(PurchaseOrderReceipt obj,IDbTransaction tr)
|
|
{
|
|
|
|
|
|
|
|
|
|
// If not a new record, check if record was modified
|
|
//by another user since original retrieval:
|
|
if(!IsNew)
|
|
DBUtil.CheckSafeToUpdate(this.mModified.Date,this.mID,"aPurchaseOrderReceiptItem");
|
|
|
|
#region Delete
|
|
if(IsDeleted)
|
|
{
|
|
if(!IsNew)
|
|
{
|
|
//Delete object and child objects
|
|
DBCommandWrapper cmDelete = DBUtil.GetCommandFromSQL("DELETE FROM aPurchaseOrderReceiptItem WHERE aID = @ID;");
|
|
cmDelete.AddInParameter("@ID",DbType.Guid,this.mID);
|
|
DBUtil.DB.ExecuteNonQuery(cmDelete, tr);
|
|
}
|
|
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 aPurchaseOrderReceiptItem (aID, aPurchaseOrderReceiptID, " +
|
|
"aPartID, aPartWarehouseID, aPurchaseOrderID, aPurchaseOrderItemID, " +
|
|
"aReceiptCost, aQuantityReceived, aCreated,aModified,aCreator, " +
|
|
"aModifier) VALUES (@ID,@PurchaseOrderReceiptID, " +
|
|
"@PartID, @PartWarehouseID, @PurchaseOrderID,@PurchaseOrderItemID, @ReceiptCost, " +
|
|
"@QuantityReceived,@Created,@Modified,@CurrentUserID,@CurrentUserID)"
|
|
);
|
|
else
|
|
cm=DBUtil.GetCommandFromSQL(
|
|
"UPDATE aPurchaseOrderReceiptItem SET aID=@ID, aPurchaseOrderReceiptID=@PurchaseOrderReceiptID, " +
|
|
"aPartID=@PartID, aPartWarehouseID=@PartWarehouseID, " +
|
|
"aPurchaseOrderID=@PurchaseOrderID, aPurchaseOrderItemID=@PurchaseOrderItemID, " +
|
|
"aReceiptCost=@ReceiptCost, " +
|
|
"aQuantityReceived=@QuantityReceived, aModifier=@CurrentUserID, " +
|
|
"aModified=@Modified WHERE aID=@ID"
|
|
);
|
|
|
|
|
|
|
|
//PurchaseOrderReceiptItem specific parameters
|
|
cm.AddInParameter("@ID",DbType.Guid,this.mID);
|
|
cm.AddInParameter("@PurchaseOrderReceiptID",DbType.Guid,mPurchaseOrderReceiptID);
|
|
cm.AddInParameter("@PartID",DbType.Guid,mPartID);
|
|
cm.AddInParameter("@PartWarehouseID",DbType.Guid,this.mPartWarehouseID);
|
|
cm.AddInParameter("@PurchaseOrderID",DbType.Guid,mPurchaseOrderID);
|
|
cm.AddInParameter("@PurchaseOrderItemID",DbType.Guid,mPurchaseOrderItemID);
|
|
cm.AddInParameter("@ReceiptCost",DbType.Decimal,mReceiptCost);
|
|
cm.AddInParameter("@QuantityReceived",DbType.Decimal,mQuantityReceived);
|
|
|
|
//Standard fields
|
|
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);
|
|
|
|
|
|
//SerialNumbers is a grandchild collection
|
|
//It can not be saved until this receipt item is saved
|
|
//because there is a foreign key to the poreceipt item that requires
|
|
//the poreceiptitem to be present before it's saved
|
|
mSerialNumbers.Update(tr);
|
|
|
|
MarkOld();//db is now synched with object
|
|
//Successful update so
|
|
//change modification time to match
|
|
this.mModified.Date=dtModified;
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
}
|
|
#endregion update
|
|
|
|
#endregion
|
|
|
|
}//end PurchaseOrderReceiptItem
|
|
|
|
}//end namespace GZTW.AyaNova.BLL |