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('/unidades[/]', [Ventas::class, 'unidades']);
|
||||||
$app->get('/comentarios[/]', [Ventas::class, 'comentarios']);
|
$app->get('/comentarios[/]', [Ventas::class, 'comentarios']);
|
||||||
$app->post('/escriturar[/]', [Ventas::class, 'escriturar']);
|
$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->post('[/]', [Ventas::class, 'edit']);
|
||||||
$app->get('[/]', [Ventas::class, 'get']);
|
$app->get('[/]', [Ventas::class, 'get']);
|
||||||
});
|
});
|
||||||
|
@ -9,35 +9,50 @@
|
|||||||
</a>
|
</a>
|
||||||
</h1>
|
</h1>
|
||||||
<form class="ui form" id="desistida_form">
|
<form class="ui form" id="desistida_form">
|
||||||
<div class="three wide field">
|
<div class="fields">
|
||||||
<label for="fecha">Fecha</label>
|
<div class="three wide field">
|
||||||
<div class="ui calendar" id="fecha">
|
<label for="fecha">Fecha</label>
|
||||||
<div class="ui left icon input">
|
<div class="ui calendar" id="fecha">
|
||||||
<i class="calendar icon"></i>
|
<div class="ui left icon input">
|
||||||
<input type="text" />
|
<i class="calendar icon"></i>
|
||||||
|
<input type="text" />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
<div class="one wide field">
|
||||||
<div class="three wide field">
|
<div id="loading-spinner-fecha" class="ui tiny blue active inline elastic loader" style="display: none;"></div>
|
||||||
<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>
|
</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>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
@endsection
|
@endsection
|
||||||
|
|
||||||
@push('page_scripts')
|
@push('page_scripts')
|
||||||
<script>
|
<script>
|
||||||
function alertResponse(message, color = 'green') {
|
function alertResponse(message, {color = 'green', icon = 'check circle'}={}) {
|
||||||
$.toast({
|
$.toast({
|
||||||
message,
|
message,
|
||||||
showProgress: 'bottom',
|
showProgress: 'bottom',
|
||||||
progressUp: true,
|
progressUp: true,
|
||||||
class: color,
|
class: color,
|
||||||
showIcon: 'check circle',
|
showIcon: icon,
|
||||||
classProgress: 'blue'
|
classProgress: 'blue'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -52,7 +67,9 @@
|
|||||||
}
|
}
|
||||||
const body = new FormData()
|
const body = new FormData()
|
||||||
body.set('fecha', date.toISOString())
|
body.set('fecha', date.toISOString())
|
||||||
|
$('#loading-spinner-fecha').show()
|
||||||
fetchAPI(url, {method: 'post', body}).then(response => {
|
fetchAPI(url, {method: 'post', body}).then(response => {
|
||||||
|
$('#loading-spinner-fecha').hide()
|
||||||
if (!response) {
|
if (!response) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -62,17 +79,36 @@
|
|||||||
}
|
}
|
||||||
$('#fecha').calendar(calendar_date_options)
|
$('#fecha').calendar(calendar_date_options)
|
||||||
$('#devolucion').change(event => {
|
$('#devolucion').change(event => {
|
||||||
console.debug(event)
|
|
||||||
const val = $(event.currentTarget).val()
|
const val = $(event.currentTarget).val()
|
||||||
const body = new FormData()
|
const body = new FormData()
|
||||||
body.set('valor', val)
|
body.set('valor', val)
|
||||||
|
$('#loading-spinner-devolucion').show()
|
||||||
fetchAPI(url, {method: 'post', body}).then(response => {
|
fetchAPI(url, {method: 'post', body}).then(response => {
|
||||||
|
$('#loading-spinner-devolucion').hide()
|
||||||
if (!response) {
|
if (!response) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
alertResponse('Devolución cambiada correctamente.')
|
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>
|
</script>
|
||||||
@endpush
|
@endpush
|
||||||
|
@ -258,4 +258,16 @@ class Ventas
|
|||||||
} catch (EmptyResult) {}
|
} catch (EmptyResult) {}
|
||||||
return $this->withJson($response, $output);
|
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 {
|
try {
|
||||||
if ($this->validarData($data, ['fecha', 'devolucion'])) {
|
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]);
|
$this->ventaRepository->edit($venta, ['resciliacion' => $pago->id]);
|
||||||
}
|
}
|
||||||
$tipoEstado = $this->tipoEstadoVentaRepository->fetchByDescripcion('desistida');
|
$tipoEstado = $this->tipoEstadoVentaRepository->fetchByDescripcion('desistida');
|
||||||
@ -394,4 +394,18 @@ class Venta
|
|||||||
return false;
|
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 DateTimeInterface;
|
||||||
use DateTimeImmutable;
|
use DateTimeImmutable;
|
||||||
|
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||||
use Incoviba\Service\Money;
|
use Incoviba\Service\Money;
|
||||||
use PDOException;
|
use PDOException;
|
||||||
use Incoviba\Repository;
|
use Incoviba\Repository;
|
||||||
@ -66,8 +67,11 @@ class Pago
|
|||||||
return false;
|
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);
|
$pago = $this->pagoRepository->fetchById($pago_id);
|
||||||
return $this->process($pago);
|
return $this->process($pago);
|
||||||
}
|
}
|
||||||
@ -118,6 +122,15 @@ class Pago
|
|||||||
$pago->currentEstado = $estado;
|
$pago->currentEstado = $estado;
|
||||||
return $pago;
|
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
|
protected function process($pago): Model\Venta\Pago
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user