This commit is contained in:
2024-01-17 10:33:11 -03:00
parent c4f486d3fa
commit 674aba801e
27 changed files with 1210 additions and 2 deletions

View File

@ -0,0 +1,52 @@
<?php
namespace Incoviba\Controller\API;
use DateTimeImmutable;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Incoviba\Common\Implement\Exception\EmptyResult;
use Incoviba\Repository;
use Incoviba\Service;
class Contabilidad
{
use withJson;
public function procesarCartola(ServerRequestInterface $request, ResponseInterface $response,
Repository\Inmobiliaria $inmobiliariaRepository,
Repository\Banco $bancoRepository,
Service\Cartola $cartolaService): ResponseInterface
{
$body = $request->getParsedBody();
$output = [
'input' => $body,
'movimientos' => []
];
try {
$inmobiliaria = $inmobiliariaRepository->fetchById($body['inmobiliaria']);
$banco = $bancoRepository->fetchById($body['banco']);
$mes = new DateTimeImmutable($body['mes']);
$file = $request->getUploadedFiles()['file'];
$output['movimientos'] = $cartolaService->process($inmobiliaria, $banco, $mes, $file);
} catch (EmptyResult) {}
return $this->withJson($response, $output);
}
public function exportarCartola(ServerRequestInterface $request, ResponseInterface $response,
Repository\Inmobiliaria $inmobiliariaRepository,
Repository\Banco $bancoRepository,
Service\Cartola $cartolaService): ResponseInterface
{
$body = $request->getParsedBody();
$output = [
'input' => $body,
'filename' => ''
];
try {
$inmobiliaria = $inmobiliariaRepository->fetchById($body['inmobiliaria']);
$banco = $bancoRepository->fetchById($body['banco']);
$mes = new DateTimeImmutable($body['mes']);
$output['filename'] = $cartolaService->export($inmobiliaria, $banco, $mes, json_decode($body['movimientos']));
} catch (EmptyResult) {}
return $this->withJson($response, $output);
}
}

View File

@ -0,0 +1,25 @@
<?php
namespace Incoviba\Controller\API;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Incoviba\Service;
class Informes
{
use withJson;
public function diario(ServerRequestInterface $request, ResponseInterface $response, Service\Informes\Diario $diarioService): ResponseInterface
{
$body = $request->getParsedBody();
$output = [
'input' => $body,
'data' => []
];
try {
$file = $request->getUploadedFiles()['file'];
$output['data'] = $diarioService->process($file);
} catch (\Error) {}
return $this->withJson($response, $output);
}
}

View File

@ -0,0 +1,48 @@
<?php
namespace Incoviba\Controller\API;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Incoviba\Common\Implement\Exception\EmptyResult;
use Incoviba\Model;
use Incoviba\Repository;
use Incoviba\Service;
class Inmobiliarias
{
use withJson;
public function cuentas(ServerRequestInterface $request, ResponseInterface $response,
Repository\Inmobiliaria $inmobiliariaRepository,
Repository\Inmobiliaria\Cuenta $cuentaRepository, int $inmobiliaria_rut): ResponseInterface
{
$output = [
'inmobiliaria_rut' => $inmobiliaria_rut,
'cuentas' => []
];
try {
$inmobiliaria = $inmobiliariaRepository->fetchById($inmobiliaria_rut);
$output['cuentas'] = $cuentaRepository->fetchByInmobiliaria($inmobiliaria->rut);
} catch (EmptyResult) {}
return $this->withJson($response, $output);
}
public function proyectos(ServerRequestInterface $request, ResponseInterface $response,
Repository\Inmobiliaria $inmobiliariaRepository,
Service\Proyecto $proyectoService, int $inmobiliaria_rut): ResponseInterface
{
$output = [
'inmobiliaria_rut' => $inmobiliaria_rut,
'proyectos' => []
];
try {
$inmobiliaria = $inmobiliariaRepository->fetchById($inmobiliaria_rut);
$output['proyectos'] = array_map(function(Model\Proyecto $proyecto) {
$p = json_decode(json_encode($proyecto));
$p->current_estado = $proyecto->currentEstado();
$p->estados = $proyecto->estados();
return $p;
},$proyectoService->getByInmobiliaria($inmobiliaria->rut));
} catch (EmptyResult) {}
return $this->withJson($response, $output);
}
}

View File

