/**
  * Show the application welcome screen to the user.
  *
  * @return Response
  */
 public function index()
 {
     $actif = 0;
     $preference = Preference::first();
     $notes = Note::where('etat', 1)->orderBy('created_at', 'desc')->paginate(5);
     $contacts = Contact::where('etat', 1)->orderBy('created_at', 'desc')->paginate(5);
     $societes = Societe::where('etat', 1)->orderBy('created_at', 'desc')->paginate(5);
     $devis = Devis::where('etat_devis', 1)->orderBy('created_at', 'desc')->paginate(5);
     return view('accueil', compact('actif', 'preference', 'notes', 'contacts', 'societes', 'devis'));
 }
 public function evenement(Request $request)
 {
     $groupe['null'] = '';
     $ListGroupeCRM = DB::table('groupes')->select('id', 'nom_groupe', 'date_groupe')->get();
     foreach ($ListGroupeCRM as $key => $value) {
         $groupe[$value->id] = $value->nom_groupe . ' ' . $value->date_groupe;
     }
     $id = $request->input('groupe');
     $visite = Societe::where('etat', 1)->where('groupe_id', $id)->count();
     $presentation = DB::table('societes')->join('contacts', 'societes.id', '=', 'contacts.societe_id')->join('notes', 'contacts.id', '=', 'notes.contact_id')->select('notes.*', 'contacts.nom_contact', 'societes.id AS ste')->where('societes.groupe_id', '=', $id)->where('societes.etat', '=', '1')->where('notes.categorie', '=', 'Réunion')->count();
     $actif = 'rapport';
     return view('rapport.event', compact('actif', 'visite', 'presentation', 'groupe', 'id'));
 }
 public function Trigroupe($tripar, $id)
 {
     //
     $actif = 'contact';
     $type = 3;
     if ($tripar == 'pays') {
         $societegr = Groupe::findOrFail($id)->societe()->where('etat', 1)->orderBy('pays_clt', 'asc')->get();
         $tri = 'pays';
     } elseif ($tripar == 'notes') {
         $note = DB::table('societes')->join('contacts', 'societes.id', '=', 'contacts.societe_id')->join('notes', 'contacts.id', '=', 'notes.contact_id')->select('societes.*', 'notes.*')->where('societes.etat', 1)->get();
         $societes = Societe::where('etat', 1)->orderBy('nom_clt', 'asc')->get();
         $tri = 'notes';
         // Tri des contacts sans note
         foreach ($societes as $key => $value) {
             $exist = 0;
             foreach ($note as $keyn => $valuen) {
                 if ($value->nom_clt == $valuen->nom_clt) {
                     $exist = 1;
                 }
             }
             if ($exist == 0) {
                 $societegr[] = $value;
             }
         }
     } elseif ($tripar == 'ajout') {
         $societegr = Groupe::findOrFail($id)->societe()->where('etat', 1)->orderBy('created_at', 'asc')->get();
         $tri = 'ajout';
     } elseif ($tripar == 'modification') {
         $societegr = Groupe::findOrFail($id)->societe()->where('etat', 1)->orderBy('udpated_at', 'asc')->get();
         $tri = 'modif';
     } elseif ($tripar == 'alpha') {
         $societegr = Groupe::findOrFail($id)->societe()->where('etat', 1)->orderBy('nom_clt', 'desc')->get();
         $tri = 'alpha';
     } elseif ($tripar == 'client') {
         $societegr = Groupe::findOrFail($id)->societe()->where('etat', 1)->orderBy('statut', 'asc')->get();
         $tri = 'client';
     }
     return view('contact.contact', compact('actif', 'societegr', 'type', 'tri', 'note'));
 }
 /**
  * Return Societe Sort to View.
  *
  * @param  int  $id
  * @return Response
  */
 public function TriSociete($tripar)
 {
     //
     $actif = 'contact';
     $type = 0;
     if ($tripar == 'pays') {
         $societe = Societe::where('etat', 1)->orderBy('pays_clt', 'asc')->get();
         $tri = 'pays';
     } elseif ($tripar == 'notes') {
         $societe = Societe::where('etat', 1)->orderBy('pays_clt', 'asc')->get();
         $tri = 'notes';
     } elseif ($tripar == 'groupe') {
         $societe = DB::table('societes')->leftjoin('groupes', 'societes.groupe_id', '=', 'groupes.id')->orderBy('groupes.nom_groupe', 'asc')->where('societes.etat', 1)->get();
         $tri = 'groupe';
     } elseif ($tripar == 'ajout') {
         $societe = Societe::where('etat', 1)->orderBy('created_at', 'desc')->get();
         $tri = 'ajout';
     } elseif ($tripar == 'modification') {
         $societe = Societe::where('etat', 1)->orderBy('updated_at', 'desc')->get();
         $tri = 'modif';
     } elseif ($tripar == 'alpha') {
         $societe = Societe::where('etat', 1)->orderBy('nom_clt', 'asc')->get();
         $tri = 'alpha';
     } elseif ($tripar == 'client') {
         $societe = Societe::where('etat', 1)->orderBy('nom_clt', 'asc')->get();
         $tri = 'client';
     }
     return view('contact.contact', compact('actif', 'societe', 'type', 'tri'));
 }
 /**
  * Return Societe Sort to View.
  *
  * @param  int  $id
  * @return Response
  */
 public function TriSociete($tripar)
 {
     //
     $actif = 'contact';
     $type = 0;
     if ($tripar == 'pays') {
         //$societe = Societe::where('etat',1)->orderBy('pays_clt','asc')->get();
         $societes = new Societe();
         $type = 4;
         $societe = $societes->sortable()->where('etat', 1)->get();
         $tri = 'pays';
         return view('contact.contact', compact('actif', 'societe', 'type', 'tri'));
     } elseif ($tripar == 'notes') {
         $note = DB::table('societes')->join('contacts', 'societes.id', '=', 'contacts.societe_id')->join('notes', 'contacts.id', '=', 'notes.contact_id')->select('societes.*', 'notes.*')->where('societes.etat', 1)->get();
         $societes = Societe::where('etat', 1)->orderBy('nom_clt', 'asc')->get();
         $tri = 'notes';
         // Tri des contacts sans note
         foreach ($societes as $key => $value) {
             $exist = 0;
             foreach ($note as $keyn => $valuen) {
                 if ($value->nom_clt == $valuen->nom_clt) {
                     $exist = 1;
                 }
             }
             if ($exist == 0) {
                 $societe[] = $value;
             }
         }
     } elseif ($tripar == 'groupe') {
         $societe = DB::table('groupes')->rightjoin('societes', 'societes.groupe_id', '=', 'groupes.id')->orderBy('groupes.nom_groupe', 'asc')->where('societes.etat', 1)->get();
         foreach ($societe as $value) {
             echo $value->nom_clt . ' => ' . $value->nom_groupe . ' => ' . $value->statut . '<br/>';
         }
         dd();
         $categorie = Societe::where('etat', 1)->orderBy('statut', 'asc')->get();
         $tri = 'groupe';
         return view('contact.contact', compact('actif', 'societe', 'type', 'tri', 'categorie', 'groupe'));
     } elseif ($tripar == 'ajout') {
         $societe = Societe::where('etat', 1)->orderBy('created_at', 'desc')->get();
         $tri = 'ajout';
     } elseif ($tripar == 'modification') {
         $societe = Societe::where('etat', 1)->orderBy('updated_at', 'desc')->get();
         $tri = 'modif';
     } elseif ($tripar == 'alpha') {
         $societe = Societe::where('etat', 1)->orderBy('nom_clt', 'desc')->get();
         $tri = 'alpha';
     } elseif ($tripar == 'client') {
         $societe = Societe::where('etat', 1)->orderBy('statut', 'asc')->get();
         $tri = 'client';
     }
     return view('contact.contact', compact('actif', 'societe', 'type', 'tri', 'note'));
 }