Upload Files Booking, Mails, Attachments,

This commit is contained in:
Kevin Adametz 2020-04-17 15:51:22 +02:00
parent 5daea268f7
commit 68b9d1ff88
92 changed files with 2837 additions and 1778 deletions

View file

@ -4,7 +4,9 @@ namespace App\Http\Controllers;
use App\Models\Booking;
use App\Models\BookingDraftItem;
use App\Models\BookingFile;
use App\Models\Customer;
use App\Repositories\BookingFileRepository;
use App\Repositories\BookingRepository;
use App\Repositories\CustomerMailRepository;
use App\Repositories\DraftRepository;
@ -43,6 +45,7 @@ class BookingController extends Controller
$data = [
'booking' => $booking,
'id' => $id,
];
return view('booking.detail', $data);
@ -186,17 +189,35 @@ 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['email'] = $booking->customer ? $booking->customer->email : "";
$tmp['name'] = $booking->customer ? $booking->customer->firstname." ".$booking->customer->name." | " : "- | ";
$tmp['name'] .= $booking->travel_country_id ? $booking->travel_country->name." | " : "- | ";
$tmp['name'] .= $booking->travelagenda_id ? $booking->travel_agenda->name."" : "-";
$data['customers'][$booking->id] = $tmp;
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['booking_id']) && $booking = Booking::find($data['booking_id'])) {
$tmp = [];
$tmp['email'] = $booking->customer ? $booking->customer->email : "";
$tmp['name'] = $booking->customer ? $booking->customer->firstname . " " . $booking->customer->name . " | " : "- | ";
$tmp['name'] .= $booking->travel_country_id ? $booking->travel_country->name . " | " : "- | ";
$tmp['name'] .= $booking->travelagenda_id ? $booking->travel_agenda->name . "" : "-";
$data['customers'][$booking->id] = $tmp;
}
$ret = CustomerMailRepository::loadModal($data);
}
if($data['action'] === "modal-upload-booking-file") {
$ret = view("booking.upload_modal", compact('data'))->render();
}
if($data['action'] === "upload-booking-file"){
if($data['booking_id']){
$bookingFileRepo = new BookingFileRepository(new BookingFile());
$bookingFileRepo->_set('disk', 'booking');
$bookingFileRepo->_set('booking_id', $data['booking_id']);
$bookingFileRepo->_set('dir', '/files/'.date('Y/m').'/');
$bookingFileRepo->_set('identifier', 'booking');
return $bookingFileRepo->uploadFile(Request::all());
}
}
$ret = CustomerMailRepository::loadModal($data);
}
return response()->json(['response' => $data, 'html'=>$ret]);
}

View file

@ -5,20 +5,16 @@ namespace App\Http\Controllers\CMS;
use App\Http\Controllers\Controller;
use App\Models\CMSContent;
use App\Repositories\CMSFileRepository;
use Request;
use Validator;
class CMSContentController extends Controller
{
/*
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
}
@ -28,13 +24,25 @@ class CMSContentController extends Controller
'contents' => CMSContent::all()->sortByDesc('id')
];
return view('cms.content.all.index', $data);
}
public function store()
{
$data = Request::all();
if(Request::ajax()) {
//upload file
if($data['file']){
$cmsFileRepo = new CMSFileRepository(new CMSContent());
$cmsFileRepo->_set('disk', 'public');
$cmsFileRepo->_set('dir', '/cms_files/'.date('Y/m').'/');
$cmsFileRepo->_set('identifier', 'cms_file');
return $cmsFileRepo->uploadFile(Request::all());
}
return response()->json(['response' => $data, 'html'=>""]);
}
$rules = array(
'name' => 'required',
'field' => 'required',
@ -50,7 +58,6 @@ class CMSContentController extends Controller
//store in cms old Datebase
\App\Models\Sym\CmsContent::create($data);
}else{
$model = CMSContent::find($data['id']);
$model->fill($data);
$model->save();
@ -65,7 +72,7 @@ class CMSContentController extends Controller
}
public function loadModal()
public function loadModal()
{
if(Request::ajax()){
$data = Request::all();
@ -79,16 +86,19 @@ class CMSContentController extends Controller
}
$returnHTML = view("cms.content.all.modal", compact('data','value') )->render();
}
}
return response()->json(['response' => $data, 'html'=>$returnHTML]);
}
}
//public
public function delete($id){
$content = CMSContent::findOrFail($id);
if($content->isFile()){
$content->deleteFile();
}
$content->delete();
\Session()->flash('alert-success', __('Content gelöscht'));
return redirect(route('cms_content_all'));

View file

@ -25,7 +25,6 @@ class CustomerFileController extends Controller
public function __construct(CustomerFileRepository $customerFileRepo)
{
$this->middleware('admin');
$this->customerFileRepo = $customerFileRepo;
}

View file

@ -7,6 +7,7 @@ use App\Models\CustomerFile;
use App\Models\CustomerMail;
use App\Repositories\CustomerMailRepository;
use App\Repositories\CustomerFileRepository;
use App\Services\Util;
use Carbon;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Facades\URL;
@ -53,14 +54,19 @@ class CustomerMailController extends Controller
}
public function store($id)
public function store($id, $action=false)
{
$data = Request::all();
$customer_mail = CustomerMail::findOrFail($id);
if($action === 'move-mail'){
$data['travel_country_id'] = isset($data['travel_country_id']) && $data['travel_country_id'] ? $data['travel_country_id'] : null;
$customer_mail->dir = $data['dir'];
$customer_mail->travel_country_id = $data['travel_country_id'];
$customer_mail->save();
}
return back();
/* $data = Request::all();
\Session()->flash('alert-save', '1');
return redirect(route('lead_detail', [$lead->id]));*/
}
public function delete($id){
@ -201,11 +207,36 @@ class CustomerMailController extends Controller
$status = false;
if(Request::ajax()){
if($data['action'] === 'toggle_important'){
$customer_mail = CustomerMail::find($data['id']);
$customer_mail = CustomerMail::find($data['id']);
$customer_mail->important = ($customer_mail->important ? false : true);
$customer_mail->save();
$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 CustomerFileRepository(new CustomerFile());
$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');
$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]);
}

