Пример #1
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 {
         return response(['status' => 'error']);
     }
 }
Пример #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']);
                 }
             }
         }
     }
 }