Edit / PDF / Mail / ->Leads

This commit is contained in:
Kevin Adametz 2021-05-07 17:44:02 +02:00
parent 5d55e5be3f
commit 66ca252bfa
43 changed files with 2915 additions and 76 deletions

View file

@ -51,6 +51,13 @@ class FileController extends Controller
$path = $file->getPath();
}
if ($disk === 'lead'){
$file = \App\Models\LeadFile::findOrFail($id);
$filename = $file->original_name;
$path = $file->getPath();
}
if ($disk === 'cms_file'){
$file = \App\Models\CMSContent::findOrFail($id);
$filename = $file->name;

View file

@ -2,20 +2,27 @@
namespace App\Http\Controllers;
use App\Models\Lead;
use App\Repositories\LeadRepository;
use Carbon;
use Request;
use App\Models\Lead;
use App\Models\LeadFile;
use App\Models\LeadNotice;
use App\Repositories\LeadRepository;
use App\Repositories\CustomerRepository;
use App\Repositories\LeadFileRepository;
class LeadController extends Controller
{
protected $leadRepo;
protected $custRepo;
public function __construct(LeadRepository $leadRepo)
public function __construct(LeadRepository $leadRepo, CustomerRepository $custRepo)
{
$this->middleware('admin');
$this->leadRepo = $leadRepo;
$this->custRepo = $custRepo;
}
public function index($step = false)
@ -46,18 +53,92 @@ class LeadController extends Controller
public function store($id)
{
$data = Request::all();
if($data['action'] === 'saveCustomer'){
$customer = $this->custRepo->updateCustomerFromLead($id, $data);
\Session()->flash('alert-save', '1');
return redirect(route('lead_detail', [$id]).'#collapseLeadCustomer');
}
if($data['action'] === 'saveLead'){
$lead = $this->leadRepo->updateLead($id, $data);
\Session()->flash('alert-save', '1');
return redirect(route('lead_detail', [$id]).'#collapseLeadDetail');
}
if($data['action'] === 'saveStatus'){
$lead = $this->leadRepo->updateLeadStatus($id, $data);
\Session()->flash('alert-save', '1');
return redirect(route('lead_detail', [$id]).'#collapseLeadStatus');
}
if($data['action'] === 'save_notice'){
$lead = $this->leadRepo->updateNotice($id, $data);
\Session()->flash('alert-save', '1');
return redirect(route('lead_detail', [$lead->id])."#collapseLeadNotice");
}
if($data['action'] === 'edit_notice'){
$lead = $this->leadRepo->updateNotice($id, $data);
\Session()->flash('alert-save', '1');
return redirect(route('lead_detail', [$lead->id])."#collapseLeadNotice");
}
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()) {
if($data['action'] === "edit_notice") {
$value = LeadNotice::findOrFail($data['id']);
$ret = view("lead.edit_notice_modal", compact('data', 'value'))->render();
}
}
return response()->json(['response' => $data, 'html'=>$ret]);
}
public function delete($id, $del="lead"){
if($del === 'lead') {
$lead = Lead::findOrFail($id);
dump($lead);
dd('TODO check delete');
//Files
$leadFiles = LeadFile::where('lead_id', $lead->id)->get();
foreach ($leadFiles as $leadFile) {
$fileRepo = new LeadFileRepository($leadFile);
$fileRepo->_set('disk', 'lead');
$fileRepo->delete();
$leadFile->delete();
}
//Mails Files CASCADE
$lead->delete();
\Session()->flash('alert-success', __('Anfrage gelöscht'));
}
if($del === 'lead_notice'){
$leadNotice = LeadNotice::findOrFail($id);
$lead = $leadNotice->lead;
$leadNotice->delete();
\Session()->flash('alert-success', 'Notiz gelöscht');
return redirect(route('lead_detail', [$lead->id]));
}
if($del === 'lead_files'){
$leadFile = LeadFile::findOrFail($id);
$lead = $leadFile->lead;
$fileRepo = new LeadFileRepository($leadFile);
$fileRepo->_set('disk', 'lead');
$fileRepo->delete();
$leadFile->delete();
\Session()->flash('alert-success', 'Datei gelöscht');
return redirect(route('lead_detail', [$lead->id]));
}
return redirect(route('leads'));
}
public function getLeads()
@ -77,8 +158,14 @@ class LeadController extends Controller
->addColumn('request_date', function (Lead $lead) {
return Carbon::parse($lead->request_date)->format(\Util::formatDateDB());
})
->addColumn('status', function (Lead $lead) {
//umbuchen
return $lead->getStatusBadge();
})
->orderColumn('id', 'id $1')
->orderColumn('customer_id', 'customer_id $1')
->orderColumn('status', 'status_id $1')
->filterColumn('id', function($query, $keyword) {
if($keyword != ""){
$query->where('id', 'LIKE', '%'.$keyword.'%');
@ -89,7 +176,7 @@ class LeadController extends Controller
$query->where('customer_id', 'LIKE', '%'.$keyword.'%');
}
})
->rawColumns(['action_edit', 'customer_id', 'sf_guard_user_id', 'id'])
->rawColumns(['action_edit', 'customer_id', 'sf_guard_user_id', 'id', 'status'])
->make(true);
}

View file

