BEGIN
mOrgTypeN = AOrgType;
IF (mOrgTypeN = 0) THEN
SELECT OrganisationType from GlobData INTO mOrgTypeN;
IF (mOrgTypeN > 0) then BEGIN
mOrgTypeC = CAST(mOrgTypeN as char);
FOR SELECT Master.DocumentType FROM MasterAccPresetDefs Master WHERE Master.ForOrgTypes containing :mOrgTypeC
GROUP BY Master.DocumentType INTO :mMaster_DocumentType
DO BEGIN
/*Pokud existují předkontace pro uzávěrku mezd doplní se chybějící*/
IF ((EXISTS (SELECT A.* FROM AccPresetDefs A WHERE A.DocumentType = :mMaster_DocumentType)) and
(:mMaster_DocumentType = '46')) then begin
for
select M1.ID
from MasterAccPresetDefs M1
WHERE
(M1.DocumentType = :mMaster_DocumentType) and (M1.ForOrgTypes containing :mOrgTypeC) and
not exists (SELECT A.ID FROM AccPresetDefs A WHERE (A.DocumentType = :mMaster_DocumentType) and
(A.ID = M1.ID))
into :m1_ID
do begin
execute procedure CopyOneAccPresetDefFromMast(m1_ID);
end
end
/*Doplnění předkontací pro doklady, pro které žádná předkontace neexistuje.*/
IF (NOT EXISTS (SELECT A.* FROM AccPresetDefs A WHERE A.DocumentType = :mMaster_DocumentType))
THEN BEGIN
FOR SELECT M1.ID
FROM MasterAccPresetDefs M1
WHERE (M1.DocumentType = :mMaster_DocumentType) and (M1.ForOrgTypes containing :mOrgTypeC)
INTO :m1_ID
DO BEGIN
execute procedure CopyOneAccPresetDefFromMast(m1_ID);
END
END
END
END
END;