API 1.0.0-rc
This commit is contained in:
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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user