<?php
session_start();
// ============
include("../../asset/theme/css/myfunc.php");
include("../../php_crud/my_class.php");
//include("test_page.php");	
require_once("../../asset/custom/mpdf/mpdf.php");
$obj=new my_class();
extract($_GET);

$branchid = $_SESSION['LOGIN_BRANCH'];
/* $month;
$year;
$section_id;
$stdid; */
$invoice_id;

$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_zip_code = $brans_obj->_zip_code;
	$ins_web = $brans_obj->_web_address !='' ? $brans_obj->_web_address : '' ;
	$ins_email = $brans_obj->_email_add !='' ? '|| '.$brans_obj->_email_add : '' ;
	
}

$detail='<html><head>
<title>Students Fee Invoice </title>
	<style>
		.fee_col_left_bottom{
			border-right: 1px solid;
			border-bottom: 1px solid; 
			border-collapse: collapse;
			width: 10%;
			height: 20px;
		}
		.fee_col_left_bottom_summ{
			border-bottom: 1px solid; 
			border-collapse: collapse;
			width: 10%;
			height: 20px;
		}
		.fee_col_middle_bottom{
			border-right: 1px solid;
			border-bottom: 1px solid; 
			border-collapse: collapse;
			width: 70%;
			height: 20px;
		}
		.fee_col_right_bottom{
			border-left:1px solid;
			border-bottom: 1px solid; 
			border-collapse:collapse;
			width: 20%;
			height: 20px;
		}
		.fee_col_left_top{
			border-top:1px solid; 
			border-right:1px solid;
			border-bottom: 1px solid; 
			border-collapse:collapse;
			width: 10%;
			height: 20px;
		}
		.fee_col_left_top_summ{
			border-top:1px solid;
			border-bottom: 1px solid; 			
			border-collapse:collapse;
			width: 10%;
			height: 20px;
		}
		.fee_col_middle_top{
			border-top:1px solid; 
			border-right:1px solid;
			border-bottom: 1px solid; 
			border-collapse:collapse;
			width: 70%;
			height: 20px;
		}
		.fee_col_right_top{
			border-top:1px solid; 
			border-left:1px solid;
			border-bottom: 1px solid; 
			border-collapse:collapse;
			width: 20%;
			height: 20px;
		}
		.fee_col_left{
			border-right: 1px solid;
			border-collapse: collapse;
			width: 10%;
			height: 20px;
		}
		.fee_col_left_summ{
			width: 10%;
			height: 20px;
		}
		.fee_col_middle{
			border-right: 1px solid;
			border-collapse: collapse;
			width: 70%;
			height: 20px;
		}
		.fee_col_right{
			border-left: 1px solid;
			border-collapse: collapse;
			width: 20%;
			height: 20px;
		}
	</style>
	</head>
	<body>';

function numberTowords($num){ 
	$ones = array( 1 => "One", 2 => "Two", 3 => "Three", 4 => "Four", 5 => "Five", 6 => "Six", 7 => "Seven", 8 => "Eight", 9 => "Nine", 10 => "Ten", 11 => "Eleven", 12 => "Twelve", 
					13 => "Thirteen", 14 => "Fourteen", 15 => "Fifteen", 16 => "Sixteen", 17 => "Seventeen", 18 => "Eighteen", 19 => "Nineteen"); 
	
	$tens = array( 1 => "Ten", 2 => "Twenty", 3 => "Thirty", 4 => "Forty", 5 => "Fifty", 6 => "Sixty", 7 => "Seventy", 8 => "Eighty", 9 => "Ninety" ); 
	
	$hundreds = array( "Hundred", "Thousand", "Million", "Billion", "Trillion", "Quadrillion" ); //limit t quadrillion 

	$num = number_format($num,2,".",","); 
	$num_arr = explode(".",$num); 
	$wholenum = $num_arr[0]; 
	$decnum = $num_arr[1]; 
	$whole_arr = array_reverse(explode(",",$wholenum)); 
	krsort($whole_arr); 
	$rettxt = ""; 
	
	foreach($whole_arr as $key => $i){ 
		if($i < 20){ 
			$rettxt .= $ones[$i]; 
		}elseif($i < 100){ 
			$rettxt .= $tens[substr($i,0,1)]; 
			$rettxt .= " ".$ones[substr($i,1,1)]; 
		}else{ 
			$rettxt .= $ones[substr($i,0,1)]." ".$hundreds[0]; 
			$rettxt .= " ".$tens[substr($i,1,1)]; 
			$rettxt .= " ".$ones[substr($i,2,1)]; 
		} 
		if($key > 0){ 
			$rettxt .= " ".$hundreds[$key]." "; 
		} 
	}
	
	if($decnum > 0){ 
		$rettxt .= " and "; 
		
		if($decnum < 20){ 
			$rettxt .= $ones[$decnum]; 
		}elseif($decnum < 100){ 
			$rettxt .= $tens[substr($decnum,0,1)]; 
			$rettxt .= " ".$ones[substr($decnum,1,1)]; 
		} 
	} 
	return $rettxt; 
} 


