feature/cierres (#25)

Varios cambios

Co-authored-by: Juan Pablo Vial <jpvialb@incoviba.cl>
Reviewed-on: #25
This commit is contained in:
2025-07-22 13:18:00 +00:00
parent ba57cad514
commit 307f2ac7d7
418 changed files with 20045 additions and 984 deletions

View File

@ -7,8 +7,13 @@ use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Incoviba\Common\Ideal\Controller;
use Incoviba\Common\Implement\Exception\EmptyRedis;
use Incoviba\Common\Implement\Exception\EmptyResponse;
use Incoviba\Common\Implement\Exception\EmptyResult;
use Incoviba\Controller\withRedis;
use Incoviba\Exception\InvalidResult;
use Incoviba\Exception\ServiceAction\Read;
use Incoviba\Exception\ServiceAction\Create;
use Incoviba\Exception\ServiceAction\Update;
use Incoviba\Model;
use Incoviba\Repository;
use Incoviba\Service;
@ -36,7 +41,17 @@ class Ventas extends Controller
$proyectos = $proyectoRepository->fetchAllActive();
$this->saveRedis($redisService, $proyectosKey, $proyectos);
}
$proyecto = array_values(array_filter($proyectos, function($proyecto) use ($proyecto_id) {return $proyecto->id === $proyecto_id;}))[0];
$filtrado = array_filter($proyectos, function($proyecto) use ($proyecto_id) {return $proyecto->id === $proyecto_id;});
if (count($filtrado) === 0) {
$proyectos = $proyectoRepository->fetchAllActive();
$this->saveRedis($redisService, $proyectosKey, $proyectos);
$filtrado = array_filter($proyectos, function($proyecto) use ($proyecto_id) {return $proyecto->id === $proyecto_id;});
if (count($filtrado) === 0) {
return $this->withJson($response, $output);
}
}
$proyecto = array_values($filtrado)[0];
$output['proyecto']['descripcion'] = $proyecto->descripcion;
$redisKey = "ventas:proyecto:{$proyecto_id}";
@ -93,7 +108,7 @@ class Ventas extends Controller
$venta = $service->getById($venta_id);
$output['ventas'] []= $venta;
$this->saveRedis($redisService, $redisKey, $venta);
} catch (EmptyResult $exception) {
} catch (Read $exception) {
$this->logger->notice($exception);
}
}
@ -212,7 +227,8 @@ class Ventas extends Controller
$this->saveRedis($redisService, "venta:{$venta->id}", $venta);
$output['venta_id'] = $venta->id;
$output['status'] = true;
} catch (EmptyResult | PDOException $exception) {
} catch (Create | Update $exception) {
$this->logger->error($exception);
$output['errors'] = [
'code' => $exception->getCode(),
'message' => $exception->getMessage(),
@ -303,6 +319,7 @@ class Ventas extends Controller
return $this->withJson($response, $output);
}
public function propietario(ServerRequestInterface $request, ResponseInterface $response,
Service\Venta\MediosPago\Toku\Customer $customerService,
Service\Venta\Propietario $propietarioService,
Repository\Venta $ventaRepository, int $venta_id): ResponseInterface
{
@ -332,8 +349,20 @@ class Ventas extends Controller
} else {
$propietario = $propietarioService->edit($propietario, $data);
}
try {
$customer = $customerService->getById($propietario->rut);
$customerData = [
'rut' => $customer['rut'],
'nombreCompleto' => $propietario->nombreCompleto(),
'email' => $propietario->datos?->email ?? '',
'telefono' => $propietario->datos?->telefono ?? ''
];
$customerService->edit($customer['toku_id'], $customerData);
} catch (InvalidResult|EmptyResponse $exception) {
$this->logger->warning($exception);
}
$output['edited'] = true;
} catch (EmptyResult) {}
} catch (EmptyResult|Read|Create|Update) {}
return $this->withJson($response, $output);
}
@ -368,4 +397,17 @@ class Ventas extends Controller
} catch (EmptyResult) {}
return $this->withJson($response, $output);
}
public function byUnidades(ServerRequestInterface $request, ResponseInterface $response,
Service\Venta $ventaService, Service\Venta\Unidad $unidadService): ResponseInterface
{
$input = $request->getParsedBody();
$output = [
'input' => $input,
'ventas' => []
];
try {
$output['ventas'] = $ventaService->getActiveByUnidadIds($input['unidad_ids']);
} catch (Read) {}
return $this->withJson($response, $output);
}
}