From 4f7cbb99fd8129979614ac2a6eae882860fea009 Mon Sep 17 00:00:00 2001 From: amazuecos Date: Thu, 2 Jan 2025 17:47:57 +0100 Subject: [PATCH] feat confirm alert pedido to produccion --- ci4/app/Config/Routes.php | 2 +- ci4/app/Controllers/Pedidos/Pedido.php | 9 +++- .../vuexy/form/pedidos/viewPedidoForm.php | 6 ++- .../js/safekat/pages/produccion/to_prod.js | 47 +++++++++++++++++++ 4 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 httpdocs/assets/js/safekat/pages/produccion/to_prod.js diff --git a/ci4/app/Config/Routes.php b/ci4/app/Config/Routes.php index 8fb9f265..6ee2a32e 100644 --- a/ci4/app/Config/Routes.php +++ b/ci4/app/Config/Routes.php @@ -691,7 +691,7 @@ $routes->group('pedidos', ['namespace' => 'App\Controllers\Pedidos'], function ( $routes->post('cambiarestado', 'Pedido::cambiarEstado', ['as' => 'cambiarEstadoPedido']); $routes->post('update/(:any)', 'Pedido::update/$1', ['as' => 'actualizarPedido']); $routes->get('xml/(:num)', 'Pedido::get_xml_pedido/$1', ['as' => 'getXMLPedido']); - $routes->get('produccion/(:num)', 'Pedido::to_produccion/$1', ['as' => 'toProduccion']); + $routes->post('produccion/(:num)', 'Pedido::to_produccion/$1', ['as' => 'toProduccion']); }); $routes->resource('pedidos', ['namespace' => 'App\Controllers\Pedidos', 'controller' => 'Pedido', 'except' => 'show,new,create,update']); diff --git a/ci4/app/Controllers/Pedidos/Pedido.php b/ci4/app/Controllers/Pedidos/Pedido.php index a2fe761f..4cfa2a1d 100755 --- a/ci4/app/Controllers/Pedidos/Pedido.php +++ b/ci4/app/Controllers/Pedidos/Pedido.php @@ -395,8 +395,13 @@ class Pedido extends \App\Controllers\BaseResourceController $serviceProduction = service('production'); $pedido = $this->model->find($pedido_id); $serviceProduction->setPedido($pedido); - $r = $serviceProduction->createOrdenTrabajo(); - return $this->respond()->setJSON($r); + if($pedido->orden_trabajo()){ + return $this->response->setJSON(["data"=>$pedido->orden_trabajo(),"message" => "Ya existe una orden de trabajo para este pedido"]); + + }else{ + $r = $serviceProduction->createOrdenTrabajo(); + return $this->response->setJSON(["data"=>$r,"message" => "Orden trabajo creada correctamente"]); + } } } diff --git a/ci4/app/Views/themes/vuexy/form/pedidos/viewPedidoForm.php b/ci4/app/Views/themes/vuexy/form/pedidos/viewPedidoForm.php index fe66a608..a0a9bf5f 100644 --- a/ci4/app/Views/themes/vuexy/form/pedidos/viewPedidoForm.php +++ b/ci4/app/Views/themes/vuexy/form/pedidos/viewPedidoForm.php @@ -33,7 +33,7 @@ estado == 'finalizado') : ?>
- +
@@ -54,9 +54,13 @@ "> + + endSection() ?> section('additionalExternalJs') ?> + + diff --git a/httpdocs/assets/js/safekat/pages/produccion/to_prod.js b/httpdocs/assets/js/safekat/pages/produccion/to_prod.js new file mode 100644 index 00000000..125c5254 --- /dev/null +++ b/httpdocs/assets/js/safekat/pages/produccion/to_prod.js @@ -0,0 +1,47 @@ +import Ajax from "../../components/ajax.js" +$(() => { + $("#button-pedido-to-prod").on("click", (event) => { + const pedidoId = $(event.currentTarget).data("id"); + Swal.fire({ + title: '¿Estás seguro?', + text: "Esta acción creará la orden de trabajo del pedido", + icon: 'warning', + showCancelButton: true, + confirmButtonColor: '#3085d6', + cancelButtonColor: '#d33', + confirmButtonText: 'Sí', + cancelButtonText: 'Cancelar', + customClass: { + confirmButton: 'btn btn-primary me-1', + cancelButton: 'btn btn-label-secondary' + }, + buttonsStyling: false + }).then((result) => { + if (result.isConfirmed) { + let ajax = new Ajax( + "/pedidos/produccion/" + pedidoId, + null, + null, + (response) => { + Swal.fire({ + title: response.message, + icon: 'success', + showCancelButton: true, + showConfirmButton: false, + cancelButtonText: 'Cancelar', + customClass: { + confirmButton: 'btn btn-primary me-1', + cancelButton: 'btn btn-label-secondary' + }, + buttonsStyling: false + }) + }, + null, + ) + ajax.post() + } + }).catch((err) => { + + }); + }) +}) \ No newline at end of file