Acumatica PXGraphExtension - Table doesn't exist - acumatica

Apologies, I am new to Acumatica and can't find anything online about this customized BLC (business logic code) problem.
I have made an extension off the existing class, "Testing" and copied the PXSelectJoin statement from the original class which uses a InventoryTranHistEnqResult. Problem is however whenever I include InventoryTranHistEnqResult in any PXSelectJoin, it will have a runtime error saying: Table 'InventoryTranHistEnqResult' doesn't exist.
Looking at the SQL profiler, it seems InventoryTranHistEnqResult is made up of different tables and there is indeed no table called InventoryTranHistEnqResult. So how can I modify the PXSelectJoin using InventoryTranHistEnqResult?
DAC:
public partial class InventoryTranHistEnqResult : PX.Data.IBqlTable { #region GridLineNbr
// just for sorting in gris
public abstract class gridLineNbr : PX.Data.IBqlField { }
protected Int32? _GridLineNbr;
[PXDBInt(IsKey = true)]
[PXUIField(DisplayName = "Grid Line Nbr.", Visibility = PXUIVisibility.SelectorVisible, Visible = false)]
public virtual Int32? GridLineNbr
{
get
{
return this._GridLineNbr;
}
set
{
this._GridLineNbr = value;
}
}
#endregion
#region InventoryID
public abstract class inventoryID : PX.Data.IBqlField { }
protected Int32? _InventoryID;
[Inventory(Visibility = PXUIVisibility.SelectorVisible, DisplayName = "Inventory ID")]
public virtual Int32? InventoryID
{
get
{
return this._InventoryID;
}
set
{
this._InventoryID = value;
}
}
#endregion #region TranDate
public abstract class tranDate : PX.Data.IBqlField
{
}
protected DateTime? _TranDate;
[PXDBDate()]
[PXUIField(DisplayName = "Date")]
public virtual DateTime? TranDate
{
get
{
return this._TranDate;
}
set
{
this._TranDate = value;
}
}
#endregion #region TranType
public abstract class tranType : PX.Data.IBqlField { }
protected String _TranType;
[PXString(3)] // ???
[INTranType.List()]
[PXUIField(DisplayName = "Tran. Type", Visibility = PXUIVisibility.SelectorVisible)]
public virtual String TranType
{
get
{
return this._TranType;
}
set
{
this._TranType = value;
}
}
#endregion #region DocType
public abstract class docType : PX.Data.IBqlField
{
}
protected String _DocType;
[PXDBString(1, IsKey = true, IsFixed = true)]
[PXUIField(DisplayName = "Doc Type", Visibility = PXUIVisibility.Visible, Visible = false)]
public virtual String DocType
{
get
{
return this._DocType;
}
set
{
this._DocType = value;
}
}
#endregion #region DocRefNbr
public abstract class docRefNbr : PX.Data.IBqlField
{
}
protected String _DocRefNbr;
[PXString(15, IsUnicode = true)]
[PXUIField(DisplayName = "Reference Nbr.", Visibility = PXUIVisibility.SelectorVisible)]
[PXSelector(typeof(Search<INRegister.refNbr>))]
public virtual String DocRefNbr
{
get
{
return this._DocRefNbr;
}
set
{
this._DocRefNbr = value;
}
}
#endregion
#region SubItemID
public abstract class subItemID : PX.Data.IBqlField
{
}
protected Int32? _SubItemID;
[SubItem(Visibility = PXUIVisibility.SelectorVisible, DisplayName = "Subitem")]
public virtual Int32? SubItemID
{
get
{
return this._SubItemID;
}
set
{
this._SubItemID = value;
}
}
#endregion #region SiteId
public abstract class siteID : PX.Data.IBqlField { }
protected Int32? _SiteID;
//[PXDBInt(IsKey = true)] //???
[Site(Visibility = PXUIVisibility.SelectorVisible, DisplayName = "Warehouse")]
public virtual Int32? SiteID
{
get
{
return this._SiteID;
}
set
{
this._SiteID = value;
}
}
#endregion #region LocationID
public abstract class locationID : PX.Data.IBqlField { }
protected Int32? _LocationID;
// [PXDBInt(IsKey = true)] //???
[Location(Visibility = PXUIVisibility.SelectorVisible, DisplayName = "Location")]
public virtual Int32? LocationID
{
get
{
return this._LocationID;
}
set
{
this._LocationID = value;
}
}
#endregion #region LotSerialNbr
public abstract class lotSerialNbr : PX.Data.IBqlField
{
}
protected String _LotSerialNbr;
[PXDBString(100, IsUnicode = true, IsKey = true, InputMask = "")]
[PXUIField(DisplayName = "Lot/Serial Number", Visibility = PXUIVisibility.SelectorVisible)]
public virtual String LotSerialNbr
{
get
{
return this._LotSerialNbr;
}
set
{
this._LotSerialNbr = value;
}
}
#endregion #region FinPerNbr
public abstract class finPerNbr : PX.Data.IBqlField { };
protected String _FinPerNbr;
[GL.FinPeriodID()]
[PXUIField(DisplayName = "Fin. Period", Visibility = PXUIVisibility.SelectorVisible)]
public virtual String FinPerNbr
{
get
{
return this._FinPerNbr;
}
set
{
this._FinPerNbr = value;
}
}
#endregion #region TranPerNbr
public abstract class tranPerNbr : PX.Data.IBqlField { };
protected String _TranPerNbr;
[GL.FinPeriodID()]
[PXUIField(DisplayName = "Tran. Period", Visibility = PXUIVisibility.SelectorVisible)]
public virtual String TranPerNbr
{
get
{
return this._TranPerNbr;
}
set
{
this._TranPerNbr = value;
}
}
#endregion
#region Released
public abstract class released : PX.Data.IBqlField { }
protected bool? _Released = false;
[PXBool]
[PXUIField(DisplayName = "Released", Visibility = PXUIVisibility.SelectorVisible)]
public virtual bool? Released
{
get
{
return this._Released;
}
set
{
this._Released = value;
}
}
#endregion
// Qtys in stock UOM here #region BegQty
public abstract class begQty : PX.Data.IBqlField
{
}
protected Decimal? _BegQty;
[PXDBQuantity()]
[PXDefault(TypeCode.Decimal, "0.0")]
[PXUIField(DisplayName = "Beginning Qty.", Visibility = PXUIVisibility.SelectorVisible)]
public virtual Decimal? BegQty
{
get
{
return this._BegQty;
}
set
{
this._BegQty = value;
}
}
#endregion #region QtyIn
public abstract class qtyIn : PX.Data.IBqlField
{
}
protected Decimal? _QtyIn;
[PXDBQuantity()]
[PXDefault(TypeCode.Decimal, "0.0")]
[PXUIField(DisplayName = "Qty. In", Visibility = PXUIVisibility.SelectorVisible)]
public virtual Decimal? QtyIn
{
get
{
return this._QtyIn;
}
set
{
this._QtyIn = value;
}
}
#endregion #region QtyOut
public abstract class qtyOut : PX.Data.IBqlField
{
}
protected Decimal? _QtyOut;
[PXDBQuantity()]
[PXDefault(TypeCode.Decimal, "0.0")]
[PXUIField(DisplayName = "Qty. Out", Visibility = PXUIVisibility.SelectorVisible)]
public virtual Decimal? QtyOut
{
get
{
return this._QtyOut;
}
set
{
this._QtyOut = value;
}
}
#endregion #region EndQty
public abstract class endQty : PX.Data.IBqlField
{
}
protected Decimal? _EndQty;
[PXDBQuantity()]
[PXDefault(TypeCode.Decimal, "0.0")]
[PXUIField(DisplayName = "Ending Qty.", Visibility = PXUIVisibility.SelectorVisible)]
public virtual Decimal? EndQty
{
get
{
return this._EndQty;
}
set
{
this._EndQty = value;
}
}
#endregion
#region UnitCost
public abstract class unitCost : PX.Data.IBqlField
{
}
protected Decimal? _UnitCost;
[PXDBPriceCost()]
[PXDefault(TypeCode.Decimal, "0.0")]
[PXUIField(DisplayName = "Unit Cost", Visibility = PXUIVisibility.SelectorVisible)]
public virtual Decimal? UnitCost
{
get
{
return this._UnitCost;
}
set
{
this._UnitCost = value;
}
}
#endregion
// not used currently : #region ExtCost
public abstract class extCost : PX.Data.IBqlField
{
}
protected Decimal? _ExtCost;
[PXDBBaseCury()]
[PXDefault(TypeCode.Decimal, "0.0")]
[PXUIField(DisplayName = "Extended Cost", Visibility = PXUIVisibility.SelectorVisible)]
public virtual Decimal? ExtCost
{
get
{
return this._ExtCost;
}
set
{
this._ExtCost = value;
}
}
#endregion #region BegBalance
public abstract class begBalance : PX.Data.IBqlField
{
}
protected Decimal? _BegBalance;
[PXDBBaseCury()]
[PXDefault(TypeCode.Decimal, "0.0")]
[PXUIField(DisplayName = "Beginning Balance", Visibility = PXUIVisibility.SelectorVisible)]
public virtual Decimal? BegBalance
{
get
{
return this._BegBalance;
}
set
{
this._BegBalance = value;
}
}
#endregion #region EndBalance
public abstract class endBalance : PX.Data.IBqlField
{
}
protected Decimal? _EndBalance;
[PXDBBaseCury()]
[PXDefault(TypeCode.Decimal, "0.0")]
[PXUIField(DisplayName = "Ending Balance", Visibility = PXUIVisibility.SelectorVisible)]
public virtual Decimal? EndBalance
{
get
{
return this._EndBalance;
}
set
{
this._EndBalance = value;
}
}
#endregion
}
BLC:
public class Testing_Extension:PXGraph<InventoryTranHistEnq> {
public PXFilter<InventoryTranHistEnqFilter> Filter;
[PXFilterable]
public PXSelectJoin<InventoryTranHistEnqResult,
CrossJoin<INTran>,
Where<True, Equal<True>>,
OrderBy<Asc<InventoryTranHistEnqResult.gridLineNbr>>> ResultRecords;
public PXSelectJoin<InventoryTranHistEnqResult,
CrossJoin<INTran>,
Where<True, Equal<True>>,
OrderBy<Asc<InventoryTranHistEnqResult.gridLineNbr>>> InternalResultRecords;
public PXCancel<InventoryTranHistEnqFilter> Cancel;
public PXAction<InventoryTranHistEnqFilter> viewSummary;
public PXAction<InventoryTranHistEnqFilter> viewAllocDet;
protected virtual void InventoryTranHistEnqFilter_StartDate_FieldDefaulting(PXCache sender, PXFieldDefaultingEventArgs e)
{
if (true)
{
DateTime businessDate = (DateTime)this.Accessinfo.BusinessDate;
e.NewValue = new DateTime(businessDate.Year, businessDate.Month, 01);
e.Cancel = true;
}
}
public override void Initialize()
{
ResultRecords.Cache.AllowInsert = false;
ResultRecords.Cache.AllowDelete = false;
ResultRecords.Cache.AllowUpdate = false;
}
protected virtual IEnumerable resultRecords()
{
int startRow = 0;
int totalRows = 0;
PXResultset<InventoryTranHistEnqResult> usortedList = InternalResultRecords.Select();
if (usortedList.Count == 0)
return usortedList;
decimal beginQty = ((InventoryTranHistEnqResult)usortedList[0]).BegQty ?? 0m;
List<object> list = InternalResultRecords.View.Select(PXView.Currents, PXView.Parameters, new object[PXView.SortColumns.Length], PXView.SortColumns, PXView.Descendings, PXView.Filters, ref startRow, 0, ref totalRows);
foreach (PXResult<InventoryTranHistEnqResult> item in list)
{
InventoryTranHistEnqResult it = (InventoryTranHistEnqResult)item;
it.BegQty = beginQty;
decimal? QtyIn = it.QtyIn;
decimal? QtyOut = it.QtyOut;
beginQty += (QtyIn ?? 0m) - (QtyOut ?? 0m);
it.EndQty = beginQty;
}
return list;
}
protected virtual IEnumerable internalResultRecords()
{
InventoryTranHistEnqFilter filter = Filter.Current;
bool summaryByDay = filter.SummaryByDay ?? false;
bool includeUnreleased = filter.IncludeUnreleased ?? false;
PXUIFieldAttribute.SetVisible<InventoryTranHistEnqResult.inventoryID>(ResultRecords.Cache, null, false);
PXUIFieldAttribute.SetVisible<InventoryTranHistEnqResult.finPerNbr>(ResultRecords.Cache, null, false); //???
PXUIFieldAttribute.SetVisible<InventoryTranHistEnqResult.tranPerNbr>(ResultRecords.Cache, null, false); //???
PXUIFieldAttribute.SetVisible<InventoryTranHistEnqResult.tranType>(ResultRecords.Cache, null, !summaryByDay);
PXUIFieldAttribute.SetVisible<InventoryTranHistEnqResult.docRefNbr>(ResultRecords.Cache, null, !summaryByDay);
PXUIFieldAttribute.SetVisible<InventoryTranHistEnqResult.subItemID>(ResultRecords.Cache, null, !summaryByDay);
PXUIFieldAttribute.SetVisible<InventoryTranHistEnqResult.siteID>(ResultRecords.Cache, null, !summaryByDay);
PXUIFieldAttribute.SetVisible<InventoryTranHistEnqResult.locationID>(ResultRecords.Cache, null, !summaryByDay);
PXUIFieldAttribute.SetVisible<InventoryTranHistEnqResult.lotSerialNbr>(ResultRecords.Cache, null, !summaryByDay);
PXUIFieldAttribute.SetVisible(Tran.Cache, null, !summaryByDay);
var resultList = new List<PXResult<InventoryTranHistEnqResult, INTran>>();
if (filter.InventoryID == null)
{
return resultList; //empty
}
// it's better for perfomance to calc. BegQty in the separate GROUP BY query before main.. but currently as is
PXSelectBase<INTranSplit> cmd = new PXSelectReadonly3<INTranSplit,
InnerJoin<INTran,
On<INTran.tranType, Equal<INTranSplit.tranType>,
And<INTran.refNbr, Equal<INTranSplit.refNbr>,
And<INTran.lineNbr, Equal<INTranSplit.lineNbr>>>>,
InnerJoin<INSubItem,
On<INSubItem.subItemID, Equal<INTranSplit.subItemID>>,
InnerJoin<INSite, On<INSite.siteID, Equal<INTran.siteID>>>>>,
OrderBy<Asc<INTranSplit.tranDate, Asc<INTranSplit.createdDateTime, Asc<INTranSplit.lastModifiedDateTime>>>>>(this);
cmd.WhereAnd<Where<INTranSplit.inventoryID, Equal<Current<InventoryTranHistEnqFilter.inventoryID>>, And<Match<INSite, Current<AccessInfo.userName>>>>>();
if (!SubCDUtils.IsSubCDEmpty(filter.SubItemCD))
{
cmd.WhereAnd<Where<INSubItem.subItemCD, Like<Current<InventoryTranHistEnqFilter.subItemCDWildcard>>>>();
}
if (filter.SiteID != null)
{
cmd.WhereAnd<Where<INTranSplit.siteID, Equal<Current<InventoryTranHistEnqFilter.siteID>>>>();
}
if ((filter.LocationID ?? -1) != -1) // there are cases when filter.LocationID = -1
{
cmd.WhereAnd<Where<INTranSplit.locationID, Equal<Current<InventoryTranHistEnqFilter.locationID>>>>();
}
if ((filter.LotSerialNbr ?? "") != "")
{
cmd.WhereAnd<Where<INTranSplit.lotSerialNbr, Like<Current<InventoryTranHistEnqFilter.lotSerialNbrWildcard>>>>();
}
if (!includeUnreleased)
{
cmd.WhereAnd<Where<INTranSplit.released, Equal<boolTrue>>>();
}
// commented because we need all the trans to calc BegQty
// if (filter.StartDate != null)
// {
// cmd.WhereAnd<Where<INTranSplit.tranDate, GreaterEqual<Current<InventoryTranHistEnqFilter.startDate>>>>();
// }
if (filter.EndDate != null)
{
cmd.WhereAnd<Where<INTranSplit.tranDate, LessEqual<Current<InventoryTranHistEnqFilter.endDate>>>>();
}
PXResultset<INTranSplit> intermediateResult = (PXResultset<INTranSplit>)cmd.Select();
decimal cumulativeQty = 0m;
int gridLineNbr = 0;
foreach (PXResult<INTranSplit, INTran, INSubItem> it in intermediateResult)
{
INTranSplit ts_rec = (INTranSplit)it;
INTran t_rec = (INTran)it;
if (ts_rec.TranDate < filter.StartDate)
{
cumulativeQty += (ts_rec.InvtMult * ts_rec.BaseQty) ?? 0m;
}
else
{
if (summaryByDay)
{
if ((resultList.Count > 0) && (((InventoryTranHistEnqResult)resultList[resultList.Count - 1]).TranDate == ts_rec.TranDate))
{
InventoryTranHistEnqResult lastItem = resultList[resultList.Count - 1];
if (ts_rec.InvtMult * ts_rec.BaseQty >= 0)
{
lastItem.QtyIn += ts_rec.InvtMult * ts_rec.BaseQty;
}
else
{
lastItem.QtyOut -= ts_rec.InvtMult * ts_rec.BaseQty;
}
lastItem.EndQty += ts_rec.InvtMult * ts_rec.BaseQty;
}
else
{
InventoryTranHistEnqResult item = new InventoryTranHistEnqResult();
item.BegQty = cumulativeQty;
item.TranDate = ts_rec.TranDate;
if (ts_rec.InvtMult * ts_rec.BaseQty >= 0)
{
item.QtyIn = ts_rec.InvtMult * ts_rec.BaseQty;
item.QtyOut = 0m;
}
else
{
item.QtyIn = 0m;
item.QtyOut = -ts_rec.InvtMult * ts_rec.BaseQty;
}
item.EndQty = item.BegQty + (ts_rec.InvtMult * ts_rec.BaseQty);
item.GridLineNbr = ++gridLineNbr;
resultList.Add(new PXResult<InventoryTranHistEnqResult, INTran>(item, null));
}
cumulativeQty += (ts_rec.InvtMult * ts_rec.BaseQty) ?? 0m;
}
else
{
InventoryTranHistEnqResult item = new InventoryTranHistEnqResult();
item.BegQty = cumulativeQty;
item.TranDate = ts_rec.TranDate;
if (ts_rec.InvtMult * ts_rec.BaseQty >= 0)
{
item.QtyIn = ts_rec.InvtMult * ts_rec.BaseQty;
item.QtyOut = 0m;
}
else
{
item.QtyIn = 0m;
item.QtyOut = -ts_rec.InvtMult * ts_rec.BaseQty;
}
item.EndQty = item.BegQty + (ts_rec.InvtMult * ts_rec.BaseQty);
item.InventoryID = ts_rec.InventoryID;
item.TranType = ts_rec.TranType;
item.DocType = ts_rec.DocType;
item.DocRefNbr = ts_rec.RefNbr;
item.SubItemID = ts_rec.SubItemID;
item.SiteID = ts_rec.SiteID;
item.LocationID = ts_rec.LocationID;
item.LotSerialNbr = ts_rec.LotSerialNbr;
item.FinPerNbr = t_rec.FinPeriodID;
item.TranPerNbr = t_rec.TranPeriodID;
item.Released = t_rec.Released;
item.GridLineNbr = ++gridLineNbr;
item.UnitCost = (t_rec.BaseQty != null && t_rec.BaseQty != 0m && t_rec.TranCost != null && t_rec.TranCost != 0m) ? t_rec.TranCost / t_rec.BaseQty : t_rec.UnitCost;
resultList.Add(new PXResult<InventoryTranHistEnqResult, INTran>(item, t_rec));
cumulativeQty += (ts_rec.InvtMult * ts_rec.BaseQty) ?? 0m;
}
}
}
return resultList;
}
public override bool IsDirty
{
get
{
return false;
}
}
public static void Redirect(string finPeriodID, int? inventoryID, string subItemCD, string lotSerNum, int? siteID, int? locationID)
{
InventoryTranHistEnq graph = PXGraph.CreateInstance<InventoryTranHistEnq>();
graph.Filter.Current.InventoryID = inventoryID;
graph.Filter.Current.SubItemCD = subItemCD;
graph.Filter.Current.SiteID = siteID;
graph.Filter.Current.LocationID = locationID;
graph.Filter.Current.LotSerialNbr = lotSerNum;
throw new PXRedirectRequiredException(graph, Messages.InventoryTranHist);
}
}

Related

Acumatica - Revision

We have 2 DAC - Master and Child
Master DAC
#region MasterID
public abstract class masterID:PX.Data.BQL.BqlInt.Field<masterID> { }
protected int? _MasterID;
[PXDBIdentity()]
[PXUIField(Visibility = PXUIVisibility.Invisible)]
[PXReferentialIntegrityCheck]
public virtual int? MasterID
{
get {return this._MasterID;}
set {this._MasterID = value;}
}
#endregion
#region MasterCD
public abstract class masterRoutingCD:PX.Data.BQL.BqlString.Field<masterCD> { }
protected string _MasterRoutingCD;
[BomID(DisplayName = "Master #", IsKey = true, Required = true,
Visibility = PXUIVisibility.SelectorVisible)]
[PXDefault]
[Rev.Key(typeof(Setup.pMMasterNumberSequenceID),
typeof(Master.masterCD),
typeof(Master.revisionNo),
typeof(Master.masterCD),
typeof(Master.revisionNo)
)]
public virtual string MasterCD
{
get {return this._MasterCD;}
set {this._MasterCD = value;}
}
#endregion
#region RevisionNo
public abstract class revisionNo:PX.Data.IBqlField { }
protected string _RevisionNo;
[RevisionIDField(IsKey = true, Visibility = PXUIVisibility.SelectorVisible,
Required = true)]
[PXDefault(typeof(Master.defaultRevisionNo),
PersistingCheck = PXPersistingCheck.Nothing)]
[Rev.ID(typeof(Master.defaultRevisionNo),
typeof(Master.masterCD),
typeof(Master.revisionNo),
typeof(Master.revisionNo),
typeof(Master.description),
typeof(Master.fromDate),
typeof(Master.toDate))]
public virtual string RevisionNo
{
get {return this._RevisionNo;}
set {this._RevisionNo = value;}
}
#endregion
Child DAC
public abstract class childID:PX.Data.BQL.BqlInt.Field<childID> { }
protected int? _ChildID;
[PXDBIdentity()]
//[PXReferentialIntegrityCheck]
public virtual int? ChildID
{
get {return this._ChildID;}
set {this._ChildID = value;}
}
#endregion
#region MasterID
public abstract class masterID:PX.Data.BQL.BqlInt.Field<masterID> { }
protected int? _MasterID;
[PXDBInt()]
[PXDBDefault(typeof(Master.masterID))]
[PXParent(typeof(Select<Master, Where<Master.masterRoutingCD, Equal<Current<masterCD>>,
And<Master.revisionNo, Equal<Current<revisionNo>>>>>))]
public virtual int? MasterID
{
get {return _MasterID;}
set {_MasterID = value;}
}
#endregion MasterID
#region MasterCD
public abstract class masterCD:PX.Data.BQL.BqlString.Field<masterCD> { }
protected string _MasterCD;
[PXDBDefault(typeof(Master.masterCD))]
[PXDBString(IsKey = true, IsUnicode = true)]
public virtual string MasterCD
{
get {return this._MasterCD;}
set {this._MasterCD = value;}
}
#endregion
#region Revision
public abstract class revisionNo:PX.Data.BQL.BqlString.Field<revisionNo> {}
[PXDBString(15, IsKey = true, IsUnicode = true)]
[PXDBDefault(typeof(Master.revisionNo))]
public virtual string RevisionNo { get; set; }
#endregion Revision
public abstract class stepsID:PX.Data.BQL.BqlInt.Field<stepsID> { }
[OperationCDField(IsKey =true, DisplayName = "Steps ID",
Visibility = PXUIVisibility.SelectorVisible)]
[PXDefault(PersistingCheck = PXPersistingCheck.NullOrBlank)]
//[PXUIField(DisplayName = "Process Steps ID")]
public virtual string StepsID { get; set; }
Graph - MasterMaint
public class MasterMaint:PXRevisionableGraph<MasterMaint, Master,
Master.masterCD, Master.revisionNo>
{
public PXSelect<Child, Where<Child.masterCD, Equal<Current<Master.masterCD>>,
And<Child.revisionNo, Equal<Current<Master.revisionNo>>>>> ChildRecords;
#region Override
public override bool CanClipboardCopyPaste()
{
return false;
}
public override bool CanCreateNewRevision(MasterMaint fromGraph, MasterMaint toGraph,
string keyValue, string revisionValue, out string error)
{
// Always returns true as new revisions can be created at any time
error = string.Empty;
return true;
}
public override void CopyRevision(MasterMaint fromGraph, MasterMaint toGraph,
string keyValue, string revisionValue)
{
if(toGraph?.Documents?.Current == null || fromGraph?.Documents?.Current == null)
{
// api calls should create new revs on their own - this causes issues
// when calling from api so we need to turn the copy rev logic off
return;
}
toGraph.Documents.Cache.SetDefaultExt<EWPMMasterRouting.status>
(toGraph.Documents.Current);
if(SkipAutoCreateNewRevision())
{
return;
}
CopyChildRecords(fromGraph.Documents.Current.MasterRoutingCD,
fromGraph.Documents.Current.RevisionNo, toGraph.Documents.Current.MasterID,
keyValue, revisionValue, false);
}
internal virtual void CopyChildRecords(string sourceID, string sourceRevisionNo,
int? newMasterID, string newMasterCD, string newRevisionID, bool copyNotes)
{
foreach(Child fromRow in PXSelect<Child,
Where<Child.masterCD, Equal<Required<Child.masterCD>>,
And<Child.revisionNo, Equal<Required<Child.revisionNo>>>>>
.Select(this, sourceID, sourceRevisionNo))
{
var toRow = PXCache<Child>.CreateCopy(fromRow);
toRow.MasterID = newMasterRoutingID;
toRow.ChildID = null;
toRow.MasterCD = newMasterCD;
toRow.RevisionNo= newRevisionID;
toRow = ChildRecords.Insert(toRow);
}
}
#endregion
}
Issue - When the value is changed in the Revision the record is displayed with new revision number keeping the CD fields as for previous revision and all the child.
That is all correct, But when the record is saved, there is error "Another process has updated the Record, your changes will be lost"
Why there is a Error
In Acuamtica we have NoteID column unique across the system If you try to create a record with duplicating NoteID field value you'll get "Another process has updated the record" exception because it consider that you are updating the same record.
In you case when you copy revision you do not reset the NoteID value for the record so you actually try to insert another record with the same value.
You'll need to add the following line to CopyRevision method
toGraph.Documents.Cache.SetDefaultExt<EWPMMasterRouting.noteID>(toGraph.Documents.Current);

