
/*ALIAS>prop_db*/
/*Hist_TBL>SQL_UPDATES_INCOMES*/

/*SQLStart>7046*/
delete from taking where t_personid = -1;
/*SQLStop*/

/*SQLStart>7047*/
create or alter procedure UPDATE_TAKING_DIFFERENCE
as
declare variable T_SUM numeric(15,2);
declare variable EXP_SUM numeric(15,2);
declare variable T_ID integer;
begin
    FOR select t_id, t_dutysum, ts.takingexpectedsum
        from taking t
        left join takingsums ts on takingid = t_id
        where
            ((ts.takingexpectedsum - t.t_dutysum) > 0.001)
            and (t.t_appcode = "D")
        into :t_id, :t_sum, :exp_sum
    DO
        BEGIN
            UPDATE paytaking
            SET PT_EXPECTEDSUM = :t_sum
            WHERE PT_ID = :t_id;
			
			UPDATE takingsums
            SET takingexpectedsum = :t_sum
            WHERE takingid = :t_id;
        END
end;
/*SQLStop*/

/*SQLStart>7048*/
execute procedure UPDATE_TAKING_DIFFERENCE
/*SQLStop*/

/*SQLStart>7049*/
drop procedure UPDATE_TAKING_DIFFERENCE;
/*SQLStop*/