totalizadores implementados

This commit is contained in:
2024-08-05 21:25:16 +02:00
parent 4255b74f33
commit 8ea0ab13c0
6 changed files with 234 additions and 84 deletions

View File

@ -93,6 +93,94 @@ class PedidoLineaModel extends \App\Models\BaseModel
}
}
public function getSumOfTirada(array $search, $estado = '', $start = 0, $length = 5)
{
$builder = $this->db
->table($this->table . " t1")
->selectSum('t3.tirada', 'total_tirada');
$builder->join("pedidos t2", "t2.id = t1.pedido_id", "left");
$builder->join("presupuestos t3", "t1.presupuesto_id = t3.id", "left");
// Aplica los filtros de búsqueda y estado
if (!empty($search)) {
$builder->groupStart();
foreach ($search as $col_search) {
if ($col_search[0] != 1 && $col_search[0] != 2)
$builder->like(self::SORTABLE[$col_search[0]], $col_search[2]);
else {
$dates = explode(" ", $col_search[2]);
$builder->where(self::SORTABLE[$col_search[0]] . ">=", $dates[0]);
$builder->where(self::SORTABLE[$col_search[0]] . "<=", $dates[1]);
}
}
$builder->groupEnd();
}
if ($estado !== '') {
$builder->where('estado', $estado);
}
// Aplicar el orden y el límite
$builder->limit($length, $start);
return $builder->get()->getRow()->total_tirada;
}
public function getSumOfTotalAceptado(array $search, $estado = '', $start = 0, $length = 5)
{
$builder = $this->db
->table($this->table . " t1")
->selectSum('t3.total_aceptado', 'total');
$builder->join("pedidos t2", "t2.id = t1.pedido_id", "left");
$builder->join("presupuestos t3", "t1.presupuesto_id = t3.id", "left");
// Aplica los filtros de búsqueda y estado
if (!empty($search)) {
$builder->groupStart();
foreach ($search as $col_search) {
if ($col_search[0] != 1 && $col_search[0] != 2)
$builder->like(self::SORTABLE[$col_search[0]], $col_search[2]);
else {
$dates = explode(" ", $col_search[2]);
$builder->where(self::SORTABLE[$col_search[0]] . ">=", $dates[0]);
$builder->where(self::SORTABLE[$col_search[0]] . "<=", $dates[1]);
}
}
$builder->groupEnd();
}
if ($estado !== '') {
$builder->where('estado', $estado);
}
// Aplicar el orden y el límite
$builder
->limit($length, $start);
return $builder->get()->getRow()->total;
}
public function getTotalOfTotalAceptado()
{
$builder = $this->db
->table($this->table . " t1")
->selectSum('t3.total_aceptado', 'total');
$builder->join("pedidos t2", "t2.id = t1.pedido_id", "left");
$builder->join("presupuestos t3", "t1.presupuesto_id = t3.id", "left");
return $builder->get()->getRow()->total;
}
public function obtenerLineasPedidoSinFacturar($cliente_id) {
$resultaArray = [];