Eliminar desistimiento y loading en editar desistimiento
This commit is contained in:
@ -25,7 +25,10 @@ $app->group('/venta/{venta_id}', function($app) {
|
||||
$app->get('/unidades[/]', [Ventas::class, 'unidades']);
|
||||
$app->get('/comentarios[/]', [Ventas::class, 'comentarios']);
|
||||
$app->post('/escriturar[/]', [Ventas::class, 'escriturar']);
|
||||
$app->post('/desistir[/]', [Ventas::class, 'desistir']);
|
||||
$app->group('/desistir', function($app) {
|
||||
$app->get('/eliminar[/]', [Ventas::class, 'insistir']);
|
||||
$app->post('[/]', [Ventas::class, 'desistir']);
|
||||
});
|
||||
$app->post('[/]', [Ventas::class, 'edit']);
|
||||
$app->get('[/]', [Ventas::class, 'get']);
|
||||
});
|
||||
|
@ -9,35 +9,50 @@
|
||||
</a>
|
||||
</h1>
|
||||
<form class="ui form" id="desistida_form">
|
||||
<div class="three wide field">
|
||||
<label for="fecha">Fecha</label>
|
||||
<div class="ui calendar" id="fecha">
|
||||
<div class="ui left icon input">
|
||||
<i class="calendar icon"></i>
|
||||
<input type="text" />
|
||||
<div class="fields">
|
||||
<div class="three wide field">
|
||||
<label for="fecha">Fecha</label>
|
||||
<div class="ui calendar" id="fecha">
|
||||
<div class="ui left icon input">
|
||||
<i class="calendar icon"></i>
|
||||
<input type="text" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="three wide field">
|
||||
<label for="devolucion">Devolución</label>
|
||||
<div class="ui left labeled input">
|
||||
<div class="ui basic label">$</div>
|
||||
<input type="text" id="devolucion" value="{{$venta->resciliacion()->valor}}" />
|
||||
<div class="one wide field">
|
||||
<div id="loading-spinner-fecha" class="ui tiny blue active inline elastic loader" style="display: none;"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="fields">
|
||||
<div class="three wide field">
|
||||
<label for="devolucion">Devolución</label>
|
||||
<div class="ui left labeled input">
|
||||
<div class="ui basic label">$</div>
|
||||
<input type="text" id="devolucion" value="{{$venta->resciliacion()->valor}}" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="one wide field">
|
||||
<div id="loading-spinner-devolucion" class="ui tiny blue active inline elastic loader" style="display: none;"></div>
|
||||
</div>
|
||||
</div>
|
||||
<button class="ui red icon button" type="button" id="eliminar_desistimiento">
|
||||
<i class="ban icon"></i>
|
||||
Elmininar desistimiento
|
||||
</button>
|
||||
<div id="loading-spinner-eliminar" class="ui tiny blue active inline elastic loader" style="display: none;"></div>
|
||||
</form>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@push('page_scripts')
|
||||
<script>
|
||||
function alertResponse(message, color = 'green') {
|
||||
function alertResponse(message, {color = 'green', icon = 'check circle'}={}) {
|
||||
$.toast({
|
||||
message,
|
||||
showProgress: 'bottom',
|
||||
progressUp: true,
|
||||
class: color,
|
||||
showIcon: 'check circle',
|
||||
showIcon: icon,
|
||||
classProgress: 'blue'
|
||||
})
|
||||
}
|
||||
@ -52,7 +67,9 @@
|
||||
}
|
||||
const body = new FormData()
|
||||
body.set('fecha', date.toISOString())
|
||||
$('#loading-spinner-fecha').show()
|
||||
fetchAPI(url, {method: 'post', body}).then(response => {
|
||||
$('#loading-spinner-fecha').hide()
|
||||
if (!response) {
|
||||
return
|
||||
}
|
||||
@ -62,17 +79,36 @@
|
||||
}
|
||||
$('#fecha').calendar(calendar_date_options)
|
||||
$('#devolucion').change(event => {
|
||||
console.debug(event)
|
||||
const val = $(event.currentTarget).val()
|
||||
const body = new FormData()
|
||||
body.set('valor', val)
|
||||
$('#loading-spinner-devolucion').show()
|
||||
fetchAPI(url, {method: 'post', body}).then(response => {
|
||||
$('#loading-spinner-devolucion').hide()
|
||||
if (!response) {
|
||||
return
|
||||
}
|
||||
alertResponse('Devolución cambiada correctamente.')
|
||||
})
|
||||
})
|
||||
$('#eliminar_desistimiento').click(event => {
|
||||
const url = '{{$urls->api}}/venta/{{$venta->id}}/desistir/eliminar'
|
||||
$('#loading-spinner-eliminar').show()
|
||||
fetchAPI(url).then(response => {
|
||||
$('#loading-spinner-eliminar').hide()
|
||||
if (!response) {
|
||||
alertResponse('No se pudo eliminar el desistimiento', {color: 'red', icon: 'triangle exclamation'})
|
||||
return
|
||||
}
|
||||
response.json().then(json => {
|
||||
if (!json.eliminado) {
|
||||
alertResponse('No se pudo eliminar el disistimiento', {color: 'red', icon: 'triangle exclamation'})
|
||||
return
|
||||
}
|
||||
window.location = '{{$urls->base}}/venta/{{$venta->id}}'
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
</script>
|
||||
@endpush
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
{
|
||||
|
Reference in New Issue
Block a user