Esempio n. 1
0
 public function index($market_id = '')
 {
     $setting = new Setting();
     $wallet = new Wallet();
     $m = Market::where('active', 1)->orderBy('id')->first();
     if ($market_id == '') {
         $market_id = $setting->getSetting('default_market', $m->id);
     }
     Session::put('market_id', $market_id);
     $market_default = Market::find($market_id);
     if (!isset($market_default->active) || $market_default->active == 0) {
         //$setting->setSetting('default_market',$m->id);
         return Redirect::to('market/' . $m->id);
     }
     $wallet_from = $market_default->wallet_from;
     $wallet_to = $market_default->wallet_to;
     $from = strtoupper($wallet->getType($wallet_from));
     $to = strtoupper($wallet->getType($wallet_to));
     //get limit amount
     $limit_day = WalletTimeLimitTrade::select('limit_amount')->where('wallet_id', $wallet_to)->where('time_limit', 'per day')->first();
     if (isset($limit_day)) {
         $data['limit_day'] = $limit_day->limit_amount;
     } else {
         $data['limit_day'] = 1000;
     }
     $limit_week = WalletTimeLimitTrade::select('limit_amount')->where('wallet_id', $wallet_to)->where('time_limit', 'per week')->first();
     if (isset($limit_week)) {
         $data['limit_week'] = $limit_week->limit_amount;
     } else {
         $data['limit_week'] = 1000;
     }
     //get amount : day
     $user = Confide::user();
     if (isset($user)) {
         $uid = $user->id;
         $select = "SELECT sum(t.to_value) as sumamount from orders t, market m where m.id=t.market_id and m.wallet_to=" . $wallet_to . " and t.user_id=" . $uid . " and t.created_at='" . date("Y-m-d") . "'";
         $selectsum = DB::select($select);
         $sumamount = $selectsum[0]->sumamount;
         $data['amount_sum_day'] = $sumamount;
     }
     if (!isset($data['amount_sum_day'])) {
         $data['amount_sum_day'] = 0;
     }
     //echo 'aaaaaaaaaaa:'; print_r($data['amount_sum_day']);
     //get name of wallet
     $wallet1 = Wallet::where('id', $wallet_from)->first();
     $wallet2 = Wallet::where('id', $wallet_to)->first();
     $data['market_from'] = $wallet1->name;
     $data['market_to'] = $wallet2->name;
     $data['coinmain'] = $from;
     $data['coinsecond'] = $to;
     //get balance
     $balance = new Balance();
     $data['balance_coinmain'] = sprintf('%.8f', $balance->getBalance($wallet_from, 0));
     $data['balance_coinsecond'] = sprintf('%.8f', $balance->getBalance($wallet_to, 0));
     //get Sell Lowest
     $data['sell_lowest'] = sprintf('%.8f', 0);
     $data['buy_highest'] = sprintf('%.8f', 0);
     $order = new Order();
     $sell_lowest = $order->getSellLowest($market_id);
     $buy_highest = $order->getBuyHighest($market_id);
     if (isset($sell_lowest->price)) {
         $data['sell_lowest'] = sprintf('%.8f', $sell_lowest->price);
     }
     if (isset($buy_highest->price)) {
         $data['buy_highest'] = sprintf('%.8f', $buy_highest->price);
     }
     //fee_buy, fee_sell
     $fee_trade = new FeeTrade();
     $fee = $fee_trade->getFeeTrade($market_id);
     $data['fee_buy'] = $fee['fee_buy'];
     $data['fee_sell'] = $fee['fee_sell'];
     //get list orders
     $num_transaction_display = $setting->getSetting('num_transaction_display', 0);
     $list_sell_orders = $order->getOrders($market_id, 'sell', $num_transaction_display);
     $list_buy_orders = $order->getOrders($market_id, 'buy', $num_transaction_display);
     $data['sell_orders'] = $list_sell_orders;
     $data['buy_orders'] = $list_buy_orders;
     //get all history
     $trade_history = Trade::where('market_id', '=', $market_id)->orderBy('created_at', 'desc')->take($num_transaction_display)->get();
     $data['trade_history'] = $trade_history;
     $data['market_id'] = $market_id;
     $current_orders_user = $order->getCurrentOrdersUser($market_id);
     if ($current_orders_user) {
         $data['current_orders_user'] = $current_orders_user;
     }
     $trade = new Trade();
     $datachart = $trade->getDatasChart($market_id, '6 hour');
     $news = Post::where('type', 'news')->take(5)->orderby('created_at', 'desc')->get();
     $data['news'] = $news;
     //price
     $data_price = $trade->getBlockPrice($market_id);
     $data["get_prices"] = $data_price['get_prices'];
     $data['lastest_price'] = $data_price['lastest_price'];
     //limit trade amount
     $limit_trade = WalletLimitTrade::where('wallet_id', $wallet_from)->first();
     if ($limit_trade) {
         $data['limit_trade'] = $limit_trade->toArray();
     } else {
         $data['limit_trade'] = array('min_amount' => 0.0001, 'max_amount' => 1000);
     }
     //get data for block statistic
     $btc_wallet = Wallet::where('type', 'BTC')->first();
     $ltc_wallet = Wallet::where('type', 'LTC')->first();
     $btc_markets = array();
     $ltc_markets = array();
     //btc market on sidebar left
     $all_market_btc = array();
     if (isset($btc_wallet->id)) {
         $btc_markets = Market::leftJoin('wallets', 'market.wallet_from', '=', 'wallets.id')->select('market.*', 'wallets.name', 'wallets.type')->where('wallet_to', $btc_wallet->id)->orderby('wallets.type')->get();
         $btc_datainfo = array();
         foreach ($btc_markets as $value) {
             $all_market_btc[] = $value->id;
             $btc_datainfo[$value->id] = Trade::where('market_id', $value->id)->orderby('created_at', 'desc')->take(2)->get()->toArray();
             //      	$total_btc = DB::table('trade_history')->select(DB::raw('SUM( amount * price ) AS total'))
             //                  ->where('market_id', '=', $value->id)->first();
             //              //echo "<pre>total_btc: "; print_r($total_btc); echo "</pre>";
             //              //echo "<pre>getQueryLog: ".dd(DB::getQueryLog())."</pre>";
             // if(isset($total_btc->total))
             // 	$ltc_datainfo[$value->id]['total'] = $total_btc->total;
             $select = "SELECT SUM( amount * price ) AS total FROM trade_history Where `market_id`='" . $value->id . "' GROUP BY market_id";
             $total_btc = DB::select($select);
             if (isset($total_btc[0])) {
                 $btc_datainfo[$value->id]['total'] = $total_btc[0]->total;
             } else {
                 $btc_datainfo[$value->id]['total'] = 0;
             }
         }
         $data['btc_datainfo'] = $btc_datainfo;
     }
     //ltc market on sidebar left
     $all_market_ltc = array();
     if (isset($ltc_wallet->id)) {
         $ltc_markets = Market::leftJoin('wallets', 'market.wallet_from', '=', 'wallets.id')->select('market.*', 'wallets.name', 'wallets.type')->where('wallet_to', $ltc_wallet->id)->orderby('wallets.type')->get();
         $ltc_datainfo = array();
         foreach ($ltc_markets as $value) {
             $all_market_ltc[] = $value->id;
             $ltc_datainfo[$value->id] = Trade::where('market_id', $value->id)->orderby('created_at', 'desc')->take(2)->get()->toArray();
             // $total_ltc = DB::table('trade_history')->select(DB::raw('SUM( amount * price ) AS total'))
             //                  ->where('market_id', '=', $value->id)->first();
             // if(isset($total_ltc->total))
             // 	$ltc_datainfo[$value->id]['total'] = $total_ltc->total;
             $select = "SELECT SUM( amount * price ) AS total FROM trade_history Where `market_id`='" . $value->id . "' GROUP BY market_id";
             $total_ltc = DB::select($select);
             if (isset($total_ltc[0])) {
                 $ltc_datainfo[$value->id]['total'] = $total_ltc[0]->total;
             } else {
                 $ltc_datainfo[$value->id]['total'] = 0;
             }
         }
         $data['ltc_datainfo'] = $ltc_datainfo;
     }
     $data['btc_markets'] = $btc_markets;
     $data['ltc_markets'] = $ltc_markets;
     $date = date("Y-m-d H:i:s", strtotime(" -24 hour"));
     //echo "+24 hours: ".$date;
     if (!empty($all_market_btc)) {
         $data['statistic_btc'] = DB::table('trade_history')->select(DB::raw('COUNT(*) as number_trade,SUM( amount * price ) AS total'))->where('created_at', '>=', $date)->whereIn('market_id', $all_market_btc)->first();
     }
     if (!empty($all_market_ltc)) {
         $data['statistic_ltc'] = DB::table('trade_history')->select(DB::raw('COUNT(*) as number_trade,SUM( amount * price ) AS total'))->where('created_at', '>=', $date)->whereIn('market_id', $all_market_ltc)->first();
     }
     $data['wallets'] = Wallet::orderby('type')->get();
     return View::make('home', $data);
 }
 public function routePage($page = '', $pager_page = '')
 {
     $markets = Market::where('active', 1)->get();
     $market_wallet = array();
     foreach ($markets as $market) {
         $market_wallet[$market->id] = $market->getWalletType($market->id);
     }
     $data['markets'] = $market_wallet;
     switch ($page) {
         case 'fee':
             $data['fee_trades'] = FeeTrade::leftJoin('market', 'fee_trade.market_id', '=', 'market.id')->leftJoin('wallets', 'market.wallet_from', '=', 'wallets.id')->select('fee_trade.*', 'market.wallet_from', 'wallets.name', 'wallets.type')->orderby('wallets.name', 'asc')->get();
             //echo "<pre>fee_trades: "; print_r($fee_trades); echo "</pre>";
             //echo "<pre>markets: "; print_r($markets); echo "</pre>";exit;
             return View::make('admin.setting_fee', $data);
             break;
         case 'fee-withdraw':
             $data['fee_withdraws'] = FeeWithdraw::leftjoin('wallets', 'fee_withdraw.wallet_id', '=', 'wallets.id')->select('fee_withdraw.*', 'wallets.type', 'wallets.name')->orderby('wallets.type')->get();
             return View::make('admin.setting_fee_withdraw', $data);
             break;
         case 'limit-trade':
             $record_per_page = 15;
             $total = WalletLimitTrade::count();
             if ($pager_page == '') {
                 $pager_page = 1;
             }
             $data['total_pages'] = ceil($total / $record_per_page);
             //15 user per page
             $data['cur_page'] = $pager_page;
             $offset_start = ($pager_page - 1) * $record_per_page;
             $data['wallets'] = Wallet::orderby('type')->get();
             $data['limit_trades'] = WalletLimitTrade::leftjoin('wallets', 'wallet_limittrade.wallet_id', '=', 'wallets.id')->select('wallet_limittrade.*', 'wallets.type as wallet_type', 'wallets.name as wallet_name')->skip($offset_start)->take($record_per_page)->orderby('wallet_type')->get();
             return View::make('admin.limittrade.setting_limittrade', $data);
             break;
             //add newbie
         //add newbie
         case 'time-limit-trade':
             $record_per_page = 15;
             $total = WalletTimeLimitTrade::count();
             if ($pager_page == '') {
                 $pager_page = 1;
             }
             $data['total_pages'] = ceil($total / $record_per_page);
             //15 user per page
             $data['cur_page'] = $pager_page;
             $offset_start = ($pager_page - 1) * $record_per_page;
             $data['wallets'] = Wallet::orderby('type')->get();
             $data['limit_trades'] = WalletTimeLimitTrade::leftjoin('wallets', 'wallet_timelimittrade.wallet_id', '=', 'wallets.id')->select('wallet_timelimittrade.*', 'wallets.type as wallet_type', 'wallets.name as wallet_name')->skip($offset_start)->take($record_per_page)->orderby('wallet_type')->get();
             return View::make('admin.limittrade.setting_timelimittrade', $data);
             break;
         case 'statistic-coin-exchanged':
             $select = "SELECT mk.wallet_from, mk.wallet_to, sum(amount) as total_amount from trade_history a left join market mk on a.market_id=mk.id";
             $select_maincoin = "SELECT mk.wallet_from, mk.wallet_to, sum(amount*price) as total_amount from trade_history a left join market mk on a.market_id=mk.id";
             $where = '';
             if (isset($_GET['filter_time']) && $_GET['filter_time'] != '') {
                 switch ($_GET['filter_time']) {
                     case 'hourly':
                         $hourly = date('Y-m-d H:i:s', strtotime('-1 hour'));
                         $where = $where == '' ? " Where a.created_at>='" . $hourly . "'" : $where . " Where a.created_at>='" . $hourly . "'";
                         break;
                     case 'daily':
                         $daily = date('Y-m-d H:i:s', strtotime('-24 hour'));
                         $where = $where == '' ? " Where a.created_at>='" . $daily . "'" : $where . " Where a.created_at>='" . $daily . "'";
                         break;
                     case 'weekly':
                         $thisweek = date('Y-m-d', strtotime('-7 day'));
                         $where = $where == '' ? " Where a.created_at>='" . $thisweek . "'" : $where . " Where a.created_at>='" . $thisweek . "'";
                         break;
                     case 'monthly':
                         $thismonth = date('Y-m-1', strtotime('-1 month'));
                         $where = $where == '' ? " Where a.created_at>='" . $thismonth . "'" : $where . " Where a.created_at>='" . $thismonth . "'";
                         break;
                 }
             }
             $select .= " " . $where . " group by mk.wallet_from";
             $coins_exchanged = DB::select($select);
             $data['coins_exchanged'] = $coins_exchanged;
             $select_maincoin .= " " . $where . " group by mk.wallet_to";
             $maincoins_exchanged = DB::select($select_maincoin);
             $data['maincoins_exchanged'] = $maincoins_exchanged;
             // echo "<pre>"; print_r($fees); echo "</pre>";
             $wallets_temp = Wallet::get();
             $wallets = array();
             foreach ($wallets_temp as $wallet) {
                 $wallets[$wallet->id] = $wallet;
             }
             $data['wallets'] = $wallets;
             return View::make('admin.statistics.statistic_coin_exchanged', $data);
             break;
         case 'statistic-fees':
             $select = "SELECT mk.wallet_from, mk.wallet_to, sum(fee_sell) as fee_sell, sum(fee_buy) as fee_buy from trade_history a left join market mk on a.market_id=mk.id";
             $where = '';
             if (isset($_GET['filter_time']) && $_GET['filter_time'] != '') {
                 switch ($_GET['filter_time']) {
                     case 'hourly':
                         $hourly = date('Y-m-d H:i:s', strtotime('-1 hour'));
                         $where = $where == '' ? " Where a.created_at>='" . $hourly . "'" : $where . " Where a.created_at>='" . $hourly . "'";
                         break;
                     case 'daily':
                         $daily = date('Y-m-d H:i:s', strtotime('-24 hour'));
                         $where = $where == '' ? " Where a.created_at>='" . $daily . "'" : $where . " Where a.created_at>='" . $daily . "'";
                         break;
                     case 'weekly':
                         $thisweek = date('Y-m-d', strtotime('-7 day'));
                         $where = $where == '' ? " Where a.created_at>='" . $thisweek . "'" : $where . " Where a.created_at>='" . $thisweek . "'";
                         break;
                     case 'monthly':
                         $thismonth = date('Y-m-1', strtotime('-1 month'));
                         $where = $where == '' ? " Where a.created_at>='" . $thismonth . "'" : $where . " Where a.created_at>='" . $thismonth . "'";
                         break;
                 }
             }
             $select .= " " . $where . " group by a.market_id order by `created_at` desc";
             $fees = DB::select($select);
             $data['fees'] = $fees;
             // echo "<pre>"; print_r($fees); echo "</pre>";
             $wallets_temp = Wallet::get();
             $wallets = array();
             foreach ($wallets_temp as $wallet) {
                 $wallets[$wallet->id] = $wallet;
             }
             $data['wallets'] = $wallets;
             return View::make('admin.statistics.statistic_fees', $data);
             break;
         case 'statistic-fee-withdraw':
             $select = "SELECT w.type, w.name, sum(fee_amount) as total_fee from withdraws a left join wallets w on a.wallet_id=w.id";
             $where = '';
             if (isset($_GET['filter_time']) && $_GET['filter_time'] != '') {
                 switch ($_GET['filter_time']) {
                     case 'hourly':
                         $hourly = date('Y-m-d H:i:s', strtotime('-1 hour'));
                         $where = $where == '' ? " Where a.created_at>='" . $hourly . "'" : $where . " Where a.created_at>='" . $hourly . "'";
                         break;
                     case 'daily':
                         $daily = date('Y-m-d H:i:s', strtotime('-24 hour'));
                         $where = $where == '' ? " Where a.created_at>='" . $daily . "'" : $where . " Where a.created_at>='" . $daily . "'";
                         break;
                     case 'weekly':
                         $thisweek = date('Y-m-d', strtotime('-7 day'));
                         $where = $where == '' ? " Where a.created_at>='" . $thisweek . "'" : $where . " Where a.created_at>='" . $thisweek . "'";
                         break;
                     case 'monthly':
                         $thismonth = date('Y-m-1', strtotime('-1 month'));
                         $where = $where == '' ? " Where a.created_at>='" . $thismonth . "'" : $where . " Where a.created_at>='" . $thismonth . "'";
                         break;
                 }
             }
             $select .= " " . $where . " group by a.wallet_id";
             $withdraw_fees = DB::select($select);
             $data['withdraw_fees'] = $withdraw_fees;
             return View::make('admin.statistics.statistic_fee_withdraw', $data);
             break;
         case 'add-page':
             $data['type'] = 'page';
             return View::make('admin.pages.add_post', $data);
             break;
         case 'add-news':
             $data['type'] = 'news';
             return View::make('admin.pages.add_post', $data);
             break;
         case 'all-page':
             $data['type'] = 'page';
             $record_per_page = 15;
             $total = Post::where('type', $data['type'])->count();
             if ($pager_page == '') {
                 $pager_page = 1;
             }
             $data['total_pages'] = ceil($total / $record_per_page);
             //15 user per page
             $data['cur_page'] = $pager_page;
             $offset_start = ($pager_page - 1) * $record_per_page;
             $posts = Post::where('type', $data['type'])->skip($offset_start)->take($record_per_page)->get();
             $data['posts'] = $posts;
             return View::make('admin.pages.all_posts', $data);
             break;
         case 'all-news':
             $data['type'] = 'news';
             $record_per_page = 15;
             $total = Post::where('type', $data['type'])->count();
             if ($pager_page == '') {
                 $pager_page = 1;
             }
             $data['total_pages'] = ceil($total / $record_per_page);
             //15 user per page
             $data['cur_page'] = $pager_page;
             $offset_start = ($pager_page - 1) * $record_per_page;
             $posts = Post::where('type', $data['type'])->skip($offset_start)->take($record_per_page)->get();
             $data['posts'] = $posts;
             return View::make('admin.pages.all_posts', $data);
             break;
         case 'users':
             $record_per_page = 15;
             $total_users = User::count();
             if ($pager_page == '') {
                 $pager_page = 1;
             }
             $data['total_pages'] = ceil($total_users / $record_per_page);
             //15 user per page
             $data['cur_page'] = $pager_page;
             $offset_start = ($pager_page - 1) * $record_per_page;
             //$offset_end = ($pager_page*$record_per_page)-1;
             $users = User::skip($offset_start)->take($record_per_page)->get()->toArray();
             foreach ($users as $key => $value) {
                 $user = USer::find($value['id']);
                 $users[$key]['roles'] = $user->roles->toArray();
                 //echo "<pre>roles:"; print_r($user->roles->toArray()); echo "</pre>";
             }
             //echo "<pre>"; print_r($users); echo "</pre>";
             $roles = Role::get();
             $data['users'] = $users;
             $data['roles'] = $roles;
             return View::make('admin.user.manage_users', $data);
             break;
         case 'orders':
             $record_per_page = 15;
             if ($pager_page == '') {
                 $pager_page = 1;
             }
             $data['cur_page'] = $pager_page;
             $offset_start = ($pager_page - 1) * $record_per_page;
             //$offset_end = ($pager_page*$record_per_page)-1;
             $select = "select a.*, b.wallet_from as `from`, b.wallet_to as `to`, c.username from orders a left join market b on a.market_id=b.id left join users c on a.user_id=c.id";
             $select_count = "select count(*) as total from orders a";
             $where = '';
             if (isset($_GET['do_filter'])) {
                 if ($where == '') {
                     if (!empty($_GET['market'])) {
                         $where = $where == '' ? " Where a.market_id='" . $_GET['market'] . "'" : $where . " AND a.market_id='" . $_GET['market'] . "'";
                     }
                 }
                 if ($_GET['status'] != '') {
                     $where = $where == '' ? " Where a.status='" . $_GET['status'] . "'" : $where . " AND a.status='" . $_GET['status'] . "'";
                 }
                 if ($_GET['type'] != '') {
                     $where = $where == '' ? " Where a.type='" . $_GET['type'] . "'" : $where . " AND a.type='" . $_GET['type'] . "'";
                 }
             }
             $select_count = $select_count . " " . $where . " order by `created_at` desc";
             $total_records = DB::select($select_count);
             //echo "<pre>total_records: "; print_r($total_records); echo "</pre>"; exit;
             $data['total_pages'] = ceil($total_records[0]->total / $record_per_page);
             $select .= " " . $where . " order by `created_at` desc limit " . $offset_start . "," . $record_per_page;
             $ordershistory = DB::select($select);
             $data['ordershistories'] = $ordershistory;
             return View::make('admin.orders', $data);
             break;
         case 'trade-histories':
             $record_per_page = 15;
             if ($pager_page == '') {
                 $pager_page = 1;
             }
             $data['cur_page'] = $pager_page;
             $offset_start = ($pager_page - 1) * $record_per_page;
             $select = "select a.*, b.wallet_from as `from`, b.wallet_to as `to`,c.username as seller, d.username as buyer from trade_history a left join market b on a.market_id=b.id left join users c on a.seller_id=c.id left join users d on a.buyer_id=d.id";
             $select_count = "select count(*) as total from trade_history a";
             $where = '';
             if (isset($_GET['do_filter'])) {
                 if ($where == '') {
                     if (!empty($_GET['market'])) {
                         $where = $where == '' ? " Where a.market_id='" . $_GET['market'] . "'" : $where . " AND a.market_id='" . $_GET['market'] . "'";
                     }
                 }
                 if ($_GET['type'] != '') {
                     $where = $where == '' ? " Where a.type='" . $_GET['type'] . "'" : $where . " AND a.type='" . $_GET['type'] . "'";
                 }
                 if ($_GET['time'] != '') {
                     switch ($_GET['time']) {
                         case 'today':
                             $where = $where == '' ? " Where a.created_at>='" . date("Y-m-d") . "'" : $where . " Where a.created_at>='" . date("Y-m-d") . "'";
                             break;
                         case 'thisweek':
                             $thisweek = date('Y-m-d', strtotime('this week'));
                             $where = $where == '' ? " Where a.created_at>='" . $thisweek . "'" : $where . " Where a.created_at>='" . $thisweek . "'";
                             break;
                         case 'thismonth':
                             $thismonth = date('Y-m-1', strtotime('this month'));
                             $where = $where == '' ? " Where a.created_at>='" . $thismonth . "'" : $where . " Where a.created_at>='" . $thismonth . "'";
                             break;
                     }
                 }
             }
             $select_count = $select_count . " " . $where . " order by `created_at` desc";
             $total_records = DB::select($select_count);
             //echo "<pre>total_records: "; print_r($total_records); echo "</pre>"; exit;
             $data['total_pages'] = ceil($total_records[0]->total / $record_per_page);
             $select .= " " . $where . " order by `created_at` desc limit " . $offset_start . "," . $record_per_page;
             $trades = DB::select($select);
             $data['tradehistories'] = $trades;
             return View::make('admin.trade_histories', $data);
             break;
         case 'coins-voting':
             $coinvotes = DB::table('coin_votes')->get();
             $wallet = Wallet::where('type', 'BTC')->first();
             if (isset($wallet->id)) {
                 try {
                     $wallet->connectJsonRPCclient($wallet->wallet_username, $wallet->wallet_password, $wallet->wallet_ip, $wallet->port);
                     foreach ($coinvotes as $key => $value) {
                         $num_vote = Vote::where('coinvote_id', '=', $value->id)->count();
                         //echo "<pre>getreceivedbyaccount"; print_r($wallet->getReceivedByAddress($value->btc_address)); echo "</pre>";//$value->label_address
                         $btc_payment = $wallet->getReceivedByAddress($value->btc_address);
                         //'12X9jVe4S8pAqJ7EoKN7B4YwMQpzfgArtX'
                         $num_payment = floor($btc_payment / 0.0001);
                         //echo "btc_payment: ".$btc_payment;
                         //echo "<br>num_payment: ".$num_payment;
                         $coinvotes[$key]->balance = $num_payment;
                         $coinvotes[$key]->num_vote = $num_vote + $num_payment;
                     }
                 } catch (Exception $e) {
                     $data['error_message'] = "Not connect to this";
                     //'Caught exception: '.$e->getMessage()."\n";  //
                 }
                 //echo "<pre>coinvotes"; print_r($coinvotes); echo "</pre>";
                 $data['coinvotes'] = $coinvotes;
             } else {
                 $data['not_wallet'] = "Please add BTC wallet before add the vote coin.";
             }
             return View::make('admin.coins_voting', $data);
             break;
         case 'funds':
             $wallets = Wallet::leftjoin('fee_withdraw', 'fee_withdraw.wallet_id', '=', 'wallets.id')->orderby('type')->get();
             $balances = array();
             $fee_withdraws = array();
             foreach ($wallets as $wallet) {
                 try {
                     $wallet->connectJsonRPCclient($wallet->wallet_username, $wallet->wallet_password, $wallet->wallet_ip, $wallet->port);
                     $balances[$wallet->id] = $wallet->getBalance();
                     $fee_withdraws[$wallet->id] = $wallet->getTxFee();
                     UserAddressDeposit::insert(array('user_id' => $user->id, 'wallet_id' => $wallet->id, 'addr_deposit' => $address));
                 } catch (Exception $e) {
                     $data['error_message'] = 'Caught exception: ' . $e->getMessage() . "\n";
                     //"Not connect to this wallet";//'Caught exception: '.$e->getMessage()."\n";
                 }
             }
             $data['wallets'] = $wallets;
             $data['balances'] = $balances;
             $data['fee_withdraws'] = $fee_withdraws;
             //echo "<pre>fee_withdraws"; print_r($fee_withdraws); echo "</pre>";
             return View::make('admin.funds', $data);
             break;
         case 'withdraws-queue':
             $record_per_page = 20;
             if ($pager_page == '') {
                 $pager_page = 1;
             }
             $data['cur_page'] = $pager_page;
             $offset_start = ($pager_page - 1) * $record_per_page;
             if (isset($_GET['do_filter'])) {
                 $withdraws = Withdraw::leftjoin('users', 'users.id', '=', 'withdraws.user_id');
                 if ($_GET['wallet_id'] != '') {
                     $withdraws->where('wallet_id', $_GET['wallet_id']);
                 }
                 if ($_GET['status'] != '') {
                     $withdraws->where('status', $_GET['status']);
                 }
                 if ($_GET['username'] != '') {
                     $withdraws->where('users.username', $_GET['username']);
                 }
                 $withdraws->select('withdraws.*', 'users.username', 'users.id as user_id');
             } else {
                 $withdraws = Withdraw::leftjoin('users', 'users.id', '=', 'withdraws.user_id')->select('withdraws.*', 'users.username');
             }
             $total_records = $withdraws->get();
             //echo "<br>total_records: ".count($total_records);
             $data['total_pages'] = ceil(count($total_records) / $record_per_page);
             //echo "<br>total_records: ".$data['total_pages'];
             $withdraws = $withdraws->skip($offset_start)->take($record_per_page)->orderby("created_at", "desc")->get();
             $wallets = Wallet::orderby('type')->get()->toArray();
             $new_wallet = array();
             foreach ($wallets as $key => $value) {
                 $new_wallet[$value['id']] = $value;
             }
             $data['wallets'] = $new_wallet;
             $data['withdraws'] = $withdraws;
             $data['users'] = User::orderBy('username')->get();
             return View::make('admin.withdraws_queue', $data);
             break;
         case 'deposits-queue':
             $record_per_page = 20;
             if ($pager_page == '') {
                 $pager_page = 1;
             }
             $data['cur_page'] = $pager_page;
             $offset_start = ($pager_page - 1) * $record_per_page;
             if (isset($_GET['do_filter'])) {
                 $deposits = Deposit::leftjoin('users', 'users.id', '=', 'deposits.user_id');
                 if ($_GET['wallet_id'] != '') {
                     $deposits->where('wallet_id', $_GET['wallet_id']);
                 }
                 if ($_GET['status'] != '') {
                     $deposits->where('paid', $_GET['status']);
                 }
                 if ($_GET['username'] != '') {
                     $deposits->where('users.username', $_GET['username']);
                 }
                 $deposits->select('deposits.*', 'users.username', 'users.id as user_id');
             } else {
                 $deposits = Deposit::leftjoin('users', 'users.id', '=', 'deposits.user_id')->select('deposits.*', 'users.username');
             }
             $total_records = $deposits->get();
             //echo "<br>total_records: ".count($total_records);
             $data['total_pages'] = ceil(count($total_records) / $record_per_page);
             //echo "<br>total_records: ".$data['total_pages'];
             $deposits = $deposits->skip($offset_start)->take($record_per_page)->orderby("created_at", "desc")->get();
             $wallets = Wallet::orderby('type')->get()->toArray();
             $new_wallet = array();
             foreach ($wallets as $key => $value) {
                 $new_wallet[$value['id']] = $value;
             }
             $data['wallets'] = $new_wallet;
             $data['deposits'] = $deposits;
             $data['users'] = User::orderBy('username')->get();
             return View::make('admin.deposits_queue', $data);
             break;
         case 'wallets':
             $record_per_page = 15;
             $total_users = Wallet::count();
             if ($pager_page == '') {
                 $pager_page = 1;
             }
             $data['total_pages'] = ceil($total_users / $record_per_page);
             //15 user per page
             $data['cur_page'] = $pager_page;
             $offset_start = ($pager_page - 1) * $record_per_page;
             $wallets = Wallet::skip($offset_start)->take($record_per_page)->orderby('name')->get();
             $data['wallets'] = $wallets;
             return View::make('admin.wallet.manage_wallets', $data);
             break;
         case 'markets':
             $record_per_page = 15;
             $total_users = Market::count();
             if ($pager_page == '') {
                 $pager_page = 1;
             }
             $data['total_pages'] = ceil($total_users / $record_per_page);
             //15 user per page
             $data['cur_page'] = $pager_page;
             $offset_start = ($pager_page - 1) * $record_per_page;
             $markets = Market::skip($offset_start)->take($record_per_page)->get();
             $data['markets'] = $markets;
             $wallets_temp = Wallet::orderby('type')->get();
             $wallets = array();
             foreach ($wallets_temp as $wallet) {
                 $wallets[$wallet->id] = $wallet;
             }
             $data['wallets'] = $wallets;
             return View::make('admin.manage_markets', $data);
             break;
         case 'balance-wallets':
             $record_per_page = 15;
             $total_users = Wallet::count();
             if ($pager_page == '') {
                 $pager_page = 1;
             }
             $data['total_pages'] = ceil($total_users / $record_per_page);
             //15 user per page
             $data['cur_page'] = $pager_page;
             $offset_start = ($pager_page - 1) * $record_per_page;
             $wallets = Wallet::skip($offset_start)->take($record_per_page)->orderby('name')->get();
             $amount_transaction = array();
             $balances = array();
             foreach ($wallets as $wallet) {
                 //get total deposit
                 $total_deposit = Deposit::where('wallet_id', $wallet->id)->where('paid', 1)->sum('amount');
                 $total_withdraw = Withdraw::where('wallet_id', $wallet->id)->where('status', 1)->sum('receive_amount');
                 $amount_transaction[$wallet->id] = array('total_amount_deposit' => $total_deposit, 'total_amount_withdraw' => $total_withdraw);
                 try {
                     $wallet->connectJsonRPCclient($wallet->wallet_username, $wallet->wallet_password, $wallet->wallet_ip, $wallet->port);
                     $balances[$wallet->id] = $wallet->getBalance();
                 } catch (Exception $e) {
                     $balances[$wallet->id] = Lang::get('messages.cannot_connect');
                 }
             }
             $data['wallets'] = $wallets;
             $data['amount_transaction'] = $amount_transaction;
             $data['balances'] = $balances;
             return View::make('admin.wallet.manage_wallets_balance', $data);
             break;
         case "login-histories":
             $record_per_page = 15;
             if ($pager_page == '') {
                 $pager_page = 1;
             }
             $data['cur_page'] = $pager_page;
             $offset_start = ($pager_page - 1) * $record_per_page;
             //$offset_end = ($pager_page*$record_per_page)-1;
             $select = "select a.*, b.username from login_history a left join users b on a.user_id=b.id";
             $select_count = "select count(*) as total from login_history as a";
             $where = '';
             if (isset($_GET['do_filter'])) {
                 if ($where == '') {
                     if (!empty($_GET['user'])) {
                         $where = $where == '' ? " Where a.user_id='" . $_GET['user'] . "'" : $where . " AND a.user='******'user'] . "'";
                     }
                 }
             }
             $select_count = $select_count . " " . $where;
             $total_records = DB::select($select_count);
             //echo "<pre>total_records: "; print_r($total_records); echo "</pre>"; exit;
             $data['total_pages'] = ceil($total_records[0]->total / $record_per_page);
             $select .= " " . $where . " order by `date` desc limit " . $offset_start . "," . $record_per_page;
             $login_histories = DB::select($select);
             $data['login_histories'] = $login_histories;
             $users = User::orderby('username')->get();
             $data['users'] = $users;
             return View::make('admin.user.login_histories', $data);
             break;
         case 'method-deposit':
             $record_per_page = 15;
             $total_users = MethodDepositCurrency::count();
             if ($pager_page == '') {
                 $pager_page = 1;
             }
             $data['total_pages'] = ceil($total_users / $record_per_page);
             //15 user per page
             $data['cur_page'] = $pager_page;
             $offset_start = ($pager_page - 1) * $record_per_page;
             $MethodDepositCurrency = MethodDepositCurrency::skip($offset_start)->take($record_per_page)->get();
             $data['MethodDepositCurrency'] = $MethodDepositCurrency;
             return View::make('admin.method-deposit-currency.manage_method_deposit', $data);
             break;
         case 'method-withdraw':
             $record_per_page = 15;
             $total_users = MethodWithdrawCurrency::count();
             if ($pager_page == '') {
                 $pager_page = 1;
             }
             $data['total_pages'] = ceil($total_users / $record_per_page);
             //15 user per page
             $data['cur_page'] = $pager_page;
             $offset_start = ($pager_page - 1) * $record_per_page;
             $MethodWithdrawCurrency = MethodWithdrawCurrency::skip($offset_start)->take($record_per_page)->get();
             $data['MethodWithdrawCurrency'] = $MethodWithdrawCurrency;
             return View::make('admin.method-withdraw-currency.manage_method_withdraw', $data);
             break;
         default:
             $setting = new Setting();
             //$data['bg_color']=$setting->getSetting('bg_color','');
             $data['site_mode'] = $setting->getSetting('site_mode', 0);
             //$data['bg_file']=$setting->getSetting('bg_file','');
             $data['disable_withdraw'] = $setting->getSetting('disable_withdraw', 0);
             $data['recaptcha_publickey'] = $setting->getSetting('recaptcha_publickey', '');
             $data['recaptcha_privatekey'] = $setting->getSetting('recaptcha_privatekey', '');
             $data['amount_btc_per_vote'] = $setting->getSetting('amount_btc_per_vote', 0.0001);
             //pusher app
             $data['pusher_app_id'] = $setting->getSetting('pusher_app_id', '');
             $data['pusher_app_key'] = $setting->getSetting('pusher_app_key', '');
             $data['pusher_app_secret'] = $setting->getSetting('pusher_app_secret', '');
             //default_market
             $m_default = Market::where('active', 1)->orderBy('id')->first();
             $market_default_id = isset($m_default->id) ? $m_default->id : 0;
             $data['default_market'] = $setting->getSetting('default_market', $market_default_id);
             //setting points
             $data['disable_points'] = $setting->getSetting('disable_points', 0);
             $data['point_per_btc'] = $setting->getSetting('point_per_btc', 1);
             $data['percent_point_reward_trade'] = $setting->getSetting('percent_point_reward_trade', 0);
             $data['percent_point_reward_referred_trade'] = $setting->getSetting('percent_point_reward_referred_trade', 0);
             $data['max_amount_funds'] = $setting->getSetting('max_amount_funds', 1000);
             //echo "<pre>data: "; print_r($data); echo "</pre>"; exit;
             return View::make('admin.setting', $data);
             break;
     }
 }