<?php
session_start();
// ============ this file shows a service report for selected session in a pdf format
include("../../asset/theme/css/myfunc.php");
include("../../php_crud/my_class.php");
require_once("../../asset/custom/mpdf/mpdf.php");
$obj=new my_class();
// ============
$branch_id=$_SESSION['LOGIN_BRANCH'];
$session_input_for_view_report=addslashes(trim($_GET['session_input_for_view_report']));

$service_provider_details = $obj->View_branch_details_By_Cond($branch_id,'I');
$service_provider_name = $service_provider_details->insName;
$service_provider_code = $service_provider_details->insCodeName; 
$service_provider_logo = $service_provider_details->_logo_location;
$service_provider_address = $service_provider_details->_address;
$service_provider_thana = $service_provider_details->thana_name ;
$service_provider_district = $service_provider_details->distrinc_name;
$service_provider_division = $service_provider_details->division_name;
$service_provider_web = $service_provider_details->_web_address !='' ? $service_provider_details->_web_address : '' ;
$service_provider_email = $service_provider_details->_email_add !='' ? '|| '. $service_provider_details->_email_add : '' ;

$table_name="_exam_service_school_add a left join _exam_service_registration b on a._id=b._pid";
$column="a._school_name,b._id,b._pid,b._exam_name,b._session,b._total_amount,b._due_amount,b._paid_amount,b._discount_amount,b._last_paid_amount,b._status";
$where_cond="b._session='".$session_input_for_view_report."' order by a._school_name";
$shift_list=$obj->View_all_data_row_column_By_Cond($table_name,$column,$where_cond);
?>
<style type="text/css">
i{
	cursor:pointer;
}
td{
	
}
</style>
<script src="module/finance/js/exam_service_fee_collection.js" type="text/javascript"></script>
<?php if($_SESSION['add']=='Y'){
$html="<html><head></head><body>
<div id='report-holder'>
	<div class='span12 ins-info' id='service-provider-info-holder' style='font-family: Tahoma, Geneva, sans-serif; text-align: center;'> 
		<h4 style='margin: 2'><b>$service_provider_name </b>($service_provider_code)</h4>
		<h5 style='margin: 3'>$service_provider_address, $service_provider_thana $service_provider_district, $service_provider_division<br>
		$service_provider_web  $service_provider_email</h5>
		<h4>Service Report for Session $session_input_for_view_report</h4>
	</div>
	<div class='row-fluid'>				
		<table id='sample-table-22' style='margin-left: 40px; font-family: Tahoma, Geneva, sans-serif; border: 1px solid black; border-collapse: collapse;'>
			<thead>
			<tr>
				<th style='font-size: 13px; width: 50px; border: 1px solid; border-collapse: collapse;'>Sl</th>
				<th style='font-size: 13px; border: 1px solid; border-collapse: collapse;'>School Name</th>
				<th style='font-size: 13px; border: 1px solid; border-collapse: collapse;'>Exam Name</th>
				<th style='font-size: 13px; border: 1px solid border-collapse: collapse;'>Total Amount</th>
				<th style='font-size: 13px; border: 1px solid; border-collapse: collapse;'>Paid Amount</th>
				<th style='font-size: 13px; border: 1px solid; border-collapse: collapse;'>Discount Amount</th>
				<th style='font-size: 13px; border: 1px solid; border-collapse: collapse;'>Due Amount</th>
			</tr>
			</thead>
			<tbody>
";
$sl=0;
$total_no_of_services = 0;
$total_amount_for_all_services = 0;
$total_due_amount_for_all_services = 0;
$total_paid_amount_for_all_services = 0;
$total_discount_amount_for_all_services = 0;
$set_payment_status_for_all_services = "";
$count_school = 1;
$next_school="";
foreach($shift_list AS $index1=>$value1){
$school_name_for_selected_row = $value1['_school_name'];
$new_id=$value1['_pid'];
$exam_name_for_selected_row = $value1['_exam_name'];
$total_amount_for_selected_row = $value1['_total_amount'];
$total_amount_for_all_services = $total_amount_for_all_services + $total_amount_for_selected_row;
$due_amount_for_selected_row = $value1['_due_amount'];
$total_due_amount_for_all_services = $total_due_amount_for_all_services + $due_amount_for_selected_row;
$paid_amount_for_selected_row = $value1['_paid_amount'];
$total_paid_amount_for_all_services = $total_paid_amount_for_all_services + $paid_amount_for_selected_row;
$discount_amount_for_selected_row = $value1['_discount_amount'];
$total_discount_amount_for_all_services = $total_discount_amount_for_all_services + $discount_amount_for_selected_row;
$show_payment_status = $value1['_status'];
	$html.="	<tr style='border: 1px solid black; border-collapse: collapse;'>";
						
						if ($new_id!=$pre_id)
{
$table_name=" _exam_service_registration";
$where_cond="_session='".$session_input_for_view_report."' and _pid=".$value1['_pid'];
$count_school=$obj->Total_Count_By_Cond($table_name,$where_cond);
$sl++;
$html.=	"<td rowspan='$count_school' style='font-size: 12px; text-align: center; width: 50px; border: 1px solid; border-collapse: collapse;'>$sl</td>
		<td rowspan='$count_school' style='font-size: 12px; text-align: center; border: 1px solid; border-collapse: collapse;'>$school_name_for_selected_row</td>";						
$pre_id=$value1['_pid'];
}
$html.="<td style='font-size: 12px; text-align: center; border: 1px solid; border-collapse: collapse;'>$exam_name_for_selected_row</td>
		<td style='font-size: 12px; text-align: center; border: 1px solid; border-collapse: collapse;'>$total_amount_for_selected_row</td>
		<td style='font-size: 12px; text-align: center; border: 1px solid; border-collapse: collapse;'>$paid_amount_for_selected_row</td>
		<td style='font-size: 12px; text-align: center; border: 1px solid; border-collapse: collapse;'>$discount_amount_for_selected_row</td>
		<td style='font-size: 12px; text-align: center; border: 1px; border-collapse: collapse;'>$due_amount_for_selected_row</td>
		</tr>";


$count_school=1;
}
$html.="<tr style='border: 1px solid black; border-collapse: collapse;'>
			<td colspan='3' style='font-size: 13px; font-weight:bold; text-align: right;'>Payment Summary</td>
			<td style='text-align: center; font-size: 13px; color:blue; border: 1px solid; border-collapse: collapse;'>$total_amount_for_all_services</td>
			<td style='text-align: center; font-size: 13px; color:green; border: 1px solid; border-collapse: collapse;'>$total_paid_amount_for_all_services</td>
			<td style='text-align: center; font-size: 13px; border: 1px solid; border-collapse: collapse;'>$total_discount_amount_for_all_services</td>
			<td style='text-align: center; font-size: 13px; color:red; border: 1px solid; border-collapse: collapse;'>$total_due_amount_for_all_services</td></tr>";
$html=$html."</tbody></table></div></div></body></html>";
$mpdf = new mPDF();
$mpdf->SetDisplayMode('fullpage');
$mpdf->SetWatermarkImage('../../'.$service_provider_logo);
$mpdf->showWatermarkImage = true;
$mpdf->WriteHTML($html);
$mpdf->Output();
}?>