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

@ -171,19 +171,25 @@ class Vendors extends Controller
*/
public function import(ImportFile $import)
{
$rows = $import->all();
foreach ($rows as $row) {
$data = $row->toArray();
if (empty($data['email'])) {
$data['email'] = '';
// Loop through all sheets
$import->each(function ($sheet) {
if ($sheet->getTitle() != 'vendors') {
return;
}
$data['company_id'] = session('company_id');
// Loop through all rows
$sheet->each(function ($row) {
$data = $row->toArray();
Vendor::create($data);
}
if (empty($data['email'])) {
$data['email'] = '';
}
$data['company_id'] = session('company_id');
Vendor::create($data);
});
});
$message = trans('messages.success.imported', ['type' => trans_choice('general.vendors', 2)]);
@ -265,6 +271,22 @@ class Vendors extends Controller
return redirect('expenses/vendors');
}
/**
* Export the specified resource.
*
* @return Response
*/
public function export()
{
\Excel::create('vendors', function($excel) {
$excel->sheet('vendors', function($sheet) {
$sheet->fromModel(Vendor::filter(request()->input())->get()->makeHidden([
'id', 'company_id', 'created_at', 'updated_at', 'deleted_at'
]));
});
})->download('xlsx');
}
public function currency()
{
$vendor_id = request('vendor_id');