Centros de Costos
This commit is contained in:
19
app/src/Repository/CategoriaCentro.php
Normal file
19
app/src/Repository/CategoriaCentro.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository;
|
||||
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Model;
|
||||
|
||||
class CategoriaCentro extends Tipo
|
||||
{
|
||||
public function __construct(Define\Connection $connection)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('categorias_centros_costos');
|
||||
}
|
||||
|
||||
protected function getBlank(): Define\Model
|
||||
{
|
||||
return new Model\CategoriaCentro();
|
||||
}
|
||||
}
|
81
app/src/Repository/CentroCosto.php
Normal file
81
app/src/Repository/CentroCosto.php
Normal file
@ -0,0 +1,81 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository;
|
||||
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement\Repository\Mapper;
|
||||
use Incoviba\Common\Implement\Repository\MapperParser;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Model;
|
||||
|
||||
class CentroCosto extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection, protected TipoCentro $tipoCentroRepository,
|
||||
protected CategoriaCentro $categoriaCentroRepository,
|
||||
protected TipoCuenta $tipoCuentaRepository)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('centros_costos');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Model\CentroCosto
|
||||
{
|
||||
$map = (new MapperParser(['descripcion']))
|
||||
->register('tipo_centro_id', (new Mapper())
|
||||
->setProperty('tipoCentro')
|
||||
->setFunction(function(array $data) {
|
||||
return $this->tipoCentroRepository->fetchById($data['tipo_centro_id']);
|
||||
}))
|
||||
->register('categoria_id', (new Mapper())
|
||||
->setProperty('categoria')
|
||||
->setFunction(function(array $data) {
|
||||
return $this->categoriaCentroRepository->fetchById($data['categoria_id']);
|
||||
}))
|
||||
->register('tipo_cuenta', (new Mapper())
|
||||
->setProperty('tipoCuenta')
|
||||
->setFunction(function(array $data) {
|
||||
return $this->tipoCuentaRepository->fetchById($data['tipo_cuenta_id']);
|
||||
})
|
||||
->setDefault(null))
|
||||
->register('cuenta_contable', (new Mapper())
|
||||
->setProperty('cuentaContable'));
|
||||
return $this->parseData(new Model\CentroCosto(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Model\CentroCosto
|
||||
{
|
||||
$this->saveNew(
|
||||
['id', 'tipo_centro_id', 'categoria_id', 'tipo_cuenta_id', 'cuenta_contable', 'descripcion'],
|
||||
[$model->id, $model->tipoCentro->id, $model->categoria->id, $model->tipoCuenta?->id, $model->cuentaContable, $model->descripcion]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Model\CentroCosto
|
||||
{
|
||||
return $this->update($model, ['tipo_centro_id', 'categoria_id', 'tipo_cuenta_id', 'cuenta_contable', 'descripcion'], $new_data);
|
||||
}
|
||||
|
||||
public function fetchByDescripcion(string $descripcion): Model\CentroCosto
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select()
|
||||
->from($this->getTable())
|
||||
->where('descripcion LIKE ?');
|
||||
return $this->fetchOne($query, [$descripcion]);
|
||||
}
|
||||
public function fetchByTipoCuenta(string $tipo_cuenta): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select()
|
||||
->from($this->getTable())
|
||||
->where('tipo_cuenta_id LIKE ?');
|
||||
return $this->fetchMany($query, [$tipo_cuenta]);
|
||||
}
|
||||
public function fetchByCategoria(string $categoria): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select()
|
||||
->from($this->getTable())
|
||||
->where('categoria_id LIKE ?');
|
||||
return $this->fetchMany($query, [$categoria]);
|
||||
}
|
||||
}
|
42
app/src/Repository/PagoCentroCosto.php
Normal file
42
app/src/Repository/PagoCentroCosto.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository;
|
||||
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class PagoCentroCosto extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection, protected Repository\Venta\Pago $pagoRepository, protected CentroCosto $centroCostoRepository)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('pagos_centros_costos');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Model\PagoCentroCosto
|
||||
{
|
||||
$map = (new Implement\Repository\MapperParser())
|
||||
->register('pago_id', (new Implement\Repository\Mapper())
|
||||
->setProperty('pago')
|
||||
->setFunction(function(array $data) {
|
||||
return $this->pagoRepository->fetchById($data['pago_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\PagoCentroCosto(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Model\PagoCentroCosto
|
||||
{
|
||||
$model->id = $this->saveNew(['pago_id', 'centro_costo_id'], [$model->pago->id, $model->centroCosto->id]);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Model\PagoCentroCosto
|
||||
{
|
||||
return $this->update($model, ['pago_id', 'centro_costo_id'], $new_data);
|
||||
}
|
||||
}
|
37
app/src/Repository/Tipo.php
Normal file
37
app/src/Repository/Tipo.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository;
|
||||
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement;
|
||||
|
||||
abstract class Tipo extends Ideal\Repository
|
||||
{
|
||||
abstract protected function getBlank(): Define\Model;
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = new Implement\Repository\MapperParser(['descripcion']);
|
||||
return $this->parseData($this->getBlank(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['descripcion'],
|
||||
[$model->descripcion]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
{
|
||||
return $this->update($model, ['descripcion'], $new_data);
|
||||
}
|
||||
|
||||
public function fetchByDescripcion(string $descripcion): Define\Model
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select()
|
||||
->from($this->getTable())
|
||||
->where('descripcion LIKE ?');
|
||||
return $this->fetchOne($query, [$descripcion]);
|
||||
}
|
||||
}
|
19
app/src/Repository/TipoCentro.php
Normal file
19
app/src/Repository/TipoCentro.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository;
|
||||
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Model;
|
||||
|
||||
class TipoCentro extends Tipo
|
||||
{
|
||||
public function __construct(Define\Connection $connection)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('tipos_centros_costos');
|
||||
}
|
||||
|
||||
protected function getBlank(): Define\Model
|
||||
{
|
||||
return new Model\TipoCentro();
|
||||
}
|
||||
}
|
19
app/src/Repository/TipoCuenta.php
Normal file
19
app/src/Repository/TipoCuenta.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository;
|
||||
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Model;
|
||||
|
||||
class TipoCuenta extends Tipo
|
||||
{
|
||||
public function __construct(Define\Connection $connection)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('tipos_cuentas_costos');
|
||||
}
|
||||
|
||||
protected function getBlank(): Define\Model
|
||||
{
|
||||
return new Model\TipoCuenta();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user