create and post invoice journal ax 2012
public void createpostInvoiceJournal(ProjInvoiceJour projInvoiceJour)
{
LedgerJournalCheckPost jourCheckPost;
LedgerJournalTable jourTable;
AxLedgerJournalTable header = new AxLedgerJournalTable();
AxLedgerJournalTrans trans = new AxLedgerJournalTrans();
container offsetDim;
GeneralJournalAccountEntry generalJournalAccountEntry;
GeneralJournalEntry generalJournalEntry;
ProjParameters projParameters;
ProjJournalTrans projJournalTrans;
DimensionAttributeValueSetStorage dimStorage;
Str worker;
Counter i;
// The AP invoice journal name, could vary.
LedgerJournalNameId ledgerJournalNameId;
// This is the entry against the Vendor account.
// It will have to pre-exist for this script to work.
// It is probably created the first time such an entry is
// made on a journal line.
DimensionAttributeValueCombination davc;
LedgerJournalACType accType, offsetAccType;
BankAccountTable bankAccountTable;
accType = LedgerJournalACType::Vend;
offsetAccType = LedgerJournalACType::Ledger;
select projParameters;
ledgerJournalNameId = projParameters.JournalName;
header.parmJournalName(ledgerJournalNameId);
header.parmJournalType(LedgerJournalType::VendInvoiceRegister);
header.save();
select generalJournalEntry
join generalJournalAccountEntry where generalJournalEntry.JournalNumber == GeneralJournalEntry::findBySubledgerVoucher(projInvoiceJour.LedgerVoucher,curext()).JournalNumber
&& generalJournalAccountEntry.GeneralJournalEntry == generalJournalEntry.RecId
&& generalJournalAccountEntry.PostingType == LedgerPostingType::ProjPayrollAllocation;
trans.parmAccountType(accType);
trans.parmJournalNum(header.ledgerJournalTable().JournalNum);
trans.parmInvoice(projInvoiceJour.ProjInvoiceId);
//First is Display value, followed by Main Account and then dimensions.
trans.parmAccountType(LedgerJournalACType::Vend);
// Note: This only works if the DimensionValueAttributeCombindation record
// exists from before.
select projJournalTrans where projJournalTrans.ProjId == projInvoiceJour.ProjInvoiceProjId;
select firstonly RecId from davc
where davc.DisplayValue == projJournalTrans.ALE_AccountNum;// "202-000300"; //Vendor123 is the vendor account number.
trans.parmLedgerDimension(davc.RecId);
//There's a parm method for credit as well. generalJournalAccountEntry.
trans.parmAmountCurDebit(generalJournalAccountEntry.AccountingCurrencyAmount);
trans.parmOffsetAccountType(offsetAccType);
trans.clearField(fieldNum(ledgerJournalTrans, offsetLedgerDimension), false);
trans.parmOffsetLedgerDimension(generalJournalAccountEntry.LedgerDimension);
dimStorage = DimensionAttributeValueSetStorage::find(generalJournalAccountEntry.LedgerDimension);
for (i= 1 ; i<= dimStorage.elements() ; i++)
{
if(DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name == "worker")
{
worker = dimStorage.getDisplayValueByIndex(i);
}
}
trans.parmApprover(str2int(worker));
trans.parmApproved(NoYes::Yes);
trans.save();
jourTable = header.ledgerJournalTable();
if (jourTable.RecId > 0)
{
jourCheckPost = ledgerJournalCheckPost::newLedgerJournalTable(jourTable,
NoYes::Yes,
NoYes::Yes);
// Post only if there is succesful validation.
//if (jourCheckPost.validate())
{
jourCheckPost.run();
}
}
}
public void createpostInvoiceJournal(ProjInvoiceJour projInvoiceJour)
{
LedgerJournalCheckPost jourCheckPost;
LedgerJournalTable jourTable;
AxLedgerJournalTable header = new AxLedgerJournalTable();
AxLedgerJournalTrans trans = new AxLedgerJournalTrans();
container offsetDim;
GeneralJournalAccountEntry generalJournalAccountEntry;
GeneralJournalEntry generalJournalEntry;
ProjParameters projParameters;
ProjJournalTrans projJournalTrans;
DimensionAttributeValueSetStorage dimStorage;
Str worker;
Counter i;
// The AP invoice journal name, could vary.
LedgerJournalNameId ledgerJournalNameId;
// This is the entry against the Vendor account.
// It will have to pre-exist for this script to work.
// It is probably created the first time such an entry is
// made on a journal line.
DimensionAttributeValueCombination davc;
LedgerJournalACType accType, offsetAccType;
BankAccountTable bankAccountTable;
accType = LedgerJournalACType::Vend;
offsetAccType = LedgerJournalACType::Ledger;
select projParameters;
ledgerJournalNameId = projParameters.JournalName;
header.parmJournalName(ledgerJournalNameId);
header.parmJournalType(LedgerJournalType::VendInvoiceRegister);
header.save();
select generalJournalEntry
join generalJournalAccountEntry where generalJournalEntry.JournalNumber == GeneralJournalEntry::findBySubledgerVoucher(projInvoiceJour.LedgerVoucher,curext()).JournalNumber
&& generalJournalAccountEntry.GeneralJournalEntry == generalJournalEntry.RecId
&& generalJournalAccountEntry.PostingType == LedgerPostingType::ProjPayrollAllocation;
trans.parmAccountType(accType);
trans.parmJournalNum(header.ledgerJournalTable().JournalNum);
trans.parmInvoice(projInvoiceJour.ProjInvoiceId);
//First is Display value, followed by Main Account and then dimensions.
trans.parmAccountType(LedgerJournalACType::Vend);
// Note: This only works if the DimensionValueAttributeCombindation record
// exists from before.
select projJournalTrans where projJournalTrans.ProjId == projInvoiceJour.ProjInvoiceProjId;
select firstonly RecId from davc
where davc.DisplayValue == projJournalTrans.ALE_AccountNum;// "202-000300"; //Vendor123 is the vendor account number.
trans.parmLedgerDimension(davc.RecId);
//There's a parm method for credit as well. generalJournalAccountEntry.
trans.parmAmountCurDebit(generalJournalAccountEntry.AccountingCurrencyAmount);
trans.parmOffsetAccountType(offsetAccType);
//offsetDim = ["52121-Disp", "52121", 2, "Site", "12345", "Department", "204"];
//52121-12345-204,"52121",2,"site",12345,'dep',204
//main account and other dim followed by - and no of dim//trans.parmOffsetLedgerDimension(AxdDimensionUtil::getLedgerAccountId(offsetDim));
trans.clearField(fieldNum(ledgerJournalTrans, offsetLedgerDimension), false);
trans.parmOffsetLedgerDimension(generalJournalAccountEntry.LedgerDimension);
dimStorage = DimensionAttributeValueSetStorage::find(generalJournalAccountEntry.LedgerDimension);
for (i= 1 ; i<= dimStorage.elements() ; i++)
{
if(DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name == "worker")
{
worker = dimStorage.getDisplayValueByIndex(i);
}
}
trans.parmApprover(str2int(worker));
trans.parmApproved(NoYes::Yes);
trans.save();
jourTable = header.ledgerJournalTable();
if (jourTable.RecId > 0)
{
jourCheckPost = ledgerJournalCheckPost::newLedgerJournalTable(jourTable,
NoYes::Yes,
NoYes::Yes);
// Post only if there is succesful validation.
//if (jourCheckPost.validate())
{
jourCheckPost.run();
}
}
}
No comments:
Post a Comment