Mejoras en Facturacion
This commit is contained in:
@ -140,4 +140,19 @@ class Proyectos
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function terreno(ServerRequestInterface $request, ResponseInterface $response, Repository\Proyecto $proyectoRepository, int $proyecto_id): ResponseInterface
|
||||
{
|
||||
$body = $request->getParsedBody();
|
||||
$output = [
|
||||
'input' => $body,
|
||||
'proyecto_id' => $proyecto_id,
|
||||
'edited' => false
|
||||
];
|
||||
try {
|
||||
$proyecto = $proyectoRepository->fetchById($proyecto_id);
|
||||
$proyectoRepository->editTerreno($proyecto, $body);
|
||||
$output['edited'] = true;
|
||||
} catch (EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
}
|
||||
|
@ -83,4 +83,19 @@ class Unidades
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function prorrateo(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Unidad $unidadRepository, int $unidad_id): ResponseInterface
|
||||
{
|
||||
$body = $request->getParsedBody();
|
||||
$output = [
|
||||
'unidad_id' => $unidad_id,
|
||||
'input' => $body,
|
||||
'edited' => false
|
||||
];
|
||||
try {
|
||||
$unidad = $unidadRepository->fetchById($unidad_id);
|
||||
$unidadRepository->editProrrateo($unidad, $body);
|
||||
$output['edited'] = true;
|
||||
} catch (EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ class Proyectos
|
||||
{
|
||||
$redisKey = "proyecto:{$proyecto_id}";
|
||||
try {
|
||||
$proyecto = $proyectoService->getById($proyectoRepository->load((array) $this->fetchRedis($redisService, $redisKey)));
|
||||
$proyecto = $proyectoService->getById($this->fetchRedis($redisService, $redisKey)->id);
|
||||
} catch (EmptyRedis) {
|
||||
$proyecto = $proyectoService->getById($proyecto_id);
|
||||
$this->saveRedis($redisService, $redisKey, $proyecto);
|
||||
|
@ -8,14 +8,14 @@ class Terreno implements JsonSerializable
|
||||
{
|
||||
public float $superficie;
|
||||
public float $valor;
|
||||
public ?DateTimeInterface $date;
|
||||
public ?DateTimeInterface $fecha;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return [
|
||||
'superficie' => $this->superficie,
|
||||
'valor' => $this->valor,
|
||||
'date' => $this->date?->format('Y-m-d')
|
||||
'date' => $this->fecha?->format('Y-m-d')
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository;
|
||||
|
||||
use PDO;
|
||||
use PDOException;
|
||||
use DateTimeImmutable;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
@ -37,9 +39,9 @@ class Proyecto extends Ideal\Repository
|
||||
$terreno = new Model\Proyecto\Terreno();
|
||||
$terreno->superficie = $data['superficie_terreno'];
|
||||
$terreno->valor = $data['valor_terreno'];
|
||||
$terreno->date = null;
|
||||
$terreno->fecha = null;
|
||||
if (isset($data['fecha_terreno']) and $data['fecha_terreno'] !== '') {
|
||||
$terreno->date = new DateTimeImmutable($data['fecha_terreno']);
|
||||
$terreno->fecha = new DateTimeImmutable($data['fecha_terreno']);
|
||||
}
|
||||
return $terreno;
|
||||
}))
|
||||
@ -71,7 +73,7 @@ class Proyecto extends Ideal\Repository
|
||||
'subterraneos'], $new_data);
|
||||
}
|
||||
|
||||
public function fetchById(int $id): Define\Model
|
||||
public function fetchById(int $id): Model\Proyecto
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select($this->columns())
|
||||
@ -81,7 +83,7 @@ class Proyecto extends Ideal\Repository
|
||||
return $this->fetchOne($query, [$id]);
|
||||
}
|
||||
|
||||
public function fetchByName(string $name): Define\Model
|
||||
public function fetchByName(string $name): Model\Proyecto
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select($this->columns())
|
||||
@ -116,6 +118,43 @@ class Proyecto extends Ideal\Repository
|
||||
->order('a.descripcion');
|
||||
return $this->fetchMany($query);
|
||||
}
|
||||
public function editTerreno(Model\Proyecto $proyecto, array $data): Model\Proyecto
|
||||
{
|
||||
$fecha = new DateTimeImmutable($data['fecha']);
|
||||
try {
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select('valor')
|
||||
->from('proyecto_terreno')
|
||||
->where('proyecto_id = ? AND fecha = ?');
|
||||
$result = $this->connection->execute($query, [$proyecto->id, $fecha->format('Y-m-d')])->fetch(PDO::FETCH_ASSOC);
|
||||
if ($result === false) {
|
||||
throw new Implement\Exception\EmptyResult($query);
|
||||
}
|
||||
if ($result['valor'] !== $data['valor']) {
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->update('proyecto_terreno')
|
||||
->set('valor = ?')
|
||||
->where('proyecto_id = ? AND fecha = ?');
|
||||
$this->connection->execute($query, [$data['valor'], $proyecto->id, $fecha->format('Y-m-d')]);
|
||||
$proyecto->terreno->valor = $data['valor'];
|
||||
}
|
||||
} catch (PDOException | Implement\Exception\EmptyResult) {
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->insert()
|
||||
->into('proyecto_terreno')
|
||||
->columns(['proyecto_id', 'fecha', 'valor', 'tipo_moneda_id'])
|
||||
->values(['?', '?', '?', '1']);
|
||||
try {
|
||||
$this->connection->execute($query, [$proyecto->id, $fecha->format('Y-m-d'), $data['valor']]);
|
||||
$proyecto->terreno->fecha = $fecha;
|
||||
$proyecto->terreno->valor = $data['valor'];
|
||||
} catch (PDOException $exception) {
|
||||
error_log($exception);
|
||||
throw new Implement\Exception\EmptyResult($query);
|
||||
}
|
||||
}
|
||||
return $proyecto;
|
||||
}
|
||||
/*public function fetchSuperficieVendido(int $proyecto_id): float
|
||||
{
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
namespace Incoviba\Repository\Venta;
|
||||
|
||||
use PDO;
|
||||
use PDOException;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Implement;
|
||||
@ -38,6 +39,40 @@ 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
|
||||
{
|
||||
|
@ -27,7 +27,8 @@ class Proyecto
|
||||
{
|
||||
return $this->process($this->proyectoRepository->fetchByName($name));
|
||||
}
|
||||
public function process(Model\Proyecto $proyecto): Model\Proyecto
|
||||
|
||||
protected function process(Model\Proyecto $proyecto): Model\Proyecto
|
||||
{
|
||||
$proyecto->addFactory('estados', (new Implement\Repository\Factory())
|
||||
->setCallable([$this->estadoProyecto, 'fetchByProyecto'])
|
||||
|
Reference in New Issue
Block a user