@ -0,0 +1,387 @@
<?php
namespace App\Http\Controllers;
use Carbon;
use Request;
use Response;
use App\Services\Util;
use App\Models\LeadFile;
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;
use App\Repositories\BookingFewoFileRepository;
use App\Repositories\CustomerFewoFileRepository;
use App\Repositories\CustomerFewoMailRepository;
class LeadMailController extends Controller
{
protected $customerMailRepo;
public function __construct(LeadMailRepository $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 CustomerFewoMail();
$id = 'new';
}else{
$customer_mail = CustomerFewoMail::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, $action=false)
{
$data = Request::all();
$customer_mail = CustomerFewoMail::findOrFail($id);
if($action === 'move-mail'){
$data['subdir'] = isset($data['subdir']) && $data['subdir'] ? $data['subdir'] : null;
$customer_mail->dir = $data['dir'];
$customer_mail->subdir = $data['subdir'];
$customer_mail->save();
}
return back();
}
public function delete($id){
$customer_mail = CustomerFewoMail::find($id);
$customer_mail->dir = 12;
$customer_mail->subdir = 0;
$customer_mail->save();
\Session()->flash('alert-success', __('Mail gelöscht'));
return back();
}*/
public function loadModal(){
$data = Request::all();
$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"){
$data['customers'] = [];
if ($data['action'] === "new-customer-mail" && isset($data['travel_user_booking_fewo_id']) && $TravelUserBookingFewo = TravelUserBookingFewo::find($data['travel_user_booking_fewo_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;
}
$ret = CustomerFewoMailRepository::loadModal($data);
}*/
if($data['action'] === "modal-upload-lead-file") {
$ret = view("lead.upload_modal", compact('data'))->render();
}
if($data['action'] === "upload-lead-file"){
if($data['lead_id']){
$bookingFileRepo = new LeadFileRepository(new LeadFile());
$bookingFileRepo->_set('disk', 'lead');
$bookingFileRepo->_set('lead_id', $data['lead_id']);
$bookingFileRepo->_set('dir', '/files/'.date('Y/m').'/');
$bookingFileRepo->_set('identifier', 'lead');
return $bookingFileRepo->uploadFile(Request::all());
}
}
}
return response()->json(['response' => $data, 'html'=>$ret]);
}
public function sendMail(CustomerFewoMailRepository $customerFewoMailRepository){
$data = Request::all();
$customerFewoMailRepository->sendAndStore($data);
if($data['action'] == 'draft'){
\Session()->flash('alert-success', "Entwurf gespeichert!");
}else{
\Session()->flash('alert-success', "Mail gesendet!");
}
return back();
}
public function replyMail(CustomerFewoMailRepository $customerFewoMailRepository){
$data = Request::all();
$customerFewoMailRepository->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);
if(Request::get('filter_email_templates_directory') != ""){
$query->where('email_template_dir_id', '=', Request::get('filter_email_templates_directory'));
}
return \DataTables::eloquent($query)
->addColumn('action', function (EmailTemplate $emailTemplate) {
return '<a href="javascript:void(0)" class="btn icon-btn btn-sm btn-primary email-template-action"
data-url="'.route('customer_mail_ajax').'" data-id="'.$emailTemplate->id.'" data-action="load_email_template"
title="Vorlage laden" data-placement="left" rel="tooltip"><span class="ion ion-ios-arrow-dropup"></span></a>';
})
->addColumn('email_template_dir.name', function (EmailTemplate $emailTemplate) {
return $emailTemplate->email_template_dir ? '<span class="badge badge-default" style="background-color: '.$emailTemplate->email_template_dir->color.'">'.$emailTemplate->email_template_dir->name.'</span>' : '&nbsp;';
})
->orderColumn('id', 'id $1')
->orderColumn('subject', 'subject $1')
->orderColumn('name', 'name $1')
->orderColumn('email_template_dir.name', 'email_template_dir.name $1')
->orderColumn('message', 'message $1')
->filterColumn('id', function($query, $keyword) {
if($keyword != ""){
$query->where('id', 'LIKE', '%'.$keyword.'%');
}
})
->filterColumn('subject', function($query, $keyword) {
if($keyword != ""){
$query->where('name', 'LIKE', '%'.$keyword.'%');
$query->OrWhere('subject', 'LIKE', '%'.$keyword.'%');
$query->OrWhere('message', 'LIKE', '%'.$keyword.'%');
}
})
->rawColumns(['action', 'email_template_dir.name'])
->make(true);
}
public function uploadAttachment($id){
$fileRepo = new CustomerFewoFileRepository(new CustomerFewoFile());
if($id === 'tmp'){
$fileRepo->_set('disk', 'travel_user');
$fileRepo->_set('dir', '/attachment/'.date('Y/m').'/');
$fileRepo->_set('travel_user_id', NULL);
$fileRepo->_set('customer_fewo_mail_id', NULL);
$fileRepo->_set('identifier', 'tmp');
return $fileRepo->uploadFile(Request::all());
}
return Response::json([
'error' => true,
'code' => 200
], 200);
}
public function ajax(){
$data = Request::all();
$ret = "";
$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();
$status = 'success';
}
if($data['action'] === 'load_email_template'){
$email_template = EmailTemplate::find($data['id']);
$ret = $email_template->message;
$data['subject'] = $email_template->subject;
$status = 'success';
}
if($data['action'] === 'delete_mail_attachment'){
$customer_file = CustomerFewoFile::find($data['id']);
$fileRepo = new CustomerFewoFileRepository($customer_file);
$fileRepo->_set('disk', 'travel_user');
$ret = $fileRepo->delete();
$status = 'success';
}
if($data['action'] === 'add_attachment'){
$arrContextOptions=array(
"ssl"=>array(
"verify_peer"=>false,
"verify_peer_name"=>false,
),
);
$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->_set('dir', '/attachment/'.date('Y/m').'/');
$fileRepo->_set('travel_user_id', NULL);
$fileRepo->_set('customer_fewo_mail_id', NULL);
$fileRepo->_set('identifier', 'tmp');
$fileRepo->_set('originalName', $data['name']);
$fileRepo->_set('mine', $mine);
$fileRepo->_set('extension', $extension);
return $fileRepo->storeFile($contents);
}
}
return response()->json(['response' => $data, 'html'=>$ret, 'status'=>$status]);
}
private function getSearchRequests()
{
if (!Request::get('travel_user_booking_fewo_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->where('draft', '=', true)->where('dir', '!=', 12);
}else{
$query->where('dir', '=', Request::get('customer_mail_dir')); //with('lead'
}
if (Request::get('customer_mail_subdir')) {
$query->where('subdir', '=', Request::get('customer_mail_subdir'));
}
return $query;
}
public function getRequests(){
$query = $this->getSearchRequests();
return \DataTables::eloquent($query)
->addColumn('checkbox', function (CustomerFewoMail $customer_mail) {
return '<div class="message-checkbox mr-1">
<label class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input">
<span class="custom-control-label"></span>
</label>
</div>';
})
->addColumn('important', function (CustomerFewoMail $customer_mail) {
$icon = ($customer_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>';
})
->addColumn('subject', function (CustomerFewoMail $customer_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') : '';
return '<a href="javascript:void(0)" class="badge '.$badge.'" data-toggle="modal"
data-target="#modals-load-content" data-id="'.$id.'" data-model="CustomerFewoMail"
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>' : '');
})
->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>';
}
return '<span class="badge badge-default"><i class="fa fa-times-circle"></i> '.$customer_mail->sent_at.'</span>';
})
->addColumn('action', function (CustomerFewoMail $customer_mail) {
$ret = '';
if(!$customer_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.'">
<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.'">
<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>';
return '<div style="white-space: nowrap;">'.$ret.'</div>';
})
->orderColumn('date', 'sent_at $1')
->orderColumn('subject', 'subject $1')
->orderColumn('important', 'important $1')
->rawColumns(['checkbox', 'important', 'subject', 'date', 'action'])
->make(true);
}
}

