/** * Export a Filtered Listing of the resource. * * See: ViewCreators/ExportTypeCreator for a list of the exportTypes we need to support. */ public function export($id) { if (Entrust::hasRole('teamLead') == False) { return redirect()->route('home'); } $request = (object) Request::all(); $filter = ['id' => $id]; //dd(__METHOD__.'('.__LINE__.')',compact('id','request','filter')); if ($request->ExportType == 'xls') { /* Merge a list Purchase Order Details with their Articles * * First we build an array of this POD Articles * fill out the calculated received / expected values * and lastly hand it to our xls formatter */ $podArticles = $this->articleRepository->getPODArticles($id, 0); $this->calculateReceivedExpected($podArticles); //dd(__METHOD__."(".__LINE__.")",compact('id','request','filter','podArticles')); // TODO file name should be calculated in a separate class $count = sprintf('%04d', $this->countersRepository->increment('exportFile')); $currentDate = Carbon::now()->format('YmdHis'); $fileName = 'POReconciliation-' . $currentDate . $count; //dd(__METHOD__."(".__LINE__.")",compact('id','request','filter','podArticles','fileName')); // create Excel workbook Excel::create($fileName, function ($excel) use($filter, $podArticles) { $excel->sheet('New sheet', function ($sheet) use($filter, $podArticles) { $sheet->loadView('pages.poReconciliation.excel')->with('filter', $filter)->with('podArticles', $podArticles); }); })->export('xls'); } if ($request->ExportType == 'csv') { /* Merge a list Purchase Order Details with their Articles * * First we build an array of this POD Articles * fill out the calculated received / expected values * and lastly hand it to our xls formatter */ $podArticles = $this->articleRepository->getPODArticles($id, 0); $this->calculateReceivedExpected($podArticles); //dd(__METHOD__."(".__LINE__.")",compact('id','request','filter','podArticles')); // TODO file name should be calculated in a separate class $count = sprintf('%04d', $this->countersRepository->increment('exportFile')); $currentDate = Carbon::now()->format('YmdHis'); $fileName = 'POReconciliation-' . $currentDate . $count; //dd(__METHOD__."(".__LINE__.")",compact('id','request','filter','podArticles','fileName')); // create Excel workbook Excel::create($fileName, function ($excel) use($filter, $podArticles) { $excel->sheet('New sheet', function ($sheet) use($filter, $podArticles) { $sheet->loadView('pages.poReconciliation.excel')->with('filter', $filter)->with('podArticles', $podArticles); }); })->export('csv'); } }