public function sales(Request $request) { // Sets the parameters from the get request to the variables. if (Input::has('code') || Input::has('date') || Input::has('date2')) { $code = Input::get('code'); $from_date = date("Y-m-d", strtotime(Input::get('date'))); $to_date = date("Y-m-d", strtotime(Input::get('date2'))); // if(Sale::where('id', '=', $code)->orWhere('customer_name', 'like', '%'.$code.'%')->exists()) { // $sales = Sale::Where('id', '=', $code)->orWhere('customer_name', 'like', '%'.$code.'%')->whereBetween('created_at',[$from_date, $to_date])->paginate(15); // return view('report.sale')->with('saleReport', $sales); // }else{ // Alert::error('Whoops, your search not found !.'); // // echo "<script>alert('Barcode Item not found !');</script>"; // } // $sales = Sale::whereBetween('created_at',[$from_date.'%', $to_date.'%'])->paginate(15); // if($sales = Sale::Where('customer_name', 'like', '%'.$code)->orWhere('id', $code)->whereBetween('created_at',[$from_date.'%', $to_date.'%'])->orderBy('created_at','asc')->paginate(15)) // { // print_r($sales) ; // // return view('report.sale')->with('saleReport', $sales); // } else{ // Alert::error('Whoops, your search not found !.'); // // echo "<script>alert('Barcode Item not found !');</script>"; // } $sales = Sale::Where('id', $code)->orWhere('customer_name', 'like', '%' . $code . '%')->WhereBetween('created_at', [$from_date . '%', $to_date . '%'])->orderBy('created_at', 'asc')->paginate(15); // print_r($sales); return view('report.sale')->with('saleReport', $sales); } else { $salesReport = Sale::orderby('created_at', 'desc')->paginate(20); } return view('report.sale')->with('saleReport', $salesReport); }