Example #1
0
 /**
  * View a blog post.
  *
  * @param  string  $slug
  * @return Redirect
  */
 public function postView($slug)
 {
     $user = $this->user->currentUser();
     // Get this blog post data
     $client = $this->client->where('slug', '=', $slug)->first();
     // Redirect to this blog post page
     return Redirect::to($slug);
 }
 /**
  * Display a listing of clients
  *
  * @return Response
  */
 public function index()
 {
     $user = Auth::user()->id;
     // Grab all the user clients
     $clients = $this->client->where('user_id', $user)->get();
     //Include  deleted clients
     if (Input::get('withTrashed')) {
     } else {
         if (Input::get('onlyTrashed')) {
             $clients = $this->client->onlyTrashed()->where('user_id', $user)->get();
         }
     }
     return View::make('clients.index', compact('clients'));
 }
Example #3
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $credit = Credit::createNew();
     $last_credit = Credit::where('account_id', '=', Auth::user()->account_id)->where('client_id', '=', Input::get('client'))->max('credit_number');
     if (!$last_credit) {
         $last_credit = 0;
     }
     $credit->setClient(Input::get('client'));
     //Client::getPrivateId(Input::get('client'));
     $dateparser = explode("/", Input::get('credit_date'));
     $date = $dateparser[2] . '-' . $dateparser[1] . '-' . $dateparser[0];
     $credit->setCreditDate(date($date));
     $credit->setAmount(Input::get('amount'));
     $credit->setBalance(Input::get('amount'));
     $credit->setPrivateNotes(trim(Input::get('private_notes')));
     $credit->setUser(Auth::user()->id);
     $credit->setCreditNumber($last_credit + 1);
     $error = $credit->guardar();
     if ($error) {
         Session::flash('error', $error);
         return Redirect::to('creditos/create');
     }
     $credit->save();
     Session::flash('message', 'Crédito creado con éxito');
     $client = Client::where('id', '=', Input::get('client'))->first();
     return Redirect::to('clientes/' . $client->public_id);
 }
Example #4
0
 public function authenticate()
 {
     $username = Input::get('username');
     $password = Input::get('password');
     $captcha_string = Input::get('g-recaptcha-response');
     $captcha_response = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret=6LcCwgATAAAAAKaXhPJOGPTBwX-n2-PPLZ7iupKj&response=' . $captcha_string);
     $captcha_json = json_decode($captcha_response);
     if ($captcha_json->success) {
         if (Auth::attempt(['loginClient' => $username, 'password' => $password], true)) {
             // Gestion de la connexion administrateur via le front-office
             $is_admin = Client::where('loginClient', '=', $username)->firstOrFail()->admin;
             if ($is_admin == '1') {
                 Session::put('admin', '1');
             } else {
                 Session::put('admin', '0');
             }
             Session::flash('flash_msg', "Vous êtes maintenant connecté.");
             Session::flash('flash_type', "success");
             return Redirect::to('/account');
         } else {
             Session::flash('flash_msg', "Identifiants incorrects, veuillez réessayer.");
             Session::flash('flash_type', "fail");
             return Redirect::to('/login');
         }
     } else {
         Session::flash('flash_msg', "Champ de vérification incorrect ou non coché.");
         Session::flash('flash_type', "fail");
         return Redirect::to(URL::previous());
     }
 }
Example #5
0
 public function testClientDeletePost()
 {
     $client = Client::where('name', '=', 'TestClient2')->firstOrFail();
     $this->call('POST', '/client/delete/' . $client->id);
     $this->assertRedirectedTo('/client/list');
     $this->assertSessionHas('success');
 }
Example #6
0
 public function __construct()
 {
     $this->beforeFilter('auth.admin');
     $this->hasUnverifiedUsers = Client::where('is_verified', '=', 0)->count();
     $this->hasUsersInWaitlist = Client::where('on_waitlist', '=', 1)->count();
     View::share('actionName', explode('@', Route::currentRouteAction())[1]);
     $this->userRules = array('email' => 'required|email', 'first_name' => 'required', 'last_name' => 'required');
 }
Example #7
0
 /**
  * Load the manage clients page.
  * @param String $lrs_id
  * @return View
  */
 public function manage($lrs_id)
 {
     $opts = ['user' => \Auth::user()];
     $lrs = $this->lrs->show($lrs_id, $opts);
     $lrs_list = $this->lrs->index($opts);
     $clients = \Client::where('lrs_id', $lrs->id)->get();
     return View::make('partials.client.manage', ['clients' => $clients, 'lrs' => $lrs, 'list' => $lrs_list]);
 }
