trabajando en la tabla de las lineas

This commit is contained in:
2025-05-03 18:27:52 +02:00
parent 71e70bf551
commit 3f90665c39
9 changed files with 682 additions and 8 deletions

View File

@ -32,4 +32,50 @@ class EtiquetasTitulosLineasModel extends Model
protected $validationRules = [];
protected $validationMessages = [];
protected $skipValidation = false;
protected $beforeDelete = ['addUserDeleted'];
protected function addUserDeleted(array $data)
{
$userId = auth()->user()->id;
if (!isset($data['data'])) {
$data['data'] = [];
}
if (!empty($data['id'])) {
$builder = $this->builder();
$builder->whereIn($this->primaryKey, (array) $data['id'])
->update(['user_deleted_at' => $userId]);
}
return $data;
}
public function getDatatableQuery($etiqueta_id, $direccion = null){
$direccionNormalizada = str_replace(' ', '', strtolower(trim($direccion)));
$direccionSQL = $this->db->escape($direccionNormalizada);
$builder = $this->db->table('etiquetas_titulos_lineas etl')
->select('etl.ot_id as ot, pr.titulo as titulo, etl.unidades as unidades, etl.numero_caja as numero_caja,
pd.cantidad as unidadesTotal, etl.id as id, etl.unidades as unidadesRaw,
(SELECT ROUND(SUM(peso)/1000, 2)
FROM presupuesto_linea
WHERE presupuesto_id = pr.id) AS pesoUnidad')
->join('etiquetas_titulos et', 'et.id = etl.etiqueta_titulos_id')
->join('ordenes_trabajo ot', 'ot.id = etl.ot_id')
->join('pedidos p', 'p.id = ot.pedido_id')
->join('pedidos_linea pl', 'pl.pedido_id = p.id')
->join('presupuestos pr', 'pr.id = pl.presupuesto_id')
->join('presupuesto_linea plinea', 'pr.id = plinea.presupuesto_id')
->join('presupuesto_direcciones pd', 'pd.presupuesto_id = pr.id')
->where('etl.deleted_at IS NULL')
->where('et.id', $etiqueta_id)
->where("REPLACE(LOWER(TRIM(pd.direccion)), ' ', '') = $direccionSQL", null, false)
->groupBy('etl.numero_caja');
return $builder;
}
}

View File

@ -32,4 +32,34 @@ class EtiquetasTitulosModel extends Model
protected $validationRules = [];
protected $validationMessages = [];
protected $skipValidation = false;
protected $beforeDelete = ['addUserDeleted'];
protected function addUserDeleted(array $data)
{
$userId = auth()->user()->id;
if (!isset($data['data'])) {
$data['data'] = [];
}
if (!empty($data['id'])) {
$builder = $this->builder();
$builder->whereIn($this->primaryKey, (array) $data['id'])
->update(['user_deleted_at' => $userId]);
}
return $data;
}
public function getEtiquetasTitulos()
{
return $this->db->table('etiquetas_titulos et')
->select('et.id, GROUP_CONCAT(DISTINCT etl.ot_id ORDER BY etl.ot_id ASC SEPARATOR ", ") as lista_ots')
->select('COUNT(DISTINCT etl.numero_caja) as cajas, et.att, et.direccion')
->join('etiquetas_titulos_lineas etl', 'etl.etiqueta_titulos_id = et.id')
->where('et.deleted_at IS NULL')
->where('etl.deleted_at IS NULL')
->groupBy('et.id, et.att, et.direccion');
}
}