adsenseheader

Monday, November 18, 2019

Create Ledger dimension only with MainAccount in AX 365 for operations

HI,

The below code shall help you to create a Ledger Dimension through MainAccountNum in 365 for operations.


LedgerDimensionFacade::serviceCreateLedgerDimension(
            LedgerDefaultAccountHelper::getDefaultAccountFromMainAccountRecId(
                MainAccount::findByMainAccountId(_mainAccountId).RecId),
            0);

Regards,
Pradeep

Monday, November 4, 2019

Additional voucher creation for an Procurement item, Correct and Cancel Product receipt for Purchase Order in D365 for opeartions

Hi Guys,

Below code shall help in  creating additional Vouchers for a Procurement item and also correcting and canceling the Product receipt.

Distributes amount based on the Accounting distribution setup on the Purchase order line


[ExtensionOf(classStr(PurchPackingSlipJournalPost))]
final class ABC_PurchPackingSlipJournalPost_Extension
{
    protected void postSingleLine(boolean _countryRegion_RU,
                                  boolean _hasQualityOrder,
                                  boolean _isExciseEnableIN,
                                  boolean _isVATEnableIN,
                                  boolean _isCustomsEnableIN,
                                  boolean _isConfigurationkeyRetailEnabled)
    {
        LedgerDimensionAccount          ledgerDimensionId;
        AccountingDistribution          accountingDistribution;
        LedgerDimensionDefaultAccount   ledgerDefaultAccount;
        LedgerDimensionDefaultAccount   ledgerDefaultAccountOffset;
        DimensionDefault                defaultDim;
        Amount                          gstAmount;
        Amount                          creditAmount;
        Amount                          debitAmount;
        LedgerVoucher                   ledgerVoucher;
        LedgerVoucherTransObject        ledgerVoucherTransObject;
        CurrencyCode                    standardCurrencyCode;
        LedgerVoucherObject             ledgerVoucherObject;
        CurrencyExchangeHelper          currencyExchHelper;

        xyz_POItemFeeTable              POItemFeeTable;
        PurchLine                       purchLineLocal = this.sourceLine();

        next postSingleline (_countryRegion_RU,     _hasQualityOrder, _isExciseEnableIN, _isVATEnableIN, _isCustomsEnableIN,  _isConfigurationkeyRetailEnabled);

        PurchParmLine                   purchParmLine = this.purchParmLine;
        PurchParmLine                   purchParmLineloc = this.purchParmLine;
        SourceDocumentLine              sourceDocumentLine;
        Qty                             res = purchParmLineloc.purchQtyCorrection();
        AccountingDistribution          accDist;
        AccountingDistribution          revAccDist;
        SourceDocumentLine              sourceDocLine;
        PurchTable                      purchTable = PurchTable::find(purchline.PurchId);
        AllocationFactor                allocationFactor;

        while select forupdate RecId from sourceDocLine
                where
                    sourceDocLine.SourceDocumentHeader == purchTable.SourceDocumentHeader
            join forupdate accDist
                where
                    accDist.SourceDocumentLine == sourceDocLine.RecId &&
                    accDist.ReferenceRole != AccountingDistributionReferenceRole::Reversing
            notexists join revAccDist
                where
                    (   revAccDist.ReferenceDistribution == accDist.RecId &&
                        revAccDist.SourceDocumentLine == sourceDocLine.RecId &&
                        revAccDist.ReferenceRole == AccountingDistributionReferenceRole::Reversing
                    )
                    ||
                    (
                        revAccDist.ReferenceDistribution == accDist.RecId &&
                        revAccDist.SourceDocumentLine == sourceDocLine.RecId &&
                        revAccDist.ReferenceRole == AccountingDistributionReferenceRole::Adjusting
                    )
        {
            if (accDist.AllocationFactor == 1.0)
            {
                continue;
            }

            allocationFactor += accDist.AllocationFactor;
         
            if (purchLineLocal.ProcCatRecoverable_xyz== NoYes::Yes)
            {
                Amount exclGst =   xyz_ItemFeeTable::findByPurchLine(purchLineLocal.recId).RecoveryAmountExclGST;
                if (this.versioningUpdateType == VersioningUpdateType::Correction)
                {
                    gstAmount = ((exclGst /purchLineLocal.PurchQty ) * res) * accDist.AllocationFactor;
                    creditAmount = -decRound(gstAmount,2);
                    debitAmount  = creditAmount * -1;
                }

                else if (this.versioningUpdateType == VersioningUpdateType::Cancel)
                {
                    gstAmount = xyz_ItemFeeTable::findByPurchLine(purchLineLocal.recId).RecoveryAmountExclGST / purchLineLocal.PurchQty;
                    creditAmount = -(gstAmount * res) * accDist.AllocationFactor;
                    creditAmount = decRound(creditAmount,2);
                    debitAmount  = creditAmount * -1;
                }
                else
                {
                    gstAmount = 0 ;
                    creditAmount = ((xyz_ItemFeeTable::findByPurchLine(purchLineLocal.recId).RecoveryAmountExclGST /purchLineLocal.PurchQty ) * purchParmLineloc.ReceiveNow) * accDist.AllocationFactor  ;
                    creditAmount = decRound(creditAmount,2);
                    debitAmount  = -creditAmount;
                }
         

                ledgerDefaultAccount = InventPosting::accountItemLedgerDimensionFromParameters(InventPostingAccountItemLedgerDimensionParameters::newFromParameters(
                                                                                        InventAccountType::RevenueAccrual_xyz,
                                                                                        purchLineLocal.ItemId,
                                                                                        purchLineLocal.inventTable().itemGroupId(),
                                                                                        purchLineLocal.ProcurementCategory,
                                                                                        purchLineLocal.VendAccount,
                                                                                        purchLineLocal.VendGroup,
                                                                                        purchLineLocal.TaxGroup
                                                                                        ));
                ledgerDimensionId = LedgerDimensionFacade::serviceCreateLedgerDimension(ledgerDefaultAccount);

                ledgerVoucher = this.ledgerVoucher;
         
                ledgerVoucherObject = this.findOrCreateLedgerVoucherObject(this.getVoucher(), this.updateDate());
         
                standardCurrencyCode = CompanyInfoHelper::standardCurrency();
                currencyExchHelper = CurrencyExchangeHelper::newExchangeDate(Ledger::current(), systemDateGet());

                ledgerVoucherTransObject =  LedgerVoucherTransObject::newTransactionAmountDefault(ledgerVoucherObject  ,
                                                                                                    LedgerPostingType::RevenueAccrual_xyz,
                                                                                                    ledgerDimensionId,
                                                                                                    standardCurrencyCode,
                                                                                                    debitAmount,
                                                                                                    currencyExchHelper);

                ledgerVoucher.addTrans(ledgerVoucherTransObject);

                //for credit account
                ledgerDefaultAccount = InventPosting::accountItemLedgerDimensionFromParameters(InventPostingAccountItemLedgerDimensionParameters::newFromParameters(
                                                                                        InventAccountType::RevenuePurchReceipt_xyz,
                                                                                        purchLineLocal.ItemId,
                                                                                        purchLineLocal.inventTable().itemGroupId(),
                                                                                        purchLineLocal.ProcurementCategory,
                                                                                        purchLineLocal.VendAccount,
                                                                                        purchLineLocal.VendGroup,
                                                                                        purchLineLocal.TaxGroup
                                                                                        ));

                defaultDim = LedgerDimensionFacade::getDefaultDimensionFromLedgerDimension(accDist.ledgerdimension);

                ledgerDimensionId = LedgerDimensionFacade::serviceCreateLedgerDimension(ledgerDefaultAccount);
                ledgerDefaultAccountOffset = LedgerDimensionFacade::serviceMergeLedgerDimensions(ledgerDimensionId,accDist.ledgerdimension);
                ledgerVoucherTransObject =  LedgerVoucherTransObject::newTransactionAmountDefault(ledgerVoucherObject,
                                                                                                    LedgerPostingType::RevenuePurchReceipt_xyz,
                                                                                                    ledgerDefaultAccountOffset,
                                                                                                    standardCurrencyCode,
                                                                                                    creditAmount,
                                                                                                    currencyExchHelper);
                ledgerVoucherObject.addTrans(ledgerVoucherTransObject);
                ledgerVoucherObject.parmVoucherCheck(false);
            }

            if (allocationFactor == 1.0)
            {
                break ;
            }
        }
    }

}