FieldDefaulting handlers

I am having trouble setting default values for a filter on a processing page. I originally had code in the RowSelected handler to set the default values and set the end dates default as below:
//Local unbound filter DAC
#region StartShipDate
public abstract class startShipDate : PX.Data.IBqlField { }
protected DateTime? _StartShipDate;
[PXDate()]
[PXUIField(DisplayName = "Start Ship Date", Visibility = PXUIVisibility.SelectorVisible, Required = false)]
[PXDefault(PersistingCheck = PXPersistingCheck.Nothing)]
public virtual DateTime? StartShipDate { get; set; }
#endregion
#region EndShipDate
public abstract class endShipDate : PX.Data.IBqlField { }
protected DateTime? _EndShipDate;
[PXDate()]
[PXUIField(DisplayName = "End Ship Date", Visibility = PXUIVisibility.SelectorVisible)]
[PXDefault(typeof(AccessInfo.businessDate), PersistingCheck = PXPersistingCheck.Nothing)]
public virtual DateTime? EndShipDate { get; set; }
#endregion
#region StartImportDate
public abstract class startImportDate : PX.Data.IBqlField { }
protected DateTime? _StartImportDate;
[PXDate()]
[PXUIField(DisplayName = "Start Import Date", Visibility = PXUIVisibility.SelectorVisible, Required = false)]
[PXDefault(PersistingCheck = PXPersistingCheck.Nothing)]
public virtual DateTime? StartImportDate { get; set; }
#endregion
#region EndImportDate
public abstract class endImportDate : PX.Data.IBqlField { }
protected DateTime? _EndImportDate;
[PXDate()]
[PXUIField(DisplayName = "End Import Date", Visibility = PXUIVisibility.SelectorVisible)]
[PXDefault(typeof(AccessInfo.businessDate), PersistingCheck = PXPersistingCheck.Nothing)]
public virtual DateTime? EndImportDate { get; set; }
#endregion
//Excerpt from RowSelected handler
if (!filter.StartImportDate.HasValue && filter.EndImportDate.HasValue)
{
DateTime endDate = DateTime.Today;
DateTime begDate = endDate.AddMonths(-1);
filter.StartImportDate = begDate;
filter.EndImportDate = endDate;
}
if (!filter.StartShipDate.HasValue && filter.EndShipDate.HasValue)
{
DateTime endDate = DateTime.Today.AddMonths(1);
DateTime begDate = DateTime.Today.AddMonths(-1);
filter.StartShipDate = begDate;
filter.EndShipDate = endDate;
}
I then installed the latest Acuminator and it gave me a warning not to set DAC fields from within the RowSelected handler so I removed the code and attempted to set it in the FieldDefaulting handler. I can't seem to get the defaults to set correctly.
protected virtual void EDOrderReviewFilter_StartImportDate_FieldDefaulting(PXCache sender, PXFieldDefaultingEventArgs e)
{
EDOrderReviewFilter row = e.Row as EDOrderReviewFilter;
if (row != null)
{
if (!row.StartImportDate.HasValue && row.EndImportDate.HasValue)
{
e.NewValue = DateTime.Today.AddMonths(-1);
e.Cancel = true;
}
}
}
protected virtual void EDOrderReviewFilter_StartShipDate_FieldDefaulting(PXCache sender, PXFieldDefaultingEventArgs e)
{
EDOrderReviewFilter row = e.Row as EDOrderReviewFilter;
if (row != null)
{
if (!row.StartShipDate.HasValue && row.EndShipDate.HasValue)
{
e.NewValue = DateTime.Today.AddMonths(-1);
e.Cancel = true;
}
}
}
Is there a way to do a date calculation in the PXDefault attribute, or what is wrong with my defaulting handlers?
With Brendan's help, this is what I ended up with.
protected virtual void EDOrderReviewFilter_StartImportDate_FieldDefaulting(PXCache sender, PXFieldDefaultingEventArgs e)
{
e.NewValue = DateTime.Today.AddMonths(-1);
}
protected virtual void EDOrderReviewFilter_EndImportDate_FieldDefaulting(PXCache sender, PXFieldDefaultingEventArgs e)
{
e.NewValue = DateTime.Today;
}
protected virtual void EDOrderReviewFilter_StartShipDate_FieldDefaulting(PXCache sender, PXFieldDefaultingEventArgs e)
{
e.NewValue = DateTime.Today.AddMonths(-1);
}
protected virtual void EDOrderReviewFilter_EndShipDate_FieldDefaulting(PXCache sender, PXFieldDefaultingEventArgs e)
{
e.NewValue = DateTime.Today.AddMonths(1);
}
Since there are no PXDefault attributes on the columns the cancel was not required. Sometimes simpler is better!

