/**
  * Execute the command.
  *
  * @param RestaurantLocationsRepository|ExperiencesRepository $repository
  * @param Product $product
  * @return array
  */
 public function handle(ExperiencesRepository $repository, Product $product)
 {
     $experience = $product->add($this->vendor_id, $this->product_type_id, $this->name, $this->slug, $this->status, $this->restaurant_locations, $this->short_description, $this->description, $this->seo_title, $this->seo_meta_description, $this->seo_meta_keywords, $this->main_image, $this->listing_image, $this->gallery_images, $this->min_people_per_reservation, $this->max_people_per_reservation, $this->max_reservation_per_time_slot, $this->max_reservation_per_day, $this->min_reservation_time_buffer, $this->max_reservation_time_buffer, $this->commision_per_reservation, $this->prepayment, $this->reward_points_per_reservation, $this->tax, $this->price_before_tax, $this->price_after_tax, $this->price_type, $this->commission_calculated_on, $this->addons, $this->allow_gift_card_redemption, $this->allow_cancellations, $this->terms_conditions, $this->publish_date, $this->publish_time);
     $response = $repository->add($experience);
     //event(new NewUserWasRegistered($this->email,$this->full_name));
     return $response;
 }
 public function getByExperienceId($id)
 {
     $productWithAttributes = Product::with('attributesBoolean', 'attributesDate', 'attributesInteger', 'attributesFloat', 'attributesText', 'attributesVarChar', 'attributesSingleSelect', 'attributesMultiSelect')->findOrFail($id);
     /*->wherehas('vendor.vendorType',function($q) {
           $q->where('type','Restaurants');
       })->first();*/
     //dd(array_flatten($vendorLocationWithAttributes->schedules->toArray()));
     $this->populateExperienceAttributes($productWithAttributes->attributesBoolean);
     $this->populateExperienceAttributes($productWithAttributes->attributesInteger);
     $this->populateExperienceAttributes($productWithAttributes->attributesFloat);
     $this->populateExperienceAttributes($productWithAttributes->attributesDate);
     $this->populateExperienceAttributes($productWithAttributes->attributesText);
     $this->populateExperienceAttributes($productWithAttributes->attributesVarChar);
     $this->populateExperienceAttributes($productWithAttributes->attributesSingleSelect);
     $this->populateExperienceMultiSelectAttributes($productWithAttributes->attributesMultiSelect);
     //$this->populateExperienceSchedules($id);
     return ['Experience' => Product::find($id), 'attributes' => $this->attributes];
 }
 /**
  * Push this reservation to specified devices
  *
  * @param  int  $id
  * @return Response
  */
 public function push($id, $tokenArr, $showNotification)
 {
     try {
         $reservation = array();
         $key = 'reservation_id';
         $value = (int) $id;
         $reservation[$key] = $value;
         //Int type
         $reservationIntAttrArr = ReservationAttributesInteger::where('reservation_id', (int) $id)->get();
         foreach ($reservationIntAttrArr as $reservationIntAttr) {
             $key = $reservationIntAttr->attribute->alias;
             $value = $reservationIntAttr->attribute_value;
             $reservation[$key] = $value;
             //Check log for same attribute
             $reservationStatusLog = ReservationStatusLog::where(['reservation_id' => $reservationIntAttr->reservation_id, 'new_reservation_status_id' => ReservationController::$edited_status_id])->orderBy('created_at', 'DESC')->first();
             if ($reservationStatusLog != null) {
                 $reservationIntAttrLogArr = ReservationAttributesIntegerLog::where(['reservation_attribute_id' => $reservationIntAttr->attribute->id, 'reservation_status_log_id' => $reservationStatusLog->id])->get();
                 foreach ($reservationIntAttrLogArr as $reservationIntAttrLog) {
                     $key = "old_" . $reservationIntAttrLog->attribute->alias;
                     $value = $reservationIntAttrLog->old_attribute_value;
                     $reservation[$key] = $value;
                 }
             }
         }
         //Float type
         $reservationFloatAttrArr = ReservationAttributesFloat::where('reservation_id', (int) $id)->get();
         foreach ($reservationFloatAttrArr as $reservationFloatAttr) {
             $key = $reservationFloatAttr->attribute->alias;
             $value = $reservationFloatAttr->attribute_value;
             $reservation[$key] = $value;
         }
         //Date type
         $reservationDateAttrArr = ReservationAttributesDate::where('reservation_id', (int) $id)->get();
         foreach ($reservationDateAttrArr as $reservationDateAttr) {
             $key = $reservationDateAttr->attribute->alias;
             $value = $reservationDateAttr->attribute_value;
             $reservation[$key] = $value;
             //Check log for same attribute
             $reservationStatusLog = ReservationStatusLog::where(['reservation_id' => $reservationDateAttr->reservation_id, 'new_reservation_status_id' => ReservationController::$edited_status_id])->orderBy('created_at', 'DESC')->first();
             if ($reservationStatusLog != null) {
                 $reservationDateAttrLogArr = ReservationAttributesDateLog::where(['reservation_attribute_id' => $reservationDateAttr->attribute->id, 'reservation_status_log_id' => $reservationStatusLog->id])->get();
                 foreach ($reservationDateAttrLogArr as $reservationDateAttrLog) {
                     $key = "old_" . $reservationDateAttrLog->attribute->alias;
                     $value = $reservationDateAttrLog->old_attribute_value;
                     $reservation[$key] = $value;
                 }
             }
         }
         //Text type
         $reservationTextAttrArr = ReservationAttributesText::where('reservation_id', (int) $id)->get();
         foreach ($reservationTextAttrArr as $reservationTextAttr) {
             $key = $reservationTextAttr->attribute->alias;
             $value = $reservationTextAttr->attribute_value;
             $reservation[$key] = $value;
             $reservationStatusLog = ReservationStatusLog::where(['reservation_id' => $reservationTextAttr->reservation_id, 'new_reservation_status_id' => ReservationController::$edited_status_id])->orderBy('created_at', 'DESC')->first();
             if ($reservationStatusLog != null) {
                 $reservationTextAttrLogArr = ReservationAttributesTextLog::where(['reservation_attribute_id' => $reservationTextAttr->attribute->id, 'reservation_status_log_id' => $reservationStatusLog->id])->get();
                 foreach ($reservationTextAttrLogArr as $reservationTextAttrLog) {
                     $key = "old_" . $reservationTextAttrLog->attribute->alias;
                     $value = $reservationTextAttrLog->old_attribute_value;
                     $reservation[$key] = $value;
                 }
             }
         }
         //Boolean type
         $reservationBoolAttrArr = ReservationAttributesBoolean::where('reservation_id', (int) $id)->get();
         foreach ($reservationBoolAttrArr as $reservationBoolAttr) {
             $key = $reservationBoolAttr->attribute->alias;
             $value = $reservationBoolAttr->attribute_value;
             if ($value == 1) {
                 $reservation[$key] = true;
             } else {
                 $reservation[$key] = false;
             }
         }
         //VarChar type
         $reservationVarcharAttrArr = ReservationAttributesVarchar::where('reservation_id', (int) $id)->get();
         foreach ($reservationVarcharAttrArr as $reservationVarcharAttr) {
             $key = $reservationVarcharAttr->attribute->alias;
             $value = $reservationVarcharAttr->attribute_value;
             $reservation[$key] = $value;
         }
         //Get Customer
         $reservationDetail = ReservationDetail::where('id', (int) $id)->first();
         if ($reservationDetail) {
             $reservation['reservation_type'] = $reservationDetail->reservation_type;
             $customer = array();
             $customer['id'] = $reservationDetail->user->id;
             $customer['full_name'] = $reservationDetail->user->full_name;
             $customer['email'] = $reservationDetail->user->email;
             $customer['phone_number'] = $reservationDetail->user->phone_number;
             $customer['points_earned'] = $reservationDetail->user->points_earned;
             $customer['rating'] = UserRating::where(['user_id' => $reservationDetail->user, 'id' => $reservationDetail->id])->avg('rating');
             if ($customer['rating'] == null) {
                 $customer['rating'] = 0.0;
             }
             $customerPreferences = UserAttributesVarChar::where(['user_id' => $reservationDetail->user->id, 'user_attribute_id' => ReservationController::$cust_pref_attr_id])->first();
             if ($customerPreferences) {
                 $customer['customer_preferences'] = $customerPreferences->attribute_value;
             }
             $reservation['customer'] = $customer;
         }
         //Get Location
         $reservationDetail = ReservationDetail::where('id', (int) $id)->first();
         if ($reservationDetail) {
             $location = array();
             $vendorLocation = VendorLocation::where('id', $reservationDetail->vendor_location_id)->first();
             $location['location_id'] = $vendorLocation->location_id;
             $location['location'] = Location::where('id', $vendorLocation->location_id)->first()->name;
             $reservation['location'] = $location;
         }
         //Get Product
         $reservationDetail = ReservationDetail::where('id', (int) $id)->first();
         if ($reservationDetail && $reservationDetail->reservation_type == 'experience') {
             $product = array();
             $product['product_id'] = $reservationDetail->product_id;
             $product['product'] = Product::where('id', $reservationDetail->product_id)->first()->name;
             $addonsArr = Product::where('product_parent_id', $reservationDetail->product_id)->get();
             if (sizeof($addonsArr) > 0) {
                 $productAddonArr = array();
                 foreach ($addonsArr as $addon) {
                     $addons = array();
                     $addons['addon_id'] = $addon->id;
                     $addons['addon_name'] = $addon->name;
                     $reservationAddonDetail = ReservationAddonsVariantsDetail::where(['reservation_id' => (int) $id, 'reservation_status_id' => $reservation['reservation_status_id'], 'options_id' => $addon->id])->first();
                     if ($reservationAddonDetail != null) {
                         $addons['no_of_persons'] = $reservationAddonDetail->no_of_persons;
                     }
                     array_push($productAddonArr, $addons);
                 }
                 $product['addons'] = $productAddonArr;
             }
             $reservation['product'] = $product;
         }
         if ($showNotification) {
             $reservation["show_notfn"] = 1;
         } else {
             $reservation["show_notfn"] = 0;
         }
         //$tokenArr = json_decode($input['tokens'], true);
         foreach ($tokenArr as $token) {
             PushNotification::app('appNameAndroid')->to($token['token'])->send(json_encode($reservation));
         }
         $arrResponse['status'] = Config::get('constants.API_SUCCESS');
         return response()->json($arrResponse, 200);
     } catch (\Exception $e) {
         return response()->json(['message' => 'An application error occured.', 'error' => $e->getMessage()], 500);
     }
 }