Eliminar desistimiento y loading en editar desistimiento

This commit is contained in:
2023-12-22 12:52:04 -03:00
parent afbadd520b
commit 8492d1df2b
5 changed files with 96 additions and 18 deletions

View File

@ -258,4 +258,16 @@ class Ventas
} catch (EmptyResult) {}
return $this->withJson($response, $output);
}
public function insistir(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $ventaService, int $venta_id): ResponseInterface
{
$output = [
'venta_id' => $venta_id,
'eliminado' => false
];
try {
$venta = $ventaService->getById($venta_id);
$output['eliminado'] = $ventaService->insistir($venta);
} catch (EmptyResult) {}
return $this->withJson($response, $output);
}
}

View File

@ -384,7 +384,7 @@ class Venta
{
try {
if ($this->validarData($data, ['fecha', 'devolucion'])) {
$pago = $this->pagoService->add(['fecha' => $data['fecha'], 'valor' => $data['devolucion']]);
$pago = $this->pagoService->add(['fecha' => $data['fecha'], 'valor' => str_replace(['.', ','], ['', '.'], $data['devolucion'])]);
$this->ventaRepository->edit($venta, ['resciliacion' => $pago->id]);
}
$tipoEstado = $this->tipoEstadoVentaRepository->fetchByDescripcion('desistida');
@ -394,4 +394,18 @@ class Venta
return false;
}
}
public function insistir(Model\Venta $venta): bool
{
try {
$pago = $venta->resciliacion();
$this->pagoService->delete($pago);
$estado = $venta->currentEstado();
error_log(var_export($estado,true));
$this->estadoVentaRepository->remove($estado);
$this->ventaRepository->edit($venta, ['resciliacion' => null]);
return true;
} catch (Implement\Exception\EmptyResult) {
return false;
}
}
}

View File

@ -3,6 +3,7 @@ namespace Incoviba\Service\Venta;
use DateTimeInterface;
use DateTimeImmutable;
use Incoviba\Common\Implement\Exception\EmptyResult;
use Incoviba\Service\Money;
use PDOException;
use Incoviba\Repository;
@ -66,8 +67,11 @@ class Pago
return false;
}
}
public function getById(int $pago_id): Model\Venta\Pago
public function getById(?int $pago_id): ?Model\Venta\Pago
{
if ($pago_id === null) {
return null;
}
$pago = $this->pagoRepository->fetchById($pago_id);
return $this->process($pago);
}
@ -118,6 +122,15 @@ class Pago
$pago->currentEstado = $estado;
return $pago;
}
public function delete(Model\Venta\Pago $pago): bool
{
try {
$this->pagoRepository->remove($pago);
return true;
} catch (EmptyResult|PDOException) {
return false;
}
}
protected function process($pago): Model\Venta\Pago
{