maquinista view-basic

This commit is contained in:
amazuecos
2025-04-25 07:40:20 +02:00
parent 288a3f02eb
commit 52b3b1ae4d
28 changed files with 911 additions and 132 deletions

View File

@ -404,12 +404,29 @@ class MaquinaModel extends \App\Models\BaseModel
->select([
'lg_maquinas.id as maquinaId',
'lg_maquinas.nombre',
'COUNT(orden_trabajo_tareas.id) as countTareas'
'COUNT(tarea_progress.ot_tarea_id) as countTareas'
])
->join('orden_trabajo_tareas','orden_trabajo_tareas.maquina_id = lg_maquinas.id','left')
->join('orden_trabajo_tareas', 'orden_trabajo_tareas.maquina_id = lg_maquinas.id', 'left')
->join(
"(SELECT ot_tarea_id, estado,deleted_at
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
WHERE estado = 'P'
GROUP BY ot_tarea_id
)
) as tarea_progress",
'tarea_progress.ot_tarea_id = orden_trabajo_tareas.id',
'left'
)
->join('ordenes_trabajo', 'ordenes_trabajo.id = orden_trabajo_tareas.orden_trabajo_id', 'left')
->join('pedidos', 'pedidos.id = ordenes_trabajo.pedido_id', 'left')
->where('lg_maquinas.tipo', $maquina_tipo)
->where('lg_maquinas.deleted_at',null)
->groupBy('lg_maquinas.id');
->where('lg_maquinas.deleted_at', null)
->where('tarea_progress.deleted_at', null)
->groupBy('lg_maquinas.id')
->orderBy('countTareas','DESC');
return $query;
}

View File

@ -103,8 +103,5 @@ class OrdenTrabajoModel extends Model
return $q;
}
public function updateMaquinas(OrdenTrabajoEntity $ot)
{
}
}

View File

@ -30,7 +30,9 @@ class OrdenTrabajoTarea extends Model
"tiempo_real",
"is_corte",
"tipo_corte",
"comment"
"comment",
"click_init",
"click_end"
];
protected bool $allowEmptyInserts = false;

View File

@ -0,0 +1,70 @@
<?php
namespace App\Models\OrdenTrabajo;
use App\Entities\Produccion\OrdenTrabajoTareaEntity;
use CodeIgniter\Database\MySQLi\Builder;
use CodeIgniter\Model;
class OrdenTrabajoTareaProgressDate extends Model
{
protected $table = 'orden_trabajo_tarea_progress_dates';
protected $primaryKey = 'id';
protected $useAutoIncrement = true;
protected $returnType = OrdenTrabajoTareaEntity::class;
protected $useSoftDeletes = true;
protected $protectFields = true;
protected $allowedFields = [
"ot_tarea_id",
"action_at",
"action_user_id",
"estado"
];
protected bool $allowEmptyInserts = false;
protected bool $updateOnlyChanged = true;
protected array $casts = [];
protected array $castHandlers = [];
// Dates
protected $useTimestamps = true;
protected $dateFormat = 'datetime';
protected $createdField = 'created_at';
protected $updatedField = 'updated_at';
protected $deletedField = 'deleted_at';
// Validation
protected $validationRules = [];
protected $validationMessages = [];
protected $skipValidation = false;
protected $cleanValidationRules = true;
// Callbacks
protected $allowCallbacks = true;
protected $beforeInsert = [];
protected $afterInsert = ['updateTiempoReal'];
protected $beforeUpdate = [];
protected $afterUpdate = [];
protected $beforeFind = [];
protected $afterFind = [];
protected $beforeDelete = [];
protected $afterDelete = [];
protected function updateTiempoReal(array $data)
{
if (!isset($data['data']['estado']) && !isset($data['data']['ot_tarea_id']) ) {
return $data;
}
$m = model(OrdenTrabajoTarea::class);
$ot_tarea = $m->find($data['data']['ot_tarea_id']);
if($ot_tarea){
$tiempo_real = $ot_tarea->tiempo_trabajado();
$m->update($data['data']['ot_tarea_id'],['tiempo_real' => $tiempo_real]);
}
return $data;
}
}