/**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $prod = Product::select('products.*', 'pgroups.name AS product_group', 'total_qty')->leftJoin('inventory_totals', 'inventory_totals.product_id', '=', 'products.id')->join('pgroups', 'pgroups.id', '=', 'pgroup_id')->where('products.is_active', 1)->get();
     $products = json_encode($prod);
     $pgroups = DB::table('pgroups')->lists('name', 'id');
     return view('products/index', compact('products', 'pgroups'));
 }
 /**
  * Filter products by category
  *
  * @param $request
  * @return Response
  */
 public function filterByCategory(Request $request)
 {
     $title = 'Product Listing';
     $categories = Category::lists('title', 'id')->toArray();
     $products = Product::select(DB::raw("products.id, products.name, products.photo"))->leftJoin('category_product', 'category_product.product_id', '=', 'products.id')->whereIn('category_product.category_id', $request->input('category_id'))->groupBy('product_id')->paginate(10);
     return view('home', compact('title', 'categories', 'products'));
 }
 public function getProductPrice(Request $request)
 {
     $product_id = $request->get('product_id');
     $price = Product::select("price")->whereId($product_id)->first();
     echo $price->price;
     exit;
 }
Example #4
0
 public static function detail($id)
 {
     return Product::select(array(DB::raw("check_coupon(pro_product.id,pro_product.cid_cate,1) AS discountcoupon"), DB::raw("check_coupon(pro_product.id,pro_product.cid_cate,2) AS coupons"), DB::raw("get_review(pro_product.id,1) AS rating"), DB::raw("get_review(pro_product.id,2) AS countrating"), DB::raw("get_price(pro_supplier_product.id,pro_supplier_product.discount) AS discount"), DB::raw("get_sale_price(pro_supplier_product.id,pro_supplier_product.saleprice) AS saleprice"), "pro_product.id AS myid", "pro_product.code", "pro_product.sap_code", "pro_product.is_hot", "pro_product.name", "pro_product.cid_series", "pro_product.cid_cate", "pro_supplier_product.id AS cid_res", "pro_product.isprice", "pro_supplier_product.stock_num", "pro_product.is_sample", "pro_product.is_shopping", "pro_supplier_product.is_tranc", "pro_supplier_product.content", "m.name AS name_supplier", "pro_supplier_product.id AS cid_res", "pro_supplier_product.cid_supplier"))->whereRaw("pro_product.id={$id}  AND pro_supplier_product.status='1' AND pro_product.status='1' AND pro_product.is_status_cate='1' AND pro_product.is_status_series='1' ")->join("pro_supplier_product", function ($join) {
         $join->on("pro_product.id", "=", "pro_supplier_product.cid_product");
     })->join("market_supplier AS m", function ($join) {
         $join->on("m.id", "=", "pro_supplier_product.cid_supplier");
     })->orderBy("pro_supplier_product.date_mod", "DESC")->remember(10)->first();
 }
Example #5
0
 private function createTags()
 {
     $product = Product::select(['id', 'name'])->get();
     foreach ($product as $value) {
         $prod = Product::find($value->id);
         $prod->tags = str_replace(' ', ',', $value->name);
         $prod->save();
     }
 }
Example #6
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     //
     $users = User::select('id')->get();
     $products = Product::select('id')->get();
     $categories = Category::select('id')->get();
     $areas = Area::select('id')->get();
     $orders = Order::select('id')->get();
     return view('admin.dashboard', compact('users', 'products', 'categories', 'areas', 'orders'));
 }
Example #7
0
 /**
  * Provides a json encoded array of matching product names
  * @param  string $query
  * @return json
  */
 public static function searchByNameAutocomplete($query, $customer_id = NULL)
 {
     $products = Product::select('*', 'products.name as product_name', 'taxes.name as tax_name')->leftjoin('taxes', 'taxes.id', '=', 'products.tax_id')->orderBy('products.name')->where('products.name', 'like', '%' . $query . '%')->get();
     /*
     $return = array();
     
     foreach ($products as $product)
     {
         // $return[]['value'] = $client->name_fiscal;
         $return[] = array ('value' => $client->name_fiscal, 'data' => $client->id);
     }
     
     return json_encode( array('query' => $query, 'suggestions' => $return) );
     */
     // return json_encode( $products );
     return json_encode(array('query' => $query, 'suggestions' => $products));
 }