// add a page
foreach($obj->sect_invoice("ins.branch_id = '$branchid' AND fm._invoice_no = '$invoice_id'") as $value){
	extract($value);
	/////
	$std_id = $value['_std_id'];
	$sc_id = $value['section_id'];
	$mnt = $value['_month'];
	$br = $value['branch_id'];
	$yr = $value['_year'];
	$std_class_info_table="_pf_std_personal_info psf LEFT JOIN _pf_std_basic_info pbf ON psf._id=pbf._pid
							LEFT JOIN _int_institute_setup_vw ins ON pbf._section_id=ins.section_id";
	$std_class_info_col="psf._full_name AS std_name,psf._section_roll AS roll,psf._uniq_id AS uid,ins.class AS _class,ins.section AS _sect,ins.medium";
	$std_class_info_where_cond="psf._id='$std_id'";
	$std_class_info = $obj->View_column_details_By_Cond($std_class_info_table,$std_class_info_col,$std_class_info_where_cond);
	extract($std_class_info);
	$std_name = $std_class_info['std_name'];
	$std_roll = $std_class_info['roll'];
	$std_uid = $std_class_info['uid'];
	$std_class = $std_class_info['_class'];
	$std_sec = $std_class_info['_sect'];
	
	if($std_class_info['medium']=='Bangla' || $std_class_info['medium']=='Toddler'){
		//$im='../../asset/custom/upload/deen_bangla_logo.png';
		$ins_logo='asset/custom/upload/deen_bangla_logo.png';
		$image = '<img src="../../'.$ins_logo.'" style="top:15px; height:160px; float:left;margin-left: 12px;" title="logo" alt="" id="image" />';
	}
	else{
		//$im='../../asset/custom/upload/deen_english_logo.png';
		$ins_logo='asset/custom/upload/deen_english_logo.png';
		$image = '<img src="../../'.$ins_logo.'" style="top:15px; height:120px; float:left;margin-left: 12px;" title="logo" alt="" id="image" />';
	}
	
	$status_flag="";
	foreach($obj->View_All_By_Cond(" _fee_master_invoice ","_br_id = '$br' AND _section_id = '$sc_id' AND _month = '$mnt'  AND _year = '$yr'  AND _std_id = '$std_id' AND _invoice_no='$invoice_id'") as $net){
		extract($net);
		$_status;
		$status_flag = $_status;
        $paid_date = $obj->Details_By_Cond("_fee_total_receive","_invoice_no='".$net['_invoice_no']."'"); 
		if($net['_month']<10){
			$inv_mon_no = '0'.$net['_month'];
		}
		else{
			$inv_mon_no = $net['_month'];
		}
		if(strlen($net['_invoice_no'])>30){
			$show_inv_no = $net['_invoice_no'];	
		}
		else{
			$show_inv_no = $net['_year'].$inv_mon_no.'-'.$net['_invoice_no'];	
		}
			   					
		if(!empty($net['_payment_date'])){ 
			if($net['_payment_date']=='0000-00-00'){$f_date = '';}
			else { 
				$f_date = date('d/m/Y',strtotime($net['_payment_date'])); 
				//$f_date =$paid_date['_entry_date'];
			}
		}
		$imi ='';	
        if($_status=='P'){
			$imi ='<img src="invoice_report/circular_paid_stamp.png" style="top:15px;height: 255px; float:right;margin-left: 12px;"/>'; 
		}
		if($_status=='AD'){
			$imi ='<img src="invoice_report/ADJUSTMENT-1.png" style="top:15px;height:200px; float:right;margin-left: 12px;" />'; 
		}
		if($_status=='PR'){
			$imi ='<img src="invoice_report/circular_received_stamp.png" style="top:15px; height: 210px; float:right;margin-left: 12px;" />'; 
		}
		//if($_status=='U'){
			//$imi ='<img src="invoice_report/empty_img_for_unpaid_status.png" style="top:15px; height: 90px; float:right;margin-left: 12px;" />'; 
		//}		
	}
	
	if($status_flag=='U'){
		$num_of_empty_row=18;
	}
	else if($status_flag=='PR'){
		$num_of_empty_row=10;
	}
	else{
		$num_of_empty_row=8;
	}
	$month_name='';
	if($value['_month']==1){
		$month_name.='Jan';
	}
	elseif($value['_month']==2){
		$month_name.='Feb';
	}
	elseif($value['_month']==3){
		$month_name.='Mar';
	}
	elseif($value['_month']==4){
		$month_name.='Apr';
	}	
	elseif($value['_month']==5){
		$month_name.='May';
	}	
	elseif($value['_month']==6){
		$month_name.='Jun';
	}	
	elseif($value['_month']==7){
		$month_name.='Jul';
	}	
	elseif($value['_month']==8){
		$month_name.='Aug';
	}	
	elseif($value['_month']==9){
		$month_name.='Sep';
	}	
	elseif($value['_month']==10){
		$month_name.='Oct';
	}	
	elseif($value['_month']==11){
		$month_name.='Nov';
	}	
	elseif($value['_month']==12){
		$month_name.='Dec';
	}
	
	
/* =============================== */
	//include("test_page.php");
	//start of main table
	$detail .= '<table style="width: 100%; padding-top:20px;">
	<tr>';
	//student copy column
	$detail .= '<td style="width: 32%; padding-right:10px;">
					<table style="width:100%; margin-right:12px;">';
	//row holds student copy school info				
	$detail .= '		<tr>
							<td>
								<!--school info table -->
								<table style="width: 100%; margin-right:5px;">
									<tr style="width: 100%;">
										<td style="width: 100%; text-align: center;">
											<p style="font-size: 35px; text-align: center;"><b>'.$inst_name.'</b></p>
										</td>
									</tr>
									<tr style="width: 100%;">
										<td style="width: 100%; text-align: center; font-size: 20px;">
											<p><b>'.$ins_address.' <br>'.$inst_thanta.', '.$ins_district.'-'.$ins_zip_code.'</b></p>
											<p>'.$image.'</p>
										</td>
									</tr>
									<tr style="width: 100%;">
										<td style="width: 100%; text-align: center;">
											<p style=" font-size: 26px;"><b>Money Receipt (Accounts Copy)</b></p>
										</td>
									</tr>
								</table>
							</td>
						</tr>';
	//row holds student copy student info
	
	$detail .= '
						<tr>
							<td>
								<table style="width:100%; border-collapse: collapse;" >
									<tr> 
										<td  style="width: 50%; height: 20px; text-align: left;"><p style=" font-size: 26px;">Payment Date : <b>'.$f_date.'</b></p></td>
										<td style="padding-left: 0px; width: 50%; height: 20px; text-align: right;"><p style=" font-size: 26px;"><b>'.$show_inv_no.'</b></p></td>
									</tr>
									<tr> 
										<!--<td colspan="2" style="width: 100%; height: 20px; text-align: left;"><p style=" font-size: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p></td>-->
										<td  style="width: 50%; height: 20px; text-align: left;"><p style=" font-size: 26px;">&nbsp;&nbsp;&nbsp;&nbsp;</p></td>
										<td style="padding-left: 0px; width: 50%; height: 20px; text-align: right;"><p style=" font-size: 26px;"><b>'. $month_name.'-'.$value['_year'].'</b></p></td>
									</tr>
									<tr> 
										<td colspan="2" style="width: 100%; height: 20px; text-align: left;"><p style=" font-size: 28px;">Name : <b>'.$std_name.'</b></p></td>	
									</tr>
									<tr>
										<td style="width: 50%; height: 20px; font-size: 26px; text-align: left;"><p style=" font-size: 26px;">ID  : <b>'.$std_uid.'</b></p></td>
										<td style="padding-left: 0px; width: 50%; height: 20px; text-align: left;"><p style=" font-size: 26px;">Roll : <b>'.$std_roll.'</b></p></td>
									</tr>
									<tr> 
										<td style="width: 50%; height: 20px; text-align: left;"><p style=" font-size: 26px;">Class : <b>'.$std_class.'</b></p></td>
										<td style="padding-left: 0px; width: 50%; height: 20px; text-align: left;"><p style=" font-size: 26px;">Sec : <b>'. $std_sec.'</b></p></td>												
										<!--<td style="padding-left: 0px; width: 50%; height: 20px; text-align: left;"><p style=" font-size: 26px;">Dept : <b>'. $value['department'].'</b></p></td>-->												
									</tr>
								</table>
							</td>
						</tr>
						<!--<tr><td style="width: 100%; height: 3px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td></tr>-->';
	//row holds student copy fee info
	$detail .= '		<tr>
							<td style="border-left: 1px solid;border-right: 1px solid;border-top: 1px solid;border-bottom: 1px solid;">
								<table style="width:100%; border-collapse: collapse;">
								<tr>
									<td class="fee_col_left_bottom" style="font-weight: bold; text-align: center;" ><p style="font-size: 26px;">Sl</p></td>
									<td class="fee_col_middle_bottom" style="font-weight: bold; text-align: center;" ><p style="font-size: 26px;">Description</p></td>
									<td class="fee_col_right_bottom" style="font-weight: bold; text-align: center;" ><p style="font-size: 26px;">Amount</p></td>
								</tr>';
								$in_std=0;
								foreach($obj->View_All_By_Cond(" _fee_details_invoice ","_br_id = '$br' AND _month = '$mnt'  AND _year = '$yr'  AND _std_id = '$std_id' AND _type='C' AND _invoice_no='$invoice_id'") as $tes){
									extract($tes);
									$in_std++;
									$a= $tes['_amount'];
									$b = floatval($a);
									$deb = number_format( (float) $b, 2, '.', '');				
									$detail .='<tr>
												<td class="fee_col_left" style="text-align: center;"><p style="font-size: 26px;">'.$in_std.'</p></td>
												<td class="fee_col_middle" style="text-align: left;"><p style="font-size: 26px;">&nbsp;&nbsp;'.$tes['_fee_head'].'</p></td>
												<td class="fee_col_right" style="text-align: right;"><p style="font-size: 26px;">'.$deb.'&nbsp;&nbsp;</p></td>
											</tr>';
								}
								foreach($obj->View_All_By_Cond(" _fee_details_invoice ","_br_id = '$br' AND _month = '$mnt'  AND _year = '$yr'  AND _std_id = '$std_id' AND _type='D' AND _invoice_no='$invoice_id'") as $tes1){
									extract($tes1);	
									$in_std++;
									$a= $tes1['_amount'];
									$b = floatval($a);
									$cr = number_format( (float) $b, 2, '.', '');					
									$detail .='<tr>
												<td class="fee_col_left" style="text-align: center;"><p style="font-size: 26px;">'.$in_std.'</p></td>
												<td class="fee_col_middle" style="text-align: left;"><p style="font-size: 26px;">&nbsp;&nbsp;'.$tes1['_fee_head'].'</p></td>
												<td class="fee_col_right" style="text-align: right;"><p style="font-size: 26px;">(-)'.$cr.'&nbsp;&nbsp;</p></td>
											</tr>';
								}
								if($net['_status']=='PR'){
									 foreach($obj->View_All_By_Cond(" _fee_partial_pay_table  ","_invoice = '$invoice_id' ") as $par){
										extract($par);
										$in_std++;
										$par_date = date('d-m-Y',strtotime($par['_entry_date']));
										$a = floatval($par['_par_amount']);
										$par_amount = number_format( (float) $a, 2, '.', '');	
										$detail .='<tr>
												<td class="fee_col_left" style="text-align: center;"><p style="font-size: 26px;">'.$in_std.'</p></td>
												<td class="fee_col_middle" style="text-align: left;"><p style="font-size: 26px;">&nbsp;&nbsp;Partial Payment&nbsp;('.$par_date.')</p></td>
												<td class="fee_col_right" style="text-align: right;"><p style="font-size: 26px;">(-)'.$par_amount.'&nbsp;&nbsp;</p></td></tr>';
									}
								}
								
								for($i=$in_std+1; $i<=$num_of_empty_row; $i++){
									if($i==($num_of_empty_row-2) && $status_flag!='U'){
										$detail .= '<tr>
											<td class="fee_col_left" style="text-align: center;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
											<td class="fee_col_middle" style="text-align: center; padding-right: 10px;">'.$imi.'</td>
											<td class="fee_col_right" style="text-align: center;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
										</tr>';
									}
									else{
										$detail .= '<tr>
											<td class="fee_col_left" style="text-align: center;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
											<td class="fee_col_middle" style="text-align: center;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
											<td class="fee_col_right" style="text-align: center;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
										</tr>';
									}
								
								}
								if(($in_std==$num_of_empty_row || $in_std==($num_of_empty_row-2) || $in_std==($num_of_empty_row-1)) && $status_flag!='U'){
									$detail .= '<tr>
											<td class="fee_col_left" style="text-align: center;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
											<td class="fee_col_middle" style="text-align: center; padding-right: 10px;">'.$imi.'</td>
											<td class="fee_col_right" style="text-align: center;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
										</tr>';
								}
	//row holds fee summary info
	foreach($obj->View_All_By_Cond(" _fee_master_invoice ","_br_id = '$br' AND _invoice_no = '$invoice_id'") as $val){
					extract($val);
					//$a= $val['_cr_amount'];
					$tot_amount= $val['_total_amount'];
					$tot_amount = floatval($tot_amount);
					//$cr_am = number_format( (float) $b, 2, '.', '');
									
					//$c= $val['_dr_amount'];
					//$d = floatval($c);
					//$dr_am = number_format( (float) $d, 2, '.', '');
					$tot_am = number_format( (float)($tot_amount), 2, '.', '');
					
					$detail .='<tr>
								<td class="fee_col_left_top_summ" style="text-align: right;"><p style="font-size: 26px;"></p></td>
								<td class="fee_col_middle_top" style="text-align: right;"><p style="font-size: 26px;"><b>Total Payable Amount&nbsp;</b></p></td>
								<td class="fee_col_right_top" style="text-align: right;"><p style="font-size: 26px;"><b>'.$tot_am.'&nbsp;</b></p></td>
							</tr>';
				}
				foreach($obj->View_All_By_Cond(" _fee_master_invoice ","_br_id = '$br' AND _invoice_no = '$invoice_id'") as $net){
					extract($net);
					$_status;
					$discount_amt= $net['_discount'];
					$discount_amt = floatval($discount_amt);
					$discount_amt = number_format( (float) $discount_amt, 2, '.', '');
														
					$detail .='<tr>
								<td class="fee_col_left_bottom_summ" style="text-align: right;" ><p style=" font-size: 26px;"></p></td>
								<td class="fee_col_middle_bottom" style="text-align: right;" ><p style=" font-size: 26px;"><b>Discount&nbsp;</b></p></td>
								<td class="fee_col_right_bottom" style="text-align: right;"><p style=" font-size: 26px;"><b>'.$discount_amt.'&nbsp;</b></p></td>
							</tr>';       
				}
				foreach($obj->View_All_By_Cond(" _fee_master_invoice ","_br_id = '$br' AND _invoice_no = '$invoice_id'") as $net){
					extract($net);
					$_status;
					$tot_recv= $net['_paid_amount'];
					$tot_rcv = floatval($tot_recv);
					$tot_recve = number_format( (float) $tot_rcv, 2, '.', '');							
					$detail .='<tr>
								<td class="fee_col_left_bottom_summ" style="text-align: right;" ><p style=" font-size: 26px;"></p></td>
								<td class="fee_col_middle_bottom" style="text-align: right;" ><p style=" font-size: 26px;"><b>Total Received Amount&nbsp;</b></p></td>
								<td class="fee_col_right_bottom" style="text-align: right;"><p style=" font-size: 26px;"><b>'.$tot_recve.'&nbsp;</b></p></td>
							</tr>';              
				}
				foreach($obj->View_All_By_Cond(" _fee_master_invoice ","_br_id = '$br' AND _invoice_no = '$invoice_id'") as $net){
					extract($net);
					$_status;
					$recv= $net['_last_paid_amount'];
					$rcv = floatval($recv);
					$recve = number_format( (float) $rcv, 2, '.', '');
														
					$detail .='<tr>
								<td class="fee_col_left_bottom_summ" style="text-align: right;" ><p style=" font-size: 26px;"></p></td>
								<td class="fee_col_middle_bottom" style="text-align: right;" ><p style=" font-size: 26px;"><b>Last Received Amount&nbsp;</b></p></td>
								<td class="fee_col_right_bottom" style="text-align: right;"><p style=" font-size: 26px;"><b>'.$recve.'&nbsp;</b></p></td>
							</tr>'; 
				}
				foreach($obj->View_All_By_Cond(" _fee_master_invoice ","_br_id = '$br' AND _invoice_no = '$invoice_id'") as $net){
					extract($net);
					$_status;
					$a= $net['_due_amount'];
					$b = floatval($a);
					$nt = number_format( (float) $b, 2, '.', '');
		
					$detail .='<tr>
					    <td class="fee_col_left_summ" style="text-align: right;" ><p style=" font-size: 26px;"></p></td>
					    <td class="fee_col_middle" style="text-align: right;" ><p style=" font-size: 26px;"><b>Due&nbsp;</b></p></td>
					    <td class="fee_col_right" style="text-align: right;"><p style=" font-size: 26px;"><b>'.$nt.'&nbsp;</b></p></td>
					</tr>';
				}
	$detail .= '				
								</table>
							</td>
						</tr>
				<tr><td style="width: 100%; height: 20px;"><p style="font-size: 20px;">(In Words):&nbsp;<span style="border-bottom: 3px dotted;">'.numberTowords($tot_am).' Taka Only</span></p></td></tr>
				<tr><td style="width: 100%; height: 20px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td></tr>
				<tr><td style="width: 100%; height: 20px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td></tr>
				<!--<tr><td style="width: 100%; height: 20px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td></tr>-->
				<tr><td>
					<table style="width:100%;">
						<tr>
							<td  style="height: 20px; text-align: left; font-weight: bold;"><p style=" font-size: 20px;">_ _ _ _ _ _ _ _</p></td>
							<td style="height: 20px; text-align: right; font-weight:bold;"><p style=" font-size: 20px;">_ _ _ _ _ _ _ _</p></td>
						</tr>
						<tr>
							<td  style="height: 20px; text-align: left; font-weight: bold;"><p style=" font-size: 20px;">Depositor</p></td>
							<td style="height: 20px; text-align: right; font-weight: bold;"><p style=" font-size: 20px;">Received by F.Afrin</p></td>
						</tr>
						<tr>
							<td  style="height: 20px; text-align: left;"><p style=" font-size: 20px;">Printed By: <b>'.$_SESSION["LOGIN_USER"].'</b></p></td>
							<td style="height: 20px; text-align: right;"><p style=" font-size: 20px;">Print Date: <b>'.date(" d/m/Y").'</b></p></td>
						</tr>
				 </table>
				</td></tr>
			</table>
		</td>';
	//1st dotted line column
	$detail .= '<td style=" width: 2%;border-left: 5px dotted black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>';
	//office copy column
	$detail .= '<td style="width: 32%;">
					<table style="width:100%;">';
	//row holds office copy school info				
	$detail .= '		<tr>
							<td>
								<!--school info table -->
								<table style="width: 100%;">
									<tr style="width: 100%;">
										<td style="width: 100%; text-align: center;">
											<p style="font-size: 35px; text-align: center;"><b>'.$inst_name.'</b></p>
										</td>
									</tr>
									<tr style="width: 100%;">
										<td style="width: 100%; text-align: center; font-size: 20px;">
											<p><b>'.$ins_address.' <br>'.$inst_thanta.', '.$ins_district.'-'.$ins_zip_code.'</b></p>
											<p>'.$image.'</p>
										</td>
									</tr>
									<tr style="width: 100%;">
							
										<td style="width: 100%; text-align: center;">
											<p style=" font-size: 26px;"><b>Money Receipt (Office Copy)</b></p>
										</td>
									</tr>
								</table>
							</td>
						</tr>';				
	//row holds office copy student info
	$detail .= '
						<tr>
							<td>
								<table style="width:100%; height:80px; border-collapse: collapse;" ><b>'. $month_name.'-'.$value['_year'].'</b>
									<tr> 
										<td  style="width: 50%; height: 20px; text-align: left;"><p style=" font-size: 26px;">Payment Date : <b>'.$f_date.'</b></p></td>
										<td style="width: 50%; height: 20px; text-align: right;"><p style=" font-size: 26px;"><b>'.$show_inv_no.'</p></td>	
									</tr>
									<tr> 
										<!--<td colspan="2" style="width: 100%; height: 20px; text-align: left;"><p style=" font-size: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p></td>-->	
										<td  style="width: 50%; height: 20px; text-align: left;"><p style=" font-size: 26px;">&nbsp;&nbsp;&nbsp;&nbsp;</p></td>
										<td style="width: 50%; height: 20px; text-align: right;"><p style=" font-size: 26px;"><b>'. $month_name.'-'.$value['_year'].'</b></p></td>	
									</tr>
									<tr> 
										<td colspan="2" style="width: 100%; height: 20px; text-align: left;"><p style=" font-size: 28px;">Name : <b>'.$std_name.'</b></p></td>	
									</tr>
									<tr> 
										<td style="width: 50%; height: 20px; text-align: left;"><p style=" font-size: 26px;">ID  : <b>'.$std_uid.'</b></p></td>
										<td  style="padding-left: 0px; width: 50%; height: 20px; text-align: left;"><p style=" font-size: 26px;">Roll : <b>'.$std_roll.'</b></p></td>											
									</tr>
									<tr> 
										<td style="width: 50%; height: 20px; text-align: left;"><p style=" font-size: 26px;">Class : <b>'.$std_class.'</b></p></td>
										<td style="padding-left: 0px; width: 50%; height: 20px; text-align: left;"><p style=" font-size: 26px;">Sec : <b>'. $std_sec.'</b></p></td>	
										<!--<td style="padding-left: 0px; width: 50%; height: 20px; text-align: left;"><p style=" font-size: 26px;">Dept : <b>'. $value['department'].'</b></p></td>-->	
									</tr>	
								</table>
							</td>
						</tr>
						<!--<tr><td style="width: 100%; height: 3px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td></tr>-->';
	//row holds office copy fee info
	$detail .= '		<tr>
							<td style="border-left: 1px solid;border-right: 1px solid;border-top: 1px solid;border-bottom: 1px solid;">
								<table style="width:100%; border-collapse: collapse;">
								<tr>
									<td class="fee_col_left_bottom" style="font-weight: bold; text-align: center;" ><p style=" font-size: 26px;">Sl</p></td>
									<td class="fee_col_middle_bottom" style="font-weight: bold; text-align: center;" ><p style=" font-size: 26px;">Description</p></td>
									<td class="fee_col_right_bottom" style="font-weight: bold; text-align: center;" ><p style=" font-size: 26px;">Amount</p></td>
								</tr>';				
						$in_office=0;
						foreach($obj->View_All_By_Cond(" _fee_details_invoice ","_br_id = '$br' AND  _month = '$mnt'  AND _year = '$yr'  AND _std_id = '$std_id' AND _type='C' AND _invoice_no='$invoice_id'") as $tes){
							extract($tes);
							$in_office++;
							$a= $tes['_amount'];
							$b = floatval($a);
							$deb = number_format( (float) $b, 2, '.', '');				
							$detail .='<tr>
											<td class="fee_col_left" style="text-align: center;"><p style=" font-size: 26px;">'.$in_office.'</p></td>
											<td class="fee_col_middle" style="text-align: left;"><p style=" font-size: 26px;">&nbsp;&nbsp;'.$tes['_fee_head'].'</p></td>
											<td class="fee_col_right" style="text-align: right;"><p style=" font-size: 26px;">'.$deb.'&nbsp;&nbsp;</p></td>
										</tr>';	
						}
						foreach($obj->View_All_By_Cond(" _fee_details_invoice ","_br_id = '$br' AND _month = '$mnt'  AND _year = '$yr'  AND _std_id = '$std_id' AND _type='D' AND _invoice_no='$invoice_id'") as $tes1){
							extract($tes1);	
							$in_office++;
							$a= $tes1['_amount'];
							$b = floatval($a);
							$cr = number_format( (float) $b, 2, '.', '');					
							$detail .='<tr>
											<td class="fee_col_left" style="text-align: center;"><p style=" font-size: 26px;">'.$in_office.'</p></td>
											<td class="fee_col_middle" style="text-align: left;"><p style=" font-size: 26px;">&nbsp;&nbsp;'.$tes1['_fee_head'].'</p></td>
											<td class="fee_col_right" style="text-align: right;"><p style=" font-size: 26px;">(-)'.$cr.'&nbsp;&nbsp;</p></td>
										</tr>';	
						}
						if($net['_status']=='PR'){
							foreach($obj->View_All_By_Cond(" _fee_partial_pay_table  ","_invoice = '$invoice_id' ") as $par){
								extract($par);
								$in_office++;
								$par_date = date('d-m-Y',strtotime($par['_entry_date']));
								$a = floatval($par['_par_amount']);
								$par_amount = number_format( (float) $a, 2, '.', '');
								$detail .='<tr>
											<td class="fee_col_left" style="text-align: center;"><p style=" font-size: 26px;">'.$in_office.'</p></td>
											<td class="fee_col_middle" style="text-align: left;"><p style=" font-size: 26px;">&nbsp;&nbsp;Partial Payment&nbsp;('.$par_date.')</p></td>
											<td class="fee_col_right" style="text-align: right;"><p style=" font-size: 26px;">(-)'.$par_amount.'&nbsp;&nbsp;</p></td>
										</tr>';
							}
						}
						
						for($i=$in_office+1; $i<=$num_of_empty_row; $i++){
							if($i==($num_of_empty_row-2) && $status_flag!='U'){
								$detail .= '<tr>
											<td class="fee_col_left" style="text-align: center;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
											<td class="fee_col_middle" style="text-align: center; padding-right: 30px;">'.$imi.'</td>
											<td class="fee_col_right" style="text-align: center;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
										</tr>';
							}
							else{
								$detail .= '<tr>
											<td class="fee_col_left" style="text-align: center;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
											<td class="fee_col_middle" style="text-align: center;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
											<td class="fee_col_right" style="text-align: center;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
										</tr>';
							}		
						}
						if(($in_office==$num_of_empty_row || $in_office==($num_of_empty_row-2) || $in_office==($num_of_empty_row-1)) && $status_flag!='U'){
							$detail .= '<tr>
										<td class="fee_col_left" style="text-align: center;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
										<td class="fee_col_middle" style="text-align: center; padding-right: 30px;">'.$imi.'</td>
										<td class="fee_col_right" style="text-align: center;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
								</tr>';
						}
	//row holds office fee summary info
	foreach($obj->View_All_By_Cond(" _fee_master_invoice ","_br_id = '$br' AND _invoice_no = '$invoice_id'") as $val){
					extract($val);
					//$a= $val['_cr_amount'];
					$tot_amount= $val['_total_amount'];
					$tot_amount = floatval($tot_amount);
					//$cr_am = number_format( (float) $b, 2, '.', '');
									
					//$c= $val['_dr_amount'];
					//$d = floatval($c);
					//$dr_am = number_format( (float) $d, 2, '.', '');
					$tot_am = number_format( (float)($tot_amount), 2, '.', '');
					
					$detail .='<tr>
								<td class="fee_col_left_top_summ" style="text-align: right;"><p style=" font-size: 26px;"></p></td>
								<td class="fee_col_middle_top" style="text-align: right;"><p style=" font-size: 26px;"><b><b>Total Payable Amount&nbsp;</b></b></p></td>
								<td class="fee_col_right_top" style="text-align: right;"><p style=" font-size: 26px;"><b>'.$tot_am.'&nbsp;</b></p></td>
							</tr>';
				}
				foreach($obj->View_All_By_Cond(" _fee_master_invoice ","_br_id = '$br' AND _invoice_no = '$invoice_id'") as $net){
					extract($net);
					$_status;
					$discount_amt= $net['_discount'];
					$discount_amt = floatval($discount_amt);
					$discount_amt = number_format( (float) $discount_amt, 2, '.', '');
														
					$detail .='<tr>
								<td class="fee_col_left_bottom_summ" style="text-align: right;" ><p style=" font-size: 26px;"></p></td>
								<td class="fee_col_middle_bottom" style="text-align: right;" ><p style=" font-size: 26px;"><b>Discount&nbsp;</b></p></td>
								<td class="fee_col_right_bottom" style="text-align: right;"><p style=" font-size: 26px;"><b>'.$discount_amt.'&nbsp;</b></p></td>
							</tr>';       
				}
				foreach($obj->View_All_By_Cond(" _fee_master_invoice ","_br_id = '$br' AND _invoice_no = '$invoice_id'") as $net){
					extract($net);
					$_status;
					$tot_recv= $net['_paid_amount'];
					$tot_rcv = floatval($tot_recv);
					$tot_recve = number_format( (float) $tot_rcv, 2, '.', '');							
					$detail .='<tr>
								<td class="fee_col_left_bottom_summ" style="text-align: right;" ><p style=" font-size: 26px;"></p></td>
								<td class="fee_col_middle_bottom" style="text-align: right;" ><p style=" font-size: 26px;"><b>Total Received Amount&nbsp;</b></p></td>
								<td class="fee_col_right_bottom" style="text-align: right;"><p style=" font-size: 26px;"><b>'.$tot_recve.'&nbsp;</b></p></td>
							</tr>';       
				}
				foreach($obj->View_All_By_Cond(" _fee_master_invoice ","_br_id = '$br' AND _invoice_no = '$invoice_id'") as $net){
					extract($net);
					$_status;
					$recv= $net['_last_paid_amount'];
					$rcv = floatval($recv);
					$recve = number_format( (float) $rcv, 2, '.', '');
														
					$detail .='<tr>
								<td class="fee_col_left_bottom_summ" style="text-align: right;" ><p style=" font-size: 26px;"></p></td>
								<td class="fee_col_middle_bottom" style="text-align: right;" ><p style=" font-size: 26px;"><b>Last Received Amount&nbsp;</b></p></td>
								<td class="fee_col_right_bottom" style="text-align: right;"><p style=" font-size: 26px;"><b>'.$recve.'&nbsp;</b></p></td>
							</tr>'; 
				}
				foreach($obj->View_All_By_Cond(" _fee_master_invoice ","_br_id = '$br' AND _invoice_no = '$invoice_id'") as $net){
					extract($net);
					$_status;
					$a= $net['_due_amount'];
					$b = floatval($a);
					$nt = number_format( (float) $b, 2, '.', '');
		
					$detail .='<tr>
					    <td class="fee_col_left_summ" style="text-align: right;" ><p style=" font-size: 26px;"></p></td>
					    <td class="fee_col_middle" style="text-align: right;" ><p style=" font-size: 26px;"><b>Due&nbsp;</b></p></td>
					    <td class="fee_col_right" style="text-align: right;"><p style=" font-size: 26px;"><b>'.$nt.'&nbsp;</b></p></td>
					</tr>';
				}
	$detail .= '		</table>
					</td>
				</tr>
				<tr><td style="width: 100%; height: 20px;"><p style="font-size: 20px;">(In Words):&nbsp;<span style="border-bottom: 3px dotted;">'.numberTowords($tot_am).' Taka Only</span></p></td></tr>
				<tr><td style="width: 100%; height: 20px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td></tr>
				<tr><td style="width: 100%; height: 20px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td></tr>
				<!--<tr><td style="width: 100%; height: 20px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td></tr>-->
				<tr><td>
					<table style="width:100%;">
						<tr>
							<td  style="height: 20px; text-align: left; font-weight: bold;"><p style=" font-size: 20px;">_ _ _ _ _ _ _ _</p></td>
							<td style="height: 20px; text-align: right; font-weight: bold;"><p style=" font-size: 20px;">_ _ _ _ _ _ _ _</p></td>
						</tr>
						<tr>
							<td  style="height: 20px; text-align: left; font-weight: bold;"><p style=" font-size: 20px;">Depositor</p></td>
							<td style="height: 20px; text-align: right; font-weight: bold;"><p style=" font-size: 20px;">Received by F.Afrin</p></td>
						</tr>
						<tr>
							<td  style="height: 20px; text-align: left;"><p style=" font-size: 20px;">Printed By: <b>'.$_SESSION["LOGIN_USER"].'</b></p></td>
							<td style="height: 20px; text-align: right;"><p style=" font-size: 20px;">Print Date: <b>'.date(" d/m/Y").'</b></p></td>
						</tr>
				 </table>
				</td></tr>
			</table></td>';
	//2nd dotted line column		
	$detail .= '<td style=" width: 2%;border-right: 5px dotted black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>';
	//accounts copy column
	$detail .= '<td style="width: 32%;  padding-left:10px;">
					<table style="width:100%; margin-left:12px;">';
	//row holds accounts copy school info				
	$detail .= '		<tr>
							<td>
								<!--school info table -->
								<table style="width: 100%; margin-left:5px;">
									<tr style="width: 100%;">
										<td style="width: 100%; text-align: center;">
											<p style="font-size: 35px; text-align: center;"><b>'.$inst_name.'</b></p>
										</td>
									</tr>
									<tr style="width: 100%;">
										<td style="width: 100%; text-align: center; font-size: 20px;">
											<p><b>'.$ins_address.' <br>'.$inst_thanta.', '.$ins_district.'-'.$ins_zip_code.'</b></p>
											<p>'.$image.'</p>
										</td>
									</tr>
									<tr style="width: 100%;">
										<td style="width: 100%; text-align: center;">
											<p style=" font-size: 26px;"><b>Money Receipt (Student Copy)</b></p>
										</td>
									</tr>
								</table>
							</td>
						</tr>';				
	//row holds accounts copy student info
	$detail .= '		
						<tr>
							<td>
								<table style="width:100%; height:80px; border-collapse: collapse;" >
									<tr> 
										<td style="padding-left: 0px; width: 50%; height: 20px; text-align: left;"><p style=" font-size: 26px;">Payment Date : <b>'.$f_date.'</b></p></td>
										<td style="width: 50%; height: 20px; text-align: right;"><p style=" font-size: 26px;"><b>'.$show_inv_no.'</b></p></td>	
									</tr>
									<tr> 
										<!--<td colspan="2" style="width: 100%; height: 20px; text-align: left;"><p style=" font-size: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p></td>-->
										<td style="padding-left: 0px; width: 50%; height: 20px; text-align: left;"><p style=" font-size: 26px;">&nbsp;&nbsp;&nbsp;&nbsp;</p></td>
										<td style="width: 50%; height: 20px; text-align: right;"><p style=" font-size: 26px;"><b>'. $month_name.'-'.$value['_year'].'</b></p></td>	
									</tr>
									<tr> 
										<td colspan="2" style="width: 100%; height: 20px; text-align: left;"><p style=" font-size: 28px;">Name : <b>'.$std_name.'</b></p></td>	
									</tr>
									<tr> 
										<td style="width: 50%; height: 20px; text-align: left;"><p style=" font-size: 26px;">ID  : <b>'.$std_uid.'</b></p></td>
										<td style="padding-left: 0px; width: 50%; height: 20px; text-align: left;"><p style=" font-size: 26px;">Roll : <b>'.$std_roll.'</b></p></td>
									</tr>
									<tr> 
										<td style="width: 50%; height: 20px; text-align: left;"><p style=" font-size: 26px;">Class : <b>'.$std_class.'</b></p></td>
										<td style="padding-left: 0px; width: 50%; height: 20px; text-align: left;"><p style=" font-size: 26px;">Sec : <b>'. $std_sec.'</b></p></td>												
										<!--<td style="padding-left: 0px; width: 50%; height: 20px; text-align: left;"><p style=" font-size: 26px;">Dept : <b>'. $value['department'].'</b></p></td>-->												
									</tr>	
								</table>
							</td>
						</tr>
						<!--<tr><td style="width: 100%; height: 3px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td></tr>-->';
	//row holds accounts copy fee info
	$detail .= '		<tr>
							<td style="border-left: 1px solid;border-right: 1px solid;border-top: 1px solid;border-bottom: 1px solid;">
								<table style="width:100%; border-collapse: collapse;">
								<tr>
									<td class="fee_col_left_bottom" style="font-weight: bold; text-align: center;" ><p style=" font-size: 26px;">Sl</p></td>
									<td class="fee_col_middle_bottom" style="font-weight: bold; text-align: center;" ><p style=" font-size: 26px;">Description</p></td>
									<td class="fee_col_right_bottom" style="font-weight: bold; text-align: center;" ><p style=" font-size: 26px;">Amount</p></td>
								</tr>';				
						$in_account=0;
						foreach($obj->View_All_By_Cond(" _fee_details_invoice ","_br_id = '$br' AND _month = '$mnt'  AND _year = '$yr'  AND _std_id = '$std_id' AND _type='C' AND _invoice_no='$invoice_id'") as $tes){
							extract($tes);
							$in_account++;
							$a= $tes['_amount'];
							$b = floatval($a);
							$deb = number_format( (float) $b, 2, '.', '');				
							$detail .='<tr>
											<td class="fee_col_left" style="text-align: center;"><p style=" font-size: 26px;">'.$in_account.'</p></td>
											<td class="fee_col_middle" style="text-align: left;"><p style=" font-size: 26px;">&nbsp;&nbsp;'.$tes['_fee_head'].'</p></td>
											<td class="fee_col_right" style="text-align: right;"><p style=" font-size: 26px;">'.$deb.'&nbsp;&nbsp;</p></td>
										</tr>';
						}
						foreach($obj->View_All_By_Cond(" _fee_details_invoice ","_br_id = '$br' AND _month = '$mnt'  AND _year = '$yr'  AND _std_id = '$std_id' AND _type='D' AND _invoice_no='$invoice_id'") as $tes1){
							extract($tes1);	
							$in_account++;
							$a= $tes1['_amount'];
							$b = floatval($a);
							$cr = number_format( (float) $b, 2, '.', '');					
							$detail .='<tr>
											<td class="fee_col_left" style="text-align: center;"><p style=" font-size: 26px;">'.$in_account.'</p></td>
											<td class="fee_col_middle" style="text-align: left;"><p style=" font-size: 26px;">&nbsp;&nbsp;'.$tes1['_fee_head'].'</p></td>
											<td class="fee_col_right" style="text-align: right;"><p style=" font-size: 26px;">(-)'.$cr.'&nbsp;&nbsp;</p></td>
										</tr>';
						}
						if($net['_status']=='PR'){
							foreach($obj->View_All_By_Cond(" _fee_partial_pay_table  ","_invoice = '$invoice_id' ") as $par){
								extract($par);
								$in_account++;
								$par_date = date('d-m-Y',strtotime($par['_entry_date']));
								$a = floatval($par['_par_amount']);
								$par_amount = number_format( (float) $a, 2, '.', '');
								$detail .='<tr>
											<td class="fee_col_left" style="text-align: center;"><p style=" font-size: 26px;">'.$in_account.'</p></td>
											<td class="fee_col_middle" style="text-align: left;"><p style=" font-size: 26px;">&nbsp;&nbsp;Partial Payment&nbsp;('.$par_date.')</p></td>
											<td class="fee_col_right" style="text-align: right;"><p style=" font-size: 26px;">(-)'.$par_amount.'&nbsp;&nbsp;</p></td></tr>';
							}
						}
						
						for($i=$in_account+1; $i<=$num_of_empty_row; $i++){
							if($i==($num_of_empty_row-2) && $status_flag!='U'){
								$detail .= '<tr>
											<td class="fee_col_left" style="text-align: center;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
											<td class="fee_col_middle" style="text-align: center; padding-right: 30px;">'.$imi.'</td>
											<td class="fee_col_right" style="text-align: center;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
										</tr>';
							}
							else{
								$detail .= '<tr>
											<td class="fee_col_left" style="text-align: center;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
											<td class="fee_col_middle" style="text-align: center;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
											<td class="fee_col_right" style="text-align: center;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
										</tr>';
							}		
						}
						if(($in_account==$num_of_empty_row || $in_account==($num_of_empty_row-2) || $in_account==($num_of_empty_row-1)) && $status_flag!='U'){
							$detail .= '<tr>
										<td class="fee_col_left" style="text-align: center;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
										<td class="fee_col_middle" style="text-align: center; padding-right: 30px;">'.$imi.'</td>
										<td class="fee_col_right" style="text-align: center;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
								</tr>';
						}
	//row holds accounts fee summary info
	foreach($obj->View_All_By_Cond(" _fee_master_invoice ","_br_id = '$br' AND _invoice_no = '$invoice_id'") as $val){
					extract($val);
					//$a= $val['_cr_amount'];
					$tot_amount= $val['_total_amount'];
					$tot_amount = floatval($tot_amount);
					//$cr_am = number_format( (float) $b, 2, '.', '');
									
					//$c= $val['_dr_amount'];
					//$d = floatval($c);
					//$dr_am = number_format( (float) $d, 2, '.', '');
					$tot_am = number_format( (float)($tot_amount), 2, '.', '');
					
					$detail .='<tr>
								<td class="fee_col_left_top_summ" style="text-align: right;"><p style=" font-size: 26px;"></p></td>
								<td class="fee_col_middle_top" style="text-align: right;"><p style=" font-size: 26px;"><b>Total Payable Amount&nbsp;</b></p></td>
								<td class="fee_col_right_top" style="text-align: right;"><p style=" font-size: 26px;"><b>'.$tot_am.'&nbsp;</b></p></td>
							</tr>';
				}
				foreach($obj->View_All_By_Cond(" _fee_master_invoice ","_br_id = '$br' AND _invoice_no = '$invoice_id'") as $net){
					extract($net);
					$_status;
					$discount_amt= $net['_discount'];
					$discount_amt = floatval($discount_amt);
					$discount_amt = number_format( (float) $discount_amt, 2, '.', '');
														
					$detail .='<tr>
								<td class="fee_col_left_bottom_summ" style="text-align: right;" ><p style=" font-size: 26px;"></p></td>
								<td class="fee_col_middle_bottom" style="text-align: right;" ><p style=" font-size: 26px;"><b>Discount&nbsp;</b></p></td>
								<td class="fee_col_right_bottom" style="text-align: right;"><p style=" font-size: 26px;"><b>'.$discount_amt.'&nbsp;</b></p></td>
							</tr>';      
				}
				foreach($obj->View_All_By_Cond(" _fee_master_invoice ","_br_id = '$br' AND _invoice_no = '$invoice_id'") as $net){
					extract($net);
					$_status;
					$tot_recv= $net['_paid_amount'];
					$tot_rcv = floatval($tot_recv);
					$tot_recve = number_format( (float) $tot_rcv, 2, '.', '');							
					$detail .='<tr>
								<td class="fee_col_left_bottom_summ" style="text-align: right;" ><p style=" font-size: 26px;"></p></td>
								<td class="fee_col_middle_bottom" style="text-align: right;" ><p style=" font-size: 26px;"><b>Total Received Amount&nbsp;</b></p></td>
								<td class="fee_col_right_bottom" style="text-align: right;"><p style=" font-size: 26px;"><b>'.$tot_recve.'&nbsp;</b></p></td>
							</tr>';            
				}
				foreach($obj->View_All_By_Cond(" _fee_master_invoice ","_br_id = '$br' AND _invoice_no = '$invoice_id'") as $net){
					extract($net);
					$_status;
					$recv= $net['_last_paid_amount'];
					$rcv = floatval($recv);
					$recve = number_format( (float) $rcv, 2, '.', '');							
					$detail .='<tr>
								<td class="fee_col_left_bottom_summ" style="text-align: right;" ><p style=" font-size: 26px;"></p></td>
								<td class="fee_col_middle_bottom" style="text-align: right;" ><p style=" font-size: 26px;"><b>Last Received Amount&nbsp;</b></p></td>
								<td class="fee_col_right_bottom" style="text-align: right;"><p style=" font-size: 26px;"><b>'.$recve.'&nbsp;</b></p></td>
							</tr>';
				}
				foreach($obj->View_All_By_Cond(" _fee_master_invoice ","_br_id = '$br' AND _invoice_no = '$invoice_id'") as $net){
					extract($net);
					$_status;
					$a= $net['_due_amount'];
					$b = floatval($a);
					$nt = number_format( (float) $b, 2, '.', '');
		
					$detail .='<tr>
					    <td class="fee_col_left_summ" style="text-align: right;" ><p style=" font-size: 26px;"></p></td>
					    <td class="fee_col_middle" style="text-align: right;" ><p style=" font-size: 26px;"><b>Due&nbsp;</b></p></td>
					    <td class="fee_col_right" style="text-align: right;"><p style=" font-size: 26px;"><b>'.$nt.'&nbsp;</b></p></td>
					</tr>';
				}
	$detail .= '		</table>
					</td>
				</tr>
				<tr><td style="width: 100%; height: 20px;"><p style="font-size: 20px;">(In Words):&nbsp;<span style="border-bottom: 3px dotted;">'.numberTowords($tot_am).' Taka Only</span></p></td></tr>
				<tr><td style="width: 100%; height: 20px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td></tr>
				<tr><td style="width: 100%; height: 20px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td></tr>
				<!--<tr><td style="width: 100%; height: 20px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td></tr>-->
				<tr><td>
					<table style="width:100%;">
						<tr>
							<td  style="height: 20px; text-align: left; font-weight: bold;"><p style=" font-size: 20px;">_ _ _ _ _ _ _ _</p></td>
							<td style="height: 20px; text-align: right; font-weight: bold;"><p style=" font-size: 20px;">_ _ _ _ _ _ _ _</p></td>
						</tr>
						<tr>
							<td style="height: 20px; text-align: left; font-weight: bold;"><p style=" font-size: 20px;">Depositor</p></td>
							<td style="height: 20px; text-align: right; font-weight: bold;"><p style=" font-size: 20px;">Received by F.Afrin</p></td>
						</tr>
						<tr>
							<td style="height: 20px; text-align: left;"><p style=" font-size: 20px;">Printed By: <b>'.$_SESSION["LOGIN_USER"].'</b></p></td>
							<td style="height: 20px; text-align: right;"><p style=" font-size: 20px;">Print Date: <b>'.date(" d/m/Y").'</b></p></td>
						</tr>
				 </table>
				</td></tr>
			</table></td>';
	//main table ends here
	$detail .= '</tr></table>';
}
$detail.='</body></html>';
//echo $detail;
$foothtml='<table width="100%">
			<tr>
				<td style="width: 32%; padding-right:10px;">
					<table style="width:100%; margin-right:12px;">
					<tr>
						<td style="text-align:left;font-size:10px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
						<td style="text-align:right;font-size:10px;">Powered By: www.'.$_SESSION["powred"].'</td>
					</tr>
					</table>
				</td>
				<td style=" width: 2%;"></td>
				<td style="width: 32%;">
					<table style="width:100%;">
						<tr>
							<td style="text-align:left;font-size:10px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
							<td style="text-align:right;font-size:10px;">Powered By: www.'.$_SESSION["powred"].'</td>
						</tr>
					</table>
				</td>
				<td style=" width: 2%;"></td>
				<td style="width: 32%;  padding-left:10px;">
					<table style="width:100%; margin-left:12px;">
					<tr>
						<td style="text-align:left;font-size:10px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
						<td style="text-align:right;font-size:10px;">Powered By: www.'.$_SESSION["powred"].'</td>
					</tr>
					</table>
				</td>
			</tr>	
			</table>
			';
//echo $detail;
//exit;
$mpdf=new mPDF('c','A4-L','','' , 0 , 0 , 0 ,0, 0 , 0); 
//$mpdf=new mPDF('utf-8','A4','L');
//$mpdf = new mPDF('utf-8', 'A4', '', '', 0, 0, 0, 0, 0, 0, 'L');
$mpdf->SetDisplayMode('fullpage');
$mpdf->setFooter($foothtml);
$mpdf->WriteHTML($detail);
$mpdf->Output();
?>