Esempio n. 1
0
 /**
  * list of all agents and returning lists array of id and name
  * @param integer $cat_id
  * @return bool
  */
 public function scopeAgentsLists($query, $cat_id = null)
 {
     if ($cat_id == null) {
         return $query->where('ticketit_agent', '1')->lists('name', 'id')->toArray();
     }
     return Category::find($cat_id)->agents->lists('name', 'id')->toArray();
 }
 public function index($indicator_period = 2)
 {
     $tickets_count = Ticket::count();
     $open_tickets_count = Ticket::whereNull('completed_at')->count();
     $closed_tickets_count = Ticket::whereNotNull('completed_at')->count();
     // Per Category pagination
     $categories = Category::paginate(10, ['*'], 'cat_page');
     // Total tickets counter per category for google pie chart
     $categories_all = Category::all();
     $categories_share = [];
     foreach ($categories_all as $cat) {
         $categories_share[$cat->name] = $cat->tickets()->count();
     }
     // Total tickets counter per agent for google pie chart
     $agents_all = Agent::agents();
     $agents_share = [];
     foreach ($agents_all as $agent_single) {
         $agents_share[$agent_single->name] = $agent_single->agentTickets(false)->count() + $agent_single->agentTickets(true)->count();
     }
     // Per Agent
     $agents = Agent::agents(10);
     // Per User
     $users = Agent::users(10);
     // Per Category performance data
     $ticketController = new TicketsController(new Ticket(), new Agent());
     $monthly_performance = $ticketController->monthlyPerfomance($indicator_period);
     return view('ticketit::admin.index', compact('open_tickets_count', 'closed_tickets_count', 'tickets_count', 'categories', 'agents', 'users', 'monthly_performance', 'categories_share', 'agents_share'));
 }
Esempio n. 3
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($id)
 {
     $ticket = Models\Ticket::find($id);
     $status_lists = Models\Status::lists('name', 'id');
     $priority_lists = Models\Priority::lists('name', 'id');
     $category_lists = Models\Category::lists('name', 'id');
     $agent_lists = ['auto' => 'Auto Select'] + Models\Agent::agentsLists($ticket->category_id);
     $comments = $ticket->comments()->paginate(config('ticketit.paginate_items'));
     return view('ticketit::tickets.show', compact('ticket', 'status_lists', 'priority_lists', 'category_lists', 'agent_lists', 'comments'));
 }
Esempio n. 4
0
 /**
  * Calculate average closing period of days per category for number of months
  * @param int $period
  * @return \Illuminate\Database\Eloquent\Collection|static[]
  */
 public function monthlyPerfomance($period = 2)
 {
     $categories = Category::all();
     foreach ($categories as $cat) {
         $records['categories'][] = $cat->name;
     }
     for ($m = $period; $m >= 0; $m--) {
         $from = Carbon::now();
         $from->day = 1;
         $from->subMonth($m);
         $to = Carbon::now();
         $to->day = 1;
         $to->subMonth($m);
         $to->endOfMonth();
         $records['interval'][$from->format('F Y')] = [];
         foreach ($categories as $cat) {
             $records['interval'][$from->format('F Y')][] = round($this->intervalPerformance($from, $to, $cat->id), 1);
         }
     }
     return $records;
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $category = Category::findOrFail($id);
     $name = $category->name;
     $category->delete();
     Session::flash('status', trans('ticketit::lang.category-name-has-been-deleted', ['name' => $name]));
     return redirect()->action('\\Kordy\\Ticketit\\Controllers\\CategoriesController@index');
 }
