Simplificacion de retorno de ventas por unidades
This commit is contained in:
@ -321,7 +321,7 @@ class Venta extends Ideal\Repository
|
||||
* @return array
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchActiveByUnidadIds(array $unidad_ids): array
|
||||
public function fetchActiveArrayByUnidadIds(array $unidad_ids): array
|
||||
{
|
||||
$subSubQuery = $this->connection->getQueryBuilder()
|
||||
->select('MAX(`id`) AS `id`, `venta`')
|
||||
@ -347,7 +347,7 @@ class Venta extends Ideal\Repository
|
||||
return array_map(function($result) {
|
||||
return [
|
||||
'unidad_id' => $result['unidad'],
|
||||
'venta' => $this->load($result)
|
||||
'venta' => $result
|
||||
];
|
||||
}, $results);
|
||||
} catch (PDOException $exception) {
|
||||
|
@ -108,11 +108,11 @@ class Venta extends Service
|
||||
public function getActiveByUnidadIds(array $unidad_ids): array
|
||||
{
|
||||
try {
|
||||
$ventas = $this->ventaRepository->fetchActiveByUnidadIds($unidad_ids);
|
||||
$ventas = $this->ventaRepository->fetchActiveArrayByUnidadIds($unidad_ids);
|
||||
return array_map(function($data) {
|
||||
return [
|
||||
'unidad_id' => $data['unidad_id'],
|
||||
'venta' => $this->process($data['venta'])
|
||||
'venta' => $this->processSimple($data['venta'])
|
||||
];
|
||||
}, $ventas);
|
||||
} catch (Implement\Exception\EmptyResult $exception) {
|
||||
@ -189,6 +189,18 @@ class Venta extends Service
|
||||
return $venta;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $venta
|
||||
* @return array
|
||||
* @throws Read
|
||||
*/
|
||||
protected function processSimple(array $venta): array
|
||||
{
|
||||
$output = $venta;
|
||||
$output['propiedad'] = $this->propiedadService->getArrayById($venta['propiedad']);
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
|
@ -7,6 +7,7 @@ use Psr\Log\LoggerInterface;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal\Service;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Exception;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Model;
|
||||
|
||||
@ -21,6 +22,33 @@ class Propiedad extends Service
|
||||
parent::__construct($logger);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $propiedad_id
|
||||
* @return Model\Venta\Propiedad
|
||||
* @throws Exception\ServiceAction\Read
|
||||
*/
|
||||
public function getById(int $propiedad_id): Model\Venta\Propiedad
|
||||
{
|
||||
try {
|
||||
return $this->process($this->propiedadRepository->fetchById($propiedad_id));
|
||||
} catch (EmptyResult $exception) {
|
||||
throw new Exception\ServiceAction\Read(__CLASS__, $exception);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $propiedad_id
|
||||
* @return array
|
||||
* @throws Exception\ServiceAction\Read
|
||||
*/
|
||||
public function getArrayById(int $propiedad_id): array
|
||||
{
|
||||
try {
|
||||
return $this->propiedadRepository->fetchArrayById($propiedad_id);
|
||||
} catch (EmptyResult $exception) {
|
||||
throw new Exception\ServiceAction\Read(__CLASS__, $exception);
|
||||
}
|
||||
}
|
||||
public function addPropiedad(array $ids): Model\Venta\Propiedad
|
||||
{
|
||||
$unidades = [];
|
||||
@ -90,4 +118,8 @@ class Propiedad extends Service
|
||||
$statement->execute([$propiedad->id, $id]);
|
||||
}
|
||||
}
|
||||
protected function process(Model\Venta\Propiedad $propiedad): Model\Venta\Propiedad
|
||||
{
|
||||
return $propiedad;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user