/**
  * show Contact
  *
  * @param  Business           $business Business holding the Contact
  * @param  Contact            $contact  Desired Contact to show
  * @param  ViewContactRequest $request  Read access Request
  * @return Response                     Rendered view of Contact
  */
 public function show(Business $business, Contact $contact, ViewContactRequest $request)
 {
     $this->log->info(__METHOD__);
     $this->log->info(sprintf("  businessId:%s contactId:%s", $business->id, $contact->id));
     $memberSince = $business->contacts()->find($contact->id)->pivot->created_at;
     return view('user.contacts.show', compact('business', 'contact', 'memberSince'));
 }
 /**
  * post Import
  *
  * @param  Business $business Business to import Contacts to
  * @param  Request  $request  Submitted form data
  * @return Response           Redirect to Business addressbook
  */
 public function postImport(Business $business, Request $request)
 {
     $this->log->info(__METHOD__);
     $this->log->info(sprintf("  businessId:%s", $business->id));
     //////////////////
     // FOR REFACTOR //
     //////////////////
     $csv = $this->csvToArray(Request::get('data'));
     foreach ($csv as $import) {
         $import = array_map(function ($item) {
             return $item == 'NULL' ? null : $item;
         }, $import);
         if ($import['birthdate'] !== null) {
             $date = \DateTime::createFromFormat('Ymd', $import['birthdate']);
             $import['birthdate'] = $date->format('m/d/Y');
         }
         $notes = $import['notes'];
         unset($import['notes']);
         $contact = Contact::create($import);
         $business->contacts()->attach($contact, ['notes' => $notes]);
         $business->save();
     }
     $count = count($csv);
     $this->log->info("  Imported {$count} contacts");
     Notifynder::category('user.importedContacts')->from('App\\Models\\User', auth()->user()->id)->to('App\\Models\\Business', $business->id)->url('http://localhost')->extra(compact('count'))->send();
     Flash::success(trans('manager.contacts.msg.import.success'));
     return redirect()->route('manager.business.contact.index', [$business]);
 }
 /**
  * get Index
  *
  * @param  Business $business Business to get agenda
  * @return Response           Rendered view of Business agenda
  */
 public function getIndex(Business $business)
 {
     $this->log->info(__METHOD__);
     $this->log->info(sprintf("businessId:%s", $business->id));
     ///////////////////////////////
     // TODO: AUTH GATE GOES HERE //
     ///////////////////////////////
     //////////////////
     // FOR REFACTOR //
     //////////////////
     $appointments = $business->bookings()->with('contact')->with('business')->with('service')->unserved()->orderBy('start_at')->get();
     return view('manager.businesses.appointments.' . $business->strategy . '.index', compact('business', 'appointments'));
 }
 protected function setBusinessPreferences(Business $business, $preferences)
 {
     // Get parameters from app configuration
     $parameters = config()->get('preferences.App\\Models\\Business');
     // Get the keys of the parameters
     $parametersKeys = array_flip(array_keys($parameters));
     // Merge the user input with the parameter keys
     $mergedPreferences = array_intersect_key($preferences, $parametersKeys);
     // Store each parameter key-value pair to the business preferences
     foreach ($mergedPreferences as $key => $value) {
         $this->log->info(sprintf("set preference: businessId:%s key:%s='%s' type:%s", $business->id, $key, $value, $parameters[$key]['type']));
         $business->pref($key, $value, $parameters[$key]['type']);
     }
 }
Exemplo n.º 5
0
 /**
  * post Store.
  *
  * @param Request $request Input data of booking form
  *
  * @return Response Redirect to Appointments listing
  */
 public function postStore(Request $request)
 {
     $this->log->info(__METHOD__);
     //////////////////
     // FOR REFACTOR //
     //////////////////
     $issuer = auth()->user();
     $business = Business::findOrFail($request->input('businessId'));
     $contact = $issuer->getContactSubscribedTo($business->id);
     $service = Service::find($request->input('service_id'));
     $strDateTime = $request->input('_date') . ' ' . $business->pref('start_at');
     $datetime = Carbon::parse($strDateTime . ' ' . $business->timezone)->setTimezone('UTC');
     $comments = $request->input('comments');
     $this->concierge->setBusiness($business);
     $appointment = $this->concierge->makeReservation($issuer, $business, $contact, $service, $datetime, $comments);
     if (false === $appointment) {
         $this->log->info('[ADVICE] Unable to book');
         Flash::warning(trans('user.booking.msg.store.error'));
         return redirect()->route('user.agenda');
     }
     if (!$appointment->exists) {
         $this->log->info('[ADVICE] Appointment is duplicated');
         Flash::warning(trans('user.booking.msg.store.sorry_duplicated', ['code' => $appointment->code]));
         return redirect()->route('user.agenda');
     }
     $this->log->info('Appointment saved successfully');
     event(new NewBooking($issuer, $appointment));
     Flash::success(trans('user.booking.msg.store.success', ['code' => $appointment->code]));
     return redirect()->route('user.agenda');
 }
