ALTER VIEW "EMOBILITY"."V_CHARGEDATA_EMP" ( "ID",
	 "CALLID",
	 "CDRID",
	 "EVSEID",
	 "CONTRACTID",
	 "RFID",
	 "INSTANCE",
	 "TOKENTYPE",
	 "CONSUMEDENERGY",
	 "OPERATORID",
	 "OPERATORNAME",a
	 "OPERATORSUBMANDANT",
	 "FREECHARGE",
	 "CHARGEPOINTTYPE",
	 "MAXSOCKETPOWER",
	 "ADDRESS",
	 "ZIP",
	 "CITY",
	 "COUNTRY",
	 "PROVIDERID",
	 "PROVIDERNAME",
	 "CHARGINGSTARTTIME",
	 "CHARGINGSTOPTIME",
	 "PARKINGSTARTTIME",
	 "PARKINGSTOPTIME",
	 "METERSTART",
	 "METERSTOP",
	 "TARIFF",
	 "CURRENCY",
	 "VAT",
	 "BILLINGVALUEBRUTTO",
	 "BILLINGVALUENETTO",
	 "PARKINGTIMEPRICEBRUTTO",
	 "PARKINGTIMEPRICENETTO",
	 "ADITIONALPRICEBRUTTO",
	 "ADITIONALPRICENETTO",
	 "KWHNETPRICE",
	 "MINUTENETPRICE",
	 "SESSIONNETPRICE",
	 "EICHRECHTTYPE",
	 "MILEAGE",
	 "CREATE_TS",
	 "UPDATE_TS",
	 "STATUS",
	 "BILLING",
	 "SYSTYPE",
	 "VIEWVERSION" ) AS select
	 "UUID",
	 "UUID",
	 "UUID",
	 "FULLEVSEID",
	 "CUSTOMERID",
	 UPPER("RFID"),
	 UPPER("RFID"),
	 'RFID',
	 IFNULL("WATTHOUR",
	 0),
	 'OPERATORID',
	 'OPERATORNAME',
	 'true',
	 CASE "FREECHARGING" WHEN 'yes' 
THEN 'true' WHEN 'no' 
then 'false' 
ELSE '' 
END as FREECHARGE,
	 "PLUGTYPE",
	 0,
	 --'MAXSOCKETPOWER',
"LOCATION_ADDRESS",
	 '',
	 --LOCATION ZIP
 "LOCATION_CITY",
	 'DE',
	 'PROVIDERID',
	 'PROVIDERNAME',
	 
left("STARTTIME",
	 19),
	 
left("STOPTIME",
	 19),
	 
left("STARTTIME",
	 19),
	 
left("STOPTIME",
	 19),
	 IFNULL( "METERSTART",
	 0),
	 IFNULL( "METERSTOP",
	 0),
	 'TARIFF',
	 "CURRENCY",
	 0,
	 --'VAT',
0,
	 --'BILLINGVALUEBRUTTO',
0,
	 --'BILLINGVALUENETTO',
0,
	 --'PARKINGTIMEPRICEBRUTTO',
0,
	 --'PARKINGTIMEPRICENETTO',
0,
	 --'ADITIONALPRICEBRUTTO',
0,
	 --'ADITIONALPRICENETTO',
	 "KWHGROSSPRICE" / '1.16',
	 "MINUTEGROSSPRICE" / '1.16',
	 "SESSIONGROSSPRICE" / '1.16',
	 -- "SESSIONGROSSPRICE" ,
 "EICHRECHTTYPE",
	 "MILEAGE",
	 --'B2CPRICING',
--'ASSETOWNERPRICING',
--'CPOPRICING',
 /* "STATIONUUID",
	 "CUSTOMERID",
	 "STARTTIME",
	 "STOPTIME",
	 "DURATION",
	 "WATTHOUR",
	 "AMOUNT",
	 "CURRENCY",
	 "TRANSACTIONTYPE",
	 "CREATED",
	 "RFID",
	 "STATION",
	 "CUSTOMERGROUPID",
	 "CUSTOMERGROUPNAME",
	 "ORGANIZATIONID",
	 "PAYMENTTYPE",
	 "EVSEID",
	 "PLUGTYPE",
	 "EMPSHARE",
	 "SIGNEDMETERVALUEBEGIN",
	 "SIGNEDMETERVALUEEND",
	 "OPERATORPRICE",
	 "OPERATORCURRENCY",
	 "OPERATORID",
	 "FREECHARGING",
	 "EMPTARIFFID",
	 "EMPTARIFFNAME",
	 "FULLEVSEID",
	 "METERSTART",
	 "METERSTOP",
	 "NOTES",
	 "MILEAGE",
	 */ --"JSONRAW",