Example #8
0
 public function run()
 {
     $faker = Faker::create();
     $addresses = Address::get();
     $status_list = array_keys(trans('globals.order_status'));
     $products = Product::select('id', 'price')->get();
     for ($i = 0; $i < 20; $i++) {
         $address = $addresses->random(1);
         $type = $faker->randomElement(['cart', 'wishlist', 'order']);
         $status = 'open';
         switch ($type) {
             case 'order':
                 $status = $faker->randomElement($status_list);
                 break;
         }
         $stock = $faker->numberBetween(1, 20);
         $order = Order::create(['user_id' => $address->user_id, 'seller_id' => '3', 'address_id' => $address->id, 'status' => $status, 'type' => $type, 'description' => $type == 'wishlist' ? $faker->companySuffix : '', 'end_date' => $status == 'closed' || $status == 'cancelled' ? $faker->dateTime() : null]);
         $num = $faker->numberBetween(2, 5);
         $list = [];
         if ($num > 1 && count($products) - 1 < $num) {
             $num = count($products) - 1;
         }
         for ($j = 0; $j < $num; $j++) {
             do {
                 $a = true;
                 $product = $products->random(1);
                 if (in_array($product->id, $list)) {
                     $a = false;
                 } else {
                     $list[] = $product->id;
                 }
             } while ($a == false);
             if ($status == 'closed') {
                 $delivery = $faker->dateTime();
             } else {
                 $delivery = $faker->numberBetween(0, 1) ? $faker->dateTime() : null;
             }
             OrderDetail::create(['order_id' => $order->id, 'product_id' => $product->id, 'price' => $product->price, 'quantity' => $stock, 'delivery_date' => $delivery]);
         }
         $order->sendNotice();
     }
 }
