
<style type="text/css">
	.input-append, .input-prepend {
		margin-bottom: 0px !important;
	}
	.table td {
		padding: 3px !important;
	}
</style>



<?php

session_start();
// ============

include("../../../php_crud/my_class.php");
$obj=new my_class();
extract($_POST);
$shift_id;
$medium_id;
$chose_date = date("Y-m-d", strtotime($from_date));




$branch_id = isset($_SESSION['LOGIN_BRANCH']) ? $_SESSION['LOGIN_BRANCH']: '';
if($branch_id !=''){
$brans_obj = $obj->View_branch_details_By_Cond($branch_id,'B');
$inst_name = $brans_obj->insName;
$ins_code_name = $brans_obj->insCodeName; 
$extablishd_year = $brans_obj->_establish_year ;
$ins_logo = $brans_obj->_logo_location;
$ins_address = $brans_obj->_address;
$inst_thanta = $brans_obj->thana_name ;
$ins_district = $brans_obj->distrinc_name  ;
$ins_division = $brans_obj->division_name  ;
$ins_web = $brans_obj->_web_address !='' ? $brans_obj->_web_address.'|| ' : '' ;
$ins_email = $brans_obj->_email_add !='' ? $brans_obj->_email_add : '' ;

}

$im='../../../'.$ins_logo;
if(file_exists($im)){

$image = '<img src="../../../'.$ins_logo.'" style="top:20px;height:150px; float:left;margin-left: -12px;" title="logo" alt="" id="image" />';

}		 
else{
$image = '<img src="../../../asset/custom/shadow.jpg"  />';
			
}



// Include the main TCPDF library (search for installation path).
require_once('../../../asset/custom/tcpdf/examples/tcpdf_include.php');
require_once('../../../asset/custom/tcpdf/tcpdf.php');



$PDF_HEADER_LOGO = "logo_example.jpg";//any image file. check correct path.
/*$PDF_HEADER_LOGO_WIDTH = "20";
$PDF_HEADER_TITLE = "This is my Title";
$PDF_HEADER_STRING = "Tel 1234567896 Fax 987654321\n"
. "E abc@gmail.com\n"
. "www.abc.com";
$pdf->SetHeaderData($PDF_HEADER_LOGO, $PDF_HEADER_LOGO_WIDTH, $PDF_HEADER_TITLE, $PDF_HEADER_STRING); */

// create new PDF document
//$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$your_width=210;
$your_height=297;
$custom_layout = array($your_width, $your_height);

class MYPDF extends TCPDF {


/*  */



protected $image1 ;
public $size ;
public $type_id ;
public function setImagesrc($sr) {
$this->image1 = $sr;


}
public $isLastPage = false;

public function Header() {

$this->SetAlpha(0.09);
$this->Image($this->image1, 65, 95, 70, 100, '', '', '', true, 50);
$this->SetAlpha(1);

}



public function Footer() {
//$image_file = "";
//$this->Image($image_file, 11, 241, 189, '', 'JPG', '', 'T', false, 300, '', false, false, 0, false, false, false);

$this->SetFont('helvetica', 'N', 10);









$this->Line(15, 290, 205, 290);

$this->SetY(-7);
$this->SetX(15);
$by = 'Generated By:'.$_SESSION["LOGIN_USER"];
$this->SetFont('helvetica', 'N', 8);
$this->Cell(0, 5,$by, 0, false, '', 0, '', 0, false, 'T', 'M');





$this->SetY(-4);
$this->SetX(15);
$date = 'Printed Date:';
$this->SetFont('helvetica', 'N', 6);
$this->Cell(0, 5,$date.   date(" d/m/Y H\hi:s"), 0, false, '', 0, '', 0, false, 'T', 'M');



$this->SetY(-5);
$this->SetFont('helvetica', 'N', 10);
$a = 'Powred by:'.$_SESSION["powred"];
$this->Cell(0, 5, $a, 0, false, 'C', 0, '', 0, false, 'T', 'M');

$this->SetY(-7);
// Set font
$this->SetFont('helvetica', 'I', 8);
// Page number
$this->Cell(0, 10, 'Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'R', 0, '', 0, false, 'T', 'M');

/* 	 if($this->isLastPage)
{ */	
$style3 = array('width' => 0.4, 'cap' => 'round', 'join' => 'round', 'dash' => '1,1', 'color' => black);

//$this->Line(15, 283, 50, 283, $style3);
//$this->Line(90, 283, 135, 283, $style3);
//$this->Line(170, 283, 205, 283, $style3);
//$this->Text(15, 285, 'Parents Signature');
//$this->Text(90, 285, 'approved by');
//$this->Text(170, 285, 'Controller of Examination');
//}


}
public function lastPage($resetmargins=false) {
$this->setPage($this->getNumPages(), $resetmargins);
$this->isLastPage = true;
}
}

$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, $custom_layout, true, 'UTF-8', false);
/* logo */
$pdf->setImagesrc('../../../'.$ins_logo);
$pdf->size= $size;	
$pdf->type_id= $type_id;
//$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, $custom_layout, true, 'UTF-8', false);


