![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/mcoil.corals.io/app/Http/Controllers/Front/ |
<?php namespace App\Http\Controllers\Front; use App\Shop\Categories\Repositories\Interfaces\CategoryRepositoryInterface; use App\Shop\Pages\Creator; use Illuminate\Http\Request; use App\Shop\Towns\Town; use App\Shop\ProductAttributes\ProductAttribute; use App\Shop\FillTanks\FillTank; use App\Shop\DiscountCoupons\DiscountCoupon; use App\Shop\TextBoxes\TextBox; use App\Shop\ServiceBoxes\ServiceBox; use App\Shop\CalltoAction\CalltoAction; use App\Shop\Products\Product; use App\Shop\Orders\Order; use App\Shop\OrderProducts\OrderProduct; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Session; use Illuminate\Support\Facades\Auth; use App\Shop\Categories\Category; use App\Shop\GDPR\ConsentLog; use App\Shop\GDPR\CookieListOption; class HomeController { /** * @var CategoryRepositoryInterface */ private $categoryRepo; /** * HomeController constructor. * @param CategoryRepositoryInterface $categoryRepository */ public function __construct(CategoryRepositoryInterface $categoryRepository) { $this->categoryRepo = $categoryRepository; } /** * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View */ public function index() { $page_details = Creator::where('slug','home')->first(); if ($page_details != null) { $modules = json_decode($page_details->modules); $banner1 = DB::table('banners')->where(['id' => $modules->banner1])->first(); $banner2 = DB::table('banners')->where(['id' => $modules->banner2])->first(); $text_box1 = TextBox::find($modules->text_box1); $text_box2 = TextBox::find($modules->text_box2); $productService = ServiceBox::find($modules->service_box1); $productServiceBoxes = null; if ($productService) { $productServiceBoxes = ServiceBox::where('type', $productService->type)->orderBy('orderNO','ASC')->take($page_details->no_of_service_box_display)->get(); } $orderStepService = ServiceBox::find($modules->service_box2); $orderStepServiceBoxes = null; if ($orderStepService) { $orderStepServiceBoxes = ServiceBox::where('type', $orderStepService->type)->orderBy('orderNO','ASC')->take($page_details->no_of_service_box_display2)->get(); } $calltoaction = null; if(isset($modules->call_to_action)){ $calltoaction = CalltoAction::find($modules->call_to_action); } } $cat1 = null; $cat_det = Category::where('id',4)->first(); if($cat_det){ $cat1 =$cat_det; } $cat2 = null; $cat_det_two = Category::where('id',5)->first(); if($cat_det_two){ $cat2 = $cat_det_two; } return view('front.index', [ 'page_details' => $page_details, 'cat1' => $cat1, 'cat2' => $cat2, 'banner1' => $banner1, 'banner2' => $banner2, 'text_box1' => $text_box1, 'text_box2' => $text_box2, 'productServiceBoxes' => $productServiceBoxes, 'orderStepServiceBoxes' => $orderStepServiceBoxes, 'calltoaction' => $calltoaction ]); } public function fetch_towns(Request $request) { $towns = Town::where('county_id',$request->county_id)->orderBy('name', 'asc')->get(); $output = "<option value=''>TOWN</option>"; foreach($towns as $town) { $output .="<option value='".$town->id."'>".$town->name."</option>"; } echo json_encode($output); } public function fetch_towns_order(Request $request) { // Reset the session if ($request->session()->has('county_name_quote')) { //echo json_encode('exist'); die(); //session([ 'county_name_quote' => $request->county_id]); $request->session()->put('county_name_quote', $request->county_id); //Session::set('county_name_quote', $request->county_id); } $towns = Town::where('county_id',$request->county_id)->orderBy('name', 'asc')->get(); $output="<option value=''>TOWN</option>"; foreach($towns as $town) { $output .="<option value='".$town->id."'>".$town->name."</option>"; } echo json_encode($output); } public function session_towns_order(Request $request) { // Reset the session if ($request->session()->has('town_name_quote')) { session([ 'town_name_quote' => $request->town_id]); } } public function fetch_quantity(Request $request) { // Here we are showing combination of [Attribute:Attribute value] // Fetch product_attributes_id from product_attributes table $product_attributes_data = DB::table('product_attributes') ->leftJoin('attribute_value_product_attribute', 'attribute_value_product_attribute.product_attribute_id', '=', 'product_attributes.id') ->leftJoin('attribute_values','attribute_values.id','=','attribute_value_product_attribute.attribute_value_id') ->leftJoin('attributes','attributes.id','=','attribute_values.attribute_id') ->select('product_attributes.id', 'attributes.name', 'attribute_values.value') ->where('product_attributes.product_id', $request->product_id) ->orderBy('attribute_values.value', 'ASC') ->get(); $fillthetank_price_data = DB::table('fill_tank_price')->where('id', '1')->first(); if ($fillthetank_price_data->price && $fillthetank_price_data->price != '0.00') { $output = "<option value=''>QUANTITY</option><option value='fill the tank'>Fill The Tank</option>"; } else { $output = "<option value=''>QUANTITY</option>"; } foreach($product_attributes_data as $product_attributes) { $output .="<option value='".$product_attributes->id."'>".$product_attributes->name." : ".$product_attributes->value."</option>"; } echo json_encode($output); } public function fetch_quantity_order(Request $request) { // Reset the session if ($request->session()->has('product_name_quote')) { session([ 'product_name_quote' => $request->product_id]); } // Here we are showing combination of [Attribute:Attribute value] // Fetch product_attributes_is from product_attributes table $product_attributes_data = DB::table('product_attributes') ->leftJoin('attribute_value_product_attribute', 'attribute_value_product_attribute.product_attribute_id', '=', 'product_attributes.id') ->leftJoin('attribute_values','attribute_values.id','=','attribute_value_product_attribute.attribute_value_id') ->leftJoin('attributes','attributes.id','=','attribute_values.attribute_id') ->select('product_attributes.id', 'attributes.name', 'attribute_values.value') ->where('product_attributes.product_id', $request->product_id) ->orderBy('attribute_values.value', 'ASC') ->get(); $fillthetank_price_data = DB::table('fill_tank_price')->where('id', '1')->first(); if ($fillthetank_price_data->price && $fillthetank_price_data->price != '0.00') { $output = "<option value=''>QUANTITY</option><option value='fill the tank'>Fill The Tank</option>"; } else { $output = "<option value=''>QUANTITY</option>"; } foreach($product_attributes_data as $product_attributes) { $output .="<option value='".$product_attributes->id."'>".$product_attributes->name." : ".$product_attributes->value."</option>"; } echo json_encode($output); } public function quote_order(Request $request, $orderId=null) { // Customer order flow if (is_null($orderId)) { if ($_POST) { session([ 'county_name_quote' => $request->county_name_quote, 'town_name_quote' => $request->town_name_quote, 'product_name_quote' => $request->product_name_quote, 'quantity_name_quote' => $request->quantity_name_quote ]); } elseif($request->session()->has('county_name_quote')) { $request->county_name_quote = session()->get('county_name_quote'); $request->town_name_quote = session()->get('town_name_quote'); $request->product_name_quote = session()->get('product_name_quote'); $request->quantity_name_quote = session()->get('quantity_name_quote'); } else { return redirect()->route('home'); } $town_list = Town::where('county_id',$request->county_name_quote)->orderBy('name', 'asc')->get(); $quantity_list = $this->get_quantity_quote_order_page($request->product_name_quote); if ($request->quantity_name_quote =="fill the tank") { $initial_quote_price = $this->fill_the_tank_price(); } else { $initial_quote_price = $this->get_initial_price($request->quantity_name_quote); } // Calculate the vat $productDetails = Product::find($request->product_name_quote); $vat = 0; if ($productDetails && ($productDetails->count() > 0)) { $vat = (($initial_quote_price * $productDetails->tax) / 100); } return view('front.quote.order',[ 'order_id' => null, 'town_list'=> $town_list, 'quantity_list' => $quantity_list, 'initial_quote_price' => $initial_quote_price, 'product_tax' => $productDetails->tax, 'vat' => $vat ]); } else { // Order created by admin on behalf of customer // Fetch the order details $orderDetails = Order::find($orderId); if ($orderDetails) { // Get the logged-in user $customerId = Auth::id(); // Check if the order is created for this user if ($customerId == $orderDetails->customer_id) { $county = DB::table('county')->where('id', $orderDetails->order_county_id)->first(); $town_list = Town::where('county_id', $orderDetails->order_county_id)->orderBy('name', 'asc')->get(); // Get the order product details $orderProduct = OrderProduct::where('order_id', $orderId)->first(); $quantity_list = $this->get_quantity_quote_order_page($orderProduct->product_id); return view('front.quote.order', [ 'order_id' => $orderId, 'town_list' => $town_list, 'quantity_list' => $quantity_list, 'initial_quote_price' => $orderDetails->total_products, 'product_tax' => $orderDetails->tax_percentage, 'vat' => $orderDetails->tax, 'orderDetails' => $orderDetails, 'orderProduct' => $orderProduct ]); } else { return redirect('/accounts?tab=profile')->with('error', 'You are not authorized to access this order.'); } } else { return redirect('/accounts?tab=profile')->with('error', 'Invalid order.'); } } } public function get_initial_price($product_attribute_id) { $attribute_data = ProductAttribute::find($product_attribute_id); return $attribute_data->price; } public function get_quantity_quote_order_page($product_id) { // Fetch product_attributes_is from product_attributes table $product_attributes_data = DB::table('product_attributes') ->leftJoin('attribute_value_product_attribute', 'attribute_value_product_attribute.product_attribute_id', '=', 'product_attributes.id') ->leftJoin('attribute_values','attribute_values.id','=','attribute_value_product_attribute.attribute_value_id') ->leftJoin('attributes','attributes.id','=','attribute_values.attribute_id') ->select('product_attributes.id','attributes.name','attribute_values.value') ->where('product_attributes.product_id',$product_id) ->orderBy('attribute_values.value', 'asc') ->get(); return $product_attributes_data; } public function fetch_price_order(Request $request) { // Reset the session if ($request->session()->has('quantity_name_quote')) { session([ 'quantity_name_quote' => $request->product_attribute_id]); } $quote_price = $this->get_initial_price($request->product_attribute_id); echo json_encode($quote_price); } public function fetch_price_fill_tank_order(Request $request) { // Reset the session if ($request->session()->has('quantity_name_quote')) { session([ 'quantity_name_quote' => $request->product_attribute_id]); } } public function fill_the_tank_price() { $fill_tank_data = FillTank::find(1); if (!empty($fill_tank_data->price)) { return $fill_tank_data->price; } } /** * Function to check if the discount coupon is valid and available for logged in user * @return array */ public function validateDiscountCoupon(Request $request) { $couponCode = $request->get('coupon_code'); $quotePrice = $request->get('quote_price'); $response = array(); if ($couponCode != '') { // fetch the coupon details $discountCoupon = DiscountCoupon::where(['coupon_code' => $couponCode])->first(); if ($discountCoupon) { // Check if coupon is not expired $todayDate = date('Y-m-d'); $validUpto = $discountCoupon->valid_upto; if ($validUpto > $todayDate) { // Check if coupon is not used by the user $customerId = Auth::id(); $orderDetails = DB::table('orders')->where(['discount_coupon_code' => $couponCode, 'customer_id' => $customerId])->first(); if ($orderDetails) { $response = array('response' => '1', 'message' => 'You have already used this coupon.', 'discount_amount' => 0); } else { // Calculate the discount amount $discountAmount = 0; if ($discountCoupon->coupon_type == 1) { $discountAmount = number_format((($quotePrice * $discountCoupon->discount_value) / 100), 2); } else { $discountAmount = number_format($discountCoupon->discount_value, 2); } $response = array('response' => '0', 'message' => 'Discount of '. config('cart.currency_symbol') . $discountAmount .' will be applied', 'discountAmount' => $discountAmount, 'couponType' => $discountCoupon->coupon_type, 'discountValue' => $discountCoupon->discount_value, 'couponCode' => $couponCode); } } else { $response = array('response' => '2', 'message' => 'Coupon code expired.'); } } else { $response = array('response' => '3', 'message' => 'Invalid coupon code.'); } } else { $response = array('response' => '4', 'message' => 'Enter the coupon code.'); } return response()->json($response); } public function checkSession(){ if (Auth::guard('employee')->check()) { $response = array('status' => '1', 'message' => 'Success'); return response()->json($response); } else{ $response = array('status' => '0', 'message' => 'Session expired.'); return response()->json($response); } } public function storeCookie(Request $request){ $consentLog = ConsentLog::where("ip_addr", $request->myip)->first(); if($consentLog){ $consentLog->visited_date = date("Y-m-d"); $consentLog->viewed_cookie = "Yes"; $consentLog->ip_addr = $request->myip; $consentLog->necessary = ($request->necessary) ? "Yes" : "No"; $consentLog->marketing = ($request->marketing) ? "Yes" : "No"; $consentLog->analytics = ($request->analytics) ? "Yes" : "No"; $consentLog->preferences = ($request->preferences) ? "Yes" : "No"; $consentLog->unclassified = ($request->unclassified) ? "Yes" : "No"; $consentLog->save(); return "success"; } else{ $consentLog = new ConsentLog(); $consentLog->visited_date = date("Y-m-d"); $consentLog->viewed_cookie = "Yes"; $consentLog->ip_addr = $request->myip; $consentLog->necessary = ($request->necessary) ? "Yes" : "No"; $consentLog->marketing = ($request->marketing) ? "Yes" : "No"; $consentLog->analytics = ($request->analytics) ? "Yes" : "No"; $consentLog->preferences = ($request->preferences) ? "Yes" : "No"; $consentLog->unclassified = ($request->unclassified) ? "Yes" : "No"; $consentLog->save(); return "success"; } } public function cronCookie(){ $todayDate = date("Y-m-d"); $optionList = CookieListOption::get(); foreach($optionList as $optList) { if($optList->duration != "Persistent"){ $expiryDate = date("Y-m-d", strtotime($todayDate. ' - '.$optList->duration)); ConsentLog::where("visited_date", "<", $expiryDate)->delete(); } } } }