Fewos in CRM,
Fewo Clients Bookings create / edit / delelte via API in DB
This commit is contained in:
parent
aebfb0586a
commit
c0c2a1822c
55 changed files with 9787 additions and 1486 deletions
104
app/Http/Controllers/API/FewoController.php
Executable file
104
app/Http/Controllers/API/FewoController.php
Executable file
|
|
@ -0,0 +1,104 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\API;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\BookingDraftItem;
|
||||
use App\Models\TravelUser;
|
||||
use App\Models\TravelUserBookingFewo;
|
||||
use Carbon\Carbon;
|
||||
use Validator;
|
||||
|
||||
class FewoController extends Controller
|
||||
{
|
||||
public $successStatus = 200;
|
||||
public $errorStatus = 500;
|
||||
public $data = "";
|
||||
public $room_str = "";
|
||||
public $room_name = "";
|
||||
public $className = "";
|
||||
public $option = "";
|
||||
|
||||
public function action($action)
|
||||
{
|
||||
|
||||
|
||||
|
||||
if ($action == "create_travel_users") {
|
||||
$data = \Input::all();
|
||||
if(!isset($data['travel_user']) && !is_array($data['travel_user'])) {
|
||||
return response()->json(['error' => 'travel_user not exist, but need'], $this->errorStatus);
|
||||
}
|
||||
if(!isset($data['travel_user']['email'])){
|
||||
return response()->json(['error' => 'travel_user email not exist, but need'], $this->errorStatus);
|
||||
}
|
||||
|
||||
$rules = array(
|
||||
'salutation_id' => 'required',
|
||||
'travel_nationality_id' => 'required',
|
||||
'first_name'=>'required',
|
||||
'last_name'=>'required',
|
||||
'email' => 'required|string|email|max:255|'
|
||||
|
||||
);
|
||||
$validator = Validator::make($data['travel_user'], $rules);
|
||||
if ($validator->fails()) {
|
||||
return response()->json($validator->messages(), $this->errorStatus);
|
||||
|
||||
}
|
||||
|
||||
$travel_user = TravelUser::where('email', trim($data['travel_user']['email']))->first();
|
||||
if(!$travel_user) {
|
||||
$travel_user = TravelUser::create($data['travel_user']);
|
||||
}else{
|
||||
$checked = [
|
||||
'salutation_id',
|
||||
'first_name',
|
||||
'last_name',
|
||||
'street',
|
||||
'zipcode',
|
||||
'city',
|
||||
'phone',
|
||||
'fax',
|
||||
'travel_nationality_id'
|
||||
];
|
||||
|
||||
$last_user_data = [];
|
||||
foreach ($checked as $check){
|
||||
if($travel_user->{$check} != $data['travel_user'][$check]){
|
||||
$last_user_data[$check] = $travel_user->{$check};
|
||||
}
|
||||
}
|
||||
$data['travel_user']['last_user_data'] = $last_user_data;
|
||||
$travel_user->fill($data['travel_user'])->save();
|
||||
}
|
||||
return response()->json(['success' => ['travel_user_id' => $travel_user->id]], $this->successStatus);
|
||||
}
|
||||
|
||||
|
||||
if ($action == "create_fewo_booking") {
|
||||
|
||||
$data = \Input::all();
|
||||
if(!isset($data['travel_user_booking_fewo']) && !is_array($data['travel_user_booking_fewo'])) {
|
||||
return response()->json(['error' => 'travel_user_booking_fewo not exist, but need'], $this->errorStatus);
|
||||
}
|
||||
$rules = array(
|
||||
'travel_user_id' => 'required',
|
||||
'fewo_lodging_id' => 'required',
|
||||
'from_date'=>'required',
|
||||
'to_date'=>'required',
|
||||
|
||||
);
|
||||
$validator = Validator::make($data['travel_user_booking_fewo'], $rules);
|
||||
if ($validator->fails()) {
|
||||
return response()->json($validator->messages(), $this->errorStatus);
|
||||
|
||||
}
|
||||
|
||||
$travel_user_booking_fewo = TravelUserBookingFewo::create($data['travel_user_booking_fewo']);
|
||||
|
||||
return response()->json(['success' => ['travel_user_booking_fewo_id' => $travel_user_booking_fewo->id, 'crm_url' => route('travel_user_booking_fewo_detail', [$travel_user_booking_fewo->id])]], $this->successStatus);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
131
app/Http/Controllers/TravelUserBookingFewoController.php
Executable file
131
app/Http/Controllers/TravelUserBookingFewoController.php
Executable file
|
|
@ -0,0 +1,131 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
|
||||
use App\Models\FewoReservation;
|
||||
use App\Models\TravelUser;
|
||||
use App\Models\TravelUserBookingFewo;
|
||||
use Input;
|
||||
use Validator;
|
||||
|
||||
class TravelUserBookingFewoController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('admin');
|
||||
|
||||
}
|
||||
|
||||
public function index($step = false)
|
||||
{
|
||||
$data = [
|
||||
'step' => $step
|
||||
];
|
||||
return view('travel.user.booking.index', $data);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function detail($id)
|
||||
{
|
||||
if($id == "new") {
|
||||
$travel_user_booking_fewo = new TravelUserBookingFewo();
|
||||
$id = 'new';
|
||||
|
||||
}else{
|
||||
$travel_user_booking_fewo = TravelUserBookingFewo::findOrFail($id);
|
||||
$id = $travel_user_booking_fewo->id;
|
||||
}
|
||||
$data = [
|
||||
'travel_user_booking_fewo' => $travel_user_booking_fewo,
|
||||
'id' => $id,
|
||||
];
|
||||
return view('travel.user.booking.detail', $data);
|
||||
|
||||
}
|
||||
|
||||
public function store($id)
|
||||
{
|
||||
$data = Input::all();
|
||||
|
||||
|
||||
$rules = array(
|
||||
'travel_user_id' => 'required',
|
||||
'fewo_lodging_id' => 'required',
|
||||
'from_date'=>'required',
|
||||
'to_date'=>'required',
|
||||
'travel_booking_fewo_channel_id' => 'required',
|
||||
'status' => 'required'
|
||||
|
||||
);
|
||||
|
||||
$validator = Validator::make(Input::all(), $rules);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return back()->withInput(Input::all())->withErrors($validator);
|
||||
}
|
||||
|
||||
if($id == "new") {
|
||||
$model = TravelUserBookingFewo::create($data);
|
||||
}else{
|
||||
$model = TravelUserBookingFewo::findOrFail($id);
|
||||
$model->fill($data)->save();
|
||||
}
|
||||
|
||||
\Session()->flash('alert-save', '1');
|
||||
return redirect(route('travel_user_booking_fewo_detail', [$model->id]));
|
||||
|
||||
}
|
||||
|
||||
public function delete($id){
|
||||
$model = TravelUserBookingFewo::findOrFail($id);
|
||||
$FewoReservations = FewoReservation::where('lodging_id', $model->fewo_lodging_id)->where('from_date', $model->getFromDateRaw())->where('to_date', $model->getToDateRaw())->get();
|
||||
foreach ($FewoReservations as $FewoReservation){
|
||||
$FewoReservation->delete();
|
||||
}
|
||||
$model->delete();
|
||||
\Session()->flash('alert-success', __('Buchung gelöscht sowie die Reservierung im Sterntrous Kalender'));
|
||||
return redirect(route('travel_user_booking_fewos'));
|
||||
}
|
||||
|
||||
|
||||
public function getTravelUserBookingFewos()
|
||||
{
|
||||
//confirmation_code_remider is delete 2
|
||||
$query = TravelUserBookingFewo::where('deleted_at', '=', null);
|
||||
|
||||
return \DataTables::eloquent($query)
|
||||
->addColumn('action_edit', function (TravelUserBookingFewo $travel_user_booking_fewo) {
|
||||
return '<a data-order="'.$travel_user_booking_fewo->id.'" href="' . route('travel_user_booking_fewo_detail', [$travel_user_booking_fewo->id]) . '" class="btn icon-btn btn-sm btn-primary"><span class="far fa-edit"></span></a>';
|
||||
})
|
||||
->addColumn('fewo_lodging', function (TravelUserBookingFewo $travel_user_booking_fewo) {
|
||||
//return '<a href="' . route('travel_user_booking_fewo_detail', [$travel_user_booking_fewo->fewo_lodging_id]) . '">'.$travel_user_booking_fewo->fewo_lodging->name.'</a>';
|
||||
return $travel_user_booking_fewo->fewo_lodging->name;
|
||||
})
|
||||
->addColumn('travel_user', function (TravelUserBookingFewo $travel_user_booking_fewo) {
|
||||
return '<a href="' . route('travel_user_detail', [$travel_user_booking_fewo->travel_user_id]) . '">'.$travel_user_booking_fewo->travel_user->first_name.' '.$travel_user_booking_fewo->travel_user->last_name.'</a>';
|
||||
})
|
||||
->addColumn('is_calendar', function (TravelUserBookingFewo $travel_user_booking_fewo) {
|
||||
|
||||
$back = "";
|
||||
$back .= $travel_user_booking_fewo->is_calendar_fewo_direct ? ' <span class="badge badge-pill badge-success"><i class="far fa-check"></i></span>' : ' <span class="badge badge-pill badge-danger"><i class="far fa-times"></i></span>';
|
||||
$back .= $travel_user_booking_fewo->is_calendar_hrs ? ' <span class="badge badge-pill badge-success"><i class="far fa-check"></i></span>' : ' <span class="badge badge-pill badge-danger"><i class="far fa-times"></i></span>';
|
||||
$back .= $travel_user_booking_fewo->is_calendar_stern_tours ? ' <span class="badge badge-pill badge-success"><i class="far fa-check"></i></span>' : ' <span class="badge badge-pill badge-danger"><i class="far fa-times"></i></span>';
|
||||
return $back;
|
||||
})
|
||||
->addColumn('status_name', function (TravelUserBookingFewo $travel_user_booking_fewo) {
|
||||
return $travel_user_booking_fewo->getStatuesName();
|
||||
})
|
||||
|
||||
->addColumn('action_delete', function (TravelUserBookingFewo $travel_user_booking_fewo) {
|
||||
return '<a href="' . route('travel_user_booking_fewo_delete', [$travel_user_booking_fewo->id]) . '" class="btn icon-btn btn-sm btn-danger" onclick="return confirm(\''.__('Really delete entry?').'\');"><span class="far fa-trash"></span></a>';
|
||||
})
|
||||
->rawColumns(['action_edit', 'fewo_lodging', 'travel_user', 'is_calendar', 'action_delete'])
|
||||
->make(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
111
app/Http/Controllers/TravelUserController.php
Executable file
111
app/Http/Controllers/TravelUserController.php
Executable file
|
|
@ -0,0 +1,111 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
|
||||
use App\Models\TravelUser;
|
||||
use Input;
|
||||
use Validator;
|
||||
|
||||
class TravelUserController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('admin');
|
||||
|
||||
}
|
||||
|
||||
public function index($step = false)
|
||||
{
|
||||
$data = [
|
||||
'step' => $step
|
||||
];
|
||||
return view('travel.user.index', $data);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function detail($id)
|
||||
{
|
||||
if($id == "new") {
|
||||
$travel_user = new TravelUser();
|
||||
$id = 'new';
|
||||
|
||||
}else{
|
||||
$travel_user = TravelUser::findOrFail($id);
|
||||
$id = $travel_user->id;
|
||||
}
|
||||
$data = [
|
||||
'travel_user' => $travel_user,
|
||||
'id' => $id,
|
||||
];
|
||||
return view('travel.user.detail', $data);
|
||||
|
||||
}
|
||||
|
||||
public function store($id)
|
||||
{
|
||||
$data = Input::all();
|
||||
|
||||
$rules = array(
|
||||
'salutation_id' => 'required',
|
||||
'travel_nationality_id' => 'required',
|
||||
'first_name'=>'required',
|
||||
'last_name'=>'required',
|
||||
);
|
||||
if($id == "new"){
|
||||
$rules['email'] = 'required|string|email|max:255|unique:mysql_stern.travel_users,email';
|
||||
}else{
|
||||
$model = TravelUser::findOrFail($id);
|
||||
$rules['email'] = 'required|string|email|max:255|unique:mysql_stern.travel_users,email,'.$model->id;
|
||||
}
|
||||
|
||||
$validator = Validator::make(Input::all(), $rules);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return back()->withInput(Input::all())->withErrors($validator);
|
||||
}
|
||||
|
||||
if($id == "new") {
|
||||
$model = TravelUser::create($data);
|
||||
}else{
|
||||
$model = TravelUser::findOrFail($id);
|
||||
$model->fill($data)->save();
|
||||
}
|
||||
|
||||
\Session()->flash('alert-save', '1');
|
||||
return redirect(route('travel_user_detail', [$model->id]));
|
||||
|
||||
}
|
||||
|
||||
public function delete($id){
|
||||
$model = TravelUser::findOrFail($id);
|
||||
$model->email = time()."@delete.de";
|
||||
$model->save();
|
||||
$model->delete();
|
||||
\Session()->flash('alert-success', __('Vorlage gelöscht'));
|
||||
return redirect(route('travel_users'));
|
||||
}
|
||||
|
||||
|
||||
public function getTravelUsers()
|
||||
{
|
||||
//confirmation_code_remider is delete 2
|
||||
$query = TravelUser::where('deleted_at', '=', null);
|
||||
|
||||
return \DataTables::eloquent($query)
|
||||
->addColumn('action_edit', function (TravelUser $user) {
|
||||
return '<a data-order="'.$user->id.'" href="' . route('travel_user_detail', [$user->id]) . '" class="btn icon-btn btn-sm btn-primary"><span class="far fa-edit"></span></a>';
|
||||
})
|
||||
|
||||
->addColumn('action_delete', function (TravelUser $user) {
|
||||
return '<a href="' . route('travel_user_delete', [$user->id]) . '" class="btn icon-btn btn-sm btn-danger" onclick="return confirm(\''.__('Really delete entry?').'\');"><span class="far fa-trash"></span></a>';
|
||||
})
|
||||
->rawColumns(['action_edit', 'action_delete'])
|
||||
->make(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue