SET SCHEMA "A19753_EON_P01";
CREATE VIEW "A19753_EON_P01"."V_UO_LOST_CONTRACT_HISTORY_RECORDS" ( "DocEntry",
	 "ObjType",
	 "DocNum",
	 "U_EON_CONTRACT",
	 "U_EON_PERIOD_FROM",
	 "U_EON_PERIOD_TO",
	 "DocDate",
	 "DocTotal" ) AS select
	 t0."DocEntry" ,
	 t0."ObjType" ,
	 t0."DocNum" ,
	 t0."U_EON_CONTRACT" ,
	 t0."U_EON_PERIOD_FROM" ,
	 t0."U_EON_PERIOD_TO" ,
	 t0."DocDate" ,
	 t0."DocTotal" 
from OINV t0 
inner join OUSR t3 on t0."UserSign"=t3."USERID" 
inner join "@EON_CONTRACT" t1 on t1."DocEntry"=t0."U_EON_CONTRACT" 
where not exists ( select
	 1 
	from "@EON_CONTRACT_BILL" t2 
	where t0."DocEntry"=t2."U_DOCENTRY" 
	and t0."ObjType"=t2."U_OBJTYPE" ) 
and t0."DocDate" between '20220902' and '20221231' 
and t0.CANCELED='N' 
and t3.USER_CODE='XAPP' 
order by t1."DocEntry",
	 t0."U_EON_PERIOD_FROM",
	 t0."U_EON_PERIOD_TO",
	 t0."DocEntry" WITH READ ONLY;