Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intermediate version adding UNITS management #25

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9,010 changes: 4,505 additions & 4,505 deletions datos/REE.csv

Large diffs are not rendered by default.

136 changes: 136 additions & 0 deletions proxy-Catastro-detalle x refcat.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
<?PHP
// Allow from any origin
if (isset($_SERVER['HTTP_ORIGIN'])) {
header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Max-Age: 86400'); // cache for 1 day
}

// Access-Control headers are received during OPTIONS requests
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']))
header("Access-Control-Allow-Methods: GET, POST, OPTIONS");

if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']))
header("Access-Control-Allow-Headers: {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");

exit(0);
}

$urlbase = "http://ovc.catastro.meh.es/OVCServWeb/OVCWcfCallejero/COVCCallejero.svc/json/Consulta_DNPRC?RefCat=";
$t1 = date("Y/m/d H:i:s");
if(isset($_GET['idSesion']))
{
$idSesion = $_GET['idSesion'];
}

if(isset($_GET['refcat']))
{
$refcat = $_GET['refcat'];
}
$url = $urlbase . $refcat;

//Initialize cURL.
$ch = curl_init();

//Set the URL that you want to GET by using the CURLOPT_URL option.
curl_setopt($ch, CURLOPT_URL, $url);

//Set CURLOPT_RETURNTRANSFER so that the content is returned as a variable.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

//Set CURLOPT_FOLLOWLOCATION to true to follow redirects.
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

//Execute the request.
$datoFincas = curl_exec($ch);

//Close the cURL handle.
curl_close($ch);

$jsonFincas = json_decode($datoFincas);
//echo json_encode($jsonFincas->consulta_dnprcResult);
$control = $jsonFincas->consulta_dnprcResult->control;

$numeroFincas = $control->cudnp;
if (property_exists($control, 'cucons')) {
$numeroUnidades = $control->cucons;
} /* else {
$fincas = $jsonFincas->consulta_dnprcResult->lrcdnp->rcdnp;
} */
$i = 0;
$pref = '';
$datos = '[';
if (property_exists($jsonFincas->consulta_dnprcResult, 'bico')) {
//echo json_encode($jsonFincas->consulta_dnprcResult->bico->bi->debi);
$finca = $jsonFincas->consulta_dnprcResult->bico->bi->idbi;
$refcatLarga = $finca->rc->pc1 . $finca->rc->pc2 . $finca->rc->car . $finca->rc->cc1 . $finca->rc->cc2;
if ($i > 0) $pref = ',';
$datos = $datos . $pref . '{"idFinca":"' . $i . '","refcat":"' . $refcatLarga . '"';
$detalles = $jsonFincas->consulta_dnprcResult->bico->bi->debi;
$datos = $datos . ',"uso":"' . $detalles->luso . '"';
$datos = $datos . ',"superficie":"' . $detalles->sfc .'"';

if (property_exists($detalles, 'cpt')) {
$datos = $datos . ',"participacion":"' . $detalles->cpt . '"';
} else {
$datos = $datos . ',"participacion":"100"';
};


/* $datos = $datos . ',"participacion":"' . $detalles->cpt .'"'; */
$datos = $datos . ',"tipoConsumo":"Por definir"}';
$i = $i + 1;

} else if (property_exists($jsonFincas->consulta_dnprcResult, 'lrcdnp')) {

foreach($jsonFincas->consulta_dnprcResult->lrcdnp->rcdnp as $finca) {
$refcatLarga = $finca->rc->pc1 . $finca->rc->pc2 . $finca->rc->car . $finca->rc->cc1 . $finca->rc->cc2;
$url = $urlbase . $refcatLarga;

if ($i > 0) $pref = ',';
$datos = $datos . $pref . '{"idFinca":"' . $i . '","refcat":"' . $refcatLarga . '"';
$ubicacion = $finca->dt->locs->lous->lourb->loint;
$nombre = "";
if (property_exists($ubicacion, 'bq')) {
$datos = $datos . ',"bloque":"' . $ubicacion->bq . '"';
$nombre = $nombre . 'BL-' . $ubicacion->bq;
};
if (property_exists($ubicacion, 'es')) {
$datos = $datos . ',"escalera":"' . $ubicacion->es . '"';
$nombre = $nombre . 'ES-' . $ubicacion->es;
};
if (property_exists($ubicacion, 'pt')) {
$datos = $datos . ',"planta":"' . $ubicacion->pt . '"';
$nombre = $nombre . 'PL-' . $ubicacion->pt;
};
if (property_exists($ubicacion, 'pu')) {
$datos = $datos . ',"puerta":"' . $ubicacion->pu . '"';
$nombre = $nombre . 'PU-' . $ubicacion->pu;
};

$datos = $datos . ',"nombreFinca":"' . $nombre . '"';

/* echo "dt: " . json_encode($jsonDetallado->consulta_dnprcResult->bico->bi->debi); */
$detalles = $finca->debi;
$datos = $datos . ',"uso":"' . $detalles->luso . '"';
$datos = $datos . ',"superficie":"' . $detalles->sfc .'"';

if (property_exists($detalles, 'cpt')) {
$datos = $datos . ',"participacion":"' . $detalles->cpt . '"}';
} else {
$datos = $datos . ',"participacion":"100"}';
};
$i = $i + 1;
}
}
$datos = $datos . ']';
echo $datos;