Example #8
0
 public function show($id)
 {
     $group = Group::scope($id)->firstOrFail();
     print_r($group->id);
     $clients = Client::where('group_id', '=', $group->id)->select('clients.id', 'clients.nit', 'clients.name', 'clients.public_id')->get();
     $clientes = array();
     foreach ($clients as $key => $client) {
         array_push($clientes, $client);
     }
     return View::make('groups.show', array('group' => $group, 'clients' => $clientes, 'showBreadcrumbs' => false));
 }
Example #9
0
 public function dashboard()
 {
     $sucursales = Branch::where('account_id', Auth::user()->account_id)->get();
     $usuarios = Account::find(Auth::user()->account_id)->users;
     //$clientes = Account::find(Auth::user()->account_id)->clients;
     $clientes = Client::where('account_id', Auth::user()->account_id)->count();
     $productos = Account::find(Auth::user()->account_id)->products;
     $informacionCuenta = array('sucursales' => sizeof($sucursales), 'usuarios' => sizeof($usuarios), 'clientes' => $clientes, 'productos' => sizeof($productos));
     // return Response::json($informacionCuenta);
     return View::make('cuentas.dashboard')->with('cuenta', $informacionCuenta);
 }
 /**
  * Remove the specified resource from storage.
  * DELETE /users/{id}
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     // Delete everything related to the user
     Task::where('user_id', Auth::id())->delete();
     Credential::where('user_id', Auth::id())->delete();
     Project::where('user_id', Auth::id())->delete();
     Client::where('user_id', Auth::id())->delete();
     User::where('id', Auth::id())->delete();
     // Logout and redirect back to home page
     Auth::logout();
     return Redirect::to('/');
 }
Example #11
0
 /**
  * Run a general search.
  * @return  array of objects with the search results.
  */
 public function search()
 {
     $q = Input::get("q");
     // redirect user back if nothing was typed
     if (empty(trim($q))) {
         return Redirect::back();
     }
     $clients = Client::where('name', 'like', '%' . $q . '%')->whereUserId(Auth::id())->get();
     $projects = Project::where('name', 'like', '%' . $q . '%')->whereUserId(Auth::id())->get();
     $tasks = Task::where('name', 'like', '%' . $q . '%')->whereUserId(Auth::id())->get();
     $pTitle = "Search Results";
     return View::make('search', compact('q', 'clients', 'projects', 'tasks', 'pTitle'));
 }
Example #12
0
 public function getInvoices()
 {
     $invoices = Invoice::where('account_id', Auth::user()->account_id)->where('branch_id', Session::get('branch_id'))->select('public_id', 'invoice_status_id', 'client_id', 'invoice_number', 'invoice_date', 'importe_total', 'branch_name')->orderBy('public_id', 'DESC')->get();
     foreach ($invoices as $key => $invoice) {
         $invoice_razon = Client::where('account_id', Auth::user()->account_id)->select('name')->where('id', $invoice->client_id)->first();
         $invoice->razon = $invoice_razon->name;
         $estado = InvoiceStatus::where('id', $invoice->invoice_status_id)->first();
         $invoice->estado = $estado->name;
         $invoice->accion = "<a class='btn btn-primary btn-xs' data-task='view' href='factura/{$invoice->public_id}'  style='text-decoration:none;color:white;'><i class='glyphicon glyphicon-eye-open'></i></a> <a class='btn btn-warning btn-xs' href='copia/{$invoice->public_id}' style='text-decoration:none;color:white;'><i class='glyphicon glyphicon-duplicate'></i></a>";
     }
     $invoiceJson = ['data' => $invoices];
     return Response::json($invoiceJson);
 }
Example #13
0
 public function clientList($id = null)
 {
     if ($id == null) {
         $clients = Client::all(array('id', 'name'));
     } else {
         $clients = Client::where('id_user', '=', Auth::user()->id)->get(array('id', 'name'));
     }
     $clientsRow = array();
     $clientsRow[0] = "Cliente";
     foreach ($clients as $client) {
         $clientsRow[$client["id"]] = $client["name"];
     }
     return $clientsRow;
 }