View file

@ -389,23 +389,8 @@ class RequestController extends Controller
})
->addColumn('lead.status_id', function (Booking $booking) {
//umbuchen
if($booking->lead->status_id){
$color = $booking->lead->status->color;
$icon = "";
if($booking->lead->status_id == 14 && $booking->lead->is_rebook){
$color = '#94ae59';
$icon = '<i class="fa fa-check-circle"></i> ';
}
if($booking->lead->status_id == 14 && !$booking->lead->is_rebook){
$icon = '<i class="fa fa-times-circle"></i> ';
}
if($booking->lead->status_id == 15){
$icon = '<i class="fa fa-balance-scale"></i> ';
if($booking->lawyer_date){
return '<span data-order="'.$booking->lead->status_id.'"><span class="badge badge-dark" style="background-color: '.$color.'">'.$icon.$booking->lawyer_date->format('d.m.Y').'</span></span>';
}
}
return '<span data-order="'.$booking->lead->status_id.'"><span class="badge badge-dark" style="background-color: '.$color.'">'.$icon.$booking->lead->status->name.'</span></span>';
if($booking->lead){
return $booking->lead->getStatusBadge($booking);
}
return '<span data-order="0">-</span>';
})

View file

@ -9,6 +9,7 @@ use App\Models\EmailTemplate;
use App\Models\EmailTemplateDir;
use App\Services\Booking;
use App\Services\BookingFewo;
use App\Services\Lead;
use App\Services\Util;
use Request;
@ -22,6 +23,8 @@ class EmailsController extends Controller
{
$this->identifier_booking_file = 'booking-email-file';
$this->identifier_fewo_file = 'fewo-email-file';
$this->identifier_lead_file = 'lead-email-file';
$this->middleware('admin');
}
@ -36,8 +39,11 @@ class EmailsController extends Controller
'customer_mail_dirs' => Booking::getCustomerMailDirs(),
'identifier_booking_file' => $this->identifier_booking_file,
'identifier_fewo_file' => $this->identifier_fewo_file,
'identifier_lead_file' => $this->identifier_lead_file,
'fewo_email_files' => CMSContent::where('identifier', '=', $this->identifier_fewo_file)->get()->sortByDesc('pos'),
'customer_fewo_mail_dirs' => BookingFewo::getCustomerMailDirs(),
'lead_email_files' => CMSContent::where('identifier', '=', $this->identifier_lead_file)->get()->sortByDesc('pos'),
'customer_lead_mail_dirs' => Lead::getCustomerMailDirs(),
'step' => $step
];

View file

@ -6,6 +6,7 @@
namespace App\Models;
use App\Models\Sym\TravelCountry;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
@ -123,6 +124,11 @@ class Customer extends Model
'country_id',
];
public static $salutationType = [
1 => 'Mann',
2 => 'Frau'
];
public function travel_country()
{
return $this->belongsTo(TravelCountry::class, 'country_id');
@ -154,6 +160,10 @@ class Customer extends Model
}
return $this->name;
}
public static function getCustomerCountriesArray(){
return TravelCountry::where('is_customer_country', 1)->get()->pluck('name', 'id');
}
}

View file

@ -6,6 +6,7 @@
namespace App\Models;
use App\Models\Lead as ModelsLead;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
@ -157,9 +158,12 @@ class Lead extends Model
if(!$date){
$carbon = Carbon::now();
$this->next_due_date = $carbon->modify('+ '.$this->status->handling_days.' days')->format("Y-m-d");
$this->save();
}
}else{
$carbon = Carbon::parse($date);
}
$this->next_due_date = $carbon->modify('+ '.$this->status->handling_days.' days')->format("Y-m-d");
$this->save();
}
public function customer()
{
@ -242,6 +246,83 @@ class Lead extends Model
public function status_histories()
{
return $this->hasMany(StatusHistory::class);
return $this->hasMany(StatusHistory::class)->orderByDesc('id')->orderByDesc('date');
}
public function lead_files()
{
//no lead_mail_id
return $this->hasMany(LeadFile::class, 'lead_id')->where('lead_mail_id', null);
}
public function lead_mails()
{
return $this->hasMany(LeadMail::class, 'lead_id', 'id');
}
public function lead_mails_sent_at()
{
return $this->hasMany(LeadMail::class, 'lead_id')->orderBy('sent_at', 'ASC');
}
public function lead_mail_last()
{
return $this->hasOne(LeadMail::class, 'lead_id')->latest();
}
public function lead_notices()
{
return $this->hasMany(LeadNotice::class, 'lead_id')->orderBy('created_at', 'DESC');
}
public static function getSfGuardUserArray(){
return SfGuardUser::where('is_active', 1)->get()->pluck('fullname', 'id');
}
public static function getTravelCountryArray($emtpy = false){
$TravelCountry = TravelCountry::where('active_backend', 1)->orderBy('name')->get()->pluck('name', 'id');
return $emtpy ? $TravelCountry->prepend('-', 0) : $TravelCountry;
}
public static function getTravelCategoryArray($emtpy = false){
$TravelCategory = TravelCategory::orderBy('name')->get()->pluck('name', 'id');
return $emtpy ? $TravelCategory->prepend('-', 0) : $TravelCategory;
}
public static function getTravelAgendaArray($emtpy = false){
$TravelAgenda = TravelAgenda::orderBy('name')->get()->pluck('name', 'id');
return $emtpy ? $TravelAgenda->prepend('-', 0) : $TravelAgenda;
}
public static function getStatusArray($emtpy = false){
$Status = Status::orderBy('name')->get()->pluck('name', 'id');
return $emtpy ? $Status->prepend('-', 0) : $Status;
}
public function getStatusBadge($booking = null)
{
if($this->status_id && $this->status){
$color = $this->status->color;
$icon = "";
if($this->status_id == 14 && $this->is_rebook){
$color = '#94ae59';
$icon = '<i class="fa fa-check-circle"></i> ';
}
if($this->status_id == 14 && !$this->is_rebook){
$icon = '<i class="fa fa-times-circle"></i> ';
}
if($this->status_id == 15){
$icon = '<i class="fa fa-balance-scale"></i> ';
if($booking && $booking->lawyer_date){
return '<span data-order="'.$this->status_id.'"><span class="badge badge-dark" style="background-color: '.$color.'">'.$icon.$booking->lawyer_date->format('d.m.Y').'</span></span>';
}
}
return '<span data-order="'.$this->status_id.'"><span class="badge badge-dark" style="background-color: '.$color.'">'.$icon.$this->status->name.'</span></span>';
}
return '<span data-order="0">-</span>';
}
}

