API 1.0.0-rc
This commit is contained in:
5
api/Dockerfile
Normal file
5
api/Dockerfile
Normal file
@ -0,0 +1,5 @@
|
||||
FROM php:8-fpm
|
||||
|
||||
RUN docker-php-ext-install pdo pdo_mysql
|
||||
|
||||
WORKDIR /app
|
71
api/common/Controller/Bancos.php
Normal file
71
api/common/Controller/Bancos.php
Normal file
@ -0,0 +1,71 @@
|
||||
<?php
|
||||
namespace Contabilidad\Common\Controller;
|
||||
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use ProVM\Common\Define\Controller\Json;
|
||||
use ProVM\Common\Factory\Model as Factory;
|
||||
use Contabilidad\Banco;
|
||||
|
||||
class Bancos {
|
||||
use Json;
|
||||
|
||||
public function __invoke(Request $request, Response $response, Factory $factory): Response {
|
||||
$bancos = $factory->find(Banco::class)->array();
|
||||
if ($bancos) {
|
||||
usort($bancos, function($a, $b) {
|
||||
return strcmp($a['nombre'], $b['nombre']);
|
||||
});
|
||||
}
|
||||
$output = [
|
||||
'bancos' => $bancos
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function show(Request $request, Response $response, Factory $factory, $banco_id): Response {
|
||||
$banco = $factory->find(Banco::class)->one($banco_id);
|
||||
$output = [
|
||||
'input' => $banco_id,
|
||||
'banco' => $banco?->toArray()
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function add(Request $request, Response $response, Factory $factory): Response {
|
||||
$input = json_decode($request->getBody());
|
||||
$results = [];
|
||||
if (is_array($input)) {
|
||||
foreach ($input as $in) {
|
||||
$banco = Banco::add($factory, $in);
|
||||
$results []= ['banco' => $banco?->toArray(), 'agregado' => $banco?->save()];
|
||||
}
|
||||
} else {
|
||||
$banco = Banco::add($factory, $input);
|
||||
$results []= ['banco' => $banco?->toArray(), 'agregado' => $banco?->save()];
|
||||
}
|
||||
$output = [
|
||||
'input' => $input,
|
||||
'bancos' => $results
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function edit(Request $request, Response $response, Factory $factory, $banco_id): Response {
|
||||
$banco = $factory->find(Banco::class)->one($banco_id);
|
||||
$output = [
|
||||
'input' => $banco_id,
|
||||
'old' => $banco->toArray()
|
||||
];
|
||||
$input = json_decode($request->getBody());
|
||||
$banco->edit($input);
|
||||
$output['banco'] = $banco->toArray();
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function delete(Request $request, Response $response, Factory $factory, $banco_id): Response {
|
||||
$banco = $factory->find(Banco::class)->one($banco_id);
|
||||
$output = [
|
||||
'input' => $banco_id,
|
||||
'banco' => $banco->toArray(),
|
||||
'eliminado' => $banco->delete()
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
}
|
14
api/common/Controller/Base.php
Normal file
14
api/common/Controller/Base.php
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
namespace Contabilidad\Common\Controller;
|
||||
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use ProVM\Common\Define\Controller\Json;
|
||||
|
||||
class Base {
|
||||
use Json;
|
||||
|
||||
public function __invoke(Request $request, Response $response): Response {
|
||||
return $this->withJson($response, []);
|
||||
}
|
||||
}
|
89
api/common/Controller/Categorias.php
Normal file
89
api/common/Controller/Categorias.php
Normal file
@ -0,0 +1,89 @@
|
||||
<?php
|
||||
namespace Contabilidad\Common\Controller;
|
||||
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use ProVM\Common\Define\Controller\Json;
|
||||
use ProVM\Common\Factory\Model as Factory;
|
||||
use Contabilidad\Categoria;
|
||||
|
||||
class Categorias {
|
||||
use Json;
|
||||
|
||||
public function __invoke(Request $request, Response $response, Factory $factory): Response {
|
||||
$categorias = $factory->find(Categoria::class)->array();
|
||||
if ($categorias) {
|
||||
usort($categorias, function($a, $b) {
|
||||
return strcmp($a['nombre'], $b['nombre']);
|
||||
});
|
||||
}
|
||||
$output = [
|
||||
'categorias' => $categorias
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function show(Request $request, Response $response, Factory $factory, $categoria_id): Response {
|
||||
$categoria = $factory->find(Categoria::class)->one($categoria_id);
|
||||
$output = [
|
||||
'input' => $categoria_id,
|
||||
'categoria' => $categoria?->toArray()
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function add(Request $request, Response $response, Factory $factory): Response {
|
||||
$input = json_decode($request->getBody());
|
||||
$results = [];
|
||||
if (is_array($input)) {
|
||||
foreach ($input as $in) {
|
||||
$categoria = Categoria::add($factory, $in);
|
||||
$results []= ['categoria' => $categoria?->toArray(), 'agregado' => $categoria?->save()];
|
||||
}
|
||||
} else {
|
||||
$categoria = Categoria::add($factory, $input);
|
||||
$results []= ['categoria' => $categoria?->toArray(), 'agregado' => $categoria?->save()];
|
||||
}
|
||||
$output = [
|
||||
'input' => $input,
|
||||
'categorias' => $results
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function edit(Request $request, Response $response, Factory $factory, $categoria_id): Response {
|
||||
$categoria = $factory->find(Categoria::class)->one($categoria_id);
|
||||
$output = [
|
||||
'input' => $categoria_id,
|
||||
'old' => $categoria->toArray()
|
||||
];
|
||||
$input = json_decode($request->getBody());
|
||||
$categoria->edit($input);
|
||||
$output['categoria'] = $categoria->toArray();
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function delete(Request $request, Response $response, Factory $factory, $categoria_id): Response {
|
||||
$categoria = $factory->find(Categoria::class)->one($categoria_id);
|
||||
$output = [
|
||||
'input' => $categoria_id,
|
||||
'categoria' => $categoria->toArray(),
|
||||
'eliminado' => $categoria->delete()
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function cuentas(Request $request, Response $response, Factory $factory, $categoria_id): Response {
|
||||
$categoria = $factory->find(Categoria::class)->one($categoria_id);
|
||||
$cuentas = null;
|
||||
if ($categoria !== null) {
|
||||
$cuentas = $categoria->cuentas();
|
||||
if ($cuentas !== null) {
|
||||
array_walk($cuentas, function(&$item) {
|
||||
$item = $item->toArray();
|
||||
});
|
||||
}
|
||||
}
|
||||
$output = [
|
||||
'input' => $categoria_id,
|
||||
'categoria' => $categoria?->toArray(),
|
||||
'cuentas' => $cuentas
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
}
|
93
api/common/Controller/Cuentas.php
Normal file
93
api/common/Controller/Cuentas.php
Normal file
@ -0,0 +1,93 @@
|
||||
<?php
|
||||
namespace Contabilidad\Common\Controller;
|
||||
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use ProVM\Common\Define\Controller\Json;
|
||||
use ProVM\Common\Factory\Model as Factory;
|
||||
use Contabilidad\Cuenta;
|
||||
|
||||
class Cuentas {
|
||||
use Json;
|
||||
|
||||
public function __invoke(Request $request, Response $response, Factory $factory): Response {
|
||||
$cuentas = $factory->find(Cuenta::class)->array();
|
||||
if ($cuentas) {
|
||||
usort($cuentas, function($a, $b) {
|
||||
$c = strcmp($a['categoria']['nombre'], $b['categoria']['nombre']);
|
||||
if ($c == 0) {
|
||||
return strcmp($a['nombre'], $b['nombre']);
|
||||
}
|
||||
return $c;
|
||||
});
|
||||
}
|
||||
$output = [
|
||||
'cuentas' => $cuentas
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function show(Request $request, Response $response, Factory $factory, $cuenta_id): Response {
|
||||
$cuenta = $factory->find(Cuenta::class)->one($cuenta_id);
|
||||
$output = [
|
||||
'input' => $cuenta_id,
|
||||
'cuenta' => $cuenta?->toArray()
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function add(Request $request, Response $response, Factory $factory): Response {
|
||||
$input = json_decode($request->getBody());
|
||||
$results = [];
|
||||
if (is_array($input)) {
|
||||
foreach ($input as $in) {
|
||||
$cuenta = Cuenta::add($factory, $in);
|
||||
$results []= ['cuenta' => $cuenta?->toArray(), 'agregado' => $cuenta?->save()];
|
||||
}
|
||||
} else {
|
||||
$cuenta = Cuenta::add($factory, $input);
|
||||
$results []= ['cuenta' => $cuenta?->toArray(), 'agregado' => $cuenta?->save()];
|
||||
}
|
||||
$output = [
|
||||
'input' => $input,
|
||||
'cuentas' => $results
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function edit(Request $request, Response $response, Factory $factory, $cuenta_id): Response {
|
||||
$cuenta = $factory->find(Cuenta::class)->one($cuenta_id);
|
||||
$output = [
|
||||
'input' => $cuenta_id,
|
||||
'old' => $cuenta->toArray()
|
||||
];
|
||||
$input = json_decode($request->getBody());
|
||||
$cuenta->edit($input);
|
||||
$output['cuenta'] = $cuenta->toArray();
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function delete(Request $request, Response $response, Factory $factory, $cuenta_id): Response {
|
||||
$cuenta = $factory->find(Cuenta::class)->one($cuenta_id);
|
||||
$output = [
|
||||
'input' => $cuenta_id,
|
||||
'cuenta' => $cuenta->toArray(),
|
||||
'eliminado' => $cuenta->delete()
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function entradas(Request $request, Response $response, Factory $factory, $cuenta_id): Response {
|
||||
$cuenta = $factory->find(Cuenta::class)->one($cuenta_id);
|
||||
$entradas = null;
|
||||
if ($cuenta !== null) {
|
||||
$entradas = $cuenta->entradas();
|
||||
if ($entradas !== null) {
|
||||
array_walk($entradas, function(&$item) {
|
||||
$item = $item->toArray();
|
||||
});
|
||||
}
|
||||
}
|
||||
$output = [
|
||||
'input' => $cuenta_id,
|
||||
'cuenta' => $cuenta?->toArray(),
|
||||
'entradas' => $entradas
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
}
|
66
api/common/Controller/Entradas.php
Normal file
66
api/common/Controller/Entradas.php
Normal file
@ -0,0 +1,66 @@
|
||||
<?php
|
||||
namespace Contabilidad\Common\Controller;
|
||||
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use ProVM\Common\Define\Controller\Json;
|
||||
use ProVM\Common\Factory\Model as Factory;
|
||||
use Contabilidad\Entrada;
|
||||
|
||||
class Entradas {
|
||||
use Json;
|
||||
|
||||
public function __invoke(Request $request, Response $response, Factory $factory): Response {
|
||||
$entradas = $factory->find(Entrada::class)->array();
|
||||
$output = [
|
||||
'entradas' => $entradas
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function show(Request $request, Response $response, Factory $factory, $entrada_id): Response {
|
||||
$entrada = $factory->find(Entrada::class)->one($entrada_id);
|
||||
$output = [
|
||||
'input' => $entrada_id,
|
||||
'entrada' => $entrada?->toArray()
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function add(Request $request, Response $response, Factory $factory): Response {
|
||||
$input = json_decode($request->getBody());
|
||||
$results = [];
|
||||
if (is_array($input)) {
|
||||
foreach ($input as $in) {
|
||||
$entrada = Entrada::add($factory, $in);
|
||||
$results []= ['entrada' => $entrada?->toArray(), 'agregado' => $entrada?->save()];
|
||||
}
|
||||
} else {
|
||||
$entrada = Entrada::add($factory, $input);
|
||||
$results []= ['entrada' => $entrada?->toArray(), 'agregado' => $entrada?->save()];
|
||||
}
|
||||
$output = [
|
||||
'input' => $input,
|
||||
'entradas' => $results
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function edit(Request $request, Response $response, Factory $factory, $entrada_id): Response {
|
||||
$entrada = $factory->find(Entrada::class)->one($entrada_id);
|
||||
$output = [
|
||||
'input' => $entrada_id,
|
||||
'old' => $entrada->toArray()
|
||||
];
|
||||
$input = json_decode($request->getBody());
|
||||
$entrada->edit($input);
|
||||
$output['entrada'] = $entrada->toArray();
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function delete(Request $request, Response $response, Factory $factory, $entrada_id): Response {
|
||||
$entrada = $factory->find(Entrada::class)->one($entrada_id);
|
||||
$output = [
|
||||
'input' => $entrada_id,
|
||||
'entrada' => $entrada->toArray(),
|
||||
'eliminado' => $entrada->delete()
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
}
|
84
api/common/Controller/Fuentes.php
Normal file
84
api/common/Controller/Fuentes.php
Normal file
@ -0,0 +1,84 @@
|
||||
<?php
|
||||
namespace Contabilidad\Common\Controller;
|
||||
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use ProVM\Common\Define\Controller\Json;
|
||||
use ProVM\Common\Factory\Model as Factory;
|
||||
use Contabilidad\Fuente;
|
||||
|
||||
class Fuentes {
|
||||
use Json;
|
||||
|
||||
public function __invoke(Request $request, Response $response, Factory $factory): Response {
|
||||
$fuentes = $factory->find(Fuente::class)->array();
|
||||
$output = [
|
||||
'fuentes' => $fuentes
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function show(Request $request, Response $response, Factory $factory, $fuente_id): Response {
|
||||
$fuente = $factory->find(Fuente::class)->one($fuente_id);
|
||||
$output = [
|
||||
'input' => $fuente_id,
|
||||
'fuente' => $fuente?->toArray()
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function add(Request $request, Response $response, Factory $factory): Response {
|
||||
$input = json_decode($request->getBody());
|
||||
$results = [];
|
||||
if (is_array($input)) {
|
||||
foreach ($input as $in) {
|
||||
$fuente = Fuente::add($factory, $in);
|
||||
$results []= ['fuente' => $fuente?->toArray(), 'agregado' => $fuente?->save()];
|
||||
}
|
||||
} else {
|
||||
$fuente = Fuente::add($factory, $input);
|
||||
$results []= ['fuente' => $fuente?->toArray(), 'agregado' => $fuente?->save()];
|
||||
}
|
||||
$output = [
|
||||
'input' => $input,
|
||||
'fuentes' => $results
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function edit(Request $request, Response $response, Factory $factory, $fuente_id): Response {
|
||||
$fuente = $factory->find(Fuente::class)->one($fuente_id);
|
||||
$output = [
|
||||
'input' => $fuente_id,
|
||||
'old' => $fuente->toArray()
|
||||
];
|
||||
$input = json_decode($request->getBody());
|
||||
$fuente->edit($input);
|
||||
$output['fuente'] = $fuente->toArray();
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function delete(Request $request, Response $response, Factory $factory, $fuente_id): Response {
|
||||
$fuente = $factory->find(Fuente::class)->one($fuente_id);
|
||||
$output = [
|
||||
'input' => $fuente_id,
|
||||
'fuente' => $fuente->toArray(),
|
||||
'eliminado' => $fuente->delete()
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function entradas(Request $request, Response $response, Factory $factory, $fuente_id): Response {
|
||||
$fuente = $factory->find(Fuente::class)->one($fuente_id);
|
||||
$entradas = null;
|
||||
if ($fuente !== null) {
|
||||
$entradas = $fuente->entradas();
|
||||
if ($entradas !== null) {
|
||||
array_walk($entradas, function(&$item) {
|
||||
$item = $item->toArray();
|
||||
});
|
||||
}
|
||||
}
|
||||
$output = [
|
||||
'input' => $fuente_id,
|
||||
'fuente' => $fuente?->toArray(),
|
||||
'entradas' => $entradas
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
}
|
89
api/common/Controller/TiposFuentes.php
Normal file
89
api/common/Controller/TiposFuentes.php
Normal file
@ -0,0 +1,89 @@
|
||||
<?php
|
||||
namespace Contabilidad\Common\Controller;
|
||||
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use ProVM\Common\Define\Controller\Json;
|
||||
use ProVM\Common\Factory\Model as Factory;
|
||||
use Contabilidad\TipoFuente;
|
||||
|
||||
class TiposFuentes {
|
||||
use Json;
|
||||
|
||||
public function __invoke(Request $request, Response $response, Factory $factory): Response {
|
||||
$tipos_fuentes = $factory->find(TipoFuente::class)->array();
|
||||
if ($tipos_fuentes) {
|
||||
usort($tipos_fuentes, function($a, $b) {
|
||||
return strcmp($a['descripcion'], $b['descripcion']);
|
||||
});
|
||||
}
|
||||
$output = [
|
||||
'tipos_fuentes' => $tipos_fuentes
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function show(Request $request, Response $response, Factory $factory, $tipo_fuente_id): Response {
|
||||
$tipo_fuente = $factory->find(TipoFuente::class)->one($tipo_fuente_id);
|
||||
$output = [
|
||||
'input' => $tipo_fuente_id,
|
||||
'tipo_fuente' => $tipo_fuente?->toArray()
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function add(Request $request, Response $response, Factory $factory): Response {
|
||||
$input = json_decode($request->getBody());
|
||||
$results = [];
|
||||
if (is_array($input)) {
|
||||
foreach ($input as $in) {
|
||||
$tipo_fuente = TipoFuente::add($factory, $in);
|
||||
$results []= ['tipo_fuente' => $tipo_fuente?->toArray(), 'agregado' => $tipo_fuente?->save()];
|
||||
}
|
||||
} else {
|
||||
$tipo_fuente = TipoFuente::add($factory, $input);
|
||||
$results []= ['tipo_fuente' => $tipo_fuente?->toArray(), 'agregado' => $tipo_fuente?->save()];
|
||||
}
|
||||
$output = [
|
||||
'input' => $input,
|
||||
'tipo_fuentes' => $results
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function edit(Request $request, Response $response, Factory $factory, $tipo_fuente_id): Response {
|
||||
$tipo_fuente = $factory->find(TipoFuente::class)->one($tipo_fuente_id);
|
||||
$output = [
|
||||
'input' => $tipo_fuente_id,
|
||||
'old' => $tipo_fuente->toArray()
|
||||
];
|
||||
$input = json_decode($request->getBody());
|
||||
$tipo_fuente->edit($input);
|
||||
$output['tipo_fuente'] = $tipo_fuente->toArray();
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function delete(Request $request, Response $response, Factory $factory, $tipo_fuente_id): Response {
|
||||
$tipo_fuente = $factory->find(TipoFuente::class)->one($tipo_fuente_id);
|
||||
$output = [
|
||||
'input' => $tipo_fuente_id,
|
||||
'tipo_fuente' => $tipo_fuente->toArray(),
|
||||
'eliminado' => $tipo_fuente->delete()
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function fuentes(Request $request, Response $response, Factory $factory, $tipo_fuente_id): Response {
|
||||
$tipo_fuente = $factory->find(TipoFuente::class)->one($tipo_fuente_id);
|
||||
$fuentes = null;
|
||||
if ($tipo_fuente !== null) {
|
||||
$fuentes = $tipo_fuente->fuentes();
|
||||
if ($fuentes !== null) {
|
||||
array_walk($fuentes, function(&$item) {
|
||||
$item = $item->toArray();
|
||||
});
|
||||
}
|
||||
}
|
||||
$output = [
|
||||
'input' => $tipo_fuente_id,
|
||||
'tipo_fuente' => $tipo_fuente?->toArray(),
|
||||
'fuentes' => $fuentes
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
}
|
21
api/common/Controller/Workers.php
Normal file
21
api/common/Controller/Workers.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
namespace Contabilidad\Common\Controller;
|
||||
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use ProVM\Common\Define\Controller\Json;
|
||||
use Contabilidad\Common\Service\WorkerHandler as Handler;
|
||||
|
||||
class Workers {
|
||||
use Json;
|
||||
|
||||
public function register(Request $request, Response $response, Handler $handler): Response {
|
||||
$post = $request->getBody();
|
||||
$result = $handler->register($post);
|
||||
$output = [
|
||||
'input' => $post,
|
||||
'result' => $result
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
}
|
44
api/composer.json
Normal file
44
api/composer.json
Normal file
@ -0,0 +1,44 @@
|
||||
{
|
||||
"name": "provm/contabilidad-api",
|
||||
"description": "API para contabilidad",
|
||||
"type": "project",
|
||||
"require": {
|
||||
"php-di/php-di": "^6.3",
|
||||
"php-di/slim-bridge": "^3.1",
|
||||
"nyholm/psr7": "^1.4",
|
||||
"nyholm/psr7-server": "^1.0",
|
||||
"zeuxisoo/slim-whoops": "^0.7.3",
|
||||
"provm/controller": "^1.0",
|
||||
"provm/models": "1.0.0-rc2",
|
||||
"nesbot/carbon": "^2.50"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^9.5",
|
||||
"kint-php/kint": "^3.3"
|
||||
},
|
||||
"authors": [
|
||||
{
|
||||
"name": "Aldarien",
|
||||
"email": "aldarien85@gmail.com"
|
||||
}
|
||||
],
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Contabilidad\\Common\\": "common",
|
||||
"Contabilidad\\": "src"
|
||||
}
|
||||
},
|
||||
"repositories": [
|
||||
{
|
||||
"type": "git",
|
||||
"url": "http://git.provm.cl/ProVM/controller.git"
|
||||
},
|
||||
{
|
||||
"type": "git",
|
||||
"url": "http://git.provm.cl/ProVM/models.git"
|
||||
}
|
||||
],
|
||||
"config": {
|
||||
"secure-http": false
|
||||
}
|
||||
}
|
22
api/nginx.conf
Normal file
22
api/nginx.conf
Normal file
@ -0,0 +1,22 @@
|
||||
server {
|
||||
listen 80;
|
||||
index index.php index.html index.htm;
|
||||
error_log /var/log/nginx/error.log;
|
||||
access_log /var/log/nginx/access.log;
|
||||
root /app/public;
|
||||
|
||||
location / {
|
||||
try_files $uri $uri/ /index.php?$query_string;
|
||||
}
|
||||
|
||||
location ~ \.php$ {
|
||||
try_files $uri =404;
|
||||
fastcgi_split_path_info ^(.+\.php)(/.+)$;
|
||||
fastcgi_pass api:9000;
|
||||
fastcgi_index index.php;
|
||||
include fastcgi_params;
|
||||
fastcgi_param REQUEST_URI $request_uri;
|
||||
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
|
||||
fastcgi_param PATH_INFO $fastcgi_path_info;
|
||||
}
|
||||
}
|
7
api/public/index.php
Normal file
7
api/public/index.php
Normal file
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
require_once implode(DIRECTORY_SEPARATOR, [
|
||||
dirname(__DIR__),
|
||||
'setup',
|
||||
'app.php'
|
||||
]);
|
||||
$app->run();
|
12
api/resources/routes/bancos.php
Normal file
12
api/resources/routes/bancos.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
use Contabilidad\Common\Controller\Bancos;
|
||||
|
||||
$app->group('/bancos', function($app) {
|
||||
$app->post('/add[/]', [Bancos::class, 'add']);
|
||||
$app->get('[/]', Bancos::class);
|
||||
});
|
||||
$app->group('/banco/{banco_id}', function($app) {
|
||||
$app->put('/edit', [Bancos::class, 'edit']);
|
||||
$app->delete('/delete', [Bancos::class, 'delete']);
|
||||
$app->get('[/]', [Bancos::class, 'show']);
|
||||
});
|
4
api/resources/routes/base.php
Normal file
4
api/resources/routes/base.php
Normal file
@ -0,0 +1,4 @@
|
||||
<?php
|
||||
use Contabilidad\Common\Controller\Base;
|
||||
|
||||
$app->get('/', Base::class);
|
13
api/resources/routes/categorias.php
Normal file
13
api/resources/routes/categorias.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
use Contabilidad\Common\Controller\Categorias;
|
||||
|
||||
$app->group('/categorias', function($app) {
|
||||
$app->post('/add[/]', [Categorias::class, 'add']);
|
||||
$app->get('[/]', Categorias::class);
|
||||
});
|
||||
$app->group('/categoria/{categoria_id}', function($app) {
|
||||
$app->get('/cuentas', [Categorias::class, 'cuentas']);
|
||||
$app->put('/edit', [Categorias::class, 'edit']);
|
||||
$app->delete('/delete', [Categorias::class, 'delete']);
|
||||
$app->get('[/]', [Categorias::class, 'show']);
|
||||
});
|
13
api/resources/routes/cuentas.php
Normal file
13
api/resources/routes/cuentas.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
use Contabilidad\Common\Controller\Cuentas;
|
||||
|
||||
$app->group('/cuentas', function($app) {
|
||||
$app->post('/add[/]', [Cuentas::class, 'add']);
|
||||
$app->get('[/]', Cuentas::class);
|
||||
});
|
||||
$app->group('/cuenta/{cuenta_id}', function($app) {
|
||||
$app->get('/entradas', [Cuentas::class, 'entradas']);
|
||||
$app->put('/edit', [Cuentas::class, 'edit']);
|
||||
$app->delete('/delete', [Cuentas::class, 'delete']);
|
||||
$app->get('[/]', [Cuentas::class, 'show']);
|
||||
});
|
12
api/resources/routes/entradas.php
Normal file
12
api/resources/routes/entradas.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
use Contabilidad\Common\Controller\Entradas;
|
||||
|
||||
$app->group('/entradas', function($app) {
|
||||
$app->post('/add[/]', [Entradas::class, 'add']);
|
||||
$app->get('[/]', Entradas::class);
|
||||
});
|
||||
$app->group('/entrada/{entrada_id}', function($app) {
|
||||
$app->put('/edit', [Entradas::class, 'edit']);
|
||||
$app->delete('/delete', [Entradas::class, 'delete']);
|
||||
$app->get('[/]', [Entradas::class, 'show']);
|
||||
});
|
13
api/resources/routes/fuentes.php
Normal file
13
api/resources/routes/fuentes.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
use Contabilidad\Common\Controller\Fuentes;
|
||||
|
||||
$app->group('/fuentes', function($app) {
|
||||
$app->post('/add[/]', [Fuentes::class, 'add']);
|
||||
$app->get('[/]', Fuentes::class);
|
||||
});
|
||||
$app->group('/fuente/{fuente_id}', function($app) {
|
||||
$app->get('/entradas', [Fuentes::class, 'entradas']);
|
||||
$app->put('/edit', [Fuentes::class, 'edit']);
|
||||
$app->delete('/delete', [Fuentes::class, 'delete']);
|
||||
$app->get('[/]', [Fuentes::class, 'show']);
|
||||
});
|
13
api/resources/routes/tipos_fuentes.php
Normal file
13
api/resources/routes/tipos_fuentes.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
use Contabilidad\Common\Controller\TiposFuentes;
|
||||
|
||||
$app->group('/tipos_fuentes', function($app) {
|
||||
$app->post('/add[/]', [TiposFuentes::class, 'add']);
|
||||
$app->get('[/]', TiposFuentes::class);
|
||||
});
|
||||
$app->group('/tipo_fuente/{tipo_fuente_id}', function($app) {
|
||||
$app->get('/fuentes', [TiposFuentes::class, 'fuentes']);
|
||||
$app->put('/edit', [TiposFuentes::class, 'edit']);
|
||||
$app->delete('/delete', [TiposFuentes::class, 'delete']);
|
||||
$app->get('[/]', [TiposFuentes::class, 'show']);
|
||||
});
|
6
api/resources/routes/workers.php
Normal file
6
api/resources/routes/workers.php
Normal file
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
use Contabilidad\Common\Controller\Workers;
|
||||
|
||||
$app->group('/workers', function($app) {
|
||||
$app->post('/register', [Workers::class, 'register']);
|
||||
});
|
46
api/setup/app.php
Normal file
46
api/setup/app.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
use DI\ContainerBuilder as Builder;
|
||||
use DI\Bridge\Slim\Bridge as Bridge;
|
||||
use Zeuxisoo\Whoops\Slim\WhoopsMiddleware;
|
||||
|
||||
include_once 'composer.php';
|
||||
|
||||
$builder = new Builder();
|
||||
$folders = [
|
||||
'settings',
|
||||
'setups'
|
||||
];
|
||||
foreach ($folders as $f) {
|
||||
$folder = implode(DIRECTORY_SEPARATOR, [__DIR__, $f]);
|
||||
if (!file_exists($folder)) {
|
||||
continue;
|
||||
}
|
||||
$files = new DirectoryIterator($folder);
|
||||
foreach ($files as $file) {
|
||||
if ($file->isDir()) {
|
||||
continue;
|
||||
}
|
||||
$builder->addDefinitions($file->getRealPath());
|
||||
}
|
||||
}
|
||||
|
||||
$container = $builder->build();
|
||||
$app = Bridge::create($container);
|
||||
|
||||
$app->addRoutingMiddleware();
|
||||
$app->add(new WhoopsMiddleware());
|
||||
|
||||
|
||||
$folder = 'middlewares';
|
||||
if (file_exists($folder)) {
|
||||
$files = new DirectoryIterator($folder);
|
||||
foreach ($files as $file) {
|
||||
if ($file->isDir() or $file->getExtension() != 'php') {
|
||||
continue;
|
||||
}
|
||||
include_once $file->getRealPath();
|
||||
}
|
||||
}
|
||||
|
||||
include_once 'databases.php';
|
||||
include_once 'router.php';
|
6
api/setup/composer.php
Normal file
6
api/setup/composer.php
Normal file
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
require_once implode(DIRECTORY_SEPARATOR, [
|
||||
dirname(__DIR__),
|
||||
'vendor',
|
||||
'autoload.php'
|
||||
]);
|
37
api/setup/databases.php
Normal file
37
api/setup/databases.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
$databases = $app->getContainer()->get('databases');
|
||||
|
||||
foreach ($databases->databases as $name => $settings) {
|
||||
if (!is_object($settings)) {
|
||||
continue;
|
||||
}
|
||||
$auth = false;
|
||||
$dsn = '';
|
||||
switch (strtolower($settings->type)) {
|
||||
case 'mysql':
|
||||
$data = [
|
||||
['host', $settings->host->name],
|
||||
['dbname', $settings->name]
|
||||
];
|
||||
if (isset($settings->host->port)) {
|
||||
$data []= ['port', $settings->host->port];
|
||||
}
|
||||
array_walk($data, function(&$item) {
|
||||
$item = implode('=', $item);
|
||||
});
|
||||
$dsn = implode(':', [
|
||||
'mysql',
|
||||
implode(';', $data)
|
||||
]);
|
||||
$auth = true;
|
||||
break;
|
||||
}
|
||||
ORM::configure($dsn, null, $name);
|
||||
if ($auth) {
|
||||
ORM::configure('username', $settings->user->name, $name);
|
||||
ORM::configure('password', $settings->user->password, $name);
|
||||
}
|
||||
}
|
||||
if (isset($databases->short_names) and $databases->short_names) {
|
||||
Model::$short_table_names = true;
|
||||
}
|
9
api/setup/router.php
Normal file
9
api/setup/router.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
$folder = $app->getContainer()->get('folders')->routes;
|
||||
$files = new DirectoryIterator($folder);
|
||||
foreach ($files as $file) {
|
||||
if ($file->isDir() or $file->getExtension() != 'php') {
|
||||
continue;
|
||||
}
|
||||
include_once $file->getRealPath();
|
||||
}
|
4
api/setup/settings/01_env.php
Normal file
4
api/setup/settings/01_env.php
Normal file
@ -0,0 +1,4 @@
|
||||
<?php
|
||||
return [
|
||||
'debug' => $_ENV['DEBUG'] ?? false
|
||||
];
|
19
api/setup/settings/02_common.php
Normal file
19
api/setup/settings/02_common.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
use Psr\Container\ContainerInterface as Container;
|
||||
|
||||
return [
|
||||
'folders' => function(Container $c) {
|
||||
$arr = [
|
||||
'base' => dirname(__DIR__, 2)
|
||||
];
|
||||
$arr['resources'] = implode(DIRECTORY_SEPARATOR, [
|
||||
$arr['base'],
|
||||
'resources'
|
||||
]);
|
||||
$arr['routes'] = implode(DIRECTORY_SEPARATOR, [
|
||||
$arr['resources'],
|
||||
'routes'
|
||||
]);
|
||||
return (object) $arr;
|
||||
}
|
||||
];
|
28
api/setup/settings/03_database.php
Normal file
28
api/setup/settings/03_database.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
return [
|
||||
'databases' => function() {
|
||||
$arr = [
|
||||
ORM::DEFAULT_CONNECTION => [
|
||||
'type' => 'mysql',
|
||||
'host' => [
|
||||
'name' => $_ENV['MYSQL_HOST'] ?? 'db'
|
||||
],
|
||||
'user' => [
|
||||
'name' => $_ENV['MYSQL_USER'],
|
||||
'password' => $_ENV['MYSQL_PASSWORD']
|
||||
],
|
||||
'name' => $_ENV['MYSQL_DATABASE']
|
||||
]
|
||||
];
|
||||
function toObj($arr) {
|
||||
$obj = (object) $arr;
|
||||
foreach ($arr as $k => $v) {
|
||||
if (is_array($v)) {
|
||||
$obj->{$k} = toObj($v);
|
||||
}
|
||||
}
|
||||
return $obj;
|
||||
}
|
||||
return (object) ['databases' => toObj($arr), 'short_names' => true];
|
||||
}
|
||||
];
|
13
api/src/Banco.php
Normal file
13
api/src/Banco.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
namespace Contabilidad;
|
||||
|
||||
use ProVM\Common\Alias\Model;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property string $nombre
|
||||
*/
|
||||
class Banco extends Model {
|
||||
public static $_table = 'bancos';
|
||||
protected static $fields = ['nombre'];
|
||||
}
|
21
api/src/Categoria.php
Normal file
21
api/src/Categoria.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
namespace Contabilidad;
|
||||
|
||||
use ProVM\Common\Alias\Model;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property string $nombre
|
||||
*/
|
||||
class Categoria extends Model {
|
||||
public static $_table = 'categorias';
|
||||
protected static $fields = ['nombre'];
|
||||
|
||||
protected $cuentas;
|
||||
public function cuentas() {
|
||||
if ($this->cuentas === null) {
|
||||
$this->cuentas = $this->parentOf(Cuenta::class, [Model::CHILD_KEY => 'categoria_id']);
|
||||
}
|
||||
return $this->cuentas;
|
||||
}
|
||||
}
|
36
api/src/Cuenta.php
Normal file
36
api/src/Cuenta.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
namespace Contabilidad;
|
||||
|
||||
use ProVM\Common\Alias\Model;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property string $nombre
|
||||
* @property Categoria $categoria_id
|
||||
*/
|
||||
class Cuenta extends Model {
|
||||
public static $_table = 'cuentas';
|
||||
protected static $fields = ['nombre', 'categoria_id'];
|
||||
|
||||
protected $categoria;
|
||||
public function categoria() {
|
||||
if ($this->categoria === null) {
|
||||
$this->categoria = $this->childOf(Categoria::class, [Model::SELF_KEY => 'categoria_id']);
|
||||
}
|
||||
return $this->categoria;
|
||||
}
|
||||
|
||||
protected $entradas;
|
||||
public function entradas() {
|
||||
if ($this->entradas === null) {
|
||||
$this->entradas = $this->parentOf(Entrada::class, [Model::CHILD_KEY => 'cuenta_id']);
|
||||
}
|
||||
return $this->entradas;
|
||||
}
|
||||
|
||||
public function toArray(): array {
|
||||
$arr = parent::toArray();
|
||||
$arr['categoria'] = $this->categoria()->toArray();
|
||||
return $arr;
|
||||
}
|
||||
}
|
38
api/src/Entrada.php
Normal file
38
api/src/Entrada.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
namespace Contabilidad;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use ProVM\Common\Alias\Model;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property \DateTime $fecha
|
||||
* @property Fuente $fuente_id
|
||||
* @property Cuenta $cuenta_id
|
||||
* @property double $valor
|
||||
*/
|
||||
class Entrada extends Model {
|
||||
public static $_table = 'entradas';
|
||||
protected static $fields = ['fecha', 'fuente_id', 'cuenta_id', 'value'];
|
||||
|
||||
protected $fuente;
|
||||
public function fuente() {
|
||||
if ($this->fuente === null) {
|
||||
$this->fuente = $this->childOf(Fuente::class, [Model::SELF_KEY => 'fuente_id']);
|
||||
}
|
||||
return $this->fuente;
|
||||
}
|
||||
protected $cuenta;
|
||||
public function cuenta() {
|
||||
if ($this->cuenta === null) {
|
||||
$this->cuenta = $this->childOf(Cuente::class, [Model::SELF_KEY => 'cuenta_id']);
|
||||
}
|
||||
return $this->cuenta;
|
||||
}
|
||||
public function fecha(\DateTime $fecha = null) {
|
||||
if ($fecha === null) {
|
||||
return Carbon::parse($this->fecha);
|
||||
}
|
||||
$this->fecha = $fecha->format('Y-m-d');
|
||||
}
|
||||
}
|
44
api/src/Fuente.php
Normal file
44
api/src/Fuente.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
namespace Contabilidad;
|
||||
|
||||
use ProVM\Common\Alias\Model;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property TipoFuente $tipo_id
|
||||
* @property Banco $banco_id
|
||||
*/
|
||||
class Fuente extends Model {
|
||||
public static $_table = 'fuentes';
|
||||
protected static $fields = ['tipo_id', 'banco_id'];
|
||||
|
||||
protected $tipo;
|
||||
public function tipo() {
|
||||
if ($this->tipo === null) {
|
||||
$this->tipo = $this->childOf(TipoFuente::class, [Model::SELF_KEY => 'tipo_id']);
|
||||
}
|
||||
return $this->tipo;
|
||||
}
|
||||
protected $banco;
|
||||
public function banco() {
|
||||
if ($this->banco === null) {
|
||||
$this->banco = $this->childOf(Banco::class, [Model::SELF_KEY => 'banco_id']);
|
||||
}
|
||||
return $this->banco;
|
||||
}
|
||||
|
||||
protected $entradas;
|
||||
public function entradas() {
|
||||
if ($this->entradas === null) {
|
||||
$this->entradas = $this->parentOf(Entrada::class, [Model::CHILD_KEY => 'fuente_id']);
|
||||
}
|
||||
return $this->entradas;
|
||||
}
|
||||
|
||||
public function toArray(): array {
|
||||
$arr = parent::toArray();
|
||||
$arr['tipo'] = $this->tipo()->toArray();
|
||||
$arr['banco'] = $this->banco()->toArray();
|
||||
return $arr;
|
||||
}
|
||||
}
|
21
api/src/TipoFuente.php
Normal file
21
api/src/TipoFuente.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
namespace Contabilidad;
|
||||
|
||||
use ProVM\Common\Alias\Model;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property string $descripcion
|
||||
*/
|
||||
class TipoFuente extends Model {
|
||||
public static $_table = 'tipos_fuente';
|
||||
protected static $fields = ['descripcion'];
|
||||
|
||||
protected $fuentes;
|
||||
public function fuentes() {
|
||||
if ($this->fuentes === null) {
|
||||
$this->fuentes = $this->parentOf(Fuente::class, [Model::CHILD_KEY => 'tipo_id']);
|
||||
}
|
||||
return $this->fuentes;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user