public function previous($level, $self)
 {
     if ($level < 0) {
         return null;
     } elseif ($level == 0) {
         return $self;
     } else {
         $previous = TicketHistory::where('id', '=', $self->previous_id)->first();
         return count($previous) ? $this->previous(--$level, $previous) : null;
     }
 }
 private function updateHistory($ticket)
 {
     $history = new TicketHistory();
     $last_history = TicketHistory::where('ticket_id', $ticket->id)->orderBy("created_at", "DESC")->first();
     $history->previous_id = count($last_history) ? $last_history->id : NULL;
     $history->changer_id = Auth::user()->active_contact->id;
     $history->ticket_id = $ticket->id;
     $history->title = $ticket->title;
     $history->post = $ticket->post;
     $history->creator_id = $ticket->creator_id;
     $history->assignee_id = $ticket->assignee_id;
     $history->status_id = $ticket->status_id;
     $history->priority_id = $ticket->priority_id;
     $history->division_id = $ticket->division_id;
     $history->equipment_id = $ticket->equipment_id;
     $history->company_id = $ticket->company_id;
     $history->contact_id = $ticket->contact_id;
     $history->level_id = $ticket->level_id;
     $history->job_type_id = $ticket->job_type_id;
     $history->emails = $ticket->emails;
     $history->save();
 }
Example #3
0
 public function diff($id_ticket_history1 = null, $id_ticket_history2 = null)
 {
     $changes = [];
     if (!isset($id_ticket_history1) && !isset($id_ticket_history2)) {
         $id_ticket_history1 = $this->anchestor(1)->id;
         $id_ticket_history2 = $this->anchestor(0)->id;
     } elseif (!isset($id_ticket_history2)) {
         $id_ticket_history2 = $this->anchestor(0)->id;
     }
     $assignee = DB::raw("CONCAT(assignees.last_name,' ',assignees.first_name) as assignee");
     $contact = DB::raw("CONCAT(contacts.last_name,' ',contacts.first_name) as contact");
     $equipment = DB::raw("CONCAT(COALESCE(NULLIF(equipment.serial_number, ''), '[ND]'),' - ',CONCAT(COALESCE(NULLIF(equipment.name, ''), '[ND]'))) as equipment");
     $tickets = TicketHistory::select('tickets_history.id', 'tickets_history.title', 'tickets_history.post', $assignee, 'divisions.name as division', $equipment, $contact, 'job_types.name as job_type', 'levels.name as level', 'priorities.name as priority', 'tickets_history.emails', 'statuses.name as status');
     $tickets->leftJoin('company_person as assignee_contacts', 'tickets_history.assignee_id', '=', 'assignee_contacts.id');
     $tickets->leftJoin('people as assignees', 'assignee_contacts.person_id', '=', 'assignees.id');
     $tickets->leftJoin('company_person as ticket_contacts', 'tickets_history.contact_id', '=', 'ticket_contacts.id');
     $tickets->leftJoin('people as contacts', 'ticket_contacts.person_id', '=', 'contacts.id');
     $tickets->leftJoin('equipment', 'equipment.id', '=', 'tickets_history.equipment_id');
     $tickets->leftJoin('divisions', 'divisions.id', '=', 'tickets_history.division_id');
     $tickets->leftJoin('job_types', 'job_types.id', '=', 'tickets_history.job_type_id');
     $tickets->leftJoin('priorities', 'priorities.id', '=', 'tickets_history.priority_id');
     $tickets->leftJoin('statuses', 'statuses.id', '=', 'tickets_history.status_id');
     $tickets->leftJoin('levels', 'levels.id', '=', 'tickets_history.level_id');
     $tickets->whereIn('tickets_history.id', [$id_ticket_history1, $id_ticket_history2]);
     $tickets->where('tickets_history.ticket_id', $this->id);
     $temp = $tickets->get()->toArray();
     foreach ($temp as $record) {
         $key = $record['id'] == $id_ticket_history1 ? 'first' : 'second';
         $result[$key] = $record;
     }
     if (isset($result['first']) && isset($result['second'])) {
         foreach ($result['first'] as $key => $attribute) {
             if ($result['first'][$key] != $result['second'][$key] && $key != 'id') {
                 $label = ucfirst(str_replace("_", " ", $key));
                 $changes[$label] = new \StdClass();
                 $changes[$label]->old = $result['first'][$key];
                 $changes[$label]->new = $result['second'][$key];
             }
         }
     }
     return $changes;
 }
 private function updateTicket($request)
 {
     $updated = false;
     $ticket = Ticket::find($request->get('ticket_id'));
     $status_id = $request->get('status_id');
     $priority_id = $request->get('priority_id');
     $ticket->status_id = $status_id;
     $ticket->priority_id = $priority_id;
     $updated = $ticket->isDirty();
     if ($updated) {
         $ticket->save();
         $history = new TicketHistory();
         $last_history = TicketHistory::where('ticket_id', $ticket->id)->orderBy("created_at", "DESC")->first();
         $history->previous_id = count($last_history) ? $last_history->id : NULL;
         $history->changer_id = Auth::user()->active_contact->id;
         $history->ticket_id = $ticket->id;
         $history->title = $ticket->title;
         $history->post = $ticket->post;
         $history->creator_id = $ticket->creator_id;
         $history->assignee_id = $ticket->assignee_id;
         $history->status_id = $ticket->status_id;
         $history->priority_id = $ticket->priority_id;
         $history->division_id = $ticket->division_id;
         $history->equipment_id = $ticket->equipment_id;
         $history->company_id = $ticket->company_id;
         $history->contact_id = $ticket->contact_id;
         $history->level_id = $ticket->level_id;
         $history->job_type_id = $ticket->job_type_id;
         $history->emails = $ticket->emails;
         $history->save();
     }
     return $updated;
 }