<?php

namespace App\Http\Controllers\CustomerService;

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 PDF;

use App\Staff;
use App\Model\StaffDetail;
use App\Model\WorkOrder;

class ProfileController extends Controller
{
	public function viewProfile(){

		$id = Auth::guard('cs')->id();
		$user = Staff::with('StaffDetail')->find($id);

		$pp = count(WorkOrder::where('status','Pending Non Prelaid')->get());
		$sp = count(WorkOrder::where('status','Success Non Prelaid')->get());
		$rs = count(WorkOrder::where('status','Reschedule')->get());
		$ss = count(WorkOrder::where('status','Suspend')->get());
		$cm = count(WorkOrder::where('status','Completed')->get());

    	return view('customer-service.view_profile',compact('user','pp','sp','rs','ss','cm'));
	}

	public function updateProfilePicture(Request $request){
		$this->validate($request, [
			'prof_img' => 'mimes:jpeg,jpg,png|required|dimensions:width=128,height=128'
		]);

		if($request->hasfile('prof_img')){
				// Move / Upload Icon into server
			$destinationPath = 'assets/avatar';
				// create folder/dir if not exist
			if(!File::exists(public_path().$destinationPath)){
				File::makeDirectory(public_path().$destinationPath,0777,true);
			}

			$icon = $request->file('prof_img');
			$icon->move($destinationPath,$request->id.'.'.$icon->getClientOriginalExtension());
			$pathIcon = $destinationPath.'/'.$request->id.'.'.$icon->getClientOriginalExtension();
		}
	}
}