public static function destroy($id)
 {
     self::check_admin_logged_in();
     $participant = Participant::find($id);
     Participant::delete($id);
     Participant::nullify_and_update_competition_standings($participant->competition_id);
     Redirect::to('/competition/' . $participant->competition_id . '/participants', array('message' => 'Kilpailija ' . $participant->competitor_name . ' poistettiin onnistuneesti kilpailusta ' . $participant->competition_name));
 }
 public function PaymentSuccess($id)
 {
     $result = Session::get('result');
     $user = Auth::user();
     $participant = Participant::find($id);
     $player = $participant->player;
     $club = $participant->event->club;
     $title = 'League Together - ' . $participant->event->club->name . ' Events';
     if (!$result) {
         return Redirect::action('AccountController@index');
     }
     $param = array('transaction_id' => $result->transactionid, 'club' => $club->id, 'action_type' => $result->type);
     $payment = new Payment();
     $transaction = json_decode(json_encode($payment->ask($param)), false);
     $items = Cart::contents();
     // Clean the cart
     Cart::destroy();
     return View::make('app.club.event.participant.checkout.success')->with('page_title', 'Payment Complete')->withUser($user)->with('products', $items)->with('result', $result)->with('transaction', $transaction->transaction);
 }
 public static function update()
 {
     $attributes = self::get_attributes();
     $split_number = Split::find($attributes['id'])->split_number;
     $attributes['split_number'] = $split_number;
     $split = new Split($attributes);
     $participant = Participant::find($split->participant_id);
     $competition_id = $participant->competition_id;
     self::check_admin_or_recorder_logged_in($competition_id);
     $errors = $split->validate_split_time();
     if (count($errors) == 0) {
         $split->update();
         Participant::update_competition_standings($competition_id);
         Redirect::to('/competition/' . $competition_id . '/splits', array('message' => 'Väliaikaa muokattu.'));
     } else {
         $splits = Split::participants_splits($participant->id);
         self::edit_view($participant, $attributes, $splits, $errors);
     }
 }
 public function PaymentCreate($club, $id)
 {
     $user = Auth::user();
     $club = Club::find($club);
     $event = Evento::find($id);
     $cart = Cart::contents(true);
     $uuid = Uuid::generate();
     //Addition for stub feature
     $follow = Follower::where("user_id", "=", $user->id)->FirstOrFail();
     foreach (Cart::contents() as $item) {
         //check if selected event equal event in cart
         if ($id != $item->event_id) {
             return Redirect::action('ClubPublicController@eventSingle', array($club->id, $event->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) {
         //add participant for free !idea
         foreach (Cart::contents() as $item) {
             $participant = new Participant();
             $participant->id = $uuid;
             $participant->firstname = $player->firstname;
             $participant->lastname = $player->lastname;
             $participant->due = $event->getOriginal('fee');
             $participant->early_due = $event->getOriginal('early_fee');
             $participant->early_due_deadline = $event->early_deadline;
             $participant->event_id = $item->event_id;
             $participant->method = 'full';
             $participant->player_id = $player->id;
             $participant->accepted_on = Carbon::Now();
             $participant->accepted_by = $user->profile->firstname . ' ' . $user->profile->lastname;
             $participant->accepted_user = $user->id;
             $participant->status = 1;
             $participant->save();
             $participant = Participant::find($uuid);
             //waitlist process
             if ($event->max < $event->participants->count()) {
                 //add to waitlist
                 $waitlist = new Waitlist();
                 $waitlist->id = Uuid::generate();
                 $waitlist->participant_id = $uuid;
                 $waitlist->event_id = $event->id;
                 $waitlist->save();
             }
         }
         //send email notification of acceptance
         $data = array('club' => $club, 'player' => $player, 'user' => $user, 'event' => $event, 'participant' => $participant);
         $mail = Mail::send('emails.notification.event.accept', $data, function ($message) use($user, $club, $participant) {
             $message->from('*****@*****.**', 'C2C Lacrosse')->to($user->email, $participant->accepted_by)->subject("Thank you for joining our event | " . $club->name);
             foreach ($club->users()->get() as $value) {
                 $message->bcc($value->email, $club->name);
             }
         });
         return "Congratulation! your player has been added, please close this window.";
         return Redirect::action('AccountController@index');
     }
     /**********************/
     //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.checkoutWithoutVault')->with('page_title', 'Checkout')->withUser($user)->with('club', $club)->with('event', $event)->with('products', Cart::contents())->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 $vault->;
         return View::make('app.public.club.checkoutVault')->with('page_title', 'Checkout')->withUser($user)->with('club', $club)->with('event', $event)->with('products', Cart::contents())->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.checkout')->with('page_title', 'Checkout')->withUser($user)->with('club', $club)->with('event', $event)->with('products', Cart::contents())->with('subtotal', $subtotal)->with('service_fee', $fee)->with('tax', $tax)->with('cart_total', $total)->with('discount', $discount)->with('vault', $vault)->with('player', $player);
     }
 }