Merge branch 'feat/ordenes-trabajo' into 'main'

feat confirm alert pedido to produccion

See merge request jjimenez/safekat!458
This commit is contained in:
Alvaro
2025-01-02 16:49:02 +00:00
4 changed files with 60 additions and 4 deletions

View File

@ -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']);

View File

@ -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"]);
}
}
}

View File

@ -33,7 +33,7 @@
</div><!-- /.card-footer -->
<?php if ($pedidoEntity->estado == 'finalizado') : ?>
<div class="pt-4">
<button class="btn btn-primary btn-md"><span> <i class="ti ti-building-factory-2 ti-xs"></i> <?= lang("Produccion.btn_pedido_produccion_accion") ?> </span></button>
<button type="button" class="btn btn-primary btn-md" id="button-pedido-to-prod" data-id="<?= $pedidoEntity->id ?>"><span> <i class="ti ti-building-factory-2 ti-xs"></i> <?= lang("Produccion.btn_pedido_produccion_accion") ?> </span></button>
</div><!-- /.card-footer -->
<?php endif; ?>
@ -54,9 +54,13 @@
<link rel="stylesheet"
href="<?= site_url("/themes/vuexy/vendor/libs/datatables-sk/plugins/buttons/buttons.bootstrap5.min.css") ?>">
<link rel="stylesheet" href="<?= site_url('themes/vuexy/css/sk-datatables.css') ?>">
<link rel="stylesheet" href="<?= site_url('themes/vuexy/vendor/libs/sweetalert2/sweetalert2.css') ?>" />
<?= $this->endSection() ?>
<?= $this->section('additionalExternalJs') ?>
<script src="<?= site_url('themes/vuexy/vendor/libs/sweetalert2/sweetalert2.js') ?>"></script>
<script type="module" src="<?= site_url("assets/js/safekat/pages/produccion/to_prod.js") ?>"></script>
<script src="<?= site_url("/themes/vuexy/vendor/libs/flatpickr/flatpickr.js") ?>"></script>
<script src="<?= site_url("/themes/vuexy/vendor/libs/datatables-sk/plugins/buttons/dataTables.buttons.min.js") ?>">
</script>

View File

@ -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) => {
});
})
})