public function doReport()
 {
     $user = Auth::user();
     $club = $user->Clubs()->FirstOrFail();
     $type = Input::get('type');
     $from = date('Y-m-d', strtotime(Input::get('from')));
     $to = date('Y-m-d', strtotime(Input::get('to')));
     switch ($type) {
         case 1:
             $payment = Payment::where('club_id', '=', $club->id)->with('player')->whereBetween('created_at', array($from, $to))->get();
             return $payment;
         case 2:
             $payment = SchedulePayment::where('club_id', '=', $club->id)->where('status', 0)->with('member')->whereBetween('date', array($from, $to))->get();
             return $payment;
         default:
     }
     // $payment = Payment::where('club_id', '=', $club->id)
     // ->with('player')
     // ->whereBetween('created_at', array($from , $to))->get();
     // return $payment;
 }
 public function PaymentStore($id)
 {
     $user = Auth::user();
     $participant = Participant::find($id);
     $title = 'League Together - ' . $participant->event->club->name . ' Teams';
     $player = $participant->player;
     $club = $participant->event->club;
     $cart = Cart::contents(true);
     $uuid = Uuid::generate();
     //Addition for stub feature
     $follow = Follower::where("user_id", "=", $user->id)->FirstOrFail();
     //check if follower equal club
     if ($follow->club_id != $club->id) {
         $param = array('ccnumber' => str_replace('_', '', Input::get('card')), 'ccexp' => sprintf('%02s', Input::get('month')) . Input::get('year'), 'cvv' => Input::get('cvv'), 'address1' => Input::get('address'), 'city' => Input::get('city'), 'state' => Input::get('state'), 'zip' => Input::get('zip'), 'discount' => Input::get('discount'), 'club' => $club->id, 'firstname' => $user->profile->firstname, 'lastname' => $user->profile->lastname, 'phone' => $user->profile->mobile);
     } else {
         $param = array('customer_vault_id' => $user->profile->customer_vault, 'discount' => Input::get('discount'), 'club' => $club->id);
     }
     $payment = new Payment();
     $transaction = $payment->sale($param);
     if ($transaction->response == 3 || $transaction->response == 2) {
         return Redirect::action('ParticipantController@paymentCreate', array($participant->id))->with('error', $transaction->responsetext);
     } else {
         foreach (Cart::contents() as $item) {
             $payment->id = $uuid;
             $payment->customer = $user->profile->customer_vault;
             $payment->transaction = $transaction->transactionid;
             $payment->subtotal = $transaction->subtotal;
             $payment->service_fee = $transaction->fee;
             $payment->total = $transaction->total;
             $payment->promo = $transaction->promo;
             $payment->tax = $transaction->tax;
             $payment->discount = $transaction->discount;
             $payment->club_id = $club->id;
             $payment->user_id = $user->id;
             $payment->player_id = $item->player_id;
             $payment->event_type = $participant->event->type_id;
             $payment->type = $transaction->type;
             $payment->save();
             $salesfee = $item->price / getenv("SV_FEE") - $item->price;
             $sale = new Item();
             $sale->description = $item->name;
             $sale->quantity = $item->quantity;
             $sale->price = $item->price;
             $sale->fee = $salesfee;
             $sale->participant_id = $participant->id;
             $sale->payment_id = $uuid;
             $sale->event_id = $participant->event->id;
             $sale->save();
             $participant->accepted_on = Carbon::Now();
             $participant->accepted_by = $user->profile->firstname . ' ' . $user->profile->lastname;
             $participant->accepted_user = $user->id;
             $participant->method = $item->type;
             $participant->status = 1;
             $participant->save();
             //create payments plan schedule
             if ($item->type == "plan") {
                 $subtotal = $participant->plan->getOriginal('recurring');
                 $fee = $subtotal / getenv("SV_FEE") - $subtotal;
                 $total = $fee + $subtotal;
                 for ($x = 1; $x < $participant->plan->recurrences + 1; $x++) {
                     $today = Carbon::now();
                     $today->addMonths($x);
                     $payon = $participant->plan->getOriginal('on');
                     //make sure the payday is a valid day
                     if ($payon == 31) {
                         if ($today->month == 2) {
                             $payon = 28;
                         }
                         if ($today->month == 4 || $today->month == 6 || $today->month == 9 || $today->month == 11) {
                             $payon = 30;
                         }
                     }
                     $payday = Carbon::create($today->year, $today->month, $payon, 0);
                     $schedule = new SchedulePayment();
                     $schedule->date = $payday;
                     $schedule->description = "Membership Team " . $participant->event->name;
                     $schedule->subtotal = number_format($subtotal, 2);
                     $schedule->fee = number_format($fee, 2);
                     $schedule->total = number_format($total, 2);
                     $schedule->plan_id = $participant->plan->id;
                     $schedule->club_id = $club->id;
                     $schedule->participant_id = $participant->id;
                     $status = $schedule->save();
                     if (!$status) {
                         return "We process your payment but and error occurred in the process, please contact us: support@leaguetogether.com Error# 597";
                     }
                 }
                 //end for loop
             }
             //end if plan
         }
         //email receipt
         $payment->receipt($transaction, $club->id, $item->player_id);
         $data = array('club' => $club, 'player' => $player, 'user' => $user, '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 Redirect::action('ParticipantController@paymentSuccess', array($participant->id))->with('result', $transaction);
     }
 }
Beispiel #3
0
 public function aggregateReceivable()
 {
     $count = 0;
     foreach ($this->children as $e) {
         $count += SchedulePayment::with('member')->whereHas('member', function ($query) use($e) {
             $query->where('team_id', '=', $e->id);
         })->sum('subtotal');
     }
     return $count + SchedulePayment::with('member')->whereHas('member', function ($query) use($e) {
         $query->where('team_id', '=', $this->id);
     })->sum('subtotal');
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $startDate = Carbon::now();
     $from = Carbon::now()->hour(0)->minute(0)->second(0);
     $to = Carbon::now()->hour(23)->minute(59)->second(59);
     $schedules = SchedulePayment::where('status', 0)->whereBetween('date', array($from, $to))->with('member.user.profile')->get();
     //$schedules = SchedulePayment::where('status', 0)->with('member.user.profile')->get();
     $errors = array();
     $totalAmount = array();
     $errorAmount = array();
     //save daylog
     $dayLog = new ScheduleDailyLog();
     $dayLog->started_on = Carbon::now()->toDateTimeString();
     $dayLog->payments_count = count($schedules);
     $dayLog->save();
     Cart::destroy();
     foreach ($schedules as $schedule) {
         try {
             $vault = $schedule->member->user->profile->customer_vault;
             $user = User::find($schedule->member->user->id);
             $player = Player::find($schedule->member->player->id);
             $club = Club::find($schedule->club_id);
             $team = Team::find($schedule->member->team_id);
             $uuid = Uuid::generate();
             $member = Member::find($schedule->member->id);
             $history = SchedulePayment::find($schedule->id);
             //manually login user out before login new user
             Auth::logout();
             //manually login user
             Auth::login($user);
             //clear cart content
             Cart::destroy();
             //set cart item
             $itemCart = array('id' => $team->id, 'name' => "Scheduled payment for " . $team->name, 'price' => $schedule->subtotal, 'quantity' => 1, 'organization' => $club->name, 'organization_id' => $club->id, 'player_id' => $player->id, 'user_id' => $user->id, 'type' => 'full', 'autopay' => true);
             Cart::insert($itemCart);
             //check if vault exist
             if ($vault) {
                 $param = array('customer_vault_id' => $vault, 'discount' => null, 'club' => $club->id);
                 $payment = new Payment();
                 $transaction = $payment->sale($param);
                 //temp json_decode(json_encode($array), FALSE);
                 //$transaction = json_decode(json_encode(array('response' => 1, 'total'=>$schedule->total, 'fee'=>$schedule->fee)), FALSE);
                 if ($transaction->response == 3 || $transaction->response == 2) {
                     $errors[] = array('payment_schedule_id' => $schedule->id, 'error_description' => $transaction->transactionid . ' : ' . $transaction->responsetext, 'error_amount' => $schedule->total, 'daily_log_id' => $dayLog->id);
                     array_push($errorAmount, number_format($schedule->total, 2));
                     //Email error
                     $emailerrorstatus = $payment->error($transaction, $club->id, $player->id);
                 } else {
                     array_push($totalAmount, number_format($transaction->total, 2));
                     $payment->id = $uuid;
                     $payment->customer = $vault;
                     $payment->transaction = $transaction->transactionid;
                     $payment->subtotal = $transaction->subtotal;
                     $payment->service_fee = $transaction->fee;
                     $payment->total = $transaction->total;
                     $payment->promo = $transaction->promo;
                     $payment->tax = $transaction->tax;
                     $payment->discount = $transaction->discount;
                     $payment->club_id = $club->id;
                     $payment->user_id = $user->id;
                     $payment->player_id = $player->id;
                     $payment->event_type = null;
                     $payment->type = $transaction->type;
                     $payment->save();
                     //Email receipt
                     $payment->receipt($transaction, $club->id, $player->id);
                     $sale = new Item();
                     $sale->description = $itemCart['name'];
                     $sale->quantity = $itemCart['quantity'];
                     $sale->price = $itemCart['price'];
                     $sale->fee = $transaction->fee;
                     $sale->member_id = $member->id;
                     $sale->team_id = $team->id;
                     $sale->payment_id = $uuid;
                     $sale->save();
                     //update schedule
                     $history->status = 2;
                     $history->save();
                 }
             } else {
                 //save error that vault didnt exist
                 $errors[] = array('payment_schedule_id' => $schedule->id, 'error_description' => 'Customer Vault not found', 'error_amount' => number_format($schedule->total, 2), 'daily_log_id' => $dayLog->id);
                 array_push($errorAmount, number_format($schedule->total, 2));
             }
         } catch (Exception $e) {
             //save internal error
             $errors[] = array('payment_schedule_id' => $schedule->id, 'error_description' => $e, 'error_amount' => number_format($schedule->total, 2), 'daily_log_id' => $dayLog->id);
             array_push($errorAmount, number_format($schedule->total, 2));
         }
     }
     //end of foreach schedule
     //save log for everything done
     $dayLogEnd = ScheduleDailyLog::find($dayLog->id);
     $dayLogEnd->ended_on = Carbon::now()->toDateTimeString();
     $dayLogEnd->successful_count = Count($totalAmount);
     $dayLogEnd->error_count = Count($errors);
     $dayLogEnd->total_amount = array_sum($totalAmount);
     $dayLogEnd->total_amount_error = array_sum($errorAmount);
     $dayLogEnd->save();
     //save log for errors
     if (Count($errors) > 0) {
         foreach ($errors as $errorItem) {
             $scheduleError = new ScheduleDailyError();
             $scheduleError->error_description = $errorItem['error_description'];
             $scheduleError->error_amount = $errorItem['error_amount'];
             $scheduleError->payment_schedule_id = $errorItem['payment_schedule_id'];
             $scheduleError->daily_log_id = $dayLogEnd->id;
             $scheduleError->save();
         }
     }
     return Log::info($errors);
 }
 public function delete($id)
 {
     $user = Auth::user();
     $club = $user->Clubs()->FirstOrFail();
     $schedule = SchedulePayment::where('id', '=', $id)->where('club_id', '=', $club->id)->first();
     if (!$schedule) {
         return "Unauthorized";
     }
     $plan = Plan::find($schedule->plan_id);
     $title = 'League Together - ' . $club->name . ' Schedule';
     return View::make('app.club.plan.schedule.delete')->with('page_title', $title)->with('club', $club)->with('plan', $plan)->with('schedule', $schedule)->withUser($user);
 }
 public function showCoach($id)
 {
     $user = Auth::user();
     $team = Team::find($id);
     $club = $team->club;
     $coaches = $team->coaches()->get();
     $members = Member::where('team_id', '=', $team->id)->with('team')->get();
     $title = 'League Together - ' . $team->club->name . ' Teams';
     $pay = Payment::with(array('items' => function ($query) {
     }))->get();
     $sales = Item::where('team_id', $team->id)->get();
     $receivable = SchedulePayment::with('member')->whereHas('member', function ($query) use($team) {
         $query->where('team_id', '=', $team->id);
     })->get();
     $announcements = Announcement::where('team_id', $team->id)->get();
     return View::make('app.account.team.show')->with('page_title', $title)->with('team', $team)->with('club', $club)->with('coaches', $coaches)->with('members', $members)->with('sales', $sales)->with('receivable', $receivable)->with('announcements', $announcements)->withUser($user);
 }
 public function PaymentStoreTeam($club, $id)
 {
     $user = Auth::user();
     $team = Team::find($id);
     $club = Club::find($club);
     $cart = Cart::contents(true);
     $uuid = Uuid::generate();
     $uuidMember = Uuid::generate();
     //Addition for stub feature
     $follow = Follower::where("user_id", "=", $user->id)->FirstOrFail();
     $title = 'League Together - ' . $team->club->name . ' Teams';
     //check if follower equal club
     if ($follow->club_id != $club->id) {
         $param = array('ccnumber' => str_replace('_', '', Input::get('card')), 'ccexp' => sprintf('%02s', Input::get('month')) . Input::get('year'), 'cvv' => Input::get('cvv'), 'address1' => Input::get('address'), 'city' => Input::get('city'), 'state' => Input::get('state'), 'zip' => Input::get('zip'), 'discount' => Input::get('discount'), 'club' => $club->id, 'firstname' => $user->profile->firstname, 'lastname' => $user->profile->lastname, 'phone' => $user->profile->mobile);
     } else {
         $param = array('customer_vault_id' => $user->profile->customer_vault, 'discount' => Input::get('discount'), 'club' => $club->id);
     }
     $payment = new Payment();
     $transaction = $payment->sale($param);
     if ($transaction->response == 3 || $transaction->response == 2) {
         return Redirect::action('ClubPublicController@PaymentCreateTeam', array($club->id, $team->id))->with('error', $transaction->responsetext);
     } else {
         foreach (Cart::contents() as $item) {
             $player = Player::find($item->player_id);
             //default from team
             $due = $team->getOriginal('due');
             $early_due = $team->getOriginal('early_due');
             $early_due_deadline = $team->getOriginal('early_due_deadline');
             $member = new Member();
             $member->id = $uuidMember;
             $member->firstname = $player->firstname;
             $member->lastname = $player->lastname;
             $member->due = $due;
             $member->early_due = $early_due;
             $member->early_due_deadline = $early_due_deadline;
             $member->plan_id = $team->plan_id;
             $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();
             $payment->id = $uuid;
             $payment->customer = $user->profile->customer_vault;
             $payment->transaction = $transaction->transactionid;
             $payment->subtotal = $transaction->subtotal;
             $payment->service_fee = $transaction->fee;
             $payment->total = $transaction->total;
             $payment->promo = $transaction->promo;
             $payment->tax = $transaction->tax;
             $payment->discount = $transaction->discount;
             $payment->club_id = $club->id;
             $payment->user_id = $user->id;
             $payment->player_id = $item->player_id;
             $payment->event_type = null;
             $payment->type = $transaction->type;
             $payment->save();
             $salesfee = $item->price / getenv("SV_FEE") - $item->price;
             $sale = new Item();
             $sale->description = $item->name;
             $sale->quantity = $item->quantity;
             $sale->price = $item->price;
             $sale->fee = $salesfee;
             $sale->member_id = $uuidMember;
             $sale->team_id = $item->team_id;
             $sale->payment_id = $uuid;
             $sale->save();
             $member = Member::find($uuidMember);
             //create payments plan schedule
             if ($item->type == "plan") {
                 $subtotal = $member->plan->getOriginal('recurring');
                 $fee = $subtotal / getenv("SV_FEE") - $subtotal;
                 $total = $fee + $subtotal;
                 for ($x = 1; $x < $member->plan->recurrences + 1; $x++) {
                     $today = Carbon::now();
                     $today->addMonths($x);
                     $payon = $member->plan->getOriginal('on');
                     //make sure the payday is a valid day
                     if ($payon == 31) {
                         if ($today->month == 2) {
                             $payon = 28;
                         }
                         if ($today->month == 4 || $today->month == 6 || $today->month == 9 || $today->month == 11) {
                             $payon = 30;
                         }
                     }
                     $payday = Carbon::create($today->year, $today->month, $payon, 0);
                     $schedule = new SchedulePayment();
                     $schedule->date = $payday;
                     $schedule->description = "Membership Team " . $member->team->name;
                     $schedule->subtotal = number_format($subtotal, 2);
                     $schedule->fee = number_format($fee, 2);
                     $schedule->total = number_format($total, 2);
                     $schedule->plan_id = $member->plan->id;
                     $schedule->club_id = $club->id;
                     $schedule->member_id = $member->id;
                     $status = $schedule->save();
                     if (!$status) {
                         return "We process your payment but and error occurred in the process, please contact us: support@leaguetogether.com Error# 597";
                     }
                 }
                 //end for loop
             }
             //end if plan
             //waitlist process
             if ($team->max < $team->members->count()) {
                 //add to waitlist
                 $waitlist = new Waitlist();
                 $waitlist->id = Uuid::generate();
                 $waitlist->member_id = $uuidMember;
                 $waitlist->team_id = $team->id;
                 $waitlist->save();
             }
             if ($club->processor_name == 'Bluepay') {
                 //return Redirect::action('ClubPublicController@PaymentSuccessTeam', array($club->id, $team->id))->with('result','Success');
                 return Redirect::action('ClubPublicController@PaymentCreateTeam', array($club->id, $team->id))->with('error', 'Player added successfully.  Please check your email for receipt.');
             } else {
                 $payment->receipt($transaction, $club->id, $item->player_id);
                 return Redirect::action('ClubPublicController@PaymentSuccessTeam', array($club->id, $team->id))->with('result', $transaction);
             }
             //return Redirect::action('ClubPublicController@PaymentSuccessTeam', array($club->id, $team->id))->with('result',$transaction);
         }
     }
 }