コード例 #1
0
 /**
  * Display a listing of conversas
  *
  * @return Response
  */
 public function index()
 {
     $conversas = Conversa::orderBy('id', 'DESC')->get();
     $ontem = mktime(0, 0, 0, date("m"), date("d") - 1, date("Y"));
     $anteontem = mktime(0, 0, 0, date("m"), date("d") - 2, date("Y"));
     $conversas->hoje = Conversa::where('data', '=', date('Y-m-d'))->get();
     $conversas->ontem = Conversa::where('data', '=', date('Y-m-d', $ontem))->get();
     $conversas->anteontem = Conversa::where('data', '=', date('Y-m-d', $anteontem))->get();
     $conversas->anteriores = Conversa::where('data', '<', date('Y-m-d', $anteontem))->get();
     // $conversas_hoje = Conversa::where(function ($query)use($hoje) {
     //                                               $query->where('created_at', '=', $hoje)
     //                                                     ->orWhere('b', '=', 1);
     //                                           })->where(function ($query) {
     //                                               $query->where('c', '=', 1)
     //                                                     ->orWhere('d', '=', 1);
     //                                           });
     //if( Request::ajax() ){
     //return $conversas;
     //}else{
     return View::make('conversas.index', compact('conversas'));
     //}
 }
コード例 #2
0
 /**
  * Show the form for creating a new resource.
  * GET /relatorios/create
  *
  * @return Response
  */
 public function create($resource_name = NULL)
 {
     // STATUS
     $status = $this->status($resource_name);
     // OLD INPUTS
     Input::flash();
     // TIPO DE RELATÓRIO
     switch ($resource_name) {
         /*
         	DESPESAS
         */
         case 'despesas':
             /*
             	FILTROS DE BUSCA
             */
             // GET Filters
             if (@$_GET['cidade'] || @$_GET['status'] || @$_GET['from'] || @$_GET['to']) {
                 // Se for pesquisa, carrega todas despesas e depois filtra
                 $despesas = Despesa::all();
                 // CIDADE
                 $despesas = $despesas->filter(function ($despesa) {
                     if (!isset($_GET['cidade']) || @$_GET['cidade'] == "all" || @$_GET['cidade'] == $despesa->cidade) {
                         return $despesa;
                     }
                 });
                 // STATUS
                 $despesas = $despesas->filter(function ($despesa) {
                     if (@$_GET['status'] == 'enviadas') {
                         if ($despesa->relatorio_id >= 1) {
                             return $despesa;
                         }
                     } else {
                         if (@$_GET['status'] == 'nao-enviadas') {
                             if ($despesa->relatorio_id < 1) {
                                 return $despesa;
                             }
                         } else {
                             return $despesa;
                         }
                     }
                 });
                 // DATA (DE)
                 $despesas = $despesas->filter(function ($despesa) {
                     if (isset($_GET['from'])) {
                         if ($despesa->created_at >= $_GET['from'] . ' 00:00:00') {
                             return $despesa;
                         }
                     }
                 });
                 // DATA (ATÉ)
                 $despesas = $despesas->filter(function ($despesa) {
                     if (isset($_GET['to'])) {
                         if ($despesa->created_at <= $_GET['to'] . ' 23:59:59') {
                             return $despesa;
                         }
                     }
                 });
             } else {
                 // Senão, carrega só as "NÃO ENVIADAS"
                 $despesas = Despesa::where('relatorio_id', '<', 1)->get();
             }
             // Total de despesas
             $despesas->total = 0;
             foreach ($despesas as $despesa) {
                 $despesas->total += $despesa->valor;
                 // Fomata R$ despesas
                 $despesa->valor = number_format($despesa->valor, 2, ',', '.');
             }
             // Fomata R$ Total
             $despesas->total = number_format($despesas->total, 2, ',', '.');
             return View::make('relatorios.despesas.create', array('despesas' => $despesas));
             break;
             /*
             	CONVERSAS
             */
         /*
         	CONVERSAS
         */
         case 'conversas':
             /* 
             	FILTROS DE BUSCA
             */
             // CLIENTES (que tem conversas)
             $clientes = Cliente::has('conversas', '>', 0)->with('conversas')->get();
             if (!Conversa::count()) {
                 // Alert
                 $alert[] = array('class' => 'alert-warning', 'message' => '<strong><i class="fa fa-warning"></i></strong> Ainda não há nenhuma conversa cadastrada no sistema =(');
                 Session::flash('alerts', $alert);
                 return Redirect::to(URL::previous());
             }
             $fieldClientes = array('all' => 'Todos');
             foreach ($clientes as $cliente) {
                 $fieldClientes[$cliente->id] = $cliente->nome;
             }
             // DATE RANGE
             $fieldDate['min'] = Conversa::orderBy('created_at', 'ASC')->select('created_at')->first();
             $fieldDate['min'] = date('Y-m-d', strtotime($fieldDate['min']->created_at));
             $fieldDate['max'] = Conversa::orderBy('created_at', 'DESC')->select('created_at')->first();
             $fieldDate['max'] = date('Y-m-d', strtotime($fieldDate['max']->created_at));
             // FILTERS
             $filters = array('clientes' => $fieldClientes, 'status' => array('all' => 'Todas', 'enviadas' => 'Enviadas', 'nao-enviadas' => 'Não enviadas'), 'from' => array('min' => $fieldDate['min'], 'max' => $fieldDate['max']), 'to' => array('min' => $fieldDate['min'], 'max' => $fieldDate['max']));
             /*
             	FILTROS DE BUSCA
             */
             // GET Filters
             if (@$_GET['cliente'] || @$_GET['status'] || @$_GET['from'] || @$_GET['to']) {
                 // Se for pesquisa, carrega todas conversas e depois filtra
                 $conversas = Conversa::all();
                 // CLIENTE
                 $conversas = $conversas->filter(function ($conversa) {
                     if (!isset($_GET['cliente']) || @$_GET['cliente'] == "all" || @$_GET['cliente'] == $conversa->cliente_id) {
                         return $conversa;
                     }
                 });
                 // STATUS
                 $conversas = $conversas->filter(function ($conversa) {
                     if (@$_GET['status'] == 'enviadas') {
                         if ($conversa->relatorio_id >= 1) {
                             return $conversa;
                         }
                     } else {
                         if (@$_GET['status'] == 'nao-enviadas') {
                             if ($conversa->relatorio_id < 1) {
                                 return $conversa;
                             }
                         } else {
                             return $conversa;
                         }
                     }
                 });
                 // DATA (DE)
                 $conversas = $conversas->filter(function ($conversa) {
                     if (isset($_GET['from'])) {
                         if ($conversa->created_at >= $_GET['from'] . ' 00:00:00') {
                             return $conversa;
                         }
                     }
                 });
                 // DATA (ATÉ)
                 $conversas = $conversas->filter(function ($conversa) {
                     if (isset($_GET['to'])) {
                         if ($conversa->created_at <= $_GET['to'] . ' 23:59:59') {
                             return $conversa;
                         }
                     }
                 });
             } else {
                 // Senão, carrega só as "NÃO ENVIADAS"
                 $conversas = Conversa::where('relatorio_id', '<', 1)->get();
             }
             // Total de conversas encontradas
             $total = count($conversas);
             //Agrupa por cliente
             $groups = $conversas->groupBy('cliente_id');
             $clientes_conversas = array();
             foreach ($groups as $cliente_id => $conversas) {
                 $client = Cliente::find($cliente_id);
                 if (count($client)) {
                     $client->conversas = $conversas;
                     $clientes_conversas[] = $client;
                 }
             }
             $search_results = $clientes_conversas;
             // echo "<pre>";
             // print_r( $search_results );
             // echo "</pre>";
             // exit;
             // Message Text
             if (@$_GET['status']) {
                 if ($total == 1) {
                     $message = "Uma conversa encontrada";
                 } else {
                     if ($total > 1) {
                         $message = $total . " conversas encontradas";
                     } else {
                         $message = "Nenhuma conversa encontrada";
                     }
                 }
             } else {
                 $message = "Você tem " . $status['nao_enviadas'] . " conversas não enviadas.";
             }
             return View::make('relatorios.conversas.create', array('status' => $status, 'filters' => $filters, 'search_results' => $search_results, 'message' => $message, 'conversas' => $conversas, 'relatorio' => new Relatorio(), 'clientes' => $clientes));
             break;
         default:
             //  se não informado um RESOURCE_NAME, a view CREATE padrão é chamada
             return View::make('relatorios.create');
             break;
     }
 }