SET TERM ^ ; create or alter procedure PR_CORRECTPART ( DOC_ID type of DM_ID, PART_ID type of DM_ID, QUANT type of DM_DOUBLE) returns ( ID type of DM_ID, MSG DM_TEXT) as declare variable NAC type of DM_DOUBLE; declare variable PARENT_ID type of DM_ID; begin if (quant<0) then quant=0; select id, msg from pr_rashodpart (:doc_id,:part_id,:quant,null,null,null,null,1) into :parent_id, :msg; if (parent_id<=0) then begin id=parent_id; suspend; exit; --exception EX_RASHOD_ERROR; end select id from doc_detail_active where doc_id=:doc_id and parent_id=:parent_id and part_id=0 into id; if (id is null) then begin id = gen_id(gen_doc_detail_active_id,1); insert into doc_detail_active (id,parent_id,doc_id,part_id,quant,nac,koef,motherpart_id) values (:id,:parent_id,:doc_id,:part_id,:quant,:nac,0,:part_id); update doc_detail_active set part_id=0 where id=:id; insert into group_detail (group_id,parent_id,grouptable_id,grouptable) select group_id, 0, cast(:id as dm_text), 'DOC_DETAIL_ACTIVE' from group_detail gd where grouptable_id=cast(:part_id as dm_text) and grouptable='PARTS' and -- 974777 A.K. 2020-010-06 (not exists(select id from GROUP_DETAIL gd1 where gd1.GROUP_ID=gd.GROUP_ID and gd1.GROUPTABLE_ID=cast(:id as dm_text) and gd1.GROUPTABLE='DOC_DETAIL_ACTIVE')); end else begin update doc_detail_active set quant=:quant, summa=:quant*price, summa_o=:quant*price_o, sum_ndso=round((:quant*price_o)*nds/(100+nds),2), sum_ndsr=(:quant*price)*(select d.ndsr from deps d where d.id=dep)/(100+(select d.ndsr from deps d where d.id=dep)) where id=:id; end suspend; end^ SET TERM ; ^ /* Following GRANT statetements are generated automatically */ GRANT EXECUTE ON PROCEDURE PR_RASHODPART TO PROCEDURE PR_CORRECTPART; GRANT SELECT,INSERT,UPDATE ON DOC_DETAIL_ACTIVE TO PROCEDURE PR_CORRECTPART; GRANT SELECT,INSERT ON GROUP_DETAIL TO PROCEDURE PR_CORRECTPART; GRANT SELECT ON DEPS TO PROCEDURE PR_CORRECTPART; /* Existing privileges on this procedure */ GRANT EXECUTE ON PROCEDURE PR_CORRECTPART TO "PUBLIC"; GRANT EXECUTE ON PROCEDURE PR_CORRECTPART TO STANDART; GRANT EXECUTE ON PROCEDURE PR_CORRECTPART TO SYSDBA;