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

@ -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);
}
}*/
}