Optimizacion de queries a cargar de una sola vez
This commit is contained in:
@ -168,18 +168,10 @@ class Contracts
|
||||
if (is_string($unit_ids)) {
|
||||
$unit_ids = json_decode($input['unidad_ids'], true);
|
||||
}
|
||||
foreach ($unit_ids as $unit_id) {
|
||||
try {
|
||||
$unit = $unitRepository->fetchById($unit_id);
|
||||
$contractService->getById($contract_id);
|
||||
$promotions = $promotionRepository->fetchByContractAndUnit($contract_id, $unit->id);
|
||||
$output['unidades'] []= [
|
||||
'id' => $unit->id,
|
||||
'promotions' => $promotions
|
||||
];
|
||||
} catch (ServiceAction\Read | Implement\Exception\EmptyResult $exception) {
|
||||
$logger->debug($exception);
|
||||
}
|
||||
try {
|
||||
$output['unidades'] = $promotionRepository->fetchByContractAndUnits($contract_id, $unit_ids);
|
||||
} catch (Implement\Exception\EmptyResult $exception) {
|
||||
$logger->debug($exception);
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
|
@ -34,14 +34,7 @@ class Unidades extends Ideal\Controller
|
||||
}
|
||||
try {
|
||||
$proyecto = $proyectoService->getById($proyecto_id);
|
||||
foreach ($unidad_ids as $unidad_id) {
|
||||
try {
|
||||
$output['precios'][] = [
|
||||
'id' => $unidad_id,
|
||||
'precio' => $precioRepository->fetchVigenteByUnidad((int) $unidad_id)
|
||||
];
|
||||
} catch (Implement\Exception\EmptyResult) {}
|
||||
}
|
||||
$output['precios'] = $precioRepository->fetchVigentesByUnidades($unidad_ids);
|
||||
} catch (Implement\Exception\EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
@ -62,21 +55,7 @@ class Unidades extends Ideal\Controller
|
||||
}
|
||||
try {
|
||||
$proyecto = $proyectoService->getById($proyecto_id);
|
||||
foreach ($unidad_ids as $unidad_id) {
|
||||
$output['estados'][] = [
|
||||
'id' => $unidad_id,
|
||||
'sold' => false
|
||||
];
|
||||
try {
|
||||
$unidad = $unidadRepository->fetchById($unidad_id);
|
||||
try {
|
||||
$output['estados'][] = [
|
||||
'id' => $unidad_id,
|
||||
'sold' => $unidadRepository->fetchSoldByUnidad($unidad->id)
|
||||
];
|
||||
} catch (Implement\Exception\EmptyResult) {}
|
||||
} catch (Implement\Exception\EmptyResult) {}
|
||||
}
|
||||
$output['estados'] = $unidadRepository->fetchSoldByUnidades($unidad_ids);
|
||||
} catch (Implement\Exception\EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
|
@ -377,15 +377,9 @@ class Ventas extends Controller
|
||||
'input' => $input,
|
||||
'ventas' => []
|
||||
];
|
||||
foreach ($input['unidad_ids'] as $unidad_id) {
|
||||
try {
|
||||
$venta = $ventaService->getByUnidadId($unidad_id);
|
||||
$output['ventas'][] = [
|
||||
'unidad_id' => $unidad_id,
|
||||
'venta' => $venta
|
||||
];
|
||||
} catch (Read) {}
|
||||
}
|
||||
try {
|
||||
$output['ventas'] = $ventaService->getActiveByUnidadIds($input['unidad_ids']);
|
||||
} catch (Read) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user