internal final class RunnableClasstestforundosettlement
{
/// <summary>
/// Class entry point. The system will call this method when a designated menu
/// is selected or when execution starts and this class is set as the startup class.
/// </summary>
/// <param name = "_args">The specified arguments.</param>
public static void main(Args _args)
{
CustTrans findCustTrans;
CustTable custTable;
CustSettlement custSettlement;
SpecTransManager specTransManager;
//AmountCur balanceAmount;
boolean reversed;
str voucher="Payment or invoice voucher";
select firstOnly findCustTrans
where findCustTrans.Voucher == voucher;
if (findCustTrans.RecId)
{
custTable = CustTable::find(findCustTrans.AccountNum);
select firstOnly custSettlement
where custSettlement.TransCompany == findCustTrans.DataAreaId
&& custSettlement.TransRecId == findCustTrans.RecId
&& custSettlement.AccountNum == findCustTrans.AccountNum;
if (custSettlement.RecId)
{
specTransManager =
SpecTransManager::newRefTableId(
custTable,
tableNum(CustSettlement),
true);
specTransManager.insert(
custSettlement.DataAreaId,
custSettlement.TableId,
custSettlement.RecId,
custSettlement.SettleAmountCur,
findCustTrans.CurrencyCode);
custSettlement.CustVendSettlement::markThisAndRelatedOffsets(
specTransManager,
findCustTrans.CurrencyCode);
reversed = CustTrans::reverseTransact(
custTable,
null,
SettleDatePrinc::DateOfPayment,
custSettlement.TransDate);
if (reversed)
{
specTransManager.deleteAll();
}
else
{
throw error(strFmt(
"Unable to undo settlement for voucher %1.",
voucher));
}
}
else
{
warning(strFmt(
"No settlement record found for voucher %1.",
voucher));
}
}
}
}
Credits and References
Special thanks to Amir for sharing the original implementation.
The code in this article is based on the work originally published here:
Original Article: https://dynamics1608.rssing.com/
Author: Amir
Source:https://dynamics1608.rssing.com/a/x-code-to-unsettle-payment-and-invoice-h8x1adysk
No comments:
Post a Comment