add User, Mail verify, rights, Change Mail, fewo invoice PDF
This commit is contained in:
parent
26ecb09cdc
commit
7abfe3f700
44 changed files with 3041 additions and 1125 deletions
|
|
@ -6,17 +6,19 @@ namespace App\Http\Controllers;
|
|||
use App\Models\FewoPrice;
|
||||
use App\Models\FewoReservation;
|
||||
use App\Models\FewoSeason;
|
||||
use App\Models\TravelUser;
|
||||
use App\Models\TravelUserBookingFewo;
|
||||
use App\Repositories\TravelUserBookingFewoRepository;
|
||||
use Carbon\Carbon;
|
||||
use Input;
|
||||
use Validator;
|
||||
|
||||
class TravelUserBookingFewoController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
protected $userBookingFewoRepo;
|
||||
|
||||
public function __construct(TravelUserBookingFewoRepository $userBookingFewoRepo)
|
||||
{
|
||||
$this->middleware('admin');
|
||||
$this->userBookingFewoRepo = $userBookingFewoRepo;
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -29,7 +31,6 @@ class TravelUserBookingFewoController extends Controller
|
|||
|
||||
|
||||
}
|
||||
|
||||
public function detail($id)
|
||||
{
|
||||
$max_adults = 10;
|
||||
|
|
@ -50,205 +51,34 @@ class TravelUserBookingFewoController extends Controller
|
|||
'id' => $id,
|
||||
];
|
||||
return view('travel.user.booking.detail', $data);
|
||||
|
||||
}
|
||||
|
||||
public function store($id)
|
||||
{
|
||||
$data = Input::all();
|
||||
|
||||
//check for data
|
||||
$check_for_reservation = true;
|
||||
$fewo_reservation_id = 0;
|
||||
if($id > 0) {
|
||||
$model = TravelUserBookingFewo::findOrFail($id);
|
||||
if($data['from_date'] == $model->from_date && $data['to_date'] == $model->to_date){
|
||||
$check_for_reservation = false;
|
||||
}
|
||||
$fewo_reservation_id = $model->fewo_reservation_id;
|
||||
|
||||
if($data['action'] == 'saveAll'){
|
||||
return $this->userBookingFewoRepo->update($id, $data);
|
||||
}
|
||||
if($check_for_reservation){
|
||||
$from_date = Carbon::parse($data['from_date'])->format('Y-m-d');
|
||||
$to_date = Carbon::parse($data['to_date'])->format('Y-m-d');
|
||||
echo "<br>";
|
||||
$fewos = FewoReservation::where('lodging_id', $data['fewo_lodging_id'])
|
||||
->where('id', '!=', $fewo_reservation_id)
|
||||
->where('from_date', '<', $to_date)
|
||||
->where('to_date', '>', $from_date)
|
||||
->get();
|
||||
if($fewos->count()){
|
||||
$error = [];
|
||||
foreach ($fewos as $fewo){
|
||||
$error[] = "Reservierung gefunden: ".$fewo->from_date->format('d.m.Y')." - ".$fewo->to_date->format('d.m.Y');
|
||||
}
|
||||
return back()->withInput(Input::all())->withErrors($error);
|
||||
|
||||
if($data['action'] == 'createInvoice'){
|
||||
if(!TravelUserBookingFewo::find($id)){
|
||||
\Session()->flash('alert-error', __('Buchung nicht gefunden.'));
|
||||
return back()->withInput(Input::all());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//check for
|
||||
|
||||
$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);
|
||||
|
||||
/* $message = 'my custom validation rule message' . $data['from_date'];
|
||||
Validator::extend('my_custom_validation_rule', function ($attribute, $value, $parameters) {
|
||||
//
|
||||
}, $message);
|
||||
*/
|
||||
if ($validator->fails()) {
|
||||
return back()->withInput(Input::all())->withErrors($validator);
|
||||
}
|
||||
|
||||
$set_price = true;
|
||||
$data['is_calendar_fewo_direct'] = isset($data['is_calendar_fewo_direct']) ? true : false;
|
||||
$data['is_calendar_hrs'] = isset($data['is_calendar_hrs']) ? true : false;
|
||||
$data['is_calendar_stern_tours'] = isset($data['is_calendar_stern_tours']) ? true : false;
|
||||
|
||||
|
||||
if($id == "new") {
|
||||
$model = TravelUserBookingFewo::create($data);
|
||||
|
||||
}else{
|
||||
$model = TravelUserBookingFewo::findOrFail($id);
|
||||
if($data['from_date'] == $model->from_date && $data['to_date'] == $model->to_date){
|
||||
$set_price = false;
|
||||
return $this->userBookingFewoRepo->createInvoicePDF($id, $data);
|
||||
$ret = $this->userBookingFewoRepo->check($id, $data);
|
||||
if($ret['success'] == false){
|
||||
return back()->withInput(Input::all())->withErrors($ret['error']);
|
||||
}
|
||||
$model->fill($data)->save();
|
||||
}
|
||||
|
||||
$res = $this->calculatePriceNew($model);
|
||||
$model->daily_prices = $res['season'];
|
||||
if($set_price){
|
||||
$model->price_travel = $res['price_travel'];
|
||||
$model->price_service = $res['price_service'];
|
||||
$model->price_deposit = $res['price_deposit'];
|
||||
$model->price_total = $res['price_total'] + $model->getPriceBalanceRaw();
|
||||
|
||||
if($fewo_reservation = $model->fewo_reservation){
|
||||
$model->fewo_reservation->from_date = $model->getFromDateRaw();
|
||||
$model->fewo_reservation->to_date = $model->getToDateRaw();
|
||||
$model->fewo_reservation->save();
|
||||
if($ret['success'] == true){
|
||||
return redirect(route('travel_user_booking_fewo_detail', [$ret['id']]));
|
||||
|
||||
}
|
||||
}
|
||||
if($fewo_reservation = $model->fewo_reservation){
|
||||
if($model->is_calendar_stern_tours){
|
||||
$model->fewo_reservation->from_date = $model->getFromDateRaw();
|
||||
$model->fewo_reservation->to_date = $model->getToDateRaw();
|
||||
}else{
|
||||
$model->fewo_reservation->from_date = null;
|
||||
$model->fewo_reservation->to_date = null;
|
||||
}
|
||||
$model->fewo_reservation->save();
|
||||
}else{
|
||||
if($model->is_calendar_stern_tours){
|
||||
|
||||
$res = FewoReservation::create([
|
||||
'lodging_id' => $model->fewo_lodging_id,
|
||||
'from_date' => $model->getFromDateRaw(),
|
||||
'to_date' => $model->getToDateRaw(),
|
||||
'status' => 0,
|
||||
'type' => 0]);
|
||||
$model->fewo_reservation_id = $res->id;
|
||||
$model->save();
|
||||
}
|
||||
}
|
||||
|
||||
$model->save();
|
||||
|
||||
\Session()->flash('alert-save', '1');
|
||||
return redirect(route('travel_user_booking_fewo_detail', [$model->id]));
|
||||
|
||||
}
|
||||
|
||||
private function calculatePriceNew(TravelUserBookingFewo $travel_user_booking_fewo){
|
||||
|
||||
$FewoSeasons = FewoSeason::where('from_date', '<', $travel_user_booking_fewo->getToDateRaw())
|
||||
->where('to_date', '>=', $travel_user_booking_fewo->getFromDateRaw())
|
||||
->get();
|
||||
$seasons = [];
|
||||
foreach ($FewoSeasons as $fewoSeason){
|
||||
$FewoPrices = FewoPrice::where('lodging_id', $travel_user_booking_fewo->fewo_lodging_id)->where('season_id', $fewoSeason->id)->get();
|
||||
$price = [];
|
||||
foreach ($FewoPrices as $fewoPrice){
|
||||
$price = $fewoPrice;
|
||||
}
|
||||
$seasons[] = [
|
||||
'name' => $fewoSeason->name,
|
||||
'fromDay' => $fewoSeason->from_date->format("Y-m-d"),
|
||||
'toDay' => $fewoSeason->to_date->format("Y-m-d"),
|
||||
'minimum_stay' => $fewoSeason->minimum_stay,
|
||||
'price' => $price,
|
||||
];
|
||||
|
||||
}
|
||||
$fromDate = Carbon::parse($travel_user_booking_fewo->getFromDateRaw());
|
||||
$toDate = Carbon::parse($travel_user_booking_fewo->gettoDateRaw());
|
||||
|
||||
$interval = \DateInterval::createFromDateString('1 day');
|
||||
$period = new \DatePeriod($fromDate, $interval, $toDate);
|
||||
$check_days = array();
|
||||
|
||||
|
||||
$result = [];
|
||||
$result['price_total'] = 0;
|
||||
$result['price_travel'] = 0;
|
||||
$result['price_deposit'] = $travel_user_booking_fewo->getPriceDepositRaw();
|
||||
$result['price_service'] = 0;
|
||||
$result['days'] = 0;
|
||||
$result['season'] = [];
|
||||
$frist_day = false;
|
||||
|
||||
//days
|
||||
foreach ($period as $dt) {
|
||||
|
||||
foreach ($seasons as $season) {
|
||||
if($dt->format("Y-m-d") >= $season['fromDay'] && $dt->format("Y-m-d") <= $season['toDay']){
|
||||
$check_days[] = $dt->format("d.m.Y");
|
||||
$price = $season['price'];
|
||||
$name = $season['name'];
|
||||
|
||||
if(!isset($result['season'][$name])){
|
||||
$result['season'][$name]['fromDay'] = $dt->format("d.m.Y");
|
||||
$result['price_service'] = $price->flat_price;
|
||||
$result['season'][$name]['price'] = 0;
|
||||
$result['season'][$name]['numberDays'] = 0;
|
||||
$result['season'][$name]['perNight'] = $price->per_night;
|
||||
$result['season'][$name]['minimumStay'] = $season['minimum_stay'];
|
||||
}
|
||||
|
||||
if(!$frist_day){
|
||||
$result['season'][$name]['price'] += $price->per_night;
|
||||
$result['season'][$name]['numberDays'] ++;
|
||||
$result['season'][$name]['toDay'] = $dt->format("d.m.Y");
|
||||
$result['price_travel'] += $price->per_night;
|
||||
|
||||
$result['days'] ++;
|
||||
|
||||
}else{
|
||||
$frist_day = true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
$result['price_total'] = $result['price_deposit'] + $result['price_travel'] + $result['price_service'];
|
||||
return $result;
|
||||
|
||||
}
|
||||
|
||||
public function delete($id){
|
||||
$model = TravelUserBookingFewo::findOrFail($id);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue