Mails, Strono, filter

This commit is contained in:
Kevin Adametz 2020-03-26 09:48:19 +01:00
parent f53f17f9c1
commit 62e84637b6
99 changed files with 2409 additions and 474 deletions

View file

@ -4,7 +4,9 @@ namespace App\Http\Controllers;
use App\Models\Booking;
use App\Models\BookingDraftItem;
use App\Models\Customer;
use App\Repositories\BookingRepository;
use App\Repositories\CustomerMailRepository;
use Request;
class BookingController extends Controller
@ -184,6 +186,25 @@ class BookingController extends Controller
}
public function loadModal(){
$data = Request::all();
$ret = "";
if(Request::ajax()){
$data['customers'] = [];
if($data['action'] === "new-customer-mail" && isset($data['booking_id']) && $booking = Booking::find($data['booking_id'])){
$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."" : "-";
$data['customers'][$booking->id] = $tmp;
}
$ret = CustomerMailRepository::loadModal($data);
}
return response()->json(['response' => $data, 'html'=>$ret]);
}
public function draftItemDelete($id){
$boking_draft_item = BookingDraftItem::findOrFail($id);
$booking = $boking_draft_item->booking;

View file

@ -3,10 +3,15 @@
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
{
@ -37,9 +42,12 @@ class CustomerMailController extends Controller
$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);
@ -61,6 +69,56 @@ class CustomerMailController extends Controller
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');
@ -109,6 +167,25 @@ class CustomerMailController extends Controller
->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);
}
}

View file

