Exemplo n.º 1
0
 public static function getThemAllLastStatus($files)
 {
     $xfiles = [];
     $xfiles['aviser'] = [];
     $xfiles['repair_to_do'] = [];
     $xfiles['order_to_do'] = [];
     foreach ($files as $key => $file) {
         if (isset($file['laststatus'][0])) {
             $last = $file['laststatus'][0]['code'];
             if ($last['label'] == 'PE' || $last['label'] == 'PED') {
                 $xfiles['aviser'][] = $files[$key];
             } else {
                 if ($last['label'] == 'I/A' || $last['label'] == 'TDY' || $last['label'] == 'EC') {
                     $xfiles['repair_to_do'][] = $files[$key];
                 } else {
                     if ($last['label'] == 'TW') {
                         if ($file['type'] == 'ORDER') {
                             $details = OrderDetails::where('file_id', $file['id'])->with('article.supplier')->get();
                             $files[$key]['order_details'] = $details;
                         } else {
                             $details = RepairDetails::where('file_id', $file['id'])->with('article.supplier')->get();
                             $files[$key]['order_details'] = $details;
                         }
                         $xfiles['order_to_do'][] = $files[$key];
                     } else {
                     }
                 }
             }
         }
     }
     return $xfiles;
 }
Exemplo n.º 2
0
 public function handleAction(Request $request)
 {
     $action = $request->input('_action');
     if ($action == 'addDevice') {
         $this->validate($request, ['serial_number' => 'unique:devices']);
         $date = Device::convertDate($request->input('purchased_at'));
         $id = DB::table('devices')->insertGetId(['serial_number' => $request->input('serial_number'), 'purchased_at' => $date, 'model_id' => $request->input('model_id')]);
         //Device::create( $request->all() );
         return response(['status' => 'success', 'new_added_id' => $id]);
     } else {
         if ($action == 'createRepair') {
             if ($request['device_id'] != '') {
                 $id = File::create($request->all())->id;
                 Repair::create(['file_id' => $id, 'device_id' => $request->input('device_id'), 'accessory' => $request->input('accessory'), 'description' => $request->input('description')]);
                 $leftmenu['files'] = 'active';
                 $param['code_status_id'] = '4';
                 $param['file_id'] = $id;
                 $param['created_at'] = date('d/m/Y, H:i:s');
                 $param['user_id'] = Auth::user()->id;
                 $param['comment'] = '';
                 $response = StatusFile::create($param);
                 File::find($id)->touch();
                 if (isset($request['devis'])) {
                     $param['code_status_id'] = "15";
                     $response = StatusFile::create($param);
                     File::find($id)->touch();
                 }
                 return response(['status' => 'success', 'redirect' => '/file/repair/' . $id]);
             } else {
                 return response(['status' => 'error']);
             }
         } else {
             if ($action == 'createOrder') {
                 $order_details = session()->has('order_details') ? session('order_details') : false;
                 if ($order_details) {
                     $id = File::create($request->all())->id;
                     Order::create(["file_id" => $id, "total_details_amount" => $order_details['total']]);
                     $param['code_status_id'] = '4';
                     $param['file_id'] = $id;
                     $param['created_at'] = date('d/m/Y, H:i:s');
                     $param['user_id'] = Auth::user()->id;
                     $param['comment'] = '';
                     $response = StatusFile::create($param);
                     File::find($id)->touch();
                     foreach ($order_details as $order_item) {
                         if (isset($order_item['price'])) {
                             OrderDetails::create(["file_id" => $id, "article_id" => $order_item['article_id'], "price" => $order_item['price'], "quantity" => $order_item['quantity']]);
                         }
                     }
                     $request->session()->forget('order_details');
                     return response(['status' => 'success', 'redirect' => '/file/order/' . $id]);
                 }
                 return response(['status' => 'error']);
             } else {
                 if ($action == 'calculateOrder') {
                     $list = json_decode($request['_params'], true);
                     $response = Order::calculateTotal($list['orders']);
                     $list['orders']['total'] = $response;
                     $response != 0 ? Session::put('order_details', $list['orders']) : '';
                     $response = $response != 0 ? ['status' => 'success', 'total' => $response] : ['status' => 'error'];
                     return response($response);
                 } else {
                     return response(['status' => 'error']);
                 }
             }
         }
     }
 }
Exemplo n.º 3
0
 public function saveOrder(Request $request)
 {
     $input = $request->all();
     $validator = $this->validator($input);
     if ($validator->fails()) {
         return redirect('user/cart/order')->withErrors($validator);
     } else {
         $customer = new Customer();
         $customer->user_id = Auth::user()->id;
         $customer->customerName = $request->input('customerName');
         $customer->phone = $request->input('phone');
         $customer->address = $request->input('address');
         $customer->email = $request->input('email');
         $customer->save();
         $total = Cart::total();
         $order = new Order();
         $order->totalPrice = $total;
         $order->requiredDate = $request->input('requiredDate');
         $order->status = "0";
         $order->customer_id = $customer->id;
         $order->comment = "";
         $order->save();
         $carts = Cart::content();
         foreach ($carts as $cart) {
             $orderdetail = new OrderDetails();
             $orderdetail->order_id = $order->id;
             $orderdetail->quantity = $cart->qty;
             $orderdetail->size = $cart->options->size;
             $orderdetail->product_id = $cart->id;
             $orderdetail->save();
         }
         Mail::send('users.mails.order', array('name' => $customer->customerName), function ($message) use($customer) {
             $message->from('hunguetit@gmail.com', 'Bicycle Sport Shop');
             $message->to($customer->email, $customer->customerName)->subject('Thanks you for ordering at Bicycle Sport Shop!');
         });
         return redirect('');
     }
 }