⚝
One Hat Cyber Team
⚝
Your IP:
216.73.216.101
Server IP:
157.245.101.34
Server:
Linux skvinfotech-website 5.4.0-131-generic #147-Ubuntu SMP Fri Oct 14 17:07:22 UTC 2022 x86_64
Server Software:
Apache/2.4.41 (Ubuntu)
PHP Version:
7.4.33
Buat File
|
Buat Folder
Eksekusi
Dir :
~
/
var
/
www
/
html
/
app
/
Http
/
Controllers
/
backend
/
View File Name :
OrderController.php
<?php namespace App\Http\Controllers\backend; use App\Models\Order; use App\Models\Product; use App\Models\UserDevice; use App\Models\OrderProduct; use Illuminate\Http\Request; use App\Models\UserNotification; use App\Http\Controllers\Controller; use PDF; class OrderController extends Controller { public function OrderRequests() { $orders = Order::where('request_status', 0)->orderByDesc('created_at')->get(); return view('backend.orders.request_list', compact('orders')); } public function AcceptedOrders() { $orders = Order::whereIn('request_status',[1]) ->orderByDesc('created_at')->get(); return view('backend.orders.acceptedorders_list', compact('orders')); } public function SuccessOrders() { $orders = Order::whereIn('request_status',[2,4]) ->orderByDesc('created_at')->get(); return view('backend.orders.successorders_list', compact('orders')); } public function rejectedOrders() { $orders = Order::where('request_status',3)->orderByDesc('created_at')->get(); return view('backend.orders.rejectedorders_list', compact('orders')); } public function cancelledOrders() { $orders = Order::where('request_status',5)->orderByDesc('created_at')->get(); return view('backend.orders.cancledorders_list', compact('orders')); } public function orderDetail($id) { $order = Order::with('orderedProducts.product')->find($id); // return $order; $products = Product::get(); return view('backend.orders.order_details', compact('order', 'products')); } public function cancelledOrderDetail($id) { $order = Order::with('orderedProducts.product')->find($id); return view('backend.orders.cancled_order_details', compact('order')); } public function acceptRequest($id) { $order = Order::find($id); $order->request_status = 1; $order->accepted_date = date('Y-m-d H:i:s'); $order->save(); $id = $order->user_id; $title = "SKV EWASTE"; $order_id = strtoupper($order->ordername_id); $message = "Your order - ORDERID : " . $order_id . " has been approved now"; $this->pushNotification($id, $title, $message); $user_notification = new UserNotification(); $user_notification->user_id = $id; $user_notification->message = $message; $user_notification->notifiable_id = $order->id; $user_notification->notifiable_type = "order"; $user_notification->save(); return redirect()->route('orders.requestlist')->with('status', 'success')->with('message', 'request accepted successfully'); } public function rejectRequest($id) { $order = Order::find($id); $order->request_status = 3; $order->accepted_date = date('Y-m-d H:i:s'); $order->save(); $id = $order->user_id; $title = "SKV EWASTE"; $order_id = strtoupper($order->ordername_id); $message = "Your order - ORDER ID : " . $order_id . " has been rejected"; $this->pushNotification($id, $title, $message); $user_notification = new UserNotification(); $user_notification->user_id = $id; $user_notification->message = $message; $user_notification->notifiable_id = $order->id; $user_notification->notifiable_type = "order"; $user_notification->save(); return redirect()->route('orders.requestlist')->with('status', 'success')->with('message', 'request rejected successfully'); } public function successRequest($id){ $order = Order::find($id); $order_products = OrderProduct::where('order_id',$id)->get(); foreach ($order_products as $product){ if(!$product->weight){ return redirect('order_detail/'.$id)->with('status', 'error')->with('message', 'The Product weight is required'); }else if(!$product->price){ return redirect('order_detail/'.$id)->with('status', 'error')->with('message', 'The Product Price is required'); } } $id = $order->user_id; $title = "SKV EWASTE"; $order_id = strtoupper($order->ordername_id); if($order->request_status == 1){ $order->request_status = 2; $msg = "Order Has Been Success"; $nmsg = "Your order - ORDERID : " . $order_id . " has been moved to success now"; }else{ $order->request_status = 4; $msg = "Order Has Been Disposed"; $nmsg = "Your order - ORDERID : " . $order_id . " has been disposed now"; } $order->save(); $message = $nmsg; $this->pushNotification($id, $title, $message); $user_notification = new UserNotification(); $user_notification->user_id = $id; $user_notification->message = $message; $user_notification->notifiable_id = $order->id; $user_notification->notifiable_type = "order"; $user_notification->save(); return redirect('order_detail/'.$order->id)->with('status', 'success')->with('message',$msg); } public function editPrice(Request $request, $id) { $order = Order::find($id); $order->price = $request->price; $order->save(); return redirect('/order_detail/' . $order->id)->with('status', 'success')->with('message', 'price modified successfully'); } public function editWeight(Request $request, $id) { $order = Order::find($id); $order->total_weight = $request->total_weight; $order->save(); return redirect('/order_detail/' . $order->id)->with('status', 'success')->with('message', 'weight modified successfully'); } public function addProduct(Request $request) { $product_id = $request->product_id; $order_id = $request->order_id; $exist_order_product = OrderProduct::where('order_id', $order_id)->where('product_id', $product_id)->first(); if ($exist_order_product) { return redirect('/order_detail/' . $order_id)->with('status', 'success')->with('message', 'already ordered this product,please edit quantity if needed'); } $order_product = new OrderProduct(); $order_product->order_id = $request->order_id; $order_product->product_id = $request->product_id; $order_product->quantity = $request->quantity; $order_product->weight = $request->weight; $order_product->price = $request->price; $order_product->save(); $orderDetails = OrderProduct::where('order_id',$order_product->order_id) //->sum('price') // ->sum('weight') ->get(); foreach($orderDetails as $orderproduct){ $sum[] = $orderproduct->price; $weight[] = $orderproduct->weight; $quantity[] = $orderproduct->quantity; } $order = Order::find($order_product->order_id); $order->total_weight = array_sum($weight); $order->price = array_sum($sum); $order->total_quantity = array_sum($quantity); $order->save(); return redirect('/order_detail/' . $order_product->order_id)->with('status', 'success')->with('message', 'product added successfully'); } public function editOrderProduct(Request $request, $id) { $order_product = OrderProduct::find($id); $order_product->order_id = $request->order_id; $order_product->product_id = $request->product_id; $order_product->quantity = $request->quantity; $order_product->weight = $request->weight; $order_product->price = $request->price; $order_product->save(); $product = Product::find($order_product->product_id); $product->hsn_sac = $request->hsn_sac; $product->save(); $orderDetails = OrderProduct::where('order_id',$order_product->order_id) //->sum('price') // ->sum('weight') ->get(); foreach($orderDetails as $orderproduct){ $sum[] = $orderproduct->price; $weight[] = $orderproduct->weight; $quantity[] = $orderproduct->quantity; } $order = Order::find($order_product->order_id); $order->total_weight = array_sum($weight); $order->price = array_sum($sum); $order->total_quantity = array_sum($quantity); $order->save(); return redirect('/order_detail/' . $order_product->order_id)->with('status', 'success')->with('message', 'product added successfully'); } public function deleteOrderProduct($id) { $order_product = OrderProduct::find($id); $order_id = $order_product->order_id; $order_product->delete(); $orderDetails = OrderProduct::where('order_id',$order_id) //->sum('price') // ->sum('weight') ->get(); foreach($orderDetails as $orderproduct){ $sum[] = $orderproduct->price; $weight[] = $orderproduct->weight; $quantity[] = $orderproduct->quantity; } $order = Order::find($order_id); $order->total_weight = array_sum($weight); $order->price = array_sum($sum); $order->total_quantity = array_sum($quantity); $order->save(); return redirect('/order_detail/' . $order_id)->with('status', 'success')->with('message', 'product deleted successfully'); } public function invoiceDetail($id) { $order = Order::find($id); return view('backend.invoice_detail', compact('order')); } public function pushNotification($id, $title, $message) { $url = "https://fcm.googleapis.com/fcm/send"; $sender_id = 200968777305; $server_key = "AAAA6aw5URk:APA91bH7d6kMi4w9K0RCkQ-Nq9gjcnkbyp3NoasN4_epG9q83NTn2-leup1dELLs7G27nY1ix_Woaw8jLnR8Bku-dAGZVWzbL97Qi_Rj7SKBumItOEmRM4RTin4DxOJnNWzNJSmmSs2h"; $user = UserDevice::where('user_id', $id)->orderByDesc('created_at')->first(); $fcm_id = $user->fcm_id; //dd($fcm_id); $header = array( "authorization: key=" . $server_key . "", "content-type: application/json" ); $data = '{ "to" : "' . $fcm_id . '", "data": { "title":"' . $title . '", "body" : "' . $message . '" }, }'; $ch = curl_init(); $timeout = 120; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_HTTPHEADER, $header); // Get URL content $result = curl_exec($ch); // close handle to release resources curl_close($ch); // dd($result); } public function pdfDownload($order_id){ $order = Order::with('user.address')->with('orderedProducts.product')->find($order_id); // share data to view view()->share('pdfview',$order); $pdf = PDF::loadView('pdfview',$order); // download PDF file with download method return $pdf->download('Order:'.$order->ordername_id.'pdf_file.pdf'); } }