Edit Proveedores
This commit is contained in:
@ -22,6 +22,18 @@ class Proveedores extends Ideal\Controller
|
||||
} catch (Implement\Exception\EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function get(ServerRequestInterface $request, ResponseInterface $response,
|
||||
Service\Inmobiliaria\Proveedor $proveedorService, int $proveedor_rut): ResponseInterface
|
||||
{
|
||||
$output = [
|
||||
'proveedor_rut' => $proveedor_rut,
|
||||
'proveedor' => null,
|
||||
];
|
||||
try {
|
||||
$output['proveedor'] = $proveedorService->getById($proveedor_rut);
|
||||
} catch (Implement\Exception\EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function add(ServerRequestInterface $request, ResponseInterface $response,
|
||||
Service\Inmobiliaria\Proveedor $proveedorService): ResponseInterface
|
||||
{
|
||||
@ -54,7 +66,8 @@ class Proveedores extends Ideal\Controller
|
||||
foreach ($input['proveedores'] as $json) {
|
||||
$data = json_decode($json, true);
|
||||
try {
|
||||
$output['proveedores'] []= $proveedorService->edit($data);
|
||||
$proveedor = $proveedorService->getById($data['rut']);
|
||||
$output['proveedores'] []= $proveedorService->edit($proveedor, $data);
|
||||
$output['success'] []= true;
|
||||
} catch (Implement\Exception\EmptyResult) {
|
||||
$output['success'] []= false;
|
||||
|
@ -30,18 +30,9 @@ class Persona extends Ideal\Repository
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Model\Persona
|
||||
{
|
||||
return $this->update($model, $new_data, ['rut', 'digito', 'nombres', 'apellido_paterno', 'apellido_materno']);
|
||||
return $this->update($model, ['digito', 'nombres', 'apellido_paterno', 'apellido_materno'], $new_data);
|
||||
}
|
||||
|
||||
/*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']));
|
||||
|
@ -80,9 +80,4 @@ class Datos extends Ideal\Repository
|
||||
->where('persona_rut = ?');
|
||||
return $this->fetchOne($query, [$persona_rut]);
|
||||
}
|
||||
|
||||
protected function getKey(): string
|
||||
{
|
||||
return 'persona_rut';
|
||||
}
|
||||
}
|
||||
|
@ -55,14 +55,22 @@ class Proveedor extends Ideal\Service
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @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;
|
||||
$filteredData = $this->proveedorRepository->filterData($data);
|
||||
try {
|
||||
if ($proveedor->contacto->rut !== $data['contacto']['rut']) {
|
||||
$contacto = $this->contactoService->getById($data['contacto']['rut']);
|
||||
$this->contactoService->edit($contacto, $data['contacto']);
|
||||
}
|
||||
return $this->process($this->proveedorRepository->edit($proveedor, $filteredData));
|
||||
} catch (Implement\Exception\EmptyResult) {
|
||||
return $proveedor;
|
||||
}
|
||||
}
|
||||
public function delete(Model\Inmobiliaria\Proveedor $proveedor): bool
|
||||
{
|
||||
|
@ -45,6 +45,17 @@ class Persona extends Ideal\Service
|
||||
}
|
||||
return $this->process($persona);
|
||||
}
|
||||
public function edit(Model\Persona $persona, array $data): Model\Persona
|
||||
{
|
||||
$filteredData = $this->personaRepository->filterData($data);
|
||||
try {
|
||||
$datosData = $this->datosPersonaRepository->filterData($data);
|
||||
$this->datosPersonaRepository->edit($persona->datos(), $datosData);
|
||||
return $this->personaRepository->edit($persona, $filteredData);
|
||||
} catch (Implement\Exception\EmptyResult) {
|
||||
return $persona;
|
||||
}
|
||||
}
|
||||
|
||||
protected function process(Model\Persona $persona): Model\Persona
|
||||
{
|
||||
|
Reference in New Issue
Block a user