2024-06-18

This commit is contained in:
Juan Pablo Vial
2024-06-18 22:41:03 -04:00
parent 6169089475
commit 390e79ad6d
60 changed files with 3162 additions and 155 deletions

View File

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

View File

@ -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);

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

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

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

View File

@ -80,6 +80,12 @@ class Contabilidad extends Controller
$informes = $contabilidadService->build($fecha);
$filename = "Informe de Tesorería {$fecha->format('d.m.Y')}";
return $view->render($response, 'contabilidad.informes.tesoreria', compact('fecha', 'anterior', 'siguiente', 'informes', 'filename'));
}
public function semanal(ServerRequestInterface $request, ResponseInterface $response, View $view,
Service\Contabilidad\Informe\Semanal $semanalService,
string $fecha = 'today'): ResponseInterface
{
}
public function cuadratura(ServerRequestInterface $request, ResponseInterface $response, View $view,
Repository\Inmobiliaria $inmobiliariaRepository): ResponseInterface

View File

@ -0,0 +1,27 @@
<?php
namespace Incoviba\Controller\Inmobiliarias;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Incoviba\Common\Implement\Exception\EmptyResult;
use Incoviba\Common\Alias\View;
use Incoviba\Repository;
use Incoviba\Service;
class Proveedores
{
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, View $view,
Service\Sociedad $sociedadService,
Repository\Inmobiliaria\TipoSociedad $tipoSociedad): ResponseInterface
{
$sociedades = [];
try {
$sociedades = $sociedadService->getAll('nombre');
} catch (EmptyResult) {}
$tiposSociedades = [];
try {
$tiposSociedades = $tipoSociedad->fetchAll('descripcion');
} catch (EmptyResult) {}
return $view->render($response, 'inmobiliarias.proveedores', compact('sociedades', 'tiposSociedades'));
}
}

View File

@ -26,9 +26,10 @@ class Facturacion extends Ideal\Controller
* @throws Exception
*/
public function show(ServerRequestInterface $request, ResponseInterface $response, View $view,
Service\Venta $ventaService, Service\Proyecto\Terreno $terrenoService,
Service\IPC $ipcService, Service\UF $ufService,
int $venta_id): ResponseInterface
Service\Venta $ventaService, Service\Proyecto\Terreno $terrenoService,
Service\IPC $ipcService, Service\UF $ufService,
Service\Venta\Factura $facturasService,
int $venta_id): ResponseInterface
{
$venta = $ventaService->getById($venta_id);
$uf = $ufService->get($venta->currentEstado()->fecha);
@ -48,7 +49,8 @@ class Facturacion extends Ideal\Controller
$ipc = $ipcService->get($prevMonthTerreno, $prevMonth);
}
}
$facturas = $facturasService->getByVenta($venta->id);
return $view->render($response, 'ventas.facturacion.show', compact('venta', 'terreno', 'uf', 'ipc'));
return $view->render($response, 'ventas.facturacion.show', compact('venta', 'terreno', 'uf', 'ipc', 'facturas'));
}
}

View File

@ -4,8 +4,8 @@ namespace Incoviba\Model\Contabilidad;
use DateTimeInterface;
use Incoviba\Common\Ideal;
use Incoviba\Common\Implement\Exception\EmptyResult;
use Incoviba\Model\Contabilidad\Movimiento\Detalle;
use Incoviba\Model\Inmobiliaria;
use Incoviba\Model\Movimiento\Detalle;
class Movimiento extends Ideal\Model
{
@ -21,15 +21,20 @@ class Movimiento extends Ideal\Model
public function getDetalles(): ?Detalle
{
if (!isset($this->detalles)) {
try {
$this->detalles = $this->runFactory('detalles');
} catch (EmptyResult) {
$this->detalles = null;
}
$this->detalles = $this->runFactory('detalles');
}
return $this->detalles;
}
protected ?array $auxiliares;
public function getAuxiliares(): ?array
{
if (!isset($this->auxiliares)) {
$this->auxiliares = $this->runFactory('auxiliares');
}
return $this->auxiliares;
}
public function jsonSerialize(): mixed
{
return array_merge(parent::jsonSerialize(), [
@ -40,7 +45,8 @@ class Movimiento extends Ideal\Model
'cargo' => $this->cargo,
'abono' => $this->abono,
'saldo' => $this->saldo,
'detalles' => $this->getDetalles() ?? null
'detalles' => $this->getDetalles(),
'auxiliares' => $this->getAuxiliares()
]);
}
}

View File

