public virtual void MergeAttributes(INItemClass child, IEnumerable <CSAttributeGroup> attributesTemplate, Action <INItemClass, IEnumerable <CSAttributeGroup> > baseMethod) { int?childItemClassID = child.ItemClassID; _childItemClassHasTemplateWithItems = new Lazy <bool>(() => HasTemplateWithChild(childItemClassID, false)); baseMethod(child, attributesTemplate); }
protected void INItemClass_RowSelected(PXCache cache, PXRowSelectedEventArgs e) { if (e.Row == null) { return; } INItemClass inItemClassRow = (INItemClass)e.Row; EnableDisable(cache, inItemClassRow); }
/// <summary> /// Reset the values on the 'Components' grid and loads the Component registers from the selected 'ItemClass' for the current 'InventoryItem' ('StockItem'). /// </summary> public virtual void ResetValuesFromItemClass(PXCache cache, InventoryItem inventoryItemRow, int?itemClassID) { if (PXAccess.FeatureInstalled <FeaturesSet.equipmentManagementModule>() == false) { return; } if (inventoryItemRow != null && inventoryItemRow.ItemClassID != null) { using (var ts = new PXTransactionScope()) { INItemClass inItemClassRow = PXSelect <INItemClass, Where < INItemClass.itemClassID, Equal <Required <INItemClass.itemClassID> > > > .Select(Base, itemClassID); FSxEquipmentModelTemplate fsxEquipmentModelTemplateRow = Base.ItemClass.Cache.GetExtension <FSxEquipmentModelTemplate>(inItemClassRow); FSxEquipmentModel fsxEquipmentModelRow = cache.GetExtension <FSxEquipmentModel>(inventoryItemRow); var fsModelTemplateComponentSet = PXSelect <FSModelTemplateComponent, Where < FSModelTemplateComponent.modelTemplateID, Equal <Required <FSModelTemplateComponent.modelTemplateID> >, And <FSModelTemplateComponent.active, Equal <True> > > > .Select(Base, itemClassID); fsxEquipmentModelRow.EQEnabled = fsxEquipmentModelTemplateRow.EQEnabled; fsxEquipmentModelRow.EquipmentItemClass = fsxEquipmentModelTemplateRow.EquipmentItemClass; fsxEquipmentModelRow.ModelType = fsxEquipmentModelTemplateRow.DfltModelType; foreach (FSModelComponent fsModelComponentRow in ModelComponents.Select()) { ModelComponents.Delete(fsModelComponentRow); } foreach (FSModelTemplateComponent fsModelTemplateComponentRow in fsModelTemplateComponentSet) { if (fsxEquipmentModelTemplateRow.EQEnabled == true) { FSModelComponent fsModelComponentRow = new FSModelComponent(); fsModelComponentRow.Active = fsModelTemplateComponentRow.Active; fsModelComponentRow.ComponentID = fsModelTemplateComponentRow.ComponentID; fsModelComponentRow.Descr = fsModelTemplateComponentRow.Descr; fsModelComponentRow.ClassID = fsModelTemplateComponentRow.ClassID; fsModelComponentRow.Optional = fsModelTemplateComponentRow.Optional; fsModelComponentRow.Qty = fsModelTemplateComponentRow.Qty; ModelComponents.Cache.Insert(fsModelComponentRow); } } ts.Complete(); } } }
protected virtual void _(Events.RowSelected <INItemClass> e) { if (e.Row == null) { return; } INItemClass inItemClassRow = (INItemClass)e.Row; EnableDisable(e.Cache, inItemClassRow); }
protected virtual bool IsUsedInMapping(INItemClass itemClass) { IEnumerable <KNSIKCClassificationsMapping> classificationsMapping = PXSelect <KNSIKCClassificationsMapping> .Select(Base).RowCast <KNSIKCClassificationsMapping>().Where(x => x.IsMapped == true); foreach (KNSIKCClassificationsMapping mapping in classificationsMapping) { if (itemClass.ItemClassID == mapping.ItemClassID) { return(true); } } return(false); }
public virtual void MergeAttribute(INItemClass child, CSAttributeGroup existingAttribute, CSAttributeGroup attr, Action <INItemClass, CSAttributeGroup, CSAttributeGroup> baseMethod) { if (existingAttribute == null) { ValidateInsert(Base.Mapping.Cache, _childItemClassHasTemplateWithItems, attr, true); } else { ValidateUpdate(Base.Mapping.Cache, _childItemClassHasTemplateWithItems, attr, true, existingAttribute); } baseMethod.Invoke(child, existingAttribute, attr); }
protected virtual void INItemClass_ItemType_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e) { if (e.Row == null) { return; } INItemClass itemClassRow = (INItemClass)e.Row; FSxServiceClass fsxServiceClassRow = cache.GetExtension <FSxServiceClass>(itemClassRow); if (itemClassRow.ItemType != INItemTypes.ServiceItem) { fsxServiceClassRow.RequireRoute = false; } }
protected virtual void _(Events.FieldUpdated <INItemClass, INItemClass.itemType> e) { if (e.Row == null) { return; } INItemClass itemClassRow = (INItemClass)e.Row; FSxServiceClass fsxServiceClassRow = e.Cache.GetExtension <FSxServiceClass>(itemClassRow); if (itemClassRow.ItemType != INItemTypes.ServiceItem) { fsxServiceClassRow.RequireRoute = false; } }
protected virtual void _(Events.FieldUpdated <InventoryItem, InventoryItem.itemClassID> eventArgs) { var row = eventArgs.Row; if (row != null && row.ItemClassID < 0) { INItemClass ic = ItemClass.Select(); row.ParentItemClassID = ic?.ParentItemClassID; } else if (row != null) { row.ParentItemClassID = row.ItemClassID; } if (doResetDefaultsOnItemClassChange) { eventArgs.Cache.SetDefaultExt <InventoryItem.postClassID>(row); eventArgs.Cache.SetDefaultExt <InventoryItem.priceClassID>(row); eventArgs.Cache.SetDefaultExt <InventoryItem.priceWorkgroupID>(row); eventArgs.Cache.SetDefaultExt <InventoryItem.priceManagerID>(row); eventArgs.Cache.SetDefaultExt <InventoryItem.markupPct>(row); eventArgs.Cache.SetDefaultExt <InventoryItem.minGrossProfitPct>(row); INItemClass ic = ItemClass.Select(); if (ic != null) { eventArgs.Cache.SetValue <InventoryItem.priceWorkgroupID>(row, ic.PriceWorkgroupID); eventArgs.Cache.SetValue <InventoryItem.priceManagerID>(row, ic.PriceManagerID); } eventArgs.Cache.SetDefaultExt <InventoryItem.lotSerClassID>(row); ResetConversionsSettings(eventArgs.Cache, row); eventArgs.Cache.SetDefaultExt <InventoryItem.dfltSiteID>(row); eventArgs.Cache.SetDefaultExt <InventoryItem.valMethod>(row); eventArgs.Cache.SetDefaultExt <InventoryItem.taxCategoryID>(row); eventArgs.Cache.SetDefaultExt <InventoryItem.itemType>(row); } if (row != null && row.ItemClassID != null && eventArgs.ExternalCall) { Answers.Cache.Clear(); } }
/// <summary> /// Assign the default Billing Rule set in the ItemClass. /// </summary> public virtual void SetDefaultBillingRule(PXCache cache, InventoryItem nonStockItemRow) { if (nonStockItemRow == null || nonStockItemRow.ItemClassID == null) { return; } if (nonStockItemRow.ItemType == INItemTypes.ServiceItem) { INItemClass inItemClassRow = PXSelect <INItemClass, Where < INItemClass.itemClassID, Equal <Required <InventoryItem.itemClassID> > > > .Select(Base, nonStockItemRow.ItemClassID); FSxServiceClass fsxServiceClassRow = PXCache <INItemClass> .GetExtension <FSxServiceClass>(inItemClassRow); FSxService service = cache.GetExtension <FSxService>(nonStockItemRow); service.BillingRule = fsxServiceClassRow.DfltBillingRule; } }
/// <summary> /// Enables or disables fields. /// </summary> private void EnableDisable(PXCache cache, INItemClass itemClassRow) { bool isEnabledAsModelTemplate = false; bool isStkItem = itemClassRow.StkItem == true; FSxServiceClass fsxServiceClassRow = cache.GetExtension <FSxServiceClass>(itemClassRow); PXUIFieldAttribute.SetEnabled <FSxServiceClass.dfltBillingRule>(cache, itemClassRow, itemClassRow.ItemType == INItemTypes.ServiceItem); EnableDisable_ItemType(cache, itemClassRow, fsxServiceClassRow); ModelTemplateComponentRecords.AllowSelect = false; if (PXAccess.FeatureInstalled <FeaturesSet.equipmentManagementModule>()) { FSxEquipmentModelTemplate fsxEquipmentModelTemplateRow = cache.GetExtension <FSxEquipmentModelTemplate>(itemClassRow); isEnabledAsModelTemplate = fsxEquipmentModelTemplateRow.EQEnabled == true && fsxEquipmentModelTemplateRow.EquipmentItemClass == ID.Equipment_Item_Class.MODEL_EQUIPMENT; fsxEquipmentModelTemplateRow.Mem_ShowComponent = isEnabledAsModelTemplate; PXUIFieldAttribute.SetEnabled <FSxEquipmentModelTemplate.equipmentItemClass>(cache, itemClassRow, isStkItem); PXUIFieldAttribute.SetEnabled <FSxEquipmentModelTemplate.eQEnabled>(cache, itemClassRow, isStkItem); PXUIFieldAttribute.SetEnabled <FSxEquipmentModelTemplate.dfltModelType>(cache, itemClassRow, isEnabledAsModelTemplate); PXDefaultAttribute.SetPersistingCheck <FSxEquipmentModelTemplate.dfltModelType>( cache, itemClassRow, isEnabledAsModelTemplate == true ? PXPersistingCheck.NullOrBlank : PXPersistingCheck.Nothing); ModelTemplateComponentRecords.AllowSelect = fsxEquipmentModelTemplateRow.Mem_ShowComponent == true; } ModelTemplateComponentRecords.Cache.AllowInsert = isEnabledAsModelTemplate; ModelTemplateComponentRecords.Cache.AllowUpdate = isEnabledAsModelTemplate; ModelTemplateComponentRecords.Cache.AllowDelete = isEnabledAsModelTemplate; if (isEnabledAsModelTemplate == false) { ModelTemplateComponentRecords.Cache.Clear(); } }
/// <summary> /// Enables/Disables the Item Type field depending of there is at least one service related to. /// </summary> /// <param name="cache">PXCache instance.</param> /// <param name="itemClassRow">The current INItemClass object row.</param> /// <param name="fsxServiceClassRow">The current <c>FSxServiceClass</c> object row.</param> private void EnableDisable_ItemType(PXCache cache, INItemClass itemClassRow, FSxServiceClass fsxServiceClassRow) { bool enableItemType = true; PXSetPropertyException exception = null; if (itemClassRow.ItemType == INItemTypes.ServiceItem && cache.GetStatus(itemClassRow) != PXEntryStatus.Inserted) { int rowCount = PXSelectJoin <InventoryItem, InnerJoin <INItemClass, On <INItemClass.itemClassID, Equal <InventoryItem.itemClassID> > >, Where < InventoryItem.itemClassID, Equal <Required <InventoryItem.itemClassID> >, And <InventoryItem.itemType, Equal <INItemTypes.serviceItem> > > > .SelectWindowed(cache.Graph, 0, 1, itemClassRow.ItemClassID).Count; enableItemType = rowCount == 0; } if (enableItemType == false) { exception = new PXSetPropertyException( PXMessages.LocalizeFormat(TX.Warning.CANNOT_MODIFY_FIELD, "Services", "Item Class"), PXErrorLevel.Warning); } cache.RaiseExceptionHandling <INItemClass.itemType>( itemClassRow, itemClassRow.ItemType, exception ); cache.RaiseExceptionHandling <FSxServiceClass.requireRoute>( itemClassRow, fsxServiceClassRow.RequireRoute, exception ); PXUIFieldAttribute.SetEnabled <INItemClass.itemType>(cache, itemClassRow, enableItemType); PXUIFieldAttribute.SetEnabled <FSxServiceClass.requireRoute>(cache, itemClassRow, enableItemType); }
protected virtual void INItemClass_RowPersisting(PXCache cache, PXRowPersistingEventArgs e) { if (e.Row == null) { return; } INItemClass itemClassRow = (INItemClass)e.Row; FSxServiceClass fsxServiceClassRow = cache.GetExtension <FSxServiceClass>(itemClassRow); if (string.IsNullOrEmpty(fsxServiceClassRow.DfltBillingRule)) { cache.RaiseExceptionHandling <FSxServiceClass.dfltBillingRule>(e.Row, fsxServiceClassRow.DfltBillingRule, new PXException(PX.Objects.FS.TX.Error.FIELD_EMPTY)); e.Cancel = true; } if (PXAccess.FeatureInstalled <FeaturesSet.equipmentManagementModule>()) { FSxEquipmentModelTemplate fsxEquipmentModelTemplateRow = cache.GetExtension <FSxEquipmentModelTemplate>(itemClassRow); CheckComponentsClassID(fsxEquipmentModelTemplateRow); } }
public async Task <System.Web.Http.IHttpActionResult> ProcessRequestAsync( HttpRequestMessage request, CancellationToken cancellationToken) { var ok = new OkResult(request); using (var scope = GetAdminScope()) { try { // Request custom authorization header example var secret = string.Empty; if (request.Headers.TryGetValues("CustomAuthorization", out IEnumerable <string> headerValues)) { secret = headerValues.FirstOrDefault(); } // If secret does not match we reject the notification if (secret != "secretValue") { return(new StatusCodeResult(System.Net.HttpStatusCode.Unauthorized, request)); } // Deserialize JSON into our Notification class var notification = JsonConvert.DeserializeObject <Notification>(await request.Content.ReadAsStringAsync()); // No changes to make, lets exit if (notification == null || (notification?.Inserted?.Count ?? 0) < 1 && (notification?.Deleted?.Count ?? 0) < 1) { return(ok); } // Generate updated item list (if item appears in both it is updated) notification.Updated = (from inserted in notification.Inserted join deleted in notification.Deleted on inserted.InventoryID equals deleted.InventoryID select inserted).ToList(); // Remove updated from deleted notification.Deleted = (notification.Deleted.Where(deleted => !notification.Updated.Any(updated => updated.InventoryID == deleted.InventoryID))).ToList(); // We will use this Graph to insert our new item var graph = PXGraph.CreateInstance <NonStockItemMaint>(); foreach (var item in notification.Inserted) { // Only Non-stock items if (item.Type.ToString() != "Non-Stock Item") { continue; } // We set No string itemType = "N"; string inventoryID = item.InventoryID.ToString().Trim(); string classCD = item.ItemClass.ToString().Trim(); InventoryItem newItem = graph.Item.Search <InventoryItem.inventoryCD>(inventoryID); INItemClass itemClass = null; if (!string.IsNullOrEmpty(classCD)) { try { itemClass = graph.ItemClass.Select(classCD); } catch { itemClass = null; } } // If we find the item we skip it if (newItem != null) { graph.Item.Current = newItem; // Set values graph.Item.Cache.SetValueExt(newItem, "Descr", item.Description.ToString()); graph.Item.Cache.SetValueExt(newItem, "ItemType", itemType); graph.Item.Cache.SetValueExt(newItem, "PostClassID", item.PostingClass.ToString()); graph.Item.Cache.SetValueExt(newItem, "TaxCategoryID", item.TaxCategory.ToString()); graph.Item.Cache.SetValueExt(newItem, "NonStockReceipt", Convert.ToBoolean(item.RequireReceipt)); graph.Item.Cache.SetValueExt(newItem, "NonStockShip", Convert.ToBoolean(item.RequireShipment)); graph.Item.Cache.SetValueExt(newItem, "BaseUnit", item.BaseUnit.ToString()); graph.Item.Cache.SetValueExt(newItem, "PurchaseUnit", item.PurchaseUnit.ToString()); graph.Item.Cache.SetValueExt(newItem, "SalesUnit", item.SalesUnit.ToString()); graph.Item.Cache.SetValueExt(newItem, "ItemClassID", itemClass?.ItemClassID); // Simple way for us to track automatic inserts graph.Item.Cache.SetValueExt(newItem, "NoteText", "Updated by Webhook"); } else { newItem = graph.Item.Insert(new InventoryItem() { InventoryCD = inventoryID, Descr = item.Description.ToString(), ItemType = itemType, PostClassID = item.PostingClass.ToString(), ItemClassID = itemClass?.ItemClassID, TaxCategoryID = item.TaxCategory.ToString(), NonStockReceipt = Convert.ToBoolean(item.RequireReceipt), NonStockShip = Convert.ToBoolean(item.RequireShipment), BaseUnit = item.BaseUnit.ToString(), PurchaseUnit = item.PurchaseUnit.ToString(), SalesUnit = item.SalesUnit.ToString() }); // Simple way for us to track automatic inserts graph.Item.Cache.SetValueExt(newItem, "NoteText", "Created by Webhook"); } } foreach (var item in notification.Deleted) { string id = item.InventoryID.ToString().Trim(); InventoryItem deletedItem = graph.Item.Search <InventoryItem.inventoryCD>(id); // If we dont find the item we go to next one if (deletedItem == null) { continue; } deletedItem = graph.Item.Delete(deletedItem); } graph.Actions.PressSave(); } catch (Exception ex) { var failed = new ExceptionResult(ex, false, new DefaultContentNegotiator(), request, new[] { new JsonMediaTypeFormatter() }); return(failed); } } return(ok); }