Inheritance: extends Eloquen\Eloquent
 public function log(string $description)
 {
     $activity = new Activity();
     if ($this->performedOn) {
         $activity->subject()->associate($this->performedOn);
     }
     if ($this->causedBy) {
         $activity->causer()->associate($this->causedBy);
     }
     $activity->properties = $this->properties;
     $activity->description = $this->replacePlaceholders($description, $activity);
     $activity->log_name = $this->logName;
     $activity->save();
 }
 public function handle()
 {
     $this->comment('Cleaning activity log...');
     $maxAgeInDays = config('laravel-activitylog.delete_records_older_than_days');
     $cutOffDate = Carbon::now()->subDays($maxAgeInDays)->format('Y-m-d H:i:s');
     $amountDeleted = Activity::where('created_at', '<', $cutOffDate)->delete();
     $this->info("Deleted {$amountDeleted} record(s) from the activity log.");
     $this->comment('All done!');
 }
Exemplo n.º 3
0
 /**
  * Define the application's command schedule.
  *
  * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
  * @return void
  */
 protected function schedule(Schedule $schedule)
 {
     $schedule->command('imgclear')->daily()->at('01:00');
     $schedule->command('backup:clean')->daily()->at('01:30');
     $schedule->command('backup:run')->daily()->at('02:00');
     $schedule->exec('cd ' . storage_path('logs') . ' && : > laravel.log')->daily()->at('02:30');
     $schedule->call(function () {
         Activity::cleanLog();
     })->weekly();
 }
Exemplo n.º 4
0
 public function filter()
 {
     $input = Request::all();
     $filter = $input['filter'];
     $activities = Activity::where('user_id', $filter)->paginate(10);
     if ($filter == "All") {
         return redirect()->action('LogsController@index');
     }
     $activities->appends(Request::only('filter'));
     $users = User::where('role', '!=', 'General Manager')->lists('username', 'id');
     return view('logs.index', compact('activities', 'users'));
 }
Exemplo n.º 5
0
 /**
  * Get signed in user's profile.
  */
 public function getUser(Request $request)
 {
     $user = User::find($request['user']['sub']);
     $user->roles = $user->roles()->get();
     $user->isAdmin = $user->hasRole('admin');
     $user->profile = $user->profile;
     $user->locations = $user->locations;
     $user->notifications = $user->getNotifications();
     $user->notificationsNotRead = $user->countNotificationsNotRead();
     $threads = Thread::forUser($user->id)->latest('updated_at')->get();
     $user->threads = $threads;
     $roles = Role::all(['id', 'display_name']);
     $activities = ActivityModel::where('user_id', $user->id)->get();
     return Response::json(['user' => $user, 'roles' => $roles, 'activities' => $activities]);
 }
Exemplo n.º 6
0
 /**
  * Clean old log records.
  *
  * @param int $maxAgeInMonths
  *
  * @return bool
  */
 public function cleanLog($maxAgeInMonths)
 {
     $minimumDate = Carbon::now()->subMonths($maxAgeInMonths);
     Activity::where('created_at', '<=', $minimumDate)->delete();
     return true;
 }
Exemplo n.º 7
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function activity()
 {
     $latestActivities = Activity::with('user')->latest()->limit(100)->get();
     return view('metrics.activity', ['latestActivities' => $latestActivities]);
 }
Exemplo n.º 8
0
 /**
  * Get user latest activities
  * 
  * @param  integer $id
  * @return Activity collection
  */
 public function getUserLatestActivities($id)
 {
     return Activity::where('user_id', '=', $id)->latest('id')->limit(5)->get();
 }
Exemplo n.º 9
0
 public function getActivityLog()
 {
     //        $lists      =   SysLog::orderBy('created_at','DESC')->paginate(10);
     $lists = Activity::with('user')->latest()->limit(100)->paginate(20);
     return view('utilities.activitylog', compact('lists'));
 }
