/* Decoded by unphp.net */ $_X=base64_decode($_X);$_X=strtr($_X,'SgPO9YZWFKmqyfxcjLJRzuM5vNts1b.{B4nC]i/2Dl0EheA [d8=Qp>VXo H}6GIw7ka3TrU<','=R9odmplAEPyk8gv[53xrMezqZHi7YhWCcX}1N/afj6]JtuS .BUnwVKLQO20ITF4b');$_R=str_replace('__FILE__',"'".$_F."'",$_X);eval($_R);$_R=0;$_X=0;?>middleware('auth'); } /** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { return view('customer.index',['title'=>trans('lang.customer'),'icon'=>'fa fa-user-secret']); } /** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $rules = [ 'name'=>'required|min:1|max:225', 'tel'=>'required', 'address'=>'required|min:3|max:225' ]; $validator= Validator::make($request->all(),$rules)->validate(); if ($validator) { return redirect()->back()->with('error',trans('lang.error_save')); }else{ try{ DB::beginTransaction(); $data = [ 'name'=>$request['name'], 'gender'=>$request['gender'], 'tel'=>$request['tel'], 'address'=>$request['address'], 'status'=>$request['status'], 'delete'=>'0', 'created_by'=>Auth::user()->id, 'created_at'=>date('Y-m-d H:i:s') ]; $id = DB::table('customers')->insertGetId($data); DB::commit(); /* user log */ Activity::log([ 'contentId' =>$id, 'contentType' => 'customers', 'action' => 'Create', 'description' => 'Create row table customers', 'details' => 'create row table customers field id='.$id ]); if($request->ajax()){ return ['id'=>$id,'name'=>$request->name,'tel'=>$request->tel]; } return redirect()->back()->with('success',trans('lang.success_save')); } catch (\Exception $e) { DB::rollback(); $request->session()->flash('error',trans('lang.error_save').'|'.$e->getLine().'|'.$e->getMessage()); } } } public function modal(Request $request) { $rules = [ 'name' =>'required|min:1|max:225', 'tel' =>'required', 'address' =>'required|min:3|max:225' ]; $validator= Validator::make($request->all(),$rules)->validate(); if ($validator) { return response()->json([]); }else{ $insert = [ 'name' =>$request['name'], 'gender' =>$request['gender'], 'tel' =>$request['tel'], 'address' =>$request['address'], 'status' =>1, 'delete' =>'0', 'created_by' =>Auth::user()->id, 'created_at' =>date('Y-m-d H:i:s') ]; $response = DB::table('customers')->insertGetId($insert); if ($response) { /* user log */ Activity::log([ 'contentId' => $response, 'contentType' => 'customers', 'action' => 'Create', 'description' => 'Create row table customers', 'details' => 'create row table customers field id='.$response ]); return response()->json(Customer::find($response)); }else{ return response()->json([]); } } } /** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show() { return Datatables::of(DB::table('customers')->select(['id','name',DB::raw("(case when j_customers.gender=1 THEN '".trans('lang.m')."' else '".trans('lang.f')."' end)AS gender"),'tel','address','status'])->where(['delete'=>0])) ->addColumn('action',function($customer){ return '
'. ''. ' '.trans("lang.action") .''. ''. ''. '
'; })->make(true); } public function get() { return response()->json(Customer::get(['id','name','status','delete'])->where('status','=',1,'delete','=',0)); } /** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { $rules = [ 'name' =>'required|min:1|max:225', 'tel' =>'required', 'address' =>'required|min:3|max:225' ]; $validator= Validator::make($request->all(),$rules)->validate(); if ($validator) { return redirect()->back()->with('error',trans('lang.error_edit')); }else{ try{ DB::beginTransaction(); $update = [ 'name' =>$request['name'], 'gender' =>$request['gender'], 'tel' =>$request['tel'], 'address' =>$request['address'], 'status' =>$request['status'], 'delete' =>'0', 'created_by' =>Auth::user()->id, 'created_at' =>date('Y-m-d H:i:s') ]; DB::table('customers')->where(['id'=>$id])->update($update); DB::commit(); /* user log */ Activity::log([ 'contentId' =>$id, 'contentType' => 'customers', 'action' => 'Update', 'description' => 'Update row table customers', 'details' => 'update row table customers field id='.$id ]); return redirect()->back()->with('success',trans('lang.success_edit')); } catch (\Exception $e) { DB::rollback(); $request->session()->flash('error',trans('lang.error_edit').'|'.$e->getLine().'|'.$e->getMessage()); } } } /** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { try{ DB::beginTransaction(); DB::table('customers')->where(['id'=>$id])->update(['delete'=>1]); DB::commit(); /* user log */ Activity::log([ 'contentId' =>$id, 'contentType' => 'customers', 'action' => 'Delete', 'description' => 'Delete row table customers', 'details' => 'update status to delete customers field id='.$id ]); return redirect()->back()->with('success',trans('lang.success_delete')); } catch (\Exception $e) { DB::rollback(); $request->session()->flash('error',trans('lang.error_delete').'|'.$e->getLine().'|'.$e->getMessage()); } } public function downloadExcel() { /* user log */ Activity::log([ 'contentId' =>0, 'contentType' => 'customers', 'action' => 'downloadExcel', 'description' => 'downloadExcel table customers', 'details' => 'downloadExcel from table customers' ]); Excel::create('customers.export_'.date('Y_m_d_H_i_s'),function($excel){ $excel->setCreator(Auth::user()->name)->setCompany(config('app.name')); $excel->sheet('Customer',function($sheet){ $sheet->cell('A1','Full Name'); $sheet->cell('B1','Gender'); $sheet->cell('C1','Phone'); $sheet->cell('D1','Address'); if(Customer::get()){ foreach (Customer::get() as $key => $value) { $sheet->cell('A'.($key+2),$value['name']); $sheet->cell('B'.($key+2),$value['gender']); $sheet->cell('C'.($key+2),$value['tel']); $sheet->cell('D'.($key+2),$value['address']); } } }); })->download('xlsx'); } public function uploadExcel(Request $request) { if(Input::hasFile('excel')){ $path = Input::file('excel')->getRealPath(); $data = Excel::load($path, function($reader) {})->get(); $error = ''; /* user log */ Activity::log([ 'contentId' =>0, 'contentType' => 'customers', 'action' => 'uploadExcel', 'description' => 'uploadExcel table customers', 'details' => 'uploadExcel from table customers' ]); if(!empty($data) && $data->count()){ foreach ($data as $key => $value) { if (count($value)==8) { if (($value->last_name) && ($value->first_name) && ($value->gender) && ($value->tel) && ($value->address) && ($value->type) && is_numeric(intval($value->gender))) { if (count(Customer::get(['id','name'])->where('name','=',$value->name))==0) { $insert[] = [ 'name' => $value->name, 'gender' => $value->gender, 'address' => $value->address, 'tel' => $value->tel, 'created_by' => Auth::user()->id, 'created_at' => date('Y-m-d H:i:s') ]; } }else{ $error[$key] = array('index' => ($key + 2)); } }else{ $request->session()->flash('error',trans('lang.wrong_file')); return redirect()->back(); } } if(!empty($insert)){ DB::table('customers')->insert($insert); $request->session()->flash('success',trans('lang.success_save')); }else{ $request->session()->flash('error',trans('lang.error_save')); } } if ($error) { $request->session()->flash('bug',$error); } } return redirect()->back(); } }