Ejemplo n.º 1
0
 /**
  * Create a new user instance after a valid registration.
  *
  * @param  array  $data
  * @return User
  */
 protected function create(array $data)
 {
     $user = User::create(['name' => $data['name'], 'email' => $data['email'], 'password' => bcrypt($data['password'])]);
     $month = new Month();
     $month->userID = $user->id;
     $month->cash = 0.0;
     $month->income = 0.0;
     $month->profit = 0.0;
     $month->name = date('M');
     $month->year = date('Y');
     $month->save();
     return $user;
 }
 function getAttendance($member = '')
 {
     $input = Input::all();
     if ($member == null or $member == '') {
         $memberId = Session::get('memberId');
     } else {
         $memberId = $member;
     }
     if (array_key_exists('date', $input)) {
         $year = date("Y", strtotime($input['date']));
         $startDate = $year . '-01-01';
         $endDate = $startDate . '12-31';
     } else {
         $year = date("Y");
         $startDate = $year . '-01-01';
         $endDate = $year . '-12-31';
     }
     $month = array_key_exists('month', $input) ? $input['month'] : date('F');
     $month = Month::ForMonth($month)->first();
     if (!empty($month)) {
         $attendance = $month->attendances()->DateBetween($startDate, $endDate)->ForMember($memberId)->get();
         $attendances = $this->AverageMonthAttendance($attendance, $month, $year);
         return $attendances;
     } else {
         return Redirect::to('/auth/dashboard')->withFlashMessage('No Attendnce for the month');
     }
 }
Ejemplo n.º 3
0
 function make($data)
 {
     $month = Month::ForMonth('January')->first();
     $config['month_id'] = $month->id;
     $config['member_id'] = Session::get('memberId');
     $config['date'] = $data['date'];
     if (array_key_exists('check_in', $data)) {
         $config['check_in'] = $data['check_in'];
         $attendance = Attendance::ForUniqueCheck($config['member_id'], $config['date'])->first();
         if (empty($attendance)) {
             Attendance::create($config);
         } else {
             throw new Exception('You Already have check In for the day');
         }
     }
     if (array_key_exists('check_out', $data)) {
         $config['check_out'] = $data['check_out'];
         //        foreach($data as  $key => $value)
         //        {
         //            $this->is_empty($value);
         //        }
         //        $this->is_valid($this->checkInFlag);
         $attendance = Attendance::ForUniqueCheck($config['member_id'], $config['date'])->first();
         if (empty($attendance)) {
             throw new Exception('You Havent check in yet');
         }
         if ($attendance->check_out === '00:00:00') {
             $attendance->update($data);
         } else {
             throw new Exception('You Already have check out for the day');
         }
     }
 }
 public function index(\App\Gameweek $gameweek = null, \App\Month $month = null)
 {
     $user = null;
     $users = \App\User::ranked()->orderBy('rank')->get();
     $lastFixture = \App\Fixture::over()->orderBy('kickoff', 'desc')->first();
     $activeTabs = ['active', '', ''];
     if (!$month or !$month->hasStarted()) {
         $month = $lastFixture->gameweek->month;
     } else {
         $activeTabs = ['', 'active', ''];
     }
     if (!$gameweek or !$gameweek->hasCompletedFixture()) {
         $gameweek = $lastFixture->gameweek;
     } else {
         $activeTabs = ['', '', 'active'];
     }
     if (\Auth::check()) {
         $user = \Auth::user();
     }
     $months = \App\Month::orderBy('id', 'desc')->get()->filter(function ($month) {
         return $month->hasStarted();
     });
     $gameweeks = \App\Gameweek::orderBy('id', 'desc')->get()->filter(function ($gw) {
         return $gw->hasCompletedFixture();
     });
     $gameweekUsers = $gameweek->predictors()->orderBy('gameweek_user.rank', 'asc')->get();
     $monthUsers = $month->users()->orderBy('month_user.rank', 'asc')->get();
     $nameOfPage = 'standings';
     return view('pages.standings', compact('gameweeks', 'months', 'users', 'gameweekUsers', 'monthUsers', 'month', 'gameweek', 'user', 'activeTabs', 'nameOfPage'));
 }
 /**
  * Bootstrap any application services.
  *
  * @return void
  */
 public function boot()
 {
     $faults = Attendfault::where('attended', '=', 'No')->get();
     $months = Month::all();
     $states = State::all();
     View::share(['counts' => $faults, 'states' => $states, 'months' => $months]);
 }
Ejemplo n.º 6
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     //This creates a new Entry in the Month table and carries over the data from last month.
     $months = DB::select('select * from month where name = :month and year = :year', ['month' => date("M"), 'year' => date("Y")]);
     if ($months) {
     } else {
         $months = DB::select('select * from month');
         foreach ($months as $month) {
             $new = new Month();
             $new->userID = $month->userID;
             $new->cash = $month->cash;
             $new->year = date("Y");
             $new->name = date("M");
             $new->save();
         }
     }
 }
 /**
  * Define your route model bindings, pattern filters, etc.
  *
  * @param  \Illuminate\Routing\Router  $router
  * @return void
  */
 public function boot(Router $router)
 {
     parent::boot($router);
     $router->bind('username', function ($username) {
         return \App\User::where('username', $username)->firstOrFail();
     });
     $router->bind('gwid', function ($gwid) {
         return \App\Gameweek::where('id', $gwid)->firstOrFail();
     });
     $router->bind('monthid', function ($monthid) {
         return \App\Month::where('id', $monthid)->firstOrFail();
     });
 }
Ejemplo n.º 8
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::table('month')->delete();
     Month::create(['title' => 'Январь']);
     Month::create(['title' => 'Февраль']);
     Month::create(['title' => 'Март']);
     Month::create(['title' => 'Апрель']);
     Month::create(['title' => 'Май']);
     Month::create(['title' => 'Июнь']);
     Month::create(['title' => 'Июль']);
     Month::create(['title' => 'Август']);
     Month::create(['title' => 'Сентябрь']);
     Month::create(['title' => 'Октябрь']);
     Month::create(['title' => 'Ноябрь']);
     Month::create(['title' => 'Декабрь']);
 }
Ejemplo n.º 9
0
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     $months = Month::lists('name', 'id')->toArray();
     $runningGameweeks = Gameweek::incomplete()->get()->filter(function ($gw) {
         return $gw->started();
     });
     $runningGameweeks->each(function ($gw, $key) {
         $gw->overFixtureCnt = $gw->fixtures()->over()->get()->count();
         $gw->pendingFixtureCnt = $gw->fixtures()->get()->filter(function ($fxt) {
             return $fxt->isClosed() and !$fxt->isOver();
         })->count();
     });
     $upcomingGameweeks = Gameweek::incomplete()->get()->filter(function ($gw) {
         return !$gw->started();
     });
     $completeGameweeks = Gameweek::complete()->get();
     return view('admin.gameweek.index', compact('months', 'runningGameweeks', 'upcomingGameweeks', 'completeGameweeks'));
 }
