diff --git a/app/resources/routes/05_contabilidad.php b/app/resources/routes/05_contabilidad.php
new file mode 100644
index 0000000..08de783
--- /dev/null
+++ b/app/resources/routes/05_contabilidad.php
@@ -0,0 +1,10 @@
+group('/contabilidad', function($app) {
+ $files = new FilesystemIterator(implode(DIRECTORY_SEPARATOR, [__DIR__, 'contabilidad']));
+ foreach ($files as $file) {
+ if ($file->isDir()) {
+ continue;
+ }
+ include_once $file->getRealPath();
+ }
+});
diff --git a/app/resources/routes/api/contabilidad.php b/app/resources/routes/api/contabilidad.php
new file mode 100644
index 0000000..08de783
--- /dev/null
+++ b/app/resources/routes/api/contabilidad.php
@@ -0,0 +1,10 @@
+group('/contabilidad', function($app) {
+ $files = new FilesystemIterator(implode(DIRECTORY_SEPARATOR, [__DIR__, 'contabilidad']));
+ foreach ($files as $file) {
+ if ($file->isDir()) {
+ continue;
+ }
+ include_once $file->getRealPath();
+ }
+});
diff --git a/app/resources/routes/api/contabilidad/centros_costos.php b/app/resources/routes/api/contabilidad/centros_costos.php
new file mode 100644
index 0000000..877052b
--- /dev/null
+++ b/app/resources/routes/api/contabilidad/centros_costos.php
@@ -0,0 +1,10 @@
+group('/centros_costos', function($app) {
+ $app->post('/add[/]', [CentrosCostos::class, 'add']);
+});
+$app->group('/centro_costo/{centro_costo_id}', function($app) {
+ $app->post('/edit[/]', [CentrosCostos::class, 'edit']);
+ $app->delete('[/]', [CentrosCostos::class, 'remove']);
+});
diff --git a/app/resources/routes/contabilidad/centros_costos.php b/app/resources/routes/contabilidad/centros_costos.php
new file mode 100644
index 0000000..8af10b3
--- /dev/null
+++ b/app/resources/routes/contabilidad/centros_costos.php
@@ -0,0 +1,6 @@
+group('/centros_costos', function($app) {
+ $app->get('[/]', CentrosCostos::class);
+});
diff --git a/app/resources/views/contabilidad/centros_costos.blade.php b/app/resources/views/contabilidad/centros_costos.blade.php
new file mode 100644
index 0000000..81b4f57
--- /dev/null
+++ b/app/resources/views/contabilidad/centros_costos.blade.php
@@ -0,0 +1,329 @@
+@extends('layout.base')
+
+@section('page_content')
+
+
+
+
+
+
+
+
+ Tipo de Centro |
+ Categoría |
+ Tipo de Cuenta |
+ Cuenta Contable |
+ Centro de Costo |
+ Descripción |
+
+ |
+
+
+
+ @foreach ($centrosCostos as $centroCosto)
+
+ {{$centroCosto->tipoCentro->descripcion}} |
+ {{$centroCosto->categoria->descripcion}} |
+ {{$centroCosto->tipoCuenta?->descripcion}} |
+ {{$centroCosto->cuentaContable}} |
+ {{$centroCosto->id}} |
+ {{$centroCosto->descripcion}} |
+
+
+
+
+
+ |
+
+ @endforeach
+
+
+
+
+
+
+
+
+
+
+
+
+
+@endsection
+
+@include('layout.head.styles.datatables')
+@include('layout.body.scripts.datatables')
+
+@push('page_scripts')
+
+@endpush
diff --git a/app/src/Controller/API/CentrosCostos.php b/app/src/Controller/API/CentrosCostos.php
new file mode 100644
index 0000000..f1466b5
--- /dev/null
+++ b/app/src/Controller/API/CentrosCostos.php
@@ -0,0 +1,62 @@
+getParsedBody();
+ $output = [
+ 'input' => $body,
+ 'added' => false
+ ];
+ try {
+ $centroCosto = $centroCostoRepository->create($body);
+ $centroCosto->id = $body['id'];
+ $centroCostoRepository->save($centroCosto);
+ $output['added'] = true;
+ } catch (EmptyResult) {}
+ return $this->withJson($response, $output);
+ }
+ public function edit(ServerRequestInterface $request, ResponseInterface $response,
+ Repository\CentroCosto $centroCostoRepository, int $centro_costo_id): ResponseInterface
+ {
+ $body = $request->getParsedBody();
+ $output = [
+ 'centro_costo_id' => $centro_costo_id,
+ 'input' => $body,
+ 'edited' => false
+ ];
+ try {
+ $centroCosto = $centroCostoRepository->fetchById($centro_costo_id);
+ if ($body['tipo_cuenta_id'] === '') {
+ $body['tipo_cuenta_id'] = null;
+ }
+ $centroCostoRepository->edit($centroCosto, $body);
+ $output['edited'] = true;
+ } catch (EmptyResult) {}
+ return $this->withJson($response, $output);
+ }
+ public function remove(ServerRequestInterface $request, ResponseInterface $response,
+ Repository\CentroCosto $centroCostoRepository, int $centro_costo_id): ResponseInterface
+ {
+ $output = [
+ 'centro_costo_id' => $centro_costo_id,
+ 'removed' => false
+ ];
+ try {
+ $centroCosto = $centroCostoRepository->fetchById($centro_costo_id);
+ $centroCostoRepository->remove($centroCosto);
+ $output['removed'] = true;
+ } catch (EmptyResult) {}
+ return $this->withJson($response, $output);
+ }
+}
diff --git a/app/src/Controller/CentrosCostos.php b/app/src/Controller/CentrosCostos.php
new file mode 100644
index 0000000..13fb89a
--- /dev/null
+++ b/app/src/Controller/CentrosCostos.php
@@ -0,0 +1,24 @@
+fetchAll();
+ $tiposCentros = $tipoCentroRepository->fetchAll();
+ $categorias = $categoriaCentroRepository->fetchAll('descripcion');
+ $tiposCuentas = $tipoCuentaRepository->fetchAll();
+ return $view->render($response, 'contabilidad.centros_costos', compact('centrosCostos',
+ 'tiposCentros', 'categorias', 'tiposCuentas'));
+ }
+}
diff --git a/app/src/Model/CategoriaCentro.php b/app/src/Model/CategoriaCentro.php
new file mode 100644
index 0000000..e131f86
--- /dev/null
+++ b/app/src/Model/CategoriaCentro.php
@@ -0,0 +1,5 @@
+ $this->tipoCentro,
+ 'categoria' => $this->categoria,
+ 'tipo_cuenta' => $this->tipoCuenta,
+ 'cuenta_contable' => $this->cuentaContable,
+ 'descripcion' => $this->descripcion
+ ]);
+ }
+}
diff --git a/app/src/Model/PagoCentroCosto.php b/app/src/Model/PagoCentroCosto.php
new file mode 100644
index 0000000..5be8849
--- /dev/null
+++ b/app/src/Model/PagoCentroCosto.php
@@ -0,0 +1,18 @@
+ $this->pago,
+ 'centro_costo' => $this->centroCosto
+ ]);
+ }
+}
diff --git a/app/src/Model/TipoCentro.php b/app/src/Model/TipoCentro.php
new file mode 100644
index 0000000..9c23000
--- /dev/null
+++ b/app/src/Model/TipoCentro.php
@@ -0,0 +1,5 @@
+setTable('categorias_centros_costos');
+ }
+
+ protected function getBlank(): Define\Model
+ {
+ return new Model\CategoriaCentro();
+ }
+}
diff --git a/app/src/Repository/CentroCosto.php b/app/src/Repository/CentroCosto.php
new file mode 100644
index 0000000..55c24b2
--- /dev/null
+++ b/app/src/Repository/CentroCosto.php
@@ -0,0 +1,81 @@
+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]);
+ }
+}
diff --git a/app/src/Repository/PagoCentroCosto.php b/app/src/Repository/PagoCentroCosto.php
new file mode 100644
index 0000000..0e2e046
--- /dev/null
+++ b/app/src/Repository/PagoCentroCosto.php
@@ -0,0 +1,42 @@
+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);
+ }
+}
diff --git a/app/src/Repository/Tipo.php b/app/src/Repository/Tipo.php
new file mode 100644
index 0000000..791d47c
--- /dev/null
+++ b/app/src/Repository/Tipo.php
@@ -0,0 +1,37 @@
+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]);
+ }
+}
diff --git a/app/src/Repository/TipoCentro.php b/app/src/Repository/TipoCentro.php
new file mode 100644
index 0000000..db5bae9
--- /dev/null
+++ b/app/src/Repository/TipoCentro.php
@@ -0,0 +1,19 @@
+setTable('tipos_centros_costos');
+ }
+
+ protected function getBlank(): Define\Model
+ {
+ return new Model\TipoCentro();
+ }
+}
diff --git a/app/src/Repository/TipoCuenta.php b/app/src/Repository/TipoCuenta.php
new file mode 100644
index 0000000..2076a65
--- /dev/null
+++ b/app/src/Repository/TipoCuenta.php
@@ -0,0 +1,19 @@
+setTable('tipos_cuentas_costos');
+ }
+
+ protected function getBlank(): Define\Model
+ {
+ return new Model\TipoCuenta();
+ }
+}