Thursday, September 3, 2015

EcoResCategory Category Lookup in Form

// EcoResCategory Lookup in Form

Enable Purch/Sales Category in Customized Table:

TableOne(Customize Table)
1)      Create New Field – Data Type (Int64) ,Extends to Purch Category/Sales Category
2)      Create New Relation for New Field
2.1) Relation Table – EcoResCategory
2.2) Create Normal Relation
        Field – TableOne.fieldName == EcoResCategory.RecId
2.3) Relation Properties Changes to
      2.3.1) RelatedTableCardinality – ZeroOne
       2.3.2) Cardinality – Zero More
       2.3.3) RelationShip Type – Association
     à Form
3)      Form à datasource à tableàField(category Field)
3.1) Add New Method  -- resolveReference
 public Common resolveReference(FormReferenceControl _formReferenceControl)
{
    return EcoResCategory::resolveCategoryHierarchyRole(
        _formReferenceControl,
        EcoResCategoryNamedHierarchyRole::(CategoryType));
}

3.2) Add New Method  -- lookupReference

public Common lookupReference(FormReferenceControl _formReferenceControl)
{

        return EcoResCategory::lookupCategoryHierarchyRole(
            _formReferenceControl,
            EcoResCategoryNamedHierarchyRole:: ::(CategoryType));
}

3.3) Add New Method  -- Modified

public void modified()
{
    <CategoryEDT>               NAmeCategory;
    ItemFreeTxt                 name;
    LedgerDimensionAccount      ledgerDimension;

    name                     = salesQuotationLine.Name;

    NAmeCategory = salesQuotationLine.fieldName;
    salesQuotationTableForm.resetSalesQuotationLine(salesQuotationLine);
    salesQuotationLine. fieldName = NAmeCategory;
    salesQuotationLine_ds.changedInventoriedStatus();
 }



Tuesday, August 18, 2015

Inventory Item Registration lines Auto in ax 2012

//Inventory Item Registration in Transfer Order lines Auto in ax 2012
//Registering an Item , success only when On hand Avail physical Qty is greater than Zero

static void San_InvTransRegistrationCode(Args _args)
{
    InventTransferTable     transferTable;
    InventTransferLine      transferLine;
    InventTransWMS_Register inventTransWMS_register;
    InventTrans             inventTrans;
    TmpInventTransWMS       tmpInventTransWMS;
    InventDim               inventDim,Dimtmp,inventDimCreate;
    int                     i;
    Name                    size,color,warehouse,wmslocation,site;

    while select transferTable
                where transferTable.InventLocationIdFrom == "<from warehouse number>"   && transferTable.InventLocationIdTo == "<To Warehouse number>"
                            && transferTable.TransferStatus == InventTransferStatus::Shipped
                            //&& transferTable.TransferId =="<Transfer Order id>"
    {
        while select transferLine where transferLine.TransferId == transferTable.TransferId
               //&&  transferLine.ItemId == "<Item number >"
        {
            Dimtmp.clear();
            Dimtmp.InventSizeId = InventDim::find(transferLine.inventDimId).InventSizeId;
            Dimtmp.InventColorId = InventDim::find(transferLine.inventDimId).InventColorId;
            Dimtmp.InventLocationId = transferTable.InventLocationIdTo;
            Dimtmp.wMSLocationId = "Default";
            Dimtmp.InventSiteId = InventDim::find(transferLine.inventDimId).InventSiteId;
            inventDimCreate = inventDim::findOrCreate(Dimtmp);

            ttsBegin;
            inventTrans = InventTrans::findTransId(transferLine.InventTransIdReceive,true);
            if(inventTrans)
            {
                inventTrans.inventDimId = inventDimCreate.InventDimId;
                inventTrans.update();
            }
            ttsCommit;

            inventDim = inventDim::find(inventTrans.inventDimId);
            inventTransWMS_register = inventTransWMS_register::newStandard(tmpInventTransWMS);
            tmpInventTransWMS.clear();
            tmpInventTransWMS.initFromInventTrans(inventTrans);
            tmpInventTransWMS.InventQty = transferLine.QtyShipped;
            tmpInventTransWMS.InventDimId = inventTrans.InventDimId;          
            tmpInventTransWMS.insert();

            inventTransWMS_register.writeTmpInventTransWMS(tmpInventTransWMS,inventTrans,inventTrans.inventDim());
            inventTransWMS_register.updateInvent(transferLine);
  i++;
        }
    }
}

Sunday, August 2, 2015

Hiding form parts in a form

Please use this Code if you want to hide a few parts(Form Parts or Info Parts) in your form

