<?php
include("conexion.php");
$json = file_get_contents('php://input');
$data = json_decode($json,true);
$dataid = $data['Packets'][0]['Id'];
$tipotran = $data['Packets'][0]['Type'];

$fechafin = $data['Packets'][0]['Data'][0]['DateTime'];
$fechaini = $data['Packets'][0]['Data'][0]['DateTimeStart'];
$surtidor = $data['Packets'][0]['Data'][0]['Pump'];
$manguera = $data['Packets'][0]['Data'][0]['Nozzle'];
$combusid = $data['Packets'][0]['Data'][0]['FuelGradeId'];
$combunom = $data['Packets'][0]['Data'][0]['FuelGradeName'];
$tranid   = $data['Packets'][0]['Data'][0]['Transaction'];
$userid   = $data['Packets'][0]['Data'][0]['UserId'];
$volumen  = $data['Packets'][0]['Data'][0]['Volume'];
$precio   = $data['Packets'][0]['Data'][0]['Price'];
$totalvta = $data['Packets'][0]['Data'][0]['Amount'];
$totsoles = $data['Packets'][0]['Data'][0]['TotalAmount'];
$totgalon = $data['Packets'][0]['Data'][0]['TotalVolume'];

if ($tipotran=="UploadPumpTransaction"){
	$oC= new Access_clsConexion();
        $vC="insert into public.transaccion values (DEFAULT,'".$fechaini."','".$fechafin."',".$surtidor.",".$manguera.",".$combusid.",'".$combunom."',".$tranid.",".$userid.",".$volumen.",".$precio.",".$totalvta.",".$totsoles.",".$totgalon.");";
        $oC->Ejecutar_Consulta($vC);
echo "HTTP/1.1 200 OK";
echo "Content-Type: application/json; charset=utf-8";
echo "Content-Length: 188";
echo '{
 "Protocol":"jsonPTS",
 "Packets":[{
 "Id":'.$dataid.',
 "Type":"UploadPumpTransaction",
 "Message":"OK"
}
]
}
';
/*$vGestor=fopen("logpts.txt", "a");
fwrite($vGestor, date('Y-m-d H:i:s')."\tData:".$json."\tID:".$dataid."\tHost:".$_SERVER['AUTH_TYPE']."\tRequest-->".$_SERVER['REQUEST_METHOD']."\tTipo-->".$tipotran."\tTransaccion-->".$combunom."\tPrecio-->$precio\tGalones-->$galones\tTotal-->$total\tCont Galones-->$totalgalon\tTotal Soles-->$totalsoles"."\r\n".$vC);
fclose($vGestor);*/
}
?>
