added export and improved import
This commit is contained in:
@ -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');
|
||||
|
Reference in New Issue
Block a user