Pages

Banner 468 x 60px

 

Monday, March 27, 2017

How to using to code import to GL journal[AX2012]

0 comments
static void THK_importLedgerJournalTrans(Args _args)
{
    Filename                          fileName = "C:\\Users\\ksiu3880\\Desktop\\GL Journal test.xlsx";
 
    LedgerJournalId                   ledgerJournalId = "000425_010";
    Name                              nameDimensionAttribute1 = "Department";
    Name                              nameDimensionAttribute2 = "CostCenter";
    Name                              nameDimensionAttribute3 = "ExpensePurpose";
 
    LedgerJournalTrans_Asset          ledgerJournalTrans_Asset;
 
    AxLedgerJournalTable              axLedgerJournalTable;
    AxLedgerJournalTrans              axLedgerJournalTrans;
 
    DimensionAttributeValueSetStorage dimensionAttributeValueSetStorage;
 
    SysExcelApplication               application = SysExcelApplication::construct();
    SysExcelWorkbooks                 workbooks = application.workbooks();
    SysExcelWorkbook                  workbook;
    SysExcelWorksheets                worksheets;
    SysExcelWorksheet                 worksheet;
    SysExcelCells                     cells;
 
    COMVariantType                    type;
 
    TransDate                         transDate;
    LedgerJournalACType               ledgerJournalACType, ledgerJournalACTypeOffset;
    MainAccountNum                    mainAccountNum, mainAccountNumOffset;
    DimensionValue                    dimensionValue1, dimensionValue2, dimensionValue3;
    LedgerJournalTransTxt             ledgerJournalTransTxt;
    CurrencyCode                      currencyCode;
    AmountCur                         amountCur;
    ExchRate                          exchRate, exchRateSecond;
    InvoiceId                         invoiceId;
    DocumentDate                      documentDate;
    DueDate                           dueDate;
    PaymTermId                        paymTermId;
    AssetTransTypeJournal             assetTransTypeJournal;
    AssetBookIdPurchSalesInvent       assetBookIdPurchSalesInvent;
 
    container                         con, conOffset;
    int                               numOfDimension;
 
    int                               row = 2;
 
    setPrefix("THK_importLedgerJournalTrans");
 
    try
    {
        if (!LedgerJournalTable::checkExist(ledgerJournalId))
            throw Exception::Error;
 
        workbooks.open(fileName);
 
        workbook   = workbooks.item(1);
        worksheets = workbook.worksheets();
        worksheet  = worksheets.itemFromNum(1);
        cells      = worksheet.cells();
 
        ttsBegin;
 
        do
        {
            row++;
 
            print row;
 
            setPrefix(strFmt("Row %1", row));
 
            transDate                   = cells.item(row, 2).value().date();
            mainAccountNum              = strLRTrim(cells.item(row, 4).value().bStr());
            dimensionValue1             = strLRTrim(cells.item(row, 5).value().bStr());
            dimensionValue2             = strLRTrim(cells.item(row, 6).value().bStr());
            dimensionValue3             = strLRTrim(cells.item(row, 7).value().bStr());
            ledgerJournalTransTxt       = strLRTrim(cells.item(row, 8).value().bStr());
            currencyCode                = strLRTrim(cells.item(row, 9).value().bStr());
            amountCur                   = cells.item(row, 10).value().double();
            exchRate                    = cells.item(row, 13).value().double();
            exchRateSecond              = cells.item(row, 14).value().double();
            invoiceId                   = strLRTrim(cells.item(row, 15).value().bStr());
            documentDate                = cells.item(row, 16).value().date();
            dueDate                     = cells.item(row, 17).value().date();
            paymTermId                  = strLRTrim(cells.item(row, 18).value().bStr());
            assetBookIdPurchSalesInvent = strLRTrim(cells.item(row, 20).value().bStr());
            mainAccountNumOffset        = strLRTrim(cells.item(row, 22).value().bStr());
 
            switch (strLRTrim(cells.item(row, 3).value().bStr()))
            {
                case "Bank":         ledgerJournalACType = ledgerJournalACType::Bank;        break;
                case "Customer":     ledgerJournalACType = ledgerJournalACType::Cust;        break;
                case "Fixed Assets": ledgerJournalACType = ledgerJournalACType::FixedAssets; break;
                case "Ledger":       ledgerJournalACType = ledgerJournalACType::Ledger;      break;
                case "Project":      ledgerJournalACType = ledgerJournalACType::Project;     break;
                case "Vendor":       ledgerJournalACType = ledgerJournalACType::Vend;        break;
                default:             ledgerJournalACType = ledgerJournalACType::Ledger;      break;
            }
 
            switch (strLRTrim(cells.item(row, 19).value().bStr()))
            {
                case "Acquisition":            assetTransTypeJournal = AssetTransTypeJournal::Acquisition;    break;
                case "Acquisition Adjustment": assetTransTypeJournal = AssetTransTypeJournal::AcquisitionAdj; break;
                default:                       assetTransTypeJournal = AssetTransTypeJournal::Acquisition;    break;
            }
 
            switch (strLRTrim(cells.item(row, 21).value().bStr()))
            {
                case "Bank":         ledgerJournalACTypeOffset = ledgerJournalACType::Bank;        break;
                case "Customer":     ledgerJournalACTypeOffset = ledgerJournalACType::Cust;        break;
                case "Fixed Assets": ledgerJournalACTypeOffset = ledgerJournalACType::FixedAssets; break;
                case "Ledger":       ledgerJournalACTypeOffset = ledgerJournalACType::Ledger;      break;
                case "Project":      ledgerJournalACTypeOffset = ledgerJournalACType::Project;     break;
                case "Vendor":       ledgerJournalACTypeOffset = ledgerJournalACType::Vend;        break;
                default:             ledgerJournalACTypeOffset = ledgerJournalACType::Ledger;      break;
            }
 
            axLedgerJournalTrans              = new AxLedgerJournalTrans();
            con                               = [mainAccountNum, mainAccountNum];
            conOffset                         = [mainAccountNumOffset, mainAccountNumOffset];
            dimensionAttributeValueSetStorage = new DimensionAttributeValueSetStorage();
            numOfDimension                    = 0;
 
            if (dimensionValue1)
            {
                con            += [nameDimensionAttribute1, dimensionValue1];
                conOffset      += [nameDimensionAttribute1, dimensionValue1];
                numOfDimension ++;
 
                dimensionAttributeValueSetStorage.addItem(DimensionAttributeValue::findByDimensionAttributeAndValue(DimensionAttribute::findByName(nameDimensionAttribute1), dimensionValue1));
            }
 
            if (dimensionValue2)
            {
                con            += [nameDimensionAttribute2, dimensionValue2];
                conOffset      += [nameDimensionAttribute2, dimensionValue2];
                numOfDimension ++;
 
                dimensionAttributeValueSetStorage.addItem(DimensionAttributeValue::findByDimensionAttributeAndValue(DimensionAttribute::findByName(nameDimensionAttribute2), dimensionValue2));
            }
 
            if (dimensionValue3)
            {
                con            += [nameDimensionAttribute3, dimensionValue3];
                conOffset      += [nameDimensionAttribute3, dimensionValue3];
                numOfDimension ++;
 
                dimensionAttributeValueSetStorage.addItem(DimensionAttributeValue::findByDimensionAttributeAndValue(DimensionAttribute::findByName(nameDimensionAttribute3), dimensionValue3));
            }
 
            con       = conIns(con, 3, numOfDimension);
            conOffset = conIns(conOffset, 3, numOfDimension);
 
            axLedgerJournalTrans.parmJournalNum(ledgerJournalId);
            axLedgerJournalTrans.parmTransDate(transDate);
            axLedgerJournalTrans.parmAccountType(ledgerJournalACType);
            axLedgerJournalTrans.parmLedgerDimension(AxdDimensionUtil::getMultiTypeAccountId(enumNum(LedgerJournalACType), ledgerJournalACType, con));
            axLedgerJournalTrans.parmTxt(ledgerJournalTransTxt);
            axLedgerJournalTrans.parmCurrencyCode(currencyCode);
            axLedgerJournalTrans.parmExchRate(exchRate * 100);
            axLedgerJournalTrans.parmPaymId(num2str(exchRateSecond, 0, 12, 1, 0));
            axLedgerJournalTrans.parmInvoice(invoiceId);
            axLedgerJournalTrans.parmDocumentDate(documentDate);
            axLedgerJournalTrans.parmDue(dueDate);
            axLedgerJournalTrans.parmPayment(paymTermId);
 
            if (ledgerJournalACType != LedgerJournalACType::Ledger)
                axLedgerJournalTrans.parmDefaultDimension(dimensionAttributeValueSetStorage.save());
 
            if (amountCur >= 0)
                axLedgerJournalTrans.parmAmountCurDebit(amountCur);
            else
                axLedgerJournalTrans.parmAmountCurCredit(-amountCur);
 
            if (mainAccountNumOffset)
            {
                axLedgerJournalTrans.parmOffsetAccountType(ledgerJournalACTypeOffset);
                axLedgerJournalTrans.parmOffsetLedgerDimension(AxdDimensionUtil::getMultiTypeAccountId(enumNum(LedgerJournalACType), ledgerJournalACTypeOffset, conOffset));
 
                if (ledgerJournalACTypeOffset != LedgerJournalACType::Ledger)
                    axLedgerJournalTrans.parmOffsetDefaultDimension(dimensionAttributeValueSetStorage.save());
            }
 
            axLedgerJournalTrans.save();
 
            if (axLedgerJournalTrans.ledgerJournalTrans().isFixedAssetsTransaction())
            {
                ledgerJournalTrans_Asset.clear();
                ledgerJournalTrans_Asset.initValue();
 
                ledgerJournalTrans_Asset.RefRecId  = axLedgerJournalTrans.ledgerJournalTrans().RecId;
                ledgerJournalTrans_Asset.AssetId   = axLedgerJournalTrans.ledgerJournalTrans().getAssetId();
                ledgerJournalTrans_Asset.Company   = axLedgerJournalTrans.ledgerJournalTrans().getAssetCompany();
                ledgerJournalTrans_Asset.TransType = assetTransTypeJournal;
                ledgerJournalTrans_Asset.BookId    = assetBookIdPurchSalesInvent;
 
                if (!ledgerJournalTrans_Asset.validateWrite())
                    throw Exception::Error;
 
                ledgerJournalTrans_Asset.insert();
            }
 
            type = cells.item(row + 1, 1).value().variantType();
        }
        while (type != COMVariantType::VT_EMPTY);
 
        ttsCommit;
    }
    catch (Exception::Error)
    {
    }
 
    application.quit();
}






