format("Y-m-d"); //https://www.youtube.com/watch?v=gNH6NNyhJLk //https://www.youtube.com/watch?v=EYYZFRRdR6A PDF with MySQL database $count = 0; require ('./fpdf.php'); class PDF extends FPDF{ function Header(){ $this->Image('../images/ahg_logo.png',10,5, 25,10, 'PNG','wwww.autohubgroup.com'); } /* function Footer(){ $this->SetY(-25); $this->Image('../images/ahg_logo.png'); } */ } $myUID = $_GET['s']; $unitID = $_GET['e']; $sourceID = $_GET['s']; $sem = $_GET['sm']; $nme = $_GET['n']; $rptYear = $_GET['ye']; if($sem == 1){ $semester = "1st Semester"; }else if($sem == 2){ $semester = "2nd Semester"; }else{ $semester = "1st & 2nd Semester"; } $unitNamen = $nme . " - Scorecard" ." (". $semester." of ". $rptYear .")"; include_once("../../../cfg/conn.php"); include ("../functions/users.php"); $roleID=0; if(isset($_GET['s'])){ $empID = $_GET['e']; $sourceID = $_GET['s']; $sem = $_GET['sm']; $nme = $_GET['n']; $rptYear = $_GET['ye']; $fN = explode(" ", $nme); $fName = $fN[0]; $lName = $fN[1]; //START OF CHECKPOINT=============================================================================== //START OF CHECKPOINT=============================================================================== //==========CHECK IF USER EXIST IN THE RECORD AND MATCH ALL INFORMATION IN THE LICNK ========= $chkUser = "SELECT * FROM `pms_employee_data` WHERE `id`='$sourceID' AND `deleted` = 0"; $qCU=mysqli_query($conn,$chkUser); $countUser = mysqli_num_rows($qCU); if($countUser == 0){ echo "
"; echo "

Access Denied

"; echo "

Sorry, you are not authorized to access this page.
Please contact your system support for assistance.

Thank you!

"; exit(); }else{ while($uow=mysqli_fetch_array($qCU)){ $uowaccStat = $uow['account_status']; $uowdeleted = $uow['deleted']; } } if($uowaccStat == 0){ echo "
"; echo "

Access Denied

"; echo "

Sorry, you are not authorized to access this page.
Please contact your system support for assistance.

Thank you!

"; exit(); } if($uowdeleted == 1){ echo "
"; echo "

Access Denied

"; echo "

Sorry, you are not authorized to access this page.
Please contact your system support for assistance.

Thank you!

"; exit(); } //==========CHECK IF EMPLOYEE EXIST IN RECORD AND MATCH ALL INFORMATION IN THE LICNK ========= $chkPoint = "SELECT `last_name`, `first_name`,`account_status`,`deleted` FROM `pms_employee_data` WHERE `id`='$empID'"; $qChk=mysqli_query($conn,$chkPoint); $ckhRow = mysqli_num_rows($qChk); If($ckhRow > 0){ while($row=mysqli_fetch_array($qChk)){ $lastName = $row['last_name']; $firstName = $row['first_name']; $accStat = $row['account_status']; $deleted = $row['deleted']; } }else{ echo "
"; echo "

Access Denied

"; echo "

Sorry, you are not authorized to access this page.
Please contact your system support for assistance.

Thank you!