Example #14
0
 public function updatemotdepasse($token)
 {
     $client = Client::where('token', '=', $token)->firstOrFail();
     $input = ["password1" => Input::get('password1'), "password2" => Input::get('password2'), "mdpClient" => Hash::make(Input::get('password1'))];
     $messages = array('required' => ":attribute est requis pour changer votre mot de passe.", 'same' => 'Les mots de passe ne correspondent pas', 'min' => "Le mot de passe entré est trop court (5 car. mini)");
     $rules = array('password1' => 'required|same:password2|min:5', 'password2' => 'required');
     $validator = Validator::make(Input::all(), $rules, $messages);
     if ($validator->fails()) {
         $messages = $validator->messages();
         return Redirect::to(URL::previous())->withErrors($validator);
     } else {
         Session::flash('flash_msg', "Le mot de passe a bien été changé.");
         Session::flash('flash_type', "success");
         $client->mdpClient = $input['mdpClient'];
         $client->token = '';
         $client->save();
         return Redirect::to("/login");
     }
 }
Example #15
0
 public function action_check_id()
 {
     try {
         $jwt = $this->authserver->getRequest()->get()['access_token'];
         //Get Token header and payload
         $content = JWT::decode($this->authserver->getRequest()->get()['access_token'], null, false);
         $client_id = DB::table('oauth_client_metadata')->where('key', 'website')->where('value', $content->aud)->first()->client_id;
         $client_secret = Client::where('id', $client_id)->first()->secret;
         //Verify Signature
         $response = JWT::decode($this->authserver->getRequest()->get()['access_token'], $client_secret);
     } catch (League\OAuth2\Server\Exception\ClientException $e) {
         // Throw an exception because there was a problem with the client's request
         $response = array('error' => $this->authserver->getExceptionType($e->getCode()), 'error_description' => $e->getMessage());
         // Set the correct header
         header($this->authserver->getExceptionHttpHeaders($this->authserver->getExceptionType($e->getCode()))[0]);
     } catch (Exception $e) {
         // Throw an error when a non-library specific exception has been thrown
         $response = array('error' => 'undefined_error', 'error_description' => $e->getMessage());
     }
     header('Content-type: application/json');
     echo json_encode($response);
 }
Example #16
0
 public static function findUserClient($id_client = null, $id_user = null)
 {
     return Client::where('id', '=', $id_client)->where('id_user', '=', $id_user)->first();
 }
 public function requestRevision()
 {
     $tripId = Input::get('trip_id');
     $carName = Input::get('car');
     $clientName = Input::get('client');
     $customerName = Input::get('customer_name');
     $customerEmail = Input::get('customer_email');
     $customerPhone = Input::get('customer_phone');
     $departureKm = Input::get('start_km');
     $arrivalKm = Input::get('end_km');
     $departureDateTime = Input::get('start_time');
     $arrivalDateTime = Input::get('end_time');
     $departureAddress = Input::get('departure_address');
     $arrivalAddress = Input::get('destination_address');
     $car = Cars::where('name', '=', substr($carName, 0, 3))->first();
     if ($car instanceof Cars) {
         $carId = $car->id;
     } else {
         $carId = '';
     }
     $client = Client::where('name', '=', $clientName)->first();
     if ($client instanceof Client) {
         $clientId = $client->id;
     } else {
         $clientId = '';
     }
     try {
         $myTrip = DailyTrips::find($tripId);
         $myTrip->edit_req = 1;
         $myTrip->save();
         $myTripRevison = new DailyTripsRevision();
         $myTripRevison->trip_id = $tripId;
         $myTripRevison->user_id = Session::get('user_id');
         $myTripRevison->car_id = $carId;
         $myTripRevison->client_id = $clientId;
         $myTripRevison->customer_name = $customerName;
         $myTripRevison->customer_email = $customerEmail;
         $myTripRevison->customer_phone = $customerPhone;
         $myTripRevison->departure_km = $departureKm;
         $myTripRevison->departure_date_time = $departureDateTime;
         $myTripRevison->arrival_km = $arrivalKm;
         $myTripRevison->arrival_date_time = $arrivalDateTime;
         $myTripRevison->departure_address = $departureAddress;
         $myTripRevison->arrival_address = $arrivalAddress;
         $myTripRevison->save();
         $results = array('success' => true, 'message' => 'revision requested');
     } catch (Exception $ex) {
         \Log::error(__METHOD__ . ' | error :' . print_r($ex, 1));
         $results = array('success' => false, 'message' => 'an error occurred');
     }
     return $results;
 }