========================================================


// Cara dapatkan Default dimension
public static RefRecId getDefaultDimension (str CashFlow, str Location, str Divison, str YOPID, str Fields,
                                                 str Vehicle, str Station, str Category)
{
    DimensionAttributeValueSetStorage   valueSetStorage = new DimensionAttributeValueSetStorage();
    DimensionDefault                    result;

    int                     i;
    DimensionAttribute      dimensionAttribute;
    DimensionAttributeValue dimensionAttributeValue;
    InventJournalTrans      _inventjournaltrans;
    InventDim               _inventdim;
    InventTable             _inventtable;

    // Note that "Item" is not one of the default dimension,
    // but DimensionAttributeValueSetStorage will handle it gracefully

    container                conAttr;
    container                conValue;

    str                      dimValue;

    conAttr = ["CashFlow", "Location", "Divison", "YOPID", "Fields", "Vehicle", "Station", "Category"];

    conValue = [CashFlow, Location, Divison, YOPID, Fields, Vehicle, Station, Category];

    for (i = 1; i <= conLen(conAttr); i++)
    {
        dimensionAttribute = dimensionAttribute::findByName(conPeek(conAttr,i));

        if (dimensionAttribute.RecId == 0)
        {
            continue;
        }

        dimValue = conPeek(conValue,i);

        if (dimValue != "")
        {
            // The last parameter is "true". A dimensionAttributeValue record will be created if not found.
            dimensionAttributeValue=dimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute,dimValue,false,true);

            // Add the dimensionAttibuteValue to the default dimension
            valueSetStorage.addItem(dimensionAttributeValue);
        }
    }

    result = valueSetStorage.save();

    return result;
}







 switch(LedgerJournalACType::Bank)
   {
       case    LedgerJournalACType::Bank   :   select firstOnly b1
                                                   join RecId from ledgerDimension
                                                       where ledgerDimension.DisplayValue == b1.AccountID &&
                                                       b1.AccountID        == "USMF OPER";
                          journalTrans.parmOffsetLedgerDimension(ledgerDimension.RecId);
   }
Ledger Dimension Creation on Ax 2012 R1/R2
25 October, 2013   Sin categoría   1 Comment
In AX 2012 to obtain a Individual Dimension a number combination is used, the DimensionAttributeValueCombination table contains information about accounts and various dimensions combinations that are used. Anything that uses dimensions will hold reference to a record on this table. To explain this the following example was made:
·         We create the header of our Journal, then we declare a variable of RecId type.
imagen1
·         Once our variable is declared we proceed to create our LedgerDimension with the code shown in the image below.
imagen2
We use the class “DimensionStoreage” and inside of it the method accountNum2LedgerDimension which will take as values the Journal name and the type, in this case the name is “BCPMN” and the type “BANK”
·         We proceed to create the Journal Lines
imagen3
·         In the field parmLedgerDimension we put the variable offsetLedgerDimension, the one that will be transform our Ledger Account in a RecId, this will be our Offset Account
·         NOTE: The offset account is a RecId
We execute our Job and it will show the following message:
imagen4
·         Verify that our Journal it’s created and then we check the Journal Lines:
imagen5
·         As we can see the account type is BANK and the name of the account is BCPMN.
imagen6
The same configuration can be use for the following account types:
·         Banks
·         Customers
·         Vendors
·         Projects
·         Journals
What we should do is the following
Let’s take as an example the Customer case, we should modify the code with the following lines:
corregido
Now the type must be Cust (Customer).
imagen8
Ready…


http://www.andesoft.net/ledger-dimension-creation-ax-2012-r1r2/














