Customer Cancel Payment Transaction



Customer Cancel Payment Transaction 

Oftentimes Technical consultants receive the requirement to write some logic or feature where we can cancel the X number of payments by selecting many records at once.


class TMV_CustomerPaymentCancel
{

   

    public static void main(Args _args)
    {
        LedgerJournalTrans _ledgerJournalTrans;
        TMV_CustomerPaymentCancel objCancelPayment=new TMV_CustomerPaymentCancel();
        objCancelPayment.cancelpaymentExecution('R00007404',_ledgerJournalTrans);
    }

    public void cancelpaymentExecution(InvoiceId _invoiceid,LedgerJournalTrans _ledgerJournalTrans)
    {

        CustTrans custTransOffset;
       
        ReasonTable reasonTable;
        ReasonCode reasonCode;
        ReasonRefRecID reasonRefRecID;
     
        Args args;
 
        ;
        custTransOffset= this.findPaymentReference(_invoiceid);
        if(custTransOffset.RecId>0)
        {
            this.CancelPayment(custTransOffset, _ledgerJournalTrans);
        }

    }

    public CustTrans findPaymentReference(InvoiceId _invoiceid)
    {
        CustTrans custTrans,custTransOffset;

        custTrans = CustTrans::findFromInvoice(_invoiceid);
        select custTransOffset
            where custTransOffset.OffsetRecid==custTrans.RecId
            && custTransOffset.TransType==LedgerTransType::Payment;
        return custTransOffset;
    }

    public void CancelPayment(CustTrans custTransOffset,LedgerJournalTrans _ledgerJournalTrans)
    {
        CustVendPDCManager  custVendPDCManager;
        BankPaymCancel bankPaymCancel;
        Args    localArgs;
        if(custTransOffset.RecId)
        {
 
            infolog.clear();
            try
            {
                localArgs = new Args();

                bankPaymCancel = BankPaymCancel::newBankPaymCancel(custTransOffset);

                //  bankPaymCancel.parmReason(reasonTable.Reason);
                //   bankPaymCancel.parmReasonComment(reasonTable.Description);
                bankPaymCancel.parmTransDate(systemDateGet());
       
                localArgs.caller(bankPaymCancel);
                localArgs.record(custTransOffset);
                BankPaymCancel::serverRun(localArgs);
 
            }
            catch
            {
               


            }
           
        }
    }



    public  str getErrorStr()
    {
        SysInfologEnumerator enumerator;
        SysInfologMessageStruct msgStruct;
        Exception exception;
        str error;
        enumerator = SysInfologEnumerator::newData(infolog.cut());
        while (enumerator.moveNext())
        {
            msgStruct = new SysInfologMessageStruct(enumerator.currentMessage());
            exception = enumerator.currentException();
            error = strfmt("%1 %2", error, msgStruct.message());
        }
        return error;
    }

}

Support Faryal's Cusine


Reverse customer Posted Invoice


Reverse customer Posted Invoice 

Using below code you can reverse the posted invoice of the customer.


class DemoTransationReversal extends TransactionReversal_Cust
{
    public static DemoTransationReversal construct()
    {
        return new DemoTransationReversal();
    }

    public boolean showDialog()
    {
        return false;
    }

    public static void main(Args _args)
    {
        CustTrans custTrans;
        DemoTransationReversal demoTransationReversal;
        ReasonTable reasonTable;
        ReasonCode reasonCode;
        ReasonRefRecID reasonRefRecID;
        InvoiceId invoiceId;
        Args args;
        ;

        invoiceId = "0099";
        reasonCode = "DEMO Purpose";       
        reasonTable = ReasonTable::find(reasonCode);
        reasonRefRecID = ReasonTableRef::createReasonTableRef(
            reasonTable.Reason, reasonTable.Description);

        custTrans = CustTrans::findFromInvoice(invoiceId);
           
        if (custTrans.RecId && !custTrans.LastSettleVoucher)
        {
            args = new Args();
            args.record(custTrans);

            demoTransationReversal = DemoTransationReversal::construct();
            demoTransationReversal.parmReversalDate(systemDateGet());
            demoTransationReversal.parmReasonRefRecId(reasonRefRecID);
            demoTransationReversal.reversal(args);
           
            info(strFmt("%1 %2 %3 %4 reversed.",
                custTrans.Voucher,
                custTrans.TransDate,
                custTrans.Invoice,
                custTrans.Txt));
        }       
    }
}

Support Faryal's Cusine


SQL In Operator in D365FO


SQL In Operator in D365FO


Microsoft Introduce In Operator in X++ Syntax, but it will work with Enums only.

Following are the example how you can use this


SalesTable  salesTable;
container   con = [SalesType::Sales, SalesType::ReturnItem, SalesType::Subscription];
while select SalesId from salesTable
where salesTable.SalesType in con
{
Info(salesTable.SalesId);
}

