ÿØÿà JFIF ÿá Exif MM * ÿÛ C
Server IP : 199.250.214.225 / Your IP : 18.119.106.176 Web Server : Apache System : Linux vps64074.inmotionhosting.com 3.10.0-1160.105.1.vz7.214.3 #1 SMP Tue Jan 9 19:45:01 MSK 2024 x86_64 User : nicngo5 ( 1001) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /home/nicngo5/funds.upgrade.nicn.gov.ng/funds-upgraded/app/Http/Controllers/ |
Upload File : |
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Http\Controllers\Controller; use App\Http\Requests; use Illuminate\Support\Facades\Storage; use Input; use Session; use DB; use Auth; use Schema; class StaffInformationSetUpController extends Controller { //make this page accessible only by authenticated user public function __construct(Request $request) { $this->middleware('auth'); } //load create page public function home() { if (!Schema::hasTable('tblStaffInformation')) { $this->creatStaffClaimTable(); } $data['bank'] = $this->getBank(); $data['department'] = $this->getDepartment(); $data['allStaffDetails'] = $this->getAllStaff(30); $data['showError'] = Session::get('showError'); return view('staffInformation.home', $data); } //Get all bank names public function getBank() { return DB::table('tblbanklist')->orderBy('bank', 'Asc')->get(); //return array(); } //Get all bank names public function getDepartment() { return DB::table('tbldepartment')->orderBy('department', 'Asc')->get(); //return array(); } //Query record public function getAllStaff($perPage) { if($perPage > 0) { $getStaffClaim = DB::table('tblStaffInformation') ->join('users', 'users.id', '=', 'tblStaffInformation.userID') ->leftjoin('tblbanklist', 'tblbanklist.bankID', '=', 'tblStaffInformation.bankID') ->leftjoin('tbldepartment', 'tbldepartment.id', '=', 'tblStaffInformation.departmentID') ->where('tblStaffInformation.active', 1) ->orderBy('tblStaffInformation.staffID', 'Desc') ->select('*', 'tblStaffInformation.departmentID as staffDepartmentID', 'tblStaffInformation.fileNo as StaffFileNo', 'users.id as userID', 'tblStaffInformation.bankID as staffBankID') ->paginate($perPage); return $getStaffClaim; }else{ $getStaffClaim = DB::table('tblStaffInformation') ->join('users', 'users.id', '=', 'tblStaffInformation.userID') ->leftjoin('tblbanklist', 'tblbanklist.bankID', '=', 'tblStaffInformation.bankID') ->leftjoin('tbldepartment', 'tbldepartment.id', '=', 'tblStaffInformation.departmentID') ->where('tblStaffInformation.active', 1) ->orderBy('tblStaffInformation.staffID', 'Desc') ->select('*', 'tblStaffInformation.departmentID as staffDepartmentID', 'tblStaffInformation.fileNo as StaffFileNo', 'users.id as userID', 'tblStaffInformation.bankID as staffBankID') ->get(); return $getStaffClaim; } } //http post (Insert new record) public function store(Request $httpReq) { Session::put('showError', 0); $this->validate($httpReq, [ 'staffFileNo' => 'required|unique:tblStaffInformation,fileNo', 'staffName' => 'required|regex:/^[\pL\s\-]+$/u|max:255|unique:tblStaffInformation,full_name', 'staffEmail' => 'email|unique:users,email|max:200', 'bankName' => 'required|max:200', 'accountNumber' => 'required|numeric|unique:tblStaffInformation,account_no', 'department' => 'required|numeric', 'sortCode' => 'numeric', ]); //create staff to users Table $userID = DB::table('users')->insertGetId(array( 'name' => trim($httpReq['staffName']), 'username' => trim($httpReq['staffFileNo']), 'email' => trim($httpReq['staffEmail']), 'resettoken' => rand(100, 100000), 'password' => bcrypt(trim($httpReq['staffFileNo']).'123'), 'temp_pass' => trim($httpReq['staffFileNo']).'123', 'user_type' => 'STAFF', 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s'), )); // add staff to claim Table if($userID) { DB::table('tblStaffInformation')->insertGetId(array( 'userID' => $userID, 'full_name' => trim($httpReq['staffName']), 'fileNo' => trim($httpReq['staffFileNo']), 'sort_code' => trim($httpReq['sortCode']), 'bankID' => trim($httpReq['bankName']), 'account_no' => trim($httpReq['accountNumber']), 'departmentID' => trim($httpReq['department']), 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s'), )); Session::put('showError', 1); return redirect()->route('staffInfo')->with('message', trim($httpReq['staffName']) . " account was created successfully."); } return redirect()->route('staffInfo')->with('error', "Sorry, we cannot create this staff record! Pls try again."); } //Update record public function update(Request $httpReq) { Session::put('showError', 1); $this->validate($httpReq, [ 'staffFileNo' => 'required', 'staffName' => 'required|regex:/^[\pL\s\-]+$/u|max:255', 'staffEmail' => 'email|max:200', 'bankName' => 'required|max:200', 'accountNumber' => 'required|numeric', 'department' => 'required|numeric', 'sortCode' => 'numeric', 'recordID' => 'required|numeric', ]); //CUSTOMIZED VALIDATION: Pre-check user vital info. //$getPreData = DB::table('tblStaffInformation')->where('staffID', trim($httpReq['recordID']))->first(); if(DB::table('tblStaffInformation')->where('staffID', '<>', trim($httpReq['recordID']))->where('fileNo', trim($httpReq['staffFileNo']))->count() > 0){ $this->validate($httpReq, [ 'staffFileNo' => 'required|unique:tblStaffInformation,fileNo', ]); } if(DB::table('tblStaffInformation')->where('staffID', '<>', trim($httpReq['recordID']))->where('account_no', trim($httpReq['accountNumber']))->count() > 0){ $this->validate($httpReq, [ 'accountNumber' => 'required|numeric|unique:tblStaffInformation,account_no', ]); } ///// if(trim($httpReq['password']) != "DEFAULTPASSWORD" || trim($httpReq['password']) != "") { $updateStaff = DB::table('users')->where('id', trim($httpReq['userID']))->update(array( 'email' => trim($httpReq['staffEmail']), 'username' => trim($httpReq['username']), 'password' => bcrypt(trim($httpReq['password'])), )); }else{ $updateStaff = DB::table('users')->where('id', trim($httpReq['userID']))->update(array( 'email' => trim($httpReq['staffEmail']), 'username' => trim($httpReq['username']), )); } $changeMade = DB::table('tblStaffInformation')->where('staffID', trim($httpReq['recordID']))->update(array( 'full_name' => trim($httpReq['staffName']), 'fileNo' => trim($httpReq['staffFileNo']), 'sort_code' => trim($httpReq['sortCode']), 'bankID' => trim($httpReq['bankName']), 'account_no' => trim($httpReq['accountNumber']), 'departmentID' => trim($httpReq['department']), 'updated_at' => date('Y-m-d H:i:s'), )); if($changeMade or $updateStaff) { return redirect()->route('staffInfo')->with('message', trim($httpReq['staffName']) . " account was updated successfully."); }else{ return redirect()->route('staffInfo')->with('error', "Sorry, we cannot update this staff record! Pls try again."); } } //DB Schema for Table (Create New Table) public function creatStaffClaimTable() { return Schema::create('tblStaffInformation', function($table) { $table->increments('staffID'); $table->integer('userID')->nullable(); $table->integer('fileNo')->nullable(); $table->string('full_name')->nullable(); $table->integer('departmentID')->nullable(); $table->integer('bankID')->nullable(); $table->string('account_no', 11)->nullable(); $table->string('sort_code', 100)->nullable(); $table->date('created_at')->nullable(); $table->date('updated_at')->nullable(); $table->integer('active')->default(1); }); /* //Check and Add New Column ..check whether Table has column if(!Schema::hasColumn('users', 'email')) { Schema::table('tableName', function(Blueprint $table){ $table->text('newField')->after('fieldName'); }); } //Update Column if(!Schema::hasColumn('users', 'email')) { Schema::table('tableName', function(Blueprint $table){ $table->string('name', 50)->change(); }); } //OR update like this if(!Schema::hasColumn('users', 'email')) { Schema::table('users', function($table){ DB::statement('ALTER TABLE users MODIFY COLUMN name VARCHAR(50)'); }); } */ } //////end it here/////// }//end class