Example #1
0
 public function indexDown($name = null, $numero = null, $nit = null, $group = null, $contact = null)
 {
     $name = Input::get('name');
     $numero = Input::get('numero');
     $nit = Input::get('nit');
     $group = Input::get('group');
     $contact = Input::get('contact');
     if (Session::get('sw') == 'DESC') {
         Session::put('sw', 'ASC');
     } else {
         Session::put('sw', 'DESC');
     }
     $sw = Session::get('sw');
     if ($numero == "" && $name == "" && $nit == "" && $group == "" && $contact == "") {
         $clientes = Client::where('account_id', Auth::user()->account_id)->select('id', 'business_name', 'nit', 'created_at', 'group_id')->orderBy('id', $sw)->simplePaginate(30);
         foreach ($clientes as $key => $client) {
             $contacts = Contact::where('account_id', Auth::user()->account_id)->select('first_name', 'last_name')->where('client_id', $client->id)->first();
             $client->contacto_first_name = $contacts->first_name;
             $client->contacto_last_name = $contacts->last_name;
         }
         return View::make('clientes.index', array('clients' => $clientes, 'sw' => 'ASC', 'contacts' => $contacts));
     }
     if ($numero) {
         $clientes = Client::where('account_id', Auth::user()->account_id)->select('id', 'business_name', 'nit', 'created_at', 'group_id')->where('id', 'like', $numero . "%")->orderBy('id', $sw)->simplePaginate(30);
         foreach ($clientes as $key => $client) {
             $contacts = Contact::where('account_id', Auth::user()->account_id)->select('first_name', 'last_name')->where('client_id', $client->id)->first();
             $client->contacto_first_name = $contacts->first_name;
             $client->contacto_last_name = $contacts->last_name;
         }
         $data = ['clients' => $clientes, 'numero' => $numero, 'name' => $name, 'nit' => $nit, 'create' => $create];
         return View::make('clientes.index', $data);
     }
     if ($name) {
         $clientes = Client::where('account_id', Auth::user()->account_id)->select('id', 'business_name', 'nit', 'created_at', 'group_id')->where('business_name', 'like', $name . "%")->orderBy('business_name', $sw)->simplePaginate(30);
         //  $clientes = Client::join('contacts', 'clients.id' ,'=', 'contacts.client_id')
         //  ->where('business_name', 'like', $name."%")
         //  ->select('clients.id', 'clients.business_name', 'clients.nit', 'clients.created_at', 'contacts.first_name', 'contacts.last_name')
         //  ->orderBy('business_name', $sw)
         //  ->simplePaginate(30);
         foreach ($clientes as $key => $client) {
             $contacts = Contact::where('account_id', Auth::user()->account_id)->select('first_name', 'last_name')->where('client_id', $client->id)->first();
             $client->contacto_first_name = $contacts->first_name;
             $client->contacto_last_name = $contacts->last_name;
         }
         // return $clientes;
         $data = ['clients' => $clientes, 'numero' => $numero, 'name' => $name, 'nit' => $nit, 'create' => $create];
         return View::make('clientes.index', $data);
     }
     if ($nit) {
         $clientes = Client::where('account_id', Auth::user()->account_id)->select('id', 'business_name', 'nit', 'created_at', 'group_id')->where('nit', 'like', $nit . "%")->orderBy('nit', $sw)->simplePaginate(30);
         foreach ($clientes as $key => $client) {
             $contacts = Contact::where('account_id', Auth::user()->account_id)->select('first_name', 'last_name')->where('client_id', $client->id)->first();
             $client->contacto_first_name = $contacts->first_name;
             $client->contacto_last_name = $contacts->last_name;
         }
         $data = ['clients' => $clientes, 'numero' => $numero, 'name' => $name, 'nit' => $nit, 'create' => $create];
         return View::make('clientes.index', $data);
     }
     //  if ($create) {
     //
     // 		$clientes = Client::where('account_id', Auth::user()->account_id)
     // 	 ->select('id', 'business_name', 'nit', 'created_at', 'group_id')
     // 	 ->where('created_at', 'like', $create."%")
     // 	 ->orderBy('created_at', $sw)
     // 	 ->simplePaginate(30);
     // 			 foreach ($clientes as $key => $client) {
     // 				 $contacts = Contact::where('account_id', Auth::user()->account_id)
     // 				 ->select('first_name', 'last_name')
     // 				 ->where('client_id', $client->id)
     // 				 ->first();
     // 				 $client->contacto_first_name = $contacts->first_name;
     // 				 $client->contacto_last_name = $contacts->last_name;
     // 			 }
     //
     // 	 $data = [
     // 		 'clients' => $clientes,
     // 		 'numero' => $numero,
     // 		 'name' => $name,
     // 		 'nit' => $nit,
     // 		 'create' => $create
     // 	 ];
     // 	 return View::make('clientes.index', $data);
     //  }
     if ($group) {
         $clientes = Client::join('groups', 'clients.group_id', '=', 'groups.id')->select('clients.id', 'clients.nit', 'clients.business_name', 'clients.created_at', 'clients.group_id')->where('groups.name', 'like', $group . '%')->orderBy('groups.name', $sw)->simplePaginate(30);
         foreach ($clientes as $key => $client) {
             $contacts = Contact::where('account_id', Auth::user()->account_id)->select('first_name', 'last_name')->where('client_id', $client->id)->first();
             $client->contacto_first_name = $contacts->first_name;
             $client->contacto_last_name = $contacts->last_name;
         }
         $data = ['clients' => $clientes, 'group' => $group];
         return View::make('clientes.index', $data);
     }
     if ($contact) {
         $clientes = Client::join('contacts', 'clients.id', '=', 'contacts.client_id')->select('clients.id', 'clients.nit', 'clients.business_name', 'clients.created_at', 'clients.group_id', 'contacts.first_name', 'contacts.last_name')->where('contacts.first_name', 'like', $contact . "%")->orderBy('contacts.first_name', $sw)->simplePaginate(30);
         foreach ($clientes as $key => $client) {
             $client->contacto_first_name = $client->first_name;
             $client->contacto_last_name = $client->last_name;
         }
         $data = ['clients' => $clientes, 'contact' => $contact];
         return View::make('clientes.index', $data);
     }
 }