//$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

// set document information
/* $pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Nicola Asuni');
$pdf->SetTitle('TCPDF Example 007');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide'); */

// set default header data
//$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 007', PDF_HEADER_STRING);

//$PDF_HEADER_LOGO = "Untitled-1.jpg";//any image file. check correct path.
/* $PDF_HEADER_LOGO_WIDTH = "20";
$PDF_HEADER_TITLE = "This is my Title";
$PDF_HEADER_STRING = "Tel 1234567896 Fax 987654321\n"
. "E abc@gmail.com\n"
. "www.abc.com";
$pdf->SetHeaderData($PDF_HEADER_LOGO, $PDF_HEADER_LOGO_WIDTH, $PDF_HEADER_TITLE, $PDF_HEADER_STRING); */


// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);




// set margins
//$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
//$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);

$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);

// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

// set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

// set some language-dependent strings (optional)
if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
require_once(dirname(__FILE__).'/lang/eng.php');
$pdf->setLanguageArray($l);
}

// ---------------------------------------------------------




// set font
$pdf->SetFont('times', '', 10);



$pdf->AddPage();
//============== Heading ===========
//=================================

$dst = $ins_district.','.$ins_division;
if($ins_district==$ins_division){
	$dist = $ins_district ;
}
else { $dist = $dst; }
$test .= '<table style="width: 100%;height:10%;"  cellspacing="">';
$test1 = '</table>';
// create columns content=='.$image.'
$test .= '<tr>
<td style=" width: 20%;"></td>
<td style=" width: 60%;">
<h1 style="font-size: 25px;text-align: center;line-height: 10px;margin-bottom: 3px; margin-top: 20px;;"><b>  '.$inst_name.'</b>
	  ('.$ins_code_name.')
</h1>
<h5 style="text-align:center;font-size:14px;margin-top:6px"> '.$ins_address.' , '.$inst_thanta.' , '.$dist.'  </h5>
<h5 style="text-align:center;font-size:10px;line-height: 5px;">'.$ins_web.'  '.$ins_email.' </h5>
<h2 style="font-size:14px;text-align:center; margin-top: 30px;padding-bottom: 1px;width:100%;">Attendance Details Report('.$chose_date.')</h2>
</td>
<td style=" width:20%;"></td></tr>';
$pdf->writeHTML($test . $test1, false, false, false, false, '');
$pdf->Ln(10);
//===============================
//================ Report =======
//===============================

$all_section = '';
$branch_id = isset($_SESSION['LOGIN_BRANCH']) ? $_SESSION['LOGIN_BRANCH']: '';	
$table_name=" _int_institute_setup_vw";
$column="*";
$where_cond='branch_id ='.$branch_id .' AND shift_id ='.$shift_id .' AND medium_id ='.$medium_id ;
$all_sec=$obj->View_all_data_row_column_By_Cond($table_name,$column,$where_cond);
//	print_r($all_sec);
//=====================
if(count($all_sec)>0){
	foreach($all_sec as $sc ){
		if(isset($sc['section_id'])){
			$all_section .= ', '. $sc['section_id'];
		}
	}
}

//==============
if($all_section){
		$all_section = trim($all_section, ',');
	}

//======================
$table_name=" _atd_daily_status_class";
$column="*";
$where_cond='_atd_status = 1 && _section_id IN ('.$all_section.') && DATE(_entry_date) = "'.$chose_date.'" ';
if($all_section)
$all_section_id=$obj->View_all_data_row_column_By_Cond($table_name,$column,$where_cond);

$j = 1;
$total_student = 0;
$for_total_absent = 0;
$for_total_late = 0;
$for_total_leave = 0;
$k = 0;
	//$show_approve_all = 0;
