mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
Merge branch 'main' into add/impresion_etiquetas_envios
This commit is contained in:
@ -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
|
||||
|
||||
@ -20,6 +20,7 @@ use App\Entities\Tarifas\Acabados\TarifaAcabadoEntity;
|
||||
use App\Models\Configuracion\ConfigVariableModel;
|
||||
use App\Models\Configuracion\MaquinaModel;
|
||||
use App\Models\OrdenTrabajo\OrdenTrabajoFileModel;
|
||||
use App\Models\OrdenTrabajo\OrdenTrabajoTareaProgressDate;
|
||||
use App\Models\Pedidos\PedidoModel;
|
||||
use App\Models\Usuarios\UserModel;
|
||||
use CodeIgniter\Database\BaseBuilder;
|
||||
@ -55,6 +56,7 @@ class ProductionService extends BaseService
|
||||
protected OrdenTrabajoUser $otUser;
|
||||
protected OrdenTrabajoEntity $ot;
|
||||
protected OrdenTrabajoFileModel $otFileModel;
|
||||
protected OrdenTrabajoTareaProgressDate $otTareaProgressDate;
|
||||
protected PedidoModel $pedidoModel;
|
||||
protected UserModel $userModel;
|
||||
protected ConfigVariableModel $configVariableModel;
|
||||
@ -172,6 +174,7 @@ class ProductionService extends BaseService
|
||||
$this->userModel = model(UserModel::class);
|
||||
$this->otFileModel = model(OrdenTrabajoFileModel::class);
|
||||
$this->pedidoModel = model(PedidoModel::class);
|
||||
$this->otTareaProgressDate = model(OrdenTrabajoTareaProgressDate::class);
|
||||
$this->ordenTrabajoConfig = config('OrdenTrabajo');
|
||||
$this->statusColor = $this->ordenTrabajoConfig->OT_COLORS["sin_imprimir"];
|
||||
$this->configVariableModel = model(ConfigVariableModel::class);
|
||||
@ -926,7 +929,38 @@ class ProductionService extends BaseService
|
||||
}
|
||||
return $this->otTarea->update($tarea_id, $data);
|
||||
}
|
||||
|
||||
public function storeOrdenTrabajoTareaProgressDate($data): bool
|
||||
{
|
||||
$data["action_at"] = Time::now()->format('Y-m-d H:i:s');
|
||||
$data["action_user_id"] = auth()->user()->id;
|
||||
$lastDate = $this->otTareaProgressDate->where('ot_tarea_id', $data['ot_tarea_id'])->orderBy('action_at', 'DESC')->first();
|
||||
if ($lastDate) {
|
||||
if ($lastDate->estado == $data['estado']) {
|
||||
throw new Exception(lang('Produccion.duplicate_estado_tarea_progress'));
|
||||
}
|
||||
if ($lastDate->estado == 'F') {
|
||||
throw new Exception(lang('Produccion.task_already_finished'));
|
||||
}
|
||||
}
|
||||
return $this->otTareaProgressDate->insert($data);
|
||||
}
|
||||
public function getTareaLastState($tarea_id)
|
||||
{
|
||||
$lastDate = $this->otTareaProgressDate->where('ot_tarea_id', $tarea_id)->orderBy('action_at', 'DESC')->first();
|
||||
return $lastDate->estado;
|
||||
}
|
||||
public function deleteOrdenTrabajoTareaProgressDates($orden_trabajo_tarea_id): bool
|
||||
{
|
||||
$response = false;
|
||||
$data = ['ot_tarea_id' => $orden_trabajo_tarea_id, 'estado' => 'P'];
|
||||
$data["action_at"] = Time::now()->format('Y-m-d H:i:s');
|
||||
$data["action_user_id"] = auth()->user()->id;
|
||||
$status = $this->otTareaProgressDate->where('ot_tarea_id', $orden_trabajo_tarea_id)->delete();
|
||||
if ($status) {
|
||||
$response = $this->storeOrdenTrabajoTareaProgressDate($data);
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
public function updateOrdenTrabajoDate($data)
|
||||
{
|
||||
$result = [];
|
||||
@ -948,6 +982,18 @@ class ProductionService extends BaseService
|
||||
$this->updateProgress();
|
||||
return $result;
|
||||
}
|
||||
public function emptyOrdenTrabajoDate(int $orden_trabajo_id, string $dateName)
|
||||
{
|
||||
$status = $this->otDate->where('orden_trabajo_id', $orden_trabajo_id)
|
||||
->set($dateName, null)
|
||||
->update();
|
||||
if (isset($this->ordenTrabajoConfig->DATE_USER_MAPPING[$dateName])) {
|
||||
$this->otUser->where('orden_trabajo_id', $orden_trabajo_id)
|
||||
->set($this->ordenTrabajoConfig->DATE_USER_MAPPING[$dateName], auth()->user()->id)
|
||||
->update();
|
||||
}
|
||||
return $status;
|
||||
}
|
||||
public function updateOrdenTrabajoPedidoDate($data): array
|
||||
{
|
||||
$status = false;
|
||||
@ -970,6 +1016,25 @@ class ProductionService extends BaseService
|
||||
"status" => $status
|
||||
];
|
||||
}
|
||||
public function emptyOrdenTrabajoPedidoDate(string $dateName)
|
||||
{
|
||||
$status = false;
|
||||
$user = auth()->user();
|
||||
$row = [];
|
||||
$pedidoDatesUser = $this->ordenTrabajoConfig->DATE_USER_MAPPING_PEDIDO;
|
||||
if (isset($pedidoDatesUser[$dateName])) {
|
||||
$attrUserPedido = $pedidoDatesUser[$dateName];
|
||||
$row[$attrUserPedido] = $user->id;
|
||||
$row[$dateName] = null;
|
||||
$status = $this->pedidoModel->update($this->pedido->id, $row);
|
||||
$this->updateProgress();
|
||||
} else {
|
||||
throw new Exception(lang('Produccion.errors.attr_not_exist', [$dateName]));
|
||||
}
|
||||
|
||||
|
||||
return $status;
|
||||
}
|
||||
public function updateOrdenTrabajo($data): bool
|
||||
{
|
||||
if (isset($data["is_pedido_espera"])) {
|
||||
@ -1620,4 +1685,56 @@ class ProductionService extends BaseService
|
||||
{
|
||||
return $this->ot->getBarCodeFile();
|
||||
}
|
||||
|
||||
public function getMaquinaImpresionTareasList(int $maquina_id)
|
||||
{
|
||||
|
||||
$q = $this->otModel->builder()->select([
|
||||
"ordenes_trabajo.id as otId",
|
||||
"orden_trabajo_tareas.id as ot_tarea_id",
|
||||
"pedidos.fecha_impresion",
|
||||
"orden_trabajo_tareas.nombre as tareaName",
|
||||
"presupuestos.titulo as presupuesto_titulo",
|
||||
"orden_trabajo_tareas.maquina_id",
|
||||
"lg_papel_impresion.nombre as papel_impresion",
|
||||
"presupuesto_linea.gramaje as papel_gramaje",
|
||||
"tarea_progress.estado as tareaEstado"
|
||||
])
|
||||
->join("orden_trabajo_tareas", "orden_trabajo_tareas.orden_trabajo_id = ordenes_trabajo.id", "left")
|
||||
// Obtener el ultimo estado de la tarea
|
||||
->join(
|
||||
'(SELECT ot_tarea_id, estado
|
||||
FROM orden_trabajo_tarea_progress_dates
|
||||
WHERE (ot_tarea_id, created_at) IN (
|
||||
SELECT ot_tarea_id, MAX(created_at)
|
||||
FROM orden_trabajo_tarea_progress_dates
|
||||
GROUP BY ot_tarea_id
|
||||
)
|
||||
) as tarea_progress',
|
||||
'tarea_progress.ot_tarea_id = orden_trabajo_tareas.id',
|
||||
'left'
|
||||
)
|
||||
->join("presupuesto_linea", "presupuesto_linea.id = orden_trabajo_tareas.presupuesto_linea_id", "left")
|
||||
->join("presupuestos", "presupuestos.id = presupuesto_linea.presupuesto_id", "right")
|
||||
->join("pedidos", "pedidos.id = ordenes_trabajo.pedido_id", "right")
|
||||
->join("lg_papel_formato", "lg_papel_formato.id = presupuestos.papel_formato_id", "left")
|
||||
->join("lg_maquinas", "lg_maquinas.id = orden_trabajo_tareas.maquina_id", "left")
|
||||
->join("lg_papel_impresion", "lg_papel_impresion.id = presupuesto_linea.papel_impresion_id", "left")
|
||||
->groupStart()
|
||||
->orWhere('orden_trabajo_tareas.maquina_id', $maquina_id)
|
||||
->orWhere('presupuesto_linea.maquina_id', $maquina_id)
|
||||
->groupEnd()
|
||||
// ->where('pedidos.fecha_impresion IS NOT NULL', null, false)
|
||||
->where("orden_trabajo_tareas.deleted_at", null)
|
||||
->where("tarea_progress.estado", 'P')
|
||||
->orderBy("pedidos.fecha_impresion", "ASC")
|
||||
->groupBy('orden_trabajo_tareas.nombre');
|
||||
|
||||
return $q;
|
||||
}
|
||||
public function buttonActionDatatableTareaList($id)
|
||||
{
|
||||
$url = route_to("viewProduccionMaquinistaTareaView", $id);
|
||||
return "<a type='button' href='$url' class='maquina-btn btn btn-primary btn-md'><span class='ti ti-arrow-big-right'></span></a>";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user