/*ALIAS>prop_db*/

/*SQLStart>1770*/
ALTER TABLE RENTSINFO
ADD RI_CARRIEDINTEREST REAL3
/*SQLStop*/

/*SQLStart>1771*/
ALTER TABLE RENTSINFO
ADD RI_PAIDINTEREST REAL3
/*SQLStop*/

/*SQLStart>1772*/
CREATE OR ALTER procedure NEWCARRYINTEREST 
as
declare variable YEARPAYMENT integer;
declare variable MONTHPAYMENT integer;
declare variable CARRYPAYMENT numeric(15,2);
declare variable MAXNUMPAYMENT integer;
declare variable DOCID integer;
begin
 for
    select documents.doc_id from documents where documents.doc_type in (1002,1004)
    into :docid
 do
   begin
       select max(payment.p_num) from payment where payment.p_id = :docid
       into :MAXNUMPAYMENT;

       select payment.p_carry, extract(month from p_data) monthPayment, extract(year from p_data) yearPayment
       from payment where (payment.p_id = :docid) and (payment.p_num =:MAXNUMPAYMENT)
        into  :carryPayment, :monthPayment, :yearPayment;
        if (carrypayment > 0) then
         update rentsinfo set rentsinfo.ri_carriedinterest = :carrypayment where (rentsinfo.ri_docid = :docid) and (rentsinfo.ri_month = :monthPayment) and (rentsinfo.ri_year= :yearpayment);
   end
end
/*SQLStop*/


/*SQLStart>1773*/
execute procedure NEWCARRYINTEREST
/*SQLStop*/


/*SQLStart>1774*/
drop procedure NEWCARRYINTEREST
/*SQLStop*/

/*ManyStart>1775*/
update system_strings set sys_str = '6.1.7.27' where sys_id = 1402;  /*Imot*/
update system_strings set sys_str = '2.1.14.27' where sys_id = 1401;      /*Kasa*/
update system_strings set sys_str = '2.1.1.1' where sys_id = 1403;      /*Incomes*/
update system_strings set sys_str = '6.1.8.26' where sys_id = 1404;      /*Rents*/
/*ManyStop>1775*/