Example #18
0
 private function seedTestUsersAndClients()
 {
     $resource_server = ResourceServer::first();
     // create users and clients ...
     User::create(array('identifier' => 'sebastian.marcet', 'external_identifier' => 13867, 'last_login_date' => gmdate("Y-m-d H:i:s", time())));
     $user = User::where('identifier', '=', 'sebastian.marcet')->first();
     OpenIdTrustedSite::create(array('user_id' => $user->id, 'realm' => 'https://www.test.com/', 'policy' => IAuthService::AuthorizationResponse_AllowForever));
     Client::create(array('app_name' => 'oauth2_test_app', 'app_description' => 'oauth2_test_app', 'app_logo' => null, 'client_id' => 'Jiz87D8/Vcvr6fvQbH4HyNgwTlfSyQ3x.openstack.client', 'client_secret' => 'ITc/6Y5N7kOtGKhg', 'client_type' => IClient::ClientType_Confidential, 'application_type' => IClient::ApplicationType_Web_App, 'user_id' => $user->id, 'rotate_refresh_token' => true, 'use_refresh_token' => true));
     Client::create(array('app_name' => 'oauth2.service', 'app_description' => 'oauth2.service', 'app_logo' => null, 'client_id' => '11z87D8/Vcvr6fvQbH4HyNgwTlfSyQ3x.openstack.client', 'client_secret' => '11c/6Y5N7kOtGKhg', 'client_type' => IClient::ClientType_Confidential, 'application_type' => IClient::ApplicationType_Service, 'user_id' => $user->id, 'rotate_refresh_token' => true, 'use_refresh_token' => true));
     Client::create(array('app_name' => 'oauth2_test_app_public', 'app_description' => 'oauth2_test_app_public', 'app_logo' => null, 'client_id' => 'Jiz87D8/Vcvr6fvQbH4HyNgwKlfSyQ3x.openstack.client', 'client_secret' => null, 'client_type' => IClient::ClientType_Public, 'application_type' => IClient::ApplicationType_JS_Client, 'user_id' => $user->id, 'rotate_refresh_token' => false, 'use_refresh_token' => false));
     Client::create(array('app_name' => 'oauth2_test_app_public_2', 'app_description' => 'oauth2_test_app_public_2', 'app_logo' => null, 'client_id' => 'Jiz87D8/Vcvr6fvQbH4HyNgwKlfSyQ2x.openstack.client', 'client_secret' => null, 'client_type' => IClient::ClientType_Public, 'application_type' => IClient::ApplicationType_JS_Client, 'user_id' => $user->id, 'rotate_refresh_token' => false, 'use_refresh_token' => false));
     Client::create(array('app_name' => 'resource_server_client', 'app_description' => 'resource_server_client', 'app_logo' => null, 'client_id' => 'resource.server.1.openstack.client', 'client_secret' => '123456789', 'client_type' => IClient::ClientType_Confidential, 'application_type' => IClient::ApplicationType_Service, 'resource_server_id' => $resource_server->id, 'rotate_refresh_token' => false, 'use_refresh_token' => false));
     $client_confidential = Client::where('app_name', '=', 'oauth2_test_app')->first();
     $client_public = Client::where('app_name', '=', 'oauth2_test_app_public')->first();
     $client_service = Client::where('app_name', '=', 'oauth2.service')->first();
     //attach scopes
     $scopes = ApiScope::get();
     foreach ($scopes as $scope) {
         $client_confidential->scopes()->attach($scope->id);
         $client_public->scopes()->attach($scope->id);
         $client_service->scopes()->attach($scope->id);
     }
     //add uris
     ClientAuthorizedUri::create(array('uri' => 'https://www.test.com/oauth2', 'client_id' => $client_confidential->id));
     //add uris
     ClientAllowedOrigin::create(array('allowed_origin' => 'https://www.test.com/oauth2', 'client_id' => $client_confidential->id));
     ClientAuthorizedUri::create(array('uri' => 'https://www.test.com/oauth2', 'client_id' => $client_public->id));
 }
Example #19
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);
     }
 }
