diff --git a/ci4/app/Config/Routes.php b/ci4/app/Config/Routes.php index 03ad8f11..4e1c1a81 100755 --- a/ci4/app/Config/Routes.php +++ b/ci4/app/Config/Routes.php @@ -871,6 +871,7 @@ $routes->group('logistica', ['namespace' => 'App\Controllers\Logistica'], functi $routes->get('selectForNewEnvio', 'LogisticaController::findForNewEnvio'); $routes->get('selectDireccionForEnvio', 'LogisticaController::selectDireccionForEnvio'); $routes->post('imprimirEtiquetas', 'LogisticaController::imprimirEtiquetas'); + $routes->post('ficharEmbalaje', 'LogisticaController::ficharEmbalaje'); $routes->get('listAlbaranes', 'LogisticaController::listAlbaranes', ['as' => 'albaranesList']); }); diff --git a/ci4/app/Controllers/Logistica/LogisticaController.php b/ci4/app/Controllers/Logistica/LogisticaController.php index b69b0f4c..4ffd0733 100755 --- a/ci4/app/Controllers/Logistica/LogisticaController.php +++ b/ci4/app/Controllers/Logistica/LogisticaController.php @@ -132,6 +132,8 @@ class LogisticaController extends BaseController $result = $query->orderBy("name", "asc")->get()->getResultObject(); + $query = model('App\Models\Logistica\EnvioModel')->db->getLastQuery(); + return $this->response->setJSON($result); } else { return $this->failUnauthorized('Invalid request', 403); @@ -392,6 +394,17 @@ class LogisticaController extends BaseController } } + public function ficharEmbalaje() + { + if ($this->request->isAJAX()) { + + $ids = $this->request->getPost('ids') ?? []; + $result = LogisticaService::ficharEmbalaje($ids); + return $this->response->setJSON($result); + } else { + return $this->failUnauthorized('Invalid request', 403); + } + } public function datatable_enviosEdit($idEnvio) { @@ -406,6 +419,12 @@ class LogisticaController extends BaseController return ''; } ) + ->edit( + "ordenTrabajo", + function ($row, $meta) { + return '' . $row->ordenTrabajo . ''; + } + ) ->edit( "pedido", function ($row, $meta) { diff --git a/ci4/app/Language/es/Logistica.php b/ci4/app/Language/es/Logistica.php index 0ef3e713..be9a91d8 100755 --- a/ci4/app/Language/es/Logistica.php +++ b/ci4/app/Language/es/Logistica.php @@ -44,6 +44,7 @@ return [ 'totales' => 'Totales', 'cajas' => 'Cajas', + 'ordenTrabajo' => 'OT', 'pedido' => 'Pedido', 'presupuesto' => 'Presupuesto', 'unidadesEnvio' => 'Unidades envío', @@ -62,6 +63,7 @@ return [ 'codigoSeguimiento' => 'Código de seguimiento', 'empresaMensajería' => 'Empresa de mensajería', + 'ficharEmbalaje' => 'Fichar embalaje', 'finalizarEnvio' => 'Finalizar envío', 'finalizarEnvioYOTs' => 'Finalizar envío y OTS', @@ -90,6 +92,7 @@ return [ 'errorInsertarEtiqueta' => 'Error al insertar la etiqueta', 'noEtiqueta' => 'No se ha encontrado la etiqueta', 'noEtiquetaLineas' => 'No se han encontrado líneas de etiqueta', + 'noLineas' => 'No se ha seleccionado ninguna línea', ], 'success' => [ 'finalizado' => 'El envío se ha finalizado correctamente', @@ -101,6 +104,7 @@ return [ 'comentariosUpdated' => 'Comentarios actualizados correctamente', 'successReordenarCajas' => 'Cajas reordenadas correctamente', 'imprimirEtiquetas' => 'Etiquetas impresas correctamente', + 'successFicharEmbalaje' => 'Embalaje fichado correctamente', ], ]; \ No newline at end of file diff --git a/ci4/app/Language/es/Produccion.php b/ci4/app/Language/es/Produccion.php index 728920c0..3d990871 100755 --- a/ci4/app/Language/es/Produccion.php +++ b/ci4/app/Language/es/Produccion.php @@ -182,6 +182,7 @@ return [ 'duplicate_estado_tarea_progress' => "Último estado de la tarea repetido", 'task_already_finished' => "La tarea se ha marcado como finalizada.", 'print_label' => "Imprimir etiqueta", + 'fichar_embalaje' => "Fichar embalaje", 'click_init' => "Clicks al inicio", 'click_end' => "Clicks al final", "comentarios" => "Comentarios", diff --git a/ci4/app/Models/Logistica/EnvioLineaModel.php b/ci4/app/Models/Logistica/EnvioLineaModel.php index a50709d3..76ae7b9b 100644 --- a/ci4/app/Models/Logistica/EnvioLineaModel.php +++ b/ci4/app/Models/Logistica/EnvioLineaModel.php @@ -35,7 +35,7 @@ class EnvioLineaModel extends Model $builder = $this->db ->table($this->table . " t1") ->select( - "t1.id, t1.pedido_id as pedido, t3.id as presupuesto, + "t1.id, t1.pedido_id as pedido, t3.id as presupuesto, t4.id as ordenTrabajo, t3.titulo as titulo, t1.unidades_envio as unidadesEnvio, t1.unidades_envio as unidadesEnvioRaw, t1.unidades_total as unidadesTotal, t2.tipo_envio as tipo_envio, IFNULL(( @@ -59,6 +59,7 @@ class EnvioLineaModel extends Model ); $builder->join("envios t2", "t1.envio_id = t2.id", "left"); $builder->join("presupuestos t3", "t1.presupuesto_id = t3.id", "left"); + $builder->join("ordenes_trabajo t4", "t1.pedido_id = t4.pedido_id", "left"); $builder->where("t1.envio_id", $envio_id); diff --git a/ci4/app/Services/LogisticaService.php b/ci4/app/Services/LogisticaService.php index cb4fb1b5..6d5f91b9 100644 --- a/ci4/app/Services/LogisticaService.php +++ b/ci4/app/Services/LogisticaService.php @@ -57,7 +57,8 @@ class LogisticaService ->join('orden_trabajo_dates ot_dates', 'ot_dates.orden_trabajo_id = ot.id') ->whereIn('pr.id', $presupuestoIds) ->whereIn('p.estado', ['finalizado', 'produccion']) - ->where('ot_dates.embalaje_at IS NOT NULL') + ->where('p.fecha_encuadernado IS NOT NULL') + ->where('DATE(p.fecha_encuadernado) <=', date('Y-m-d')) ->where("NOT EXISTS ( SELECT 1 FROM envios_lineas el @@ -103,16 +104,15 @@ class LogisticaService ->join('presupuestos pr', 'pr.id = pl.presupuesto_id') ->join('presupuesto_direcciones pd', 'pd.presupuesto_id = pr.id') ->join('ordenes_trabajo ot', 'ot.pedido_id = p.id') - ->join('orden_trabajo_dates ot_dates', 'ot_dates.orden_trabajo_id = ot.id') ->whereIn('p.estado', ['finalizado', 'produccion']) - ->where('ot_dates.embalaje_at IS NOT NULL') + ->where('p.fecha_encuadernado IS NOT NULL') + ->where('DATE(p.fecha_encuadernado) <=', date('Y-m-d')) ->groupBy('pl.id'); // 4. Envolver y filtrar por unidades pendientes $builder = $db->table("({$subBuilder->getCompiledSelect(false)}) AS sub"); $builder->select('id, name'); $builder->where('cantidad > unidades_enviadas'); - $builder->orderBy('name', 'ASC'); return $builder; } @@ -539,6 +539,13 @@ class LogisticaService $ot = $otModel->where('pedido_id', $linea->pedido_id) ->first(); $ps = (new ProductionService())->init($ot->id); + $date = $ps->getOrdenTrabajo()->dates()->embalaje_at; + if (is_null($date) || empty($date)) { + $ps->updateOrdenTrabajoDate([ + "name" => "embalaje_at", + "embalaje_at" => date('Y-m-d H:i:s') + ]); + } $ps->updateOrdenTrabajoDate([ "name" => "envio_at", "envio_at" => date('Y-m-d H:i:s') @@ -572,6 +579,29 @@ class LogisticaService return $data_return; } + public static function ficharEmbalaje($ids = null) + { + + if (is_null($ids) || empty($ids) || count($ids) == 0) { + return [ + 'status' => false, + 'message' => lang('Logistica.errors.noLineas'), + ]; + } + + for ($index = 0; $index < count($ids); $index++) { + $ps = (new ProductionService())->init($ids[$index]); + $ps->updateOrdenTrabajoDate([ + "name" => "embalaje_at", + "embalaje_at" => date('Y-m-d') + ]); + } + return [ + 'status' => true, + 'message' => lang('Logistica.success.successFicharEmbalaje'), + ]; + } + public static function generateEtiquetasTitulos($envio, $lineas, $printer, $cajas) { $data = [ diff --git a/ci4/app/Views/themes/vuexy/form/logistica/viewEnvioEditForm.php b/ci4/app/Views/themes/vuexy/form/logistica/viewEnvioEditForm.php index 7c63bd17..27eecf8c 100644 --- a/ci4/app/Views/themes/vuexy/form/logistica/viewEnvioEditForm.php +++ b/ci4/app/Views/themes/vuexy/form/logistica/viewEnvioEditForm.php @@ -10,7 +10,7 @@
= lang('Logistica.buttonsActions') ?>
-| - | = lang("Logistica.pedido") ?> | -= lang("Logistica.presupuesto") ?> | -= lang("Logistica.titulo") ?> | -- = lang("Logistica.unidadesEnvio") ?> - | -- = lang("Logistica.unidadesEnviadas") ?> - | -- = lang("Logistica.unidadesTotales") ?> - | -- | - | - |
|---|---|---|---|---|---|---|---|---|---|
|
-
- = lang("Logistica.unidadesTotalesFooter") ?>
-
-
- |
- |||||||||
|
-
- = lang("Logistica.peso") ?>
-
-
- |
- |||||||||
= lang('Logistica.buttonsActions') ?>
| + | = lang("Logistica.ordenTrabajo") ?> | += lang("Logistica.pedido") ?> | += lang("Logistica.presupuesto") ?> | += lang("Logistica.titulo") ?> | ++ = lang("Logistica.unidadesEnvio") ?> + | ++ = lang("Logistica.unidadesEnviadas") ?> + | ++ = lang("Logistica.unidadesTotales") ?> + | ++ | + | + |
|---|---|---|---|---|---|---|---|---|---|---|
|
+
+ = lang("Logistica.unidadesTotalesFooter") ?>
+
+
+ |
+ ||||||||||
|
+
+ = lang("Logistica.peso") ?>
+
+
+ |
+ ||||||||||