@ -3,11 +3,11 @@
namespace App\Http\Controllers;
use App\Models\Booking;
use App\Models\Status;
use App\Models\Sym\TravelCountry;
use App\Models\TravelAgenda;
use App\Repositories\CustomerMailRepository;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Collection;
use Request;
use DataTables;
@ -23,22 +23,36 @@ class RequestController extends Controller
public function index($step = false)
{
$d = Booking::join('travel_country', 'travel_country_id', '=', 'travel_country.id')->get()->pluck('name', 'travel_country_id')->unique()->toArray();
$travel_countries = Booking::join('travel_country', 'travel_country_id', '=', 'travel_country.id')->get()->pluck('name', 'travel_country_id')->unique()->toArray();
$filter_lead_status = Status::get()->pluck('name', 'id')->toArray();
$filter_paying_out = Booking::$paying_out_types;
$filter_paying_out_status = Booking::$paying_out_status_types;
$filter_refund = Booking::$refund_types;
$filter_xx_tkt = Booking::$xx_tkt_types;
unset($filter_paying_out[0]);
unset($filter_refund[0]);
unset($filter_xx_tkt[0]);
$data = [
'step' => $step,
'travel_countries' => $d,
'travel_countries' => $travel_countries,
'filter_lead_status' => $filter_lead_status,
'filter_paying_out' => $filter_paying_out,
'filter_paying_out_status' => $filter_paying_out_status,
'filter_refund' => $filter_refund,
'filter_xx_tkt' => $filter_xx_tkt,
];
return view('request.index', $data);
}
public function detail($id)
{
$d = Booking::join('travel_country', 'travel_country_id', '=', 'travel_country.id')->get()->pluck('name', 'travel_country_id')->unique()->toArray();
$travel_countries = Booking::join('travel_country', 'travel_country_id', '=', 'travel_country.id')->get()->pluck('name', 'travel_country_id')->unique()->toArray();
$data = [
'travel_countries' => $d,
'travel_countries' => $travel_countries,
];
return view('request.index', $data);
}
@ -59,7 +73,7 @@ class RequestController extends Controller
*/
private function getSearchRequests(){
$query = Booking::where('lead_id', '!=', NULL);
$query = Booking::with('lead')->where('lead_id', '!=', NULL);
if(Request::get('full_firstname_search') != ""){
$query->where('participant_firstname', 'LIKE', '%'.Request::get('full_firstname_search').'%');
@ -69,18 +83,34 @@ class RequestController extends Controller
$query->where('participant_name', 'LIKE', '%'.Request::get('full_lastname_search').'%');
}
if(Request::get('travel_option_country_id') != ""){
$country_ids = TravelCountry::where('contact_lands', 'LIKE', '%"'.Request::get('travel_option_country_id').'"%')->get()->pluck('id');
$country_ids[] = Request::get('travel_option_country_id');
$query->whereIn('travel_country_id', $country_ids);
}
if(Request::get('travel_option_agenda_id') != ""){
$query->where('travelagenda_id', '=', Request::get('travel_option_agenda_id'));
}
if(Request::get('travel_option_lead_status_id') != ""){
$query->whereHas('lead', function ($q) {
$q->where('status_id', '=', Request::get('travel_option_lead_status_id'));
});
}
if(Request::get('travel_option_paying_out') != ""){
$query->where('paying_out', '=', Request::get('travel_option_paying_out'));
}
if(Request::get('travel_option_paying_out_status') != ""){
$query->where('paying_out_status', '=', Request::get('travel_option_paying_out_status'));
}
if(Request::get('travel_option_refund') != ""){
$query->where('refund', '=', Request::get('travel_option_refund'));
}
if(Request::get('travel_option_xx_tkt') != ""){
$query->where('xx_tkt', '=', Request::get('travel_option_xx_tkt'));
}
// $query->where('end_date', '<=', $now);
if(Request::get('travel_option_search')){
$now = Carbon::now();
@ -172,7 +202,6 @@ class RequestController extends Controller
$query->where('travel_documents', '=', Request::get('sort_travel_documents'));
}
if(Request::get('full_lead_id_search') != ""){
$query->where('lead_id', 'LIKE', '%'.Request::get('full_lead_id_search'). '%');
}
@ -194,8 +223,7 @@ class RequestController extends Controller
$data = Request::all();
$ret = "";
if(Request::ajax()){
$customers = [];
$data['customers'] = [];
$query = $this->getSearchRequests();
$bookings = $query->orderBy('id', 'DESC')->limit(50)->get();
foreach ($bookings as $booking){
@ -204,41 +232,19 @@ class RequestController extends Controller
$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;
$data['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("request.modal-mail", compact('data','value', 'url') )->render();
}
$ret = CustomerMailRepository::loadModal($data);
}
return response()->json(['response' => $data, 'html'=>$ret]);
}
public function sendCustomerMail(CustomerMailRepository $customerMailRepository){
$data = Request::all();
$customerMailRepository->sendAndStore($data);
\Session()->flash('alert-success', "Mails gesendet!");
return back();
}
public function getRequests()
{
$query = $this->getSearchRequests();
return \DataTables::eloquent($query)
return DataTables::eloquent($query)
->addColumn('action_lead_edit', function (Booking $booking) {
return '<a href="' . route('booking_detail', [$booking->id]) . '" class="btn icon-btn btn-sm btn-primary"><span class="fa fa-edit"></span></a>';
})
@ -276,7 +282,56 @@ class RequestController extends Controller
return '<span data-order="'.($booking->sf_guard_user_id ? $booking->sf_guard_user_id : 0).'">'.($booking->sf_guard_user_id? $booking->sf_guard_user->first_name." ".$booking->sf_guard_user->last_name : "-").'</span>';
})
->addColumn('lead.status_id', function (Booking $booking) {
return '<span data-order="'.($booking->lead->status_id ? $booking->lead->status_id : 0).'">'.($booking->lead->status_id ? $booking->lead->status->name : "-").'</span>';
//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> ';
}
return '<span data-order="'.$booking->lead->status_id.'"><span class="badge badge-dark" style="background-color: '.$color.'">'.$icon.$booking->lead->status->name.'</span></span>';
}
return '<span data-order="0">-</span>';
})
->addColumn('last_customer_email', function (Booking $booking) {
//umbuchen
if($booking->customer_mails->count()){
$customer_mail = $booking->customer_mails_sent_at->last();
return '<a href="'.route('booking_detail', [$booking->id]).'#collapseBookingMails" data-order="'.$customer_mail->sent_at.'"><span class="badge '.($customer_mail->is_answer ? 'badge-default' : 'badge-secondary').'">'.$customer_mail->sent_at.'</span></a>';
}
return '<span data-order="0">-</span>';
})
->addColumn('paying_out', function (Booking $booking) {
$icon = "";
$badge = $booking->getPayingOutColor();
if($booking->paying_out_status == 1){ //offen
$icon = '<i class="fa fa-times-circle"></i> ';
}
if($booking->paying_out_status == 2){ //erledigt
$badge = 'success';
$icon = '<i class="fa fa-check-circle"></i> ';
}
return '<span data-order="'.$booking->paying_out.'"><span class="badge badge-'.$booking->getPayingOutColor().'">'.$icon.$booking->getPayingOutType().'</span></span>';
})
->addColumn('paying_out_status', function (Booking $booking) {
return '<span data-order="'.$booking->paying_out_status.'"><span class="badge badge-'.$booking->getPayingOutStatusColor().'">'.$booking->getPayingOutStatusType().'</span></span>';
})
->addColumn('refund', function (Booking $booking) {
return '<span data-order="'.$booking->refund_date.'"><span class="badge badge-'.$booking->getRefundColor().'">'.$booking->getRefundTypeList().'</span></span>';
})
->addColumn('xx_tkt', function (Booking $booking) {
return '<span data-order="'.$booking->xx_tkt_date.'"><span class="badge badge-'.$booking->getXxTktColor().'">'.$booking->getXxTktTypeList().'</span></span>';
})
/* ->filterColumn('travel_country_id', function($query, $keyword) {
@ -301,8 +356,12 @@ class RequestController extends Controller
->orderColumn('sf_guard_user_id', 'sf_guard_user_id $1')
->orderColumn('start_date', 'start_date $1')
->orderColumn('end_date', 'end_date $1')
->orderColumn('paying_out', 'paying_out $1')
->orderColumn('paying_out_status', 'paying_out_status $1')
->orderColumn('refund', 'refund_date $1')
->orderColumn('xx_tkt', 'xx_tkt_date $1')
->orderColumn('travel_documents', 'travel_documents $1')
->rawColumns(['action_lead_edit', 'lead_id', 'participant_firstname', 'participant_name', 'action_booking_edit', 'travel_country_id', 'travelagenda_id', 'sf_guard_user_id', 'lead.status_id', 'id', 'travel_documents'])
->rawColumns(['action_lead_edit', 'lead_id', 'participant_firstname', 'participant_name', 'action_booking_edit', 'travel_country_id', 'travelagenda_id', 'sf_guard_user_id', 'lead.status_id', 'last_customer_email', 'id', 'travel_documents', 'paying_out', 'paying_out_status', 'refund', 'xx_tkt'])
->make(true);
}
}

View file

@ -0,0 +1,60 @@
<?php
namespace App\Http\Controllers\Settings;
use App\Http\Controllers\Controller;
use App\Models\Status;
use App\Models\TravelNationality;
use App\Models\TravelNationalityRequirement;
use Request;
class BookingStatusController extends Controller
{
public function __construct()
{
$this->middleware('admin');
}
public function index($step = false)
{
$data = [
'status' => Status::all(),
];
return view('settings.status.index', $data);
}
public function update(){
$data = Request::all();
if($data['id'] === "new"){
$model = Status::create([
'name' => $data['name'],
'color' => $data['color'],
'handling_days' => $data['handling_days'],
]);
}else{
$model = Status::find($data['id']);
$model->name = $data['name'];
$model->color = $data['color'];
$model->handling_days = $data['handling_days'];
$model->save();
}
\Session()->flash('alert-save', '1');
return redirect(route('admin_settings_booking_status'));
}
public function delete($id){
$model = Status::findOrFail($id);
$model->delete();
\Session()->flash('alert-success', 'Eintrag gelöscht');
return redirect()->back();
}
}

View file

@ -28,7 +28,7 @@ class TravelAgendaController extends Controller
public function update(){
$data = Request::all();
if($data['id'] == "new"){
if($data['id'] === "new"){
$model = TravelAgenda::create([
'name' => $data['name'],
'active' => isset($data['active']) ? true : false,

View file

@ -12,23 +12,39 @@ class MailSendInfo extends Mailable
{
use Queueable, SerializesModels;
protected $travel_user_booking_fewo;
public $subject;
protected $content;
public $files;
public function __construct($subject, $content)
public function __construct($subject, $content, $files = [])
{
$this->subject = $subject;
$this->content = $content;
$this->files = $files;
}
public function build()
{
return $this->view('emails.content')->with([
$message = $this->view('emails.content')->with([
'content' => $this->content,
'greetings' => __('Best regards'),
]);
/* foreach ($this->files as $file) {
$message->attach($file->getPath(),[
'as' => $file->original_name,
'mime' => $file->mine,
]); // attach each file
}*/
foreach ($this->files as $file) {
$message->attach((string) $file->getPath()); // attach each file
}
return $message;
}
}

