В объемах на финансирование проверял соответстие лс и организации
(т.е. лицевойСчет.ОрганизацияВладелец должна быть равен Организации).
Вот таким скриптом я проверяю:
Код: Выделить всё
select d.id, c.anumber, c.acceptdate, d.facialacc, f.org_ref , o2.name, o.id, o.name
from limitfindetail d
left join limitnotifycaption c on (c.id=d.recordindex)
left join facialacc_cls f on (f.id=d.facialacc)
left join org_accounts oa on (d.acc_ref = oa.id)
left join organizations o on (oa.org_ref = o.id)
left join organizations o2 on (f.org_ref = o2.id)
where f.org_ref <> o.id
order by c.anumber
Возвращаются все записи, которые придется править.
Проверяю на ЕДИНЫЙ СЧЕТ:
Код: Выделить всё
select d.id, oa.acc from limitfindetail d
left join org_accounts oa on (oa.id=d.acc_ref)
left join organizations o on (o.id=oa.org_ref)
where oa.acc<>'ЕДИНЫЙ СЧЕТ'
Делаю триггер который будет править и организацию и счет:
Код: Выделить всё
SET NAMES WIN1251;
SET TERM ^ ;
CREATE TRIGGER LIMITFINDETAIL_BU900 FOR LIMITFINDETAIL
ACTIVE BEFORE UPDATE POSITION 900
as
declare variable org integer;
declare variable cnt integer;
declare variable acc2 integer;
declare variable my_id integer;
begin
my_id = new.id;
select o2.id
from limitfindetail d
left join limitnotifycaption c on (c.id=d.recordindex)
left join facialacc_cls f on (f.id=d.facialacc)
left join org_accounts oa on (d.acc_ref = oa.id)
left join organizations o on (oa.org_ref = o.id)
left join organizations o2 on (f.org_ref = o2.id)
where d.id=:my_id
into :org;
select count(*) from org_accounts oa
left join organizations o on (oa.org_ref=o.id)
where o.id=:org and oa.acc = 'AAEIUE N?AO'
into :cnt;
if (cnt=0) then
begin
select max(oa.id) from org_accounts oa
left join organizations o on (oa.org_ref=o.id)
where o.id=:org
into :acc2;
end
else
begin
select max(oa.id) from org_accounts oa
left join organizations o on (oa.org_ref=o.id)
where o.id=:org and oa.acc = 'AAEIUE N?AO'
into :acc2;
end
new.acc_ref = acc2;
end
^
SET TERM ; ^
И запускаю триггер:
Код: Выделить всё
update limitfindetail set rversion=rversion+1
Потом триггер удаляю.