Facturacion, se agrega PropiedadUnidad
This commit is contained in:
@ -70,13 +70,24 @@ class Proyecto extends Ideal\Repository
|
||||
'valor_terreno', 'corredor', 'superficie_sobre_nivel', 'superficie_bajo_nivel', 'pisos',
|
||||
'subterraneos'], $new_data);
|
||||
}
|
||||
|
||||
public function fetchById(int $id): Define\Model
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select($this->columns())
|
||||
->from("{$this->getTable()} a")
|
||||
->joined($this->joinTerreno())
|
||||
->where("a.id = ?");
|
||||
return $this->fetchOne($query, [$id]);
|
||||
}
|
||||
|
||||
public function fetchByName(string $name): Define\Model
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select($this->columns())
|
||||
->from("{$this->getTable()} a")
|
||||
->joined($this->joinTerreno())
|
||||
->where("descripcion = ?");
|
||||
->where("a.descripcion = ?");
|
||||
return $this->fetchOne($query, [$name]);
|
||||
}
|
||||
public function fetchAllActive(): array
|
||||
|
@ -9,7 +9,7 @@ use Incoviba\Service;
|
||||
|
||||
class Propiedad extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection, protected Service\Venta\Unidad $unidadService)
|
||||
public function __construct(Define\Connection $connection, protected Service\Venta\PropiedadUnidad $unidadService)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('propiedad');
|
||||
|
118
app/src/Repository/Venta/PropiedadUnidad.php
Normal file
118
app/src/Repository/Venta/PropiedadUnidad.php
Normal file
@ -0,0 +1,118 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Venta;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Service;
|
||||
|
||||
class PropiedadUnidad extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection,
|
||||
protected Unidad $unidadRepository,
|
||||
protected Service\Proyecto\ProyectoTipoUnidad $proyectoTipoUnidadService)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('propiedad_unidad');
|
||||
}
|
||||
|
||||
public function load(array $data_row): Define\Model
|
||||
{
|
||||
$unidad = $this->unidadRepository->fetchById($data_row['unidad']);
|
||||
$data = [
|
||||
'id' => $unidad->id,
|
||||
'subtipo' => $unidad->subtipo,
|
||||
'piso' => $unidad->piso,
|
||||
'descripcion' => $unidad->descripcion,
|
||||
'orientacion' => $unidad->orientacion,
|
||||
'prorrateo' => $unidad->prorrateo,
|
||||
'pt' => $unidad->proyectoTipoUnidad->id,
|
||||
'pu_id' => $data_row['id'],
|
||||
'propiedad' => $data_row['propiedad'],
|
||||
'valor' => $data_row['valor']
|
||||
];
|
||||
return parent::load($data);
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Model\Venta\PropiedadUnidad
|
||||
{
|
||||
$map = (new Implement\Repository\MapperParser(['subtipo', 'piso', 'descripcion', 'orientacion', 'prorrateo', 'valor', 'id']))
|
||||
->register('propiedad', (new Implement\Repository\Mapper())
|
||||
->setProperty('propiedad_id'))
|
||||
->register('pt', (new Implement\Repository\Mapper())
|
||||
->setProperty('proyectoTipoUnidad')
|
||||
->setFunction(function($data) {
|
||||
return $this->proyectoTipoUnidadService->getById($data['pt']);
|
||||
}));
|
||||
return $this->parseData(new Model\Venta\PropiedadUnidad(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Model\Venta\PropiedadUnidad
|
||||
{
|
||||
$model->pu_id = $this->saveNew(['propiedad', 'unidad', 'valor'], [$model->propiedad_id, $model->id, $model->valor]);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Model\Venta\PropiedadUnidad
|
||||
{
|
||||
return $this->update($model, ['propiedad', 'unidad', 'valor'], $new_data);
|
||||
}
|
||||
|
||||
public function fetchById(int $id): Define\Model
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select()
|
||||
->from($this->getTable())
|
||||
->where("id = ?");
|
||||
return $this->fetchOne($query, [$id]);
|
||||
}
|
||||
|
||||
public function fetchByVenta(int $venta_id): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select('a.*')
|
||||
->from("{$this->getTable()} a")
|
||||
->joined('JOIN unidad ON a.unidad = unidad.id
|
||||
JOIN venta ON venta.propiedad = a.propiedad')
|
||||
->where('venta.id = ?');
|
||||
return $this->fetchMany($query, [$venta_id]);
|
||||
}
|
||||
public function fetchByPropiedad(int $propiedad_id): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select('a.*')
|
||||
->from("{$this->getTable()} a")
|
||||
->joined('JOIN `unidad` ON a.`unidad` = `unidad`.`id`')
|
||||
->where('a.`propiedad` = ?')
|
||||
->group('`unidad`.`id`');
|
||||
return $this->fetchMany($query, [$propiedad_id]);
|
||||
}
|
||||
|
||||
protected function update(Define\Model $model, array $columns, array $data): Define\Model
|
||||
{
|
||||
$changes = [];
|
||||
$values = [];
|
||||
foreach ($columns as $column) {
|
||||
if (isset($data[$column])) {
|
||||
$changes []= $column;
|
||||
$values []= $data[$column];
|
||||
}
|
||||
}
|
||||
|
||||
if (count($changes) === 0) {
|
||||
return $model;
|
||||
}
|
||||
$columns_string = implode(', ', array_map(function($property) {return "`{$property}` = ?";}, $changes));
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->update($this->getTable())
|
||||
->set($columns_string)
|
||||
->where("id = ?");
|
||||
$values []= $model->{$this->getKey()};
|
||||
$this->connection->execute($query, $values);
|
||||
return $this->fetchById($model->{$this->getKey()});
|
||||
}
|
||||
|
||||
protected function getKey(): string
|
||||
{
|
||||
return 'pu_id';
|
||||
}
|
||||
}
|
@ -39,6 +39,16 @@ class Unidad extends Ideal\Repository
|
||||
return $this->update($model, ['subtipo', 'piso', 'descripcion', 'orientacion', 'pt'], $new_data);
|
||||
}
|
||||
|
||||
public function fetchById(int $id): Model\Venta\Unidad
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select('a.*, up.prorrateo')
|
||||
->from("{$this->getTable()} a")
|
||||
->joined($this->joinProrrateo())
|
||||
->where('a.id = ?');
|
||||
return $this->fetchOne($query, [$id]);
|
||||
}
|
||||
|
||||
public function fetchByVenta(int $venta_id): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
|
Reference in New Issue
Block a user