Example #9
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $group_id = false;
     $id = explode('_', $id);
     $view = $id[1];
     $id = $id[0];
     $deleteAll = $view == $id;
     $product = Product::select('id', 'products_group')->with(['group' => function ($query) {
         $query->select('id', 'products_group');
     }])->find($id);
     #is necesary re make the actual group before add to new one because is the principal product of the last one
     if ($product->products_group == $id && count($product->group) > 1) {
         $newPrincipal = Product::select('id')->where('products_group', $id)->where('id', '<>', $id)->first();
         $group_id = $newPrincipal->id;
         Product::where('products_group', $id)->update(['products_group' => $group_id]);
     }
     $product->products_group = null;
     $product->save();
     return json_encode(['deleteAll' => $deleteAll ? true : false, 'message' => trans('product.product_was_deleted_from_this_group')]);
 }
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $products = Product::select()->with('category', 'media', 'tags')->orderBy('publish_date', 'DESC')->get();
     return view('admin.dashboard', compact('products'));
 }
 /**
  * This method is able to return the higher rate product list, everything will depends of $point parameter.
  *
  * @param [integer] $point [it is the rate evaluates point, which allows get the products list required]
  * @param [integer] $limit [num of records to be returned]
  * @param [boolean] $tags  [it sees if we want to return a product list or a product tags list]
  *
  * @return [array or laravel collection] $_tags, $products [returning either products tags array or products collection]
  */
 public static function getTopRated($point = '5', $limit = 5, $tags = false)
 {
     if ($tags == true) {
         $products = Product::select(['id', 'tags', 'rate_count', 'rate_val'])->WhereNotNull('tags')->free()->orderBy('rate_count', 'desc')->orderBy('rate_val', 'desc')->take($limit)->get();
         $_tags = [];
         $products->each(function ($prod) use(&$_tags) {
             $array = explode(',', $prod->tags);
             foreach ($array as $value) {
                 if (trim($value) != '') {
                     $_tags[] = trim($value);
                 }
             }
         });
         return array_unique($_tags, SORT_STRING);
     } else {
         $products = Product::select(['id', 'name', 'description', 'features', 'price', 'type', 'stock'])->free()->orderBy('rate_count', 'desc')->orderBy('rate_val', 'desc')->take($limit)->get();
         return $products;
     }
 }
 /**
  * 根据关键字搜索商品
  *
  * @param $keywords
  * @return response
  */
 public function search($keywords)
 {
     return Product::select('id', 'name')->where('name', 'like', '%' . $keywords . '%')->orderBy('created_at', 'desc')->paginate(10)->toJson();
 }
 /**
  *	edit the number of key registered for email.
  *
  *	@param 	string|int 	id product
  *	@param 	Request 	object to validate the type of request|action to ejecute
  *
  *	@return json
  */
 public function editKey($id, Request $request)
 {
     if (!$request->wantsJson()) {
         return ['message' => trans('globals.error_not_available')];
     }
     if (!$request->has('email')) {
         return ['message' => trans('globals.error_not_available')];
     }
     $cart = Order::ofType('cart')->select('id', 'status')->where('user_id', \Auth::id())->first();
     if (!$cart) {
         return ['message' => trans('globals.error_not_available')];
     }
     $product = Product::select('id', 'stock')->find($id);
     if (!$product) {
         return ['message' => trans('globals.error_not_available')];
     }
     $order = OrderDetail::where('order_id', $cart->id)->where('product_id', $product->id)->first();
     if (!$order) {
         return ['message' => trans('globals.error_not_available')];
     }
     $virtual = VirtualProduct::select('id')->where('product_id', $product->id)->first();
     if ($request->has('delete')) {
         $virtualOrder = VirtualProductOrder::where('virtual_product_id', $virtual->id)->where('email', $request->input('email'))->delete();
         $num2 = VirtualProductOrder::where('virtual_product_id', $virtual->id)->where('status', 1)->get()->toArray();
         if (!count($num2)) {
             $order->delete();
         } else {
             $order->quantity = count($num2);
             $order->save();
         }
         return ['all' => true];
     } elseif ($request->has('decrement')) {
         $virtualOrder = VirtualProductOrder::where('virtual_product_id', $virtual->id)->where('email', $request->input('email'))->where('status', 1)->first();
         $virtualOrder->delete();
         $num2 = VirtualProductOrder::where('virtual_product_id', $virtual->id)->where('status', 1)->get()->toArray();
         if (!count($num2)) {
             $order->delete();
         } else {
             $order->quantity = count($num2);
             $order->save();
         }
         $num = VirtualProductOrder::where('virtual_product_id', $virtual->id)->where('email', $request->input('email'))->where('status', 1)->get()->toArray();
         if (count($num)) {
             return ['delete' => true, 'num' => count($num)];
         }
         return ['all' => true];
     } elseif ($request->has('increment')) {
         $num2 = VirtualProductOrder::where('virtual_product_id', $virtual->id)->where('status', 1)->get()->toArray();
         if (count($num2) + 1 > $product->stock) {
             return ['message' => trans('product.virtualProductOrdersController_controller.no_stock')];
         }
         $virtualOrder = new VirtualProductOrder();
         $virtualOrder->order_id = $order->order_id;
         $virtualOrder->status = 1;
         $virtualOrder->email = $request->input('email');
         $virtualOrder->virtual_product_id = $virtual->id;
         $virtualOrder->save();
         $order->quantity = count($num2) + 1;
         $order->save();
         $num = VirtualProductOrder::where('virtual_product_id', $virtual->id)->where('email', $request->input('email'))->where('status', 1)->get()->toArray();
         return ['insert' => true, 'num' => count($num)];
     }
     return ['message' => trans('globals.error_not_available')];
 }
