CREATE VIEW "EOPERATE"."V_CHARGEDATA" ( "CHECK_CONSUMED_WATTHOUR",
	 "CHECK_START_STOP",
	 "CHECK_DURATION",
	 "CHECK_CONTRACT_EXISTS",
	 "CHECK_BILLING",
	 "BILLING_ID",
	 "BDR_ID",
	 "EMAID",
	 "UNIQUE_ID",
	 "CREATION_DATE_UTC",
	 "CHARGEPOINT_ID",
	 "CHARGEPOINT_TYPE",
	 "CHARGEPOINT_METER_ID",
	 "CHARGEPOINT_ADDRESS_COUNTRY",
	 "CHARGEPOINT_ADDRESS_POSTALCODE",
	 "CHARGEPOINT_ADDRESS_CITY",
	 "CHARGEPOINT_ADDRESS_STREET",
	 "CHARGEPOINT_OPERATOR_ID",
	 "CHARGEPOINT_OPERATOR_NAME",
	 "EMOBILITY_PROVIDER_ID",
	 "EMOBILITY_PROVIDER_NAME",
	 "CHARGE_DATA_AUTHORIZATION_TYPE",
	 "CHARGE_DATA_CONSUMPTION_KWH",
	 "CHARGE_DATA_BEGIN_UTC",
	 "CHARGE_DATA_END_UTC",
	 "CHARGE_DATA_TIME_ZONE",
	 "CHARGE_DATA_EKA_STATUS",
	 "SUBSCRIPTION_ID",
	 "PRICING_ITEMS_1_TYPE",
	 "PRICING_ITEMS_1_UNIT",
	 "PRICING_ITEMS_1_UNIT_PRICE",
	 "PRICING_ITEMS_1_QUANTITY",
	 "PRICING_ITEMS_1_NET_AMOUNT",
	 "PRICING_ITEMS_1_CURRENCY",
	 "PRICING_ITEMS_2_TYPE",
	 "PRICING_ITEMS_2_UNIT",
	 "PRICING_ITEMS_2_UNIT_PRICE",
	 "PRICING_ITEMS_2_QUANTITY",
	 "PRICING_ITEMS_2_NET_AMOUNT",
	 "PRICING_ITEMS_2_CURRENCY",
	 "PRICING_ITEMS_3_TYPE",
	 "PRICING_ITEMS_3_UNIT",
	 "PRICING_ITEMS_3_UNIT_PRICE",
	 "PRICING_ITEMS_3_QUANTITY",
	 "PRICING_ITEMS_3_NET_AMOUNT",
	 "PRICING_ITEMS_3_CURRENCY",
	 "PRICING_ITEMS_4_TYPE",
	 "PRICING_ITEMS_4_UNIT",
	 "PRICING_ITEMS_4_UNIT_PRICE",
	 "PRICING_ITEMS_4_QUANTITY",
	 "PRICING_ITEMS_4_NET_AMOUNT",
	 "PRICING_ITEMS_4_CURRENCY",
	 "CREATE_TS",
	 "UPDATE_TS",
	 "CREATE_USER",
	 "UPDATE_USER" ) AS WITH "EVDRV" AS (select
	 distinct U_EOPERATE_ID 
	from "A19753_EON_P01"."@EON_CONTRACT_EVDRV" 
	where U_EOPERATE_ID <> '') SELECT
	 CASE WHEN CHARGE_DATA_CONSUMPTION_KWH > 120 
OR CHARGE_DATA_CONSUMPTION_KWH = 0 
THEN 'INVALID' 
ELSE 'OK' 
END as "CHECK_CONSUMED_WATTHOUR",
	 CASE WHEN CHARGE_DATA_BEGIN_UTC IS NULL 
THEN 'NULL' WHEN CHARGE_DATA_BEGIN_UTC = CHARGE_DATA_END_UTC 
THEN 'EQUAL' WHEN CHARGE_DATA_END_UTC < CHARGE_DATA_BEGIN_UTC 
THEN 'INVALID' 
ELSE 'OK' 
END AS "CHECK_START_STOP",
	 'OK' AS "CHECK_DURATION",
	 CASE WHEN EVDRV.U_EOPERATE_ID IS NULL 
THEN 'NO CONTRACT' 
ELSE 'OK' 
END as "CHECK_CONTRACT_EXISTS",
	 (SELECT
	 LAST_VALUE(STATUS 
		order by ID) 
	FROM "A19753_EON_P01"."EON_CHARGEDATA" CD 
	WHERE CD.NICE_CDRID = ET.UNIQUE_ID 
	AND CD.BILLING_MODE = 'EMP' ) as CHECK_BILLING,
	 (SELECT
	 MAX(ID ) 
	FROM "A19753_EON_P01"."EON_CHARGEDATA" CD 
	WHERE CD.NICE_CDRID = ET.UNIQUE_ID 
	AND CD.BILLING_MODE = 'EMP' ) as BILLING_ID,
	 "BDR_ID",
	 "EMAID",
	 "UNIQUE_ID",
	 "CREATION_DATE_UTC",
	 "CHARGEPOINT_ID",
	 "CHARGEPOINT_TYPE",
	 "CHARGEPOINT_METER_ID",
	 "CHARGEPOINT_ADDRESS_COUNTRY",
	 "CHARGEPOINT_ADDRESS_POSTALCODE",
	 "CHARGEPOINT_ADDRESS_CITY",
	 "CHARGEPOINT_ADDRESS_STREET",
	 "CHARGEPOINT_OPERATOR_ID",
	 "CHARGEPOINT_OPERATOR_NAME",
	 "EMOBILITY_PROVIDER_ID",
	 "EMOBILITY_PROVIDER_NAME",
	 "CHARGE_DATA_AUTHORIZATION_TYPE",
	 "CHARGE_DATA_CONSUMPTION_KWH",
	 "CHARGE_DATA_BEGIN_UTC",
	 "CHARGE_DATA_END_UTC",
	 "CHARGE_DATA_TIME_ZONE",
	 "CHARGE_DATA_EKA_STATUS",
	 "SUBSCRIPTION_ID",
	 "PRICING_ITEMS_1_TYPE",
	 "PRICING_ITEMS_1_UNIT",
	 "PRICING_ITEMS_1_UNIT_PRICE",
	 "PRICING_ITEMS_1_QUANTITY",
	 "PRICING_ITEMS_1_NET_AMOUNT",
	 "PRICING_ITEMS_1_CURRENCY",
	 "PRICING_ITEMS_2_TYPE",
	 "PRICING_ITEMS_2_UNIT",
	 "PRICING_ITEMS_2_UNIT_PRICE",
	 "PRICING_ITEMS_2_QUANTITY",
	 "PRICING_ITEMS_2_NET_AMOUNT",
	 "PRICING_ITEMS_2_CURRENCY",
	 "PRICING_ITEMS_3_TYPE",
	 "PRICING_ITEMS_3_UNIT",
	 "PRICING_ITEMS_3_UNIT_PRICE",
	 "PRICING_ITEMS_3_QUANTITY",
	 "PRICING_ITEMS_3_NET_AMOUNT",
	 "PRICING_ITEMS_3_CURRENCY",
	 "PRICING_ITEMS_4_TYPE",
	 "PRICING_ITEMS_4_UNIT",
	 "PRICING_ITEMS_4_UNIT_PRICE",
	 "PRICING_ITEMS_4_QUANTITY",
	 "PRICING_ITEMS_4_NET_AMOUNT",
	 "PRICING_ITEMS_4_CURRENCY",
	 "CREATE_TS",
	 "UPDATE_TS",
	 "CREATE_USER",
	 "UPDATE_USER" 
from "EOPERATE"."CHARGEDATA" ET 
LEFT OUTER join EVDRV on ET."EMAID" = EVDRV.U_EOPERATE_ID WITH READ ONLY