mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
tabajando
This commit is contained in:
@ -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');
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -314,14 +314,14 @@
|
||||
<?php if ($envioEntity->finalizado == 0): ?>
|
||||
<div class="col-sm-3 px-3">
|
||||
<button id="finalizarEnvio" name="finalizar_envio" tabindex="1"
|
||||
class="btn btn-primary mt-4 w-100">
|
||||
class="btn btn-primary mt-4 w-100 btn-finalizar">
|
||||
<?= lang("Logistica.finalizarEnvio") ?>
|
||||
<ti class="ti ti-check"></ti>
|
||||
</button>
|
||||
</div>
|
||||
<div class="col-sm-3 px-3">
|
||||
<button id="finalizarEnvioYOTs" name="finalizar_envio_ots" tabindex="1"
|
||||
class="btn btn-primary mt-4 w-100">
|
||||
class="btn btn-primary mt-4 w-100 btn-finalizar">
|
||||
<?= lang("Logistica.finalizarEnvioYOTs") ?>
|
||||
<ti class="ti ti-checks"></ti>
|
||||
</button>
|
||||
|
||||
@ -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?',
|
||||
|
||||
Reference in New Issue
Block a user