Example #14
0
 public function currentStock()
 {
     $productStock = Product::select('id', 'name', 'current_stock');
 }
 public function searchInventory()
 {
     $date = Input::get('date');
     $qty = Input::get('qty');
     if ($qty == 1) {
         $inventory = Product::select('products.id AS product_id', 'products.name', 'products.code', 'pgroups.name AS product_group', 'total_qty')->leftJoin('inventory_totals', 'inventory_totals.product_id', '=', 'products.id')->join('pgroups', 'pgroups.id', '=', 'pgroup_id')->where('products.is_active', 1)->where('products.is_stock', 1)->where('total_qty', '>', 0)->orderBy('pgroups.name', 'ASC')->orderBy('products.name', 'ASC')->get();
     } else {
         if ($qty <= 0 && $qty != "") {
             $inventory = Product::select('products.id AS product_id', 'products.name', 'products.code', 'pgroups.name AS product_group', 'total_qty')->leftJoin('inventory_totals', 'inventory_totals.product_id', '=', 'products.id')->join('pgroups', 'pgroups.id', '=', 'pgroup_id')->where('products.is_active', 1)->where('products.is_stock', 1)->where(function ($query) {
                 $query->where('total_qty', '<', 0)->orWhere('total_qty', null);
             })->orderBy('pgroups.name', 'ASC')->orderBy('products.name', 'ASC')->get();
         } else {
             $inventory = Product::select('products.id AS product_id', 'products.name', 'products.code', 'pgroups.name AS product_group', 'total_qty')->leftJoin('inventory_totals', 'inventory_totals.product_id', '=', 'products.id')->join('pgroups', 'pgroups.id', '=', 'pgroup_id')->where('products.is_active', 1)->where('products.is_stock', 1)->orderBy('pgroups.name', 'ASC')->orderBy('products.name', 'ASC')->get();
         }
     }
     return Response::json($inventory);
 }
Example #16
0
 public function getList()
 {
     $data = Product::select('*')->orderBy('id', 'desc')->get()->toArray();
     return view('admin.product.list', compact('data'));
 }
 /**
  * Return a json list of records matching the provided query
  *
  * @return json
  */
 public function ajaxProductSearch(Request $request)
 {
     // return Product::searchByNameAutocomplete(Input::get('query'));
     $products = Product::select('id', 'name as label', 'reference')->orderBy('products.name')->where('name', 'like', '%' . $request->input('term') . '%')->get();
     return json_encode($products);
 }
Example #18
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function getList()
 {
     $products = Product::select('products.*', 'categories.name as category')->join('categories', 'products.category_id', '=', 'categories.id')->get();
     return response(['data' => $products], 200);
 }
Example #19
0
 public function getcompareproduct($id, $cate)
 {
     return array("template" => Template::Compare_Cate($cate, $id), "product" => Product::select(array(DB::raw("check_coupon(pro_product.id,pro_product.cid_cate,1) AS discountcoupon"), DB::raw("check_coupon(pro_product.id,pro_product.cid_cate,2) AS coupons"), DB::raw("get_review(pro_product.id,1) AS rating"), DB::raw("get_review(pro_product.id,2) AS countrating"), DB::raw("get_price(pro_supplier_product.id,pro_supplier_product.discount) AS discount"), DB::raw("get_sale_price(pro_supplier_product.id,pro_supplier_product.saleprice) AS saleprice"), "market_supplier.name AS myname", "pro_product.cid_series", "pro_supplier_product.cid_supplier", "pro_product.id", "pro_product.id AS myid", "pro_product.name", "pro_product.isprice", "pro_supplier_product.stock_num", "pro_product.is_shopping"))->whereRaw("pro_product.id ={$id} AND pro_product.status='1' AND pro_product.is_status_cate='1' AND pro_product.is_status_series='1'  ")->join("pro_supplier_product", function ($join) {
         $join->on("pro_product.id", "=", "pro_supplier_product.cid_product");
     })->join("market_supplier", function ($join) {
         $join->on("market_supplier.id", "=", "pro_supplier_product.cid_supplier");
     })->first());
 }