Example #20
0
 public function enviarCorreoFactura($min = 0, $max = 0)
 {
     //todotix http
     $min = Input::get('min');
     $max = Input::get('max');
     $branch = 1;
     $cuenta = Account::where('domain', 'roy')->where('id', 1)->first();
     $invoices = Invoice::where('account_id', $cuenta->id)->where('branch_id', $branch)->where('public_id', '>=', $min)->where('public_id', '<=', $max)->get();
     $count = 1;
     foreach ($invoices as $key => $invoice) {
         $client = Client::where('id', $invoice->client_id)->select('name', 'business_name', 'nit')->first();
         if (filter_var($client->name, FILTER_VALIDATE_EMAIL)) {
             $this->sendInvoiceByMailLocal($client->name, $client->business_name, $invoice->id, $invoice->invoice_date, $client->nit);
             echo $count . " " . $client->name . " " . $invoice->control_code . " " . $invoice->invoice_number . "<br>";
             sleep(0.2);
             $count = $count + 1;
         }
     }
 }
Example #21
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     //return 0;
     // return Response::json(Input::all());
     // $rules = array(
     //           'client' => 'required',
     //           'invoice' => 'required',
     //           'amount' => 'required'
     //       );
     //       if (Input::get('invoice')) {
     //           $invoice = Invoice::scope(Input::get('invoice'))->firstOrFail();
     //           $rules['amount'] .= '|less_than:' . $invoice->balance;
     //       }
     //       if (Input::get('payment_type_id') == PAYMENT_TYPE_CREDIT)
     //       {
     //           $rules['payment_type_id'] = 'has_credit:' . Input::get('client') . ',' . Input::get('amount');
     //       }
     //       $messages = array(
     //     'required' => 'El campo es Requerido',
     //     'positive' => 'El Monto debe ser mayor a cero',
     //     'less_than' => 'El Monto debe ser menor o igual a ' . $invoice->balance,
     //     'has_credit' => 'El Cliente no tiene crédito suficiente'
     // );
     //       $validator = \Validator::make(Input::all(), $rules, $messages);
     //       if ($validator->fails())
     //       {
     //           $url = 'pagos/create';
     //           return Redirect::to($url)
     //               ->withErrors($validator)
     //               ->withInput();
     //       }
     //       else
     //       {
     $payment = Payment::createNew();
     $paymentTypeId = Input::get('payment_type_id');
     $clientId = Input::get('client');
     $amount = floatval(Input::get('amount'));
     // if ($paymentTypeId == PAYMENT_TYPE_CREDIT)
     // {
     //     $credits = Credit::scope()->where('client_id', '=', $clientId)
     //                 ->where('balance', '>', 0)->orderBy('created_at')->get();
     //     $applied = 0;
     //     foreach ($credits as $credit)
     //     {
     //         $applied += $credit->apply($amount);
     //         if ($applied >= $amount)
     //         {
     //             break;
     //         }
     //     }
     // }
     //                $payment->client_id = $clientId;
     //	        $payment->invoice_id =Input::get('invoice');
     //	        $payment->payment_type_id = $paymentTypeId;
     //	       	$payment->user_id = Auth::user()->id;
     //	        $payment->payment_date =  date("Y-m-d",strtotime(Input::get('payment_date')));
     //	        $payment->amount = $amount;
     //	        $payment->transaction_reference = trim(Input::get('transaction_reference'));
     $payment->setClientId($clientId);
     $payment->setInvoiceId(Input::get('invoice'));
     $payment->setPaymentTypeId($paymentTypeId);
     $payment->setUserId(Auth::user()->id);
     $dateparser = explode("/", Input::get('payment_date'));
     $date = $dateparser[2] . '-' . $dateparser[1] . '-' . $dateparser[0];
     $payment->setPaymentDate($date);
     $payment->setAmount($amount);
     $payment->setTransactionReference(trim(Input::get('transaction_reference')));
     $error = $payment->guardar();
     if ($error) {
         Session::flash('error', $error);
         return Redirect::to('pagos/create');
     }
     $payment->save();
     $cliente = Client::find($payment->client_id);
     $cliente->balance = $cliente->balance - $payment->amount;
     $cliente->paid_to_date = $cliente->paid_to_date + $payment->amount;
     $cliente->save();
     $invoice = Invoice::find($payment->invoice_id);
     $invoice->balance = $invoice->balance - $payment->amount;
     $invoice->save();
     if ($paymentTypeId == PAYMENT_TYPE_CREDIT) {
         $credits = Credit::scope()->where('client_id', '=', $clientId)->where('balance', '>', 0)->orderBy('created_at')->get();
         $applied = 0;
         foreach ($credits as $credit) {
             $applied += $credit->apply($amount);
             if ($applied >= $amount) {
                 break;
             }
         }
     }
     $paymentName = PaymentType::where('id', '=', $paymentTypeId)->first();
     if ($invoice->balance == 0) {
         // $invoice->invoice_status_id = INVOICE_STATUS_PAID;
         Utils::addNote($invoice->id, '<b>' . $invoice->getClientName() . ': </b>Totalmente pagada;&nbsp;&nbsp; se pagó:<b>' . $payment->amount . '</b>Bs, con <b>' . $paymentName->name . '</b>', INVOICE_STATUS_PAID);
     } else {
         // $invoice->invoice_status_id = INVOICE_STATUS_PARTIAL;
         Utils::addNote($invoice->id, '<b>' . $invoice->getClientName() . ': </b>Parcialmente pagado;&nbsp;&nbsp; se pagó:<b>' . $payment->amount . '</b> Bs, con <b>' . $paymentName->name . '</b>', INVOICE_STATUS_PARTIAL);
     }
     Session::flash('message', 'Pago creado con éxito');
     $client = Client::where('id', '=', Input::get('client'))->first();
     return Redirect::to('clientes/' . $client->public_id);
     // }
 }
 public function users()
 {
     $users = Client::where('admin', '=', '1')->get();
     return View::make('private.pages.users')->with('users', $users);
 }
