Create and post Invoice proposal through code in ax 2012 X++
public class CreateInvoiceProposal extends RunBaseBatch
{
}
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
public boolean canGoBatch()
{
return true;
}
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
protected boolean canGoBatchJournal()
{
return true;
}
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
public boolean runsImpersonated()
{
return true;
}
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
static ClassDescription description()
{
return "Invocie proposal creation";
}
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
public static void main(Args args)
{
CreateInvoiceProposal createInvoiceProposal = new CreateInvoiceProposal();
if (createInvoiceProposal.prompt())
{
createInvoiceProposal.run();
}
}
public class CreateInvoiceProposal extends RunBaseBatch
{
}
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
public boolean canGoBatch()
{
return true;
}
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
protected boolean canGoBatchJournal()
{
return true;
}
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
public boolean runsImpersonated()
{
return true;
}
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
static ClassDescription description()
{
return "Invocie proposal creation";
}
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
public static void main(Args args)
{
CreateInvoiceProposal createInvoiceProposal = new CreateInvoiceProposal();
if (createInvoiceProposal.prompt())
{
createInvoiceProposal.run();
}
}
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
public void run()
{
ProjParameters projParameters;
ProjEmplTrans projEmplTrans;
ProjOnAccTrans projOnAccTrans;
ProjProposalJour projProposalJour; //Table which will store journal records after creating Invoice Proposal
ProjFormLetter projFormLetter;
ProjOnAccTrans objProjOnAccTrans_1;
ALE_STG_Milestone milestone,milestoneLines;
ALE_STG_HourJournal hourJournal,hourJournalLines;
ALE_STG_ExpenseJournal expenseJournal,expenseJournalLines;
TransactionID transId;
ALE_ProposalInvoiceTable proposalInvoiceTable;
CategoryId categoryId;
ProjTable projTable;
container transIdCon;
int i,j;
ProjInvoiceProposalInsertLines projInvoiceProposalInsertLines;
ProjInvoiceProposalCreateLinesBase projInvoiceProposalCreateLinesBase;
ProjInvoiceProposalCreateLines proposalCreateLines;
ProjInvoiceProposalCreateLinesParams projInvoiceProposalCreateLinesParams;
proposalCreateLines = new ProjInvoiceProposalCreateLines();
projInvoiceProposalCreateLinesParams = new ProjInvoiceProposalCreateLinesParams();
proposalCreateLines.parmProposalCreateLinesParams(projInvoiceProposalCreateLinesParams).parmInvoiceDate(today());
projInvoiceProposalInsertLines = new ProjInvoiceProposalInsertLines(proposalCreateLines,false);
select projParameters;
try
{
while select hourJournal group by InvoiceId,CompanyId order by ProjectDate asc //ProjectDate,ProjId
join expenseJournal
where hourJournal.Status == 2 && hourJournal.InterCompany == NoYes::No && hourJournal.InvoiceId != '' && hourJournal.AXInvoiceId == '' && expenseJournal.PSAInvoiceId == hourJournal.InvoiceId
{
ttsBegin;
changeCompany(hourJournal.CompanyId)
// Start added by kiran PSA AX Integration 13 Aug 2019
delete_from proposalInvoiceTable;
// End added by kiran PSA AX Integration 13 Aug 2019
proposalInvoiceTable.PSAInvoiceId = hourJournal.InvoiceId;
proposalInvoiceTable.insert();
projInvoiceProposalInsertLines.run();
select proposalInvoiceTable;
select forUpdate projProposalJour where projProposalJour.ProposalId == proposalInvoiceTable.ProposalId &&
projProposalJour.InvoiceDate == today()
&& (projProposalJour.LineProperty!=ProjLinePropertyCode::Invoiced && projProposalJour.LineProperty!=ProjLinePropertyCode::Canceled);
{
//For approving Invoice proposals
projProposalJour.LineProperty = ProjLinePropertyCode::Approved;
projProposalJour.update();
//For Posting Invoice Proposals
projFormLetter = ProjFormLetter::construct(DocumentStatus::ProjectInvoice);
projFormLetter.createParmLine(projProposalJour);
projFormLetter.run();
//To get latest record
projProposalJour = projProposalJour::find(projProposalJour.ProposalId);
info(strFmt("Invoice ProposalId: %1 \t InvoiceId: %2",projProposalJour.ProposalId,projProposalJour.ProjInvoiceId));
}
select proposalInvoiceTable;
while select forUpdate hourJournalLines order by RecId asc where hourJournalLines.InvoiceId == hourJournal.InvoiceId
&& hourJournalLines.Status == 2
&& hourJournalLines.InterCompany == NoYes::No
{
hourJournalLines.AXInvoiceId = proposalInvoiceTable.InvoiceId;
hourJournalLines.Status = 3;
hourJournalLines.update();
}
while select forUpdate expenseJournalLines order by RecId asc where expenseJournalLines.PSAInvoiceId == hourJournal.InvoiceId
&& expenseJournalLines.Status == 2
&& expenseJournalLines.InterCompany == NoYes::No
{
expenseJournalLines.AXInvoiceId = proposalInvoiceTable.InvoiceId;
expenseJournalLines.Status = 3;
expenseJournalLines.update();
}
ttsCommit;
}
// Onaccount - expense
while select milestone group by InvoiceId,CompanyId order by ProjDate asc //ProjectDate,ProjId
join expenseJournal
where milestone.Status == 2 && milestone.InterCompany == NoYes::No && milestone.InvoiceId != '' && milestone.AXInvoiceId == '' && expenseJournal.PSAInvoiceId == milestone.InvoiceId
{
ttsBegin;
changeCompany(milestone.CompanyId)
// Start added by kiran PSA AX Integration 13 Aug 2019
delete_from proposalInvoiceTable;
// End added by kiran PSA AX Integration 13 Aug 2019
proposalInvoiceTable.PSAInvoiceId = milestone.InvoiceId;
proposalInvoiceTable.insert();
projInvoiceProposalInsertLines.run();
select proposalInvoiceTable;
select forUpdate projProposalJour where projProposalJour.ProposalId == proposalInvoiceTable.ProposalId &&
projProposalJour.InvoiceDate == today()
&& (projProposalJour.LineProperty!=ProjLinePropertyCode::Invoiced && projProposalJour.LineProperty!=ProjLinePropertyCode::Canceled);
{
//For approving Invoice proposals
projProposalJour.LineProperty = ProjLinePropertyCode::Approved;
projProposalJour.update();
//For Posting Invoice Proposals
projFormLetter = ProjFormLetter::construct(DocumentStatus::ProjectInvoice);
projFormLetter.createParmLine(projProposalJour);
projFormLetter.run();
//To get latest record
projProposalJour = projProposalJour::find(projProposalJour.ProposalId);
info(strFmt("Invoice ProposalId: %1 \t InvoiceId: %2",projProposalJour.ProposalId,projProposalJour.ProjInvoiceId));
}
select proposalInvoiceTable;
while select forUpdate milestoneLines order by RecId asc where milestoneLines.InvoiceId == milestone.InvoiceId
&& milestoneLines.Status == 2
&& milestoneLines.InterCompany == NoYes::No
{
milestoneLines.AXInvoiceId = proposalInvoiceTable.InvoiceId;
milestoneLines.Status = 3;
milestoneLines.update();
}
while select forUpdate expenseJournalLines order by RecId asc where expenseJournalLines.PSAInvoiceId == milestone.InvoiceId
&& expenseJournalLines.Status == 2
&& expenseJournalLines.InterCompany == NoYes::No
{
expenseJournalLines.AXInvoiceId = proposalInvoiceTable.InvoiceId;
expenseJournalLines.Status = 3;
expenseJournalLines.update();
}
ttsCommit;
}
// On Account - expense end
// On account alone - start
while select milestone group by InvoiceId,CompanyId order by ProjDate asc //ProjectDate,ProjId
where milestone.Status == 2 && milestone.InterCompany == NoYes::No && milestone.InvoiceId != '' && milestone.AXInvoiceId == ''
{
ttsBegin;
changeCompany(milestone.CompanyId)
// Start added by kiran PSA AX Integration 13 Aug 2019
delete_from proposalInvoiceTable;
// End added by kiran PSA AX Integration 13 Aug 2019
proposalInvoiceTable.PSAInvoiceId = milestone.InvoiceId;
proposalInvoiceTable.insert();
projInvoiceProposalInsertLines.run();
select proposalInvoiceTable;
select forUpdate projProposalJour where projProposalJour.ProposalId == proposalInvoiceTable.ProposalId &&
projProposalJour.InvoiceDate == today()
&& (projProposalJour.LineProperty!=ProjLinePropertyCode::Invoiced && projProposalJour.LineProperty!=ProjLinePropertyCode::Canceled);
{
//For approving Invoice proposals
projProposalJour.LineProperty = ProjLinePropertyCode::Approved;
projProposalJour.update();
//For Posting Invoice Proposals
projFormLetter = ProjFormLetter::construct(DocumentStatus::ProjectInvoice);
projFormLetter.createParmLine(projProposalJour);
projFormLetter.run();
//To get latest record
projProposalJour = projProposalJour::find(projProposalJour.ProposalId);
info(strFmt("Invoice ProposalId: %1 \t InvoiceId: %2",projProposalJour.ProposalId,projProposalJour.ProjInvoiceId));
}
select proposalInvoiceTable;
while select forUpdate milestoneLines order by RecId asc where milestoneLines.InvoiceId == milestone.InvoiceId
&& milestoneLines.Status == 2
&& milestoneLines.InterCompany == NoYes::No
{
milestoneLines.AXInvoiceId = proposalInvoiceTable.InvoiceId;
milestoneLines.Status = 3;
milestoneLines.update();
}
ttsCommit;
}
// On account alone - end
// Expense/Cost Invoice proposal
while select expenseJournal group by PSAInvoiceId,CompanyId order by ProjectDate asc //ProjectDate,ProjId
where expenseJournal.Status == 2 && expenseJournal.InterCompany == NoYes::No && expenseJournal.PSAInvoiceId != '' && expenseJournal.AXInvoiceId == ''
{
ttsBegin;
changeCompany(expenseJournal.CompanyId)
// Start added by kiran PSA AX Integration 13 Aug 2019
delete_from proposalInvoiceTable;
// End added by kiran PSA AX Integration 13 Aug 2019
proposalInvoiceTable.PSAInvoiceId = expenseJournal.PSAInvoiceId;
proposalInvoiceTable.insert();
projInvoiceProposalInsertLines.run();
select proposalInvoiceTable;
select forUpdate projProposalJour where projProposalJour.ProposalId == proposalInvoiceTable.ProposalId &&
projProposalJour.InvoiceDate == today()
&& (projProposalJour.LineProperty!=ProjLinePropertyCode::Invoiced && projProposalJour.LineProperty!=ProjLinePropertyCode::Canceled);
{
//For approving Invoice proposals
projProposalJour.LineProperty = ProjLinePropertyCode::Approved;
projProposalJour.update();
//For Posting Invoice Proposals
projFormLetter = ProjFormLetter::construct(DocumentStatus::ProjectInvoice);
projFormLetter.createParmLine(projProposalJour);
projFormLetter.run();
//To get latest record
projProposalJour = projProposalJour::find(projProposalJour.ProposalId);
info(strFmt("Invoice ProposalId: %1 \t InvoiceId: %2",projProposalJour.ProposalId,projProposalJour.ProjInvoiceId));
}
select proposalInvoiceTable;
while select forUpdate expenseJournalLines order by RecId asc where expenseJournalLines.PSAInvoiceId == expenseJournal.PSAInvoiceId
&& expenseJournalLines.Status == 2
&& expenseJournalLines.InterCompany == NoYes::No
{
expenseJournalLines.AXInvoiceId = proposalInvoiceTable.InvoiceId;
expenseJournalLines.Status = 3;
expenseJournalLines.update();
}
ttsCommit;
}
//
//
while select hourJournal group by InvoiceId,CompanyId order by ProjectDate asc //ProjectDate,ProjId
where hourJournal.Status == 2 && hourJournal.InterCompany == NoYes::No && hourJournal.InvoiceId != '' && hourJournal.AXInvoiceId == ''
{
ttsBegin;
changeCompany(hourJournal.CompanyId)
// Start added by kiran PSA AX Integration 13 Aug 2019
delete_from proposalInvoiceTable;
// End added by kiran PSA AX Integration 13 Aug 2019
proposalInvoiceTable.PSAInvoiceId = hourJournal.InvoiceId;
proposalInvoiceTable.insert();
projInvoiceProposalInsertLines.run();
select proposalInvoiceTable;
select forUpdate projProposalJour where projProposalJour.ProposalId == proposalInvoiceTable.ProposalId &&
projProposalJour.InvoiceDate == today()
&& (projProposalJour.LineProperty!=ProjLinePropertyCode::Invoiced && projProposalJour.LineProperty!=ProjLinePropertyCode::Canceled);
{
//For approving Invoice proposals
projProposalJour.LineProperty = ProjLinePropertyCode::Approved;
projProposalJour.update();
//For Posting Invoice Proposals
projFormLetter = ProjFormLetter::construct(DocumentStatus::ProjectInvoice);
projFormLetter.createParmLine(projProposalJour);
projFormLetter.run();
//To get latest record
projProposalJour = projProposalJour::find(projProposalJour.ProposalId);
info(strFmt("Invoice ProposalId: %1 \t InvoiceId: %2",projProposalJour.ProposalId,projProposalJour.ProjInvoiceId));
}
select proposalInvoiceTable;
while select forUpdate hourJournalLines order by RecId asc where hourJournalLines.InvoiceId == hourJournal.InvoiceId
&& hourJournalLines.Status == 2
&& hourJournalLines.InterCompany == NoYes::No
{
hourJournalLines.AXInvoiceId = proposalInvoiceTable.InvoiceId;
hourJournalLines.Status = 3;
hourJournalLines.update();
}
ttsCommit;
}
//
}
catch(Exception::Error)
{
error('An Exception has occurred');
}
}
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>