Example #20
0
 public function getseries($id, $cate)
 {
     return Product::select(array(DB::raw("check_coupon(pro_product.id,pro_product.cid_cate,1) AS discountcoupon"), DB::raw("check_coupon(pro_product.id,pro_product.cid_cate,2) AS coupons"), DB::raw("get_review(pro_product.id,1) AS rating"), DB::raw("get_review(pro_product.id,2) AS countrating"), DB::raw("get_price(pro_supplier_product.id,pro_supplier_product.discount) AS discount"), DB::raw("get_sale_price(pro_supplier_product.id,pro_supplier_product.saleprice) AS saleprice"), "pro_product.id", "pro_product.id AS myid", "pro_product.name", "pro_product.isprice", "pro_supplier_product.id AS cid_res", "pro_supplier_product.cid_supplier", "pro_product.cid_series"))->whereRaw("pro_supplier_product.status='1' AND pro_product.status='1' AND pro_product.is_status_cate='1' AND pro_product.is_status_series='1' AND pro_product.cid_series={$id}  AND pro_product.cid_cate={$cate}")->join("pro_supplier_product", function ($join) {
         $join->on("pro_product.id", "=", "pro_supplier_product.cid_product");
     })->orderBy("pro_supplier_product.date_mod", "DESC")->limit(9)->get()->toJson();
 }
	public function anyTonDauThang(Request $request){


		if($request->has('input-sort')){
			$arr_sort = $request->input('input-sort');
			$arr_sort =(array) json_decode($arr_sort);
		}elseif( session('sort_filter_product_ton_dau_thang.arr_sort') !== null){
			$arr_sort = session('sort_filter_product_ton_dau_thang.arr_sort');
		}else{
			$arr_sort=array();
		}
		session('sort_filter_product_ton_dau_thang.arr_sort', $arr_sort);

		$list_month = ReceiptMonth::select('month','year')
									->distinct()->where('month','>',0)
									->orderBy('year','ASC')
									->orderBy('month','ASC')
									->get()->toArray();
		if($request->has('input-filter')){
			$arr_filter = $request->input('input-filter');
		}elseif( session('sort_filter_product_ton_dau_thang.arr_filter') !== null ){
			$arr_filter = session('sort_filter_product_ton_dau_thang.arr_filter');
		}else{
			$arr_filter=[
					'sku'=>'',
					'like_name'=>'',
					'name'=>'',
					'company_id'=>'',
					'oum_id'=>''
				       ];
			if(count($list_month)){
				$arr_filter['month'] = $list_month[0]['month'].'-'.$list_month[0]['year'];
			}
		}

		session(['sort_filter_product_ton_dau_thang.arr_sort'=>$arr_sort]);
		session(['sort_filter_product_ton_dau_thang.arr_filter'=> $arr_filter]);

		$list_all_product = Product::select('sku','name')->orderBy('sku')->get()->toArray();
		$list_month = array();
		//Init array
		$distributes = array();
		$oums = array();
		$producttypes = array();
		$list_sku = array();
		//Get value array
		$distributes = Company::getDistributeList()->get()->toArray();
		$oums = Oum::orderBy('name')->get()->toArray();
		$producttypes = ProductType::get()->toArray();
		$list_all_product = Product::select('sku','name')->orderBy('sku')->get()->toArray();

		$list_product = TonDauThang::select(
					'products.id',
					'products.name',
					'products.sku',
					'ton_dau_thangs.quantity',
					'ton_dau_thangs.month',
					'ton_dau_thangs.year',
					'm_products.oum_id',
					'm_products.specification',
					'm_products.origin_price',
					'companies.name as company_name',
					'oums.name as oum_name'
		            )
					->addSelect(DB::raw('product_stocks.in_stock/m_products.specification as real_in_stock'))
					->leftJoin('m_products','m_products.id','=','ton_dau_thangs.m_product_id')
					->leftJoin('products','products.id','=','m_products.product_id')
					->leftJoin('oums','oums.id','=','m_products.oum_id')	
					->leftJoin('companies','companies.id','=','m_products.company_id')
					->leftJoin('product_stocks','m_products.id','=','product_stocks.m_product_id')
					->groupBy('products.id','m_products.company_id','m_products.oum_id','m_products.specification','m_products.origin_price')
					->where('ton_dau_thangs.quantity','>',0);

					
		foreach ($arr_filter as $key => $value) {
			if($value!=''){
				if($arr_filter['sku']!=''){
					$list_product->where('products.sku',$arr_filter['sku']);
				}
				if($key == 'like_name'){
					$list_product->where('products.name','LIKE',"%".$arr_filter['like_name']."%");
					$arr_filter['name']='';
				}
				if($key == 'name' && $arr_filter['name']!=''){
					$list_product->where('products.name',$arr_filter['name']);
				}
				if($key == 'company_id'){
					$list_product->where('m_products.company_id',$arr_filter['company_id']);
				}
				if($key == 'status'){
					$list_product->where('products.status',$arr_filter['status']);
				}
				if($key == 'oum_id'){
					$list_product->where('m_products.oum_id',$arr_filter['oum_id']);
				}
				if($key == 'month' && $arr_filter['month'] !=''){
					$month_year = explode('-',$arr_filter['month']);
					$list_product->where('ton_dau_thangs.month','=',$month_year[0])
								->where('ton_dau_thangs.year','=',$month_year[1]);
				}
			}
		}

		foreach ($arr_sort as $key => $value) {
			if($key=='company_id'){
				$list_product = $list_product->orderBy('companies.name',$value);
			}elseif($key=='oum_id'){
				$list_product = $list_product->orderBy('oums.name',$value);
			}elseif($key=='id'){
				$list_product = $list_product->orderBy('products.id',$value);
			}elseif($key=='specification'){
				$list_product = $list_product->orderBy('m_products.specification',$value);
			}elseif($key=='quantity'){
				$list_product = $list_product->orderBy('ton_dau_thangs.quantity',$value);
			}else{
				$list_product = $list_product->orderBy($key,$value);
			}
		}
		$list_month = ReceiptMonth::select('month','year')
									->distinct()->where('month','>',0)
									->orderBy('year','ASC')
									->orderBy('month','ASC')
									->get()->toArray();
		$list_product = $list_product->orderBy('products.id','asc');
		\Cache::put('list_product'.\Auth::user()->id, $list_product->get()->toArray(), 30);
		$sum_invest =  0;

		foreach ($list_product->get()->toArray() as $key => $value) {
			$sum_invest += $value['origin_price'] * $value['quantity'];
		}
		$list_product = $list_product->paginate(100);

		$this->layout->content=view('product.list-ton-dau-thang', [
								'distributes'			=> $distributes,
								'oums'					=> $oums,
								'producttypes'			=> $producttypes,
								'list_product'			=> $list_product,
								'list_all_product'		=> $list_all_product,
								'arr_sort' 				=> $arr_sort,
								'arr_filter' 			=> $arr_filter,
								'sum_invest'			=> $sum_invest,
								'list_month'			=> $list_month
							        ]);
	}
