Merge branch '249-add-export-to-csv-button-for-popapp-report' into 'master'
Resolve "Add export to csv button for popapp report" Closes #249 See merge request jankstudio/resq!294
This commit is contained in:
commit
4d0c0345fb
3 changed files with 54 additions and 10 deletions
|
|
@ -33,7 +33,7 @@ rep_popapp_comp_form:
|
|||
controller: App\Controller\ReportController::popappComparisonForm
|
||||
methods: [GET]
|
||||
|
||||
rep_popapp_comp_submit:
|
||||
path: /report/popapp_comparison
|
||||
controller: App\Controller\ReportController::popappComparisonSubmit
|
||||
rep_popapp_export_csv:
|
||||
path: /report/popapp_export
|
||||
controller: App\Controller\ReportController::popappExportCSV
|
||||
methods: [POST]
|
||||
|
|
|
|||
|
|
@ -420,7 +420,7 @@ class ReportController extends Controller
|
|||
/**
|
||||
* @Menu(selected="outlet_list")
|
||||
*/
|
||||
public function popappComparisonSubmit(Request $req)
|
||||
/* public function popappComparisonSubmit(Request $req)
|
||||
{
|
||||
// retrieve temporary info for file
|
||||
$file = $req->files->get('csv_file');
|
||||
|
|
@ -437,6 +437,49 @@ class ReportController extends Controller
|
|||
$params['data'] = $data;
|
||||
|
||||
return $this->render('report/popapp/form.html.twig', $params);
|
||||
} */
|
||||
|
||||
/**
|
||||
* @Menu(selected="outlet_list")
|
||||
*/
|
||||
public function popappExportCSV(Request $req)
|
||||
{
|
||||
// retrieve temporary info for file
|
||||
$file = $req->files->get('csv_file');
|
||||
|
||||
// process the csv file
|
||||
$data = $this->processPopappFile($file);
|
||||
|
||||
$resp = new StreamedResponse();
|
||||
$resp->setCallback(function() use ($data) {
|
||||
// csv output
|
||||
$csv_handle = fopen('php://output', 'w+');
|
||||
fputcsv($csv_handle, [
|
||||
'Customer ID',
|
||||
'Last Name',
|
||||
'First Name',
|
||||
'Plate Number',
|
||||
'Serial',
|
||||
'Warranty Create Date',
|
||||
'Activation Status',
|
||||
'Has Mobile App?',
|
||||
]);
|
||||
foreach ($data as $row)
|
||||
{
|
||||
fputcsv($csv_handle, $row);
|
||||
}
|
||||
|
||||
fclose($csv_handle);
|
||||
});
|
||||
|
||||
$filename = 'popapp_comparison_report' . '.csv';
|
||||
|
||||
$resp->setStatusCode(200);
|
||||
$resp->headers->set('Content-Type', 'text/csv; charset=utf-8');
|
||||
$resp->headers->set('Content-Disposition', 'attachment; filename="' . $filename . '"');
|
||||
|
||||
return $resp;
|
||||
|
||||
}
|
||||
|
||||
protected function processPopappFile(UploadedFile $csv_file)
|
||||
|
|
@ -507,8 +550,8 @@ class ReportController extends Controller
|
|||
'plate_num' => $cv->getPlateNumber(),
|
||||
'serial' => $warranty->getSerial(),
|
||||
'warr_date_create' => $warranty->getDateCreate()->format("d M Y"),
|
||||
'has_mobile' => $has_mobile,
|
||||
'warr_activation_status' => $warranty->isActivated(),
|
||||
'warr_activation_status' => ($warranty->isActivated() ? 'Active' : 'Inactive'),
|
||||
'has_mobile' => ($has_mobile ? 'Yes' : 'No'),
|
||||
];
|
||||
|
||||
}
|
||||
|
|
@ -517,4 +560,5 @@ class ReportController extends Controller
|
|||
|
||||
return $results;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<form id="upload_form" class="m-form m-form--fit m-form--label-align-right m-form--group-seperator-dashed" method="post" action="{{ url('rep_popapp_comp_submit') }}" enctype="multipart/form-data">
|
||||
<form id="upload_form" class="m-form m-form--fit m-form--label-align-right m-form--group-seperator-dashed" method="post" action="{{ url('rep_popapp_export_csv') }}" enctype="multipart/form-data">
|
||||
<div class="m-portlet__body">
|
||||
<div class="form-group m-form__group row">
|
||||
<input type="file" id="csv_file" name="csv_file" >
|
||||
|
|
@ -38,7 +38,7 @@
|
|||
<div class="m-form__actions m-form__actions--solid m-form__actions--right">
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
<button type="submit" class="btn btn-success">Submit</button>
|
||||
<button type="submit" class="btn btn-success">Export to CSV</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -96,8 +96,8 @@
|
|||
<td>{{ result.plate_num|default('') }}</td>
|
||||
<td>{{ result.serial|default('') }}</td>
|
||||
<td>{{ result.warr_date_create|default('') }}</td>
|
||||
<td>{{ result.warr_activation_status ? 'Active' : 'Inactive' }}</td>
|
||||
<td>{{ result.has_mobile ? 'Yes' : 'No' }} </td>
|
||||
<td>{{ result.warr_activation_status }}</td>
|
||||
<td>{{ result.has_mobile }} </td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
|
|
|
|||
Loading…
Reference in a new issue