100
app/Models/LeadFile.php Normal file
View file

@ -0,0 +1,100 @@
<?php
/**
* Created by Reliese Model.
*/
namespace App\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
/**
* Class LeadFile
*
* @property int $id
* @property int $lead_id
* @property int $lead_mail_id
* @property string $identifier
* @property string $filename
* @property string $dir
* @property string $original_name
* @property string $ext
* @property string $mine
* @property int $size
* @property Carbon $created_at
* @property Carbon $updated_at
*
* @property Lead $lead
* @property LeadMail $lead_mail
*
* @package App\Models
*/
class LeadFile extends Model
{
protected $table = 'lead_files';
protected $casts = [
'lead_id' => 'int',
'lead_mail_id' => 'int',
'size' => 'int'
];
protected $fillable = [
'lead_id',
'lead_mail_id',
'identifier',
'filename',
'dir',
'original_name',
'ext',
'mine',
'size'
];
public static $icon_ext = [
'default' => 'fa fa-file',
'pdf'=> 'fa fa-file-pdf',
'jpg'=> 'fa fa-file-image',
'png'=> 'fa fa-file-image',
];
public function lead()
{
return $this->belongsTo(Lead::class);
}
public function lead_mail()
{
return $this->belongsTo(LeadMail::class);
}
public function getIconExt(){
return isset(self::$icon_ext[$this->ext]) ? self::$icon_ext[$this->ext] : self::$icon_ext['default'];
}
public function getURL($do=false){
return route('storage_file', [$this->id, 'lead', $do]);
}
public function getPath(){
return \Storage::disk('lead')->path($this->dir.$this->filename);
}
public function formatBytes($precision = 2)
{
$size = $this->size;
if ($size > 0) {
$size = (int) $size;
$base = log($size) / log(1024);
$suffixes = array(' bytes', ' KB', ' MB', ' GB', ' TB');
return round(pow(1024, $base - floor($base)), $precision) . $suffixes[floor($base)];
} else {
return $size;
}
}
}

114
app/Models/LeadMail.php Normal file
View file

@ -0,0 +1,114 @@
<?php
/**
* Created by Reliese Model.
*/
namespace App\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
/**
* Class LeadMail
*
* @property int $id
* @property int $lead_id
* @property int $customer_id
* @property bool $is_answer
* @property int $reply_id
* @property string $email
* @property string $recipient
* @property string $cc
* @property string $bcc
* @property string $subject
* @property string $message
* @property int $dir
* @property int $subdir
* @property bool $draft
* @property bool $important
* @property bool $send
* @property bool $fail
* @property string $error
* @property string $forward
* @property Carbon $sent_at
* @property Carbon $scheduled_at
* @property Carbon $delivered_at
* @property Carbon $created_at
* @property Carbon $updated_at
*
* @property Customer $customer
* @property Lead $lead
* @property CustomerMail $customer_mail
* @property Collection|LeadFile[] $lead_files
*
* @package App\Models
*/
class LeadMail extends Model
{
protected $table = 'lead_mails';
protected $casts = [
'lead_id' => 'int',
'customer_id' => 'int',
'is_answer' => 'bool',
'reply_id' => 'int',
'dir' => 'int',
'subdir' => 'int',
'draft' => 'bool',
'important' => 'bool',
'send' => 'bool',
'fail' => 'bool'
];
protected $dates = [
'sent_at',
'scheduled_at',
'delivered_at'
];
protected $fillable = [
'lead_id',
'customer_id',
'is_answer',
'reply_id',
'email',
'recipient',
'cc',
'bcc',
'subject',
'message',
'dir',
'subdir',
'draft',
'important',
'send',
'fail',
'error',
'forward',
'sent_at',
'scheduled_at',
'delivered_at'
];
public function customer()
{
return $this->belongsTo(Customer::class);
}
public function lead()
{
return $this->belongsTo(Lead::class);
}
public function customer_mail()
{
return $this->belongsTo(CustomerMail::class, 'reply_id');
}
public function lead_files()
{
return $this->hasMany(LeadFile::class);
}
}

91
app/Models/LeadNotice.php Normal file
View file

@ -0,0 +1,91 @@
<?php
/**
* Created by Reliese Model.
*/
namespace App\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
use App\User;
/**
* Class LeadNotice
*
* @property int $id
* @property int $lead_id
* @property int $from_user_id
* @property int $to_user_id
* @property string $message
* @property bool $show
* @property bool $important
* @property Carbon $edit_at
* @property Carbon $created_at
* @property Carbon $updated_at
*
* @property User $user
* @property Lead $lead
*
* @package App\Models
*/
class LeadNotice extends Model
{
protected $table = 'lead_notices';
protected $casts = [
'lead_id' => 'int',
'from_user_id' => 'int',
'to_user_id' => 'int',
'show' => 'bool',
'important' => 'bool'
];
protected $dates = [
'edit_at'
];
protected $fillable = [
'lead_id',
'from_user_id',
'to_user_id',
'message',
'show',
'important',
'edit_at'
];
public function to_user()
{
return $this->belongsTo(User::class, 'to_user_id');
}
public function from_user()
{
return $this->belongsTo(User::class, 'from_user_id');
}
public function lead()
{
return $this->belongsTo(Lead::class);
}
public function getName(){
if($this->from_user){
if($this->from_user->sf_guard_user){
return $this->from_user->sf_guard_user->first_name." ".$this->from_user->sf_guard_user->last_name;
}else{
$this->from_user->name;
}
}
}
public function getSmallerMessage($max = 500){
$ret = substr($this->message, 0, $max);
if(strlen($this->message) > 500){
$ret .= " ...";
}
return $ret;
}
}

View file

@ -66,4 +66,9 @@ class SfGuardUser extends Model
return $this->belongsTo(User::class, 'user_id');
}
public function getFullnameAttribute(){
return $this->first_name." ".$this->last_name;
}
}

