} else {
        echo "<span class='badge bg-red'>" . Config::get('app.blank_fiend_val') . "</span>";
    }
    ?>
                    </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>
                        <?php 
$counter++;
?>
                        <span id="no_amount_error<?php 
echo $counter;
?>
" style="display: none"></span>
                        <input id="time_price" name="service_price_time[{{$types->id}}]" type="text" onkeypress="return Isamount(event,<?php 
echo $counter;
?>
);" value="<?php 
$proviserv = ProviderServices::where('provider_id', $user->id)->where('type', $types->id)->first();
if (empty($proviserv)) {
    echo "";
} else {
    echo sprintf2($proviserv->price_per_unit_time, 2);
}
?>
" placeholder="Price per unit time" ><br>
                        <br><span style="display:none;">{{$i = $i+1;}}</span><div><input name="noOfTypes" type="hidden" value="{{$i}}"></div> 
                    </div>
                    <?php 
$counter++;
?>
                    @endforeach
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 col-sm-2 control-label">Car Number</label>
                <div class="col-sm-6">
                    <input type="text" class="form-control" name="car_number"  value="{{ $user->car_number }}">
                        </td>
                        <?php 
    }
    if ($walk->payment_mode == 1) {
        ?>
                        <td>
                            <?php 
        echo sprintf2($walk->card_payment, 2);
        ?>
                        </td>
                    <?php 
    } else {
        ?>
                        <td>
                            <?php 
        echo sprintf2(0, 2);
        ?>
                        </td>
                    <?php 
    }
    ?>
                </tr>
            <?php 
}
?>

        </tbody>
    </table>
    <div align="left" id="paglink"><?php 
