Movimiento + Detalles
This commit is contained in:
60
app/src/Repository/Movimiento/Detalle.php
Normal file
60
app/src/Repository/Movimiento/Detalle.php
Normal file
@ -0,0 +1,60 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Movimiento;
|
||||
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class Detalle extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection, protected Repository\Movimiento $movimientoRepository,
|
||||
protected Repository\CentroCosto $centroCostoRepository)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('movimientos_detalles');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Model\Movimiento\Detalle
|
||||
{
|
||||
$map = (new Implement\Repository\MapperParser(['detalle']))
|
||||
->register('movimiento_id', (new Implement\Repository\Mapper())
|
||||
->setProperty('movimiento')
|
||||
->setFunction(function(array $data) {
|
||||
return $this->movimientoRepository->fetchById($data['movimiento_id']);
|
||||
}))
|
||||
->register('centro_costo_id', (new Implement\Repository\Mapper())
|
||||
->setProperty('centroCosto')
|
||||
->setFunction(function(array $data) {
|
||||
return $this->centroCostoRepository->fetchById($data['centro_costo_id']);
|
||||
}));
|
||||
return $this->parseData(new Model\Movimiento\Detalle(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Model\Movimiento\Detalle
|
||||
{
|
||||
$this->saveNew(
|
||||
['movimiento_id', 'centro_costo_id', 'detalle'],
|
||||
[$model->movimiento->id, $model->centroCosto->id, $model->detalle]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Model\Movimiento\Detalle
|
||||
{
|
||||
return $this->update($model, ['movimiento_id', 'centro_costo_id', 'detalle'], $new_data);
|
||||
}
|
||||
|
||||
public function fetchByMovimiento(int $movimiento_id): Model\Movimiento\Detalle
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select()
|
||||
->from($this->getTable())
|
||||
->where('movimiento_id = ?');
|
||||
return $this->fetchOne($query, [$movimiento_id]);
|
||||
}
|
||||
|
||||
protected function getKey(): string
|
||||
{
|
||||
return 'movimiento_id';
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user