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 .