Rutas y controladores para editar bono Formulario para editar bono pie Filtro de columnas Uso de nuevas estructuras y editar Bono Pie Uso de nuevas estructuras. Capacidad de pasar a pesos o a UF en Servicio Valor FIX: botón incorrecto Co-authored-by: Juan Pablo Vial <jpvialb@incoviba.cl> Reviewed-on: #24
65 lines
2.4 KiB
PHP
65 lines
2.4 KiB
PHP
<?php
|
|
namespace Incoviba\Controller\API\Ventas;
|
|
|
|
use DateTimeImmutable;
|
|
use Psr\Http\Message\ResponseInterface;
|
|
use Psr\Http\Message\ServerRequestInterface;
|
|
use Incoviba\Common\Implement\Exception\EmptyResult;
|
|
use Incoviba\Common\Ideal\Controller;
|
|
use Incoviba\Controller\API\withJson;
|
|
use Incoviba\Exception\ServiceAction\Update;
|
|
use Incoviba\Repository;
|
|
use Incoviba\Service;
|
|
|
|
class Bonos extends Controller
|
|
{
|
|
use withJson;
|
|
|
|
public function add(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta $ventaRepository,
|
|
Service\Valor $valorService, Service\UF $ufService,
|
|
Service\Venta\BonoPie $bonoPieService, int $venta_id): ResponseInterface
|
|
{
|
|
$input = $request->getParsedBody();
|
|
$output = [
|
|
'venta_id' => $venta_id,
|
|
'input' => $input,
|
|
'bono' => null,
|
|
'success' => false
|
|
];
|
|
try {
|
|
$venta = $ventaRepository->fetchById($venta_id);
|
|
$input['venta_id'] = $venta->id;
|
|
$uf = $ufService->get(new DateTimeImmutable($input['fecha']));
|
|
$input['valor'] = $input['valor'] * $uf;
|
|
$input['valor'] = $valorService->clean($input['valor']);
|
|
$input['uf'] = $uf;
|
|
$bono = $bonoPieService->add($input);
|
|
$ventaRepository->edit($venta, ['bono_pie' => $bono->id]);
|
|
$output['bono'] = $bono;
|
|
$output['success'] = true;
|
|
} catch (EmptyResult) {}
|
|
return $this->withJson($response, $output);
|
|
}
|
|
public function edit(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $ventaService,
|
|
Service\Venta\BonoPie $bonoPieService, int $venta_id): ResponseInterface
|
|
{
|
|
$input = $request->getParsedBody();
|
|
$output = [
|
|
'venta_id' => $venta_id,
|
|
'input' => $input,
|
|
'bono' => null,
|
|
'success' => false,
|
|
];
|
|
try {
|
|
try {
|
|
$venta = $ventaService->getById($venta_id);
|
|
} catch (EmptyResult $exception) {
|
|
throw new Update(__CLASS__, $exception);
|
|
}
|
|
$output['bono'] = $bonoPieService->edit($venta->formaPago()->bonoPie, $input);
|
|
$output['success'] = true;
|
|
} catch (Update) {}
|
|
return $this->withJson($response, $output);
|
|
}
|
|
}
|