Example #1
0
 public function exportExcel()
 {
     $date = request()->input('date');
     $arrayDate = str_split($date, 8);
     $startDate = $this->order->stringToDate($arrayDate[0]);
     $endDate = $this->order->stringToDate($arrayDate[1]);
     $orderRepo = new OrderRepository(new Order());
     if (request()->has('id')) {
         $unitId = request()->input('id');
         $monitor = $this->order->statisticsUnit($startDate, $endDate, $unitId, 'monitor');
         $orther = $this->order->statisticsUnit($startDate, $endDate, $unitId);
         $data = $monitor->merge($orther);
         $data = $data->groupBy('purpose.symbol');
         $view = 'statistics.output_unit';
     } else {
         $data = $orderRepo->statistics($startDate, $endDate);
         $view = 'statistics.output';
     }
     Excel::create($date, function ($excel) use($view, $data) {
         // var_dump($data);
         // Call them separately
         $excel->setDescription('File created by TNT');
         // Set top, right, bottom, left
         $excel->sheet('tnt', function ($sheet) use($view, $data) {
             $sheet->setPageMargin(array(0.25, 0, 0, 0.5));
             $sheet->setOrientation('landscape');
             // Font family
             $sheet->setFontFamily('Times New Roman');
             // Font size
             $sheet->setFontSize(14);
             $sheet->loadView($view, ['result' => $data]);
         });
     })->export('xlsx');
 }