Form --> method --> Run

 PartList        partList;
 int                partListCount,cnt;
 FormRun     factBox;

        partList = new PartList(element);
        cnt = partList.partCount();

        for (partListCount = 1; partListCount <= cnt; partListCount++)
        {
            factBox = partList.getPartById(partListCount);
            switch(factBox.name())
            {
                // Header factboxes:
                case identifierStr(InventOnHandItemCostPart):
                    factBox.design().visible(false);
                    break;
            }
       }

Saturday, July 25, 2015

Enable filter option in Display method Ax 2012

/// To Enable filter option in Display method Ax 2012


public void context()
{
    int             selectedMenu;
    formrun         fr;
    Args            ag;
    Name            strtext;
    querybuilddataSource qb1;
    queryrun    qr;
    query       q;
    PopupMenu menu = new PopupMenu(element.hWnd());
    int a = menu.insertItem('Filter By Field');
    int b = menu.insertItem('Filter By Selection');
    int c = menu.insertItem('Remove Filter');
    ;

    selectedMenu = menu.draw();
    switch (selectedMenu)
    {
    case -1:
            break;
    case a:
            ag = new args('SysformSearch');
            fr = new formrun(ag);
            fr.run();
            fr.wait();
            strtext = fr.design().controlName('FindEdit').valueStr();
            if(strtext)
            {
                q   = TestDisplayLkp_ds.query();
                qb1 = q.dataSourceTable(tablenum(TestDisplayLkp));
                qb1 = qb1.addDataSource(TableNum(InventTable));
                qb1.addLink(FieldNum(TestDisplayLkp,ItemId1),FieldNum(InventTable,ItemId));
                qb1.addRange(FieldNum(InventTable,NameAlias)).value(strtext);
                TestDisplayLkp_ds.query(Q);
                TestDisplayLkp_ds.executeQuery();
            }
            break;

    case b:
            q   = TestDisplayLkp_ds.query();
            qb1 = q.dataSourceTable(tablenum(TestDisplayLkp));
            qb1 = qb1.addDataSource(TableNum(InventTable));
            qb1.addLink(FieldNum(TestDisplayLkp,ItemId1),FieldNum(InventTable,ItemId));
            qb1.addRange(FieldNum(InventTable,NameAlias)).value(strtext);
            TestDisplayLkp_ds.query(Q);
            TestDisplayLkp_ds.executeQuery();
            break;
    case c :
            q   = new Query();
            qb1 = q.addDataSource(tablenum(TestDisplayLkp));
            qb1.clearLinks();
            qb1.clearRanges();
            TestDisplayLkp_ds.query(Q);
            TestDisplayLkp_ds.removeFilter();
            break;

    Default:
            break;
    }

}

Monday, July 20, 2015

Retail AX

Retail Blogs:

http://axretail.blogspot.ae/

http://ax-retail.com/ 

Entity Relationship Diagram in Ax 2012 ( New Creation and Existing ER)

ER Diagram for System Default Table in Ax 2012 for all Modules

https://www.microsoft.com/dynamics/ax/erd/ax2012r2/

And We can also create new ER diagram for our Customize Table (New Functionality) also by using Below Link tutorial

https://www.visual-paradigm.com/tutorials/reverse-ddl.jsp
.bak
.sql

.sql and .bak file to Reverse ddl to make ER in SQL server 2012

Wednesday, July 15, 2015

Inventory Marking Functionality x++ Batch in Ax 2012

// Inventory Marking Functionality in X++ for All Transaction:

 Create New Batch Class , Extends RunBaseBatch

public void InventAutoMarkingRec()
{
    //InventTransOrigin InventTransOrigin,InventTransOriginL;
    InventTrans InventTrans,InventTransL;
    InventTransOriginId receiptInventTransOriginId;
    CostAmountValue CostAmountValue1,CostAmountValue2;

   while select forupdate InventTransOrigin
                    where InventTransOrigin.ReferenceId == ‘Reference Id’
            join InventTrans where InventTransOrigin.RecId == InventTrans.InventTransOrigin
                     && InventTransOrigin.ReferenceCategory == inventtranstype::InventTransaction
                            && InventTrans.StatusReceipt ==StatusReceipt::Purchased
                                //&& (InventTransOrigin.itemid == '9696'||InventTransOrigin.itemid == '9697')
    {
        //qtyToMark = InventTrans.Qty;
       // inventDim        = InventTrans.inventDim();
      while  select forupdate InventTransOriginL
                                where InventTransOriginL.ReferenceId == ‘Reference Id’

                    join InventTransL where InventTransOriginL.RecId == InventTransL.InventTransOrigin
                                && InventTransOriginL.ReferenceCategory == inventtranstype::InventTransaction
                                    && InventTransL.StatusIssue == StatusIssue::Sold
                                        && InventTransL.Qty * -1 == InventTrans.Qty
                                            // && InventTransOrigin.itemid ==InventTransOriginL.itemid
                                            //&& InventTrans.CostAmountPosted == InventTransL.CostAmountPosted *-1
                                            //&& InventTransOrigin.itemid =='1004'
            {
                CostAmountValue1=  InventTrans.CostAmountPosted;
                CostAmountValue2=  InventTransL.CostAmountPosted * -1;
                if(CostAmountValue1 == CostAmountValue2)
                {

                    this.AdremTek_San_InvMarkAuto(InventTransOriginL.InventTransId,InventTransOrigin.InventTransId,InventTrans.Qty);
                    info(strFmt("%1 -Lot Id %2 - Ref Lot %3",InventTransOrigin.ItemId,InventTransOriginL.InventTransId,InventTransOrigin.InventTransId));
                }
            }
     }
}