//==========================
if(!empty($all_section_id)){
		foreach($all_section_id as $value ){
			
		
		$section_id = $value['_section_id'];
		$status_comments = $value['_comments'];
		$_atd_time = $value['_atd_time'];
		$approved_status = $value['_approve_satus'];
		$atd_status_id = $value['_id'];
		
		
			 				 
		$table_name="_int_institute_setup_vw iv LEFT JOIN _atd_daily_status_class hs ON hs._section_id = iv.section_id";
		$column="iv.section,iv.section,iv.student_type,iv.class,iv.department,iv.shift,iv.medium";
		$where_cond='_atd_status = 1 && iv.section_id = '.$section_id.' && DATE(_entry_date) = "'.$chose_date.'" order by TIME(_entry_date) ASC limit 1 ';
		 
		$list = $obj->View_all_data_row_column_By_Cond($table_name,$column,$where_cond);
		
		
				$table_name1 = '_pf_std_basic_info';
				$where_cond1 = '_section_id='.$section_id;
				$total_row = $obj->View_All_By_Cond($table_name1,$where_cond1 ); 

$report = '<legend>';
	
$report .='Shift: '.$list[0]['shift']. ', Medium: '.$list[0]['medium']. ', Class: '.$list[0]['class'].', Department: '.$list[0]['department'].', Student Type: '.$list[0]['student_type'].', Section: '.$list[0]['section'];
$report .= '</legend>';
$report .= '<br/><br/>';
//$pdf->Ln(5);
$report .= '<table style="width:100%" border="1"><thead>
			<tr style="background-color:#C0C0C0;">
			<th style="border: 1px solid #000000;">Sl</th>
			<th style="border: 1px solid #000000;">Student ID</th>
			<th style="border: 1px solid #000000;">Name</th>
			<th style="border: 1px solid #000000;">Roll</th>
			<th style="text-align: center;border: 1px solid #000000;">Status</th>
            <th style="text-align: center;border: 1px solid #000000;">Guardian Name</th>
			<th style="border: 1px solid #000000;">Contact No</th></tr>
			</thead>
			<tbody>';
//===============================
 $i=0;
$p = 0 ;
$ab= 0;
$la = 0;
$le= 0;			


			if($a_type=='P'){
	$atd_type = 'sc._id='.$section_id.' AND pf_std._status!="D" AND hmc._atd_status="P" && DATE(hmc._entry_date) ="'.$chose_date.'"  ORDER BY hmc._atd_status  ASC';
				//$atd_type ='P';
			}
elseif( $a_type=='A')
			{
				$atd_type = 'sc._id='.$section_id.' AND pf_std._status!="D" AND hmc._atd_status="A" && DATE(hmc._entry_date) ="'.$chose_date.'"  ORDER BY hmc._atd_status  ASC';
			//$atd_type ='A';
			}
elseif( $a_type=='AA')
			{
				$atd_type = 'sc._id='.$section_id.' AND pf_std._status!="D" AND hmc._atd_status IN("P","A","LA","LE") && DATE(hmc._entry_date) ="'.$chose_date.'"  ORDER BY hmc._atd_status  ASC';
			//$atd_type = 'A';
			}
elseif( $a_type=='LA')
			{
				$atd_type = 'sc._id='.$section_id.' AND pf_std._status!="D" AND hmc._atd_status="LA" && DATE(hmc._entry_date) ="'.$chose_date.'"  ORDER BY hmc._atd_status  ASC';
			//$atd_type = 'A';
			}	
elseif( $a_type=='LE')
			{
				$atd_type = 'sc._id='.$section_id.' AND pf_std._status!="D" AND hmc._atd_status="LE" && DATE(hmc._entry_date) ="'.$chose_date.'"  ORDER BY hmc._atd_status  ASC';
			//$atd_type = 'A';
			}
elseif( $a_type=='NP')
			{
				$atd_type = 'sc._id='.$section_id.' AND pf_std._status!="D" AND hmc._atd_status!="P" && DATE(hmc._entry_date) ="'.$chose_date.'"  ORDER BY hmc._atd_status  ASC';
			//$atd_type = 'A';
			}
			
			
			//$where_cond = 'sc._id='.$section_id.' AND pf_std._status!="D" AND $atd_type && DATE(hmc._entry_date) ="'.$chose_date.'"  ORDER BY hmc._atd_status  ASC';
	
			foreach($obj->View_Student_List_atttd($atd_type) as $value){
			
			extract($value);
			
			 $_late_time = $value['_late_time'] ;
			 
			 
			if($_atd_status=='P'){
				$atd_status = 'Present';
				//$atd_status =$obj->View_column_details_By_Cond($table_name,$column,$where_cond);
			}
			elseif( $_atd_status=='A')
			{
				$atd_status = 'Absent';
				$ab = $ab +1 ;
				
				
			}elseif($_atd_status=='LA'){
				$atd_status = 'Late';
				$la = $la +1 ;
				
			
			}elseif($_atd_status=='LE'){
				$atd_status = 'Leave';
				$le = $le +1 ;
				
			}
			
			 
			
			$i++;	

//========================================
$report .= '<tr nobr="true">
			<td style="text-align: center;border: 1px solid #000000;">'.$i.'</td>
			<td style="text-align: center;border: 1px solid #000000;">'.$value['_uniq_id'].'</td>
			<td style="text-align: center;border: 1px solid #000000;">'.$value['_full_name'];
			if(!empty($value['_nick_name']))
			{
				$report .=  ' ('.$value['_nick_name'].')'; 
			}
			
$report .= 	'</td>
			<td style="text-align: center;border: 1px solid #000000;">'.$value['_section_roll'].'</td>
			<td style="text-align: center;border: 1px solid #000000;">'.$atd_status.'</td><td>';
if($value['_current_guardian']=="F")
	{$report .=$value['father_name'];}
	elseif($value['_current_guardian']=="M")
	{$report .=$value['mother_name'];}
	else
	{$report .=$value['guardian_name'];}
$report .= 	'</td><td style="text-align: center;border: 1px solid #000000;">'.$value['_contact_mobile'].'</td></tr>';
			}
//====================================================
$selected_student = $i;
			$total_row = $obj->View_Student_List_rows("sc._id='$section_id' AND pf_std._status!='D'");
			/* echo $total_std;*/
			$total_std = $obj->Total_Count_By_Cond("_atd_daily_by_class","_section_id='$section_id' && DATE(_entry_date) ='$chose_date'");
			$total_p = $obj->Total_Count_By_Cond("_atd_daily_by_class","_section_id='$section_id' AND _atd_status= 'P' && DATE(_entry_date) ='$chose_date'");
			$total_a = $obj->Total_Count_By_Cond("_atd_daily_by_class","_section_id='$section_id' AND _atd_status= 'A' && DATE(_entry_date) ='$chose_date'");
			$total_la = $obj->Total_Count_By_Cond("_atd_daily_by_class","_section_id='$section_id' AND _atd_status= 'LA' && DATE(_entry_date) ='$chose_date'");
			$total_le = $obj->Total_Count_By_Cond("_atd_daily_by_class","_section_id='$section_id' AND _atd_status= 'LE' && DATE(_entry_date) ='$chose_date'");
			
			/* echo $total_std;*/
			$total_std1 = $obj->Total_Count_By_Cond("_atd_daily_by_class"," DATE(_entry_date) ='$chose_date'");
			$total_p1 = $obj->Total_Count_By_Cond("_atd_daily_by_class","_atd_status= 'P' && DATE(_entry_date) ='$chose_date'");
			$total_a1 = $obj->Total_Count_By_Cond("_atd_daily_by_class","_atd_status= 'A' && DATE(_entry_date) ='$chose_date'");
			$total_la1 = $obj->Total_Count_By_Cond("_atd_daily_by_class"," _atd_status= 'LA' && DATE(_entry_date) ='$chose_date'");
			$total_le1 = $obj->Total_Count_By_Cond("_atd_daily_by_class","_atd_status= 'LE' && DATE(_entry_date) ='$chose_date'");
			
			$present = $total_row-($ab+$la +$le) ;
			$pres = $total_p;
			$prsent_persentage = round(($total_p * 100)/$total_std, 1);
			//echo $prsent_per = round(($total_p * 100)/$total_row, 1);
			
			
			$sing_ab_persentage = round(($total_a * 100)/$total_std, 1);
			$sing_la_persentage = round(($total_la * 100)/$total_std, 1);
			$single_le_persentage = round(($total_le * 100)/$total_std, 1);
			
			
			/// count at every loop, this is for counting total info of all
			$for_total_absent = $for_total_absent + $ab  ;
			$for_total_late = $for_total_late + $la  ;
			$for_total_leave = $for_total_leave + $le  ;
			$total_student = $total_student + $total_row ;
			
//========================================================
$report .= 	'<tr> <td colspan="8" rowspan="1" style="text-align:center; vertical-align:middle; padding-bottom:5px !important; ">
			<b>Total Stuednt: </b>' .$total_std.',<b> Preseant:</b>' .$total_p.'( '.$prsent_persentage.'%), &nbsp; &nbsp;  <b>Absent: </b>'.$total_a.'( '.$sing_ab_persentage.'%),&nbsp; &nbsp; <b> Late: </b> '.$total_la.'( '.$sing_la_persentage.'%),&nbsp; &nbsp;  <b>Leave: </b> '.$total_le.'( '.$single_le_persentage.'%) ';

 $report .= 	'</td></tr></tbody></table>'; 
 //==================================================
$tch_id = $obj->Details_By_Cond("_r_class_routine","_section_id='$section_id' AND _teacher_type='CT' AND _teacher_id!='0' GROUP BY _teacher_type");
$teacher_id =  $tch_id['_teacher_id'];

$tch_det = $obj->Details_By_Cond("_pf_emp_personal_info","_id='$teacher_id'");
//==========================================
$report .= 	'<h4><b>Class Teacher name:</b>';
$report .= 	$tch_det['_full_name']; 
if(!empty($tch_det['_nick_name']))
{ $report .= ' ('.$tch_det['_nick_name'].')';}
$report .= '&nbsp;&nbsp;<b>Mobile No:</b>'.$tch_det['_contact_mobile_no'].'&nbsp;&nbsp;<b>Attendence Time :</b>'.date("H:i", strtotime($_atd_time)).'&nbsp;&nbsp;<b>Comments: </b>'.$status_comments.'</h4>';			

//=====================================
$pdf->writeHTML($report, true, true, false, false, '');  		
}


}

if(!empty($all_section_id)){
//=====================================
$report1 = '<legend>
			<strong>Summary  : </strong>
			</legend>';
//=====================================
$report1 .= '<br/><br/>';
$report1 .= '<table style="width:100%" border="1"><thead>
			<tr style="background-color:#C0C0C0;">
			<th>Total Student </th>
			<th>Preseant</th>
			<th>Absent</th>
			<th>Late</th>
			</tr></thead>
			<tbody>';
			$total_present = $total_student-($for_total_absent+$for_total_late +$for_total_leave) ;
			$prsent_persentage = round(($total_p1 * 100)/$total_std1, 1);
			$absent_persentage = round(($total_a1 * 100)/$total_std1, 1);
			$late_persentage = round(($total_la1 * 100)/$total_std1, 1);
			$leave_persentage = round(($total_le1 * 100)/$total_std1, 1);
$report1 .= '<tr>
				
				<td style="border: 1px solid #000000;">'.$total_std1.'</td>
				<td style="border: 1px solid #000000;">'.$total_p1." ( ".$prsent_persentage.'%)</td>
				<td style="border: 1px solid #000000;">'.$total_a1." ( ".$absent_persentage.'%)</td>
			
				<td class="td_pad" style="text-align: center;border: 1px solid #000000;">'. $total_la1." ( ".$late_persentage.'%)</td>
				<td class="td_pad" style="text-align: center;border: 1px solid #000000;">'.$total_le1." ( ".$leave_persentage.'%) </td>
				
				
			</tr></tbody>
			</table >';	
	$pdf->writeHTML($report1, true, true, false, false, ''); 
			
}		
// set color for background
$pdf->SetFillColor(255, 255, 200);

// set color for text
$pdf->SetTextColor(0, 63, 127);

// write the first column


// set color for background
$pdf->SetFillColor(215, 235, 255);

// set color for text
$pdf->SetTextColor(127, 31, 0);

// write the second column


// reset pointer to the last page
$pdf->lastPage();


// ---------------------------------------------------------

//Close and output PDF document
if (file_exists(__DIR__."/date_wise_atd.pdf"))
unlink(__DIR__."/date_wise_atd.pdf"); 

$pdf->Output(__DIR__."/date_wise_atd.pdf", 'F');
//$fileatt = $pdf->Output('mark_sheet.pdf', 'D');






