Created
May 12, 2021 18:21
-
-
Save BrianMRO/cb704b415cea011d2a352ab037798ad2 to your computer and use it in GitHub Desktop.
Acumatica Mobile Demo - Tags - InventoryItemMaint_Extension.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using BLOG.Common; | |
using BLOG.IN; | |
using PX.Data; | |
using PX.Objects.AR; | |
using PX.Objects.CR; | |
using System; | |
using System.Collections; | |
namespace PX.Objects.IN | |
{ | |
public class InventoryItemMaint_Extension : PXGraphExtension<InventoryItemMaint> | |
{ | |
public static bool IsActive() | |
{ | |
bool active = false; | |
// Set active condition here to enable as applicable | |
return active; | |
} | |
public PXSetup<ZZBlogSetup> BlogSetup; | |
public PXFilter<TagParamFilter> tagparamfilter; | |
#region Create Tag | |
public PXAction<InventoryItem> createTag; | |
[PXUIField(DisplayName = "Create Tag", MapEnableRights = PXCacheRights.Select, MapViewRights = PXCacheRights.Select)] | |
[PXButton] | |
protected virtual IEnumerable CreateTag(PXAdapter adapter) | |
{ | |
ZZINTagEntry graph = PXGraph.CreateInstance<ZZINTagEntry>(); | |
tagparamfilter.View.RequestRefresh(); | |
WebDialogResult dialogResult = tagparamfilter.AskExt(setTagStateFilter, true); | |
if (dialogResult == WebDialogResult.OK || (Base.IsContractBasedAPI && dialogResult == WebDialogResult.Yes)) | |
{ | |
Base.Save.Press(); | |
InventoryItem item = PXCache<InventoryItem>.CreateCopy(Base.Item.Current); | |
TagParamFilter filter = tagparamfilter.Current; | |
if (item?.InventoryID != null) | |
{ | |
ZZINTag tag = CreateTagProc(graph, filter); | |
if (tag?.TagID != null) throw new PXRedirectRequiredException(graph, "Tag Entry"); | |
} | |
} | |
return adapter.Get(); | |
} | |
#endregion | |
#region CheckTagParams | |
public PXAction<InventoryItem> checkTagParams; | |
[PXUIField(DisplayName = "OK", MapEnableRights = PXCacheRights.Select, MapViewRights = PXCacheRights.Select)] | |
[PXLookupButton] | |
public virtual IEnumerable CheckTagParams(PXAdapter adapter) | |
{ | |
return adapter.Get(); | |
} | |
#endregion | |
#region setTagStateFilter | |
private void setTagStateFilter(PXGraph aGraph, string ViewName) | |
{ | |
checkTagParams.SetEnabled( | |
tagparamfilter.Current.CustomerID != null && | |
tagparamfilter.Current.ContactID != null | |
); | |
} | |
#endregion | |
#region CreateTagProc | |
protected virtual ZZINTag CreateTagProc(ZZINTagEntry graph, TagParamFilter filter) | |
{ | |
ZZINTag tag = null; | |
if (filter?.CustomerID != null && filter?.ContactID != null) | |
{ | |
tag = graph.Document.Insert(); | |
graph.Document.Cache.SetValueExt<ZZINTag.inventoryID>(tag, Base.Item.Current.InventoryID); | |
graph.Document.Cache.SetValueExt<ZZINTag.descr>(tag, Base.Item.Current.InventoryCD); | |
graph.Document.Cache.SetValueExt<ZZINTag.customerID>(tag, filter.CustomerID); | |
graph.Document.Cache.SetValueExt<ZZINTag.contactID>(tag, filter.ContactID); | |
graph.Document.Update(tag); | |
graph.Persist(); | |
} | |
return tag; | |
} | |
#endregion | |
#region TagParamFilter | |
[PXHidden] | |
[Serializable()] | |
public partial class TagParamFilter : IBqlTable | |
{ | |
#region CustomerID | |
[PXDefault] | |
[CustomerActive( | |
typeof(Search<BAccountR.bAccountID, Where<True, Equal<True>>>), // TODO: remove fake Where after AC-101187 | |
Visibility = PXUIVisibility.SelectorVisible, | |
DescriptionField = typeof(Customer.acctName), | |
Filterable = true)] | |
public virtual Int32? CustomerID { get; set; } | |
public abstract class customerID : PX.Data.BQL.BqlInt.Field<customerID> { } | |
#endregion | |
#region ContactID | |
[PXDBInt()] | |
[PXSelector( | |
typeof(Search<Contact.contactID, | |
Where<Contact.bAccountID, Equal<Current<TagParamFilter.customerID>>, | |
And<Contact.contactType, Equal<ContactTypesAttribute.person>>>>), | |
typeof(Contact.contactID), | |
typeof(Contact.displayName), | |
SubstituteKey = typeof(Contact.displayName), | |
Filterable = true | |
)] | |
[PXDefault()] | |
[PXUIField(DisplayName = "Contact")] | |
public virtual int? ContactID { get; set; } | |
public abstract class contactID : PX.Data.BQL.BqlInt.Field<contactID> { } | |
#endregion | |
} | |
#endregion | |
#region Event Handlers | |
#endregion | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment