public function delete($participant)
 {
     $user = Auth::user();
     $club = $user->clubs()->FirstOrFail();
     $participant = Participant::Find($participant);
     $player = Player::Find($participant->player_id);
     $event = Evento::find($participant->event->id);
     // $payment = Payment::find($payment);
     $title = 'League Together - ' . $event->name . ' Event';
     return View::make('app.club.event.participant.delete')->with('page_title', $title)->withEvent($event)->withClub($club)->withPlayer($player)->with('participant', $participant)->withUser($user);
 }
 public function PaymentCreateTeam($club, $id)
 {
     $user = Auth::user();
     $club = Club::find($club);
     $team = Team::find($id);
     $cart = Cart::contents();
     $uuid = Uuid::generate();
     //Addition for stub feature
     $follow = Follower::where("user_id", "=", $user->id)->FirstOrFail();
     foreach (Cart::contents() as $item) {
         //check if selected team equal team in cart
         if ($id != $item->team_id) {
             return Redirect::action('ClubPublicController@teamSingle', array($club->id, $team->id));
         }
         $player = Player::Find($item->player_id);
     }
     $discount = Session::get('discount');
     if (!$discount) {
         $discount = 0;
     }
     $discount = $discount['percent'] * Cart::total();
     $subtotal = Cart::total() - $discount;
     $taxfree = Cart::total(false) - $discount;
     $fee = $subtotal / getenv("SV_FEE") - $subtotal;
     $tax = $subtotal - $taxfree;
     $total = $fee + $tax + $subtotal;
     if (!$total) {
         foreach (Cart::contents() as $item) {
             $member = new Member();
             $member->id = $uuid;
             $member->firstname = $player->firstname;
             $member->lastname = $player->lastname;
             $member->due = $team->getOriginal('due');
             $member->early_due = $team->getOriginal('early_due');
             $member->early_due_deadline = $team->getOriginal('early_due_deadline');
             $member->plan_id = null;
             $member->player_id = $player->id;
             $member->team_id = $item->team_id;
             $member->accepted_on = Carbon::Now();
             $member->accepted_by = $user->profile->firstname . ' ' . $user->profile->lastname;
             $member->accepted_user = $user->id;
             $member->method = $item->type;
             $member->status = 1;
             $member->save();
             //waitlist process
             if ($team->max < $team->members->count()) {
                 //add to waitlist
                 $waitlist = new Waitlist();
                 $waitlist->id = Uuid::generate();
                 $waitlist->member_id = $uuid;
                 $waitlist->team_id = $team->id;
                 $waitlist->save();
             }
         }
         //send email notification of acceptance
         $data = array('club' => $club, 'player' => $player, 'user' => $user, 'member' => $member);
         $mail = Mail::send('emails.notification.accept', $data, function ($message) use($user, $club, $member) {
             $message->from('*****@*****.**', 'C2C Lacrosse')->to($user->email, $member->accepted_by)->subject("Thank you for joining our team | " . $club->name);
             foreach ($club->users()->get() as $value) {
                 $message->bcc($value->email, $club->name);
             }
         });
         $vault = false;
         Cart::destroy();
         return View::make('app.public.club.team.free')->with('page_title', 'Checkout')->withUser($user)->with('club', $club)->with('team', $team)->with('products', $cart)->with('subtotal', $subtotal)->with('service_fee', $fee)->with('tax', $tax)->with('cart_total', $total)->with('discount', $discount)->with('vault', $vault)->with('player', $player);
         // return "You've been added to the team for free, please close this window to complete transaction";
         // return Redirect::action('ClubPublicController@selectTeamPlayer', array($club->id, $team->$id));
     }
     /**********************/
     //stub temporary fix for parent that like to sign up for an event team in a different club with a saved customer id
     //check if user is follower of the club hosting the team.
     if ($follow->club_id != $club->id) {
         $vault = false;
         return View::make('app.public.club.team.checkoutWithoutVault')->with('page_title', 'Checkout')->withUser($user)->with('club', $club)->with('team', $team)->with('products', $cart)->with('subtotal', $subtotal)->with('service_fee', $fee)->with('tax', $tax)->with('cart_total', $total)->with('discount', $discount)->with('vault', $vault)->with('player', $player);
     }
     /*******************************/
     if ($user->profile->customer_vault) {
         $param = array('report_type' => 'customer_vault', 'customer_vault_id' => $user->profile->customer_vault, 'club' => $club->id);
         $payment = new Payment();
         $vault = $payment->ask($param);
         return View::make('app.public.club.team.checkoutVault')->with('page_title', 'Checkout')->withUser($user)->with('club', $club)->with('team', $team)->with('products', $cart)->with('subtotal', $subtotal)->with('service_fee', $fee)->with('tax', $tax)->with('cart_total', $total)->with('discount', $discount)->with('vault', $vault)->with('player', $player);
     } else {
         $vault = false;
         return View::make('app.public.club.team.checkout')->with('page_title', 'Checkout')->withUser($user)->with('club', $club)->with('team', $team)->with('products', $cart)->with('subtotal', $subtotal)->with('service_fee', $fee)->with('tax', $tax)->with('cart_total', $total)->with('discount', $discount)->with('vault', $vault)->with('player', $player);
     }
 }
 public function doRefund($id)
 {
     $user = Auth::user();
     $club = $user->clubs()->FirstOrFail();
     $uuid = Uuid::generate();
     $payment = Payment::where('club_id', '=', $club->id)->where('transaction', '=', $id)->FirstOrFail();
     $user_parent = User::find($payment->user_id);
     $uuid = Uuid::generate();
     if ($payment->event_type) {
         $participant = Participant::Find($payment->items->first()->participant_id);
         $event = Evento::find($participant->event->id);
     } else {
         $participant = Member::Find($payment->items->first()->member_id);
         $event = Team::find($participant->team->id);
     }
     $player = Player::Find($participant->player->id);
     //$amount = $payment->getOriginal('subtotal');
     $amount = Input::get('amount');
     if ($amount > $payment->getOriginal('subtotal')) {
         return Redirect::action('AccountingController@refund', $payment->transaction)->with('error', "You cannot refund more than " . $payment->getOriginal('subtotal'));
     }
     if ($amount <= 0 || $amount == '') {
         return Redirect::action('AccountingController@refund', $payment->transaction)->with('error', "Amount must be more than 0");
     }
     if ($amount > 0) {
         $param = array('transactionid' => $payment->transaction, 'club' => $club->id, 'amount' => number_format($amount, 2, ".", ""));
         $transaction = $payment->refund($param);
         if ($transaction->response == 3 || $transaction->response == 2) {
             return Response::json($transaction);
             return Redirect::action('AccountingController@transaction', $payment->transaction)->with('error', $transaction->responsetext);
         } else {
             $payment1 = new Payment();
             $payment1->id = $uuid;
             $payment1->customer = $user_parent->profile->customer_vault;
             $payment1->transaction = $transaction->transactionid;
             $payment1->subtotal = -$transaction->total;
             $payment1->total = -$transaction->total;
             $payment1->club_id = $club->id;
             $payment1->user_id = $user_parent->id;
             $payment1->player_id = $player->id;
             $payment1->type = $transaction->type;
             $sale = new Item();
             $sale->description = $event->name . " ({$transaction->type})";
             $sale->quantity = 1;
             $sale->price = -$transaction->total;
             $sale->payment_id = $uuid;
             if ($payment->event_type) {
                 $payment1->event_type = $event->type_id;
             } else {
                 $payment1->event_type = NULL;
             }
             $payment1->save();
             $sale->save();
             $data = array('club' => $club, 'transaction' => $transaction, 'user' => $user, 'contact' => $user_parent);
             //send notification for refund confirmation
             $mail = Mail::send('emails.receipt.refund', $data, function ($message) use($user, $club, $user_parent) {
                 $message->to($user_parent->email)->subject("Refund Confirmation | " . $club->name);
                 foreach ($club->users()->get() as $value) {
                     $message->bcc($value->email, $club->name);
                 }
             });
         }
         //end of transaction result
     }
     //end of amount test
     return Redirect::action('AccountingController@transaction', $payment->transaction);
 }
 /**
  * Display the specified resource.
  * GET /members/{id}
  *
  * @param  int  $id
  * @return Response
  */
 public function show($team, $id)
 {
     setlocale(LC_MONETARY, "en_US");
     $user = Auth::user();
     $club = $user->Clubs()->FirstOrFail();
     $member = Member::find($id);
     $player = Player::Find($member->player_id);
     $title = 'League Together - ' . $club->name . ' Teams';
     $team = Team::where("id", "=", $team)->where("club_id", '=', $club->id)->FirstOrFail();
     $plan = Plan::where("member_id", "=", $member->id)->with("schedulepayments")->First();
     if (isset($plan)) {
         //$plan = Plan::where("member_id", "=",$member->id)->with("schedulepayments")->FirstOrFail();
         return View::make('pages.user.club.member.show')->with('page_title', $title)->with('team', $team)->with('member', $member)->with('player', $player)->with('plan', $plan)->withUser($user);
     } else {
         return View::make('pages.user.club.member.show')->with('page_title', $title)->with('team', $team)->with('member', $member)->with('player', $player)->withUser($user);
     }
 }