<?php
//ob_start();
session_start();
// ============
include("../../asset/theme/css/myfunc.php");
include("../../php_crud/my_class.php");
require_once("../../asset/custom/mpdf/mpdf.php");
$obj=new my_class();
$branchid = $_SESSION['LOGIN_BRANCH'];
$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;
			$ins_zip_code = $brans_obj->_zip_code;
			$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 : '';
		}
extract($_GET);
$uniq_id = trim($uniq_id);

//$sec = $obj->Details_By_Cond("_fee_master_invoice","_invoice_no='$invoice'");

$std_info_table = "_pf_std_personal_info psf LEFT JOIN _pf_std_basic_info pbf ON psf._id=pbf._pid";
$std_info_cols = "psf._id AS std_id,psf._full_name AS std_name,psf._section_roll AS std_roll,pbf._section_id AS sec_id";
$std_info_where_cond = "psf._uniq_id='$uniq_id' AND pbf._session='$fee_year' AND psf._status='A'";

$std_info = $obj->View_column_details_By_Cond($std_info_table,$std_info_cols,$std_info_where_cond);
$std_id= $std_info['std_id'];
$std_name = $std_info['std_name'];
$student_sectionroll = $std_info['std_roll'];

$sec = $obj->Details_By_Cond("_pf_std_basic_info","_pid='".$std_id."'");
$det_in = $obj->Details_By_Cond("_int_institute_setup_vw","section_id='".$std_info['sec_id']."'");
$detin_shift = $det_in["shift"];
$detin_medium = $det_in["medium"];
$detin_class = $det_in["class"];
$detin_department = $det_in["department"];
$detin_student_type = $det_in["student_type"];
$detin_section = $det_in["section"];

$std_img="";
				if(file_exists('../../'.$std_info['_image_location'])) {
					$std_img = '<img src="../../' . $std_info['_image_location'] . '" style="width:110px;height:100px; border: 2px solid; border-collapse: collapse;" title="photo" alt="student photo" id="image" />';
				}
				else{
					$std_img ="";
				}
				//echo $std_img;

$output='<html><head></head><body>';
$output.='<style>
	
				.page-border
		   {
			width:100%;
			height:100%;
			padding:1px;
			
			
			border:6px solid #00AEEF; 
			/*#ff33b2 #F7931D   */
			
			}
			
		   .page-border2
		   {
			width:100%;
			height:98.5%;
			
			
			
			border:3px solid #00AEEF; 
			
			}
			</style>';

$output .= "<div class='page-border'><div class='page-border2'>
<table style=' width: 100%;'>
					<tr>
					<td colspan='3' style='text-transform: uppercase;  width: 100%;font-size:24px;font-weight:bold; text-align:center;'>$inst_name</td>
					</tr>
						<tr>
					<td style='padding-top: 10px; width: 20%; padding-bottom: 50px; text-align:left;'>";

						if ($ins_logo != '') {
						$img = '<img src="../../' . $ins_logo . '" valign="top" style="width:70px;height:70px;" title="logo" alt="institute logo" id="image" />';
                } else {
						// alternate iamge
						$img = '';
                }		

						$output .= "$img</td>
						<td valign='top'>
						<table style='width:100% ;'>
						<tr>
							<td style='text-align: center; width: 60%; font-size:12px;'>$ins_address, $inst_thanta, $ins_district-$ins_zip_code</td>
						</tr>
						<tr>
							<td style='text-align: center;'><h2 style=' border-bottom: 2px solid black;'>Fee Statement for $fee_year</h2></td>
						</tr>
						</table>
						<td  rowspan='2' style='text-align: center; width: 20%;font-size:12px;'>$std_img</td>

						</tr>";

					 /*$output .= "<tr style='border: 1px solid; border-collapse: collapse;'>
					 <td ></td>
						
					<td style='border: 1px solid; border-collapse: collapse''></td>
						</tr>";*/
						$output .= "</table>";