Exemplo n.º 6
0
 public static function queryUserInfo($keyword, $user_id = null)
 {
     $user_records = Watchdog::getUserRecords($user_id);
     $user_queues = Analytics::getUserQueues($user_id);
     $user_data = array_merge($user_records, $user_queues);
     $values = [];
     foreach ($user_data as $data) {
         if ($keyword === 'geolocation' && isset($data['latitude'])) {
             $values[] = $data['latitude'] . ', ' . $data['longitude'];
         } else {
             if ($keyword === 'broadcast' && isset($data['business_id'])) {
                 try {
                     $values[] = Business::name($data['business_id']);
                 } catch (Exception $e) {
                     $values[] = 'Deleted Businesses';
                 }
             } else {
                 if (isset($data[$keyword])) {
                     $values[] = $data[$keyword];
                 }
             }
         }
     }
     $numbers = array_count_values($values);
     return $numbers;
 }
Exemplo n.º 7
0
 /**
  * scan Businesses.
  *
  * @return void
  */
 protected function scanBusinesses()
 {
     $businesses = Business::all();
     foreach ($businesses as $business) {
         $this->sendBusinessReport($business);
     }
 }
Exemplo n.º 8
0
 private function getContacts($expression)
 {
     $businesses = Business::whereIn('id', $this->scope['businessesIds'])->get();
     foreach ($businesses as $business) {
         $collection = $business->contacts()->where(function ($query) use($expression) {
             $query->where('lastname', 'like', $expression . '%')->orWhere('firstname', 'like', $expression . '%')->orWhere('nin', $expression)->orWhere('mobile', 'like', '%' . $expression);
         })->get();
         $this->results['contacts'] = $collection;
     }
 }
Exemplo n.º 9
0
 /**
  * get Home.
  *
  * @param Business $business Business to display
  *
  * @return Response Rendered view for desired Business
  */
 public function getHome($slug)
 {
     logger()->info(__METHOD__);
     logger()->info(sprintf('slug:%s', $slug));
     if ($domain = Domain::where('slug', $slug)->first()) {
         return $this->getDomain($domain);
     }
     $business = Business::where('slug', $slug)->first();
     return view('guest.businesses.show', compact('business'));
 }
Exemplo n.º 10
0
 public static function getAllBusinessDetailsByOwner($user_id)
 {
     $businesses = [];
     $user_businesses = UserBusiness::getAllBusinessIdByOwner($user_id);
     foreach ($user_businesses as $user_business) {
         $business = Business::find($user_business->business_id);
         array_push($businesses, $business);
     }
     return $businesses;
 }
Exemplo n.º 11
0
 /**
  * Get available times.
  *
  * @param  int $businessId
  * @param  int $serviceId
  * @param  string $date
  *
  * @return Symfony\Component\HttpFoundation\JsonResponse
  */
 public function getTimes($businessId, $serviceId, $date)
 {
     logger()->info(__METHOD__);
     logger()->info("businessId:{$businessId} serviceId:{$serviceId} date:{$date}");
     $business = Business::findOrFail($businessId);
     $service = Service::findOrFail($serviceId);
     $vacancies = $business->vacancies()->forDate(Carbon::parse($date))->get();
     $times = $this->splitTimes($vacancies, $service);
     return response()->json(['business' => $businessId, 'service' => ['id' => $service->id, 'duration' => $service->duration], 'date' => $date, 'times' => $times], 200);
 }
Exemplo n.º 12
0
 /**
  * Define your route model bindings, pattern filters, etc.
  *
  * @param \Illuminate\Routing\Router $router
  *
  * @return void
  */
 public function boot(Router $router)
 {
     parent::boot($router);
     $router->model('contact', Contact::class);
     $router->model('service', Service::class);
     $router->model('appointment', Appointment::class);
     $router->bind('business', function ($businessSlug) {
         return Business::where('slug', $businessSlug)->first();
     });
 }
 /**
  * Define your route model bindings, pattern filters, etc.
  *
  * @param  \Illuminate\Routing\Router  $router
  * @return void
  */
 public function boot(Router $router)
 {
     parent::boot($router);
     $router->model('contact', 'App\\Models\\Contact');
     $router->model('business', 'App\\Models\\Business');
     $router->model('service', 'App\\Models\\Service');
     $router->model('appointment', 'App\\Models\\Appointment');
     $router->bind('business_slug', function ($business_slug) {
         return Business::where('slug', $business_slug)->get();
     });
 }