"CREATE_TS",
	 "UPDATE_TS",
	 "STATUS",
	 "BILLING",
	 'VIRTAPORTAL',
	 'V 1.4/10.09.2020' 
from "VIRTAPORTAL"."EMP_TRANSACTIONS" 
where "TRANSACTIONTYPE" = 'charge' 
and "WATTHOUR" > 0 
and "DURATION" > 2;

DROP VIEW "EMOBILITY"."V_CHARGEDATA_CPO";
CREATE VIEW "EMOBILITY"."V_CHARGEDATA_CPO" ( "ID",
	 "CALLID",
	 "CDRID",
	 "EVSEID",
	 "CONTRACTID",
	 "RFID",
	 "INSTANCE",
	 "TOKENTYPE",
	 "CONSUMEDENERGY",
	 "OPERATORID",
	 "OPERATORNAME",
	 "OPERATORSUBMANDANT",
	 "FREECHARGE",
	 "CHARGEPOINTTYPE",
	 "MAXSOCKETPOWER",
	 "ADDRESS",
	 "ZIP",
	 "CITY",
	 "COUNTRY",
	 "PROVIDERID",
	 "PROVIDERNAME",
	 "CHARGINGSTARTTIME",
	 "CHARGINGSTOPTIME",
	 "PARKINGSTARTTIME",
	 "PARKINGSTOPTIME",
	 "METERSTART",
	 "METERSTOP",
	 "TARIFF",
	 "CURRENCY",
	 "VAT",
	 "BILLINGVALUEBRUTTO",
	 "BILLINGVALUENETTO",
	 "PARKINGTIMEPRICEBRUTTO",
	 "PARKINGTIMEPRICENETTO",
	 "ADITIONALPRICEBRUTTO",
	 "ADITIONALPRICENETTO",
	 "KWHNETPRICE",
"MINUTENETPRICE",
"SESSIONNETPRICE",
	 "EICHRECHTTYPE",
	 "CREATE_TS",
	 "UPDATE_TS",
	 "STATUS",
	 "BILLING",
	 "SYSTYPE",
	 "VIEWVERSION") AS select
	 "CDRID",
	 IFNULL("UUID",
	CDRID),
	 "CDRID",
	 "FULLEVSEID",
	 CASE WHEN "ROAMINGEMPID" > '' 
THEN 'ROAMING' 
ELSE 'DE-EON-C00000000-0' -- ADHOC
 
END as "CONTRACTID",
	 UPPER("RFID"),
	 UPPER("RFID"),
	 'RFID',
	 IFNULL("WATTHOUR",
	 0),
	 'EMPSELLERID',
	 'EMPSELLERID',
	 'true',
	 CASE "FREECHARGING" WHEN 'yes' 
THEN 'true' WHEN 'no' 
then 'false' 
ELSE '' 
END as FREECHARGE,
	 "PLUGTYPE",
	 0,
	 --'MAXSOCKETPOWER',
"LOCATION_ADDRESS",
	 '',
	 --LOCATION ZIP
 "LOCATION_CITY",
	 'DE',
	 'EMPSELLERID',
	 'STRING',
	 
left("STARTTIME",
	 19),
	 
left("STOPTIME",
	 19),
	 
left("STARTTIME",
	 19),
	 
left("STOPTIME",
	 19),
	 IFNULL( "METERSTART",
	 0),
	 IFNULL( "METERSTOP",
	 0),
	 'TARIFF',
	 'CURRENCY',
	 'VAT',
	 --'BILLINGVALUEBRUTTO',
 IFNULL("AMOUNT",
	 0)/100,
	 --'BILLINGVALUENETTO',
0,
	 --'PARKINGTIMEPRICEBRUTTO',
0,
	 --'PARKINGTIMEPRICENETTO',
0,
	 --'ADITIONALPRICEBRUTTO',
0,
	 --'ADITIONALPRICENETTO',
0,
"KWHNETPRICE",
"MINUTENETPRICE",
"SESSIONNETPRICE",
"EICHRECHTTYPE",
	 "CREATE_TS",
	 "UPDATE_TS",
	 "STATUS",
	 "BILLING",
	 'VIRTAPORTAL',
	 'V 1.2/31.07.2020' 
from "VIRTAPORTAL"."CPO_CHARGES" --where "TRANSACTIONTYPE" = 'charge' 
 
where "PLUGTYPE" IS NOT NULL 
and "WATTHOUR" > 0 
and "DURATION" > 2;



