mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
terminado
This commit is contained in:
@ -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');
|
||||
});
|
||||
|
||||
|
||||
@ -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(
|
||||
|
||||
@ -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',
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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
|
||||
|
||||
@ -50,7 +50,7 @@
|
||||
<thead>
|
||||
<tr>
|
||||
<th><?= lang('Logistica.idEnvio') ?? 'ID Envío' ?></th>
|
||||
<th><?= lang('Logistica.numeroPedidos') ?? 'Nº Pedidos' ?></th>
|
||||
<th><?= lang('Logistica.numeroOts') ?? 'Nº OTs' ?></th>
|
||||
<th><?= lang('Logistica.numeroLineas') ?? 'Nº Líneas' ?></th>
|
||||
<th><?= lang('Logistica.att') ?? 'Att' ?></th>
|
||||
<th><?= lang('Logistica.direccion') ?? 'Dirección' ?></th>
|
||||
|
||||
@ -71,7 +71,7 @@
|
||||
<thead>
|
||||
<tr>
|
||||
<th><?= lang('Logistica.idEnvio') ?? 'ID Envío' ?></th>
|
||||
<th><?= lang('Logistica.numeroPedidos') ?? 'Nº Pedidos' ?></th>
|
||||
<th><?= lang('Logistica.numeroOts') ?? 'Nº OTs' ?></th>
|
||||
<th><?= lang('Logistica.numeroLineas') ?? 'Nº Líneas' ?></th>
|
||||
<th><?= lang('Logistica.att') ?? 'Att' ?></th>
|
||||
<th><?= lang('Logistica.direccion') ?? 'Dirección' ?></th>
|
||||
@ -83,6 +83,26 @@
|
||||
<th><?= lang('Logistica.finalizado') ?? 'Finalizado' ?></th>
|
||||
<th><?= lang('Logistica.acciones') ?? 'Acciones' ?></th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><input type="text" class="form-control envio-filter" name="id"></th>
|
||||
<th><input type="text" class="form-control envio-filter-ots" name="ots"></th>
|
||||
<th></th>
|
||||
<th><input type="text" class="form-control envio-filter" name="att"></th>
|
||||
<th><input type="text" class="form-control envio-filter" name="direccion"></th>
|
||||
<th><input type="text" class="form-control envio-filter" name="ciudad"></th>
|
||||
<th><input type="text" class="form-control envio-filter" name="pais"></th>
|
||||
<th><input type="text" class="form-control envio-filter" name="cp"></th>
|
||||
<th><input type="text" class="form-control envio-filter" name="email"></th>
|
||||
<th><input type="text" class="form-control envio-filter" name="telefono"></th>
|
||||
<th>
|
||||
<select class="form-control envio-filter-select" name="finalizado">
|
||||
<option value=""><?= lang('Logistica.todos')?></option>
|
||||
<option value="0"><?= lang('Basic.global.no') ?></option>
|
||||
<option value="1"><?= lang('Basic.global.yes') ?></option>
|
||||
</select>
|
||||
</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
</tbody>
|
||||
|
||||
@ -3,8 +3,9 @@ import ClassSelect from '../../components/select2.js';
|
||||
|
||||
$(() => {
|
||||
|
||||
let otsFilter = '';
|
||||
|
||||
const selectPedidos = new ClassSelect($('#buscadorPedidos'), '/logistica/selectPedidosForEnvio', "");
|
||||
const selectPedidos = new ClassSelect($('#buscadorPedidos'), '/logistica/selectForNewEnvio', "");
|
||||
selectPedidos.init();
|
||||
const selectDirecciones = new ClassSelect($('#selectDirecciones'), '/logistica/selectDireccionForEnvio', "", true, {
|
||||
pedido_id: () => selectPedidos.getVal()
|
||||
@ -63,10 +64,13 @@ $(() => {
|
||||
"dom": 'lBrtip',
|
||||
"ajax": {
|
||||
"url": "/logistica/datatableEnvios",
|
||||
"data": function (d) {
|
||||
d.otsFilter = otsFilter;
|
||||
}
|
||||
},
|
||||
"columns": [
|
||||
{ "data": "id" },
|
||||
{ "data": "pedidos" },
|
||||
{ "data": "ots" },
|
||||
{ "data": "num_lineas" },
|
||||
{ "data": "att" },
|
||||
{ "data": "direccion" },
|
||||
@ -99,6 +103,26 @@ $(() => {
|
||||
window.location.href = '/logistica/envio/' + $(this).attr('data-id');
|
||||
});
|
||||
|
||||
$(document).on("keyup", ".envio-filter", (event) => {
|
||||
let columnName = $(event.currentTarget).attr("name");
|
||||
let columnIndex = $('#tableOfEnvios').DataTable().columns().eq(0).filter(function (index) {
|
||||
return $('#tableOfEnvios').DataTable().column(index).dataSrc() === columnName;
|
||||
})[0];
|
||||
$('#tableOfEnvios').DataTable().column(columnIndex).search($(event.currentTarget).val()).draw()
|
||||
})
|
||||
|
||||
|
||||
$(document).on("keyup", ".envio-filter-ots", (event) => {
|
||||
otsFilter = $(event.currentTarget).val();
|
||||
$('#tableOfEnvios').DataTable().ajax.reload();
|
||||
})
|
||||
|
||||
$(document).on("change", ".envio-filter-select", (event) => {
|
||||
let columnName = $(event.currentTarget).attr("name");
|
||||
let columnIndex = $('#tableOfEnvios').DataTable().columns().eq(0).filter(function (index) {
|
||||
return $('#tableOfEnvios').DataTable().column(index).dataSrc() === columnName;
|
||||
})[0];
|
||||
$('#tableOfEnvios').DataTable().column(columnIndex).search($(event.currentTarget).val()).draw();
|
||||
});
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user