@ -0,0 +1,36 @@
<?php
namespace Incoviba\Model\Contabilidad\Movimiento;
use Incoviba\Common\Ideal;
use Incoviba\Common\Implement;
use Incoviba\Model;
class Auxiliar extends Ideal\Model
{
public Model\Contabilidad\Movimiento $movimiento;
public int $cargo;
public int $abono;
protected ?Model\Contabilidad\Movimiento\Auxiliar\Detalle $detalles;
public function getDetalles(): ?Model\Contabilidad\Movimiento\Auxiliar\Detalle
{
if (!isset($this->detalles)) {
try {
$this->detalles = $this->runFactory('detalles');
} catch (Implement\Exception\EmptyResult) {
$this->detalles = null;
}
}
return $this->detalles;
}
public function jsonSerialize(): mixed
{
return array_merge(parent::jsonSerialize(), [
'movimiento_id' => $this->movimiento->id,
'cargo' => $this->cargo,
'abono' => $this->abono,
'detalles' => $this->getDetalles()
]);
}
}

View File

@ -0,0 +1,39 @@
<?php
namespace Incoviba\Model\Contabilidad\Movimiento\Auxiliar;
use Incoviba\Common\Ideal;
use Incoviba\Model;
class Detalle extends Ideal\Model
{
public Model\Contabilidad\Movimiento\Auxiliar $auxiliar;
public ?Model\Contabilidad\CentroCosto $centroCosto;
public ?int $rut;
public ?string $digito;
public ?string $nombre;
public ?string $categoria;
public ?string $detalle;
public function rut(): string
{
return $this->rut . '-' . $this->digito;
}
public function rutFormatted(): string
{
return number_format($this->rut, 0, ',', '.') . '-' . $this->digito;
}
public function jsonSerialize(): mixed
{
return [
'auxiliar_id' => $this->auxiliar->id,
'centro_costo' => $this->centroCosto,
'rut' => $this->rut,
'digito' => $this->digito,
'nombre' => $this->nombre,
'categoria' => $this->categoria,
'detalle' => $this->detalle,
'rutFormatted' => $this->rutFormatted(),
];
}
}

View File

@ -0,0 +1,39 @@
<?php
namespace Incoviba\Model\Contabilidad\Movimiento;
use Incoviba\Common\Ideal;
use Incoviba\Model;
class Detalle extends Ideal\Model
{
public Model\Contabilidad\Movimiento $movimiento;
public ?Model\Contabilidad\CentroCosto $centroCosto;
public ?int $rut;
public ?string $digito;
public ?string $nombre;
public ?string $categoria;
public ?string $detalle;
public function rut(): string
{
return $this->rut . '-' . $this->digito;
}
public function rutFormatted(): string
{
return number_format($this->rut, 0, ',', '.') . '-' . $this->digito;
}
public function jsonSerialize(): mixed
{
return [
'movimiento_id' => $this->movimiento->id,
'centro_costo' => $this->centroCosto,
'rut' => $this->rut,
'digito' => $this->digito,
'nombre' => $this->nombre,
'categoria' => $this->categoria,
'detalle' => $this->detalle,
'rutFormatted' => $this->rutFormatted()
];
}
}

View File

@ -0,0 +1,32 @@
<?php
namespace Incoviba\Model;
use DateTimeInterface;
use Incoviba\Common\Ideal;
class DatosPersona extends Ideal\Model
{
public Persona $persona;
public ?Direccion $direccion;
public ?int $telefono;
public ?string $email;
public ?DateTimeInterface $fechaNacimiento;
public ?string $sexo;
public ?string $estadoCivil;
public ?string $nacionalidad;
public ?string $profesion;
public function jsonSerialize(): mixed
{
return [
'direccion' => $this->direccion,
'telefono' => $this->telefono,
'email' => $this->email,
'fechaNacimiento' => $this->fechaNacimiento,
'sexo' => $this->sexo,
'estadoCivil' => $this->estadoCivil,
'nacionalidad' => $this->nacionalidad,
'profesion' => $this->profesion,
];
}
}

View File

@ -0,0 +1,29 @@
<?php
namespace Incoviba\Model\Inmobiliaria;
use Incoviba\Common\Ideal;
use Incoviba\Model;
class Proveedor extends Ideal\Model
{
public Model\Inmobiliaria $inmobiliaria;
public Model\Sociedad $sociedad;
protected array $tipos;
public function tipos(): array
{
if (!isset($this->tipos)) {
$this->tipos = $this->runFactory('tipos');
}
return $this->tipos;
}
public function jsonSerialize(): mixed
{
return array_merge(parent::jsonSerialize(), [
'inmobiliaria' => $this->inmobiliaria,
'sociedad' => $this->sociedad,
'tipos' => $this->tipos(),
]);
}
}

View File

@ -1,21 +0,0 @@
<?php
namespace Incoviba\Model\Movimiento;
use Incoviba\Common\Ideal;
use Incoviba\Model;
class Detalle extends Ideal\Model
{
public Model\Contabilidad\Movimiento $movimiento;
public ?Model\Contabilidad\CentroCosto $centroCosto;
public ?string $detalle;
public function jsonSerialize(): mixed
{
return [
'movimiento_id' => $this->movimiento->id,
'centro_costo' => $this->centroCosto,
'detalle' => $this->detalle
];
}
}

