/**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index(Request $request)
 {
     $country = Country::find($request->country_id);
     $city = City::find($request->city_id);
     $state = State::find($request->state_id);
     return ['country' => $country->name, 'city' => $city->name, 'state' => $state->name];
 }
 public function saveReferees(Season $season, Competition $competition, Request $request)
 {
     $data = $request->all();
     $competition->referees()->wherePivot('season_id', '=', $season->id)->detach();
     $pairs = $this->getPairs($season, $competition);
     foreach ($pairs as $pair) {
         $pair->active = 0;
         $pair->save();
     }
     $response = ['refs' => array(), 'crefs' => array()];
     $country = Country::find($data['country']);
     $refs = json_decode($data['referees'], true);
     foreach ($refs as $ref) {
         $newRef = $competition->storeReferee($ref, $season, 0, $country);
         if (array_key_exists('styled', $ref)) {
             if ($ref['styled'] == 'new') {
                 $newRef['location'] = Location::find($newRef->location_id)->name;
                 array_push($response['refs'], $newRef);
             }
         }
     }
     $crefs = json_decode($data['court_referees'], true);
     foreach ($crefs as $cref) {
         $newRef = $competition->storeReferee($cref, $season, 1, $country);
         if (array_key_exists('styled', $cref)) {
             if ($cref['styled'] == 'new') {
                 $newRef['location'] = Location::find($newRef->location_id)->name;
                 array_push($response['crefs'], $newRef);
             }
         }
     }
     $response['pairs'] = $this->getPairs($season, $competition)->toArray();
     return $response;
 }
예제 #3
0
 public function create(ApplicationRequest $request)
 {
     $services = Service::join('service_visas', 'services.id', '=', 'service_visas.service_id')->select('services.id', 'services.name', 'min_process', 'max_process')->orderBy('min_process')->orderBy('max_process')->where('country_id', '=', $request->get('country'))->groupBy('services.id')->get();
     $service = $services->first();
     $states = DB::table('states')->orderBy('name', 'asc')->lists('name', 'id');
     $countries = Country::orderBy('name')->lists('name', 'id');
     $country = Country::find($request->get('country'));
     return View('apply', ['services' => $services->lists('title', 'id'), 'service' => $service, 'country' => $country, 'countries' => $countries, 'states' => $states]);
 }
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($id)
 {
     //
     $country = Country::find($id);
     //return $gender;
     if (count($country) > 0) {
         $statusCode = 200;
         $response = ['id' => $country->id, 'Country' => $country->country];
     } else {
         $response = ["error" => "Country doesn`t exist"];
         $statusCode = 404;
     }
     return response($response, $statusCode)->header('Content-Type', 'application/json');
 }
예제 #5
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     if ($this->option('all')) {
         foreach (Country::all() as $country) {
             $country->import();
             sleep(5);
         }
     } elseif ($this->argument('country')) {
         $country = Country::find($this->argument('country'));
         if (count($country)) {
             $country->import();
         }
     }
 }
 /**
  * Show the form for creating a new resource.
  *
  * @return Response
  */
 public function create(Request $request)
 {
     if ($request['countryId'] != 0) {
         $retcountry = Country::whereId($request['countryId'])->first();
         if ($retcountry) {
             $country = Country::find($request['countryId']);
             $country->name = $request['name'];
             $country->save();
             Session::flash('message', 'Country Updated Successfully');
         }
     } else {
         $country = new Country();
         $country->name = $request['name'];
         $country->save();
         Session::flash('message', 'Country added Successfully');
     }
     return Redirect::to('country');
 }