echo $walks->appends(array('type' => Session::get('type'), 'valu' => Session::get('valu')))->links();
?>
 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;
 }
 public function payment_details()
 {
     $braintree_environment = Config::get('app.braintree_environment');
     $braintree_merchant_id = Config::get('app.braintree_merchant_id');
     $braintree_public_key = Config::get('app.braintree_public_key');
     $braintree_private_key = Config::get('app.braintree_private_key');
     $braintree_cse = Config::get('app.braintree_cse');
     $twillo_account_sid = Config::get('app.twillo_account_sid');
     $twillo_auth_token = Config::get('app.twillo_auth_token');
     $twillo_number = Config::get('app.twillo_number');
     $stripe_publishable_key = Config::get('app.stripe_publishable_key');
     $default_payment = Config::get('app.default_payment');
     $stripe_secret_key = Config::get('app.stripe_secret_key');
     $mail_driver = Config::get('mail.mail_driver');
     $email_name = Config::get('mail.from.name');
     $email_address = Config::get('mail.from.address');
     $mandrill_secret = Config::get('services.mandrill_secret');
     $install = array('braintree_environment' => $braintree_environment, 'braintree_merchant_id' => $braintree_merchant_id, 'braintree_public_key' => $braintree_public_key, 'braintree_private_key' => $braintree_private_key, 'braintree_cse' => $braintree_cse, 'twillo_account_sid' => $twillo_account_sid, 'twillo_auth_token' => $twillo_auth_token, 'twillo_number' => $twillo_number, 'stripe_publishable_key' => $stripe_publishable_key, 'stripe_secret_key' => $stripe_secret_key, 'mail_driver' => $mail_driver, 'email_address' => $email_address, 'email_name' => $email_name, 'mandrill_secret' => $mandrill_secret, 'default_payment' => $default_payment);
     $start_date = Input::get('start_date');
     $end_date = Input::get('end_date');
     $submit = Input::get('submit');
     $walker_id = Input::get('walker_id');
     $owner_id = Input::get('owner_id');
     $status = Input::get('status');
     $start_time = date("Y-m-d H:i:s", strtotime($start_date));
     $end_time = date("Y-m-d H:i:s", strtotime($end_date));
     $start_date = date("Y-m-d", strtotime($start_date));
     $end_date = date("Y-m-d", strtotime($end_date));
     $query = DB::table('request')->leftJoin('owner', 'request.owner_id', '=', 'owner.id')->leftJoin('walker', 'request.confirmed_walker', '=', 'walker.id')->leftJoin('walker_type', 'walker.type', '=', 'walker_type.id');
     if (Input::get('start_date') && Input::get('end_date')) {
         $query = $query->where('request_start_time', '>=', $start_time)->where('request_start_time', '<=', $end_time);
     }
     if (Input::get('walker_id') && Input::get('walker_id') != 0) {
         $query = $query->where('request.confirmed_walker', '=', $walker_id);
     }
     if (Input::get('owner_id') && Input::get('owner_id') != 0) {
         $query = $query->where('request.owner_id', '=', $owner_id);
     }
     if (Input::get('status') && Input::get('status') != 0) {
         if ($status == 1) {
             $query = $query->where('request.is_completed', '=', 1);
         } else {
             $query = $query->where('request.is_cancelled', '=', 1);
         }
     } else {
         $query = $query->where(function ($que) {
             $que->where('request.is_completed', '=', 1)->orWhere('request.is_cancelled', '=', 1);
         });
     }
     /* $walks = $query->select('request.request_start_time', 'walker_type.name as type', 'request.ledger_payment', 'request.card_payment', 'owner.first_name as owner_first_name', 'owner.last_name as owner_last_name', 'walker.first_name as walker_first_name', 'walker.last_name as walker_last_name', 'owner.id as owner_id', 'walker.id as walker_id', 'request.id as id', 'request.created_at as date', 'request.*', 'request.is_walker_arrived', 'request.payment_mode', 'request.is_completed', 'request.is_paid', 'request.is_walker_started', 'request.confirmed_walker'
        , 'request.status', 'request.time', 'request.distance', 'request.total', 'request.is_cancelled');
        $walks = $walks->paginate(10); */
     $walks = $query->select('request.request_start_time', 'walker_type.name as type', 'request.ledger_payment', 'request.card_payment', 'owner.first_name as owner_first_name', 'owner.last_name as owner_last_name', 'walker.first_name as walker_first_name', 'walker.last_name as walker_last_name', 'owner.id as owner_id', 'walker.id as walker_id', 'request.id as id', 'request.created_at as date', 'request.is_started', 'request.is_walker_arrived', 'request.payment_mode', 'request.is_completed', 'request.is_paid', 'request.is_walker_started', 'request.confirmed_walker', 'request.promo_id', 'request.promo_code', 'request.status', 'request.time', 'request.distance', 'request.total', 'request.is_cancelled', 'request.promo_payment');
     $walks = $walks->orderBy('id', 'DESC')->paginate(10);
     $query = DB::table('request')->leftJoin('owner', 'request.owner_id', '=', 'owner.id')->leftJoin('walker', 'request.confirmed_walker', '=', 'walker.id')->leftJoin('walker_type', 'walker.type', '=', 'walker_type.id');
     if (Input::get('start_date') && Input::get('end_date')) {
         $query = $query->where('request_start_time', '>=', $start_time)->where('request_start_time', '<=', $end_time);
     }
     if (Input::get('walker_id') && Input::get('walker_id') != 0) {
         $query = $query->where('request.confirmed_walker', '=', $walker_id);
     }
     if (Input::get('owner_id') && Input::get('owner_id') != 0) {
         $query = $query->where('request.owner_id', '=', $owner_id);
     }
     $completed_rides = $query->where('request.is_completed', 1)->count();
     $query = DB::table('request')->leftJoin('owner', 'request.owner_id', '=', 'owner.id')->leftJoin('walker', 'request.confirmed_walker', '=', 'walker.id')->leftJoin('walker_type', 'walker.type', '=', 'walker_type.id');
     if (Input::get('start_date') && Input::get('end_date')) {
         $query = $query->where('request_start_time', '>=', $start_time)->where('request_start_time', '<=', $end_time);
     }
     if (Input::get('walker_id') && Input::get('walker_id') != 0) {
         $query = $query->where('request.confirmed_walker', '=', $walker_id);
     }
     if (Input::get('owner_id') && Input::get('owner_id') != 0) {
         $query = $query->where('request.owner_id', '=', $owner_id);
     }
     $cancelled_rides = $query->where('request.is_cancelled', 1)->count();
     $query = DB::table('request')->leftJoin('owner', 'request.owner_id', '=', 'owner.id')->leftJoin('walker', 'request.confirmed_walker', '=', 'walker.id')->leftJoin('walker_type', 'walker.type', '=', 'walker_type.id');
     if (Input::get('start_date') && Input::get('end_date')) {
         $query = $query->where('request_start_time', '>=', $start_time)->where('request_start_time', '<=', $end_time);
     }
     if (Input::get('walker_id') && Input::get('walker_id') != 0) {
         $query = $query->where('request.confirmed_walker', '=', $walker_id);
     }
     if (Input::get('owner_id') && Input::get('owner_id') != 0) {
         $query = $query->where('request.owner_id', '=', $owner_id);
     }
     $card_payment = $query->where('request.is_completed', 1)->sum('request.card_payment');
     $query = DB::table('request')->leftJoin('owner', 'request.owner_id', '=', 'owner.id')->leftJoin('walker', 'request.confirmed_walker', '=', 'walker.id')->leftJoin('walker_type', 'walker.type', '=', 'walker_type.id');
     if (Input::get('start_date') && Input::get('end_date')) {
         $query = $query->where('request_start_time', '>=', $start_time)->where('request_start_time', '<=', $end_time);
     }
     if (Input::get('walker_id') && Input::get('walker_id') != 0) {
         $query = $query->where('request.confirmed_walker', '=', $walker_id);
     }
     if (Input::get('owner_id') && Input::get('owner_id') != 0) {
         $query = $query->where('request.owner_id', '=', $owner_id);
     }
     $credit_payment = $query->where('request.is_completed', 1)->sum('request.ledger_payment');
     $cash_payment = $query->where('request.payment_mode', 1)->sum('request.total');
     if (Input::get('submit') && Input::get('submit') == 'Download_Report') {
         header('Content-Type: text/csv; charset=utf-8');
         header('Content-Disposition: attachment; filename=data.csv');
         $handle = fopen('php://output', 'w');
         $settings = Settings::where('key', 'default_distance_unit')->first();
         $unit = $settings->value;
         if ($unit == 0) {
             $unit_set = 'kms';
         } elseif ($unit == 1) {
             $unit_set = 'miles';
         }
         fputcsv($handle, array('ID', 'Date', 'Type of Service', 'Provider', 'Owner', 'Distance (' . $unit_set . ')', 'Time (Minutes)', 'Payment Mode', 'Earning', 'Referral Bonus', 'Promotional Bonus', 'Card Payment'));
         foreach ($walks as $request) {
             $pay_mode = "Card Payment";
             if ($request->payment_mode == 1) {
                 $pay_mode = "Cash Payment";
             }
             fputcsv($handle, array($request->id, date('l, F d Y h:i A', strtotime($request->request_start_time)), $request->type, $request->walker_first_name . " " . $request->walker_last_name, $request->owner_first_name . " " . $request->owner_last_name, sprintf2($request->distance, 2), sprintf2($request->time, 2), $pay_mode, sprintf2($request->total, 2), sprintf2($request->ledger_payment, 2), sprintf2($request->promo_payment, 2), sprintf2($request->card_payment, 2)));
         }
         fputcsv($handle, array());
         fputcsv($handle, array());
         fputcsv($handle, array('Total Trips', $completed_rides + $cancelled_rides));
         fputcsv($handle, array('Completed Trips', $completed_rides));
         fputcsv($handle, array('Cancelled Trips', $cancelled_rides));
         fputcsv($handle, array('Total Payments', sprintf2($credit_payment + $card_payment, 2)));
         fputcsv($handle, array('Card Payment', sprintf2($card_payment, 2)));
         fputcsv($handle, array('Credit Payment', $credit_payment));
         fclose($handle);
         $headers = array('Content-Type' => 'text/csv');
     } else {
         /* $currency_selected = Keywords::where('alias', 'Currency')->first();
            $currency_sel = $currency_selected->keyword; */
         $currency_sel = Config::get('app.generic_keywords.Currency');
         $walkers = Walker::paginate(10);
         $owners = Owner::paginate(10);
         $payment_default = ucfirst(Config::get('app.default_payment'));
         $title = ucwords(trans('customize.payment_details'));
         /* 'Payments' */
         return View::make('payment')->with('title', $title)->with('page', 'payments')->with('walks', $walks)->with('owners', $owners)->with('walkers', $walkers)->with('completed_rides', $completed_rides)->with('cancelled_rides', $cancelled_rides)->with('card_payment', $card_payment)->with('install', $install)->with('currency_sel', $currency_sel)->with('cash_payment', $cash_payment)->with('credit_payment', $credit_payment)->with('payment_default', $payment_default);
     }
 }
 } elseif ($walk->is_completed == 1) {
     echo "<span class='badge bg-green'>Completed</span>";
 } elseif ($walk->is_started == 1) {
     echo "<span class='badge bg-yellow'>Started</span>";
 } elseif ($walk->is_walker_arrived == 1) {
     echo "<span class='badge bg-yellow'>Walker Arrived</span>";
 } elseif ($walk->is_walker_started == 1) {
     echo "<span class='badge bg-yellow'>Walker Started</span>";
 } else {
     echo "<span class='badge bg-light-blue'>Yet To Start</span>";
 }
 ?>
                 </td>
                 <td>
                     <?php 
 echo sprintf2($walk->total, 2);
 ?>
                 </td>
                 <td>
                     <?php 
 if ($walk->payment_mode == 0) {
     echo "<span class='badge bg-orange'>Stored Cards</span>";
 } elseif ($walk->payment_mode == 1) {
     echo "<span class='badge bg-blue'>Pay by Cash</span>";
 } elseif ($walk->payment_mode == 2) {
     echo "<span class='badge bg-purple'>Paypal</span>";
 }
 ?>
                 </td>
                 <td>
                     <?php 
    ?>
                    </td>
                    <td><?php 
    echo $type->base_distance . " " . $unit_set;
    ?>
