Agregar Proveedor
This commit is contained in:
@ -10,8 +10,8 @@ use Incoviba\Service;
|
||||
|
||||
class Proveedor extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection, protected Repository\Inmobiliaria $inmobiliariaRepository,
|
||||
protected Repository\Sociedad $sociedadRepository)
|
||||
public function __construct(Define\Connection $connection,
|
||||
protected Service\Persona $personaService)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('proveedores');
|
||||
@ -19,43 +19,40 @@ class Proveedor extends Ideal\Repository
|
||||
|
||||
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']);
|
||||
}));
|
||||
$map = (new Implement\Repository\MapperParser(['rut', 'digito', 'nombre', 'razon']))
|
||||
->register('contacto_rut', (new Implement\Repository\Mapper())->setProperty('contacto')->setFunction(function($data) {
|
||||
return $this->personaService->getById($data['contacto_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]);
|
||||
$this->saveNew(['rut', 'digito', 'nombre', 'razon', 'contacto_rut'], [
|
||||
$model->rut, $model->digito, $model->nombre, $model->razon, $model->contacto->rut
|
||||
]);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Model\Inmobiliaria\Proveedor
|
||||
{
|
||||
return $this->update($model, ['sociedad_id'], $new_data);
|
||||
return $this->update($model, ['rut', 'digito', 'nombre', 'razon', 'contacto_rut'], $new_data);
|
||||
}
|
||||
|
||||
public function fetchByInmobiliaria(int $inmobiliaria_rut): array
|
||||
public function fetchByNombre(string $nombre): Model\Inmobiliaria\Proveedor
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select()
|
||||
->from($this->getTable())
|
||||
->where('inmobiliaria_rut = :inmobiliaria_rut');
|
||||
return array_map([$this, 'load'], $this->fetchMany($query, compact('inmobiliaria_rut')));
|
||||
->where('nombre = :nombre');
|
||||
return $this->fetchOne($query, compact('nombre'));
|
||||
}
|
||||
public function fetchBySociedad(int $sociedad_rut): array
|
||||
|
||||
public function filterData(array $data): 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')));
|
||||
return array_intersect_key($data, array_flip(['rut', 'digito', 'nombre', 'razon', 'contacto_rut']));
|
||||
}
|
||||
|
||||
protected function getKey(): string
|
||||
{
|
||||
return 'rut';
|
||||
}
|
||||
}
|
||||
|
52
app/src/Repository/Inmobiliaria/Proveedor/Datos.php
Normal file
52
app/src/Repository/Inmobiliaria/Proveedor/Datos.php
Normal file
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Inmobiliaria\Proveedor;
|
||||
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Service;
|
||||
|
||||
class Datos extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection, protected Repository\Inmobiliaria\Proveedor $proveedorRepository,
|
||||
protected Repository\Direccion $direccionRepository)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('datos_proveedores');
|
||||
}
|
||||
public function create(?array $data = null): Model\Inmobiliaria\Proveedor\Datos
|
||||
{
|
||||
$map = (new Implement\Repository\MapperParser(['telefono', 'giro']))
|
||||
->register('proveedor_rut', (new Implement\Repository\Mapper())->setProperty('proveedor')->setFunction(function($data) {
|
||||
return $this->proveedorRepository->fetchById($data['proveedor_rut']);
|
||||
}))
|
||||
->register('direccion_id', (new Implement\Repository\Mapper())->setProperty('direccion')->setFunction(function($data) {
|
||||
return $this->direccionRepository->fetchById($data['direccion_id']);
|
||||
}));
|
||||
return $this->parseData(new Model\Inmobiliaria\Proveedor\Datos(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Model\Inmobiliaria\Proveedor\Datos
|
||||
{
|
||||
$model->id = $this->saveNew([
|
||||
'proveedor_rut', 'direccion_id', 'telefono', 'giro'
|
||||
], [
|
||||
$model->proveedor->rut, $model->direccion->id, $model->telefono, $model->giro
|
||||
]);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Model\Inmobiliaria\Proveedor\Datos
|
||||
{
|
||||
return $this->update($model, ['proveedor_rut', 'direccion_id', 'telefono', 'giro'], $new_data);
|
||||
}
|
||||
|
||||
public function fetchByProveedor(int $proveedor_rut): Model\Inmobiliaria\Proveedor\Datos
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select()
|
||||
->from($this->getTable())
|
||||
->where('proveedor_rut = :proveedor_rut');
|
||||
return $this->fetchOne($query, compact('proveedor_rut'));
|
||||
}
|
||||
}
|
@ -33,13 +33,18 @@ class Persona extends Ideal\Repository
|
||||
return $this->update($model, $new_data, ['rut', 'digito', 'nombres', 'apellido_paterno', 'apellido_materno']);
|
||||
}
|
||||
|
||||
public function fetchByRut(int $rut): Model\Persona
|
||||
/*public function fetchById(int $rut): Model\Persona
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select()
|
||||
->from($this->getTable())
|
||||
->where('rut = ?');
|
||||
return $this->fetchOne($query, [$rut]);
|
||||
}*/
|
||||
|
||||
public function filterData(array $data): array
|
||||
{
|
||||
return array_intersect_key($data, array_flip(['rut', 'digito', 'nombres', 'apellido_paterno', 'apellido_materno']));
|
||||
}
|
||||
|
||||
protected function getKey(): string
|
||||
|
@ -1,12 +1,14 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository;
|
||||
namespace Incoviba\Repository\Persona;
|
||||
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository\Direccion;
|
||||
use Incoviba\Repository\Persona;
|
||||
|
||||
class DatosPersona extends Ideal\Repository
|
||||
class Datos extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection, protected Persona $personaRepository,
|
||||
protected Direccion $direccionRepository)
|
||||
@ -15,7 +17,7 @@ class DatosPersona extends Ideal\Repository
|
||||
$this->setTable('datos_personas');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Model\DatosPersona
|
||||
public function create(?array $data = null): Model\Persona\Datos
|
||||
{
|
||||
$map = (new Implement\Repository\MapperParser())
|
||||
->register('persona_rut', (new Implement\Repository\Mapper())
|
||||
@ -46,31 +48,31 @@ class DatosPersona extends Ideal\Repository
|
||||
->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'];
|
||||
->register('ocupacion', (new Implement\Repository\Mapper())->setFunction(function($data) {
|
||||
return $data['ocupacion'];
|
||||
})->setDefault(null));
|
||||
return $this->parseData(new Model\DatosPersona(), $data, $map);
|
||||
return $this->parseData(new Model\Persona\Datos(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Model\DatosPersona
|
||||
public function save(Define\Model $model): Model\Persona\Datos
|
||||
{
|
||||
$this->saveNew([
|
||||
'persona_rut', 'direccion_id', 'telefono', 'email', 'fecha_nacimiento', 'sexo', 'estado_civil',
|
||||
'nacionalidad', 'profesion'
|
||||
'nacionalidad', 'ocupacion'
|
||||
], [
|
||||
$model->persona->rut, $model->direccion?->id, $model->telefono, $model->email, $model->fechaNacimiento,
|
||||
$model->sexo, $model->estadoCivil, $model->nacionalidad, $model->ocupacion
|
||||
]);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Model\DatosPersona
|
||||
public function edit(Define\Model $model, array $new_data): Model\Persona\Datos
|
||||
{
|
||||
return $this->update($model, [
|
||||
'direccion_id', 'telefono', 'email', 'fecha_nacimiento', 'sexo', 'estado_civil',
|
||||
'nacionalidad', 'profesion'
|
||||
'nacionalidad', 'ocupacion'
|
||||
], $new_data);
|
||||
}
|
||||
|
||||
public function fetchByPersona(int $persona_rut): Model\DatosPersona
|
||||
public function fetchByPersona(int $persona_rut): Model\Persona\Datos
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select()
|
@ -31,7 +31,7 @@ class Sociedad extends Ideal\Repository
|
||||
->register('contacto_rut', (new Implement\Repository\Mapper())
|
||||
->setProperty('contacto')
|
||||
->setFunction(function ($data) {
|
||||
return $this->personaService->getByRut($data['contacto_rut']);
|
||||
return $this->personaService->getById($data['contacto_rut']);
|
||||
}));
|
||||
return $this->parseData(new Model\Sociedad(), $data, $map);
|
||||
}
|
||||
|
Reference in New Issue
Block a user