46
app/src/Model/Persona.php Normal file
View File

@ -0,0 +1,46 @@
<?php
namespace Incoviba\Model;
use Incoviba\Common\Ideal;
class Persona extends Ideal\Model
{
public int $rut;
public string $digito;
public string $nombres;
public string $apellidoPaterno;
public string $apellidoMaterno;
public function nombreCompleto(): string
{
return $this->nombres . ' ' . $this->apellidoPaterno . ' ' . $this->apellidoMaterno;
}
public function rutCompleto(): string
{
return number_format($this->rut, 0, ',', '.') . '-' . $this->digito;
}
protected ?DatosPersona $datos;
public function datos(): ?DatosPersona
{
if (!isset($this->datos)) {
$this->datos = $this->runFactory('datos');
}
return $this->datos;
}
public function jsonSerialize(): mixed
{
return [
'rut' => $this->rut,
'digito' => $this->digito,
'nombres' => $this->nombres,
'apellidoPaterno' => $this->apellidoPaterno,
'apellidoMaterno' => $this->apellidoMaterno,
'nombreCompleto' => $this->nombreCompleto(),
'rutCompleto' => $this->rutCompleto(),
'datos' => $this->datos(),
];
}
}

View File

@ -0,0 +1,33 @@
<?php
namespace Incoviba\Model;
use Incoviba\Common\Ideal;
use Incoviba\Model\Inmobiliaria\TipoSociedad;
class Sociedad extends Ideal\Model
{
public int $rut;
public string $digito;
public string $nombre;
public string $razonSocial;
public TipoSociedad $tipoSociedad;
public Persona $contacto;
public function nombreCompleto(): string
{
return implode(' ', [$this->razonSocial, $this->tipoSociedad->descripcion]);
}
public function jsonSerialize(): mixed
{
return [
'rut' => $this->rut,
'digito' => $this->digito,
'nombre' => $this->nombre,
'razonSocial' => $this->razonSocial,
'tipoSociedad' => $this->tipoSociedad,
'contacto' => $this->contacto,
'nombreCompleto' => $this->nombreCompleto(),
];
}
}

View File

@ -0,0 +1,86 @@
<?php
namespace Incoviba\Model\Venta;
use DateTimeInterface;
use Incoviba\Common\Ideal;
use Incoviba\Model;
class Factura extends Ideal\Model
{
public Model\Venta $venta;
public int $index;
public float $proporcion;
public string $emisorRut;
public string $emisorNombre;
public string $emisorDireccion;
public string $receptorRut;
public string $receptorNombre;
public string $receptorDireccion;
public string $receptorComuna;
public DateTimeInterface $fecha;
public array $unidades;
public int $detalleBase;
public int $detalleTerreno;
public int $detalleNeto;
public int $detalleIva;
public int $detalleBruto;
public float $detalleDescuento;
public int $detalleTotal;
public int $totalNeto;
public int $totalExento;
public int $totalIva;
public int $totalTotal;
public DateTimeInterface $fechaUF;
public float $valorUF;
protected array $estados;
public function estados(): array
{
if (!isset($this->estados)) {
$this->estados = $this->runFactory('estados');
}
return $this->estados ?? [];
}
public function jsonSerialize(): mixed
{
return array_merge(parent::jsonSerialize(), [
'venta_id' => $this->venta->id,
'index' => $this->index,
'proporcion' => $this->proporcion,
'emisor' => [
'rut' => $this->emisorRut,
'nombre' => $this->emisorNombre,
'direccion' => $this->emisorDireccion
],
'receptor' => [
'rut' => $this->receptorRut,
'nombre' => $this->receptorNombre,
'direccion' => $this->receptorDireccion,
'comuna' => $this->receptorComuna
],
'fecha' => $this->fecha->format('Y-m-d'),
'unidades' => $this->unidades,
'detalle' => [
'base' => $this->detalleBase,
'terreno' => $this->detalleTerreno,
'neto' => $this->detalleNeto,
'iva' => $this->detalleIva,
'bruto' => $this->detalleBruto,
'descuento' => $this->detalleDescuento,
'total' => $this->detalleTotal
],
'total' => [
'neto' => $this->totalNeto,
'exento' => $this->totalExento,
'iva' => $this->totalIva,
'total' => $this->totalTotal
],
'uf' => [
'fecha' => $this->fechaUF->format('Y-m-d'),
'valor' => $this->valorUF
],
'estados' => $this->estados()
]);
}
}

View File

