public function alacarteCheckout()
 {
     //echo "<pre>"; print_r(Input::all());
     $dataPost['reservationDate'] = Input::get('booking_date');
     $dataPost['reservationDay'] = date("D", strtotime($dataPost['reservationDate']));
     //
     $dataPost['reservationTime'] = Input::get('booking_time');
     $dataPost['partySize'] = Input::get('qty');
     $dataPost['vendorLocationID'] = Input::get('address');
     $dataPost['guestName'] = Input::get('fullname');
     $dataPost['guestEmail'] = Input::get('email');
     $dataPost['phone'] = Input::get('phone');
     $dataPost['reservationType'] = 'alacarte';
     $dataPost['specialRequest'] = Input::get('special');
     $dataPost['addon'] = Input::get('add_ons');
     $award = Input::get('avard_point');
     $user_email = Input::get('mail');
     $vendor_name = Input::get('vendor_name');
     $userID = Input::get('user_id');
     $userData = Profile::getUserProfileWeb($userID);
     $outlet = $this->alacarte_model->getOutlet($dataPost['vendorLocationID']);
     $locationDetails = $this->alacarte_model->getLocationDetails($dataPost['vendorLocationID']);
     $vendorDetails = $this->alacarterepository->getByRestaurantLocationId($dataPost['vendorLocationID']);
     $getUsersDetails = $this->experiences_model->fetchDetails($userID);
     $getReservationID = '';
     if ($userID > 0) {
         //validating the information submitted by users
         $arrResponse = $this->alacarte_model->validateReservationData($dataPost);
         if ($arrResponse['status'] == 'success') {
             $reservationResponse = $this->alacarte_model->addReservationDetails($dataPost, $userID);
             $rewardsPoints = isset($award) && $award != 0 ? $vendorDetails['attributes']['reward_points_per_reservation'] : 0;
             $bookingsMade = $userData['data']['a_la_carte_reservation'] + 1;
             $type = "new";
             $reservationType = "alacarte";
             $lastOrderId = $reservationResponse['data']['reservationID'];
             Profile::updateReservationInUsers($rewardsPoints, $type, $bookingsMade, $reservationType, $userID, $lastOrderId);
             DB::table('users')->where('id', $userID)->update(array('full_name' => $dataPost['guestName'], 'phone_number' => $dataPost['phone']));
             $getReservationID = $reservationResponse['data']['reservationID'];
             //for the new db structure support
             /*$newDb['attributes']['date'] = date('d-M-Y', strtotime($dataPost['reservationDate']));
               $newDb['attributes']['time'] = date("g:i A", strtotime($dataPost['reservationTime']));*/
             $combined_date_and_time = $dataPost['reservationDate'] . ' ' . $dataPost['reservationTime'];
             $newDb['attributes']['reserv_datetime'] = Carbon::createFromFormat('Y-m-d H:i A', $combined_date_and_time)->toDateTimeString();
             $newDb['attributes']['no_of_people_booked'] = $dataPost['partySize'];
             $newDb['attributes']['cust_name'] = $dataPost['guestName'];
             $newDb['attributes']['email'] = $dataPost['guestEmail'];
             $newDb['attributes']['contact_no'] = $dataPost['phone'];
             $newDb['attributes']['reserv_type'] = "Alacarte";
             $newDb['attributes']['loyalty_points_awarded'] = $rewardsPoints;
             $newDb['attributes']['special_request'] = $dataPost['specialRequest'];
             $newDb['attributes']['experience'] = $outlet->vendor_name . ' - Ala Carte';
             $newDb['attributes']['api_added'] = "Admin Reservation";
             $newDb['attributes']['giu_membership_id'] = $userData['data']['membership_number'];
             $newDb['attributes']['outlet'] = $outlet->name;
             $newDb['attributes']['auto_reservation'] = "Not available";
             $newDb['attributes']['ar_confirmation_id'] = "0";
             $newDb['attributes']['alternate_id'] = 'A' . sprintf("%06d", $reservationResponse['data']['reservationID']);
             $newDb['attributes']['reservation_status_id'] = 1;
             $newDb['userdetails']['user_id'] = $userID;
             $newDb['userdetails']['status'] = 1;
             //print_r($newDb);die;
             $reservDetails = new ReservationDetails();
             $newDbStatus = $reservDetails->updateAttributes($reservationResponse['data']['reservationID'], $newDb);
             $tokens = $reservDetails->pushToRestaurant($reservationResponse['data']['reservationID']);
             $this->restaurantapp->push($reservationResponse['data']['reservationID'], $tokens, true);
             //print_r($newDbStatus);die;
             /*TODO: Add the status of success check and include added_by and transaction_id attributes */
             //die;
             $zoho_data = array('Name' => $dataPost['guestName'], 'Email_ids' => $dataPost['guestEmail'], 'Contact' => $dataPost['phone'], 'Experience_Title' => $outlet->vendor_name . ' - Ala Carte', 'No_of_People' => $dataPost['partySize'], 'Date_of_Visit' => date('d-M-Y', strtotime($dataPost['reservationDate'])), 'Time' => date("g:i A", strtotime($dataPost['reservationTime'])), 'Alternate_ID' => 'A' . sprintf("%06d", $reservationResponse['data']['reservationID']), 'Special_Request' => $dataPost['specialRequest'], 'Type' => "Alacarte", 'API_added' => 'Admin Reservation', 'GIU_Membership_ID' => $userData['data']['membership_number'], 'Outlet' => $outlet->name, 'AR_Confirmation_ID' => '0', 'Auto_Reservation' => 'Not available', 'Calling_option' => 'No');
             //echo "<pre>"; print_r($zoho_data);
             $zoho_res = AdminReservations::zoho_add_booking($zoho_data);
             $zoho_success = $zoho_res->result->form->add->status;
             //echo "<pre>"; print_r($zoho_success); die;
             if ($zoho_success[0] != "Success") {
                 //$this->email->from('*****@*****.**', 'WowTables by GourmetItUp');
                 //$list = array('*****@*****.**', '*****@*****.**', '*****@*****.**');
                 //$this->email->to($list);
                 //$this->email->subject('Urgent: Zoho reservation posting error');
                 $mailbody = 'A' . sprintf("%06d", $reservationResponse['data']['reservationID']) . ' reservation has not been posted to zoho. Please fix manually.<br><br>';
                 $mailbody .= 'Reservation Details<br>';
                 foreach ($zoho_data as $key => $val) {
                     $name = str_replace('_', ' ', $key);
                     $mailbody .= $name . ' ' . $val . '<br>';
                 }
                 Mail::send('site.pages.zoho_posting_error', ['zoho_data' => $mailbody], function ($message) use($zoho_data) {
                     $message->from('*****@*****.**', 'WowTables by GourmetItUp');
                     $message->to('*****@*****.**')->subject('Urgent: Zoho reservation posting error');
                     $message->cc('*****@*****.**', '*****@*****.**', '*****@*****.**');
                 });
             }
             $mergeReservationsArray = array('order_id' => sprintf("%06d", $reservationResponse['data']['reservationID']), 'reservation_date' => date('d-F-Y', strtotime($dataPost['reservationDate'])), 'reservation_time' => date('g:i a', strtotime($dataPost['reservationTime'])), 'venue' => $outlet->vendor_name, 'username' => $dataPost['guestName']);
             //echo "<pre>"; print_r($mergeReservationsArray); die;
             $city_id = $locationDetails->city_id;
             $city_name = Location::where(['Type' => 'City', 'id' => $userData['data']['location_id']])->pluck('name');
             if (empty($city_name)) {
                 $city_name = 'mumbai';
             }
             $city = ucfirst($city_name);
             //Start MailChimp
             if (!empty($getUsersDetails)) {
                 $merge_vars = array('MERGE1' => $dataPost['guestName'], 'MERGE10' => date('m/d/Y'), 'MERGE11' => $userData['data']['a_la_carte_reservation'] + 1, 'MERGE13' => $dataPost['phone'], 'MERGE27' => date("m/d/Y", strtotime($dataPost['reservationDate'])), 'GROUPINGS' => array(array('id' => 9713, 'groups' => [$city])));
                 $this->mailchimp->lists->subscribe($this->listId, ["email" => $dataPost['guestEmail']], $merge_vars, "html", false, true);
                 //$this->mc_api->listSubscribe($list_id, $_POST['email'], $merge_vars,"html",true,true );
             }
             //End MailChimp
             $footerpromotions = DB::select('SELECT efp.link,mrn.file  FROM email_footer_promotions as efp LEFT JOIN media_resized_new as mrn ON mrn.media_id = efp.media_id WHERE efp.show_in_alacarte = 1 AND efp.city_id = ' . $city_id);
             if (isset($user_email) && $user_email != 0) {
                 Mail::send('site.pages.restaurant_reservation', ['location_details' => $locationDetails, 'outlet' => $outlet, 'post_data' => $dataPost, 'productDetails' => $vendorDetails, 'reservationResponse' => $reservationResponse, 'footerPromotions' => !empty($footerpromotions) ? $footerpromotions : ""], function ($message) use($mergeReservationsArray) {
                     $message->from('*****@*****.**', 'WowTables by GourmetItUp');
                     $message->to(Input::get('email'))->subject('Your WowTables Reservation at ' . $mergeReservationsArray['venue']);
                     //$message->cc('*****@*****.**', '*****@*****.**');
                 });
             }
             Mail::send('site.pages.restaurant_reservation', ['location_details' => $locationDetails, 'outlet' => $outlet, 'post_data' => $dataPost, 'productDetails' => $vendorDetails, 'reservationResponse' => $reservationResponse, 'footerPromotions' => !empty($footerpromotions) ? $footerpromotions : ""], function ($message) use($mergeReservationsArray) {
                 $message->from('*****@*****.**', 'WowTables by GourmetItUp');
                 $message->to('*****@*****.**')->subject('NR - #A' . $mergeReservationsArray['order_id'] . ' | ' . $mergeReservationsArray['reservation_date'] . ' , ' . $mergeReservationsArray['reservation_time'] . ' | ' . $mergeReservationsArray['venue'] . ' | ' . $mergeReservationsArray['username']);
                 $message->cc(['*****@*****.**', '*****@*****.**', '*****@*****.**']);
             });
             $result_data = array('full_name' => $dataPost['guestName'], 'email' => $dataPost['guestEmail'], 'phone' => $dataPost['phone'], 'booking_date' => $dataPost['reservationDate'], 'booking_time' => $dataPost['reservationTime'], 'exp_title' => $vendor_name, 'order_id' => 'A' . sprintf("%06d", $reservationResponse['data']['reservationID']));
             echo json_encode($result_data);
         }
     }
 }
 public function alaorder()
 {
     $dataPost['reservationDate'] = Input::get('booking_date');
     $dataPost['reservationDay'] = date("D", strtotime($dataPost['reservationDate']));
     //
     $dataPost['reservationTime'] = Input::get('booking_time');
     $dataPost['partySize'] = Input::get('qty');
     $dataPost['vendorLocationID'] = Input::get('address');
     $dataPost['guestName'] = Input::get('fullname');
     $dataPost['guestEmail'] = Input::get('email');
     $dataPost['phone'] = Input::get('phone');
     $dataPost['reservationType'] = 'alacarte';
     $dataPost['specialRequest'] = Input::get('special');
     $dataPost['addon'] = Input::get('add_ons');
     //var_dump($this->request->get('special_offer'));die;
     $special_offer_title = $this->request->get('special_offer_title');
     $special_offer_desc = $this->request->get('special_offer_desc');
     $dataPost['special_offer_title'] = !empty($special_offer_title) && $special_offer_title != "" ? $special_offer_title : "";
     $dataPost['special_offer_desc'] = !empty($special_offer_desc) && $special_offer_desc != "" ? $special_offer_desc : "";
     //var_dump($dataPost['special_offer_desc']);die;
     //$dataPost['access_token'] = Session::get('id');
     $userID = Session::get('id');
     $userData = Profile::getUserProfileWeb($userID);
     $outlet = $this->alacarte_model->getOutlet($dataPost['vendorLocationID']);
     //echo "<pre>"; print_r($outlet);
     $locationDetails = $this->alacarte_model->getLocationDetails($dataPost['vendorLocationID']);
     //echo "<pre>"; print_r($locationDetails);
     $vendorDetails = $this->repository->getByRestaurantLocationId($dataPost['vendorLocationID']);
     //echo "sfa = ".$vendorDetails['attributes']['reward_points_per_reservation'];
     //echo $vendorDetails['RestaurantLocation']->slug;
     //echo "<pre>"; print_r($vendorDetails); die;
     $arrRules = array('reservationDate' => 'required|date', 'reservationDay' => 'required', 'reservationTime' => 'required', 'partySize' => 'required|integer', 'vendorLocationID' => 'required|not_in:0', 'guestName' => 'required|max:255', 'guestEmail' => 'required|email|max:255', 'phone' => 'required', 'reservationType' => 'required|in:experience,alacarte,event', 'specialRequest' => 'max:512');
     $validator = Validator::make($dataPost, $arrRules);
     $cities = Location::where(['Type' => 'City', 'visible' => 1])->lists('name', 'id');
     $arrResponse['cities'] = $cities;
     $city_id = Input::get('city');
     $city_name = Location::where(['Type' => 'City', 'id' => $city_id])->pluck('name');
     if (empty($city_name)) {
         $city_name = 'mumbai';
     }
     if ($validator->fails()) {
         $message = $validator->messages();
         $errorMessage = "";
         foreach ($data as $key => $value) {
             if ($message->has($key)) {
                 $errorMessage .= $message->first($key) . '\\n ';
             }
         }
         return redirect()->back()->withErrors($validator);
     } else {
         /*$getUsersDetails = $this->experiences_model->fetchDetails($userID);
         
                     //Start MailChimp
                     if(!empty($getUsersDetails)){
         
                         $merge_vars = array(
                             'MERGE1'=>$dataPost['guestName'],
                             'MERGE10'=>date('m/d/Y'),
                             'MERGE11'=>$userData['data']['a_la_carte_reservation'] + 1,
                             'MERGE13'=>$dataPost['phone'],
                             'MERGE27'=>date("m/d/Y",strtotime($dataPost['reservationDate'])),
                             'GROUPINGS' => array(array('id' => 9613, 'groups' => [$city]))
                         );
                         $this->mailchimp->lists->subscribe($this->listId, ["email"=>$dataPost['guestEmail']],$merge_vars,"html",false,true );
                         //$this->mc_api->listSubscribe($list_id, $_POST['email'], $merge_vars,"html",true,true );
         
                         /*$my_email = $dataPost['guestEmail'];
                         //$city = $users['city'];
                         $city = ucfirst($city_name);
                         $mergeVars = array(
                             'GROUPINGS' => array(
                                 array(
                                     'id' => 9613,
                                     'groups' => [$city],
                                 )
                             )
                         );
                         //echo "asd , ";
                         //$this->mailchimp->lists->interestGroupings($this->listId,true);
                         //print_r($test);die;
                         $this->mailchimp->lists->updateMember($this->listId, $my_email, $mergeVars);
                     }*/
         //End MailChimp
         $getReservationID = '';
         if ($userID > 0) {
             //validating the information submitted by users
             $arrResponse = $this->alacarte_model->validateReservationData($dataPost);
             if ($arrResponse['status'] == 'success') {
                 $reservationResponse = $this->alacarte_model->addReservationDetails($dataPost, $userID);
                 $rewardsPoints = $vendorDetails['attributes']['reward_points_per_reservation'];
                 $bookingsMade = $userData['data']['a_la_carte_reservation'] + 1;
                 $type = "new";
                 $reservationType = "alacarte";
                 $lastOrderId = $reservationResponse['data']['reservationID'];
                 //for the new db structure support
                 /*$newDb['attributes']['date'] = date('d-M-Y', strtotime($dataPost['reservationDate']));
                   $newDb['attributes']['time'] = date("g:i A", strtotime($dataPost['reservationTime']));*/
                 $combined_date_and_time = $dataPost['reservationDate'] . ' ' . $dataPost['reservationTime'];
                 $newDb['attributes']['reserv_datetime'] = Carbon::createFromFormat('Y-m-d H:i A', $combined_date_and_time)->toDateTimeString();
                 $newDb['attributes']['no_of_people_booked'] = $dataPost['partySize'];
                 $newDb['attributes']['cust_name'] = $dataPost['guestName'];
                 $newDb['attributes']['email'] = $dataPost['guestEmail'];
                 $newDb['attributes']['contact_no'] = $dataPost['phone'];
                 $newDb['attributes']['reserv_type'] = "Alacarte";
                 //$newDb['attributes']['gift_card_id'] = $dataPost['giftCardID'];
                 $newDb['attributes']['loyalty_points_awarded'] = $rewardsPoints;
                 $newDb['attributes']['special_request'] = $dataPost['specialRequest'];
                 $newDb['attributes']['experience'] = $outlet->vendor_name . ' - Ala Carte';
                 $newDb['attributes']['api_added'] = "Web Reservation";
                 $newDb['attributes']['giu_membership_id'] = $userData['data']['membership_number'];
                 $newDb['attributes']['outlet'] = $outlet->name;
                 $newDb['attributes']['auto_reservation'] = "Not available";
                 $newDb['attributes']['ar_confirmation_id'] = "0";
                 $newDb['attributes']['alternate_id'] = 'A' . sprintf("%06d", $reservationResponse['data']['reservationID']);
                 $newDb['attributes']['special_offer_title'] = $dataPost['special_offer_title'];
                 $newDb['attributes']['special_offer_desc'] = $dataPost['special_offer_desc'];
                 $newDb['attributes']['reservation_status_id'] = 1;
                 $newDb['userdetails']['user_id'] = $userID;
                 $newDb['userdetails']['status'] = 1;
                 $reservDetails = new ReservationDetails();
                 $newDbStatus = $reservDetails->updateAttributes($reservationResponse['data']['reservationID'], $newDb);
                 $tokens = $reservDetails->pushToRestaurant($reservationResponse['data']['reservationID']);
                 $this->restaurantapp->push($reservationResponse['data']['reservationID'], $tokens, true);
                 //print_r($newDbStatus);die;
                 /*TODO: Add the status of success check and include added_by and transaction_id attributes */
                 //die;
                 Profile::updateReservationInUsers($rewardsPoints, $type, $bookingsMade, $reservationType, $userID, $lastOrderId);
                 DB::table('users')->where('id', $userID)->update(array('full_name' => $dataPost['guestName'], 'phone_number' => $dataPost['phone']));
                 $getReservationID = $reservationResponse['data']['reservationID'];
                 $zoho_data = array('Name' => $dataPost['guestName'], 'Email_ids' => $dataPost['guestEmail'], 'Contact' => $dataPost['phone'], 'Experience_Title' => $outlet->vendor_name . ' - Ala Carte', 'No_of_People' => $dataPost['partySize'], 'Date_of_Visit' => date('d-M-Y', strtotime($dataPost['reservationDate'])), 'Time' => date("g:i A", strtotime($dataPost['reservationTime'])), 'Alternate_ID' => 'A' . sprintf("%06d", $reservationResponse['data']['reservationID']), 'Special_Request' => $dataPost['specialRequest'], 'Type' => "Alacarte", 'API_added' => 'Web Reservation', 'GIU_Membership_ID' => $userData['data']['membership_number'], 'Outlet' => $outlet->name, 'AR_Confirmation_ID' => '0', 'Auto_Reservation' => 'Not available', 'Special_offer_title' => $dataPost['special_offer_title'], 'Special_offer_desc' => $dataPost['special_offer_desc'], 'Calling_option' => 'No');
                 //echo "<pre>"; print_r($zoho_data);
                 $zoho_res = $this->zoho_add_booking($zoho_data);
                 //print_r($zoho_res);die;
                 $zoho_success = $zoho_res->result->form->add->status;
                 //echo "<pre>"; print_r($zoho_success); die;
                 if ($zoho_success[0] != "Success") {
                     //$this->email->from('*****@*****.**', 'WowTables by GourmetItUp');
                     //$list = array('*****@*****.**', '*****@*****.**', '*****@*****.**');
                     //$this->email->to($list);
                     //$this->email->subject('Urgent: Zoho reservation posting error');
                     $mailbody = 'A' . sprintf("%06d", $reservationResponse['data']['reservationID']) . ' reservation has not been posted to zoho. Please fix manually.<br><br>';
                     $mailbody .= 'Reservation Details<br>';
                     foreach ($zoho_data as $key => $val) {
                         $name = str_replace('_', ' ', $key);
                         $mailbody .= $name . ' ' . $val . '<br>';
                     }
                     Mail::send('site.pages.zoho_posting_error', ['zoho_data' => $mailbody], function ($message) use($zoho_data) {
                         $message->from('*****@*****.**', 'WowTables by GourmetItUp');
                         $message->to('*****@*****.**')->subject('Urgent: Zoho reservation posting error');
                         $message->cc(['*****@*****.**', '*****@*****.**']);
                     });
                 }
                 $mergeReservationsArray = array('order_id' => sprintf("%06d", $reservationResponse['data']['reservationID']), 'reservation_date' => date('d-F-Y', strtotime($dataPost['reservationDate'])), 'reservation_time' => date('g:i a', strtotime($dataPost['reservationTime'])), 'venue' => $outlet->vendor_name, 'username' => $dataPost['guestName']);
                 //start mailchimp
                 $city_id = Input::get('city_id');
                 $city_name = Location::where(['Type' => 'City', 'id' => $city_id])->pluck('name');
                 if (empty($city_name)) {
                     $city_name = 'mumbai';
                 }
                 $city = ucfirst($userData['data']['location']);
                 $merge_vars = array('MERGE1' => $dataPost['guestName'], 'MERGE10' => date('m/d/Y'), 'MERGE11' => $userData['data']['a_la_carte_reservation'] + 1, 'MERGE13' => $dataPost['phone'], 'MERGE27' => date("m/d/Y", strtotime($dataPost['reservationDate'])), 'GROUPINGS' => array(array('id' => 9713, 'groups' => [$city])));
                 $this->mailchimp->lists->subscribe($this->listId, ["email" => $dataPost['guestEmail']], $merge_vars, "html", false, true);
                 //end mailchimp
                 $footerpromotions = DB::select('SELECT efp.link,mrn.file  FROM email_footer_promotions as efp LEFT JOIN media_resized_new as mrn ON mrn.media_id = efp.media_id WHERE efp.show_in_alacarte = 1 AND efp.city_id = ' . $city_id);
                 Mail::send('site.pages.restaurant_reservation', ['location_details' => $locationDetails, 'outlet' => $outlet, 'post_data' => $dataPost, 'productDetails' => $vendorDetails, 'reservationResponse' => $reservationResponse, 'footerPromotions' => !empty($footerpromotions) ? $footerpromotions : ""], function ($message) use($mergeReservationsArray) {
                     $message->from('*****@*****.**', 'WowTables by GourmetItUp');
                     $message->to(Input::get('email'))->subject('Your WowTables Reservation at ' . $mergeReservationsArray['venue']);
                     //$message->cc('*****@*****.**', '*****@*****.**');
                 });
                 Mail::send('site.pages.restaurant_reservation', ['location_details' => $locationDetails, 'outlet' => $outlet, 'post_data' => $dataPost, 'productDetails' => $vendorDetails, 'reservationResponse' => $reservationResponse, 'footerPromotions' => !empty($footerpromotions) ? $footerpromotions : ""], function ($message) use($mergeReservationsArray) {
                     $message->from('*****@*****.**', 'WowTables by GourmetItUp');
                     $message->to('*****@*****.**')->subject('NR - #A' . $mergeReservationsArray['order_id'] . ' | ' . $mergeReservationsArray['reservation_date'] . ' , ' . $mergeReservationsArray['reservation_time'] . ' | ' . $mergeReservationsArray['venue'] . ' | ' . $mergeReservationsArray['username']);
                     $message->cc(['*****@*****.**', '*****@*****.**', '*****@*****.**']);
                 });
             }
         } else {
             return redirect()->back()->withErrors($validator);
         }
     }
     $arrResponse['allow_guest'] = 'Yes';
     $arrResponse['current_city'] = strtolower($city_name);
     $arrResponse['current_city_id'] = $city_id;
     $arrResponse['restaurant_name'] = $outlet->vendor_name;
     $arrResponse['restaurantID'] = $outlet->vendor_id;
     $arrResponse['vendorLocationID'] = $dataPost['vendorLocationID'];
     $arrResponse['reservation_date'] = $dataPost['reservationDate'];
     $arrResponse['reservation_time'] = $dataPost['reservationTime'];
     $arrResponse['order_id'] = $mergeReservationsArray['order_id'];
     $arrResponse['guests'] = $dataPost['partySize'];
     $arrResponse['outlet_name'] = $outlet->name;
     $arrResponse['terms_and_conditions'] = $vendorDetails['attributes']['terms_and_conditions'];
     $arrResponse['address'] = $locationDetails->address;
     $arrResponse['lat'] = $locationDetails->latitude;
     $arrResponse['long'] = $locationDetails->longitude;
     $arrResponse['city'] = $arrResponse['current_city'];
     $arrResponse['guestEmail'] = $dataPost['guestEmail'];
     $arrResponse['guestName'] = $dataPost['guestName'];
     $arrResponse['slug'] = $vendorDetails['RestaurantLocation']->slug;
     //echo "<pre>"; print_r($arrResponse); die;
     //return response()->view('frontend.pages.thankyou',$arrResponse);
     return Redirect::to('/alacarte/thankyou/A' . $mergeReservationsArray['order_id'])->with('response', $arrResponse);
 }
 /**
  * Send mail by zoho for every edited reservation .
  * 
  * @access	public
  * @return	 
  * @since	1.0.0
  */
 public static function sendZohoMailupdate($arrData, $lastReservationDetail)
 {
     $queryResult = DB::table('reservation_details')->where('id', $arrData['reservationID'])->select('user_id')->first();
     $userData = Profile::getUserProfileWeb($queryResult->user_id);
     if ($arrData['reservationType'] == "experience") {
         $arrProductVendorLocationId = DB::table('reservation_details')->where('id', $arrData['reservationID'])->select('product_vendor_location_id')->get();
         $arrProductID = DB::table('product_vendor_locations')->where('id', $arrProductVendorLocationId[0]->product_vendor_location_id)->select('product_id', 'vendor_location_id')->get();
         //$productDetails = $this->experiencesRepository->getByExperienceId($arrProductID[0]->product_id);
         //$outlet = $this->experiences_model->getOutlet($arrProductVendorLocationId[0]->product_vendor_location_id);
         //$locationDetails = $this->experiences_model->getLocationDetails($arrProductVendorLocationId[0]->product_vendor_location_id);
         //-----------------------------------------------------------------------------------------------------
         $locationDetails = self::getExperienceLocationDetails($arrProductVendorLocationId[0]->product_vendor_location_id);
         $outlet = self::getExperienceOutlet($arrProductVendorLocationId[0]->product_vendor_location_id);
         $productDetailsTemp = self::readProductDetailByProductVendorLocationID($arrProductVendorLocationId[0]->product_vendor_location_id);
         $productDetails['attributes'] = array('experience_includes' => $productDetailsTemp['experience_includes'], 'short_description' => $productDetailsTemp['short_description'], 'terms_and_conditions' => $productDetailsTemp['terms_and_conditions']);
         //--------------------------------------------------------------------------------------------------------
         //echo "<prE>"; print_r($productDetails);
         //echo "<br/>----outlet-----<prE>"; print_r($outlet);
         //echo "<br/>----locationDetails-----<prE>"; print_r($locationDetails);
         if (!array_key_exists('giftCardID', $arrData)) {
             $arrData['giftCardID'] = '';
         }
         //for the new db structure support
         $combined_date_and_time = $arrData['reservationDate'] . ' ' . $arrData['reservationTime'];
         $newDb['attributes']['reserv_datetime'] = Carbon::createFromFormat('Y-m-d H:i A', $combined_date_and_time)->toDateTimeString();
         $newDb['attributes']['no_of_people_booked'] = $arrData['partySize'];
         $newDb['attributes']['cust_name'] = $userData['data']['full_name'];
         $newDb['attributes']['email'] = $userData['data']['email'];
         $newDb['attributes']['contact_no'] = $userData['data']['phone_number'];
         $newDb['attributes']['reserv_type'] = "Experience";
         $newDb['attributes']['gift_card_id_reserv'] = $arrData['giftCardID'];
         $newDb['attributes']['experience'] = $outlet->vendor_name . ' - ' . $outlet->descriptive_title;
         $newDb['attributes']['api_added'] = "Mobile";
         $newDb['attributes']['giu_membership_id'] = $userData['data']['membership_number'];
         $newDb['attributes']['outlet'] = $outlet->name;
         $newDb['attributes']['auto_reservation'] = "Not available";
         $newDb['attributes']['ar_confirmation_id'] = "0";
         $newDb['attributes']['alternate_id'] = 'E' . sprintf("%06d", $arrData['reservationID']);
         $newDb['attributes']['special_request'] = $arrData['addons_special_request'];
         //$newDb['attributes']['order_completed'] = 'User Changed';
         $newDb['attributes']['reservation_status_id'] = 2;
         $newDb['userdetails']['user_id'] = $queryResult->user_id;
         $newDb['userdetails']['status'] = 2;
         $newDb['userdetails']['addons'] = isset($arrData['addon']) ? $arrData['addon'] : "";
         $newDb['userdetails']['mobile'] = 1;
         //print_r($newDb);die;
         $reservDetails = new ReservationModel();
         $newDbStatus = $reservDetails->updateAttributes($arrData['reservationID'], $newDb);
         //print_r($newDbStatus);die;
         /*TODO: Add the status of success check and include added_by and transaction_id attributes */
         $zoho_data = array('Name' => $userData['data']['full_name'], 'Email_ids' => $userData['data']['email'], 'Contact' => $userData['data']['phone_number'], 'Experience_Title' => $outlet->vendor_name . ' - ' . $outlet->descriptive_title, 'No_of_People' => $arrData['partySize'], 'Date_of_Visit' => date('d-M-Y', strtotime($arrData['reservationDate'])), 'Time' => date("g:ia", strtotime($arrData['reservationTime'])), 'Type' => 'Experience', 'API_added' => 'Mobile', 'GIU_Membership_ID' => $userData['data']['membership_number'], 'Outlet' => $outlet->name, 'AR_Confirmation_ID' => '0', 'Auto_Reservation' => 'Not available', 'Order_completed' => 'User Changed', 'Special_Request' => $arrData['addons_special_request'], 'gift_card_id_from_reservation' => $arrData['giftCardID']);
         //echo "<pre>"; print_r($zoho_data);
         self::zohoEditBooking('E' . sprintf("%06d", $arrData['reservationID']), $zoho_data);
         $dataPost = array('reservation_type' => $arrData['reservationType'], 'reservationID' => $arrData['reservationID'], 'partySize' => $arrData['partySize'], 'reservationDate' => $arrData['reservationDate'], 'reservationTime' => $arrData['reservationTime'], 'guestName' => $userData['data']['full_name'], 'guestEmail' => $userData['data']['email'], 'guestPhoneNo' => $userData['data']['phone_number'], 'order_id' => sprintf("%06d", $arrData['reservationID']), 'venue' => $outlet->vendor_name, 'reservation_date' => date('d-F-Y', strtotime($arrData['reservationDate'])), 'reservation_time' => date('g:i a', strtotime($arrData['reservationTime'])));
         $dataPost['addons_special_request'] = $arrData['addons_special_request'];
         $dataPost['giftcard_id'] = "";
         //echo "<br/>---datapost---<pre>"; print_r($dataPost);die;
         Mail::send('site.pages.edit_experience_reservation', ['location_details' => $locationDetails, 'outlet' => $outlet, 'post_data' => $dataPost, 'productDetails' => $productDetails], function ($message) use($dataPost, $outlet) {
             $message->from('*****@*****.**', 'WowTables by GourmetItUp');
             $message->to($dataPost['guestEmail'])->subject('Your WowTables Reservation at ' . $outlet->vendor_name . ' has been changed');
             //$message->cc('*****@*****.**', '*****@*****.**');
         });
         //--------------------------------------------------------------------
         $dataPost['admin_email'] = 1;
         $dataPost['final_reservation_oulet'] = $lastReservationDetail['reservation_oulet'];
         $dataPost['final_reservation_party_size'] = $lastReservationDetail['reservation_party_size'];
         $dataPost['final_reservation_date'] = $lastReservationDetail['reservation_date'];
         $dataPost['final_reservation_time'] = $lastReservationDetail['reservation_time'];
         //--------------------------------------------------------------------
         Mail::send('site.pages.edit_experience_reservation', ['location_details' => $locationDetails, 'outlet' => $outlet, 'post_data' => $dataPost, 'productDetails' => $productDetails], function ($message) use($dataPost) {
             $message->from('*****@*****.**', 'WowTables by GourmetItUp');
             $message->to('*****@*****.**')->subject('ER - #E' . $dataPost['order_id'] . ' | ' . $dataPost['reservation_date'] . ' , ' . $dataPost['reservation_time'] . ' | ' . $dataPost['venue'] . ' | ' . $dataPost['guestName']);
             $message->cc('*****@*****.**', '*****@*****.**', '*****@*****.**');
         });
     } else {
         if ($arrData['reservationType'] == "alacarte") {
             $arrVendorLocationID = DB::table('reservation_details')->where('id', $arrData['reservationID'])->select('vendor_location_id')->get();
             //$outlet = $this->alacarte_model->getOutlet($arrVendorLocationID[0]->vendor_location_id);
             //$locationDetails = $this->alacarte_model->getLocationDetails($arrVendorLocationID[0]->vendor_location_id);
             //$vendorDetails = $this->restaurantLocationsRepository->getByRestaurantLocationId($arrVendorLocationID[0]->vendor_location_id);
             //---------------------------------------------------------------------------------------------------
             $outlet = self::getAlacarteOutlet($arrVendorLocationID[0]->vendor_location_id);
             $locationDetails = self::getAlacarteLocationDetails($arrVendorLocationID[0]->vendor_location_id);
             $vendorDetailsTemp = self::readVendorDetailByLocationID($arrVendorLocationID[0]->vendor_location_id);
             $vendorDetails['attributes'] = array('short_description' => $vendorDetailsTemp['short_description'], 'terms_and_conditions' => $vendorDetailsTemp['terms_conditions']);
             //-------------------------------------------------------------------------------------------------------
             //for the new db structure support
             $combined_date_and_time = $arrData['reservationDate'] . ' ' . $arrData['reservationTime'];
             $newDb['attributes']['reserv_datetime'] = Carbon::createFromFormat('Y-m-d H:i A', $combined_date_and_time)->toDateTimeString();
             $newDb['attributes']['no_of_people_booked'] = $arrData['partySize'];
             $newDb['attributes']['cust_name'] = $userData['data']['full_name'];
             $newDb['attributes']['email'] = $userData['data']['email'];
             $newDb['attributes']['contact_no'] = $userData['data']['phone_number'];
             $newDb['attributes']['reserv_type'] = "Alacarte";
             //$newDb['attributes']['gift_card_id_reserv'] = $arrData['giftCardID'];
             $newDb['attributes']['experience'] = $outlet->vendor_name . ' - Ala Carte';
             $newDb['attributes']['api_added'] = "Mobile";
             $newDb['attributes']['giu_membership_id'] = $userData['data']['membership_number'];
             $newDb['attributes']['outlet'] = $outlet->name;
             $newDb['attributes']['auto_reservation'] = "Not available";
             $newDb['attributes']['ar_confirmation_id'] = "0";
             $newDb['attributes']['alternate_id'] = 'A' . sprintf("%06d", $arrData['reservationID']);
             //$newDb['attributes']['order_completed'] = 'User Changed';
             $newDb['attributes']['reservation_status_id'] = 2;
             $newDb['userdetails']['user_id'] = $queryResult->user_id;
             $newDb['userdetails']['status'] = 2;
             //print_r($newDb);die;
             $reservDetails = new ReservationModel();
             $newDbStatus = $reservDetails->updateAttributes($arrData['reservationID'], $newDb);
             //print_r($newDbStatus);die;
             /*TODO: Add the status of success check and include added_by and transaction_id attributes */
             //echo "experience success";die;
             $zoho_data = array('Name' => $userData['data']['full_name'], 'Email_ids' => $userData['data']['email'], 'Contact' => $userData['data']['phone_number'], 'Experience_Title' => $outlet->vendor_name . ' - Ala Carte', 'No_of_People' => $arrData['partySize'], 'Date_of_Visit' => date('d-M-Y', strtotime($arrData['reservationDate'])), 'Time' => date("g:i a", strtotime($arrData['reservationTime'])), 'Type' => 'alacarte', 'API_added' => 'Mobile', 'GIU_Membership_ID' => $userData['data']['membership_number'], 'Outlet' => $outlet->name, 'AR_Confirmation_ID' => '0', 'Auto_Reservation' => 'Not available', 'Order_completed' => 'User Changed');
             self::zohoEditBooking('A' . sprintf("%06d", $arrData['reservationID']), $zoho_data);
             $dataPost = array('reservation_type' => $arrData['reservationType'], 'reservationID' => $arrData['reservationID'], 'partySize' => $arrData['partySize'], 'reservationDate' => $arrData['reservationDate'], 'reservationTime' => $arrData['reservationTime'], 'guestName' => $userData['data']['full_name'], 'guestEmail' => $userData['data']['email'], 'guestPhoneNo' => $userData['data']['phone_number'], 'order_id' => sprintf("%06d", $arrData['reservationID']), 'venue' => $outlet->vendor_name, 'reservation_date' => date('d-F-Y', strtotime($arrData['reservationDate'])), 'reservation_time' => date('g:i a', strtotime($arrData['reservationTime'])));
             $dataPost['giftcard_id'] = "";
             //echo "<br/>---datapost---<pre>"; print_r($dataPost);die;
             Mail::send('site.pages.edit_restaurant_reservation', ['location_details' => $locationDetails, 'outlet' => $outlet, 'post_data' => $dataPost, 'productDetails' => $vendorDetails], function ($message) use($dataPost, $outlet) {
                 $message->from('*****@*****.**', 'WowTables by GourmetItUp');
                 $message->to($dataPost['guestEmail'])->subject('Your WowTables Reservation at ' . $outlet->vendor_name . ' has been changed');
                 //$message->cc('*****@*****.**', '*****@*****.**');
             });
             //--------------------------------------------------------
             $dataPost['admin_email'] = 1;
             $dataPost['final_reservation_party_size'] = $lastReservationDetail['reservation_party_size'];
             $dataPost['final_reservation_date'] = $lastReservationDetail['reservation_date'];
             $dataPost['final_reservation_time'] = $lastReservationDetail['reservation_time'];
             //---------------------------------------------------------
             Mail::send('site.pages.edit_restaurant_reservation', ['location_details' => $locationDetails, 'outlet' => $outlet, 'post_data' => $dataPost, 'productDetails' => $vendorDetails], function ($message) use($dataPost) {
                 $message->from('*****@*****.**', 'WowTables by GourmetItUp');
                 $message->to('*****@*****.**')->subject('ER - #A' . $dataPost['order_id'] . ' | ' . $dataPost['reservation_date'] . ' , ' . $dataPost['reservation_time'] . ' | ' . $dataPost['venue'] . ' | ' . $dataPost['guestName']);
                 //$message->to('*****@*****.**')->subject('ER - #A'.$dataPost['order_id'].' | '.$dataPost['reservation_date'].' , '.$dataPost['reservation_time'].' | '.$dataPost['venue'].' | '.$dataPost['guestName']);
                 $message->cc('*****@*****.**', '*****@*****.**', '*****@*****.**');
             });
         }
     }
 }
 public static function pushToRestaurant($reservation_id)
 {
     $reservationDetails = ReservationDetails::find($reservation_id);
     $vendor_location_id = $reservationDetails->vendor_location_id;
     $vendorUsers = VendorLocationContacts::where('vendor_location_id', $vendor_location_id)->get();
     $tokens = array();
     foreach ($vendorUsers as $vendorUser) {
         $userDevices = DB::table('user_devices')->where('user_id', $vendorUser->user_id)->get();
         foreach ($userDevices as $userDevice) {
             if (isset($userDevice->rest_notification_id)) {
                 $tokenStr = array();
                 $tokenStr['token'] = $userDevice->rest_notification_id;
                 $tokens[] = $tokenStr;
             }
         }
     }
     return $tokens;
     /*if(!empty($tokens)){
           $ch = curl_init();
           $curlConfig = array(
               CURLOPT_URL            => "http://concierge.wowtables.com/conciergeapi/reservation/".$reservation_id."/notification",
               CURLOPT_POST           => true,
               CURLOPT_RETURNTRANSFER => true,
               CURLOPT_POSTFIELDS     => "tokens=".json_encode($tokens),
           );
           curl_setopt_array($ch, $curlConfig);
           $result = curl_exec($ch);
           //echo "<pre> results == "; print_r($result);die;
           curl_close($ch);
       }*/
 }
 /**
  * Handles requests for cancelling a reservation.
  * 
  * @access	public
  * @return	response
  * @since	1.0.0
  */
 public function updateReservetion()
 {
     //echo "<pre>"; print_r(Input::all()); //die;
     $reserv_id = $this->request->input('reserv_id');
     $vendor_details = $this->request->input('vendor_details');
     $array = explode(',', $vendor_details);
     $reserveType = $array['0'];
     //echo "sd = ".$reserveType; die;
     $party_size = $this->request->input('party_size');
     $locality_val = $this->request->input('locality_val');
     $edit_date = $this->request->input('edit_date');
     $edit_date1 = $this->request->input('last_reserv_date');
     $new_date = date('Y-m-d', strtotime($this->request->input('last_reserv_date')));
     /*$datearray=explode(" ",$edit_date);
     		$date = trim(str_replace(range('a','z'),'',$datearray["0"]));
     		$remove_comma = trim(str_replace(',','',$datearray["1"]));
     		$month = str_pad($remove_comma, 2, "0", STR_PAD_LEFT); 
     		$year = $datearray["2"];
     		$final_date_format = $year.'-'.$month.'-'.$date;*/
     $final_date_format = $edit_date1;
     $edit_time = $this->request->input('edit_time');
     //echo "new_date = ".$new_date;
     $last_reservation_time = $this->request->input('last_reservation_time');
     $last_reservation_date = $this->request->input('last_reservation_date');
     $last_reservation_party_size = $this->request->input('last_reservation_party_size');
     $new_reservation_outlet = $this->request->input('new_locality_value');
     $last_reservation_outlet_val = $this->request->input('old_locality_value');
     $last_reservation_outlet_name = $this->request->input('old_area_name');
     $last_reservation_giftcard_id = rtrim($this->request->input('last_reservation_giftcard_id'));
     $user_id = $this->request->input('user_id');
     $added_by = $this->request->input('added_by');
     //check for outlet change
     if ($locality_val != $last_reservation_outlet_val) {
         //echo " , outlet changed, send to email";
         $old_reservation_outlet = $last_reservation_outlet_name;
         $new_reservation_outlet = $new_reservation_outlet;
         $reservation_oulet = " Old Outlet: " . $old_reservation_outlet . " -> New Outlet: " . $new_reservation_outlet;
     } else {
         $reservation_oulet = "";
     }
     //check for party size change
     if ($party_size != $last_reservation_party_size) {
         //echo " , party size changed, send to email";
         $old_reservation_party_size = $last_reservation_party_size;
         $new_reservation_party_size = $party_size;
         $reservation_party_size = " Old Party Size: " . $old_reservation_party_size . " -> New Party Size: " . $new_reservation_party_size;
     } else {
         $reservation_party_size = "";
     }
     //check for date change
     if ($new_date != $last_reservation_date) {
         $old_reservation_date = $last_reservation_date;
         $new_reservation_date = $new_date;
         $reservation_date = " Old Date: " . $old_reservation_date . " -> New Date: " . $new_reservation_date;
     } else {
         $reservation_date = "";
     }
     //check for time change
     if ($edit_time != $last_reservation_time) {
         $old_reservation_time = $last_reservation_time;
         $new_reservation_time = $edit_time;
         $reservation_time = " Old Time: " . $old_reservation_time . " -> New Time: " . $new_reservation_time;
     } else {
         $reservation_time = "";
     }
     $addonsArray = $this->request->input('addonsArray');
     $giftcard_id = $this->request->input('giftcard_id');
     $giftcard_id_text = $this->request->input('giftcard_id') != "" ? $this->request->input('giftcard_id') : "NULL";
     $special_request = $this->request->input('special_request');
     //	`print_r($addonsArray);
     //echo "sad = ".$giftcard_id;
     $count = $this->request->input('addonsArray');
     $giftcard_change = '';
     if ($giftcard_id != $last_reservation_giftcard_id) {
         if ($giftcard_id == "") {
             //echo " d null = ".$giftcard_id_text;
             $giftcard_change = " old Giftcard ID: " . $last_reservation_giftcard_id . " -> New Giftcard ID: " . $giftcard_id_text;
         } else {
             $giftcard_change = " old Giftcard ID: " . $last_reservation_giftcard_id . " -> New Giftcard ID: " . $giftcard_id_text;
         }
     } else {
         $giftcard_change = "";
     }
     //die;
     if ($count == "") {
         $addonsArray = array();
     }
     $addonsText = '';
     foreach ($addonsArray as $prod_id => $qty) {
         if ($qty > 0) {
             //echo "prod id = ".$prod_id." , qty = ".$qty;
             $addonsDetails = DB::select("SELECT attribute_value from product_attributes_text where product_id = {$prod_id} and product_attribute_id = 17");
             //echo "<pre>"; print_r($addonsDetails);
             $addonsText .= $addonsDetails[0]->attribute_value . " (" . $qty . ") , ";
         }
     }
     //$addons_special_request = isset($addonsText) && $addonsText != "" ? "Addons: ".$addonsText : " ";
     $finalAddontext = isset($addonsText) && $addonsText != "" ? "Addons: " . $addonsText : " ";
     $special_request_data = isset($special_request) && $special_request != "" ? "Spl Req: " . $special_request : "";
     $addons_special_request = $finalAddontext . " " . $special_request_data;
     //echo " addon special request = ".$addons_special_request;
     //echo "<pre>"; print_r($addonsArray); die;
     /*if(count($addonsArray)>=1)
     		{
     			DB::delete("delete from reservation_addons_variants_details where reservation_id = '$reserv_id'");
     			$this->experiences_model->addReservationAddonDetails($reserv_id, $addonsArray);
     		}*/
     //exit;
     if ($locality_val == "" || $locality_val == '0') {
         //echo 'null';
         DB::update("update reservation_details set reservation_date='{$final_date_format}',reservation_time='{$edit_time}',no_of_persons='{$party_size}',reservation_status='edited' where id = '{$reserv_id}'");
     } else {
         //echo 'value is present';
         DB::update("update reservation_details set reservation_date='{$final_date_format}',reservation_time='{$edit_time}',no_of_persons='{$party_size}',vendor_location_id='{$locality_val}',reservation_status='edited' where id = '{$reserv_id}'");
     }
     //exit;
     DB::update("update reservation_details set giftcard_id='{$giftcard_id}', special_request = '{$special_request}' where id = '{$reserv_id}'");
     //code for new db structure changes
     $combined_date_and_time = $final_date_format . ' ' . $edit_time;
     $newDb['attributes']['reserv_datetime'] = Carbon::createFromFormat('Y-m-d H:i A', $combined_date_and_time)->toDateTimeString();
     $newDb['attributes']['no_of_people_booked'] = $party_size;
     $newDb['attributes']['gift_card_id_reserv'] = isset($giftcard_id) ? $giftcard_id : "";
     $newDb['attributes']['special_request'] = $special_request ? $special_request : "";
     $newDb['attributes']['reservation_status_id'] = 2;
     $newDb['userdetails']['user_id'] = $user_id;
     $newDb['userdetails']['status'] = 2;
     $newDb['userdetails']['addons'] = $addonsArray;
     //print_r($newDb);die;
     $reservDetails = new ReservDetailsModel();
     $newDbStatus = $reservDetails->updateAttributes($reserv_id, $newDb);
     $tokens = $reservDetails->pushToRestaurant($reserv_id);
     $this->restaurantapp->push($reserv_id, $tokens, true);
     //print_r($newDbStatus);die;
     /*TODO: Add the status of success check and include added_by and transaction_id attributes */
     //die;
     $userID = $user_id;
     $userData = Profile::getUserProfileWeb($userID);
     if ($reserveType == "experience") {
         $arrProductVendorLocationId = DB::table('reservation_details')->where('id', $reserv_id)->select('product_vendor_location_id')->get();
         $arrProductID = DB::table('product_vendor_locations')->where('id', $arrProductVendorLocationId[0]->product_vendor_location_id)->select('product_id', 'vendor_location_id')->get();
         $productDetails = $this->experiencesRepository->getByExperienceId($arrProductID[0]->product_id);
         $outlet = $this->experiences_model->getOutlet($arrProductVendorLocationId[0]->product_vendor_location_id);
         $locationDetails = $this->experiences_model->getLocationDetails($arrProductVendorLocationId[0]->product_vendor_location_id);
         //echo "<prE>"; print_r($productDetails);
         //echo "<br/>----outlet-----<prE>"; print_r($outlet);
         //echo "<br/>----locationDetails-----<prE>"; print_r($locationDetails);
         $zoho_data = array('Name' => $userData['data']['full_name'], 'Email_ids' => $userData['data']['email'], 'Contact' => $userData['data']['phone_number'], 'Experience_Title' => $outlet->vendor_name . ' - ' . $outlet->descriptive_title, 'No_of_People' => $party_size, 'Date_of_Visit' => date('d-M-Y', strtotime($edit_date1)), 'Time' => date("g:ia", strtotime($this->request->input('edit_time'))), 'Type' => 'Experience', 'API_added' => $added_by == 'user' ? 'Web Updated' : 'Admin Updated', 'GIU_Membership_ID' => $userData['data']['membership_number'], 'Outlet' => $outlet->name, 'AR_Confirmation_ID' => '0', 'Auto_Reservation' => 'Not available', 'Order_completed' => $added_by == 'user' ? 'User Changed' : 'Admin Changed', 'Special_Request' => $addons_special_request, 'gift_card_id_from_reservation' => $giftcard_id);
         //echo "<pre>E".sprintf("%06d",$reserv_id); print_r($zoho_data); die;
         $this->zoho_edit_booking('E' . sprintf("%06d", $reserv_id), $zoho_data);
         //echo "<pre> a ="; print_r($a); die;
         $dataPost = array('reservation_type' => $reserveType, 'reservationID' => $reserv_id, 'partySize' => $party_size, 'reservationDate' => $edit_date1, 'reservationTime' => $this->request->input('edit_time'), 'guestName' => $userData['data']['full_name'], 'guestEmail' => $userData['data']['email'], 'guestPhoneNo' => $userData['data']['phone_number'], 'order_id' => sprintf("%06d", $reserv_id), 'venue' => $outlet->vendor_name, 'reservation_date' => date('d-F-Y', strtotime($edit_date1)), 'reservation_time' => date('g:i a', strtotime($this->request->input('edit_time'))), 'addons_special_request' => $addons_special_request, 'giftcard_id' => $giftcard_id);
         //echo "<br/>---datapost---<pre>"; print_r($dataPost);die;
         Mail::send('site.pages.edit_experience_reservation', ['location_details' => $locationDetails, 'outlet' => $outlet, 'post_data' => $dataPost, 'productDetails' => $productDetails], function ($message) use($dataPost) {
             $message->from('*****@*****.**', 'WowTables by GourmetItUp');
             $message->to($dataPost['guestEmail'])->subject('Your WowTables Reservation at ' . $dataPost['venue'] . ' has been changed');
             //$message->cc('*****@*****.**', '*****@*****.**');
         });
         $dataPost['admin_email'] = 1;
         $dataPost['final_reservation_oulet'] = $reservation_oulet;
         $dataPost['final_reservation_party_size'] = $reservation_party_size;
         $dataPost['final_reservation_date'] = $reservation_date;
         $dataPost['final_reservation_time'] = $reservation_time;
         $dataPost['final_giftcard_id'] = $giftcard_change;
         Mail::send('site.pages.edit_experience_reservation', ['location_details' => $locationDetails, 'outlet' => $outlet, 'post_data' => $dataPost, 'productDetails' => $productDetails], function ($message) use($dataPost) {
             $message->from('*****@*****.**', 'WowTables by GourmetItUp');
             $message->to('*****@*****.**')->subject('ER - #E' . $dataPost['order_id'] . ' | ' . $dataPost['reservation_date'] . ' , ' . $dataPost['reservation_time'] . ' | ' . $dataPost['venue'] . ' | ' . $dataPost['guestName']);
             $message->cc('*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**');
         });
     } else {
         if ($reserveType == "alacarte") {
             $arrVendorLocationID = DB::table('reservation_details')->where('id', $reserv_id)->select('vendor_location_id')->get();
             $outlet = $this->alacarte_model->getOutlet($arrVendorLocationID[0]->vendor_location_id);
             $locationDetails = $this->alacarte_model->getLocationDetails($arrVendorLocationID[0]->vendor_location_id);
             $vendorDetails = $this->restaurantLocationsRepository->getByRestaurantLocationId($arrVendorLocationID[0]->vendor_location_id);
             $zoho_data = array('Name' => $userData['data']['full_name'], 'Email_ids' => $userData['data']['email'], 'Contact' => $userData['data']['phone_number'], 'Experience_Title' => $outlet->vendor_name . ' - Ala Carte', 'No_of_People' => $party_size, 'Date_of_Visit' => date('d-M-Y', strtotime($edit_date1)), 'Time' => date("g:i a", strtotime($this->request->input('edit_time'))), 'Type' => 'Experience', 'API_added' => $added_by == 'user' ? 'Web Updated' : 'Admin Updated', 'GIU_Membership_ID' => $userData['data']['membership_number'], 'Outlet' => $outlet->name, 'AR_Confirmation_ID' => '0', 'Auto_Reservation' => 'Not available', 'Order_completed' => $added_by == 'user' ? 'User Changed' : 'Admin Changed', 'Special_Request' => $addons_special_request);
             $this->zoho_edit_booking('A' . sprintf("%06d", $reserv_id), $zoho_data);
             $dataPost = array('reservation_type' => $reserveType, 'reservationID' => $reserv_id, 'partySize' => $party_size, 'reservationDate' => $edit_date1, 'reservationTime' => $this->request->input('edit_time'), 'guestName' => $userData['data']['full_name'], 'guestEmail' => $userData['data']['email'], 'guestPhoneNo' => $userData['data']['phone_number'], 'order_id' => sprintf("%06d", $reserv_id), 'venue' => $outlet->vendor_name, 'reservation_date' => date('d-F-Y', strtotime($edit_date1)), 'reservation_time' => date('g:i a', strtotime($this->request->input('edit_time'))));
             //echo "<br/>---datapost---<pre>"; print_r($dataPost);die;
             Mail::send('site.pages.edit_restaurant_reservation', ['location_details' => $locationDetails, 'outlet' => $outlet, 'post_data' => $dataPost, 'productDetails' => $vendorDetails], function ($message) use($dataPost) {
                 $message->from('*****@*****.**', 'WowTables by GourmetItUp');
                 $message->to($dataPost['guestEmail'])->subject('Your WowTables Reservation at ' . $dataPost['venue'] . ' has been changed');
                 //$message->cc('*****@*****.**', '*****@*****.**');
             });
             $dataPost['admin_email'] = 1;
             $dataPost['final_reservation_party_size'] = $reservation_party_size;
             $dataPost['final_reservation_date'] = $reservation_date;
             $dataPost['final_reservation_time'] = $reservation_time;
             Mail::send('site.pages.edit_restaurant_reservation', ['location_details' => $locationDetails, 'outlet' => $outlet, 'post_data' => $dataPost, 'productDetails' => $vendorDetails], function ($message) use($dataPost) {
                 $message->from('*****@*****.**', 'WowTables by GourmetItUp');
                 $message->to('*****@*****.**')->subject('ER - #A' . $dataPost['order_id'] . ' | ' . $dataPost['reservation_date'] . ' , ' . $dataPost['reservation_time'] . ' | ' . $dataPost['venue'] . ' | ' . $dataPost['guestName']);
                 $message->cc(['*****@*****.**', '*****@*****.**']);
             });
         }
     }
     echo '1';
 }
 /**
  * Handles requests for updating an existing reservation.
  * 
  * @access	public
  * @return	response
  * @since	1.0.0
  */
 public function changeReservation()
 {
     //array to store response
     $arrResponse = array();
     //reading data input by the user
     $data = $this->request->all();
     /*
     		//reading the reservation rules
     		$arrRule = Reservation::$arrRules;
     		
     		//updating the validation rule for reservation time
     		$arrRule['reservationTime'] = 'required|OutsidePrevReservationTimeRange: reservationDate, reservationID'; 
     */
     //print_r($data); die();
     //validating user data
     $validator = Validator::make($data, Reservation::$arrRules);
     //print_r($validator->fails());die;
     if ($validator->fails()) {
         $message = $validator->messages();
         $errorMessage = "";
         foreach ($data as $key => $value) {
             if ($message->has($key)) {
                 $errorMessage .= $message->first($key) . '\\n ';
             }
         }
         $arrResponse['status'] = Config::get('constants.API_ERROR');
         $arrResponse['error'] = $errorMessage;
     } else {
         //validating the user input data
         $arrResponse = Reservation::validateEditReservationData($data);
         //die('hello');
         if ($arrResponse['status'] == Config::get('constants.API_SUCCESS')) {
             $arrResponse = ReservationDetails::updateReservationDetail($data);
         }
     }
     if (!empty($data['reservationID'])) {
         $tokens = ReservationModel::pushToRestaurant($data['reservationID']);
         $this->restaurantapp->push($data['reservationID'], $tokens, true);
     }
     return response()->json($arrResponse, 200);
 }
 public function today()
 {
     $todayBookings = array();
     $count = 0;
     $statusCancelledNew = DB::select(DB::raw('select rd.id as reservation_id,rd.user_id as user_id from reservation_details as rd left join reservation_attributes_date as rad on rd.id = rad.reservation_id where DATE(rad.attribute_value) = \'' . Carbon::now()->format('Y-m-d') . '\''));
     $reservationIdArr = array();
     foreach ($statusCancelledNew as $reservId) {
         $reservationIdArr[$reservId->reservation_id] = $reservId->user_id;
     }
     $reservStatusArr = $this->reservationDetails->getReservationStatus(array_keys($reservationIdArr), [1, 2, 3, 6, 7, 8]);
     $todayPaginate = ReservationDetails::with('experience', 'vendor_location.vendor', 'vendor_location.address.city_name', 'attributesDatetime')->where('vendor_location_id', '!=', '0')->where('vendor_location_id', '!=', '54')->whereIn('id', array_keys($reservationIdArr))->where('created_at', '>=', '2015-10-12 15:20:00')->orderBy('created_at', 'desc')->paginate(15);
     foreach (ReservationDetails::with('experience', 'vendor_location.vendor', 'vendor_location.address.city_name', 'attributesDatetime')->where('vendor_location_id', '!=', '0')->where('vendor_location_id', '!=', '54')->whereIn('id', array_keys($reservationIdArr))->where('created_at', '>=', '2015-10-12 15:20:00')->orderBy('created_at', 'desc')->paginate(15) as $today) {
         $booking = new \stdClass();
         $booking->id = $today->id;
         /*$reservCarbonDate = Carbon::createFromFormat('Y-m-d H:i:s',$today->attributesDatetime->attribute_value);
         		$booking->bdate = $reservCarbonDate->format('d-m-Y');
         		$booking->btime = $reservCarbonDate->format('h:i A');*/
         if ($today->product_id == 0) {
             $booking->name = "Classic Reservation";
         } else {
             $booking->name = $today->experience->name;
         }
         $booking->cust_name = $today->guest_name;
         if (isset($today->vendor_location->vendor->name)) {
             $booking->restaurant_name = $today->vendor_location->vendor->name;
         } else {
             $booking->restaurant_name = "";
         }
         if (empty($today->vendor_location->address->city_name)) {
             $booking->city = "";
         } else {
             $booking->city = $today->vendor_location->address->city_name->name;
         }
         //$reservStatus = $today->reservationStatus->first();
         //dd($reservStatus);
         $booking->email = $today->guest_email;
         $booking->phone_no = $today->guest_phone;
         $booking->no_of_persons = $today->no_of_persons;
         //$booking->status = $reservStatus->status;
         $userModel = User::find($reservationIdArr[$today->id]);
         $booking->lastmodified = $userModel->role->name;
         $booking->user_id = $today->user_id;
         $statusArr = $this->reservStatuses;
         $statusKey = array_search($reservStatusArr[$today->id], $statusArr);
         if ($statusKey != -1) {
             unset($statusArr[$statusKey]);
         }
         $booking->reserv_status = $reservStatusArr[$today->id][0];
         $booking->statusArr = $statusArr;
         $reservationDetailsAttr = $this->reservationDetails->getByReservationId($today->id);
         $booking->special_request = isset($reservationDetailsAttr['attributes']['special_request']) ? $reservationDetailsAttr['attributes']['special_request'] : "";
         $booking->gift_card_id = isset($reservationDetailsAttr['attributes']['gift_card_id_reserv']) ? $reservationDetailsAttr['attributes']['gift_card_id_reserv'] : "";
         $booking->outlet = isset($reservationDetailsAttr['attributes']['outlet']) ? $reservationDetailsAttr['attributes']['outlet'] : "";
         $booking->reserv_type = $reservationDetailsAttr['attributes']['reserv_type'];
         $reservCarbonDate = Carbon::createFromFormat('Y-m-d H:i:s', $reservationDetailsAttr['attributes']['reserv_datetime']);
         $booking->bdate = $reservCarbonDate->format('d-m-Y');
         $booking->btime = $reservCarbonDate->format('h:i A');
         $todayBookings[$count] = $booking;
         $count++;
         //print_r($today);
     }
     return view('admin.bookings.list.today')->with('todaysbookings', $todayBookings)->with('today_paginate', $todayPaginate);
 }
 public function exporder()
 {
     //echo "<pre>"; print_r(Input::all()); die;
     $dataPost['reservationDate'] = Input::get('booking_date');
     $dataPost['reservationDay'] = date("D", strtotime($dataPost['reservationDate']));
     //
     $dataPost['reservationTime'] = Input::get('booking_time');
     $dataPost['partySize'] = Input::get('qty');
     $dataPost['vendorLocationID'] = Input::get('address');
     $dataPost['guestName'] = Input::get('fullname');
     $dataPost['guestEmail'] = Input::get('email');
     $dataPost['phone'] = Input::get('phone');
     $dataPost['reservationType'] = isset($dataPost['prepaid']) && $dataPost['prepaid'] == 1 ? 'event' : 'experience';
     $dataPost['specialRequest'] = Input::get('special');
     $dataPost['addon'] = Input::get('add_ons');
     $dataPost['giftCardID'] = Input::get('giftcard_id');
     $dataPost['status'] = Input::get('prepaid') == 1 ? "unpaid" : "new";
     $dataPost['prepaid'] = Input::get('prepaid');
     $count = $dataPost['addon'];
     if ($count == "") {
         $dataPost['addon'] = array();
     }
     $addonsText = '';
     $addonsPostTaxTotal = '';
     foreach ($dataPost['addon'] as $prod_id => $qty) {
         if ($qty > 0) {
             //echo "prod id = ".$prod_id." , qty = ".$qty;
             $addonsDetails = DB::select("SELECT attribute_value from product_attributes_text where product_id = {$prod_id} and product_attribute_id = 17");
             $addonsPricing = DB::select("SELECT post_tax_price from product_pricing where product_id = {$prod_id}");
             $addonsPostTaxTotal += $qty * $addonsPricing[0]->post_tax_price;
             //echo "<pre>"; print_r($addonsDetails);
             $addonsText .= $addonsDetails[0]->attribute_value . " (" . $qty . ") , ";
             $dataPost['addon_' . $prod_id] = $qty;
         }
     }
     $dataPost['total_amount'] = Input::get('post_amount') + $addonsPostTaxTotal;
     //echo "grand total addons = ".$addonsPostTaxTotal." , grand total = ".$dataPost['total_amount'];die;
     $finalAddontext = isset($addonsText) && $addonsText != "" ? "Addons: " . $addonsText : " ";
     $special_request = isset($dataPost['specialRequest']) && $dataPost['specialRequest'] != "" ? "Spl Req: " . $dataPost['specialRequest'] : "";
     $dataPost['addons_special_request'] = $finalAddontext . " " . $special_request;
     //echo "<pre>"; print_r($dataPost); die;
     //echo $finalSpecialRequest;
     //die;
     $userID = Session::get('id');
     $userData = Profile::getUserProfileWeb($userID);
     //echo "<pre>"; print_r($userData); die;
     //$dataPost['access_token'] = Session::get('id');
     //echo "<pre>"; print_r($dataPost); die;
     $locationDetails = $this->experiences_model->getLocationDetails($dataPost['vendorLocationID']);
     //echo "<pre>"; print_r($locationDetails); //die;
     $outlet = $this->experiences_model->getOutlet($dataPost['vendorLocationID']);
     //echo "<pre>"; print_r($outlet);
     //die;
     $productDetails = $this->repository->getByExperienceId($outlet->product_id);
     //echo "<pre>"; print_r($productDetails); die;
     $dataPost['product_id'] = isset($outlet->product_id) && $outlet->product_id != 0 ? $outlet->product_id : 0;
     $dataPost['vendor_location_id'] = isset($outlet->vendor_location_id) && $outlet->vendor_location_id != 0 ? $outlet->vendor_location_id : 0;
     //echo "<pre>"; print_r($dataPost); //die;
     $arrRules = array('reservationDate' => 'required|date', 'reservationDay' => 'required', 'reservationTime' => 'required', 'partySize' => 'required|integer', 'vendorLocationID' => 'required|not_in:0', 'guestName' => 'required|max:255', 'guestEmail' => 'required|email|max:255', 'phone' => 'required', 'reservationType' => 'required|in:experience,alacarte,event', 'specialRequest' => 'max:512');
     $validator = Validator::make($dataPost, $arrRules);
     if ($validator->fails()) {
         //echo "validation fails";
         $message = $validator->messages();
         $errorMessage = "";
         foreach ($data as $key => $value) {
             if ($message->has($key)) {
                 $errorMessage .= $message->first($key) . '\\n ';
             }
         }
         return redirect()->back()->withErrors($validator);
     } else {
         //End MailChimp
         //echo "validates success";
         if ($userID > 0) {
             //validating the information submitted by users
             $arrResponse = $this->experiences_model->validateReservationData($dataPost);
             //echo "checking validation";
             if ($arrResponse['status'] == 'success') {
                 /*$getUsersDetails = $this->user->fetchDetails($userID);
                   echo "<pre>"; print_r($getUsersDetails); die;*/
                 //echo "status is success";
                 $reservationResponse = $this->experiences_model->addReservationDetails($dataPost, $userID);
                 //die;
                 //for the new db structure support
                 $combined_date_and_time = $dataPost['reservationDate'] . ' ' . $dataPost['reservationTime'];
                 //echo Carbon::createFromFormat('Y-m-d H:i A',$combined_date_and_time)->toDateTimeString();die;
                 $newDb['attributes']['reserv_datetime'] = Carbon::createFromFormat('Y-m-d H:i A', $combined_date_and_time)->toDateTimeString();
                 //$newDb['attributes']['time'] = date("g:i A", strtotime($dataPost['reservationTime']));
                 $newDb['attributes']['no_of_people_booked'] = $dataPost['partySize'];
                 $newDb['attributes']['cust_name'] = $dataPost['guestName'];
                 $newDb['attributes']['email'] = $dataPost['guestEmail'];
                 $newDb['attributes']['contact_no'] = $dataPost['phone'];
                 $newDb['attributes']['reserv_type'] = "Experience";
                 $newDb['attributes']['gift_card_id_reserv'] = $dataPost['giftCardID'];
                 $newDb['attributes']['loyalty_points_awarded'] = $productDetails['attributes']['reward_points_per_reservation'];
                 $newDb['attributes']['special_request'] = trim($dataPost['addons_special_request']);
                 $newDb['attributes']['experience'] = $outlet->vendor_name . ' - ' . $outlet->descriptive_title;
                 $newDb['attributes']['api_added'] = "Web Reservation";
                 $newDb['attributes']['giu_membership_id'] = $userData['data']['membership_number'];
                 $newDb['attributes']['outlet'] = $outlet->name;
                 $newDb['attributes']['auto_reservation'] = "Not available";
                 $newDb['attributes']['ar_confirmation_id'] = "0";
                 $newDb['attributes']['alternate_id'] = 'E' . sprintf("%06d", $reservationResponse['data']['reservationID']);
                 $newDb['attributes']['reservation_status_id'] = 1;
                 $newDb['userdetails']['user_id'] = $userID;
                 $newDb['userdetails']['status'] = 1;
                 $newDb['userdetails']['addons'] = $dataPost['addon'];
                 //print_r($newDb);die;
                 $reservDetails = new ReservationDetails();
                 $newDbStatus = $reservDetails->updateAttributes($reservationResponse['data']['reservationID'], $newDb);
                 $tokens = $reservDetails->pushToRestaurant($reservationResponse['data']['reservationID']);
                 //print_r($tokens);die;
                 $this->restaurantapp->push($reservationResponse['data']['reservationID'], $tokens, true);
                 //print_r($newDbStatus);die;
                 /*TODO: Add the status of success check and include added_by and transaction_id attributes */
                 //die;
                 if (isset($dataPost['prepaid']) && $dataPost['prepaid'] == 1) {
                     //echo "prepaid is true";
                     Session::forget('email_session');
                     $cookiearray = array('reservationDate' => $dataPost['reservationDate'], 'reservationDay' => $dataPost['reservationDay'], 'reservationTime' => $dataPost['reservationTime'], 'partySize' => $dataPost['partySize'], 'vendorLocationID' => $dataPost['vendorLocationID'], 'guestName' => $dataPost['guestName'], 'guestEmail' => $dataPost['guestEmail'], 'phone' => $dataPost['phone'], 'reservationType' => $dataPost['reservationType'], 'specialRequest' => $dataPost['specialRequest'], 'giftCardID' => isset($dataPost['giftCardID']) && $dataPost['giftCardID'] != "" ? $dataPost['giftCardID'] : "", 'status' => $dataPost['status'], 'prepaid' => $dataPost['prepaid'], 'addons_special_request' => $dataPost['addons_special_request'], 'product_id' => $dataPost['product_id'], 'vendor_location_id' => $dataPost['vendor_location_id'], 'vendor_id' => $outlet->vendor_id, 'total_amount' => $dataPost['total_amount'], 'order_id' => $reservationResponse['data']['reservationID'], 'user_id' => $userID, 'reward_points' => $productDetails['attributes']['reward_points_per_reservation'], 'bookingsMade' => $userData['data']['bookings_made'] + 1, 'restaurant_name' => $outlet->vendor_name, 'descriptive_title' => $outlet->descriptive_title, 'membership_number' => $userData['data']['membership_number'], 'outlet_name' => $outlet->name, 'experience_title' => $outlet->product_name, 'experience_description' => $productDetails['attributes']['short_description'], 'order_id_digits' => sprintf("%06d", $reservationResponse['data']['reservationID']), 'experience_includes' => $productDetails['attributes']['experience_includes'], 'terms_and_conditions' => $productDetails['attributes']['terms_and_conditions'], 'short_description' => $productDetails['attributes']['short_description'], 'address' => $locationDetails->address, 'lat' => $locationDetails->latitude, 'long' => $locationDetails->longitude, 'slug' => $outlet->slug);
                     //echo "<pre>"; print_r($cookiearray); die;
                     if (isset($dataPost['addon']) && !empty($dataPost['addon'])) {
                         //echo "set addons in cookie";
                         foreach ($dataPost['addon'] as $prod_id => $qty) {
                             if ($qty > 0) {
                                 //echo "prod id = ".$prod_id." , qty = ".$qty;
                                 $addonsDetails = DB::select("SELECT attribute_value from product_attributes_text where product_id = {$prod_id} and product_attribute_id = 17");
                                 $cookiearray['addon_' . $prod_id] = $qty;
                             }
                         }
                     }
                     $city_id = Input::get('city');
                     $city_name = Location::where(['Type' => 'City', 'id' => $city_id])->pluck('name');
                     if (empty($city_name)) {
                         $city_name = 'mumbai';
                     }
                     $cookiearray['allow_guest'] = 'Yes';
                     $cookiearray['current_city'] = strtolower($city_name);
                     $cookiearray['current_city_id'] = $city_id;
                     Session::put('email_session', $cookiearray);
                     //die;
                     //echo "<pre>sad = "; print_r($_COOKIE); die;
                     return view('site.pages.payment', ['cookie_array' => $cookiearray]);
                 } else {
                     //echo "not prepaid";
                     $rewardsPoints = $productDetails['attributes']['reward_points_per_reservation'];
                     $bookingsMade = $userData['data']['bookings_made'] + 1;
                     $type = "new";
                     $reservationType = "experience";
                     $lastOrderId = $reservationResponse['data']['reservationID'];
                     //echo "rewardsPoints = ".$rewardsPoints." , bookingsMade = ".$bookingsMade." , type = ".$type." , reservationType = ".$reservationType; die;
                     Profile::updateReservationInUsers($rewardsPoints, $type, $bookingsMade, $reservationType, $userID, $lastOrderId);
                     DB::table('users')->where('id', $userID)->update(array('full_name' => $dataPost['guestName'], 'phone_number' => $dataPost['phone']));
                     //echo "<pre>"; print_r($reservationResponse); die;
                     $zoho_data = array('Name' => $dataPost['guestName'], 'Email_ids' => $dataPost['guestEmail'], 'Contact' => $dataPost['phone'], 'Experience_Title' => $outlet->vendor_name . ' - ' . $outlet->descriptive_title, 'No_of_People' => $dataPost['partySize'], 'Date_of_Visit' => date('d-M-Y', strtotime($dataPost['reservationDate'])), 'Time' => date("g:i A", strtotime($dataPost['reservationTime'])), 'Alternate_ID' => 'E' . sprintf("%06d", $reservationResponse['data']['reservationID']), 'Special_Request' => $dataPost['addons_special_request'], 'Type' => "Experience", 'API_added' => 'Web Reservation', 'GIU_Membership_ID' => $userData['data']['membership_number'], 'Outlet' => $outlet->name, 'AR_Confirmation_ID' => '0', 'Auto_Reservation' => 'Not available', 'Calling_option' => 'No', 'gift_card_id_from_reservation' => $dataPost['giftCardID']);
                     //echo "<pre>"; print_r($zoho_data);
                     $zoho_res = $this->zoho_add_booking($zoho_data);
                     $zoho_success = $zoho_res->result->form->add->status;
                     //echo "<pre>"; print_r($zoho_success); die;
                     if ($zoho_success[0] != "Success") {
                         //$this->email->from('*****@*****.**', 'WowTables by GourmetItUp');
                         //$list = array('*****@*****.**', '*****@*****.**', '*****@*****.**');
                         //$this->email->to($list);
                         //$this->email->subject('Urgent: Zoho reservation posting error');
                         $mailbody = 'E' . sprintf("%06d", $reservationResponse['data']['reservationID']) . ' reservation has not been posted to zoho. Please fix manually.<br><br>';
                         $mailbody .= 'Reservation Details<br>';
                         foreach ($zoho_data as $key => $val) {
                             $name = str_replace('_', ' ', $key);
                             $mailbody .= $name . ' ' . $val . '<br>';
                         }
                         Mail::send('site.pages.zoho_posting_error', ['zoho_data' => $mailbody], function ($message) use($zoho_data) {
                             $message->from('*****@*****.**', 'WowTables by GourmetItUp');
                             $message->to('*****@*****.**')->subject('Urgent: Zoho reservation posting error');
                             $message->cc(['*****@*****.**', '*****@*****.**']);
                         });
                     }
                     $city_id = Input::get('city');
                     $footerpromotions = DB::select('SELECT efp.link,mrn.file  FROM email_footer_promotions as efp LEFT JOIN media_resized_new as mrn ON mrn.media_id = efp.media_id WHERE efp.show_in_experience = 1 AND efp.city_id = ' . $city_id);
                     //echo "<pre>"; print_r($footerpromotions); die;
                     $mergeReservationsArray = array('order_id' => sprintf("%06d", $reservationResponse['data']['reservationID']), 'reservation_date' => date('d-F-Y', strtotime($dataPost['reservationDate'])), 'reservation_time' => date('g:i a', strtotime($dataPost['reservationTime'])), 'venue' => $outlet->vendor_name, 'username' => $dataPost['guestName']);
                     Mail::send('site.pages.experience_reservation', ['location_details' => $locationDetails, 'outlet' => $outlet, 'post_data' => $dataPost, 'productDetails' => $productDetails, 'reservationResponse' => $reservationResponse, 'footerPromotions' => !empty($footerpromotions) ? $footerpromotions : ""], function ($message) use($mergeReservationsArray) {
                         $message->from('*****@*****.**', 'WowTables by GourmetItUp');
                         $message->to(Input::get('email'))->subject('Your WowTables Reservation at ' . $mergeReservationsArray['venue']);
                         //$message->cc('*****@*****.**', '*****@*****.**');
                     });
                     $dataPost['admin'] = "yes";
                     Mail::send('site.pages.experience_reservation', ['location_details' => $locationDetails, 'outlet' => $outlet, 'post_data' => $dataPost, 'productDetails' => $productDetails, 'reservationResponse' => $reservationResponse, 'footerPromotions' => !empty($footerpromotions) ? $footerpromotions : ""], function ($message) use($mergeReservationsArray) {
                         $message->from('*****@*****.**', 'WowTables by GourmetItUp');
                         $message->to('*****@*****.**')->subject('NR - #E' . $mergeReservationsArray['order_id'] . ' | ' . $mergeReservationsArray['reservation_date'] . ' , ' . $mergeReservationsArray['reservation_time'] . ' | ' . $mergeReservationsArray['venue'] . ' | ' . $mergeReservationsArray['username']);
                         $message->cc(['*****@*****.**', '*****@*****.**', '*****@*****.**']);
                     });
                     $mergeReservationsArray = array('order_id' => sprintf("%06d", $reservationResponse['data']['reservationID']), 'reservation_date' => date('d-F-Y', strtotime($dataPost['reservationDate'])), 'reservation_time' => date('g:i a', strtotime($dataPost['reservationTime'])), 'venue' => $outlet->vendor_name, 'username' => $dataPost['guestName']);
                     //echo "userid == ".$userID;
                     $getUsersDetails = $this->experiences_model->fetchDetails($userID);
                     $cities = Location::where(['Type' => 'City', 'visible' => 1])->lists('name', 'id');
                     $arrResponse['cities'] = $cities;
                     $city_id = Input::get('city');
                     $city_name = Location::where(['Type' => 'City', 'id' => $city_id])->pluck('name');
                     if (empty($city_name)) {
                         $city_name = 'mumbai';
                     }
                     //Start MailChimp
                     $city = ucfirst($userData['data']['location']);
                     if (!empty($getUsersDetails)) {
                         $merge_vars = array('MERGE1' => $dataPost['guestName'], 'MERGE10' => date('m/d/Y'), 'MERGE11' => $userData['data']['bookings_made'] + 1, 'MERGE13' => $dataPost['phone'], 'MERGE27' => date("m/d/Y", strtotime($dataPost['reservationDate'])), 'GROUPINGS' => array(array('id' => 9713, 'groups' => [$city])));
                         $this->mailchimp->lists->subscribe($this->listId, ["email" => $dataPost['guestEmail']], $merge_vars, "html", false, true);
                     }
                     $arrResponse['allow_guest'] = 'Yes';
                     $arrResponse['current_city'] = strtolower($city_name);
                     $arrResponse['current_city_id'] = $city_id;
                     $arrResponse['restaurant_name'] = $outlet->vendor_name;
                     $arrResponse['experience_title'] = $outlet->product_name;
                     $arrResponse['experience_description'] = $productDetails['attributes']['short_description'];
                     $arrResponse['reservation_date'] = $dataPost['reservationDate'];
                     $arrResponse['reservation_time'] = $dataPost['reservationTime'];
                     $arrResponse['order_id'] = $mergeReservationsArray['order_id'];
                     $arrResponse['guests'] = $dataPost['partySize'];
                     $arrResponse['experience_includes'] = $productDetails['attributes']['experience_includes'];
                     $arrResponse['terms_and_conditions'] = $productDetails['attributes']['terms_and_conditions'];
                     $arrResponse['short_description'] = $productDetails['attributes']['short_description'];
                     $arrResponse['address'] = $locationDetails->address;
                     $arrResponse['lat'] = $locationDetails->latitude;
                     $arrResponse['long'] = $locationDetails->longitude;
                     $arrResponse['city'] = $arrResponse['current_city'];
                     $arrResponse['slug'] = $outlet->slug;
                     $arrResponse['total_amount'] = $dataPost['total_amount'];
                     $arrResponse['guestEmail'] = $dataPost['guestEmail'];
                     $arrResponse['guestName'] = $dataPost['guestName'];
                     $arrResponse['outlet_name'] = $outlet->name;
                     $arrResponse['product_id'] = $outlet->product_id;
                     $arrResponse['vendor_location_id'] = $outlet->vendor_location_id;
                     $arrResponse['vendor_id'] = $outlet->vendor_id;
                     //echo "<pre>"; print_r($arrResponse); die;
                     return Redirect::to('/experiences/thankyou/E' . $mergeReservationsArray['order_id'])->with('response', $arrResponse);
                 }
             }
         } else {
             return redirect()->back()->withErrors($validator);
         }
     }
 }