public static void main(Args _args)
{
boolean isScheduleHeader;
SubBillScheduleTable scheduleTable = SubBillScheduleTable::find("USMF-000000001");
SubBillScheduleLine lineTable,billingScheduleLine;
SubBillMassTerminationParmLine parmLine,subBillMassTerminationParmLine;
RecordInsertList parmLineList;
SubBillMassTerminationParmUpdate parmUpdate,massTerminationParmUpdate;
parmId parmId,curParmId;
SubBillCreditOption enumtype;
SubBillTerminationType termEnumType;
SubBillScheduleLineTmp subBillScheduleLineTmp;
select firstonly lineTable where lineTable.SubBillScheduleStatus == SubBillScheduleStatus::Active
&& lineTable.SubBillBillingScheduleNumber == scheduleTable.SubBillBillingScheduleNumber;
parmId = NumberSeq::newGetNum(CompanyInfo::numRefParmId()).num();
SubBillMassTerminationParmUpdate::createFromParmId(parmId);
ttsbegin;
select forupdate parmUpdate where parmUpdate.ParmId == parmId;
parmUpdate.SubBillOpenedFromHeader = isScheduleHeader;
parmUpdate.SubBillInvTransType = scheduleTable.SubBillInvTransType;
parmUpdate.SubBillTerminationType = isScheduleHeader ? scheduleTable.SubBillTerminationType : lineTable.SubBillTerminationType;
parmUpdate.SubBillIssueCredit = (parmUpdate.SubBillTerminationType != SubBillTerminationType::NoAdjustment);
parmUpdate.SubBillTerminationDate = DateTimeUtil::getSystemDate(DateTimeUtil::getUserPreferredTimeZone());
parmUpdate.SubBillTermReasonCode = 'PRICE';
parmUpdate.SubBillTermNotes = '';
parmUpdate.SubBillCreditOption = str2Enum(enumtype,'Issue credit');
parmUpdate.TransDate = DateTimeUtil::getSystemDate(DateTimeUtil::getUserPreferredTimeZone());
parmUpdate.update();
parmLineList = new RecordInsertList(tableNum(SubBillMassTerminationParmLine));
if (isScheduleHeader)
{
while select billingScheduleLine where billingScheduleLine.SubBillScheduleStatus == SubBillScheduleStatus::Active
&& billingScheduleLine.SubBillBillingScheduleNumber == scheduleTable.SubBillBillingScheduleNumber
{
parmLine.initializeParmLine(scheduleTable, billingScheduleLine, parmUpdate);
parmLineList.add(parmLine);
}
}
else
{
Container lineNumbers;
parmLine.initializeParmLine(scheduleTable, lineTable, parmUpdate);
parmLineList.add(parmLine);
lineNumbers += lineTable.LineNum;
}
parmLineList.insertDatabase();
ttscommit;
massTerminationParmUpdate = SubBillMassTerminationParmUpdate::find(parmId);
curParmId = parmId;
ttsbegin;
delete_from subBillScheduleLineTmp
where subBillScheduleLineTmp.ParmId == curParmId;
parmLineList = new RecordInsertList(tableNum(SubBillScheduleLineTmp), true, true, true, false, true, subBillScheduleLineTmp);
while select * from subBillMassTerminationParmLine
where subBillMassTerminationParmLine.ParmId == curParmId
{
subBillScheduleLineTmp.clear();
subBillScheduleLineTmp.ParmId = curParmId;
subBillScheduleLineTmp.ScheduleLnRecId = subBillMassTerminationParmLine.ScheduleLnRecId;
//Only set refund amount if IssueCredit is true, otherwise, leave it 0
if (massTerminationParmUpdate.SubBillIssueCredit)
{
subBillScheduleLineTmp.RefundAmount = subBillMassTerminationParmLine.RefundAmount;
}
subBillScheduleLineTmp.TotalLineAmount = subBillMassTerminationParmLine.TotalLineAmount;
parmLineList.add(subBillScheduleLineTmp);
}
parmLineList.insertDatabase();
ttscommit;
// Using common code to get the count of the termination lines.
int countLines = SubBillMassTermination::massTerminationProcess(massTerminationParmUpdate, subBillScheduleLineTmp);
if (countLines == 1)
{
info("@SubBill:OneScheduleLineTerminated");
}
// Clear temp tables.
ttsbegin;
SubBillScheduleLineTmp subBillScheduleLineTmp1;
delete_from subBillScheduleLineTmp1
where subBillScheduleLineTmp1.ParmId == curParmId;
SubBillMassTerminationParmLine subBillMassTerminationParmLine1;
delete_from subBillMassTerminationParmLine1
where subBillMassTerminationParmLine1.ParmId == curParmId;
SubBillMassTerminationParmUpdate subBillMassTerminationParmUpdate;
delete_from subBillMassTerminationParmUpdate
where subBillMassTerminationParmUpdate.ParmId == curParmId;
ttscommit;
}
}
Output :