2024-06-18
This commit is contained in:
62
app/src/Repository/Contabilidad/Movimiento/Auxiliar.php
Normal file
62
app/src/Repository/Contabilidad/Movimiento/Auxiliar.php
Normal 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]);
|
||||
}
|
||||
}
|
@ -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]);
|
||||
}
|
||||
}
|
@ -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()
|
86
app/src/Repository/DatosPersona.php
Normal file
86
app/src/Repository/DatosPersona.php
Normal 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';
|
||||
}
|
||||
}
|
@ -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']);
|
||||
}));
|
||||
|
61
app/src/Repository/Inmobiliaria/Proveedor.php
Normal file
61
app/src/Repository/Inmobiliaria/Proveedor.php
Normal 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')));
|
||||
}
|
||||
}
|
49
app/src/Repository/Persona.php
Normal file
49
app/src/Repository/Persona.php
Normal 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';
|
||||
}
|
||||
}
|
55
app/src/Repository/Sociedad.php
Normal file
55
app/src/Repository/Sociedad.php
Normal 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';
|
||||
}
|
||||
}
|
129
app/src/Repository/Venta/Factura.php
Normal file
129
app/src/Repository/Venta/Factura.php
Normal 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]);
|
||||
}
|
||||
}
|
60
app/src/Repository/Venta/Factura/Estado.php
Normal file
60
app/src/Repository/Venta/Factura/Estado.php
Normal 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]);
|
||||
}
|
||||
}
|
17
app/src/Repository/Venta/Factura/Estado/Tipo.php
Normal file
17
app/src/Repository/Venta/Factura/Estado/Tipo.php
Normal 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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user