Customer Cancel Payment Transaction
Oftentimes Technical consultants receive the requirement to write some logic or feature where we can cancel the X number of payments by selecting many records at once.class TMV_CustomerPaymentCancel
{
public static void main(Args _args)
{
LedgerJournalTrans _ledgerJournalTrans;
TMV_CustomerPaymentCancel objCancelPayment=new TMV_CustomerPaymentCancel();
objCancelPayment.cancelpaymentExecution('R00007404',_ledgerJournalTrans);
}
public void cancelpaymentExecution(InvoiceId _invoiceid,LedgerJournalTrans _ledgerJournalTrans)
{
CustTrans custTransOffset;
ReasonTable reasonTable;
ReasonCode reasonCode;
ReasonRefRecID reasonRefRecID;
Args args;
;
custTransOffset= this.findPaymentReference(_invoiceid);
if(custTransOffset.RecId>0)
{
this.CancelPayment(custTransOffset, _ledgerJournalTrans);
}
}
public CustTrans findPaymentReference(InvoiceId _invoiceid)
{
CustTrans custTrans,custTransOffset;
custTrans = CustTrans::findFromInvoice(_invoiceid);
select custTransOffset
where custTransOffset.OffsetRecid==custTrans.RecId
&& custTransOffset.TransType==LedgerTransType::Payment;
return custTransOffset;
}
public void CancelPayment(CustTrans custTransOffset,LedgerJournalTrans _ledgerJournalTrans)
{
CustVendPDCManager custVendPDCManager;
BankPaymCancel bankPaymCancel;
Args localArgs;
if(custTransOffset.RecId)
{
infolog.clear();
try
{
localArgs = new Args();
bankPaymCancel = BankPaymCancel::newBankPaymCancel(custTransOffset);
// bankPaymCancel.parmReason(reasonTable.Reason);
// bankPaymCancel.parmReasonComment(reasonTable.Description);
bankPaymCancel.parmTransDate(systemDateGet());
localArgs.caller(bankPaymCancel);
localArgs.record(custTransOffset);
BankPaymCancel::serverRun(localArgs);
}
catch
{
}
}
}
public str getErrorStr()
{
SysInfologEnumerator enumerator;
SysInfologMessageStruct msgStruct;
Exception exception;
str error;
enumerator = SysInfologEnumerator::newData(infolog.cut());
while (enumerator.moveNext())
{
msgStruct = new SysInfologMessageStruct(enumerator.currentMessage());
exception = enumerator.currentException();
error = strfmt("%1 %2", error, msgStruct.message());
}
return error;
}
}
This concept is a good way to enhance the knowledge.thanks for sharing.. Great article ...
ReplyDeleteMicrosoft Dynamics AX Training
MS Dynamics AX Training
MS Dynamics Training in Hyderabad
Microsoft Dynamics AX Technical Training
Microsoft Dynamics AX Technical Training in Hyderabad