Compare commits
6 Commits
6c4e51bfff
...
release
Author | SHA1 | Date | |
---|---|---|---|
459a95bf12 | |||
06071884c7 | |||
ca8229abee | |||
6ff584013f | |||
cf27465d75 | |||
560fb356fa |
@ -1,11 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Contabilidad\Common\Controller;
|
namespace Contabilidad\Common\Controller;
|
||||||
|
|
||||||
|
use Carbon\Carbon;
|
||||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||||
use Psr\Http\Message\ResponseInterface as Response;
|
use Psr\Http\Message\ResponseInterface as Response;
|
||||||
use ProVM\Common\Factory\Model as Factory;
|
use ProVM\Common\Factory\Model as Factory;
|
||||||
use ProVM\Common\Define\Controller\Json;
|
use ProVM\Common\Define\Controller\Json;
|
||||||
use Contabilidad\Common\Service\Consolidar as Service;
|
use Contabilidad\Common\Service\Consolidar as Service;
|
||||||
|
use Contabilidad\Cuenta;
|
||||||
use Contabilidad\Consolidado;
|
use Contabilidad\Consolidado;
|
||||||
|
|
||||||
class Consolidados {
|
class Consolidados {
|
||||||
@ -50,4 +52,15 @@ class Consolidados {
|
|||||||
}
|
}
|
||||||
return $this->withJson($response, []);
|
return $this->withJson($response, []);
|
||||||
}
|
}
|
||||||
|
public function update(Request $request, Response $response, Factory $factory, Service $service, $mes, $cuenta_id): Response {
|
||||||
|
try {
|
||||||
|
$cuenta = $factory->find(Cuenta::class)->one($cuenta_id);
|
||||||
|
$mes = Carbon::parse($mes);
|
||||||
|
$service->consolidarCuenta($cuenta, $mes);
|
||||||
|
} catch (\Error | \Exception $e) {
|
||||||
|
error_log($e);
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
return $this->withJson($response, []);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,24 +5,28 @@ use Psr\Http\Message\ServerRequestInterface as Request;
|
|||||||
use Psr\Http\Message\ResponseInterface as Response;
|
use Psr\Http\Message\ResponseInterface as Response;
|
||||||
use ProVM\Common\Define\Controller\Json;
|
use ProVM\Common\Define\Controller\Json;
|
||||||
use ProVM\Common\Factory\Model as Factory;
|
use ProVM\Common\Factory\Model as Factory;
|
||||||
|
use Contabilidad\Common\Service\Queuer as Service;
|
||||||
use Contabilidad\Transaccion;
|
use Contabilidad\Transaccion;
|
||||||
|
|
||||||
class Transacciones {
|
class Transacciones {
|
||||||
use Json;
|
use Json;
|
||||||
|
|
||||||
|
protected function parseTransacciones(?array $transacciones): ?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']);
|
||||||
|
}
|
||||||
|
return $d;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return $transacciones;
|
||||||
|
}
|
||||||
public function __invoke(Request $request, Response $response, Factory $factory): Response {
|
public function __invoke(Request $request, Response $response, Factory $factory): Response {
|
||||||
$transacciones = $factory->find(Transaccion::class)->array();
|
$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']);
|
|
||||||
}
|
|
||||||
return $d;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
$output = [
|
$output = [
|
||||||
'transacciones' => $transacciones
|
'transacciones' => $this->parseTransacciones($transacciones)
|
||||||
];
|
];
|
||||||
return $this->withJson($response, $output);
|
return $this->withJson($response, $output);
|
||||||
}
|
}
|
||||||
@ -52,17 +56,33 @@ class Transacciones {
|
|||||||
];
|
];
|
||||||
return $this->withJson($response, $output);
|
return $this->withJson($response, $output);
|
||||||
}
|
}
|
||||||
public function edit(Request $request, Response $response, Factory $factory, $transaccion_id): Response {
|
public function edit(Request $request, Response $response, Factory $factory, Service $queuer, $transaccion_id): Response {
|
||||||
$transaccion = $factory->find(Transaccion::class)->one($transaccion_id);
|
$transaccion = $factory->find(Transaccion::class)->one($transaccion_id);
|
||||||
$output = [
|
$output = [
|
||||||
'input' => $transaccion_id,
|
'input' => $transaccion_id,
|
||||||
'old' => $transaccion->toArray()
|
'old' => $transaccion->toArray()
|
||||||
];
|
];
|
||||||
|
$old_cuentas = ['credito' => $transaccion->credito_id, 'debito_id' => $transaccion->debito_id];
|
||||||
$input = json_decode($request->getBody());
|
$input = json_decode($request->getBody());
|
||||||
$transaccion->edit($input);
|
$transaccion->edit($input);
|
||||||
|
$new_cuentas = ['credito' => $transaccion->credito_id, 'debito_id' => $transaccion->debito_id];
|
||||||
|
$cuentas = [];
|
||||||
|
foreach ($new_cuentas as $tipo => $id) {
|
||||||
|
if ($old_cuentas[$tipo] != $id) {
|
||||||
|
$cuentas []= $old_cuentas[$tipo];
|
||||||
|
$cuentas []= $id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->updateConsolidar($queuer, $transaccion->fecha(), $cuentas);
|
||||||
|
|
||||||
$output['transaccion'] = $transaccion->toArray();
|
$output['transaccion'] = $transaccion->toArray();
|
||||||
return $this->withJson($response, $output);
|
return $this->withJson($response, $output);
|
||||||
}
|
}
|
||||||
|
protected function updateConsolidar(Service $queuer, \DateTimeInterface $mes, $cuentas) {
|
||||||
|
foreach ($cuentas as $cuenta_id) {
|
||||||
|
$queuer->queue('update_consolidar', ['mes' => $mes->format('Y-m-1'), 'cuenta' => $cuenta_id]);
|
||||||
|
}
|
||||||
|
}
|
||||||
public function delete(Request $request, Response $response, Factory $factory, $transaccion_id): Response {
|
public function delete(Request $request, Response $response, Factory $factory, $transaccion_id): Response {
|
||||||
$transaccion = $factory->find(Transaccion::class)->one($transaccion_id);
|
$transaccion = $factory->find(Transaccion::class)->one($transaccion_id);
|
||||||
$output = [
|
$output = [
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
namespace Contabilidad\Common\Service;
|
namespace Contabilidad\Common\Service;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Contabilidad\Queue;
|
|
||||||
use \Model;
|
use \Model;
|
||||||
use ProVM\Common\Factory\Model as ModelFactory;
|
use ProVM\Common\Factory\Model as ModelFactory;
|
||||||
use Contabilidad\Consolidado;
|
use Contabilidad\Consolidado;
|
||||||
@ -10,9 +9,19 @@ use Contabilidad\Cuenta;
|
|||||||
use Contabilidad\Transaccion;
|
use Contabilidad\Transaccion;
|
||||||
|
|
||||||
class Consolidar {
|
class Consolidar {
|
||||||
protected $factory;
|
public function __construct(ModelFactory $factory, Queuer $queuer) {
|
||||||
public function __construct(ModelFactory $factory) {
|
$this->setFactory($factory);
|
||||||
|
$this->setQueuer($queuer);
|
||||||
|
}
|
||||||
|
protected ModelFactory $factory;
|
||||||
|
public function setFactory(ModelFactory $factory): Consolidar {
|
||||||
$this->factory = $factory;
|
$this->factory = $factory;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
protected Queuer $queuer;
|
||||||
|
public function setQueuer(Queuer $queuer): Consolidar {
|
||||||
|
$this->queuer = $queuer;
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
protected $cuentas;
|
protected $cuentas;
|
||||||
public function getCuentas() {
|
public function getCuentas() {
|
||||||
@ -40,12 +49,7 @@ class Consolidar {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
public function queue() {
|
public function queue() {
|
||||||
$data = [
|
$this->queuer->queue('consolidar');
|
||||||
'command' => 'consolidar',
|
|
||||||
'created' => Carbon::now()->format('Y-m-d H:i:s')
|
|
||||||
];
|
|
||||||
$queue = Queue::add($this->factory, $data);
|
|
||||||
$queue->save();
|
|
||||||
}
|
}
|
||||||
public function consolidar() {
|
public function consolidar() {
|
||||||
ini_set('max_execution_time', 60*5);
|
ini_set('max_execution_time', 60*5);
|
||||||
@ -57,29 +61,40 @@ class Consolidar {
|
|||||||
$first = $this->getFirst($cuenta);
|
$first = $this->getFirst($cuenta);
|
||||||
$last = $this->getLast($cuenta);
|
$last = $this->getLast($cuenta);
|
||||||
for ($current = $first->copy()->startOfMonth(); $current < $last->copy()->addMonthWithoutOverflow()->endOfMonth(); $current = $current->copy()->addMonthWithoutOverflow()) {
|
for ($current = $first->copy()->startOfMonth(); $current < $last->copy()->addMonthWithoutOverflow()->endOfMonth(); $current = $current->copy()->addMonthWithoutOverflow()) {
|
||||||
$transacciones = $this->getTransacciones($cuenta, $current);
|
$this->consolidarCuenta($cuenta, $current);
|
||||||
if (count($transacciones) == 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$f = $this->factory;
|
|
||||||
array_walk($transacciones, function(&$item) use ($cuenta, $f) {
|
|
||||||
$item->setFactory($f);
|
|
||||||
$item->valor = $item->transformar($cuenta->moneda());
|
|
||||||
});
|
|
||||||
$saldo = array_reduce($transacciones, function($sum, $item) {
|
|
||||||
return $sum + $item->valor;
|
|
||||||
});
|
|
||||||
$data = [
|
|
||||||
'cuenta_id' => $cuenta->id,
|
|
||||||
'fecha' => $current->format('Y-m-1'),
|
|
||||||
'periodo' => 'P1M',
|
|
||||||
'saldo' => $saldo
|
|
||||||
];
|
|
||||||
$consolidado = $this->factory->create(Consolidado::class, $data);
|
|
||||||
$consolidado->save();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public function consolidarCuenta(Cuenta $cuenta, Carbon $mes) {
|
||||||
|
if (!$cuenta->hasTransacciones($mes)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$transacciones = $this->getTransacciones($cuenta, $mes);
|
||||||
|
if (count($transacciones) == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
array_walk($transacciones, function(&$item) use ($cuenta) {
|
||||||
|
$item->valor = $item->transformar($cuenta->moneda());
|
||||||
|
});
|
||||||
|
$saldo = array_reduce($transacciones, function($sum, $item) {
|
||||||
|
return $sum + $item->valor;
|
||||||
|
});
|
||||||
|
if ($cuenta->tipo()->cargo()) {
|
||||||
|
$saldo += -1;
|
||||||
|
}
|
||||||
|
$consolidado = $this->factory->find(Consolidado::class)->where([['cuenta_id', $cuenta->id], ['fecha', $mes->format('Y-m-1')]])->one();
|
||||||
|
if ($consolidado === null) {
|
||||||
|
$data = [
|
||||||
|
'cuenta_id' => $cuenta->id,
|
||||||
|
'fecha' => $mes->format('Y-m-1'),
|
||||||
|
'periodo' => 'P1M',
|
||||||
|
'saldo' => $saldo
|
||||||
|
];
|
||||||
|
$consolidado = $this->factory->create(Consolidado::class, $data);
|
||||||
|
}
|
||||||
|
$consolidado->saldo = $saldo;
|
||||||
|
$consolidado->save();
|
||||||
|
}
|
||||||
public function getFirst(Cuenta $cuenta): ?Carbon {
|
public function getFirst(Cuenta $cuenta): ?Carbon {
|
||||||
$first = [
|
$first = [
|
||||||
Model::factory(Transaccion::class)
|
Model::factory(Transaccion::class)
|
||||||
@ -150,6 +165,10 @@ class Consolidar {
|
|||||||
->whereEqual('credito_id', $cuenta->id)
|
->whereEqual('credito_id', $cuenta->id)
|
||||||
->whereRaw("fecha BETWEEN '{$start->format('Y-m-d')}' AND '{$end->format('Y-m-d')}'")
|
->whereRaw("fecha BETWEEN '{$start->format('Y-m-d')}' AND '{$end->format('Y-m-d')}'")
|
||||||
->findMany();
|
->findMany();
|
||||||
return array_merge($debitos, $creditos);
|
$transacciones = array_merge($debitos, $creditos);
|
||||||
|
foreach ($transacciones as &$transaccion) {
|
||||||
|
$transaccion->setFactory($this->factory);
|
||||||
|
}
|
||||||
|
return $transacciones;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
47
api/common/Service/Queuer.php
Normal file
47
api/common/Service/Queuer.php
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
namespace Contabilidad\Common\Service;
|
||||||
|
|
||||||
|
use ProVM\Common\Factory\Model as Factory;
|
||||||
|
use Contabilidad\Queue;
|
||||||
|
use Contabilidad\QueueArgument;
|
||||||
|
|
||||||
|
class Queuer {
|
||||||
|
protected Factory $factory;
|
||||||
|
public function __construct(Factory $factory) {
|
||||||
|
$this->setFactory($factory);
|
||||||
|
}
|
||||||
|
public function setFactory(Factory $factory): Queuer {
|
||||||
|
$this->factory = $factory;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
public function queue(string $command, array $arguments = []) {
|
||||||
|
if ($this->isProcessed($command, $arguments)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$queue = $this->factory->create(Queue::class, ['command' => $command, 'created' => (new \DateTime('now'))->format('Y-m-d H:i:s')]);
|
||||||
|
$queue->save();
|
||||||
|
if (count($arguments) > 0) {
|
||||||
|
foreach ($arguments as $argument => $value) {
|
||||||
|
$arg = $this->factory->create(QueueArgument::class, ['queue_id' => $queue->id, 'argument' => $argument, 'value' => $value]);
|
||||||
|
$arg->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public function isProcessed(string $command, array $arguments = []): bool {
|
||||||
|
$queues = $this->find($command, $arguments);
|
||||||
|
if ($queues == null or count($queues) === 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public function find(string $command, array $arguments = []): ?array {
|
||||||
|
$queues = $this->factory->find(Queue::class)->where([['command', $command], ['processed', 0]])->many();
|
||||||
|
if ($queues === null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (count($arguments) > 0) {
|
||||||
|
$queues = array_filter($queues, function($item) use ($arguments) {return count($arguments) === count($item->matchArguments($arguments));});
|
||||||
|
}
|
||||||
|
return $queues;
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
try {
|
try {
|
||||||
require_once implode(DIRECTORY_SEPARATOR, [
|
ini_set('error_reporting', E_ALL & ~E_NOTICE & ~E_DEPRECATED);
|
||||||
|
$app = require_once implode(DIRECTORY_SEPARATOR, [
|
||||||
dirname(__DIR__),
|
dirname(__DIR__),
|
||||||
'setup',
|
'setup',
|
||||||
'app.php'
|
'app.php'
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
use Contabilidad\Common\Controller\Consolidados;
|
use Contabilidad\Common\Controller\Consolidados;
|
||||||
|
|
||||||
$app->get('/consolidar', [Consolidados::class, 'cli']);
|
$app->group('/consolidar', function($app) {
|
||||||
|
$app->get('/update/{mes}/{cuenta_id}', [Consolidados::class, 'update']);
|
||||||
|
$app->get('[/]', [Consolidados::class, 'cli']);
|
||||||
|
});
|
||||||
|
@ -2,11 +2,11 @@
|
|||||||
use Contabilidad\Common\Controller\Transacciones;
|
use Contabilidad\Common\Controller\Transacciones;
|
||||||
|
|
||||||
$app->group('/transacciones', function($app) {
|
$app->group('/transacciones', function($app) {
|
||||||
$app->post('/add[/]', [Transacciones::class, 'add']);
|
$app->post('/add[/]', [Transacciones::class, 'add']);
|
||||||
$app->get('[/]', Transacciones::class);
|
$app->get('[/]', Transacciones::class);
|
||||||
});
|
});
|
||||||
$app->group('/transaccion/{transaccion_id}', function($app) {
|
$app->group('/transaccion/{transaccion_id}', function($app) {
|
||||||
$app->put('/edit', [Transacciones::class, 'edit']);
|
$app->put('/edit', [Transacciones::class, 'edit']);
|
||||||
$app->delete('/delete', [Transacciones::class, 'delete']);
|
$app->delete('/delete', [Transacciones::class, 'delete']);
|
||||||
$app->get('[/]', [Transacciones::class, 'show']);
|
$app->get('[/]', [Transacciones::class, 'show']);
|
||||||
});
|
});
|
||||||
|
@ -44,3 +44,5 @@ if (file_exists($folder)) {
|
|||||||
|
|
||||||
include_once 'databases.php';
|
include_once 'databases.php';
|
||||||
include_once 'router.php';
|
include_once 'router.php';
|
||||||
|
|
||||||
|
return $app;
|
||||||
|
@ -2,7 +2,10 @@
|
|||||||
use Psr\Container\ContainerInterface as Container;
|
use Psr\Container\ContainerInterface as Container;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
\Contabilidad\Common\Service\Queuer::class => function(Container $container) {
|
||||||
|
return new \Contabilidad\Common\Service\Queuer($container->get(\ProVM\Common\Factory\Model::class));
|
||||||
|
},
|
||||||
\Contabilidad\Common\Service\Consolidar::class => function(Container $container) {
|
\Contabilidad\Common\Service\Consolidar::class => function(Container $container) {
|
||||||
return new \Contabilidad\Common\Service\Consolidar($container->get(\ProVM\Common\Factory\Model::class));
|
return new \Contabilidad\Common\Service\Consolidar($container->get(\ProVM\Common\Factory\Model::class), $container->get(\Contabilidad\Common\Service\Queuer::class));
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
@ -59,32 +59,50 @@ class Cuenta extends Model {
|
|||||||
}
|
}
|
||||||
return $this->consolidados;
|
return $this->consolidados;
|
||||||
}
|
}
|
||||||
public function hasConsolidados(): bool {
|
public function hasConsolidados(\DateTimeInterface $mes = null): bool {
|
||||||
$t = Carbon::now();
|
$t = Carbon::now();
|
||||||
return (bool) Model::factory(Consolidado::class)
|
$q = Model::factory(Consolidado::class)
|
||||||
->whereEqual('cuenta_id', $this->id)
|
->whereEqual('cuenta_id', $this->id);
|
||||||
->count('id');
|
if ($mes !== null) {
|
||||||
|
//$q = $q->whereEqual('fecha', $mes->format('Y-m-1'));
|
||||||
|
$q = $q->whereRaw("fecha BETWEEN '{$mes->format('Y-m-1')}' AND '{$mes->format('Y-m-t')}'");
|
||||||
|
}
|
||||||
|
$q = $q->count('id');
|
||||||
|
return (bool) $q;
|
||||||
}
|
}
|
||||||
public function hasConsolidadosPending(): bool {
|
public function hasConsolidadosPending(\DateTimeInterface $mes = null): bool {
|
||||||
$t = Carbon::now();
|
$t = Carbon::now();
|
||||||
return !(bool) Model::factory(Consolidado::class)
|
$q = Model::factory(Consolidado::class)
|
||||||
->whereEqual('cuenta_id', $this->id)
|
->whereEqual('cuenta_id', $this->id)
|
||||||
->whereGte('fecha', $t->copy()->subMonthNoOverflow()->startOfMonth()->format('Y-m-d'))
|
->whereGte('fecha', $t->copy()->subMonthNoOverflow()->startOfMonth()->format('Y-m-d'));
|
||||||
|
if ($mes !== null) {
|
||||||
|
$q = $q->whereRaw("fecha BETWEEN '{$mes->format('Y-m-1')}' AND '{$mes->format('Y-m-t')}'");
|
||||||
|
}
|
||||||
|
return !(bool) $q
|
||||||
->orderByDesc('fecha')
|
->orderByDesc('fecha')
|
||||||
->count('id');
|
->count('id');
|
||||||
}
|
}
|
||||||
public function hasTransacciones(): bool {
|
public function hasTransacciones(\DateTimeInterface $mes = null): bool {
|
||||||
return (bool) Model::factory(Transaccion::class)
|
$q = Model::factory(Transaccion::class)
|
||||||
->select('transacciones.*')
|
->select('transacciones.*')
|
||||||
->join('cuentas', 'cuentas.id = transacciones.debito_id OR cuentas.id = transacciones.credito_id')
|
->join('cuentas', 'cuentas.id = transacciones.debito_id OR cuentas.id = transacciones.credito_id')
|
||||||
->whereEqual('cuentas.id', $this->id)
|
->whereEqual('cuentas.id', $this->id);
|
||||||
->count('transacciones.id');
|
if ($mes !== null) {
|
||||||
|
$q = $q->whereRaw("fecha BETWEEN '{$mes->format('Y-m-1')}' AND '{$mes->format('Y-m-t')}'");
|
||||||
|
}
|
||||||
|
return (bool) $q->count('transacciones.id');
|
||||||
}
|
}
|
||||||
protected $transacciones;
|
protected $transacciones;
|
||||||
protected function parseTransaccion(Transaccion $transaccion) {
|
protected function parseTransaccion(Transaccion $transaccion) {
|
||||||
$transaccion->setFactory($this->factory);
|
$transaccion->setFactory($this->factory);
|
||||||
if ($transaccion->debito_id === $this->id) {
|
if ($this->tipo()->cargo()) {
|
||||||
$transaccion->valor = - $transaccion->valor;
|
if ($transaccion->credito_id == $this->id) {
|
||||||
|
$transaccion->valor = -$transaccion->valor;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ($transaccion->debito_id == $this->id) {
|
||||||
|
$transaccion->valor = -$transaccion->valor;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$transaccion->valor = $transaccion->transformar($this->moneda());
|
$transaccion->valor = $transaccion->transformar($this->moneda());
|
||||||
return $transaccion;
|
return $transaccion;
|
||||||
|
@ -23,7 +23,7 @@ class Queue extends Model {
|
|||||||
$this->created = $fecha->format('Y-m-d H:i:s');
|
$this->created = $fecha->format('Y-m-d H:i:s');
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
public function hasArguments() {
|
public function hasArguments(): bool {
|
||||||
return Model::factory(QueueArgument::class)
|
return Model::factory(QueueArgument::class)
|
||||||
->whereEqual('queue_id', $this->id)
|
->whereEqual('queue_id', $this->id)
|
||||||
->groupBy('queue_id')
|
->groupBy('queue_id')
|
||||||
@ -36,10 +36,25 @@ class Queue extends Model {
|
|||||||
}
|
}
|
||||||
return $this->arguments;
|
return $this->arguments;
|
||||||
}
|
}
|
||||||
public function isProcessed() {
|
public function matchArguments(array $arguments): array {
|
||||||
|
$args = $this->arguments();
|
||||||
|
if ($args === null) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
$matched = [];
|
||||||
|
foreach ($arguments as $argument => $value) {
|
||||||
|
foreach ($args as $arg) {
|
||||||
|
if ($arg->argument == $argument and $arg->value == $value) {
|
||||||
|
$matched []= $arg;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $matched;
|
||||||
|
}
|
||||||
|
public function isProcessed(): bool {
|
||||||
return $this->processed > 0;
|
return $this->processed > 0;
|
||||||
}
|
}
|
||||||
public function setProcessed(bool $processed) {
|
public function setProcessed(bool $processed): Queue {
|
||||||
$this->processed = $processed ? 1 : 0;
|
$this->processed = $processed ? 1 : 0;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,6 @@ class QueueArgument extends Model {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function __toString(): string {
|
public function __toString(): string {
|
||||||
return "{$this->argument}='{$this->value}'";
|
return "--{$this->argument} '{$this->value}'";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,19 @@ use ProVM\Common\Alias\Model;
|
|||||||
* @property string $color
|
* @property string $color
|
||||||
*/
|
*/
|
||||||
class TipoCuenta extends Model {
|
class TipoCuenta extends Model {
|
||||||
public static $_table = 'tipos_cuenta';
|
public static $_table = 'tipos_cuenta';
|
||||||
protected static $fields = ['descripcion', 'color'];
|
protected static $fields = ['descripcion', 'color'];
|
||||||
|
|
||||||
|
public function cargo()
|
||||||
|
{
|
||||||
|
$tipos = [
|
||||||
|
'activo',
|
||||||
|
'perdida',
|
||||||
|
'banco'
|
||||||
|
];
|
||||||
|
if (in_array(strtolower($this->descripcion), $tipos)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,12 +27,12 @@ class Queue extends Command {
|
|||||||
if ($response->getStatusCode() !== 200) {
|
if ($response->getStatusCode() !== 200) {
|
||||||
return Command::FAILURE;
|
return Command::FAILURE;
|
||||||
}
|
}
|
||||||
$input = json_decode($response->getBody()->getContents());
|
$data = json_decode($response->getBody()->getContents());
|
||||||
$output = [
|
$output = [
|
||||||
'input' => $input,
|
'input' => $data,
|
||||||
'processed' => []
|
'processed' => []
|
||||||
];
|
];
|
||||||
foreach ($input->pending as $queue) {
|
foreach ($data->pending as $queue) {
|
||||||
$log = "Running {$queue->command} from queue. Created in {$queue->created}.";
|
$log = "Running {$queue->command} from queue. Created in {$queue->created}.";
|
||||||
error_log($log);
|
error_log($log);
|
||||||
$cmd = '/usr/local/bin/php /app/bin/console ' . $queue->cmd;
|
$cmd = '/usr/local/bin/php /app/bin/console ' . $queue->cmd;
|
||||||
|
38
console/common/Command/UpdateConsolidar.php
Normal file
38
console/common/Command/UpdateConsolidar.php
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
namespace Contabilidad\Common\Command;
|
||||||
|
|
||||||
|
use Psr\Http\Client\ClientInterface;
|
||||||
|
use Symfony\Component\Console\Command\Command;
|
||||||
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
|
||||||
|
class UpdateConsolidar extends Command {
|
||||||
|
protected $client;
|
||||||
|
public function __construct(ClientInterface $client = null, string $name = null) {
|
||||||
|
parent::__construct($name);
|
||||||
|
$this->setClient($client);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setClient(ClientInterface $client) {
|
||||||
|
$this->client = $client;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
public function getClient(): ClientInterface {
|
||||||
|
return $this->client;
|
||||||
|
}
|
||||||
|
public function execute(InputInterface $input, OutputInterface $output) {
|
||||||
|
try {
|
||||||
|
$mes = $input->getArgument('mes');
|
||||||
|
$cuenta = $input->getArgument('cuenta');
|
||||||
|
$response = $this->getClient()->get("/consolidar/update/{$mes}/{$cuenta}/");
|
||||||
|
if ($response->getStatusCode() === 200) {
|
||||||
|
return Command::SUCCESS;
|
||||||
|
}
|
||||||
|
error_log($response->getReasonPhrase());
|
||||||
|
return Command::FAILURE;
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
error_log($e);
|
||||||
|
return Command::FAILURE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
4
console/setup/commands/03_update_consolidar.php
Normal file
4
console/setup/commands/03_update_consolidar.php
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
<?php
|
||||||
|
use Contabilidad\Common\Command\UpdateConsolidar;
|
||||||
|
|
||||||
|
$app->add(new UpdateConsolidar($app->getContainer()->get(\Psr\Http\Client\ClientInterface::class), 'update_consolidar'));
|
13
ui/common/Controller/Queues.php
Normal file
13
ui/common/Controller/Queues.php
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
namespace Contabilidad\Common\Controller;
|
||||||
|
|
||||||
|
use Psr\Http\Message\ResponseInterface as Response;
|
||||||
|
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||||
|
use Slim\Views\Blade as View;
|
||||||
|
|
||||||
|
class Queues
|
||||||
|
{
|
||||||
|
public function __invoke(Request $request, Response $response, View $view): Response {
|
||||||
|
return $view->render($response, 'queues.list');
|
||||||
|
}
|
||||||
|
}
|
@ -47,7 +47,7 @@ class Transaccion {
|
|||||||
).append(
|
).append(
|
||||||
$('<td></td>').attr('class', 'right aligned').html((this.isIncrement()) ? '' : format_call({value: this.valor.valor, format, format_array}))
|
$('<td></td>').attr('class', 'right aligned').html((this.isIncrement()) ? '' : format_call({value: this.valor.valor, format, format_array}))
|
||||||
).append(
|
).append(
|
||||||
$('<td></td>').attr('class', 'right aligned').html((this.isIncrement()) ? format_call({value: this.valor.valor, format, format_array}) : '')
|
$('<td></td>').attr('class', 'right aligned').html((this.isIncrement()) ? format_call({value: -this.valor.valor, format, format_array}) : '')
|
||||||
).append(
|
).append(
|
||||||
$('<td></td>').attr('class', 'right aligned').html(format_call({value: saldo, format_array, format}))
|
$('<td></td>').attr('class', 'right aligned').html(format_call({value: saldo, format_array, format}))
|
||||||
).append(
|
).append(
|
||||||
@ -95,6 +95,7 @@ const transacciones = {
|
|||||||
buttons: {
|
buttons: {
|
||||||
prev: '#prev_button',
|
prev: '#prev_button',
|
||||||
left: '#left_button',
|
left: '#left_button',
|
||||||
|
today: '#today_button',
|
||||||
right: '#right_button',
|
right: '#right_button',
|
||||||
next: '#next_button'
|
next: '#next_button'
|
||||||
},
|
},
|
||||||
@ -133,7 +134,6 @@ const transacciones = {
|
|||||||
sendGet(_urls.api + '/cuenta/' + this.cuenta_id + '/categoria').then((resp) => {
|
sendGet(_urls.api + '/cuenta/' + this.cuenta_id + '/categoria').then((resp) => {
|
||||||
this.cuenta.categoria = resp.categoria
|
this.cuenta.categoria = resp.categoria
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
//this.saldo = this.cuenta.saldo
|
|
||||||
$('#cuenta').html(this.cuenta.nombre + ' (' + this.cuenta.categoria.nombre + ')').append(
|
$('#cuenta').html(this.cuenta.nombre + ' (' + this.cuenta.categoria.nombre + ')').append(
|
||||||
$('<i></i>').attr('class', 'square full icon').css('color', '#' + this.cuenta.tipo.color)
|
$('<i></i>').attr('class', 'square full icon').css('color', '#' + this.cuenta.tipo.color)
|
||||||
)
|
)
|
||||||
@ -342,6 +342,11 @@ const transacciones = {
|
|||||||
this.checkButtons()
|
this.checkButtons()
|
||||||
$(this.mes).calendar('set date', this.date)
|
$(this.mes).calendar('set date', this.date)
|
||||||
},
|
},
|
||||||
|
today: function() {
|
||||||
|
this.date = new Date()
|
||||||
|
this.checkButtons()
|
||||||
|
$(this.mes).calendar('set date', this.date)
|
||||||
|
},
|
||||||
changeYear: function(dif) {
|
changeYear: function(dif) {
|
||||||
let d = this.date
|
let d = this.date
|
||||||
d.setFullYear(this.date.getFullYear() + dif)
|
d.setFullYear(this.date.getFullYear() + dif)
|
||||||
@ -356,6 +361,11 @@ const transacciones = {
|
|||||||
} else {
|
} else {
|
||||||
$(this.buttons.right).removeClass('disabled')
|
$(this.buttons.right).removeClass('disabled')
|
||||||
}
|
}
|
||||||
|
if (this.date.toDateString() === f.toDateString()) {
|
||||||
|
$(this.buttons.today).addClass('disabled')
|
||||||
|
} else {
|
||||||
|
$(this.buttons.today).removeClass('disabled')
|
||||||
|
}
|
||||||
if (this.date.getFullYear() === f.getFullYear()) {
|
if (this.date.getFullYear() === f.getFullYear()) {
|
||||||
$(this.buttons.next).addClass('disabled')
|
$(this.buttons.next).addClass('disabled')
|
||||||
} else {
|
} else {
|
||||||
@ -422,6 +432,9 @@ const transacciones = {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
buttons: () => {
|
buttons: () => {
|
||||||
|
$(this.buttons.today).click((e) => {
|
||||||
|
this.today()
|
||||||
|
})
|
||||||
$(this.buttons.right).click((e) => {
|
$(this.buttons.right).click((e) => {
|
||||||
this.changeMonth(1)
|
this.changeMonth(1)
|
||||||
})
|
})
|
||||||
|
6
ui/resources/routes/queues.php
Normal file
6
ui/resources/routes/queues.php
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?php
|
||||||
|
use Contabilidad\Common\Controller\Queues;
|
||||||
|
|
||||||
|
$app->group('/queues', function($app) {
|
||||||
|
$app->get('[/]', Queues::class);
|
||||||
|
});
|
@ -2,4 +2,5 @@
|
|||||||
@include('config.menu.tipos_categorias')
|
@include('config.menu.tipos_categorias')
|
||||||
@include('config.menu.tipos_cuentas')
|
@include('config.menu.tipos_cuentas')
|
||||||
@include('config.menu.files')
|
@include('config.menu.files')
|
||||||
|
@include('config.menu.queues')
|
||||||
</div>
|
</div>
|
||||||
|
3
ui/resources/views/config/menu/queues.blade.php
Normal file
3
ui/resources/views/config/menu/queues.blade.php
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<a class="item" href="{{$urls->base}}queues">
|
||||||
|
Queues
|
||||||
|
</a>
|
@ -18,6 +18,9 @@
|
|||||||
<div class="ui icon button" id="left_button">
|
<div class="ui icon button" id="left_button">
|
||||||
<i class="left angle icon"></i>
|
<i class="left angle icon"></i>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="ui icon disabled button" id="today_button">
|
||||||
|
<i class="calendar day icon"></i>
|
||||||
|
</div>
|
||||||
<div class="ui icon disabled button" id="right_button">
|
<div class="ui icon disabled button" id="right_button">
|
||||||
<i class="right angle icon"></i>
|
<i class="right angle icon"></i>
|
||||||
</div>
|
</div>
|
||||||
|
8
ui/resources/views/queues/base.blade.php
Normal file
8
ui/resources/views/queues/base.blade.php
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
@extends('config.base')
|
||||||
|
|
||||||
|
@section('config_content')
|
||||||
|
<h1 class="ui header">Queues</h1>
|
||||||
|
<div class="ui basic fitted segment">
|
||||||
|
@yield('queues_content')
|
||||||
|
</div>
|
||||||
|
@endsection
|
38
ui/resources/views/queues/list.blade.php
Normal file
38
ui/resources/views/queues/list.blade.php
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
@extends('queues.base')
|
||||||
|
|
||||||
|
@section('queues_content')
|
||||||
|
<table class="ui table" id="queues">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Comando</th>
|
||||||
|
<th>Creado</th>
|
||||||
|
<!-- <th class="right aligned">
|
||||||
|
Procesar
|
||||||
|
<button class="ui tiny circular icon button" id="procesar">
|
||||||
|
<i class="green play icon"></i>
|
||||||
|
</button>
|
||||||
|
</th> -->
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
</table>
|
||||||
|
@endsection
|
||||||
|
|
||||||
|
@push('scripts')
|
||||||
|
<script type="text/javascript">
|
||||||
|
$(document).ready(() => {
|
||||||
|
sendGet(_urls.api + '/queues/pending').then((response) => {
|
||||||
|
const table = $('#queues')
|
||||||
|
const tbody = $('<tbody></tbody>')
|
||||||
|
response.pending.forEach((el, i) => {
|
||||||
|
const row = $('<tr></tr>').append(
|
||||||
|
$('<td></td>').html(el.command)
|
||||||
|
).append(
|
||||||
|
$('<td></td>').html(el.created)
|
||||||
|
)
|
||||||
|
tbody.append(row)
|
||||||
|
})
|
||||||
|
table.append(tbody)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
@endpush
|
Reference in New Issue
Block a user