Exemplo n.º 10
0
 public function index()
 {
     //collected - sale invoices where due date = this week and status is collected
     if (Auth::user()->role == 'General Manager' || Auth::user()->role == 'Accounting') {
         $currentCollected = DB::SELECT("SELECT sum(total_amount) as 'total', count(*) as 'num' FROM sales_invoices\n    \t\t\t\t\t\t\t\t\t\t\tWHERE week(date_collected) = week(now())\n    \t\t\t\t\t\t\t\t\t\t\tAND status='collected'");
         if ($currentCollected[0]->num == 0) {
             $currentAmount = 0;
             $currentCount = 0;
         } else {
             $currentAmount = $currentCollected[0]->total;
             $currentCount = $currentCollected[0]->num;
         }
         //current collectibles - sale invoices where due date = this week and status is delivered
         $currentCollectibles = DB::SELECT("SELECT sum(total_amount) as 'total', count(*) as 'num' FROM sales_invoices\n    \t\t\t\t\t\t\t\t\t\t\tWHERE week(due_date) = week(now())\n    \t\t\t\t\t\t\t\t\t\t\tAND status='delivered'");
         if ($currentCollectibles[0]->num == 0) {
             $currentCollectibleAmount = 0;
             $currentCollectibleCount = 0;
         } else {
             $currentCollectibleAmount = $currentCollectibles[0]->total;
             $currentCollectibleCount = $currentCollectibles[0]->num;
         }
         //upcoming collectibles - sale invoices where due date = next week and status is delivered
         $upcomingCollectibles = DB::SELECT("SELECT sum(total_amount) as 'total', count(*) as 'num' FROM sales_invoices\n    \t\t\t\t\t\t\t\t\t\t\tWHERE week(due_date) - week(now()) = 1\n    \t\t\t\t\t\t\t\t\t\t\tAND status='delivered'");
         if ($upcomingCollectibles[0]->num == 0) {
             $upcomingCollectibleAmount = 0;
             $upcomingCollectibleCount = 0;
         } else {
             $upcomingCollectibleAmount = $upcomingCollectibles[0]->total;
             $upcomingCollectibleCount = $upcomingCollectibles[0]->num;
         }
         //overdue collectibles - sale invoices where date difference of due date and today is > 7 and status is delivered
         $overdueCollectibles = DB::SELECT("SELECT sum(total_amount) as 'total', count(*) as 'num' FROM sales_invoices\n    \t\t\t\t\t\t\t\t\t\t\tWHERE  week(now()) - week(due_date) >= 1\n    \t\t\t\t\t\t\t\t\t\t\tAND status='overdue'");
         if ($overdueCollectibles[0]->num == 0) {
             $overdueCollectibleAmount = 0;
             $overdueCollectibleCount = 0;
         } else {
             $overdueCollectibleAmount = $overdueCollectibles[0]->total;
             $overdueCollectibleCount = $overdueCollectibles[0]->num;
         }
         $dailySales = DB::SELECT("SELECT DATE_FORMAT(date,'%m-%d-%y') as 'date', sum(total_amount) as 'total' FROM sales_invoices\n        \t\t\t\t\t\t\t\tWHERE YEAR(date) = YEAR(NOW()) AND status != 'draft'\n        \t\t\t\t\t\t\t\tGROUP BY date");
         //FOR DONUT CHART. MONTH OVERVIEW OF COLLECTED / COLLETIBLES
         $currentCollectedMonth = DB::SELECT("SELECT sum(total_amount) as 'total', count(*) as 'num' FROM sales_invoices\n                                                WHERE MONTH(date_collected) = MONTH(now())\n                                                AND status='collected'");
         if ($currentCollectedMonth[0]->num == 0) {
             $currentAmountMonth = 0;
             //$currentCountMonth = 0;
         } else {
             $currentAmountMonth = $currentCollectedMonth[0]->total;
             //$currentCountMonth = $currentCollected[0]->num;
         }
         //current collectibles - sale invoices where due date = this week and status is delivered
         $currentCollectiblesMonth = DB::SELECT("SELECT sum(total_amount) as 'total', count(*) as 'num' FROM sales_invoices\n                                                WHERE MONTH(due_date) = MONTH(now())\n                                                AND status='delivered'");
         if ($currentCollectiblesMonth[0]->num == 0) {
             $currentCollectibleAmountMonth = 0;
             //$currentCollectibleCountMonth = 0;
         } else {
             $currentCollectibleAmountMonth = $currentCollectiblesMonth[0]->total;
             //$currentCollectibleCountMonth = $currentCollectibles[0]->num;
         }
         $overdueCollectiblesMonth = DB::SELECT("SELECT sum(total_amount) as 'total', count(*) as 'num' FROM sales_invoices\n                                                WHERE MONTH(due_date) = MONTH(now())\n                                                AND status='overdue'");
         if ($overdueCollectiblesMonth[0]->num == 0) {
             $overdueCollectibleAmountMonth = 0;
             //$overdueCollectibleCountMonth = 0;
         } else {
             $overdueCollectibleAmountMonth = $overdueCollectiblesMonth[0]->total;
             //$overdueCollectibleCountMonth = $overdueCollectibles[0]->num;
         }
         //assumes general manager is logged in
         $activities = Activity::where('user_id', '!=', Auth::user()['id'])->orderBy('created_at', 'desc')->take(10)->get();
         // $activities = DB::SELECT("SELECT text, user_id, DATE_FORMAT(created_at, '%b %d, %Y %h:%i %p')  as created_at FROM activity_log ORDER BY created_at desc LIMIT 10");
         // $activities = DB::table('activity_log')->orderby('created_at', 'desc')->limit(10)->get();
         $users = User::where('role', '!=', 'General Manager')->lists('username', 'id');
         // $collection_logs = CollectionLog::where('week(follow_up_date'), '=', 'week(now())', 'AND', 'status', '=', 'pending');
         $collection_logs = DB::SELECT("SELECT c.id, name, action, date, note, c.client_id FROM collection_logs c\n                                                JOIN clients cl on c.client_id = cl.id\n                                                WHERE  DATE(now()) = date\n                                                AND c.status='To Do'");
         $collection_logs_all = CollectionLog::where('status', 'To Do')->get();
         return view('pages.home', compact('currentAmount', 'currentCount', 'currentCollectibleCount', 'currentCollectibleAmount', 'upcomingCollectibleCount', 'upcomingCollectibleAmount', 'overdueCollectibleCount', 'overdueCollectibleAmount', 'dailySales', 'currentAmountMonth', 'currentCollectibleAmountMonth', 'overdueCollectibleAmountMonth', 'activities', 'users', 'collection_logs', 'collection_logs_all'));
         // return $collection_logs_all;
         //return $currentCollectiblesMonth[0]->total;
     } else {
         if (Auth::user()->role == 'Sales') {
             // $sales_invoices = SalesInvoice::where('user_id', Auth::user()['id'])->paginate(10);
             // $dates = SalesInvoice::all()->lists('due_date','due_date');
             // return view('sales_invoices.index', compact('sales_invoices','dates'));
             return redirect()->action('SalesInvoicesController@index');
         }
     }
 }