@ -0,0 +1,22 @@
<?php
namespace Incoviba\Model\Venta\Factura;
use DateTimeInterface;
use Incoviba\Common\Ideal;
use Incoviba\Model;
class Estado extends Ideal\Model
{
public Model\Venta\Factura $factura;
public DateTimeInterface $fecha;
public Model\Venta\Factura\Estado\Tipo $tipo;
public function jsonSerialize(): mixed
{
return array_merge(parent::jsonSerialize(), [
'factura_id' => $this->factura->id,
'fecha' => $this->fecha->format('Y-m-d'),
'tipo' => $this->tipo
]);
}
}

View File

@ -0,0 +1,7 @@
<?php
namespace Incoviba\Model\Venta\Factura\Estado;
use Incoviba\Model\Tipo as Base;
class Tipo extends Base
{}

View File

@ -0,0 +1,62 @@
<?php
namespace Incoviba\Repository\Contabilidad\Movimiento;
use Incoviba\Common\Define;
use Incoviba\Common\Ideal;
use Incoviba\Common\Implement;
use Incoviba\Common\Implement\Exception\EmptyResult;
use Incoviba\Model;
use Incoviba\Repository;
class Auxiliar extends Ideal\Repository
{
public function __construct(Define\Connection $connection, protected Repository\Contabilidad\Movimiento $movimientoRepository)
{
parent::__construct($connection);
$this->setTable('movimientos_auxiliares');
}
public function create(?array $data = null): Model\Contabilidad\Movimiento\Auxiliar
{
$map = (new Implement\Repository\MapperParser(['cargo', 'abono']))
->register('movimiento_id', (new Implement\Repository\Mapper())
->setProperty('movimiento')
->setFunction(function($data) {
return $this->movimientoRepository->fetchById($data['movimiento_id']);
}));
return $this->parseData(new Model\Contabilidad\Movimiento\Auxiliar(), $data, $map);
}
public function save(Define\Model $model): Model\Contabilidad\Movimiento\Auxiliar
{
$model->id = $this->saveNew([
'movimiento_id',
'cargo',
'abono'
],[
$model->movimiento->id,
$model->cargo,
$model->abono
]);
return $model;
}
public function edit(Define\Model $model, array $new_data): Model\Contabilidad\Movimiento\Auxiliar
{
return $this->update($model, [
'movimiento_id',
'cargo',
'abono'
], $new_data);
}
/**
* @throws EmptyResult
*/
public function fetchByMovimiento(int $movimiento_id): array
{
$query = $this->connection->getQueryBuilder()
->select()
->from($this->getTable())
->where('movimiento_id = :movimiento_id');
return $this->fetchMany($query, ['movimiento_id' => $movimiento_id]);
}
}

View File

@ -0,0 +1,72 @@
<?php
namespace Incoviba\Repository\Contabilidad\Movimiento\Auxiliar;
use Incoviba\Common\Define;
use Incoviba\Common\Ideal;
use Incoviba\Common\Implement;
use Incoviba\Common\Implement\Exception\EmptyResult;
use Incoviba\Model;
use Incoviba\Repository;
class Detalle extends Ideal\Repository
{
public function __construct(Define\Connection $connection,
protected Repository\Contabilidad\Movimiento\Auxiliar $auxiliarRepository,
protected Repository\Contabilidad\CentroCosto $centroCostoRepository)
{
parent::__construct($connection);
$this->setTable('auxiliar_detalles');
}
public function create(?array $data = null): Model\Contabilidad\Movimiento\Auxiliar\Detalle
{
$map = (new Implement\Repository\MapperParser(['rut', 'digito', 'nombre', 'categoria', 'detalle']))
->register('auxiliar_id', (new Implement\Repository\Mapper())
->setProperty('auxiliar')
->setFunction(function($data) {
return $this->auxiliarRepository->fetchById($data['auxiliar_id']);
}))
->register('centro_costo_id', (new Implement\Repository\Mapper())
->setProperty('centroCosto')
->setFunction(function($data) {
return $this->centroCostoRepository->fetchById($data['centro_costo_id']);
})
->setDefault(null));
return $this->parseData(new Model\Contabilidad\Movimiento\Auxiliar\Detalle(), $data, $map);
}
public function save(Define\Model $model): Model\Contabilidad\Movimiento\Auxiliar\Detalle
{
$this->saveNew([
'auxiliar_id',
'rut',
'digito',
'nombre',
'categoria',
'detalle'
], [
$model->auxiliar->id,
$model->rut,
$model->digito,
$model->nombre,
$model->categoria,
$model->detalle
]);
return $model;
}
public function edit(Define\Model $model, array $new_data): Model\Contabilidad\Movimiento\Auxiliar\Detalle
{
return $this->update($model, ['rut', 'digito', 'nombre', 'categoria', 'detalle'], $new_data);
}
/**
* @throws EmptyResult
*/
public function fetchByAuxiliar(int $auxiliar_id): array
{
$query = $this->connection->getQueryBuilder()
->select()
->from($this->getTable())
->where('auxiliar_id = :auxiliar_id');
return $this->fetchMany($query, ['auxiliar_id' => $auxiliar_id]);
}
}