void Adt_San_InvMarkAuto(InventTransId _issueInventTransId,InventTransId _receiveInventTransId,InventQty _qty)
{
    InventTrans issueInventTrans;
    TmpInventTransMark tmpInventTransMask;
    Map mapMarkNow;
    container con;
    real qty;
    Map mapTmp;
    MapEnumerator mapEnumerator;

    //for Issue Lot Id
    InventTransOriginId issueInventTransOriginId =
        InventTransOrigin::findByInventTransId(_issueInventTransId).RecId;
    //For ReceiptL  Lot Id
    InventTransOriginId receiptInventTransOriginId =
        InventTransOrigin::findByInventTransId(_receiveInventTransId).RecId;
    InventQty qtyToMark = _qty; // Qty Need to Mark

    ttsBegin;

    issueInventTrans = InventTrans::findByInventTransOrigin(issueInventTransOriginId);

    [con, qty] = TmpInventTransMark::packTmpMark(InventTransOrigin::find(issueInventTransOriginId),issueInventTrans.inventDim(),issueInventTrans.Qty);

    mapTmp = Map::create(con);
    mapEnumerator = mapTmp.getEnumerator();
    while (mapEnumerator.moveNext())
    {
        tmpInventTransMask = mapEnumerator.currentValue();

        if (tmpInventTransMask.InventTransOrigin == receiptInventTransOriginId)
        {
            tmpInventTransMask.QtyMarkNow = qtyToMark;
            tmpInventTransMask.QtyRemain -= tmpInventTransMask.QtyMarkNow;
            mapMarkNow = new Map(Types::Int64, Types::Record);
            mapMarkNow.insert(tmpInventTransMask.RecId, tmpInventTransMask);

            TmpInventTransMark::updateTmpMark(
                issueInventTransOriginId,
                issueInventTrans.inventDim(),
                -qtyToMark,
                mapMarkNow.pack());

            break;
        }
    }

    ttsCommit;
}


Sunday, June 14, 2015

Cancel SO , Return order as Open Order and Picked and delivered in X++

//Cancel SO
-->Open Order in X++

private void toCancelSo()
{
    //info(strFmt("%1 -- %2 ",transDate,salesOrder));
    Query                   query;
    QueryBuildDataSource    qbds;
    QueryBuildRange         qbrSalesId,qbrDate;
    QueryRun                qr;
    InventTrans             inventTrans;
    InventMovement          inventMovement;
    InventTransWMS_Pick     inventTranspick;
    TmpInventTransWMS       TmpInventTransWMS;
    ;
    query = new query();
    qbds= query.addDataSource(tableNum(SalesTable));
    qbds.addRange(fieldNum(SalesTable,SalesType)).value("Sales Order");
    if (transDate != dateNull())
    {
        qbds.addRange(fieldNum(SalesTable,ShippingDateRequested)).value(SysQuery::range(dateNull(),transDate));
    }
    //qbds.addRange(fieldNum(SalesTable,CustAccount)).value("R0003");
    if (salesOrder != "")
    {
        qbrSalesId = qbds.addRange(fieldNum(SalesTable,SalesId));
        qbrSalesId.value(salesOrder);
    }
    qr = new QueryRun(query);
    while(qr.next())
    {
        salesTable = qr.get(tableNum(SalesTable));

        ttsBegin;
        while select forupdate salesLine
                where salesLine.SalesId == salesTable.SalesId
                    && salesLine.SalesStatus == SalesStatus::Backorder
        {
            inventTrans = InventTrans::findTransId(salesLine.InventTransId);
            if (!inventTrans)
            {
                salesLine.RemainInventPhysical = 0;
                salesLine.RemainSalesPhysical  = 0;
                salesLine.update();
            }
            else if(inventTrans.StatusIssue == StatusIssue::OnOrder
                    || inventTrans.StatusIssue == StatusIssue::ReservOrdered
                    || inventTrans.StatusIssue == StatusIssue::ReservPhysical
                    || inventTrans.StatusIssue == StatusIssue::None)
            {
                    salesLine.RemainInventPhysical = 0;
                    salesLine.RemainSalesPhysical  = 0;
                    salesLine.update();
            }

        }
        ttsCommit;
    }
}