Exemplo n.º 14
0
 /**
  * store Business
  *
  * @param  BusinessFormRequest $request Business form Request
  * @return Response                     Redirect
  */
 public function store(BusinessFormRequest $request)
 {
     $this->log->info(__METHOD__);
     //////////////////
     // FOR REFACTOR //
     //////////////////
     // Search Existing
     $existingBusiness = Business::withTrashed()->where(['slug' => $request->input('slug')])->first();
     // If found
     if ($existingBusiness !== null) {
         $this->log->info("  Found existing businessId:{$existingBusiness->id}");
         // If owned, restore
         if (auth()->user()->isOwner($existingBusiness)) {
             $this->log->info("  Restoring owned businessId:{$existingBusiness->id}");
             $existingBusiness->restore();
             Flash::success(trans('manager.businesses.msg.store.restored_trashed'));
             return redirect()->route('manager.business.service.create', $existingBusiness);
         }
         // If not owned, return message
         $this->log->info("  Already taken businessId:{$existingBusiness->id}");
         Flash::error(trans('manager.businesses.msg.store.business_already_exists'));
         return redirect()->back()->withInput(request()->all());
     }
     // Register new Business
     $business = new Business($request->all());
     $category = Category::find($request->get('category'));
     $business->strategy = $category->strategy;
     $business->category()->associate($category);
     $business->save();
     auth()->user()->businesses()->attach($business);
     auth()->user()->save();
     // Generate local notification
     $business_name = $business->name;
     Notifynder::category('user.registeredBusiness')->from('App\\Models\\User', auth()->user()->id)->to('App\\Models\\Business', $business->id)->url('http://localhost')->extra(compact('business_name'))->send();
     // Redirect success
     Flash::success(trans('manager.businesses.msg.store.success'));
     return redirect()->route('manager.business.service.create', $business);
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Business $business, Request $request)
 {
     $this->log->info(__METHOD__);
     $this->log->info(sprintf("  businessId:%s", $business->id));
     ///////////////////////////////
     // TODO: AUTH GATE GOES HERE //
     ///////////////////////////////
     //////////////////
     // FOR REFACTOR //
     //////////////////
     $dates = $request->get('vacancy');
     $changed = false;
     foreach ($dates as $date => $vacancy) {
         foreach ($vacancy as $serviceId => $capacity) {
             switch (trim($capacity)) {
                 case '':
                     // Dont update, leave as is
                     $this->log->info("Blank vacancy capacity value");
                     break;
                 default:
                     $start_at = Carbon::parse($date . ' ' . $business->pref('start_at'))->timezone($business->timezone);
                     $finish_at = Carbon::parse($date . ' ' . $business->pref('finish_at', '20:00:00'))->timezone($business->timezone);
                     $vacancy = Vacancy::updateOrCreate(['business_id' => $business->id, 'service_id' => $serviceId, 'date' => $date], ['capacity' => intval($capacity), 'start_at' => $start_at, 'finish_at' => $finish_at]);
                     $changed = true;
                     break;
             }
         }
     }
     if (!$changed) {
         $this->log->warning("Nothing to update");
         Flash::warning(trans('manager.vacancies.msg.store.nothing_changed'));
         return redirect()->back();
     }
     $this->log->warning("Vacancies updated");
     Flash::success(trans('manager.vacancies.msg.store.success'));
     return redirect()->route('manager.business.show', [$business]);
 }
Exemplo n.º 16
0
 public function create($id)
 {
     $business = Business::all()->first();
     $event = Event::find($id);
     $presentations = Presentation::where('event_id', $id)->where('cancelled', 0)->where('starts_at', '>', strtotime(Carbon::now()))->get();
     foreach ($presentations as $presentation) {
         if ($presentation->cancelled == 0 || $presentation->cancelled != null) {
             $presentation->starts_at = date("d-m-Y h:i a", $presentation->starts_at);
         }
     }
     $presentations = $presentations->lists('starts_at', 'id');
     $zones = Zone::where('event_id', $id)->lists('name', 'id');
     $array = ['event' => $event, 'presentations' => $presentations, 'zones' => $zones, 'business' => $business];
     return view('external.booking.create', $array);
 }