Support Faryal's Cusine


Project Item Journal D365FO


Project Item Journal D365FO

Dynamics technical consultants often times receive the requirements to create the journal using X++ where we couldn't use data entity for any reason.

So, In this article, I am writing the sample which may help you a lot to create a project Item journal easily.





public void createProjectInventJournal(ProjectJournalContract    _projectJournal)
    {
        InventDim                            inventDim;
        InventJournalName                    InventJournalName;
        InventJournalTable                   inventJournalTable;
        InventJournalTableData               journalTableData = JournalTableData::newTable(inventJournalTable);
        InventTable                          inventTable;
        ProjTable                               projTable;
        AWCFieldServIntegrtionMainAccount     ServiceOffsetAccount=this.findServiceMainAccount(AWCFieldServiceIntegrationType::ProjectItem);
       
         ProjectJournalTransContract  journalTransContract;

        if(_projectJournal.getProjectJournalTransCount()==0)
        {
            return;
        }
       

        journalTransContract = _projectJournal.getProjectJournalTrans(0);

        select projTable
            where projTable.ProjId==journalTransContract.ProjectId;

        select inventTable
            where inventTable.itemId==journalTransContract.ItemId;

        select InventJournalName
            where InventJournalName.JournalType==InventJournalType::project
        && InventJournalName.isFSJournal==NoYes::Yes;

        inventJournalTable.JournalId = journalTableData.nextJournalId();
        inventJournalTable.JournalType=InventJournalType::project;
      
        journalTableData.initFromJournalName(InventJournalName);
     
        inventJournalTable.insert();

        InventJournalTrans          inventJournalTrans;
        InventJournalTransData      journalTransData = journalTableData.journalStatic().newJournalTransData(inventJournalTrans, journalTableData);
        journalTransData.initFromJournalTable();

        inventJournalTrans.TransDate    = today();

       

        inventJournalTrans.ProjId               =journalTransContract.ProjectId;
       inventJournalTrans.ProjCategoryId       = journalTransContract.ProjectCateId;
        inventJournalTrans.initFromProjTable(projTable);

        inventJournalTrans.initFromInventTable(inventTable);
       
        inventJournalTrans.Qty              = journalTransContract.QtyUsed;
        inventJournalTrans.PriceUnit        = journalTransContract.CostPrice;
     
        inventJournalTrans.ProjUnitID       = journalTransContract.Unit;
        inventJournalTrans.Worker           = HcmWorkerLookup::currentWorker();
        inventJournalTrans.LedgerDimension  = LedgerDefaultAccountHelper::getDefaultAccountFromMainAccountRecId(MainAccount::findByMainAccountId(ServiceOffsetAccount.MainAccountId).RecId);
        inventJournalTrans.activityNumberModified();
        inventDim.clear();
        inventDim.InventSiteId  = journalTransContract.Site;
        inventDim.InventLocationId =journalTransContract.Location;
        inventDim.wMSLocationId = journalTransContract.Warehouse;

       
        inventJournalTrans.InventDimId = inventDim::findOrCreate(inventDim).inventDimId;

        //other fields
        journalTransData.create();
    }

Support Faryal's Cusine


Currency Conversion X++ AX7, D365FO and AX-2012


Currency Conversion X++ AX7, D365FO and AX-2012


Convert currency to currency.


Static void main(Args args)
{
    CurrencyExchangeHelper currencyExchangeHelper;
    AmountMst amountMST;
    CurrencyCode toCurrency =  ‘AED’;
    CurrencyCode FromCurrency =  ‘USD’;

    AmountCur amountCur = 5000;



        currencyExchangeHelper = CurrencyExchangeHelper::newExchangeDate(Ledger::current(), systemDateGet());
        amountMST =  currencyExchangeHelper.calculateCurrencyToCurrency(toCurrency, fromCurrency,amountCur,true);

  
info(strFmt(“%1”, amountMST))


}



Convert Transaction currency to company ledger currency.
The method will convert the transaction currency into accounting currency defined in the ledger.

static void Main(Args _args)
{
    CurrencyExchangeHelper currencyExchangeHelper;
    CurrencyCode transCurrency = ‘EUR’;
    AmountCur amountCur = 5500.00;
    AmountMst amountMST;
   
    currencyExchangeHelper = CurrencyExchangeHelper::newExchangeDate(Ledger::current(), systemDateGet());
    amountMST = currencyExchangeHelper.calculateTransactionToAccounting(transCurrency, amountCur ,true);
    info(strFmt(‘%1’,amountMST));
}





Convert Company currency to transaction currency.

The method calculates the transaction currency amount from an accounting currency given.