View File

@ -1,5 +1,5 @@
<?php
namespace Incoviba\Repository\Movimiento;
namespace Incoviba\Repository\Contabilidad\Movimiento;
use Incoviba\Common\Define;
use Incoviba\Common\Ideal;
@ -9,14 +9,15 @@ use Incoviba\Repository;
class Detalle extends Ideal\Repository
{
public function __construct(Define\Connection $connection, protected Repository\Contabilidad\Movimiento $movimientoRepository,
public function __construct(Define\Connection $connection,
protected Repository\Contabilidad\Movimiento $movimientoRepository,
protected Repository\Contabilidad\CentroCosto $centroCostoRepository)
{
parent::__construct($connection);
$this->setTable('movimientos_detalles');
}
public function create(?array $data = null): Model\Movimiento\Detalle
public function create(?array $data = null): Model\Contabilidad\Movimiento\Detalle
{
$map = (new Implement\Repository\MapperParser(['detalle']))
->register('movimiento_id', (new Implement\Repository\Mapper())
@ -29,22 +30,22 @@ class Detalle extends Ideal\Repository
->setFunction(function(array $data) {
return $this->centroCostoRepository->fetchById($data['centro_costo_id']);
}));
return $this->parseData(new Model\Movimiento\Detalle(), $data, $map);
return $this->parseData(new Model\Contabilidad\Movimiento\Detalle(), $data, $map);
}
public function save(Define\Model $model): Model\Movimiento\Detalle
public function save(Define\Model $model): Model\Contabilidad\Movimiento\Detalle
{
$this->saveNew(
['movimiento_id', 'centro_costo_id', 'detalle'],
[$model->movimiento->id, $model->centroCosto->id, $model->detalle]
[$model->movimiento->id, $model->centroCosto->id, $model->detalles]
);
return $model;
}
public function edit(Define\Model $model, array $new_data): Model\Movimiento\Detalle
public function edit(Define\Model $model, array $new_data): Model\Contabilidad\Movimiento\Detalle
{
return $this->update($model, ['movimiento_id', 'centro_costo_id', 'detalle'], $new_data);
}
public function fetchByMovimiento(int $movimiento_id): Model\Movimiento\Detalle
public function fetchByMovimiento(int $movimiento_id): Model\Contabilidad\Movimiento\Detalle
{
$query = $this->connection->getQueryBuilder()
->select()

View File

@ -0,0 +1,86 @@
<?php
namespace Incoviba\Repository;
use Incoviba\Common\Define;
use Incoviba\Common\Ideal;
use Incoviba\Common\Implement;
use Incoviba\Model;
class DatosPersona extends Ideal\Repository
{
public function __construct(Define\Connection $connection, protected Persona $personaRepository,
protected Direccion $direccionRepository)
{
parent::__construct($connection);
$this->setTable('datos_personas');
}
public function create(?array $data = null): Model\DatosPersona
{
$map = (new Implement\Repository\MapperParser())
->register('persona_rut', (new Implement\Repository\Mapper())
->setProperty('persona')
->setFunction(function($data) {
return $this->personaRepository->fetchById($data['persona_rut']);
}))
->register('direccion_id', (new Implement\Repository\Mapper())
->setProperty('direccion')
->setFunction(function($data) {
return $this->direccionRepository->fetchById($data['direccion_id']);
})->setDefault(null))
->register('telefono', (new Implement\Repository\Mapper())->setFunction(function($data) {
return $data['telefono'];
})->setDefault(null))
->register('email', (new Implement\Repository\Mapper())->setFunction(function($data) {
return $data['email'];
})->setDefault(null))
->register('fecha_nacimiento', (new Implement\Repository\Mapper\DateTime('fecha_nacimiento'))
->setDefault(null)
->setProperty('fechaNacimiento'))
->register('sexo', (new Implement\Repository\Mapper())->setFunction(function($data) {
return $data['sexo'];
})->setDefault(null))
->register('estado_civil', (new Implement\Repository\Mapper())->setFunction(function($data) {
return $data['estado_civil'];
})->setDefault(null)->setProperty('estadoCivil'))
->register('nacionalidad', (new Implement\Repository\Mapper())->setFunction(function($data) {
return $data['nacionalidad'];
})->setDefault(null))
->register('profesion', (new Implement\Repository\Mapper())->setFunction(function($data) {
return $data['profesion'];
})->setDefault(null));
return $this->parseData(new Model\DatosPersona(), $data, $map);
}
public function save(Define\Model $model): Model\DatosPersona
{
$this->saveNew([
'persona_rut', 'direccion_id', 'telefono', 'email', 'fecha_nacimiento', 'sexo', 'estado_civil',
'nacionalidad', 'profesion'
], [
$model->persona->rut, $model->direccion?->id, $model->telefono, $model->email, $model->fechaNacimiento,
$model->sexo, $model->estadoCivil, $model->nacionalidad, $model->profesion
]);
return $model;
}
public function edit(Define\Model $model, array $new_data): Model\DatosPersona
{
return $this->update($model, [
'direccion_id', 'telefono', 'email', 'fecha_nacimiento', 'sexo', 'estado_civil',
'nacionalidad', 'profesion'
], $new_data);
}
public function fetchByPersona(int $persona_rut): Model\DatosPersona
{
$query = $this->connection->getQueryBuilder()
->select()
->from($this->getTable())
->where('persona_rut = ?');
return $this->fetchOne($query, [$persona_rut]);
}
protected function getKey(): string
{
return 'persona_rut';
}
}

View File

@ -24,6 +24,7 @@ class AgenteTipo extends Ideal\Repository
return ($data === null) ? null : $this->agenteRepository->fetchById($data['agente']);
}))
->register('tipo', (new Implement\Repository\Mapper())
->setProperty('tipoAgente')
->setFunction(function(?array $data) {
return ($data === null) ? null : $this->tipoAgenteRepository->fetchById($data['tipo']);
}));