View file

@ -47,9 +47,20 @@ class Status extends Model
'color'
];
public function leads()
public function getStatusBadge()
{
return $this->hasMany(Lead::class);
$color = $this->color;
$icon = "";
if($this->id == 14){
$icon = '<i class="fa fa-times-circle"></i> ';
}
if($this->id == 15){
$icon = '<i class="fa fa-balance-scale"></i> ';
}
return '<span data-order="'.$this->id.'"><span class="badge badge-dark" style="background-color: '.$color.'">'.$icon.$this->name.'</span></span>';
}
/*public function status_histories()

View file

@ -52,7 +52,8 @@ class StatusHistory extends Model
protected $dates = [
'date',
'target_date'
'target_date',
'created_at'
];
protected $fillable = [
@ -61,7 +62,8 @@ class StatusHistory extends Model
'sf_guard_user_id',
'date',
'remarks',
'target_date'
'target_date',
'created_at'
];
public function lead()

View file

@ -2,26 +2,20 @@
namespace App\Repositories;
use App\Models\BookingFile;
use App\Models\TravelUserBookingFile;
use Response;
class BookingFewoFileRepository extends FileRepository {
protected $booking_fewo_file;
protected $travel_user_booking_fewo_id;
protected $identifier;
public function __construct(TravelUserBookingFile $model){
parent::__construct();
$this->model = $model;
}
public function save(){
$this->booking_fewo_file = TravelUserBookingFile::create([
'travel_user_booking_fewo_id' => $this->travel_user_booking_fewo_id,
@ -35,7 +29,6 @@ class BookingFewoFileRepository extends FileRepository {
]);
}
public function response(){
return Response::json([
'error' => false,

View file

@ -3,19 +3,46 @@
namespace App\Repositories;
use App\Models\Booking;
use App\Models\Customer;
use App\Models\Lead;
class CustomerRepository extends BaseRepository {
public function __construct(Booking $model)
public function __construct(Customer $model)
{
$this->model = $model;
}
public function update($data)
public function updateCustomer($id, $data)
{
$this->model = Customer::findOrFail($id);
$fill = [
'salutation_id' => $data['salutation_id'],
'name' => $data['name'],
'firstname' => $data['firstname'],
'street' => $data['street'],
'zip' => $data['zip'],
'city' => $data['city'],
'email' => $data['email'],
'phone' => $data['phone'],
'phonemobile' => $data['phonemobile'],
'country_id' => $data['country_id'],
];
$this->model->fill($fill);
$this->model->save();
return $this->model;
}
public function updateCustomerFromLead($id, $data){
$lead = Lead::findOrFail($id);
if(isset($data['customer']) && $lead->customer){
return $this->updateCustomer($lead->customer->id, $data['customer']);
}
}
}

View file

@ -0,0 +1,46 @@
<?php
namespace App\Repositories;
use App\Models\LeadFile;
use Response;
class LeadFileRepository extends FileRepository {
protected $lead_file;
protected $lead_id;
protected $identifier;
public function __construct(LeadFile $model){
parent::__construct();
$this->model = $model;
}
public function save(){
$this->lead_file = LeadFile::create([
'lead_id' => $this->lead_id,
'identifier' => $this->identifier,
'filename' => $this->allowed_filename,
'dir' => $this->dir,
'original_name' => $this->originalName,
'ext' => $this->extension,
'mine' => $this->mine,
'size' => $this->size
]);
}
public function response(){
return Response::json([
'error' => false,
'filename' => $this->allowed_filename,
'file_id' =>$this->lead_file->id,
'file_data' => $this->extension,
'file_icon' => $this->lead_file->getIconExt(),
'file_format_bytes' => $this->lead_file->formatBytes(),
'file_url' => $this->lead_file->getURL(),
'redirect' => '',
'code' => 200
], 200);
}
}

View file

@ -0,0 +1,387 @@
<?php
namespace App\Repositories;
use App\Mail\MailSendInfo;
use App\Models\CMSContent;
use App\Models\CustomerFewoFile;
use App\Models\CustomerFewoMail;
use App\Models\EmailTemplate;
use App\Models\TravelUserBookingFewo;
use App\Services\Placeholder;
use App\Services\Util;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Facades\Mail;
class LeadMailRepository extends BaseRepository {
public function __construct(CustomerFewoMail $model)
{
$this->model = $model;
}
public function update($data)
{
return $this->model;
}
public function sendAndStore($data){
//send or draft
//$data['action']
if(isset($data['send_mail_to']) && is_array($data['send_mail_to'])) {
//has Attachments
$customer_files = [];
if(isset($data['message_attachment_id']) && is_array($data['message_attachment_id'])){
foreach ($data['message_attachment_id'] as $message_attachment_id){
if($CustomerFile = CustomerFewoFile::find($message_attachment_id)){
$customer_files[] = $CustomerFile;
}
}
}
foreach ($data['send_mail_to'] as $booking_fewo_id => $on) {
$booking_fewo = TravelUserBookingFewo::find($booking_fewo_id);
if ($booking_fewo->travel_user) {
$data['draft'] = (isset($data['action']) && $data['action'] === 'draft' ? true : false);
if(!$data['draft']){
$data['message'] = $this->prepareContent($booking_fewo, $data['message']);
$data['subject'] = $this->prepareContent($booking_fewo, $data['subject']);
}
$reply_id = isset($data['customer_mail_id']) ? $data['customer_mail_id'] : NULL;
$email = isset($data['send_mail_to_mail'][$booking_fewo_id]) ? $data['send_mail_to_mail'][$booking_fewo_id] : $booking_fewo->travel_user->email;
$customer_mail = $this->store($booking_fewo, $data, $email, false, $reply_id);
foreach ($customer_files as $file) {
$file->travel_user_id = $booking_fewo->travel_user_id;
$file->customer_fewo_mail_id = $customer_mail->id;
$file->identifier = 'mail';
$file->save();
}
if(isset($data['action']) && $data['action'] === 'send'){ //not at draft
$this->sendMail($customer_mail);
}
}
}
}
}
public function forwardMail($customer_mail, $data){
//send or draft
//$data['action']
if(isset($data['customer_mail_forward_email']) && !empty($data['customer_mail_forward_email'])) {
$to_mails = [];
if(strpos($data['customer_mail_forward_email'], ',')){
$to_mails = array_map('trim', explode(',', $data['customer_mail_forward_email']));
}else{
$to_mails[] = $data['customer_mail_forward_email'];
}
$customer_files = $customer_mail->customer_files;
$full_message = $this->prepareMessageFull($customer_mail);
try {
//
Mail::to($to_mails)
->bcc($customer_mail->bcc ?: [])
->send(new MailSendInfo($customer_mail->subject, $full_message, $customer_files));
}
catch(\Exception $e){
// Never reached
$forward = array();
$forward[now()->format("d.m.Y H:i:s")] = ['fail'=> true, 'to'=> $data['customer_mail_forward_email'], 'error'=>$e->getMessage()];
$customer_mail->setForwardMessage($forward);
return false;
}
$forward = array();
$forward[now()->format("d.m.Y H:i:s")] = ['sent'=> true, 'to'=> $data['customer_mail_forward_email']];
$customer_mail->setForwardMessage($forward);
return true;
}
}
public function replyStore($data){
if(isset($data['travel_user_booking_fewo_id']) && $booking_fewo = TravelUserBookingFewo::find($data['travel_user_booking_fewo_id'])) {
//has Attachments
$customer_files = [];
if(isset($data['message_attachment_id']) && is_array($data['message_attachment_id'])){
foreach ($data['message_attachment_id'] as $message_attachment_id){
if($CustomerFile = CustomerFewoFile::find($message_attachment_id)){
$customer_files[] = $CustomerFile;
}
}
}
if ($booking_fewo->travel_user) {
$data['draft'] = (isset($data['action']) && $data['action'] === 'draft' ? true : false);
$mail_from = isset($data['mail_from']) ? $data['mail_from'] : $booking_fewo->travel_user->email;
$sent_at = isset($data['sent_at']) ? \Carbon::parse(str_replace("- ", "", $data['sent_at'])) : now();
$reply_id = isset($data['customer_mail_id']) ? $data['customer_mail_id'] : NULL;
$customer_mail = $this->store($booking_fewo, $data, $mail_from, true, $reply_id, $sent_at);
foreach ($customer_files as $file) {
$file->travel_user_id = $booking_fewo->travel_user_id;
$file->customer_fewo_mail_id = $customer_mail->id;
$file->identifier = 'mail';
$file->save();
}
}
}
}
public function store($booking_fewo, $data, $mail_from, $is_answer = false, $reply_id = NULL, $sent_at=false){
if(isset($data['save_customer_mail_id'])){
$customer_mail = CustomerFewoMail::find($data['save_customer_mail_id']);
$customer_mail->fill([
'travel_user_booking_fewo_id' => $booking_fewo->id,
'travel_user_id' => $booking_fewo->travel_user_id,
'is_answer' => $is_answer,
'reply_id' => $reply_id,
'email' => $mail_from,
'recipient' => isset($data['recipient']) ? Util::_explodeLines($data['recipient']) : null,
'cc' => isset($data['cc']) ? Util::_explodeLines($data['cc']) : null,
'bcc' => isset($data['bcc']) ? Util::_explodeLines($data['bcc']) : null,
'subject' => $data['subject'],
'message' => $data['message'],
'dir' => isset($data['dir']) ? $data['dir'] : 0,
'subdir' => isset($data['subdir']) ? $data['subdir'] : 0,
'draft' => $data['draft'],
'sent_at' => $sent_at ? $sent_at : now(),
])->save();
}else{
$customer_mail = CustomerFewoMail::create([
'travel_user_booking_fewo_id' => $booking_fewo->id,
'travel_user_id' => $booking_fewo->travel_user_id,
'is_answer' => $is_answer,
'reply_id' => $reply_id,
'email' => $mail_from,
'recipient' => isset($data['recipient']) ? Util::_explodeLines($data['recipient']) : null,
'cc' => isset($data['cc']) ? Util::_explodeLines($data['cc']) : null,
'bcc' => isset($data['bcc']) ? Util::_explodeLines($data['bcc']) : null,
'subject' => $data['subject'],
'message' => $data['message'],
'dir' => isset($data['dir']) ? $data['dir'] : 0,
'subdir' => isset($data['subdir']) ? $data['subdir'] : 0,
'draft' => $data['draft'],
'sent_at' => $sent_at ? $sent_at : now(),
]);
}
return $customer_mail;
}
private function sendMail($customer_mail){
$to_mails = [];
if(strpos($customer_mail->email, ',')){
$to_mails = array_map('trim', explode(',', $customer_mail->email));
}else{
$to_mails[] = $customer_mail->email;
}
if($customer_mail->recipient){
$to_mails = array_merge($to_mails, $customer_mail->recipient);
}
$customer_files = $customer_mail->customer_files;
$full_message = $this->prepareMessageFull($customer_mail);
try {
//
Mail::to($to_mails)
->cc($customer_mail->cc ?: [])
->bcc($customer_mail->bcc ?: [])
->send(new MailSendInfo($customer_mail->subject, $full_message, $customer_files));
}
catch(\Exception $e){
// Never reached
$customer_mail->fail = true;
$customer_mail->error = $e->getMessage();
$customer_mail->save();
return false;
}
$customer_mail->send = true;
$customer_mail->sent_at = now();
$customer_mail->save();
return true;
}
private function prepareMessageFull($customer_mail, $deep = 0){
$ret = "";
if($deep === 0){
$ret .= $customer_mail->message;
}else{
$ret .= "--------------------------------\n";
$ret .= $customer_mail->is_answer ? "Antwort von: " : "Gesendet an: ";
$ret .= "&lt;".$customer_mail->email."&gt; ".$customer_mail->sent_at."\n";
$ret .= "<strong>".$customer_mail->subject."</strong>\n";
$ret .= $customer_mail->message;
}
if($customer_mail->customer_mail){
$ret .= $this->prepareMessageFull($customer_mail->customer_mail, $deep+1);
}
return $ret;
}
private function prepareContent($booking_fewo, $content){
$content = Placeholder::replaceBookingFewo($booking_fewo, $content);
return $content;
}
private static function prepareContactMails($value){
if(isset($value->customers)){ //&& $value->customer_mail_dir !== NULL
$first_mail = "";
if($value->customer_mail_dir < 10){ // && $value->customer_mail_subdir > 0
$customer_mail_dir = \App\Services\BookingFewo::getCustomerMailDir($value->customer_mail_dir);
$contact_emails = \App\Services\BookingFewo::getCustomerMailEmails($customer_mail_dir, $value->customer_mail_subdir);
if($value->customer_mail_dir == 0){
$value->recipient = Util::_implodeLines($contact_emails);
return $value;
}else{
if($contact_emails && count($contact_emails) > 0) {
$first_mail = array_shift($contact_emails);
if (count($contact_emails) > 0) {
$value->recipient = Util::_implodeLines($contact_emails);
}
}
}
}
foreach ($value->customers as $key=>$val){
$val['email'] = $first_mail;
$value->customers[$key] = $val;
}
}
return $value;
}
public static function loadModal($data)
{
$value = new Collection();
$value->title = "";
$value->subtitle = "";
$value->url = "";
$value->recipient = "";
$value->cc = "";
$value->bcc = "";
$value->lead_title_id = "";
$value->filter_email_templates_directories = EmailTemplate::join('email_template_dirs', 'email_template_dir_id', '=', 'email_template_dirs.id')->get()->pluck('name', 'id')->unique()->toArray();
/*Ansicht*/
if ($data['action'] === "show-customer-mail") {
if (isset($data['customer_mail_id']) && $customer_mail = CustomerFewoMail::find($data['customer_mail_id'])) {
$value->url = $data['url'];
$value->title = "E-Mail Ansicht";
return view("travel.user.booking.mail.modal-show-mail", compact('data', 'value', 'customer_mail'))->render();
}
}
/* neue Mail */
if ($data['action'] === "edit-customer-mail") {
$value->id = $data['id']; //
$customer_mail = CustomerFewoMail::find($value->id);
$booking = $customer_mail->travel_user_booking_fewo;
$value->customer_files = $customer_mail->customer_files;
$value->save_customer_mail_id = $customer_mail->id;
$value->draft = true;
$value->id = $customer_mail->travel_user_booking_fewo_id;
$value->booking = $booking;
$value->show = 'single';
$value->lead_title_id = " - (".$value->booking->invoice_number.")";
$tmp = [];
$tmp['email'] = $booking->travel_user ? $booking->travel_user->email : "";
$tmp['name'] = $booking->travel_user ? $booking->travel_user->first_name . " " . $booking->travel_user->last_name . " | " : "- | ";
$tmp['name'] .= $booking->fewo_lodging_id ? $booking->fewo_lodging->name . " | " : "- | ";
$data['customers'][$booking->id] = $tmp;
$value->customers = $data['customers'];
$value->subject = $customer_mail->subject;
$value->message = $customer_mail->message;
$value->recipient = Util::_implodeLines($customer_mail->recipient);
$value->cc = Util::_implodeLines($customer_mail->cc);
$value->bcc = Util::_implodeLines($customer_mail->bcc);
$value->title = "E-Mail- Nachricht an Kunden senden";
$value->subtitle = "Dem Kunden wird eine E-Mail zugesendet.";
if($customer_mail->reply_id){
$value->title = "E-Mail Antwort an Kunden senden";
$value->subtitle = "Dem Kunden wird eine E-Mail zugesendet, die im System als Antwort gespeichert wird.";
$value->customer_mail = $customer_mail->customer_mail;
}
$value->s_placeholder = "Betreff der E-Mail";
$value->m_placeholder = "Nachricht der E-Mail";
$value->url = $data['url'];
$value->customer_mail_dir = $customer_mail->dir ? $customer_mail->dir : 0;
$value->customer_mail_subdir = $customer_mail->subdir ? $customer_mail->subdir : 0;
return view("travel.user.booking.mail.modal-new-mail", compact('data', 'value'))->render();
}
/* neue Mail */
if ($data['action'] === "new-customer-mail") {
$value->id = "";
$value->draft = false;
$value->lead_title_id = "-";
//singel
if (isset($data['travel_user_booking_fewo_id']) && $booking_fewo = TravelUserBookingFewo::find($data['travel_user_booking_fewo_id'])) {
$value->id = $data['travel_user_booking_fewo_id'];
$value->booking = $booking_fewo;
$value->show = 'single';
$value->draft = true;
$value->lead_title_id = " - (".$value->booking->invoice_number.")";
}else{
//multi
$value->show = 'multi';
}
$value->customers = $data['customers'];
$value->subject = $value->lead_title_id;
$value->message = CMSContent::getContentBySlug('mailvorlage');
$value->s_placeholder = "Betreff der E-Mail";
$value->m_placeholder = "Nachricht der E-Mail";
if(isset($data['customer_mail_id']) && $customer_mail = CustomerFewoMail::find($data['customer_mail_id'])){
$value->subject = "Re: ".Util::_first_replace($customer_mail->subject);
$value->customer_mail = $customer_mail;
}
$value->title = "E-Mail- Nachricht an Kunden senden";
$value->subtitle = "Dem Kunden wird eine E-Mail zugesendet.";
if($data['id'] === 'reply-send'){
$value->title = "E-Mail Antwort an Kunden senden";
$value->subtitle = "Dem Kunden wird eine E-Mail zugesendet, die im System als Antwort gespeichert wird.";
}
$value->url = $data['url'];
$value->customer_mail_dir = isset($data['customer_mail_dir']) ? $data['customer_mail_dir'] : 0;
$value->customer_mail_subdir = isset($data['customer_mail_subdir']) ? $data['customer_mail_subdir'] : 0;
$value = self::prepareContactMails($value);
return view("travel.user.booking.mail.modal-new-mail", compact('data', 'value'))->render();
}
/*Antwort speichern*/
if ($data['action'] === "reply-customer-mail") {
if (isset($data['travel_user_booking_fewo_id']) && $booking_fewo = TravelUserBookingFewo::find($data['travel_user_booking_fewo_id'])) {
$value->id = $data['travel_user_booking_fewo_id'];
$value->draft = false;
$value->booking = $booking_fewo;
$value->message = "";
$value->subject = " - (".$value->booking->invoice_number.")";
$value->lead_title_id = " - (".$value->booking->invoice_number.")";
$value->s_placeholder = "Betreff des Kunden";
$value->m_placeholder = "Nachricht des Kunden";
if(isset($data['customer_mail_id']) && $customer_mail = CustomerFewoMail::find($data['customer_mail_id'])){
$value->subject = "Re: ".Util::_first_replace($customer_mail->subject);
$value->customer_mail = $customer_mail;
}
$value->title = "E-Mail Antwort speichern";
$value->subtitle = "Die E-Mail wird im System gespeichert.";
if($data['id'] === 'reply-save'){
$value->subtitle = "Die E-Mail wird im System als Antwort gespeichert.";
}
$value->url = $data['url'];
$value->show = 'reply';
$value->customer_mail_dir = isset($data['customer_mail_dir']) ? $data['customer_mail_dir'] : 0;
$value->customer_mail_subdir = isset($data['customer_mail_subdir']) ? $data['customer_mail_subdir'] : 0;
$value = self::prepareContactMails($value);
return view("travel.user.booking.mail.modal-new-mail", compact('data', 'value'))->render();
}
}
}
}