static client void UploadLedgerJournalTrans(Filename filename, int start)
{
    #WinApi
    #File

    SysExcelApplication application = SysExcelApplication::construct();
    SysExcelWorkbooks   workbooks   = application.workbooks();
    SysExcelWorkbook    workbook;
    SysExcelWorksheets  workSheets;
    SysExcelWorksheet   workSheet;
    SysExcelCells       cells;
    SysExcelCell        cell;
    int                 i=0, j=0, k=0, l=0;

    real                lineNum;
    RecId               FSRecId;
    boolean             first;
    str                 _mainAccount;
    str                 _mainAccountComplete;

    str                 FinDim1,FinDim2,FinDim3,FinDim4;

    container               ledgerDimensions;
    LedgerDimensionAccount  ledgerDim, ledgerDim2;

    AXLedgerJournalTrans    AXLedgerJournalTrans;
    LedgerJournalTrans      LedgerJournalTrans;
    ;

    startLengthyOperation();
    if (!WinAPI::fileExists(filename))
        throw error(strfmt("@SYS109820", filename));

    if (workbooks.open(filename, false /*Update links*/, true /*Read only*/))
    {
        workbook   = workbooks.item(1);
        workSheets = workbook.worksheets();
        workSheet  = workSheets.itemFromNum(1); //worksheet keberapa dari excel di mulai dari angka 1
        cells      = workSheet.cells();

        i   = start;
        while (true)
        {
            if (cells.item(i, 2).value().bStr() == "" || i > 65536)
                break;
            else
            {
                try
                {
                    ttsBegin;
                    AXLedgerJournalTrans = new AXLedgerJournalTrans();
                    AXLedgerJournalTrans.parmCurrencyCode(cells.item(i, 2).value().bStr());
                    AXLedgerJournalTrans.parmJournalNum(cells.item(i, 3).value().bStr());
                    AXLedgerJournalTrans.parmTransDate(cells.item(i, 5).value().date());
                    AXLedgerJournalTrans.parmCompany(cells.item(i, 6).value().bStr());
                    AXLedgerJournalTrans.parmAccountType(cells.item(i, 7).value().double());

                    FinDim1 = cells.item(i, 10).value().bStr();
                    FinDim2 = cells.item(i, 11).value().bStr();
                    FinDim3 = cells.item(i, 24).value().bStr();
                    FinDim4 = cells.item(i, 25).value().bStr();

                    //info(FinDim1+" - "+FinDim2+" - "+FinDim3+" - "+FinDim4);

                    ledgerDimensions = conNull();
                    FinDim1="";
                    _mainAccountComplete="";
                    k=0;
                    _mainAccount = "";
                    _mainAccount = cells.item(i, 9).value().bStr();
                    //_mainAccountComplete = _mainAccount + "-------";
                    _mainAccountComplete = _mainAccount + "-" + cells.item(i, 10).value().bStr() + "-" +  cells.item(i, 11).value().bStr() + "-"; //+
                                           //cells.item(i, 24).value().bStr()+ "-" + cells.item(i, 25).value().bStr() + "---"+ "1";

                    ledgerDimensions = [_mainAccountComplete,_mainAccount];

                    if(AXLedgerJournalTrans.parmAccountType() == 0)
                    {
                        if(FinDim1)
                        {
                            k++;
                            ledgerDimensions = conIns(ledgerDimensions,conLen(ledgerDimensions)+1,"Department");
                            ledgerDimensions = conIns(ledgerDimensions,conLen(ledgerDimensions)+1,FinDim1);
                        }
                        if(FinDim2)
                        {
                            k++;
                            ledgerDimensions = conIns(ledgerDimensions,conLen(ledgerDimensions)+1,"Center");
                            ledgerDimensions = conIns(ledgerDimensions,conLen(ledgerDimensions)+1,FinDim2);
                        }
                        if(FinDim3)
                        {
                            k++;
                            ledgerDimensions = conIns(ledgerDimensions,conLen(ledgerDimensions)+1,"Purpose");
                            ledgerDimensions = conIns(ledgerDimensions,conLen(ledgerDimensions)+1,FinDim3);
                        }
                        if(FinDim4)
                        {
                            k++;
                            ledgerDimensions = conIns(ledgerDimensions,conLen(ledgerDimensions)+1,"Detail");
                            ledgerDimensions = conIns(ledgerDimensions,conLen(ledgerDimensions)+1,FinDim4);
                        }
                        //ledgerDimensions = conIns(ledgerDimensions,conLen(ledgerDimensions)+1,"Site");
                        //ledgerDimensions = conIns(ledgerDimensions,conLen(ledgerDimensions)+1,"1");

                        ledgerDimensions = conIns(ledgerDimensions,3,k);



   //                     ledgerDimensions = [_mainAccountComplete,_mainAccount,5,"Department",cells.item(i, 10).value().bStr(),"Center",
   //                     cells.item(i, 11).value().bStr(),"Purpose",cells.item(i, 24).value().bStr(), "Detail", cells.item(i, 25).value().bStr(),"Site", "JG"];
                        ledgerDim = AxdDimensionUtil::getLedgerAccountId(ledgerDimensions);
                        AXLedgerJournalTrans.parmLedgerDimension(ledgerDim);
   //                     info(strFmt("%1", _mainAccount));
   //                     info(strFmt("%1", _mainAccountComplete));
   //                     info(strfmt("%1",ledgerDim));

                    }
                    else if(AXLedgerJournalTrans.parmAccountType() == 1)
                    {
                        ledgerDim = DimensionStorage::getDynamicAccount(_mainAccount, LedgerJournalACType::Cust);
                        AXLedgerJournalTrans.parmLedgerDimension(ledgerDim);
                    }
                    else if(AXLedgerJournalTrans.parmAccountType() == 2)
                    {
                        ledgerDim = DimensionStorage::getDynamicAccount(_mainAccount, LedgerJournalACType::Vend);
                        AXLedgerJournalTrans.parmLedgerDimension(ledgerDim);
                    }
                    else if(AXLedgerJournalTrans.parmAccountType() == 3)
                    {
                        ledgerDim = DimensionStorage::getDynamicAccount(_mainAccount, LedgerJournalACType::Project);
                        AXLedgerJournalTrans.parmLedgerDimension(ledgerDim);
                    }
                    else if(AXLedgerJournalTrans.parmAccountType() == 5)
                    {
                        ledgerDim = DimensionStorage::getDynamicAccount(_mainAccount, LedgerJournalACType::FixedAssets);
                        AXLedgerJournalTrans.parmLedgerDimension(ledgerDim);
                    }
                    else if(AXLedgerJournalTrans.parmAccountType() == 6)
                    {
                        ledgerDim = DimensionStorage::getDynamicAccount(_mainAccount, LedgerJournalACType::Bank);
                        AXLedgerJournalTrans.parmLedgerDimension(ledgerDim);
                    }

                    AXLedgerJournalTrans.parmTxt(cells.item(i, 12).value().bStr());
                    AXLedgerJournalTrans.parmAmountCurDebit(cells.item(i, 13).value().double());
                    AXLedgerJournalTrans.parmAmountCurCredit(cells.item(i, 14).value().double());
                    AXLedgerJournalTrans.parmInvoice(cells.item(i, 15).value().bStr());
                    AXLedgerJournalTrans.parmOffsetCompany(cells.item(i, 16).value().bStr());
                    AXLedgerJournalTrans.parmOffsetAccountType(cells.item(i, 17).value().double());

                    FinDim1 = cells.item(i, 20).value().bStr();


                    ledgerDimensions = conNull();
                    _mainAccount = "";
                    _mainAccount = cells.item(i, 19).value().bStr();
                    _mainAccountComplete = _mainAccount + "-" + cells.item(i, 19).value().bStr() + "-" +  cells.item(i, 20).value().bStr() + "-"; //+
                    //info(strFmt("%1 - %2", AXLedgerJournalTrans.parmOffsetAccountType(), _mainAccount));

                    ledgerDimensions = [_mainAccountComplete,_mainAccount];

                    if(AXLedgerJournalTrans.parmOffsetAccountType() == 0)
                    {
                        if(FinDim1)
                        {
                            k++;
                            ledgerDimensions = conIns(ledgerDimensions,conLen(ledgerDimensions)+1,"Department");
                            ledgerDimensions = conIns(ledgerDimensions,conLen(ledgerDimensions)+1,FinDim1);
                        }
                        if(FinDim2)
                        {
                            k++;
                            ledgerDimensions = conIns(ledgerDimensions,conLen(ledgerDimensions)+1,"Center");
                            ledgerDimensions = conIns(ledgerDimensions,conLen(ledgerDimensions)+1,FinDim2);
                        }
                        if(FinDim3)
                        {
                            k++;
                            ledgerDimensions = conIns(ledgerDimensions,conLen(ledgerDimensions)+1,"Purpose");
                            ledgerDimensions = conIns(ledgerDimensions,conLen(ledgerDimensions)+1,FinDim3);
                        }
                        if(FinDim4)
                        {
                            k++;
                            ledgerDimensions = conIns(ledgerDimensions,conLen(ledgerDimensions)+1,"Detail");
                            ledgerDimensions = conIns(ledgerDimensions,conLen(ledgerDimensions)+1,FinDim4);
                        }

                        ledgerDimensions = conIns(ledgerDimensions,3,k);
                        ledgerDim2 = AxdDimensionUtil::getLedgerAccountId(ledgerDimensions);
                        AXLedgerJournalTrans.parmOffsetLedgerDimension(ledgerDim2);
                        //info(strfmt("%1",ledgerDim2));
                    }
                    else if(AXLedgerJournalTrans.parmOffsetAccountType() == 1)
                    {
                        ledgerDim = DimensionStorage::getDynamicAccount(_mainAccount, LedgerJournalACType::Cust);
                        AXLedgerJournalTrans.parmOffsetLedgerDimension(ledgerDim);
                    }
                    else if(AXLedgerJournalTrans.parmOffsetAccountType() == 2)
                    {
                        ledgerDim = DimensionStorage::getDynamicAccount(_mainAccount, LedgerJournalACType::Vend);
                        AXLedgerJournalTrans.parmOffsetLedgerDimension(ledgerDim);
                    }
                    else if(AXLedgerJournalTrans.parmOffsetAccountType() == 3)
                    {
                        ledgerDim = DimensionStorage::getDynamicAccount(_mainAccount, LedgerJournalACType::Project);
                        AXLedgerJournalTrans.parmOffsetLedgerDimension(ledgerDim);
                    }
                    else if(AXLedgerJournalTrans.parmOffsetAccountType() == 5)
                    {
                        ledgerDim = DimensionStorage::getDynamicAccount(_mainAccount, LedgerJournalACType::FixedAssets);
                        AXLedgerJournalTrans.parmOffsetLedgerDimension(ledgerDim);
                    }
                    else if(AXLedgerJournalTrans.parmOffsetAccountType() == 6)
                    {
                        ledgerDim = DimensionStorage::getDynamicAccount(_mainAccount, LedgerJournalACType::Bank);
                        AXLedgerJournalTrans.parmOffsetLedgerDimension(ledgerDim);
                    }

                    //AXLedgerJournalTrans.parmOffsetTxt(cells.item(i, 21).value().bStr());
                    AXLedgerJournalTrans.parmDue(cells.item(i, 22).value().date());
                    AXLedgerJournalTrans.parmDocumentDate(cells.item(i, 23).value().date());
                    if(cells.item(i, 24).value().double())
                        AXLedgerJournalTrans.parmExchRate(cells.item(i, 24).value().double()*100);
                    AXLedgerJournalTrans.save();

                    select forUpdate LedgerJournalTrans where LedgerJournalTrans.RecId == AXLedgerJournalTrans.parmRecId();
                    LedgerJournalTrans.Voucher = cells.item(i, 4).value().bStr();
                    LedgerJournalTrans.OffsetLedgerDimension = ledgerDim2;
                    LedgerJournalTrans.LedgerDimension = ledgerDim;
                    LedgerJournalTrans.update();

                    ttsCommit;
                    j++;
                    i++;
                    print(strfmt("Line %1 is succeeded", i));
                }
                catch
                {
                    error(strfmt("Line %1 is error", i));
                    i++;
                }
            }
        }

        info(strfmt("%1 data uploaded to Ledger Journal Trans", j));
        application.displayAlerts(false);
        application.quit();
        application.displayAlerts(true);
    }
}


