Facturacion
This commit is contained in:
62
app/src/Controller/API/CentrosCostos.php
Normal file
62
app/src/Controller/API/CentrosCostos.php
Normal file
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller\API;
|
||||
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class CentrosCostos
|
||||
{
|
||||
use withJson;
|
||||
|
||||
public function add(ServerRequestInterface $request, ResponseInterface $response,
|
||||
Repository\CentroCosto $centroCostoRepository): ResponseInterface
|
||||
{
|
||||
$body = $request->getParsedBody();
|
||||
$output = [
|
||||
'input' => $body,
|
||||
'added' => false
|
||||
];
|
||||
try {
|
||||
$centroCosto = $centroCostoRepository->create($body);
|
||||
$centroCosto->id = $body['id'];
|
||||
$centroCostoRepository->save($centroCosto);
|
||||
$output['added'] = true;
|
||||
} catch (EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function edit(ServerRequestInterface $request, ResponseInterface $response,
|
||||
Repository\CentroCosto $centroCostoRepository, int $centro_costo_id): ResponseInterface
|
||||
{
|
||||
$body = $request->getParsedBody();
|
||||
$output = [
|
||||
'centro_costo_id' => $centro_costo_id,
|
||||
'input' => $body,
|
||||
'edited' => false
|
||||
];
|
||||
try {
|
||||
$centroCosto = $centroCostoRepository->fetchById($centro_costo_id);
|
||||
if ($body['tipo_cuenta_id'] === '') {
|
||||
$body['tipo_cuenta_id'] = null;
|
||||
}
|
||||
$centroCostoRepository->edit($centroCosto, $body);
|
||||
$output['edited'] = true;
|
||||
} catch (EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function remove(ServerRequestInterface $request, ResponseInterface $response,
|
||||
Repository\CentroCosto $centroCostoRepository, int $centro_costo_id): ResponseInterface
|
||||
{
|
||||
$output = [
|
||||
'centro_costo_id' => $centro_costo_id,
|
||||
'removed' => false
|
||||
];
|
||||
try {
|
||||
$centroCosto = $centroCostoRepository->fetchById($centro_costo_id);
|
||||
$centroCostoRepository->remove($centroCosto);
|
||||
$output['removed'] = true;
|
||||
} catch (EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
}
|
90
app/src/Controller/API/Nubox.php
Normal file
90
app/src/Controller/API/Nubox.php
Normal 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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user