2024-06-18
This commit is contained in:
36
app/src/Service/Contabilidad/Informe/Semanal.php
Normal file
36
app/src/Service/Contabilidad/Informe/Semanal.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
namespace Incoviba\Service\Contabilidad\Informe;
|
||||
|
||||
use DateTimeInterface;
|
||||
use DateInterval;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Service;
|
||||
|
||||
class Semanal extends Ideal\Service
|
||||
{
|
||||
public function __construct(LoggerInterface $logger, protected Repository\Inmobiliaria $repositoryRepository,
|
||||
protected Service\Inmobiliaria\Cuenta $cuentaService,
|
||||
protected Repository\Contabilidad\Deposito $depositoRepository,
|
||||
protected Service\Contabilidad\Cartola $cartolaService,
|
||||
protected Service\Contabilidad\Movimiento $movimientoService,
|
||||
protected Service\Contabilidad\Informe\Tesoreria\Excel $excelService,
|
||||
protected Service\Contabilidad\Informe\Tesoreria\PDF $pdfService)
|
||||
{
|
||||
parent::__construct($logger);
|
||||
}
|
||||
|
||||
public function getAnterior(DateTimeInterface $fecha): DateTimeInterface
|
||||
{
|
||||
if (!isset($this->anterior)) {
|
||||
$this->anterior = $fecha->sub(new DateInterval('P1D'));
|
||||
if ($this->anterior->format('N') === '7') {
|
||||
$this->anterior = $fecha->sub(new DateInterval('P3D'));
|
||||
}
|
||||
}
|
||||
return $this->anterior;
|
||||
}
|
||||
public function build(DateTimeInterface $fecha): array
|
||||
{}
|
||||
}
|
@ -2,17 +2,18 @@
|
||||
namespace Incoviba\Service\Contabilidad;
|
||||
|
||||
use DateTimeInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Incoviba\Common\Ideal\Service;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class Movimiento extends Service
|
||||
{
|
||||
public function __construct(LoggerInterface $logger,
|
||||
protected Repository\Contabilidad\Movimiento $movimientoRepository,
|
||||
protected Repository\Movimiento\Detalle $detalleRepository)
|
||||
public function __construct(LoggerInterface $logger,
|
||||
protected Repository\Contabilidad\Movimiento $movimientoRepository,
|
||||
protected Repository\Contabilidad\Movimiento\Detalle $detalleRepository,
|
||||
protected Movimiento\Auxiliar $auxiliarService)
|
||||
{
|
||||
parent::__construct($logger);
|
||||
}
|
||||
@ -48,9 +49,20 @@ class Movimiento extends Service
|
||||
|
||||
public function process(Model\Contabilidad\Movimiento $movimiento): Model\Contabilidad\Movimiento
|
||||
{
|
||||
$movimiento->addFactory('detalles', (new Implement\Repository\Factory())->setCallable(function(int $movimiento_id) {
|
||||
return $this->detalleRepository->fetchByMovimiento($movimiento_id);
|
||||
})->setArgs(['movimiento_id' => $movimiento->id]));
|
||||
$movimiento->addFactory('detalles', (new Implement\Repository\Factory())
|
||||
->setCallable(function(int $movimiento_id) {
|
||||
try {
|
||||
return $this->detalleRepository->fetchByMovimiento($movimiento_id);
|
||||
} catch (Implement\Exception\EmptyResult) {
|
||||
return null;
|
||||
}
|
||||
})
|
||||
->setArgs(['movimiento_id' => $movimiento->id]));
|
||||
$movimiento->addFactory('auxiliares', (new Implement\Repository\Factory())
|
||||
->setCallable(function(int $movimiento_id) {
|
||||
return $this->auxiliarService->getByMovimiento($movimiento_id);
|
||||
})
|
||||
->setArgs(['movimiento_id' => $movimiento->id]));
|
||||
return $movimiento;
|
||||
}
|
||||
}
|
||||
|
42
app/src/Service/Contabilidad/Movimiento/Auxiliar.php
Normal file
42
app/src/Service/Contabilidad/Movimiento/Auxiliar.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
namespace Incoviba\Service\Contabilidad\Movimiento;
|
||||
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Service;
|
||||
|
||||
class Auxiliar extends Ideal\Service
|
||||
{
|
||||
public function __construct(LoggerInterface $logger,
|
||||
protected Repository\Contabilidad\Movimiento\Auxiliar $auxiliarRepository,
|
||||
protected Repository\Contabilidad\Movimiento\Auxiliar\Detalle $detalleRepository)
|
||||
{
|
||||
parent::__construct($logger);
|
||||
}
|
||||
|
||||
public function getByMovimiento(int $movimiento_id): ?array
|
||||
{
|
||||
try {
|
||||
return array_map([$this, 'process'], $this->auxiliarRepository->fetchByMovimiento($movimiento_id));
|
||||
} catch (Implement\Exception\EmptyResult) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
protected function process(Model\Contabilidad\Movimiento\Auxiliar $auxiliar): Model\Contabilidad\Movimiento\Auxiliar
|
||||
{
|
||||
$auxiliar->addFactory('detalles', (new Implement\Repository\Factory())
|
||||
->setCallable(function(int $auxiliar_id) {
|
||||
try {
|
||||
return $this->detalleRepository->fetchByAuxiliar($auxiliar_id);
|
||||
} catch (Implement\Exception\EmptyResult) {
|
||||
return null;
|
||||
}
|
||||
})
|
||||
->setArgs(['auxiliar_id' => $auxiliar->id]));
|
||||
return $auxiliar;
|
||||
}
|
||||
}
|
@ -40,9 +40,6 @@ class Nubox extends Ideal\Service
|
||||
->withHeader('Content-Type', 'application/json')
|
||||
->withHeader('Accept', 'application/json');
|
||||
$response = $this->client->sendRequest($request);
|
||||
if ($response->getStatusCode() !== 200) {
|
||||
throw new Exception\HttpResponse($response->getReasonPhrase(), $response->getStatusCode());
|
||||
}
|
||||
$sistemas = json_decode($response->getBody()->getContents(), JSON_OBJECT_AS_ARRAY);
|
||||
|
||||
$this->setToken($inmobiliaria_rut, $response->getHeaderLine('Token'))
|
||||
@ -133,9 +130,6 @@ class Nubox extends Ideal\Service
|
||||
];
|
||||
$uri = 'contabilidad/libro-mayor?' . http_build_query($query);
|
||||
$response = $this->send($uri, $inmobiliaria_rut);
|
||||
if ($response->getStatusCode() !== 200) {
|
||||
throw new Exception\HttpResponse($response->getReasonPhrase(), $response->getStatusCode());
|
||||
}
|
||||
return json_decode($response->getBody()->getContents(), JSON_OBJECT_AS_ARRAY);
|
||||
}
|
||||
public function getLibroDiario(int $inmobiliaria_rut, DateTimeInterface $from, DateTimeInterface $to): array
|
||||
@ -157,10 +151,6 @@ class Nubox extends Ideal\Service
|
||||
];
|
||||
$uri = 'contabilidad/libro-diario?' . http_build_query($query);
|
||||
$response = $this->send($uri, $inmobiliaria_rut);
|
||||
if ($response->getStatusCode() !== 200) {
|
||||
$this->logger->debug($uri);
|
||||
throw new Exception\HttpResponse($response->getReasonPhrase(), $response->getStatusCode());
|
||||
}
|
||||
return json_decode($response->getBody()->getContents(), JSON_OBJECT_AS_ARRAY);
|
||||
}
|
||||
public function getMesCuenta(int $inmobiliaria_rut, string $cuenta, DateTimeInterface $mes): array
|
||||
@ -186,11 +176,29 @@ class Nubox extends Ideal\Service
|
||||
];
|
||||
$uri = 'contabilidad/libro-mayor?' . http_build_query($query);
|
||||
$response = $this->send($uri, $inmobiliaria_rut);
|
||||
if ($response->getStatusCode() !== 200) {
|
||||
throw new Exception\HttpResponse($response->getReasonPhrase(), $response->getStatusCode());
|
||||
}
|
||||
return json_decode($response->getBody()->getContents(), JSON_OBJECT_AS_ARRAY);
|
||||
}
|
||||
public function getFacturas(int $inmobiliaria_rut, DateTimeInterface $dia): array
|
||||
{
|
||||
//$inmobiliaria = $this->nuboxRepository->fetchByInmobiliaria($inmobiliaria_rut);
|
||||
$query = [
|
||||
'factura',
|
||||
'documento',
|
||||
'78017310-6',
|
||||
'estadoVenta',
|
||||
551,
|
||||
'FAC-EL',
|
||||
1
|
||||
];
|
||||
$uri = implode('/', $query);
|
||||
$response = $this->send($uri, $inmobiliaria_rut);
|
||||
$content = json_decode($response->getBody()->getContents(), JSON_OBJECT_AS_ARRAY);
|
||||
if (!is_array($content)) {
|
||||
$this->logger->error($content);
|
||||
return [];
|
||||
}
|
||||
return $content;
|
||||
}
|
||||
|
||||
private function send(string $uri, int $inmobiliaria_rut, string $method = 'GET', ?StreamInterface $body = null): ResponseInterface
|
||||
{
|
||||
@ -200,6 +208,12 @@ class Nubox extends Ideal\Service
|
||||
if ($body !== null) {
|
||||
$request = $request->withBody($body);
|
||||
}
|
||||
return $this->client->sendRequest($request);
|
||||
$response = $this->client->sendRequest($request);
|
||||
if ($response->getStatusCode() !== 200) {
|
||||
$json = json_decode($response->getBody()->getContents(), JSON_OBJECT_AS_ARRAY);
|
||||
$message = $json['Message'] ?? '';
|
||||
throw new Exception\HttpResponse($response->getReasonPhrase(), $message, $response->getStatusCode());
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
56
app/src/Service/Persona.php
Normal file
56
app/src/Service/Persona.php
Normal file
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
namespace Incoviba\Service;
|
||||
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class Persona extends Ideal\Service
|
||||
{
|
||||
public function __construct(LoggerInterface $logger, protected Repository\Persona $personaRepository,
|
||||
protected Repository\DatosPersona $datosPersonaRepository)
|
||||
{
|
||||
parent::__construct($logger);
|
||||
}
|
||||
|
||||
public function getByRut(int $rut): Model\Persona
|
||||
{
|
||||
return $this->process($this->personaRepository->fetchByRut($rut));
|
||||
}
|
||||
public function add(array $data): Model\Persona
|
||||
{
|
||||
try {
|
||||
$persona = $this->personaRepository->fetchByRut($data['rut']);
|
||||
} catch (Implement\Exception\EmptyResult) {
|
||||
$persona = $this->personaRepository->create($data);
|
||||
$persona = $this->personaRepository->save($persona);
|
||||
}
|
||||
if (isset($data['email']) or isset($data['telefono'])) {
|
||||
$datosData = ['persona_rut' => $persona->rut];
|
||||
if (isset($data['email'])) {
|
||||
$datosData['email'] = $data['email'];
|
||||
}
|
||||
if (isset($data['telefono'])) {
|
||||
$datosData['telefono'] = $data['telefono'];
|
||||
}
|
||||
try {
|
||||
$datos = $this->datosPersonaRepository->fetchByPersona($persona->rut);
|
||||
$this->datosPersonaRepository->edit($datos, $data);
|
||||
} catch (Implement\Exception\EmptyResult) {
|
||||
$datos = $this->datosPersonaRepository->create($datosData);
|
||||
$this->datosPersonaRepository->save($datos);
|
||||
}
|
||||
}
|
||||
return $this->process($persona);
|
||||
}
|
||||
|
||||
protected function process(Model\Persona $persona): Model\Persona
|
||||
{
|
||||
$persona->addFactory('datos', (new Implement\Repository\Factory())
|
||||
->setCallable([$this->datosPersonaRepository, 'fetchByPersona'])
|
||||
->setArgs(['persona_rut' => $persona->rut]));
|
||||
return $persona;
|
||||
}
|
||||
}
|
85
app/src/Service/Sociedad.php
Normal file
85
app/src/Service/Sociedad.php
Normal file
@ -0,0 +1,85 @@
|
||||
<?php
|
||||
namespace Incoviba\Service;
|
||||
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
|
||||
class Sociedad extends Ideal\Service
|
||||
{
|
||||
public function __construct(LoggerInterface $logger, protected Repository\Sociedad $sociedadRepository,
|
||||
protected Repository\Inmobiliaria $inmobiliariaRepository,
|
||||
protected Repository\Inmobiliaria\Proveedor $proveedorRepository)
|
||||
{
|
||||
parent::__construct($logger);
|
||||
}
|
||||
|
||||
public function getByRut(int $sociedad_rut): ?Model\Sociedad
|
||||
{
|
||||
try {
|
||||
return $this->process($this->sociedadRepository->fetchById($sociedad_rut));
|
||||
} catch (EmptyResult) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public function getAll(?string $orderBy = null): array
|
||||
{
|
||||
try {
|
||||
return array_map([$this, 'process'], $this->sociedadRepository->fetchAll($orderBy));
|
||||
} catch (EmptyResult) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
public function add(array $data): ?Model\Sociedad
|
||||
{
|
||||
try {
|
||||
return $this->process($this->sociedadRepository->fetchById($data['rut']));
|
||||
} catch (EmptyResult) {
|
||||
try {
|
||||
return $this->process($this->sociedadRepository->save($this->sociedadRepository->create($data)));
|
||||
} catch (EmptyResult) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
public function edit(int $sociedad_rut, array $data): ?Model\Sociedad
|
||||
{
|
||||
try {
|
||||
return $this->process(
|
||||
$this->sociedadRepository->edit(
|
||||
$this->sociedadRepository->fetchById($sociedad_rut), $data));
|
||||
} catch (EmptyResult) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public function delete(int $sociedad_rut): bool
|
||||
{
|
||||
try {
|
||||
$this->sociedadRepository->remove($this->sociedadRepository->fetchById($sociedad_rut));
|
||||
return true;
|
||||
} catch (EmptyResult) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public function asignar(int $inmobiliaria_rut, int $sociedad_rut): ?Model\Inmobiliaria\Proveedor
|
||||
{
|
||||
try {
|
||||
$inmobiliaria = $this->inmobiliariaRepository->fetchById($inmobiliaria_rut);
|
||||
$sociedad = $this->sociedadRepository->fetchById($sociedad_rut);
|
||||
$data = [
|
||||
'inmobiliaria_rut' => $inmobiliaria->rut,
|
||||
'sociedad_rut' => $sociedad->rut,
|
||||
];
|
||||
return $this->proveedorRepository->save($this->proveedorRepository->create($data));
|
||||
} catch (EmptyResult) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
protected function process(Model\Sociedad $sociedad): Model\Sociedad
|
||||
{
|
||||
return $sociedad;
|
||||
}
|
||||
}
|
95
app/src/Service/Venta/Factura.php
Normal file
95
app/src/Service/Venta/Factura.php
Normal file
@ -0,0 +1,95 @@
|
||||
<?php
|
||||
namespace Incoviba\Service\Venta;
|
||||
|
||||
use DateTimeInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class Factura extends Ideal\Service
|
||||
{
|
||||
public function __construct(LoggerInterface $logger,
|
||||
protected Repository\Venta\Factura $facturaRepository,
|
||||
protected Repository\Venta\Factura\Estado $estadoRepository,
|
||||
protected Repository\Venta\Factura\Estado\Tipo $tipoRepository)
|
||||
{
|
||||
parent::__construct($logger);
|
||||
}
|
||||
|
||||
public function getAll(null|string|array $orderBy = null): array
|
||||
{
|
||||
try {
|
||||
return array_map([$this, 'process'], $this->facturaRepository->fetchAll($orderBy));
|
||||
} catch (Implement\Exception\EmptyResult) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
public function getByVenta(int $venta_id): array
|
||||
{
|
||||
try {
|
||||
return array_map([$this, 'process'], $this->facturaRepository->fetchByVenta($venta_id));
|
||||
} catch (Implement\Exception\EmptyResult) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
public function getById(int $factura_id): ?Model\Venta\Factura
|
||||
{
|
||||
try {
|
||||
return $this->process($this->facturaRepository->fetchById($factura_id));
|
||||
} catch (Implement\Exception\EmptyResult) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public function getByVentaAndIndex(int $venta_id, int $index): ?Model\Venta\Factura
|
||||
{
|
||||
try {
|
||||
return $this->process($this->facturaRepository->fetchByVentaAndIndex($venta_id, $index));
|
||||
} catch (Implement\Exception\EmptyResult) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function add(array $data): Model\Venta\Factura
|
||||
{
|
||||
$factura = $this->getByVentaAndIndex($data['venta_id'], $data['index']);
|
||||
if ($factura !== null) {
|
||||
return $factura;
|
||||
}
|
||||
$factura = $this->facturaRepository->save($this->facturaRepository->create($data));
|
||||
$tipo = $this->tipoRepository->fetchByDescripcion('generada');
|
||||
$this->estadoRepository->save($this->estadoRepository->create([
|
||||
'factura_id' => $factura->id,
|
||||
'tipo_id' => $tipo->id,
|
||||
'fecha' => $factura->fecha
|
||||
]));
|
||||
return $this->process($factura);
|
||||
}
|
||||
public function aprobar(int $factura_id, DateTimeInterface $fecha): ?Model\Venta\Factura
|
||||
{
|
||||
try {
|
||||
$factura = $this->facturaRepository->fetchById($factura_id);
|
||||
$tipo = $this->tipoRepository->fetchByDescripcion('aprobada');
|
||||
$this->estadoRepository->save($this->estadoRepository->create([
|
||||
'factura_id' => $factura->id,
|
||||
'tipo_id' => $tipo->id,
|
||||
'fecha' => $fecha->format('Y-m-d')
|
||||
]));
|
||||
return $this->process($factura);
|
||||
} catch (Implement\Exception\EmptyResult) {
|
||||
$this->logger->error('Error al aprobar factura', ['factura_id' => $factura_id]);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
protected function process(Model\Venta\Factura $factura): Model\Venta\Factura
|
||||
{
|
||||
$factura->addFactory('estados', (new Implement\Repository\Factory())
|
||||
->setCallable(function($factura_id) {
|
||||
return $this->estadoRepository->fetchByFactura($factura_id);
|
||||
})
|
||||
->setArgs(['factura_id' => $factura->id]));
|
||||
return $factura;
|
||||
}
|
||||
}
|
@ -94,7 +94,7 @@ class Propietario extends Service
|
||||
if ($sociedad->datos->direccion->id !== $mapped_data['direccion']) {
|
||||
$edits['direccion'] = $mapped_data['direccion'];
|
||||
}
|
||||
if ($sociedad->representante->rut !== $mapped_data['representante']) {
|
||||
if ($sociedad->contacto->rut !== $mapped_data['representante']) {
|
||||
$edits['representante'] = $mapped_data['representante'];
|
||||
}
|
||||
$sociedad = $this->propietarioRepository->edit($sociedad, $edits);
|
||||
|
Reference in New Issue
Block a user