diff --git a/ci4/app/Config/Routes.php b/ci4/app/Config/Routes.php
index ca0cd92a..9df9401a 100755
--- a/ci4/app/Config/Routes.php
+++ b/ci4/app/Config/Routes.php
@@ -817,7 +817,7 @@ $routes->group('logistica', ['namespace' => 'App\Controllers\Logistica'], functi
$routes->post('updateProveedorEnvio', 'LogisticaController::updateProveedorEnvio');
$routes->post('finalizarEnvio', 'LogisticaController::finalizarEnvio');
$routes->post('generateEnvio', 'LogisticaController::generarEnvio');
- $routes->get('selectPedidosForEnvio', 'LogisticaController::findPedidosNewEnvio');
+ $routes->get('selectForNewEnvio', 'LogisticaController::findForNewEnvio');
$routes->get('selectDireccionForEnvio', 'LogisticaController::selectDireccionForEnvio');
});
diff --git a/ci4/app/Controllers/Logistica/LogisticaController.php b/ci4/app/Controllers/Logistica/LogisticaController.php
index 8dbd4630..06c57d89 100755
--- a/ci4/app/Controllers/Logistica/LogisticaController.php
+++ b/ci4/app/Controllers/Logistica/LogisticaController.php
@@ -70,11 +70,11 @@ class LogisticaController extends BaseController
}
- public function findPedidosNewEnvio()
+ public function findForNewEnvio()
{
if ($this->request->isAJAX()) {
- $query = LogisticaService::findPedidosNewEnvio();
+ $query = LogisticaService::findForNewEnvio();
if ($this->request->getGet("q")) {
$query->groupStart()
->orLike("id", $this->request->getGet("q"))
@@ -109,21 +109,6 @@ class LogisticaController extends BaseController
- public function searchPedidoOrISBN($search = "", $envio_id = null)
- {
-
- if (empty($search)) {
- $result = [
- 'status' => false,
- 'message' => lang('Logistica.errors.noDataToFind'),
- ];
- return $this->response->setJSON($result);
- }
- $result = LogisticaService::findPedidoOrISBN($search);
- return $this->response->setJSON($result);
- }
-
-
public function generarEnvio()
{
if ($this->request->isAJAX()) {
@@ -176,9 +161,18 @@ class LogisticaController extends BaseController
public function datatable_envios()
{
+
+ $otsFilter = $this->request->getGetPost('otsFilter');
+
$model = model('App\Models\Logistica\EnvioModel');
$q = $model->getDatatableQuery();
+ if (!empty($otsFilter)) {
+ $q->groupStart();
+ $q->like('t5.id', $otsFilter);
+ $q->groupEnd();
+ }
+
$result = DataTable::of($q)
->edit(
diff --git a/ci4/app/Language/es/Logistica.php b/ci4/app/Language/es/Logistica.php
index db614f9a..f0e2d6bc 100755
--- a/ci4/app/Language/es/Logistica.php
+++ b/ci4/app/Language/es/Logistica.php
@@ -9,12 +9,13 @@ return [
'albaranes' => 'Albaranes',
'envioSimpleMultiple' => 'Envío simple/múltiple',
'nuevoEnvio' => 'Nuevo envío',
- 'buscadorPedidosTitle' => 'Código Pedido o ISBN',
- 'buscadorPedidosTitle2' => 'Código Pedido o título',
+ 'buscadorPedidosTitle' => 'Código OT o ISBN',
+ 'buscadorPedidosTitle2' => 'Código OT o título',
'selectDirecciones' => 'Dirección de envio',
'listadoEnvios' => 'Listado de envíos',
'idEnvio' => 'ID Envío',
'numeroPedidos' => 'Nº Pedidos',
+ 'numeroOts' => 'Nº OTs',
'numeroLineas' => 'Nº Líneas',
'att' => 'Att',
'direccion' => 'Dirección',
@@ -28,6 +29,7 @@ return [
'backToPanel' => 'Volver al panel',
'no' => 'No',
'si' => 'Sí',
+ 'todos' => 'Todos',
'envio' => 'Envío',
'addLineasEnvio' => 'Añadir líneas al envío',
diff --git a/ci4/app/Models/Logistica/EnvioModel.php b/ci4/app/Models/Logistica/EnvioModel.php
index b0a60026..f94556c8 100644
--- a/ci4/app/Models/Logistica/EnvioModel.php
+++ b/ci4/app/Models/Logistica/EnvioModel.php
@@ -43,12 +43,14 @@ class EnvioModel extends Model
$builder = $this->db
->table($this->table . " t1")
->select(
- "t1.id, GROUP_CONCAT(DISTINCT t2.pedido_id) AS pedidos,
+ "t1.id, GROUP_CONCAT(DISTINCT t5.id) AS ots,
COUNT(t2.id) AS num_lineas,
t1.att, t1.direccion, t1.ciudad, t3.nombre as pais, t1.cp, t1.email, t1.telefono, t1.finalizado"
);
$builder->join("envios_lineas t2", "t2.envio_id = t1.id", "left");
$builder->join("lg_paises t3", "t3.id = t1.pais_id", "left");
+ $builder->join("pedidos t4", "t4.id = t2.pedido_id", "left");
+ $builder->join('ordenes_trabajo t5', 't5.pedido_id = t4.id');
$builder->groupBy("t1.id");
return $builder;
diff --git a/ci4/app/Services/LogisticaService.php b/ci4/app/Services/LogisticaService.php
index 9124a3d7..4d6f1bdc 100644
--- a/ci4/app/Services/LogisticaService.php
+++ b/ci4/app/Services/LogisticaService.php
@@ -7,111 +7,6 @@ use Config\Services;
class LogisticaService
{
- public static function findPedidoOrISBN($search)
- {
- $multienvio = false;
- $direcciones = [];
-
- $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',
- 'pedidos_linea.cantidad as cantidad_linea',
- '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->join('envios_lineas', 'envios_lineas.pedido_id = pedidos_linea.pedido_id', 'left');
-
- $builder->groupStart()
- ->where('pedidos.id', $search)
- ->whereIn('pedidos.estado', ['finalizado', 'produccion'])
- ->orWhere("REPLACE(presupuestos.isbn, '-', '')", $searchClean)
- ->groupEnd();
-
- $builder->groupBy('pedidos_linea.id');
- $builder->having('IFNULL(SUM(envios_lineas.unidades_envio), 0) < cantidad_linea', null, false);
-
-
- $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;
- } else if ($numDirecciones > 1) {
- $multienvio = true;
- $dirs = $PresupuestoDireccionesModel->select('direccion')->where('presupuesto_id', $result[0]->presupuesto_id)
- ->findAll();
- foreach ($dirs as $key => $direccion) {
- $modelEnvioLineasModel = model('App\Models\Logistica\EnvioLineaModel');
- $unidades_en_direccion = $modelEnvioLineasModel->select('SUM(envios_lineas.unidades_envio) as unidades_enviadas,
- envios_lineas.unidades_total')
- ->join('envios', 'envios.id = envios_lineas.envio_id')
- ->where('pedido_id', $result[0]->pedido_id)
- ->where('envios.direccion', $direccion->direccion)
- ->where('envios.finalizado', 1)
- ->groupBy('pedido_id')->get()->getResult();
- if (count($unidades_en_direccion) == 0 || $unidades_en_direccion[0]->unidades_enviadas < $unidades_en_direccion[0]->unidades_total) {
- array_push($direcciones, $direccion->direccion);
- }
- }
- }
-
- $response = [
- 'status' => true,
- 'data' => $result[0],
- ];
-
- if ($multienvio) {
- $response_envio = [
- 'status' => true,
- 'multienvio' => true,
- 'direcciones' => $direcciones,
- 'pedido_id' => $result[0]->pedido_id,
- ];
- return $response_envio;
- }
-
-
- $direccion = $PresupuestoDireccionesModel->select('direccion')->where('presupuesto_id', $result[0]->presupuesto_id)
- ->first()->direccion;
- $response_envio = LogisticaService::generateEnvio($result[0]->pedido_id, $direccion);
- if ($response_envio['status'] == false) {
- $response = [
- 'status' => false,
- 'message' => $response_envio['message'],
- ];
- return $response;
- } else {
- $response['data']->id_envio = $response_envio['data']['id_envio'];
- $response['data']->multienvio = false;
- }
-
- return $response;
- }
-
public static function findLineaEnvioPorEnvio(int $envio_id)
@@ -142,8 +37,8 @@ class LogisticaService
// 3. Subconsulta principal
$subBuilder = $db->table('pedidos_linea pl')
->select("
- pl.id AS id,
- CONCAT('[', p.id, '] - ', pr.titulo) AS name,
+ ot.id AS id,
+ CONCAT('[', ot.id, '] - ', pr.titulo) AS name,
(
SELECT IFNULL(SUM(el.unidades_envio), 0)
FROM envios_lineas el
@@ -183,15 +78,15 @@ class LogisticaService
return $builder;
}
- public static function findPedidosNewEnvio()
+ public static function findForNewEnvio()
{
$db = \Config\Database::connect();
// 3. Subconsulta principal
$subBuilder = $db->table('pedidos_linea pl')
->select("
- pl.id AS id,
- CONCAT('[', p.id, '] - ', pr.titulo) AS name,
+ ot.id AS id,
+ CONCAT('[', ot.id, '] - ', pr.titulo) AS name,
(
SELECT IFNULL(SUM(el.unidades_envio), 0)
FROM envios_lineas el
diff --git a/ci4/app/Views/themes/vuexy/form/logistica/viewEnvioForm.php b/ci4/app/Views/themes/vuexy/form/logistica/viewEnvioForm.php
index 8aee1d7a..75b3bbc6 100644
--- a/ci4/app/Views/themes/vuexy/form/logistica/viewEnvioForm.php
+++ b/ci4/app/Views/themes/vuexy/form/logistica/viewEnvioForm.php
@@ -50,7 +50,7 @@
= lang('Logistica.idEnvio') ?? 'ID Envío' ?>
- = lang('Logistica.numeroPedidos') ?? 'Nº Pedidos' ?>
+ = lang('Logistica.numeroOts') ?? 'Nº OTs' ?>
= lang('Logistica.numeroLineas') ?? 'Nº Líneas' ?>
= lang('Logistica.att') ?? 'Att' ?>
= lang('Logistica.direccion') ?? 'Dirección' ?>
diff --git a/ci4/app/Views/themes/vuexy/form/logistica/viewLogisticaSelectEnvios.php b/ci4/app/Views/themes/vuexy/form/logistica/viewLogisticaSelectEnvios.php
index c8fd78c3..cea9b37b 100644
--- a/ci4/app/Views/themes/vuexy/form/logistica/viewLogisticaSelectEnvios.php
+++ b/ci4/app/Views/themes/vuexy/form/logistica/viewLogisticaSelectEnvios.php
@@ -71,7 +71,7 @@
+ = lang('Logistica.idEnvio') ?? 'ID Envío' ?>
- = lang('Logistica.numeroPedidos') ?? 'Nº Pedidos' ?>
+ = lang('Logistica.numeroOts') ?? 'Nº OTs' ?>
= lang('Logistica.numeroLineas') ?? 'Nº Líneas' ?>
= lang('Logistica.att') ?? 'Att' ?>
= lang('Logistica.direccion') ?? 'Dirección' ?>
@@ -83,6 +83,26 @@
= lang('Logistica.finalizado') ?? 'Finalizado' ?>
= lang('Logistica.acciones') ?? 'Acciones' ?>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+