Ejemplo n.º 1
0
 public function jqgrid(Request $request)
 {
     // TODO: must be in inventory
     //        return dd($request->all());
     if (Auth::check()) {
         if (in_array('ADD_EDIT_BIDPROFILE', $this->permission)) {
             //permission goes here
             $rules = array('domain' => 'required', 'bid_strategy' => 'required');
             if ($request->input('oper') == 'edit' or $request->input('oper') == 'del') {
                 $rules['bid_value'] = 'required';
             } else {
                 if ($request->input('bid_strategy') == 'Absolute' or $request->input('bid_strategy') == 1) {
                     $rules['bid_value'] = 'required';
                 } else {
                     $rules["bid_value1"] = 'required';
                 }
             }
             $validate = \Validator::make($request->all(), $rules);
             if ($validate->passes()) {
                 //                    return dd($request->input('parent_id'));
                 if (User::isSuperAdmin()) {
                     $bid_profile_obj = Bid_Profile::find($request->input('parent_id'));
                 } else {
                     $usr_company = $this->user_company();
                     $bid_profile_obj = Bid_Profile::whereHas('getAdvertiser', function ($q) use($usr_company) {
                         $q->whereHas('GetClientID', function ($p) use($usr_company) {
                             $p->whereIn('user_id', $usr_company);
                         });
                     })->find($request->input('parent_id'));
                     if (!$bid_profile_obj) {
                         return Redirect::back()->withErrors(['success' => false, 'msg' => 'please Select your Client'])->withInput();
                     }
                 }
                 if ($bid_profile_obj) {
                     if (preg_match($this->pattern, $request->input('domain'))) {
                         //                            return dd($request->all());
                         $audit = new AuditsController();
                         switch ($request->input('oper')) {
                             case 'add':
                                 $chk = Bid_Profile_Entry::where('bid_profile_id', $request->input('parent_id'))->get();
                                 foreach ($chk as $index) {
                                     if ($index->domain == $request->input('domain')) {
                                         return Redirect::back()->withErrors(['success' => false, 'msg' => 'this name already existed !!!'])->withInput();
                                     }
                                 }
                                 $bid_profile_entry = new Bid_Profile_Entry();
                                 $bid_profile_entry->domain = $request->input('domain');
                                 $bid_profile_entry->bid_strategy = $request->input('bid_strategy');
                                 $bid_profile_entry->bid_profile_id = $request->input('parent_id');
                                 $bid_profile_entry->bid_value = $request->has('bid_value') ? $request->input('bid_value') : $request->input('bid_value1');
                                 $bid_profile_entry->save();
                                 $audit->store('bid_profile_entry', $bid_profile_entry->id, $request->input('parent_id'), 'add');
                                 return $msg = ['success' => true, 'msg' => "your Entry has been Added"];
                                 break;
                             case 'edit':
                                 $bid_profile_entry = Bid_Profile_Entry::where('bid_profile_id', $request->input('parent_id'))->where('id', $request->input('id'))->first();
                                 if ($bid_profile_entry) {
                                     $data = array();
                                     if ($bid_profile_entry->domain != $request->input('domain')) {
                                         array_push($data, 'Domain');
                                         array_push($data, $bid_profile_entry->domain);
                                         array_push($data, $request->input('domain'));
                                         $bid_profile_entry->domain = $request->input('domain');
                                     }
                                     $bid_strategy = $request->input('bid_strategy') == 1 ? 'Absolute' : 'Percentage';
                                     //                                        return dd($bid_strategy);
                                     if ($bid_profile_entry->bid_strategy != $bid_strategy) {
                                         array_push($data, 'Bid Strategy');
                                         array_push($data, $bid_profile_entry->bid_strategy);
                                         array_push($data, $bid_strategy);
                                         $bid_profile_entry->bid_strategy = $bid_strategy;
                                     }
                                     if ($bid_profile_entry->bid_value != $request->input('bid_value')) {
                                         array_push($data, 'Bid Value');
                                         array_push($data, $bid_profile_entry->bid_value);
                                         array_push($data, $request->input('bid_value'));
                                         $bid_profile_entry->bid_value = $request->input('bid_value');
                                     }
                                     $audit->store('bid_profile_entry', $request->input('id'), $data, 'edit');
                                     $bid_profile_entry->save();
                                     return $msg = ['success' => true, 'msg' => "your Entry has been Edited"];
                                 }
                                 return 'some things went wrong!';
                                 break;
                             case 'del':
                                 $audit = new AuditsController();
                                 $d = array($request->input('id'), $request->input('parent_id'));
                                 $audit->store('bid_profile_entry', $request->input('id'), $d, 'del');
                                 Bid_Profile_Entry::where('id', $request->input('id'))->where('bid_profile_id', $request->input('parent_id'))->delete();
                                 return $msg = ['success' => true, 'msg' => "your Entry has been Deleted"];
                                 break;
                         }
                     }
                     return $msg = ['success' => false, 'msg' => "PLZ enter valid Web site domain"];
                 }
                 return $msg = ['success' => false, 'msg' => "please select correct Bid Profile!"];
             }
             //return print_r($validate->messages());
             return $msg = ['success' => false, 'msg' => "please Check your fields"];
         }
     }
     return Redirect::to(url('/user/login'));
 }