Thursday, May 15, 2014

Journal Creation Method in Class

// Journal Creation Method in Class

private void JournalCreation( System.Data.SqlClient.SqlDataReader   dr1)
{

    NumberSequenceTable                 numberSequenceTable;

    Voucher                             voucher;
    Amount                              amountCurDebit,amountCurCredit;

    AxLedgerJournalTrans                trans  = new AxLedgerJournalTrans();
    AxLedgerJournalTable                header ;//= new AxLedgerJournalTable();

    str                                 description;
    str                                 Agreement,Category,Department,Division,Employee,ProductManagers,Project,Publisher,Region,Salesmen;

    DimensionStorage                    DimensionStorage;
    LedgerJournalNameId                 LedgerJournalNameId;
    CurrencyCode                        currencycode;
    TransDate                           TransDate = today();

    LedgerAccountContract               ledgerAccountContract,OffledgerAccountContract;
    MainAccountNum                      mainAccount;
    mainAccountNum                      OffmainAccount ;
    DimensionAttributeValueContract     attributeValueContract;

    LedgerJournalCheckPost              ledgerJournalCheckPost;

    ;

    ttsBegin;

    header = new AxLedgerJournalTable();
    LedgerJournalNameId = "GenJrn";
    header.parmJournalName(LedgerJournalNameId);

    header.save();

    numberSequenceTable = NumberSequenceTable::find(LedgerJournalName::find(LedgerJournalNameId).NumberSequenceTable);

    voucher =  NumberSeq::newGetVoucherFromId(numberSequenceTable.RecId).voucher();

    mainAccount     = dr1.get_Item('Account');
    OffmainAccount  = dr1.get_Item('OffsetAccount');

    amountCurDebit  = dr1.get_Item('Debit');
    amountCurCredit = dr1.get_Item('Credit');

    description  = dr1.get_Item('Txt');
    currencycode = dr1.get_Item('Currency');

    Employee        = dr1.get_Item('Dimension1');
    ProductManagers = dr1.get_Item('Dimension2');
    Project         = dr1.get_Item('Dimension3');
    Publisher       = dr1.get_Item('Dimension4');
    Region          = dr1.get_Item('Dimension5');

    trans.parmJournalNum(header.ledgerJournalTable().JournalNum);

    //AccountNum
    ledgerAccountContract = new LedgerAccountContract();
    ledgerAccountContract.parmValues(new List(Types::Class));

    ledgerAccountContract.parmMainAccount(mainAccount);
    if (Employee)
    {
        attributeValueContract = new DimensionAttributeValueContract();
        attributeValueContract.parmName("Employee");
        attributeValueContract.parmValue(Employee);

        ledgerAccountContract.parmValues().addEnd(attributeValueContract);
    }
    if (ProductManagers)
    {
        attributeValueContract = new DimensionAttributeValueContract();
        attributeValueContract.parmName("ProductManagers");
        attributeValueContract.parmValue(ProductManagers);

        ledgerAccountContract.parmValues().addEnd(attributeValueContract);
    }
    if (Project)
    {
        attributeValueContract = new DimensionAttributeValueContract();
        attributeValueContract.parmName("Project");
        attributeValueContract.parmValue(Project);

        ledgerAccountContract.parmValues().addEnd(attributeValueContract);
    }
    if (Publisher)
    {
        attributeValueContract = new DimensionAttributeValueContract();
        attributeValueContract.parmName("Publisher");
        attributeValueContract.parmValue(Publisher);

        ledgerAccountContract.parmValues().addEnd(attributeValueContract);
    }
    if (Region)
    {
        attributeValueContract = new DimensionAttributeValueContract();
        attributeValueContract.parmName("Region");
        attributeValueContract.parmValue(Region);

        ledgerAccountContract.parmValues().addEnd(attributeValueContract);
    }

    dimensionStorage = DimensionServiceProvider::buildDimensionStorageForLedgerAccount(ledgerAccountContract);

    trans.parmLedgerDimension(dimensionStorage.save());
    //-------------------------------------
    //OffsetAccount
    OffledgerAccountContract = new LedgerAccountContract();
    OffledgerAccountContract.parmValues(new List(Types::Class));
    Employee        = dr1.get_Item('Dimension1');
    ProductManagers = dr1.get_Item('Dimension2');
    Project         = dr1.get_Item('Dimension3');
    Publisher       = dr1.get_Item('Dimension4');
    Region          = dr1.get_Item('Dimension5');

    OffledgerAccountContract.parmMainAccount(OffmainAccount);
    if (Employee)
    {
        attributeValueContract = new DimensionAttributeValueContract();
        attributeValueContract.parmName("Employee");
        attributeValueContract.parmValue(Employee);

        OffledgerAccountContract.parmValues().addEnd(attributeValueContract);
    }
    if (ProductManagers)
    {
        attributeValueContract = new DimensionAttributeValueContract();
        attributeValueContract.parmName("ProductManagers");
        attributeValueContract.parmValue(ProductManagers);

        OffledgerAccountContract.parmValues().addEnd(attributeValueContract);
    }
    if (Project)
    {
        attributeValueContract = new DimensionAttributeValueContract();
        attributeValueContract.parmName("Project");
        attributeValueContract.parmValue(Project);

        OffledgerAccountContract.parmValues().addEnd(attributeValueContract);
    }
    if (Publisher)
    {
        attributeValueContract = new DimensionAttributeValueContract();
        attributeValueContract.parmName("Publisher");
        attributeValueContract.parmValue(Publisher);

        OffledgerAccountContract.parmValues().addEnd(attributeValueContract);
    }
    if (Region)
    {
        attributeValueContract = new DimensionAttributeValueContract();
        attributeValueContract.parmName("Region");
        attributeValueContract.parmValue(Region);

        OffledgerAccountContract.parmValues().addEnd(attributeValueContract);
    }

    dimensionStorage = DimensionServiceProvider::buildDimensionStorageForLedgerAccount(OffledgerAccountContract);

    trans.parmOffsetLedgerDimension(dimensionStorage.save());
    //------------------------------------
    trans.parmTxt(description);

    trans.parmDocumentDate(today());
    trans.parmTransDate(today());

    trans.parmAmountCurDebit(AmountCurDebit);

    trans.parmAmountCurCredit(AmountCurCredit) ;

    trans.parmCompany(curext());
    trans.parmCurrencyCode(currencycode);
    trans.parmVoucher(voucher);
    trans.parmExchRate(1);
    trans.currentRecord().insert();

    trans.save();

    //ledgerJournalCheckPost= ledgerJournalCheckPost::newLedgerJournalTable(header.ledgerJournalTable(),NoYes::Yes);
    //ledgerJournalCheckPost.run();

    info(header.ledgerJournalTable().JournalNum);

    ttsCommit;

}

No comments:

Post a Comment

Convert Call stack to readable format in D365FO X++

//Input --container _xppCallStack = xSession::xppCallStack();  Public static str POL_formatXppCallStack(container _xppCallStack, int _skipFr...