Facturacion
This commit is contained in:
@ -2,6 +2,7 @@
|
||||
namespace Incoviba\Service\Contabilidad;
|
||||
|
||||
use DateTimeInterface;
|
||||
use DateTimeImmutable;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement\Exception;
|
||||
use Incoviba\Repository;
|
||||
@ -130,6 +131,34 @@ class Nubox extends Ideal\Service
|
||||
}
|
||||
return json_decode($response->getBody()->getContents(), JSON_OBJECT_AS_ARRAY);
|
||||
}
|
||||
public function getSaldoCuenta(int $inmobiliaria_rut, string $cuenta, DateTimeInterface $mes, bool $acumuladoAnual = false): array
|
||||
{
|
||||
$inmobiliaria = $this->nuboxRepository->fetchByInmobiliaria($inmobiliaria_rut);
|
||||
$from = new DateTimeImmutable($mes->format('Y-m-1'));
|
||||
$to = new DateTimeImmutable($mes->format('Y-m-t'));
|
||||
$query = [
|
||||
'NumeroSerie' => 1,
|
||||
'CodigoEmpresa' => $inmobiliaria->alias,
|
||||
'DDInicio' => $from->format('j'),
|
||||
'MMInicio' => $from->format('n'),
|
||||
'YYInicio' => $from->format('Y'),
|
||||
'DDTermino' => $to->format('j'),
|
||||
'MMTermino' => $to->format('n'),
|
||||
'YYTermino' => $to->format('Y'),
|
||||
'CodigoCentroDeCosto' => 0,
|
||||
'CodigoSucursal' => 0,
|
||||
'CodigoCuenta' => $cuenta,
|
||||
'ModoIFRS' => 'false',
|
||||
'CuentasConSaldo' => 'false',
|
||||
'IncluirCodigoCuenta' => 'true',
|
||||
];
|
||||
$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);
|
||||
}
|
||||
|
||||
private function send(string $uri, int $inmobiliaria_rut, string $method = 'GET', ?StreamInterface $body = null): ResponseInterface
|
||||
{
|
||||
|
36
app/src/Service/Proyecto/Terreno.php
Normal file
36
app/src/Service/Proyecto/Terreno.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
namespace Incoviba\Service\Proyecto;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Service;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Terreno extends Ideal\Service
|
||||
{
|
||||
public function __construct(LoggerInterface $logger, protected Repository\Proyecto $proyectoRepository,
|
||||
protected Service\Contabilidad\Nubox $nuboxService)
|
||||
{
|
||||
parent::__construct($logger);
|
||||
}
|
||||
|
||||
public function valor(int $proyecto_id): ?Model\Proyecto\Terreno
|
||||
{
|
||||
$terreno = null;
|
||||
try {
|
||||
$proyecto = $this->proyectoRepository->fetchById($proyecto_id);
|
||||
$today = new DateTimeImmutable();
|
||||
$lastDecember = (new DateTimeImmutable($today->modify('-1 year')->format('Y-12-31')));
|
||||
// 1110-02
|
||||
$movimientos = $this->nuboxService->getSaldoCuenta($proyecto->inmobiliaria()->rut, '1110-02', $lastDecember, true);
|
||||
error_log(var_export($movimientos, true).PHP_EOL,3,'/logs/debug');
|
||||
if ($proyecto->terreno->fecha >= $lastDecember) {
|
||||
return $proyecto->terreno;
|
||||
}
|
||||
} catch (Implement\Exception\EmptyResult) {}
|
||||
return $terreno;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user