|
6 | 6 | use App\Models\Setting;
|
7 | 7 | use Gloudemans\Shoppingcart\Facades\Cart;
|
8 | 8 | use Illuminate\Http\Request;
|
9 |
| - |
| 9 | +use Illuminate\Support\Facades\DB; |
10 | 10 |
|
11 | 11 | class CartController extends Controller
|
12 | 12 | {
|
@@ -67,4 +67,87 @@ public function invoice(Request $request){
|
67 | 67 | $customer_info = Customer::find($request->cus_id);
|
68 | 68 | return view('dashbord.Pos.invoice',compact('customer_info','setting'));
|
69 | 69 | }
|
| 70 | + |
| 71 | + |
| 72 | + //order information save in database |
| 73 | + public function order_store(Request $request){ |
| 74 | + |
| 75 | + |
| 76 | + if (!empty($request->pay)) {//just check not empty pay fild |
| 77 | + |
| 78 | + $input_amount =$request->pay + $request->due; |
| 79 | + $order = Cart::total(); |
| 80 | + if ($input_amount > $order) { |
| 81 | + $notification = array( |
| 82 | + 'message' => 'Your Payment Amount And Your Order Bill not same', |
| 83 | + 'alert-type' => 'error' |
| 84 | + ); |
| 85 | + return redirect()->back()->with($notification); |
| 86 | + }else{ |
| 87 | + $data = array(); |
| 88 | + $data['customar_id'] = $request->customer_id; |
| 89 | + $data['order_date'] = date('d/m/y'); |
| 90 | + $data['order_status'] = 'panding'; |
| 91 | + $data['total_products'] = Cart::count(); |
| 92 | + $data['sub_total'] = Cart::subtotal(); |
| 93 | + $data['vat'] = Cart::tax();//set vat 5% |
| 94 | + $data['total'] = Cart::total(); |
| 95 | + $data['payment_status'] = $request->payment_status; |
| 96 | + $data['pay'] = $request->pay; |
| 97 | + $data['due'] = $request->due; |
| 98 | + |
| 99 | + $order_id = DB::table('orders')->insertGetId($data); |
| 100 | + |
| 101 | + |
| 102 | + //right now insert data in orderdetails table |
| 103 | + $contant = Cart::content(); //all cart information save this variable |
| 104 | + foreach ($contant as $contant_item) { |
| 105 | + $order_data = array(); |
| 106 | + $order_data['order_id'] = $order_id;//same id of orders |
| 107 | + $order_data['product_id'] = $contant_item->id; |
| 108 | + $order_data['quentity'] = $contant_item->qty; |
| 109 | + $order_data['unitcost'] = $contant_item->price; |
| 110 | + $order_data['total'] = $contant_item->total; |
| 111 | + |
| 112 | + //insert order data in orderdatils table |
| 113 | + $order_insert = DB::table('orderdatils')->insert($order_data); |
| 114 | + } |
| 115 | + if ($order_insert) { |
| 116 | + Cart::destroy(); |
| 117 | + $notification = array( |
| 118 | + 'message' => 'Complete order', |
| 119 | + 'alert-type' => 'info' |
| 120 | + ); |
| 121 | + return redirect()->route('dashboard')->with($notification); |
| 122 | + }else{ |
| 123 | + $notification = array( |
| 124 | + 'message' => 'Plz try agin', |
| 125 | + 'alert-type' => 'error' |
| 126 | + ); |
| 127 | + return redirect()->route('dashboard')->with($notification); |
| 128 | + } |
| 129 | + |
| 130 | + } |
| 131 | + |
| 132 | + |
| 133 | + } else { |
| 134 | + $notification = array( |
| 135 | + 'message' => 'Required pay fild', |
| 136 | + 'alert-type' => 'error' |
| 137 | + ); |
| 138 | + return redirect()->back()->with($notification); |
| 139 | + } |
| 140 | + |
| 141 | + } |
| 142 | + //panding order |
| 143 | + public function panding_order(){ |
| 144 | + $panding_order = DB::table('orders') |
| 145 | + ->join('customers','orders.customar_id','customers.id') |
| 146 | + ->select('customers.name','customers.email','orders.*') |
| 147 | + ->where('order_status','panding')->get(); |
| 148 | + return view('dashbord.Order.pandingorder',compact('panding_order')); |
| 149 | + } |
| 150 | + |
| 151 | + |
| 152 | + |
70 | 153 | }
|
0 commit comments