API Movimientos y cartola diaria
This commit is contained in:
60
app/src/Repository/Cartola.php
Normal file
60
app/src/Repository/Cartola.php
Normal file
@ -0,0 +1,60 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository;
|
||||
|
||||
use DateTimeInterface;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class Cartola extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection, protected Repository\Inmobiliaria\Cuenta $cuentaRepository)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('cartolas');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Model\Cartola
|
||||
{
|
||||
$map = (new Implement\Repository\MapperParser(['cargos', 'abonos', 'saldo']))
|
||||
->register('fecha', new Implement\Repository\Mapper\DateTime('fecha'))
|
||||
->register('cuenta_id', (new Implement\Repository\Mapper())
|
||||
->setProperty('cuenta')
|
||||
->setFunction(function($data) {
|
||||
return $this->cuentaRepository->fetchById($data['cuenta_id']);
|
||||
}));
|
||||
return $this->parseData(new Model\Cartola(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Model\Cartola
|
||||
{
|
||||
$model->id = $this->saveNew([
|
||||
'cuenta_id',
|
||||
'fecha',
|
||||
'cargos',
|
||||
'abonos',
|
||||
'saldo'
|
||||
], [
|
||||
$model->cuenta->id,
|
||||
$model->fecha->format('Y-m-d'),
|
||||
$model->cargos,
|
||||
$model->abonos,
|
||||
$model->saldo
|
||||
]);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Model\Cartola
|
||||
{
|
||||
return $this->update($model, ['cuenta_id', 'fecha', 'cargos', 'abonos', 'saldo'], $new_data);
|
||||
}
|
||||
|
||||
public function fetchByCuentaAndFecha(int $cuenta_id, DateTimeInterface $fecha): Model\Cartola
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select()
|
||||
->from($this->getTable())
|
||||
->where('cuenta_id = ? AND fecha = ?');
|
||||
return $this->fetchOne($query, [$cuenta_id, $fecha->format('Y-m-d')]);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user