public function audit($id)
 {
     $company = Company::findOrFail($id);
     $logs = $company->logs;
     $audit = array();
     $labels = array('name' => 'Nome', 'cnpj' => 'CNPJ', 'insc' => 'Inscrição Estadual', 'phone1' => 'Telefone', 'phone2' => 'Telefone', 'email' => 'E-mail', 'address' => 'Endereço', 'number' => 'Número', 'comp' => 'Complemento', 'quarter' => 'Bairro', 'city' => 'Cidade', 'state' => 'Estado', 'country' => 'País', 'postalcode' => 'CEP');
     if ($logs) {
         foreach ($logs as $log) {
             foreach ($log->new_value as $key => $value) {
                 $audit[] = array('label' => $labels[$key], 'old' => testVal($log->old_value, $key) ? $log->old_value[$key] : '', 'new' => testVal($log->new_value, $key) ? $log->new_value[$key] : '', 'user' => $log->user->username, 'date' => date('d/m/Y H:i:s', strtotime($log->updated_at)));
             }
         }
     }
     $grid = \DataGrid::source($audit);
     $grid->attributes(array("class" => "table table-striped .table-condensed"));
     $grid->add('label', 'Campo');
     $grid->add('old', 'Valor Anterior');
     $grid->add('new', 'Novo Valor');
     $grid->add('user', 'Alterado por');
     $grid->add('date', 'Data/Hora da Alteração');
     $grid->paginate(10);
     return view('layouts.audit', compact('grid'));
 }
 public function audit($id)
 {
     $account = Account::findOrFail($id);
     $logs = $account->logs;
     $audit = array();
     $labels = array('name' => 'Nome', 'cpf_cnpj' => 'CPF/CNPJ', 'phone1' => 'Telefone', 'phone2' => 'Telefone', 'description' => 'Observações');
     if ($logs) {
         foreach ($logs as $log) {
             foreach ($log->new_value as $key => $value) {
                 $audit[] = array('label' => $labels[$key], 'old' => testVal($log->old_value, $key) ? $log->old_value[$key] : '', 'new' => testVal($log->new_value, $key) ? $log->new_value[$key] : '', 'user' => $log->user->username, 'date' => date('d/m/Y H:i:s', strtotime($log->updated_at)));
             }
         }
     }
     $grid = \DataGrid::source($audit);
     $grid->attributes(array("class" => "table table-striped .table-condensed"));
     $grid->add('label', 'Campo');
     $grid->add('old', 'Valor Anterior');
     $grid->add('new', 'Novo Valor');
     $grid->add('user', 'Alterado por');
     $grid->add('date', 'Data/Hora da Alteração');
     $grid->paginate(10);
     return view('layouts.audit', compact('grid'));
 }
 public function audit($id)
 {
     $device = Device::findOrFail($id);
     $logs = $device->logs;
     //dd($logs);
     $audit = array();
     $labels = array('name' => 'Identificação', 'serial' => 'Número de Série', 'model' => 'Modelo', 'company_id' => 'Empresa', 'vehicle_id' => 'Veículo', 'description' => 'Observações');
     if ($logs) {
         foreach ($logs as $log) {
             foreach ($log->new_value as $key => $value) {
                 switch ($key) {
                     case 'model':
                         $audit[] = array('label' => $labels[$key], 'old' => testVal($log->old_value, $key) ? fieldValue("devices", $log->old_value[$key]) : '[novo]', 'new' => fieldValue("devices", $value), 'user' => $log->user->username, 'date' => date('d/m/Y H:i:s', strtotime($log->updated_at)));
                         break;
                     case 'vehicle_id':
                         $audit[] = array('label' => $labels[$key], 'old' => testVal($log->old_value, $key) ? Vehicle::find($log->old_value[$key])->plate : '[não associado]', 'new' => testVal($log->new_value, $key) ? Vehicle::find($log->new_value[$key])->plate : '[não associado]', 'user' => $log->user->username, 'date' => date('d/m/Y H:i:s', strtotime($log->updated_at)));
                         break;
                     case 'company_id':
                         $audit[] = array('label' => $labels[$key], 'old' => testVal($log->old_value, $key) ? Company::find($log->old_value[$key])->name : '[não associado]', 'new' => testVal($log->new_value, $key) ? Company::find($log->new_value[$key])->name : '[não associado]', 'user' => $log->user->username, 'date' => date('d/m/Y H:i:s', strtotime($log->updated_at)));
                         break;
                     default:
                         $audit[] = array('label' => $labels[$key], 'old' => testVal($log->old_value, $key) ? $log->old_value[$key] : '', 'new' => testVal($log->new_value, $key) ? $log->new_value[$key] : '', 'user' => $log->user->username, 'date' => date('d/m/Y H:i:s', strtotime($log->updated_at)));
                         break;
                 }
             }
         }
     }
     $grid = \DataGrid::source($audit);
     $grid->attributes(array("class" => "table table-striped .table-condensed"));
     $grid->add('label', 'Campo');
     $grid->add('old', 'Valor Anterior');
     $grid->add('new', 'Novo Valor');
     $grid->add('user', 'Usuário');
     $grid->add('date', 'Data/Hora');
     $grid->orderBy('date', 'DESC');
     $grid->paginate(10);
     return view('layouts.audit', compact('grid'));
 }
 public function audit($id)
 {
     $user = User::findOrFail($id);
     $logs = $user->logs;
     $audit = array();
     $labels = array('name' => 'Nome', 'username' => 'Nome de Usuário', 'email' => 'E-mail', 'company_id' => 'Empresa', 'role' => 'Perfil');
     if ($logs) {
         foreach ($logs as $log) {
             foreach ($log->new_value as $key => $value) {
                 switch ($key) {
                     case 'role':
                         $audit[] = array('label' => $labels[$key], 'old' => testVal($log->old_value, $key) ? fieldValue("all_roles", $log->old_value[$key]) : '', 'new' => testVal($log->old_value, $key) ? fieldValue("all_roles", $log->new_value[$key]) : '', 'user' => $log->user->username, 'date' => date('d/m/Y H:i:s', strtotime($log->updated_at)));
                         break;
                     case 'company_id':
                         $audit[] = array('label' => $labels[$key], 'old' => testVal($log->old_value, $key) ? Company::find($log->old_value[$key])->name : '[não associado]', 'new' => testVal($log->new_value, $key) ? Company::find($log->new_value[$key])->name : '[não associado]', 'user' => $log->user->username, 'date' => date('d/m/Y H:i:s', strtotime($log->updated_at)));
                         break;
                     default:
                         $audit[] = array('label' => $labels[$key], 'old' => testVal($log->old_value, $key) ? $log->old_value[$key] : '', 'new' => testVal($log->new_value, $key) ? $log->new_value[$key] : '', 'user' => $log->user->username, 'date' => date('d/m/Y H:i:s', strtotime($log->updated_at)));
                         break;
                 }
             }
         }
     }
     $grid = \DataGrid::source($audit);
     $grid->attributes(array("class" => "table table-striped .table-condensed"));
     $grid->add('label', 'Campo');
     $grid->add('old', 'Valor Anterior');
     $grid->add('new', 'Novo Valor');
     $grid->add('user', 'Alterado por');
     $grid->add('date', 'Data/Hora da Alteração');
     $grid->paginate(10);
     return view('layouts.audit', compact('grid'));
 }
 public function audit($id)
 {
     $vehicle = Vehicle::findOrFail($id);
     $logs = $vehicle->logs;
     $audit = array();
     $labels = array('plate' => 'Placa', 'brand' => 'Marca', 'model' => 'Modelo', 'year' => 'Ano', 'color' => 'Cor', 'active' => 'Ativo', 'account_id' => 'Cliente');
     if ($logs) {
         foreach ($logs as $log) {
             foreach ($log->new_value as $key => $value) {
                 switch ($key) {
                     case 'active':
                         $audit[] = array('label' => $labels[$key], 'old' => testVal($log->old_value, $key) ? "Ativo" : "Inativo", 'new' => testVal($log->new_value, $key) ? "Ativo" : "Inativo", 'user' => $log->user->username, 'date' => date('d/m/Y H:i:s', strtotime($log->updated_at)));
                         break;
                     default:
                         $audit[] = array('label' => $labels[$key], 'old' => testVal($log->old_value, $key) ? $log->old_value[$key] : '', 'new' => testVal($log->new_value, $key) ? $log->new_value[$key] : '', 'user' => $log->user->username, 'date' => date('d/m/Y H:i:s', strtotime($log->updated_at)));
                         break;
                 }
             }
         }
     }
     $grid = \DataGrid::source($audit);
     $grid->attributes(array("class" => "table table-striped .table-condensed"));
     $grid->add('label', 'Campo');
     $grid->add('old', 'Valor Anterior');
     $grid->add('new', 'Novo Valor');
     $grid->add('user', 'Alterado por');
     $grid->add('date', 'Data/Hora da Alteração');
     $grid->paginate(10);
     return view('layouts.audit', compact('grid'));
 }