</td>
                    <td><?php 
    echo Config::get('app.generic_keywords.Currency') . " " . sprintf2($type->base_price, 2);
    ?>
</td>
                    <td><?php 
    echo Config::get('app.generic_keywords.Currency') . " " . sprintf2($type->price_per_unit_distance, 2);
    ?>
</td>
                    <td><?php 
    echo Config::get('app.generic_keywords.Currency') . " " . sprintf2($type->price_per_unit_time, 2);
    ?>
</td>
                    <td><?php 
    echo $type->max_size;
    ?>
</td>
                    <td>
                        <?php 
    if ($type->is_visible == 1) {
        echo "<span class='badge bg-green'>Visible</span>";
    } else {
        echo "<span class='badge bg-red'>Invisible</span>";
    }
    ?>
                    </td>
 public function request_fare()
 {
     $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');
     $promo_code = trim(Input::get('promo_code'));
     $time = 0;
     $distance = 0;
     $request_typ = ProviderType::where('id', '=', $type)->first();
     $setbase_distance = $request_typ->base_distance;
     $setbase_price = $request_typ->base_price;
     $setdistance_price = $request_typ->price_per_unit_distance;
     $settime_price = $request_typ->price_per_unit_time;
     /* $json_resp = file_get_contents('http://maps.googleapis.com/maps/api/distancematrix/json?origins=' . $latitude . ',' . $longitude . '&destinations=' . $d_latitude . ',' . $d_longitude); */
     /* $data = json_decode($json_resp);
               Log::info('data = ' . print_r($data, true));
     
     
               $distance = $data->rows[0]->elements[0]->distance->value;
     
               $time = $data->rows[0]->elements[0]->duration->value; */
     $settings = Settings::where('key', 'default_distance_unit')->first();
     $unit = $settings->value;
     $distance = get_dist($latitude, $longitude, $d_latitude, $d_longitude);
     Log::info('data = ' . print_r($distance, true));
     if ($unit == 0) {
         $distanceNew = $distance * 0.001;
         /* $setdistance_price = Settings::where('key', 'price_per_unit_distance')->first();
            $price_per_unit_distance = $setdistance_price->value * $distanceNew; */
         if ($distanceNew <= $setbase_distance) {
             $price_per_unit_distance = 0;
         } else {
             $price_per_unit_distance = $setdistance_price->value * ($distanceNew - $setbase_distance);
         }
     } else {
         $distanceNew = $distance * 0.000621371;
         /* $setdistance_price = Settings::where('key', 'price_per_unit_distance')->first();
            $price_per_unit_distance = $setdistance_price->value * $distanceNew; */
         if ($distanceNew <= $setbase_distance) {
             $price_per_unit_distance = 0;
         } else {
             $price_per_unit_distance = $setdistance_price->value * ($distanceNew - $setbase_distance);
         }
     }
     $timeMinutes = $time * 0.0166667;
     /* $settime_price = Settings::where('key', 'price_per_unit_time')->first();
        $price_per_unit_time = $settime_price->value * $timeMinutes; */
     $price_per_unit_time = $settime_price * $timeMinutes;
     $total = 0;
     $base_price = 0;
     if (Input::has('provider')) {
         $pt = ProviderServices::where('provider_id', $provider)->where('type', $type)->first();
         $base_price = $pt->base_price;
         if ($distanceNew <= $setbase_distance) {
             $price_per_unit_distance = 0;
         } else {
             $price_per_unit_distance = $pt->price_per_unit_distance * ($distanceNew - $setbase_distance);
         }
         $total = $base_price + $price_per_unit_distance + $price_per_unit_time;
     } else {
         /* $setbase_price = Settings::where('key', 'base_price')->first();
            $base_price = $setbase_price->value; */
         $base_price = $setbase_price;
         /* $setdistance_price = Settings::where('key', 'price_per_unit_distance')->first();
            $price_per_unit_distance = $setdistance_price->value * $distanceNew; */
         if ($distanceNew <= $setbase_distance) {
             $price_per_unit_distance = 0;
         } else {
             $price_per_unit_distance = $setdistance_price->value * ($distanceNew - $setbase_distance);
         }
         $total = $base_price + $price_per_unit_distance + $price_per_unit_time;
     }
     if ($promo_code) {
         $promosett = Settings::where('key', 'promotional_code_activation')->first();
         $promo_discount = 0;
         $total_amount = $total;
         if ($promosett->value == 1) {
             /* if ($request->promo_code != "") { */
             $promo_code = PromoCodes::where('coupon_code', $promo_code)->first();
             if (isset($promo_code->id)) {
                 $promo_value = $promo_code->value;
                 $promo_type = $promo_code->type;
                 if ($promo_type == 1) {
                     $discount = $total_amount * ($promo_value / 100);
                 } elseif ($promo_type == 2) {
                     $discount = $promo_value;
                 }
                 $promo_discount = $discount;
                 /* } */
                 $total = $total_amount - $promo_discount;
             }
         }
     }
     /* $currency_selected = Keywords::find(5);
        if ($currency_selected->keyword == '$') { */
     if (Config::get('app.generic_keywords.Currency') == '$') {
         $currency_sel = "USD";
     } else {
         /* $currency_sel = $currency_selected->keyword; */
         $currency_sel = Config::get('app.generic_keywords.Currency');
     }
     if ($currency_sel != 'USD') {
         $httpAdapter = new \Ivory\HttpAdapter\FileGetContentsHttpAdapter();
         // Create the Yahoo Finance provider
         $yahooProvider = new \Swap\Provider\YahooFinanceProvider($httpAdapter);
         // Create Swap with the provider
         $swap = new \Swap\Swap($yahooProvider);
         $rate = $swap->quote("USD/" . $currency_sel);
         $rate = json_decode($rate, true);
         Log::info($rate);
         $total = $total * $rate;
     }
     $status = 1;
     /* return Response::json(array('success' => true, 'total' => $currency_selected->keyword . " " . $total)); */
     return Response::json(array('success' => true, 'total' => Config::get('app.generic_keywords.Currency') . " " . sprintf2($total, 2)));
 }
 ?>
                 </td>
                 <td>
                     <?php 
 echo sprintf2($walk->card_payment, 2);
 ?>
                 </td>
                 <td>
                     <?php 
 if ($walk->promo_id !== NULL) {
     $promo = PromoCodes::where('id', $walk->promo_id)->first();
     if ($promo) {
         if ($promo->type == 2) {
             echo sprintf2($promo->value, 2);
         } elseif ($promo->type == 1) {
             echo sprintf2($promo->value * $walk->total / 100, 2);
         } else {
             echo "<span class='badge bg-red'>" . Config::get('app.blank_fiend_val') . "</span>";
         }
     } else {
         echo "<span class='badge bg-red'>" . Config::get('app.blank_fiend_val') . "</span>";
     }
 } else {
     echo "<span class='badge bg-red'>" . Config::get('app.blank_fiend_val') . "</span>";
 }
 ?>
                 </td>
                 <td>
                     <div class="dropdown">
                         <button class="btn btn-flat btn-info dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown">
                             Actions
        // console.log(timevar);
        document.getElementById("time<?php 
    echo $i;
    ?>
").innerHTML = timevar;
    <?php 
    $i++;
    ?>
                        </script>
                    </td>
                    <td><?php 
    echo $status1;
    ?>
</td>
                    <td><?php 
    echo Config::get('app.generic_keywords.Currency') . " " . sprintf2($amount, 2);
    ?>
</td>
                    <td><?php 
    echo $pay_mode;
    ?>
</td>
                    <td><?php 
    echo $pay_status;
    ?>
</td>
                    <td>
                        <?php 
    if ($meta->status == 0) {
        echo "<span class='badge bg-yellow'>In Queue</span>";
    } elseif ($meta->status == 1) {