View File

@ -0,0 +1,61 @@
<?php
namespace Incoviba\Repository\Inmobiliaria;
use Incoviba\Common\Define;
use Incoviba\Common\Ideal;
use Incoviba\Common\Implement;
use Incoviba\Model;
use Incoviba\Repository;
use Incoviba\Service;
class Proveedor extends Ideal\Repository
{
public function __construct(Define\Connection $connection, protected Repository\Inmobiliaria $inmobiliariaRepository,
protected Repository\Sociedad $sociedadRepository)
{
parent::__construct($connection);
$this->setTable('proveedores');
}
public function create(?array $data = null): Model\Inmobiliaria\Proveedor
{
$map = (new Implement\Repository\MapperParser())
->register('inmobiliaria_rut', (new Implement\Repository\Mapper())
->setProperty('inmobiliaria')
->setFunction(function($data) {
return $this->inmobiliariaRepository->fetchById($data['inmobiliaria_rut']);
}))
->register('sociedad_rut', (new Implement\Repository\Mapper())
->setProperty('sociedad')
->setFunction(function($data) {
return $this->sociedadRepository->fetchById($data['sociedad_rut']);
}));
return $this->parseData(new Model\Inmobiliaria\Proveedor(), $data, $map);
}
public function save(Define\Model $model): Model\Inmobiliaria\Proveedor
{
$model->id = $this->saveNew(['inmobiliaria_rut', 'sociedad_rut'], [$model->inmobiliaria->rut, $model->sociedad->rut]);
return $model;
}
public function edit(Define\Model $model, array $new_data): Model\Inmobiliaria\Proveedor
{
return $this->update($model, ['sociedad_id'], $new_data);
}
public function fetchByInmobiliaria(int $inmobiliaria_rut): array
{
$query = $this->connection->getQueryBuilder()
->select()
->from($this->getTable())
->where('inmobiliaria_rut = :inmobiliaria_rut');
return array_map([$this, 'load'], $this->fetchMany($query, compact('inmobiliaria_rut')));
}
public function fetchBySociedad(int $sociedad_rut): array
{
$query = $this->connection->getQueryBuilder()
->select()
->from($this->getTable())
->where('sociedad_rut = :sociedad_rut');
return array_map([$this, 'load'], $this->fetchMany($query, compact('sociedad_rut')));
}
}

View File

@ -0,0 +1,49 @@
<?php
namespace Incoviba\Repository;
use Incoviba\Common\Define;
use Incoviba\Common\Ideal;
use Incoviba\Common\Implement;
use Incoviba\Model;
class Persona extends Ideal\Repository
{
public function __construct(Define\Connection $connection)
{
parent::__construct($connection);
$this->setTable('personas');
}
public function create(?array $data = null): Model\Persona
{
$map = (new Implement\Repository\MapperParser(['rut', 'digito', 'nombres']))
->register('apellido_paterno', (new Implement\Repository\Mapper())->setProperty('apellidoPaterno'))
->register('apellido_materno', (new Implement\Repository\Mapper())->setProperty('apellidoMaterno'))
;
return $this->parseData(new Model\Persona(), $data, $map);
}
public function save(Define\Model $model): Model\Persona
{
$this->saveNew(['rut', 'digito', 'nombres', 'apellido_paterno', 'apellido_materno'],
[$model->rut, $model->digito, $model->nombres, $model->apellidoPaterno, $model->apellidoMaterno]);
return $model;
}
public function edit(Define\Model $model, array $new_data): Model\Persona
{
return $this->update($model, $new_data, ['rut', 'digito', 'nombres', 'apellido_paterno', 'apellido_materno']);
}
public function fetchByRut(int $rut): Model\Persona
{
$query = $this->connection->getQueryBuilder()
->select()
->from($this->getTable())
->where('rut = ?');
return $this->fetchOne($query, [$rut]);
}
protected function getKey(): string
{
return 'rut';
}
}