"; exit(); } //END OF CHECKPOINT=============================================================================== //END OF CHECKPOINT=============================================================================== } $getName = "SELECT * FROM pms_employee_data WHERE id = $myUID LIMIT 1"; $getMyName = mysqli_query($conn,$getName); while($nRow = mysqli_fetch_array($getMyName)){ $fname=$nRow['first_name']; $lname=$nRow['last_name']; $compID=$nRow['comp_id']; $myFName = $fname ." ". $lname; } $compName = getCompanyNameSub($compID)[0]; $sql ="SELECT * FROM `pcp_employee_data` WHERE `employee_id`='$empID' AND `deleted`=0 GROUP BY `pcp_kpi_id`"; $pdf = new PDF(); //set margins $pdf->SetMargins(10,20,10); $pdf->AddPage('L'); //L = Land Scape, P = Portrait //set column size in array format $width_cell = array(91,15,85,15,15,18,18,18); $height_cell= 7; //set Image //$pdf->Image('../images/ahg_logo.png',10,5, 25,10, 'PNG','wwww.autohubgroup.com'); //background color $pdf->SetFillColor(255,255,255); //use for report title bgcolor $pdf->SetFont('Arial','B',10 ); $pdf->MultiCell(0,5,$compName,0,1,0,true); $pdf->SetFont('Arial','',10 ); $pdf->MultiCell(0,5,$unitNamen,0,1,0,true); $pdf->MultiCell(0,5,"",0,0,true); $pdf->SetFont('Arial','',8); $pdf->SetFillColor(0,0,0,90); //use for header bgcolor $pdf->SetTextColor(255,255,255,90); $pdf->SetLineWidth(0); $pdf->SetDrawColor(0,0,25); //header start $pdf->Cell($width_cell[0],$height_cell,'KRA NAME',1,0,'L',true); $pdf->Cell($width_cell[1],$height_cell,'WEIGHT',1,0,'L',true); $pdf->Cell($width_cell[2],$height_cell,'KPI NAME',1,0,'L',true); $pdf->Cell($width_cell[3],$height_cell,'TARGET',1,0,'L',true); $pdf->Cell($width_cell[4],$height_cell,'ACTUAL',1,0,'L',true); $pdf->Cell($width_cell[5],$height_cell,'ACHV. RATE',1,0,'L',true); $pdf->Cell($width_cell[6],$height_cell,'AVG. SCORE',1,0,'L',true); $pdf->Cell($width_cell[7],$height_cell,'W. POINTS',1,0,'L',true); $pdf->SetFillColor(255,255,255,0); //use for header bgcolor $pdf->SetTextColor(0,0,0,90); $fill=false; //$pdf->Cell(400,200,'Hello Arnel'); $getData = mysqli_query($conn,$sql); $statRow = mysqli_num_rows($getData); $kraCode = 0; $kpiCount = 0; $count = 0; $achvRateTotal=0; $wPointTotal =0; $kraWeightTotal=0; $kraWeightT=0; while($row = mysqli_fetch_array($getData)){ $kpiRow = 0; $count = $count + 1; $empKRAid = $row['pcp_kra_id']; $empKPIid = $row['pcp_kpi_id']; $empKRAName = getEmployeeKRAName($empKRAid)[0]; $empkpiName = getEmployeeKPIName($empKPIid)[0]; //GET ACTUAL SCORE $gKpiCount = "SELECT * FROM `pcp_employee_data` WHERE `employee_id`='$empID' AND `pcp_kra_id`='$empKRAid' AND `deleted`=0 GROUP BY `pcp_kpi_id`"; if($sem == 0){ // Sen 1 & 2 combined $gKpi = "SELECT AVG(`mar_actual`) AS 'marActual' FROM `mar_emp_data` WHERE `kra_id`='$empKRAid' AND `kpi_id`='$empKPIid' AND `mar_year_data`='$rptYear' AND `deleted`=0 LIMIT 1"; }else{ $gKpi = "SELECT AVG(`mar_actual`) AS 'marActual' FROM `mar_emp_data` WHERE `kra_id`='$empKRAid' AND `kpi_id`='$empKPIid' AND `mar_year_data`='$rptYear' AND `mar_semester_data`='$sem' AND `deleted`=0 LIMIT 1"; } $qKpiC = mysqli_query($conn,$gKpiCount); while($nt = mysqli_fetch_array($qKpiC)){ $kpiRow = $kpiRow + 1; } $qKpi = mysqli_query($conn,$gKpi); while($row = mysqli_fetch_array($qKpi)){ $myActualDataPrint = number_format($row['marActual'],2,'.',''); $myActualData = $row['marActual']; } if (preg_match("/%/",getEmployeeKPIName($empKPIid)[2])) { $percent ="%"; $pcpKPITargetEx = explode("%",getEmployeeKPIName($empKPIid)[2]); $pcpKPITargetPercent = $pcpKPITargetEx[0]; }else{ $percent =""; $pcpKPITargetPercent = getEmployeeKPIName($empKPIid)[2]; } if (preg_match("/%/",getEmployeeKRAName($empKRAid)[1])) { $kraWeightpercent = explode("%",getEmployeeKRAName($empKRAid)[1]); $kraWeight = $kraWeightpercent[0] /100; $kraWeightT = $kraWeightpercent[0]; }else{ $kraWeight = getEmployeeKPIName($empKPIid)[1] / 100; $kraWeightT = $kraWeightpercent[0]; } $achvRate = (($myActualData/$pcpKPITargetPercent) * 100); $achvRatePrint= number_format((($myActualData/$pcpKPITargetPercent)* 100),2,'.',''); $achvRateTotal = $achvRateTotal + $achvRate; $pdf->MultiCell(0,$height_cell,"",0,'P',false); //setup row padding if($empKRAid == $kraCode){ $pdf->Cell($width_cell[0],$height_cell,"" ,1,0,'L',$fill); //getEmployeeKRAName($kraID)[0] $pdf->Cell($width_cell[1],$height_cell,"" ,1,0,'L',$fill); }else{ $pdf->Cell($width_cell[0],$height_cell,$empKRAName,1,0,'L',$fill); //getEmployeeKRAName($kraID)[0] $pdf->Cell($width_cell[1],$height_cell,getEmployeeKRAName($empKRAid)[1],1,0,'C',$fill); $kraWeightTotal = $kraWeightTotal + $kraWeightT; } $pdf->Cell($width_cell[2],$height_cell,$empkpiName,1,0,'L',$fill); $pdf->Cell($width_cell[3],$height_cell,getEmployeeKPIName($empKPIid)[2],1,0,'C',$fill); $pdf->Cell($width_cell[4],$height_cell,$myActualDataPrint."".$percent,1,0,'C',$fill); $pdf->Cell($width_cell[5],$height_cell,$achvRatePrint."%",1,0,'C',$fill); if($count == $kpiRow){ $achvRateTotalFinal = number_format(($achvRateTotal / $kpiRow),2,'.',''); $wPoint = number_format(($kraWeight * $achvRateTotalFinal ),2,'.',''); $pdf->Cell($width_cell[6],$height_cell,$achvRateTotalFinal."%",1,0,'C',$fill); $pdf->Cell($width_cell[7],$height_cell,$wPoint."%",1,0,'C',$fill); $wPointTotal = number_format(($wPointTotal + $wPoint),2,'.',''); $count =0; $kpiRow = 0; $achvRateTotal=0; }else{ $pdf->Cell($width_cell[6],$height_cell,"",1,0,'C',$fill); $pdf->Cell($width_cell[7],$height_cell,"",1,0,'C',$fill); } $kraCode = $empKRAid ; } $fill =!$fill; // use code to put alternate color between rows //$kraTitle=$kraID; $pdf->SetFillColor(0,0,0,90); //use for header bgcolor $pdf->SetTextColor(255,255,255,10); $pdf->MultiCell(1,$height_cell,"",0,'L',false); //setup row padding $pdf->Cell($width_cell[0],$height_cell,'TOTAL',1,0,'L',true); $pdf->Cell($width_cell[1],$height_cell,$kraWeightTotal."%",1,0,'C',true); $pdf->Cell($width_cell[2],$height_cell,'',1,0,'L',true); $pdf->Cell($width_cell[3],$height_cell,'',1,0,'L',true); $pdf->Cell($width_cell[4],$height_cell,'',1,0,'L',true); $pdf->Cell($width_cell[5],$height_cell,'',1,0,'L',true); $pdf->Cell($width_cell[6],$height_cell,'',1,0,'L',true); $pdf->Cell($width_cell[7],$height_cell,$wPointTotal,1,0,'C',true); $pdf->SetFillColor(255,255,255,10); //use for header bgcolor $pdf->SetTextColor(0,0,0,90); $pdf->MultiCell(1,25,"",0,'L',false); //setup row padding $pdf->Cell(100,0,"_____________________________",0,1,'L',false); $pdf->Cell(100,8,$myFName .' / '. $prfDateX ,0,0,'L',false); $pdf->Output('my_file.php','I'); ?>