Tuesday, November 27, 2012

Processing a project journal


1. In the AOT, create a new job named ProjJournalCreate with the following code:

static void ProjJournalCreate(Args _args)
{
    ProjJournalTable jourTable;
    ProjJournalTrans jourTrans;
    ProjJournalTableData jourTableData;
    ProjJournalTransData jourTransData;
    ProjJournalStatic jourStatic;
    ttsBegin;
    jourTableData = JournalTableData::newTable(jourTable);
    jourTable.JournalId = jourTableData.nextJournalId();
    jourTable.JournalType = ProjJournalType::Hour;
    jourTable.JournalNameId = 'Hours';
    jourTableData.initFromJournalName(ProjJournalName::find(jourTable.JournalNameId)); 
    jourStatic = jourTableData.journalStatic();
    jourTransData = jourStatic.newJournalTransData(jourTrans, jourTableData);
    jourTransData.initFromJournalTable();
    jourTrans.initValue();
    jourTrans.ProjId = '10001';
    jourTrans.initFromProjTable(ProjTable::find(jourTrans.ProjId));

    jourTrans.TransDate = systemDateGet();
    jourTrans.ProjTransDate = jourTrans.TransDate;
    jourTrans.CategoryId = 'Design';
    jourTrans.setHourCostPrice();
    jourTrans.setHourSalesPrice();
    jourTrans.TaxItemGroupId = ProjCategory::find(jourTrans.CategoryId).TaxItemGroupId;
    jourTrans.Worker = HcmWorker::findByPersonnelNumber('000062').RecId;
    jourTrans.Txt = 'Design documentation';
    jourTrans.Qty = 8;
    jourTransData.create();
    jourTable.insert();
    ttsCommit;
    info(strFmt("Journal '%1' has been created", jourTable.JournalId));
}

2. Run the job and check the results by going to Project management and accounting | Journals | Hour:


3. Click on the Lines button to open the journal lines, and notice the newly created record:




No comments: