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