예제 #7
0
 /**
  * Updates the specified User node in the graph
  *
  * @param $name Node 'name' label to match when saving a User
  * @return \Illuminate\Http\RedirectResponse
  */
 public function update($name)
 {
     // Get the request params
     $userUpdate = Request::all();
     // Find the matching User node
     $user = User::whereName($name)->first();
     // Find the matching Group with which this User is associated
     $newGroup = Group::find($userUpdate['group']);
     // If we've changed the user group, then detach the existing group
     // relation and create a new relation in its place.
     if ($newGroup['id'] != $user->group->id) {
         $user->group()->detach();
         $user->group()->save($newGroup);
     }
     // Find the matching Country with which this User is associated
     $newCountry = Country::find($userUpdate['country']);
     // Detach the previous nationality relation, and save the new one
     // TODO: don't detach and save unless it's changed!
     $user->country()->detach();
     $user->country()->save($newCountry);
     // Update the User details
     $user->update($userUpdate);
     return redirect()->action('Admin\\UserController@index')->with('status', 'User has been updated.');
 }
예제 #8
0
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     $this->validate($request, ['title' => 'required']);
     $country = Country::find($id);
     if ($request->file('edit-country-flag')) {
         $this->validate($request, ['edit-country-flag' => 'required|image|mimes:jpeg,jpg,png,bmp,gif,svg']);
         $flagFile = $country->flag_path . $country->flag_name;
         if (\File::isFile($flagFile)) {
             \File::delete($flagFile);
         }
         $file = $request->file('edit-country-flag');
         $country_flag_path = $this->_country_flag_path;
         $country_flag_name = $file->getClientOriginalName();
         $file->move($country_flag_path, $country_flag_name);
         $country->flag_name = $country_flag_name;
         $country->flag_path = $country_flag_path;
     }
     $country->title = $request->get('title');
     $country->save();
     flash()->success('', 'Redaguota!');
     return Redirect::to('/dashboard/countries/');
 }
예제 #9
0
파일: User.php 프로젝트: jdeugarte/twitter
 public function country()
 {
     return Country::find($this->country_id);
 }
