mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
generando el grupo de envios
This commit is contained in:
@ -774,7 +774,7 @@ $routes->group('logistica', ['namespace' => 'App\Controllers\Logistica'], functi
|
|||||||
$routes->get('print/label/test', 'LogisticaController::print_test_label');
|
$routes->get('print/label/test', 'LogisticaController::print_test_label');
|
||||||
$routes->get('panel', 'LogisticaController::panel', ['as' => 'LogisticaPanel']);
|
$routes->get('panel', 'LogisticaController::panel', ['as' => 'LogisticaPanel']);
|
||||||
$routes->get('selectEnvios/(:any)', 'LogisticaController::selectorEnvios/$1', ['as' => 'selectEnvios']);
|
$routes->get('selectEnvios/(:any)', 'LogisticaController::selectorEnvios/$1', ['as' => 'selectEnvios']);
|
||||||
|
$routes->get('buscar/(:any)', 'LogisticaController::searchPedidoOrISBN/$1', ['as' => 'buscarPedidoOrISBN']);
|
||||||
});
|
});
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@ -4,6 +4,7 @@ namespace App\Controllers\Logistica;
|
|||||||
|
|
||||||
use App\Controllers\BaseController;
|
use App\Controllers\BaseController;
|
||||||
use App\Services\ImpresoraEtiquetaService;
|
use App\Services\ImpresoraEtiquetaService;
|
||||||
|
use App\Services\LogisticaService;
|
||||||
use CodeIgniter\HTTP\RequestInterface;
|
use CodeIgniter\HTTP\RequestInterface;
|
||||||
use CodeIgniter\HTTP\ResponseInterface;
|
use CodeIgniter\HTTP\ResponseInterface;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
@ -70,28 +71,14 @@ class LogisticaController extends BaseController
|
|||||||
|
|
||||||
public function searchPedidoOrISBN($search = ""){
|
public function searchPedidoOrISBN($search = ""){
|
||||||
|
|
||||||
$modelPedido = model('App\Models\Pedidos\PedidoModel');
|
if(empty($search)){
|
||||||
|
$result = [
|
||||||
$search = trim($search);
|
'status' => false,
|
||||||
$searchClean = str_replace('-', '', $search);
|
'message' => lang('Logistica.errors.noDataToFind'),
|
||||||
$modelPedido = model('App\Models\Pedidos\PedidoModel');
|
];
|
||||||
|
return $this->response->setJSON($result);
|
||||||
// Builder con joins
|
}
|
||||||
$builder = $modelPedido->builder();
|
$result = LogisticaService::findPedidoOrISBN($search);
|
||||||
$builder->select('pedidos.*');
|
return $this->response->setJSON($result);
|
||||||
$builder->join('pedidos_linea', 'pedidos_linea.pedido_id = pedidos.id', 'left');
|
|
||||||
$builder->join('presupuestos', 'presupuestos.id = pedidos_linea.presupuesto_id', 'left');
|
|
||||||
|
|
||||||
// Agrupar condiciones: por ID exacto o por ISBN sin guiones
|
|
||||||
$builder->groupStart()
|
|
||||||
->where('pedidos.id', $search)
|
|
||||||
->orWhere("REPLACE(presupuestos.isbn, '-', '')", $searchClean)
|
|
||||||
->groupEnd();
|
|
||||||
|
|
||||||
$result = $builder->get()->getResult();
|
|
||||||
$response = [
|
|
||||||
'status' => true,
|
|
||||||
'data' => $result,
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -382,6 +382,16 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
|
|||||||
'descripcion' => $linea_pedido->concepto
|
'descripcion' => $linea_pedido->concepto
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
// se actualiza el totalizador del pedido
|
||||||
|
$total_tirada = $pedidoModel
|
||||||
|
->selectSum('cantidad')
|
||||||
|
->where('pedido_id', $idPedido)
|
||||||
|
->first()->cantidad;
|
||||||
|
$pedidoModel = model('App\Models\Pedidos\PedidoModel');
|
||||||
|
$pedidoModel->update($idPedido, [
|
||||||
|
'total_tirada' => $total_tirada
|
||||||
|
]);
|
||||||
|
|
||||||
// se actualiza la factura
|
// se actualiza la factura
|
||||||
$linea_pedido = $this->model->generarLineaPedido($id, true, $idPedido)[0];
|
$linea_pedido = $this->model->generarLineaPedido($id, true, $idPedido)[0];
|
||||||
$facturaLineaModel = model('App\Models\Facturas\FacturaLineaModel');
|
$facturaLineaModel = model('App\Models\Facturas\FacturaLineaModel');
|
||||||
|
|||||||
@ -26,4 +26,10 @@ return [
|
|||||||
'finalizado' => 'Finalizado',
|
'finalizado' => 'Finalizado',
|
||||||
'acciones' => 'Acciones',
|
'acciones' => 'Acciones',
|
||||||
'backToPanel' => 'Volver al panel',
|
'backToPanel' => 'Volver al panel',
|
||||||
|
|
||||||
|
'errors' => [
|
||||||
|
'noDataToFind' => 'No se ha introducido ningún dato para buscar',
|
||||||
|
'notFound' => 'No se encuentra el pedido o ISBN',
|
||||||
|
'noAddresses' => 'El pedido no tiene direcciones de envío',
|
||||||
|
],
|
||||||
];
|
];
|
||||||
67
ci4/app/Services/LogisticaService.php
Normal file
67
ci4/app/Services/LogisticaService.php
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services;
|
||||||
|
|
||||||
|
use Config\Services;
|
||||||
|
|
||||||
|
class LogisticaService
|
||||||
|
{
|
||||||
|
public static function findPedidoOrISBN($search)
|
||||||
|
{
|
||||||
|
$modelPedido = model('App\Models\Pedidos\PedidoModel');
|
||||||
|
|
||||||
|
$search = trim($search);
|
||||||
|
$searchClean = str_replace('-', '', $search);
|
||||||
|
$modelPedido = model('App\Models\Pedidos\PedidoModel');
|
||||||
|
|
||||||
|
$builder = $modelPedido->builder();
|
||||||
|
$builder->select('pedidos.id as pedido_id, pedidos_linea.id as linea_id, presupuestos.id as presupuesto_id');
|
||||||
|
$builder->join('pedidos_linea', 'pedidos_linea.pedido_id = pedidos.id', 'left');
|
||||||
|
$builder->join('presupuestos', 'presupuestos.id = pedidos_linea.presupuesto_id', 'left');
|
||||||
|
|
||||||
|
$builder->groupStart()
|
||||||
|
->where('pedidos.id', $search)
|
||||||
|
->whereIn('pedidos.estado', ['finalizado'])
|
||||||
|
->orWhere("REPLACE(presupuestos.isbn, '-', '')", $searchClean)
|
||||||
|
->groupEnd();
|
||||||
|
|
||||||
|
$result = $builder->get()->getResult();
|
||||||
|
|
||||||
|
if (empty($result)) {
|
||||||
|
$response = [
|
||||||
|
'status' => false,
|
||||||
|
'message' => lang('Logistica.errors.notFound'),
|
||||||
|
];
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
|
||||||
|
$PresupuestoDireccionesModel = model('App\Models\Presupuestos\PresupuestoDireccionesModel');
|
||||||
|
$numDirecciones = $PresupuestoDireccionesModel->where('presupuesto_id', $result[0]->presupuesto_id)
|
||||||
|
->countAllResults();
|
||||||
|
if ($numDirecciones == 0) {
|
||||||
|
$response = [
|
||||||
|
'status' => false,
|
||||||
|
'message' => lang('Logistica.errors.noAddresses'),
|
||||||
|
];
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
|
||||||
|
// detectar si el pedido tiene los albaranes generados
|
||||||
|
$AlbaranModel = model('App\Models\Pedidos\AlbaranModel');
|
||||||
|
$numAlbaranes = $AlbaranModel->where('pedido_id', $result[0]->pedido_id)
|
||||||
|
->countAllResults();
|
||||||
|
|
||||||
|
$response = [
|
||||||
|
'status' => true,
|
||||||
|
'data' => $result[0],
|
||||||
|
];
|
||||||
|
|
||||||
|
if($numAlbaranes == 0){
|
||||||
|
$user = auth()->user()->id;
|
||||||
|
$AlbaranModel->generarAlbaranes($result[0]->pedido_id, [$result[0]->presupuesto_id], $user);
|
||||||
|
$response['data']->createAlbaran = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -11,6 +11,8 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
|
|
||||||
|
<?= view("themes/_commonPartialsBs/_alertBoxes") ?>
|
||||||
|
|
||||||
<div class="card accordion-item active mb-5">
|
<div class="card accordion-item active mb-5">
|
||||||
<h4 class="accordion-header px-4 py-3">
|
<h4 class="accordion-header px-4 py-3">
|
||||||
<?= lang("Logistica.nuevoEnvio") ?>
|
<?= lang("Logistica.nuevoEnvio") ?>
|
||||||
@ -72,7 +74,8 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mt-3">
|
<div class="mt-3">
|
||||||
<button type="button" class="btn btn-secondary" id="btnImprimirEtiquetas" onclick="window.location.href='<?= route_to('LogisticaPanel') ?>'">
|
<button type="button" class="btn btn-secondary" id="btnImprimirEtiquetas"
|
||||||
|
onclick="window.location.href='<?= route_to('LogisticaPanel') ?>'">
|
||||||
<?= lang('Logistica.backToPanel') ?>
|
<?= lang('Logistica.backToPanel') ?>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
@ -81,3 +84,13 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<?= $this->endSection() ?>
|
<?= $this->endSection() ?>
|
||||||
|
|
||||||
|
|
||||||
|
<?= $this->section('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/logistica/envio.js") ?>"></script>
|
||||||
|
<?= $this->endSection() ?>
|
||||||
41
httpdocs/assets/js/safekat/pages/logistica/envio.js
Normal file
41
httpdocs/assets/js/safekat/pages/logistica/envio.js
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
import Ajax from '../../components/ajax.js';
|
||||||
|
|
||||||
|
$(()=>{
|
||||||
|
|
||||||
|
$('#buscadorPedidos').on('keydown', function(e) {
|
||||||
|
if (e.key === 'Enter' || e.keyCode === 13) {
|
||||||
|
e.preventDefault(); // Evita el submit si está dentro de un form
|
||||||
|
let search = $(this).val().trim();
|
||||||
|
new Ajax(
|
||||||
|
'/logistica/buscar/'+search,
|
||||||
|
{},
|
||||||
|
{},
|
||||||
|
function(response) {
|
||||||
|
if(response.data.createAlbaran){
|
||||||
|
|
||||||
|
Swal.fire({
|
||||||
|
title: 'Atención!',
|
||||||
|
text: 'El pedido no contenía ningún albarán. Se han añadido automáticamente.',
|
||||||
|
icon: 'warning',
|
||||||
|
showCancelButton: false,
|
||||||
|
confirmButtonColor: '#3085d6',
|
||||||
|
confirmButtonText: 'Ok',
|
||||||
|
customClass: {
|
||||||
|
confirmButton: 'btn btn-primary me-1',
|
||||||
|
},
|
||||||
|
buttonsStyling: false
|
||||||
|
}).then(() => {
|
||||||
|
//window.open(`${urlObj.origin}` + '/presupuestoadmin/edit/' + response.id);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
function(xhr, status, error) {
|
||||||
|
popErrorAlert(error.responseJSON.message);
|
||||||
|
}
|
||||||
|
).get();
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user