added export and improved import

This commit is contained in:
denisdulici
2018-06-11 03:47:32 +03:00
parent c274d38f13
commit 3d68496145
35 changed files with 347 additions and 115 deletions

View File

@ -133,14 +133,20 @@ class Payments extends Controller
*/
public function import(ImportFile $import)
{
$rows = $import->all();
// Loop through all sheets
$import->each(function ($sheet) {
if ($sheet->getTitle() != 'payments') {
return;
}
foreach ($rows as $row) {
$data = $row->toArray();
$data['company_id'] = session('company_id');
// Loop through all rows
$sheet->each(function ($row) {
$data = $row->toArray();
$data['company_id'] = session('company_id');
Payment::create($data);
}
Payment::create($data);
});
});
$message = trans('messages.success.imported', ['type' => trans_choice('general.payments', 2)]);
@ -231,4 +237,20 @@ class Payments extends Controller
return redirect('expenses/payments');
}
/**
* Export the specified resource.
*
* @return Response
*/
public function export()
{
\Excel::create('payments', function($excel) {
$excel->sheet('payments', function($sheet) {
$sheet->fromModel(Payment::filter(request()->input())->get()->makeHidden([
'id', 'company_id', 'parent_id', 'created_at', 'updated_at', 'deleted_at'
]));
});
})->download('xlsx');
}
}