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')]);
|
||||
}
|
||||
}
|
@ -6,6 +6,7 @@ use Incoviba\Common\Ideal;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Common\Implement;
|
||||
use PhpParser\Node\Expr\BinaryOp\Mod;
|
||||
|
||||
class Cuenta extends Ideal\Repository
|
||||
{
|
||||
@ -49,4 +50,12 @@ class Cuenta extends Ideal\Repository
|
||||
->where('inmobiliaria = ?');
|
||||
return $this->fetchMany($query, [$inmobiliaria_rut]);
|
||||
}
|
||||
public function fetchByInmobiliariaAndBanco(int $inmobiliaria_rut, int $banco_id): Model\Inmobiliaria\Cuenta
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select()
|
||||
->from($this->getTable())
|
||||
->where('inmobiliaria = ? AND banco = ?');
|
||||
return $this->fetchOne($query, [$inmobiliaria_rut, $banco_id]);
|
||||
}
|
||||
}
|
||||
|
64
app/src/Repository/Movimiento.php
Normal file
64
app/src/Repository/Movimiento.php
Normal file
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository;
|
||||
|
||||
use DateTimeInterface;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Movimiento extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection, protected Inmobiliaria\Cuenta $cuentaRepository)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('movimientos');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Model\Movimiento
|
||||
{
|
||||
$map = (new Implement\Repository\MapperParser(['cargo', 'abono', 'saldo', 'glosa', 'documento']))
|
||||
->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\Movimiento(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Model\Movimiento
|
||||
{
|
||||
$model->id = $this->saveNew([
|
||||
'cuenta_id',
|
||||
'fecha',
|
||||
'glosa',
|
||||
'documento',
|
||||
'cargo',
|
||||
'abono',
|
||||
'saldo'
|
||||
], [
|
||||
$model->cuenta->id,
|
||||
$model->fecha->format('Y-m-d'),
|
||||
$model->glosa,
|
||||
$model->documento,
|
||||
$model->cargo,
|
||||
$model->abono,
|
||||
$model->saldo
|
||||
]);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Model\Movimiento
|
||||
{
|
||||
return $this->update($model, ['cuenta_id', 'fecha', 'glosa', 'documento', 'cargo', 'abono', 'saldo'], $new_data);
|
||||
}
|
||||
|
||||
public function fetchByCuentaAndFechaAndMonto(int $cuenta_id, DateTimeInterface $fecha, int $monto): Model\Movimiento
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select()
|
||||
->from($this->getTable())
|
||||
->where('cuenta_id = ? AND fecha = ? AND (cargo = ? OR abono = ?)');
|
||||
return $this->fetchOne($query, [$cuenta_id, $fecha->format('Y-m-d'), $monto, $monto]);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user