static void  main(Args _args)
{
    CurrencyExchangeHelper currencyExchangeHelper;
    CurrencyCode transCurrency = ‘AED’;
    AmountCur amountCur;
    AmountMst amountMST = 5500.00;
   
    currencyExchangeHelper = CurrencyExchangeHelper::newExchangeDate(Ledger::primaryLedger(CompanyInfo::findDataArea("DUM").RecId), systemDateGet());
    amountCur = currencyExchangeHelper.calculateAccountingToTransaction(transCurrency, amountMST ,true);
    info(strFmt(‘%1’,amountcur));
}

Support Faryal's Cusine


Project Journal D365FO


Project-Hour Journal D365FO


By using the following code sample, You can create the Project journal easily.



  public void createProjectHourJournal(ProjectJournalContract    _projectJournal) // project hour journal
    {
        ProjJournalTableData    JournalTableData;
        ProjJournalTransData    journalTransData;
        ProjJournalTable        journalTable, journalTableUpdate;
        ProjJournalTrans        journalTrans;
        ProjTable               projTable;
        ProjInvoiceTable        projInvoiceTable;
        NumberSeq               numberSeq;
        ProjJournalCheckPost    jourPost;
        ProjQtyEmpl             qty;
        JournalNumOfLines       numOfLines;
        ProjCategory            projCategory;
        LedgerJournalName       ledgerJournalName;
        ProjectJournalTransContract     projecJournalTrans;
       // ProjLinePropertySetup       projLinePropertySetup;
        ProjJournalName         projJournalName;

        if(_projectJournal!=null)
        {

            select projJournalName
                where projJournalName.isFSJournal==NoYes::Yes;

            projecJournalTrans=_projectJournal.getProjectJournalTrans(0);
           
            ttsBegin;
            journalTableData =          JournalTableData::newTable(journalTable);


            journalTransData =            journalTableData.journalStatic().newJournalTransData(journalTrans,  journalTableData);


            //select projLinePropertySetup
            //    where projLinePropertySetup.ProjCode==TableGroupAll::All
            //    && projLinePropertySetup.ProjRelation==projTable.ProjId;

            projTable           = ProjTable::find(projecJournalTrans.ProjectId);
            // Init        JournalTable
            projCategory=ProjCategory::find(projecJournalTrans.ProjectCateId);
      
            journalTable.JournalId      = journalTableData.nextJournalId();

            journalTable.JournalType    = ProjJournalType::Hour;

            journalTable.ProjId=projecJournalTrans.ProjectId;
            journalTable.ProjQty=projecJournalTrans.QtyUsed;
            journalTable.CategoryId=projecJournalTrans.ProjectCateId;
            journalTable.ProjTransDate=systemDateGet();
            //journalTable.LinePropertyId
            journalTable.initFromProjJournalName(projJournalName);
            journalTable.insert();

          
            journalTableData.initFromJournalName(journalTableData.journalStatic().findJournalName(journalTable.JournalNameId));

            journalTrans.clear();
            journalTransData.initFromJournalTable();
    
            projInvoiceTable    = projTable.projInvoice();
           
          

            journalTrans.setTransDate();
          //  journalTrans.TransDate      = systemDateGet();
            journalTrans.ProjTransDate  = systemDateGet();
            journalTrans.ProjId         = projTable.ProjId;
            journalTrans.Qty            = projecJournalTrans.QtyUsed;
            journalTrans.CategoryId     = projCategory.CategoryId;
         //   journalTrans.LinePropertyId = projLinePropertySetup.LinePropertyId;
            journalTrans.Worker         = HcmWorkerLookup::currentWorker();
            journalTrans.ActivityNumber = projecJournalTrans.ActivityId;
            journalTrans.Txt            = _projectJournal.FreeTxt;

           
           

            if(projInvoiceTable.CurrencyId)
            {
                journalTrans.CurrencyId =            projInvoiceTable.CurrencyId;
            }

            else
            {
                journalTrans.CurrencyId =           Ledger::accountingCurrency(CompanyInfo::current());

            }


            journalTrans.DefaultDimension   = projTable.DefaultDimension;
            journalTrans.TaxGroupId         =           ProjParameters::taxGroupInvoice(projTable.ProjId);

            if  (journalTrans.Worker)
            {
                journalTrans.setHourPrices();
                journalTrans.setPeriodDate();
            }

            numberSeq =            NumberSeq::newGetVoucherFromId(journalTable.VoucherNumberSequenceTable, false);
            journalTrans.Voucher        = numberSeq.voucher();
            journalTransData.create();

            ttsCommit;
       

        }

    }

Support Faryal's Cusine


Compile AX 2012




Using below command you can compile the AX-2012

  1. copy and paste the highlighted cd C:\Program Files\Microsoft Dynamics AX\60\Server\MicrosoftDynamicsAX\bin , press enter.
  2. copy and paste the highlighted ,AXBuild.exe xppcompileall /s=06,press enter.

Support Faryal's Cusine


Virtual Fields Vs Computed Fields

  Virtual Field: A virtual field in D365FO is a field that doesn't have a direct representation in the database. It's a field that y...