Editar movimientos
This commit is contained in:
@ -16,7 +16,8 @@ class Movimientos extends Ideal\Controller
|
||||
|
||||
public function detalles(ServerRequestInterface $request, ResponseInterface $response,
|
||||
Service\Contabilidad\Movimiento $movimientoService,
|
||||
Repository\Contabilidad\CentroCosto $centroCostoRepository, int $movimiento_id): ResponseInterface
|
||||
Repository\Contabilidad\CentroCosto $centroCostoRepository,
|
||||
int $movimiento_id): ResponseInterface
|
||||
{
|
||||
$body = $request->getParsedBody();
|
||||
$output = [
|
||||
@ -50,7 +51,8 @@ class Movimientos extends Ideal\Controller
|
||||
} catch (EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, Service\Contabilidad\Movimiento $movimientoService): ResponseInterface
|
||||
public function __invoke(ServerRequestInterface $request, ResponseInterface $response,
|
||||
Service\Contabilidad\Movimiento $movimientoService): ResponseInterface
|
||||
{
|
||||
$output = [
|
||||
'movimientos' => []
|
||||
@ -92,6 +94,38 @@ class Movimientos extends Ideal\Controller
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function edit(ServerRequestInterface $request, ResponseInterface $response,
|
||||
Service\Contabilidad\Movimiento $movimientoService): ResponseInterface
|
||||
{
|
||||
$body = $request->getParsedBody();
|
||||
$output = [
|
||||
'input' => $body,
|
||||
'status' => false,
|
||||
'movimiento' => null
|
||||
];
|
||||
try {
|
||||
$movimiento = $movimientoService->getById($body['id']);
|
||||
$output['movimiento'] = $movimientoService->edit($movimiento, $body);
|
||||
$output['status'] = true;
|
||||
} catch (EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function remove(ServerRequestInterface $request, ResponseInterface $response,
|
||||
Service\Contabilidad\Movimiento $movimientoService, int $movimiento_id): ResponseInterface
|
||||
{
|
||||
$output = [
|
||||
'movimiento_id' => $movimiento_id,
|
||||
'movimiento' => null,
|
||||
'status' => false
|
||||
];
|
||||
try {
|
||||
$movimiento = $movimientoService->getById($movimiento_id);
|
||||
$movimientoService->remove($movimiento);
|
||||
$output['movimiento'] = $movimiento;
|
||||
$output['status'] = true;
|
||||
} catch (EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
|
||||
protected function movimientosToArray(array $movimientos): array
|
||||
{
|
||||
|
@ -45,6 +45,20 @@ class Detalle extends Ideal\Repository
|
||||
{
|
||||
return $this->update($model, ['movimiento_id', 'centro_costo_id', 'rut', 'digito', 'nombres', 'categoria', 'detalle', 'identificador'], $new_data);
|
||||
}
|
||||
public function filterData(array $data): array
|
||||
{
|
||||
$map = [
|
||||
'costo_id' => 'centro_costo_id',
|
||||
'nombre' => 'nombres',
|
||||
];
|
||||
foreach ($map as $source => $dest) {
|
||||
if (key_exists($source, $data)) {
|
||||
$data[$dest] = $data[$source];
|
||||
unset($data[$source]);
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function fetchByMovimiento(int $movimiento_id): Model\Contabilidad\Movimiento\Detalle
|
||||
{
|
||||
|
@ -62,6 +62,19 @@ class Movimiento extends Service
|
||||
}
|
||||
return $movimiento;
|
||||
}
|
||||
public function edit(Model\Contabilidad\Movimiento $movimiento, array $data): Model\Contabilidad\Movimiento
|
||||
{
|
||||
try {
|
||||
$detalles = $this->detalleRepository->fetchByMovimiento($movimiento->id);
|
||||
$mappedData = $this->detalleRepository->filterData($data);
|
||||
$this->detalleRepository->edit($detalles, $mappedData);
|
||||
} catch (Implement\Exception\EmptyResult) {}
|
||||
return $this->process($movimiento);
|
||||
}
|
||||
public function remove(Model\Contabilidad\Movimiento $movimiento): void
|
||||
{
|
||||
$this->movimientoRepository->remove($movimiento);
|
||||
}
|
||||
|
||||
public function process(Model\Contabilidad\Movimiento $movimiento): Model\Contabilidad\Movimiento
|
||||
{
|
||||
|
Reference in New Issue
Block a user