/*

Identifying the Status of a Line

if(salesLine.remainSalesFinancial != 0)
{
    // I am delivered
}

or

if(invnetTrans.statusIssue == StatusIssue::Deducted)
{
    // I am delivered
}

if(inventTrans.statusIssue == StatusIssue::Picked)
{
    // I am Picked
}

cancel Status as deleivered

ttsbegin;
salesLine = SalesLine::find(_salesID, _lineNum, true);
 
salesLine.SalesDeliverNow   = -1;
salesLine.setInventDeliverNow();
salesLine.doUpdate();
salesFormLetter = SalesFormLetter::construct(DocumentStatus::PackingSlip);
salesFormLetter.progressHide();                                
 
salesFormLetter.update(salesTable,                           
                       SystemDateGet(),                      
                       SalesUpdate::DeliverNow,              
                       AccountOrder::None,                 
                       false,                             
                       false);                            
ttsCommit;


cancel Status as Picked 

ttsBegin;
salesLine       = salesLine::find(_salesID, _lineNum, true);
inventMovement  = InventMovement::construct(salesLine);
inventTranspick = new InventTransWMS_Pick(inventMovement,tmpInventTransWMS);
 
TmpInventTransWMS.clear();
TmpInventTransWMS.initFromInventTrans(inventTrans::findTransId(salesLine.InventTransId));
TmpInventTransWMS.LineNum     = _LineNum;
TmpInventTransWMS.InventDimId = InventTrans::findTransId(salesLine.InventTransId).InventDimId;
TmpInventTransWMS.InventQty   = ( ABS( InventTrans::findTransId(salesLine.InventTransId).Qty ) * -1 );
TmpInventTransWMS.insert();
 
if( TmpInventTransWMS.InventQty != 0 )
{
    if( inventTranspick.validateTmp(TmpInventTransWMS) )
    {
        InventTransWMS_Pick::updateInvent(inventTranspick,TmpInventTransWMS);
    }
}
 
//cancel order
salesLine.RemainSalesPhysical = 0;
salesLine.remainInventPhysical = 0;
salesLine.update();
ttsCommit;

Cancel a Return Order in AX


    SalesLine       returnLine;
    SalesTable      returnTableUpdate;
    Counter         numberOfRecords;
    SalesTable      salesTable;
    PurchTable      purchTable;
    PurchLine       purchLine;
    ;
 
    ttsbegin;
 
        if (_returnTable.ReturnStatus == ReturnStatusHeader::Created &amp;&amp; !_returnTable.existRegisteredReceivedInvoicedLines() &amp;&amp; !_returnTable.type().interCompanyIsDerivedOrder())
        {
            while select forupdate returnLine
                  where returnLine.SalesId == _returnTable.SalesId
                  &amp;&amp;    returnLine.InventTransId
            {
                if (returnLine.interCompanySalesLineExist())
                {
                    purchLine            = PurchLine::findInventTransId(returnLine.InventRefTransId,true);
                    purchTable           = PurchTable::find(purchLine.PurchId);
 
                    purchLine.SkipUpdate = InterCompanySkipUpdate::Internal;
                    purchLine.delete(false);
 
                    if (!purchTable.existPurchLine())
                    {
                        if (purchTable.InterCompanyCompanyId
                        &amp;&amp;  purchTable.InterCompanySalesId)
                        {
                            changecompany(purchTable.InterCompanyCompanyId)
                            {
                                salesTable = null;
                                salesTable = SalesTable::find(purchTable.InterCompanySalesId,true);
                                if (salesTable)
                                    salesTable.delete();
                            }
                        }
                    }
                }
 
                returnLine.SalesQty     = 0;
                returnLine.salesQtyModified();
                returnLine.DeliveryType = TradeLineDlvType::None;
                returnLine.SkipUpdate   = InterCompanySkipUpdate::Internal;
                returnLine.update();
            }
 
            returnLine.skipDataMethods(true);
            update_recordset returnLine
            setting     ReturnStatus         = ReturnStatusLine::Canceled,
                        CostPrice            = 0,
                        InventTransIdReturn  = '',
                        SalesStatus          = SalesStatus::Canceled,
                        ReturnClosedDate     = systemdateget()
            where returnLine.SalesId == _returnTable.SalesId;
 
            returnTableUpdate = SalesTable::find(_returnTable.SalesId, true);
            returnTableUpdate.ReturnStatus               = ReturnStatusHeader::Canceled;
            returnTableUpdate.SalesStatus                = SalesStatus::Canceled;
            returnTableUpdate.InterCompanyDirectDelivery = false;
            returnTableUpdate.update();
        }
 
    ttscommit;

*/

Copy Markup charges while posting purchase invoice using X++

 Copy Markup charges while posting purchase invoice using X++ Class: Important: Code logic is just for Reference.  New class => Duplicate...