public function deposit()
 {
     //retrieve POST value
     $param = Input::only('credits', 'account_id');
     $rules = array('credits' => 'required|numeric|min:1,max:1000000', 'account_id' => 'exists:acl_users,id');
     $messages = array('buyer_id.exists' => 'Buyer id is not valid.', 'merchant_id.exists' => 'Merchant id is not valid');
     $validator = Validator::make($param, $rules, $messages);
     if ($validator->passes()) {
         $retrieve = Wallet::where('account_id', $param['account_id'])->first();
         $credits = array('account_id' => $param['account_id'], 'credits' => $param['credits']);
         if (!empty($retrieve)) {
             try {
                 $update = $retrieve->increment('credits', $param['credits']);
                 if ($update == 1) {
                     $fundin = array('wallet_id' => $retrieve->id, 'onbehalf' => Auth::user()->id, 'credits' => $param['credits'], 'description' => 'Deposit credits', 'fundtype' => 'fundin');
                     $funds = Fundinout::create($fundin);
                 }
             } catch (Exception $e) {
                 return false;
             }
         } else {
             $add_credits = Wallet::create($credits);
             $fundin = array('wallet_id' => $add_credits->id, 'onbehalf' => Auth::user()->id, 'credits' => $param['credits'], 'description' => 'Deposit credits', 'fundtype' => 'fundin');
             $funds = Fundinout::create($fundin);
         }
         $message = 'Credit has been successfully added.';
         return Redirect::action('roulette.index')->with('success', $message);
     } else {
         $messages = $validator->messages();
         return Redirect::action('roulette.index')->with('error', $messages->all());
     }
 }
 public function redeem()
 {
     if (ACL::checkUserPermission('reports.redeem') == false) {
         return Redirect::action('dashboard');
     }
     $funout = Fundinout::with('wallet', 'wallet.playerdetails', 'operator')->where('fundtype', 'fundout')->get();
     $title = Lang::get('Reedemed Credits Report');
     $data = array('acl' => ACL::buildACL(), 'depositlist' => $funout, 'title' => $title);
     return View::make('reports/withdraw', $data);
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     if (ACL::checkUserPermission('bet.roulette') == false) {
         return Redirect::action('dashboard');
     }
     $param = Input::only('bettype', 'betnumber', 'amount', 'game_id');
     $retrieve = Wallet::where('account_id', Auth::user()->id)->first();
     $bet_type = array('straight', 'split', 'line', 'square', 'basket', 'doublestreet');
     if ($retrieve->credits >= $param['amount']) {
         if (Input::has('betnumber')) {
             if (count($param['betnumber']) >= 0 && count($param['betnumber']) <= 6) {
                 $retrieve = Wallet::where('account_id', Auth::user()->id)->first();
                 $index = count($param['betnumber']) - 1;
                 try {
                     $update = $retrieve->decrement('credits', (double) $param['amount']);
                     $fundinout = array('wallet_id' => $retrieve->id, 'onbehalf' => Auth::user()->id, 'credits' => $param['amount'], 'description' => 'Bet on Roulette amount of $' . (double) $param['amount'], 'fundtype' => 'bet');
                     $fundout = Fundinout::create($fundinout);
                     $bet = array('player_id' => Auth::user()->id, 'channel_id' => $param['game_id'], 'bet_number' => implode(',', $param['betnumber']), 'bet_amount' => $param['amount'], 'bet_type' => $bet_type[$index]);
                     Gamebets::create($bet);
                     $message = 'Bet has been successfully place.';
                     return Redirect::action('bet.roulette')->with('success', $message);
                 } catch (Exception $e) {
                     return false;
                 }
             } else {
                 return Redirect::action('bet.roulette')->with('error', 'You can only place maximum of 6 number.');
             }
         }
         if (Input::has('bettype')) {
             $param = Input::only('bettype', 'amount', 'game_id');
             $retrieve = Wallet::where('account_id', Auth::user()->id)->first();
             try {
                 $update = $retrieve->decrement('credits', (double) $param['amount']);
                 $fundinout = array('wallet_id' => $retrieve->id, 'onbehalf' => Auth::user()->id, 'credits' => $param['amount'], 'description' => 'Bet on Roulette amount of $' . (double) $param['amount'], 'fundtype' => 'bet');
                 $fundout = Fundinout::create($fundinout);
                 $bet = array('player_id' => Auth::user()->id, 'channel_id' => $param['game_id'], 'bet_number' => $param['bettype'], 'bet_amount' => $param['amount'], 'bet_type' => $param['bettype']);
                 Gamebets::create($bet);
                 $message = 'Bet has been successfully place.';
                 return Redirect::action('bet.roulette')->with('success', $message);
             } catch (Exception $e) {
                 return false;
             }
         }
     } else {
         return Redirect::action('bet.roulette')->with('error', 'Insufficient credits!');
     }
 }
 public function withdraw()
 {
     //retrieve POST value
     $param = Input::only('credits', 'account_id');
     $rules = array('credits' => 'required|numeric|min:1,max:1000000', 'account_id' => 'exists:acl_users,id');
     //custom error messaging
     $messages = array();
     $validator = Validator::make($param, $rules, $messages);
     if ($validator->passes()) {
         $retrieve = Wallet::where('account_id', $param['account_id'])->first();
         if (!empty($retrieve)) {
             if ($retrieve->credits >= $param['credits']) {
                 try {
                     $update = $retrieve->decrement('credits', $param['credits']);
                     if ($update == 1) {
                         $fundin = array('wallet_id' => $retrieve->id, 'onbehalf' => Auth::user()->id, 'credits' => $param['credits'], 'description' => 'Withdraw credits', 'fundtype' => 'fundout');
                         $funds = Fundinout::create($fundin);
                     }
                 } catch (Exception $e) {
                     return false;
                 }
                 $message = 'Credit has been successfully withdraw.';
                 return Redirect::action('player.index')->with('success', $message);
             } else {
                 return Redirect::action('player.index')->with('error', 'Insufficient credits!');
             }
         } else {
             return Redirect::action('player.index')->with('error', 'Insufficient credits!');
         }
     } else {
         $messages = $validator->messages();
         return Redirect::action('player.index')->with('error', $messages->all());
     }
 }
 public function player_winnings($payout, $player_id, $bet_amount, $channel_id)
 {
     $payout_amount = $payout * $bet_amount + $bet_amount;
     $retrieve = Wallet::where('account_id', $player_id)->first();
     try {
         $update = $retrieve->increment('credits', $payout_amount);
         if ($update == 1) {
             $fundin = array('wallet_id' => $retrieve->id, 'onbehalf' => Auth::user()->id, 'credits' => $payout_amount, 'description' => 'Player winnings on roullete ' . $channel_id, 'fundtype' => 'winnings');
             $funds = Fundinout::create($fundin);
         }
     } catch (Exception $e) {
         return false;
     }
 }