Agregar Proveedor
This commit is contained in:
79
app/src/Controller/API/Inmobiliarias/Proveedores.php
Normal file
79
app/src/Controller/API/Inmobiliarias/Proveedores.php
Normal file
@ -0,0 +1,79 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller\API\Inmobiliarias;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Controller\API\withJson;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Service;
|
||||
|
||||
class Proveedores extends Ideal\Controller
|
||||
{
|
||||
use withJson;
|
||||
|
||||
public function __invoke(ServerRequestInterface $request, ResponseInterface $response,
|
||||
Service\Inmobiliaria\Proveedor $proveedorService): ResponseInterface
|
||||
{
|
||||
$output = ['proveedores' => []];
|
||||
try {
|
||||
$output['proveedores'] = $proveedorService->getAll('nombre');
|
||||
} catch (Implement\Exception\EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function add(ServerRequestInterface $request, ResponseInterface $response,
|
||||
Service\Inmobiliaria\Proveedor $proveedorService): ResponseInterface
|
||||
{
|
||||
$input = $request->getParsedBody();
|
||||
$output = [
|
||||
'input' => $input,
|
||||
'proveedores' => [],
|
||||
'success' => [],
|
||||
];
|
||||
foreach ($input['proveedores'] as $json) {
|
||||
$data = json_decode($json, true);
|
||||
try {
|
||||
$output['proveedores'] []= $proveedorService->add($data);
|
||||
$output['success'] []= true;
|
||||
} catch (Implement\Exception\EmptyResult) {
|
||||
$output['success'] []= false;
|
||||
}
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function edit(ServerRequestInterface $request, ResponseInterface $response,
|
||||
Service\Inmobiliaria\Proveedor $proveedorService): ResponseInterface
|
||||
{
|
||||
$input = $request->getParsedBody();
|
||||
$output = [
|
||||
'input' => $input,
|
||||
'proveedores' => [],
|
||||
'success' => [],
|
||||
];
|
||||
foreach ($input['proveedores'] as $json) {
|
||||
$data = json_decode($json, true);
|
||||
try {
|
||||
$output['proveedores'] []= $proveedorService->edit($data);
|
||||
$output['success'] []= true;
|
||||
} catch (Implement\Exception\EmptyResult) {
|
||||
$output['success'] []= false;
|
||||
}
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function delete(ServerRequestInterface $request, ResponseInterface $response,
|
||||
Service\Inmobiliaria\Proveedor $proveedorService, int $proveedor_rut): ResponseInterface
|
||||
{
|
||||
$output = [
|
||||
'proveedor_rut' => $proveedor_rut,
|
||||
'proveedor' => null,
|
||||
'success' => false
|
||||
];
|
||||
try {
|
||||
$output['proveedor'] = $proveedorService->getById($proveedor_rut);
|
||||
$output['success'] = $proveedorService->delete($output['proveedor']);
|
||||
} catch (Implement\Exception\EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
}
|
@ -11,8 +11,7 @@ use Incoviba\Service;
|
||||
class Proveedores
|
||||
{
|
||||
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, View $view,
|
||||
Service\Inmobiliaria\Proveedor $proveedorService,
|
||||
Repository\Inmobiliaria\TipoSociedad $tipoSociedad): ResponseInterface
|
||||
Service\Inmobiliaria\Proveedor $proveedorService): ResponseInterface
|
||||
{
|
||||
$proveedores = [];
|
||||
try {
|
||||
|
@ -1,32 +0,0 @@
|
||||
<?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 $ocupacion;
|
||||
|
||||
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->ocupacion,
|
||||
];
|
||||
}
|
||||
}
|
@ -2,7 +2,9 @@
|
||||
namespace Incoviba\Model\Inmobiliaria;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Model\Inmobiliaria\Proveedor\Datos;
|
||||
|
||||
class Proveedor extends Ideal\Model
|
||||
{
|
||||
@ -10,18 +12,30 @@ class Proveedor extends Ideal\Model
|
||||
public string $digito;
|
||||
public string $nombre;
|
||||
public ?string $razon;
|
||||
public ?DatosProveedor $datos;
|
||||
public ?Model\Persona $contacto;
|
||||
|
||||
public ?Datos $datos;
|
||||
public function datos(): ?Datos
|
||||
{
|
||||
if (!isset($this->datos)) {
|
||||
$this->datos = $this->runFactory('datos');
|
||||
}
|
||||
return $this->datos;
|
||||
}
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return [
|
||||
$json = [
|
||||
'rut' => $this->rut,
|
||||
'digito' => $this->digito,
|
||||
'nombre' => $this->nombre,
|
||||
'razon' => $this->razon,
|
||||
'datos' => $this->datos,
|
||||
'datos' => null,
|
||||
'contacto' => $this->contacto
|
||||
];
|
||||
try {
|
||||
$json['datos'] = $this->datos();
|
||||
} catch (EmptyResult) {}
|
||||
return $json;
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,11 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Inmobiliaria;
|
||||
namespace Incoviba\Model\Inmobiliaria\Proveedor;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Model\Direccion;
|
||||
use Incoviba\Model\Inmobiliaria\Proveedor;
|
||||
|
||||
class DatosProveedor extends Ideal\Model
|
||||
class Datos extends Ideal\Model
|
||||
{
|
||||
public Proveedor $proveedor;
|
||||
public ?Direccion $direccion;
|
@ -2,6 +2,7 @@
|
||||
namespace Incoviba\Model;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Model\Persona\Datos;
|
||||
|
||||
class Persona extends Ideal\Model
|
||||
{
|
||||
@ -21,8 +22,8 @@ class Persona extends Ideal\Model
|
||||
return number_format($this->rut, 0, ',', '.') . '-' . $this->digito;
|
||||
}
|
||||
|
||||
protected ?DatosPersona $datos;
|
||||
public function datos(): ?DatosPersona
|
||||
protected ?Datos $datos;
|
||||
public function datos(): ?Datos
|
||||
{
|
||||
if (!isset($this->datos)) {
|
||||
$this->datos = $this->runFactory('datos');
|
||||
@ -40,7 +41,7 @@ class Persona extends Ideal\Model
|
||||
'apellidoMaterno' => $this->apellidoMaterno,
|
||||
'nombreCompleto' => $this->nombreCompleto(),
|
||||
'rutCompleto' => $this->rutCompleto(),
|
||||
'datos' => $this->datos(),
|
||||
'datos' => $this->datos() ?? null,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
34
app/src/Model/Persona/Datos.php
Normal file
34
app/src/Model/Persona/Datos.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Persona;
|
||||
|
||||
use DateTimeInterface;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Model\Direccion;
|
||||
use Incoviba\Model\Persona;
|
||||
|
||||
class Datos 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 $ocupacion;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return [
|
||||
'direccion' => $this->direccion ?? null,
|
||||
'telefono' => $this->telefono ?? null,
|
||||
'email' => $this->email ?? null,
|
||||
'fechaNacimiento' => $this->fechaNacimiento ?? null,
|
||||
'sexo' => $this->sexo ?? null,
|
||||
'estadoCivil' => $this->estadoCivil ?? null,
|
||||
'nacionalidad' => $this->nacionalidad ?? null,
|
||||
'ocupacion' => $this->ocupacion ?? null,
|
||||
];
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
@ -1,16 +1,20 @@
|
||||
<?php
|
||||
namespace Incoviba\Service\Inmobiliaria;
|
||||
|
||||
use PDOException;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Service;
|
||||
|
||||
class Proveedor extends Ideal\Service
|
||||
{
|
||||
public function __construct(LoggerInterface $logger, protected Repository\Inmobiliaria\Proveedor $proveedorRepository)
|
||||
public function __construct(LoggerInterface $logger,
|
||||
protected Repository\Inmobiliaria\Proveedor $proveedorRepository,
|
||||
protected Repository\Inmobiliaria\Proveedor\Datos $datosRepository,
|
||||
protected Service\Persona $contactoService)
|
||||
{
|
||||
parent::__construct($logger);
|
||||
}
|
||||
@ -18,18 +22,61 @@ class Proveedor extends Ideal\Service
|
||||
public function getAll(?string $orderBy = null): array
|
||||
{
|
||||
try {
|
||||
return $this->proveedorRepository->fetchAll($orderBy);
|
||||
return array_map([$this, 'process'], $this->proveedorRepository->fetchAll($orderBy));
|
||||
} catch (Implement\Exception\EmptyResult) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public function getByRut(int $proveedor_rut): ?Model\Inmobiliaria\Proveedor
|
||||
public function getById(int $proveedor_rut): ?Model\Inmobiliaria\Proveedor
|
||||
{
|
||||
try {
|
||||
return $this->proveedorRepository->fetchById($proveedor_rut);
|
||||
return $this->process($this->proveedorRepository->fetchById($proveedor_rut));
|
||||
} catch (Implement\Exception\EmptyResult) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function add(array $data): Model\Inmobiliaria\Proveedor
|
||||
{
|
||||
$filteredData = $this->proveedorRepository->filterData($data);
|
||||
try {
|
||||
$proveedor = $this->process($this->proveedorRepository->fetchByNombre($filteredData['nombre']));
|
||||
if ($proveedor->contacto->rut !== $data['contacto']['rut']) {
|
||||
$contacto = $this->contactoService->add($data['contacto']);
|
||||
return $this->proveedorRepository->edit($proveedor, ['contacto_rut' => $contacto->rut]);
|
||||
}
|
||||
return $proveedor;
|
||||
} catch (Implement\Exception\EmptyResult) {
|
||||
$contacto = $this->contactoService->add($data['contacto']);
|
||||
$filteredData['contacto_rut'] = $contacto->rut;
|
||||
$proveedor = $this->proveedorRepository->create($filteredData);
|
||||
return $this->process($this->proveedorRepository->save($proveedor));
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @TODO Implement
|
||||
* @param Model\Inmobiliaria\Proveedor $proveedor
|
||||
* @param array $data
|
||||
* @return Model\Inmobiliaria\Proveedor
|
||||
*/
|
||||
public function edit(Model\Inmobiliaria\Proveedor $proveedor, array $data): Model\Inmobiliaria\Proveedor
|
||||
{
|
||||
return $proveedor;
|
||||
}
|
||||
public function delete(Model\Inmobiliaria\Proveedor $proveedor): bool
|
||||
{
|
||||
try {
|
||||
$this->proveedorRepository->remove($proveedor);
|
||||
return true;
|
||||
} catch (Implement\Exception\EmptyResult | PDOException) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
protected function process(Model\Inmobiliaria\Proveedor $proveedor): Model\Inmobiliaria\Proveedor
|
||||
{
|
||||
$proveedor->addFactory('datos', (new Implement\Repository\Factory())->setCallable([$this->datosRepository, 'fetchByProveedor'])->setArgs(['proveedor_rut' => $proveedor->rut]));
|
||||
return $proveedor;
|
||||
}
|
||||
}
|
||||
|
@ -1,28 +1,28 @@
|
||||
<?php
|
||||
namespace Incoviba\Service;
|
||||
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class Persona extends Ideal\Service
|
||||
{
|
||||
public function __construct(LoggerInterface $logger, protected Repository\Persona $personaRepository,
|
||||
protected Repository\DatosPersona $datosPersonaRepository)
|
||||
public function __construct(LoggerInterface $logger, protected Repository\Persona $personaRepository,
|
||||
protected Repository\Persona\Datos $datosPersonaRepository)
|
||||
{
|
||||
parent::__construct($logger);
|
||||
}
|
||||
|
||||
public function getByRut(int $rut): Model\Persona
|
||||
public function getById(int $rut): Model\Persona
|
||||
{
|
||||
return $this->process($this->personaRepository->fetchByRut($rut));
|
||||
return $this->process($this->personaRepository->fetchById($rut));
|
||||
}
|
||||
public function add(array $data): Model\Persona
|
||||
{
|
||||
try {
|
||||
$persona = $this->personaRepository->fetchByRut($data['rut']);
|
||||
$persona = $this->personaRepository->fetchById($data['rut']);
|
||||
} catch (Implement\Exception\EmptyResult) {
|
||||
$persona = $this->personaRepository->create($data);
|
||||
$persona = $this->personaRepository->save($persona);
|
||||
|
Reference in New Issue
Block a user