View file

@ -142,15 +142,20 @@ class Booking extends Model
'price_total' => 'float',
'deposit_total' => 'float',
'final_payment' => 'float',
'travelagenda_id' => 'int'
];
'travelagenda_id' => 'int',
'paying_out' => 'int',
'refund' => 'int',
'xx_tkt' => 'int',
];
protected $dates = [
'booking_date',
'start_date',
'end_date',
'participant_birthdate',
'final_payment_date'
'final_payment_date',
'refund_date'
];
protected $fillable = [
@ -184,9 +189,69 @@ class Booking extends Model
'deposit_total',
'final_payment',
'final_payment_date',
'travelagenda_id'
'travelagenda_id',
'paying_out',
'paying_out_status',
'refund',
'refund_date',
'xx_tkt',
'xx_tkt_date',
];
public static $paying_out_types = [
0 => '-',
1 => 'Gutschein',
2 => 'Auszahlung',
3 => 'Umbuchung',
4 => 'AZ + GS',
5 => 'AZ o. FP',
];
public static $refund_types = [
0 => '-',
1 => 'eingereicht',
2 => 'erledigt',
];
public static $xx_tkt_types = [
0 => '-',
1 => 'offen',
2 => 'erledigt',
];
public static $paying_out_status_types = [
0 => '-',
1 => 'offen',
2 => 'erledigt',
];
protected $paying_out_colors = [
0 => '',
1 => 'info',
2 => 'dark',
3 => 'warning',
4 => 'warning',
5 => 'warning',
];
protected $refund_colors = [
0 => '',
1 => 'warning',
2 => 'success',
];
protected $xx_tkt_colors = [
0 => '',
1 => 'danger',
2 => 'success',
];
protected $paying_out_status_colors = [
0 => '',
1 => 'danger',
2 => 'success',
];
/*public function branch()
{
return $this->belongsTo(Branch::class);
@ -297,6 +362,17 @@ class Booking extends Model
{
return $this->hasMany(ServiceProviderEntry::class);
}
public function customer_mails()
{
return $this->hasMany(CustomerMail::class, 'booking_id', 'id');
}
public function customer_mails_sent_at()
{
return $this->hasMany(CustomerMail::class, 'booking_id')->orderBy('sent_at', 'ASC');
}
/*
public function travel_insurances()
{
@ -437,4 +513,57 @@ class Booking extends Model
return $this->ev_number;
}
public function getPayingOutType(){
return isset(self::$paying_out_types[$this->paying_out]) ? self::$paying_out_types[$this->paying_out] : '-';
}
public function getPayingOutStatusType(){
return isset(self::$paying_out_status_types[$this->paying_out_status]) ? self::$paying_out_status_types[$this->paying_out_status] : '-';
}
public function getRefundType(){
return isset(self::$refund_types[$this->refund]) ? self::$refund_types[$this->refund] : '-';
}
public function getXxTktType(){
return isset(self::$xx_tkt_types[$this->xx_tkt]) ? self::$xx_tkt_types[$this->xx_tkt] : '-';
}
public function getXxTktTypeList(){
if(isset(self::$xx_tkt_types[$this->xx_tkt])){
if($this->xx_tkt == 1 && $this->xx_tkt_date){
return Carbon::parse($this->xx_tkt_date)->format('d.m.Y');
}
return self::$xx_tkt_types[$this->xx_tkt];
}
return "-";
}
public function getRefundTypeList(){
if(isset(self::$refund_types[$this->refund])){
if($this->refund == 1 && $this->refund_date){
return Carbon::parse($this->refund_date)->format('d.m.Y');
}
return self::$refund_types[$this->refund];
}
return "-";
}
public function getPayingOutColor(){
return isset($this->paying_out_colors[$this->paying_out]) ? $this->paying_out_colors[$this->paying_out] : '';
}
public function getPayingOutStatusColor(){
return isset($this->paying_out_status_colors[$this->paying_out_status]) ? $this->paying_out_status_colors[$this->paying_out_status] : '';
}
public function getRefundColor(){
return isset($this->refund_colors[$this->refund]) ? $this->refund_colors[$this->refund] : '-';
}
public function getXxTktColor(){
return isset($this->xx_tkt_colors[$this->xx_tkt]) ? $this->xx_tkt_colors[$this->xx_tkt] : '-';
}
}

View file

@ -72,7 +72,8 @@ class Coupon extends Model
'issue_date',
'valid_date',
'is_redeemed',
'redeem_date'
'redeem_date',
'text'
];
public function booking()

106
app/Models/CustomerFile.php Normal file
View file

@ -0,0 +1,106 @@
<?php
/**
* Created by Reliese Model.
*/
namespace App\Models;
use Carbon\Carbon;
use Reliese\Database\Eloquent\Model;
/**
* Class CustomerFile
*
* @property int $id
* @property int $customer_id
* @property int $customer_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 Customer $customer
* @property CustomerMail $customer_mail
*
* @package App\Models
*/
class CustomerFile extends Model
{
protected $connection = 'mysql';
protected $table = 'customer_files';
protected $casts = [
'customer_id' => 'int',
'customer_mail_id' => 'int',
'size' => 'int'
];
public static $icon_ext = [
'default' => 'fa fa-file',
'pdf'=> 'fa fa-file-pdf',
'jpg'=> 'fa fa-file-image',
'png'=> 'fa fa-file-image',
];
protected $fillable = [
'customer_id',
'customer_mail_id',
'identifier',
'filename',
'dir',
'original_name',
'ext',
'mine',
'size'
];
public function customer()
{
return $this->belongsTo(Customer::class);
}
public function customer_mail()
{
return $this->belongsTo(CustomerMail::class);
}
public function user()
{
return $this->belongsTo(User::class);
}
public function getIconExt(){
return isset(self::$icon_ext[$this->ext]) ? self::$icon_ext[$this->ext] : self::$icon_ext['default'];
}
public function getURL(){
return route('storage_file', [$this->id, 'customer']);
}
public function getPath(){
return \Storage::disk('customer')->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;
}
}
}

