public function postReservation()
 {
     $rType = Input::get('rType');
     $cType = Input::get('cType');
     $checkCottage = Input::get('checkCottage');
     $chosenCottages = explode(",", $checkCottage);
     $kid = Input::get('kid');
     $adult = Input::get('adult');
     $email = Input::get('email');
     $date = date('Y-m-d', strtotime(Input::get('date')));
     $time = date('H:i', strtotime(Input::get('time')));
     $chosenDay = Input::get('chosenDay');
     $package = Input::get('roomPackage');
     $room = Input::get('room');
     if ($rType == 1) {
         if (empty($cType) || empty($checkCottage) || empty($adult)) {
             return View::make('index')->with('mt', "HOME")->with('alert', 'fail')->with('msg', 'failed to reserve cottage please fill all the required fields. Please choose cottage type, cottage and atleast 1 adult.');
         }
     }
     if ($rType == 2) {
         if (empty($room) || empty($package) || empty($time)) {
             return View::make('index')->with('mt', "HOME")->with('alert', 'fail')->with('msg', 'failed to reserve room fill all the required fields. Please choose time, room and room package ');
         }
     }
     if (empty($email)) {
         $email = Input::get('emailRes');
         $userInfo = UserInfo::where('email', '=', str_replace(' ', '', $email))->first();
     } else {
         $userInfo = UserInfo::where('user_id', '=', Auth::User()['id'])->first();
     }
     $season = Input::get('seasoncode');
     // 1: regular 2:week and holidays 3: summer (mar,apr,may)
     $addPerson = Input::get('addPerson');
     $addBed = Input::get('addBed');
     $addLinen = Input::get('addLinen');
     $addTowel = Input::get('addTowel');
     $addPillow = Input::get('addPillow');
     $totalAdd = 0;
     if (!empty($addPerson)) {
         $totalAdd = $totalAdd + $addPerson * (int) AdditionalPrice::where('additional', '=', 'AdditionalPerson')->first()['price'];
     }
     if (!empty($addBed)) {
         $totalAdd = $totalAdd + $addBed * (int) AdditionalPrice::where('additional', '=', 'ExtraBed')->first()['price'];
     }
     if (!empty($addLinen)) {
         $totalAdd = $totalAdd + $addLinen * (int) AdditionalPrice::where('additional', '=', 'ExtraLinen')->first()['price'];
     }
     if (!empty($addTowel)) {
         $totalAdd = $totalAdd + $addTowel * (int) AdditionalPrice::where('additional', '=', 'ExtraTowel')->first()['price'];
     }
     if (!empty($addPillow)) {
         $totalAdd = $totalAdd + $addPillow * (int) AdditionalPrice::where('additional', '=', 'ExtraPillow')->first()['price'];
     }
     $getcountcheck = count(explode(",", $checkCottage)) - 1;
     $cottageType = CottageType::where('Cottage_ID', '=', $cType)->first();
     $price = (int) $cottageType['price'];
     if ($chosenDay == "1") {
         if ($season == "1") {
             $priceAdult = PricingSwimming::where('day', '=', 'Morning')->where('desc_a', '=', 'Adult')->first();
             $priceKid = PricingSwimming::where('day', '=', 'Morning')->where('desc_a', '=', 'Kids')->first();
         } elseif ($season == "2") {
             $priceAdult = PricingSwimming::where('day', '=', 'Weekend And Holiday Morning')->where('desc_a', '=', 'Adult')->first();
             $priceKid = PricingSwimming::where('day', '=', 'Weekend And Holiday Morning')->where('desc_a', '=', 'Kids')->first();
         } else {
             $priceAdult = PricingSwimming::where('day', '=', 'Summer Morning')->where('desc_a', '=', 'Adult')->first();
             $priceKid = PricingSwimming::where('day', '=', 'Summer Morning')->where('desc_a', '=', 'Kids')->first();
         }
     } else {
         if ($season == "1") {
             $priceAdult = PricingSwimming::where('day', '=', 'Overnight')->where('desc_a', '=', 'Adult')->first();
             $priceKid = PricingSwimming::where('day', '=', 'Overnight')->where('desc_a', '=', 'Kids')->first();
         } elseif ($season == "2") {
             $priceAdult = PricingSwimming::where('day', '=', 'Weekend And Holiday Overnight')->where('desc_a', '=', 'Adult')->first();
             $priceKid = PricingSwimming::where('day', '=', 'Weekend And Holiday Overnight')->where('desc_a', '=', 'Kids')->first();
         } else {
             $priceAdult = PricingSwimming::where('day', '=', 'Summer Overnight')->where('desc_a', '=', 'Adult')->first();
             $priceKid = PricingSwimming::where('day', '=', 'Summer Overnight')->where('desc_a', '=', 'Kids')->first();
         }
     }
     if (!empty($priceAdult) && !empty($priceKid)) {
         $cottageprice = $getcountcheck * $price;
         $kidprice = $kid * (int) $priceKid['price'];
         $adultprice = $adult * (int) $priceAdult['price'];
         $total = $cottageprice + $kidprice + $adultprice;
     }
     if (!empty($package)) {
         $total = (int) RoomPackage::where('packid', '=', $package)->first()['Price'] + $totalAdd;
     }
     $getReservation = new CottageReservation();
     $getReservation['user_id'] = $userInfo['user_id'];
     $getReservation['reservation_type'] = $rType;
     $getReservation['cottage_type'] = $cType;
     $getReservation['cottagelist_id'] = $checkCottage;
     $getReservation['day_type'] = $chosenDay;
     $getReservation['reservation_date'] = $date;
     $getReservation['room_id'] = $room;
     $getReservation['package_id'] = $package;
     $getReservation['check_in_datetime'] = $time;
     $getReservation['check_out_datetime'] = "";
     $getReservation['num_adult'] = $adult;
     $getReservation['num_kid'] = $kid;
     $getReservation['status'] = "Pending";
     $getReservation['total_amount'] = $total;
     $getReservation['season'] = $season;
     if (!$getReservation->save()) {
         return Redirect::route('home');
     } else {
         if ($rType == 1) {
             if (!empty($priceAdult)) {
                 $this->postCharges($getReservation['id'], $rType, "Swimming_Entrance", $priceAdult['idp'], $adult);
             }
             if (!empty($priceKid)) {
                 $this->postCharges($getReservation['id'], $rType, "Swimming_Entrance", $priceKid['idp'], $kid);
             }
             if (!empty($checkCottage)) {
                 $this->postCharges($getReservation['id'], $rType, "Cottages", $checkCottage, count($chosenCottages) - 1);
             }
         } else {
             if (!empty($addPerson)) {
                 //$totalAdd = $totalAdd + ($addPerson * (int)AdditionalPrice::where('additional','=','AdditionalPerson')->first()['price']);
                 $this->postCharges($getReservation['id'], $rType, "Additional_room", AdditionalPrice::where('additional', '=', 'AdditionalPerson')->first()['aid'], $addPerson);
             }
             if (!empty($addBed)) {
                 //$totalAdd = $totalAdd + ($addBed * (int)AdditionalPrice::where('additional','=','ExtraBed')->first()['price']);
                 $this->postCharges($getReservation['id'], $rType, "Additional_room", AdditionalPrice::where('additional', '=', 'ExtraBed')->first()['aid'], $addBed);
             }
             if (!empty($addLinen)) {
                 //$totalAdd = $totalAdd + ($addLinen * (int)AdditionalPrice::where('additional','=','ExtraLinen')->first()['price']);
                 $this->postCharges($getReservation['id'], $rType, "Additional_room", AdditionalPrice::where('additional', '=', 'ExtraLinen')->first()['aid'], $addLinen);
             }
             if (!empty($addTowel)) {
                 //$totalAdd = $totalAdd + ($addTowel * (int)AdditionalPrice::where('additional','=','ExtraTowel')->first()['price']);
                 $this->postCharges($getReservation['id'], $rType, "Additional_room", AdditionalPrice::where('additional', '=', 'ExtraTowel')->first()['aid'], $addTowel);
             }
             if (!empty($addPillow)) {
                 //$totalAdd = $totalAdd + ($addPillow * (int)AdditionalPrice::where('additional','=','ExtraPillow')->first()['price']);
                 $this->postCharges($getReservation['id'], $rType, "Additional_room", AdditionalPrice::where('additional', '=', 'ExtraPillow')->first()['aid'], $addPillow);
             }
             if (!empty($package)) {
                 //$totalAdd = $totalAdd + ($addPillow * (int)AdditionalPrice::where('additional','=','ExtraPillow')->first()['price']);
                 $this->postCharges($getReservation['id'], $rType, "Package_room", (int) RoomPackage::where('packid', '=', $package)->first()['packid'], 1);
             }
         }
         $emailcontent = array('fname' => $userInfo['firstname'], 'lname' => $userInfo['lastname'], 'link' => URL::route('getReservation_step2', $getReservation['id']));
         Mail::send('emails.confirmation.reservation', $emailcontent, function ($message) {
             $email = Input::get('email');
             if (empty($email)) {
                 $email = Input::get('emailRes');
             }
             $message->to($email, 'Kalugdan Garden Resort')->subject('Kalugdan Garden Resort Confirmation Email');
         });
         return Redirect::route('getReservation_step2', $getReservation['id'])->with('id', $getReservation['id'])->with('mt', "HOME")->with('id', $getReservation['id'])->with('alert', 'success')->with('msg', 'You have successfully reserve.');
         //return View::make('reservation.reservation_step2')->with('mt', "HOME")->with('id',$getReservation['id'])->with('alert', 'success')->with('msg', 'You have successfully reserve.');
     }
 }
 public function filterTransaction()
 {
     $rType = Input::get('rType');
     $sType = Input::get('sType');
     $response = array();
     if (empty($sType) && !empty($rType)) {
         $transactions = CottageReservation::where('reservation_type', '=', $rType)->get();
     } elseif (!empty($sType) && !empty($rType)) {
         $transactions = CottageReservation::where('reservation_type', '=', $rType)->where('status', '=', $sType)->get();
     } else {
         $transactions = CottageReservation::where('status', '=', $sType)->get();
     }
     foreach ($transactions as $transaction) {
         $roomname = Room::where('rnid', '=', $transaction['room_id'])->first();
         $userInfo = UserInfo::where('user_id', '=', $transaction['user_id'])->first();
         $reservation_type = ReservationType::find($transaction['reservation_type'])->first();
         if ($transaction['reservation_type'] == "1") {
             if ($transaction['day_type'] == 1) {
                 $time = "Morning";
             } else {
                 $time = "Overnight";
             }
         } else {
             $time = date("g:i a", strtotime($transaction['check_in_datetime']));
         }
         //cottage list
         /*
                     $cottagelists = explode(",", $transaction['cottagelist_id']);
                     foreach($cottagelists as $list)
                     {
                     	$cottagename = CottageList::where('cottagelist_id','=',$list)->first();
                     	
                     	
                     	
                     	if(!in_array($cottagename['cottagename'], $cottagelists))
         				{
         					$a[count($cottagelists)] = $cottagename['cottagename'];
         				}
                     }*/
         $all = CottageList::all();
         $cottagelists = explode(",", $transaction['cottagelist_id']);
         $cottagelists2 = array();
         foreach ($all as $cottagename) {
             if (in_array($cottagename['cottagelist_id'], $cottagelists)) {
                 $cottagelists2[count($cottagelists2)] = $cottagename['cottagename'] . "<br>";
             }
         }
         $a = $cottagelists2;
         $response[] = array("id" => $transaction['id'], "fname" => $userInfo['firstname'], "lname" => $userInfo['lastname'], "rtpe" => $reservation_type['name'], "rdate" => $transaction['reservation_date'], "status" => $transaction['status'], "room_name" => !empty($roomname) ? $roomname['roomname'] : "", "cottage_name" => $a, "ttime" => $time);
     }
     return $response;
 }
    $( '#date' ).datepicker({
    'formatDate': 'Y-m-d H:i:s'

    });

    $('#time').timepicker({
    timeFormat: 'hh:mm tt'
    });
    });
    </script>
