Monday, 31 January 2022

tax journal creation through code d365fo

 public void createTaxJournal(AirSalesTable _airSales, AirAmountTable _airAmount, LedgerJournalTable ljt,Amount  salesAmount,RefRecId leddim,

        Voucher _voucher,DebitCredit _debitCredit ,TaxEngineTaxJournalAccountType accountType ,SAC_IN _sacCode ,Amount _gstBaseAmount,NoYes   _gstApplicable,RefRecId _offsetLedgerDim )

    {

        TaxEngineTaxJournal             taxEngineTaxJournal;

        TaxEngineTaxJournalLine         taxEngineTaxJournalLine;

        TaxEngineTaxJournalLineTaxExtensionIN   taxEngineTaxJournalLineTaxExtensionIN;

        LedgerJournalName               ledgerJournalName;

        TradeGLSetupParameters      tradeGLParameters;

        TaxInformation_IN               taxInformation_IN;

        TaxRuntimeDocComponent          taxRuntimeDocComponent;

        TransTaxInformation             transTaxInformation;

        TaxComponentTable_IN            taxComponentTable_IN;

        TaxRuntimePostingType           taxRuntimePostingType;          

        TaxRuntimeDocTaxType            taxRuntimeDocTaxType;

        

        TaxEngineTaxJournalConstructor  taxEngineTaxJournalConstructor;


        select firstonly SalesTaxJournal,SAC from tradeGLParameters ;


        _sacCode = tradeGLParameters.SAC;


        select ledgerJournalName where ledgerJournalName.JournalName == tradeGLParameters.SalesTaxJournal

                && ledgerJournalName.DataAreaId == _airSales.CompanyCode;

        

        taxEngineTaxJournal.clear();

        taxEngineTaxJournalLine.clear();

        taxEngineTaxJournal.initValue();

        taxEngineTaxJournal.defaultRow();

        //taxEngineTaxJournal.JournalNum =  JournalTableData::newTable(taxEngineTaxJournal).nextJournalId();

        taxEngineTaxJournal.JournalNum              = TaxEngineTaxJournalUtil::getTaxJournalNum();

        taxEngineTaxJournal.insert();

            //NumberSeq::newGetNum(LedgerParameters::numRefJournalNum()).parmRefTableNum(; 

        taxEngineTaxJournalLine.TaxEngineTaxJournal = taxEngineTaxJournal.RecId;

        

        taxEngineTaxJournalLine.Purpose             =  TaxDocumentPurpose::Transaction;

        

                

        taxEngineTaxJournalLine.TransDate           = _airSales.ProcessedDate;

        taxEngineTaxJournalLine.Description         = _airSales.BookingNo;

        taxEngineTaxJournalLine.CurrencyCode        = _airSales.CurrencyCode;

        taxEngineTaxJournalLine.Triangulation       = Currency::triangulation(taxEngineTaxJournalLine.CurrencyCode);

        taxEngineTaxJournalLine.ExchRate            = ExchangeRateHelper::exchRate(taxEngineTaxJournalLine.CurrencyCode, taxEngineTaxJournalLine.TransDate, Currency::noYes2UnknownNoYes(taxEngineTaxJournalLine.Triangulation));


        taxEngineTaxJournalLine.AccountType         =  TaxEngineTaxJournalAccountType::Tax;

        

        taxEngineTaxJournalLine.LedgerDimension     =  leddim;

        


        if(_airAmount.TotalCgst != 0)

        {

            select RecId from taxRuntimeDocComponent where taxRuntimeDocComponent.Name == "CGST";

        }

        else if(_airAmount.Totaligst != 0)

        {

            select RecId from taxRuntimeDocComponent where taxRuntimeDocComponent.Name == "IGST" ;

        }

        if(_airAmount.TotalSgst != 0)

        {

            select RecId from taxRuntimeDocComponent where taxRuntimeDocComponent.Name == "SGST" ;

        }

        

        taxEngineTaxJournalLine.TaxComponent        = taxRuntimeDocComponent.RecId;

         


        select firstonly RecId from taxRuntimePostingType where taxRuntimePostingType.Name == "Tax Payable";

        

        taxEngineTaxJournalLine.TaxPostingType      = taxRuntimePostingType.RecId;

        taxEngineTaxJournalLine.OffsetAccountType   =  TaxEngineTaxJournalAccountType::Ledger;

        taxEngineTaxJournalLine.OffsetLedgerDimension = _offsetLedgerDim;

        //taxEngineTaxJournalLine.TaxMeasure = 

        //TaxEngineTaxJournalUtil::("GST", TaxEngineTaxJournalLine.OffsetTaxComponent);

        //taxEngineTaxJournalLine.    = _airSales.CompanyCode;

        //ledgerJournalTrans.ExchRate = exchRate;

        

         

        //taxEngineTaxJournalLine.LineNum++;

        //ledgerJournalTrans.Voucher = Numberseq::newGetVoucherFromCode(NumberSequenceTable::find(ledgerJournalTable.ledgerJournalName().NumberSequenceTable).NumberSequence).voucher();//bookingTable.MODocNum;

        

        //taxEngineTaxJournalLine.Voucher          = _voucher;

        

        //ledgerJournalTrans.DocumentDate = DateTimeUtil::getSystemDate(DateTimeUtil::getUserPreferredTimeZone());

        if(_debitCredit == DebitCredit::Credit)

        {

            taxEngineTaxJournalLine.AmountCurCredit = salesAmount;

        }

        else

        {

            taxEngineTaxJournalLine.AmountCurDebit = salesAmount;

        }

        

        

        taxEngineTaxJournalLine.insert();

        


        taxEngineTaxJournalConstructor = TaxEngineTaxJournalConstructor::construct(taxEngineTaxJournalLine.TaxEngineTaxJournal().JournalType);

        //taxEngineTaxJournalConstructor.(taxEngineTaxJournalLine);

        taxEngineTaxJournalLine.update();


        //taxEngineTaxJournalLineTaxExtensionIN = taxEngineTaxJournalLine.TaxEngineTaxJournal();

                        

        

        taxEngineTaxJournalLineTaxExtensionIN.TaxEngineTaxJournalLine = taxEngineTaxJournalLine.RecId;

        

        

        taxEngineTaxJournalLineTaxExtensionIN.insert();


        transTaxInformation = TransTaxInformationHelper::findOrCreateTransTaxInformationByRecord(taxEngineTaxJournalLine,true);

        transTaxInformation.ServiceAccountingCodeTable = ServiceAccountingCodeTable_IN::findByServiceAccountingCode(_sacCode);

        transTaxInformation.update();


        //TaxEngineTaxJournalUtil::postTaxJournal(taxEngineTaxJournal);


    }

Thursday, 2 September 2021

Department lookup

 Department lookup


public void lookup()
{
    Query                   query  = new Query();
    QueryBuildDataSource    qbds;
    SysTableLookup          sysTableLookup;
    sysTableLookup = sysTableLookup::newParameters(tableNum(OMOperatingUnit),this);
    sysTableLookup.addLookupfield(fieldNum(OMOperatingUnit,OMOperatingUnitNumber));
    sysTableLookup.addLookupfield(fieldNum(OMOperatingUnit,Name));
    sysTableLookup.addLookupfield(fieldNum(OMOperatingUnit,OMOperatingUnitType));
    sysTableLookup.addSelectionField(fieldNum(OMOperatingUnit,Name));
    qbds = query.addDataSource(tableNum(OMOperatingUnit));
    qbds.addSortField(fieldNum(OMOperatingUnit,OMOperatingUnitNumber));
    qbds.addRange(fieldNum(OMOperatingUnit,OMOperatingUnitType)).value(enum2str(OMOperatingUnitType::OMDepartment));
    sysTableLookup.parmQuery(query);
    sysTableLookup.performFormLookup();
}

Wednesday, 26 May 2021

Delete model from D365 FO

 Delete model from D365 FO 

CMD - Run as admin


Change path respectivly - K:\AosService\PackagesLocalDirectory\bin

ModelUtil.exe -delete -metadatastorepath="K:\AOSService\PackagesLocalDirectory" -modelname="xxxx"

Wednesday, 7 April 2021

create default dimensions ax 2012

 create default dimensions


private RefRecId createPurchDefaultDimensions(OMOperatingUnitNumber _dept, DimensionValue _vehicleDim)

{

    DimensionAttributeValueSetStorage       dimStorage;

    RefRecId                                defaultDimensionLoc;

    

    Counter                                 i;

    DimensionAttribute                      dimensionAttribute;

    DimensionAttributeValue                 dimensionAttributeValue;

    DimensionAttributeValueSetItem          dimensionAttributeValueSetItem;

    DimensionAttributeValueSetStorage       valueSetStorage = new DimensionAttributeValueSetStorage();

    DimensionDefault                        defaultDim;

    container                               conAttribute, conAttributeValue;

    DimensionValue                          deptLoc,vehicleDim;

    

    deptLoc = _dept;    

    vehicleDim = _vehicleDim;


    conAttribute        = conNull();

    conAttributeValue   = conNull();


    conAttribute        = conIns(conAttribute,1,'Department');

    conAttributeValue   = conIns(conAttributeValue, 1, deptLoc);

    conAttribute        = conIns(conAttribute,2,'Vehicles');

    conAttributeValue   = conIns(conAttributeValue, 2, vehicleDim);

    

    for (i = 1; i <= conLen(conAttribute); i++)

    {

        dimensionAttribute = dimensionAttribute::findByName(conPeek(conAttribute,i));

        if (dimensionAttribute.RecId == 0)

        {

            continue;

        }

        if (conPeek(conAttributeValue,i) != "")

        {

            dimensionAttributeValue =  dimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute,conPeek(conAttributeValue,i),false,true);

            valueSetStorage.addItem(dimensionAttributeValue);

        }


        defaultDimensionLoc = valueSetStorage.save();

    }

    return defaultDimensionLoc;

}

