/** * * @return \Illuminate\View\View */ public function payer() { //I got an error with the package if //I didn't put $pusher_public_key into a variable first $pusher_public_key = env('PUSHER_PUBLIC_KEY'); $payer = Payer::find(Auth::user()->id); JavaScript::put(['projects' => $payer->confirmedProjects->toArray(), 'payees' => $payer->payees->toArray(), 'me' => Auth::user(), 'notifications' => $payer->notifications, 'project_requests' => $payer->projectRequests, 'pusher_public_key' => $pusher_public_key]); return view('payer'); }
/** * Run the database seeds. * * @return void */ public function run() { Project::truncate(); Timer::truncate(); $faker = Faker::create(); $john = User::where('name', 'John')->first(); $payee_john = Payee::find($john->id); $payer_john = Payer::find($john->id); $jenny = User::where('name', 'Jenny')->first(); $jane = User::where('name', 'Jane')->first(); $bob = User::where('name', 'Bob')->first(); $payee_bob = Payee::find($bob->id); /** * John is payee */ // dd($faker->randomElement([1,2,3])); // dd($faker->randomElement($payee_john->payers()->lists('id'))); // dd($payee_john->payers()->lists('id')->all()); foreach (range(0, 2) as $index) { $project = Project::create(['payee_id' => $john->id, 'payer_id' => $faker->randomElement($payee_john->payers()->lists('id')->all()), 'description' => $faker->word, 'rate_per_hour' => 40, 'status' => 'confirmed']); $this->createTimersForProject($project); } //Create a project with Jenny as payer $project = Project::create(['payee_id' => $john->id, 'payer_id' => $jenny->id, 'description' => $faker->word, 'rate_per_hour' => 40, 'status' => 'confirmed']); $this->createTimersForProject($project); /** * John is payer */ foreach (range(0, 2) as $index) { $project = Project::create(['payee_id' => $faker->randomElement($payer_john->payees()->lists('id')->all()), 'payer_id' => $john->id, 'description' => $faker->word, 'rate_per_hour' => 1, 'status' => 'confirmed']); $this->createTimersForProject($project); } /** * Bob is payee */ foreach (range(0, 4) as $index) { $project = Project::create(['payee_id' => $bob->id, 'payer_id' => $jenny->id, 'description' => $faker->word, 'rate_per_hour' => 40, 'status' => 'confirmed']); $this->createTimersForProject($project); } /** * Jenny is payee */ foreach (range(0, 2) as $index) { $project = Project::create(['payee_id' => $jenny->id, 'payer_id' => $john->id, 'description' => $faker->word, 'rate_per_hour' => 10, 'status' => 'confirmed']); $this->createTimersForProject($project); } }
/** * Get the total amount the current user owes the user * @return mixed */ public function getOwedByUserAttribute() { $payer = Payer::find(Auth::user()->id); //Find the projects belonging to the current user and $this user $projects_with_payee = Project::where('payer_id', $payer->id)->where('payee_id', $this->id)->lists('id'); //Find the timers belonging to those projects, //but only those that have not been paid for $timers_with_payee = Timer::whereIn('project_id', $projects_with_payee)->where('paid', 0)->lists('id'); //Find the amount owed $owed = Timer::whereIn('id', $timers_with_payee)->sum('price'); return (double) $owed; }