@stop
@section('content')
<?php 
$id = Auth::User()['id'];
$userInfo = UserInfo::find($id);
$reservation = CottageReservation::find($reserve_id);
$getcountcheck = count(explode(",", $reservation['cottagelist_id'])) - 1;
$countRoom = empty($reservation['room_id']) ? 0 : 1;
$userInfo = UserInfo::where('user_id', '=', $reservation['user_id'])->first();
$package = RoomPackage::where('packid', '=', $reservation['package_id'])->first();
$cottageType = CottageType::where('Cottage_ID', '=', $reservation['cottage_type'])->first();
$price = (int) $cottageType['price'];
$day = $reservation['day_type'];
$season = $reservation['season'];
if ($day == "1") {
    if ($season == "1") {
        $priceAdult = PricingSwimming::where('day', '=', 'Morning')->where('desc_a', '=', 'Adult')->first();
        $priceKid = PricingSwimming::where('day', '=', 'Morning')->where('desc_a', '=', 'Kids')->first();
    } elseif ($season == "2") {
        $priceAdult = PricingSwimming::where('day', '=', 'Weekend And Holiday Morning')->where('desc_a', '=', 'Adult')->first();
        $priceKid = PricingSwimming::where('day', '=', 'Weekend And Holiday Morning')->where('desc_a', '=', 'Kids')->first();