Ejemplo n.º 10
0
 /**
  * Show the application dashboard to the user.
  *
  * @return Response
  */
 public function index()
 {
     //add check for row in month table with correct month
     //make it if not there.
     $user = Auth::user();
     $month = Input::get('month');
     $year = Input::get('year');
     $banks = DB::select('select * from accounts where userID = :id and accountType = "b"', ['id' => $user->id]);
     $cc = DB::select('select * from accounts where userID = :id and accountType = "c"', ['id' => $user->id]);
     $credits = DB::select('select * from income where userID = :id and month = :month and year = :year', ['id' => $user->id, 'month' => $month, 'year' => $year]);
     $accounts = DB::select('select * from accounts where userID = :id', ['id' => $user->id]);
     $debits = DB::select('select * from transactions where userID = :id and month = :month and year = :year', ['id' => $user->id, 'month' => $month, 'year' => $year]);
     $transfers = DB::select('select * from transfers where userID = :id and month = :month and year = :year', ['id' => $user->id, 'month' => $month, 'year' => $year]);
     $payments = DB::select('select * from payments where userID = :id and month = :month and year = :year', ['id' => $user->id, 'month' => $month, 'year' => $year]);
     if ($credits || $debits) {
         $accountNames = [];
         foreach ($accounts as $account) {
             $accountNames = $accountNames + [$account->id => $account->name];
         }
         $monthData = Month::where('userID', $user->id)->where('name', $month)->where('year', $year)->first();
         $income = $monthData->income;
         $profit = $monthData->profit;
         //prepare spending amounts for types for the pie chart.
         $types = DB::select('select * from types where userID = :id order by name ASC', ['id' => $user->id]);
         $spending = [];
         $typeNames = [];
         foreach ($types as $type) {
             $typeNames = $typeNames + [$type->id => $type->name];
             $tmp = DB::select('select * from transactions where userID = :id and month = :month and typeID = :typeID and year = :year', ['id' => $user->id, 'month' => $month, 'typeID' => $type->id, 'year' => $year]);
             $sum = 0;
             foreach ($tmp as $i) {
                 $sum = $sum + $i->amount;
             }
             if ($sum != 0) {
                 array_push($spending, ["sum" => $sum, "name" => $type->name]);
             }
         }
         arsort($spending);
         return view('view-past')->with('month', $month)->with('year', $year)->with('income', $income)->with('profit', $profit)->with('spending', $spending)->with('accountNames', $accountNames)->with('typeNames', $typeNames)->with('transactions', $debits)->with('incomeData', $credits)->with('payments', $payments)->with('transfers', $transfers);
     } else {
         return view('view-past-no-data');
     }
 }
Ejemplo n.º 11
0
 /**
  * Show the application dashboard to the user.
  *
  * @return Response
  */
 public function index()
 {
     //add check for row in month table with correct month
     //make it if not there.
     $user = Auth::user();
     $month = date("M");
     $year = date('Y');
     $banks = DB::select('select * from accounts where userID = :id and accountType = "b"', ['id' => $user->id]);
     $cc = DB::select('select * from accounts where userID = :id and accountType = "c"', ['id' => $user->id]);
     $credits = DB::select('select * from income where userID = :id and month = :month and year = :year', ['id' => $user->id, 'month' => $month, 'year' => $year]);
     $accounts = DB::select('select * from accounts where userID = :id', ['id' => $user->id]);
     $debits = DB::select('select * from transactions where userID = :id and month = :month and year = :year', ['id' => $user->id, 'month' => $month, 'year' => $year]);
     $transfers = DB::select('select * from transfers where userID = :id and month = :month and year = :year', ['id' => $user->id, 'month' => $month, 'year' => $year]);
     $payments = DB::select('select * from payments where userID = :id and month = :month and year = :year', ['id' => $user->id, 'month' => $month, 'year' => $year]);
     $accountNames = [];
     foreach ($accounts as $account) {
         $accountNames = $accountNames + [$account->id => $account->name];
     }
     $income = 0;
     $spent = 0;
     //sum  up for months profit
     foreach ($credits as $credit) {
         $income += $credit->amount;
     }
     foreach ($debits as $debit) {
         if ($debit->accountID == 0 && $debit->month == date("M")) {
             $spent = $spent + $debit->amount;
         } else {
             //check to make sure teh cc id is not a bank if so this is a transfer and doesn't get counted
             $account2 = Account::find($debit->accountID);
             if ($account2->accountType == 'b' && $debit->month == date("M")) {
                 //this is a payment on a cc
                 $spent = $spent + $debit->amount;
             }
         }
     }
     foreach ($payments as $payment) {
         if ($payment->month == date("M")) {
             $spent = $spent + $payment->amount;
         }
     }
     $profit = $income - $spent;
     $monthData = Month::where('userID', $user->id)->where('name', date("M"))->where('year', date("Y"))->first();
     $monthData->income = $income;
     $monthData->profit = $profit;
     $monthData->save();
     //prepare spending amounts for types for the pie chart.
     $types = DB::select('select * from types where userID = :id order by name ASC', ['id' => $user->id]);
     $spending = [];
     $typeNames = [];
     foreach ($types as $type) {
         $typeNames = $typeNames + [$type->id => $type->name];
         $tmp = DB::select('select * from transactions where userID = :id and month = :month and typeID = :typeID and year = :year', ['id' => $user->id, 'month' => $month, 'typeID' => $type->id, 'year' => $year]);
         $sum = 0;
         foreach ($tmp as $i) {
             $sum = $sum + $i->amount;
         }
         if ($sum != 0) {
             array_push($spending, ["sum" => $sum, "name" => $type->name]);
         }
     }
     arsort($spending);
     $cash = DB::select('select cash from month where userID = :id and name = :month and year = :year', ['id' => $user->id, 'month' => $month, 'year' => date("Y")]);
     return view('home')->with('banks', $banks)->with('cc', $cc)->with('income', $income)->with('profit', $profit)->with('spending', $spending)->with('cash', $cash)->with('accountNames', $accountNames)->with('typeNames', $typeNames)->with('transactions', $debits)->with('incomeData', $credits)->with('payments', $payments)->with('transfers', $transfers);
 }