View file

@ -7,15 +7,19 @@
namespace App\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Collection;
use Reliese\Database\Eloquent\Model;
/**
* Class CustomerMail
*
*
* @property int $id
* @property int $booking_id
* @property int $customer_id
* @property int $lead_id
* @property bool $is_answer
* @property int $reply_id
* @property string $email
* @property string $subject
* @property string $message
* @property bool $send
@ -26,28 +30,15 @@ use Reliese\Database\Eloquent\Model;
* @property Carbon $delivered_at
* @property Carbon $created_at
* @property Carbon $updated_at
*
* @property Booking $booking
* @property Customer $customer
* @property CustomerMail $customer_mail
* @property Lead $lead
* @property Collection|CustomerFile[] $customer_files
* @property Collection|CustomerMail[] $customer_mails
*
* @package App\Models
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CustomerMail newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CustomerMail newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CustomerMail query()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CustomerMail whereBookingId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CustomerMail whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CustomerMail whereCustomerId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CustomerMail whereDeliveredAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CustomerMail whereError($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CustomerMail whereFail($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CustomerMail whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CustomerMail whereLeadId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CustomerMail whereMessage($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CustomerMail whereScheduledAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CustomerMail whereSend($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CustomerMail whereSentAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CustomerMail whereSubject($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CustomerMail whereUpdatedAt($value)
* @mixin \Eloquent
*/
class CustomerMail extends Model
{
@ -57,6 +48,8 @@ class CustomerMail extends Model
'booking_id' => 'int',
'customer_id' => 'int',
'lead_id' => 'int',
'is_answer' => 'bool',
'reply_id' => 'int',
'send' => 'bool',
'fail' => 'bool'
];
@ -71,7 +64,9 @@ class CustomerMail extends Model
'booking_id',
'customer_id',
'lead_id',
'email',
'is_answer',
'reply_id',
'email',
'subject',
'message',
'send',
@ -92,11 +87,27 @@ class CustomerMail extends Model
return $this->belongsTo(Customer::class);
}
public function customer_mail()
{
return $this->belongsTo(CustomerMail::class, 'reply_id');
}
public function lead()
{
return $this->belongsTo(Lead::class);
}
public function customer_files()
{
return $this->hasMany(CustomerFile::class);
}
public function customer_mails()
{
return $this->hasMany(CustomerMail::class, 'reply_id');
}
public function getSentAtAttribute(){
if(!$this->attributes['sent_at']){ return ""; }
return Carbon::parse($this->attributes['sent_at'])->format(\Util::formatDateTimeDB());

View file

@ -105,7 +105,8 @@ class Lead extends Model
'travelagenda_id' => 'int',
'sf_guard_user_id' => 'int',
'is_closed' => 'bool',
'initialcontacttype_id' => 'int',
'is_rebook' => 'bool',
'initialcontacttype_id' => 'int',
'searchengine_id' => 'int',
'status_id' => 'int',
'website_id' => 'int',
@ -134,6 +135,7 @@ class Lead extends Model
'remarks',
'sf_guard_user_id',
'is_closed',
'is_rebook',
'initialcontacttype_id',
'searchengine_id',
'searchengine_keywords',

View file

@ -1,25 +1,26 @@
<?php
/**
* Created by Reliese Model.
*/
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Collection;
use Reliese\Database\Eloquent\Model;
/**
* App\Models\Status
*
* Class Status
*
* @property int $id
* @property string $name
* @property int $handling_days
* @property string|null $color
* @property-read \App\Models\Status $status
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Status whereColor($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Status whereHandlingDays($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Status whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Status whereName($value)
* @mixin \Eloquent
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Status newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Status newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Status query()
* @property string $color
*
* @property Collection|Lead[] $leads
* @property Collection|StatusHistory[] $status_histories
*
* @package App\Models
*/
class Status extends Model
{
@ -27,8 +28,25 @@ class Status extends Model
protected $table = 'status';
public function status()
{
return $this->belongsTo('App\Models\Status', 'status_id', 'id');
}
public $timestamps = false;
protected $casts = [
'handling_days' => 'int'
];
protected $fillable = [
'name',
'handling_days',
'color'
];
public function leads()
{
return $this->hasMany(Lead::class);
}
/*public function status_histories()
{
return $this->hasMany(StatusHistory::class);
}*/
}

View file

@ -6,7 +6,9 @@ namespace App\Repositories;
use App\Mail\MailSendFeWoService;
use App\Mail\MailSendInfo;
use App\Models\Booking;
use App\Models\CustomerFile;
use App\Models\CustomerMail;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Facades\Mail;
@ -25,36 +27,80 @@ class CustomerMailRepository extends BaseRepository {
public function sendAndStore($data){
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 = CustomerFile::find($message_attachment_id)){
$customer_files[] = $CustomerFile;
}
}
}
foreach ($data['send_mail_to'] as $booking_id => $on) {
$booking = Booking::find($booking_id);
if ($booking->customer) {
$message = $this->prepareContent($booking, $data['message']);
$subject = $this->prepareContent($booking, $data['subject']);
$customer_mail = $this->store($booking, $subject, $message);
$this->sendMail($customer_mail);
$reply_id = isset($data['customer_mail_id']) ? $data['customer_mail_id'] : NULL;
$customer_mail = $this->store($booking, $subject, $message, $booking->customer->email, false, $reply_id);
$this->sendMail($customer_mail, $customer_files);
foreach ($customer_files as $file) {
$file->customer_id = $booking->customer_id;
$file->customer_mail_id = $customer_mail->id;
$file->save();
}
}
}
}
}
public function store($booking, $subject, $message){
public function replyStore($data){
if(isset($data['booking_id']) && $booking = Booking::find($data['booking_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 = CustomerFile::find($message_attachment_id)){
$customer_files[] = $CustomerFile;
}
}
}
if ($booking->customer) {
$mail_from = isset($data['mail_from']) ? $data['mail_from'] : $booking->customer->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, $data['subject'], $data['message'], $mail_from, true, $reply_id, $sent_at);
foreach ($customer_files as $file) {
$file->customer_id = $booking->customer_id;
$file->customer_mail_id = $customer_mail->id;
$file->save();
}
}
}
}
public function store($booking, $subject, $message, $mail_from, $is_answer = false, $reply_id = NULL, $sent_at=false){
$customer_mail = CustomerMail::create([
'booking_id' => $booking->id,
'customer_id' => $booking->customer_id,
'lead_id' => $booking->lead_id,
'email' => $booking->customer->email,
'is_answer' => $is_answer,
'reply_id' => $reply_id,
'email' => $mail_from,
'subject' => $subject,
'message' => $message,
'sent_at' => $sent_at ? $sent_at : now(),
]);
return $customer_mail;
}
private function sendMail($customer_mail){
private function sendMail($customer_mail, $customer_files){
try{
Mail::to($customer_mail->email)->send(new MailSendInfo($customer_mail->subject, $customer_mail->message));
Mail::to($customer_mail->email)->send(new MailSendInfo($customer_mail->subject, $customer_mail->message, $customer_files));
}
catch(\Exception $e){
// Never reached
@ -68,6 +114,9 @@ class CustomerMailRepository extends BaseRepository {
$customer_mail->save();
return true;
}
private function prepareContent($booking, $content){
$first_name = $booking->customer->firstname;
@ -76,7 +125,6 @@ class CustomerMailRepository extends BaseRepository {
$program = $booking->travelagenda_id ? $booking->travel_agenda->name : "-";
$salutation = $booking->customer->salutation->name;
$dear = $booking->customer->salutation_id == 1 ? 'geehrter' : 'geehrte';
$search = ['#geehrte/r#', '#Anrede#', '#Vorname#', '#Nachname#', '#Reiseland#', '#Programm#'];
$replace = [$dear, $salutation, $first_name, $last_name, $country, $program, $salutation];
@ -86,4 +134,70 @@ class CustomerMailRepository extends BaseRepository {
}
public static function loadModal($data)
{
$value = new Collection();
$value->title = "";
$value->subtitle = "";
$value->url = "";
if ($data['action'] === "new-customer-mail") {
if (isset($data['booking_id'])) {
$value->id = $data['booking_id'];
$value->customers = $data['customers'];
$value->subject = "";
$value->message = "Sehr #geehrte/r# #Anrede# #Vorname# #Nachname#,\n\nText ....";
$value->s_placeholder = "Betreff der E-Mail";
$value->m_placeholder = "Nachricht der E-Mail";
if(isset($data['customer_mail_id']) && $customer_mail = CustomerMail::find($data['customer_mail_id'])){
$value->subject = "Re: ".$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'];
return view("customer.mail.modal-new-mail", compact('data', 'value'))->render();
}
}
if ($data['action'] === "show-customer-mail") {
if (isset($data['customer_mail_id']) && $customer_mail = CustomerMail::find($data['customer_mail_id'])) {
$value->url = $data['url'];
$value->title = "E-Mail Ansicht";
return view("customer.mail.modal-show-mail", compact('data', 'value', 'customer_mail'))->render();
}
}
if ($data['action'] === "reply-customer-mail") {
if (isset($data['booking_id']) && $booking = Booking::find($data['booking_id'])) {
$value->id = $data['booking_id'];
$value->booking = $booking;
$value->message = "";
$value->subject = "";
$value->s_placeholder = "Betreff des Kunden";
$value->m_placeholder = "Nachricht des Kunden";
if(isset($data['customer_mail_id']) && $customer_mail = CustomerMail::find($data['customer_mail_id'])){
$value->subject = "Re: ".$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'];
return view("customer.mail.modal-new-mail", compact('data', 'value'))->render();
}
}
}
}

View file

@ -0,0 +1,147 @@
<?php
namespace App\Repositories;
use App\Models\CustomerFile;
use Request;
use Response;
use Storage;
use Util;
use Validator;
class FileRepository extends BaseRepository {
protected $rules;
protected $messages;
protected $disk;
protected $dir;
protected $customer_id;
protected $customer_mail_id;
protected $identifier;
public function __construct(CustomerFile $model){
$this->model = $model;
$this->rules = [
'file' => 'required|mimes:pdf,jpeg,png|max:32768'
];
$this->messages = [
'file.mimes' => 'Datei ist kein PDF/JPG/PNG Format',
'file.required' => 'PDF/JPG/PNG-Datei wird benötigt'
];
}
public function _set($name, $value){
$this->{$name} = $value;
}
/* public function load($id){
$this->model = $id;
}
*/
public function uploadFile( $form_data )
{
$validator = Validator::make($form_data, $this->rules, $this->messages);
if ($validator->fails()) {
return Response::json([
'error' => true,
'message' => $validator->messages()->first(),
'code' => 400
], 400);
}
$file = $form_data['file'];
$originalName = $file->getClientOriginalName();
$extension = $file->getClientOriginalExtension();
$mine = $file->getClientMimeType();
$size = $file->getClientSize();
$originalNameWithoutExt = substr($originalName, 0, strlen($originalName) - strlen($extension) - 1);
$filename = Util::sanitize($originalNameWithoutExt, true, false, true);
$allowed_filename = uniqid() . '_' . $filename.".".$extension;
//$dir = $this->model->getInvoiceStorageAttDir();
if(!Storage::disk($this->disk)->exists( $this->dir )){
Storage::disk($this->disk)->makeDirectory($this->dir); //creates directory
}
Storage::disk($this->disk)->put($this->dir.$allowed_filename, file_get_contents($file->getRealPath()));
$customer_file = CustomerFile::create([
'customer_id' => $this->customer_id,
'customer_mail_id' => $this->customer_mail_id,
'identifier' => $this->identifier,
'filename' => $allowed_filename,
'dir' => $this->dir,
'original_name' => $originalName,
'ext' => $extension,
'mine' => $mine,
'size' => $size
]);
return Response::json([
'error' => false,
'filename' => $allowed_filename,
'file_id' =>$customer_file->id,
'file_data' => $extension,
'file_icon' => $customer_file->getIconExt(),
'file_format_bytes' => $customer_file->formatBytes(),
'file_url' => $customer_file->getURL(),
'redirect' => '',
'code' => 200
], 200);
}
/* public function createFile(Request $request)
{
$locale = \App::getLocale();
$data = [
'step' => 2,
'locale' => $locale,
];
$rules = array(
'network_name' => 'required|max:255',
'input_file_now' => 'required|mimes:png,pdf,jpg,jpeg|max:30000'
);
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails()) {
// get the error messages from the validator
$messages = $validator->messages();
// redirect our user back to the form with the errors from the validator
return view('user.register_complete', $data)->withErrors($validator);
} else {
$user = \Auth::user();
if(!$user->account->network_name){
$file = request()->file('input_file_now');
//$ext = $file->guessClientExtension();
//$file->storeAs('user/' . $user->id .'/verification');
$data = $file->store('user/' . $user->id .'/verification');
$account = $user->account;
$account->network_name = Input::get('network_name');
$account->network_verification = basename($data);
$account->save();
$user->role_id = 2; //set as User by default!
$user->save();
}
return redirect('complete_register');
//return view('user.register_complete', $data);
}
}*/
}

View file

@ -29,6 +29,14 @@ class Util
return 'd.m.Y - H:i';
}
public static function _format_date($date, $to = 'date'){
if($to === 'datetime'){
return \Carbon::parse($date)->format(\Util::formatDateTimeDB());
}
//date
return \Carbon::parse($date)->format(\Util::formatDateDB());
}
public static function _format_number($value){
return preg_replace("/[^0-9,]/", "", $value);

View file

@ -17,6 +17,13 @@ if (! function_exists('make_v2_url')) {
}
}
if (! function_exists('_format_date')) {
function _format_date($date, $to = 'date')
{
return \App\Services\Util::_format_date($date, $to);
}
}
if (! function_exists('array_to_json')) {
function array_to_json($value)