Tuesday, May 17, 2011

Create Ledger Journal Table and Trans Records


----------- Journal Table ------------------------

LedgerJournalTable createLedgerJournalTable()
{
    LedgerJournalTable journalTable;
    ;

    journalTable.JournalNum    = JournalTableData::newTable(journalTable).nextJournalId();
    journalTable.journalType   = LedgerJournalType::Daily;
    journalTable.JournalName   = PSAParameters::find().ExpenseJournalNameId;//Customized field

    journalTable.initFromLedgerJournalName(journalTable.JournalName);
    cnrAccount = journalTable.ledgerJournalName().OffsetAccount;
    if(!cnrAccount)
        throw error("Account not defined in PSA Parameters.");

    origLedgerTrans.JournalNum);
    
journalTable.insert();
    return journalTable;
}

----------- Journal Trans ------------------------
void createLedgerJournalTrans(LedgerJournalTable        _ledgerJournalTable,
                                   tmpProjectOpenPOs    _tmpProjectOpenPOs //Customized table)
{
    LedgerJournalTrans  journalTrans;
    PurchLine           lPurchLine = PurchLine::find(_tmpProjectOpenPOs.PurchId, _tmpProjectOpenPOs.LineNum, true);
    ProjTable           lProjtable = ProjTable::find(_tmpProjectOpenPOs.ProjId);
    ;
    journalTrans.clear();
    journalTrans.initValue();
    journalTrans.Txt = StrFmt("Invoice for Purchase order %1 line number %2",_tmpProjectOpenPOs.PurchId, _tmpProjectOpenPOs.LineNum);
    journalTrans.Voucher = this.newVoucher(_ledgerJournalTable);
    journalTrans.JournalNum = _ledgerJournalTable.JournalNum;
    journalTrans.LineNum = LedgerJournalTrans::lastLineNum(journalTrans.JournalNum)+1;
    journalTrans.transDate = systemDateGet();
    journalTrans.AccountType = LedgerJournalACType::Project;
    journalTrans.AccountNum = _tmpProjectOpenPOs.ProjId;
    journalTrans.AmountCurDebit = _tmpProjectOpenPOs.NetAmount;
    journalTrans.OffsetAccountType = LedgerJournalACType::Ledger;
    journalTrans.OffsetAccount = NRAccount; //Customized field
    journalTrans.Dimension = lPurchLine.Dimension;
    journalTrans.CurrencyCode = lPurchLine.CurrencyCode;
    journalTrans.ProjCategoryId = lPurchLine.ProjCategoryId;
    journalTrans.ProjLinePropertyId = lPurchLine.ProjLinePropertyId;
    journalTrans.ProjQty = 1;
    journalTrans.modifiedField(FieldNum(LedgerJournalTrans,Projqty));
    journalTrans.SalesPrice = lPurchLine.ProjSalesPrice;
    journalTrans.ProjSalesCurrencyId = lPurchline.ProjSalesCurrencyId;

   
    journalTrans.insert();
}

2 comments:

  1. Thanks Vishal for sharing this. Its really helpful

    ReplyDelete
  2. what does it means "journalTrans.Voucher = this.newVoucher(_ledgerJournalTable);"
    where is this method?

    ReplyDelete