Exemplo n.º 1
0
 /**
  * Show the form for creating a new resource.
  * GET /properties/create
  *
  * @return Response
  */
 public function create()
 {
     $properties = Owner::where('agent_id', '=', Sentry::getUser()->id)->get();
     if (!$properties->isEmpty()) {
         return View::make('backend.code.property.create', compact('properties'));
     } else {
         return Redirect::action('Controllers\\Admin\\UsersController@getCreate')->withFlashMessage('You need to create an Owner first before you Proceed');
     }
 }
 public function getOwnerData($owner_id, $token, $is_admin)
 {
     if ($owner_data = Owner::where('token', '=', $token)->where('id', '=', $owner_id)->first()) {
         return $owner_data;
     } elseif ($is_admin) {
         $owner_data = Owner::where('id', '=', $owner_id)->first();
         if (!$owner_data) {
             return false;
         }
         return $owner_data;
     } else {
         return false;
     }
 }
Exemplo n.º 3
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $this->info('Working');
     $date1 = date('Y-m-d h:i:s');
     $this->info($date1);
     $date = date_create($date1);
     $msgtime = $date->add(new DateInterval('P0Y0M0DT0H30M0S'))->format('Y-m-d H:i:s');
     $requests = Requests::where('later', 1)->where('is_started', 0)->where('request_start_time', '<=', $msgtime)->get();
     if ($requests->count() > 0) {
         $this->info('hola');
         foreach ($requests as $request) {
             $provider = Walker::where('id', $request->confirmed_walker)->first();
             $owner = Owner::where('id', $request->owner_id)->first();
             $message = "You have a ride scheduled in 30 mins from now. Client name is {$owner->first_name} {$owner->last_name} and phone no. is {$owner->phone}";
             $this->info($request->id);
             $this->info($message);
             send_notifications($provider->id, 'provider', 'Ride in 30 min', $message);
             $request->later = 0;
             $request->save();
         }
     }
 }
 /**
  * Show the form for editing the specified resource.
  * GET /properties/{id}/edit
  *
  * @param  int  $id
  * @return Response
  */
 public function edit($id)
 {
     $properties = Property::find($id);
     $owners = Owner::where('agent_id', '=', Sentry::getUser()->id)->get();
     $deposits = Receivable::where('receivable_type', '=', 'deposit')->get();
     $others = Receivable::where('receivable_type', '=', 'recurrent')->get();
     if (is_null($properties)) {
         return Redirect::route('admin.property.index');
     }
     return View::make('backend.code.property.edit', compact('properties', 'owners', 'deposits', 'others'));
 }
 public function create_manual_request()
 {
     $latitude = Input::get('latitude');
     $longitude = Input::get('longitude');
     $d_latitude = Input::get('d_latitude');
     $d_longitude = Input::get('d_longitude');
     $type = Input::get('type');
     $provider = Input::get('provider');
     $user_id = Session::get('user_id');
     $time = date("Y-m-d H:i:s");
     $provider_details = Walker::where('id', '=', $provider)->first();
     $user = Owner::where('id', '=', $user_id)->first();
     $request = new Requests();
     $request->owner_id = $user_id;
     $request->request_start_time = $time;
     $request->confirmed_walker = $provider;
     if ($d_longitude != '' && $d_latitude != '') {
         $request->D_latitude = $d_latitude;
         $request->D_longitude = $d_longitude;
     }
     $request->current_walker = $provider;
     $request->status = 1;
     $request->save();
     $reqid = $request->id;
     $request_service = new RequestServices();
     $request_service->type = $type;
     $request_service->request_id = $request->id;
     $request_service->save();
     $owner = Owner::find($user_id);
     $owner->latitude = $latitude;
     $owner->longitude = $longitude;
     $owner->save();
     $walkerlocation = new WalkLocation();
     $walkerlocation->request_id = $request->id;
     $walkerlocation->distance = 0.0;
     $walkerlocation->latitude = $latitude;
     $walkerlocation->longitude = $longitude;
     $walkerlocation->save();
     if ($request->save()) {
         $current_request = Requests::where('id', '=', $reqid)->first();
         return Redirect::to('/user/request-trip');
     }
 }
Exemplo n.º 6
0
 /**
  * Display a listing of the resource.
  * GET /owners
  *
  * @return Response
  */
 public function index()
 {
     $agent_id = Sentry::getUser()->id;
     $owners = Owner::where('agent_id', $agent_id)->get();
     return View::make('backend.code.owner.index', compact('owners'));
 }
 public function send_eta()
 {
     $token = Input::get('token');
     $owner_id = Input::get('id');
     $phones = Input::get('phone');
     $request_id = Input::get('request_id');
     $eta = Input::get('eta');
     $validator = Validator::make(array('token' => $token, 'owner_id' => $owner_id, 'phones' => $phones, 'eta' => $eta), array('token' => 'required', 'phones' => 'required', 'owner_id' => 'required|integer', 'eta' => 'required'));
     if ($validator->fails()) {
         $error_messages = $validator->messages()->all();
         $response_array = array('success' => false, 'error' => 'Invalid Input', 'error_code' => 401, 'error_messages' => $error_messages);
         $response_code = 200;
     } else {
         $is_admin = $this->isAdmin($token);
         if ($owner_data = $this->getOwnerData($owner_id, $token, $is_admin)) {
             // check for token validity
             if (is_token_active($owner_data->token_expiry) || $is_admin) {
                 // If phones is not an array
                 if (!is_array($phones)) {
                     $phones = explode(',', $phones);
                 }
                 Log::info('phones = ' . print_r($phones, true));
                 foreach ($phones as $key) {
                     $owner = Owner::where('id', $owner_id)->first();
                     $secret = str_random(6);
                     $request = Requests::where('id', $request_id)->first();
                     $request->security_key = $secret;
                     $request->save();
                     $msg = $owner->first_name . ' ' . $owner->last_name . ' ETA : ' . $eta;
                     send_eta($key, $msg);
                     Log::info('Send ETA MSG  = ' . print_r($msg, true));
                 }
                 $response_array = array('success' => true);
                 $response_code = 200;
             } else {
                 $response_array = array('success' => false, 'error' => 'Token Expired', 'error_code' => 405);
                 $response_code = 200;
             }
         } else {
             if ($is_admin) {
                 /* $var = Keywords::where('id', 2)->first();
                    $response_array = array('success' => false, 'error' => '' . $var->keyword . ' ID not Found', 'error_code' => 410); */
                 $response_array = array('success' => false, 'error' => '' . Config::get('app.generic_keywords.User') . ' ID not Found', 'error_code' => 410);
             } else {
                 $response_array = array('success' => false, 'error' => 'Not a valid token', 'error_code' => 406);
             }
             $response_code = 200;
         }
     }
     $response = Response::json($response_array, $response_code);
     return $response;
 }