import fixed asset to Fixed asset Trans asset


static void ledgerjournalTrans_FixedAsset(Args _args)
{
    LedgerJournalTrans_Asset                LedgerJournalTrans_Asset;
     DimensionDisplayValue                   DimensionDisplayValue;
    LedgerJournalTrans                      LedgerJournalTrans;
    DimensionAttributeValueCombination      DimensionAttributeValueCombination;
    CommaIO                                 csvFile;
    container                               readCon;
    counter                                 icount,inserted;
    Dialog                                  dialog;
    DialogField                             dfFileName;
    FileName                                fileName;
    str                                     contactperson;
    str 70                                  TransType;
    BinData binData;
    inserted =0;

    #File

    dialog = new Dialog("Pick the file");
    dfFileName = dialog.addField(extendedTypeStr(FileNameOpen));
    dialog.filenameLookupFilter(["All files", #AllFiles]);



    if (dialog.run())
        {
             filename =  dfFileName.value();
        }




    csvFile = new CommaIO(filename, 'r');


    if (csvFile)
    {
        readCon = csvFile.read();
        ttsbegin;
        while (csvFile.status() == IO_Status::OK)
        {
            readCon = csvFile.read();
            icount++;
            if (readCon)
            {
                DimensionDisplayValue = conPeek(readCon,1);

                select * from DimensionAttributeValueCombination where DimensionAttributeValueCombination.DisplayValue == DimensionDisplayValue;
                select  * from LedgerJournalTrans where LedgerJournalTrans.LedgerDimension == DimensionAttributeValueCombination.RecId ;
                LedgerJournalTrans_Asset.clear();
                select * from LedgerJournalTrans_Asset where LedgerJournalTrans_Asset.RefRecId == LedgerJournalTrans.RecId;
                if(!LedgerJournalTrans_Asset)
                {
                    ttsBegin;
                    LedgerJournalTrans_Asset.AssetId            = DimensionDisplayValue;
                    LedgerJournalTrans_Asset.RefAssetID         = DimensionDisplayValue;
                    LedgerJournalTrans_Asset.BookId             = conPeek(readCon,2);
                    LedgerJournalTrans_Asset.Company            = conPeek(readCon,3);
                    LedgerJournalTrans_Asset.FAQty              = conPeek(readCon,4);
                    LedgerJournalTrans_Asset.FAUnit             = conPeek(readCon,5);
                    LedgerJournalTrans_Asset.FAUnitPrice        = conPeek(readCon,6);
                    TransType = conPeek(readCon,7);
                    if(TransType == "Acquisition")
                    {
                    LedgerJournalTrans_Asset.TransType             = AssetTransTypeJournal::Acquisition;
                    }
                    else
                        if(TransType == "Depreciation")
                            {
                                 LedgerJournalTrans_Asset.TransType             = AssetTransTypeJournal::Depreciation;
                            }

                    LedgerJournalTrans_Asset.insert();
                    ttsCommit;
                }

            }
        }
        ttsCommit;
    }
    info(strfmt("%1 records inserted out of %2",inserted,icount));

}

Dynamics AX 2012 – X++ code to create General Journal

Posted on by vincysomanna
static void Demo_CreateGLJournal(Args _args)
{
    AxLedgerJournalTable journalTable;
    AxLedgerJournalTrans journalTrans;
    container            accEntryPattern;
    container            offSetEntryPattern;
    ;

    journalTable = new AxLedgerJournalTable();
    journalTrans = new AxLedgerJournalTrans();

    //Journal Name
    journalTable.parmJournalName(“GenJrn”);
    journalTable.save();

    journalTrans.parmJournalNum(journalTable.ledgerJournalTable().JournalNum);
    journalTrans.parmTransDate(systemDateGet());
    journalTrans.parmAccountType(LedgerJournalACType::Ledger);

    //LedgerDimension  => Ledgeraccount, DAX 2009
    accEntryPattern = [“601501”, “601501”, 0]; 
    journalTrans.parmLedgerDimension(AxdDimensionUtil::getLedgerAccountId(accEntryPattern));

    journalTrans.parmAmountCurDebit(2000);

    //OffsetLedgerDimension => OffsetLedgerAccount,  DAX 2009
    offSetEntryPattern = [“401100”, “401100”, 0];
    journalTrans.parmOffsetAccountType(LedgerJournalACType:: Ledger );
    journalTrans.parmOffsetLedgerDimension(AxdDimensionUtil::getLedgerAccountId( offSetEntryPattern));
  
    journalTrans.save();

    info(strFmt(“Journal %1 created”, journalTable.ledgerJournalTable().JournalNum));
}

How to post with Financial dimensions:

Format : 
[“DisplayValue”, “MainAccount”, NumberOfDimensions, “DimensionName”, “DimensionValue”]; 

E.g:
accEntryPattern = [“601501-Test”, “601501”, 1, “Department”, “OU_1”]


======================== http://natepaine.blogspot.co.id/2010/01/how-to-load-fixed-assets.html==========================

How to Load Fixed Assets

Task: load about 2000 fixed assets into Dynamics AX 4.0.  Some assets have been previously scrapped, sold, and fully depreciated.  Otherwise, the assets are generally part way through straight-line depreciation.  Assets fall into 6 groups (i.e. buildings, machinery, etc.) and need to be associated with a financial dimension indicating the department (i.e. shipping, production, etc.).

Minimum Data that you need to import...and where it maps to in AX)
Fixed Asset Number  (AssetTable.AssetId, AssetBook.AssetId)
Asset Name (AssetTable.Name)
Asset Group (AssetTable.AssetGroup, AssetBook.AssetGroup)
Placed in Service Date (AssetBook.AcquisitionDate, AssetTable.GuaranteeDate) - GuaranteeDate is temporary, use whatever field you like
Aquisition Price (AssetBook.AcquisitionPrice)
Service Life in Years (AssetBook.ServiceLife)
Service Life in Months (AssetBook.LifeTime) - I could have calculated this during import
Depreciation Periods Remaining (AssetBook.LifeTimeRest)
Accumulated depreciation from legacy system (AssetTable.AssetReplaceCost) - this is temporary, use whatever field you like
plus other data that you may or may not have

Step 1 - Import
Define custom definition group for AssetTable and AssetBook.  Field setup as described above.
(Administration, Periodic, Data Export/Import, Definition Groups)

I used the Conversion tab to set some values:

AssetBook book;
;
book.data(assetBook);
book.BookId = 'OurBookId';
book.PostingProfile = 'OurPostingProfileId';
book.Depreciation = NoYes::Yes;
book.LastDepreciationDate = mkDate(31,10,2009);
book.DepreciationConvention = AssetDepreciationConvention::MidMonth1st;
assetBook.data(book);
Note: the LastDepreciationDate is the date that accumulated depreciation was calculated through in the legacy system.

Step 2 - Post Journal for Acquisition
Once you have the Fixed Asset records that you imported in step 1, you will see that they have the status 'Not yet acquired'.  To properly record the aquisition, you have to post a Fixed Asset acquisition journal.  

In our case, the Ledger balances already reflected the prior purchase of the assets.  We needed to record the acquisition, but didn't want it to affect our ledger balances.  The simple work-around was to temporarily set the aquisition ledger account and offset account to the same ledger account so there is no net affect.  (GL, Setup, Fixed Assets, Posting Profiles)
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjD_9bDQyuT43Zh1dpneSqHV97QnT5f1BDfq_VvD92wYFCMyM_1SVYNAhGp66Zcq0Qv6kjnZsJP97vvf_ndju7SMKLjl4em41X51gltPRFUDoZESdwQyOGvpqvYYROGKngXR2EWa78xoX48/s320/ScreenShot011.jpg
It's possible to use Proposal > Acquisition to create lines in the Fixed Asset journal and then change the dates* on all the lines (they are defaulted to the acquisition date - but those periods were closed for us).  Instead, I wrote a little job to create the journals.  (see below)
*when you change this date, the AssetBook.AcquisitionDate is overwritten.  see solution below.

Step 3 - Post Journal for (legacy system) Accumulated Depreciation
Since most of our fixed assets were partially depreciated at the time of import, we needed some way to record the prior depreciation.  To do this you could use Proposal > Depreciation to get 'caught up'.  There are two small issues: 1) if acquisition date was changed during step 2, the depreciation proposal will not know the correct aquisition date.  2) in our case, again, the Ledger balances already reflected the depreciation prior to import.
Our solution was to create a Depreciation Adjustment journal that has a matching ledger account and offset account.  Since there isn't a Proposal > Depreciation Adjustment, I wrote a job to do this.  (see below)

