Skip to content

Instantly share code, notes, and snippets.

@matheusdavidson
Created December 31, 2014 00:25
Show Gist options
  • Save matheusdavidson/fe420c5c615e68e3c19d to your computer and use it in GitHub Desktop.
Save matheusdavidson/fe420c5c615e68e3c19d to your computer and use it in GitHub Desktop.
$query = DB::table('cal_calendar_table');
$query->select(DB::raw("
SUM(object = 'pro_assistances' AND is_first = 1 AND type = 'start') as total_atendimentos,
SUM(object = 'pro_clients' AND type = 'new') as total_clientes_novos,
SUM(object = 'pro_clients' AND type = 'edit') as total_clientes_edições,
SUM(object = 'pro_receipts' AND type = 'new') as total_notas,
SUM(object = 'pro_coupons' AND type = 'new') as total_cupons,
SUM(object = 'pro_exchange' AND type = 'made') as total_trocas
"));
$query->leftJoin('pro_activities', DB::raw('DATE(pro_activities.created_at)') , '=', 'cal_calendar_table.dt');
$query->whereRaw("(dt > ('$today' - INTERVAL 200 DAY)) AND (dt <= ('$today' + INTERVAL 1 DAY))");
$query->groupBy('dt');
$model['activities'] = $query->get();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment