示例#1
0
 public function delete($id)
 {
     if (Timer::destroy($id)) {
         return redirect()->back()->with('msg', 'Таймер удален');
     }
     return redirect()->back()->with('warning', 'Не удалось удалить');
 }
示例#2
0
 public function homepage()
 {
     $params = array('logo' => Title::findOrFail(1), 'timer' => Timer::findOrFail(1), 'about' => About::findOrFail(1), 'contacts' => Contact::where('enabled', '=', true)->orderBy('id', 'ASC')->get(), 'grouped' => GroupRepository::grouped(), 'offices' => Office::where('enabled', '=', true)->orderBy('position', 'ASC')->get(), 'title' => 'TWIGA – крупнейшая независимая коммуникационная группа в России и странах СНГ');
     /*if (Request::has('r')) {
     			$r = Request::get('r');
     			Session::set('r', $r);
     
     			return redirect('/#' . $r);
     		}*/
     $view = Agent::isTablet() || Request::has('t') ? 'tablet.homepage' : (Agent::isMobile() || Request::has('m') ? 'mobile.homepage' : 'index.homepage');
     return view($view, $params);
 }
 /**
  * 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);
     }
 }
示例#4
0
 /**
  * Return the price for the project
  * This method needs to be called getFieldAttribute
  * @return string
  */
 public function getPriceAttribute()
 {
     // @TODO Try to abstract this logic, since you are using it in multiple places
     //        $rate = $this->rate_per_hour;
     //        $time = $this->total_time;
     //        $price = 0;
     //
     //        if ($time['seconds'] > 30) {
     //            $time['minutes'] = $time['minutes'] + 1;
     //        }
     //
     //        $price+= $rate * $time['hours'];
     //        $price+= $rate / 60 * $time['minutes'];
     //Get the ids of the timers that belong to the project
     $timer_ids = Timer::where('project_id', $this->id)->lists('id');
     //Get the sum of all the timers that belong to the project
     $price = (double) Timer::whereIn('id', $timer_ids)->sum('price');
     /**
      * @VP:
      * Why is sum returning a string here? I want it to be a decimal.
      */
     return $price;
 }
 /**
  * Delete a timer
  * @param Request $request
  * @param $id
  * @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response
  */
 public function destroy(Request $request, $id)
 {
     $timer = Timer::findOrFail($id);
     $timer->delete();
     return $this->responseNoContent();
 }
示例#6
0
 /**
  * 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;
 }
示例#7
0
<?php

use App\Models\Payer;
use App\Models\Project;
use App\Models\Timer;
use App\User;
/**
 * Views
 */
Route::get('/test', function () {
    $timer = Timer::find(1);
    //dd($timer);
    return $timer;
});
//test
//Route::any('/test', function()
//{
//    $pusher = new Pusher(env('PUSHER_PUBLIC_KEY'), env('PUSHER_SECRET_KEY'), env('PUSHER_APP_ID'));
//
//    $channel = 'testChannel';
//    $event = 'testEvent';
//    $data = ['It works!'];
//
//    $pusher->trigger($channel, $event, $data);
//});
//Projects
//Route::get('projects', ['as' => 'projects', 'uses' => 'PagesController@index']);
Route::get('payee', ['as' => 'payee', 'uses' => 'PagesController@payee']);
Route::get('payer', ['as' => 'payer', 'uses' => 'PagesController@payer']);
//Credits
Route::get('/credits', function () {
 /**
  * Transform :)
  * @param Timer $timer
  * @return array
  */
 public function transform(Timer $timer)
 {
     return ['id' => (int) $timer->id, 'start' => $timer->formattedStart, 'finish' => $timer->formattedFinish, 'price' => $timer->calculatePrice(), 'time' => $timer->formattedTime, 'project' => ['id' => $timer->project->id, 'price' => $timer->project->price, 'time' => $timer->project->totalTimeFormatted], 'payer' => ['id' => $timer->project->payer->id, 'owed' => $timer->project->payer->owedToUser]];
 }