Ну, как-то так:
X++:
static void eglaSMAServiceObjectTableReplicate(Args _args)
{
SMAServiceObjectTable object116, object101, father116, father101;
smmBusRelTable busRel116, busRel101;
DirPartyTable dirParty116, dirParty101;
CustTable cust116, cust101;
int record;
SMAAgreementTable agreementTable;
SMAAgreementLine agreementLine;
SMAServiceObjectRelation objectRelation;
;
try
{
changeCompany('101')
{
object101.skipDataMethods(true);
object101.skipTTSCheck(true);
while select forupdate object101
where object101.dataAreaId == '101' &&
(object101.ServiceObjectGroup like "FREIBAD*" ||
object101.ServiceObjectGroup like "HALLENB.*" ||
object101.ServiceObjectGroup like "THERAPIE*" ||
object101.ServiceObjectGroup like "WELLNESS*" ||
object101.ServiceObjectGroup like "WHIRLP.*" ||
object101.ServiceObjectGroup like "ZIERBECKEN")
&& ! (object101.ServiceObjectId like "*P")
&& object101.EcoObjectStatusId == "Verfügbar"
{
select firstonly RecId from agreementTable
where (! agreementTable.EndDate || agreementTable.EndDate >= today())
&& (! agreementTable.Suspended)
exists join objectRelation
where objectRelation.ServiceObjectId == object101.ServiceObjectId
&& objectRelation.RelKeyId == agreementTable.AgreementId
&& objectRelation.RelTableId == tableNum(SMAAgreementTable);
if (agreementTable)
{
continue;
}
select firstonly RecId from agreementLine
where (! agreementLine.EndDate || agreementLine.EndDate >= today())
&& (! agreementLine.Suspended)
join RecId from agreementTable
where (! agreementTable.EndDate || agreementTable.EndDate >= today())
&& agreementTable.AgreementId == agreementLine.AgreementId
&& (! agreementTable.Suspended)
exists join objectRelation
where objectRelation.ServiceObjectId == object101.ServiceObjectId
&& objectRelation.RelKeyId == agreementTable.AgreementId
&& objectRelation.RelTableId == tableNum(SMAAgreementLine);
if (agreementLine)
{
continue;
}
object101.EcoObjectStatusId = "Gelöscht";
print object101.ServiceObjectId + " " + object101.EcoObjectStatusId;
object101.doUpdate();
}
}
info(time2str(timenow(),-1,-1) + " " + curExt());
while select object116
order by EcoSMAServiceObjectFatherId asc
where object116.dataAreaId == '116' &&
(object116.ServiceObjectGroup like "FREIBAD*" ||
object116.ServiceObjectGroup like "HALLENB.*" ||
object116.ServiceObjectGroup like "THERAPIE*" ||
object116.ServiceObjectGroup like "WELLNESS*" ||
object116.ServiceObjectGroup like "WHIRLP.*" ||
object116.ServiceObjectGroup like "ZIERBECKEN")
outer join busRel116
where busRel116.BusRelAccount == object116.EcoBusRelAccount
join dirParty116
where dirParty116.PartyId == busRel116.PartyId
{
cust116 = CustTable::findByPartyId(dirParty116.PartyId);
father116 = SMAServiceObjectTable::find(object116.EcoSMAServiceObjectFatherId);
changeCompany('101')
{
select firstonly busRel101
where busRel101.BusRelAccount == busRel116.BusRelAccount
join dirParty101
where dirParty101.PartyId == busRel101.PartyId;
if (dirParty116.Name != dirParty101.Name)
{
select firstonly cust101
where cust101.AccountNum == cust116.AccountNum
join dirParty101
where dirParty101.PartyId == cust101.PartyId
join busRel101
where busRel101.PartyId == dirParty101.PartyId;
if (! busRel101)
{
select firstonly dirParty101
where dirParty101.Name like "*"+strReplace(strReplace(strltrim(strrtrim(busRel116.Name)),"Frau ",""),"Herr ","")+"*"
join busRel101
where busRel101.PartyId == dirParty101.PartyId;
}
}
ttsbegin;
object101.clear();
object101 = SMAServiceObjectTable::find(object116.ServiceObjectId+"P", true);
buf2Buf(object116, object101);
object101.ServiceObjectId = object116.ServiceObjectId+"P";
if (! busRel101)
{
print dirParty116.Name;
print dirParty101.Name;
object101.EcoBusRelAccount = strRem(strReplace(strReplace(strltrim(strrtrim(busRel116.Name)),"Frau",""),"Herr","")," ");
}
else
{
object101.EcoBusRelAccount = busRel101.BusRelAccount;
}
if (object116.EcoSMAServiceObjectFatherId)
{
object101.EcoSMAServiceObjectFatherId = object116.EcoSMAServiceObjectFatherId+"P";
father101 = SMAServiceObjectTable::find(object101.EcoSMAServiceObjectFatherId);
if (! father101 && father116)
{
buf2Buf(father116, father101);
father101.ServiceObjectId = object101.EcoSMAServiceObjectFatherId;
father101.EcoBusRelAccount = object101.EcoBusRelAccount;
father101.Description += " Pool";
father101.write();
record++;
}
}
print object101.ServiceObjectId;
record++;
object101.write();
ttscommit;
}
}
}
catch (Exception::Error)
{
warning(strFmt("Error at the object %1", object116.ServiceObjectId));
}
info(time2str(timenow(),-1,-1) + " " + strFmt("Total objects - %1",record));
}