This commit is contained in:
2024-01-17 10:33:11 -03:00
parent c4f486d3fa
commit 674aba801e
27 changed files with 1210 additions and 2 deletions

View File

@ -46,4 +46,20 @@ class Inmobiliaria extends Ideal\Repository
{
return $this->update($model, ['dv', 'razon', 'abreviacion', 'cuenta', 'banco', 'sociedad'], $new_data);
}
public function fetchAllActive(null|string|array $sorting = null): array
{
$query = $this->connection->getQueryBuilder()
->select('a.*')
->from("{$this->getTable()} a")
->joined('JOIN proyecto ON a.rut = proyecto.inmobiliaria')
->joined('JOIN (SELECT ep1.* FROM estado_proyecto ep1 JOIN (SELECT MAX(id) AS id, proyecto FROM estado_proyecto GROUP BY proyecto) ep0 ON ep0.id = ep1.id) ep ON ep.proyecto = proyecto.id')
->joined('JOIN tipo_estado_proyecto tep ON tep.id = ep.estado')
->joined('JOIN etapa_proyecto ON etapa_proyecto.id = tep.etapa')
->where('etapa_proyecto.orden BETWEEN ? AND ?');
if ($sorting !== null) {
$query->order($sorting);
}
return $this->fetchMany($query, [1, 8]);
}
}

View File

@ -0,0 +1,52 @@
<?php
namespace Incoviba\Repository\Inmobiliaria;
use Incoviba\Common\Define;
use Incoviba\Common\Ideal;
use Incoviba\Repository;
use Incoviba\Model;
use Incoviba\Common\Implement;
class Cuenta extends Ideal\Repository
{
public function __construct(Define\Connection $connection,
protected Repository\Inmobiliaria $inmobiliariaRepository,
protected Repository\Banco $bancoRepository)
{
parent::__construct($connection);
$this->setTable('cuenta');
}
public function create(?array $data = null): Model\Inmobiliaria\Cuenta
{
$map = (new Implement\Repository\MapperParser(['cuenta']))
->register('inmobiliaria', (new Implement\Repository\Mapper())
->setFunction(function(array $data) {
return $this->inmobiliariaRepository->fetchById($data['inmobiliaria']);
}))
->register('banco', (new Implement\Repository\Mapper())
->setFunction(function(array $data) {
return $this->bancoRepository->fetchById($data['banco']);
}));
return $this->parseData(new Model\Inmobiliaria\Cuenta(), $data, $map);
}
public function save(Define\Model $model): Model\Inmobiliaria\Cuenta
{
$model->id = $this->saveNew(['inmobiliaria', 'banco', 'cuenta'],
[$model->inmobiliaria->rut, $model->banco->id, $model->cuenta]);
return $model;
}
public function edit(Define\Model $model, array $new_data): Model\Inmobiliaria\Cuenta
{
return $this->update($model, ['inmobiliaria', 'banco', 'cuenta'], $new_data);
}
public function fetchByInmobiliaria(int $inmobiliaria_rut): array
{
$query = $this->connection->getQueryBuilder()
->select()
->from($this->getTable())
->where('inmobiliaria = ?');
return $this->fetchMany($query, [$inmobiliaria_rut]);
}
}

View File

@ -0,0 +1,55 @@
<?php
namespace Incoviba\Repository;
use Incoviba\Common\Define;
use Incoviba\Common\Ideal;
use Incoviba\Common\Implement;
use Incoviba\Model;
class Nubox extends Ideal\Repository
{
public function __construct(Define\Connection $connection, protected Inmobiliaria $inmobiliariaRepository)
{
parent::__construct($connection);
$this->setTable('inmobiliarias_nubox');
}
public function create(?array $data = null): Model\Nubox
{
$map = (new Implement\Repository\MapperParser(['usuario', 'alias']))
->register('inmobiliaria_rut', (new Implement\Repository\Mapper())
->setProperty('inmobiliaria')
->setFunction(function(array $data) {
return $this->inmobiliariaRepository->fetchById($data['inmobiliaria_rut']);
}))
->register('contraseña', (new Implement\Repository\Mapper())
->setProperty('password'));
return $this->parseData(new Model\Nubox(), $data, $map);
}
public function save(Define\Model $model): Model\Nubox
{
$this->saveNew(
['inmobiliaria_rut', 'alias', 'usuario', 'contraseña'],
[$model->inmobiliaria->rut, $model->alias, $model->usuario, $model->password]
);
return $model;
}
public function edit(Define\Model $model, array $new_data): Model\Nubox
{
return $this->update($model, ['inmobiliaria_rut', 'alias', 'usuario', 'contraseña'], $new_data);
}
public function fetchByInmobiliaria(int $inmobiliaria_rut): Model\Nubox
{
$query = $this->connection->getQueryBuilder()
->select()
->from($this->getTable())
->where('inmobiliaria_rut = ?');
return $this->fetchOne($query, [$inmobiliaria_rut]);
}
protected function getKey(): string
{
return 'inmobiliaria_rut';
}
}