2024-02-12 09:59:15 -03:00
|
|
|
<?php
|
|
|
|
namespace Incoviba\Repository;
|
|
|
|
|
|
|
|
use Incoviba\Common\Define;
|
|
|
|
use Incoviba\Common\Ideal;
|
|
|
|
use Incoviba\Common\Implement;
|
|
|
|
use Incoviba\Repository;
|
|
|
|
use Incoviba\Model;
|
|
|
|
|
2024-02-13 01:16:17 -03:00
|
|
|
class Deposito extends Ideal\Repository
|
2024-02-12 09:59:15 -03:00
|
|
|
{
|
|
|
|
public function __construct(Define\Connection $connection, protected Repository\Inmobiliaria\Cuenta $cuentaRepository)
|
|
|
|
{
|
|
|
|
parent::__construct($connection);
|
|
|
|
$this->setTable('depositos');
|
|
|
|
}
|
|
|
|
|
2024-02-13 01:16:17 -03:00
|
|
|
public function create(?array $data = null): Model\Deposito
|
2024-02-12 09:59:15 -03:00
|
|
|
{
|
2024-02-13 01:16:17 -03:00
|
|
|
$map = (new Implement\Repository\MapperParser(['id', 'capital', 'futuro']))
|
2024-02-12 09:59:15 -03:00
|
|
|
->register('cuenta_id', (new Implement\Repository\Mapper())
|
|
|
|
->setProperty('cuenta')
|
|
|
|
->setFunction(function(array $data) {
|
|
|
|
return $this->cuentaRepository->fetchById($data['cuenta_id']);
|
|
|
|
}))
|
|
|
|
->register('inicio', new Implement\Repository\Mapper\DateTime('inicio'))
|
|
|
|
->register('termino', new Implement\Repository\Mapper\DateTime('termino'));
|
2024-02-13 01:16:17 -03:00
|
|
|
return $this->parseData(new Model\Deposito(), $data, $map);
|
2024-02-12 09:59:15 -03:00
|
|
|
}
|
2024-02-13 01:16:17 -03:00
|
|
|
public function save(Define\Model $model): Model\Deposito
|
2024-02-12 09:59:15 -03:00
|
|
|
{
|
2024-02-13 01:16:17 -03:00
|
|
|
$this->saveNew([
|
|
|
|
'id', 'cuenta_id', 'capital', 'futuro', 'inicio', 'termino'
|
2024-02-12 09:59:15 -03:00
|
|
|
], [
|
2024-02-13 01:16:17 -03:00
|
|
|
$model->id, $model->cuenta->id, $model->capital, $model->futuro,
|
2024-02-12 09:59:15 -03:00
|
|
|
$model->inicio->format('Y-m-d'), $model->termino->format('Y-m-d')
|
|
|
|
]);
|
|
|
|
return $model;
|
|
|
|
}
|
|
|
|
|
2024-02-13 01:16:17 -03:00
|
|
|
public function edit(Define\Model $model, array $new_data): Model\Deposito
|
2024-02-12 09:59:15 -03:00
|
|
|
{
|
|
|
|
return $this->update($model, ['cuenta_id', 'capital', 'futuro', 'inicio', 'termino'], $new_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function fetchByCuenta(int $cuenta_id): array
|
|
|
|
{
|
|
|
|
$query = $this->connection->getQueryBuilder()
|
|
|
|
->select()
|
|
|
|
->from($this->getTable())
|
|
|
|
->where('cuenta_id = ?');
|
|
|
|
return $this->fetchMany($query, [$cuenta_id]);
|
|
|
|
}
|
2024-02-13 01:16:17 -03:00
|
|
|
}
|