Limpieza de input de valor y filtro de datos a nivel Repo
This commit is contained in:
@ -161,4 +161,9 @@ abstract class Repository implements Define\Repository
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
|
||||
public function filterData(array $data): array
|
||||
{
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ use Throwable;
|
||||
|
||||
class EmptyResult extends Exception
|
||||
{
|
||||
public function __construct(string $query, ?Throwable $previous = null)
|
||||
public function __construct(public string $query, ?Throwable $previous = null)
|
||||
{
|
||||
$message = "Empty results for {$query}";
|
||||
$code = 700;
|
||||
|
@ -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);
|
||||
|
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller\Ventas;
|
||||
|
||||
use Exception;
|
||||
use DateInterval;
|
||||
use DateTimeImmutable;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
@ -20,10 +21,14 @@ class Facturacion extends Ideal\Controller
|
||||
}
|
||||
return $view->render($response, 'ventas.facturacion', compact('proyectos'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function show(ServerRequestInterface $request, ResponseInterface $response, View $view,
|
||||
Service\Venta $ventaService, Service\Proyecto\Terreno $terrenoService,
|
||||
Service\IPC $ipcService, Service\UF $ufService,
|
||||
int $venta_id): ResponseInterface
|
||||
Service\Venta $ventaService, Service\Proyecto\Terreno $terrenoService,
|
||||
Service\IPC $ipcService, Service\UF $ufService,
|
||||
int $venta_id): ResponseInterface
|
||||
{
|
||||
$venta = $ventaService->getById($venta_id);
|
||||
$uf = $ufService->get($venta->currentEstado()->fecha);
|
||||
|
19
app/src/Model/Venta/Unidad/Prorrateo.php
Normal file
19
app/src/Model/Venta/Unidad/Prorrateo.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Venta\Unidad;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Prorrateo extends Ideal\Model
|
||||
{
|
||||
public Model\Venta\Unidad $unidad;
|
||||
public float $prorrateo;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return [
|
||||
'unidad_id' => $this->unidad->id,
|
||||
'prorrateo' => $this->prorrateo,
|
||||
];
|
||||
}
|
||||
}
|
@ -203,4 +203,8 @@ GROUP BY a.`id`";
|
||||
->where('pago = ?');
|
||||
return $this->fetchOne($query, [$pago_id]);
|
||||
}
|
||||
public function filterData(array $data): array
|
||||
{
|
||||
return array_intersect_key($data, array_fill_keys(['pie', 'fecha', 'valor', 'estado', 'banco', 'fecha_pago', 'abonado', 'fecha_abonado', 'uf', 'pago', 'numero'], 0));
|
||||
}
|
||||
}
|
||||
|
@ -117,4 +117,8 @@ WHERE venta_id = ?";
|
||||
->where('venta.id = ?');
|
||||
return $this->fetchOne($query, [$venta_id]);
|
||||
}
|
||||
public function filterData(array $data): array
|
||||
{
|
||||
return array_intersect_key($data, array_fill_keys(['valor', 'banco', 'tipo', 'identificador', 'fecha', 'uf', 'pagador', 'asociado'], 0));
|
||||
}
|
||||
}
|
||||
|
@ -81,4 +81,8 @@ class Pie extends Ideal\Repository
|
||||
->where('venta.id = ?');
|
||||
return $this->fetchOne($query, [$venta_id]);
|
||||
}
|
||||
public function filterData(array $data): array
|
||||
{
|
||||
return array_intersect_key($data, array_fill_keys(['fecha', 'valor', 'uf', 'cuotas', 'asociado', 'reajuste'], 0));
|
||||
}
|
||||
}
|
||||
|
@ -39,40 +39,6 @@ class Unidad extends Ideal\Repository
|
||||
{
|
||||
return $this->update($model, ['subtipo', 'piso', 'descripcion', 'orientacion', 'pt'], $new_data);
|
||||
}
|
||||
public function editProrrateo(Model\Venta\Unidad $model, array $new_data): Model\Venta\Unidad
|
||||
{
|
||||
try {
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select('prorrateo')
|
||||
->from('unidad_prorrateo')
|
||||
->where('unidad_id = ?');
|
||||
$result = $this->connection->execute($query, [$model->id])->fetch(PDO::FETCH_ASSOC);
|
||||
if ($result === false) {
|
||||
throw new Implement\Exception\EmptyResult($query);
|
||||
}
|
||||
if ($new_data['prorrateo'] !== $result['prorrateo']) {
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->update('unidad_prorrateo')
|
||||
->set('prorrateo = ?')
|
||||
->where('unidad_id = ?');
|
||||
$this->connection->execute($query, [$new_data['prorrateo'], $model->id]);
|
||||
$model->prorrateo = $new_data['prorrateo'];
|
||||
}
|
||||
} catch (PDOException | Implement\Exception\EmptyResult) {
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->insert()
|
||||
->into('unidad_prorrateo')
|
||||
->columns(['unidad_id', 'prorrateo'])
|
||||
->values(['?', '?']);
|
||||
try {
|
||||
$this->connection->execute($query, [$model->id, $new_data['prorrateo']]);
|
||||
$model->prorrateo = $new_data['prorrateo'];
|
||||
} catch (PDOException) {
|
||||
throw new Implement\Exception\EmptyResult($query);
|
||||
}
|
||||
}
|
||||
return $model;
|
||||
}
|
||||
|
||||
public function fetchById(int $id): Model\Venta\Unidad
|
||||
{
|
||||
|
54
app/src/Repository/Venta/Unidad/Prorrateo.php
Normal file
54
app/src/Repository/Venta/Unidad/Prorrateo.php
Normal file
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Venta\Unidad;
|
||||
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Prorrateo extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection, protected Repository\Venta\Unidad $unidadRepository)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('unidad_prorrateo');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Model\Venta\Unidad\Prorrateo
|
||||
{
|
||||
$map = (new Implement\Repository\MapperParser(['prorrateo']))
|
||||
->register('unidad_id', (new Implement\Repository\Mapper())
|
||||
->setProperty('unidad')
|
||||
->setFunction(function($data) {
|
||||
return $this->unidadRepository->fetchById($data['unidad_id']);
|
||||
}));
|
||||
return $this->parseData(new Model\Venta\Unidad\Prorrateo(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Model\Venta\Unidad\Prorrateo
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['unidad_id', 'prorrateo'],
|
||||
[$model->unidad->id, $model->prorrateo]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Model\Venta\Unidad\Prorrateo
|
||||
{
|
||||
return $this->update($model, ['unidad_id', 'prorrateo'], $new_data);
|
||||
}
|
||||
|
||||
public function fetchByUnidad(int $unidad_id): Model\Venta\Unidad\Prorrateo
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select()
|
||||
->from($this->getTable())
|
||||
->where('unidad_id = ?');
|
||||
return $this->fetchOne($query, [$unidad_id]);
|
||||
}
|
||||
|
||||
public function filterData(array $data): array
|
||||
{
|
||||
return array_intersect_key($data, array_flip(['prorrateo']));
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@
|
||||
namespace Incoviba\Service\Informe;
|
||||
|
||||
use PhpOffice\PhpSpreadsheet;
|
||||
use PhpOffice\PhpSpreadsheet\Exception;
|
||||
use Incoviba\Common\Define;
|
||||
|
||||
class Excel implements Define\Informe
|
||||
@ -40,6 +41,10 @@ class Excel implements Define\Informe
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
* @throws PhpSpreadsheet\Writer\Exception
|
||||
*/
|
||||
public function build(): void
|
||||
{
|
||||
$spreadsheet = new PhpSpreadsheet\Spreadsheet();
|
||||
|
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
namespace Incoviba\Service\Money;
|
||||
|
||||
use Exception;
|
||||
use DateTimeInterface;
|
||||
use DateTimeImmutable;
|
||||
use DateInterval;
|
||||
@ -14,6 +15,10 @@ class Ine implements Provider
|
||||
protected string $uri = 'https://api-calculadora.ine.cl/ServiciosCalculadoraVariacion';
|
||||
public function __construct(protected ClientInterface $client) {}
|
||||
|
||||
/**
|
||||
* @throws EmptyResponse
|
||||
* @throws Exception
|
||||
*/
|
||||
public function get(string $money_symbol, DateTimeInterface $dateTime): float
|
||||
{
|
||||
$end = new DateTimeImmutable($dateTime->format('Y-m-1'));
|
||||
@ -21,6 +26,9 @@ class Ine implements Provider
|
||||
return $this->getVar($start, $end);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws EmptyResponse
|
||||
*/
|
||||
public function getVar(DateTimeInterface $start, DateTimeInterface $end): float
|
||||
{
|
||||
$base = 1000000000;
|
||||
@ -33,9 +41,10 @@ class Ine implements Provider
|
||||
];
|
||||
$request_uri = implode('?', [
|
||||
$this->uri,
|
||||
implode('&', array_map(function($val, $key) {
|
||||
http_build_query($request_query),
|
||||
/*implode('&', array_map(function($val, $key) {
|
||||
return "{$key}={$val}";
|
||||
}, $request_query, array_keys($request_query)))
|
||||
}, $request_query, array_keys($request_query)))*/
|
||||
]);
|
||||
try {
|
||||
$response = $this->client->get($request_uri);
|
||||
@ -44,6 +53,9 @@ class Ine implements Provider
|
||||
}
|
||||
$body = $response->getBody();
|
||||
$json = json_decode($body->getContents());
|
||||
if (empty($json)) {
|
||||
throw new EmptyResponse($request_uri);
|
||||
}
|
||||
return ((int) str_replace('.', '', $json[0]->valorajustado) - $base) / $base;
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,9 @@ class MiIndicador implements Provider
|
||||
|
||||
public function __construct(protected ClientInterface $client) {}
|
||||
|
||||
/**
|
||||
* @throws EmptyResponse
|
||||
*/
|
||||
public function get(string $money_symbol, DateTimeInterface $dateTime): float
|
||||
{
|
||||
$request_uri = "{$money_symbol}/{$dateTime->format('d-m-Y')}";
|
||||
@ -31,7 +34,7 @@ class MiIndicador implements Provider
|
||||
$body = $response->getBody();
|
||||
$json = json_decode($body->getContents());
|
||||
|
||||
if ($json->codigo !== $money_symbol or count($json->serie) === 0) {
|
||||
if (empty($json) or $json->codigo !== $money_symbol or count($json->serie) === 0) {
|
||||
throw new EmptyResponse($request_uri);
|
||||
}
|
||||
return $json->serie[0]->valor;
|
||||
|
@ -1,8 +1,12 @@
|
||||
<?php
|
||||
namespace Incoviba\Service\Proyecto;
|
||||
|
||||
use Exception;
|
||||
use DateTimeImmutable;
|
||||
use DateInterval;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResponse;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Common\Implement\Exception\HttpResponse;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement;
|
||||
@ -18,6 +22,11 @@ class Terreno extends Ideal\Service
|
||||
parent::__construct($logger);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $proyecto_id
|
||||
* @return Model\Proyecto\Terreno|null
|
||||
* @throws Exception
|
||||
*/
|
||||
public function valor(int $proyecto_id): ?Model\Proyecto\Terreno
|
||||
{
|
||||
$terreno = null;
|
||||
@ -42,6 +51,12 @@ class Terreno extends Ideal\Service
|
||||
return $terreno;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws EmptyResponse
|
||||
* @throws HttpResponse
|
||||
* @throws EmptyResult
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function getValorContable(Model\Proyecto $proyecto, DateTimeImmutable $lastDecember): Model\Proyecto\Terreno
|
||||
{
|
||||
$cuentaNubox = $this->nuboxService->getCuenta($proyecto->inmobiliaria()->rut, 'Terrenos');
|
||||
@ -57,6 +72,9 @@ class Terreno extends Ideal\Service
|
||||
return $proyecto->terreno;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function getValorReajustado(Model\Proyecto $proyecto): ?Model\Proyecto\Terreno
|
||||
{
|
||||
$novPrevTerreno = new DateTimeImmutable($proyecto->terreno->fecha->format('m') < 12 ? $proyecto->terreno->fecha->sub(new DateInterval('P1Y'))->format('Y-11-1') : $proyecto->terreno->fecha->format('Y-11-1'));
|
||||
|
13
app/src/Service/Valor.php
Normal file
13
app/src/Service/Valor.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
namespace Incoviba\Service;
|
||||
|
||||
class Valor
|
||||
{
|
||||
public function clean(string|float|int $value): float
|
||||
{
|
||||
if ((float) $value == $value) {
|
||||
return (float) $value;
|
||||
}
|
||||
return (float) str_replace(['.', ','], ['', '.'], $value);
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
namespace Incoviba\Service;
|
||||
|
||||
use Exception;
|
||||
use DateTimeImmutable;
|
||||
use DateInterval;
|
||||
use Psr\Log\LoggerInterface;
|
||||
@ -29,7 +30,8 @@ class Venta extends Service
|
||||
protected Venta\BonoPie $bonoPieService,
|
||||
protected Venta\Pago $pagoService,
|
||||
protected Proyecto\Terreno $terrenoService,
|
||||
protected Money $moneyService
|
||||
protected Money $moneyService,
|
||||
protected Valor $valorService
|
||||
) {
|
||||
parent::__construct($logger);
|
||||
}
|
||||
@ -136,6 +138,9 @@ class Venta extends Service
|
||||
return $venta;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function add(array $data): Model\Venta
|
||||
{
|
||||
$fecha = new DateTimeImmutable($data['fecha_venta']);
|
||||
@ -147,7 +152,7 @@ class Venta extends Service
|
||||
'propietario' => $propietario->rut,
|
||||
'propiedad' => $propiedad->id,
|
||||
'fecha' => $fecha->format('Y-m-d'),
|
||||
'valor_uf' => $this->cleanValue($data['valor']),
|
||||
'valor_uf' => $this->valorService->clean($data['valor']),
|
||||
'fecha_ingreso' => (new DateTimeImmutable())->format('Y-m-d'),
|
||||
'uf' => $data['uf']
|
||||
];
|
||||
@ -279,6 +284,10 @@ class Venta extends Service
|
||||
{
|
||||
return $this->formaPagoService->add($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function addEstado(Model\Venta $venta, Model\Venta\TipoEstadoVenta $tipoEstadoVenta, array $data): void
|
||||
{
|
||||
$fecha = new DateTimeImmutable($data['fecha']);
|
||||
@ -290,13 +299,6 @@ class Venta extends Service
|
||||
$estado = $this->estadoVentaRepository->create($estadoData);
|
||||
$this->estadoVentaRepository->save($estado);
|
||||
}
|
||||
protected function cleanValue($value): float
|
||||
{
|
||||
if ((float) $value == $value) {
|
||||
return (float) $value;
|
||||
}
|
||||
return (float) str_replace(['.', ','], ['', '.'], $value);
|
||||
}
|
||||
|
||||
public function escriturar(Model\Venta $venta, array $data): bool
|
||||
{
|
||||
@ -340,21 +342,29 @@ class Venta extends Service
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function reajustarEscritura(Model\Venta $venta, array $data): void
|
||||
{
|
||||
$fecha = new DateTimeImmutable($data['fecha_reajuste']);
|
||||
$reajusteData = [
|
||||
'valor' => $data['valor_reajuste'],
|
||||
'valor' => $this->valorService->clean($data['valor_reajuste']),
|
||||
'fecha' => $fecha->format('Y-m-d')
|
||||
];
|
||||
$pie = $venta->formaPago()->pie;
|
||||
$this->pieService->reajustar($pie, $reajusteData);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function abonoEscritura(Model\Venta $venta, array $data): void
|
||||
{
|
||||
$fecha = new DateTimeImmutable($data['fecha_pago']);
|
||||
$uf = $this->moneyService->getUF($fecha);
|
||||
$valor = $data['valor_pago_ufs'] !== '' ? $data['valor_pago_ufs'] * $uf : $data['valor_pago_pesos'];
|
||||
$valor = $data['valor_pago_ufs'] !== '' ? $this->valorService->clean($data['valor_pago_ufs']) * $uf : $this->valorService->clean($data['valor_pago_pesos']);
|
||||
$pagoData = [
|
||||
'valor' => $valor,
|
||||
'fecha' => $fecha->format('Y-m-d'),
|
||||
@ -371,24 +381,32 @@ class Venta extends Service
|
||||
$escritura = $this->escrituraRepository->save($escritura);
|
||||
$this->ventaRepository->edit($venta, ['escritura' => $escritura->id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function subsidioEscritura(Model\Venta $venta, array $data): void
|
||||
{
|
||||
$fecha = new DateTimeImmutable($data['fecha']);
|
||||
$uf = $this->moneyService->getUF($fecha);
|
||||
$subsidioData = [
|
||||
'fecha_venta' => $fecha->format('Y-m-d'),
|
||||
'ahorro' => $data['valor_ahorro'],
|
||||
'subsidio' => $data['valor_subsidio'],
|
||||
'ahorro' => $this->valorService->clean($data['valor_ahorro']),
|
||||
'subsidio' => $this->valorService->clean($data['valor_subsidio']),
|
||||
'uf' => $uf
|
||||
];
|
||||
$subsidio = $this->addSubsidio($subsidioData);
|
||||
$this->ventaRepository->edit($venta, ['subsidio' => $subsidio->id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function editCredito(Model\Venta $venta, array $data): void
|
||||
{
|
||||
$fecha = new DateTimeImmutable($data['fecha']);
|
||||
$uf = $this->moneyService->getUF($fecha);
|
||||
$valor = $data['valor_credito'] * $uf;
|
||||
$valor = $this->valorService->clean($data['valor_credito']) * $uf;
|
||||
if ($venta->formaPago()->credito === null) {
|
||||
$pagoData = [
|
||||
'valor' => $valor,
|
||||
@ -425,7 +443,7 @@ class Venta extends Service
|
||||
{
|
||||
try {
|
||||
if ($this->validarData($data, ['fecha', 'devolucion'])) {
|
||||
$pago = $this->pagoService->add(['fecha' => $data['fecha'], 'valor' => str_replace(['.', ','], ['', '.'], $data['devolucion'])]);
|
||||
$pago = $this->pagoService->add(['fecha' => $data['fecha'], 'valor' => $this->valorService->clean($data['devolucion'])]);
|
||||
$this->ventaRepository->edit($venta, ['resciliacion' => $pago->id]);
|
||||
}
|
||||
$tipoEstado = $this->tipoEstadoVentaRepository->fetchByDescripcion('desistida');
|
||||
|
@ -10,7 +10,9 @@ class BonoPie
|
||||
|
||||
public function add(array $data): Model\Venta\BonoPie
|
||||
{
|
||||
return new Model\Venta\BonoPie();
|
||||
$filteredData = $this->bonoPieRepository->filterData($data);
|
||||
$bono = $this->bonoPieRepository->create($filteredData);
|
||||
return $this->bonoPieRepository->save($bono);
|
||||
}
|
||||
public function getByVenta(int $venta_id): Model\Venta\BonoPie
|
||||
{
|
||||
|
@ -1,23 +1,25 @@
|
||||
<?php
|
||||
namespace Incoviba\Service\Venta;
|
||||
|
||||
use Exception;
|
||||
use DateTimeImmutable;
|
||||
use Incoviba\Common\Ideal\Service;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Service\Money;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Incoviba\Service;
|
||||
|
||||
class Credito extends Service
|
||||
class Credito extends Ideal\Service
|
||||
{
|
||||
public function __construct(
|
||||
LoggerInterface $logger,
|
||||
protected Repository\Venta\Credito $creditoRepository,
|
||||
protected Repository\Venta\Pago $pagoRepository,
|
||||
protected Pago $pagoService,
|
||||
protected Repository\Venta\TipoPago $tipoPagoRepository,
|
||||
protected Repository\Venta\EstadoPago $estadoPagoRepository,
|
||||
protected Repository\Venta\TipoEstadoPago $tipoEstadoPagoRepository,
|
||||
protected Money $moneyService
|
||||
protected Service\Money $moneyService,
|
||||
protected Service\Valor $valorService
|
||||
) {
|
||||
parent::__construct($logger);
|
||||
}
|
||||
@ -27,19 +29,32 @@ class Credito extends Service
|
||||
return $this->creditoRepository->fetchByVenta($venta_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function add(array $data): Model\Venta\Credito
|
||||
{
|
||||
$fecha = new DateTimeImmutable($data['fecha']);
|
||||
$uf = $data['uf'] ?? $this->moneyService->getUF($fecha);
|
||||
$uf = $this->valorService->clean($data['uf']) ?? $this->moneyService->getUF($fecha);
|
||||
$tipoPago = $this->tipoPagoRepository->fetchByDescripcion('carta de resguardo');
|
||||
$pago = $this->addPago(['fecha' => $fecha->format('Y-m-d'), 'valor' => $data['valor'] * $uf, 'uf' => $uf, 'tipo' => $tipoPago->id]);
|
||||
$valor = $this->valorService->clean($data['valor']);
|
||||
$pago = $this->pagoService->add([
|
||||
'fecha' => $fecha->format('Y-m-d'),
|
||||
'valor' => $valor * $uf,
|
||||
'uf' => $uf,
|
||||
'tipo' => $tipoPago->id
|
||||
]);
|
||||
$credito = $this->creditoRepository->create([
|
||||
'valor' => $data['valor'],
|
||||
'valor' => $valor,
|
||||
'fecha' => $fecha->format('Y-m-d'),
|
||||
'pago' => $pago->id
|
||||
]);
|
||||
return $this->creditoRepository->save($credito);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function edit(Model\Venta\Credito $credito, array $data): Model\Venta\Credito
|
||||
{
|
||||
$uf = $this->moneyService->getUF($credito->pago->fecha);
|
||||
@ -50,7 +65,8 @@ class Credito extends Service
|
||||
$data['uf'] = $uf;
|
||||
}
|
||||
if (array_key_exists('valor', $data)) {
|
||||
$data['valor'] = round(((float) $data['valor']) * $uf);
|
||||
$data['valor'] = $this->valorService->clean($data['valor']);
|
||||
$valorPago = round($data['valor'] * $uf);
|
||||
}
|
||||
$filteredData = array_intersect_key($data, array_fill_keys([
|
||||
'fecha',
|
||||
@ -58,21 +74,12 @@ class Credito extends Service
|
||||
'valor',
|
||||
'banco'
|
||||
], 0));
|
||||
$credito->pago = $this->pagoRepository->edit($credito->pago, $filteredData);
|
||||
$filteredDataPago = $filteredData;
|
||||
if (isset($valorPago)) {
|
||||
$filteredDataPago['valor'] = $valorPago;
|
||||
}
|
||||
$credito->pago = $this->pagoService->edit($credito->pago, $filteredDataPago);
|
||||
|
||||
return $this->creditoRepository->edit($credito, $filteredData);
|
||||
}
|
||||
protected function addPago(array $data): Model\Venta\Pago
|
||||
{
|
||||
$pago = $this->pagoRepository->create($data);
|
||||
$pago = $this->pagoRepository->save($pago);
|
||||
$tipoEstado = $this->tipoEstadoPagoRepository->fetchByDescripcion('no pagado');
|
||||
$data = [
|
||||
'pago' => $pago->id,
|
||||
'fecha' => $pago->fecha->format('Y-m-d'),
|
||||
'estado' => $tipoEstado->id
|
||||
];
|
||||
$estado = $this->estadoPagoRepository->create($data);
|
||||
$this->estadoPagoRepository->save($estado);
|
||||
return $pago;
|
||||
}
|
||||
}
|
||||
|
@ -98,19 +98,10 @@ class Cuota
|
||||
$filtered_data = array_intersect_key($data, $fields);
|
||||
$pago_data = array_merge($filtered_data, ['tipo' => $tipoPago->id]);
|
||||
$pago = $this->pagoService->add($pago_data);
|
||||
|
||||
$data['pago'] = $pago->id;
|
||||
$data['estado'] = $pago->currentEstado->tipoEstadoPago->id;
|
||||
$fields = array_fill_keys([
|
||||
'pie',
|
||||
'fecha',
|
||||
'valor',
|
||||
'estado',
|
||||
'banco',
|
||||
'uf',
|
||||
'pago',
|
||||
'numero'
|
||||
], 0);
|
||||
$filtered_data = array_intersect_key($data, $fields);
|
||||
$filtered_data = $this->cuotaRepository->filterData($data);
|
||||
$mapped_data = $filtered_data;
|
||||
$mapped_data['valor_$'] = $mapped_data['valor'];
|
||||
unset($mapped_data['valor']);
|
||||
|
70
app/src/Service/Venta/Escritura.php
Normal file
70
app/src/Service/Venta/Escritura.php
Normal file
@ -0,0 +1,70 @@
|
||||
<?php
|
||||
namespace Incoviba\Service\Venta;
|
||||
|
||||
use Exception;
|
||||
use DateTimeImmutable;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Service;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Escritura extends Ideal\Service
|
||||
{
|
||||
public function __construct(LoggerInterface $logger, protected Repository\Venta $ventaRepository,
|
||||
protected Service\Venta $ventaService,
|
||||
protected Repository\Venta\Escritura $escrituraRepository,
|
||||
protected Repository\Venta\EstadoVenta $estadoVentaRepository,
|
||||
protected Service\Venta\Pago $pagoService, protected Service\UF $ufService,
|
||||
protected Service\Valor $valorService)
|
||||
{
|
||||
parent::__construct($logger);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws EmptyResult
|
||||
* @throws Exception
|
||||
*/
|
||||
public function add(int $venta_id, array $data): Model\Venta\Escritura
|
||||
{
|
||||
$venta = $this->ventaService->getById($venta_id);
|
||||
if (isset($venta->formaPago()->escritura)) {
|
||||
throw new EmptyResult('');
|
||||
}
|
||||
$fecha = new DateTimeImmutable($data['fecha']);
|
||||
$uf = $this->ufService->get($fecha);
|
||||
$valor = $this->valorService->clean($data['valor']) * (($data['uf']) ? $uf : 1);
|
||||
$pago = $this->pagoService->add([
|
||||
'fecha' => $fecha->format('Y-m-d'),
|
||||
'valor' => $valor,
|
||||
'banco' => $data['banco'],
|
||||
'tipo' => $data['tipo'],
|
||||
'uf' => $uf
|
||||
]);
|
||||
$escritura = $this->escrituraRepository->create([
|
||||
'valor' => $valor,
|
||||
'fecha' => $fecha->format('Y-m-d'),
|
||||
'uf' => $uf,
|
||||
'pago' => $pago->id
|
||||
]);
|
||||
$escritura = $this->escrituraRepository->save($escritura);
|
||||
$this->ventaRepository->edit($venta, ['escritura' => $escritura->id]);
|
||||
return $escritura;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws EmptyResult
|
||||
* @throws Exception
|
||||
*/
|
||||
public function edit(int $venta_id, array $data): Model\Venta\EstadoVenta
|
||||
{
|
||||
$venta = $this->ventaService->getById($venta_id);
|
||||
$estado = $venta->currentEstado();
|
||||
if (!in_array($estado->tipoEstadoVenta->descripcion, ['escriturando', 'firmado por inmobiliaria'])) {
|
||||
throw new EmptyResult('');
|
||||
}
|
||||
$data['fecha'] = (new DateTimeImmutable($data['fecha']))->format('Y-m-d');
|
||||
return $this->estadoVentaRepository->edit($estado, $data);
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
namespace Incoviba\Service\Venta;
|
||||
|
||||
use Incoviba\Service\Valor;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Common\Ideal;
|
||||
@ -15,7 +16,8 @@ class FormaPago extends Ideal\Service
|
||||
protected Credito $creditoService,
|
||||
protected Repository\Venta\Escritura $escrituraRepository,
|
||||
protected Subsidio $subsidioService,
|
||||
protected Pago $pagoService)
|
||||
protected Pago $pagoService,
|
||||
protected Valor $valorService)
|
||||
{
|
||||
parent::__construct($logger);
|
||||
}
|
||||
@ -83,7 +85,7 @@ class FormaPago extends Ideal\Service
|
||||
'cuotas',
|
||||
'uf'
|
||||
], $filtered_data);
|
||||
$mapped_data['valor'] = $this->cleanValue($mapped_data['valor']);
|
||||
$mapped_data['valor'] = $this->valorService->clean($mapped_data['valor']);
|
||||
return $this->pieService->add($mapped_data);
|
||||
}
|
||||
protected function addSubsidio(array $data): Model\Venta\Subsidio
|
||||
@ -101,6 +103,8 @@ class FormaPago extends Ideal\Service
|
||||
'subsidio',
|
||||
'uf'
|
||||
], $filtered_data);
|
||||
$mapped_data['ahorro'] = $this->valorService->clean($mapped_data['ahorro']);
|
||||
$mapped_data['subsidio'] = $this->valorService->clean($mapped_data['subsidio']);
|
||||
return $this->subsidioService->add($mapped_data);
|
||||
}
|
||||
protected function addCredito(array $data): Model\Venta\Credito
|
||||
@ -116,6 +120,7 @@ class FormaPago extends Ideal\Service
|
||||
'valor',
|
||||
'uf'
|
||||
], $filtered_data);
|
||||
$mapped_data['valor'] = $this->valorService->clean($mapped_data['valor']);
|
||||
return $this->creditoService->add($mapped_data);
|
||||
}
|
||||
protected function addBonoPie(array $data): Model\Venta\BonoPie
|
||||
@ -129,14 +134,7 @@ class FormaPago extends Ideal\Service
|
||||
'fecha',
|
||||
'valor'
|
||||
], $filtered_data);
|
||||
$mapped_data['valor'] = $this->valorService->clean($mapped_data['valor']);
|
||||
return $this->bonoPieService->add($mapped_data);
|
||||
}
|
||||
|
||||
protected function cleanValue($value): float
|
||||
{
|
||||
if ((float) $value == $value) {
|
||||
return (float) $value;
|
||||
}
|
||||
return (float) str_replace(['.', ','], ['', '.'], $value);
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,11 @@
|
||||
<?php
|
||||
namespace Incoviba\Service\Venta;
|
||||
|
||||
use Exception;
|
||||
use DateTimeInterface;
|
||||
use DateTimeImmutable;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Service\Money;
|
||||
use PDOException;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Service;
|
||||
@ -16,7 +16,8 @@ class Pago
|
||||
protected Repository\Venta\Pago $pagoRepository,
|
||||
protected Repository\Venta\EstadoPago $estadoPagoRepository,
|
||||
protected Repository\Venta\TipoEstadoPago $tipoEstadoPagoRepository,
|
||||
protected Service\UF $ufService
|
||||
protected Service\UF $ufService,
|
||||
protected Service\Valor $valorService
|
||||
) {}
|
||||
|
||||
public function depositar(Model\Venta\Pago $pago, DateTimeInterface $fecha): bool
|
||||
@ -115,24 +116,19 @@ class Pago
|
||||
return $this->process($this->pagoRepository->fetchDevolucionByVenta($venta_id));
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function add(array $data): Model\Venta\Pago
|
||||
{
|
||||
if (!isset($data['uf'])) {
|
||||
$data['uf'] = $this->ufService->get(new DateTimeImmutable($data['fecha']));
|
||||
}
|
||||
$fields = array_fill_keys([
|
||||
'valor',
|
||||
'banco',
|
||||
'tipo',
|
||||
'identificador',
|
||||
'fecha',
|
||||
'uf',
|
||||
'pagador',
|
||||
'asociado'
|
||||
], 0);
|
||||
$filtered_data = array_intersect_key($data, $fields);
|
||||
$filtered_data = $this->pagoRepository->filterData($data);
|
||||
$filtered_data['valor'] = round($this->valorService->clean($filtered_data['valor']));
|
||||
$pago = $this->pagoRepository->create($filtered_data);
|
||||
$pago = $this->pagoRepository->save($pago);
|
||||
|
||||
$tipoEstado = $this->tipoEstadoPagoRepository->fetchByDescripcion('no pagado');
|
||||
$estado = $this->estadoPagoRepository->create([
|
||||
'pago' => $pago->id,
|
||||
@ -143,6 +139,24 @@ class Pago
|
||||
$pago->currentEstado = $estado;
|
||||
return $pago;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function edit(Model\Venta\Pago $pago, array $data): Model\Venta\Pago
|
||||
{
|
||||
if (array_key_exists('fecha', $data)) {
|
||||
$data['fecha'] = (new DateTimeImmutable($data['fecha']))->format('Y-m-d');
|
||||
}
|
||||
if (array_key_exists('uf', $data)) {
|
||||
$data['uf'] = $this->ufService->get(new DateTimeImmutable($data['fecha']));
|
||||
}
|
||||
$filteredData = $this->pagoRepository->filterData($data);
|
||||
$filteredData['valor'] = round($this->valorService->clean($filteredData['valor']));
|
||||
$pago = $this->pagoRepository->edit($pago, $filteredData);
|
||||
$pago->currentEstado = $this->estadoPagoRepository->fetchCurrentByPago($pago->id);
|
||||
return $pago;
|
||||
}
|
||||
public function delete(Model\Venta\Pago $pago): bool
|
||||
{
|
||||
try {
|
||||
|
@ -25,7 +25,8 @@ class Pie
|
||||
|
||||
public function add(array $data): Model\Venta\Pie
|
||||
{
|
||||
$pie = $this->pieRepository->create($data);
|
||||
$filteredData = $this->pieRepository->filterData($data);
|
||||
$pie = $this->pieRepository->create($filteredData);
|
||||
return $this->pieRepository->save($pie);
|
||||
}
|
||||
public function addCuota(array $data): Model\Venta\Cuota
|
||||
@ -34,7 +35,8 @@ class Pie
|
||||
}
|
||||
public function edit(Model\Venta\Pie $pie, array $data): Model\Venta\Pie
|
||||
{
|
||||
return $this->pieRepository->edit($pie, $data);
|
||||
$filteredData = $this->pieRepository->filterData($data);
|
||||
return $this->pieRepository->edit($pie, $filteredData);
|
||||
}
|
||||
public function reajustar(Model\Venta\Pie $pie, array $data): Model\Venta\Pie
|
||||
{
|
||||
|
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
namespace Incoviba\Service\Venta;
|
||||
|
||||
use Exception;
|
||||
use DateTimeImmutable;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Model;
|
||||
@ -10,11 +11,12 @@ class Subsidio
|
||||
{
|
||||
public function __construct(
|
||||
protected Repository\Venta\Subsidio $subsidioRepository,
|
||||
protected Repository\Venta\Pago $pagoRepository,
|
||||
protected Pago $pagoService,
|
||||
protected Repository\Venta\TipoPago $tipoPagoRepository,
|
||||
protected Repository\Venta\EstadoPago $estadoPagoRepository,
|
||||
protected Repository\Venta\TipoEstadoPago $tipoEstadoPagoRepository,
|
||||
protected Service\Money $moneyService
|
||||
protected Service\Money $moneyService,
|
||||
protected Service\Valor $valorService
|
||||
) {}
|
||||
|
||||
public function getByVenta(int $venta_id): Model\Venta\Subsidio
|
||||
@ -22,28 +24,17 @@ class Subsidio
|
||||
return $this->subsidioRepository->fetchByVenta($venta_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function add(array $data): Model\Venta\Subsidio
|
||||
{
|
||||
$fecha = new DateTimeImmutable($data['fecha']);
|
||||
$uf = $data['uf'] ?? $this->moneyService->getUF($fecha);
|
||||
$tipoPago = $this->tipoPagoRepository->fetchByDescripcion('vale vista');
|
||||
$ahorro = $this->addPago(['fecha' => $fecha->format('Y-m-d'), 'valor' => $data['ahorro'] * $uf, 'uf' => $uf, 'tipo' => $tipoPago->id]);
|
||||
$subsidio = $this->addPago(['fecha' => $fecha->format('Y-m-d'), 'valor' => $data['subsidio'] * $uf, 'uf' => $uf, 'tipo' => $tipoPago->id]);
|
||||
$subsidio = $this->subsidioRepository->create(['pago' => $ahorro->id, 'subsidio' => $subsidio->id]);
|
||||
$ahorro = $this->pagoService->add(['fecha' => $fecha->format('Y-m-d'), 'valor' => $this->valorService->clean($data['ahorro']) * $uf, 'uf' => $uf, 'tipo' => $tipoPago->id]);
|
||||
$subsidioPago = $this->pagoService->add(['fecha' => $fecha->format('Y-m-d'), 'valor' => $this->valorService->clean($data['subsidio']) * $uf, 'uf' => $uf, 'tipo' => $tipoPago->id]);
|
||||
$subsidio = $this->subsidioRepository->create(['pago' => $ahorro->id, 'subsidio' => $subsidioPago->id]);
|
||||
return $this->subsidioRepository->save($subsidio);
|
||||
}
|
||||
protected function addPago(array $data): Model\Venta\Pago
|
||||
{
|
||||
$pago = $this->pagoRepository->create($data);
|
||||
$pago = $this->pagoRepository->save($pago);
|
||||
$tipoEstado = $this->tipoEstadoPagoRepository->fetchByDescripcion('no pagado');
|
||||
$data = [
|
||||
'pago' => $pago->id,
|
||||
'fecha' => $pago->fecha->format('Y-m-d'),
|
||||
'estado' => $tipoEstado->id
|
||||
];
|
||||
$estado = $this->estadoPagoRepository->create($data);
|
||||
$this->estadoPagoRepository->save($estado);
|
||||
return $pago;
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ class Unidad
|
||||
{
|
||||
public function __construct(
|
||||
protected Repository\Venta\Unidad $unidadRepository,
|
||||
protected Repository\Venta\Unidad\Prorrateo $unidadProrrateoRepository,
|
||||
protected Precio $precioService
|
||||
) {}
|
||||
|
||||
@ -38,6 +39,22 @@ class Unidad
|
||||
return $this->unidadRepository->fetchByIdForSearch($unidad_id);
|
||||
}
|
||||
|
||||
public function editProrrateo(int $unidad_id, array $new_data): Model\Venta\Unidad
|
||||
{
|
||||
$model = $this->unidadRepository->fetchById($unidad_id);
|
||||
$filteredData = $this->unidadProrrateoRepository->filterData($new_data);
|
||||
try {
|
||||
$prorrateo = $this->unidadProrrateoRepository->fetchByUnidad($model->id);
|
||||
$prorrateo = $this->unidadProrrateoRepository->edit($prorrateo, $filteredData);
|
||||
} catch (PDOException | EmptyResult) {
|
||||
$filteredData['unidad_id'] = $model->id;
|
||||
$prorrateo = $this->unidadProrrateoRepository->create($filteredData);
|
||||
$this->unidadProrrateoRepository->save($prorrateo);
|
||||
}
|
||||
$model->prorrateo = $prorrateo->prorrateo;
|
||||
return $model;
|
||||
}
|
||||
|
||||
protected function process($unidad): Model\Venta\Unidad
|
||||
{
|
||||
try {
|
||||
|
Reference in New Issue
Block a user