Navigating to next page on grid does not refresh the data

I have a grid that displays rows based on the form's filters. When navigated to the next page the data remains the same. I have exported the data into excel which gets all the rows. Only the first page and last page navigation change the rows. Please help on what am I missing in the ASPX
Graph containing view delegate and DAC
public class InventorySales : PXGraph<InventorySales>
{
[Serializable]
public class Filter : IBqlTable
{
public abstract class wareHouse : IBqlField { }
[PXDefault()]
[PXUIField(DisplayName = "Warehouse")]
[PX.Objects.IN.POSiteAvail(typeof(POReceiptLine.inventoryID), typeof(POReceiptLine.subItemID))]
public virtual int? WareHouse { get; set; }
#region InventoryID
public abstract class inventoryCD : PX.Data.IBqlField
{
}
protected Int32? _InventoryCD;
[PXInt()]
[PXUIField(DisplayName = "SKU", Visibility = PXUIVisibility.SelectorVisible)]
[PXSelector(typeof(Search<
InventoryItem.inventoryID,
Where<InventoryItem.itemStatus, Equal<InventoryItemStatus.active>>>),
new Type[] { typeof(InventoryItem.inventoryID), typeof(InventoryItem.inventoryCD),
typeof(InventoryItem.itemStatus),
typeof(InventoryItem.descr)},
SubstituteKey = typeof(InventoryItem.inventoryCD),
DescriptionField = typeof(InventoryItem.descr))]
public virtual Int32? InventoryCD
{
get
{
return this._InventoryCD;
}
set
{
this._InventoryCD = value;
}
}
#endregion
#region BeginDate
public abstract class beginDate : IBqlField
{
}
protected DateTime? _BeginDate;
[PXDBDate]
[PXDefault(typeof(AccessInfo.businessDate))]
[PXUIField(DisplayName = "Start Date")]
public virtual DateTime? BeginDate
{
get
{
return _BeginDate;
}
set
{
_BeginDate = value;
}
}
#endregion
#region EndDate
public abstract class endDate : IBqlField { }
[PXDBDate]
[PXDefault(typeof(AccessInfo.businessDate))]
[PXUIField(DisplayName = "End Date")]
public virtual DateTime? EndDate { get; set; }
#endregion
#region Sales
public abstract class sales : PX.Data.IBqlField
{
}
protected Int32? _Sales;
[PXInt()]
[PXUnboundDefault("30")]
[PXUIField(DisplayName = "Sales")]
[InvSales.List]
public virtual Int32? Sales
{
get
{
return this._Sales;
}
set
{
this._Sales = value;
}
}
#endregion
}
public PXCancel<Filter> Cancel;
public PXFilter<Filter> MasterView;
public PXSelectJoin<
POReceiptLine,
InnerJoin<POReceipt,
On<POReceiptLine.receiptType, Equal<POReceipt.receiptType>,
And<POReceiptLine.receiptNbr, Equal<POReceipt.receiptNbr>>>,
InnerJoin<INSiteStatus,
On<INSiteStatus.inventoryID, Equal<POReceiptLine.inventoryID>,
And<INSiteStatus.siteID, Equal<POReceiptLine.siteID>>>>>,
Where2<
Where2<
Where<POReceiptLine.siteID, Equal<Current<Filter.wareHouse>>,
And<POReceipt.receiptType, Equal<POReceiptType.poreceipt>>>,
And<Where<POReceiptLine.inventoryID, Equal<Current<Filter.inventoryCD>>,
Or<Current<Filter.inventoryCD>, IsNull>>>>,
And<Where<POReceiptLine.receiptDate, GreaterEqual<Current<Filter.beginDate>>,
And<POReceiptLine.receiptDate, LessEqual<Current<Filter.endDate>>>>>>>
DetailsView;
public PXSelectJoin<
SOLine,
InnerJoin<SOOrder,
On<SOLine.orderType, Equal<SOOrder.orderType>,
And<SOOrder.orderNbr, Equal<SOLine.orderNbr>>>>,
Where<SOOrder.status, NotEqual<SOStatus>,
And<SOOrder.orderDate, GreaterEqual<Sub<Current<AccessInfo.businessDate>,Current<Filter.sales>>>,
And<SOOrder.orderDate, LessEqual<Current<AccessInfo.businessDate>>>>>> ss;
List<PXResult<SOLine>> list = new List<PXResult<SOLine>>();
public IEnumerable detailsView()
{
list = PXSelectJoin<
SOLine,
InnerJoin<SOOrder,
On<SOLine.orderType, Equal<SOOrder.orderType>,
And<SOOrder.orderNbr, Equal<SOLine.orderNbr>>>>,
Where<SOOrder.status, NotEqual<SOStatus>,
And<SOOrder.orderDate, GreaterEqual<Sub<Current<AccessInfo.businessDate>, Current<Filter.sales>>>,
And<SOOrder.orderDate, LessEqual<Current<AccessInfo.businessDate>>>>>>.Select(this).ToList();
Int32 startrow = PXView.StartRow;
List<POReceiptLine> poReceiptLineList = new List<POReceiptLine>();
PXView.StartRow = 0;
foreach (PXResult<POReceiptLine, POReceipt, INSiteStatus> result in PXSelectJoin<
POReceiptLine,
InnerJoin<POReceipt,
On<POReceiptLine.receiptType, Equal<POReceipt.receiptType>,
And<POReceiptLine.receiptNbr, Equal<POReceipt.receiptNbr>>>,
InnerJoin<INSiteStatus,
On<INSiteStatus.inventoryID, Equal<POReceiptLine.inventoryID>,
And<INSiteStatus.siteID, Equal<POReceiptLine.siteID>>>>>,
Where2<
Where2<
Where<POReceiptLine.siteID, Equal<Current<Filter.wareHouse>>,
And<POReceipt.receiptType, Equal<POReceiptType.poreceipt>>>,
And<Where<POReceiptLine.inventoryID, Equal<Current<Filter.inventoryCD>>,
Or<Current<Filter.inventoryCD>, IsNull>>>>,
And<Where<POReceiptLine.receiptDate, GreaterEqual<Current<Filter.beginDate>>,
And<POReceiptLine.receiptDate, LessEqual<Current<Filter.endDate>>>>>>>
.Select(this))
{
decimal? sum = 0.00M;
POReceiptLine objsalesprice = (POReceiptLine)result;
INSiteStatus objInSiteStatus = (INSiteStatus)result;
if (objsalesprice != null)
{
POReceiptLineExt obj = objsalesprice.GetExtension<POReceiptLineExt>();
foreach (PXResult<SOLine> res in list)
{
SOLine so = (SOLine)res;
if (so.InventoryID == objsalesprice.InventoryID)
sum = sum + so.CuryLineAmt;
}
obj.UsrSales = sum;
obj.UsrQtyAvail = objInSiteStatus.QtyAvail;
if (!poReceiptLineList.Any(x => x.InventoryID == objsalesprice.InventoryID))
{
poReceiptLineList.Add(objsalesprice);
}
else if (poReceiptLineList.Any(x => x.InventoryID == objsalesprice.InventoryID && x.ReceiptDate.Value.Date < objsalesprice.ReceiptDate.Value.Date))
{
var itemToRemove = poReceiptLineList.Single(r => (r.InventoryID == objsalesprice.InventoryID));
poReceiptLineList.Remove(itemToRemove);
poReceiptLineList.Add(objsalesprice);
}
else if (poReceiptLineList.Any(x => x.InventoryID == objsalesprice.InventoryID
&& x.ReceiptDate.Value.Date == objsalesprice.ReceiptDate.Value.Date && x.CreatedDateTime < objsalesprice.CreatedDateTime))
{
var itemToRemove = poReceiptLineList.Single(r => (r.InventoryID == objsalesprice.InventoryID));
poReceiptLineList.Remove(itemToRemove);
poReceiptLineList.Add(objsalesprice);
}
}
}
return poReceiptLineList;
}
}
You will have to re-work the 'detailsView' delegate method so that it uses the PXView pattern to handle paging.
Detailed instructions on using PXView with Paging in delegate can be found here: https://asiablog.acumatica.com/2016/06/using-pxview-in-dataview-delegate.html
Here's the relevant code excerpt from that page:
public PXSelect<DAC> DataView;
public IEnumerable dataView()
{
PXView select = new PXView(this, true, DataView.View.BqlSelect);
Int32 totalrow = 0;
Int32 startrow = PXView.StartRow;
List<object> result = select.Select(PXView.Currents, PXView.Parameters,
PXView.Searches, PXView.SortColumns, PXView.Descendings,
PXView.Filters, ref startrow, PXView.MaximumRows, ref totalrow);
PXView.StartRow = 0;
foreach (PXResult<DAC> row in result)
{
// Do any dynamic calculations
yield return row;
}
}
Alternatively you can remove paging on the grid by setting the AllowPaging="false" property of the Grid element if you don't need paging.

