Expense Report Issue

Hi,

I have create a new form in which user enter the request and lines for expense in client and on the click of create expense button i want to insert the header and lines in TrvExpTable and TrvExpTrans … i have write a class which is called on the click of create expense button it generate the header info in TRVExpTable properly and but only first transaction of lines table insert into TrvExpTrans for example if i enter the 2 lines with expense category of daily allowance and hotel booking then it only inset daily allowance into TrvExpTrans on second transaction it show record hotel booking already exist

Below is my code.

class CreateExpenseCash
{
TrvExpNumber num;
RecId recid;
}

//Run Method which is called on the click of button

public void Run(PHCExpCash _expcash)
{
TrvExpTable exptable,header;
TrvExpTrans exptrans;
PHCExpCashAdv expcash,expcashtabl;
PHCExpCashLines expcashlines;
NumberSeq numberSeq;
// TrvExpNumber num;
// RecId recid;
;
//Inserting Header

select * from expcash
where expcash.PHCExpCash == _expcash;

{
ttsBegin;
//numberseq = numberSeq::newGetNumFromCode(‘Trav_10’).num();
numberSeq = NumberSeq::newGetNum(TrvParameters::numRefExpNumber());
num = numberSeq.num();
exptable.ExpNumber = num;
ttsCommit;
exptable.ApprovalStatus = TrvAppStatus::Create;//TrvAppStatus::Approved;//expcash.ApprovalStatus;
exptable.CreatingWorker = expcash.CreatingWorker;
exptable.DefaultDimension = expcash.DefaultDimension;
exptable.Destination = expcash.Destination;
exptable.LegalEntity = CompanyInfo::find().RecId;//expcash.ApprovalStatus;
exptable.ReferenceDataAreaId = CompanyInfo::find().DataArea;//expcash.ApprovalStatus;
exptable.Txt2 = expcash.Txt2;

exptable.insert();
recid = exptable.RecId;
info(strFmt("%1 %2",recid,num));
}
expcashtabl = PHCExpCashAdv::find(_expcash);

//To insert lines

this.Lines(_expcash,num,expcashtabl,recid);

}

//Insert Lines

private void Lines(PHCExpCash _expcash, TrvExpNumber _expnum,PHCExpCashAdv expcash, Recid _recid)
{
TrvExpTrans exptrans;
PHCExpCashLines expcashlines;
real line = 1.0;
TrvExpTable header;
;

while select * from expcashlines
where expcashlines.PHCExpCash == _expcash
{
exptrans.LineNumber = line;

// select * from header
// where header.ExpNumber == _expnum;

// info(strFmt(“exp num recid %1 %2”,num,header.RecId));

exptrans.ExpNumber = _expnum;
exptrans.CostType = expcashlines.CostType;// TrvCostType::find(‘General Expenses’).CostType;
exptrans.PayMethod = expcashlines.PayMethod;//TrvPayMethod::find(‘Cash’).PayMethod;
exptrans.TransDate = str2Date(date2str(expcashlines.TransDate,123,DateDay::Digits2,DateSeparator::Slash,DateMonth::Digits2,DateSeparator::Slash,DateYear::Digits4),123);
exptrans.ExchangeCode = expcashlines.ExchangeCode;
exptrans.DateFrom = expcashlines.DateFrom;
exptrans.DateTo = expcashlines.DateTo;
exptrans.ExpType = expcashlines.ExpType;
// Currency::find(‘PKR’).CurrencyCode;
exptrans.AmountCurr = expcashlines.AmountCurr;// expcash.TotalAmount;
exptrans.ApprovalStatus =TrvAppStatus::Create;// TrvAppStatus::Approved;//expcash.ApprovalStatus;
exptrans.LegalEntity = CompanyInfo::find().RecId;
exptrans.ExchangeRate = 100.0;
exptrans.DefaultDimension = expcash.DefaultDimension;
exptrans.ReferenceDataAreaId = CompanyInfo::find().DataArea;
exptrans.CashAdvanceRecId = TrvCashAdvance::find(expcash.CashAdvanceNumber).RecId;
exptrans.CreatingWorker = expcash.CreatingWorker;
exptrans.TrvExpTable =_recid;
exptrans.insert();
line = line + 1.0;

}

}

Kindly tell me where is the issue .

I think \Data Dictionary\Tables\TrvExpTrans\Fields\SourceDocumentLine is not properly updated.
Please try to debug and see why it is not updating, as the insert method already handles the source document line implementation.

But I have checked in table source document line is creating successfully when first transaction inserted into TrvExpTrans
when loop run second time then at the time of insert it show me an error record already exist. it does not show me an error regarding sourceDocumentLine

What is the exact error that you are receiving?

I have found the issue \Data Dictionary\Tables\TrvExpTrans\Index\SourceDocumentLineIdx there is allowduplication properties for this index is No thats why it is give me an error … how can i solve this ? is this ok if i set allow duplication property of this index to YES

You shouldn’t be changing the index, it mean that you should be having a separate source document line for each expense trans. As already said, there is a problem with the source document line generation. You have to debug to find the exact issue.

Source Document line field is not updating … How can i update it

You don’t have to do it explicitly, the insert has the below code that already does it.

SourceDocumentProcessorFacade::submitSourceDocumentLineImplementation(this);

Have a break point there and investigate it.