$t2 = date("Y/m/d H:i:s");
//Log call
$file = fopen("./log/CatastroCalls.txt", "a");
fwrite($file, $idSesion . ";" . $t1 . ";" . $t2 . ";" . $url . PHP_EOL);
fclose($file);

?>
71 changes: 71 additions & 0 deletions proxy-Catastro-refcat x lonlat.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?PHP
// Allow from any origin
if (isset($_SERVER['HTTP_ORIGIN'])) {
header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Max-Age: 86400'); // cache for 1 day
}

// Access-Control headers are received during OPTIONS requests
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']))
header("Access-Control-Allow-Methods: GET, POST, OPTIONS");

if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']))
header("Access-Control-Allow-Headers: {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");

exit(0);
}
$url = "http://ovc.catastro.meh.es/OVCServWeb/OVCWcfCallejero/COVCCoordenadas.svc/json/Consulta_RCCOOR?SRS=epsg:4326";

if(isset($_GET['coorX']))
{
$coorX = $_GET['coorX'];
}
if(isset($_GET['coorY']))
{
$coorY = $_GET['coorY'];
}
$url = $url . '&coorX=' . $coorX . '&coorY=' . $coorY;

//Initialize cURL.
$ch = curl_init();

//Set the URL that you want to GET by using the CURLOPT_URL option.
curl_setopt($ch, CURLOPT_URL, $url);

//Set CURLOPT_RETURNTRANSFER so that the content is returned as a variable.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

//Set CURLOPT_FOLLOWLOCATION to true to follow redirects.
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

//Execute the request.
$datoRC = curl_exec($ch);
//Close the cURL handle.
curl_close($ch);
try {
$jsonRC = json_decode($datoRC);
if (isset($jsonRC)){
$control = $jsonRC->Consulta_RCCOORResult;
if(isset($control->lerr)) {
$response = array('codigo' => $control->lerr[0]->cod, 'descripcion' => $control->lerr[0]->des);
} else if (isset($jsonRC->Consulta_RCCOORResult->coordenadas)) {
$parcela = $jsonRC->Consulta_RCCOORResult->coordenadas->coord[0];
$RC = $parcela->pc->pc1 . $parcela->pc->pc2;
$direccion = $parcela->ldt;

$response = array('codigo' => 0, 'refcat' => $RC, 'direccion' => $direccion);
} else {
$response = array('codigo' => -1, 'descripcion' => $jsonRC);
}
} else {
$response = array('codigo' => -3, 'descripcion' => $datoRC);
}
}
catch(Exception $e) {
$response = array('codigo' => -2, 'descripcion' => $e->getMessage . "\n" . $jsonRC);
}
echo json_encode($response);

?>
70 changes: 39 additions & 31 deletions src/Simulator/Consumption/ConsumptionSummary.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -261,37 +261,45 @@ export default function ConsumptionSummary() {

function footerSummary() {
return (
<SLDRFooterBox>
<Grid
container
alignItems="center"
justifyContent="center"
spacing={2}
sx={{ mt: '2rem' }}
>
<Grid item>
<Typography
sx={theme.titles.level_2}
textAlign={'center'}
dangerouslySetInnerHTML={{
__html: t('CONSUMPTION.TOTAL_DEMMAND', {
consumoTotal: formatoValor(
'energia',
Math.round(tipoConsumo.reduce((sum, tc) => sum + tc.totalAnual, 0)),
),
}),
}}
/>
</Grid>
<Grid item>
<Tooltip title={t('CONSUMPTION.TOOLTIP_botonMuestraTodosTipoConsumo')}>
<IconButton onClick={showGraphTotales}>
<AnalyticsIcon />
</IconButton>
</Tooltip>
</Grid>
</Grid>
</SLDRFooterBox>
<>
{TCB.modoActivo === 'INDIVIDUAL' ? (
<SLDRFooterBox>
<Grid
container
alignItems="center"
justifyContent="center"
spacing={2}
sx={{ mt: '2rem' }}
>
<Grid item>
<Typography
sx={theme.titles.level_2}
textAlign={'center'}
dangerouslySetInnerHTML={{
__html: t('CONSUMPTION.TOTAL_DEMMAND', {
consumoTotal: formatoValor(
'energia',
Math.round(
tipoConsumo.reduce((sum, tc) => sum + tc.totalAnual, 0),
),
),
}),
}}
/>
</Grid>
<Grid item>
<Tooltip title={t('CONSUMPTION.TOOLTIP_botonMuestraTodosTipoConsumo')}>
<IconButton onClick={showGraphTotales}>
<AnalyticsIcon />
</IconButton>
</Tooltip>
</Grid>
</Grid>
</SLDRFooterBox>
) : (
' '
)}
</>
)
}

Expand Down
27 changes: 21 additions & 6 deletions src/Simulator/ConsumptionContext.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@ const ConsumptionContext = createContext({})
const ConsumptionContextProvider = ({ children }) => {
const { t } = useTranslation()
const [tipoConsumo, setTipoConsumo] = useState([])
const [fincas, setFincas] = useState([])
const [zonasComunes, setZonasComunes] = useState([])
const [fincasCargadas, setFincasCargadas] = useState(false)
const [preciosValidos, setPreciosValidos] = useState(true)
const [repartoValido, setRepartoValido] = useState(false)
const [allocationGroup, setAllocationGroup] = useState()

//TCB fields to be reflected in state
const hdrTipo = {
idTipoConsumo: undefined,
nombreTipoConsumo: undefined,
nombreTipoConsumo: '',
fuente: undefined,
consumoAnualREE: undefined,
ficheroCSV: undefined,
Expand Down Expand Up @@ -46,17 +51,18 @@ const ConsumptionContextProvider = ({ children }) => {
}

function validaTipoConsumo() {
if (TCB.TipoConsumo.length === 0) {
return { status: false, error: t('CONSUMPTION.ERROR_AL_MENOS_UN_TIPOCONSUMO') }
}

if (!preciosValidos) {
return {
status: false,
error: 'Debe definir los precios correctos de las tarifas antes de continuar',
}
}
return { status: true, error: '' }

if (TCB.TipoConsumo.length === 0) {
return { status: false, error: t('CONSUMPTION.ERROR_AL_MENOS_UN_TIPOCONSUMO') }
} else {
return { status: true, error: '' }
}
}

const contextValue = {
Expand All @@ -66,6 +72,15 @@ const ConsumptionContextProvider = ({ children }) => {
preciosValidos,
setPreciosValidos,
addTCBTipoToState,
fincas,
setFincas,
fincasCargadas,
zonasComunes,
setZonasComunes,
repartoValido,
setRepartoValido,
allocationGroup,
setAllocationGroup,
}

return (
Expand Down
Loading