View File

@ -0,0 +1,55 @@
<?php
namespace Incoviba\Repository;
use Incoviba\Common\Define;
use Incoviba\Common\Ideal;
use Incoviba\Common\Implement;
use Incoviba\Model;
use Incoviba\Service;
class Sociedad extends Ideal\Repository
{
public function __construct(Define\Connection $connection,
protected Inmobiliaria\TipoSociedad $tipoSociedadRepository,
protected Service\Persona $personaService)
{
parent::__construct($connection);
$this->setTable('sociedades');
}
public function create(?array $data = null): Model\Sociedad
{
$map = (new Implement\Repository\MapperParser(['rut', 'digito', 'nombre']))
->register('razon', (new Implement\Repository\Mapper())
->setProperty('razonSocial'))
->register('tipo_sociedad_id', (new Implement\Repository\Mapper())
->setProperty('tipoSociedad')
->setFunction(function ($data) {
return $this->tipoSociedadRepository->fetchById($data['tipo_sociedad_id']);
})
)
->register('contacto_rut', (new Implement\Repository\Mapper())
->setProperty('contacto')
->setFunction(function ($data) {
return $this->personaService->getByRut($data['contacto_rut']);
}));
return $this->parseData(new Model\Sociedad(), $data, $map);
}
public function save(Define\Model $model): Model\Sociedad
{
$this->saveNew(['rut', 'digito', 'nombre', 'razon', 'tipo_sociedad_id', 'contacto_rut'],
[$model->rut, $model->digito, $model->nombre, $model->razonSocial, $model->tipoSociedad->id,
$model->contacto->rut]);
return $model;
}
public function edit(Define\Model $model, array $new_data): Model\Sociedad
{
return $this->update($model,
['digito', 'nombre', 'razon', 'tipo_sociedad_id', 'contacto_rut'], $new_data);
}
protected function getKey(): string
{
return 'rut';
}
}

View File

@ -0,0 +1,129 @@
<?php
namespace Incoviba\Repository\Venta;
use DateTimeImmutable;
use Incoviba\Common\Define;
use Incoviba\Common\Ideal;
use Incoviba\Common\Implement;
use Incoviba\Common\Implement\Exception\EmptyResult;
use Incoviba\Model;
use Incoviba\Repository;
class Factura extends Ideal\Repository
{
public function __construct(Implement\Connection $connection, protected Repository\Venta $ventaRepository)
{
parent::__construct($connection);
$this->setTable('facturas');
}
public function create(?array $data = null): Model\Venta\Factura
{
$map = (new Implement\Repository\MapperParser(['index']))
->register('venta_id', (new Implement\Repository\Mapper())
->setProperty('venta')
->setFunction(function($data) {
return $this->ventaRepository->fetchById($data['venta_id']);
}));
$factura = $this->parseData(new Model\Venta\Factura(), $data, $map);
$json = json_decode($data['data']);
$factura->proporcion = $json->proporcion;
$factura->emisorRut = $json->emisor->rut;
$factura->emisorNombre = $json->emisor->nombre;
$factura->emisorDireccion = $json->emisor->direccion;
$factura->receptorRut = $json->receptor->rut;
$factura->receptorNombre = $json->receptor->nombre;
$factura->receptorDireccion = $json->receptor->direccion;
$factura->receptorComuna = $json->receptor->comuna;
$factura->fecha = new DateTimeImmutable($json->fecha);
$factura->unidades = $json->unidades;
$factura->detalleBase = $json->detalle->base;
$factura->detalleTerreno = $json->detalle->terreno;
$factura->detalleNeto = $json->detalle->neto;
$factura->detalleIva = $json->detalle->iva;
$factura->detalleBruto = $json->detalle->bruto;
$factura->detalleDescuento = $json->detalle->descuento;
$factura->detalleTotal = $json->detalle->total;
$factura->totalNeto = $json->total->neto;
$factura->totalExento = $json->total->exento;
$factura->totalIva = $json->total->iva;
$factura->totalTotal = $json->total->total;
$factura->fechaUF = new DateTimeImmutable($json->uf->fecha);
$factura->valorUF = $json->uf->valor;
return $factura;
}
public function save(Define\Model $model): Model\Venta\Factura
{
$model->id = $this->saveNew([
'venta_id',
'index',
'data'
], [
$model->venta->id,
$model->index,
json_encode([
'proporcion' => $model->proporcion,
'emisor' => [
'rut' => $model->emisorRut,
'nombre' => $model->emisorNombre,
'direccion' => $model->emisorDireccion
],
'receptor' => [
'rut' => $model->receptorRut,
'nombre' => $model->receptorNombre,
'direccion' => $model->receptorDireccion,
'comuna' => $model->receptorComuna
],
'fecha' => $model->fecha->format('Y-m-d'),
'unidades' => $model->unidades,
'detalle' => [
'base' => $model->detalleBase,
'terreno' => $model->detalleTerreno,
'neto' => $model->detalleNeto,
'iva' => $model->detalleIva,
'bruto' => $model->detalleBruto,
'descuento' => $model->detalleDescuento,
'total' => $model->detalleTotal
],
'total' => [
'neto' => $model->totalNeto,
'exento' => $model->totalExento,
'iva' => $model->totalIva,
'total' => $model->totalTotal
],
'uf' => [
'fecha' => $model->fechaUF->format('Y-m-d'),
'valor' => $model->valorUF
]
])
]);
return $model;
}
public function edit(Define\Model $model, array $new_data): Model\Venta\Factura
{
return $this->update($model, ['venta_id', 'index', 'data'], $new_data);
}
/**
* @throws EmptyResult
*/
public function fetchByVenta(int $venta_id): array
{
$query = $this->connection->getQueryBuilder()
->select()
->from($this->getTable())
->where('venta_id = :venta_id');
return $this->fetchMany($query, ['venta_id' => $venta_id]);
}
/**
* @throws EmptyResult
*/
public function fetchByVentaAndIndex(int $venta_id, int $index): Model\Venta\Factura
{
$query = $this->connection->getQueryBuilder()
->select()
->from($this->getTable())
->where('venta_id = :venta_id AND index = :index');
return $this->fetchOne($query, ['venta_id' => $venta_id, 'index' => $index]);
}
}

