Facturacion

This commit is contained in:
Juan Pablo Vial
2024-04-15 20:13:15 -04:00
parent 8e4b5eaaf8
commit a33dd341cd
8 changed files with 259 additions and 6 deletions

View File

@ -177,7 +177,7 @@
const cantidad = this.unidades.length
this.unidades.forEach(unidad => {
const values = [
venta,
'<a href="{{$urls->base}}/ventas/factura/' + this.id + '">' + venta + '</a>',
cantidad,
unidad.tipo,
unidad.descripcion,

View File

@ -184,8 +184,8 @@
totales: {},
proporcion: 1,
precio: {{$UF->transform($venta->currentEstado()->fecha, $venta->valor)}},
terreno: {{(isset($venta->proyecto()->terreno->fecha) and $venta->proyecto()->terreno->fecha >= $lastDic) ?
$IPC->readjust($venta->proyecto()->terreno->valor, $venta->proyecto()->terreno->fecha, $venta->currentEstado()->fecha) : 0}},
terreno: {{(isset($terreno->fecha) and $terreno->fecha >= $lastDic) ?
$IPC->readjust($terreno->valor, $terreno->fecha, $venta->currentEstado()->fecha) : 0}},
uf: {{$UF->get($venta->currentEstado()->fecha)}},
unidades: JSON.parse('{!! json_encode(array_map(function(Incoviba\Model\Venta\PropiedadUnidad $unidad) use ($venta, $UF, $format) {
$precio = ($unidad->valor > 0) ? $unidad->valor : ($unidad->precio($venta->currentEstado()->fecha) ? $unidad->precio($venta->currentEstado()->fecha)->valor : 0);

View 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);
}
}

View 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);
}
}

View File

@ -0,0 +1,32 @@
<?php
namespace Incoviba\Controller;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Incoviba\Repository;
use Incoviba\Common\Alias\View;
class CentrosCostos
{
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, View $view,
Repository\CentroCosto $centroCostoRepository,
Repository\TipoCentro $tipoCentroRepository,
Repository\CategoriaCentro $categoriaCentroRepository,
Repository\TipoCuenta $tipoCuentaRepository): ResponseInterface
{
$centrosCostos = $centroCostoRepository->fetchAll();
$tiposCentros = $tipoCentroRepository->fetchAll();
$categorias = $categoriaCentroRepository->fetchAll('descripcion');
$tiposCuentas = $tipoCuentaRepository->fetchAll();
return $view->render($response, 'contabilidad.centros_costos', compact('centrosCostos',
'tiposCentros', 'categorias', 'tiposCuentas'));
}
public function asignar(ServerRequestInterface $request, ResponseInterface $response, View $view,
Repository\CentroCosto $centroCostoRepository,
Repository\Inmobiliaria $inmobiliariaRepository): ResponseInterface
{
$centrosCostos = $centroCostoRepository->fetchAll();
$inmobiliarias = $inmobiliariaRepository->fetchAllActive('razon');
return $view->render($response, 'contabilidad.centros_costos.asignar', compact('centrosCostos', 'inmobiliarias'));
}
}

View File

@ -8,14 +8,18 @@ use Incoviba\Service;
class Facturacion
{
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, View $view, Service\Proyecto $proyectoService): ResponseInterface
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, View $view,
Service\Proyecto $proyectoService): ResponseInterface
{
$proyectos = $proyectoService->getEscriturando();
return $view->render($response, 'ventas.facturacion', compact('proyectos'));
}
public function show(ServerRequestInterface $request, ResponseInterface $response, View $view, Service\Venta $ventaService, int $venta_id): ResponseInterface
public function show(ServerRequestInterface $request, ResponseInterface $response, View $view,
Service\Venta $ventaService, Service\Proyecto\Terreno $terrenoService,
int $venta_id): ResponseInterface
{
$venta = $ventaService->getById($venta_id);
return $view->render($response, 'ventas.facturacion.show', compact('venta'));
$terreno = $terrenoService->valor($venta->proyecto()->id);
return $view->render($response, 'ventas.facturacion.show', compact('venta', 'terreno'));
}
}

View File

@ -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
{

View 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;
}
}