View file

@ -3,18 +3,96 @@
namespace App\Repositories;
use App\Models\Booking;
use App\Models\Lead;
use App\Models\LeadNotice;
use App\Models\StatusHistory;
class LeadRepository extends BaseRepository {
public function __construct(Booking $model)
public function __construct(Lead $model)
{
$this->model = $model;
}
public function update($data)
{
return $this->model;
}
public function updateNotice($id, $data){
$model = Lead::findOrFail($id);
if($data['action'] === 'edit_notice' && isset($data['notice_id'])){
$BookingNotice = LeadNotice::findOrFail($data['notice_id']);
$BookingNotice->message = isset($data['lead_notice']) ? $data['lead_notice'] : "";
$BookingNotice->edit_at = now();
$BookingNotice->save();
}else{
//save_notice
LeadNotice::create([
'lead_id' => $model->id,
'from_user_id' => \Auth::user()->id,
'message' => isset($data['lead_notice']) ? $data['lead_notice'] : "",
]
);
}
return $model;
}
public function updateLead($id, $data)
{
$this->model = Lead::findOrFail($id);
$fill = [
'request_date' => _reformat_date($data['request_date']),
'travelperiod_start' => $data['travelperiod_start'] ? _reformat_date($data['travelperiod_start']) : null,
'travelperiod_end' => $data['travelperiod_end'] ? _reformat_date($data['travelperiod_end']) : null,
'travelperiod_length' => $data['travelperiod_length'],
'travelcountry_id' => $data['travelcountry_id'] ? $data['travelcountry_id'] : null,
'travelagenda_id' => $data['travelagenda_id'] ? $data['travelagenda_id'] : null,
'remarks' => $data['remarks'],
'sf_guard_user_id' => $data['sf_guard_user_id'],
'travelcategory_id' => $data['travelcategory_id'] ? $data['travelcategory_id'] : null,
'pax' => $data['pax'],
];
$this->model->fill($fill);
$this->model->save();
return $this->model;
}
public function updateLeadStatus($id, $data)
{
$this->model = Lead::findOrFail($id);
if(isset($data['status'])){
if($data['status']['id'] != $this->model->status_id || $data['status']['remarks'] !== null){
$this->model->status_id = $data['status']['id'];
$this->model->save();
$date = $data['status']['date'] ? _reformat_date($data['status']['date']) : _reformat_date(now());
$this->model->updateNextDueDate($date);
$fill = [
'status_id' => $data['status']['id'],
'lead_id' => $this->model->id,
'sf_guard_user_id' => $this->model->sf_guard_user_id,
'date' => $date,
'remarks' => $data['status']['remarks'],
'target_date' => $this->model->next_due_date,
'created_at' => now(),
];
StatusHistory::create($fill);
}
}
return $this->model;
}

104
app/Services/Lead.php Normal file
View file

@ -0,0 +1,104 @@
<?php
namespace App\Services;
use App\Models\Airline;
use App\Models\CMSContent;
use App\Models\Insurance;
use App\Models\TravelCompany;
class Lead
{
public static function contentFiles(){
$lead_files = CMSContent::where('identifier', '=', 'lead-email-file')->get()->sortByDesc('pos')->pluck('slug', 'id');
return $lead_files;
}
public static function getCustomerMailDirs(){
$customer_mail_dirs = CMSContent::where('identifier', '=', 'customer-lead-mail-dirs')->get()->sortBy('pos');
return $customer_mail_dirs;
}
public static function getCustomerMailDir($id){
return CMSContent::where('identifier', '=', 'customer-lead-mail-dirs')->where('pos', '=', $id)->first();
}
/* public static function getCustomerMailName($customer_mail_dir, $mail_dir_id){
switch ($customer_mail_dir->getArrayContent('model')){
case 'TravelCountry':
$model = \App\Models\Sym\TravelCountry::find($mail_dir_id);
break;
case 'Airline':
$model = Airline::find($mail_dir_id);
break;
case 'Insurance':
$model = Insurance::find($mail_dir_id);
break;
case 'TravelCompany':
$model = TravelCompany::find($mail_dir_id);
break;
default:
return '';
}
if($model){
if($customer_mail_dir->getArrayContent('model') === 'TravelCountry'){
return $model->mail_dir_name;
}
return $model->name;
}
return "";
}
public static function getCustomerMailEmails($customer_mail_dir, $mail_dir_id){
switch ($customer_mail_dir->getArrayContent('model')){
case 'TravelCountry':
$model = \App\Models\Sym\TravelCountry::find($mail_dir_id);
break;
case 'Airline':
$model = Airline::find($mail_dir_id);
break;
case 'Insurance':
$model = Insurance::find($mail_dir_id);
break;
case 'TravelCompany':
$model = TravelCompany::find($mail_dir_id);
break;
default:
//direkt from CMSContent
return $customer_mail_dir->getArrayContent('emails');
}
if($model){
return $model->contact_emails;
}
return [];
}
public static function getFeWoInstructionPDFName($fewo){
return "HINWEISE-FERIENWOHNUNG-".$fewo->pdf_name.".pdf";
}
public static function getFeWoCMSContent($content, $identifier_fewo){
return CMSContent::where('identifier', '=', $identifier_fewo)->where('integer', $content->id)->get()->sortBy('pos');
}
public static function getFeWoCMSContentForPDF($identifier_content, $identifier_fewo){
$pdf_content = [];
$contents = CMSContent::where('identifier', '=', $identifier_content)->get()->sortBy('pos');
foreach ($contents as $content){
if($content->decimal > 0){ //in_pdf
$pdf_content[] = $content;
}
if($fewo_contents = BookingFewo::getFeWoCMSContent($content, $identifier_fewo)){
foreach ($fewo_contents as $fewo_content){
if($fewo_content->decimal > 0){ //in_pdf
$pdf_content[] = $fewo_content;
}
}
}
}
return $pdf_content;
}*/
}