Step 4 - Ready To Go
The key fields that allow depreciation to 'pick up where it left off' are AssetBook.LifeTimeRest (remaining depreciation periods) and AssetBook.LastDepreciationDate.  We set these during the import, so there shouldn't be anything further to do.

Our Journal Creation Job
As noted in Step 2 and 3 - we used a job to create the acquisition journal and depreciation adjustment journal.  Here it is:


static void AssetCreateJournal(Args _args)
{
    LedgerJournalName   ledgerJournalName;
    LedgerJournalTable  ledgerJournalTable;
    LedgerJournalTrans  ledgerJournalTrans;
    NumberSeq           numberSeq;
    AssetTable          assetTable;
    AssetBook           assetBook;
    int                 lineNum;
    Date                transDate;
    ;
 
    transDate = mkDate(31,10,2009);  //Oct 31, 2009 = our conversion date
 
    ttsbegin;
 
    //Record the acquisition
    select firstonly ledgerjournalName where ledgerJournalName.JournalName == 'OurJournalName';
    ledgerJournalTable.JournalName = LedgerJournalName.JournalName;
    ledgerJournalTable.initFromLedgerJournalName();
    ledgerJournalTable.insert();
 
    numberSeq = NumberSeq::newGetVoucherFromCode(ledgerJournalName.VoucherSeries);
 
    while select assetBook where assetBook.Status == AssetStatus::NoAcquisition
    {
        lineNum++;
        ledgerJournalTrans.clear();
        ledgerJournalTrans.voucher = numberSeq.voucher();
        ledgerJournalTrans.LineNum = lineNum;
        ledgerJournalTrans.TransDate = transDate;
        ledgerJournalTrans.JournalNum = ledgerJournalTable.JournalNum;
        ledgerJournalTrans.initValue();  //sets currencyCode and exchRate, etc
        ledgerJournalTrans.AccountType = LedgerJournalACType::FixedAssets;
        ledgerJournalTrans.AccountNum = assetBook.AssetId;
        ledgerJournalTrans.initAssetBookid();  //sets assetBookId
        ledgerJournalTrans.initAssetPostingProfile(); //sets postingProfile
        ledgerJournalTrans.Txt = "Acquisition";
        ledgerJournalTrans.AssetTransType = AssetTransTypeJournal::Acquisition;
        ledgerJournalTrans.AmountCurDebit = assetBook.AcquisitionPrice;
        ledgerJournalTrans.OffsetAccountType = LedgerJournalACType::Ledger;
        ledgerJournalTrans.OffsetAccount = ledgerJournalTrans.findOffsetAccount();
        ledgerJournalTrans.Dimension = assetBook.Dimension;
        ledgerJournalTrans.insert();
    }
 
    ttscommit;
    info (strfmt("Fixed Asset Journal %1 was created with %2 lines",ledgerJournalTable.JournalNum,lineNum));
 
    ttsbegin;
 
    //Now do the same thing for depreciation adjustment
    lineNum = 0;
 
    select firstonly ledgerjournalName where ledgerJournalName.JournalName == 'FA';
    ledgerJournalTable.clear();
    ledgerJournalTable.JournalName = LedgerJournalName.JournalName;
    ledgerJournalTable.initFromLedgerJournalName();
    ledgerJournalTable.insert();
 
    numberSeq = NumberSeq::newGetVoucherFromCode(ledgerJournalName.VoucherSeries);
 
    //during import, the accumulated depreciation was temporarily stored in the assetReplaceCost field
    while select assetTable where assetTable.AssetReplaceCost > 0
    {
        lineNum++;
        ledgerJournalTrans.clear();
        ledgerJournalTrans.voucher = numberSeq.voucher();
        ledgerJournalTrans.LineNum = lineNum;
        ledgerJournalTrans.TransDate = transDate;
        ledgerJournalTrans.JournalNum = ledgerJournalTable.JournalNum;
        ledgerJournalTrans.initValue();  //sets currencyCode and exchRate, etc
        ledgerJournalTrans.AccountType = LedgerJournalACType::FixedAssets;
        ledgerJournalTrans.AccountNum = assetTable.AssetId;
        ledgerJournalTrans.initAssetBookid();  //sets assetBookId
        ledgerJournalTrans.initAssetPostingProfile(); //sets postingProfile
        ledgerJournalTrans.Txt = strfmt("Depreciation through %1",transDate);
        ledgerJournalTrans.AssetTransType = AssetTransTypeJournal::DepreciationAdj;
        ledgerJournalTrans.AmountCurCredit = assetTable.AssetReplaceCost; //using our temporary data from import
        ledgerJournalTrans.OffsetAccountType = LedgerJournalACType::Ledger;
        ledgerJournalTrans.OffsetAccount = ledgerJournalTrans.findOffsetAccount();
        ledgerJournalTrans.Dimension = AssetBook::Find(ledgerJournalTrans.AccountNum,ledgerJournalTrans.AssetBookId).Dimension;
        ledgerJournalTrans.insert();
    }
 
    ttscommit;
 
    info (strfmt("Fixed Asset Journal %1 was created with %2 lines",ledgerJournalTable.JournalNum,lineNum));
}
After reviewing and posting the journals, we ran the following job to clean up the records - remove temporary data and fix the aquisition date.


static void AssetFinalizeImport(Args _args)
{
    AssetTable          assetTable;
    AssetBook           assetBook;
    ;
 
    ttsbegin;
 
    //during import, the accumulated depreciation was temporarily stored in the assetReplaceCost field
    while select forupdate assetTable
    {
        assetBook = AssetBook::Find(assetTable.AssetId,'OurBookId',true);
 
        if (assetBook)
        {
            if (assetTable.GuaranteeDate != dateNull())
            {
                assetBook.AcquisitionDate = assetTable.GuaranteeDate;
            }
            //if fully depreciated
            if (assetTable.AssetReplaceCost == assetBook.AcquisitionPrice)
            {
                assetBook.Status = AssetStatus::Closed;
            }
            assetBook.update();
 
            //clear the temporary fields
            assetTable.AssetReplaceCost = 0;
            assetTable.GuaranteeDate = datenull();
            assetTable.update();
        }
    }
 
    ttscommit;
}



===============http://stackoverflow.com/questions/11138260/programmatically-depreciation-run-ax-4=============
I would like some assistance on creating a depreciation run in X++ the variables are Account Number as in the Asset and the End date.
I created LedgerJournalTable, LedgerJournalName, LedgerJournalTrans very effectively but do not understand LedgerJournalEngine of AssetProposal
The code thus far:
client static void DepreciationRun()
{
AssetProposal assetProposal ;// = AssetProposal::construct();
LedgerJournalTable _ledgerJournalTable;// = args.caller()._ledgerJournalTable();
LedgerJournalName ledgerJournalName;
LedgerJournalEngine ledgerJournalEngine;// = args.caller().ledgerJournalEngine();
FormDataSource formDataSource ;// = args.record().dataSource();
LedgerJournalTrans ledgerJournalTrans ;// = args.record();
Voucher lastVoucher; Str 10 Type = "FAD";
;
switch(Type)
{
case "FAD":
assetProposal = new AssetProposalDepreciation();
break;
case "ACC":
assetProposal = new AssetProposalAcquisition();
ledgerJournalName = LedgerJournalName::find("Fixed Asset Acquisition");
break;
}
assetProposal.getLast();
ledgerJournalName = LedgerJournalName::find("GL_Daily");
_ledgerJournalTable.JournalNum = NumberSeq::newGetVoucherFromCode(ledgerJournalName.VoucherSeries).voucher(); //Generate
_ledgerJournalTable.JournalName = ledgerJournalName.JournalName;
_ledgerJournalTable.JournalType = LedgerJournalType::Daily;
_ledgerJournalTable.Name = ledgerJournalName.Name;
_ledgerJournalTable.LedgerJournalInclTax = NoYes::Yes;
_ledgerJournalTable.initValue();
_ledgerJournalTable.insert();
ledgerJournalName = LedgerJournalName::find(Type);
//ledgerJournalTrans.Voucher = NumberSeq::newGetVoucherFromCode(ledgerJournalName.VoucherSeries).voucher();
ledgerJournalTrans.initValue();
ledgerJournalTrans.JournalNum = _ledgerJournalTable.JournalNum;
ledgerJournalTrans.Voucher = NumberSeq::newGetVoucherFromCode(ledgerJournalName.VoucherSeries).voucher();
//ledgerJournalTrans.insert();
ledgerJournalEngine = LedgerJournalEngine::construct(_ledgerJournalTable.JournalType);
ledgerJournalEngine.newJournalActive(_ledgerJournalTable);
//ledgerJournalEngine
//ledgerJournalEngine.initValue(ledgerJournalTrans);
//Fixed Asset Depriciation
assetProposal.journalNum(_ledgerJournalTable.JournalNum);
assetProposal.parmLedgerJournalEngine(ledgerJournalEngine);
assetProposal.addBookIdRange();
assetProposal.init();
if (assetProposal.prompt())
{
// Check if line exists on form that hasn't been saved, and clear the voucher number
if (!ledgerJournalTrans.RecId && ledgerJournalTrans.Voucher)
{
ledgerJournalEngine.clearVoucher();
}
//
// Find the last voucher number. This is needed when user had done a ctrl-N to
// create a new line and then deleted the line.
//
else if (ledgerJournalTrans.RecId)
{
select firstonly Voucher from ledgerJournalTrans
order by Voucher desc
where ledgerJournalTrans.JournalNum == _ledgerJournalTable.JournalNum;
lastVoucher = ledgerJournalTrans.Voucher;
}
// run the proposal
assetProposal.run();
// update the voucher totals if reuse the voucher
if (!ledgerJournalTrans.Voucher || !ledgerJournalTrans.RecId)
{
// No lines existed where user did the proposal, need to update the
// totals for the first voucher.
if (!ledgerJournalTrans.Voucher)
{
select firstonly ledgerJournalTrans
order by Voucher
where ledgerJournalTrans.JournalNum == _ledgerJournalTable.JournalNum;
}
// User was on a new line when doing the proposal, need to update the
// totals for the voucher on that line.
else
{
ledgerJournalTrans = LedgerJournalTrans::find(_ledgerJournalTable.JournalNum, 
ledgerJournalTrans.Voucher, false);
}
}
// User was on an existing line when doing the proposal, need to update the
// total for the next voucher after the last voucher number that existed
// before doing the proposal
else
{
select firstonly ledgerJournalTrans
order by Voucher
where ledgerJournalTrans.JournalNum == _ledgerJournalTable.JournalNum &&
ledgerJournalTrans.Voucher > lastVoucher;
}
// Update the totals. This is needed because is updates variables in
// JournalEngine that control if the voucher is complete.
if (ledgerJournalTrans)
{
ledgerJournalEngine.voucherTotals(ledgerJournalTrans, true);
}
// redisplay the form
formDataSource.executeQuery();
ledgerJournalEngine.ledgerJournalTableUpdateTotals(_ledgerJournalTable,true);
} }