Ejemplo n.º 12
0
 public function edit_announcement($id)
 {
     $fields = Field::orderBy('name')->lists('name', 'id');
     $terms = Term::lists('name', 'id');
     $municipalities = Municipality::lists('name', 'id');
     $regions = Region::lists('name', 'id');
     $type = array(0 => 'ვატარებ', 1 => 'ვეძებ');
     $quarter = Quarter::all()->lists('name', 'id');
     $months = Month::all()->lists('name', 'id');
     $select = DB::select(' SELECT trainings.id, field_training.field_id, term_training.term_id, municipality_training.municipality_id, month_training.month_id
                             FROM trainings
                             JOIN field_training ON trainings.id = field_training.training_id
                             JOIN term_training ON trainings.id = term_training.training_id
                             JOIN municipality_training ON trainings.id = municipality_training.training_id
                             JOIN month_training ON trainings.id = month_training.training_id
                             where trainings.id = ' . $id . '
                             group by trainings.id
                ');
     $select = $select[0];
     $training_filtered = new \stdClass();
     $training_instance = Training::find($select->id);
     $training_field = Field::find($select->field_id);
     $training_municipality = Municipality::find($select->municipality_id);
     $training_months = DB::select('SELECT months.name FROM month_training JOIN months ON months.id = month_training.month_id WHERE training_id = ' . $training_instance->id);
     $training_terms = DB::select('SELECT terms.name FROM term_training JOIN terms ON terms.id = term_training.term_id WHERE training_id = ' . $training_instance->id);
     foreach ($training_months as $month) {
         $training_months_array[] = $month->name;
     }
     foreach ($training_terms as $term) {
         $training_terms_array[] = $term->name;
     }
     $training_filtered->id = $training_instance->id;
     $training_filtered->header = $training_instance->name;
     $training_filtered->description = $training_instance->description;
     $training_filtered->file = $training_instance->file;
     $training_filtered->link = $training_instance->link;
     $training_filtered->field['name'] = $training_field->name;
     $training_filtered->field['id'] = $training_field->id;
     $training_filtered->months = $training_months_array;
     $training_filtered->terms = $training_terms_array;
     $training_filtered->municipality['name'] = $training_municipality->name;
     $training_filtered->municipality['id'] = $training_municipality->id;
     $training_filtered->region = $training_municipality->region_id;
     $training_filtered->isAdmin = Auth::check();
     return view('edit.edit_announcement', ['fields' => $fields, 'terms' => $terms, 'regions' => $regions, 'municipalities' => $municipalities, 'quarter' => $quarter, 'month' => $months, 'type' => $type, 'training' => $training_filtered]);
 }
Ejemplo n.º 13
0
 public function add_announcement()
 {
     if (!Auth::user() || Auth::user()->role != 1) {
         return redirect('/');
     }
     $fields = Field::orderBy('name')->lists('name', 'id');
     $terms = Term::lists('name', 'id');
     $municipalities = Municipality::all();
     $municipality_regions = array();
     foreach ($municipalities as $m) {
         $municipality_regions[] = array('municipality' => $m, 'region' => $m->region);
     }
     $regions = Region::lists('name', 'id');
     $type = array(0 => 'ვატარებ', 1 => 'ვეძებ');
     $quarter = Quarter::all()->lists('name', 'id');
     $month = Month::all()->lists('name', 'id');
     return view('add_forms.add_announcement', ['fields' => $fields, 'terms' => $terms, 'regions' => $regions, 'municipality_regions' => $municipality_regions, 'quarter' => $quarter, 'month' => $month, 'type' => $type]);
 }
Ejemplo n.º 14
0
 public function render_form_data()
 {
     $fields = Field::orderBy('name')->lists('name', 'id');
     $terms = Term::lists('name', 'id');
     $municipalities = Municipality::all();
     $municipality_regions = array();
     foreach ($municipalities as $m) {
         $municipality_regions[] = array('municipality' => $m, 'region' => $m->region);
     }
     $regions = Region::lists('name', 'id');
     $type = array(0 => 'ვატარებ', 1 => 'ვეძებ');
     $quarter = Quarter::all()->lists('name', 'id');
     $month = Month::all()->lists('name', 'id');
     return view('search_forms.search', ['fields' => $fields, 'terms' => $terms, 'regions' => $regions, 'municipality_regions' => $municipality_regions, 'quarter' => $quarter, 'month' => $month, 'type' => $type]);
 }
 public function postIndex()
 {
     $user = Auth::user();
     $id = Input::get('payment');
     /*
      *There is an invisible field called form that tells what form was submitted
      *
      */
     if (Input::get('form') == 'trans') {
         $monthNum = substr(Input::get('date'), 0, 2);
         $month = date('M', mktime(0, 0, 0, $monthNum, 10));
         $year = substr(Input::get('date'), -4);
         $transaction = new Transaction();
         $transaction->userID = $user->id;
         $transaction->date = Input::get('date');
         $transaction->amount = Input::get('amount');
         $transaction->typeID = Input::get('type');
         $transaction->note = Input::get('note');
         $transaction->year = $year;
         $transaction->month = $month;
         if ($id == 'cash') {
             $month = Month::where('userID', $user->id)->where('name', $month)->where('year', date("Y"))->first();
             $month->cash -= Input::get('amount');
             $month->save();
             $transaction->accountID = 0;
         } else {
             $transaction->accountID = $id;
             $account = Account::find($id);
             //add for credit subtract for bank
             if ($account->accountType == 'c') {
                 $account->balance += Input::get('amount');
             } else {
                 $account->balance -= Input::get('amount');
             }
             $account->save();
         }
         $transaction->save();
         return redirect('options')->with('message', 'Transaction added successfully.');
     } else {
         if (Input::get('form') == 'type') {
             $type = new Type();
             $type->userID = $user->id;
             $type->name = Input::get('name');
             $type->save();
             return redirect('options')->with('message', 'Category added successfully.');
         } else {
             if (Input::get('form') == 'payment') {
                 $monthNum = substr(Input::get('date'), 0, 2);
                 $month = date('M', mktime(0, 0, 0, $monthNum, 10));
                 $year = substr(Input::get('date'), -4);
                 $amount = Input::get('amount');
                 $bankID = Input::get('bank');
                 $ccID = Input::get('payment');
                 $note = Input::get('note');
                 $date = Input::get('date');
                 if ($ccID == 'cash') {
                     $month2 = Month::where('userID', $user->id)->where('name', $month)->first();
                     $month2->cash = $month2->cash + $amount;
                     $month2->save();
                     if ($bankID == 'cash') {
                         $month2 = Month::where('userID', $user->id)->where('name', $month)->first();
                         $month2->cash = $month2->cash - $amount;
                         $month2->save();
                     } else {
                         $bank = Account::find($bankID);
                         $bank->balance = $bank->balance - $amount;
                         $bank->save();
                     }
                     $transfer = new Transfer();
                     $transfer->userID = $user->id;
                     $transfer->creditAccountID = $bankID;
                     $transfer->debitAccountID = 0;
                     $transfer->amount = $amount;
                     $transfer->note = $note;
                     $transfer->date = $date;
                     $transfer->year = $year;
                     $transfer->month = $month;
                     $transfer->save();
                 } else {
                     $cc = Account::find($ccID);
                     if ($bankID == 'cash') {
                         $month2 = Month::where('userID', $user->id)->where('name', $month)->first();
                         $month2->cash = $month2->cash - $amount;
                         $month2->save();
                     } else {
                         $bank = Account::find($bankID);
                         $bank->balance = $bank->balance - $amount;
                         $bank->save();
                     }
                     if ($cc->accountType == 'b') {
                         //transfer
                         $cc->balance = $cc->balance + $amount;
                         $transfer = new Transfer();
                         $transfer->userID = $user->id;
                         $transfer->creditAccountID = $bankID;
                         $transfer->debitAccountID = $ccID;
                         $transfer->amount = $amount;
                         $transfer->note = $note;
                         $transfer->date = $date;
                         $transfer->year = $year;
                         $transfer->month = $month;
                         $transfer->save();
                     } else {
                         //payment
                         $cc->balance = $cc->balance - $amount;
                         $payment = new Payment();
                         $payment->userID = $user->id;
                         $payment->creditAccountID = $bankID;
                         $payment->debitAccountID = $ccID;
                         $payment->amount = $amount;
                         $payment->note = $note;
                         $payment->date = $date;
                         $payment->year = $year;
                         $payment->month = $month;
                         $payment->save();
                     }
                     $cc->save();
                 }
                 return redirect('options')->with('message', 'Payment saved successfully.');
             } else {
                 if (Input::get('form') == 'cc') {
                     $cc = new Account();
                     $cc->userID = $user->id;
                     $cc->name = Input::get('name');
                     $cc->balance = Input::get('balance');
                     $cc->creditLimit = Input::get('limit');
                     $cc->statementDay = Input::get('date');
                     $cc->accountType = 'c';
                     $cc->save();
                     return redirect('options')->with('message', 'Credit Card added successfully.');
                 } else {
                     if (Input::get('form') == 'bank') {
                         $bank = new Account();
                         $bank->userID = $user->id;
                         $bank->name = Input::get('name');
                         $bank->balance = Input::get('balance');
                         $bank->accountType = 'b';
                         $bank->save();
                         return redirect('options')->with('message', 'Bank Account added successfully.');
                     } else {
                         if (Input::get('form') == 'income') {
                             $date = Input::get('date');
                             $monthNum = substr($date, 0, 2);
                             $month = date('M', mktime(0, 0, 0, $monthNum, 10));
                             $amount = Input::get('amount');
                             $bankID = Input::get('bank');
                             $year = substr(Input::get('date'), -4);
                             $income = new Income();
                             $income->userID = $user->id;
                             $income->month = $month;
                             $income->amount = $amount;
                             $income->note = Input::get('note');
                             $income->date = $date;
                             $income->year = $year;
                             if ($bankID == "cash") {
                                 $income->accountID = 0;
                                 $month = Month::where('userID', $user->id)->where('name', $month)->first();
                                 $month->cash = $month->cash + $amount;
                                 $month->save();
                             } else {
                                 $income->accountID = $bankID;
                                 $bank = Account::find($bankID);
                                 $bank->balance = $bank->balance + $amount;
                                 $bank->save();
                             }
                             $income->save();
                             return redirect('options')->with('message', 'Income added successfully.');
                         }
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 16
0
 public function incomeDelete($id)
 {
     $user = Auth::user();
     $date = Input::get('date');
     $amount = Input::get('amount');
     $bankID = Input::get('bank');
     $note = Input::get('note');
     $income = Income::where('id', $id)->where('userID', $user->id)->first();
     if ($income->accountID == 0) {
         $month = Month::where('userID', $user->id)->where('name', date('M'))->first();
         $month->cash = $month->cash - $income->amount;
         $month->save();
     } else {
         $origBank = Account::find($income->accountID);
         //add original transaction value to bank account
         $origBank->balance = $origBank->balance - $income->amount;
         $origBank->save();
     }
     $income->forceDelete();
     return redirect('home')->with('message', 'Income deleted successfully.');
 }