Simplificacion a contabilidad clasica
This commit is contained in:
@ -1,71 +0,0 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
@ -90,4 +90,38 @@ class Cuentas {
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function transacciones(Request $request, Response $response, Factory $factory, $cuenta_id): Response {
|
||||
$cuenta = $factory->find(Cuenta::class)->one($cuenta_id);
|
||||
$cargos = null;
|
||||
$abonos = null;
|
||||
$transacciones = null;
|
||||
if ($cuenta !== null) {
|
||||
$cargos = $cuenta->cargos();
|
||||
if ($cargos !== null) {
|
||||
array_walk($cargos, function(&$item) {
|
||||
$item = $item->toArray();
|
||||
});
|
||||
}
|
||||
$abonos = $cuenta->abonos();
|
||||
if ($abonos !== null) {
|
||||
array_walk($abonos, function(&$item) {
|
||||
$item = $item->toArray();
|
||||
});
|
||||
}
|
||||
$transacciones = $cuenta->transacciones();
|
||||
if (count($transacciones)) {
|
||||
array_walk($transacciones, function(&$item) {
|
||||
$item = $item->toArray();
|
||||
});
|
||||
}
|
||||
}
|
||||
$output = [
|
||||
'input' => $cuenta_id,
|
||||
'cuenta' => $cuenta?->toArray(),
|
||||
'cargos' => $cargos,
|
||||
'abonos' => $abonos,
|
||||
'transacciones' => $transacciones
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
}
|
||||
|
@ -1,91 +0,0 @@
|
||||
<?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) {
|
||||
usort($entradas, function($a, $b) {
|
||||
$d = $a->fecha()->diffInDays($b->fecha(), false);
|
||||
if ($d === 0) {
|
||||
return strcmp($a->cuenta()->nombre, $b->cuenta()->nombre);
|
||||
}
|
||||
return $d;
|
||||
});
|
||||
array_walk($entradas, function(&$item) {
|
||||
$item = $item->toArray();
|
||||
});
|
||||
}
|
||||
}
|
||||
$output = [
|
||||
'input' => $fuente_id,
|
||||
'fuente' => $fuente?->toArray(),
|
||||
'entradas' => $entradas
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
}
|
@ -1,89 +0,0 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
@ -5,15 +5,15 @@ 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;
|
||||
use Contabilidad\Transaccion;
|
||||
|
||||
class Entradas {
|
||||
class Transacciones {
|
||||
use Json;
|
||||
|
||||
public function __invoke(Request $request, Response $response, Factory $factory): Response {
|
||||
$entradas = $factory->find(Entrada::class)->array();
|
||||
if ($entradas !== null) {
|
||||
usort($entradas, function($a, $b) {
|
||||
$transacciones = $factory->find(Transaccion::class)->array();
|
||||
if ($transacciones !== null) {
|
||||
usort($transacciones, function($a, $b) {
|
||||
$d = $a['fecha'] - $b['fecha'];
|
||||
if ($d === 0) {
|
||||
return strcmp($a['cuenta']['nombre'], $b['cuenta']['nombre']);
|
||||
@ -22,15 +22,15 @@ class Entradas {
|
||||
});
|
||||
}
|
||||
$output = [
|
||||
'entradas' => $entradas
|
||||
'transacciones' => $transacciones
|
||||
];
|
||||
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);
|
||||
public function show(Request $request, Response $response, Factory $factory, $transaccion_id): Response {
|
||||
$transaccion = $factory->find(Transaccion::class)->one($transaccion_id);
|
||||
$output = [
|
||||
'input' => $entrada_id,
|
||||
'entrada' => $entrada?->toArray()
|
||||
'input' => $transaccion_id,
|
||||
'transaccion' => $transaccion?->toArray()
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
@ -39,36 +39,36 @@ class Entradas {
|
||||
$results = [];
|
||||
if (is_array($input)) {
|
||||
foreach ($input as $in) {
|
||||
$entrada = Entrada::add($factory, $in);
|
||||
$results []= ['entrada' => $entrada?->toArray(), 'agregado' => $entrada?->save()];
|
||||
$transaccion = Transaccion::add($factory, $in);
|
||||
$results []= ['transaccion' => $transaccion?->toArray(), 'agregado' => $transaccion?->save()];
|
||||
}
|
||||
} else {
|
||||
$entrada = Entrada::add($factory, $input);
|
||||
$results []= ['entrada' => $entrada?->toArray(), 'agregado' => $entrada?->save()];
|
||||
$transaccion = Transaccion::add($factory, $input);
|
||||
$results []= ['transaccion' => $transaccion?->toArray(), 'agregado' => $transaccion?->save()];
|
||||
}
|
||||
$output = [
|
||||
'input' => $input,
|
||||
'entradas' => $results
|
||||
'transacciones' => $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);
|
||||
public function edit(Request $request, Response $response, Factory $factory, $transaccion_id): Response {
|
||||
$transaccion = $factory->find(Transaccion::class)->one($transaccion_id);
|
||||
$output = [
|
||||
'input' => $entrada_id,
|
||||
'old' => $entrada->toArray()
|
||||
'input' => $transaccion_id,
|
||||
'old' => $transaccion->toArray()
|
||||
];
|
||||
$input = json_decode($request->getBody());
|
||||
$entrada->edit($input);
|
||||
$output['entrada'] = $entrada->toArray();
|
||||
$transaccion->edit($input);
|
||||
$output['transaccion'] = $transaccion->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);
|
||||
public function delete(Request $request, Response $response, Factory $factory, $transaccion_id): Response {
|
||||
$transaccion = $factory->find(Transaccion::class)->one($transaccion_id);
|
||||
$output = [
|
||||
'input' => $entrada_id,
|
||||
'entrada' => $entrada->toArray(),
|
||||
'eliminado' => $entrada->delete()
|
||||
'input' => $transaccion_id,
|
||||
'transaccion' => $transaccion->toArray(),
|
||||
'eliminado' => $transaccion->delete()
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
Reference in New Issue
Block a user