Esempio n. 6
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $category = Category::findOrFail($id);
     $name = $category->name;
     $category->delete();
     Session::flash('status', "The category {$name} has been deleted!");
     return redirect()->action('\\Kordy\\Ticketit\\Controllers\\CategoriesController@index');
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Model::unguard();
     $faker = \Faker\Factory::create();
     // create agents
     $agents_counter = 1;
     for ($a = 1; $a <= $this->agents_qty; $a++) {
         $agent_info = new \App\User();
         $agent_info->name = $faker->name;
         $agent_info->email = 'agent' . $agents_counter . $this->email_domain;
         $agent_info->ticketit_agent = 1;
         $agent_info->password = Hash::make($this->default_agent_password);
         $agent_info->save();
         $agents[$agent_info->id] = $agent_info;
         $agents_counter++;
     }
     // create tickets statuses
     foreach ($this->statuses as $name => $color) {
         $status = \Kordy\Ticketit\Models\Status::create(['name' => $name, 'color' => $color]);
     }
     $counter = 0;
     // create tickets statuses
     foreach ($this->categories as $name => $color) {
         $category = \Kordy\Ticketit\Models\Category::create(['name' => $name, 'color' => $color]);
         $agent = array_rand($agents, $this->agents_per_category);
         $category->agents()->attach($agent);
         $counter++;
     }
     // create tickets statuses
     foreach ($this->priorities as $name => $color) {
         $priority = \Kordy\Ticketit\Models\Priority::create(['name' => $name, 'color' => $color]);
     }
     $categories_qty = \Kordy\Ticketit\Models\Category::count();
     $priorities_qty = \Kordy\Ticketit\Models\Priority::count();
     $statuses_qty = \Kordy\Ticketit\Models\Status::count();
     // create users
     $users_counter = 1;
     for ($u = 1; $u <= $this->users_qty; $u++) {
         $user_info = new \App\User();
         $user_info->name = $faker->name;
         $user_info->email = 'user' . $users_counter . $this->email_domain;
         $user_info->ticketit_agent = 0;
         $user_info->password = Hash::make($this->default_user_password);
         $user_info->save();
         $users_counter++;
         $tickets_qty = rand($this->tickets_per_user_min, $this->tickets_per_user_max);
         for ($t = 1; $t <= $tickets_qty; $t++) {
             $rand_category = rand(1, $categories_qty);
             $priority_id = rand(1, $priorities_qty);
             do {
                 $rand_status = rand(1, $statuses_qty);
             } while ($rand_status == $this->default_closed_status_id);
             $category = \Kordy\Ticketit\Models\Category::find($rand_category);
             $agents = $category->agents()->lists('name', 'id')->toArray();
             $agent_id = array_rand($agents);
             $random_create = rand(1, $this->tickets_date_period);
             $random_complete = rand($this->tickets_min_close_period, $this->tickets_max_close_period);
             $ticket = new \Kordy\Ticketit\Models\Ticket();
             $ticket->subject = $faker->text(50);
             $ticket->content = $faker->paragraph($nbSentences = 10);
             $ticket->status_id = $rand_status;
             $ticket->priority_id = $priority_id;
             $ticket->user_id = $user_info->id;
             $ticket->agent_id = $agent_id;
             $ticket->category_id = $rand_category;
             $ticket->created_at = \Carbon\Carbon::now()->subDays($random_create);
             $ticket->updated_at = \Carbon\Carbon::now()->subDays($random_create);
             $completed_at = new Carbon($ticket->created_at);
             if (!$completed_at->addDays($random_complete)->gt(\Carbon\Carbon::now())) {
                 $ticket->completed_at = $completed_at;
                 $ticket->updated_at = $completed_at;
                 $ticket->status_id = $this->default_closed_status_id;
             }
             $ticket->save();
             $comments_qty = rand($this->comments_per_ticket_min, $this->comments_per_ticket_max);
             for ($c = 1; $c <= $comments_qty; $c++) {
                 if (is_null($ticket->completed_at)) {
                     $random_comment_date = $faker->dateTimeBetween('-' . $random_create . ' days', 'now');
                 } else {
                     $random_comment_date = $faker->dateTimeBetween('-' . $random_create . ' days', '-' . ($random_create - $random_complete) . ' days');
                 }
                 $comment = new \Kordy\Ticketit\Models\Comment();
                 $comment->ticket_id = $ticket->id;
                 $comment->content = $faker->paragraph($nbSentences = 10);
                 if ($c % 2 == 0) {
                     $comment->user_id = $ticket->user_id;
                 } else {
                     $comment->user_id = $ticket->agent_id;
                 }
                 $comment->created_at = $random_comment_date;
                 $comment->updated_at = $random_comment_date;
                 $comment->save();
             }
             $last_comment = $ticket->Comments->sortByDesc('created_at')->first();
             $ticket->updated_at = $last_comment['created_at'];
             $ticket->save();
         }
     }
 }