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