Wednesday, 11 November 2020

split default dimensions in ax 2012

 

split default dimensions in ax 2012


static void splitDimAndExport(Args _args)

{

    DimensionAttributeValueSetStorage   dimStorage;

    DimensionValue                    bu,costCenter,cust,custbu,custsow,dept,fa,fda,ir,inv,proj,purpose,rda,vend,worker;

    Counter                             i;

    ProjTable                           projTable;

     

    

    // DimensionDefault is a RecId that combines all Dimension Values

    while select projTable where projTable.ProjId == '201P000134-01'

    {

        dimStorage = DimensionAttributeValueSetStorage::find(projTable.DefaultDimension);  

 

   

        for (i= 1 ; i<= dimStorage.elements() ; i++)

        {

            

            // Change the string "CostCenter" to whatever financial dimension you want

            if(DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name == "BusinessUnit")

            {

                bu = '';

                bu = dimStorage.getDisplayValueByIndex(i);

            }

            if(DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name == "CostCenter")

            {

                costCenter = '';

                costCenter = dimStorage.getDisplayValueByIndex(i);

            }

            if(DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name == "Customer")

            {

                cust = '';

                cust = dimStorage.getDisplayValueByIndex(i);

            }

            if(DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name == "Customer_BU")

            {

                custbu = '';

                custbu = dimStorage.getDisplayValueByIndex(i);

            }

            if(DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name == "Customer_SOW")

            {

                custsow = '';

                custsow = dimStorage.getDisplayValueByIndex(i);

            }

            if(DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name == "Department")

            {

                dept = '';

            

                dept = dimStorage.getDisplayValueByIndex(i);

            }

            if(DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name == "FixedAsset")

            {

                fa = '';

            

                fa = dimStorage.getDisplayValueByIndex(i);

            }

            if(DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name == "FixedDepositAccount")

            {

                fda = '';

                fda = dimStorage.getDisplayValueByIndex(i);

            }

            if(DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name == "InterestReceivable")

            {

                ir = '';

            

                ir = dimStorage.getDisplayValueByIndex(i);

            }

            if(DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name == "Investors")

            {

                inv = '';

            

                inv = dimStorage.getDisplayValueByIndex(i);

            }

            if(DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name == "Project")

            {

                proj = '';

            

                proj = dimStorage.getDisplayValueByIndex(i);

            }

            if(DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name == "Purpose")

            {

                purpose = '';

            

                purpose = dimStorage.getDisplayValueByIndex(i);

            }

            if(DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name == "RecurringDepositaccount")

            {

                rda = '';

            

                rda = dimStorage.getDisplayValueByIndex(i);

            }

            if(DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name == "Vendor")

            {

                vend = '';

            

                vend = dimStorage.getDisplayValueByIndex(i);

            }

            if(DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name == "Worker")

            {

                worker = '';

                worker = dimStorage.getDisplayValueByIndex(i);

            }

            

        }

        info(strFmt("%1 , %2 , %3 , %4 , %5 , %6 , %7 , %8 , %9 , %10 , %11 , %12, %13, %14 , %15 ",bu,costCenter,cust,custbu,custsow,dept,fa,fda,ir,inv,proj,purpose,rda,vend,worker));

    }


}

Monday, 9 November 2020

get User roles using x++


User roles

static void userRoles(Args _args)

{

     UserInfo            userInfo;

    SecurityUserRole    securityUserRole;

    SecurityRole        securityRole;

    str                 st;

       

    ;

        st = ',';

    while

    select userInfo

        join    securityUserRole

        where   securityUserRole.User == userInfo.Id

    {               

          

       

        securityRole = null;

        select securityRole

        where  securityRole.RecId == securityUserRole.SecurityRole;

       

        if (securityRole)

        {

            //info(securityRole.AotName);

            //info(securityRole.Name);   

            info(strFmt("%1 , %2 , %3",userInfo.Id,securityRole.Name,securityRole.Description)); //info(securityRole.Description);                      

        }  

    }


Wednesday, 14 October 2020

Customize class in D365 FO

 Customize class in D365 FO

1. create a extension of the standard class

2. use the expresions show 


[ExtensionOf(classStr(BusinessLogic1))] final class BusinessLogic1_Extension { str doSomething(int arg) { // Part 1 var s = next doSomething(arg + 4); // Part 2 return s; } }