From 512632ce608111e53296046ea67ed9f4efc4c088 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 3 Oct 2017 12:50:18 -0700 Subject: [PATCH] Make the export button contextual for requested status --- app/Http/Controllers/ReportsController.php | 37 +++++++++++++++++++--- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/ReportsController.php b/app/Http/Controllers/ReportsController.php index 589307d2b3..c3740c8c43 100644 --- a/app/Http/Controllers/ReportsController.php +++ b/app/Http/Controllers/ReportsController.php @@ -15,6 +15,7 @@ use Illuminate\Support\Facades\View; use Input; use League\Csv\Reader; use Symfony\Component\HttpFoundation\StreamedResponse; +use Illuminate\Http\Request; /** * This controller handles all actions related to Reports for @@ -102,18 +103,45 @@ class ReportsController extends Controller * @since [v1.0] * @return \Illuminate\Http\Response */ - public function exportAssetReport() + public function exportAssetReport(Request $request) { \Debugbar::disable(); $customfields = CustomField::get(); - $response = new StreamedResponse(function () use ($customfields) { + $response = new StreamedResponse(function () use ($customfields, $request) { // Open output stream $handle = fopen('php://output', 'w'); - Asset::with('assignedTo', 'assetLoc','defaultLoc','assignedTo','model','supplier','assetstatus','model.manufacturer')->orderBy('created_at', 'DESC')->chunk(500, function($assets) use($handle, $customfields) { + $assets = Asset::with('assignedTo', 'assetLoc','defaultLoc','assignedTo','model','supplier','assetstatus','model.manufacturer'); + + // This is used by the sidenav, mostly + switch ($request->input('status')) { + case 'Deleted': + $assets->withTrashed()->Deleted(); + break; + case 'Pending': + $assets->Pending(); + break; + case 'RTD': + $assets->RTD(); + break; + case 'Undeployable': + $assets->Undeployable(); + break; + case 'Archived': + $assets->Archived(); + break; + case 'Requestable': + $assets->RequestableAssets(); + break; + case 'Deployed': + $assets->Deployed(); + break; + } + + $assets->orderBy('created_at', 'DESC')->chunk(500, function($assets) use($handle, $customfields) { $headers=[ trans('general.company'), trans('admin/hardware/table.asset_tag'), @@ -168,7 +196,8 @@ class ReportsController extends Controller fclose($handle); }, 200, [ 'Content-Type' => 'text/csv', - 'Content-Disposition' => 'attachment; filename="assets-'.date('Y-m-d-his').'.csv"', + 'Content-Disposition' + => 'attachment; filename="'.(($request->has('status')) ? trim($request->input('status')) : 'all').'-assets-'.date('Y-m-d-his').'.csv"', ]); return $response;