Is it possible to dynamically change the PXSelect a view is using programatically?

I have a button in which, when pressed, I want to show or hide rows in a grid based on certain criteria. Is it possible to change the PXSelect a view uses on the fly so that it re-queries the database and retrieves different results? I will, of course, be querying the same table and not changing up the structure of the View or grid.
The code below adds a non-visible field to the header record that is set by the button press this value is then used by the child records view delegate to determine based on the child records criteria (in this case a Boolean on each child) if they are shown.
public sealed class APInvoiceExtension : PXCacheExtension<APInvoice>
{
#region UsrShowAll
public abstract class usrShowAll : IBqlField
{
}
[PXBool]
public bool? UsrShowAll { get; set; }
#endregion
}
public sealed class APTranExtension : PXCacheExtension<APTran>
{
#region UsrHidden
public abstract class usrHidden : IBqlField
{
}
[PXDBBool]
[PXUIField(DisplayName = "Hidden", Enabled = false)]
public bool? UsrHidden { get; set; }
#endregion
}
public class APInvoiceEntryExtension : PXGraphExtension<APInvoiceEntry>
{
public PXAction<APInvoice> SHW;
[PXUIField(DisplayName = "Show All Records", MapEnableRights = PXCacheRights.Update, MapViewRights = PXCacheRights.Update)]
[PXButton]
protected void sHW()
{
if (Base.Document.Current != null)
{
APInvoiceExtension docExt = Base.Document.Current.GetExtension<APInvoiceExtension>();
docExt.UsrShowAll = !(docExt.UsrShowAll ?? false);
}
}
protected virtual IEnumerable transactions()
{
bool showAll = Base.Document.Current != null ? (Base.Document.Current.GetExtension<APInvoiceExtension>().UsrShowAll ?? false) : false;
APTran tran;
foreach (PXResult<APTran, POReceiptLine> res in Base.Transactions.Select())
{
tran = res[0] as APTran;
if (!showAll)
{
if (!(tran.GetExtension<APTranExtension>().UsrHidden ?? false))
{
yield return res;
}
}
else
{
yield return res;
}
}
}
}

Unbound DAC Processing Screen

I am having trouble getting the individual select check to work on my processing screen. The DAC is unbound composed of data from several tables. Process All works correctly, but I cannot check individual rows. I get an error stating "Error: The argument is out of range. Parameter name: table.
Process All results:
I have tried a variety of combinations of attributes and have had no luck. My code is below. Any help would be appreciated.
using System;
using System.Collections;
using System.Collections.Generic;
using PX.SM;
using PX.Data;
using PX.Objects.AR;
using PX.Objects.CS;
using PX.Objects.SO;
using PX.Objects.CR;
using PX.Objects.IN;
using PX.Objects.SM;
using CRLocation = PX.Objects.CR.Standalone.Location;
using PX.Data.ReferentialIntegrity.Attributes;
using LingoInterface;
using System.Text.RegularExpressions;
namespace EDIASNs
{
public class EDInventoryProcess : PXGraph<EDInventoryProcess>
{
public PXCancel<EDInventoryFilter> Cancel;
public PXFilter<EDInventoryFilter> Filter;
[PXFilterable]
public PXFilteredProcessingOrderBy<EDInventory, EDInventoryFilter,
OrderBy<Asc<EDInventory.partnerID, Asc<EDInventory.inventoryCD>>>> EDItem;
protected virtual IEnumerable eDItem()
{
int ii = 0;
foreach (var row in EDItem.Cache.Cached)
{
ii++;
yield return row;
}
Int32 rowCntr = 0;
if (ii == 0)
{
var cmd = new PXSelectJoin<InventoryItem,
InnerJoin<INItemXRef, On<InventoryItem.inventoryID, Equal<INItemXRef.inventoryID>>,
InnerJoin<EDPartnerInfo, On<INItemXRef.bAccountID, Equal<EDPartnerInfo.customerID>>>>,
Where<INItemXRef.alternateType, Equal<INAlternateType.cPN>,
And<InventoryItem.itemStatus, Equal<InventoryItemStatus.active>>>>(this);
if (this.Filter.Current.TradingPartner != null)
{
cmd.WhereAnd<Where<EDPartnerInfo.partnerID, Equal<Current<EDInventoryFilter.tradingPartner>>>>();
}
cmd.View.Clear();
var ret = cmd.Select();
if (ret != null)
{
EDInventoryFilter filt = (EDInventoryFilter)Filter.Cache.Current;
EDInventory edInv = new EDInventory();
foreach (PXResult<InventoryItem, INItemXRef, EDPartnerInfo> record in ret)
{
edInv = new EDInventory();
InventoryItem item = (InventoryItem)record;
INItemXRef xref = (INItemXRef)record;
EDPartnerInfo partner = (EDPartnerInfo)record;
edInv.InvID = Guid.NewGuid();
rowCntr++;
edInv.IntID = rowCntr;
edInv.PartnerID = partner.PartnerID;
edInv.InventoryID = item.InventoryID;
edInv.InventoryCD = item.InventoryCD;
edInv.ItemDescr = item.Descr;
edInv.ItemStatus = item.ItemStatus;
edInv.BaseUnit = item.BaseUnit;
edInv.SalesUnit = item.SalesUnit;
edInv.PurchaseUnit = item.PurchaseUnit;
edInv.BasePrice = Convert.ToDecimal(item.BasePrice);
edInv.BaseWeight = item.BaseWeight;
edInv.BaseVolume = item.BaseVolume;
edInv.BaseItemWeight = item.BaseItemWeight;
edInv.BaseItemVolume = item.BaseItemVolume;
edInv.WeightUOM = item.WeightUOM;
edInv.VolumeUOM = item.VolumeUOM;
//edInv.NoteID = item.NoteID;
edInv.PartnerCustomerID = partner.CustomerID;
edInv.CustomerItem = xref.AlternateID;
edInv.CustomerItemDescr = xref.Descr;
var cmdAttrib = new PXSelect<CSAnswers,
Where<CSAnswers.refNoteID, Equal<Required<CSAnswers.refNoteID>>>>(this);
cmdAttrib.View.Clear();
var retAttrib = cmdAttrib.Select(item.NoteID);
if (retAttrib != null)
{
foreach (PXResult<CSAnswers> recAttrib in retAttrib)
{
CSAnswers ans = (CSAnswers)recAttrib;
switch (ans.AttributeID)
{
case "CASEQTY":
edInv.CaseQty = Convert.ToInt32(ans.Value);
break;
case "CASEL":
edInv.CaseL = Convert.ToDecimal(ans.Value);
break;
case "CASEW":
edInv.CaseW = Convert.ToDecimal(ans.Value);
break;
case "CASEH":
edInv.CaseH = Convert.ToDecimal(ans.Value);
break;
case "UPC":
edInv.UPC = ans.Value;
break;
}
}
}
var cmdPrice = new PXSelect<ARSalesPrice,
Where<ARSalesPrice.priceType, Equal<PriceTypes.customer>,
And<ARSalesPrice.customerID, Equal<Required<ARSalesPrice.customerID>>,
And<ARSalesPrice.inventoryID, Equal<Required<ARSalesPrice.inventoryID>>,
And<ARSalesPrice.expirationDate, GreaterEqual<Required<ARSalesPrice.expirationDate>>>>>>>(this);
cmdPrice.View.Clear();
var retPrice = cmdPrice.Select(partner.CustomerID, item.InventoryID, this.Accessinfo.BusinessDate);
if (retPrice != null)
{
foreach (PXResult<ARSalesPrice> recPrice in retPrice)
{
ARSalesPrice price = (ARSalesPrice)recPrice;
edInv.CustomerPrice = price.SalesPrice;
}
}
int intOnHand = 0;
int intCommitted = 0;
int intOnOrder = 0;
var cmdStock = new PXSelectJoin<INSiteStatus,
InnerJoin<INSite, On<INSiteStatus.siteID, Equal<INSite.siteID>>>,
Where<INSite.active, Equal<True>,
And<INSiteStatus.inventoryID, Equal<Required<INSiteStatus.inventoryID>>>>>(this);
cmdStock.View.Clear();
var retStock = cmdStock.Select(item.InventoryID);
if (retStock != null)
{
foreach (PXResult<INSiteStatus> recStock in retStock)
{
INSiteStatus stock = (INSiteStatus)recStock;
intOnHand += Convert.ToInt32(stock.QtyOnHand);
intCommitted += Convert.ToInt32(stock.QtySOShipped + stock.QtySOShipping);
intOnOrder += Convert.ToInt32(stock.QtyPOPrepared + stock.QtyPOReceipts);
}
edInv.OnHand = intOnHand;
edInv.Committed = intCommitted;
edInv.OnOrder = intOnOrder;
}
edInv = EDItem.Insert(edInv);
EDItem.Cache.SetStatus(edInv, PXEntryStatus.Held);
yield return edInv;
}
}
EDItem.Cache.IsDirty = false;
}
}
public void EDInventoryFilter_RowUpdated(PXCache sender, PXRowUpdatedEventArgs e)
{
EDInventoryFilter filterOld = (EDInventoryFilter)e.OldRow;
EDInventoryFilter filterNew = (EDInventoryFilter)e.Row;
if (filterOld.Action == filterNew.Action) //Don't clear cache if only action changes
EDItem.Cache.Clear();
}
public void EDInventoryFilter_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
{
//Get list of partners to set filter
List<string> strPartnerList = new List<string>();
strPartnerList.Clear();
var filter = (EDInventoryFilter)e.Row;
foreach (EDPartnerInfo partner in PXSelect<EDPartnerInfo>.Select(this))
{
strPartnerList.Add(partner.PartnerID);
}
if (strPartnerList.Count > 0)
PXStringListAttribute.SetList<EDInventoryFilter.tradingPartner>
(sender, filter, strPartnerList.ToArray(), strPartnerList.ToArray());
else
{
throw new PXException("No active partners found");
}
EDItem.SetProcessDelegate
(
delegate (List<EDInventory> list)
{
var graph = PXGraph.CreateInstance<EDInventoryProcess>();
graph.InventorySync(filter, list);
}
);
//Action must be selected for Process buttons to be available
if (filter.Action == null || filter.Action == "")
{
EDItem.SetProcessVisible(false);
EDItem.SetProcessAllVisible(false);
}
}
public void EDInventory_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
{
var row = (EDInventory)e.Row;
}
public void InventorySync(EDInventoryFilter filter, List<EDInventory> list)
{
//Create Lingo API object and login
bool ediDemo = false;
bool bolAtLeastOneError = false;
Int32 cntr = 0;
EDCompanyData edCompanyData = new EDCompanyData();
foreach (EDCompanyData data in PXSelect<EDCompanyData,
Where<EDCompanyData.active, Equal<Required<EDCompanyData.active>>>>.Select(this, true))
{
cntr++;
if (data.Service == "DEMO")
ediDemo = true;
edCompanyData = data;
}
if (cntr == 0)
throw new PXException("No active Service Data entries!");
if (cntr > 1)
throw new PXException("More than one active Service Data entry!");
var lingo = new LingoApi();
//Set url for service
lingo.Url = edCompanyData.Url;
if (!ediDemo)
{
if (!lingo.Login(edCompanyData.EDIAccount, edCompanyData.EDILoginName, edCompanyData.EDIPassword, edCompanyData.EDIApiKey))
throw new PXException("Login to EDI system failed.");
}
//Initialize variables
EdiItem updateItem = new EdiItem();
bool bolNewItem = false;
Regex rxNonDigits = new Regex(#"[^\d]+");
foreach (EDInventory acItem in list)
{
//Check for existing item in EDI
if (lingo.Login() || ediDemo) //Refresh the login session
{
if (!ediDemo)
{
LingoRetItem itemRet = lingo.RetrieveItem(acItem.PartnerID, acItem.InventoryCD);
if (itemRet && itemRet.Count != 0) //Found Item
{
if (itemRet.Count > 1)
{
PXProcessing<EDInventory>.SetError(list.IndexOf(acItem), String.Format("More than 1 occurrence found: {0}", itemRet.Message));
bolAtLeastOneError = true;
}
else
{
updateItem = itemRet.DataItem; //Load existing item data and set flag
bolNewItem = false;
}
}
else
{
updateItem = new EdiItem(); //Clear item object for new item and set flag
bolNewItem = true;
}
}
updateItem.account = edCompanyData.EDIAccount;
updateItem.partner = acItem.PartnerID;
if (bolNewItem)
updateItem.createDate = DateTime.Today.ToString("yyyyMMdd");
updateItem.upcCode = rxNonDigits.Replace(acItem.UPC, ""); //Remove non-numeric characters
updateItem.upcCodeType = "UPC";
updateItem.vendorItem = acItem.InventoryCD;
updateItem.vendorItemType = "VNDR";
updateItem.customerItem = acItem.CustomerItem;
if (string.IsNullOrEmpty(acItem.CustomerItemDescr))
updateItem.itemDesc = acItem.ItemDescr;
else
updateItem.itemDesc = acItem.CustomerItemDescr;
if (acItem.BaseItemWeight > 0)
updateItem.itemWeight = acItem.BaseItemWeight.ToString();
else
updateItem.itemWeight = acItem.BaseWeight.ToString();
//Inventory Information
updateItem.qtyOnHand = acItem.OnHand.ToString();
updateItem.qtyCommitted = acItem.Committed.ToString();
updateItem.qtyOnOrder = acItem.OnOrder.ToString();
//Item Pricing Information
if (acItem.CustomerPrice > 0)
updateItem.unitPrice = acItem.CustomerPrice.ToString();
else
updateItem.unitPrice = acItem.BasePrice.ToString();
updateItem.priceBasis = acItem.SalesUnit;
//Item Packing and Carton Information
updateItem.unitMeasure = acItem.BaseUnit;
updateItem.packSize = acItem.CaseQty.ToString();
updateItem.cartonLength = acItem.CaseL.ToString();
updateItem.cartonWidth = acItem.CaseW.ToString();
updateItem.cartonHeight = acItem.CaseH.ToString();
LingoRet itemMaintResult = new LingoRet();
if (!ediDemo)
itemMaintResult = lingo.MaintainItem(updateItem, bolNewItem);
else
{
itemMaintResult.Code = "OK";
itemMaintResult.Message = "Success";
}
//Check result
if (itemMaintResult.Code == "OK" || ediDemo)
{
PXProcessing<EDInventory>.SetInfo(list.IndexOf(acItem),
String.Format(" Item {0} EDI: {1}", bolNewItem ? "added to" : "updated in",itemMaintResult.Message));
}
else
{
PXProcessing<EDInventory>.SetError(list.IndexOf(acItem), String.Format(" Item maintenance failed: {0}", itemMaintResult.Message));
bolAtLeastOneError = true;
}
}
else
{
PXProcessing<EDInventory>.SetError(list.IndexOf(acItem), String.Format(" Lingo login failed: {0}", lingo.ResMessage));
bolAtLeastOneError = true;
}
}
if (bolAtLeastOneError)
throw new PXException("At least one item had exceptions");
}
[Serializable]
public partial class EDInventoryFilter : IBqlTable
{
#region TradingPartner
public abstract class tradingPartner : PX.Data.IBqlField
{
}
protected string _TradingPartner;
[PXString(15)]
[PXUIField(DisplayName = "Trading Partner")]
[PXStringList(new string[] { }, new string[] { })]
public virtual String TradingPartner { get; set; }
#endregion
#region Action
public abstract class action : PX.Data.IBqlField { }
protected string _Action;
[PXDefault("P")]
[PXString(15)]
[PXUIField(DisplayName = "Action")]
[PXStringList(new string[] { "P" }, new string[] { "Push to EDI" })]
public virtual String Action { get; set; }
#endregion
}
[Serializable]
public partial class EDInventory : IBqlTable
{
#region Selected
public abstract class selected : IBqlField { }
protected bool? _Selected = false;
[PXBool]
[PXDefault(false)]
[PXUIField(DisplayName = "Selected")]
public virtual bool? Selected { get; set; }
#endregion
#region InvID
public abstract class invID : PX.Data.IBqlField { }
protected Guid? _InvID;
[PXGuid]
[PXUIField(DisplayName = "ID")]
public virtual Guid? InvID { get; set; }
#endregion
#region intID
public abstract class intID : PX.Data.IBqlField { }
protected int? _IntID;
[PXInt(IsKey = true)]
[PXUIField(DisplayName = "intID")]
public virtual int? IntID { get; set; }
#endregion
#region PartnerID
public abstract class partnerID : IBqlField { }
[PXDBString(30, IsUnicode = true, IsKey = true)]
[PXDefault("")]
[PXUIField(DisplayName = "Partner")]
public virtual string PartnerID { get; set; }
#endregion
#region InventoryID
public abstract class inventoryID : PX.Data.IBqlField { }
protected Int32? _InventoryID;
[PXDBInt(IsKey = true)]
[PXUIField(DisplayName = "Inventory ID", Visibility = PXUIVisibility.Visible, Visible = false)]
public virtual Int32? InventoryID { get; set; }
#endregion
#region InventoryCD
public abstract class inventoryCD : PX.Data.IBqlField { }
protected String _InventoryCD;
[PXDefault()]
[InventoryRaw(IsKey = true, DisplayName = "Inventory ID")]
public virtual String InventoryCD { get; set; }
#endregion
#region ItemDescr
public abstract class itemDescr : PX.Data.IBqlField { }
protected String _ItemDescr;
[PXDBString(255, IsUnicode = true)]
[PXUIField(DisplayName = "Item Description")]
public virtual String ItemDescr { get; set; }
#endregion
#region ItemStatus
public abstract class itemStatus : PX.Data.IBqlField { }
protected String _ItemStatus;
[PXDBString(2, IsFixed = true)]
[PXDefault("AC")]
[PXUIField(DisplayName = "Item Status", Visibility = PXUIVisibility.SelectorVisible)]
public virtual String ItemStatus { get; set; }
#endregion
#region BaseUnit
public abstract class baseUnit : PX.Data.IBqlField { }
protected String _BaseUnit;
[PXDBString]
[PXDefault("")]
[PXUIField(DisplayName = "Base Unit", Visibility = PXUIVisibility.SelectorVisible)]
public virtual String BaseUnit { get; set; }
#endregion
#region SalesUnit
public abstract class salesUnit : PX.Data.IBqlField { }
protected String _SalesUnit;
[PXDBString(6)]
[PXDefault("")]
[PXUIField(DisplayName = "Sales Unit", Visibility = PXUIVisibility.SelectorVisible)]
public virtual String SalesUnit { get; set; }
#endregion
#region PurchaseUnit
public abstract class purchaseUnit : PX.Data.IBqlField { }
protected String _PurchaseUnit;
[PXDBString(6)]
[PXDefault("")]
[PXUIField(DisplayName = "Purchase Unit", Visibility = PXUIVisibility.SelectorVisible)]
public virtual String PurchaseUnit { get; set; }
#endregion
#region BasePrice
public abstract class basePrice : PX.Data.IBqlField { }
protected Decimal? _BasePrice;
[PXPriceCost()]
[PXDefault(TypeCode.Decimal, "0.0")]
[PXUIField(DisplayName = "Default Price", Visibility = PXUIVisibility.SelectorVisible)]
public virtual Decimal? BasePrice { get; set; }
#endregion
#region BaseWeight
public abstract class baseWeight : PX.Data.IBqlField { }
protected Decimal? _BaseWeight;
[PXDBDecimal(6)]
[PXUIField(DisplayName = "Base Weight")]
[PXDefault(TypeCode.Decimal, "0.0")]
public virtual Decimal? BaseWeight { get; set; }
#endregion
#region BaseVolume
public abstract class baseVolume : PX.Data.IBqlField { }
protected Decimal? _BaseVolume;
[PXDBDecimal(6)]
[PXDefault(TypeCode.Decimal, "0.0")]
[PXUIField(DisplayName = "Base Volume")]
public virtual Decimal? BaseVolume { get; set; }
#endregion
#region BaseItemWeight
public abstract class baseItemWeight : PX.Data.IBqlField { }
protected Decimal? _BaseItemWeight;
[PXDBDecimal(6)]
[PXDefault(TypeCode.Decimal, "0.0")]
[PXUIField(DisplayName = "Weight")]
public virtual Decimal? BaseItemWeight { get; set; }
#endregion
#region BaseItemVolume
public abstract class baseItemVolume : PX.Data.IBqlField { }
protected Decimal? _BaseItemVolume;
[PXDBDecimal(6)]
[PXDefault(TypeCode.Decimal, "0.0")]
[PXUIField(DisplayName = "Volume")]
public virtual Decimal? BaseItemVolume { get; set; }
#endregion
#region WeightUOM
public abstract class weightUOM : PX.Data.IBqlField { }
protected String _WeightUOM;
[PXDBString(6)]
[PXUIField(DisplayName = "Weight UOM")]
[PXDefault("")]
public virtual String WeightUOM { get; set; }
#endregion
#region VolumeUOM
public abstract class volumeUOM : PX.Data.IBqlField { }
protected String _VolumeUOM;
[PXDBString(6)]
[PXUIField(DisplayName = "Volume UOM")]
[PXDefault("")]
public virtual String VolumeUOM { get; set; }
#endregion
/*
#region NoteID
public abstract class noteID : PX.Data.IBqlField { }
[PXGuid(IsKey = true)]
[PXDefault(PersistingCheck = PXPersistingCheck.Nothing)]
[PXNote]
public virtual Guid? NoteID { get; set; }
#endregion
*/
#region PartnerCustomerID
public abstract class partnerCustomerID : PX.Data.IBqlField { }
[PXDBInt]
[PXUIField(DisplayName = "Customer")]
[Customer(DescriptionField = typeof(Customer.acctName))]
public virtual Int32? PartnerCustomerID { get; set; }
#endregion
#region CustomerItem
public abstract class customerItem : PX.Data.IBqlField { }
protected string _CustomerItem;
[PXDBString(50)]
[PXDefault("")]
[PXUIField(DisplayName = "Customer Item")]
public virtual String CustomerItem { get; set; }
#endregion
#region CustomerItemDescr
public abstract class customerItemDescr : PX.Data.IBqlField { }
[PXDBString(60, IsUnicode = true)]
[PXDefault("")]
[PXUIField(DisplayName = "Customer Item Description")]
public virtual String CustomerItemDescr { get; set; }
#endregion
#region CaseQty
public abstract class caseQty : PX.Data.IBqlField { }
protected int? _CaseQty;
[PXDBInt]
[PXDefault(0)]
[PXUIField(DisplayName = "Case Qty")]
public virtual Int32? CaseQty { get; set; }
#endregion
#region CaseL
public abstract class caseL : PX.Data.IBqlField { }
protected decimal? _CaseL;
[PXDBDecimal(6)]
[PXDefault(TypeCode.Decimal, "0.0")]
[PXUIField(DisplayName = "Case Length")]
public virtual Decimal? CaseL { get; set; }
#endregion
#region CaseW
public abstract class caseW : PX.Data.IBqlField { }
protected decimal? _CaseW;
[PXDBDecimal(6)]
[PXDefault(TypeCode.Decimal, "0.0")]
[PXUIField(DisplayName = "Case Width")]
public virtual Decimal? CaseW { get; set; }
#endregion
#region CaseH
public abstract class caseH : PX.Data.IBqlField { }
protected decimal? _CaseH;
[PXDBDecimal(6)]
[PXDefault(TypeCode.Decimal, "0.0")]
[PXUIField(DisplayName = "Case Height")]
public virtual Decimal? CaseH { get; set; }
#endregion
#region CaseL
public abstract class customerPrice : PX.Data.IBqlField { }
protected int? _CustomerPrice;
[PXDBDecimal(6)]
[PXDefault(TypeCode.Decimal, "0.0")]
[PXUIField(DisplayName = "Customer Price")]
public virtual Decimal? CustomerPrice { get; set; }
#endregion
#region UPC
public abstract class uPC : PX.Data.IBqlField { }
protected string _UPC;
[PXDBString(20)]
[PXDefault("")]
[PXUIField(DisplayName = "UPC Code")]
public virtual String UPC { get; set; }
#endregion
#region OnHand
public abstract class onHand : PX.Data.IBqlField { }
protected int? _OnHand;
[PXDBInt]
[PXDefault(0)]
[PXUIField(DisplayName = "On Hand")]
public virtual Int32? OnHand { get; set; }
#endregion
#region Committed
public abstract class committed : PX.Data.IBqlField { }
protected int? _Committed;
[PXDBInt]
[PXDefault(0)]
[PXUIField(DisplayName = "Committed")]
public virtual Int32? Committed { get; set; }
#endregion
#region OnOrder
public abstract class onOrder : PX.Data.IBqlField { }
protected int? _OnOrder;
[PXDBInt]
[PXDefault(0)]
[PXUIField(DisplayName = "On Order")]
public virtual Int32? OnOrder { get; set; }
#endregion
}
}
}
I see you have both DB Filed attributes and Non DB Field attributes. Besides, You even have a combination of Non DB and DB key fields in one DAC. It is not recommended.
So, first of all, make sure you have all key fields marked with either DB field or Non DB field attributes, but not a mixture of both.
Second, you can put [PXVirtualDAC] attribute to your EDItem view. It will prevent it from trying to go to a database.

Resources