Example #23
0
 /** Find Client by Id
  *
  * @param $client_id
  *
  * @return bool
  */
 public function getClientById($client_id)
 {
     $this->model = Client::where('id', '=', $client_id)->get();
     if ($this->model->count() === 1) {
         $this->model = $this->model->first();
         return true;
     }
     return false;
 }
Example #24
0
 private function validateShatterExcel($invoices)
 {
     $stackAstray = "";
     foreach ($invoices as $invoice) {
         $client = Client::where('account_id', Auth::user()->account_id)->where('public_id', $invoice['id'])->where('nit', $invoice['nit'])->first();
         if (!$client) {
             $stackAstray .= "El cliente " . $invoice['id'] . " con NIT: " . $invoice['nit'] . " no existe<br>";
         }
         foreach ($invoice['products'] as $pro) {
             $product = Product::where('account_id', Auth::user()->account_id)->where('product_key', $pro['product_key'])->first();
             if (!$product) {
                 $stackAstray .= "El producto con codigo: " . $pro['product_key'] . " no existe<br>";
             }
             //                else
             //                    echo $product->name;
         }
     }
     if ($stackAstray != "") {
         $stackAstray .= "Revise el documento y vuelva a intentar.";
     }
     return $stackAstray;
 }
 public function utilisateurs()
 {
     $utilisateurs = Client::where('admin', '=', '0')->get();
     return View::make('private.pages.utilisateurs')->with('utilisateurs', $utilisateurs);
 }
