Mails previews, Lead Passolution, Lead Country Files, LeadParticipant

This commit is contained in:
Kevin Adametz 2021-09-17 14:32:51 +02:00
parent 5e3bd3a1ba
commit ae70577289
28 changed files with 596 additions and 97 deletions

View file

@ -52,7 +52,7 @@ class BookingController extends Controller
$data = [
'booking' => $booking,
'id' => $id,
'show_modal_quill_preview' => true,
];
return view('booking.detail', $data);
@ -117,7 +117,6 @@ class BookingController extends Controller
return redirect(route('booking_detail', [$booking->id])."#collapseBookingProvider");
}
if($data['action'] === 'update_booking_participant'){
$booking = $this->bookingRepo->updateBookingParticipant($id, $data);
\Session()->flash('alert-save', '1');
@ -366,7 +365,7 @@ class BookingController extends Controller
if($del === 'booking') {
//$model = Booking::findOrFail($id);
//$model->delete();
\Session()->flash('alert-success', __('Buchung gelöscht sowie die Reservierung im Sterntrous Kalender'));
\Session()->flash('alert-success', __('Löschen noch nicht programmiert'));
}
if($del === 'booking_file'){
$booking_file = BookingFile::findOrFail($id);

View file

@ -2,20 +2,21 @@
namespace App\Http\Controllers;
use Carbon;
use Request;
use Response;
use App\Services\Util;
use App\Models\EmailTemplate;
use App\Services\Placeholder;
use App\Models\CustomerFewoFile;
use App\Models\CustomerFewoMail;
use App\Models\EmailTemplate;
use Illuminate\Support\Facades\URL;
use App\Models\TravelUserBookingFewo;
use App\Models\TravelUserBookingFile;
use Illuminate\Database\Eloquent\Collection;
use App\Repositories\BookingFewoFileRepository;
use App\Repositories\CustomerFewoFileRepository;
use App\Repositories\CustomerFewoMailRepository;
use App\Services\Util;
use Carbon;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Facades\URL;
use Request;
use Response;
class CustomerFewoMailController extends Controller
{
@ -198,7 +199,13 @@ class CustomerFewoMailController extends Controller
$data = Request::all();
$ret = "";
$status = false;
if(Request::ajax()){
if(Request::ajax() && isset($data['action'])){
if($data['action'] === 'load_preview_mail'){
$booking_fewo = TravelUserBookingFewo::findOrFail($data['booking_fewo_id']);
$ret = Placeholder::replaceBookingFewo($booking_fewo, $data['content']);
$data['subject'] = Placeholder::replaceBookingFewo($booking_fewo, $data['subject']);
$status = 'success';
}
if($data['action'] === 'toggle_important'){
$customer_mail = CustomerFewoMail::find($data['id']);
$customer_mail->important = ($customer_mail->important ? false : true);

View file

@ -2,20 +2,22 @@
namespace App\Http\Controllers;
use Carbon;
use Request;
use Response;
use App\Services\Util;
use App\Models\Booking;
use App\Models\Customer;
use App\Models\CustomerFewoMail;
use App\Models\CustomerFile;
use App\Models\CustomerMail;
use App\Models\EmailTemplate;
use App\Repositories\CustomerFewoMailRepository;
use App\Repositories\CustomerMailRepository;
use App\Repositories\CustomerFileRepository;
use App\Services\Util;
use Carbon;
use Illuminate\Database\Eloquent\Collection;
use App\Services\Placeholder;
use App\Models\CustomerFewoMail;
use Illuminate\Support\Facades\URL;
use Request;
use Response;
use App\Repositories\CustomerFileRepository;
use App\Repositories\CustomerMailRepository;
use Illuminate\Database\Eloquent\Collection;
use App\Repositories\CustomerFewoMailRepository;
class CustomerMailController extends Controller
{
@ -216,7 +218,13 @@ class CustomerMailController extends Controller
$data = Request::all();
$ret = "";
$status = false;
if(Request::ajax()){
if(Request::ajax() && isset($data['action'])){
if($data['action'] === 'load_preview_mail'){
$booking = Booking::findOrFail($data['booking_id']);
$ret = Placeholder::replaceBooking($booking, $data['content']);
$data['subject'] = Placeholder::replaceBooking($booking, $data['subject']);
$status = 'success';
}
if($data['action'] === 'toggle_important'){
$customer_mail = CustomerMail::find($data['id']);
$customer_mail->important = ($customer_mail->important ? false : true);

View file

@ -7,6 +7,7 @@ use Request;
use App\Models\Lead;
use App\Models\LeadFile;
use App\Models\LeadNotice;
use App\Models\LeadParticipant;
use App\Models\StatusHistory;
use App\Repositories\LeadRepository;
use App\Repositories\CustomerRepository;
@ -42,11 +43,13 @@ class LeadController extends Controller
}else{
$lead = Lead::findOrFail($id);
$lead->getPassolutionPDF(true);
$id = $lead->id;
}
$data = [
'lead' => $lead,
'id' => $id,
'show_modal_quill_preview' => true,
];
return view('lead.detail', $data);
@ -84,11 +87,34 @@ class LeadController extends Controller
\Session()->flash('alert-save', '1');
return redirect(route('lead_detail', [$lead->id])."#collapseLeadNotice");
}
if($data['action'] === 'update_lead_participant'){
$lead = $this->leadRepo->updateLeadParticipant($id, $data);
\Session()->flash('alert-save', '1');
return redirect(route('lead_detail', [$lead->id])."#collapseBookingParticipant");
}
return back();
}
public function action($action, $id=false){
if(!$lead = Lead::find($id)){
abort(404);
}
if($action === 'lead_participant_add'){
LeadParticipant::create([
'lead_id' => $lead->id,
'nationality_id' => 1,
'participant_salutation_id' => 1,
]);
\Session()->flash('alert-success', __('Neuen Teilnehmer hinzugefügt'));
return redirect(route('lead_detail', [$lead->id])."#collapseLeadParticipant");
}
}
public function getAjaxRequests(){
$data = Request::all();
@ -142,13 +168,19 @@ class LeadController extends Controller
$lead->delete();
\Session()->flash('alert-success', __('Anfrage gelöscht'));
}
if($del === 'passolution_file'){
$lead = Lead::findOrFail($id);
$lead->resyncPassolutionPDF();
\Session()->flash('alert-success', 'Passolution erneuert');
return redirect(route('lead_detail', [$lead->id]).'#collapseLeadFiles');
}
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]));
return redirect(route('lead_detail', [$lead->id]).'#collapseLeadNotice');
}
if($del === 'lead_files'){
@ -159,7 +191,7 @@ class LeadController extends Controller
$fileRepo->delete();
$leadFile->delete();
\Session()->flash('alert-success', 'Datei gelöscht');
return redirect(route('lead_detail', [$lead->id]));
return redirect(route('lead_detail', [$lead->id]).'#collapseLeadFiles');
}
return redirect(route('leads'));
}

View file

@ -11,6 +11,7 @@ use App\Models\LeadFile;
use App\Models\LeadMail;
use App\Models\EmailTemplate;
use App\Services\Placeholder;
use Illuminate\Support\Facades\URL;
use App\Models\TravelUserBookingFewo;
use App\Repositories\LeadFileRepository;
@ -53,8 +54,6 @@ class LeadMailController extends Controller
\Session()->flash('alert-success', __('E-Mail weitergeleitet'));
}
return back();
}
@ -68,7 +67,6 @@ class LeadMailController extends Controller
return back();
}
public function loadModal(){
$data = Request::all();
$ret = "";
@ -184,7 +182,13 @@ class LeadMailController extends Controller
$data = Request::all();
$ret = "";
$status = false;
if(Request::ajax()){
if(Request::ajax() && isset($data['action'])){
if($data['action'] === 'load_preview_mail'){
$lead = Lead::findOrFail($data['lead_id']);
$ret = Placeholder::replaceLead($lead, $data['content']);
$data['subject'] = Placeholder::replaceLead($lead, $data['subject']);
$status = 'success';
}
if($data['action'] === 'toggle_important'){
$lead_mail = LeadMail::find($data['id']);
$lead_mail->important = ($lead_mail->important ? false : true);

View file

@ -76,6 +76,7 @@ class TravelUserBookingFewoController extends Controller
'max_adults' => $max_adults,
'max_children' => $max_children,
'id' => $id,
'show_modal_quill_preview' => true,
];
return view('travel.user.booking.detail', $data);
}
@ -258,7 +259,7 @@ class TravelUserBookingFewoController extends Controller
$travel_user_booking_fewo = $booking_fewo_notice->travel_user_booking_fewo;
$booking_fewo_notice->delete();
\Session()->flash('alert-success', 'Notiz gelöscht');
return redirect(route('travel_user_booking_fewo_detail', [$travel_user_booking_fewo->id]));
return redirect(route('travel_user_booking_fewo_detail', [$travel_user_booking_fewo->id])."#collapseBookingNotice");
}
if($del === 'booking_fewo_files'){
@ -269,7 +270,7 @@ class TravelUserBookingFewoController extends Controller
$fileRepo->delete();
$booking_fewo_file->delete();
\Session()->flash('alert-success', 'Datei gelöscht');
return redirect(route('travel_user_booking_fewo_detail', [$travel_user_booking_fewo->id]));
return redirect(route('travel_user_booking_fewo_detail', [$travel_user_booking_fewo->id]).'#collapseBookingFiles');
}
return redirect(route('travel_user_booking_fewos'));
}

