| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- <?php
-
- namespace App\Http\Controllers\v3\Contractor;
-
- use Illuminate\Http\Request;
- use App\Http\Controllers\Controller;
- use Illuminate\Support\Facades\Auth;
- use LynX39\LaraPdfMerger\Facades\PdfMerger;
-
- use Carbon\Carbon;
- use Validator;
- use Hash;
-
- use App\SiteSetting;
- use App\LatestModel\Staff;
- use App\LatestModel\StaffDetail;
- use App\LatestModel\Module\Form;
- use App\LatestModel\Module\Subscriber;
- use App\LatestModel\Module\WorkOrder;
- use App\LatestModel\Module\PackageDetail;
- use App\LatestModel\Module\Company;
- use App\LatestModel\Module\Coverage;
- use App\LatestModel\Module\Product;
- use App\LatestModel\Module\Docket;
-
- class TeamController extends Controller
- {
- /**
- * Create docket controller.
- *
- * @return post
- */
- public function view_company_rating(){
-
- $id = Auth::guard('main-contractor')->id();
- $user = Staff::with('StaffDetail')->find($id);
-
- $site = SiteSetting::first();
- $company = Company::where('_id', $user->company_id)->withTrashed()->first();
- $staff = Staff::with('StaffDetail')->where('company_id', $user->company_id)->where('roles_access','Installer')->withTrashed()->get();
-
- $total_docket = 0; $total_rating = 0;
- if(!empty($staff)){
- foreach($staff as $s){
- $t_rating = 0;
- $total_docket += count(Docket::where('installer_id',$s->_id)->get());
- $docket = Docket::where('installer_id',$s->_id)->get();
- if(!empty($docket)){
- foreach($docket as $d){
- $t_rating += $d->Rating1 + $d->Rating2 + $d->Rating3;
- }
- }
- $total_rating += $t_rating;
- }
- }
- return view('v3.main-contractor.team.overall_rating', compact('user','site','company','total_rating','total_docket'));
-
- }
-
- function random_color_part() {
- return str_pad( dechex( mt_rand( 0, 255 ) ), 2, '0', STR_PAD_LEFT);
- }
-
- function random_color() {
- return $this->random_color_part() . $this->random_color_part() . $this->random_color_part();
- }
-
- /**
- * Create staff list
- *
- * @return post
- */
-
- public function viewInstallerList()
- {
- $id = Auth::guard('main-contractor')->id();
- $user = Staff::with('StaffDetail')->find($id);
- $site = SiteSetting::first();
-
- return view('v3.main-contractor.team.installer_list',compact('user','site'));
- }
-
- public function viewStaffForm()
- {
- $id = Auth::guard('main-contractor')->id();
- $user = Staff::with('StaffDetail')->find($id);
- $site = SiteSetting::first();
-
- return view('v3.main-contractor.team.add_new_staff', compact('user','site'));
- }
-
- public function requestAddStaff(Request $request){
-
- $validator = Validator::make($request->all(), [
- 'password' => 'min:6|confirmed',
- ]);
-
- if ($validator->fails()) {
- return redirect()->back()->withInput()->withErrors($validator);
- }
-
- // $encrP = $this->encryptPassword('encrypt', $request->password);
- $encrP = Hash::make($request->get('password'));
- $company = Company::where('_id',$request->vendor)->first();
- if(!empty($company)){
- $exist = Staff::with('StaffDetail')->where('email',$request->email)->where('roles_access','Installer')->first();
- if(empty($exist)){
- $sl = Staff::create([
- 'email' => $request->email,
- 'password' => $encrP,
- 'roles_access' => 'Installer',
- 'company_id' => $request->vendor,
- 'last_login_at' => '',
- 'last_login_ip'=> '',
- 'company_id' => $request->vendor,
- 'authorized' => false,
- 'token_firebase' => '',
- ]);
-
- $sdl = new StaffDetail();
- $sdl->name = $request->name;
- $sdl->ic = $request->ic;
- $sdl->email = $request->email;
- $sdl->phone = $request->phone;
- $sdl->company_id = $request->vendor;
- $sdl->color = $company->color;
- $sdl->position = 'Installer';
- $sdl->password = $encrP;
- $sdl->user_pic = 'uploads/profile/user.png';
-
- $company->staff()->save($sl);
- $company->save();
- $sl->staffdetail()->save($sdl);
-
- return redirect()->back()->with('success_msg', '<strong>Success!</strong> add <strong>'.$request->get('aname').'</strong> as new installer ');
-
- }else {
- return redirect()->back()->withInput()->with('error_msg', 'Staff installer with '.$request->email.' already exist!');
- }
-
- }else {
- return redirect()->back()->withInput()->with('error_msg', 'Record company not found!');
- }
- }
-
- public function editStaffDetail($type,$_id)
- {
- $id = Auth::guard('main-contractor')->id();
- $user = Staff::with('StaffDetail')->find($id);
- $site = SiteSetting::first();
-
- $staff = Staff::with('StaffDetail')->where('_id', $_id)->first();
- $current_company = Company::where('_id', $staff->company_id)->first();
-
- return view('v3.main-contractor.team.edit_staff_detail',compact('user','site','current_company','staff','type'));
- }
-
- public function requestEditStaff(Request $request){
-
- $exist = Staff::with('StaffDetail')->where('_id',$request->_id)->first();
-
- if(empty($exist)){
- return redirect()->back()->withInput()->withErrors('staff not found');
- }else {
-
- $exist->email = $request->email;
- $exist->save();
-
- $exist->StaffDetail->name = $request->name;
- $exist->StaffDetail->ic = $request->ic;
- $exist->StaffDetail->email = $request->email;
- $exist->StaffDetail->phone = $request->phone;
- $exist->StaffDetail->save();
-
- return redirect()->back()->with('success_msg', '<strong>Success!</strong> update detail staff <strong>'.$request->get('name').'</strong>');
-
- }
- }
- }
|