Example #26
0
 public function indexDown($name = null, $numero = null, $nit = null, $telefono = null, $matricula = null)
 {
     $name = Input::get('name');
     $numero = Input::get('numero');
     $nit = Input::get('nit');
     $telefono = Input::get('telefono');
     $matricula = Input::get('matricula');
     if (Session::get('sw') == 'DESC') {
         Session::put('sw', 'ASC');
     } else {
         Session::put('sw', 'DESC');
     }
     $sw = Session::get('sw');
     if (!$numero && !$name && !$nit && !$telefono && !$matricula) {
         $clientes = Client::where('account_id', Auth::user()->account_id)->select('public_id', 'name', 'nit', 'custom_value4', 'work_phone')->orderBy('public_id', $sw)->simplePaginate(15);
         //  return View::make('clientes.index', array('clients' => $clientes));
         return View::make('clientes.index', array('clients' => $clientes, 'sw' => 'ASC'));
     }
     if ($numero) {
         $clientes = Client::where('account_id', Auth::user()->account_id)->select('public_id', 'name', 'nit', 'custom_value4', 'work_phone')->where('public_id', 'like', $numero . "%")->orderBy('public_id', $sw)->simplePaginate(15);
         $data = ['clients' => $clientes, 'numero' => $numero, 'name' => $name, 'nit' => $nit, 'telefono' => $telefono];
         return View::make('clientes.index', $data);
     }
     if ($name) {
         $clientes = Client::where('account_id', Auth::user()->account_id)->select('public_id', 'name', 'nit', 'custom_value4', 'work_phone')->where('name', 'like', $name . "%")->orderBy('name', $sw)->simplePaginate(15);
         $data = ['clients' => $clientes, 'numero' => $numero, 'name' => $name, 'nit' => $nit, 'telefono' => $telefono];
         return View::make('clientes.index', $data);
     }
     if ($nit) {
         $clientes = Client::where('account_id', Auth::user()->account_id)->select('public_id', 'name', 'nit', 'custom_value4', 'work_phone')->where('nit', 'like', $nit . "%")->orderBy('nit', $sw)->simplePaginate(15);
         $data = ['clients' => $clientes, 'numero' => $numero, 'name' => $name, 'nit' => $nit, 'telefono' => $telefono];
         return View::make('clientes.index', $data);
     }
     if ($telefono) {
         $clientes = Client::where('account_id', Auth::user()->account_id)->select('public_id', 'name', 'nit', 'custom_value4', 'work_phone')->where('work_phone', 'like', $telefono . "%")->orderBy('work_phone', $sw)->simplePaginate(15);
         $data = ['clients' => $clientes, 'numero' => $numero, 'name' => $name, 'nit' => $nit, 'telefono' => $telefono];
         return View::make('clientes.index', $data);
     }
     if ($matricula) {
         $clientes = Client::where('account_id', Auth::user()->account_id)->select('public_id', 'name', 'nit', 'custom_value4', 'work_phone')->where('custom_value4', 'like', $matricula . "%")->orderBy('custom_value4', $sw)->simplePaginate(15);
         $data = ['clients' => $clientes, 'numero' => $numero, 'name' => $name, 'nit' => $nit, 'telefono' => $telefono, 'matricula' => $matricula];
         return View::make('clientes.index', $data);
     }
 }
 /**
  * Destroys the model with the given ID and options.
  * @param String $lrs_id ID to match.
  * @param [String => Mixed] $opts
  * @return Boolean
  */
 public function destroy($lrs_id, array $opts)
 {
     // Delete related documents from client and oauth_clients collections.
     $clients = ClientModel::where('lrs_id', $lrs_id)->get();
     foreach ($clients as $client) {
         $client->delete();
     }
     StatementModel::where('lrs_id', $lrs_id)->delete();
     return parent::destroy($lrs_id, $opts);
 }
Example #28
0
 public function cliente($nit)
 {
     // $cuenta = Account::find(Auth::user()->account_id);
     // $client =  DB::table('clients')->select('id','public_id','name','nit')->where('account_id',$user->account_id)->where('nit',$public_id)->first();
     $client = Client::where('account_id', Auth::user()->account_id)->where('nit', $nit)->first();
     if ($client != null) {
         $datos = array('resultado' => 0, 'cliente' => $client);
         return Response::json($datos);
     }
     $datos = array('resultado' => 1, 'mensaje' => 'cliente no encontrado');
     return Response::json($datos);
 }
 public function testDoubleSaveManyToMany()
 {
     $user = User::create(array('name' => 'John Doe'));
     $client = Client::create(array('name' => 'Admins'));
     $user->clients()->save($client);
     $user->clients()->save($client);
     $user->save();
     $this->assertEquals(1, $user->clients()->count());
     $this->assertEquals(array($user->_id), $client->user_ids);
     $this->assertEquals(array($client->_id), $user->client_ids);
     $user = User::where('name', 'John Doe')->first();
     $client = Client::where('name', 'Admins')->first();
     $this->assertEquals(1, $user->clients()->count());
     $this->assertEquals(array($user->_id), $client->user_ids);
     $this->assertEquals(array($client->_id), $user->client_ids);
     $user->clients()->save($client);
     $user->clients()->save($client);
     $user->save();
     $this->assertEquals(1, $user->clients()->count());
     $this->assertEquals(array($user->_id), $client->user_ids);
     $this->assertEquals(array($client->_id), $user->client_ids);
 }
Example #30
0
 public function pagoCliente($client_id, $invoice_id)
 {
     $client = Client::where('id', $client_id)->first();
     $invoice = Invoice::where('id', $invoice_id)->first();
     $dato = ['now' => date('d/m/Y'), 'cliente' => $client->name, 'client_id' => $client->id, 'factura' => 'Factura #' . $invoice->invoice_number . ' Importe Total ' . $invoice->importe_total . '(' . $invoice->balance . ')', 'invoice_id' => $invoice->id, 'amount' => $invoice->balance];
     return View::make('pagos.createCustom', $dato);
 }