Wednesday, 4 March 2015

Getting Availablephysical for item based on financial Dimension site in Ax 2012

public InventQty getavailablephysicalqty(ItemId _itemId, DimensionDefault _defualtDimension)
{
    InventSum                       inventSum;
    DefaultDimensionView            defaultDimensionView;
    DimensionAttributeValueSetItem  dimensionAttributeValueSetItem;
    DimensionAttributeValueSet      dimensionAttributeValueSet;
    InventSite                      inventSite;
    InventDim                       inventDimtemp,inventDimdummy;

    select firstonly DisplayValue from defaultDimensionView
        where defaultDimensionView.DefaultDimension == _defualtDimension
        && defaultDimensionView.Name == 'CostCenterSYS';

    select DimensionAttributeValueSet from dimensionAttributeValueSetItem
        where dimensionAttributeValueSetItem.DisplayValue == defaultDimensionView.DisplayValue
    join dimensionAttributeValueSet
        where dimensionAttributeValueSet.RecId  == dimensionAttributeValueSetItem.DimensionAttributeValueSet
    join SiteId from inventSite
        where inventSite.DefaultDimension == dimensionAttributeValueSet.RecId;

    inventDimtemp.InventLocationId  = "";
    inventDimtemp.InventColorId     = "";
    inventDimtemp.InventSizeId      = "";
    inventDimtemp.inventBatchId     = "";
    inventDimtemp.InventStyleId     = "";
    inventDimtemp.inventSerialId    = "";
    inventDimtemp.InventSiteId      = inventSite.SiteId;

    inventDimdummy = InventDim::findOrCreate(inventDimtemp);
    inventDimdummy = null;
   
     select PhysicalInvent from inventSum
         exists join inventDimdummy
            where inventSum.ItemId == _itemId
               && inventSum.Closed == NoYes::No     
               && inventSum.InventDimId == inventDimdummy.inventDimId
               && inventDimdummy.InventSiteId == inventSite.SiteId;

    return inventSum.PhysicalInvent;
}

No comments:

Post a Comment

Calculate ledger balance by dimension set in X++ in AX2012/Dynamics 365 FO

There are a variety of ways users can view balances in the general ledger. Some of the most common options are: 1. Trial balance 2. Financia...