/**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function search()
 {
     Log::info("Into SpecialController");
     $design_trend_B = Input::get('design_trend_B');
     $search = Input::get('search');
     $sortBy = Input::get('sortBy');
     $orderBy = Input::get('orderBy');
     if (empty($design_trend_B)) {
         $design_trend_B = Auth::user()->empId;
     }
     $datas = MmnameModel::on(DBUtils::getDBName())->newQuery();
     if (Input::has('page')) {
         // paging
         Log::info("into paging");
         $search = session()->get('design_trend_search');
         $sortBy = session()->get('sortBy');
         $orderBy = session()->get('orderBy');
         $design_trend_B = session()->get('design_trend_B');
     }
     if (!empty($search)) {
         $datas = $datas->Where(function ($datas) use($search) {
             $datas->orWhere('A', 'LIKE', "%{$search}%");
         });
     }
     if (!empty($design_trend_B) && $design_trend_B != -1) {
         $datas = $datas->Where('B', '=', "{$design_trend_B}");
     }
     if (!empty($sortBy) && !empty($orderBy)) {
         $datas = $datas->orderBy($sortBy, $orderBy);
     }
     session()->put('sortBy', $sortBy);
     session()->put('orderBy', $orderBy);
     session()->put('design_trend_search', $search);
     session()->put('design_trend_B', $design_trend_B);
     // $datas=$datas->orderBy('updated_at','DESC')->paginate(10);
     $datas = $datas->paginate(10);
     //$mmtrend_groups = DB::connection(DBUtils::getDBName())->table('mmtrend_group')->where('mmplant','=',session()->get('user_mmplant'))->get();
     //
     $mmtrend_groups = DB::table('mmtrend_group')->where('mmplant', '=', session()->get('user_mmplant'));
     if (session()->get('user_priority') < 128) {
         $mmtrend_groups = $mmtrend_groups->where('B', '=', '9');
     }
     $mmtrend_groups = $mmtrend_groups->get();
     return view('ais/special', ['mmtrendsM' => $datas, 'mmtrend_groups' => $mmtrend_groups]);
 }
Exemple #2
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function copyTrend(Request $request)
 {
     Log::info("copyTrend");
     $id = request('ZZ');
     $trend_name = request('trend_name');
     $target_group = request('target_group');
     $target_unit = request('target_unit');
     Log::info("ZZ[" . $id . "],trend_name[" . $trend_name . "],target_group[" . $target_group . "]\n        target_unit[" . $target_unit . "]");
     if ($target_group == '9') {
         $target_group = Auth::user()->empId;
     }
     $isExcessTrend = false;
     $maxTrend = 0;
     $count = 0;
     $user_priority = session()->get('user_priority');
     if (request('target_group') == '9') {
         $countMyTrend = DB::connection(DBUtils::getDBName())->table('mmname_table')->where('B', '=', $target_group)->count();
         if ($user_priority < 128) {
             $isExcessTrend = $countMyTrend > 3;
             $maxTrend = 4;
         } else {
             if ($user_priority < 201) {
                 $isExcessTrend = $countMyTrend > 48;
                 $maxTrend = 49;
             } else {
                 if ($user_priority < 255) {
                     $isExcessTrend = $countMyTrend > 98;
                     $maxTrend = 99;
                 } else {
                     $isExcessTrend = $countMyTrend > 9998;
                     $maxTrend = 9999;
                 }
             }
         }
     }
     $mmtrendM = MmnameModel::on(DBUtils::getDBName())->find($id);
     if (!empty($mmtrendM) && !$isExcessTrend) {
         // set target group
         $count = DB::connection(DBUtils::getDBName())->table('mmname_table')->where('A', '=', $trend_name)->where('B', '=', $target_group)->count();
         if ($count == 0) {
             $mmtrendM_new = new MmnameModel();
             $mmtrendM_new->setConnection(DBUtils::getDBName());
             $mmtrendM_new->A = $trend_name;
             if ($target_group == '9') {
                 $mmtrendM_new->B = Auth::user()->empId;
             } else {
                 $mmtrendM_new->B = $target_group;
             }
             $mmtrendM_new->save();
             $mmtrends = MmtrendModel::on(DBUtils::getDBName())->where('G', $id)->get();
             if (!empty($mmtrends)) {
                 foreach ($mmtrends as $mmtrend) {
                     $mmtrendModel_new = new MmtrendModel();
                     $mmtrendModel_new->setConnection(DBUtils::getDBName());
                     $mmtrendModel_new->A = $mmtrend->A;
                     if ($target_unit == '0') {
                         $mmtrendModel_new->B = $mmtrend->B;
                     } else {
                         $mmtrendModel_new->B = $target_unit;
                     }
                     $mmtrendModel_new->C = $mmtrend->C;
                     $mmtrendModel_new->D = $mmtrend->D;
                     $mmtrendModel_new->E = $mmtrend->E;
                     $mmtrendModel_new->F0 = $mmtrend->F0;
                     $mmtrendModel_new->F1 = $mmtrend->F1;
                     $mmtrendModel_new->H = $mmtrend->H;
                     $mmtrendModel_new->I = $mmtrend->I;
                     $mmtrendModel_new->G = $mmtrendM_new->ZZ;
                     $mmtrendModel_new->save();
                 }
             }
         }
     }
     Log::info("mmnameModel ->" . $mmtrendM->A);
     return response()->json(['mmtrendM' => json_encode($mmtrendM), 'count' => json_encode($count), 'isExcessTrend' => json_encode($isExcessTrend), 'maxTrend' => json_encode($maxTrend)]);
 }