app/Http/Controllers/ReportEnterpriseController.php
/**
	 * Export income data to a CSV file.
	 *
	 * @return Response
	 */
Export income data to a CSV file.
@return Response
Export income data to a CSV file . @return Response
public function exportIncomeData($start, $end)
	{
		$thanksByIncomeLevels = User::select('income', \DB::raw("count(users.income) as thanks"))->whereBetween('thanksDateTime', array(new Carbon($start), new Carbon($end)))->join('enterprise_thanks', 'enterprise_thanks.user_id', '=', 'users.id')->groupBy('users.income')->get();
        $filename = 'agradecimentos-por-renda.csv';
        $handle = fopen($filename, 'w+');
        fputcsv($handle, array('Renda', 'Número de agradecimentos'));
        foreach($thanksByIncomeLevels as $thanksByIncomeLevel) {
        	if ($thanksByIncomeLevel['income'] == '' || $thanksByIncomeLevel['income'] == null) {
        		$thanksByIncomeLevel['income'] = "Não informado";
        	}
        	fputcsv($handle, array($thanksByIncomeLevel['income'], $thanksByIncomeLevel['thanks']));
        }
        fclose($handle);
        $headers = array(
            'Content-Type' => 'text/csv',
        );
        return Response::download($filename, 'agradecimentos-por-renda.csv', $headers);
	}
public function exportIncomeData ( $ start , $ end ) { $ thanksByIncomeLevels = User :: select ( 'income' , \ DB :: raw ( " count(users.income) as thanks " ) ) -> whereBetween ( 'thanksDateTime' , array ( new Carbon ( $ start ) , new Carbon ( $ end ) ) ) -> join ( 'enterprise_thanks' , 'enterprise_thanks.user_id' , '=' , 'users.id' ) -> groupBy ( 'users.income' ) -> get ( ) ; $ filename = 'agradecimentos-por-renda.csv' ; $ handle = fopen ( $ filename , 'w+' ) ; fputcsv ( $ handle , array ( 'Renda' , 'Número de agradecimentos') ) ; foreach ( $ thanksByIncomeLevels as $ thanksByIncomeLevel ) { if ( $ thanksByIncomeLevel [ 'income' ] == '' || $ thanksByIncomeLevel [ 'income' ] == null ) { $ thanksByIncomeLevel [ 'income' ] = " Não informado" ; } fputcsv ( $ handle , array ( $ thanksByIncomeLevel [ 'income' ] , $ thanksByIncomeLevel [ 'thanks' ] ) ) ; } fclose ( $ handle ) ; $ headers = array ( 'Content-Type' => 'text/csv' , ) ; return Response :: download ( $ filename , 'agradecimentos-por-renda.csv' , $ headers ) ; }
Export income data to a CSV file.
Export income data to a CSV file .