Tags

, , , , ,

static void LedgerTransImport(Args _args)

{

    Voucher                         voucherNum;

    #define.Name(“Gen”)

    #define.Account(“110180”)

    #define.OffsetAccount(“999999”)

    #define.BusinessUnit(“001”)

    #define.Department(“022”)

    #define.CostCenter(“007”)

    #define.ItemGroup(“Audio”)

    #define.Text(“Test”)

    #define.Currency(“USD”)

    #define.Debit(100)

    #define.Credit(0)

    LedgerJournalName   ledgerJournalName;

    LedgerJournalTable  ledgerJournalTable;

    LedgerJournalTrans  ledgerJournalTrans;

     try

    {

        ttsbegin;

         ledgerJournalName = LedgerJournalName::find(#Name);

         if (ledgerJournalName)

        {

            //Journal header

            ledgerJournalTable.clear();

            ledgerJournalTable.initValue();

 

            ledgerJournalTable.initFromLedgerJournalName(ledgerJournalName.JournalName);

            ledgerJournalTable.JournalNum = NumberSeq::newGetNum(LedgerParameters::numRefJournalNum()).num();

            //ledgerJournalTable.JournalNum = NumberSeq::newGetNum(LedgerParameters::numRefJournalNum()).num();

            ledgerJournalTable.Name = #Description;

             if (ledgerJournalTable.validateWrite())

            {

                ledgerJournalTable.insert();

                 //Journal line

                ledgerJournalTrans.clear();

                ledgerJournalTrans.initValue();

                 ledgerJournalTrans.JournalNum = ledgerJournalTable.JournalNum;

                ledgerJournalTrans.TransDate = systemDateGet();

                voucherNum = new JournalVoucherNum(JournalTableData::newTable(ledgerJournalTable)).getNew(false);

               ledgerJournalTrans.Voucher = #Voucher;

               ledgerJournalTrans.Voucher      = voucherNum;

                ledgerJournalTrans.AccountType = LedgerJournalACType::Ledger;

                ledgerJournalTrans.parmLedgerDimension(AxdDimensionUtil::getLedgerAccountId(

                [strFmt(“%1-%2-%3”, #Account, #BusinessUnit, #Department),

                #Account, 2, “BusinessUnit”, #BusinessUnit, “Department”, #Department]));

                ledgerJournalTrans.OffsetAccountType = LedgerJournalACType::Ledger;

                ledgerJournalTrans.parmOffsetLedgerDimension(AxdDimensionUtil::getLedgerAccountId(

                [strFmt(“%1-%2-%3-%4-%5”, #OffsetAccount, #BusinessUnit, #Department, #CostCenter, #ItemGroup),

                #OffsetAccount, 4, “BusinessUnit”, #BusinessUnit, “Department”, #Department, “CostCenter”, #CostCenter, “ItemGroup”, #ItemGroup]));

                 ledgerJournalTrans.Txt = #Text;

                 ledgerJournalTrans.CurrencyCode = #Currency;

                ledgerJournalTrans.AmountCurDebit = #Debit;

                ledgerJournalTrans.AmountCurCredit = #Credit;

                 if (ledgerJournalTrans.validateWrite())

                {

                    ledgerJournalTrans.insert();

                }

                else

                    throw error(“Journal line”);

            }

            else

                throw error(“Journal header”);

        }

        else

            throw error(“Journal name”);

         ttscommit;

    }

    catch

    {

        error(“Error!”);

        return;

    }

     info(“Done!”);

}

Advertisements