Compare commits
89 Commits
61448a2521
...
release
Author | SHA1 | Date | |
---|---|---|---|
459a95bf12 | |||
06071884c7 | |||
ca8229abee | |||
6ff584013f | |||
cf27465d75 | |||
560fb356fa | |||
6c4e51bfff | |||
10e5383a3e | |||
81ff87d355 | |||
bc5338b1f1 | |||
4db8161c70 | |||
d94f076946 | |||
899e9f6070 | |||
8009433958 | |||
d7b406ef25 | |||
cddf768b1e | |||
0bd54fa8a4 | |||
8b86560973 | |||
f6285d6970 | |||
4ea5c6de3e | |||
5f4f5d1501 | |||
91cc28e681 | |||
ef01ab3c55 | |||
e41ffd505b | |||
0e7d7200b6 | |||
2986806137 | |||
f9076d3bac | |||
ee3133da72 | |||
dbad283e14 | |||
e3737aba27 | |||
fcc84ac09c | |||
d0d123e12e | |||
2b3b475d91 | |||
e5cf3cfa07 | |||
71975ec6d9 | |||
84a3f8e2e3 | |||
f36399c1f4 | |||
5a9dc6602c | |||
d7dfc2d221 | |||
1d62a0c04e | |||
c1eeba04a2 | |||
3cb2a877de | |||
a2a90497ae | |||
b17225549c | |||
925388df92 | |||
af78106700 | |||
665f426011 | |||
56b371d20c | |||
2126d30ee7 | |||
71b4211fc3 | |||
0378a2cf09 | |||
73df98dca5 | |||
4abe3448c0 | |||
f9bbbfd920 | |||
9e29dd09b7 | |||
52443c2226 | |||
572a9dc87c | |||
66882d9f85 | |||
aacda4d1e4 | |||
1a0c83fb2b | |||
f99b984f6c | |||
a5428b252e | |||
605c905f5d | |||
4bc1e4ae4d | |||
93f77bfbb8 | |||
fddba2fb87 | |||
79c7d5ad63 | |||
e6ebb2c279 | |||
45952bb3ac | |||
6b03d62ce0 | |||
894cc26b21 | |||
64ffb53f0c | |||
42310ef0e4 | |||
a6362a6770 | |||
e9c63abc3a | |||
9f47c8a85f | |||
34eedb93d7 | |||
960c418848 | |||
0e5714edc8 | |||
f33bddfbea | |||
25f873c453 | |||
34b429530f | |||
9d2504f016 | |||
8ef4ab1c7d | |||
10b2485cfd | |||
0382f8c286 | |||
a3311f805e | |||
378de3ed86 | |||
69c2cffa6c |
1
.api.env.sample
Normal file
1
.api.env.sample
Normal file
@ -0,0 +1 @@
|
||||
API_KEY=
|
1
.console.env.sample
Normal file
1
.console.env.sample
Normal file
@ -0,0 +1 @@
|
||||
API_URL=http://api-proxy
|
5
.db.env.sample
Normal file
5
.db.env.sample
Normal file
@ -0,0 +1,5 @@
|
||||
MYSQL_HOST=
|
||||
MYSQL_ROOT_PASSWORD=
|
||||
MYSQL_DATABASE=
|
||||
MYSQL_USER=
|
||||
MYSQL_PASSWORD=
|
@ -1,5 +1 @@
|
||||
MYSQL_HOST=
|
||||
MYSQL_ROOT_PASSWORD=
|
||||
MYSQL_DATABASE=
|
||||
MYSQL_USER=
|
||||
MYSQL_PASSWORD=
|
||||
COMPOSE_PROFILES=
|
||||
|
8
.idea/.gitignore
generated
vendored
8
.idea/.gitignore
generated
vendored
@ -1,8 +0,0 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
5
.idea/codeStyles/codeStyleConfig.xml
generated
5
.idea/codeStyles/codeStyleConfig.xml
generated
@ -1,5 +0,0 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<state>
|
||||
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
|
||||
</state>
|
||||
</component>
|
81
.idea/contabilidad.iml
generated
81
.idea/contabilidad.iml
generated
@ -1,81 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="WEB_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/kint-php/kint" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/zeuxisoo/slim-whoops" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/phar-io/version" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/phar-io/manifest" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/theseer/tokenizer" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/webmozart/assert" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/philo/laravel-blade" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/nesbot/carbon" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/sebastian/type" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/sebastian/diff" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/illuminate/support" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/sebastian/lines-of-code" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/illuminate/filesystem" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/sebastian/object-enumerator" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/illuminate/events" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/sebastian/comparator" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/illuminate/contracts" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/psr/simple-cache" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/sebastian/code-unit" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/illuminate/view" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/psr/http-server-handler" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/doctrine/instantiator" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/sebastian/exporter" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/illuminate/container" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/psr/http-factory" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/doctrine/inflector" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/sebastian/cli-parser" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/psr/container" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/sebastian/version" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/psr/http-message" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/sebastian/complexity" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/psr/http-server-middleware" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/sebastian/recursion-context" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/psr/log" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/sebastian/resource-operations" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/sebastian/global-state" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/composer" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/sebastian/environment" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/phpdocumentor/reflection-docblock" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/sebastian/code-unit-reverse-lookup" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/phpdocumentor/type-resolver" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/symfony/polyfill-mbstring" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/sebastian/object-reflector" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/phpdocumentor/reflection-common" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/symfony/finder" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/symfony/deprecation-contracts" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/symfony/translation-contracts" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/filp/whoops" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/symfony/polyfill-ctype" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/symfony/debug" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/nyholm/psr7-server" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/symfony/translation" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/nyholm/psr7" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/symfony/polyfill-php80" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/nikic/php-parser" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/nikic/fast-route" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/php-di/php-di" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/php-di/phpdoc-reader" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/php-di/slim-bridge" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/php-di/invoker" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/phpunit/php-code-coverage" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/phpunit/phpunit" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/phpunit/php-text-template" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/phpunit/php-invoker" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/phpunit/php-file-iterator" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/phpunit/php-timer" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/myclabs/deep-copy" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/phpspec/prophecy" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/opis/closure" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/php-http/message-factory" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/rubellum/slim-blade-view" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/ui/vendor/slim/slim" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
8
.idea/modules.xml
generated
8
.idea/modules.xml
generated
@ -1,8 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/contabilidad.iml" filepath="$PROJECT_DIR$/.idea/contabilidad.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
87
.idea/php.xml
generated
87
.idea/php.xml
generated
@ -1,87 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="PhpIncludePathManager">
|
||||
<include_path>
|
||||
<path value="$PROJECT_DIR$/ui/vendor/kint-php/kint" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/zeuxisoo/slim-whoops" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/phar-io/version" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/phar-io/manifest" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/theseer/tokenizer" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/webmozart/assert" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/philo/laravel-blade" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/nesbot/carbon" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/sebastian/type" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/sebastian/diff" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/illuminate/support" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/sebastian/lines-of-code" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/illuminate/filesystem" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/sebastian/object-enumerator" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/illuminate/events" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/sebastian/comparator" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/illuminate/contracts" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/psr/simple-cache" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/sebastian/code-unit" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/illuminate/view" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/psr/http-server-handler" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/doctrine/instantiator" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/sebastian/exporter" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/illuminate/container" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/psr/http-factory" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/doctrine/inflector" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/sebastian/cli-parser" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/psr/container" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/sebastian/version" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/psr/http-message" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/sebastian/complexity" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/psr/http-server-middleware" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/sebastian/recursion-context" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/psr/log" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/sebastian/resource-operations" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/sebastian/global-state" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/composer" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/sebastian/environment" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/phpdocumentor/reflection-docblock" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/sebastian/code-unit-reverse-lookup" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/phpdocumentor/type-resolver" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/symfony/polyfill-mbstring" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/sebastian/object-reflector" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/phpdocumentor/reflection-common" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/symfony/finder" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/symfony/deprecation-contracts" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/symfony/translation-contracts" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/filp/whoops" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/symfony/polyfill-ctype" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/symfony/debug" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/nyholm/psr7-server" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/symfony/translation" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/nyholm/psr7" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/symfony/polyfill-php80" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/nikic/php-parser" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/nikic/fast-route" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/php-di/php-di" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/php-di/phpdoc-reader" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/php-di/slim-bridge" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/php-di/invoker" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/phpunit/php-code-coverage" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/phpunit/phpunit" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/phpunit/php-text-template" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/phpunit/php-invoker" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/phpunit/php-file-iterator" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/phpunit/php-timer" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/myclabs/deep-copy" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/phpspec/prophecy" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/opis/closure" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/php-http/message-factory" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/rubellum/slim-blade-view" />
|
||||
<path value="$PROJECT_DIR$/ui/vendor/slim/slim" />
|
||||
</include_path>
|
||||
</component>
|
||||
<component name="PhpProjectSharedConfiguration" php_language_level="8.0">
|
||||
<option name="suggestChangeDefaultLanguageLevel" value="false" />
|
||||
</component>
|
||||
<component name="PhpUnit">
|
||||
<phpunit_settings>
|
||||
<PhpUnitSettings custom_loader_path="$PROJECT_DIR$/ui/vendor/autoload.php" />
|
||||
</phpunit_settings>
|
||||
</component>
|
||||
</project>
|
1
.python.env.sample
Normal file
1
.python.env.sample
Normal file
@ -0,0 +1 @@
|
||||
PYTHON_KEY=
|
1
api/.gitignore
vendored
Normal file
1
api/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
**/uploads/
|
@ -1,8 +1,8 @@
|
||||
FROM php:8-fpm
|
||||
|
||||
RUN apt-get update -y && apt-get install -y git libzip-dev zip
|
||||
RUN apt-get update -y && apt-get install -y git libzip-dev zip libpng-dev libfreetype6-dev libjpeg62-turbo-dev tesseract-ocr
|
||||
|
||||
RUN docker-php-ext-install pdo pdo_mysql zip
|
||||
RUN docker-php-ext-configure gd --with-freetype --with-jpeg && docker-php-ext-install pdo pdo_mysql zip gd
|
||||
|
||||
COPY --from=composer /usr/bin/composer /usr/bin/composer
|
||||
|
||||
|
6
api/common/Alias/DocumentHandler.php
Normal file
6
api/common/Alias/DocumentHandler.php
Normal file
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
namespace Contabilidad\Common\Alias;
|
||||
|
||||
interface DocumentHandler {
|
||||
public function load(): ?array;
|
||||
}
|
11
api/common/Concept/DocumentHandler.php
Normal file
11
api/common/Concept/DocumentHandler.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
namespace Contabilidad\Common\Concept;
|
||||
|
||||
use Contabilidad\Common\Alias\DocumentHandler as HandlerInterface;
|
||||
|
||||
abstract class DocumentHandler implements HandlerInterface {
|
||||
protected string $folder;
|
||||
public function __construct(string $source_folder) {
|
||||
$this->folder = $source_folder;
|
||||
}
|
||||
}
|
@ -11,4 +11,24 @@ class Base {
|
||||
public function __invoke(Request $request, Response $response): Response {
|
||||
return $this->withJson($response, []);
|
||||
}
|
||||
public function generate_key(Request $request, Response $response): Response {
|
||||
$server_addr = explode('.', $request->getServerParams()['SERVER_ADDR']);
|
||||
$remote_addr = explode('.', $request->getServerParams()['REMOTE_ADDR']);
|
||||
for ($i = 0; $i < 3; $i ++) {
|
||||
if ($server_addr[$i] != $remote_addr[$i]) {
|
||||
throw new \InvalidArgumentException('Invalid connection address.');
|
||||
}
|
||||
}
|
||||
$salt = mt_rand();
|
||||
$signature = hash_hmac('sha256', $salt, 'contabilidad', true);
|
||||
$key = urlencode(base64_encode($signature));
|
||||
return $this->withJson($response, ['key' => $key]);
|
||||
}
|
||||
public function info(Request $request, Response $response): Response {
|
||||
ob_start();
|
||||
phpinfo();
|
||||
$data = ob_get_clean();
|
||||
$response->getBody()->write($data);
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
@ -5,20 +5,43 @@ 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\Common\Service\TiposCambios as Service;
|
||||
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']);
|
||||
});
|
||||
public function __invoke(Request $request, Response $response, Factory $factory, Service $service): Response {
|
||||
$categorias = $factory->find(Categoria::class)->many();
|
||||
if ($categorias !== null) {
|
||||
array_walk($categorias, function(&$item) use ($service) {
|
||||
$arr = $item->toArray();
|
||||
if ($item->cuentas()) {
|
||||
$arr['cuentas'] = array_map(function($item) {
|
||||
return $item->toArray();
|
||||
}, $item->cuentas());
|
||||
}
|
||||
$maps = ['activo', 'pasivo', 'ganancia', 'perdida'];
|
||||
foreach ($maps as $m) {
|
||||
$p = $m . 's';
|
||||
$t = ucfirst($m);
|
||||
$cuentas = $item->getCuentasOf($t);
|
||||
if ($cuentas === false or $cuentas === null) {
|
||||
$arr[$p] = 0;
|
||||
continue;
|
||||
}
|
||||
$arr[$p] = array_reduce($cuentas, function($sum, $item) use($service) {
|
||||
return $sum + $item->saldo($service, true);
|
||||
});
|
||||
}
|
||||
$item = $arr;
|
||||
});
|
||||
usort($categorias, function($a, $b) {
|
||||
return strcmp($a['nombre'], $b['nombre']);
|
||||
});
|
||||
}
|
||||
$output = [
|
||||
'categorias' => $categorias
|
||||
'categorias' => $categorias
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
@ -68,14 +91,14 @@ class Categorias {
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function cuentas(Request $request, Response $response, Factory $factory, $categoria_id): Response {
|
||||
public function cuentas(Request $request, Response $response, Factory $factory, Service $service, $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();
|
||||
array_walk($cuentas, function(&$item) use ($service) {
|
||||
$item = $item->toArray($service);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
66
api/common/Controller/Consolidados.php
Normal file
66
api/common/Controller/Consolidados.php
Normal file
@ -0,0 +1,66 @@
|
||||
<?php
|
||||
namespace Contabilidad\Common\Controller;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use ProVM\Common\Factory\Model as Factory;
|
||||
use ProVM\Common\Define\Controller\Json;
|
||||
use Contabilidad\Common\Service\Consolidar as Service;
|
||||
use Contabilidad\Cuenta;
|
||||
use Contabilidad\Consolidado;
|
||||
|
||||
class Consolidados {
|
||||
use Json;
|
||||
|
||||
public function __invoke(Request $request, Response $response, Factory $factory, $cuenta_id): Response {
|
||||
$consolidados = $factory->find(Consolidados::class)->where([['cuenta_id' => $cuenta_id]])->many();
|
||||
$output = [
|
||||
'consolidados' => array_map(function($item) {
|
||||
return $item->toArray();
|
||||
}, $consolidados)
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function add(Request $request, Response $response, Factory $factory): Response {
|
||||
$input = json_decode($request->getBody()->getContents());
|
||||
$output = [
|
||||
'input' => $input,
|
||||
'consolidados' => []
|
||||
];
|
||||
if (!is_array($input)) {
|
||||
$input = [$input];
|
||||
}
|
||||
foreach ($input as $data) {
|
||||
$consolidado = Consolidado::add($factory, $data);
|
||||
$status = $consolidado->save();
|
||||
$output['consolidados'] []= [
|
||||
'consolidado' => $consolidado->toArray(),
|
||||
'added' => $status
|
||||
];
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function cli(Request $request, Response $response, Service $service): Response {
|
||||
try {
|
||||
if (!$service->isConsolidado()) {
|
||||
$service->consolidar();
|
||||
}
|
||||
} catch (\Error | \Exception $e) {
|
||||
error_log($e);
|
||||
throw $e;
|
||||
}
|
||||
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, []);
|
||||
}
|
||||
}
|
@ -1,24 +1,36 @@
|
||||
<?php
|
||||
namespace Contabilidad\Common\Controller;
|
||||
|
||||
use Contabilidad\Transaccion;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Carbon\Carbon;
|
||||
use ProVM\Common\Define\Controller\Json;
|
||||
use ProVM\Common\Factory\Model as Factory;
|
||||
use Contabilidad\Common\Service\TiposCambios as Service;
|
||||
use Contabilidad\Cuenta;
|
||||
|
||||
class Cuentas {
|
||||
use Json;
|
||||
|
||||
public function __invoke(Request $request, Response $response, Factory $factory): Response {
|
||||
$cuentas = $factory->find(Cuenta::class)->array();
|
||||
$cuentas = $factory->find(Cuenta::class)->many();
|
||||
if ($cuentas) {
|
||||
array_walk($cuentas, function (&$item) {
|
||||
$arr = $item->toArray();
|
||||
$arr['categoria'] = $item->categoria()->toArray();
|
||||
$item = $arr;
|
||||
});
|
||||
usort($cuentas, function($a, $b) {
|
||||
$t = strcmp($a['tipo']['descripcion'], $b['tipo']['descripcion']);
|
||||
if ($t != 0) {
|
||||
return $t;
|
||||
}
|
||||
$c = strcmp($a['categoria']['nombre'], $b['categoria']['nombre']);
|
||||
if ($c == 0) {
|
||||
return strcmp($a['nombre'], $b['nombre']);
|
||||
if ($c != 0) {
|
||||
return $c;
|
||||
}
|
||||
return $c;
|
||||
return strcmp($a['nombre'], $b['nombre']);
|
||||
});
|
||||
}
|
||||
$output = [
|
||||
@ -72,6 +84,15 @@ class Cuentas {
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function categoria(Request $request, Response $response, Factory $factory, $cuenta_id): Response {
|
||||
$cuenta = $factory->find(Cuenta::class)->one($cuenta_id);
|
||||
$output = [
|
||||
'input' => $cuenta_id,
|
||||
'cuenta' => $cuenta?->toArray(),
|
||||
'categoria' => $cuenta?->categoria()->toArray()
|
||||
];
|
||||
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;
|
||||
@ -90,15 +111,33 @@ class Cuentas {
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function transacciones(Request $request, Response $response, Factory $factory, $cuenta_id, $limit = null, $start = 0): Response {
|
||||
protected function transaccionToArray(Service $service, Cuenta $cuenta, Transaccion $transaccion): array {
|
||||
$arr = $transaccion->toArray();
|
||||
if ($cuenta->moneda()->codigo === 'CLP') {
|
||||
if ($transaccion->debito()->moneda()->codigo !== 'CLP' or $transaccion->credito()->moneda()->codigo !== 'CLP') {
|
||||
if ($transaccion->debito()->moneda()->codigo !== 'CLP') {
|
||||
$c = $transaccion->debito();
|
||||
} else {
|
||||
$c = $transaccion->credito();
|
||||
}
|
||||
$service->get($transaccion->fecha(), $c->moneda()->id);
|
||||
$arr['valor'] = $transaccion->valor;
|
||||
$arr['valorFormateado'] = $cuenta->moneda()->format($arr['valor']);
|
||||
}
|
||||
}
|
||||
$arr['debito']['categoria'] = $transaccion->debito()->categoria()->toArray();
|
||||
$arr['credito']['categoria'] = $transaccion->credito()->categoria()->toArray();
|
||||
return $arr;
|
||||
}
|
||||
public function transacciones(Request $request, Response $response, Factory $factory, Service $service, $cuenta_id, $limit = null, $start = 0): Response {
|
||||
$cuenta = $factory->find(Cuenta::class)->one($cuenta_id);
|
||||
$transacciones = null;
|
||||
if ($cuenta !== null) {
|
||||
$transacciones = $cuenta->transacciones($limit, $start);
|
||||
if (count($transacciones)) {
|
||||
array_walk($transacciones, function(&$item) {
|
||||
$item = $item->toArray();
|
||||
});
|
||||
if (count($transacciones) > 0) {
|
||||
foreach ($transacciones as &$transaccion) {
|
||||
$transaccion = $this->transaccionToArray($service, $cuenta, $transaccion);
|
||||
}
|
||||
}
|
||||
}
|
||||
$output = [
|
||||
@ -108,6 +147,40 @@ class Cuentas {
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function transaccionesMonth(Request $request, Response $response, Factory $factory, Service $service, $cuenta_id, $month): Response {
|
||||
$cuenta = $factory->find(Cuenta::class)->one($cuenta_id);
|
||||
$month = Carbon::parse($month);
|
||||
$transacciones = null;
|
||||
if ($cuenta !== null) {
|
||||
$transacciones = $cuenta->transaccionesMonth($month);
|
||||
if (count($transacciones) > 0) {
|
||||
foreach ($transacciones as &$transaccion) {
|
||||
$transaccion = $this->transaccionToArray($service, $cuenta, $transaccion);
|
||||
}
|
||||
}
|
||||
}
|
||||
$output = [
|
||||
'input' => compact('cuenta_id', 'month'),
|
||||
'cuenta' => $cuenta?->toArray(),
|
||||
'transacciones' => $transacciones
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function transaccionesAcumulation(Request $request, Response $response, Factory $factory, $cuenta_id, $date): Response {
|
||||
$cuenta = $factory->find(Cuenta::class)->one($cuenta_id);
|
||||
$f = Carbon::parse($date);
|
||||
$acum = 0;
|
||||
if ($cuenta !== null) {
|
||||
$acum = $cuenta->acumulacion($f);
|
||||
}
|
||||
$output = [
|
||||
'input' => compact('cuenta_id', 'date'),
|
||||
'cuenta' => $cuenta?->toArray(),
|
||||
'format' => $cuenta->moneda()->toArray(),
|
||||
'acumulation' => $acum
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function transaccionesAmount(Request $request, Response $response, Factory $factory, $cuenta_id): Response {
|
||||
$cuenta = $factory->find(Cuenta::class)->one($cuenta_id);
|
||||
$transacciones = 0;
|
||||
|
76
api/common/Controller/Files.php
Normal file
76
api/common/Controller/Files.php
Normal file
@ -0,0 +1,76 @@
|
||||
<?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\FileHandler as Handler;
|
||||
use ProVM\Common\Factory\Model as Factory;
|
||||
use Contabilidad\Cuenta;
|
||||
|
||||
class Files {
|
||||
use Json;
|
||||
|
||||
public function __invoke(Request $request, Response $response, Handler $handler): Response {
|
||||
$files = $handler->listFiles();
|
||||
usort($files, function($a, $b) {
|
||||
$f = strcmp($a->folder, $b->folder);
|
||||
if ($f == 0) {
|
||||
return strcmp($a->filename, $b->filename);
|
||||
}
|
||||
return $f;
|
||||
});
|
||||
return $this->withJson($response, compact('files'));
|
||||
}
|
||||
public function upload(Request $request, Response $response, Handler $handler, Factory $factory): Response {
|
||||
$post = $request->getParsedBody();
|
||||
$cuenta = $factory->find(Cuenta::class)->one($post['cuenta']);
|
||||
$file = $request->getUploadedFiles()['archivo'];
|
||||
$new_name = implode(' - ', [$cuenta->nombre, $cuenta->categoria()->nombre, $post['fecha']]);
|
||||
$output = [
|
||||
'input' => [
|
||||
'name' => $file->getClientFilename(),
|
||||
'type' => $file->getClientMediaType(),
|
||||
'size' => $file->getSize(),
|
||||
'error' => $file->getError()
|
||||
],
|
||||
'new_name' => $new_name,
|
||||
'uploaded' => $handler->uploadFile($file, $new_name)
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function get(Request $request, Response $response, Handler $handler, $folder, $filename): Response {
|
||||
$file = $handler->getFile($folder, $filename);
|
||||
return $response
|
||||
->withHeader('Content-Type', $handler->getType($folder))
|
||||
->withHeader('Content-Disposition', 'attachment; filename=' . $filename)
|
||||
->withAddedHeader('Cache-Control', 'no-store, no-cache, must-revalidate, max-age=0')
|
||||
->withHeader('Cache-Control', 'post-check=0, pre-check=0')
|
||||
->withHeader('Pragma', 'no-cache')
|
||||
->withBody($file);
|
||||
}
|
||||
public function edit(Request $request, Response $response, Handler $handler, Factory $factory, $folder, $filename): Response {
|
||||
$post = json_decode($request->getBody());
|
||||
$cuenta = $factory->find(Cuenta::class)->one($post->cuenta);
|
||||
$new_name = implode(' - ', [$cuenta->nombre, $cuenta->categoria()->nombre, $post->fecha]);
|
||||
$output = [
|
||||
'input' => [
|
||||
'folder' => $folder,
|
||||
'filename' => $filename,
|
||||
'post' => $post
|
||||
],
|
||||
'edited' => $handler->editFilename($folder, $filename, $new_name)
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function delete(Request $request, Response $response, Handler $handler, $folder, $filename): Response {
|
||||
$output = [
|
||||
'input' => [
|
||||
'folder' => $folder,
|
||||
'filename' => $filename
|
||||
],
|
||||
'deleted' => $handler->deleteFile($folder, $filename)
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
}
|
@ -3,19 +3,47 @@ namespace Contabilidad\Common\Controller;
|
||||
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Psr\Container\ContainerInterface as Container;
|
||||
use ProVM\Common\Define\Controller\Json;
|
||||
use ProVM\Common\Factory\Model as Factory;
|
||||
use Contabilidad\Common\Service\PdfHandler;
|
||||
use Contabilidad\Common\Service\DocumentHandler as Handler;
|
||||
use Contabilidad\Cuenta;
|
||||
|
||||
class Import {
|
||||
use Json;
|
||||
|
||||
public function __invoke(Request $request, Response $response, Factory $factory): Response {
|
||||
$post = $request->getParsedBody();
|
||||
return $this->withJson($response, $post);
|
||||
public function __invoke(Request $request, Response $response, Factory $factory, Container $container): Response {
|
||||
$post =$request->getParsedBody();
|
||||
$cuenta = $factory->find(Cuenta::class)->one($post['cuenta']);
|
||||
$file = $request->getUploadedFiles()['archivo'];
|
||||
$valid_media = [
|
||||
'text/csv' => 'csvs',
|
||||
'application/pdf' => 'pdfs',
|
||||
'application/vnd.ms-excel' => 'xlss',
|
||||
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'xlss',
|
||||
'application/json' => 'jsons'
|
||||
];
|
||||
if ($file->getError() === 0 and in_array($file->getClientMediaType(), array_keys($valid_media))) {
|
||||
$filenfo = new \SplFileInfo($file->getClientFilename());
|
||||
$new_name = implode('.', [implode(' - ', [$cuenta->nombre, $cuenta->categoria()->nombre, $post['fecha']]), $filenfo->getExtension()]);
|
||||
$to = implode(DIRECTORY_SEPARATOR, [$container->get('folders')->uploads, $valid_media[$file->getClientMediaType()], $new_name]);
|
||||
$file->moveTo($to);
|
||||
$status = file_exists($to);
|
||||
}
|
||||
$output = [
|
||||
'input' => [
|
||||
'name' => $file->getClientFilename(),
|
||||
'type' => $file->getClientMediaType(),
|
||||
'size' => $file->getSize(),
|
||||
'error' => $file->getError()
|
||||
],
|
||||
'new_name' => $new_name,
|
||||
'uploaded' => $status
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function uploads(Request $request, Response $response, PdfHandler $handler): Response {
|
||||
$output = $handler->load();
|
||||
return $this->withJson($response, $output);
|
||||
public function uploads(Request $request, Response $response, Handler $handler): Response {
|
||||
$output = $handler->handle();
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
}
|
||||
|
71
api/common/Controller/Monedas.php
Normal file
71
api/common/Controller/Monedas.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\Moneda;
|
||||
|
||||
class Monedas {
|
||||
use Json;
|
||||
|
||||
public function __invoke(Request $request, Response $response, Factory $factory): Response {
|
||||
$monedas = $factory->find(Moneda::class)->array();
|
||||
if ($monedas) {
|
||||
usort($monedas, function($a, $b) {
|
||||
return strcmp($a['denominacion'], $b['denominacion']);
|
||||
});
|
||||
}
|
||||
$output = [
|
||||
'monedas' => $monedas
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function show(Request $request, Response $response, Factory $factory, $moneda_id): Response {
|
||||
$moneda = $factory->find(Moneda::class)->one($moneda_id);
|
||||
$output = [
|
||||
'input' => $moneda_id,
|
||||
'moneda' => $moneda?->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) {
|
||||
$moneda = Moneda::add($factory, $in);
|
||||
$results []= ['moneda' => $moneda?->toArray(), 'agregado' => $moneda?->save()];
|
||||
}
|
||||
} else {
|
||||
$moneda = Moneda::add($factory, $input);
|
||||
$results []= ['moneda' => $moneda?->toArray(), 'agregado' => $moneda?->save()];
|
||||
}
|
||||
$output = [
|
||||
'input' => $input,
|
||||
'monedas' => $results
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function edit(Request $request, Response $response, Factory $factory, $moneda_id): Response {
|
||||
$moneda = $factory->find(Moneda::class)->one($moneda_id);
|
||||
$output = [
|
||||
'input' => $moneda_id,
|
||||
'old' => $moneda->toArray()
|
||||
];
|
||||
$input = json_decode($request->getBody());
|
||||
$moneda->edit($input);
|
||||
$output['moneda'] = $moneda->toArray();
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function delete(Request $request, Response $response, Factory $factory, $moneda_id): Response {
|
||||
$moneda = $factory->find(Moneda::class)->one($moneda_id);
|
||||
$output = [
|
||||
'input' => $moneda_id,
|
||||
'moneda' => $moneda->toArray(),
|
||||
'eliminado' => $moneda->delete()
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
}
|
47
api/common/Controller/Queues.php
Normal file
47
api/common/Controller/Queues.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
namespace Contabilidad\Common\Controller;
|
||||
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use ProVM\Common\Factory\Model as Factory;
|
||||
use ProVM\Common\Define\Controller\Json;
|
||||
use Contabilidad\Queue;
|
||||
|
||||
class Queues {
|
||||
use Json;
|
||||
|
||||
public function __invoke(Request $request, Response $response, Factory $factory): Response {
|
||||
$queues = $factory->find(Queue::class)->many();
|
||||
$output = [
|
||||
'queues' => array_map(function($item) {return $item->toArray();}, $queues)
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function pending(Request $request, Response $response, Factory $factory): Response {
|
||||
$pending = $factory->find(Queue::class)->where([['processed', 0]])->many();
|
||||
$output = [
|
||||
'pending' => array_map(function($item) {return $item->toArray();}, $pending)
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function processed(Request $request, Response $response, Factory $factory): Response {
|
||||
$input = json_decode($request->getBody()->getContents());
|
||||
$output = [
|
||||
'input' => $input,
|
||||
'queues' => []
|
||||
];
|
||||
if (!is_array($input->processed)) {
|
||||
$input->processed = [$input->processed];
|
||||
}
|
||||
foreach ($input->processed as $id) {
|
||||
$queue = $factory->find(Queue::class)->one($id);
|
||||
$queue->setProcessed(true);
|
||||
$status = $queue->save();
|
||||
$output['queues'] []= [
|
||||
'queue' => $queue->toArray(),
|
||||
'processed' => $status
|
||||
];
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
}
|
95
api/common/Controller/TiposCambios.php
Normal file
95
api/common/Controller/TiposCambios.php
Normal file
@ -0,0 +1,95 @@
|
||||
<?php
|
||||
namespace Contabilidad\Common\Controller;
|
||||
|
||||
use Carbon\Carbon;
|
||||
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\Common\Service\TiposCambios as Service;
|
||||
use Contabilidad\TipoCambio;
|
||||
|
||||
class TiposCambios {
|
||||
use Json;
|
||||
|
||||
public function __invoke(Request $request, Response $response, Factory $factory): Response {
|
||||
$tipos = $factory->find(TipoCambio::class)->array();
|
||||
if ($tipos) {
|
||||
usort($tipos, function($a, $b) {
|
||||
return strcmp($a['fecha'], $b['fecha']);
|
||||
});
|
||||
}
|
||||
$output = [
|
||||
'tipos' => $tipos
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function show(Request $request, Response $response, Factory $factory, $tipo_id): Response {
|
||||
$tipo = $factory->find(TipoCambio::class)->one($tipo_id);
|
||||
$output = [
|
||||
'input' => $tipo_id,
|
||||
'tipo' => $tipo?->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 = TipoCambio::add($factory, $in);
|
||||
$results []= ['tipo' => $tipo?->toArray(), 'agregado' => $tipo?->save()];
|
||||
}
|
||||
} else {
|
||||
$tipo = TipoCambio::add($factory, $input);
|
||||
$results []= ['tipo' => $tipo?->toArray(), 'agregado' => $tipo?->save()];
|
||||
}
|
||||
$output = [
|
||||
'input' => $input,
|
||||
'tipos' => $results
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function edit(Request $request, Response $response, Factory $factory, $tipo_id): Response {
|
||||
$tipo = $factory->find(TipoCambio::class)->one($tipo_id);
|
||||
$output = [
|
||||
'input' => $tipo_id,
|
||||
'old' => $tipo->toArray()
|
||||
];
|
||||
$input = json_decode($request->getBody());
|
||||
$tipo->edit($input);
|
||||
$output['tipo'] = $tipo->toArray();
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function delete(Request $request, Response $response, Factory $factory, $tipo_id): Response {
|
||||
$tipo = $factory->find(TipoCambio::class)->one($tipo_id);
|
||||
$output = [
|
||||
'input' => $tipo_id,
|
||||
'tipo' => $tipo->toArray(),
|
||||
'eliminado' => $tipo->delete()
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function obtain(Request $request, Response $response, Factory $factory, Service $service): Response {
|
||||
$post = $request->getParsedBody();
|
||||
$valor = $service->get($post['fecha'], $post['moneda_id']);
|
||||
if ($valor === null) {
|
||||
return $this->withJson($response, ['input' => $post, 'tipo' => null, 'error' => 'No se encontró valor']);
|
||||
}
|
||||
$data = [
|
||||
'fecha' => $post['fecha'],
|
||||
'desde_id' => $post['moneda_id'],
|
||||
'hasta_id' => 1,
|
||||
'valor' => $valor
|
||||
];
|
||||
$tipo = TipoCambio::add($factory, $data);
|
||||
if ($tipo !== false and $tipo->is_new()) {
|
||||
$tipo->save();
|
||||
}
|
||||
$output = [
|
||||
'input' => $post,
|
||||
'tipo' => $tipo?->toArray()
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
}
|
132
api/common/Controller/TiposCategorias.php
Normal file
132
api/common/Controller/TiposCategorias.php
Normal file
@ -0,0 +1,132 @@
|
||||
<?php
|
||||
namespace Contabilidad\Common\Controller;
|
||||
|
||||
use Contabilidad\TipoCuenta;
|
||||
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\Common\Service\TiposCambios as Service;
|
||||
use Contabilidad\TipoCategoria;
|
||||
|
||||
class TiposCategorias {
|
||||
use Json;
|
||||
|
||||
public function __invoke(Request $request, Response $response, Factory $factory, Service $service): Response {
|
||||
$tipos = $factory->find(TipoCategoria::class)->many();
|
||||
if ($tipos !== null) {
|
||||
array_walk($tipos, function(&$item) use ($service) {
|
||||
$arr = $item->toArray();
|
||||
$arr['categorias'] = $item->categorias();
|
||||
if ($arr['categorias'] !== null) {
|
||||
$arr['categorias'] = array_map(function($item) {
|
||||
return $item->toArray();
|
||||
}, $item->categorias());
|
||||
}
|
||||
$arr['saldo'] = abs($item->saldo($service));
|
||||
$arr['totales'] = $item->getTotales($service);
|
||||
$item = $arr;
|
||||
});
|
||||
usort($tipos, function($a, $b) {
|
||||
return strcmp($a['descripcion'], $b['descripcion']);
|
||||
});
|
||||
}
|
||||
$output = [
|
||||
'tipos' => $tipos
|
||||
];
|
||||
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 = TipoCategoria::add($factory, $in);
|
||||
$results []= ['tipo' => $tipo?->toArray(), 'agregado' => $tipo?->save()];
|
||||
}
|
||||
} else {
|
||||
$tipo = TipoCategoria::add($factory, $input);
|
||||
$results []= ['tipo' => $tipo?->toArray(), 'agregado' => $tipo?->save()];
|
||||
}
|
||||
$output = [
|
||||
'input' => $input,
|
||||
'tipos' => $results
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function edit(Request $request, Response $response, Factory $factory, $tipo_id): Response {
|
||||
$tipo = $factory->find(TipoCategoria::class)->one($tipo_id);
|
||||
$output = [
|
||||
'input' => $tipo_id,
|
||||
'old' => $tipo->toArray()
|
||||
];
|
||||
$input = json_decode($request->getBody());
|
||||
$tipo->edit($input);
|
||||
$output['tipo'] = $tipo->toArray();
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function delete(Request $request, Response $response, Factory $factory, $tipo_id): Response {
|
||||
$tipo = $factory->find(TipoCategoria::class)->one($tipo_id);
|
||||
$output = [
|
||||
'input' => $tipo_id,
|
||||
'tipo' => $tipo->toArray(),
|
||||
'eliminado' => $tipo->delete()
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function categorias(Request $request, Response $response, Factory $factory, Service $service, $tipo_id): Response {
|
||||
$tipo = $factory->find(TipoCategoria::class)->one($tipo_id);
|
||||
$categorias = null;
|
||||
if ($tipo != null) {
|
||||
$categorias = $tipo->categorias();
|
||||
if ($categorias !== null) {
|
||||
array_walk($categorias, function(&$item) use ($service) {
|
||||
$arr = $item->toArray($service);
|
||||
$arr['totales'] = $item->getTotales($service);
|
||||
$item = $arr;
|
||||
});
|
||||
}
|
||||
}
|
||||
$output = [
|
||||
'input' => $tipo_id,
|
||||
'tipo' => $tipo?->toArray(),
|
||||
'categorias' => $categorias
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function balance(Request $request, Response $response, Factory $factory, Service $service): Response {
|
||||
$tipos = $factory->find(TipoCategoria::class)->many();
|
||||
$balance = array_reduce($tipos, function($sum, $item) use ($service) {
|
||||
$totales = $item->getTotales($service);
|
||||
if (!is_array($sum)) {
|
||||
$sum = [];
|
||||
}
|
||||
foreach ($totales as $p => $total) {
|
||||
if (!isset($sum[$p])) {
|
||||
$sum[$p] = 0;
|
||||
}
|
||||
$sum[$p] += $total;
|
||||
}
|
||||
return $sum;
|
||||
});
|
||||
/*$balance = array_reduce($tipos, function($sum, $item) use ($service) {
|
||||
$maps = ['activo', 'pasivo', 'ganancia', 'perdida'];
|
||||
foreach ($maps as $m) {
|
||||
$p = $m . 's';
|
||||
$t = ucfirst($m);
|
||||
if (!isset($sum[$p])) {
|
||||
$sum[$p] = 0;
|
||||
}
|
||||
$cuentas = $item->getCuentasOf($t);
|
||||
if ($cuentas === false or $cuentas === null) {
|
||||
continue;
|
||||
}
|
||||
$sum[$p] += array_reduce($cuentas, function($sum, $item) use($service) {
|
||||
return $sum + $item->saldo($service, true);
|
||||
});
|
||||
}
|
||||
return $sum;
|
||||
});*/
|
||||
return $this->withJson($response, $balance);
|
||||
}
|
||||
}
|
71
api/common/Controller/TiposCuentas.php
Normal file
71
api/common/Controller/TiposCuentas.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\TipoCuenta;
|
||||
|
||||
class TiposCuentas {
|
||||
use Json;
|
||||
|
||||
public function __invoke(Request $request, Response $response, Factory $factory): Response {
|
||||
$tipos = $factory->find(TipoCuenta::class)->array();
|
||||
if ($tipos) {
|
||||
usort($tipos, function($a, $b) {
|
||||
return strcmp($a['descripcion'], $b['descripcion']);
|
||||
});
|
||||
}
|
||||
$output = [
|
||||
'tipos' => $tipos
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function show(Request $request, Response $response, Factory $factory, $tipo_id): Response {
|
||||
$tipo = $factory->find(TipoCuenta::class)->one($tipo_id);
|
||||
$output = [
|
||||
'input' => $tipo_id,
|
||||
'tipo' => $tipo?->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 = TipoCuenta::add($factory, $in);
|
||||
$results []= ['tipo' => $tipo?->toArray(), 'agregado' => $tipo?->save()];
|
||||
}
|
||||
} else {
|
||||
$tipo = TipoCuenta::add($factory, $input);
|
||||
$results []= ['tipo' => $tipo?->toArray(), 'agregado' => $tipo?->save()];
|
||||
}
|
||||
$output = [
|
||||
'input' => $input,
|
||||
'tipos' => $results
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function edit(Request $request, Response $response, Factory $factory, $tipo_id): Response {
|
||||
$tipo = $factory->find(TipoCuenta::class)->one($tipo_id);
|
||||
$output = [
|
||||
'input' => $tipo_id,
|
||||
'old' => $tipo->toArray()
|
||||
];
|
||||
$input = json_decode($request->getBody());
|
||||
$tipo->edit($input);
|
||||
$output['tipo'] = $tipo->toArray();
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function delete(Request $request, Response $response, Factory $factory, $tipo_id): Response {
|
||||
$tipo = $factory->find(TipoCuenta::class)->one($tipo_id);
|
||||
$output = [
|
||||
'input' => $tipo_id,
|
||||
'tipo' => $tipo->toArray(),
|
||||
'eliminado' => $tipo->delete()
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
}
|
@ -5,24 +5,28 @@ 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\Common\Service\Queuer as Service;
|
||||
use Contabilidad\Transaccion;
|
||||
|
||||
class Transacciones {
|
||||
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 {
|
||||
$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 = [
|
||||
'transacciones' => $transacciones
|
||||
'transacciones' => $this->parseTransacciones($transacciones)
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
@ -52,17 +56,33 @@ class Transacciones {
|
||||
];
|
||||
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);
|
||||
$output = [
|
||||
'input' => $transaccion_id,
|
||||
'old' => $transaccion->toArray()
|
||||
];
|
||||
$old_cuentas = ['credito' => $transaccion->credito_id, 'debito_id' => $transaccion->debito_id];
|
||||
$input = json_decode($request->getBody());
|
||||
$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();
|
||||
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 {
|
||||
$transaccion = $factory->find(Transaccion::class)->one($transaccion_id);
|
||||
$output = [
|
||||
|
29
api/common/Middleware/Auth.php
Normal file
29
api/common/Middleware/Auth.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
namespace Contabilidad\Common\Middleware;
|
||||
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use Psr\Http\Server\RequestHandlerInterface as Handler;
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Psr\Http\Message\ResponseFactoryInterface as Factory;
|
||||
use Contabilidad\Common\Service\Auth as Service;
|
||||
|
||||
class Auth {
|
||||
protected Factory $factory;
|
||||
protected Service $service;
|
||||
public function __construct(Factory $factory, Service $service) {
|
||||
$this->factory = $factory;
|
||||
$this->service = $service;
|
||||
}
|
||||
public function __invoke(Request $request, Handler $handler): Response {
|
||||
if ($request->getMethod() == 'OPTIONS') {
|
||||
return $handler->handle($request);
|
||||
}
|
||||
if (!$this->service->isValid($request)) {
|
||||
$response = $this->factory->createResponse(401);
|
||||
$response->getBody()->write(json_encode(['message' => 'Invalid API KEY.']));
|
||||
return $response
|
||||
->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
return $handler->handle($request);
|
||||
}
|
||||
}
|
20
api/common/Middleware/Consolidar.php
Normal file
20
api/common/Middleware/Consolidar.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
namespace Contabilidad\Common\Middleware;
|
||||
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use Psr\Http\Server\RequestHandlerInterface as Handler;
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Contabilidad\Common\Service\Consolidar as ConsolidarService;
|
||||
|
||||
class Consolidar {
|
||||
protected $service;
|
||||
public function __construct(ConsolidarService $service) {
|
||||
$this->service = $service;
|
||||
}
|
||||
public function __invoke(Request $request, Handler $handler): Response {
|
||||
if (!$this->service->isConsolidado()) {
|
||||
$this->service->queue();
|
||||
}
|
||||
return $handler->handle($request);
|
||||
}
|
||||
}
|
49
api/common/Service/Auth.php
Normal file
49
api/common/Service/Auth.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
namespace Contabilidad\Common\Service;
|
||||
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
|
||||
class Auth {
|
||||
protected string $key;
|
||||
public function __construct(string $api_key) {
|
||||
$this->key = $api_key;
|
||||
}
|
||||
public function isValid(Request $request): bool {
|
||||
if ($request->hasHeader('Authorization')) {
|
||||
$sent_key = $this->getAuthKey($request->getHeader('Authorization'));
|
||||
return $this->key == $sent_key;
|
||||
}
|
||||
if (isset($request->getParsedBody()['api_key'])) {
|
||||
$sent_key = $request->getParsedBody()['api_key'];
|
||||
return $this->key == $sent_key;
|
||||
}
|
||||
$post = $request->getParsedBody() ?? json_decode($request->getBody());
|
||||
$sent_key = $this->getArrayKey($post);
|
||||
if ($sent_key !== null) {
|
||||
return $this->key == $sent_key;
|
||||
}
|
||||
$sent_key = $this->getArrayKey($request->getQueryParams());
|
||||
return $this->key == $sent_key;
|
||||
}
|
||||
protected function getAuthKey($auth) {
|
||||
if (is_array($auth)) {
|
||||
$auth = $auth[0];
|
||||
}
|
||||
if (str_contains($auth, 'Bearer')) {
|
||||
$auth = explode(' ', $auth)[1];
|
||||
}
|
||||
return $auth;
|
||||
}
|
||||
protected function getArrayKey($array) {
|
||||
$posible_keys = [
|
||||
'API_KEY',
|
||||
'api_key',
|
||||
];
|
||||
foreach ($posible_keys as $key) {
|
||||
if (isset($array[$key])) {
|
||||
return $array[$key];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
174
api/common/Service/Consolidar.php
Normal file
174
api/common/Service/Consolidar.php
Normal file
@ -0,0 +1,174 @@
|
||||
<?php
|
||||
namespace Contabilidad\Common\Service;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use \Model;
|
||||
use ProVM\Common\Factory\Model as ModelFactory;
|
||||
use Contabilidad\Consolidado;
|
||||
use Contabilidad\Cuenta;
|
||||
use Contabilidad\Transaccion;
|
||||
|
||||
class Consolidar {
|
||||
public function __construct(ModelFactory $factory, Queuer $queuer) {
|
||||
$this->setFactory($factory);
|
||||
$this->setQueuer($queuer);
|
||||
}
|
||||
protected ModelFactory $factory;
|
||||
public function setFactory(ModelFactory $factory): Consolidar {
|
||||
$this->factory = $factory;
|
||||
return $this;
|
||||
}
|
||||
protected Queuer $queuer;
|
||||
public function setQueuer(Queuer $queuer): Consolidar {
|
||||
$this->queuer = $queuer;
|
||||
return $this;
|
||||
}
|
||||
protected $cuentas;
|
||||
public function getCuentas() {
|
||||
if ($this->cuentas === null) {
|
||||
$this->cuentas = $this->factory->find(Cuenta::class)->many();
|
||||
}
|
||||
return $this->cuentas;
|
||||
}
|
||||
|
||||
public function isConsolidado(): bool {
|
||||
$cuentas = $this->getCuentas();
|
||||
if ($cuentas === null) {
|
||||
return true;
|
||||
}
|
||||
foreach ($cuentas as $cuenta) {
|
||||
$transacciones = $cuenta->hasTransacciones();
|
||||
if (!$transacciones) {
|
||||
continue;
|
||||
}
|
||||
$pendientes = $cuenta->hasConsolidadosPending();
|
||||
if ($pendientes) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public function queue() {
|
||||
$this->queuer->queue('consolidar');
|
||||
}
|
||||
public function consolidar() {
|
||||
ini_set('max_execution_time', 60*5);
|
||||
|
||||
foreach ($this->getCuentas() as $cuenta) {
|
||||
if (!$cuenta->hasTransacciones()) {
|
||||
continue;
|
||||
}
|
||||
$first = $this->getFirst($cuenta);
|
||||
$last = $this->getLast($cuenta);
|
||||
for ($current = $first->copy()->startOfMonth(); $current < $last->copy()->addMonthWithoutOverflow()->endOfMonth(); $current = $current->copy()->addMonthWithoutOverflow()) {
|
||||
$this->consolidarCuenta($cuenta, $current);
|
||||
}
|
||||
}
|
||||
}
|
||||
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 {
|
||||
$first = [
|
||||
Model::factory(Transaccion::class)
|
||||
->select('fecha')
|
||||
->whereEqual('debito_id', $cuenta->id)
|
||||
->orderByAsc('fecha')
|
||||
->findOne(),
|
||||
Model::factory(Transaccion::class)
|
||||
->select('fecha')
|
||||
->whereEqual('credito_id', $cuenta->id)
|
||||
->orderByAsc('fecha')
|
||||
->findOne()
|
||||
];
|
||||
if (!$first[0]) {
|
||||
if (!$first[1]) {
|
||||
return null;
|
||||
}
|
||||
return $first[1]->fecha();
|
||||
}
|
||||
if (!$first[1]) {
|
||||
return $first[0]->fecha();
|
||||
}
|
||||
if ($first[0]->fecha() < $first[1]->fecha()) {
|
||||
return $first[0]->fecha();
|
||||
}
|
||||
return $first[1]->fecha();
|
||||
}
|
||||
public function getLast(Cuenta $cuenta): ?Carbon {
|
||||
$fechas = [
|
||||
Model::factory(Transaccion::class)
|
||||
->select('fecha')
|
||||
->whereEqual('debito_id', $cuenta->id)
|
||||
->orderByDesc('fecha')
|
||||
->findOne(),
|
||||
Model::factory(Transaccion::class)
|
||||
->select('fecha')
|
||||
->whereEqual('credito_id', $cuenta->id)
|
||||
->orderByDesc('fecha')
|
||||
->findOne()
|
||||
];
|
||||
if (!$fechas[0]) {
|
||||
if (!$fechas[1]) {
|
||||
return null;
|
||||
}
|
||||
return $fechas[1]->fecha();
|
||||
}
|
||||
if (!$fechas[1]) {
|
||||
return $fechas[0]->fecha();
|
||||
}
|
||||
if ($fechas[0]->fecha() > $fechas[1]->fecha()) {
|
||||
return $fechas[0]->fecha();
|
||||
}
|
||||
return $fechas[1]->fecha();
|
||||
}
|
||||
public function getTransacciones(Cuenta $cuenta, Carbon $fecha) {
|
||||
$start = $fecha->copy()->startOfMonth();
|
||||
$end = $fecha->copy()->endOfMonth();
|
||||
$debitos = Model::factory(Transaccion::class)
|
||||
->whereEqual('debito_id', $cuenta->id)
|
||||
->whereRaw("fecha BETWEEN '{$start->format('Y-m-d')}' AND '{$end->format('Y-m-d')}'")
|
||||
->findMany();
|
||||
if ($debitos) {
|
||||
array_walk($debitos, function(&$item) {
|
||||
$item->valor *= -1;
|
||||
});
|
||||
}
|
||||
$creditos = Model::factory(Transaccion::class)
|
||||
->whereEqual('credito_id', $cuenta->id)
|
||||
->whereRaw("fecha BETWEEN '{$start->format('Y-m-d')}' AND '{$end->format('Y-m-d')}'")
|
||||
->findMany();
|
||||
$transacciones = array_merge($debitos, $creditos);
|
||||
foreach ($transacciones as &$transaccion) {
|
||||
$transaccion->setFactory($this->factory);
|
||||
}
|
||||
return $transacciones;
|
||||
}
|
||||
}
|
37
api/common/Service/CsvHandler.php
Normal file
37
api/common/Service/CsvHandler.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
namespace Contabilidad\Common\Service;
|
||||
|
||||
use Contabilidad\Common\Concept\DocumentHandler;
|
||||
|
||||
class CsvHandler extends DocumentHandler {
|
||||
public function load(): ?array {
|
||||
$folder = $this->folder;
|
||||
$files = new \DirectoryIterator($folder);
|
||||
$output = [];
|
||||
foreach ($files as $file) {
|
||||
if ($file->isDir() or $file->getExtension() != 'csv') {
|
||||
continue;
|
||||
}
|
||||
$bank = 'unknown';
|
||||
$text = trim(file_get_contents($file->getRealPath()));
|
||||
if (str_contains($text, 'SCOTIABANK')) {
|
||||
$bank = 'Scotiabank';
|
||||
}
|
||||
if (str_contains($text, 'BICE')) {
|
||||
$bank = 'BICE';
|
||||
}
|
||||
$data = explode(PHP_EOL, $text);
|
||||
array_walk($data, function(&$item) {
|
||||
$item = trim($item, '; ');
|
||||
if (str_contains($item, ';') !== false) {
|
||||
$item = explode(';', $item);
|
||||
}
|
||||
});
|
||||
$output []= ['bank' => $bank, 'filename' => $file->getBasename(), 'data' => $data];
|
||||
}
|
||||
return $this->build($output);
|
||||
}
|
||||
protected function build(array $data): ?array {
|
||||
return $data;
|
||||
}
|
||||
}
|
16
api/common/Service/DocumentHandler.php
Normal file
16
api/common/Service/DocumentHandler.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
namespace Contabilidad\Common\Service;
|
||||
|
||||
class DocumentHandler {
|
||||
protected array $handlers;
|
||||
public function __construct(array $handlers) {
|
||||
$this->handlers = $handlers;
|
||||
}
|
||||
public function handle(): array {
|
||||
$output = [];
|
||||
foreach ($this->handlers as $handler) {
|
||||
$output = array_merge($output, $handler->load());
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
}
|
112
api/common/Service/FileHandler.php
Normal file
112
api/common/Service/FileHandler.php
Normal file
@ -0,0 +1,112 @@
|
||||
<?php
|
||||
namespace Contabilidad\Common\Service;
|
||||
|
||||
use Psr\Http\Message\UploadedFileInterface;
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
use Nyholm\Psr7\Stream;
|
||||
|
||||
class FileHandler {
|
||||
protected $base_folder;
|
||||
protected $valid_types;
|
||||
protected $folders;
|
||||
public function __construct(object $params) {
|
||||
$this->base_folder = $params->folder;
|
||||
$this->addValidTypes(array_keys($params->types));
|
||||
$this->addFolders($params->types);
|
||||
}
|
||||
public function addFolders(array $folders): FileHandler {
|
||||
foreach ($folders as $type => $folder) {
|
||||
$this->addFolder($type, $folder);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
public function addFolder(string $type, string $folder): FileHandler {
|
||||
$this->folders[$type] = $folder;
|
||||
return $this;
|
||||
}
|
||||
public function addValidTypes(array $valid_types): FileHandler {
|
||||
foreach ($valid_types as $type) {
|
||||
$this->addValidType($type);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
public function addValidType(string $type): FileHandler {
|
||||
$this->valid_types []= $type;
|
||||
return $this;
|
||||
}
|
||||
public function getType(string $folder): string {
|
||||
return array_search($folder, $this->folders);
|
||||
}
|
||||
|
||||
public function uploadFile(UploadedFileInterface $file, string $new_name = null): bool {
|
||||
if ($file->getError() !== UPLOAD_ERR_OK) {
|
||||
return false;
|
||||
}
|
||||
if (!in_array($file->getClientMediaType(), $this->valid_types)) {
|
||||
return false;
|
||||
}
|
||||
if ($new_name === null) {
|
||||
$new_name = $file->getClientFilename();
|
||||
}
|
||||
$filenfo = new \SplFileInfo($file->getClientFilename());
|
||||
if (!str_contains($new_name, $filenfo->getExtension())) {
|
||||
$new_name .= '.' . $filenfo->getExtension();
|
||||
}
|
||||
$to = implode(DIRECTORY_SEPARATOR, [$this->base_folder, $this->folders[$file->getClientMediaType()], $new_name]);
|
||||
$file->moveTo($to);
|
||||
return file_exists($to);
|
||||
}
|
||||
public function listFiles(): array {
|
||||
$output = [];
|
||||
foreach ($this->folders as $f) {
|
||||
$folder = implode(DIRECTORY_SEPARATOR, [$this->base_folder, $f]);
|
||||
if (!file_exists($folder)) {
|
||||
continue;
|
||||
}
|
||||
$files = new \DirectoryIterator($folder);
|
||||
foreach ($files as $file) {
|
||||
if ($file->isDir()) {
|
||||
continue;
|
||||
}
|
||||
$output []= (object) ['folder' => $f, 'filename' => $file->getBasename()];
|
||||
}
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
protected function validateFilename(string $folder, string $filename): bool|string {
|
||||
if (!in_array($folder, $this->folders)) {
|
||||
return false;
|
||||
}
|
||||
$f = implode(DIRECTORY_SEPARATOR, [$this->base_folder, $folder, $filename]);
|
||||
if (!file_exists($f)) {
|
||||
return false;
|
||||
}
|
||||
return $f;
|
||||
}
|
||||
public function getInfo(string $folder, string $filename): \SplFileInfo|bool {
|
||||
if (!$f = $this->validateFilename($folder, $filename)) {
|
||||
return false;
|
||||
}
|
||||
return new \SplFileInfo($f);
|
||||
}
|
||||
public function getFile(string $folder, string $filename): StreamInterface|bool {
|
||||
if (!$f = $this->validateFilename($folder, $filename)) {
|
||||
return false;
|
||||
}
|
||||
return Stream::create(file_get_contents($f));
|
||||
}
|
||||
public function editFilename(string $folder, string $filename, string $new_name): bool {
|
||||
if (!$f = $this->validateFilename($folder, $filename)) {
|
||||
return false;
|
||||
}
|
||||
$info = new \SplFileInfo($f);
|
||||
$new = implode(DIRECTORY_SEPARATOR, [$this->base_folder, $folder, $new_name . '.' . $info->getExtension()]);
|
||||
return rename($f, $new);
|
||||
}
|
||||
public function deleteFile(string $folder, string $filename): bool {
|
||||
if (!$f = $this->validateFilename($folder, $filename)) {
|
||||
return false;
|
||||
}
|
||||
return unlink($f);
|
||||
}
|
||||
}
|
@ -1,15 +1,15 @@
|
||||
<?php
|
||||
namespace Contabilidad\Common\Service;
|
||||
|
||||
use Contabilidad\Common\Concept\DocumentHandler;
|
||||
use GuzzleHttp\Client;
|
||||
|
||||
class PdfHandler {
|
||||
class PdfHandler extends DocumentHandler {
|
||||
protected Client $client;
|
||||
protected string $folder;
|
||||
protected string $url;
|
||||
public function __construct(Client $client, string $pdf_folder, string $url) {
|
||||
parent::__construct($pdf_folder);
|
||||
$this->client = $client;
|
||||
$this->folder = $pdf_folder;
|
||||
$this->url = $url;
|
||||
}
|
||||
|
||||
@ -25,6 +25,51 @@ class PdfHandler {
|
||||
}
|
||||
$response = $this->client->post($this->url, ['json' => ['files' => $output]]);
|
||||
$output = json_decode($response->getBody());
|
||||
return $output;
|
||||
return $this->build($output);
|
||||
}
|
||||
protected function build(array $data): ?array {
|
||||
foreach ($data as &$file) {
|
||||
$i = $this->findStartRow($file->text);
|
||||
if ($i === -1) {
|
||||
continue;
|
||||
}
|
||||
$e = $this->findEndRow($file->text, $i);
|
||||
if ($e == $i) {
|
||||
continue;
|
||||
}
|
||||
$file->data = array_filter($file->text, function($key) use ($i, $e) {
|
||||
return ($key >= $i) and ($key <= $e);
|
||||
}, ARRAY_FILTER_USE_KEY);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
protected function findStartRow(array $data): int {
|
||||
foreach ($data as $i => $row) {
|
||||
if (!is_array($row)) {
|
||||
continue;
|
||||
}
|
||||
$maybe = false;
|
||||
foreach ($row as $cell) {
|
||||
if (str_contains($cell, '/')) {
|
||||
$maybe = true;
|
||||
}
|
||||
if ($maybe and str_contains($cell, '$')) {
|
||||
return $i - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
protected function findEndRow(array $data, int $start): int {
|
||||
$l = count($data[$start]);
|
||||
for ($i = $start; $i < count($data); $i ++) {
|
||||
if (!is_array($data[$i])) {
|
||||
return $i - 1;
|
||||
}
|
||||
if (count($data[$i]) != $l) {
|
||||
return $i - 1;
|
||||
}
|
||||
}
|
||||
return $start;
|
||||
}
|
||||
}
|
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;
|
||||
}
|
||||
}
|
93
api/common/Service/TiposCambios.php
Normal file
93
api/common/Service/TiposCambios.php
Normal file
@ -0,0 +1,93 @@
|
||||
<?php
|
||||
namespace Contabilidad\Common\Service;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Exception\ConnectException;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
use GuzzleHttp\Exception\ServerException;
|
||||
use ProVM\Common\Factory\Model as Factory;
|
||||
use Contabilidad\Moneda;
|
||||
use Contabilidad\TipoCambio;
|
||||
|
||||
class TiposCambios {
|
||||
protected $client;
|
||||
protected $factory;
|
||||
protected $base_url;
|
||||
protected $key;
|
||||
public function __construct(Client $client, Factory $factory, $api_url, $api_key) {
|
||||
$this->client = $client;
|
||||
$this->factory = $factory;
|
||||
$this->base_url = $api_url;
|
||||
$this->key = $api_key;
|
||||
}
|
||||
protected function getWeekday(\DateTimeInterface $fecha) {
|
||||
if ($fecha->weekday() == 0) {
|
||||
return $fecha->subWeek()->weekday(5);
|
||||
}
|
||||
if ($fecha->weekday() == 6) {
|
||||
return $fecha->weekday(5);
|
||||
}
|
||||
return $fecha;
|
||||
}
|
||||
protected function getValor(\DateTimeInterface $fecha, string $moneda_codigo) {
|
||||
$data = [
|
||||
'fecha' => $fecha->format('Y-m-d'),
|
||||
'desde' => $moneda_codigo
|
||||
];
|
||||
$headers = [
|
||||
'Authorization' => "Bearer {$this->key}"
|
||||
];
|
||||
$url = implode('/', [
|
||||
$this->base_url,
|
||||
'cambio',
|
||||
'get'
|
||||
]);
|
||||
try {
|
||||
$response = $this->client->request('POST', $url, ['json' => $data, 'headers' => $headers]);
|
||||
} catch (ConnectException | RequestException | ServerException $e) {
|
||||
error_log($e);
|
||||
return null;
|
||||
}
|
||||
if ($response->getStatusCode() !== 200) {
|
||||
error_log('Could not connect to python API.');
|
||||
return null;
|
||||
}
|
||||
$result = json_decode($response->getBody());
|
||||
if (isset($result->message) and $result->message === 'Not Authorized') {
|
||||
error_log('Not authorized for connecting to python API.');
|
||||
return null;
|
||||
}
|
||||
return $result->serie[0]->valor;
|
||||
}
|
||||
public function get(string $fecha, int $moneda_id) {
|
||||
$fecha = Carbon::parse($fecha);
|
||||
$moneda = $this->factory->find(Moneda::class)->one($moneda_id);
|
||||
if ($moneda->codigo == 'USD') {
|
||||
$fecha = $this->getWeekday($fecha);
|
||||
}
|
||||
// If a value exists in the database
|
||||
$cambio = $moneda->cambio($fecha);
|
||||
if ($cambio !== null) {
|
||||
if ($cambio->desde()->id != $moneda->id) {
|
||||
return 1 / $cambio->valor;
|
||||
}
|
||||
return $cambio->valor;
|
||||
}
|
||||
$valor = $this->getValor($fecha, $moneda->codigo);
|
||||
if ($valor === null) {
|
||||
return 1;
|
||||
}
|
||||
$data = [
|
||||
'fecha' => $fecha->format('Y-m-d H:i:s'),
|
||||
'desde_id' => $moneda->id,
|
||||
'hasta_id' => 1,
|
||||
'valor' => $valor
|
||||
];
|
||||
$tipo = TipoCambio::add($this->factory, $data);
|
||||
if ($tipo !== false and $tipo->is_new()) {
|
||||
$tipo->save();
|
||||
}
|
||||
return $valor;
|
||||
}
|
||||
}
|
60
api/common/Service/XlsHandler.php
Normal file
60
api/common/Service/XlsHandler.php
Normal file
@ -0,0 +1,60 @@
|
||||
<?php
|
||||
namespace Contabilidad\Common\Service;
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing;
|
||||
use thiagoalessio\TesseractOCR\TesseractOCR;
|
||||
use Contabilidad\Common\Concept\DocumentHandler;
|
||||
|
||||
class XlsHandler extends DocumentHandler {
|
||||
public function load(): ?array {
|
||||
$folder = $this->folder;
|
||||
$files = new \DirectoryIterator($folder);
|
||||
$output = [];
|
||||
foreach ($files as $file) {
|
||||
if ($file->isDir() or $file->getExtension() != 'xls') {
|
||||
continue;
|
||||
}
|
||||
$reader = IOFactory::createReader(ucfirst($file->getExtension()));
|
||||
$xls = $reader->load($file->getRealPath());
|
||||
$data = [];
|
||||
$bank = 'unknown';
|
||||
for ($s = 0; $s < $xls->getSheetCount(); $s ++) {
|
||||
$sheet = $xls->getSheet($s);
|
||||
foreach ($sheet->getRowIterator() as $row) {
|
||||
$r = [];
|
||||
foreach ($row->getCellIterator() as $cell) {
|
||||
$r []= $cell->getValue();
|
||||
}
|
||||
$data []= $r;
|
||||
}
|
||||
foreach ($sheet->getDrawingCollection() as $drawing) {
|
||||
if ($drawing instanceof MemoryDrawing) {
|
||||
ob_start();
|
||||
call_user_func(
|
||||
$drawing->getRenderingFunction(),
|
||||
$drawing->getImageResource()
|
||||
);
|
||||
$imageContents = ob_get_contents();
|
||||
$size = ob_get_length();
|
||||
ob_end_clean();
|
||||
$ocr = new TesseractOCR();
|
||||
$ocr->imageData($imageContents, $size);
|
||||
$image = $ocr->run();
|
||||
if (str_contains($image, 'BICE')) {
|
||||
$bank = 'BICE';
|
||||
}
|
||||
if (str_contains($image, 'Scotiabank')) {
|
||||
$bank = 'Scotiabank';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$output []= ['bank' => $bank, 'filename' => $file->getBasename(), 'data' => $data];
|
||||
}
|
||||
return $this->build($output);
|
||||
}
|
||||
protected function build(array $data): ?array {
|
||||
return $data;
|
||||
}
|
||||
}
|
@ -14,7 +14,9 @@
|
||||
"robmorgan/phinx": "^0.12.9",
|
||||
"odan/phinx-migrations-generator": "^5.4",
|
||||
"martin-mikac/csv-to-phinx-seeder": "^1.6",
|
||||
"guzzlehttp/guzzle": "^7.4"
|
||||
"guzzlehttp/guzzle": "^7.4",
|
||||
"phpoffice/phpspreadsheet": "^1.19",
|
||||
"thiagoalessio/tesseract_ocr": "^2.12"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^9.5",
|
||||
|
@ -20,6 +20,7 @@ final class TipoCuenta extends AbstractMigration
|
||||
{
|
||||
$this->table('tipos_cuenta')
|
||||
->addColumn('descripcion', 'string')
|
||||
->addColumn('color', 'string', ['length' => 6, 'default' => 'ffffff'])
|
||||
->create();
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ final class Categoria extends AbstractMigration
|
||||
$this->table('categorias')
|
||||
->addColumn('nombre', 'string')
|
||||
->addColumn('tipo_id', 'integer')
|
||||
->addForeignKey('tipo_id', 'tipos_categoria')
|
||||
->addForeignKey('tipo_id', 'tipos_categoria', ['delete' => 'cascade', 'update' => 'cascade'])
|
||||
->create();
|
||||
}
|
||||
}
|
||||
|
@ -21,9 +21,9 @@ final class Cuenta extends AbstractMigration
|
||||
$this->table('cuentas')
|
||||
->addColumn('nombre', 'string')
|
||||
->addColumn('categoria_id', 'integer')
|
||||
->addForeignKey('categoria_id', 'categorias')
|
||||
->addForeignKey('categoria_id', 'categorias', ['delete' => 'cascade', 'update' => 'cascade'])
|
||||
->addColumn('tipo_id', 'integer')
|
||||
->addForeignKey('tipo_id', 'tipos_cuenta')
|
||||
->addForeignKey('tipo_id', 'tipos_cuenta', ['delete' => 'cascade', 'update' => 'cascade'])
|
||||
->create();
|
||||
}
|
||||
}
|
||||
|
@ -20,10 +20,10 @@ final class EstadoConeccion extends AbstractMigration
|
||||
{
|
||||
$this->table('estados_coneccion')
|
||||
->addColumn('coneccion_id', 'integer')
|
||||
->addForeignKey('coneccion_id', 'conecciones')
|
||||
->addForeignKey('coneccion_id', 'conecciones', ['delete' => 'cascade', 'update' => 'cascade'])
|
||||
->addColumn('fecha', 'date')
|
||||
->addColumn('tipo_id', 'integer')
|
||||
->addForeignKey('tipo_id', 'tipos_estado_coneccion')
|
||||
->addForeignKey('tipo_id', 'tipos_estado_coneccion', ['delete' => 'cascade', 'update' => 'cascade'])
|
||||
->create();
|
||||
}
|
||||
}
|
||||
|
@ -20,9 +20,9 @@ final class Transaccion extends AbstractMigration
|
||||
{
|
||||
$this->table('transacciones')
|
||||
->addColumn('debito_id', 'integer')
|
||||
->addForeignKey('debito_id', 'cuentas')
|
||||
->addForeignKey('debito_id', 'cuentas', ['delete' => 'cascade', 'update' => 'cascade'])
|
||||
->addColumn('credito_id', 'integer')
|
||||
->addForeignKey('credito_id', 'cuentas')
|
||||
->addForeignKey('credito_id', 'cuentas', ['delete' => 'cascade', 'update' => 'cascade'])
|
||||
->addColumn('fecha', 'datetime')
|
||||
->addColumn('glosa', 'string')
|
||||
->addColumn('detalle', 'text')
|
||||
|
29
api/db/migrations/20211204205950_moneda.php
Normal file
29
api/db/migrations/20211204205950_moneda.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class Moneda extends AbstractMigration
|
||||
{
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* Write your reversible migrations using this method.
|
||||
*
|
||||
* More information on writing migrations is available here:
|
||||
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
|
||||
*
|
||||
* Remember to call "create()" or "update()" and NOT "save()" when working
|
||||
* with the Table class.
|
||||
*/
|
||||
public function change(): void
|
||||
{
|
||||
$this->table('monedas')
|
||||
->addColumn('denominacion', 'string')
|
||||
->addColumn('codigo', 'string', ['length' => 3])
|
||||
->addColumn('prefijo', 'string', ['default' => ''])
|
||||
->addColumn('sufijo', 'string', ['default' => ''])
|
||||
->addColumn('decimales', 'integer', ['default' => 0])
|
||||
->create();
|
||||
}
|
||||
}
|
26
api/db/migrations/20211204210207_cuenta_moneda.php
Normal file
26
api/db/migrations/20211204210207_cuenta_moneda.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class CuentaMoneda extends AbstractMigration
|
||||
{
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* Write your reversible migrations using this method.
|
||||
*
|
||||
* More information on writing migrations is available here:
|
||||
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
|
||||
*
|
||||
* Remember to call "create()" or "update()" and NOT "save()" when working
|
||||
* with the Table class.
|
||||
*/
|
||||
public function change(): void
|
||||
{
|
||||
$this->table('cuentas')
|
||||
->addColumn('moneda_id', 'integer')
|
||||
->addForeignKey('moneda_id', 'monedas', ['delete' => 'cascade', 'update' => 'cascade'])
|
||||
->update();
|
||||
}
|
||||
}
|
30
api/db/migrations/20211205002439_tipo_cambio.php
Normal file
30
api/db/migrations/20211205002439_tipo_cambio.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class TipoCambio extends AbstractMigration
|
||||
{
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* Write your reversible migrations using this method.
|
||||
*
|
||||
* More information on writing migrations is available here:
|
||||
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
|
||||
*
|
||||
* Remember to call "create()" or "update()" and NOT "save()" when working
|
||||
* with the Table class.
|
||||
*/
|
||||
public function change(): void
|
||||
{
|
||||
$this->table('tipos_cambio')
|
||||
->addColumn('fecha', 'datetime')
|
||||
->addColumn('desde_id', 'integer')
|
||||
->addForeignKey('desde_id', 'monedas', ['delete' => 'cascade', 'update' => 'cascade'])
|
||||
->addColumn('hasta_id', 'integer')
|
||||
->addForeignKey('hasta_id', 'monedas', ['delete' => 'cascade', 'update' => 'cascade'])
|
||||
->addColumn('valor', 'double')
|
||||
->create();
|
||||
}
|
||||
}
|
27
api/db/migrations/20220325185534_queue.php
Normal file
27
api/db/migrations/20220325185534_queue.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class Queue extends AbstractMigration
|
||||
{
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* Write your reversible migrations using this method.
|
||||
*
|
||||
* More information on writing migrations is available here:
|
||||
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
|
||||
*
|
||||
* Remember to call "create()" or "update()" and NOT "save()" when working
|
||||
* with the Table class.
|
||||
*/
|
||||
public function change(): void
|
||||
{
|
||||
$this->table('queue')
|
||||
->addColumn('command', 'string')
|
||||
->addColumn('created', 'datetime')
|
||||
->addColumn('processed', 'boolean', ['default' => 0])
|
||||
->create();
|
||||
}
|
||||
}
|
28
api/db/migrations/20220325185539_queue_arguments.php
Normal file
28
api/db/migrations/20220325185539_queue_arguments.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class QueueArguments extends AbstractMigration
|
||||
{
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* Write your reversible migrations using this method.
|
||||
*
|
||||
* More information on writing migrations is available here:
|
||||
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
|
||||
*
|
||||
* Remember to call "create()" or "update()" and NOT "save()" when working
|
||||
* with the Table class.
|
||||
*/
|
||||
public function change(): void
|
||||
{
|
||||
$this->table('queue_arguments')
|
||||
->addColumn('queue_id', 'integer')
|
||||
->addForeignKey('queue_id', 'queue', ['delete' => 'cascade', 'update' => 'cascade'])
|
||||
->addColumn('argument', 'string', ['length' => 100])
|
||||
->addColumn('value', 'string')
|
||||
->create();
|
||||
}
|
||||
}
|
29
api/db/migrations/20220325191129_consolidados.php
Normal file
29
api/db/migrations/20220325191129_consolidados.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class Consolidados extends AbstractMigration
|
||||
{
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* Write your reversible migrations using this method.
|
||||
*
|
||||
* More information on writing migrations is available here:
|
||||
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
|
||||
*
|
||||
* Remember to call "create()" or "update()" and NOT "save()" when working
|
||||
* with the Table class.
|
||||
*/
|
||||
public function change(): void
|
||||
{
|
||||
$this->table('consolidados')
|
||||
->addColumn('cuenta_id', 'integer')
|
||||
->addForeignKey('cuenta_id', 'cuentas', ['delete' => 'cascade', 'update' => 'cascade'])
|
||||
->addColumn('fecha', 'date')
|
||||
->addColumn('periodo', 'string', ['length' => 50])
|
||||
->addColumn('saldo', 'double')
|
||||
->create();
|
||||
}
|
||||
}
|
41
api/db/seeds/Moneda.php
Normal file
41
api/db/seeds/Moneda.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
|
||||
use Phinx\Seed\AbstractSeed;
|
||||
|
||||
class Moneda extends AbstractSeed
|
||||
{
|
||||
/**
|
||||
* Run Method.
|
||||
*
|
||||
* Write your database seeder using this method.
|
||||
*
|
||||
* More information on writing seeders is available here:
|
||||
* https://book.cakephp.org/phinx/0/en/seeding.html
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$data = [
|
||||
[
|
||||
'denominacion' => 'Pesos Chilenos',
|
||||
'codigo' => 'CLP',
|
||||
'prefijo' => '$ '
|
||||
],
|
||||
[
|
||||
'denominacion' => 'Dólar',
|
||||
'codigo' => 'USD',
|
||||
'prefijo' => 'US$ ',
|
||||
'decimales' => 2
|
||||
],
|
||||
[
|
||||
'denominacion' => 'Unidad de Fomento',
|
||||
'codigo' => 'CLF',
|
||||
'sufijo' => ' UF',
|
||||
'decimales' => 2
|
||||
]
|
||||
];
|
||||
$this->table('monedas')
|
||||
->insert($data)
|
||||
->saveData();
|
||||
}
|
||||
}
|
@ -5,25 +5,26 @@ server {
|
||||
access_log /var/log/nginx/access.log;
|
||||
root /app/public;
|
||||
|
||||
client_max_body_size 50M;
|
||||
|
||||
location / {
|
||||
try_files $uri $uri/ /index.php?$query_string;
|
||||
}
|
||||
|
||||
location ~ \.php$ {
|
||||
|
||||
if ($request_method = 'OPTIONS') {
|
||||
add_header 'Access-Control-Max-Age' 1728000;
|
||||
add_header 'Access-Control-Allow-Origin' '*';
|
||||
add_header 'Access-Control-Allow-Headers' 'Authorization,Accept,Origin,DNT,X-CustomHeader,Keep-Alive,User-Agent,
|
||||
X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
|
||||
add_header 'Access-Control-Allow-Headers' 'Authorization,Accept,Origin,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
|
||||
add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS,PUT,DELETE,PATCH';
|
||||
add_header 'Access-Control-Max-Age' 1728000;
|
||||
add_header 'Content-Type' 'application/json';
|
||||
add_header 'Content-Length' 0;
|
||||
return 204;
|
||||
}
|
||||
|
||||
add_header 'Access-Control-Allow-Origin' '*';
|
||||
add_header 'Access-Control-Allow-Headers' 'Authorization,Accept,Origin,DNT,X-CustomHeader,Keep-Alive,User-Agent,
|
||||
X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
|
||||
add_header 'Access-Control-Allow-Headers' 'Authorization,Accept,Origin,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
|
||||
add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS,PUT,DELETE,PATCH';
|
||||
|
||||
try_files $uri =404;
|
||||
|
@ -1,2 +1,4 @@
|
||||
log_errors = true
|
||||
error_log = /var/log/php/error.log
|
||||
error_log = /var/log/php/error.log
|
||||
upload_max_filesize = 50M
|
||||
max_input_vars = 5000
|
||||
|
@ -1,7 +1,13 @@
|
||||
<?php
|
||||
require_once implode(DIRECTORY_SEPARATOR, [
|
||||
dirname(__DIR__),
|
||||
'setup',
|
||||
'app.php'
|
||||
]);
|
||||
$app->run();
|
||||
try {
|
||||
ini_set('error_reporting', E_ALL & ~E_NOTICE & ~E_DEPRECATED);
|
||||
$app = require_once implode(DIRECTORY_SEPARATOR, [
|
||||
dirname(__DIR__),
|
||||
'setup',
|
||||
'app.php'
|
||||
]);
|
||||
$app->run();
|
||||
} catch (Error | Exception $e) {
|
||||
error_log($e);
|
||||
throw $e;
|
||||
}
|
||||
|
Binary file not shown.
Binary file not shown.
@ -1,4 +1,7 @@
|
||||
<?php
|
||||
use Contabilidad\Common\Controller\Base;
|
||||
|
||||
$app->get('/key/generate[/]', [Base::class, 'generate_key']);
|
||||
$app->get('/balance[/]', [Contabilidad\Common\Controller\TiposCategorias::class, 'balance']);
|
||||
$app->get('/info', [Base::class, 'info']);
|
||||
$app->get('/', Base::class);
|
||||
|
7
api/resources/routes/consolidar.php
Normal file
7
api/resources/routes/consolidar.php
Normal file
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
use Contabilidad\Common\Controller\Consolidados;
|
||||
|
||||
$app->group('/consolidar', function($app) {
|
||||
$app->get('/update/{mes}/{cuenta_id}', [Consolidados::class, 'update']);
|
||||
$app->get('[/]', [Consolidados::class, 'cli']);
|
||||
});
|
@ -9,8 +9,11 @@ $app->group('/cuenta/{cuenta_id}', function($app) {
|
||||
$app->get('/entradas', [Cuentas::class, 'entradas']);
|
||||
$app->group('/transacciones', function($app) {
|
||||
$app->get('/amount', [Cuentas::class, 'transaccionesAmount']);
|
||||
$app->get('/month/{month}', [Cuentas::class, 'transaccionesMonth']);
|
||||
$app->get('/acum/{date}', [Cuentas::class, 'transaccionesAcumulation']);
|
||||
$app->get('[/{limit:[0-9]+}[/{start:[0-9]+}]]', [Cuentas::class, 'transacciones']);
|
||||
});
|
||||
$app->get('/categoria', [Cuentas::class, 'categoria']);
|
||||
$app->put('/edit', [Cuentas::class, 'edit']);
|
||||
$app->delete('/delete', [Cuentas::class, 'delete']);
|
||||
$app->get('[/]', [Cuentas::class, 'show']);
|
||||
|
12
api/resources/routes/monedas.php
Normal file
12
api/resources/routes/monedas.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
use Contabilidad\Common\Controller\Monedas;
|
||||
|
||||
$app->group('/monedas', function($app) {
|
||||
$app->post('/add[/]', [Monedas::class, 'add']);
|
||||
$app->get('[/]', Monedas::class);
|
||||
});
|
||||
$app->group('/moneda/{moneda_id}', function($app) {
|
||||
$app->put('/edit', [Monedas::class, 'edit']);
|
||||
$app->delete('/delete', [Monedas::class, 'delete']);
|
||||
$app->get('[/]', [Monedas::class, 'show']);
|
||||
});
|
8
api/resources/routes/queues.php
Normal file
8
api/resources/routes/queues.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
use Contabilidad\Common\Controller\Queues;
|
||||
|
||||
$app->group('/queues', function($app) {
|
||||
$app->get('/pending', [Queues::class, 'pending']);
|
||||
$app->post('/processed', [Queues::class, 'processed']);
|
||||
$app->get('[/]', Queues::class);
|
||||
});
|
16
api/resources/routes/tipos.php
Normal file
16
api/resources/routes/tipos.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
$folder = implode(DIRECTORY_SEPARATOR, [
|
||||
__DIR__,
|
||||
'tipos'
|
||||
]);
|
||||
if (file_exists($folder)) {
|
||||
$app->group('/tipos', function($app) use ($folder) {
|
||||
$files = new DirectoryIterator($folder);
|
||||
foreach ($files as $file) {
|
||||
if ($file->isDir() or $file->getExtension() != 'php') {
|
||||
continue;
|
||||
}
|
||||
include_once $file->getRealPath();
|
||||
}
|
||||
});
|
||||
}
|
13
api/resources/routes/tipos/cambios.php
Normal file
13
api/resources/routes/tipos/cambios.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
use Contabilidad\Common\Controller\TiposCambios;
|
||||
|
||||
$app->group('/cambios', function($app) {
|
||||
$app->post('/obtener[/]', [TiposCambios::class, 'obtain']);
|
||||
$app->post('/add[/]', [TiposCambios::class, 'add']);
|
||||
$app->get('[/]', TiposCambios::class);
|
||||
});
|
||||
$app->group('/cambio/{tipo_id}', function($app) {
|
||||
$app->put('/edit[/]', [TiposCambios::class, 'edit']);
|
||||
$app->delete('/delete[/]', [TiposCambios::class, 'delete']);
|
||||
$app->get('[/]', [TiposCambios::class, 'show']);
|
||||
});
|
13
api/resources/routes/tipos/categorias.php
Normal file
13
api/resources/routes/tipos/categorias.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
use Contabilidad\Common\Controller\TiposCategorias;
|
||||
|
||||
$app->group('/categorias', function($app) {
|
||||
$app->post('/add[/]', [TiposCategorias::class, 'add']);
|
||||
$app->get('[/]', TiposCategorias::class);
|
||||
});
|
||||
$app->group('/categoria/{tipo_id}', function($app) {
|
||||
$app->get('/categorias', [TiposCategorias::class, 'categorias']);
|
||||
$app->put('/edit', [TiposCategorias::class, 'edit']);
|
||||
$app->delete('/delete', [TiposCategorias::class, 'delete']);
|
||||
$app->get('[/]', [TiposCategorias::class, 'show']);
|
||||
});
|
12
api/resources/routes/tipos/cuentas.php
Normal file
12
api/resources/routes/tipos/cuentas.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
use Contabilidad\Common\Controller\TiposCuentas;
|
||||
|
||||
$app->group('/cuentas', function($app) {
|
||||
$app->post('/add[/]', [TiposCuentas::class, 'add']);
|
||||
$app->get('[/]', TiposCuentas::class);
|
||||
});
|
||||
$app->group('/cuenta/{tipo_id}', function($app) {
|
||||
$app->put('/edit', [TiposCuentas::class, 'edit']);
|
||||
$app->delete('/delete', [TiposCuentas::class, 'delete']);
|
||||
$app->get('[/]', [TiposCuentas::class, 'show']);
|
||||
});
|
@ -2,11 +2,11 @@
|
||||
use Contabilidad\Common\Controller\Transacciones;
|
||||
|
||||
$app->group('/transacciones', function($app) {
|
||||
$app->post('/add[/]', [Transacciones::class, 'add']);
|
||||
$app->get('[/]', Transacciones::class);
|
||||
$app->post('/add[/]', [Transacciones::class, 'add']);
|
||||
$app->get('[/]', Transacciones::class);
|
||||
});
|
||||
$app->group('/transaccion/{transaccion_id}', function($app) {
|
||||
$app->put('/edit', [Transacciones::class, 'edit']);
|
||||
$app->delete('/delete', [Transacciones::class, 'delete']);
|
||||
$app->get('[/]', [Transacciones::class, 'show']);
|
||||
$app->put('/edit', [Transacciones::class, 'edit']);
|
||||
$app->delete('/delete', [Transacciones::class, 'delete']);
|
||||
$app->get('[/]', [Transacciones::class, 'show']);
|
||||
});
|
||||
|
12
api/resources/routes/uploads.php
Normal file
12
api/resources/routes/uploads.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
use Contabilidad\Common\Controller\Files;
|
||||
|
||||
$app->group('/uploads', function($app) {
|
||||
$app->post('/add[/]', [Files::class, 'upload']);
|
||||
$app->get('[/]', Files::class);
|
||||
});
|
||||
$app->group('/upload/{folder}/{filename}', function($app) {
|
||||
$app->put('[/]', [Files::class, 'edit']);
|
||||
$app->delete('[/]', [Files::class, 'delete']);
|
||||
$app->get('[/]', [Files::class, 'get']);
|
||||
});
|
@ -31,7 +31,7 @@ $app->addRoutingMiddleware();
|
||||
$app->add(new WhoopsMiddleware());
|
||||
|
||||
|
||||
$folder = 'middlewares';
|
||||
$folder = implode(DIRECTORY_SEPARATOR, [__DIR__, 'middlewares']);
|
||||
if (file_exists($folder)) {
|
||||
$files = new DirectoryIterator($folder);
|
||||
foreach ($files as $file) {
|
||||
@ -44,3 +44,5 @@ if (file_exists($folder)) {
|
||||
|
||||
include_once 'databases.php';
|
||||
include_once 'router.php';
|
||||
|
||||
return $app;
|
||||
|
4
api/setup/middlewares/01_auth.php
Normal file
4
api/setup/middlewares/01_auth.php
Normal file
@ -0,0 +1,4 @@
|
||||
<?php
|
||||
use Contabilidad\Common\Middleware\Auth;
|
||||
|
||||
$app->add($app->getContainer()->get(Auth::class));
|
4
api/setup/middlewares/03_consolidar.php
Normal file
4
api/setup/middlewares/03_consolidar.php
Normal file
@ -0,0 +1,4 @@
|
||||
<?php
|
||||
use Contabilidad\Common\Middleware\Consolidar;
|
||||
|
||||
$app->add(new Consolidar($app->getContainer()->get(\Contabilidad\Common\Service\Consolidar::class)));
|
@ -1,4 +1,7 @@
|
||||
<?php
|
||||
return [
|
||||
'debug' => $_ENV['DEBUG'] ?? false
|
||||
'debug' => $_ENV['DEBUG'] ?? false,
|
||||
'api_key' => $_ENV['API_KEY'],
|
||||
'python_api' => $_ENV['PYTHON_API'] ?? 'http://python:5000',
|
||||
'python_key' => $_ENV['PYTHON_KEY']
|
||||
];
|
||||
|
@ -19,13 +19,21 @@ return [
|
||||
'public'
|
||||
]);
|
||||
$arr['uploads'] = implode(DIRECTORY_SEPARATOR, [
|
||||
$arr['public'],
|
||||
$arr['base'],
|
||||
'uploads'
|
||||
]);
|
||||
$arr['pdfs'] = implode(DIRECTORY_SEPARATOR, [
|
||||
$arr['uploads'],
|
||||
'pdfs'
|
||||
]);
|
||||
$arr['csvs'] = implode(DIRECTORY_SEPARATOR, [
|
||||
$arr['uploads'],
|
||||
'csvs'
|
||||
]);
|
||||
$arr['xlss'] = implode(DIRECTORY_SEPARATOR, [
|
||||
$arr['uploads'],
|
||||
'xlss'
|
||||
]);
|
||||
return (object) $arr;
|
||||
},
|
||||
'urls' => function(Container $c) {
|
||||
|
@ -2,14 +2,57 @@
|
||||
use Psr\Container\ContainerInterface as Container;
|
||||
|
||||
return [
|
||||
GuzzleHttp\Client::class => function(Container $c) {
|
||||
return new GuzzleHttp\Client();
|
||||
},
|
||||
Contabilidad\Common\Service\PdfHandler::class => function(Container $c) {
|
||||
return new Contabilidad\Common\Service\PdfHandler($c->get(GuzzleHttp\Client::class), $c->get('folders')->pdfs, implode('/', [
|
||||
$c->get('urls')->python,
|
||||
'pdf',
|
||||
'parse'
|
||||
]));
|
||||
}
|
||||
GuzzleHttp\Client::class => function(Container $c) {
|
||||
return new GuzzleHttp\Client();
|
||||
},
|
||||
Contabilidad\Common\Service\Auth::class => function(Container $c) {
|
||||
return new Contabilidad\Common\Service\Auth($c->get('api_key'));
|
||||
},
|
||||
Contabilidad\Common\Middleware\Auth::class => function(Container $c) {
|
||||
return new Contabilidad\Common\Middleware\Auth(
|
||||
$c->get(Nyholm\Psr7\Factory\Psr17Factory::class),
|
||||
$c->get(Contabilidad\Common\Service\Auth::class)
|
||||
);
|
||||
},
|
||||
Contabilidad\Common\Service\PdfHandler::class => function(Container $c) {
|
||||
return new Contabilidad\Common\Service\PdfHandler($c->get(GuzzleHttp\Client::class), $c->get('folders')->pdfs, implode('/', [
|
||||
$c->get('urls')->python,
|
||||
'pdf',
|
||||
'parse'
|
||||
]));
|
||||
},
|
||||
Contabilidad\Common\Service\CsvHandler::class => function(Container $c) {
|
||||
return new Contabilidad\Common\Service\CsvHandler($c->get('folders')->csvs);
|
||||
},
|
||||
Contabilidad\Common\Service\XlsHandler::class => function(Container $c) {
|
||||
return new Contabilidad\Common\Service\XlsHandler($c->get('folders')->xlss);
|
||||
},
|
||||
Contabilidad\Common\Service\DocumentHandler::class => function(Container $c) {
|
||||
$handlers = [
|
||||
$c->get(Contabilidad\Common\Service\XlsHandler::class),
|
||||
$c->get(Contabilidad\Common\Service\CsvHandler::class),
|
||||
$c->get(Contabilidad\Common\Service\PdfHandler::class)
|
||||
];
|
||||
return new Contabilidad\Common\Service\DocumentHandler($handlers);
|
||||
},
|
||||
Contabilidad\Common\Service\TiposCambios::class => function(Container $c) {
|
||||
return new Contabilidad\Common\Service\TiposCambios(
|
||||
$c->get(GuzzleHttp\Client::class),
|
||||
$c->get(ProVM\Common\Factory\Model::class),
|
||||
$c->get('python_api'),
|
||||
$c->get('python_key')
|
||||
);
|
||||
},
|
||||
Contabilidad\Common\Service\FileHandler::class => function(Container $c) {
|
||||
return new Contabilidad\Common\Service\FileHandler((object) [
|
||||
'folder' => $c->get('folders')->uploads,
|
||||
'types' => [
|
||||
'text/csv' => 'csvs',
|
||||
'application/pdf' => 'pdfs',
|
||||
'application/vnd.ms-excel' => 'xlss',
|
||||
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'xlss',
|
||||
'application/json' => 'jsons'
|
||||
]
|
||||
]);
|
||||
}
|
||||
];
|
||||
|
11
api/setup/setups/03_consolidar.php
Normal file
11
api/setup/setups/03_consolidar.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
use Psr\Container\ContainerInterface as Container;
|
||||
|
||||
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) {
|
||||
return new \Contabilidad\Common\Service\Consolidar($container->get(\ProVM\Common\Factory\Model::class), $container->get(\Contabilidad\Common\Service\Queuer::class));
|
||||
}
|
||||
];
|
@ -1,7 +1,9 @@
|
||||
<?php
|
||||
namespace Contabilidad;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use ProVM\Common\Alias\Model;
|
||||
use Contabilidad\Common\Service\TiposCambios as Service;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
@ -10,12 +12,17 @@ use ProVM\Common\Alias\Model;
|
||||
*/
|
||||
class Categoria extends Model {
|
||||
public static $_table = 'categorias';
|
||||
protected static $fields = ['nombre'];
|
||||
protected static $fields = ['nombre', 'tipo_id'];
|
||||
|
||||
protected $cuentas;
|
||||
public function cuentas() {
|
||||
if ($this->cuentas === null) {
|
||||
$this->cuentas = $this->parentOf(Cuenta::class, [Model::CHILD_KEY => 'categoria_id']);
|
||||
if ($this->cuentas !== null) {
|
||||
usort($this->cuentas, function($a, $b) {
|
||||
return strcmp($a->nombre, $b->nombre);
|
||||
});
|
||||
}
|
||||
}
|
||||
return $this->cuentas;
|
||||
}
|
||||
@ -27,24 +34,80 @@ class Categoria extends Model {
|
||||
return $this->tipo;
|
||||
}
|
||||
|
||||
public function getCuentasOf($tipo) {
|
||||
return $this->factory->find(Cuenta::class)
|
||||
->select([['cuentas', '*']])
|
||||
->join([
|
||||
['tipos_cuenta', 'tipos_cuenta.id', 'cuentas.tipo_id']
|
||||
])
|
||||
->where([
|
||||
['tipos_cuenta.descripcion', $tipo],
|
||||
['cuentas.categoria_id', $this->id]
|
||||
])
|
||||
->many();
|
||||
}
|
||||
protected $cuentas_of;
|
||||
public function getCuentas() {
|
||||
if ($this->cuentas_of === null) {
|
||||
$tipos = $this->factory->find(TipoCuenta::class)->many();
|
||||
$cos = [];
|
||||
foreach ($tipos as $tipo) {
|
||||
$p = strtolower($tipo->descripcion) . 's';
|
||||
$cos[$p] = [];
|
||||
$cuentas = $this->getCuentasOf($tipos->descripcion);
|
||||
if ($cuentas === null) {
|
||||
continue;
|
||||
}
|
||||
$cos[$p] = $cuentas;
|
||||
}
|
||||
$this->cuentas_of = $cos;
|
||||
}
|
||||
return $this->cuentas_of;
|
||||
}
|
||||
protected $totales;
|
||||
public function getTotales(Service $service) {
|
||||
if ($this->totales === null) {
|
||||
$tipos = $this->factory->find(TipoCuenta::class)->many();
|
||||
$totals = [];
|
||||
foreach ($tipos as $tipo) {
|
||||
$p = strtolower($tipo->descripcion) . 's';
|
||||
$totals[$p] = 0;
|
||||
$cuentas = $this->getCuentasOf($tipo->descripcion);
|
||||
if ($cuentas === null) {
|
||||
continue;
|
||||
}
|
||||
$totals[$p] = array_reduce($cuentas, function($sum, $item) use ($service) {
|
||||
return $sum + $item->saldo($service, true);
|
||||
});
|
||||
}
|
||||
$this->totales = $totals;
|
||||
}
|
||||
return $this->totales;
|
||||
}
|
||||
|
||||
protected $saldo;
|
||||
public function saldo() {
|
||||
public function saldo(Service $service = null) {
|
||||
if ($this->saldo === null) {
|
||||
$this->saldo = 0;
|
||||
if ($this->cuentas() !== null) {
|
||||
$this->saldo = array_reduce($this->cuentas(), function($sum, $item) {
|
||||
return $sum + $item->saldo();
|
||||
});
|
||||
$sum = 0;
|
||||
$debitos = ['Activo', 'Perdida'];
|
||||
foreach ($this->cuentas() as $cuenta) {
|
||||
if (array_search($cuenta->tipo()->descripcion, $debitos) !== false) {
|
||||
$sum -= $cuenta->saldo($service, true);
|
||||
continue;
|
||||
}
|
||||
$sum += $cuenta->saldo($service, true);
|
||||
}
|
||||
$this->saldo = $sum;
|
||||
}
|
||||
}
|
||||
return $this->saldo;
|
||||
}
|
||||
|
||||
public function toArray(): array {
|
||||
$arr = parent::toArray();
|
||||
$arr['tipo'] = $this->tipo()->toArray();
|
||||
$arr['saldo'] = $this->saldo();
|
||||
$arr['saldoFormateado'] = '$' . number_format($this->saldo(), 0, ',', '.');
|
||||
return $arr;
|
||||
$arr = parent::toArray();
|
||||
$arr['tipo'] = $this->tipo()->toArray();
|
||||
return $arr;
|
||||
}
|
||||
}
|
||||
|
48
api/src/Consolidado.php
Normal file
48
api/src/Consolidado.php
Normal file
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
namespace Contabilidad;
|
||||
|
||||
use DateTimeInterface;
|
||||
use DateInterval;
|
||||
use Carbon\Carbon;
|
||||
use Carbon\CarbonInterval;
|
||||
use ProVM\Common\Alias\Model;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property Cuenta $cuenta_id
|
||||
* @property DateTimeInterface $fecha
|
||||
* @property DateInterval $periodo
|
||||
* @property float $saldo
|
||||
*/
|
||||
class Consolidado extends Model {
|
||||
public static $_table = 'consolidados';
|
||||
|
||||
protected $cuenta;
|
||||
public function cuenta() {
|
||||
if ($this->cuenta === null) {
|
||||
$this->cuenta = $this->childOf(Cuenta::class, [Model::SELF_KEY => 'cuenta_id']);
|
||||
}
|
||||
return $this->cuenta;
|
||||
}
|
||||
public function fecha(DateTimeInterface $fecha = null) {
|
||||
if ($fecha === null) {
|
||||
return Carbon::parse($this->fecha);
|
||||
}
|
||||
if ($this->periodo()->days > 31) {
|
||||
$this->fecha = $fecha->format('Y-1-1');
|
||||
} else {
|
||||
$this->fecha = $fecha->format('Y-m-1');
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
public function periodo(DateInterval $periodo = null) {
|
||||
if ($periodo === null) {
|
||||
return new CarbonInterval($this->periodo);
|
||||
}
|
||||
$this->periodo = CarbonInterval::getDateIntervalSpec($periodo);
|
||||
return $this;
|
||||
}
|
||||
public function saldo() {
|
||||
return $this->saldo;
|
||||
}
|
||||
}
|
@ -1,17 +1,20 @@
|
||||
<?php
|
||||
namespace Contabilidad;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use ProVM\Common\Alias\Model;
|
||||
use Contabilidad\Common\Service\TiposCambios as Service;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property string $nombre
|
||||
* @property Categoria $categoria_id
|
||||
* @property TipoCuenta $tipo_id
|
||||
* @property Moneda $moneda_id
|
||||
*/
|
||||
class Cuenta extends Model {
|
||||
public static $_table = 'cuentas';
|
||||
protected static $fields = ['nombre', 'categoria_id', 'tipo_id'];
|
||||
protected static $fields = ['nombre', 'categoria_id', 'tipo_id', 'moneda_id'];
|
||||
|
||||
protected $categoria;
|
||||
public function categoria() {
|
||||
@ -20,67 +23,173 @@ class Cuenta extends Model {
|
||||
}
|
||||
return $this->categoria;
|
||||
}
|
||||
protected $cuenta;
|
||||
public function cuenta() {
|
||||
if ($this->cuenta === null) {
|
||||
$this->cuenta = $this->childOf(TipoCuenta::class, [Model::SELF_KEY => 'tipo_id']);
|
||||
protected $tipo;
|
||||
public function tipo() {
|
||||
if ($this->tipo === null) {
|
||||
$this->tipo = $this->childOf(TipoCuenta::class, [Model::SELF_KEY => 'tipo_id']);
|
||||
}
|
||||
return $this->cuenta;
|
||||
return $this->tipo;
|
||||
}
|
||||
protected $moneda;
|
||||
public function moneda() {
|
||||
if ($this->moneda === null) {
|
||||
$this->moneda = $this->childOf(Moneda::class, [Model::SELF_KEY => 'moneda_id']);
|
||||
}
|
||||
return $this->moneda;
|
||||
}
|
||||
|
||||
protected $cargos;
|
||||
public function cargos() {
|
||||
if ($this->cargos === null) {
|
||||
$this->cargos = $this->parentOf(Transaccion::class, [Model::CHILD_KEY => 'hasta_id']);
|
||||
$this->cargos = $this->parentOf(Transaccion::class, [Model::CHILD_KEY => 'credito_id']);
|
||||
}
|
||||
return $this->cargos;
|
||||
}
|
||||
protected $abonos;
|
||||
public function abonos() {
|
||||
if ($this->abonos === null) {
|
||||
$this->abonos = $this->parentOf(Transaccion::class, [Model::CHILD_KEY => 'desde_id']);
|
||||
$this->abonos = $this->parentOf(Transaccion::class, [Model::CHILD_KEY => 'debito_id']);
|
||||
}
|
||||
return $this->abonos;
|
||||
}
|
||||
protected $consolidados;
|
||||
public function consolidados() {
|
||||
if ($this->consolidados === null) {
|
||||
$this->consolidados = $this->parentOf(Consolidado::class, [Model::CHILD_KEY => 'cuenta_id']);
|
||||
}
|
||||
return $this->consolidados;
|
||||
}
|
||||
public function hasConsolidados(\DateTimeInterface $mes = null): bool {
|
||||
$t = Carbon::now();
|
||||
$q = Model::factory(Consolidado::class)
|
||||
->whereEqual('cuenta_id', $this->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(\DateTimeInterface $mes = null): bool {
|
||||
$t = Carbon::now();
|
||||
$q = Model::factory(Consolidado::class)
|
||||
->whereEqual('cuenta_id', $this->id)
|
||||
->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')
|
||||
->count('id');
|
||||
}
|
||||
public function hasTransacciones(\DateTimeInterface $mes = null): bool {
|
||||
$q = Model::factory(Transaccion::class)
|
||||
->select('transacciones.*')
|
||||
->join('cuentas', 'cuentas.id = transacciones.debito_id OR cuentas.id = transacciones.credito_id')
|
||||
->whereEqual('cuentas.id', $this->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 function parseTransaccion(Transaccion $transaccion) {
|
||||
$transaccion->setFactory($this->factory);
|
||||
if ($this->tipo()->cargo()) {
|
||||
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());
|
||||
return $transaccion;
|
||||
}
|
||||
public function transacciones($limit = null, $start = 0) {
|
||||
if ($this->transacciones === null) {
|
||||
$transacciones = Model::factory(Transaccion::class)
|
||||
->join('cuentas', 'cuentas.id = transacciones.desde_id OR cuentas.id = transacciones.hasta_id')
|
||||
->select('transacciones.*')
|
||||
->join('cuentas', 'cuentas.id = transacciones.debito_id OR cuentas.id = transacciones.credito_id')
|
||||
->whereEqual('cuentas.id', $this->id)
|
||||
->orderByAsc('transacciones.fecha');
|
||||
if ($limit !== null) {
|
||||
$transacciones = $transacciones->limit($limit)
|
||||
->offset($start);
|
||||
}
|
||||
$this->transacciones = $transacciones->findMany();
|
||||
foreach ($this->transacciones as &$transaccion) {
|
||||
$transaccion->setFactory($this->factory);
|
||||
if ($transaccion->desde_id === $this->id) {
|
||||
$transaccion->valor = - $transaccion->valor;
|
||||
}
|
||||
$transacciones = $transacciones->findMany();
|
||||
foreach ($transacciones as &$transaccion) {
|
||||
$transaccion = $this->parseTransaccion($transaccion);
|
||||
}
|
||||
}
|
||||
return $this->transacciones;
|
||||
return $transacciones;
|
||||
}
|
||||
public function transaccionesMonth(Carbon $month) {
|
||||
$start = $month->copy()->startOfMonth();
|
||||
$end = $month->copy()->endOfMonth();
|
||||
|
||||
$transacciones = Model::factory(Transaccion::class)
|
||||
->select('transacciones.*')
|
||||
->join('cuentas', 'cuentas.id = transacciones.debito_id OR cuentas.id = transacciones.credito_id')
|
||||
->whereEqual('cuentas.id', $this->id)
|
||||
->whereRaw("transacciones.fecha BETWEEN '{$start->format('Y-m-d')}' AND '{$end->format('Y-m-d')}'")
|
||||
->orderByAsc('transacciones.fecha');
|
||||
$transacciones = $transacciones->findMany();
|
||||
|
||||
foreach ($transacciones as &$transaccion) {
|
||||
$transaccion = $this->parseTransaccion($transaccion);
|
||||
}
|
||||
|
||||
return $transacciones;
|
||||
}
|
||||
public function acumulacion(Carbon $date) {
|
||||
$consolidados = $this->consolidados();
|
||||
if ($consolidados === null) {
|
||||
return 0;
|
||||
}
|
||||
$saldo = 0;
|
||||
foreach ($consolidados as $consolidado) {
|
||||
if ($consolidado->fecha() >= $date) {
|
||||
continue;
|
||||
}
|
||||
$saldo += $consolidado->saldo();
|
||||
}
|
||||
return $saldo;
|
||||
}
|
||||
protected $saldo;
|
||||
public function saldo() {
|
||||
public function saldo(Service $service = null, $in_clp = false) {
|
||||
if ($this->saldo === null) {
|
||||
$this->saldo = 0;
|
||||
if (count($this->transacciones()) > 0) {
|
||||
$this->saldo = array_reduce($this->transacciones(), function($sum, $item) {
|
||||
return $sum + $item->valor;
|
||||
return $sum + $item->valor;
|
||||
});
|
||||
}
|
||||
}
|
||||
if ($in_clp and $this->moneda()->codigo !== 'CLP') {
|
||||
$fecha = Carbon::today();
|
||||
if ($this->moneda()->codigo == 'USD') {
|
||||
$fecha = match ($fecha->weekday()) {
|
||||
0 => $fecha->subWeek()->weekday(5),
|
||||
6 => $fecha->weekday(5),
|
||||
default => $fecha
|
||||
};
|
||||
}
|
||||
$service->get($fecha->format('Y-m-d'), $this->moneda()->id);
|
||||
return $this->moneda()->cambiar($fecha, $this->saldo);
|
||||
}
|
||||
return $this->saldo;
|
||||
}
|
||||
|
||||
public function toArray(): array {
|
||||
public function format($valor) {
|
||||
return $this->moneda()->format($valor);
|
||||
}
|
||||
|
||||
public function toArray(Service $service = null, $in_clp = false): array {
|
||||
$arr = parent::toArray();
|
||||
$arr['categoria'] = $this->categoria()->toArray();
|
||||
$arr['saldo'] = $this->saldo();
|
||||
$arr['saldoFormateado'] = '$' . number_format($this->saldo(), 0, ',', '.');
|
||||
$arr['tipo'] = $this->tipo()->toArray();
|
||||
$arr['moneda'] = $this->moneda()->toArray();
|
||||
$arr['saldo'] = $this->saldo($service, $in_clp);
|
||||
$arr['saldoFormateado'] = $this->format($this->saldo($service, $in_clp));
|
||||
return $arr;
|
||||
}
|
||||
}
|
||||
|
59
api/src/Moneda.php
Normal file
59
api/src/Moneda.php
Normal file
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
namespace Contabilidad;
|
||||
|
||||
use ProVM\Common\Alias\Model;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property string $denominacion
|
||||
* @property string $codigo
|
||||
* @property string $sufijo
|
||||
* @property string $prefijo
|
||||
* @property int $decimales
|
||||
*/
|
||||
class Moneda extends Model {
|
||||
public static $_table = 'monedas';
|
||||
protected static $fields = ['denominacion', 'codigo'];
|
||||
|
||||
public function format($valor) {
|
||||
return trim(implode('', [
|
||||
$this->prefijo,
|
||||
number_format($valor, $this->decimales, ',', '.'),
|
||||
$this->sufijo
|
||||
]));
|
||||
}
|
||||
public function cambio(\DateTime $fecha, Moneda $moneda = null) {
|
||||
if ($moneda === null) {
|
||||
$moneda = $this->factory->find(Moneda::class)->one(1);
|
||||
}
|
||||
$cambio = $this->factory->find(TipoCambio::class)
|
||||
->where([['desde_id', $this->id], ['hasta_id', $moneda->id], ['fecha', $fecha->format('Y-m-d H:i:s')]])
|
||||
->one();
|
||||
if ($cambio === null) {
|
||||
$cambio = $this->factory->find(TipoCambio::class)
|
||||
->where([['hasta_id', $this->id], ['desde_id', $moneda->id], ['fecha', $fecha->format('Y-m-d H:i:s')]])
|
||||
->one();
|
||||
}
|
||||
return $cambio;
|
||||
}
|
||||
public function cambiar(\DateTime $fecha, float $valor, Moneda $moneda = null) {
|
||||
$cambio = $this->cambio($fecha, $moneda);
|
||||
if (!$cambio) {
|
||||
return $valor;
|
||||
}
|
||||
if ($cambio->desde()->id != $this->id) {
|
||||
return $cambio->transform($valor, TipoCambio::DESDE);
|
||||
}
|
||||
return $cambio->transform($valor);
|
||||
}
|
||||
|
||||
public function toArray(): array {
|
||||
$arr = parent::toArray();
|
||||
$arr['format'] = [
|
||||
'prefijo' => $this->prefijo,
|
||||
'sufijo' => $this->sufijo,
|
||||
'decimales' => $this->decimales
|
||||
];
|
||||
return $arr;
|
||||
}
|
||||
}
|
98
api/src/Queue.php
Normal file
98
api/src/Queue.php
Normal file
@ -0,0 +1,98 @@
|
||||
<?php
|
||||
namespace Contabilidad;
|
||||
|
||||
use DateTimeInterface;
|
||||
use Carbon\Carbon;
|
||||
use ProVM\Common\Alias\Model;
|
||||
use ProVM\Common\Factory\Model as Factory;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property string $command
|
||||
* @property DateTimeInterface $created
|
||||
* @property bool $processed
|
||||
*/
|
||||
class Queue extends Model {
|
||||
public static $_table = 'queue';
|
||||
protected static $fields = ['command', 'created', 'processed'];
|
||||
|
||||
public function created(DateTimeInterface $fecha = null) {
|
||||
if ($fecha === null) {
|
||||
return Carbon::parse($this->created);
|
||||
}
|
||||
$this->created = $fecha->format('Y-m-d H:i:s');
|
||||
return $this;
|
||||
}
|
||||
public function hasArguments(): bool {
|
||||
return Model::factory(QueueArgument::class)
|
||||
->whereEqual('queue_id', $this->id)
|
||||
->groupBy('queue_id')
|
||||
->count('id') > 0;
|
||||
}
|
||||
protected $arguments;
|
||||
public function arguments() {
|
||||
if ($this->arguments === null) {
|
||||
$this->arguments = $this->parentOf(QueueArgument::class, [Model::CHILD_KEY => 'queue_id']);
|
||||
}
|
||||
return $this->arguments;
|
||||
}
|
||||
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;
|
||||
}
|
||||
public function setProcessed(bool $processed): Queue {
|
||||
$this->processed = $processed ? 1 : 0;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public static function find(Factory $factory, $data) {
|
||||
$where = [
|
||||
'command' => $data['command'],
|
||||
'processed' => $data['processed'] ?? 0
|
||||
];
|
||||
array_walk($where, function(&$item, $key) {
|
||||
$item = [$key, $item];
|
||||
});
|
||||
$where = array_values($where);
|
||||
return $factory->find(Queue::class)->where($where)->one();
|
||||
}
|
||||
|
||||
public function toArray(): array
|
||||
{
|
||||
$arr = parent::toArray();
|
||||
$cmd = [(string) $this];
|
||||
$arr['arguments'] = [];
|
||||
if ($this->hasArguments()) {
|
||||
$arr['arguments'] = array_map(function($item) use (&$cmd) {
|
||||
$cmd []= (string) $item;
|
||||
return $item->toArray();
|
||||
}, $this->arguments());
|
||||
}
|
||||
$arr['cmd'] = implode(' ', $cmd);
|
||||
return $arr;
|
||||
}
|
||||
|
||||
public function __toString(): string {
|
||||
$str = "{$this->command}";
|
||||
$arguments = $this->arguments();
|
||||
if ($arguments !== null and count($arguments) > 0) {
|
||||
$arguments = implode(' ', array_map(function($item) {return (string) $item;}, $arguments));
|
||||
$str .= " {$arguments}";
|
||||
}
|
||||
return $str;
|
||||
}
|
||||
}
|
26
api/src/QueueArgument.php
Normal file
26
api/src/QueueArgument.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
namespace Contabilidad;
|
||||
|
||||
use ProVM\Common\Alias\Model;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property Queue $queue_id
|
||||
* @property string $argument
|
||||
* @property string $value
|
||||
*/
|
||||
class QueueArgument extends Model {
|
||||
public static $_table = 'queue_arguments';
|
||||
|
||||
protected $queue;
|
||||
public function queue() {
|
||||
if ($this->queue === null) {
|
||||
$this->queue = $this->childOf(Queue::class, [Model::SELF_KEY => 'queue_id']);
|
||||
}
|
||||
return $this->queue;
|
||||
}
|
||||
|
||||
public function __toString(): string {
|
||||
return "--{$this->argument} '{$this->value}'";
|
||||
}
|
||||
}
|
50
api/src/TipoCambio.php
Normal file
50
api/src/TipoCambio.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
namespace Contabilidad;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use DateTime;
|
||||
use ProVM\Common\Alias\Model;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property DateTime $fecha
|
||||
* @property Moneda $desde_id
|
||||
* @property Moneda $hasta_id
|
||||
* @property float $valor
|
||||
*/
|
||||
class TipoCambio extends Model {
|
||||
const DESDE = -1;
|
||||
const HASTA = 1;
|
||||
|
||||
public static $_table = 'tipos_cambio';
|
||||
protected static $fields = ['fecha', 'valor', 'desde_id', 'hasta_id'];
|
||||
|
||||
protected $desde;
|
||||
public function desde() {
|
||||
if ($this->desde === null) {
|
||||
$this->desde = $this->childOf(Moneda::class, [Model::SELF_KEY => 'desde_id']);
|
||||
}
|
||||
return $this->desde;
|
||||
}
|
||||
protected $hasta;
|
||||
public function hasta() {
|
||||
if ($this->hasta === null) {
|
||||
$this->hasta = $this->childOf(Moneda::class, [Model::SELF_KEY => 'hasta_id']);
|
||||
}
|
||||
return $this->hasta;
|
||||
}
|
||||
public function fecha(DateTime $fecha = null) {
|
||||
if ($fecha === null) {
|
||||
return Carbon::parse($this->fecha);
|
||||
}
|
||||
$this->fecha = $fecha->format('Y-m-d H:i:s');
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function transform(float $valor, int $direction = TipoCambio::HASTA): float {
|
||||
if ($direction == TipoCambio::HASTA) {
|
||||
return $valor * $this->valor;
|
||||
}
|
||||
return $valor / $this->valor;
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@
|
||||
namespace Contabilidad;
|
||||
|
||||
use ProVM\Common\Alias\Model;
|
||||
use Contabilidad\Common\Service\TiposCambios as Service;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
@ -9,6 +10,57 @@ use ProVM\Common\Alias\Model;
|
||||
* @property int $activo
|
||||
*/
|
||||
class TipoCategoria extends Model {
|
||||
public static $_table = 'tipos_categoria';
|
||||
protected static $fields = ['descripcion', 'activo'];
|
||||
public static $_table = 'tipos_categoria';
|
||||
protected static $fields = ['descripcion', 'activo'];
|
||||
|
||||
protected $categorias;
|
||||
public function categorias() {
|
||||
if ($this->categorias === null) {
|
||||
$this->categorias = $this->parentOf(Categoria::class, [Model::CHILD_KEY => 'tipo_id']);
|
||||
}
|
||||
return $this->categorias;
|
||||
}
|
||||
|
||||
public function getCuentasOf($tipo) {
|
||||
return $this->factory->find(Cuenta::class)
|
||||
->select('cuentas.*')
|
||||
->join([
|
||||
['tipos_cuenta', 'tipos_cuenta.id', 'cuentas.tipo_id'],
|
||||
['categorias', 'categorias.id', 'cuentas.categoria_id']
|
||||
])
|
||||
->where([
|
||||
['tipos_cuenta.descripcion', $tipo],
|
||||
['categorias.tipo_id', $this->id]
|
||||
])->many();
|
||||
}
|
||||
protected $totales;
|
||||
public function getTotales(Service $service) {
|
||||
if ($this->totales === null) {
|
||||
$tipos = $this->factory->find(TipoCuenta::class)->many();
|
||||
$totals = [];
|
||||
foreach ($tipos as $tipo) {
|
||||
$p = strtolower($tipo->descripcion) . 's';
|
||||
$totals[$p] = 0;
|
||||
$cuentas = $this->getCuentasOf($tipo->descripcion);
|
||||
if ($cuentas === null) {
|
||||
continue;
|
||||
}
|
||||
$totals[$p] = array_reduce($cuentas, function($sum, $item) use ($service) {
|
||||
return $sum + $item->saldo($service, true);
|
||||
});
|
||||
}
|
||||
$this->totales = $totals;
|
||||
}
|
||||
return $this->totales;
|
||||
}
|
||||
|
||||
protected $saldo;
|
||||
public function saldo(Service $service = null) {
|
||||
if ($this->saldo === null) {
|
||||
$this->saldo = array_reduce($this->categorias() ?? [], function($sum, $item) use ($service) {
|
||||
return $sum + $item->saldo($service);
|
||||
});
|
||||
}
|
||||
return $this->saldo;
|
||||
}
|
||||
}
|
||||
|
@ -6,8 +6,22 @@ use ProVM\Common\Alias\Model;
|
||||
/**
|
||||
* @property int $id
|
||||
* @property string $descripcion
|
||||
* @property string $color
|
||||
*/
|
||||
class TipoCuenta extends Model {
|
||||
public static $_table = 'tipos_cuenta';
|
||||
protected static $fields = ['descripcion'];
|
||||
}
|
||||
public static $_table = 'tipos_cuenta';
|
||||
protected static $fields = ['descripcion', 'color'];
|
||||
|
||||
public function cargo()
|
||||
{
|
||||
$tipos = [
|
||||
'activo',
|
||||
'perdida',
|
||||
'banco'
|
||||
];
|
||||
if (in_array(strtolower($this->descripcion), $tipos)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
namespace Contabilidad;
|
||||
|
||||
use DateTime;
|
||||
use Carbon\Carbon;
|
||||
use ProVM\Common\Alias\Model;
|
||||
|
||||
@ -8,14 +9,15 @@ use ProVM\Common\Alias\Model;
|
||||
* @property int $id
|
||||
* @property Cuenta $debito_id
|
||||
* @property Cuenta $credito_id
|
||||
* @property \DateTime $fecha
|
||||
* @property DateTime $fecha
|
||||
* @property string $glosa
|
||||
* @property string $detalle
|
||||
* @property double $valor
|
||||
* @property Moneda $moneda_id
|
||||
*/
|
||||
class Transaccion extends Model {
|
||||
public static $_table = 'transacciones';
|
||||
protected static $fields = ['debito_id', 'credito_id', 'fecha', 'glosa', 'detalle', 'valor'];
|
||||
protected static $fields = ['debito_id', 'credito_id', 'fecha', 'glosa', 'detalle', 'valor', 'moneda_id'];
|
||||
|
||||
protected $debito;
|
||||
public function debito() {
|
||||
@ -31,11 +33,26 @@ class Transaccion extends Model {
|
||||
}
|
||||
return $this->credito;
|
||||
}
|
||||
public function fecha(\DateTime $fecha = null) {
|
||||
public function fecha(DateTime $fecha = null) {
|
||||
if ($fecha === null) {
|
||||
return Carbon::parse($this->fecha);
|
||||
}
|
||||
$this->fecha = $fecha->format('Y-m-d');
|
||||
return $this;
|
||||
}
|
||||
protected $moneda;
|
||||
public function moneda() {
|
||||
if ($this->moneda === null) {
|
||||
$this->moneda = $this->childOf(Moneda::class, [Model::SELF_KEY => 'moneda_id']);
|
||||
}
|
||||
return $this->moneda;
|
||||
}
|
||||
|
||||
public function transformar(Moneda $moneda = null) {
|
||||
if (($moneda !== null and $this->moneda()->id === $moneda->id) or ($moneda === null and $this->moneda()->id === 1)) {
|
||||
return $this->valor;
|
||||
}
|
||||
return $this->moneda()->cambiar($this->fecha(), $this->valor, $moneda);
|
||||
}
|
||||
|
||||
public function toArray(): array {
|
||||
@ -43,7 +60,7 @@ class Transaccion extends Model {
|
||||
$arr['debito'] = $this->debito()->toArray();
|
||||
$arr['credito'] = $this->credito()->toArray();
|
||||
$arr['fechaFormateada'] = $this->fecha()->format('d-m-Y');
|
||||
$arr['valorFormateado'] = '$' . number_format($this->valor, 0, ',', '.');
|
||||
$arr['valorFormateado'] = $this->debito()->moneda()->format($this->valor);
|
||||
return $arr;
|
||||
}
|
||||
}
|
||||
|
12
console/Dockerfile
Normal file
12
console/Dockerfile
Normal file
@ -0,0 +1,12 @@
|
||||
FROM php:8-cli
|
||||
|
||||
RUN apt-get update -y && apt-get install -y cron git libzip-dev zip
|
||||
|
||||
RUN docker-php-ext-install zip
|
||||
|
||||
COPY --from=composer /usr/bin/composer /usr/bin/composer
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
CMD ["cron", "-f", "-l", "2"]
|
||||
ENTRYPOINT ["cron", "-f", "-l", "2"]
|
7
console/bin/console
Normal file
7
console/bin/console
Normal file
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
$app = require_once implode(DIRECTORY_SEPARATOR, [
|
||||
dirname(__FILE__, 2),
|
||||
'setup',
|
||||
'app.php'
|
||||
]);
|
||||
$app->run();
|
37
console/common/Command/Consolidar.php
Normal file
37
console/common/Command/Consolidar.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?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 Consolidar 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 {
|
||||
$response = $this->getClient()->get('/consolidar');
|
||||
if ($response->getStatusCode() === 200) {
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
error_log($response->getReasonPhrase());
|
||||
return Command::FAILURE;
|
||||
} catch (\Exception $e) {
|
||||
error_log($e);
|
||||
return Command::FAILURE;
|
||||
}
|
||||
}
|
||||
}
|
53
console/common/Command/Queue.php
Normal file
53
console/common/Command/Queue.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?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 Queue 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)
|
||||
{
|
||||
$response = $this->getClient()->get('/queues/pending');
|
||||
if ($response->getStatusCode() !== 200) {
|
||||
return Command::FAILURE;
|
||||
}
|
||||
$data = json_decode($response->getBody()->getContents());
|
||||
$output = [
|
||||
'input' => $data,
|
||||
'processed' => []
|
||||
];
|
||||
foreach ($data->pending as $queue) {
|
||||
$log = "Running {$queue->command} from queue. Created in {$queue->created}.";
|
||||
error_log($log);
|
||||
$cmd = '/usr/local/bin/php /app/bin/console ' . $queue->cmd;
|
||||
exec($cmd, $result, $code);
|
||||
if ($code != Command::SUCCESS) {
|
||||
error_log(var_export($queue, true));
|
||||
error_log(var_export($result, true));
|
||||
continue;
|
||||
}
|
||||
$output['processed'] []= $queue->id;
|
||||
}
|
||||
$response = $this->getClient()->post('/queues/processed', ['json' => $output]);
|
||||
if ($response->getStatusCode() !== 200) {
|
||||
return Command::FAILURE;
|
||||
}
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
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;
|
||||
}
|
||||
}
|
||||
}
|
21
console/common/Define/Application.php
Normal file
21
console/common/Define/Application.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
namespace Contabilidad\Common\Define;
|
||||
|
||||
use Psr\Container\ContainerInterface as Container;
|
||||
use Symfony\Component\Console\Application as Base;
|
||||
|
||||
class Application extends Base {
|
||||
public function __construct(Container $container = null, string $name = 'UNKNOWN', string $version = 'UNKNOWN')
|
||||
{
|
||||
parent::__construct($name, $version);
|
||||
$this->setContainer($container);
|
||||
}
|
||||
protected $container;
|
||||
public function setContainer(Container $container) {
|
||||
$this->container = $container;
|
||||
return $this;
|
||||
}
|
||||
public function getContainer() {
|
||||
return $this->container;
|
||||
}
|
||||
}
|
25
console/composer.json
Normal file
25
console/composer.json
Normal file
@ -0,0 +1,25 @@
|
||||
{
|
||||
"name": "provm/contabilidad-console",
|
||||
"type": "project",
|
||||
"require": {
|
||||
"symfony/console": "^6.0",
|
||||
"php-di/php-di": "^6.3",
|
||||
"nesbot/carbon": "^2.57",
|
||||
"guzzlehttp/guzzle": "^7.4"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^9.5",
|
||||
"kint-php/kint": "^4.1"
|
||||
},
|
||||
"authors": [
|
||||
{
|
||||
"name": "Aldarien",
|
||||
"email": "aldarien85@gmail.com"
|
||||
}
|
||||
],
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Contabilidad\\Common\\": "common/"
|
||||
}
|
||||
}
|
||||
}
|
24
console/crontab
Normal file
24
console/crontab
Normal file
@ -0,0 +1,24 @@
|
||||
# Edit this file to introduce tasks to be run by cron.
|
||||
#
|
||||
# Each task to run has to be defined through a single line
|
||||
# indicating with different fields when the task will be run
|
||||
# and what command to run for the task
|
||||
#
|
||||
# To define the time you can provide concrete values for
|
||||
# minute (m), hour (h), day of month (dom), month (mon),
|
||||
# and day of week (dow) or use '*' in these fields (for 'any').
|
||||
#
|
||||
# Notice that tasks will be started based on the cron's system
|
||||
# daemon's notion of time and timezones.
|
||||
#
|
||||
# Output of the crontab jobs (including errors) is sent through
|
||||
# email to the user the crontab file belongs to (unless redirected).
|
||||
#
|
||||
# For example, you can run a backup of all your user accounts
|
||||
# at 5 a.m every week with:
|
||||
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
|
||||
#
|
||||
# For more information see the manual pages of crontab(5) and cron(8)
|
||||
#
|
||||
# m h dom mon dow command
|
||||
0 2 * * * /usr/local/bin/php /app/bin/console queue
|
4
console/php.ini
Normal file
4
console/php.ini
Normal file
@ -0,0 +1,4 @@
|
||||
[PHP]
|
||||
display_errors = E_ALL
|
||||
log_errors = true
|
||||
error_log = /var/log/php/error.log
|
39
console/setup/app.php
Normal file
39
console/setup/app.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
use DI\ContainerBuilder as Builder;
|
||||
use Contabilidad\Common\Define\Application;
|
||||
|
||||
require_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 = new Application($container);
|
||||
|
||||
$folder = implode(DIRECTORY_SEPARATOR, [__DIR__, 'commands']);
|
||||
if (file_exists($folder)) {
|
||||
$files = new DirectoryIterator($folder);
|
||||
foreach ($files as $file) {
|
||||
if ($file->isDir() or $file->getExtension() != 'php') {
|
||||
continue;
|
||||
}
|
||||
include_once $file->getRealPath();
|
||||
}
|
||||
}
|
||||
|
||||
return $app;
|
4
console/setup/commands/01_queue.php
Normal file
4
console/setup/commands/01_queue.php
Normal file
@ -0,0 +1,4 @@
|
||||
<?php
|
||||
use Contabilidad\Common\Command\Queue;
|
||||
|
||||
$app->add(new Queue($app->getContainer()->get(\Psr\Http\Client\ClientInterface::class), 'queue'));
|
4
console/setup/commands/02_consolidar.php
Normal file
4
console/setup/commands/02_consolidar.php
Normal file
@ -0,0 +1,4 @@
|
||||
<?php
|
||||
use Contabilidad\Common\Command\Consolidar;
|
||||
|
||||
$app->add(new Consolidar($app->getContainer()->get(\Psr\Http\Client\ClientInterface::class), 'consolidar'));
|
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'));
|
6
console/setup/composer.php
Normal file
6
console/setup/composer.php
Normal file
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
require_once implode(DIRECTORY_SEPARATOR, [
|
||||
dirname(__DIR__),
|
||||
'vendor',
|
||||
'autoload.php'
|
||||
]);
|
5
console/setup/settings/02_api.php
Normal file
5
console/setup/settings/02_api.php
Normal file
@ -0,0 +1,5 @@
|
||||
<?php
|
||||
return [
|
||||
'api_url' => $_ENV['API_URL'],
|
||||
'api_key' => $_ENV['API_KEY']
|
||||
];
|
13
console/setup/setups/02_client.php
Normal file
13
console/setup/setups/02_client.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
use Psr\Container\ContainerInterface as Container;
|
||||
|
||||
return [
|
||||
\Psr\Http\Client\ClientInterface::class => function(Container $container) {
|
||||
return new \GuzzleHttp\Client([
|
||||
'base_uri' => $container->get('api_url'),
|
||||
'headers' => [
|
||||
'Authorization' => "Bearer {$container->get('api_key')}"
|
||||
]
|
||||
]);
|
||||
}
|
||||
];
|
@ -1,63 +1,108 @@
|
||||
version: '3'
|
||||
|
||||
x-restart: &restart
|
||||
restart: unless-stopped
|
||||
|
||||
services:
|
||||
api:
|
||||
restart: unless-stopped
|
||||
profiles:
|
||||
- api
|
||||
<<: *restart
|
||||
image: php
|
||||
build:
|
||||
context: api
|
||||
env_file: .env
|
||||
env_file:
|
||||
- .db.env
|
||||
- .api.env
|
||||
- .python.env
|
||||
volumes:
|
||||
- ./api/:/app/
|
||||
- ./api/php.ini:/usr/local/etc/php/conf.d/php.ini
|
||||
- ./logs/api/php/:/var/log/php/
|
||||
api-proxy:
|
||||
restart: unless-stopped
|
||||
profiles:
|
||||
- api
|
||||
<<: *restart
|
||||
image: nginx
|
||||
ports:
|
||||
- "9001:80"
|
||||
volumes:
|
||||
- ./api/nginx.conf:/etc/nginx/conf.d/default.conf
|
||||
- ./logs/api/:/var/log/nginx/
|
||||
- ./logs/api/proxy/:/var/log/nginx/
|
||||
- ./api/:/app/
|
||||
db:
|
||||
restart: unless-stopped
|
||||
profiles:
|
||||
- api
|
||||
<<: *restart
|
||||
image: mariadb
|
||||
env_file: .env
|
||||
env_file: .db.env
|
||||
volumes:
|
||||
- contabilidad_data:/var/lib/mysql
|
||||
adminer:
|
||||
restart: unless-stopped
|
||||
profiles:
|
||||
- api
|
||||
<<: *restart
|
||||
image: adminer
|
||||
ports:
|
||||
- "9002:8080"
|
||||
|
||||
ui:
|
||||
restart: unless-stopped
|
||||
profiles:
|
||||
- ui
|
||||
<<: *restart
|
||||
image: php-ui
|
||||
env_file:
|
||||
- .api.env
|
||||
- .env
|
||||
build:
|
||||
context: ui
|
||||
volumes:
|
||||
- ./ui/:/app/
|
||||
- ./ui/php.ini:/usr/local/etc/php/conf.d/php.ini
|
||||
- ./logs/ui/php/:/var/log/php/
|
||||
ui-proxy:
|
||||
restart: unless-stopped
|
||||
profiles:
|
||||
- ui
|
||||
<<: *restart
|
||||
image: nginx
|
||||
ports:
|
||||
- "9000:80"
|
||||
volumes:
|
||||
- ./ui/nginx.conf:/etc/nginx/conf.d/default.conf
|
||||
- ./logs/ui/:/var/log/nginx/
|
||||
- ./logs/ui/proxy/:/var/log/nginx/
|
||||
- ./ui/:/app/
|
||||
|
||||
python:
|
||||
restart: unless-stopped
|
||||
profiles:
|
||||
- python
|
||||
<<: *restart
|
||||
build:
|
||||
context: ./python
|
||||
env_file:
|
||||
- .python.env
|
||||
ports:
|
||||
- "9003:5000"
|
||||
volumes:
|
||||
- ./python/src/:/app/src/
|
||||
- ./python/config/:/app/config/
|
||||
- ./api/public/uploads/pdfs/:/app/data/
|
||||
- ./logs/python/:/var/log/python/
|
||||
|
||||
console:
|
||||
profiles:
|
||||
- console
|
||||
<<: *restart
|
||||
build:
|
||||
context: ./console
|
||||
env_file:
|
||||
- .api.env
|
||||
- .console.env
|
||||
- .db.env
|
||||
volumes:
|
||||
- ./console/:/app/
|
||||
- ./console/php.ini:/usr/local/etc/php/conf.d/php.ini
|
||||
- ./logs/console/:/var/log/php/
|
||||
- ./console/crontab:/var/spool/cron/crontabs/root
|
||||
|
||||
volumes:
|
||||
contabilidad_data:
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user