Mails etc. in Lead finish

This commit is contained in:
Kevin Adametz 2021-05-11 17:07:20 +02:00
parent 66ca252bfa
commit b362b93bca
45 changed files with 1460 additions and 418 deletions

View file

@ -5,14 +5,14 @@ namespace App\Http\Controllers;
use Carbon;
use Request;
use Response;
use App\Models\Lead;
use App\Services\Util;
use App\Models\LeadFile;
use App\Models\LeadMail;
use App\Models\EmailTemplate;
use App\Models\CustomerFewoFile;
use App\Models\CustomerFewoMail;
use Illuminate\Support\Facades\URL;
use App\Models\TravelUserBookingFewo;
use App\Models\TravelUserBookingFile;
use App\Repositories\LeadFileRepository;
use App\Repositories\LeadMailRepository;
use Illuminate\Database\Eloquent\Collection;
@ -23,15 +23,15 @@ use App\Repositories\CustomerFewoMailRepository;
class LeadMailController extends Controller
{
protected $customerMailRepo;
protected $leadMailRepo;
public function __construct(LeadMailRepository $customerMailRepo)
public function __construct(LeadMailRepository $leadMailRepo)
{
$this->middleware('admin');
$this->customerMailRepo = $customerMailRepo;
$this->leadMailRepo = $leadMailRepo;
}
/* public function index()
/*public function index()
{
$data = [
@ -42,48 +42,59 @@ class LeadMailController extends Controller
public function detail($id)
{
if($id === "new") {
$customer_mail = new CustomerFewoMail();
$lead_mail = new LeadMail();
$id = 'new';
}else{
$customer_mail = CustomerFewoMail::findOrFail($id);
$id = $customer_mail->id;
$lead_mail = LeadMail::findOrFail($id);
$id = $lead_mail->id;
}
$data = [
'customer_mail' => $customer_mail,
'lead_mail' => $lead_mail,
'id' => $id,
'back' => URL::previous(),
];
return view('customer.mail.detail', $data);
}
}*/
public function store($id, $action=false)
{
$data = Request::all();
$customer_mail = CustomerFewoMail::findOrFail($id);
$lead_mail = LeadMail::findOrFail($id);
if($action === 'move-mail'){
if($action === 'move-mail-lead'){
$lead_mail = LeadMail::findOrFail($id);
$data['subdir'] = isset($data['subdir']) && $data['subdir'] ? $data['subdir'] : null;
$customer_mail->dir = $data['dir'];
$customer_mail->subdir = $data['subdir'];
$customer_mail->save();
$lead_mail->dir = $data['dir'];
$lead_mail->subdir = $data['subdir'];
$lead_mail->save();
}
if($action === 'forward-mail-lead'){
$lead_mail = LeadMail::findOrFail($id);
$customerMailFewoRepo = new LeadMailRepository($lead_mail);
$customerMailFewoRepo->forwardMail($lead_mail, $data);
\Session()->flash('alert-success', __('E-Mail weitergeleitet'));
}
return back();
}
public function delete($id){
$customer_mail = CustomerFewoMail::find($id);
$customer_mail->dir = 12;
$customer_mail->subdir = 0;
$customer_mail->save();
$lead_mail = LeadMail::find($id);
$lead_mail->dir = 12;
$lead_mail->subdir = 0;
$lead_mail->save();
\Session()->flash('alert-success', __('Mail gelöscht'));
return back();
}*/
}
public function loadModal(){
@ -91,17 +102,16 @@ class LeadMailController extends Controller
$ret = "";
if(Request::ajax()) {
/* if ($data['action'] === "new-customer-mail" || $data['action'] === "reply-customer-mail" || $data['action'] === "show-customer-mail" || $data['action'] === "edit-customer-mail"){
if ($data['action'] === "new-lead-mail" || $data['action'] === "reply-lead-mail" || $data['action'] === "show-lead-mail" || $data['action'] === "edit-lead-mail"){
$data['customers'] = [];
if ($data['action'] === "new-customer-mail" && isset($data['travel_user_booking_fewo_id']) && $TravelUserBookingFewo = TravelUserBookingFewo::find($data['travel_user_booking_fewo_id'])) {
if ($data['action'] === "new-lead-mail" && isset($data['lead_id']) && $lead = Lead::find($data['lead_id'])) {
$tmp = [];
$tmp['email'] = $TravelUserBookingFewo->travel_user ? $TravelUserBookingFewo->travel_user->email : "";
$tmp['name'] = $TravelUserBookingFewo->travel_user ? $TravelUserBookingFewo->travel_user->first_name . " " . $TravelUserBookingFewo->travel_user->last_name . " | " : "- | ";
$tmp['name'] .= $TravelUserBookingFewo->fewo_lodging_id ? $TravelUserBookingFewo->fewo_lodging->name . " | " : "- | ";
$data['customers'][$TravelUserBookingFewo->id] = $tmp;
$tmp['email'] = $lead->customer ? $lead->customer->email : "";
$tmp['name'] = $lead->customer ? $lead->customer->firstname . " " . $lead->customer->name . " | " : "- | ";
$data['customers'][$lead->id] = $tmp;
}
$ret = CustomerFewoMailRepository::loadModal($data);
}*/
$ret = LeadMailRepository::loadModal($data);
}
if($data['action'] === "modal-upload-lead-file") {
$ret = view("lead.upload_modal", compact('data'))->render();
@ -122,9 +132,9 @@ class LeadMailController extends Controller
}
public function sendMail(CustomerFewoMailRepository $customerFewoMailRepository){
public function sendMail(LeadMailRepository $leadMailRepository){
$data = Request::all();
$customerFewoMailRepository->sendAndStore($data);
$leadMailRepository->sendAndStore($data);
if($data['action'] == 'draft'){
\Session()->flash('alert-success', "Entwurf gespeichert!");
}else{
@ -133,62 +143,14 @@ class LeadMailController extends Controller
return back();
}
public function replyMail(CustomerFewoMailRepository $customerFewoMailRepository){
public function replyMail(LeadMailRepository $LeadMailRepository){
$data = Request::all();
$customerFewoMailRepository->replyStore($data);
$LeadMailRepository->replyStore($data);
\Session()->flash('alert-success', "Mail gespeichert!");
return back();
}
/*public function getCustomerFewoMails()
{
$query = CustomerFewoMail::with('booking')->with('customer')->select('customer_mails.*');
return \DataTables::eloquent($query)
->addColumn('action_edit', function (CustomerFewoMail $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 (CustomerFewoMail $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 (CustomerFewoMail $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('travel_user_booking_fewo_id', function (CustomerFewoMail $customer_mail) {
return '<a data-order="'.$customer_mail->travel_user_booking_fewo_id.'" href="'.route('booking_detail', [$customer_mail->travel_user_booking_fewo_id]).'">'.$customer_mail->travel_user_booking_fewo_id.'</a>';
})
->addColumn('customer_id', function (CustomerFewoMail $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 (CustomerFewoMail $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('travel_user_booking_fewo_id', 'travel_user_booking_fewo_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('travel_user_booking_fewo_id', function($query, $keyword) {
if($keyword != ""){
$query->where('travel_user_booking_fewo_id', 'LIKE', '%'.$keyword.'%');
}
})
->rawColumns(['action_edit', 'send', 'customer_id', 'travel_user_booking_fewo_id', 'id'])
->make(true);
}*/
public function getEmailTemplates()
{
$query = EmailTemplate::with('email_template_dir')->select('email_templates.*')->where('active', '=', true);
@ -230,12 +192,12 @@ class LeadMailController extends Controller
public function uploadAttachment($id){
$fileRepo = new CustomerFewoFileRepository(new CustomerFewoFile());
$fileRepo = new LeadFileRepository(new LeadFile());
if($id === 'tmp'){
$fileRepo->_set('disk', 'travel_user');
$fileRepo->_set('disk', 'lead');
$fileRepo->_set('dir', '/attachment/'.date('Y/m').'/');
$fileRepo->_set('travel_user_id', NULL);
$fileRepo->_set('customer_fewo_mail_id', NULL);
$fileRepo->_set('lead_id', NULL);
$fileRepo->_set('lead_mail_id', NULL);
$fileRepo->_set('identifier', 'tmp');
return $fileRepo->uploadFile(Request::all());
}
@ -252,9 +214,9 @@ class LeadMailController extends Controller
$status = false;
if(Request::ajax()){
if($data['action'] === 'toggle_important'){
$customer_mail = CustomerFewoMail::find($data['id']);
$customer_mail->important = ($customer_mail->important ? false : true);
$customer_mail->save();
$lead_mail = LeadMail::find($data['id']);
$lead_mail->important = ($lead_mail->important ? false : true);
$lead_mail->save();
$status = 'success';
}
if($data['action'] === 'load_email_template'){
@ -264,9 +226,9 @@ class LeadMailController extends Controller
$status = 'success';
}
if($data['action'] === 'delete_mail_attachment'){
$customer_file = CustomerFewoFile::find($data['id']);
$fileRepo = new CustomerFewoFileRepository($customer_file);
$fileRepo->_set('disk', 'travel_user');
$lead_file = LeadFile::find($data['id']);
$fileRepo = new LeadFileRepository($lead_file);
$fileRepo->_set('disk', 'lead');
$ret = $fileRepo->delete();
$status = 'success';
}
@ -281,11 +243,11 @@ class LeadMailController extends Controller
$contents = file_get_contents($data['target'], false, stream_context_create($arrContextOptions));
$mine = Util::getMimeFromHeader($http_response_header);
$extension = Util::getExtensionFromMime($mine);
$fileRepo = new CustomerFewoFileRepository(new CustomerFewoFile());
$fileRepo->_set('disk', 'travel_user');
$fileRepo = new LeadFileRepository(new LeadFile());
$fileRepo->_set('disk', 'lead');
$fileRepo->_set('dir', '/attachment/'.date('Y/m').'/');
$fileRepo->_set('travel_user_id', NULL);
$fileRepo->_set('customer_fewo_mail_id', NULL);
$fileRepo->_set('lead_id', NULL);
$fileRepo->_set('lead_mail_id', NULL);
$fileRepo->_set('identifier', 'tmp');
$fileRepo->_set('originalName', $data['name']);
$fileRepo->_set('mine', $mine);
@ -298,17 +260,17 @@ class LeadMailController extends Controller
private function getSearchRequests()
{
if (!Request::get('travel_user_booking_fewo_id')) {
if (!Request::get('lead_id')) {
return false;
}
$query = CustomerFewoMail::where('travel_user_booking_fewo_id', '=', Request::get('travel_user_booking_fewo_id'));
if (Request::get('customer_mail_dir') == 11) { //draft
$query = LeadMail::where('lead_id', '=', Request::get('lead_id'));
if (Request::get('lead_mail_dir') == 11) { //draft
$query->where('draft', '=', true)->where('dir', '!=', 12);
}else{
$query->where('dir', '=', Request::get('customer_mail_dir')); //with('lead'
$query->where('dir', '=', Request::get('lead_mail_dir')); //with('lead'
}
if (Request::get('customer_mail_subdir')) {
$query->where('subdir', '=', Request::get('customer_mail_subdir'));
if (Request::get('lead_mail_subdir')) {
$query->where('subdir', '=', Request::get('lead_mail_subdir'));
}
return $query;
}
@ -317,7 +279,7 @@ class LeadMailController extends Controller
$query = $this->getSearchRequests();
return \DataTables::eloquent($query)
->addColumn('checkbox', function (CustomerFewoMail $customer_mail) {
->addColumn('checkbox', function (LeadMail $lead_mail) {
return '<div class="message-checkbox mr-1">
<label class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input">
@ -325,54 +287,54 @@ class LeadMailController extends Controller
</label>
</div>';
})
->addColumn('important', function (CustomerFewoMail $customer_mail) {
$icon = ($customer_mail->important ? 'ion-md-star' : 'ion-md-star-outline');
->addColumn('important', function (LeadMail $lead_mail) {
$icon = ($lead_mail->important ? 'ion-md-star' : 'ion-md-star-outline');
return '<a href="javascript:void(0)" class="ion '.$icon.' d-block text-secondary text-big mr-3 customer-mail-ajax-action"
data-url="'.route('customer_fewo_mail_ajax').'" data-id="'.$customer_mail->id.'" data-important="'.$customer_mail->important.'" data-action="toggle_important"></a>';
data-url="'.route('lead_mail_ajax').'" data-id="'.$lead_mail->id.'" data-important="'.$lead_mail->important.'" data-action="toggle_important"></a>';
})
->addColumn('subject', function (CustomerFewoMail $customer_mail) {
->addColumn('subject', function (LeadMail $lead_mail) {
$icon = $customer_mail->reply_id ? 'ion-ios-redo' : 'ion-ios-mail';
$badge = $customer_mail->is_answer ? 'badge-next' : 'badge-secondary';
$badge = $customer_mail->draft ? 'badge-default' : $badge;
$to_icon = $customer_mail->draft ? '<i class="ion ion-ios-warning" style="opacity: 0.7"></i>' : '';
$action = $customer_mail->draft ? 'edit-customer-mail' : 'show-customer-mail';
$id = $customer_mail->draft ? $customer_mail->id : 'new';
$url = $customer_mail->draft ? route('customer_fewo_mail_send_mail') : '';
$icon = $lead_mail->reply_id ? 'ion-ios-redo' : 'ion-ios-mail';
$badge = $lead_mail->is_answer ? 'badge-next' : 'badge-secondary';
$badge = $lead_mail->draft ? 'badge-default' : $badge;
$to_icon = $lead_mail->draft ? '<i class="ion ion-ios-warning" style="opacity: 0.7"></i>' : '';
$action = $lead_mail->draft ? 'edit-lead-mail' : 'show-lead-mail';
$id = $lead_mail->draft ? $lead_mail->id : 'new';
$url = $lead_mail->draft ? route('lead_mail_send_mail') : '';
return '<a href="javascript:void(0)" class="badge '.$badge.'" data-toggle="modal"
data-target="#modals-load-content" data-id="'.$id.'" data-model="CustomerFewoMail"
data-target="#modals-load-content" data-id="'.$id.'" data-model="LeadMail"
data-action="'.$action.'" data-url="'.$url.'" data-redirect="back"
data-customer_mail_id="'.$customer_mail->id.'" data-route="'.route('customer_fewo_modal_load').'">
'.$to_icon.'<i class="ion '.$icon.' ui-w-30 text-center" style="opacity: 0.7"></i>'.$customer_mail->subject.'
'.($customer_mail->customer_fewo_files->count() ? '&nbsp; <i class="ion ion-md-attach"> <span class="badge badge-primary indicator">'.$customer_mail->customer_fewo_files->count().'</span></i>' : '');
data-lead_mail_id="'.$lead_mail->id.'" data-route="'.route('lead_mail_modal_load').'">
'.$to_icon.'<i class="ion '.$icon.' ui-w-30 text-center" style="opacity: 0.7"></i>'.$lead_mail->subject.'
'.($lead_mail->lead_files->count() ? '&nbsp; <i class="ion ion-md-attach"> <span class="badge badge-primary indicator">'.$lead_mail->lead_files->count().'</span></i>' : '');
})
->addColumn('date', function (CustomerFewoMail $customer_mail) {
if($customer_mail->send){
return '<span class="badge badge-success" style="background-color: #94ae59"><i class="fa fa-check-circle"></i> '.$customer_mail->sent_at.'</span>';
->addColumn('date', function (LeadMail $lead_mail) {
if($lead_mail->send){
return '<span class="badge badge-success" style="background-color: #94ae59"><i class="fa fa-check-circle"></i> '.$lead_mail->sent_at.'</span>';
}
return '<span class="badge badge-default"><i class="fa fa-times-circle"></i> '.$customer_mail->sent_at.'</span>';
return '<span class="badge badge-default"><i class="fa fa-times-circle"></i> '.$lead_mail->sent_at.'</span>';
})
->addColumn('action', function (CustomerFewoMail $customer_mail) {
->addColumn('action', function (LeadMail $lead_mail) {
$ret = '';
if(!$customer_mail->draft){
if(!$lead_mail->draft){
$ret = '<a href="javascript:void(0)" class="btn btn-xs btn-secondary" data-toggle="modal"
data-target="#modals-load-content" data-id="reply-send" data-model="customerMail" data-action="new-customer-mail"
data-url="'.route('customer_fewo_mail_send_mail').'" data-redirect="back" data-customer_mail_id="'.$customer_mail->id.'"
data-travel_user_booking_fewo_id="'.$customer_mail->travel_user_booking_fewo_id.'" data-route="'.route('customer_fewo_modal_load').'" data-customer_mail_dir="'.$customer_mail->dir.'" data-customer_subdir="'.$customer_mail->subdir.'">
data-target="#modals-load-content" data-id="reply-send" data-model="LeadMail" data-action="new-lead-mail"
data-url="'.route('lead_mail_send_mail').'" data-redirect="back" data-lead_mail_id="'.$lead_mail->id.'"
data-lead_id="'.$lead_mail->lead_id.'" data-route="'.route('lead_mail_modal_load').'" data-lead_mail_dir="'.$lead_mail->dir.'" data-customer_subdir="'.$lead_mail->subdir.'">
<span title="Antwort auf E-Mail senden" data-placement="left" rel="tooltip"><i class="ion ion-ios-redo"></i> <i class="ion ion-md-mail-open"></i></span>
</a>
&nbsp;
<a href="javascript:void(0)" class="btn btn-xs btn-default" data-toggle="modal"
data-target="#modals-load-content" data-id="reply-save" data-model="customerMail" data-action="reply-customer-mail"
data-url="'.route('customer_fewo_mail_reply_mail').'" data-redirect="back" data-customer_mail_id="'.$customer_mail->id.'"
data-travel_user_booking_fewo_id="'.$customer_mail->travel_user_booking_fewo_id.'" data-route="'.route('customer_fewo_modal_load').'" data-customer_mail_dir="'.$customer_mail->dir.'" data-customer_mail_subdir="'.$customer_mail->subdir.'">
data-target="#modals-load-content" data-id="reply-save" data-model="LeadMail" data-action="reply-lead-mail"
data-url="'.route('lead_mail_reply_mail').'" data-redirect="back" data-lead_mail_id="'.$lead_mail->id.'"
data-lead_id="'.$lead_mail->lead_id.'" data-route="'.route('lead_mail_modal_load').'" data-lead_mail_dir="'.$lead_mail->dir.'" data-lead_mail_subdir="'.$lead_mail->subdir.'">
<span title="Antwort auf E-Mail speichern" data-placement="left" rel="tooltip"><i class="ion ion-ios-redo"></i> <i class="ion ion-md-mail-unread"></i></span>
</a>
&nbsp;';
}
$ret .= '<a href="'.route('customer_fewo_mail_delete', [$customer_mail->id]).'" class="btn btn-xs btn-default text-danger" onclick="return confirm(\'In den Papierkorb verschieben?\');"><i class="ion ion-md-trash"></i></a>';
$ret .= '<a href="'.route('lead_mail_delete', [$lead_mail->id]).'" class="btn btn-xs btn-default text-danger" onclick="return confirm(\'In den Papierkorb verschieben?\');"><i class="ion ion-md-trash"></i></a>';
return '<div style="white-space: nowrap;">'.$ret.'</div>';
})