View file

@ -6,10 +6,11 @@
namespace App\Models;
use App\Models\Lead as ModelsLead;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Collection;
use App\Services\Passolution;
use App\Models\Lead as ModelsLead;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Collection;
/**
* Class Lead
@ -153,7 +154,8 @@ class Lead extends Model
'participant_birthdate',
'participant_salutation_id'
];
protected $passolutionPDFs = [];
public static $lead_mail_dirs = [
11 => ['name' => 'Entwürfe', 'icon'=>'ion-md-create'],
12 => ['name' => 'Papierkorb', 'icon'=>'ion-md-trash'],
@ -340,4 +342,45 @@ class Lead extends Model
}
return $this->lead_mails->where('dir', $dir)->count();
}
public function getPassolutionPDF($create = false, $resync = false){
$nats = [];
if(count($this->passolutionPDFs)){
return $this->passolutionPDFs;
}
if(!$this->travel_country){
return $this->passolutionPDFs;
}
$destco = $this->travel_country->destco;
//default no travel_nationality
$nats['de'] = 'de';
if($this->lead_participants->count()){
foreach ($this->lead_participants as $participant){
if($participant->travel_nationality){
$nats[$participant->travel_nationality->nat] = $participant->travel_nationality->nat;
}
}
}
if(empty($nats)){
$nats['de'] = 'de';
}
foreach ($nats as $nat){
$data = [
'nat' => $nat,
'destco' => $destco,
];
$passolution = new Passolution($data);
$this->passolutionPDFs[] = $passolution->findOrCreatePDF($create, $resync);
}
return $this->passolutionPDFs;
}
public function resyncPassolutionPDF(){
return $this->getPassolutionPDF(true, true);
}
}

View file

@ -53,7 +53,9 @@ class LeadParticipant extends Model
'participant_name',
'participant_firstname',
'participant_birthdate',
'participant_salutation_id'
'participant_salutation_id',
'participant_child',
'nationality_id'
];
public function lead()
@ -65,4 +67,9 @@ class LeadParticipant extends Model
{
return $this->belongsTo(Salutation::class, 'participant_salutation_id');
}
public function travel_nationality()
{
return $this->belongsTo(TravelNationality::class, 'nationality_id');
}
}

View file

@ -5,6 +5,7 @@ namespace App\Repositories;
use App\Models\Lead;
use App\Models\LeadNotice;
use App\Models\LeadParticipant;
use App\Models\StatusHistory;
class LeadRepository extends BaseRepository {
@ -42,7 +43,6 @@ class LeadRepository extends BaseRepository {
return $model;
}
public function updateLead($id, $data)
{
$this->model = Lead::findOrFail($id);
@ -91,9 +91,34 @@ class LeadRepository extends BaseRepository {
StatusHistory::create($fill);
}
}
return $this->model;
}
public function updateLeadParticipant($id, $data){
$this->model = Lead::findOrFail($id);
if(isset($data['participant'])){
foreach($data['participant'] as $p_id => $fill){
$Participant = LeadParticipant::findOrFail($p_id);
if($Participant->lead_id !== $this->model->id){
abort(500);
}
$fill['participant_child'] = isset($fill['participant_child']) ? true : false;
$fill['participant_birthdate'] = isset($fill['participant_birthdate']) ? _reformat_date($fill['participant_birthdate']) : null;
$Participant->fill($fill);
$Participant->save();
}
}
//main
$this->model->participant_salutation_id = isset($data['participant_salutation_id']) ? $data['participant_salutation_id'] : null;
$this->model->participant_name = isset($data['participant_name']) ? $data['participant_name'] : null;
$this->model->participant_firstname = isset($data['participant_firstname']) ? $data['participant_firstname'] : null;
//$this->model->nationality_id = isset($data['nationality_id']) ? $data['nationality_id'] : null;
$this->model->participant_birthdate = isset($data['participant_birthdate']) ? _reformat_date($data['participant_birthdate']) : null;
$this->model->save();
return $this->model;
}
}

View file

@ -9,7 +9,7 @@ use App\Models\Lead;
class Placeholder
{
public static $booking = [
public static $placeholder_booking = [
'dear' => '#geehrte/r#',
'salutation' => '#Anrede#',
'title' => '#Titel#',
@ -24,9 +24,51 @@ class Placeholder
'airline' => '#Airline#'
];
public static function getBookingQuill(){
public static $placeholder_lead = [
'dear' => '#geehrte/r#',
'salutation' => '#Anrede#',
'title' => '#Titel#',
'first_name' => '#Vorname#',
'last_name' => '#Nachname#',
'country' => '#Reiseland#',
'program' => '#Programm#',
'start_date' => '#Anreisedatum#',
'end_date' => '#Abreisedatum#',
'participants' => '#Teilnehmer#',
'booking_date' => '#Buchungsdatum#',
];
public static $placeholder_fewo= [
'dear' => '#geehrte/r#',
'salutation' => '#Anrede#',
'title' => '#Titel#',
'first_name' => '#Vorname#',
'last_name' => '#Nachname#',
'program' => '#Programm#',
'start_date' => '#Anreisedatum#',
'end_date' => '#Abreisedatum#',
'booking_date' => '#Buchungsdatum#',
];
public static function getOptionsQuill($key){
$ret = "";
foreach (self::$booking as $key => $value) {
switch ($key) {
case 'booking':
$placehoder = self::$placeholder_booking;
break;
case 'lead':
$placehoder = self::$placeholder_lead;
break;
case 'fewo':
$placehoder = self::$placeholder_fewo;
break;
default:
$placehoder = self::$placeholder_booking;
break;
}
foreach ($placehoder as $key => $value) {
$value = str_replace('#', '', $value);
$ret .= "{id: '".$value."', label: '".$value."'},"."\n";
}
@ -35,12 +77,31 @@ class Placeholder
public static function getBookingOptions(){
$ret = "";
foreach (self::$booking as $key => $value) {
foreach (self::$placeholder_booking as $key => $value) {
$value = str_replace('#', '', $value);
$ret .= '<option value="'.$value.'">'.$value.'</option>'."\n";
}
return $ret;
}
public static function getLeadOptions(){
$ret = "";
foreach (self::$placeholder_lead as $key => $value) {
$value = str_replace('#', '', $value);
$ret .= '<option value="'.$value.'">'.$value.'</option>'."\n";
}
return $ret;
}
public static function getFewoOptions(){
$ret = "";
foreach (self::$placeholder_fewo as $key => $value) {
$value = str_replace('#', '', $value);
$ret .= '<option value="'.$value.'">'.$value.'</option>'."\n";
}
return $ret;
}
public static function replaceBooking(Booking $booking, $content)
{
@ -50,7 +111,7 @@ class Placeholder
$title = $booking->customer->title;
$country = $booking->travel_country_id ? $booking->travel_country->name : "-";
$program = $booking->travelagenda_id ? $booking->travel_agenda->name : "-";
$salutation = isset($booking->customer->salutation) ? $booking->customer->salutation->name : '';
$salutation = isset($booking->customer->salutation) ? $booking->customer->salutation->name : '-';
$start_date = $booking->getStartDateFormat();
$end_date = $booking->getEndDateFormat();
$booking_date = $booking->getBookingDateFormat();
@ -78,7 +139,7 @@ class Placeholder
$search = [];
$replace = [];
foreach (self::$booking as $key => $value) {
foreach (self::$placeholder_booking as $key => $value) {
$search[] = $value;
$replace[] = ${$key};
}
@ -94,18 +155,14 @@ class Placeholder
$first_name = $booking_fewo->travel_user->first_name;
$last_name = $booking_fewo->travel_user->last_name;
$title = $booking_fewo->travel_user->title;
$country = "";
$program = $booking_fewo->fewo_lodging_id ? $booking_fewo->fewo_lodging->name : "-";
$salutation = $booking_fewo->travel_user->salutation_id == 1 ? 'Herr' : 'Frau';
$start_date = $booking_fewo->from_date;
$end_date = $booking_fewo->to_date;
$booking_date = $booking_fewo->booking_date;
$participants = "";
$airline = "";
$search = [];
$replace = [];
foreach (self::$booking as $key => $value) {
foreach (self::$placeholder_fewo as $key => $value) {
$search[] = $value;
$replace[] = ${$key};
}
@ -121,14 +178,13 @@ class Placeholder
$first_name = $lead->customer->firstname;
$last_name = $lead->customer->name;
$title = $lead->customer->title;
$country = "";
$program = "";
$country = $lead->travelcountry_id ? $lead->travel_country->name : "-";
$program = $lead->travelagenda_id ? $lead->travel_agenda->name : "-";
$salutation = $lead->customer->salutation_id == 1 ? 'Herr' : 'Frau';
$start_date = $lead->travelperiod_start ? _format_date($lead->travelperiod_start) : '';
$end_date = $lead->travelperiod_end ? _format_date($lead->travelperiod_end) : '';
$booking_date = $lead->request_date ? _format_date($lead->request_date) : '';
$start_date = $lead->travelperiod_start ? _format_date($lead->travelperiod_start) : '-';
$end_date = $lead->travelperiod_end ? _format_date($lead->travelperiod_end) : '-';
$booking_date = $lead->request_date ? _format_date($lead->request_date) : '-';
$participants = "";
$airline = "";
if($lead->lead_participants->count()){
$participants = "Teilnehmer:<br>";
foreach($lead->lead_participants as $participant){
@ -140,12 +196,9 @@ class Placeholder
$participants .= '<br>';
}
}
$search = [];
$replace = [];
foreach (self::$booking as $key => $value) {
foreach (self::$placeholder_lead as $key => $value) {
$search[] = $value;
$replace[] = ${$key};
}