Exemplo n.º 8
0
 public function get_track_loc($id)
 {
     $request = Requests::where('security_key', $id)->where('is_started', 1)->where('is_completed', 0)->first();
     if ($request) {
         $owner = Owner::where('id', $request->owner_id)->first();
         $user_name = $owner->first_name . " " . $owner->last_name;
         $theme = Theme::all();
         $logo = '/image/logo.png';
         $favicon = '/image/favicon.ico';
         foreach ($theme as $themes) {
             $favicon = '/uploads/' . $themes->favicon;
             $logo = '/uploads/' . $themes->logo;
         }
         if ($logo == '/uploads/') {
             $logo = '/image/logo.png';
         }
         if ($favicon == '/uploads/') {
             $favicon = '/image/favicon.ico';
         }
         $app_name = Config::get('app.website_title');
         // walk location
         $start_loc = WalkLocation::where('request_id', $request->id)->first();
         $reqloc = WalkLocation::where('request_id', $request->id)->orderBy('id', 'desc')->first();
         $title = 'Track ' . $user_name;
         return Response::json(array('success' => true, 'titl' => $title, 'logo' => $logo, 'favicon' => $favicon, 'app_name' => $app_name, 'cur_lat' => $reqloc->latitude, 'cur_lon' => $reqloc->longitude, 'prev_lat' => $start_loc->latitude, 'prev_lon' => $start_loc->longitude, 'track_id' => $id));
     } else {
         return Redirect::to('/');
     }
 }
 public function request_walk_completed_old123()
 {
     if (Request::isMethod('post')) {
         $request_id = Input::get('request_id');
         $token = Input::get('token');
         $walker_id = Input::get('id');
         $latitude = Input::get('latitude');
         $longitude = Input::get('longitude');
         $distance = Input::get('distance');
         $time = Input::get('time');
         if (Input::has('bearing')) {
             $angle = Input::get('bearing');
         }
         Log::info('distance input = ' . print_r($distance, true));
         Log::info('time input = ' . print_r($time, true));
         $validator = Validator::make(array('request_id' => $request_id, 'token' => $token, 'walker_id' => $walker_id, 'latitude' => $latitude, 'longitude' => $longitude, 'distance' => $distance), array('request_id' => 'required|integer', 'token' => 'required', 'walker_id' => 'required|integer', 'latitude' => 'required', 'longitude' => 'required', 'distance' => 'required'));
         if ($validator->fails()) {
             $error_messages = $validator->messages()->all();
             $response_array = array('success' => false, 'error' => 'Invalid Input', 'error_code' => 401, 'error_messages' => $error_messages);
             $response_code = 200;
         } else {
             $cash_card_user = "";
             $payment_type = "";
             $walker_payment_remaining = 0;
             $is_admin = $this->isAdmin($token);
             if ($walker_data = $this->getWalkerData($walker_id, $token, $is_admin)) {
                 // check for token validity
                 if (is_token_active($walker_data->token_expiry) || $is_admin) {
                     $providertype = ProviderType::where('id', $walker_data->type)->first();
                     // Do necessary operations
                     if ($request = Requests::find($request_id)) {
                         $time = $request->time;
                         if ($request->confirmed_walker == $walker_id) {
                             if ($request->is_started == 1) {
                                 $settings = Settings::where('key', 'default_charging_method_for_users')->first();
                                 $pricing_type = $settings->value;
                                 $settings = Settings::where('key', 'default_distance_unit')->first();
                                 $unit = $settings->value;
                                 Log::info('distance = ' . print_r($distance, true));
                                 $reqserv = RequestServices::where('request_id', $request_id)->get();
                                 $actual_total = 0;
                                 $price_per_unit_distance = 0;
                                 $price_per_unit_time = 0;
                                 $base_price = 0;
                                 foreach ($reqserv as $rse) {
                                     Log::info('type = ' . print_r($rse->type, true));
                                     $protype = ProviderType::where('id', $rse->type)->first();
                                     $pt = ProviderServices::where('provider_id', $walker_id)->where('type', $rse->type)->first();
                                     if ($pt->base_price == 0) {
                                         /* $setbase_price = Settings::where('key', 'base_price')->first();
                                            $base_price = $setbase_price->value; */
                                         $base_price = $providertype->base_price;
                                         $rse->base_price = $base_price;
                                     } else {
                                         $base_price = $pt->base_price;
                                         $rse->base_price = $base_price;
                                     }
                                     $is_multiple_service = Settings::where('key', 'allow_multiple_service')->first();
                                     if ($is_multiple_service->value == 0) {
                                         if ($pt->price_per_unit_distance == 0) {
                                             /* $setdistance_price = Settings::where('key', 'price_per_unit_distance')->first();
                                                $price_per_unit_distance = $setdistance_price->value * $distance;
                                                $rse->distance_cost = $price_per_unit_distance; */
                                             if ($distance <= $providertype->base_distance) {
                                                 $price_per_unit_distance = 0;
                                             } else {
                                                 $price_per_unit_distance = $providertype->price_per_unit_distance * ($distance - $providertype->base_distance);
                                             }
                                             $rse->distance_cost = $price_per_unit_distance;
                                         } else {
                                             if ($distance <= $providertype->base_distance) {
                                                 $price_per_unit_distance = 0;
                                             } else {
                                                 $price_per_unit_distance = $pt->price_per_unit_distance * ($distance - $providertype->base_distance);
                                             }
                                             $rse->distance_cost = $price_per_unit_distance;
                                         }
                                         if ($pt->price_per_unit_time == 0) {
                                             /* $settime_price = Settings::where('key', 'price_per_unit_time')->first();
                                                $price_per_unit_time = $settime_price->value * $time; */
                                             $price_per_unit_time = $providertype->price_per_unit_time * $time;
                                             $rse->time_cost = $price_per_unit_time;
                                         } else {
                                             $price_per_unit_time = $pt->price_per_unit_time * $time;
                                             $rse->time_cost = $price_per_unit_time;
                                         }
                                     }
                                     Log::info('total price = ' . print_r($base_price + $price_per_unit_distance + $price_per_unit_time, true));
                                     $rse->total = $base_price + $price_per_unit_distance + $price_per_unit_time;
                                     $rse->save();
                                     $actual_total = $actual_total + $base_price + $price_per_unit_distance + $price_per_unit_time;
                                     Log::info('total_price = ' . print_r($actual_total, true));
                                 }
                                 pay_fail:
                                 $rs = RequestServices::where('request_id', $request_id)->get();
                                 $total = 0;
                                 foreach ($rs as $key) {
                                     Log::info('total = ' . print_r($key->total, true));
                                     $total = $total + $key->total;
                                 }
                                 $request = Requests::find($request_id);
                                 $request->is_completed = 1;
                                 $request->distance = $distance;
                                 $request->time = $time;
                                 $request->security_key = NULL;
                                 $request->total = $total;
                                 $owner_data = Owner::where('id', $request->owner_id)->first();
                                 /* GET REFERRAL & PROMO INFO */
                                 $prom_act = $prom_for_card = $prom_for_cash = $ref_act = $ref_for_card = $ref_for_cash = $ref_total = $promo_total = 0;
                                 $settings = Settings::where('key', 'promotional_code_activation')->first();
                                 $prom_act = $settings->value;
                                 $settings = Settings::where('key', 'referral_code_activation')->first();
                                 $ref_act = $settings->value;
                                 /* GET REFERRAL & PROMO INFO END */
                                 $cash_card_user = $request->payment_mode;
                                 if ($request->payment_mode == 0) {
                                     $walker_payment_remaining = $total;
                                     if ($prom_act) {
                                         $settings = Settings::where('key', 'get_promotional_profit_on_card_payment')->first();
                                         $prom_for_card = $settings->value;
                                         if ($prom_for_card) {
                                             if ($total > 0) {
                                                 if ($pcode = PromoCodes::where('id', $request->promo_id)->first()) {
                                                     if ($pcode->type == 1) {
                                                         $promo_total = $total * ($pcode->value / 100);
                                                         $total = $total - $promo_total;
                                                         if ($total <= 0) {
                                                             $total = 0;
                                                         }
                                                     } else {
                                                         $promo_total = $pcode->value;
                                                         $total = $total - $promo_total;
                                                         if ($total <= 0) {
                                                             $total = 0;
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                     if ($ref_act) {
                                         $settings = Settings::where('key', 'get_referral_profit_on_card_payment')->first();
                                         $ref_for_card = $settings->value;
                                         if ($ref_for_card) {
                                             // charge client
                                             $ledger = Ledger::where('owner_id', $request->owner_id)->first();
                                             if ($ledger) {
                                                 $balance = $ledger->amount_earned - $ledger->amount_spent;
                                                 Log::info('ledger balance = ' . print_r($balance, true));
                                                 if ($balance > 0) {
                                                     if ($total > 0) {
                                                         if ($total > $balance) {
                                                             $ref_total = $balance;
                                                             $ledger_temp = Ledger::find($ledger->id);
                                                             $ledger_temp->amount_spent = $ledger_temp->amount_spent + $balance;
                                                             $ledger_temp->save();
                                                             $total = $total - $balance;
                                                         } else {
                                                             $ref_total = $total;
                                                             $ledger_temp = Ledger::find($ledger->id);
                                                             $ledger_temp->amount_spent = $ledger_temp->amount_spent + $total;
                                                             $ledger_temp->save();
                                                             $total = 0;
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 } else {
                                     if ($request->payment_mode == 1) {
                                         $walker_payment_remaining = 0;
                                         if ($prom_act) {
                                             $settings = Settings::where('key', 'get_promotional_profit_on_cash_payment')->first();
                                             $prom_for_cash = $settings->value;
                                             if ($prom_for_cash) {
                                                 if ($total > 0) {
                                                     if ($pcode = PromoCodes::where('id', $request->promo_id)->first()) {
                                                         if ($pcode->type == 1) {
                                                             $promo_total = $total * ($pcode->value / 100);
                                                             $total = $total - $promo_total;
                                                             if ($total <= 0) {
                                                                 $total = 0;
                                                             }
                                                         } else {
                                                             $promo_total = $pcode->value;
                                                             $total = $total - $promo_total;
                                                             if ($total <= 0) {
                                                                 $total = 0;
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                         if ($ref_act) {
                                             $settings = Settings::where('key', 'get_referral_profit_on_cash_payment')->first();
                                             $ref_for_cash = $settings->value;
                                             if ($ref_for_cash) {
                                                 // charge client
                                                 $ledger = Ledger::where('owner_id', $request->owner_id)->first();
                                                 if ($ledger) {
                                                     $balance = $ledger->amount_earned - $ledger->amount_spent;
                                                     Log::info('ledger balance = ' . print_r($balance, true));
                                                     if ($balance > 0) {
                                                         if ($total > 0) {
                                                             if ($total > $balance) {
                                                                 $ref_total = $balance;
                                                                 $ledger_temp = Ledger::find($ledger->id);
                                                                 $ledger_temp->amount_spent = $ledger_temp->amount_spent + $balance;
                                                                 $ledger_temp->save();
                                                                 $total = $total - $balance;
                                                             } else {
                                                                 $ref_total = $total;
                                                                 $ledger_temp = Ledger::find($ledger->id);
                                                                 $ledger_temp->amount_spent = $ledger_temp->amount_spent + $total;
                                                                 $ledger_temp->save();
                                                                 $total = 0;
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                                 /* $promo_discount = 0;
                                                                       if ($pcode = PromoCodes::where('id', $request->promo_code)->where('type', 1)->first()) {
                                                                       $discount = ($pcode->value) / 100;
                                                                       $promo_discount = $total * $discount;
                                                                       $total = $total - $promo_discount;
                                                                       if ($total < 0) {
                                                                       $total = 0;
                                                                       }
                                                                       }
                                 
                                                                       $request->total = $total; */
                                 Log::info('final total = ' . print_r($total, true));
                                 $cod_sett = Settings::where('key', 'cod')->first();
                                 $allow_cod = $cod_sett->value;
                                 if ($request->payment_mode == 1 and $allow_cod == 1) {
                                     $request->is_paid = 1;
                                     $payment_type = 'Payment By cash';
                                     Log::info('allow_cod');
                                 } else {
                                     if ($request->payment_mode == 2) {
                                         // paypal
                                         $payment_type = 'Payment By paypal payment';
                                         Log::info('paypal payment');
                                     } else {
                                         Log::info('normal payment. Stored cards');
                                         if ($total == 0) {
                                             $request->is_paid = 1;
                                         } else {
                                             $payment_data = Payment::where('owner_id', $request->owner_id)->where('is_default', 1)->first();
                                             if (!$payment_data) {
                                                 $payment_data = Payment::where('owner_id', $request->owner_id)->first();
                                             }
                                             if ($payment_data) {
                                                 $customer_id = $payment_data->customer_id;
                                                 $setransfer = Settings::where('key', 'transfer')->first();
                                                 $transfer_allow = $setransfer->value;
                                                 if (Config::get('app.default_payment') == 'stripe') {
                                                     //dd($customer_id);
                                                     Stripe::setApiKey(Config::get('app.stripe_secret_key'));
                                                     try {
                                                         $charge = Stripe_Charge::create(array("amount" => floor($total) * 100, "currency" => "usd", "customer" => $customer_id));
                                                         if ($charge->paid) {
                                                             $request->is_paid = 1;
                                                             //$payment_type = "Creditcard Card Payment Successfully";
                                                         } else {
                                                             $request->is_paid = 0;
                                                             $payment_type = "Creditcard Card Payment Fail";
                                                             $ledger = Ledger::where('owner_id', $request->owner_id)->first();
                                                             if ($ledger) {
                                                                 $ledger_temp = Ledger::find($ledger->id);
                                                                 $ledger_temp->amount_spent = $ledger_temp->amount_spent + $ref_total;
                                                                 $ledger_temp->save();
                                                             }
                                                             $change_to_cash = Requests::find($request_id);
                                                             $change_to_cash->payment_mode = 1;
                                                             $change_to_cash->save();
                                                             /* Client Side Push */
                                                             $title = 'Your card is declined, please pay cash to driver for your trip.';
                                                             $response_array = array('success' => true, 'message' => $title);
                                                             $message = $response_array;
                                                             send_notifications($request->owner_id, "owner", $title, $message);
                                                             /* Client Side Push END */
                                                             /* Driver Side Push */
                                                             $title = 'Please collect cash from client for your trip.';
                                                             $response_array = array('success' => true, 'message' => $title);
                                                             $message = $response_array;
                                                             send_notifications($walker_id, "walker", $title, $message);
                                                             /* Driver Side Push END */
                                                             goto pay_fail;
                                                         }
                                                     } catch (Stripe_InvalidRequestError $e) {
                                                         $request->is_paid = 0;
                                                         // Invalid parameters were supplied to Stripe's API
                                                         $ownr = Owner::find($request->owner_id);
                                                         $ownr->debt = $total;
                                                         $ownr->save();
                                                         $response_array = array('error' => $e->getMessage());
                                                         $response_code = 200;
                                                         $response = Response::json($response_array, $response_code);
                                                         return $response;
                                                     }
                                                     $settng = Settings::where('key', 'service_fee')->first();
                                                     if ($transfer_allow == 1 && $walker_data->merchant_id != "" && Config::get('app.generic_keywords.Currency') == '$') {
                                                         $transfer = Stripe_Transfer::create(array("amount" => floor($total - $settng->value * $total / 100) * 100, "currency" => "usd", "recipient" => $walker_data->merchant_id));
                                                         $request->transfer_amount = floor($total - $settng->value * $total / 100);
                                                     }
                                                 } else {
                                                     try {
                                                         Braintree_Configuration::environment(Config::get('app.braintree_environment'));
                                                         Braintree_Configuration::merchantId(Config::get('app.braintree_merchant_id'));
                                                         Braintree_Configuration::publicKey(Config::get('app.braintree_public_key'));
                                                         Braintree_Configuration::privateKey(Config::get('app.braintree_private_key'));
                                                         if ($transfer_allow == 1) {
                                                             $sevisett = Settings::where('key', 'service_fee')->first();
                                                             $service_fee = $sevisett->value * $total / 100;
                                                             $result = Braintree_Transaction::sale(array('amount' => $total - $service_fee, 'paymentMethodNonce' => $customer_id, 'merchantAccountId' => $walker_data->merchant_id, 'options' => array('submitForSettlement' => true, 'holdInEscrow' => true), 'serviceFeeAmount' => $service_fee));
                                                         } else {
                                                             $result = Braintree_Transaction::sale(array('amount' => $total, 'paymentMethodNonce' => $customer_id));
                                                         }
                                                         if ($result->success) {
                                                             $request->is_paid = 1;
                                                             $payment_type = "Creditcard Card Payment Successfully";
                                                         } else {
                                                             $request->is_paid = 0;
                                                             $payment_type = "Creditcard Card Payment Fail";
                                                             $ledger = Ledger::where('owner_id', $request->owner_id)->first();
                                                             if ($ledger) {
                                                                 $ledger_temp = Ledger::find($ledger->id);
                                                                 $ledger_temp->amount_spent = $ledger_temp->amount_spent + $ref_total;
                                                                 $ledger_temp->save();
                                                             }
                                                             $change_to_cash = Requests::find($request_id);
                                                             $change_to_cash->payment_mode = 1;
                                                             $change_to_cash->save();
                                                             /* Client Side Push */
                                                             $title = 'Your card is declined, please pay cash to driver for your trip.';
                                                             $response_array = array('success' => true, 'message' => $title);
                                                             $message = $response_array;
                                                             send_notifications($request->owner_id, "owner", $title, $message);
                                                             /* Client Side Push END */
                                                             /* Driver Side Push */
                                                             $title = 'Please collect cash from client for your trip.';
                                                             $response_array = array('success' => true, 'message' => $title);
                                                             $message = $response_array;
                                                             send_notifications($walker_id, "walker", $title, $message);
                                                             /* Driver Side Push END */
                                                             goto pay_fail;
                                                         }
                                                     } catch (Exception $e) {
                                                         $response_array = array('success' => false, 'error' => $e, 'error_code' => 405);
                                                         $response_code = 200;
                                                         $response = Response::json($response_array, $response_code);
                                                         return $response;
                                                     }
                                                 }
                                                 $request->card_payment = $total;
                                                 $request->ledger_payment = $request->total - $total;
                                             }
                                         }
                                     }
                                 }
                                 $request->card_payment = $total;
                                 $request->ledger_payment = $ref_total;
                                 $request->promo_payment = $promo_total;
                                 //$request->payment_mode = $cash_card_user;
                                 $request->save();
                                 if ($request->is_paid == 1) {
                                     $owner = Owner::find($request->owner_id);
                                     $settings = Settings::where('key', 'sms_request_unanswered')->first();
                                     $pattern = $settings->value;
                                     $pattern = str_replace('%user%', $owner->first_name . " " . $owner->last_name, $pattern);
                                     $pattern = str_replace('%id%', $request->id, $pattern);
                                     $pattern = str_replace('%user_mobile%', $owner->phone, $pattern);
                                     sms_notification(1, 'admin', $pattern);
                                 }
                                 $walker = Walker::find($walker_id);
                                 $walker->is_available = 1;
                                 $location = get_location($latitude, $longitude);
                                 $latitude = $location['lat'];
                                 $longitude = $location['long'];
                                 if (!isset($angle)) {
                                     $angle = get_angle($walker->latitude, $walker->longitude, $latitude, $longitude);
                                 }
                                 $walker->old_latitude = $walker->latitude;
                                 $walker->old_longitude = $walker->longitude;
                                 $walker->latitude = $latitude;
                                 $walker->longitude = $longitude;
                                 $walker->bearing = $angle;
                                 $walker->save();
                                 Log::info('distance walk location = ' . print_r($distance, true));
                                 $walk_location = new WalkLocation();
                                 $walk_location->latitude = $latitude;
                                 $walk_location->longitude = $longitude;
                                 $walk_location->request_id = $request_id;
                                 $walk_location->distance = $distance;
                                 $walk_location->bearing = $angle;
                                 $walk_location->save();
                                 // Send Notification
                                 $walker = Walker::find($request->confirmed_walker);
                                 $walker_data = array();
                                 $walker_data['first_name'] = $walker->first_name;
                                 $walker_data['last_name'] = $walker->last_name;
                                 $walker_data['phone'] = $walker->phone;
                                 $walker_data['bio'] = $walker->bio;
                                 $walker_data['picture'] = $walker->picture;
                                 $walker_data['latitude'] = $walker->latitude;
                                 $walker_data['longitude'] = $walker->longitude;
                                 $walker_data['type'] = $walker->type;
                                 $walker_data['rating'] = $walker->rate;
                                 $walker_data['num_rating'] = $walker->rate_count;
                                 $walker_data['car_model'] = $walker->car_model;
                                 $walker_data['car_number'] = $walker->car_number;
                                 /* $walker_data['rating'] = DB::table('review_walker')->where('walker_id', '=', $walker->id)->avg('rating') ? : 0;
                                    $walker_data['num_rating'] = DB::table('review_walker')->where('walker_id', '=', $walker->id)->count(); */
                                 $requestserv = RequestServices::where('request_id', $request->id)->first();
                                 $bill = array();
                                 /* $currency_selected = Keywords::find(5); */
                                 if ($request->is_completed == 1) {
                                     $settings = Settings::where('key', 'default_distance_unit')->first();
                                     $unit = $settings->value;
                                     //    $bill['payment_mode'] = $request->payment_mode;
                                     // $bill['payment_mode'] = "";
                                     $bill['distance'] = (string) $distance;
                                     if ($unit == 0) {
                                         $unit_set = 'kms';
                                     } elseif ($unit == 1) {
                                         $unit_set = 'miles';
                                     }
                                     $bill['unit'] = $unit_set;
                                     $bill['time'] = floatval(sprintf2($request->time, 2));
                                     if ($requestserv->base_price != 0) {
                                         $bill['base_price'] = currency_converted($requestserv->base_price);
                                         $bill['distance_cost'] = currency_converted($requestserv->distance_cost);
                                         $bill['time_cost'] = currency_converted(floatval(sprintf2($requestserv->time_cost, 2)));
                                     } else {
                                         /* $setbase_price = Settings::where('key', 'base_price')->first();
                                            $bill['base_price'] = currency_converted($setbase_price->value); */
                                         $bill['base_price'] = currency_converted($providertype->base_price);
                                         /* $setdistance_price = Settings::where('key', 'price_per_unit_distance')->first();
                                            $bill['distance_cost'] = currency_converted($setdistance_price->value); */
                                         $bill['distance_cost'] = currency_converted($providertype->price_per_unit_distance);
                                         /* $settime_price = Settings::where('key', 'price_per_unit_time')->first();
                                            $bill['time_cost'] = currency_converted(floatval(sprintf2($settime_price->value, 2))); */
                                         $bill['time_cost'] = currency_converted(floatval(sprintf2($providertype->price_per_unit_time, 2)));
                                     }
                                     $admins = Admin::first();
                                     $bill['walker']['email'] = $walker->email;
                                     $bill['admin']['email'] = $admins->username;
                                     if ($request->transfer_amount != 0) {
                                         $bill['walker']['amount'] = currency_converted($request->total - $request->transfer_amount);
                                         $bill['admin']['amount'] = currency_converted($request->transfer_amount);
                                     } else {
                                         $bill['walker']['amount'] = currency_converted($request->transfer_amount);
                                         $bill['admin']['amount'] = currency_converted($request->total - $request->transfer_amount);
                                     }
                                     /* $bill['currency'] = $currency_selected->keyword; */
                                     $bill['currency'] = Config::get('app.generic_keywords.Currency');
                                     $bill['actual_total'] = currency_converted($actual_total);
                                     $bill['total'] = currency_converted($request->total);
                                     $bill['is_paid'] = $request->is_paid;
                                     $bill['promo_discount'] = currency_converted($promo_total);
                                     $bill['main_total'] = currency_converted($request->total);
                                     $bill['total'] = currency_converted($request->total - $request->ledger_payment - $request->promo_payment);
                                     $bill['referral_bonus'] = currency_converted($request->ledger_payment);
                                     $bill['promo_bonus'] = currency_converted($request->promo_payment);
                                     //  $bill['payment_type'] = "";
                                     //  $bill['payment_type'] = $request->"payment_mode;
                                     $bill['is_paid'] = $request->is_paid;
                                     $chagre = array();
                                     $settings = Settings::where('key', 'default_distance_unit')->first();
                                     $unit = $settings->value;
                                     if ($unit == 0) {
                                         $unit_set = 'kms';
                                     } elseif ($unit == 1) {
                                         $unit_set = 'miles';
                                     }
                                     $chagre['unit'] = $unit_set;
                                     $requestserv = RequestServices::where('request_id', $request->id)->first();
                                     if ($requestserv->base_price != 0) {
                                         $chagre['base_price'] = $requestserv->base_price;
                                         $chagre['distance_price'] = $requestserv->distance_cost;
                                         $chagre['price_per_unit_time'] = $requestserv->time_cost;
                                     } else {
                                         $setbase_price = Settings::where('key', 'base_price')->first();
                                         $chagre['base_price'] = $setbase_price->value;
                                         $setdistance_price = Settings::where('key', 'price_per_unit_distance')->first();
                                         $chagre['distance_price'] = $setdistance_price->value;
                                         $settime_price = Settings::where('key', 'price_per_unit_time')->first();
                                         $chagre['price_per_unit_time'] = $settime_price->value;
                                     }
                                     $chagre['total'] = $request->total;
                                     $chagre['is_paid'] = $request->is_paid;
                                     //$message = $response_array;
                                 }
                                 $rservc = RequestServices::where('request_id', $request->id)->get();
                                 $typs = array();
                                 $typi = array();
                                 $typp = array();
                                 foreach ($rservc as $typ) {
                                     $typ1 = ProviderType::where('id', $typ->type)->first();
                                     $typ_price = ProviderServices::where('provider_id', $request->confirmed_walker)->where('type', $typ->type)->first();
                                     if ($typ_price->base_price > 0) {
                                         $typp1 = 0.0;
                                         $typp1 = $typ_price->base_price;
                                     } elseif ($typ_price->price_per_unit_distance > 0) {
                                         $typp1 = 0.0;
                                         foreach ($rservc as $key) {
                                             $typp1 = $typp1 + $key->distance_cost;
                                         }
                                     } else {
                                         $typp1 = 0.0;
                                     }
                                     $typs['name'] = $typ1->name;
                                     // $typs['icon']=$typ1->icon;
                                     $typs['price'] = $typp1;
                                     array_push($typi, $typs);
                                 }
                                 $bill['type'] = $typi;
                                 $rserv = RequestServices::where('request_id', $request_id)->get();
                                 $typs = array();
                                 foreach ($rserv as $typ) {
                                     $typ1 = ProviderType::where('id', $typ->type)->first();
                                     array_push($typs, $typ1->name);
                                 }
                                 $response_array = array('success' => true, 'request_id' => $request_id, 'status' => $request->status, 'confirmed_walker' => $request->confirmed_walker, 'is_walker_started' => $request->is_walker_started, 'is_walker_arrived' => $request->is_walker_arrived, 'is_walk_started' => $request->is_started, 'is_completed' => $request->is_completed, 'is_walker_rated' => $request->is_walker_rated, 'walker' => $walker_data, 'payment_mode' => "", 'bill' => $bill, 'payment_option' => "", 'is_paid' => $request->is_paid);
                                 $owner_data1 = array();
                                 $owner_data1['name'] = $owner_data->first_name . " " . $owner_data->last_name;
                                 $owner_data1['picture'] = $owner_data->picture;
                                 $owner_data1['phone'] = $owner_data->phone;
                                 $owner_data1['address'] = $owner_data->address;
                                 $owner_data1['bio'] = $owner_data->bio;
                                 $owner_data1['latitude'] = $owner_data->latitude;
                                 $owner_data1['longitude'] = $owner_data->longitude;
                                 $owner_data1['owner_dist_lat'] = $request->D_latitude;
                                 $owner_data1['owner_dist_long'] = $request->D_longitude;
                                 $owner_data1['dest_latitude'] = $request->D_latitude;
                                 $owner_data1['dest_longitude'] = $request->D_longitude;
                                 //$owner_data1['payment_type'] = $request->payment_mode;
                                 // $owner_data1['payment_type'] = "";
                                 $owner_data1['rating'] = $owner_data->rate;
                                 $owner_data1['num_rating'] = $owner_data->rate_count;
                                 $title = "Trip Completed";
                                 $dog1 = array();
                                 if ($dog = Dog::find($owner_data->dog_id)) {
                                     $dog1['name'] = $dog->name;
                                     $dog1['age'] = $dog->age;
                                     $dog1['breed'] = $dog->breed;
                                     $dog1['likes'] = $dog->likes;
                                     $dog1['picture'] = $dog->image_url;
                                 }
                                 $cards = "";
                                 /* $cards['none'] = ""; */
                                 $cardlist = Payment::where('owner_id', $owner_data->id)->where('is_default', 1)->first();
                                 if (count($cardlist) >= 1) {
                                     $cards = array();
                                     $default = $cardlist->is_default;
                                     if ($default == 1) {
                                         $cards['is_default_text'] = "default";
                                     } else {
                                         $cards['is_default_text'] = "not_default";
                                     }
                                     $cards['card_id'] = $cardlist->id;
                                     $cards['owner_id'] = $cardlist->owner_id;
                                     $cards['customer_id'] = $cardlist->customer_id;
                                     $cards['last_four'] = $cardlist->last_four;
                                     $cards['card_token'] = $cardlist->card_token;
                                     $cards['card_type'] = $cardlist->card_type;
                                     $cards['is_default'] = $default;
                                 }
                                 $chagre = array();
                                 $settings = Settings::where('key', 'default_distance_unit')->first();
                                 $unit = $settings->value;
                                 if ($unit == 0) {
                                     $unit_set = 'kms';
                                 } elseif ($unit == 1) {
                                     $unit_set = 'miles';
                                 }
                                 $chagre['unit'] = $unit_set;
                                 $requestserv = RequestServices::where('request_id', $request->id)->first();
                                 if ($requestserv->base_price != 0) {
                                     $chagre['base_price'] = currency_converted($requestserv->base_price);
                                     $chagre['distance_price'] = currency_converted($requestserv->distance_cost);
                                     $chagre['price_per_unit_time'] = currency_converted($requestserv->time_cost);
                                 } else {
                                     /* $setbase_price = Settings::where('key', 'base_price')->first();
                                        $chagre['base_price'] = currency_converted($setbase_price->value); */
                                     $chagre['base_price'] = currency_converted($providertype->base_price);
                                     /* $setdistance_price = Settings::where('key', 'price_per_unit_distance')->first();
                                        $chagre['distance_price'] = currency_converted($setdistance_price->value); */
                                     $chagre['distance_price'] = currency_converted($providertype->price_per_unit_distance);
                                     /* $settime_price = Settings::where('key', 'price_per_unit_time')->first();
                                        $chagre['price_per_unit_time'] = currency_converted($settime_price->value); */
                                     $chagre['price_per_unit_time'] = currency_converted($providertype->price_per_unit_time);
                                 }
                                 $chagre['total'] = currency_converted($request->total);
                                 $chagre['is_paid'] = $request->is_paid;
                                 /* $var = Keywords::where('id', 4)->first(); */
                                 $title = 'Your ' . Config::get('app.generic_keywords.Trip') . ' is completed';
                                 $message = $response_array;
                                 send_notifications($request->owner_id, "owner", $title, $message);
                                 // Send SMS
                                 $owner = Owner::find($request->owner_id);
                                 $settings = Settings::where('key', 'sms_when_provider_completes_job')->first();
                                 $pattern = $settings->value;
                                 $pattern = str_replace('%user%', $owner->first_name . " " . $owner->last_name, $pattern);
                                 $pattern = str_replace('%driver%', $walker->first_name . " " . $walker->last_name, $pattern);
                                 $pattern = str_replace('%driver_mobile%', $walker->phone, $pattern);
                                 $pattern = str_replace('%amount%', $request->total, $pattern);
                                 sms_notification($request->owner_id, 'owner', $pattern);
                                 $id = $request->id;
                                 // send email
                                 /* $settings = Settings::where('key', 'email_request_finished')->first();
                                    $pattern = $settings->value;
                                    $pattern = str_replace('%id%', $request->id, $pattern);
                                    $pattern = str_replace('%url%', web_url() . "/admin/request/map/" . $request->id, $pattern);
                                    $subject = "Request Completed";
                                    email_notification(2, 'admin', $pattern, $subject); */
                                 // $settings = Settings::where('key','email_invoice_generated_user')->first();
                                 // $pattern = $settings->value;
                                 // $pattern = str_replace('%id%', $request->id, $pattern);
                                 // $pattern = str_replace('%amount%', $request->total, $pattern);
                                 $email_data = array();
                                 $email_data['name'] = $owner->first_name;
                                 $email_data['emailType'] = 'user';
                                 $email_data['base_price'] = $bill['base_price'];
                                 $email_data['distance'] = $bill['distance'];
                                 $email_data['time'] = $bill['time'];
                                 $email_data['unit'] = $bill['unit'];
                                 $email_data['total'] = $bill['total'];
                                 //   $email_data['payment_mode'] = $bill['payment_mode'];
                                 $email_data['actual_total'] = currency_converted($actual_total);
                                 $email_data['is_paid'] = $request->is_paid;
                                 $email_data['promo_discount'] = currency_converted($promo_total);
                                 $request_services = RequestServices::where('request_id', $request->id)->first();
                                 $locations = WalkLocation::where('request_id', $request->id)->orderBy('id')->get();
                                 $start = WalkLocation::where('request_id', $request->id)->orderBy('id')->first();
                                 $end = WalkLocation::where('request_id', $request->id)->orderBy('id', 'desc')->first();
                                 $map = "https://maps-api-ssl.google.com/maps/api/staticmap?size=249x249&style=feature:landscape|visibility:off&style=feature:poi|visibility:off&style=feature:transit|visibility:off&style=feature:road.highway|element:geometry|lightness:39&style=feature:road.local|element:geometry|gamma:1.45&style=feature:road|element:labels|gamma:1.22&style=feature:administrative|visibility:off&style=feature:administrative.locality|visibility:on&style=feature:landscape.natural|visibility:on&scale=2&markers=shadow:false|scale:2|icon:http://d1a3f4spazzrp4.cloudfront.net/receipt-new/marker-start@2x.png|{$start->latitude},{$start->longitude}&markers=shadow:false|scale:2|icon:http://d1a3f4spazzrp4.cloudfront.net/receipt-new/marker-finish@2x.png|{$end->latitude},{$end->longitude}&path=color:0x2dbae4ff|weight:4";
                                 foreach ($locations as $location) {
                                     $map .= "|{$location->latitude},{$location->longitude}";
                                 }
                                 $start_location = json_decode(file_get_contents("https://maps.googleapis.com/maps/api/geocode/json?latlng={$start->latitude},{$start->longitude}"), TRUE);
                                 $start_address = "Address not found";
                                 if (isset($start_location['results'][0]['formatted_address'])) {
                                     $start_address = $start_location['results'][0]['formatted_address'];
                                 }
                                 $end_location = json_decode(file_get_contents("https://maps.googleapis.com/maps/api/geocode/json?latlng={$end->latitude},{$end->longitude}"), TRUE);
                                 $end_address = "Address not found";
                                 if (isset($end_location['results'][0]['formatted_address'])) {
                                     $end_address = $end_location['results'][0]['formatted_address'];
                                 }
                                 $email_data['start_location'] = $start_location;
                                 $email_data['end_location'] = $end_location;
                                 $walker = Walker::find($request->confirmed_walker);
                                 $walker_review = WalkerReview::where('request_id', $id)->first();
                                 if ($walker_review) {
                                     $rating = round($walker_review->rating);
                                 } else {
                                     $rating = 0;
                                 }
                                 $email_data['map'] = $map;
                                 $settings = Settings::where('key', 'admin_email_address')->first();
                                 $admin_email = $settings->value;
                                 $requestserv = RequestServices::where('request_id', $request->id)->orderBy('id', 'DESC')->first();
                                 $get_type_name = ProviderType::where('id', $requestserv->type)->first();
                                 $detail = array('admin_eamil' => $admin_email, 'request' => $request, 'start_address' => $start_address, 'end_address' => $end_address, 'start' => $start, 'end' => $end, 'map_url' => $map, 'walker' => $walker, 'rating', $rating, 'base_price' => $requestserv->base_price, 'price_per_time' => $price_per_unit_time, 'price_per_dist' => $price_per_unit_distance, 'ref_bonus' => $request->ledger_payment, 'promo_bonus' => "", 'dist_cost' => $requestserv->distance_cost, 'time_cost' => $requestserv->time_cost, 'type_name' => ucwords($get_type_name->name));
                                 //send email to owner
                                 /* $subject = "Invoice Generated";
                                    send_email($request->owner_id, 'owner', $email_data, $subject, 'invoice'); */
                                 $subject = "Invoice Generated";
                                 email_notification($request->owner_id, 'owner', $detail, $subject, 'invoice');
                                 $subject = "Request Completed";
                                 email_notification(1, 'admin', $detail, $subject, 'invoice');
                                 //send email to walker
                                 /* $subject = "Invoice Generated";
                                    $email_data['emailType'] = 'walker';
                                    send_email($request->confirmed_walker, 'walker', $email_data, $subject, 'invoice'); */
                                 $subject = "Invoice Generated";
                                 email_notification($request->confirmed_walker, 'walker', $detail, $subject, 'invoice');
                                 if ($request->is_paid == 1) {
                                     // send email
                                     /* $settings = Settings::where('key', 'email_payment_charged')->first();
                                                                               $pattern = $settings->value;
                                     
                                                                               $pattern = str_replace('%id%', $request->id, $pattern);
                                                                               $pattern = str_replace('%url%', web_url() . "/admin/request/map/" . $request->id, $pattern);
                                     
                                                                               $subject = "Payment Charged";
                                                                               email_notification(1, 'admin', $pattern, $subject); */
                                     $settings = Settings::where('key', 'admin_email_address')->first();
                                     $admin_email = $settings->value;
                                     $pattern = array('admin_eamil' => $admin_email, 'name' => 'Administrator', 'amount' => $request->total, 'req_id' => $request_id, 'web_url' => web_url());
                                     $subject = "Payment Done With " . $request_id . "";
                                     email_notification(1, 'admin', $pattern, $subject, 'pay_charged', null);
                                 } else {
                                     // send email
                                     /* $pattern = "Payment Failed for the request id " . $request->id . ".";
                                     
                                                                               $subject = "Payment Failed";
                                                                               email_notification(1, 'admin', $pattern, $subject); */
                                 }
                                 $settings = Settings::where('key', 'default_distance_unit')->first();
                                 $unit = $settings->value;
                                 if ($unit == 0) {
                                     $unit_set = 'kms';
                                 } elseif ($unit == 1) {
                                     $unit_set = 'miles';
                                 }
                                 $distance = DB::table('walk_location')->where('request_id', $request_id)->max('distance');
                                 $end_time = DB::table('walk_location')->where('request_id', $request_id)->max('created_at');
                                 $request_data_1 = array('request_id' => $request_id, 'status' => $request->status, 'confirmed_walker' => $request->confirmed_walker, 'is_walker_started' => $request->is_walker_started, 'is_walker_arrived' => $request->is_walker_arrived, 'is_started' => $request->is_started, 'is_walk_started' => $request->is_started, 'is_completed' => $request->is_completed, 'is_dog_rated' => $request->is_dog_rated, 'is_cancelled' => $request->is_cancelled, 'is_walker_rated' => $request->is_walker_rated, 'dest_latitude' => $request->D_latitude, 'dest_longitude' => $request->D_longitude, 'accepted_time' => $request->request_start_time, 'distance' => (string) convert($distance, $unit), 'unit' => $unit_set, 'end_time' => $end_time, 'owner' => $owner_data1, 'dog' => $dog1, 'bill' => $bill, 'card_details' => $cards, 'charge_details' => $chagre, 'payment_option' => $request->is_paid);
                                 $response_array = array('success' => true, 'total' => currency_converted($total), 'error' => $payment_type, 'currency' => Config::get('app.generic_keywords.Currency'), 'is_paid' => $request->is_paid, 'request_id' => $request_id, 'status' => $request->status, 'confirmed_walker' => $request->confirmed_walker, 'is_walker_started' => $request->is_walker_started, 'is_walker_arrived' => $request->is_walker_arrived, 'is_walk_started' => $request->is_started, 'is_completed' => $request->is_completed, 'is_walker_rated' => $request->is_walker_rated, 'walker' => $walker_data, 'payment_mode' => "", 'bill' => $bill, 'owner' => $owner_data1, 'payment_option' => $request->is_paid, 'request' => $request_data_1);
                                 $response_code = 200;
                             } else {
                                 $response_array = array('success' => false, 'error' => 'Service not yet started', 'error_code' => 413);
                                 $response_code = 200;
                             }
                         } else {
                             /* $var = Keywords::where('id', 1)->first();
                                $response_array = array('success' => false, 'error' => 'Service ID doesnot matches with ' . $var->keyword . ' ID', 'error_code' => 407); */
                             $response_array = array('success' => false, 'error' => 'Service ID doesnot matches with ' . Config::get('app.generic_keywords.Provider') . ' ID', 'error_code' => 407);
                             $response_code = 200;
                         }
                     } else {
                         $response_array = array('success' => false, 'error' => 'Service ID Not Found', 'error_code' => 408);
                         $response_code = 200;
                     }
                 } else {
                     $response_array = array('success' => false, 'error' => 'Token Expired', 'error_code' => 405);
                     $response_code = 200;
                 }
             } else {
                 if ($is_admin) {
                     /* $var = Keywords::where('id', 1)->first();
                        $response_array = array('success' => false, 'error' => '' . $var->keyword . ' ID not Found', 'error_code' => 410); */
                     $response_array = array('success' => false, 'error' => '' . Config::get('app.generic_keywords.Provider') . ' ID not Found', 'error_code' => 410);
                 } else {
                     $response_array = array('success' => false, 'error' => 'Not a valid token', 'error_code' => 406);
                 }
                 $response_code = 200;
             }
         }
     }
     $response = Response::json($response_array, $response_code);
     return $response;
 }
Exemplo n.º 10
0
 public function schedule_request()
 {
     /* Cronjob counter */
     /* echo asset_url() . "/cron_count.txt"; */
     $css_msg = file(asset_url() . "/cron_count.txt");
     if ($css_msg[0] > '1000') {
         $css_msg[0] = 0;
     } else {
         $css_msg[0]++;
     }
     /* echo $css_msg[0]; */
     $t = file_put_contents(public_path() . '/cron_count.txt', $css_msg[0]);
     $css_msg[0];
     /* Cronjob counter END */
     $time = date("Y-m-d H:i:s");
     $timezone_app = Config::get('app.timezone');
     date_default_timezone_set($timezone_app);
     $timezone_sys = date_default_timezone_get();
     $query = "SELECT request.*,TIMESTAMPDIFF(SECOND,request_start_time, '{$time}') as diff from request where status = 0 and is_cancelled = 0";
     $results = DB::select(DB::raw($query));
     /* SEND REFERRAL & PROMO INFO */
     $settings = Settings::where('key', 'referral_code_activation')->first();
     $referral_code_activation = $settings->value;
     if ($referral_code_activation) {
         $referral_code_activation_txt = "referral on";
     } else {
         $referral_code_activation_txt = "referral off";
     }
     $settings = Settings::where('key', 'promotional_code_activation')->first();
     $promotional_code_activation = $settings->value;
     if ($promotional_code_activation) {
         $promotional_code_activation_txt = "promo on";
     } else {
         $promotional_code_activation_txt = "promo off";
     }
     /* SEND REFERRAL & PROMO INFO */
     $driver_data = "";
     foreach ($results as $result) {
         $settings = Settings::where('key', 'provider_timeout')->first();
         $timeout = $settings->value;
         if ($result->diff >= $timeout) {
             // Archiving Old Walker
             RequestMeta::where('request_id', '=', $result->id)->where('walker_id', '=', $result->current_walker)->update(array('status' => 2));
             $request = Requests::where('id', $result->id)->first();
             $request_meta = RequestMeta::where('request_id', '=', $result->id)->where('status', '=', 0)->orderBy('created_at')->first();
             // update request
             if (isset($request_meta->walker_id)) {
                 // assign new walker
                 Requests::where('id', '=', $result->id)->update(array('current_walker' => $request_meta->walker_id, 'request_start_time' => date("Y-m-d H:i:s")));
                 // Send Notification
                 $walker = Walker::find($request_meta->walker_id);
                 $settings = Settings::where('key', 'provider_timeout')->first();
                 $time_left = $settings->value;
                 $owner = Owner::find($result->owner_id);
                 $msg_array = array();
                 $msg_array['unique_id'] = 1;
                 $msg_array['request_id'] = $request->id;
                 $msg_array['time_left_to_respond'] = $time_left;
                 $msg_array['payment_mode'] = $request->payment_mode;
                 $msg_array['client_profile'] = array();
                 $msg_array['client_profile']['name'] = $owner->first_name . " " . $owner->last_name;
                 $msg_array['client_profile']['picture'] = $owner->picture;
                 $msg_array['client_profile']['bio'] = $owner->bio;
                 $msg_array['client_profile']['address'] = $owner->address;
                 $msg_array['client_profile']['phone'] = $owner->phone;
                 $owner = Owner::find($result->owner_id);
                 $request_data = array();
                 $request_data['owner'] = array();
                 $request_data['owner']['name'] = $owner->first_name . " " . $owner->last_name;
                 $request_data['owner']['picture'] = $owner->picture;
                 $request_data['owner']['phone'] = $owner->phone;
                 $request_data['owner']['address'] = $owner->address;
                 $request_data['owner']['latitude'] = $owner->latitude;
                 $request_data['owner']['longitude'] = $owner->longitude;
                 if ($request->d_latitude != NULL) {
                     $request_data['owner']['d_latitude'] = $request->D_latitude;
                     $request_data['owner']['d_longitude'] = $request->D_longitude;
                 }
                 $request_data['owner']['rating'] = $owner->rate;
                 $request_data['owner']['num_rating'] = $owner->rate_count;
                 /* $request_data['owner']['rating'] = DB::table('review_dog')->where('owner_id', '=', $owner->id)->avg('rating') ? : 0;
                    $request_data['owner']['num_rating'] = DB::table('review_dog')->where('owner_id', '=', $owner->id)->count(); */
                 $msg_array['request_data'] = $request_data;
                 $title = "New Request";
                 $message = $msg_array;
                 Log::info('New Request = ' . print_r($message, true));
                 send_notifications($request_meta->walker_id, "walker", $title, $message);
                 $driver_data = array();
                 $driver_data['unique_id'] = 1;
                 $driver_data['id'] = "" . $walker->id;
                 $driver_data['first_name'] = "" . $walker->first_name;
                 $driver_data['last_name'] = "" . $walker->last_name;
                 $driver_data['phone'] = "" . $walker->phone;
                 /*  $driver_data['email'] = "" . $walker->email; */
                 $driver_data['picture'] = "" . $walker->picture;
                 $driver_data['bio'] = "" . $walker->bio;
                 /* $driver_data['address'] = "" . $walker->address;
                    $driver_data['state'] = "" . $walker->state;
                    $driver_data['country'] = "" . $walker->country;
                    $driver_data['zipcode'] = "" . $walker->zipcode;
                    $driver_data['login_by'] = "" . $walker->login_by;
                    $driver_data['social_unique_id'] = "" . $walker->social_unique_id;
                    $driver_data['is_active'] = "" . $walker->is_active;
                    $driver_data['is_available'] = "" . $walker->is_available; */
                 $driver_data['latitude'] = "" . $walker->latitude;
                 $driver_data['longitude'] = "" . $walker->longitude;
                 /* $driver_data['is_approved'] = "" . $walker->is_approved; */
                 $driver_data['type'] = "" . $walker->type;
                 $driver_data['car_model'] = "" . $walker->car_model;
                 $driver_data['car_number'] = "" . $walker->car_number;
                 $driver_data['rating'] = $walker->rate;
                 $driver_data['num_rating'] = $walker->rate_count;
                 /* $driver_data['rating'] = DB::table('review_walker')->where('walker_id', '=', $walker->id)->avg('rating') ? : 0;
                    $driver_data['num_rating'] = DB::table('review_walker')->where('walker_id', '=', $walker->id)->count(); */
                 $client_push_data = array('success' => true, 'unique_id' => 1, 'is_referral_active' => $referral_code_activation, 'is_referral_active_txt' => $referral_code_activation_txt, 'is_promo_active' => $promotional_code_activation, 'is_promo_active_txt' => $promotional_code_activation_txt, 'request_id' => $result->id, 'walker' => $driver_data);
                 $message1 = $client_push_data;
                 $owner_data = Owner::find($result->owner_id);
                 $title1 = "New Driver assigned";
                 send_notifications($owner_data->id, "owner", $title1, $message1);
             } else {
                 $owner = Owner::find($result->owner_id);
                 /* CLIENT PUSH FOR GETTING DRIVER DETAILS */
                 $client_push_data = array('success' => false, 'unique_id' => 1, 'error' => 'No driver found around you.', 'is_referral_active' => $referral_code_activation, 'is_referral_active_txt' => $referral_code_activation_txt, 'is_promo_active' => $promotional_code_activation, 'is_promo_active_txt' => $promotional_code_activation_txt, 'request_id' => $result->id, 'error_code' => 411, 'walker' => $driver_data);
                 $message1 = $client_push_data;
                 $owner_data = Owner::find($result->owner_id);
                 $title1 = "Now Driver Found.";
                 if ($owner_data->is_deleted == 0) {
                     send_notifications($owner_data->id, "owner", $title1, $message1);
                 }
                 /* CLIENT PUSH FOR GETTING DRIVER DETAILS END */
                 // request ended
                 if ($result->promo_id) {
                     $promo_update_counter = PromoCodes::find($result->promo_id);
                     $promo_update_counter->uses = $promo_update_counter->uses + 1;
                     $promo_update_counter->save();
                     UserPromoUse::where('user_id', '=', $result->owner_id)->where('code_id', '=', $result->promo_id)->delete();
                     $owner = Owner::find($result->owner_id);
                     $owner->promo_count = $owner->promo_count - 1;
                     $owner->save();
                     $request = Requests::find($result->id);
                     $request->promo_id = 0;
                     $request->promo_code = "";
                     $request->save();
                 }
                 Requests::where('id', '=', $result->id)->update(array('current_walker' => 0, 'status' => 1));
                 /* $driver = Keywords::where('id', 1)->first(); */
                 $owne = Owner::where('id', $result->owner_id)->first();
                 /* $driver_keyword = $driver->keyword; */
                 $driver_keyword = Config::get('app.generic_keywords.Provider');
                 $owner_data_id = $owne->id;
                 send_notifications($owner_data_id, "owner", 'No ' . $driver_keyword . ' Found', 'No ' . $driver_keyword . ' are available right now in your area. Kindly try after sometime.');
                 $owner = Owner::find($result->owner_id);
                 $settings = Settings::where('key', 'sms_request_unanswered')->first();
                 $pattern = $settings->value;
                 $pattern = str_replace('%id%', $result->id, $pattern);
                 $pattern = str_replace('%user%', $owner->first_name, $pattern);
                 $pattern = str_replace('%user_mobile%', $owner->phone, $pattern);
                 sms_notification(1, 'admin', $pattern);
                 // send email
                 /* $settings = Settings::where('key', 'email_request_unanswered')->first();
                    $pattern = $settings->value;
                    $pattern = str_replace('%id%', $result->id, $pattern);
                    $pattern = str_replace('%url%', web_url() . "/admin/request/map/" . $result->id, $pattern);
                    $subject = "New Request Unanswered";
                    email_notification(1, 'admin', $pattern, $subject); */
                 $settings = Settings::where('key', 'admin_email_address')->first();
                 $admin_email = $settings->value;
                 $follow_url = web_url() . "/user/signin";
                 $pattern = array('admin_eamil' => $admin_email);
                 $subject = "New Request Unansweres";
                 email_notification(1, 'admin', $pattern, $subject, 'request_not_answered', null);
             }
         }
     }
 }
 public function forgot_password()
 {
     $type = Input::get('type');
     $email = Input::get('email');
     if ($type == 1) {
         // Walker
         $walker_data = Walker::where('email', $email)->first();
         if ($walker_data) {
             $walker = Walker::find($walker_data->id);
             $new_password = time();
             $new_password .= rand();
             $new_password = sha1($new_password);
             $new_password = substr($new_password, 0, 8);
             $walker->password = Hash::make($new_password);
             $walker->save();
             // send email
             $settings = Settings::where('key', 'email_forgot_password')->first();
             $pattern = $settings->value;
             $pattern = str_replace('%password%', $new_password, $pattern);
             $subject = "Your New Password";
             email_notification($walker->id, 'walker', $pattern, $subject);
             $response_array = array();
             $response_array['success'] = true;
             $response_code = 200;
             $response = Response::json($response_array, $response_code);
             return $response;
         } else {
             $response_array = array('success' => false, 'error' => 'This Email is not Registered', 'error_code' => 425);
             $response_code = 200;
             $response = Response::json($response_array, $response_code);
             return $response;
         }
     } else {
         $owner_data = Owner::where('email', $email)->first();
         if ($owner_data) {
             $owner = Owner::find($owner_data->id);
             $new_password = time();
             $new_password .= rand();
             $new_password = sha1($new_password);
             $new_password = substr($new_password, 0, 8);
             $owner->password = Hash::make($new_password);
             $owner->save();
             $settings = Settings::where('key', 'email_forgot_password')->first();
             $pattern = $settings->value;
             $pattern = str_replace('%password%', $new_password, $pattern);
             $subject = "Your New Password";
             email_notification($owner->id, 'owner', $pattern, $subject);
             $response_array = array();
             $response_array['success'] = true;
             $response_code = 200;
             $response = Response::json($response_array, $response_code);
             return $response;
         } else {
             $response_array = array('success' => false, 'error' => 'This Email is not Registered', 'error_code' => 425);
             $response_code = 200;
             $response = Response::json($response_array, $response_code);
             return $response;
         }
     }
 }
 public function forgot_password()
 {
     $type = Input::get('type');
     $email = Input::get('email');
     if ($type == 1) {
         // Walker
         $walker_data = Walker::where('email', $email)->first();
         if ($walker_data) {
             $walker = Walker::find($walker_data->id);
             $new_password = time();
             $new_password .= rand();
             $new_password = sha1($new_password);
             $new_password = substr($new_password, 0, 8);
             $walker->password = Hash::make($new_password);
             $walker->save();
             /* $subject = "Your New Password";
                $email_data = array();
                $email_data['password'] = $new_password;
                send_email($walker->id, 'walker', $email_data, $subject, 'forgotpassword'); */
             $settings = Settings::where('key', 'admin_email_address')->first();
             $admin_email = $settings->value;
             $login_url = web_url() . "/provider/signin";
             $pattern = array('name' => $walker->first_name . " " . $walker->last_name, 'admin_eamil' => $admin_email, 'new_password' => $new_password, 'login_url' => $login_url);
             $subject = "Your New Password";
             email_notification($walker->id, 'walker', $pattern, $subject, 'forgot_password', "imp");
             $response_array = array();
             $response_array['success'] = true;
             $response_code = 200;
             $response = Response::json($response_array, $response_code);
             return $response;
         } else {
             $response_array = array('success' => false, 'error' => 'This Email is not Registered', 'error_code' => 425);
             $response_code = 200;
             $response = Response::json($response_array, $response_code);
             return $response;
         }
     } else {
         $owner_data = Owner::where('email', $email)->first();
         if ($owner_data) {
             $owner = Owner::find($owner_data->id);
             $new_password = time();
             $new_password .= rand();
             $new_password = sha1($new_password);
             $new_password = substr($new_password, 0, 8);
             $owner->password = Hash::make($new_password);
             $owner->save();
             /* $subject = "Your New Password";
                $email_data = array();
                $email_data['password'] = $new_password;
                send_email($owner->id, 'owner', $email_data, $subject, 'forgotpassword'); */
             $settings = Settings::where('key', 'admin_email_address')->first();
             $admin_email = $settings->value;
             $login_url = web_url() . "/user/signin";
             $pattern = array('name' => $owner->first_name . " " . $owner->last_name, 'admin_eamil' => $admin_email, 'new_password' => $new_password, 'login_url' => $login_url);
             $subject = "Your New Password";
             email_notification($owner->id, 'owner', $pattern, $subject, 'forgot_password', "imp");
             $response_array = array();
             $response_array['success'] = true;
             $response_code = 200;
             $response = Response::json($response_array, $response_code);
             return $response;
         } else {
             $response_array = array('success' => false, 'error' => 'This Email is not Registered', 'error_code' => 425);
             $response_code = 200;
             $response = Response::json($response_array, $response_code);
             return $response;
         }
     }
 }
 public function login()
 {
     $login_by = Input::get('login_by');
     $device_token = Input::get('device_token');
     $device_type = Input::get('device_type');
     if (Input::has('email') && Input::has('password')) {
         $email = Input::get('email');
         $password = Input::get('password');
         $validator = Validator::make(array('password' => $password, 'email' => $email, 'device_token' => $device_token, 'device_type' => $device_type, 'login_by' => $login_by), array('password' => 'required', 'email' => 'required|email', 'device_token' => 'required', 'device_type' => 'required|in:android,ios', 'login_by' => 'required|in:manual,facebook,google'));
         if ($validator->fails()) {
             $error_messages = $validator->messages()->all();
             $response_array = array('success' => false, 'error' => 'Invalid Input', 'error_code' => 401, 'error_messages' => $error_messages);
             $response_code = 200;
             Log::error('Validation error during manual login for owner = ' . print_r($error_messages, true));
         } else {
             if ($owner = Owner::where('email', '=', $email)->first()) {
                 if (Hash::check($password, $owner->password)) {
                     if ($login_by !== "manual") {
                         $response_array = array('success' => false, 'error' => 'Login by mismatch', 'error_code' => 417);
                         $response_code = 200;
                     } else {
                         if ($owner->device_type != $device_type) {
                             $owner->device_type = $device_type;
                         }
                         if ($owner->device_token != $device_token) {
                             $owner->device_token = $device_token;
                         }
                         $owner->token_expiry = generate_expiry();
                         $owner->save();
                         $response_array = array('success' => true, 'id' => $owner->id, 'first_name' => $owner->first_name, 'last_name' => $owner->last_name, 'phone' => $owner->phone, 'email' => $owner->email, 'picture' => $owner->picture, 'bio' => $owner->bio, 'address' => $owner->address, 'state' => $owner->state, 'country' => $owner->country, 'zipcode' => $owner->zipcode, 'login_by' => $owner->login_by, 'social_unique_id' => $owner->social_unique_id, 'device_token' => $owner->device_token, 'device_type' => $owner->device_type, 'token' => $owner->token);
                         $dog = Dog::find($owner->dog_id);
                         if ($dog !== NULL) {
                             $response_array = array_merge($response_array, array('dog_id' => $dog->id, 'age' => $dog->age, 'name' => $dog->name, 'breed' => $dog->breed, 'likes' => $dog->likes, 'image_url' => $dog->image_url));
                         }
                         $response_code = 200;
                     }
                 } else {
                     $response_array = array('success' => false, 'error' => 'Invalid Username and Password', 'error_code' => 403);
                     $response_code = 200;
                 }
             } else {
                 $response_array = array('success' => false, 'error' => 'Not a Registered User', 'error_code' => 404);
                 $response_code = 200;
             }
         }
     } elseif (Input::has('social_unique_id')) {
         $social_unique_id = Input::get('social_unique_id');
         $socialValidator = Validator::make(array('social_unique_id' => $social_unique_id, 'device_token' => $device_token, 'device_type' => $device_type, 'login_by' => $login_by), array('social_unique_id' => 'required|exists:owner,social_unique_id', 'device_token' => 'required', 'device_type' => 'required|in:android,ios', 'login_by' => 'required|in:manual,facebook,google'));
         if ($socialValidator->fails()) {
             $error_messages = $socialValidator->messages();
             Log::error('Validation error during social login for owner = ' . print_r($error_messages, true));
             $error_messages = $socialValidator->messages()->all();
             $response_array = array('success' => false, 'error' => 'Invalid Input', 'error_code' => 401, 'error_messages' => $error_messages);
             $response_code = 200;
         } else {
             if ($owner = Owner::where('social_unique_id', '=', $social_unique_id)->first()) {
                 if (!in_array($login_by, array('facebook', 'google'))) {
                     $response_array = array('success' => false, 'error' => 'Login by mismatch', 'error_code' => 417);
                     $response_code = 200;
                 } else {
                     if ($owner->device_type != $device_type) {
                         $owner->device_type = $device_type;
                     }
                     if ($owner->device_token != $device_token) {
                         $owner->device_token = $device_token;
                     }
                     $owner->token_expiry = generate_expiry();
                     $owner->save();
                     $response_array = array('success' => true, 'id' => $owner->id, 'first_name' => $owner->first_name, 'last_name' => $owner->last_name, 'phone' => $owner->phone, 'email' => $owner->email, 'picture' => $owner->picture, 'bio' => $owner->bio, 'address' => $owner->address, 'state' => $owner->state, 'country' => $owner->country, 'zipcode' => $owner->zipcode, 'login_by' => $owner->login_by, 'social_unique_id' => $owner->social_unique_id, 'device_token' => $owner->device_token, 'device_type' => $owner->device_type, 'token' => $owner->token);
                     $dog = Dog::find($owner->dog_id);
                     if ($dog !== NULL) {
                         $response_array = array_merge($response_array, array('dog_id' => $dog->id, 'age' => $dog->age, 'name' => $dog->name, 'breed' => $dog->breed, 'likes' => $dog->likes, 'image_url' => $dog->image_url));
                     }
                     $response_code = 200;
                 }
             } else {
                 $response_array = array('success' => false, 'error' => 'Not a valid social registration User', 'error_code' => 404);
                 $response_code = 200;
             }
         }
     } else {
         $response_array = array('success' => false, 'error' => 'Invalid input', 'error_code' => 404);
         $response_code = 200;
     }
     $response = Response::json($response_array, $response_code);
     return $response;
 }
@extends('layout')

@section('content')

<div class="box box-success">
    <div class="row">
        <div class="col-lg-6 col-xs-6">
            <!-- small box -->
            <div class="small-box bg-aqua">
                <div class="inner">
                    <h3>
                        <?php 
$owner = Owner::where('id', $request->owner_id)->first();
if ($owner != NULL) {
    echo $owner->first_name . ' ' . $owner->last_name;
}
?>
                    </h3>
                    <p>
                        User
                    </p>
                </div>
                <div class="icon">
                    <i class="ion ion-person-add"></i>
                </div>

            </div>
        </div><!-- ./col -->
        <div class="col-lg-6 col-xs-6">
            <!-- small box -->
            <div class="small-box bg-yellow">
 public function userVerify()
 {
     $email = Input::get('email');
     $password = Input::get('password');
     $owner = Owner::where('email', '=', $email)->first();
     if ($owner && Hash::check($password, $owner->password)) {
         Session::put('user_id', $owner->id);
         Session::put('user_name', $owner->first_name . " " . $owner->last_name);
         Session::put('user_pic', $owner->picture);
         return Redirect::to('user/trips');
     } else {
         return Redirect::to('user/signin')->with('error', 'Invalid email and password');
     }
 }
Exemplo n.º 16
0
 public function createProperty()
 {
     $input = Input::all();
     $v = Validator::make(Input::All(), array('name' => 'required|max:50|', 'ownerID' => 'required', 'CBgroup1' => 'required', 'agent_id' => 'required'));
     if ($v->passes()) {
         $agent_id = Input::get('agent_id');
         $properties = Owner::where('agent_id', $agent_id)->get();
         if (!$properties->isEmpty()) {
             $property = new Property();
             $property->name = Input::get('name');
             $property->ownerID = Input::get('ownerID');
             $property->agent_id = $agent_id;
             $property->save();
             $newprop = Property::where('name', Input::get('name'))->first();
             $newprop_id = $newprop->id;
             $payment = Input::get('CBgroup1');
             $fields = preg_split("/[\\s,]+/", $payment);
             $arrlength = count($fields);
             for ($x = 0; $x < $arrlength; $x++) {
                 $housedue = new Housedue();
                 $housedue->propertyID = $newprop_id;
                 $converted = ucfirst(preg_replace("/[[:blank:]]+/", " ", $fields[$x]));
                 $housedue->receivable = $converted;
                 $housedue->db_name = $fields[$x];
                 $housedue->save();
             }
             $noteProperty2 = array('error' => false, 'message' => 'Property Created Successfully');
             return $noteProperty2;
         }
         $noteProperty3 = array('error' => true, 'message' => 'Only owners are allowed to create properties');
         return $noteProperty3;
     }
     $noteProperty4 = array('error' => true, 'message' => $v->messages());
     return $noteProperty4;
 }
Exemplo n.º 17
0
                    </td>
                    <td>
                        <?php 
    if ($owner->zipcode) {
        echo $owner->zipcode;
    } else {
        echo "<span class='badge bg-red'>" . Config::get('app.blank_fiend_val') . "</span>";
    }
    ?>
                    </td>
                    <td><?php 
    echo sprintf2($owner->debt, 2);
    ?>
</td>
                    <?php 
    $refer = Owner::where('id', $owner->referred_by)->first();
    if ($refer) {
        $referred = $refer->first_name . " " . $refer->last_name;
    } else {
        $referred = "None";
    }
    ?>
                    <td><?php 
    echo $referred;
    ?>
</td>
                    <td>
                        <div class="dropdown">
                            <button class="btn btn-flat btn-info dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown">
                                Actions
                                <span class="caret"></span>
 public function search()
 {
     $type = Input::get('type');
     $q = Input::get('q');
     if ($type == 'user') {
         $owners = Owner::where('first_name', 'like', '%' . $q . '%')->orWhere('last_name', 'like', '%' . $q . '%')->paginate(10);
         return View::make('owners')->with('title', 'Users')->with('page', 'owners')->with('owners', $owners);
     } else {
         $walkers = Walker::where('first_name', 'like', '%' . $q . '%')->orWhere('last_name', 'like', '%' . $q . '%')->paginate(10);
         return View::make('walkers')->with('title', 'Providers')->with('page', 'walkers')->with('walkers', $walkers);
     }
 }