===============http://axaptacorner.blogspot.co.id/2012/09/how-to-create-general-journal-in-ax.html================

How to create General Journal in AX 2012 by X++ code


With following code we can create general journal with default dimention and ledger Account
just change default values according to youe system data and simply run the job


static void Demo_CreateGLJrl(Args _args)
{
    AxLedgerJournalTable   axLedgerJournalTable ;
    AxLedgerJournalTrans   axLedgerJournalTrans;
    container            accPattern;
    container            offSetPattern;
    container            dimPattern1;
    ;
    axLedgerJournalTable = new AxLedgerJournalTable();
    axLedgerJournalTrans = new AxLedgerJournalTrans();
    dimPattern1 = [1,"Department", "000"];
    axLedgerJournalTable.parmDefaultDimension(AxdDimensionUtil::getDimensionAttributeValueSetId(dimPattern1));
    axLedgerJournalTable.parmJournalName("GenJrn");
    axLedgerJournalTable.save();
    axLedgerJournalTrans.parmJournalNum(axLedgerJournalTable.ledgerJournalTable().JournalNum);
    axLedgerJournalTrans.parmTransDate(systemDateGet());
    axLedgerJournalTrans.parmAccountType(LedgerJournalACType::Ledger);
    accPattern = ["420100", "420100", 0];
    axLedgerJournalTrans.parmLedgerDimension(AxdDimensionUtil::getLedgerAccountId(accPattern));
    offSetPattern = ["420200", "420200", 0];
    axLedgerJournalTrans.parmOffsetAccountType(LedgerJournalACType:: Ledger );
    axLedgerJournalTrans.parmOffsetLedgerDimension(AxdDimensionUtil::getLedgerAccountId( offSetPattern));
    axLedgerJournalTrans.save();
    info(strFmt("Journal %1 created with finential Dimension %2", axLedgerJournalTable.ledgerJournalTable().JournalNum,axLedgerJournalTable.ledgerJournalTable().DefaultDimension));
}
=================https://dynamicsuser.net/ax/f/developers/64477/general-journal-in-ax2012-through-x===============================

General Journal in AX2012 through X++

Hi All,
I create general journal in ax2012 through x++.it created successfully but in Lines voucher is created but account is insert with out dimension values, offset account is not inserted.but i pass the both accounts with dimension values.
how can i insert accounts with dimensions.
here is my code
AxLedgerJournalTable   axLedgerJournalTable ;
    AxLedgerJournalTrans   axLedgerJournalTrans;
    container            accPattern;
    container            offSetPattern;
    container            dimPattern1;
    ledgerJournalCheckPost  ledgerJournalCheckPost;
    ;
    axLedgerJournalTable = new AxLedgerJournalTable();
    axLedgerJournalTrans = new AxLedgerJournalTrans();
    //dimPattern1 = ['OU_3566',"00000024", "Training"];
   // axLedgerJournalTable.parmDefaultDimension(AxdDimensionUtil::getDimensionAttributeValueSetId(dimPattern1));
    axLedgerJournalTable.parmJournalName("GenJrn");
    axLedgerJournalTable.save();
    axLedgerJournalTrans.parmJournalNum(axLedgerJournalTable.ledgerJournalTable().JournalNum);
    axLedgerJournalTrans.parmTransDate(systemDateGet());
    axLedgerJournalTrans.parmAmountCurCredit(300);
    axLedgerJournalTrans.parmAccountType(LedgerJournalACType::Ledger);
    accPattern = ['110110-001-022','110110','0','022','001','0'];
    axLedgerJournalTrans.parmLedgerDimension(AxdDimensionUtil::getLedgerAccountId(accPattern));
    offSetPattern = ['110150-001-022','110150','0','022','001','0'];
    axLedgerJournalTrans.parmOffsetAccountType(LedgerJournalACType:: Ledger );
    axLedgerJournalTrans.parmOffsetLedgerDimension(AxdDimensionUtil::getLedgerAccountId( offSetPattern));
    axLedgerJournalTrans.save();





=======http://irfanaxapta.blogspot.co.id/2013/11/post-ledger-journal-through-x-code-in.html=====

post the ledger journal through x++ code in AX 2012


For posting general journal we can use this table and classes
1.  LedgerJournalTable
2.  LedgerJournalTrans     
3.  ledgerJournalCheckPost(class) 



mandatory fields are offset account,ledger account,amount,journal name,journal number… etc


createFreeTextInvoicesAndPost(default class where one method is there-“ createGeneralJournalAndPost ”-through this method we can post the ledger journal through code)



[SysEntryPointAttribute(true)]
public str createGeneralJournalAndPost(Amount         _amount,
                                        CustAccount _cutomer,
                                        str         _businessUnit,
                                        ItemId      _itemId,
                                        str         _batchId,
                                        str         _qty,
                                        str         _costPrice,
                                        str         _billCode,
                                        str         _department,
                                        str         _costCenter,
                                        str         _employee,
                                        str         _NEW_OR_CANCEL_IND,
                                        str         _company,
                                        RecId       _InvTableRecId,
                                        LedgerDimensionDefaultAccount _defaultAccount)
{
    AxLedgerJournalTable    journalTable;
    AxLedgerJournalTrans    journalTransCredit,journalTransDebit;
    container               acctPattern;
    container               offSetAcctPattern;
    LedgerJournalTable      ledgerJournalTable,ledgerJournalTableUpdate;
    ledgerJournalCheckPost  ledgerJournalCheckPost;
    LedgerJournalTable      ledgerjournalTableDelete;
    LedgerJournalTrans      journalTransDelete;
    SalesParameters         SalesParameters;//JournalNameId;
    DimAttributeCustTable   DimAttributeCustTable;
    DimensionAttributeValueCombination valueCombination;
    CustInvoiceTable        custInvoiceTable;
    CustParameters  CustParameters;
    System.Exception        ex;
    str                     errorStr;
    LedgerJournalId         journalId;
    LedgerJournalPost       LedgerJournalPost;
    Args args = new Args();
    ;
    changeCompany(_company)
    {
        try
        {
            SalesParameters = SalesParameters::find();
            journalTable = new AxLedgerJournalTable();
            journalTransCredit = new AxLedgerJournalTrans();


            journalTable.parmJournalName(SalesParameters.JournalNameId);
           //journalTable.parmDefaultDimension(this.retDefaultDimension(_businessUnit,_department,_costCenter,_employee));
            journalTable.save();

            ledgerJournalTable = journalTable.ledgerJournalTable();

            select valueCombination where valueCombination.DisplayValue == _cutomer
                                       && valueCombination.LedgerDimensionType == LedgerDimensionType::Account
                                       && !valueCombination.MainAccount
                                       && !valueCombination.AccountStructure;

            journalTransCredit.parmJournalNum(ledgerJournalTable.JournalNum);
            journalTransCredit.parmTransDate(systemDateGet());
            journalTransCredit.parmAmountCurCredit(_amount);
            journalTransCredit.parmAccountType(LedgerJournalACType::Cust);
            journalTransCredit.parmLedgerDimension(valueCombination.RecId);
            journalTransCredit.parmDefaultDimension(_defaultAccount);
            CustParameters = CustParameters::find();

            if(_NEW_OR_CANCEL_IND == "C")
            {
                journalTransCredit.parmPostingProfile(CustParameters.PrepaymentPostingProfile);
            }
            else if(_NEW_OR_CANCEL_IND == "N")
            {
                journalTransCredit.parmPostingProfile(CustParameters.PostingProfile);
            }
            journalTransCredit.save();


            journalTransDebit = new AxLedgerJournalTrans();

            journalTransDebit.parmJournalNum(ledgerJournalTable.JournalNum);
            journalTransDebit.parmTransDate(systemDateGet());
            journalTransDebit.parmAmountCurDebit(_amount);
            journalTransDebit.parmAccountType(LedgerJournalACType::Cust);
            journalTransDebit.parmLedgerDimension(valueCombination.RecId);
            journalTransDebit.parmDefaultDimension(_defaultAccount);
            if(_NEW_OR_CANCEL_IND == "C")
            {
                journalTransDebit.parmPostingProfile(CustParameters.PostingProfile);
            }
            else if(_NEW_OR_CANCEL_IND == "N")
            {
                journalTransDebit.parmPostingProfile(CustParameters.PrepaymentPostingProfile);
            }
            journalTransDebit.save();

            ledgerJournalCheckPost              = LedgerJournalCheckPost::newLedgerJournalTable(ledgerJournalTable,Noyes::Yes);
            ledgerJournalCheckPost.run();

            return journalTransDebit.parmVoucher() + "," + journalTable.parmJournalNum();
        }
        catch(Exception::CLRError)
        {

            ex = ClrInterop::getLastException();
            if (ex != null)
            {
                ex = ex.get_InnerException();
                if (ex != null)
                {
                    error(ex.ToString());
                }
            }
            errorStr = "Error while Posting the General Journal Entry.";// + ex.ToString();
            delete_from journalTransDelete wherejournalTransDelete.JournalNum == journalId;
            delete_from ledgerjournalTableDelete whereledgerjournalTableDelete.JournalNum == journalId;
           //this.updateErrorInventMovement(sqlConGlobal,kRODBCParameters,itemIdStr,wareHouseStr,batchIdStr,businessUnitStr,costPriceStr,errorStr);
            this.insertErrorLogDetails(errorStr,_businessUnit,_itemId,_batchId,_qty,_costPrice,_billCode,_company);
            return "";
        }
    }


}





my code:


example:

in my form I wrote the journal posting method in form methods as


//[SysEntryPointAttribute(true)]
public void createGeneralJournalAndPost(Amount _shipnow)
{
    AxLedgerJournalTable    journalTable;
    AxLedgerJournalTrans    journalTransCredit,journalTransDebit;
    container               acctPattern;
    container               offSetAcctPattern;
    LedgerJournalTable      ledgerJournalTable,ledgerJournalTableUpdate;
    ledgerJournalCheckPost  ledgerJournalCheckPost;
    LedgerJournalTable      ledgerjournalTableDelete;
    LedgerJournalTrans      journalTransDelete;
    SalesParameters         SalesParameters;//JournalNameId;
    DimAttributeCustTable   DimAttributeCustTable;
    DimensionAttributeValueCombination valueCombination;
    CustInvoiceTable        custInvoiceTable;
    LedgerParameters        LedgerParameters;
    System.Exception        ex;
    str                     errorStr;
    LedgerJournalId         journalId;
    LedgerJournalPost       LedgerJournalPost;
    InventParameters        InventParameters;
    Amount                  markvalue;
    InventTransferTable InventTransferTable1;
    str s;

           markvalue = InventTransferTable.markupvalue(_shipnow);

            journalTable = new AxLedgerJournalTable();
            journalTransCredit = new AxLedgerJournalTrans();

              InventParameters = InventParameters::find();
            journalTable.parmJournalName(InventParameters.JournalNameId);
           // journalTable.parmTransferRecId(InventTransferTable.RecId);
            journalTable.parmDefaultDimension(InventTransferTable.DefaultDimension);
            journalTable.save();

            ledgerJournalTable = journalTable.ledgerJournalTable();

            ttsBegin;
            select forUpdate ledgerJournalTableUpdate  whereledgerJournalTableUpdate.JournalNum == ledgerJournalTable.JournalNum;
            ledgerJournalTableUpdate.TransferRefRecId = InventTransferTable.RecId;
            ledgerJournalTableUpdate.update();
            ttsCommit;
            journalTransCredit.parmJournalNum(ledgerJournalTable.JournalNum);

            journalTransCredit.parmTransDate(systemDateGet());
            journalTransCredit.parmAmountCurCredit(round(markvalue,2));
            journalTransCredit.parmAccountType(LedgerJournalACType::Ledger);
            journalTransCredit.parmLedgerDimension(InventParameters.RevenueDimension);
            journalTransCredit.parmDefaultDimension(InventTransferTable.DefaultDimension);
            LedgerParameters = LedgerParameters::find();
            journalTransCredit.parmOffsetLedgerDimension(InventParameters.LedgerDimension);

            journalTransCredit.save();

            ledgerJournalCheckPost              = LedgerJournalCheckPost::newLedgerJournalTable(ledgerJournalTable,Noyes::Yes);
            ledgerJournalCheckPost.run();
            //if (this.showInfo())
            //info(strFmt("%1,%2-%3",journalTable.parmJournalNum(),journalTransCredit.parmVoucher(),SysInfoAction_TableField::newBuffer(LedgerJournalTable)));
info(strfmt("%1", journalTable.parmJournalNum()),'',SysInfoAction_TableField::newBuffer(LedgerJournalTable));
//////////////////this above line I wrote for showing show button
    }
//}




When the general journal posted info box opened
Here we click on show button its go to current journal record.
For this functionality we can follow this procedure
Create one int64 field in ledgerjournal table(ex: TransferRefRecId)
And give the relation in ledgerjournal table to what ever table ur using that table(ex:I used the InventTransferTable)
(Then I am giving the relation as ledgerjournaltable. TransferRefRecId == InventTransferTable.recid)
After that where the journal posting method u write this following code
info(strfmt("%1", journalTable.parmJournalNum()),'',SysInfoAction_TableField::newBuffer( LedgerJournalTable));


==================https://hellodax.com/2015/06/22/auto-settle-from-custtransopen-when-create-journal-payment-lines-via-x/========================

Auto settle from custTransOpen when create journal payment lines via x++

example code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
public static void autoSettlementJournalFromPAYDetails(JournalId    _journalNum)
{
    CustVendOpenTransManager manager;
    CustTrans                custTrans;
    CustTransOpen            custTransOpen;
    LedgerJournalTrans       ledgerJournalTrans;
    AxLedgerJournalTable     axLedgerJournalTable;
    AxLedgerJournalTrans     axLedgerJournalTrans;
    ExchangeRateHelper       exchangeRateHelper;
    AmountCur                totalSettleAmount;
    AmountCur                amountCurDebit,amountCurCredit;
    HRSPayJournalDetails     hrsPayJournalDetails;
    HRSPayJournalTable       hrsPayJournalTable;
     
    int                      Row;


    AxLedgerJournalTable = AxLedgerJournalTable::newLedgerJournalTable(LedgerJournalTable::find(_journalNum));
    ttsBegin;
    //details journal lines from Pay Journal Details
    while select hrsPayJournalTable
    join hrsPayJournalDetails
    where
        hrsPayJournalTable.HRSPayJournalId == hrsPayJournalDetails.HRSPayJournalId
    &&  HRSPayJournalTable.JournalNum      == _journalNum
    {
        CustTrans    = CustTrans::findFromInvoice(hrsPayJournalDetails.ReferenceNumber,HRSPayJournalDetails.AccountNum);
        CustTransOpen  = CustTransOpen::findRefId(CustTrans.RecId);

        if(CustTransOpen)
        {

           //Create Trans ...
            axLedgerJournalTrans = new axLedgerJournalTrans();
            axLedgerJournalTrans.parmJournalNum(AxLedgerJournalTable.ledgerJournalTable().JournalNum);

            axLedgerJournalTrans.parmTransDate(today());
            axLedgerJournalTrans.parmDue(today());
            axLedgerJournalTrans.parmAccountType(LedgerJournalACType::Cust);
            axLedgerJournalTrans.parmLedgerDimension(DimensionStorage::getDynamicAccount(hrsPayJournalDetails.AccountNum, LedgerJournalACType::Cust));
            axLedgerJournalTrans.parmAmountCurCredit(hrsPayJournalDetails.Credit);
            axLedgerJournalTrans.parmAmountCurDebit(hrsPayJournalDetails.Debit);
            axLedgerJournalTrans.save();

            manager = CustVendOpenTransManager::construct(axLedgerJournalTrans.ledgerJournalTrans());
            manager.updateTransMarked(custTransOpen,true);
            if(hrsPayJournalDetails.Debit)
            {
                manager.updateSettleAmount(custTransOpen,hrsPayJournalDetails.Debit);
            }
            else
            {
                manager.updateSettleAmount(custTransOpen,hrsPayJournalDetails.Credit);
            }

            //update after settle
            ledgerJournalTrans = axLedgerJournalTrans.ledgerJournalTrans();
            ledgerJournalTrans.selectForUpdate(true);
            ledgerJournalTrans.SettleVoucher =  SettlementType::SelectedTransact;
            ledgerJournalTrans.update();
            Row++;
        }

    }
    ttsCommit;
     
    info(strFmt("Total Lines settled : %1",Row));

}








