92 lines
2.5 KiB
PHP
Executable file
92 lines
2.5 KiB
PHP
Executable file
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Customer;
|
|
use App\Repositories\CustomerRepository;
|
|
use Carbon;
|
|
use Request;
|
|
|
|
class CustomerController extends Controller
|
|
{
|
|
|
|
protected $custRepo;
|
|
|
|
public function __construct(CustomerRepository $custRepo)
|
|
{
|
|
$this->middleware(['admin', '2fa']);
|
|
$this->custRepo = $custRepo;
|
|
}
|
|
|
|
public function index($step = false)
|
|
{
|
|
$data = [
|
|
'step' => $step
|
|
];
|
|
return view('customer.index', $data);
|
|
}
|
|
|
|
public function detail($id)
|
|
{
|
|
if($id === "new") {
|
|
$customer = new Customer();
|
|
$id = 'new';
|
|
|
|
}else{
|
|
$customer = Customer::findOrFail($id);
|
|
$id = $customer->id;
|
|
}
|
|
$data = [
|
|
'customer' => $customer,
|
|
'id' => $id,
|
|
];
|
|
return view('customer.detail', $data);
|
|
|
|
}
|
|
|
|
public function store($id)
|
|
{
|
|
$data = Request::all();
|
|
if(!isset($data['action'])){
|
|
abort(403, 'keine Action');
|
|
}
|
|
//save
|
|
$customer = $this->custRepo->updateCustomer($id, $data);
|
|
\Session()->flash('alert-save', '1');
|
|
|
|
if($data['action'] === 'saveCustomer'){
|
|
return redirect(route('customer_detail', [$id]).'#collapseCustomerDetail');
|
|
}
|
|
return back();
|
|
}
|
|
|
|
public function delete($id){
|
|
/*
|
|
\Session()->flash('alert-success', __('Eintrag gelöscht'));
|
|
return redirect(route('lead_detail', [$lead->id]));*/
|
|
}
|
|
|
|
public function getCustomers()
|
|
{
|
|
$query = Customer::with('salutation')->select('customer.*');
|
|
|
|
return \DataTables::eloquent($query)
|
|
->addColumn('action_edit', function (Customer $customer) {
|
|
return '<a href="'.route('customer_detail', [$customer->id]).'" class="btn icon-btn btn-sm btn-primary"><span class="fa fa-edit"></span></a>';
|
|
})
|
|
->addColumn('id', function (Customer $customer) {
|
|
return '<a data-order="'.$customer->id.'" href="'.route('customer_detail', [$customer->id]).'" data-id="'.$customer->id.'">'.$customer->id.'</a>';
|
|
})
|
|
|
|
->orderColumn('id', 'id $1')
|
|
->filterColumn('id', function($query, $keyword) {
|
|
if($keyword != ""){
|
|
$query->where('id', 'LIKE', '%'.$keyword.'%');
|
|
}
|
|
})
|
|
->rawColumns(['action_edit', 'id'])
|
|
->make(true);
|
|
}
|
|
}
|
|
|
|
|