$output.='
		<table style="font-size: 12px; width: 98%; padding-right:140px;">
				<tr style="border: 1px solid; border-collapse: collapse;">
					<td width="16%" style="font-weight:bold; background-color:#FFFFFF; line-height:10px; text-align:right;">Name : </td>
                    <td style="font-weight:bold; background-color:#FFFFFF; line-height:10px;"><span class="label label-success" style="font-weight:bold;">'.$std_name.'</span></td>
                    <td style="font-weight:bold; line-height:10px;text-align:right;">Roll : </td>
                    <td style="font-weight:bold; line-height:10px;"><span class="label label-warning" style="font-weight:bold;">'.$student_sectionroll.'</span></td>
					<td style="font-weight:bold; line-height:10px;text-align:right;"> </td>
                    <td style="font-weight:bold; line-height:10px;"><span class="label label-warning;"></span></td>
				</tr>
				<tr>
					<td width="16%" style="font-weight:bold; background-color:#FFFFFF; line-height:10px; text-align:right;">Shift : </td>
                    <td style="font-weight:bold; background-color:#FFFFFF; line-height:10px;"><span class="label label-success" style="font-weight:bold;">  '.$detin_shift.'</span></td>
					<td width="16%" style="font-weight:bold; background-color:#FFFFFF; line-height:10px;text-align:right;">Medium : </td>
                    <td style="font-weight:bold; background-color:#FFFFFF; line-height:10px;"><span class="label label-success" style="font-weight:bold;">'. $detin_medium.' </span></td>
				</tr>
                <tr>
					<td style="font-weight:bold; line-height:10px;text-align:right;">Class :</td>
                    <td style="font-weight:bold; line-height:10px;"><span class="label label-warning" style="font-weight:bold;">'.$detin_class.' </span></td>
					<td style="font-weight:bold;line-height:10px;text-align:right;">Department </td>
                    <td style="font-weight:bold; line-height:10px;"><span class="label label-warning" style="font-weight:bold;">'.$detin_department.'</span></td>								
				</tr>
				<tr>
					<td style="font-weight:bold; background-color:#FFFFFF; line-height:10px;text-align:right;">Student Type : </td>
                    <td style="font-weight:bold; background-color:#FFFFFF; line-height:10px;"><span class="label label-success" style="font-weight:bold;"> '.$detin_student_type.' </span></td>	
					<td style="font-weight:bold; background-color:#FFFFFF; line-height:10px;text-align:right;">Section : </td>
                    <td style="font-weight:bold; background-color:#FFFFFF; line-height:10px;"><span class="label label-success" style="font-weight:bold;">'.$detin_section.'</span></td>				
				</tr>
		</table>
		';

	$output.='<br>';