예제 #10
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $post_all = Post::latest()->published()->paginate(5);
     //get one to many
     $post = Post::find(11);
     if ($post) {
         $comments = $post->comments()->get();
     }
     //$comments->posts()->where('active', 1)->get();
     //$comments = Post::find(11)->comments()->where('title', 'foo')->first();
     //inverse
     $comment = Comment::find(1);
     if ($comment) {
         $post_found = $comment->post->title;
     }
     //many to many
     $user = User::find(32);
     if ($user) {
         $roles = $user->roles;
     }
     //$roles2 = User::find(11)->roles()->orderBy('role')->get();
     //Has Many Through
     $country = Country::find(1);
     $post_by_country = $country->posts;
     //Polymorphic
     //foreach ($post->likes as $like) {}
     //inverse
     $like = Like::find(1);
     if ($like) {
         $likeable = $like->likeable;
     }
     //Many To Many Polymorphic
     //$post = App\Post::find(1);
     //foreach ($post->tags as $tag) {}
     //inverse
     $tag = Tag::find(1);
     //Querying Relationship Existence
     // Retrieve all posts that have at least one comment...
     //$posts = Post::has('comments')->get();
     // Retrieve all posts that have three or more comments...
     $posts = Post::has('comments', '>=', 3)->get();
     // Retrieve all posts that have at least one comment with votes...
     //$posts = Post::has('comments.votes')->get();
     // Retrieve all posts with at least one comment containing words like foo%
     // $posts = Post::whereHas('comments', function ($query) {//orWhereHas
     //     $query->where('content', 'like', 'foo%');
     // })->get();
     //Eager loading
     $post2 = Post::with('user')->get();
     //Eager Loading Multiple Relationships
     //Sometimes you may need to eager load several different relationships in a single operation. To do so, just pass additional arguments to the with method:
     //$books = Post::with('user', 'publisher')->get();
     //Nested Eager Loading
     //To eager load nested relationships, you may use "dot" syntax. For example, let's eager load all of the book's authors and all of the author's personal contacts in one Eloquent statement:
     //$books = App\Book::with('author.contacts')->get();
     //Constraining Eager Loads
     //Sometimes you may wish to eager load a relationship, but also specify additional query constraints for the eager loading query. Here's an example:
     // $users = App\User::with(['posts' => function ($query) {
     //     $query->where('title', 'like', '%first%');
     // }])->get();
     //In this example, Eloquent will only eager load posts that if the post's title column contains the word first. Of course, you may call other query builder to further customize the eager loading operation:
     // $users = App\User::with(['posts' => function ($query) {
     //     $query->orderBy('created_at', 'desc');
     // }])->get();
     //Lazy Eager Loading
     //Sometimes you may need to eager load a relationship after the parent model has already been retrieved. For example, this may be useful if you need to dynamically decide whether to load related models:
     //$books = App\Book::all();
     // if ($someCondition) {
     //     $books->load('author', 'publisher');
     // }
     //If you need to set additional query constraints on the eager loading query, you may pass a Closure to the load method:
     // $books->load(['author' => function ($query) {
     //     $query->orderBy('published_date', 'asc');
     // }]);
     return view('posts.index', compact('post', 'comments', 'post_found', 'user', 'roles', 'roles2', 'country', 'post_by_country', 'likeable', 'tag', 'post2', 'post_all'));
 }
	public function postUpdate(Request $request)
	{
		$arr_return = array(
					'status' => 'error',
					'message'=>''
				);
		$time =date('H:i:s', time());
		$id_return_purchaseorder = session('current_returnpurchaseorder') !== null ? session('current_returnpurchaseorder') : 0;
		if($id_return_purchaseorder){
			$returnpurchaseorder = ReturnPurchaseorder::find($id_return_purchaseorder);
			session(['current_returnpurchaseorder' => $returnpurchaseorder['id']]);
			$time = date('H:i:s', strtotime($returnpurchaseorder->date));
		}else{

			$returnpurchaseorder = new ReturnPurchaseorder;
			$returnpurchaseorder->date = date("Y-m-d H:i:s");
			$returnpurchaseorder->created_by = \Auth::user()->id;
			$returnpurchaseorder->save();
			Log::create_log(\Auth::user()->id,'App\ReturnPurchaseorder','Tạo mới đơn hàng trả nhà cung cấp số '.$returnpurchaseorder->id);
			session(['current_returnpurchaseorder' => $returnpurchaseorder->id]);
		}
		$log = '';
		$old_company_id = $returnpurchaseorder->company_id;
		if($returnpurchaseorder->status == 0){
			$address = Address::where('module_id','=',$returnpurchaseorder->id)
						->where('module_type','=','App\ReturnPurchaseorder')->first();
			if(!$address){
				$address = new Address;
			}
			if($request->has('company_id')  && $returnpurchaseorder->company_id != $request->input('company_id')){
				$old = Company::find($returnpurchaseorder->company_id);
				if(!$old){
					$old = (object) ['name'=>''];
				}
				$new = Company::find($request->input('company_id'));
				$log .= 'công ty từ "'.$old->name.'" thành "'.$new->name.'" ';
			}
			if($returnpurchaseorder->company_id == $request->input('company_id')){

				if($request->has('user_id')  && $returnpurchaseorder->user_id != $request->input('user_id')){
					$old = User::find($returnpurchaseorder->user_id);
					if(!$old){
						$old = (object) ['name'=>''];
					}
					$new = User::find($request->input('user_id'));
					$log .= 'người liên hệ từ "'.$old->name.'" thành "'.$new->name.'" ';
				}

				$old_date=date("Y-m-d",strtotime($returnpurchaseorder->date));
				$new_date = date("Y-m-d",strtotime($request->input('date')));
				if($request->has('date')  && $old_date != $new_date){
					$log .= 'ngày từ "'.$old_date.'" thành "'.$new_date.'" ';
				}

				if($request->has('company_phone')  && $returnpurchaseorder->company_phone != $request->input('company_phone')){
					$log .= 'số điện thoại từ "'.$returnpurchaseorder->company_phone.'" thành "'.$request->input('company_phone').'" ';
				}

				if($request->has('company_email')  && $returnpurchaseorder->company_email != $request->input('company_email')){
					$log .= 'email từ "'.$returnpurchaseorder->company_email.'" thành "'.$request->input('company_email').'" ';
				}
				if($request->has('address')  && $address->address != $request->input('address')){
					$log .= 'địa chỉ từ "'.$address->address.'" thành "'.$request->input('address').'" ';
				}
				if($request->has('town_city')  && $address->town_city != $request->input('town_city')){
					$log .= 'quận huyện từ "'.$address->town_city.'" thành "'.$request->input('town_city').'" ';
				}

				if($request->has('province_id')  && $address->province_id != $request->input('province_id')){
					$old = Province::find($address->province_id);
					$new = Province::find($request->input('province_id'));
					if(!$old){
						$old = (object) ['name'=>''];
					}
					$log .= 'tỉnh thành từ "'.$old->name.'" thành "'.$new->name.'" ';
				}
				if($request->has('country_id')  && $address->country_id != $request->input('country_id')){
					$old = Country::find($address->country_id);
					$new = Country::find($request->input('country_id'));
					if(!$old){
						$old = (object) ['name'=>''];
					}
					$log .= 'quốc gia từ "'.$old->name.'" thành "'.$new->name.'" ';
				}
			}
			$returnpurchaseorder->company_id = $request->has('company_id') ? $request->input('company_id') : 0;
			$returnpurchaseorder->user_id = $request->has('user_id') ? $request->input('user_id') : 0;
			$returnpurchaseorder->date = $request->has('date') ? date("Y-m-d H:i:s",strtotime($request->input('date').' '.$time)) : date("Y-m-d H:i:s");
			$returnpurchaseorder->company_phone = $request->has('company_phone') ? $request->input('company_phone') : '';
			$returnpurchaseorder->company_email = $request->has('company_email') ? $request->input('company_email') : '';
			$address_id = isset($returnpurchaseorder->address_id) ? $returnpurchaseorder->address_id : 0;

			

			$address->module_id  = $returnpurchaseorder->id;
			$address->module_type  = 'App\\ReturnPurchaseorder';
			$address->address  = $request->has('address') ? $request->input('address') : '';
			$address->town_city  = $request->has('town_city') ? $request->input('town_city') : '';
			$address->zip_postcode  = $request->has('zip_postcode') ? $request->input('zip_postcode') : '';
			$address->country_id  = $request->has('country_id') ? $request->input('country_id') : 0;
			$address->province_id  = $request->has('province_id') ? $request->input('province_id') : 0;
			$address->save();
			$returnpurchaseorder->address_id = $address->id;
		}else{
			$returnpurchaseorder->sum_amount = 0;
			$returnpurchaseorder->sum_invest = 0;
		}
		$old_status = $returnpurchaseorder->status;
		$returnpurchaseorder->status = $request->has('status')?1:0;
		$check_save_in_stock = true;
		if($returnpurchaseorder->status){
			$arr_mproduct = Mproduct::select('m_products.id','quantity','specification','name','m_product_id','invest')
							->where('module_id', '=', $returnpurchaseorder->id)
							->where('module_type', '=', 'App\ReturnPurchaseorder')
							->leftJoin('products','products.id','=','m_products.product_id')
							->get()->toArray();
			foreach ($arr_mproduct as $key => $mproduct) {
				$returnpurchaseorder->sum_amount = $returnpurchaseorder->sum_amount + $mproduct['invest'];
				$mproduct_po = Mproduct::find($mproduct['m_product_id']);
				$product_stock = ProductStock::where('m_product_id','=',$mproduct_po->id)->first();
				$product_stock->in_stock = $product_stock->in_stock -  ($mproduct['quantity']*$mproduct['specification']);
				if($product_stock->in_stock < 0){
					$check_save_in_stock = false;
					$arr_return['message'] .= 'Số lượng sản phẩm '.$mproduct['name'].' nhập vào lớn hơn số lượng đã nhập<br/><br/>';
				}
			}
		}else{
			if($old_status != $returnpurchaseorder->status){
				$arr_mproduct = Mproduct::select('m_products.id','quantity','specification','name','m_product_id')
								->where('module_id', '=', $returnpurchaseorder->id)
								->where('module_type', '=', 'App\ReturnPurchaseorder')
								->leftJoin('products','products.id','=','m_products.product_id')
								->get()->toArray();
				foreach ($arr_mproduct as $key => $mproduct) {
					$mproduct_po = Mproduct::find($mproduct['m_product_id']);
					$product_stock = ProductStock::where('m_product_id','=',$mproduct_po->id)->first();
					$product_stock->in_stock = $product_stock->in_stock + ($mproduct['quantity']*$mproduct['specification']);
					$product_stock->save();
				}
			}
		}

		if($check_save_in_stock){
			$returnpurchaseorder->updated_by = \Auth::user()->id;
			if($returnpurchaseorder->save()){
				Log::create_log(\Auth::user()->id,'App\ReturnPurchaseorder','Cập nhật '.$log.' đơn hàng trả nhà cung cấp số '.$returnpurchaseorder->id);
				if($returnpurchaseorder->status){
					foreach ($arr_mproduct as $key => $mproduct) {
						$mproduct_po = Mproduct::find($mproduct['m_product_id']);
						$product_stock = ProductStock::where('m_product_id','=',$mproduct_po->id)->first();
						$product_stock->in_stock = $product_stock->in_stock -  ($mproduct['quantity']*$mproduct['specification']);
						$product_stock->save();
					}
				}

				if($old_company_id != $returnpurchaseorder->company_id){
					Mproduct::where('module_id', '=', $returnpurchaseorder->id)
						->where('module_type', '=', 'App\ReturnPurchaseorder')
						->where('company_id','=',$old_company_id)
						->delete();
				}else{
					Mproduct::where('module_id', '=', $returnpurchaseorder->id)
						->where('module_type', '=', 'App\ReturnPurchaseorder')
						->update(['company_id' => $returnpurchaseorder->company_id ]);
				}
				$arr_return['status']= 'success';
			}else{
				$arr_return['message']= 'Saving fail !';
			}
		}
		return $arr_return;
	}
 public function getDeleteinfo(Request $request)
 {
     if ($request->has("id")) {
         $country = Country::find(Input::get("id"));
         if ($country) {
             $country->delete();
             $response = array('status' => ['error' => 0, 'note' => '删除成功'], 'influence' => 1);
             return json_encode($response);
         } else {
             //未找到stu_id
             $response = array('status' => ['error' => 1, 'note' => '未找到id'], 'influence' => 0);
             return json_encode($response);
         }
     } else {
         //没有stu_id参数
         $response = array('status' => ['error' => -1, 'note' => '需要id'], 'influence' => 0);
         return json_encode($response);
     }
 }
예제 #13
0
 /**
  * Run the database seeds.
  */
 public function run()
 {
     $country = Country::find(1);
     $language = Language::find(1);
     User::create(['id' => 1, 'name' => 'John', 'surname' => 'Doe', 'username' => 'Doe', 'password' => base64_encode('123'), 'email' => '*****@*****.**', 'direction' => 'going up', 'enabled' => true, 'country_id' => $country->id, 'language_id' => $language->id]);
 }
예제 #14
0
 public function getList($country)
 {
     if (!Auth::check()) {
         return Redirect::to('leads/login');
     }
     $leads = Lead::where('user_id', '=', Auth::user()->id)->where('Country', '=', $country)->orderBy('Country');
     return view('leads.view')->with('country', Country::find($country))->with('leads', $leads->paginate(10))->with('leads_count', $leads->count());
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param $id
  * @return Response
  */
 public function postDelete(DeleteRequest $request, $id)
 {
     $country = Country::find($id);
     $country->delete();
 }