2024-03-04 19:55:49 -03:00
|
|
|
<?php
|
2024-06-18 22:41:03 -04:00
|
|
|
namespace Incoviba\Repository\Contabilidad\Movimiento;
|
2024-03-04 19:55:49 -03:00
|
|
|
|
|
|
|
use Incoviba\Common\Define;
|
|
|
|
use Incoviba\Common\Ideal;
|
|
|
|
use Incoviba\Common\Implement;
|
|
|
|
use Incoviba\Model;
|
|
|
|
use Incoviba\Repository;
|
|
|
|
|
|
|
|
class Detalle extends Ideal\Repository
|
|
|
|
{
|
2024-06-18 22:41:03 -04:00
|
|
|
public function __construct(Define\Connection $connection,
|
|
|
|
protected Repository\Contabilidad\Movimiento $movimientoRepository,
|
2024-03-26 09:38:20 -03:00
|
|
|
protected Repository\Contabilidad\CentroCosto $centroCostoRepository)
|
2024-03-04 19:55:49 -03:00
|
|
|
{
|
|
|
|
parent::__construct($connection);
|
|
|
|
$this->setTable('movimientos_detalles');
|
|
|
|
}
|
|
|
|
|
2024-06-18 22:41:03 -04:00
|
|
|
public function create(?array $data = null): Model\Contabilidad\Movimiento\Detalle
|
2024-03-04 19:55:49 -03:00
|
|
|
{
|
|
|
|
$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']);
|
|
|
|
}));
|
2024-06-18 22:41:03 -04:00
|
|
|
return $this->parseData(new Model\Contabilidad\Movimiento\Detalle(), $data, $map);
|
2024-03-04 19:55:49 -03:00
|
|
|
}
|
2024-06-18 22:41:03 -04:00
|
|
|
public function save(Define\Model $model): Model\Contabilidad\Movimiento\Detalle
|
2024-03-04 19:55:49 -03:00
|
|
|
{
|
|
|
|
$this->saveNew(
|
|
|
|
['movimiento_id', 'centro_costo_id', 'detalle'],
|
2024-06-18 22:41:03 -04:00
|
|
|
[$model->movimiento->id, $model->centroCosto->id, $model->detalles]
|
2024-03-04 19:55:49 -03:00
|
|
|
);
|
|
|
|
return $model;
|
|
|
|
}
|
2024-06-18 22:41:03 -04:00
|
|
|
public function edit(Define\Model $model, array $new_data): Model\Contabilidad\Movimiento\Detalle
|
2024-03-04 19:55:49 -03:00
|
|
|
{
|
|
|
|
return $this->update($model, ['movimiento_id', 'centro_costo_id', 'detalle'], $new_data);
|
|
|
|
}
|
|
|
|
|
2024-06-18 22:41:03 -04:00
|
|
|
public function fetchByMovimiento(int $movimiento_id): Model\Contabilidad\Movimiento\Detalle
|
2024-03-04 19:55:49 -03:00
|
|
|
{
|
|
|
|
$query = $this->connection->getQueryBuilder()
|
|
|
|
->select()
|
|
|
|
->from($this->getTable())
|
|
|
|
->where('movimiento_id = ?');
|
|
|
|
return $this->fetchOne($query, [$movimiento_id]);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getKey(): string
|
|
|
|
{
|
|
|
|
return 'movimiento_id';
|
|
|
|
}
|
|
|
|
}
|