diff --git a/ci4/app/Controllers/Logistica/LogisticaController.php b/ci4/app/Controllers/Logistica/LogisticaController.php index f00efa16..09cd0ef9 100755 --- a/ci4/app/Controllers/Logistica/LogisticaController.php +++ b/ci4/app/Controllers/Logistica/LogisticaController.php @@ -206,7 +206,8 @@ class LogisticaController extends BaseController { if ($this->request->isAJAX()) { - $id = $this->request->getPost('id'); + $id = $this->request->getPost('id') ?? null; + $finalizar_ots = $this->request->getPost('finalizar_ots') ?? false; $result = LogisticaService::finalizarEnvio($id); return $this->response->setJSON($result); @@ -215,6 +216,20 @@ class LogisticaController extends BaseController } } + public function finalizarEnvioYOts() + { + if ($this->request->isAJAX()) { + + $id = $this->request->getPost('id') ?? null; + $finalizar_ots = $this->request->getPost('finalizar_ots') ?? false; + + $result = LogisticaService::finalizarEnvio($id, $finalizar_ots); + return $this->response->setJSON($result); + } else { + return $this->failUnauthorized('Invalid request', 403); + } + } + public function datatable_enviosEdit($idEnvio) { $model = model('App\Models\Logistica\EnvioLineaModel'); diff --git a/ci4/app/Services/LogisticaService.php b/ci4/app/Services/LogisticaService.php index 625751a1..7b29dc01 100644 --- a/ci4/app/Services/LogisticaService.php +++ b/ci4/app/Services/LogisticaService.php @@ -286,13 +286,15 @@ class LogisticaService } - public static function finalizarEnvio($envio_id) + public static function finalizarEnvio($envio_id, $finalizar_ot = false) { // hay que comprobar que para todas las lineas de envio de este envio // se ha enviado toda la cantidad teniendo en cuenta otros envios $EnvioModel = model('App\Models\Logistica\EnvioModel'); $EnvioLineasModel = model('App\Models\Logistica\EnvioLineaModel'); + $ots = []; + $envio = $EnvioModel->find($envio_id); if (empty($envio)) { return [ @@ -325,9 +327,11 @@ class LogisticaService ->join('envios', 'envios.id = envios_lineas.envio_id') ->get()->getResult(); - if (count($cantidad_enviada) == 0 || - empty($cantidad_enviada[0]->unidades_enviadas) || - $cantidad_enviada[0]->unidades_enviadas == null) { + if ( + count($cantidad_enviada) == 0 || + empty($cantidad_enviada[0]->unidades_enviadas) || + $cantidad_enviada[0]->unidades_enviadas == null + ) { $cantidad_enviada = 0; } else { $cantidad_enviada = $cantidad_enviada[0]->unidades_enviadas; @@ -339,17 +343,30 @@ class LogisticaService ->first(); $ps = (new ProductionService())->init($ot->id); $ps->updateOrdenTrabajoDate([ - "name" => "envio_at", - "envio_at" => date('Y-m-d H:i:s') + "name" => "envio_at", + "envio_at" => date('Y-m-d H:i:s') ]); + if ($finalizar_ot) { + $ps->updateOrdenTrabajo( + [ + "estado" => 'F' + ] + ); + array_push($ots, $ot->id); + } } } - $EnvioModel->update($envio_id, ['finalizado'=> 1]); + $EnvioModel->update($envio_id, ['finalizado' => 1]); - return [ + $data_return = [ 'status' => true, 'message' => lang('Logistica.success.finalizado'), ]; + + if ($finalizar_ot) { + $data_return['ots'] = $ots; + } + return $data_return; } } diff --git a/ci4/app/Views/themes/vuexy/form/logistica/viewEnvioEditForm.php b/ci4/app/Views/themes/vuexy/form/logistica/viewEnvioEditForm.php index 1695789b..508b40df 100644 --- a/ci4/app/Views/themes/vuexy/form/logistica/viewEnvioEditForm.php +++ b/ci4/app/Views/themes/vuexy/form/logistica/viewEnvioEditForm.php @@ -314,14 +314,14 @@ finalizado == 0): ?>
diff --git a/httpdocs/assets/js/safekat/pages/logistica/envioEdit.js b/httpdocs/assets/js/safekat/pages/logistica/envioEdit.js index 7965b4c2..04357abb 100644 --- a/httpdocs/assets/js/safekat/pages/logistica/envioEdit.js +++ b/httpdocs/assets/js/safekat/pages/logistica/envioEdit.js @@ -292,8 +292,15 @@ class EnvioEdit { ); }); - $('#finalizarEnvio').on('click', () => { - + $('.btn-finalizar').on('click', (e) => { + let data = { + id : $('#id').val(); + }; + let url = '/logistica/finalizarEnvio'; + if(e.currentTarget.id() != "finalizarEnvio"){ + let url = '/logistica/finalizarEnvioYOts'; + data.finalizar_ots = true; + } if(this.codigoSeguimiento.val().length <= 0 || this.proveedor.getVal() <= 0) { Swal.fire({ title: 'Atención!', @@ -308,7 +315,7 @@ class EnvioEdit { }); return; } - +//////////////////// Swal.fire({ title: 'Finalizar envío', text: '¿Está seguro de que desea finalizar el envío?',