Mejoras en Facturacion
This commit is contained in:
@ -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
|
||||
{
|
||||
|
Reference in New Issue
Block a user