@ -0,0 +1,90 @@
<?php
namespace Incoviba\Controller\API;
use DateTimeImmutable;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Incoviba\Common\Implement\Exception\HttpResponse;
use Incoviba\Service;
class Nubox
{
use withJson;
public function token(ServerRequestInterface $request, ResponseInterface $response,
Service\Contabilidad\Nubox $nuboxService, int $inmobiliaria_rut): ResponseInterface
{
$output = [
'inmobiliaria_rut' => $inmobiliaria_rut,
'token' => ''
];
try {
$output['token'] = $nuboxService->getToken($inmobiliaria_rut);
} catch (HttpResponse $exception) {
$output['error'] = [
'code' => $exception->getCode(),
'message' => $exception->getMessage()
];
}
return $this->withJson($response, $output);
}
public function sistemas(ServerRequestInterface $request, ResponseInterface $response,
Service\Contabilidad\Nubox $nuboxService, int $inmobiliaria_rut): ResponseInterface
{
$output = [
'inmobiliaria_rut' => $inmobiliaria_rut,
'sistemas' => []
];
try {
$output['sistemas'] = $nuboxService->getSistemas($inmobiliaria_rut);
} catch (HttpResponse $exception) {
$output['error'] = [
'code' => $exception->getCode(),
'message' => $exception->getMessage()
];
}
return $this->withJson($response, $output);
}
public function libroMayor(ServerRequestInterface $request, ResponseInterface $response,
Service\Contabilidad\Nubox $nuboxService, int $inmobiliaria_rut): ResponseInterface
{
$body = $request->getParsedBody();
$output = [
'inmobiliaria_rut' => $inmobiliaria_rut,
'input' => $body,
'libro_mayor' => []
];
try {
$from = new DateTimeImmutable($body['inicio']);
$to = new DateTimeImmutable($body['termino']);
$output['libro_mayor'] = $nuboxService->getLibroMayor($inmobiliaria_rut, $from, $to);
} catch (HttpResponse $exception) {
$output['error'] = [
'code' => $exception->getCode(),
'message' => $exception->getMessage()
];
}
return $this->withJson($response, $output);
}
public function libroDiario(ServerRequestInterface $request, ResponseInterface $response,
Service\Contabilidad\Nubox $nuboxService, int $inmobiliaria_rut): ResponseInterface
{
$body = $request->getParsedBody();
$output = [
'inmobiliaria_rut' => $inmobiliaria_rut,
'input' => $body,
'libro_diario' => []
];
try {
$from = new DateTimeImmutable($body['inicio']);
$to = new DateTimeImmutable($body['termino']);
$output['libro_diario'] = $nuboxService->getLibroDiario($inmobiliaria_rut, $from, $to);
} catch (HttpResponse $exception) {
$output['error'] = [
'code' => $exception->getCode(),
'message' => $exception->getMessage()
];
}
return $this->withJson($response, $output);
}
}

View File

@ -155,4 +155,19 @@ class Proyectos
} catch (EmptyResult) {}
return $this->withJson($response, $output);
}
public function tiposUnidades(ServerRequestInterface $request, ResponseInterface $response,
Repository\Proyecto $proyectoRepository,
Repository\Proyecto\TipoUnidad $tipoUnidadRepository,
int $proyecto_id): ResponseInterface
{
$output = [
'proyecto_id' => $proyecto_id,
'tipos' => []
];
try {
$proyecto = $proyectoRepository->fetchById($proyecto_id);
$output['tipos'] = $tipoUnidadRepository->fetchByProyecto($proyecto->id);
} catch (EmptyResult) {}
return $this->withJson($response, $output);
}
}

View File

@ -21,4 +21,12 @@ class CentrosCostos
return $view->render($response, 'contabilidad.centros_costos', compact('centrosCostos',
'tiposCentros', 'categorias', 'tiposCuentas'));
}
public function asignar(ServerRequestInterface $request, ResponseInterface $response, View $view,
Repository\CentroCosto $centroCostoRepository,
Repository\Inmobiliaria $inmobiliariaRepository): ResponseInterface
{
$centrosCostos = $centroCostoRepository->fetchAll();
$inmobiliarias = $inmobiliariaRepository->fetchAllActive('razon');
return $view->render($response, 'contabilidad.centros_costos.asignar', compact('centrosCostos', 'inmobiliarias'));
}
}