$output.='
	<table style="font-size: 12px; width: 100%; border: 1px solid; border-collapse: collapse;">
		<thead>
		<tbody>
		<tr style="border: 1px solid; border-collapse: collapse;">
			<th style="width: 25px; border: 1px solid; border-collapse: collapse;">Sl</th>
			<th style="width: 70px; border: 1px solid; border-collapse: collapse;">Month</th>
			<th style="width: 100px; border: 1px solid; border-collapse: collapse;">Invoice</th>
			<th style="border: 1px solid; border-collapse: collapse;">Total Amount</th>
            <th style="border: 1px solid; border-collapse: collapse;">Paid Amount</th>
            <th style="border: 1px solid; border-collapse: collapse;">Discount Amount</th>
			<th style="border: 1px solid; border-collapse: collapse;">Due Amount</th>
            <th style="border: 1px solid; border-collapse: collapse;">Payment Date</th>
			<!--<th style="border: 1px solid; border-collapse: collapse;">Status</th>-->
			</tr>
		</thead>
		<br>
		';

		//$output .='<tbody>';
		
		//$invoice_no=$value_s["_invoice_no"];
		//$=$value_s["_invoice_no"];

			$i=0;
			$total_amount=0;
			//$total_amount=$total_amount.' +='.$value_s["_total_amount"];
			$total_paid_amount=0;
			//$paid_amount=$total_paid_amount.' +='.$value_s["_paid_amount"];
			$total_due_amount=0;
			//$total_due =$total_due_amount.' +='.$value_s['_due_amount'];
			$where_cond = "_std_id=$std_id AND _year=$fee_year ORDER BY CONVERT(_month, DECIMAL) ASC";
			foreach($obj->View_colmn_By_Cond('_fee_master_invoice','_month,_total_amount,_due_amount,_discount,_paid_amount,_payment_date,_status,_invoice_no',$where_cond) as $value_s)
			{
			extract($value_s);
			$Month=$obj->Month($value_s["_month"]);
			//$barcode=$obj->print_barcode($value_s["_invoice_no"], "20", "1");

			$invoice=$value_s["_invoice_no"];
			$format_totalamount=number_format($value_s["_total_amount"],2);
			$discount_amount=number_format($value_s['_discount'],2);
			$format_paidamount=number_format($value_s["_paid_amount"],2);
		
			$due=$value_s["_due_amount"];
			$Status=$value_s['_status'];
			$total_amount = $total_amount + $value_s["_total_amount"];
			$total_paid_amount+=$value_s["_paid_amount"];
			$total_due_amount+=$value_s['_due_amount'];
			$i++;
			//$paid_date = $obj->Details_By_Cond("_fee_total_receive","_invoice_no='".$value_s['_invoice_no']."'");
			if($value_s['_payment_date']!=null){
				$paid=date('d/m/Y',strtotime($value_s['_payment_date']));
			}
			else{
				$paid='';
			}
			
		$output.='<tr style="border: 1px solid; border-collapse: collapse;">
				<td class="td_pad" style="text-align: center; border: 1px solid; border-collapse: collapse;">
					'.$i.'
				</td>
				<td class="td_pad" style="text-align: left; border: 1px solid; border-collapse: collapse;">'. $Month.'</td> 
				<td class="td_pad" style="text-align: center; border: 1px solid; border-collapse: collapse;">
					 '.$invoice.'
				</td>
				<td class="td_pad" style="text-align: center; border: 1px solid; border-collapse: collapse;">
				'.$format_totalamount.'
				<!--'.$total_amount.'--> 
				</td>
                <td class="td_pad" style="text-align: center; border: 1px solid; border-collapse: collapse;">'.$format_paidamount.'
				<!--'.$paid_amount.'-->
				</td>
				<td class="td_pad" style="text-align: center; border: 1px solid; border-collapse: collapse;">'.$discount_amount.'
				<!--'.$paid_amount.'-->
				</td>	

				<td class="td_pad" style="text-align: center; border: 1px solid; border-collapse: collapse;">'.$due.'
				'.$total_due.'
			    </td>
                <td class="td_pad" style="text-align: center; border: 1px solid; border-collapse: collapse;"> '.$paid.'</td>				
				<!--<td class="td_pad">-->';
				 /*if($Status=="P"){ 
				$output.='<span class="btn btn-minier btn-success"><i class="icon-ok bigger-70"></i>Paid</span>';
				 } elseif($Status=="U"){
				$output.='<span class="btn btn-minier btn-danger">Unpaid</span>';
				 } elseif($Status=="PR"){ 
				$output.='<span class="btn btn-minier btn-warning">Partially Paid</span>';
				 } elseif($Status=="AD"){
				$output.='<span class="btn btn-minier btn-warning">Adjustment</span>';
				 }
				$output.='</td>-->';*/
$output.='</tr>';	
			 }
						
		$output.='</tbody>'	;
		$output.='<tfoot>
        	<tr>
            	<td colspan="3" style="text-align: center; border: 1px solid; border-collapse: collapse;"><b>Total Amount:</b></td>
                <td style="text-align: center; border: 1px solid; border-collapse: collapse;"><b>'.number_format($total_amount,2).'</b></td>
                <td  style="text-align: center; border: 1px solid; border-collapse: collapse;"><b>'.number_format($total_paid_amount,2).'</b></td>
                <td style="text-align: center; border: 1px solid; border-collapse: collapse;"><b>'.$discount_amount.'</b></td>
                <td style="text-align: center; border: 1px solid; border-collapse: collapse;"><b>'.$due.'</b></td>
                <!--<td  style="text-align: center; border: 1px solid; border-collapse: collapse;">&nbsp;</td>-->
                <!--<td style="text-align:right;">&nbsp;</td>-->
               <!--<th style="text-align:right;">&nbsp;</th>-->
            </tr>
        </tfoot>
	';

//$output.='</div>';
//$output.='</div>';
$output.='</tbody>';
$output.='</table>';
$output.='</div></div>';
//$output.='<div class="row-fluid" id="second">
//</div>';
//$output.='</div>';
$output.='</body></html>';
//echo $output;

//exit;
//ob_clean();
$mpdf =  new mPDF('c', 'A4');
$mpdf->SetDisplayMode('fullpage');
$mpdf->SetWatermarkImage('../../'.$ins_logo  , .15,50,150);
$mpdf->showWatermarkImage = true;
$mpdf->WriteHTML($output);
// Output a PDF file directly to the browser
//ob_end_flush();
$mpdf->Output();
?>