Exemplo n.º 17
0
 /**
  * Update notes from pivot table.
  *
  * @param Business $business
  * @param Contact  $contact
  * @param string   $notes
  *
  * @return void
  */
 protected function updateNotes(Business $business, Contact $contact, $notes)
 {
     if ($notes) {
         $business->contacts()->find($contact->id)->pivot->update(['notes' => $notes]);
     }
 }
Exemplo n.º 18
0
 /**
  * get List.
  *
  * @return Response Rendered view of all existing Businesses
  */
 public function getList()
 {
     logger()->info(__METHOD__);
     $businesses = Business::all();
     return view('user.businesses.index', compact('businesses'));
 }
Exemplo n.º 19
0
 /**
  * Set category to a Business and save.
  * 
  * @param Business $business
  * @param int      $category
  *
  * @return App\Models\Business
  */
 public function setCategory(Business $business, $category)
 {
     $category = Category::find($category);
     $business->category()->associate($category);
     $business->save();
     return $business;
 }
Exemplo n.º 20
0
 /**
  * Get a Vacancy for a given DateTime and Service combination.
  *
  * @param Carbon  $targetDateTime
  * @param Service $service
  *
  * @return App\Models\Vacancy
  */
 public function getSlotFor(Carbon $targetDateTime, Service $service)
 {
     return $this->business->vacancies()->forDateTime($targetDateTime)->forService($service)->first();
 }
Exemplo n.º 21
0
 /**
  * 远层一对多关联
  * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
  * 商家表
  * 商品表
  * 订单表
  * 通过商家直接查找订单
  * A hasMany/hasOne B, B hasMany/hasOne C, then A hasManyThrough C (through B)
  */
 public function through()
 {
     $obj = new Business();
     $rows = $obj->find(1)->order;
     print_r($rows);
     return view('index');
 }
Exemplo n.º 22
0
 public static function numberLimit($service_id, $date = null)
 {
     $business_id = Business::getBusinessIdByServiceId($service_id);
     return Business::find($business_id)->queue_limit;
     //return QueueSettings::queueSetting('number_limit', 99, $service_id, $date);
 }
Exemplo n.º 23
0
 public function systemUpdate(UpdateSystemRequest $request)
 {
     $system = Business::all()->first();
     $system->business_name = $request['business_name'];
     $system->ruc = $request['ruc'];
     $system->address = $request['address'];
     $system->reserve_time = $request['reserve_time'];
     if ($request['gift_module_id'] == 0) {
         $system->gift_module_id = null;
     } else {
         $system->gift_module_id = $request['gift_module_id'];
     }
     if (isset($request['logo'])) {
         $system->logo = $this->file_service->upload($request->file('logo'), 'system');
     }
     if (isset($request['favicon'])) {
         $system->favicon = $this->file_service->upload($request->file('favicon'), 'system');
     }
     if ($request['exchange_active'] == true) {
         $system->exchange_active = true;
     } else {
         if ($request['exchange_active'] == false) {
             $system->exchange_active = false;
         }
     }
     $system->save();
     Session::flash('message', 'Se actualizaron los datos!');
     Session::flash('alert-class', 'alert-success');
     return redirect()->back();
 }
Exemplo n.º 24
0
 public function createExchangePost(exchangeGift $request)
 {
     $business = Business::all()->first();
     $active = $business->exchange_active;
     $modulo = 'La marina y el marino';
     if ($active == 0) {
         $giftsArr = Gift::all();
         $giftsList = Gift::orderBy('id')->get()->lists('name', 'id');
         $min = Gift::orderBy('id')->get()->lists('id')->first();
         return view('internal.salesman.exchangeGift', ['giftsList' => $giftsList, 'giftArray' => $giftsArr, 'min' => $min, 'active' => $active]);
     }
     $input = $request->all();
     $idGift = $input['gifts'];
     $idClient = $input['nombre_de_usuario'];
     $quantGift = $input['cantidad_de_regalos'];
     $gift = Gift::find($idGift);
     $user = User::find($idClient);
     if ($gift->points * $quantGift > $user->points) {
         return back()->withErrors(['El usuario no posee puntos suficientes.']);
     } elseif ($gift->stock == 0) {
         return back()->withErrors(['El juguete seleccionado se encuentra agotado.']);
     } elseif ($gift->stock < $quantGift) {
         return back()->withErrors(['No se cuenta con suficiente stock']);
     }
     $gift->stock = $gift->stock - $quantGift;
     $gift->save();
     $user->points = $user->points - $gift->points * $quantGift;
     $user->save();
     $giftsArr = Gift::all();
     $giftsList = Gift::orderBy('id')->get()->lists('name', 'id');
     $min = Gift::orderBy('id')->get()->lists('id')->first();
     Session::flash('messageSucc', ' Canjeo exitoso ');
     return view('internal.salesman.exchangeGift', ['giftsList' => $giftsList, 'giftArray' => $giftsArr, 'min' => $min, 'active' => $active, 'modulo' => $modulo]);
 }