==============https://community.dynamics.com/ax/b/axrajdipdas/archive/2013/04/16/dynamics-ax-2012-x-code-to-create-amp-post-general-journal=============

tatic void Raj_Demo_CreateGLJournalPost(Args _args)
{
    AxLedgerJournalTable    journalTable;
    AxLedgerJournalTrans    journalTrans;
    container               acctPattern;
    container               offSetAcctPattern;
    LedgerJournalTable      ledgerJournalTable;
    ledgerJournalCheckPost  ledgerJournalCheckPost;
    ;

    journalTable = new AxLedgerJournalTable();
    journalTrans = new AxLedgerJournalTrans();

    //Journal Name
    journalTable.parmJournalName("GenJrn");
    journalTable.save();

   journalTrans.parmJournalNum(journalTable.ledgerJournalTable().JournalNum);
    journalTrans.parmTransDate(systemDateGet());
    journalTrans.parmCurrencyCode("USD");
    journalTrans.parmAmountCurDebit(200);
   
   journalTrans.parmAccountType(LedgerJournalACType::Ledger);
    acctPattern = ["211345-Disp","211345"2,"Department","00000014""CostCenter""00000007"];
   journalTrans.parmLedgerDimension(AxdDimensionUtil::getLedgerAccountId(acctPattern));       
   
   journalTrans.parmOffsetAccountType(LedgerJournalACType:: Ledger );
    offSetAcctPattern = ["401100-Disp","401100"4,"Department","00000014""CostCenter""00000007","CustomPurposeA","Nile""CustomPurposeB""Site2" ];    
   journalTrans.parmOffsetLedgerDimension(AxdDimensionUtil::getLedgerAccountId( offSetAcctPattern));   
   
    journalTrans.save();   
   
    ledgerJournalCheckPost = ledgerJournalCheckPost::newLedgerJournalTable(journalTable.ledgerJournalTable(),NoYes::Yes);
    ledgerJournalCheckPost.run();  
   

    info(strFmt("Journal No. %1.", journalTable.ledgerJournalTable().JournalNum));
}






====https://dynamicsuser.net/ax/f/developers/74951/how-to-get-asset-id-from-dimensions=====
Create a Fixed Asset Journal say Journal Number ''FA00001' and hardcode it in journalTrans.parmJournalNum(); in below code.
static void FixedAssetJournal(Args _args)
// AxLedgerJournalTable    journalTable;
    AxLedgerJournalTrans    journalTrans;
    container               acctPattern;
    container               offSetAcctPattern;
    LedgerJournalTable      ledgerJournalTable;
    ledgerJournalCheckPost  ledgerJournalCheckPost;

    NumberSeq NumberSeq;

    LedgerJournalTrans_Asset    ledgerJournalTrans_Asset
    str AssetId = 00001;//todo: Provide valid assetId
    ;


         NumberSeq =NumberSeq::newGetNumFromCode(LedgerParameters::numRefLedgerJournalizeNum().numberSequenceTable().NumberSequence);
        //journalTable = new AxLedgerJournalTable();
        journalTrans = new AxLedgerJournalTrans();
        journalTrans.parmVoucher(NumberSeq.num());

        //Journal Name
       // journalTable.parmJournalName("GenJrn");
        //journalTable.save();

        //journalTrans.parmJournalNum(journalTable.ledgerJournalTable().JournalNum);
        //todo: Change Journal Number w.r.t requirement
        journalTrans.parmJournalNum('FA00001');//todo: provide journal number

        journalTrans.parmTransDate(today());
        //Fixed asset Id
        journalTrans.parmLedgerDimension(DimensionStorage::getDynamicAccount(AssetId,LedgerJournalACType::FixedAssets));

        journalTrans.parmCurrencyCode("USD");

        journalTrans.parmAmountCurCredit(20);
        journalTrans.parmAmountCurDebit(0);

        journalTrans.parmAccountType(LedgerJournalACType::FixedAssets);
        journalTrans.parmDefaultDimension(AssetTable::find(AssetId).defaultDimension(AssetId));

        journalTrans.parmOffsetAccountType(LedgerJournalACType:: Ledger );
        journalTrans.parmOffsetLedgerDimension(OffsetLedgerDimension);//Todo: offset dim
        //journalTrans.parmOffsetLedgerDimension(DimensionDefaultingService::serviceCreateLedgerDimension(0,
        //            AssetTable::find(FATransAcqTmp.AssetId).defaultDimension(FATransAcqTmp.AssetId)));

    //    journalTrans.parmOffsetLedgerDimension(AxdDimensionUtil::getLedgerAccountId( offSetAcctPattern));

        journalTrans.save();


        if (journalTrans.ledgerJournalTrans().isFixedAssetsTransaction())
            {
                ledgerJournalTrans_Asset.clear();
                ledgerJournalTrans_Asset.initValue();

                ledgerJournalTrans_Asset.RefRecId  = journalTrans.ledgerJournalTrans().RecId;
                ledgerJournalTrans_Asset.AssetId   = journalTrans.ledgerJournalTrans().getAssetId();
                ledgerJournalTrans_Asset.Company   = journalTrans.ledgerJournalTrans().getAssetCompany();
                ledgerJournalTrans_Asset.TransType = AssetTransTypeJournal::Acquisition;
                ledgerJournalTrans_Asset.BookId    = 'SL';//Todo: Provide valid asset book id

                if (!ledgerJournalTrans_Asset.validateWrite())
                    throw Exception::Error;

                ledgerJournalTrans_Asset.insert();

    }
        info('Insert');
}





=====https://hellodax.com/2015/01/22/upload-a-ledgerjournaltrans-fixed-asset-type-without-insert-to-ledgerjournaltrans_asset-table/====

Upload a LedgerJournalTrans Fixed Asset type without insert to LedgerJournalTrans_Asset table

an error will occured when you try validate ledgerJournalTrans.
how to fix this :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
static void TIDF_fixBugsUploadFixedAssets(Args _args)
{
    ledgerjournaltrans ledgerJournalTrans;
    LedgerJournalTrans_Asset    cekExist;
    LedgerJournalTrans_Asset    LedgerJournalTrans_Asset;
     
    while select  ledgerJournalTrans
    where
        ledgerJournalTrans.JournalNum == 'GEN-000007'
    {
        select cekExist where cekExist.RefRecId == ledgerJournalTrans.RecId;
         
         if (ledgerJournalTrans.isFixedAssetsTransaction() && !cekExist)
            {
                ledgerJournalTrans_Asset.clear();
                ledgerJournalTrans_Asset.initValue();

                ledgerJournalTrans_Asset.RefRecId  = ledgerJournalTrans.RecId;
                ledgerJournalTrans_Asset.AssetId   = ledgerJournalTrans.getAssetId();
                ledgerJournalTrans_Asset.Company   = ledgerJournalTrans.getAssetCompany();
                ledgerJournalTrans_Asset.TransType = AssetTransTypeJournal::Acquisition;
                ledgerJournalTrans_Asset.BookId    = "ALL";

                if (!ledgerJournalTrans_Asset.validateWrite())
                    throw Exception::Error;

                ledgerJournalTrans_Asset.insert();
            }
    }


}



0 comments:

A financial dimension value is based on the LAND-00013 record and has been used on a transaction. You cannot delete the LAND-00013 record AX 2012

 A financial dimension value is based on the LAND-00013 record and has been used on a  transaction. You cannot delete the LAND-00013 record ...