-- B1 DEPENDS: AFTER:PT:PROCESS_END AFTER:SP:CFF_CREATEDBOBJECTS AFTER:SP:CFF_BLANKETAGREEMENT_DETAIL

CREATE PROCEDURE CFF_BLANKETAGREEMENT_OVERVIEW (IN dateFrom	DATE, 
												IN dateTo	DATE)
LANGUAGE SQLSCRIPT 
SQL SECURITY INVOKER
AS 
BEGIN 
	CALL CFF_BLANKETAGREEMENT_DETAIL(:dateFrom, :dateTo);
	
	INSERT INTO "CFF_TMP_OVERVIEW_BA"
		SELECT T1."EndDate", SUM(T0."Debit"), SUM(T0."Credit"), T0."ObjType", T0."Group", COUNT(*) FROM "CFF_TMP_DETAIL_BA" T0
		INNER JOIN "CFF_TMP_DATE" T1 ON T0."DueDate" BETWEEN T1."StartDate" AND T1."EndDate"
		GROUP BY T1."EndDate", T0."ObjType", T0."Group";

END;