View file

@ -0,0 +1,91 @@
<?php
namespace App\Http\Controllers;
use Response;
use Storage;
class FileController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
}
public function show($id = null, $disk = null, $do='file')
{
$path = "";
$filename = "";
if ($disk === 'customer'){
$file = \App\Models\CustomerFile::findOrFail($id);
$filename = $file->original_name;
$path = $file->getPath();
}
if ($disk === 'booking'){
$file = \App\Models\BookingFile::findOrFail($id);
$filename = $file->original_name;
$path = $file->getPath();
}
if ($disk === 'cms_file'){
$file = \App\Models\CMSContent::findOrFail($id);
$filename = $file->name;
$path = $file->getPath();
}
if (file_exists($path)) {
if($do === "download"){
return Response::download($path, $filename);
}
return Response::file($path);
}
}
public function showExpert($type = null, $class = null, $year = null, $file = null, $do = null) {
/*if ($type == 'xls') {
$path = storage_path("app/export/");
$filename = $file . '.xls';
}*/
$path = "";
$filename = "";
$headers = [];
if ($class === 'invoices' || $class === 'infos'){
$headers = [
'Content-Type: application/pdf',
'Pragma: no-cache',
'Cache-Control: no-store,no-cache, must-revalidate, post-check=0, pre-check=0'
];
$dir = $year."/";
$filename = $file;
if ($type === 'fewo') {
if(Storage::disk('fewo_invoices')->exists( $dir.$filename )){
$path = Storage::disk('fewo_invoices')->path($dir.$filename);
}
}
if ($type === 'fewo') {
if(Storage::disk('fewo_infos')->exists( $dir.$filename )){
$path = Storage::disk('fewo_infos')->path($dir.$filename);
}
}
}
if (file_exists($path)) {
if($do === "download"){
return Response::download($path, $filename, $headers);
}
if($do === "file"){
return Response::file($path, $headers);
}
}
}
}

View file

@ -8,6 +8,7 @@ use App\Models\CustomerMail;
use App\Models\Status;
use App\Models\Sym\TravelCountry;
use App\Models\TravelAgenda;
use App\Models\TravelCompany;
use App\Repositories\CustomerMailRepository;
use Carbon\Carbon;
use Request;
@ -26,9 +27,8 @@ class RequestController extends Controller
{
$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_travel_company = TravelCompany::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;
@ -43,6 +43,7 @@ class RequestController extends Controller
$data = [
'step' => $step,
'travel_countries' => $travel_countries,
'filter_travel_company' => $filter_travel_company,
'filter_lead_status' => $filter_lead_status,
'filter_paying_out' => $filter_paying_out,
'filter_paying_out_status' => $filter_paying_out_status,
@ -96,7 +97,9 @@ class RequestController extends Controller
if(Request::get('travel_option_agenda_id') != ""){
$query->where('travelagenda_id', '=', Request::get('travel_option_agenda_id'));
}
if(Request::get('travel_option_company_id') != ""){
$query->where('travel_company_id', '=', Request::get('travel_option_company_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'));
@ -276,6 +279,9 @@ class RequestController extends Controller
->addColumn('travelagenda_id', function (Booking $booking) {
return '<span data-order="'.($booking->travelagenda_id ? $booking->travelagenda_id : 0).'">'.($booking->travelagenda_id ? $booking->travel_agenda->name : "-").'</span>';
})
->addColumn('travel_company_id', function (Booking $booking) {
return '<span data-order="'.($booking->travel_company_id ? $booking->travel_company_id : 0).'">'.($booking->travel_company ? $booking->travel_company->name : "-").'</span>';
})
->addColumn('start_date', function (Booking $booking) {
return $booking->getStartDateFormat();
})
@ -300,6 +306,13 @@ class RequestController extends Controller
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>';
}
return '<span data-order="0">-</span>';
@ -367,6 +380,7 @@ class RequestController extends Controller
->orderColumn('id', 'id $1')
->orderColumn('travel_country_id', 'travel_country_id $1')
->orderColumn('travelagenda_id', 'travelagenda_id $1')
->orderColumn('travel_company_id', 'travel_company_id $1')
->orderColumn('sf_guard_user_id', 'sf_guard_user_id $1')
->orderColumn('start_date', 'start_date $1')
->orderColumn('end_date', 'end_date $1')
@ -377,7 +391,7 @@ class RequestController extends Controller
->orderColumn('hold', 'hold $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', 'last_customer_email', 'id', 'travel_documents', 'paying_out', 'paying_out_status', 'airline_id', 'refund', 'hold', 'xx_tkt'])
->rawColumns(['action_lead_edit', 'lead_id', 'participant_firstname', 'participant_name', 'action_booking_edit', 'travel_country_id', 'travelagenda_id', 'travel_company_id', 'sf_guard_user_id', 'lead.status_id', 'last_customer_email', 'id', 'travel_documents', 'paying_out', 'paying_out_status', 'airline_id', 'refund', 'hold', 'xx_tkt'])
->make(true);
}
}