Limpieza de input de valor y filtro de datos a nivel Repo
This commit is contained in:
@ -14,51 +14,23 @@ class Escrituras
|
||||
use withJson;
|
||||
|
||||
public function add(ServerRequestInterface $request, ResponseInterface $response,
|
||||
Repository\Venta $ventaRepository, Service\Venta $ventaService,
|
||||
Repository\Venta\Escritura $escrituraRepository, Service\Venta\Pago $pagoService,
|
||||
Service\UF $ufService, int $venta_id): ResponseInterface
|
||||
Service\Venta\Escritura $escrituraService, int $venta_id): ResponseInterface
|
||||
{
|
||||
$body = $request->getParsedBody();
|
||||
$output = [
|
||||
'venta_id' => $venta_id,
|
||||
'input' => $body,
|
||||
'escritura' => null,
|
||||
'status' => false
|
||||
];
|
||||
try {
|
||||
$venta = $ventaService->getById($venta_id);
|
||||
if (isset($venta->formaPago()->escritura)) {
|
||||
throw new EmptyResult('');
|
||||
}
|
||||
$fecha = new DateTimeImmutable($body['fecha']);
|
||||
$uf = $ufService->get($fecha);
|
||||
$valor = $body['valor'];
|
||||
if (str_contains($valor, ',')) {
|
||||
$valor = str_replace(['.', ','], ['', '.'], $valor);
|
||||
}
|
||||
$valor = ((float) $valor) * (($body['uf']) ? $uf : 1);
|
||||
$data = [
|
||||
'fecha' => $fecha->format('Y-m-d'),
|
||||
'valor' => $valor,
|
||||
'banco' => $body['banco'],
|
||||
'tipo' => $body['tipo'],
|
||||
'uf' => $uf
|
||||
];
|
||||
$pago = $pagoService->add($data);
|
||||
$data = [
|
||||
'valor' => $valor,
|
||||
'fecha' => $fecha->format('Y-m-d'),
|
||||
'uf' => $uf,
|
||||
'pago' => $pago->id
|
||||
];
|
||||
$escritura = $escrituraRepository->create($data);
|
||||
$escrituraRepository->save($escritura);
|
||||
$ventaRepository->edit($venta, ['escritura' => $escritura->id]);
|
||||
$output['escritura'] = $escrituraService->add($venta_id, $body);
|
||||
$output['status'] = true;
|
||||
} catch (EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function edit(ServerRequestInterface $request, ResponseInterface $response,
|
||||
Service\Venta $ventaService, Repository\Venta\EstadoVenta $estadoVentaRepository,
|
||||
Service\Venta\Escritura $escrituraService,
|
||||
int $venta_id): ResponseInterface
|
||||
{
|
||||
$body = $request->getParsedBody();
|
||||
@ -68,13 +40,7 @@ class Escrituras
|
||||
'edited' => false
|
||||
];
|
||||
try {
|
||||
$venta = $ventaService->getById($venta_id);
|
||||
$estado = $venta->currentEstado();
|
||||
if (!in_array($estado->tipoEstadoVenta->descripcion, ['escriturando', 'firmado por inmobiliaria'])) {
|
||||
throw new EmptyResult('');
|
||||
}
|
||||
$body['fecha'] = (new DateTimeImmutable($body['fecha']))->format('Y-m-d');
|
||||
$estadoVentaRepository->edit($estado, $body);
|
||||
$escrituraService->edit($venta_id, $body);
|
||||
$output['edited'] = true;
|
||||
} catch (EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
|
@ -34,8 +34,7 @@ class Facturacion extends Ideal\Service
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function ventas(ServerRequestInterface $request, ResponseInterface $response, Service\Redis $redisService,
|
||||
Service\Venta $ventaService, Service\Proyecto\Terreno $terrenoService, Service\UF $ufService,
|
||||
Service\IPC $ipcService): ResponseInterface
|
||||
Service\Venta $ventaService): ResponseInterface
|
||||
{
|
||||
$input = $request->getParsedBody();
|
||||
$output = [
|
||||
|
@ -1,7 +1,9 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller\API\Ventas;
|
||||
|
||||
use Exception;
|
||||
use DateTimeImmutable;
|
||||
use Incoviba\Model\Venta\Pago;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
@ -26,6 +28,15 @@ class Pagos
|
||||
} catch (EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ServerRequestInterface $request
|
||||
* @param ResponseInterface $response
|
||||
* @param Repository\Venta\Pago $pagoRepository
|
||||
* @param int $pago_id
|
||||
* @return ResponseInterface
|
||||
* @throws Exception
|
||||
*/
|
||||
public function edit(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Pago $pagoRepository, int $pago_id): ResponseInterface
|
||||
{
|
||||
$body = $request->getParsedBody();
|
||||
@ -44,6 +55,16 @@ class Pagos
|
||||
} catch (EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ServerRequestInterface $request
|
||||
* @param ResponseInterface $response
|
||||
* @param Service\Venta\Pago $pagoService
|
||||
* @param Service\Format $formatService
|
||||
* @param int $pago_id
|
||||
* @return ResponseInterface
|
||||
* @throws Exception
|
||||
*/
|
||||
public function depositar(ServerRequestInterface $request, ResponseInterface $response,
|
||||
Service\Venta\Pago $pagoService, Service\Format $formatService, int $pago_id): ResponseInterface
|
||||
{
|
||||
@ -63,6 +84,16 @@ class Pagos
|
||||
} catch (EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ServerRequestInterface $request
|
||||
* @param ResponseInterface $response
|
||||
* @param Service\Venta\Pago $pagoService
|
||||
* @param Service\Format $formatService
|
||||
* @param int $pago_id
|
||||
* @return ResponseInterface
|
||||
* @throws Exception
|
||||
*/
|
||||
public function abonar(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pago $pagoService,
|
||||
Service\Format $formatService, int $pago_id): ResponseInterface
|
||||
{
|
||||
@ -83,6 +114,15 @@ class Pagos
|
||||
} catch (EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ServerRequestInterface $request
|
||||
* @param ResponseInterface $response
|
||||
* @param Service\Venta\Pago $pagoService
|
||||
* @param int $pago_id
|
||||
* @return ResponseInterface
|
||||
* @throws Exception
|
||||
*/
|
||||
public function devolver(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pago $pagoService, int $pago_id): ResponseInterface
|
||||
{
|
||||
$body = $request->getParsedBody();
|
||||
@ -102,34 +142,49 @@ class Pagos
|
||||
public function para_pendientes(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pago $pagoService): ResponseInterface
|
||||
{
|
||||
$pagos = $pagoService->getPendientes();
|
||||
$pagos_pendientes = [];
|
||||
$pagos_pendientes = array_map(function(Pago $pago) {
|
||||
return [
|
||||
'id' => $pago->id
|
||||
];
|
||||
}, $pagos);
|
||||
/*$pagos_pendientes = [];
|
||||
foreach ($pagos as $pago) {
|
||||
$pagos_pendientes []= [
|
||||
'id' => $pago->id
|
||||
];
|
||||
}
|
||||
}*/
|
||||
return $this->withJson($response, ['pagos' => $pagos_pendientes, 'total' => count($pagos_pendientes)]);
|
||||
}
|
||||
public function para_abonar(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pago $pagoService): ResponseInterface
|
||||
{
|
||||
$pagos = $pagoService->getDepositados();
|
||||
$pagos_depositados = [];
|
||||
$pagos_depositados = array_map(function(Pago $pago) {
|
||||
return [
|
||||
'id' => $pago->id
|
||||
];
|
||||
}, $pagos);
|
||||
/*$pagos_depositados = [];
|
||||
foreach ($pagos as $pago) {
|
||||
$pagos_depositados []= [
|
||||
'id' => $pago->id
|
||||
];
|
||||
}
|
||||
}*/
|
||||
return $this->withJson($response, ['pagos' => $pagos_depositados, 'total' => count($pagos_depositados)]);
|
||||
}
|
||||
public function rebotes(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pago $pagoService): ResponseInterface
|
||||
{
|
||||
$pagos = $pagoService->getRebotes();
|
||||
$rebotes = [];
|
||||
$rebotes = array_map(function(Pago $pago) {
|
||||
return [
|
||||
'id' => $pago->id
|
||||
];
|
||||
}, $pagos);
|
||||
/*$rebotes = [];
|
||||
foreach ($pagos as $pago) {
|
||||
$rebotes []= [
|
||||
'id' => $pago->id
|
||||
];
|
||||
}
|
||||
}*/
|
||||
return $this->withJson($response, ['pagos' => $rebotes, 'total' => count($rebotes)]);
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,10 @@ class Unidades
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function disponibles(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Unidad $unidadRepository, Repository\Proyecto\TipoUnidad $tipoUnidadRepository, Service\Redis $redisService): ResponseInterface
|
||||
public function disponibles(ServerRequestInterface $request, ResponseInterface $response,
|
||||
Repository\Venta\Unidad $unidadRepository,
|
||||
Repository\Proyecto\TipoUnidad $tipoUnidadRepository,
|
||||
Service\Redis $redisService): ResponseInterface
|
||||
{
|
||||
$body = $request->getBody();
|
||||
$json = json_decode($body->getContents());
|
||||
@ -83,7 +86,10 @@ class Unidades
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function prorrateo(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Unidad $unidadRepository, int $unidad_id): ResponseInterface
|
||||
public function prorrateo(ServerRequestInterface $request, ResponseInterface $response,
|
||||
Repository\Venta\Unidad $unidadRepository,
|
||||
Service\Venta\Unidad $unidadService,
|
||||
int $unidad_id): ResponseInterface
|
||||
{
|
||||
$body = $request->getParsedBody();
|
||||
$output = [
|
||||
@ -92,8 +98,7 @@ class Unidades
|
||||
'edited' => false
|
||||
];
|
||||
try {
|
||||
$unidad = $unidadRepository->fetchById($unidad_id);
|
||||
$unidadRepository->editProrrateo($unidad, $body);
|
||||
$unidadService->editProrrateo($unidad_id, $body);
|
||||
$output['edited'] = true;
|
||||
} catch (EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
|
Reference in New Issue
Block a user