2024-06-18
This commit is contained in:
@ -120,4 +120,22 @@ class Nubox
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function facturas(ServerRequestInterface $request, ResponseInterface $response, Service\Contabilidad\Nubox $nuboxService, int $inmobiliaria_rut, string $dia): ResponseInterface
|
||||
{
|
||||
$output = [
|
||||
'inmobiliaria_rut' => $inmobiliaria_rut,
|
||||
'dia' => $dia,
|
||||
'facturas' => []
|
||||
];
|
||||
try {
|
||||
$output['facturas'] = $nuboxService->getFacturas($inmobiliaria_rut, new DateTimeImmutable($dia));
|
||||
} catch (HttpResponse $exception) {
|
||||
$output['error'] = [
|
||||
'code' => $exception->getCode(),
|
||||
'reason' => $exception->getReason(),
|
||||
'message' => $exception->getMessage(),
|
||||
];
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
}
|
||||
|
@ -55,27 +55,33 @@ class Inmobiliarias
|
||||
} catch (EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function agentes(ServerRequestInterface $request, ResponseInterface $response,
|
||||
Repository\Inmobiliaria $inmobiliariaRepository,
|
||||
Repository\Inmobiliaria\SociedadAgente $sociedadAgenteRepository,
|
||||
Repository\Inmobiliaria\TipoAgente $tipoAgenteRepository,
|
||||
int $inmobiliaria_rut): ResponseInterface
|
||||
public function proveedores(ServerRequestInterface $request, ResponseInterface $response,
|
||||
Repository\Inmobiliaria $inmobiliariaRepository,
|
||||
Repository\Inmobiliaria\SociedadAgente $sociedadAgenteRepository,
|
||||
Repository\Inmobiliaria\TipoAgente $tipoAgenteRepository,
|
||||
int $inmobiliaria_rut): ResponseInterface
|
||||
{
|
||||
$input = $request->getParsedBody();
|
||||
$output = [
|
||||
'sociedad_rut' => $inmobiliaria_rut,
|
||||
'input' => $input,
|
||||
'sociedad' => null,
|
||||
'agentes' => []
|
||||
'proveedores' => []
|
||||
];
|
||||
try {
|
||||
$inmobiliaria = $inmobiliariaRepository->fetchById($inmobiliaria_rut);
|
||||
$output['sociedad'] = $inmobiliaria;
|
||||
if (isset($input['tipo_agente_id'])) {
|
||||
$tipo = $tipoAgenteRepository->fetchById($input['tipo_agente_id']);
|
||||
$output['agentes'] = $sociedadAgenteRepository->fetchBySociedadAndTipo($inmobiliaria->rut, $tipo->id);
|
||||
$proveedores = $sociedadAgenteRepository->fetchBySociedadAndTipo($inmobiliaria->rut, $tipo->id);
|
||||
} else {
|
||||
$output['agentes'] = $sociedadAgenteRepository->fetchBySociedad($inmobiliaria->rut);
|
||||
$proveedores = $sociedadAgenteRepository->fetchBySociedad($inmobiliaria->rut);
|
||||
}
|
||||
$output['proveedores'] = json_decode(json_encode($proveedores), JSON_OBJECT_AS_ARRAY);
|
||||
foreach ($proveedores as $i => $proveedor) {
|
||||
$output['proveedores'][$i]['sociedad'] = $proveedor->sociedad;
|
||||
$output['proveedores'][$i]['proveedor'] = $proveedor->agenteTipo->agente;
|
||||
$output['proveedores'][$i]['tipo'] = $proveedor->agenteTipo->tipoAgente;
|
||||
}
|
||||
} catch (EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
|
35
app/src/Controller/API/Inmobiliarias/Sociedades.php
Normal file
35
app/src/Controller/API/Inmobiliarias/Sociedades.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller\API\Inmobiliarias;
|
||||
|
||||
use Incoviba\Controller\API\withJson;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Service;
|
||||
|
||||
class Sociedades extends Ideal\Service
|
||||
{
|
||||
use withJson;
|
||||
|
||||
public function add(ServerRequestInterface $request, ResponseInterface $response,
|
||||
Service\Sociedad $sociedadService, Service\Persona $personaService): ResponseInterface
|
||||
{
|
||||
$input = $request->getParsedBody();
|
||||
$output = [
|
||||
'input' => $input,
|
||||
'sociedad' => null
|
||||
];
|
||||
try {
|
||||
$data = json_decode($input, true);
|
||||
$contacto = $personaService->add($data['contacto']);
|
||||
$data['contacto_rut'] = $contacto->rut;
|
||||
unset($data['contacto']);
|
||||
$output['sociedad'] = $sociedadService->add($data);
|
||||
} catch (EmptyResult) {
|
||||
$output['error'] = 'No se pudo agregar la sociedad';
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
}
|
132
app/src/Controller/API/Sociedades.php
Normal file
132
app/src/Controller/API/Sociedades.php
Normal file
@ -0,0 +1,132 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller\API;
|
||||
|
||||
use Incoviba\Common\Ideal\Controller;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Incoviba\Service;
|
||||
|
||||
class Sociedades extends Controller
|
||||
{
|
||||
use withJson;
|
||||
|
||||
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, Service\Sociedad $sociedadService): ResponseInterface
|
||||
{
|
||||
$output = [
|
||||
'sociedades' => $sociedadService->getAll('nombre'),
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function getMany(ServerRequestInterface $request, ResponseInterface $response, Service\Sociedad $sociedadService): ResponseInterface
|
||||
{
|
||||
$input = $request->getParsedBody();
|
||||
$output = [
|
||||
'input' => $input,
|
||||
'sociedades' => [],
|
||||
];
|
||||
foreach ($input['sociedades_ruts'] as $rut) {
|
||||
$sociedad = $sociedadService->getByRut($rut);
|
||||
if ($sociedad === null) {
|
||||
continue;
|
||||
}
|
||||
$output['sociedades'][] = $sociedad;
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function get(ServerRequestInterface $request, ResponseInterface $response, Service\Sociedad $sociedadService, int $sociedad_rut): ResponseInterface
|
||||
{
|
||||
$output = [
|
||||
'sociedad_rut' => $sociedad_rut,
|
||||
'sociedad' => $sociedadService->getByRut($sociedad_rut),
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function add(ServerRequestInterface $request, ResponseInterface $response, Service\Sociedad $sociedadService): ResponseInterface
|
||||
{
|
||||
$input = $request->getParsedBody();
|
||||
$output = [
|
||||
'input' => $input,
|
||||
'sociedad' => $sociedadService->add($input),
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function addMany(ServerRequestInterface $request, ResponseInterface $response, Service\Sociedad $sociedadService, Service\Persona $personaService): ResponseInterface
|
||||
{
|
||||
$input = $request->getParsedBody();
|
||||
$output = [
|
||||
'input' => $input,
|
||||
'sociedades' => [],
|
||||
];
|
||||
try {
|
||||
if (json_decode($input) !== null) {
|
||||
$input = json_decode($input, true);
|
||||
}
|
||||
} catch (\TypeError) {}
|
||||
foreach ($input['sociedades'] as $sociedadData) {
|
||||
try {
|
||||
if (json_decode($sociedadData) !== null) {
|
||||
$sociedadData = json_decode($sociedadData, true);
|
||||
}
|
||||
} catch (\TypeError) {}
|
||||
$contacto = $personaService->add($sociedadData['contacto']);
|
||||
$sociedadData['contacto_rut'] = $contacto->rut;
|
||||
unset($sociedadData['contacto']);
|
||||
$sociedad = $sociedadService->add($sociedadData);
|
||||
if ($sociedad === null) {
|
||||
continue;
|
||||
}
|
||||
$output['sociedades'][] = $sociedad;
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function edit(ServerRequestInterface $request, ResponseInterface $response, Service\Sociedad $sociedadService): ResponseInterface
|
||||
{
|
||||
$input = $request->getParsedBody();
|
||||
$output = [
|
||||
'input' => $input,
|
||||
'sociedades' => [],
|
||||
];
|
||||
foreach ($input['sociedades'] as $sociedadData) {
|
||||
$sociedad = $sociedadService->edit($sociedadData['rut'], $sociedadData);
|
||||
if ($sociedad === null) {
|
||||
continue;
|
||||
}
|
||||
$output['sociedades'][] = $sociedad;
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function delete(ServerRequestInterface $request, ResponseInterface $response, Service\Sociedad $sociedadService): ResponseInterface
|
||||
{
|
||||
$input = $request->getParsedBody();
|
||||
$output = [
|
||||
'input' => $input,
|
||||
'sociedades' => [],
|
||||
];
|
||||
foreach ($input['sociedades_ruts'] as $rut) {
|
||||
$sociedad = $sociedadService->getByRut($rut);
|
||||
$deleted = $sociedadService->delete($rut);
|
||||
$output['sociedades'][] = [
|
||||
'sociedad' => $sociedad,
|
||||
'deleted' => $deleted,
|
||||
];
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
|
||||
public function asignar(ServerRequestInterface $request, ResponseInterface $response, Service\Sociedad $sociedadService): ResponseInterface
|
||||
{
|
||||
$input = $request->getParsedBody();
|
||||
$output = [
|
||||
'input' => $input,
|
||||
'proveedores' => [],
|
||||
];
|
||||
foreach ($input['proveedores'] as $proveedorData) {
|
||||
$proveedor = $sociedadService->asignar($proveedorData['inmobiliaria_rut'], $proveedorData['sociedad_rut']);
|
||||
if ($proveedor === null) {
|
||||
continue;
|
||||
}
|
||||
$output['proveedores'][] = $proveedor;
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
}
|
32
app/src/Controller/API/Ventas/Facturas.php
Normal file
32
app/src/Controller/API/Ventas/Facturas.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller\API\Ventas;
|
||||
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Incoviba\Controller\API\withJson;
|
||||
use Incoviba\Common\Ideal\Controller;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Service;
|
||||
|
||||
class Facturas extends Controller
|
||||
{
|
||||
use withJson;
|
||||
|
||||
public function add(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Factura $facturaService): ResponseInterface
|
||||
{
|
||||
$data = $request->getParsedBody();
|
||||
$output = [
|
||||
'input' => $data,
|
||||
'factura' => null,
|
||||
'saved' => false
|
||||
];
|
||||
try {
|
||||
$output['factura'] = $facturaService->add($data);
|
||||
$output['saved'] = true;
|
||||
} catch (Implement\Exception\EmptyResult) {
|
||||
$output['error'] = 'No se pudo agregar la factura';
|
||||
return $this->withJson($response, $output, 400);
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user