/home/dvjjulio/softtrash/app/VertederoOrden.php
<?php
namespace Trash;
use Illuminate\Database\Eloquent\Model;
use DB;
class VertederoOrden extends Model
{
//
protected $table = "vertedero_orden";
public $timestamps = false;
public function getVertederoOrden($year = null, $month = null, $type = 1) {
$where = "";
$typeOrder = "u.Nombre";
if($month != null && $month != "null"){
$where = " AND MONTH(o.fecha_inicio) = $month ";
}
if(($year == null && $year = "null") || $year == 0){
$year = date('Y');
}
if ($type == 2) {
$typeOrder = "c2.nombre_comercial";
}
$sql = "SELECT WEEK(o.fecha_inicio) semana, MONTH(o.fecha_inicio) mes, YEAR(o.fecha_inicio) year, o.fecha_inicio, u.nombre, c2.nombre_comercial, vo.*
FROM orden o
JOIN vertedero_orden vo ON vo.orden_id = o.id
JOIN camion c ON c.id = o.camion_id
JOIN user u ON u.id = c.user_id and u.status_id = 1
JOIN cliente c2 ON c2.id = o.cliente_id AND c2.status_id = 1
WHERE YEAR(o.fecha_inicio) = '$year' $where AND vo.status_id = 1
GROUP BY fecha_inicio, vo.orden_id
ORDER BY o.fecha_inicio, $typeOrder, vo.id";
$data = DB::select(DB::raw($sql));
if (count($data) != null){
return $data;
}
}
public function getVertederoOrdenYear($year = null) {
if(($year == null && $year = "null") || $year == 0){
$year = date('Y');
}
$sql = "SELECT MONTH(o.fecha_inicio) mes, SUM(vo.total) total, SUM(vo.peso_neto) peso_neto, COUNT(vo.nota) notas
FROM orden o
JOIN vertedero_orden vo ON vo.orden_id = o.id
JOIN cliente c2 ON c2.id = o.cliente_id AND c2.status_id = 1
WHERE YEAR(o.fecha_inicio) = '$year' AND vo.status_id = 1
GROUP BY MONTH(o.fecha_inicio)
ORDER BY MONTH(o.fecha_inicio)";
$data = DB::select(DB::raw($sql));
if (count($data) != null){
return $data;
}
}
}