Exemplo n.º 11
0
 protected function getPaginatedActivityLogItems() : Paginator
 {
     return Activity::with('causer')->orderBy('created_at', 'DESC')->paginate(50);
 }
Exemplo n.º 12
0
 protected function getLatestActivityItems() : Collection
 {
     return Activity::with('user')->latest()->limit(30)->get();
 }
Exemplo n.º 13
0
 public function generate()
 {
     ini_set("max_execution_time", 0);
     if (Auth::user()->role == "Project Manager") {
         $activities = Activity::whereIn('action', array('Created', 'Deleted', 'Updated'))->where(function ($query) {
             return $query->where('action', '!=', 'Created')->orWhere('type', '!=', 'Deliverable');
         })->where('user_id', Auth::user()->id)->get();
         $projects = Project::where('user_id', Auth::user()->id)->get();
         $projectids = array_pluck($projects, 'id');
         $milestones = Milestone::whereIn('project_id', $projectids)->get();
         $accomplishments = Accomplishment::whereIn('project_id', $projectids)->get();
         $issues = Issue::whereIn('project_id', $projectids)->get();
         $risks = Risk::whereIn('project_id', $projectids)->get();
         $expenses = Expense::whereIn('project_id', $projectids)->get();
         $actions = Action::whereIn('project_id', $projectids)->get();
         $deliverables = Deliverable::whereIn('project_id', $projectids)->get();
         $business_project_team_members = BusinessProjectTeamMember::whereIn('project_id', $projectids)->get();
         $technical_project_team_members = TechnicalProjectTeamMember::whereIn('project_id', $projectids)->get();
         $support_team_members = SupportTeamMember::whereIn('project_id', $projectids)->get();
         return view('audit.generate', compact('activities', 'projects', 'milestones', 'accomplishments', 'issues', 'risks', 'expenses', 'actions', 'deliverables', 'business_project_team_members', 'technical_project_team_members', 'support_team_members'));
     } elseif (Auth::user()->role == "System Administrator") {
         $activities = Activity::whereIn('action', array('Created', 'Deleted', 'Updated'))->where(function ($query) {
             return $query->where('action', '!=', 'Created')->orWhere('type', '!=', 'Deliverable');
         })->get();
         $projects = Project::all();
         $milestones = Milestone::all();
         $accomplishments = Accomplishment::all();
         $issues = Issue::all();
         $risks = Risk::all();
         $users = User::all();
         $expenses = Expense::all();
         $actions = Action::all();
         $deliverables = Deliverable::all();
         $business_project_team_members = BusinessProjectTeamMember::all();
         $technical_project_team_members = TechnicalProjectTeamMember::all();
         $support_team_members = SupportTeamMember::all();
         return view('audit.generate', compact('activities', 'projects', 'milestones', 'accomplishments', 'issues', 'risks', 'users', 'expenses', 'actions', 'deliverables', 'business_project_team_members', 'technical_project_team_members', 'support_team_members'));
     } else {
         flash()->error('You are not authorized to proceed.');
         return redirect()->action('ProjectsController@index');
     }
 }