View File

@ -0,0 +1,60 @@
<?php
namespace Incoviba\Repository\Venta\Factura;
use Incoviba\Common\Define;
use Incoviba\Common\Ideal;
use Incoviba\Common\Implement;
use Incoviba\Model;
use Incoviba\Repository;
class Estado extends Ideal\Repository
{
public function __construct(Define\Connection $connection, protected Repository\Venta\Factura $facturaRepository, protected Repository\Venta\Factura\Estado\Tipo $tipoRepository)
{
parent::__construct($connection);
$this->setTable('estados_facturas');
}
public function create(?array $data = null): Model\Venta\Factura\Estado
{
$map = (new Implement\Repository\MapperParser())
->register('factura_id', (new Implement\Repository\Mapper())
->setProperty('factura')
->setFunction(function($data) {
return $this->facturaRepository->fetchById($data['factura_id']);
}))
->register('fecha', new Implement\Repository\Mapper\DateTime('fecha'))
->register('tipo_id', (new Implement\Repository\Mapper())
->setProperty('tipo')
->setFunction(function($data) {
return $this->tipoRepository->fetchById($data['tipo_id']);
}));
return $this->parseData(new Model\Venta\Factura\Estado(), $data, $map);
}
public function save(Define\Model $model): Model\Venta\Factura\Estado
{
$model->id = $this->saveNew([
'factura_id',
'fecha',
'tipo_id'
], [
$model->factura->id,
$model->fecha->format('Y-m-d'),
$model->tipo->id
]);
return $model;
}
public function edit(Define\Model $model, array $new_data): Model\Venta\Factura\Estado
{
return $this->update($model, ['factura_id', 'fecha', 'tipo_id'], $new_data);
}
public function fetchByFactura(int $factura_id): array
{
$query = $this->connection->getQueryBuilder()
->select()
->from($this->getTable())
->where('factura_id = :factura_id');
return $this->fetchMany($query, ['factura_id' => $factura_id]);
}
}

View File

@ -0,0 +1,17 @@
<?php
namespace Incoviba\Repository\Venta\Factura\Estado;
use Incoviba\Repository;
use Incoviba\Model;
class Tipo extends Repository\Tipo
{
public function getTable(): string
{
return 'tipos_estados_facturas';
}
protected function getBlank(): Model\Venta\Factura\Estado\Tipo
{
return new Model\Venta\Factura\Estado\Tipo;
}
}

View File

@ -65,7 +65,7 @@ class Propietario extends Ideal\Repository
{
$model->rut = $this->saveNew(
['rut', 'dv', 'nombres', 'apellido_paterno', 'apellido_materno', 'direccion', 'otro', 'representante'],
[$model->rut, $model->dv, $model->nombres, $model->apellidos['paterno'], $model->apellidos['materno'], $model->datos->direccion->id, $model->otro->rut ?? 0, $model->representante->rut ?? 0]
[$model->rut, $model->dv, $model->nombres, $model->apellidos['paterno'], $model->apellidos['materno'], $model->datos->direccion->id, $model->otro->rut ?? 0, $model->contacto->rut ?? 0]
);
return $model;
}

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

View File

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

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

View File

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

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

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

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

View File

@ -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);