Example #22
0
 public static function detail_product($id, $supplier)
 {
     if (!empty($id)) {
         return Product::select(array(DB::raw("check_coupon(pro_product.id,pro_product.cid_cate,1) AS discountcoupon"), DB::raw("check_coupon(pro_product.id,pro_product.cid_cate,2) AS coupons"), DB::raw("get_review(pro_product.id,1) AS rating"), DB::raw("get_review(pro_product.id,2) AS countrating"), DB::raw("get_price(pro_supplier_product.id,pro_supplier_product.discount) AS discount"), DB::raw("get_sale_price(pro_supplier_product.id,pro_supplier_product.saleprice) AS saleprice"), "pro_product.id AS myid", "pro_product.code", "pro_product.sap_code", "pro_product.name", "pro_product.cid_series", "pro_product.cid_cate", "pro_supplier_product.id AS cid_res", "pro_product.isprice", "pro_product.of_type", "pro_supplier_product.stock_num", "m.name AS name_supplier", "pro_supplier_product.id AS cid_res", "pro_supplier_product.cid_supplier"))->whereRaw("pro_product.id={$id}  AND  pro_supplier_product.cid_supplier={$supplier} AND pro_supplier_product.status='1' AND pro_product.status='1' AND pro_product.is_status_cate='1' AND pro_product.is_status_series='1' ")->join("pro_supplier_product", function ($join) {
             $join->on("pro_product.id", "=", "pro_supplier_product.cid_product");
         })->join("market_supplier AS m", function ($join) {
             $join->on("m.id", "=", "pro_supplier_product.cid_supplier");
         })->orderBy("pro_supplier_product.date_mod", "DESC")->first()->toArray();
     }
     return null;
 }