191 lines
6.9 KiB
PHP
Executable file
191 lines
6.9 KiB
PHP
Executable file
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Customer;
|
|
use App\Models\CustomerFile;
|
|
use App\Models\CustomerMail;
|
|
use App\Repositories\CustomerMailRepository;
|
|
use App\Repositories\FileRepository;
|
|
use Carbon;
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
use Illuminate\Support\Facades\URL;
|
|
use Request;
|
|
use Response;
|
|
|
|
class CustomerMailController extends Controller
|
|
{
|
|
|
|
protected $customerMailRepo;
|
|
|
|
public function __construct(CustomerMailRepository $customerMailRepo)
|
|
{
|
|
$this->middleware('admin');
|
|
$this->customerMailRepo = $customerMailRepo;
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
$data = [
|
|
|
|
];
|
|
return view('customer.mail.index', $data);
|
|
}
|
|
|
|
public function detail($id)
|
|
{
|
|
if($id === "new") {
|
|
$customer_mail = new CustomerMail();
|
|
$id = 'new';
|
|
|
|
}else{
|
|
$customer_mail = CustomerMail::findOrFail($id);
|
|
$id = $customer_mail->id;
|
|
}
|
|
|
|
|
|
$data = [
|
|
'customer_mail' => $customer_mail,
|
|
'id' => $id,
|
|
'back' => URL::previous(),
|
|
];
|
|
return view('customer.mail.detail', $data);
|
|
|
|
}
|
|
|
|
public function store($id)
|
|
{
|
|
return back();
|
|
/* $data = Request::all();
|
|
|
|
\Session()->flash('alert-save', '1');
|
|
return redirect(route('lead_detail', [$lead->id]));*/
|
|
|
|
}
|
|
|
|
public function delete($id){
|
|
/*
|
|
\Session()->flash('alert-success', __('Eintrag gelöscht'));
|
|
return redirect(route('lead_detail', [$lead->id]));*/
|
|
}
|
|
|
|
|
|
/* public function loadModal(){
|
|
$data = Request::all();
|
|
$ret = "";
|
|
if(Request::ajax()){
|
|
|
|
$customers = [];
|
|
$query = $this->getSearchRequests();
|
|
$bookings = $query->orderBy('id', 'DESC')->limit(50)->get();
|
|
foreach ($bookings as $booking){
|
|
$tmp = "";
|
|
$tmp .= $booking->customer ? $booking->customer->email." | " : "- | ";
|
|
$tmp .= $booking->customer ? $booking->customer->firstname." ".$booking->customer->name." | " : "- | ";
|
|
$tmp .= $booking->travel_country_id ? $booking->travel_country->name." | " : "- | ";
|
|
$tmp .= $booking->travelagenda_id ? $booking->travel_agenda->name."" : "-";
|
|
|
|
$customers[$booking->id] = $tmp;
|
|
}
|
|
|
|
// return TravelAgenda::whereIn('id', $ret)->get()->pluck('name', 'id');
|
|
|
|
if($data['action'] === "send-customer-mail"){
|
|
$value = new Collection();
|
|
$value->id = "add";
|
|
$value->customers = $customers;
|
|
$value->message = "Sehr #geehrte/r# #Anrede# #Vorname# #Nachname#,\n\nText ....";
|
|
$data['title'] = "E-Mail-Nachricht an Auswahl";
|
|
$url = route('requests_send_customer_mail');
|
|
$ret = view("customer.mail.modal-mail", compact('data','value', 'url') )->render();
|
|
}
|
|
|
|
}
|
|
return response()->json(['response' => $data, 'html'=>$ret]);
|
|
}*/
|
|
|
|
|
|
public function sendMail(CustomerMailRepository $customerMailRepository){
|
|
$data = Request::all();
|
|
$customerMailRepository->sendAndStore($data);
|
|
\Session()->flash('alert-success', "Mails gesendet!");
|
|
return back();
|
|
}
|
|
|
|
public function replyMail(CustomerMailRepository $customerMailRepository){
|
|
$data = Request::all();
|
|
$customerMailRepository->replyStore($data);
|
|
\Session()->flash('alert-success', "Mail gespeichert!");
|
|
return back();
|
|
}
|
|
|
|
public function getCustomerMails()
|
|
{
|
|
$query = CustomerMail::with('booking')->with('customer');
|
|
|
|
return \DataTables::eloquent($query)
|
|
->addColumn('action_edit', function (CustomerMail $customer_mail) {
|
|
return '<a href="'.route('customer_mail_detail', [$customer_mail->id]).'" class="btn icon-btn btn-sm btn-primary"><span class="fa fa-edit"></span></a>';
|
|
})
|
|
->addColumn('id', function (CustomerMail $customer_mail) {
|
|
return '<a data-order="'.$customer_mail->id.'" href="'.route('customer_mail_detail', [$customer_mail->id]).'" data-id="'.$customer_mail->id.'">'.$customer_mail->id.'</a>';
|
|
})
|
|
->addColumn('booking', function (CustomerMail $customer_mail) {
|
|
$out = $customer_mail->booking->travel_country_id ? $customer_mail->booking->travel_country->name." | " : "- | ";
|
|
$out .= $customer_mail->booking->travelagenda_id ? $customer_mail->booking->travel_agenda->name."" : "-";
|
|
return $out;
|
|
})
|
|
->addColumn('booking_id', function (CustomerMail $customer_mail) {
|
|
return '<a data-order="'.$customer_mail->booking_id.'" href="'.route('booking_detail', [$customer_mail->booking_id]).'">'.$customer_mail->booking_id.'</a>';
|
|
})
|
|
->addColumn('customer_id', function (CustomerMail $customer_mail) {
|
|
return '<a data-order="'.$customer_mail->customer_id.'" href="'.route('customer_detail', [$customer_mail->customer_id]).'">'.$customer_mail->customer_id.'</a>';
|
|
})
|
|
->addColumn('send', function (CustomerMail $customer_mail) {
|
|
return $customer_mail->send ? '<span class="badge badge-pill badge-success"><i class="fa fa-check"></i></span>' : '<span class="badge badge-pill badge-danger"><i class="fa fa-times"></i></span>';
|
|
})
|
|
->orderColumn('id', 'id $1')
|
|
->orderColumn('booking_id', 'booking_id $1')
|
|
->orderColumn('customer_id', 'customer_id $1')
|
|
->orderColumn('send', 'send $1')
|
|
|
|
->filterColumn('id', function($query, $keyword) {
|
|
if($keyword != ""){
|
|
$query->where('id', 'LIKE', '%'.$keyword.'%');
|
|
}
|
|
})
|
|
->filterColumn('customer_id', function($query, $keyword) {
|
|
if($keyword != ""){
|
|
$query->where('customer_id', 'LIKE', '%'.$keyword.'%');
|
|
}
|
|
})
|
|
->filterColumn('booking_id', function($query, $keyword) {
|
|
if($keyword != ""){
|
|
$query->where('booking_id', 'LIKE', '%'.$keyword.'%');
|
|
}
|
|
})
|
|
->rawColumns(['action_edit', 'send', 'customer_id', 'booking_id', 'id'])
|
|
->make(true);
|
|
}
|
|
|
|
|
|
public function uploadAttachment($id){
|
|
|
|
$fileRepo = new FileRepository(new CustomerFile());
|
|
if($id === 'tmp'){
|
|
$fileRepo->_set('disk', 'customer');
|
|
$fileRepo->_set('dir', '/attachment/'.date('Y/m').'/');
|
|
$fileRepo->_set('customer_id', NULL);
|
|
$fileRepo->_set('customer_mail_id', NULL);
|
|
$fileRepo->_set('identifier', 'tmp');
|
|
return $fileRepo->uploadFile(Request::all());
|
|
}
|
|
|
|
return Response::json([
|
|
'error' => true,
|
|
'code' => 200
|
|
], 200);
|
|
}
|
|
}
|
|
|
|
|