Thanks,
Pradeep

Get Ledger dimension account from Invent posting profile

HI Guys,

Below code shall help in fetching the right account and create a ledgerDimension for the same from the InventPosting profile.

public InventPostingAccountItemLedgerDimensionParameters buildAccountItemLedgerDimensionParameter(PurchLine       _purchLine)
    {
        return InventPostingAccountItemLedgerDimensionParameters::newFromParameters(
                                                                                    InventAccountType::RevenueAccrual_xyz,
                                                                                    _purchLine.ItemId,
                                                                                    _purchLine.inventTable().itemGroupId(),
                                                                                    _purchLine.ProcurementCategory,
                                                                                    _purchLine.VendAccount,
                                                                                    _purchLine.VendGroup,
                                                                                    _purchLine.TaxGroup
                                                                                    );
    }

Thanks,
Pradeep

Get Accounting distribution for Purchase order line in AX for D365 for operations

Hi Guys,

The below code shall help you in pulling Account Distribution allocation factors between the Customer for a PurchaseOrder line.

while select forupdate RecId from sourceDocLine
                where
                    sourceDocLine.SourceDocumentHeader == purchTable.SourceDocumentHeader
            join forupdate accDist
                where
                    accDist.SourceDocumentLine == sourceDocLine.RecId &&
                    accDist.ReferenceRole != AccountingDistributionReferenceRole::Reversing
            notexists join revAccDist
                where
                    (   revAccDist.ReferenceDistribution == accDist.RecId &&
                        revAccDist.SourceDocumentLine == sourceDocLine.RecId &&
                        revAccDist.ReferenceRole == AccountingDistributionReferenceRole::Reversing
                    )
                    ||
                    (
                        revAccDist.ReferenceDistribution == accDist.RecId &&
                        revAccDist.SourceDocumentLine == sourceDocLine.RecId &&
                        revAccDist.ReferenceRole == AccountingDistributionReferenceRole::Adjusting
                    )
        {
            if (accDist.AllocationFactor == 1.0)
            {
                continue;
            }

            allocationFactor += accDist.AllocationFactor;

            // Write the your business logic her based on the allocation factor
Note: the First loop would always result with allocation factor 1

            if (allocationFactor == 1.0)
            {
                break ;
            }


Hope this help you

Thanks,
Pradeep