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;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user