예제 #1
0
 /**
  * @param $ids
  */
 public function exportPdf($ids = null)
 {
     $ids = explode(',', substr($ids, 0, -1));
     $ids = array_unique($ids);
     $model = Child::whereIn('id', $ids)->where('user_id', \Auth::user()->id)->get(['id', 'nom_enfant', 'created_at']);
     Excel::create('La liste des Elèves', function ($excel) use($model, $ids) {
         $excel->sheet('La liste des Elèves', function ($sheet) use($model, $ids) {
             foreach ($model as $child) {
                 $child->time = $child->created_at->toDateString();
                 $count = Bill::where('user_id', \Auth::user()->id)->where('child_id', $child->id)->where('status', 0)->count();
                 if ($count == 0) {
                     $child->status = 'Réglée';
                 } else {
                     $child->status = 'Non Réglée';
                 }
                 foreach ($child->classrooms as $cr) {
                     $child->classe = $cr->nom_classe;
                 }
                 unset($child->created_at);
                 unset($child->id);
             }
             // $sheet->setWidth('D',20);
             $sheet->fromModel($model);
             $sheet->setAllBorders('thin');
             $sheet->setFontFamily('OpenSans');
             $sheet->setFontSize(13);
             $sheet->setFontBold(false);
             for ($i = 1; $i <= count($ids) + 1; $i++) {
                 $sheet->setHeight($i, 25);
                 $sheet->row($i, function ($rows) {
                     $rows->setFontColor('#556b7b');
                     $rows->setAlignment('center');
                 });
                 $sheet->cells('A' . $i . ':' . 'D' . $i, function ($cells) {
                     $cells->setValignment('middle');
                     $cells->setFontColor('#556b7b');
                     $cells->setFont(array('family' => 'OpenSans', 'size' => '13', 'bold' => false));
                 });
             }
             // normal header
             $sheet->cells('A1:D1', function ($cells) {
                 $cells->setBackground('#e9f1f3');
                 $cells->setFontColor('#556b7b');
                 $cells->setFont(array('family' => 'OpenSans', 'size' => '15', 'bold' => true));
             });
             $sheet->row(1, array('Nom Elève', 'Date d\'inscription', 'Statut de Paiement', 'Classe'));
         });
     })->export('pdf');
 }