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

@ -191,19 +191,25 @@ class Customers 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() != 'customers') {
return;
}
$data['company_id'] = session('company_id');
// Loop through all rows
$sheet->each(function ($row) {
$data = $row->toArray();
Customer::create($data);
}
if (empty($data['email'])) {
$data['email'] = '';
}
$data['company_id'] = session('company_id');
Customer::create($data);
});
});
$message = trans('messages.success.imported', ['type' => trans_choice('general.customers', 2)]);
@ -301,6 +307,22 @@ class Customers extends Controller
return redirect('incomes/customers');
}
/**
* Export the specified resource.
*
* @return Response
*/
public function export()
{
\Excel::create('customers', function($excel) {
$excel->sheet('customers', function($sheet) {
$sheet->fromModel(Customer::filter(request()->input())->get()->makeHidden([
'id', 'company_id', 'created_at', 'updated_at', 'deleted_at'
]));
});
})->download('xlsx');
}
public function currency()
{
$customer_id = request('customer_id');