Payment attach multiple invoices

I need some help to settle my invoices with x++ in axapta ax4

static void LedgerJournal(Args _args)

{

LedgerJournalName LedgerJournalName;

LedgerJournalTable ledgerJournalTable;

LedgerJournalTrans ledgerJournalTrans;

LedgerJournalCheckPost ledgerJournalCheckPost;

NumberSeq numberseq;

LedgerJournalNameId LedgerJournalNameId = ‘GenJrn’;

BankAccountID BankAccountID = ‘EUR OPER’;

ledgerAccount offsetAccount = ‘601500’;

amountCur amountCur = 102;

;

ttsbegin;

// Find a ledgerJournalName record

select firstonly LedgerJournalName

where LedgerJournalName.JournalName ==LedgerJournalNameId;

//Created the ledgerJournalTable

ledgerJournalTable.JournalName =LedgerJournalName.JournalName;

ledgerJournalTable.initFromLedgerJournalName();

ledgerJournalTable.Name = ‘Hotel’;

ledgerJournalTable.insert();

numberseq =NumberSeq::newGetVoucherFromCode(ledgerJournalName.VoucherSeries);

ledgerJournalTrans.Voucher = numberseq.voucher();

//Generate the transaction line

ledgerJournalTrans.JournalNum =ledgerJournalTable.JournalNum;

ledgerJournalTrans.CurrencyCode = ‘EUR’;

ledgerJournalTrans.ExchRate =Currency::exchRate(ledgerJournalTrans.CurrencyCode);

ledgerJournalTrans.AccountNum = BankAccountID;

ledgerJournalTrans.AccountType =LedgerJournalACType::Bank;

ledgerJournalTrans.AmountCurCredit = amountCur;

//Pass the Date . You can also use str2Date(‘08/08/2008’) if period is not defined.

ledgerJournalTrans.TransDate = today();

ledgerJournalTrans.Txt = ‘Room Stay’;

ledgerJournalTrans.OffsetAccount = offsetAccount;

ledgerJournalTrans.OffsetAccountType =LedgerJournalACType::Ledger;

ledgerJournalTrans.insert();

info(strfmt(‘Journal Id:%1’,ledgerJournalTable.JournalNum));

//Post the Journal

ledgerJournalCheckPost= ledgerJournalCheckPost::newLedgerJournalTable(ledgerJournalTable,NoYes::Yes);

ledgerJournalCheckPost.run();

ttscommit;

/*while select ledgerJournalTrans order by recId desc

where ledgerJournalTrans.DocumentNum == localJournalTrans.DocumentNum

{

custTransOpen = CustTransOpen::findRefId(CustTrans::findVoucherDate (ledgerJournalTrans.Voucher, ledgerJournalTrans.TransDate).RecId);

//check correction payment

amountSettled = abs(custTransOpen.AmountCur);

//get amount

if(ledgerJournalTrans.AmountCurCredit > 0)

amountReceived = abs(ledgerJournalTrans.AmountCurCredit) *-1;

if(ledgerJournalTrans.AmountCurDebit > 0)

amountReceived = ledgerJournalTrans.AmountCurDebit;

//create settlement based on custTransOpen

specification = Specification::construct(SpecType::OffsetVoucher, localJournalTrans.TableId, localJournalTrans.RecId);

specification.create(custTransOpen.TableId, custTransOpen.RecId, amountReceived, localJournalTrans.CurrencyCode, NoYes::Yes);

}*/

}

i got this code of the internet the bottem part i suspect settle invoices but i need some sort of while en i think this code is for 2009.

Please help