Exemplo n.º 25
0
 private function putUserGuestContactOf(Contact $contact, Business $business)
 {
     $business->contacts()->save($contact);
 }
Exemplo n.º 26
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     //
     $moduleassigment = ModuleAssigment::where('module_id', $id)->where('status', 1)->get();
     if ($moduleassigment->count() == 0) {
         $module = Module::find($id);
         $module->delete();
         $business = Business::all()->first();
         $business->exchange_active = NULL;
         $business->save();
     } else {
         return back()->withErrors(['Debe primero desasociar el vendedor del punto de venta']);
     }
     return redirect('admin/modules');
 }
Exemplo n.º 27
0
 /**
  * Update vacancies.
  *
  * @param Business $business
  * @param array    $dates
  *
  * @return bool
  */
 public function update(Business $business, $dates)
 {
     $changed = false;
     foreach ($dates as $date => $vacancy) {
         foreach ($vacancy as $serviceId => $capacity) {
             switch (trim($capacity)) {
                 case '':
                     // Dont update, leave as is
                     logger()->info(sprintf('businessId:%s %s: Blank vacancy capacity value', $business->id, $date));
                     break;
                 default:
                     $startAt = Carbon::parse($date . ' ' . $business->pref('start_at') . ' ' . $business->timezone)->timezone('UTC');
                     $finishAt = Carbon::parse($date . ' ' . $business->pref('finish_at') . ' ' . $business->timezone)->timezone('UTC');
                     $vacancyKeys = ['business_id' => $business->id, 'service_id' => $serviceId, 'date' => $date];
                     $vacancyValues = ['capacity' => intval($capacity), 'start_at' => $startAt, 'finish_at' => $finishAt];
                     $vacancy = Vacancy::updateOrCreate($vacancyKeys, $vacancyValues);
                     $changed = true;
                     break;
             }
         }
     }
     return $changed;
 }
 protected function arrangeBusinessWithOwner()
 {
     $this->owner = $this->createUser();
     $this->business = $this->createBusiness();
     $this->business->owners()->save($this->owner);
 }
Exemplo n.º 29
0
 public static function isPartOfBusiness($business_id, $user_id)
 {
     $res = TerminalUser::getTerminalAssignement($user_id);
     if (isset($res)) {
         foreach ($res as $count => $data) {
             if ($business_id == Business::getBusinessIdByTerminalId($data['terminal_id'])) {
                 return TRUE;
             }
         }
     }
     return FALSE;
 }
Exemplo n.º 30
0
 public static function sendSMS($message, $phone, $service_id)
 {
     //ARA Adding sms as business feature
     $business_features = Business::getBusinessFeatures(Branch::businessId(Service::branchId($service_id)));
     if ($business_features['allow_sms'] == 'true') {
         $gateway = QueueSettings::smsGateway($service_id);
         $api_variables = unserialize(QueueSettings::smsGatewayApi($service_id));
         if ($gateway == 'frontline_sms') {
             $url = QueueSettings::frontlineUrl($service_id);
             $secret = QueueSettings::frontlineSecret($service_id);
             $api_key = null;
             if ($url == FRONTLINE_SMS_URL && $secret == FRONTLINE_SMS_SECRET) {
                 $url = $api_variables['frontline_sms_url'];
                 $api_key = $api_variables['frontline_sms_api_key'];
             }
             Notifier::sendFrontlineSMS($message, $phone, $url, $secret, $api_key);
         } else {
             if ($gateway == 'twilio') {
                 if ($api_variables['twilio_phone_number'] == TWILIO_PHONE_NUMBER && $api_variables['twilio_account_sid'] == TWILIO_ACCOUNT_SID && $api_variables['twilio_auth_token'] == TWILIO_AUTH_TOKEN) {
                     //@todo do something says that they are using featherq twilio service
                 }
                 $from = $api_variables['twilio_phone_number'];
                 $account_sid = $api_variables['twilio_account_sid'];
                 $auth_token = $api_variables['twilio_auth_token'];
                 Notifier::sendTwilio($phone, $message, $from, $account_sid, $auth_token);
             }
         }
     }
 }