<?php
session_start();
// ============
include("../../asset/theme/css/myfunc.php");
include("../../php_crud/my_class.php");
//include("test_page.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_web = $brans_obj->_web_address !='' ? $brans_obj->_web_address : '' ;
	$ins_email = $brans_obj->_email_add !='' ? '|| '.$brans_obj->_email_add : '' ;
	
}

 
// if($ins_logo !=''){
// 				  $image = '<img src="../../'.$ins_logo.'" style="top:20px;height:150px; float:left;margin-left: -12px;" title="logo" alt="" id="image" />';
// 				/*  $image1 = ../../../../.$ins_logo.; */
// 				 }


$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');
//require_once('test_page.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 ;
	 protected $pimage ;
	
	 public $size ;
	 public $type_id ;
	 public function setImagesrc($sr) {
		 $this->image1 = $sr;
		 
	 
	 }
	 public function setphoto($pd) {
		 //$this->pimage ='';
		 $this->pimage = $pd;
		 
	 
	 }
	 // public $isLastPage = false;
	
	public function Header() {
    	
	
	
	
	
	
    $this->SetAlpha(2);
	
       $this->Image($this->pimage, 40, 130, 40, 40, '', '', '', true, 50);
       $this->Image($this->pimage, 135, 130, 40, 40, '', '', '', true, 50);
       $this->Image($this->pimage, 230, 130, 40, 40, '', '', '', true, 50);
	   //$this->SetAlpha(1);     
	$this->SetAlpha(0.09);
	
	$this->Image($this->image1, 25, 75, 40, 60, '', '', '', true, 50);
	$this->Image($this->image1, 115, 75, 40, 60, '', '', '', true, 50);
	$this->Image($this->image1, 215, 75, 40, 60, '', '', '', true, 50);
	//$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(6, 200, 290, 200);
		
		//$this->Line(25, 90, 205, 290);
		
		$this->SetY(-10);
		$this->SetX(9);
		$by = 'printed:'.$_SESSION["LOGIN_USER"].'('.date(" d/m/Y H\hi:s").')';
        $this->SetFont('helvetica', 'N', 6);
        $this->Cell(0, 5,$by, 0, false, '', 0, '', 0, false, 'T', 'M');
		
		
		
        $this->SetY(-5);
		$this->SetX(25);
        $this->SetFont('helvetica', 'N', 10);
		$a = 'Powered By: '.$_SESSION["powred"];
        $this->Cell(0, 5, $a, 0, false, 'L', 0, '', 0, false, 'T', 'M');
		
		//////
		$this->SetY(-10);
		$this->SetX(105);
		$by = 'printed:'.$_SESSION["LOGIN_USER"].'('.date(" d/m/Y H\hi:s").')';
        $this->SetFont('helvetica', 'N', 6);
        $this->Cell(0, 5,$by, 0, false, '', 0, '', 0, false, 'T', 'M');
		
		
		
        $this->SetY(-5);
		$this->SetX(125);
        $this->SetFont('helvetica', 'N', 10);
		$a = 'Powered By: '.$_SESSION["powred"];
        $this->Cell(0, 5, $a, 0, false, 'L', 0, '', 0, false, 'T', 'M');
		
		/////
		
		$this->SetY(-10);
		$this->SetX(199);
		$by = 'printed:'.$_SESSION["LOGIN_USER"].'('.date(" d/m/Y H\hi:s").')';
        $this->SetFont('helvetica', 'N', 6);
        $this->Cell(0, 5,$by, 0, false, '', 0, '', 0, false, 'T', 'M');
		
		
		
        $this->SetY(-5);
		$this->SetX(220);
        $this->SetFont('helvetica', 'N', 10);
		$a = 'Powered By: '.$_SESSION["powred"];
        $this->Cell(0, 5, $a, 0, false, 'L', 0, '', 0, false, 'T', 'M');
		
		
		
    // Set font
   
/* 	 if($this->isLastPage)
{ */	
$style3 = array('width' => 0.4, 'cap' => 'round', 'join' => 'round', 'dash' => '1,1', 'color' => black);

$this->Line(8, 193, 28, 193, $style3);
$this->Line(78, 193, 96, 193, $style3);
$this->Line(104, 193, 124, 193, $style3);
$this->Line(173, 193, 191, 193, $style3);
$this->Line(202, 193, 222, 193, $style3);
$this->Line(270, 193, 288, 193, $style3);
$this->Text(10, 195, 'Depositor');
$this->Text(80, 195, 'receiver');
$this->Text(106, 195, 'Depositor');
$this->Text(175, 195, 'receiver');
$this->Text(204, 195, 'Depositor');
$this->Text(272, 195, 'receiver');
//}
	
		
    }
	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);
}

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


/* $empid;
$data_list_personal_info=$obj->Details_By_Cond('_pf_emp_personal_info',"_id='".$empid."'");
 */
//$image = '$data_list_personal_info['_image_location']';

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



/* $width = $pdf->pixelsToUnits(800); 
$height = $pdf->pixelsToUnits(1500);

$resolution= array($width, $height);
$pdf->AddPage('L', $resolution); */

// 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'];

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;
                 $paid_date = $obj->Details_By_Cond("_fee_total_receive","_invoice_no='".$net['_invoice_no']."'"); 
				   					
				if(!empty($paid_date['_entry_date']))
					{ 
						if($paid_date['_entry_date']=='0000-00-00')
						{$f_date = '';}
						 else { 
						 $f_date = date('d/m/Y',strtotime($paid_date['_entry_date'])); 
						 //$f_date =$paid_date['_entry_date'];
						 }
					 }		
				$imi ='';	
          //$imi ='stamp_paid.png';
            //$pdf->setphoto($imi);		  
				if($_status=='P')
				   {
					 $imi ='invoice_report/stamp_paid.png'; 
					//$imi .='stamp_paid.png';
					//$pdf->setphoto($x);
					
				   }
				    $pdf->setphoto($imi);
				   if($_status=='AD')
				   {
					 $imi ='invoice_report/ADJUSTMENT-1.png'; 
					//$imi .='stamp_paid.png';
					//$pdf->setphoto($x);
					
				   }
				  $pdf->setphoto($imi);
               
				 }



	

	$mnt='';
if($value['_month']==1)
{
	$mnt.='january';
}
elseif($value['_month']==2)
{
	$mnt.='February';
}
elseif($value['_month']==3)
{
	$mnt.='march';
}
elseif($value['_month']==4)
{
	$mnt.='April';
}	
elseif($value['_month']==5)
{
	$mnt.='May';
}	
elseif($value['_month']==6)
{
	$mnt.='June';
}	
elseif($value['_month']==7)
{
	$mnt.='July';
}	
elseif($value['_month']==8)
{
	$mnt.='August';
}	
elseif($value['_month']==9)
{
	$mnt.='September';
}	
elseif($value['_month']==10)
{
	$mnt.='October';
}	
elseif($value['_month']==11)
{
	$mnt.='November';
}	
elseif($value['_month']==12)
{
	$mnt.='December';
}	

	
	
	
	
	/////
	
	$pdf->AddPage(L);	


	

	
$pdf->SetFont('helvetica', '', 8);


// define barcode style
$style = array(
    'position' => '',
    'align' => 'C',
    'stretch' => false,
    'fitwidth' => true,
    'cellfitalign' => '',
    'border' => true,
    'hpadding' => 'auto',
    'vpadding' => 'auto',
    'fgcolor' => array(0,0,0),
    'bgcolor' => false, //array(255,255,255),
    'text' => true,
    'font' => 'helvetica',
    'fontsize' => 6,
    'stretchtext' => 4
);	
$pdf->SetFont('helvetica', '', 10);
// CODE 39 + CHECKSUM
//$pdf->Cell(0, 0, 'CODE 39 + CHECKSUM', 0, 1);
//$barcode = $pdf->write1DBarcode('CODE 39 +', 'C39+', '', '', '', 10, 0.2, $style, 'N');
$params = $pdf->serializeTCPDFtagParameters(array($value['_invoice_no'], 'C39', '', '', 29, 8, 0.4, array('position'=>'S', 'border'=>false, 'padding'=>0, 'fgcolor'=>array(0,0,0), 'bgcolor'=>array(255,255,255), 'text'=>true, 'font'=>'helvetica', 'fontsize'=>5, 'stretchtext'=>4), 'N'));    

//$pdf->Ln();	
//$inv = 
	$test = '';
	$test1 = '';
	$test2 = '';
	$detail = '';
	$br = '<br/>';

/* =============================== */
	include("test_page.php");
	
/* =============================== */	
	

//$pdf->Ln(20);	
//$pdf->writeHTML($proc, true, true, false, false, '');
//$pdf->writeHTML($hp, true, true, false, false, '');
$pdf->SetFont('helvetica', '', 10);
 $style2 = array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => 2, 'color' => array(0, 0, 0));
 $pdf->Line(101, 10, 101, 190, $style2);
 $pdf->Line(195, 10, 195, 190, $style2);


$style = array('width' => 0.1, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0));

$pdf->Line(53.5, 75.4, 53.5, 170.4, $style); 
$pdf->Line(73.7, 75.4, 73.7, 170.4, $style); 
$pdf->Line(147.5, 75.4, 147.5, 170.4, $style); 
$pdf->Line(167.55, 75.4, 167.55, 170.4, $style); 
$pdf->Line(243.2, 75.4, 243.2,170.4, $style); 
$pdf->Line(263, 75.4, 263, 170.4, $style); 
 //$pdf->Line(40, 10, 40, 200);
/* if($month==$value['_month'])
{ */	
	

$detail .= '<table style="width: 100%;">';


$detail .= '<tr>
        <td style=" width: 33%;">
		        <table border="1" >
					';
					$detail .= '<tr> 
							 <td  style="width:90%;height:13px;font-size:10px;text-align:center;"><b>Name : </b>'.$value['_full_name'].' </td>	
							 	
						</tr>

					    <tr >
						<td  style="width:45%;height:13px;font-size:10px;text-align:center;"><b>Shift : </b>'.$value['shift'].' </td>
						<td style="width:45%;height:13px;font-size:10px;text-align:center;"><b>Medium : </b>'.$value['medium'].'</td>
						</tr>
						<tr> 
							<td style="width:45%;height:13px;font-size:10px;text-align:center;"><b>Class : </b>'.$value['class'].'    </td>
							
						    <td style="width:45%;height:13px;font-size:10px;text-align:center;"><b>Dept : </b>'. $value['department'].'   </td>												
						</tr>
						<tr> 
							<td style="width:45%;height:13px;font-size:10px;text-align:center;"><b>Student Type : </b>'.$value['student_type'].'   </td>
							<td style="width:45%;height:13px;font-size:10px;text-align:center;"><b>Section : </b>'.$value['section'].'  </td>
						
						</tr>
						<tr>								
						    
						    <td style="width:45%;height:13px;font-size:10px;text-align:center;"><b>Session  :</b> '.$value['_year'].'</td>
						    <td style="width:45%;height:13px;font-size:10px;text-align:center;"><b>Student ID  :</b> '.$value['_uniq_id'].'</td>
						</tr>
						
						<tr>				
							<td  style="width:45%;height:13px;font-size:10px;text-align:center;"><b>Section Roll : </b>'.$value['_section_roll'].' </td>	
							<td style="width:45%;height:13px;font-size:10px;text-align:center;"><b>Month  : </b> '. $mnt.' </td>
						</tr>
						<tr> 
							<td style="width:90%;height:13px;font-size:10px;text-align:center;"><b>Received Date : </b>'.$f_date.'   </td>
						</tr>	
										
						
					
				  </table>
		
	
		
		</td>
		<td style=" width: 1.5%;">
		</td>
		
		<td style=" width: 33%;">
		
		<table border="1" >
					';
					$detail .= '<tr> 
							 <td  style="width:90%;height:13px;font-size:10px;text-align:center;"><b>Name : </b>'.$value['_full_name'].' </td>	
							 	
						</tr>

					    <tr >
						<td  style="width:45%;height:13px;font-size:10px;text-align:center;"><b>Shift : </b>'.$value['shift'].' </td>
						<td style="width:45%;height:13px;font-size:10px;text-align:center;"><b>Medium : </b>'.$value['medium'].'</td>
						</tr>
						<tr> 
							<td style="width:45%;height:13px;font-size:10px;text-align:center;"><b>Class : </b>'.$value['class'].'    </td>
							
						    <td style="width:45%;height:13px;font-size:10px;text-align:center;"><b>Dept : </b>'. $value['department'].'   </td>												
						</tr>
						<tr> 
							<td style="width:45%;height:13px;font-size:10px;text-align:center;"><b>Student Type : </b>'.$value['student_type'].'   </td>
							<td style="width:45%;height:13px;font-size:10px;text-align:center;"><b>Section : </b>'.$value['section'].'  </td>
						
						</tr>
						<tr>								
						    
						    <td style="width:45%;height:13px;font-size:10px;text-align:center;"><b>Session  :</b> '.$value['_year'].'</td>
						    <td style="width:45%;height:13px;font-size:10px;text-align:center;"><b>Student ID  :</b> '.$value['_uniq_id'].'</td>
						</tr>
						
						<tr>				
							<td  style="width:45%;height:13px;font-size:10px;text-align:center;"><b>Section Roll : </b>'.$value['_section_roll'].' </td>	
							<td style="width:45%;height:13px;font-size:10px;text-align:center;"><b>Month  : </b> '. $mnt.' </td>
						</tr>
						<tr> 
							<td style="width:90%;height:13px;font-size:10px;text-align:center;"><b>Received Date : </b>'.$f_date.'   </td>
						</tr>	
										
						
					
				  </table>

		
		</td>
		<td style=" width: 1%;">
		</td>
		<td style=" width: 33%;">
		       <table border="1" >
					';
					$detail .= '<tr> 
							 <td  style="width:90%;height:13px;font-size:10px;text-align:center;"><b>Name : </b>'.$value['_full_name'].' </td>	
							 	
						</tr>

					    <tr >
						<td  style="width:45%;height:13px;font-size:10px;text-align:center;"><b>Shift : </b>'.$value['shift'].' </td>
						<td style="width:45%;height:13px;font-size:10px;text-align:center;"><b>Medium : </b>'.$value['medium'].'</td>
						</tr>
						<tr> 
							<td style="width:45%;height:13px;font-size:10px;text-align:center;"><b>Class : </b>'.$value['class'].'    </td>
							
						    <td style="width:45%;height:13px;font-size:10px;text-align:center;"><b>Dept : </b>'. $value['department'].'   </td>												
						</tr>
						<tr> 
							<td style="width:45%;height:13px;font-size:10px;text-align:center;"><b>Student Type : </b>'.$value['student_type'].'   </td>
							<td style="width:45%;height:13px;font-size:10px;text-align:center;"><b>Section : </b>'.$value['section'].'  </td>
						
						</tr>
						<tr>								
						    
						    <td style="width:45%;height:13px;font-size:10px;text-align:center;"><b>Session  :</b> '.$value['_year'].'</td>
						    <td style="width:45%;height:13px;font-size:10px;text-align:center;"><b>Student ID  :</b> '.$value['_uniq_id'].'</td>
						</tr>
						
						<tr>				
							<td style="width:45%;height:13px;font-size:10px;text-align:center;"><b>Section Roll : </b>'.$value['_section_roll'].' </td>	
							<td style="width:45%;height:13px;font-size:10px;text-align:center;"><b>Month  : </b> '. $mnt.' </td>
						</tr>
						<tr> 
							<td style="width:90%;height:13px;font-size:10px;text-align:center;"><b>Received Date : </b>'.$f_date.'   </td>
						</tr>					
						
					
				  </table>

		
		
		</td>
        </tr>';

$detail .= '</table>';



$pdf->writeHTML($detail, true, true, false, false, '');
$pdf->Ln(2);

$std_id = $value['_std_id'];
$sc_id = $value['section_id'];
$mnt = $value['_month'];
$br = $value['branch_id'];


$yr = $value['_year'];
/////////

/* $imageing = $obj->Details_By_Cond("_fee_master_invoice","_br_id = '$br' AND _section_id = '$sc_id' AND _month = '$mnt'  AND _year = '$yr'  AND _std_id = '$std_id'");
  $imi ='';           
if($imageing['_status']=='P')
				   {
					  
					   $imi ='stamp_paid.png';
					   
					
				   }

 $pdf->setphoto($imi); */
/////

//}
$account_debid = '<table style="width: 100%; ">';//grand-grand


$account_debid .= '<tr><td style="width: 31%; ">';//grand-father
$account_debid .= '<table style="width: 100%; " border="1">';//father
$account_debid .= '<tr>

<td style="height:330px;" > ';
 $account_debid .='<table style="" >';//child
			    $account_debid .='<tr><td style="width:50%;height:8px;font-size:12px;border-bottom: 1px solid black;text-align:center;border-bottom: 1px solid black;" >Description</td>
				<td style="width:25%;height:8px;font-size:12px;border-bottom: 1px solid black;text-align:center;" >Amount</td>
				<td style="width:25%;height:8px;font-size:12px;border-bottom: 1px solid black;text-align:center;" >Discount</td>
				</tr>';
				 
			    foreach($obj->View_All_By_Cond(" _fee_details_invoice ","_br_id = '$br' AND _section_id = '$sc_id' AND _month = '$mnt'  AND _year = '$yr'  AND _std_id = '$std_id' AND _type='C' AND _invoice_no='$invoice_id'") as $tes){
				extract($tes);
                
                $a= $tes['_amount'];
				$b = floatval($a);
                $deb = number_format( (float) $b, 2, '.', '');				
				$account_debid .='<tr>
						<td style="width: 50%;font-size:12px;height:8px;">
						'.$tes['_fee_head'].'</td>
						<td style="width: 25%;font-size:12px;height:13px;text-align:right;">'.$deb .' </td>
						<td style="width: 25%;font-size:12px;height:8px;"></td></tr>';
					 
				 }
				 
				  foreach($obj->View_All_By_Cond(" _fee_details_invoice ","_br_id = '$br' AND _section_id = '$sc_id' AND _month = '$mnt'  AND _year = '$yr'  AND _std_id = '$std_id' AND _type='D' AND _invoice_no='$invoice_id'") as $tes1){
					extract($tes1);	
                         $a= $tes1['_amount'];
				        $b = floatval($a);
                        $cr = number_format( (float) $b, 2, '.', '');					
					$account_debid .='<tr>
					                  <td style="width: 50%;font-size:12px;height:8px;">'.$tes1['_fee_head'].'</td>
					                  <td style="width: 25%;font-size:12px;height:8px;"></td>
									  <td style="width: 25%;font-size:12px;height:13px;text-align:right;">'.$cr.'</td>
									  </tr>';
					 
				 }
				 
				 
				 
				 
				 
				 
                //$account .='<tr ><td style=""></td></tr>';			
			   /*  foreach($obj->total_cr_db($br ,$sc_id,$mnt,$yr,$std_id) as $val){
				extract($val);
				       $account_debid .='<tr>
										   <td style="width: 50%;font-size:10px;border-right: 1px solid black;text-align:center;">total</td>
										   <td style="width: 20%;font-size:10px;text-align:center;border-top: 1px solid black;border-left: 1px solid black;">'.$val['_cr_amount'].'</td>
										   <td style="width: 20%;font-size:10px;text-align:center;border-top: 1px solid black;border-left: 1px solid black;">'.$val['_dr_amount'].'</td>
										   </tr>';
				}
				 */
				/* 
				 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'") as $net){
					extract($net);	 
					$account_debid .='<tr>
					                  <td style="width: 50%;font-size:10px;height:8px;border-top: 1px solid black;border-right: 1px solid black;" >net payable</td>
					                  
									  <td style="width: 40%;font-size:10px;height:13px;border-top: 1px solid black;text-align:center;" colspan="3">'.$net['_amount'].'</td>
									  </tr>';
					 
				 } */
			$account_debid .= '</table>';   



$account_debid .= '</td>

</tr>';

//$account_debid .= '</table>';
//$account_debid .= '</td></tr>';
$account_debid .= '<tr>

<td style=""> ';
$account_debid .='<table style="" >';
foreach($obj->total_cr_db($br ,$sc_id,$mnt,$yr,$std_id,$invoice_id) as $val){
				extract($val);
				$a= $val['_cr_amount'];
				        $b = floatval($a);
                        $cr_am = number_format( (float) $b, 2, '.', '');
						
						$c= $val['_dr_amount'];
				        $d = floatval($c);
                        $dr_am = number_format( (float) $d, 2, '.', '');
				       $account_debid .='<tr>
										   <td style="width: 50%;font-size:12px;border-right: 1px solid black;text-align:center;">Total</td>
										   <td style="width: 25%;font-size:12px;text-align:right;border-top: 1px solid black;border-left: 1px solid black;">'.$cr_am.'</td>
										   <td style="width: 25%;font-size:12px;text-align:right;border-top: 1px solid black;border-left: 1px solid black;">'.$dr_am.'</td>
										   </tr>';
				}


$account_debid .= '</table>';
$account_debid .= '</td></tr>';

$account_debid .= '<tr>

<td style=""> ';
$account_debid .='<table style="" >';
          

foreach($obj->View_All_By_Cond(" _fee_master_invoice ","_br_id = '$br' AND _invoice_no = '$invoice_id'") as $net){
					extract($net);
					$_status;
                    $recv= $net['_paid_amount'];
				        $rcv = floatval($recv);
                        $recve = number_format( (float) $rcv, 2, '.', '');
											
					$account_debid .='<tr>
					                  <td style="width: 50%;font-size:12px;height:8px;border-top: 1px solid black;border-right: 1px solid black;" >Receive Amount</td>
					                  
									  <td style="width: 50%;font-size:12px;height:13px;border-top: 1px solid black;text-align:Right;" colspan="2">'.$recve.'</td>
									  </tr>';
				//$imi ='';	
          //$imi ='stamp_paid.png';
            //$pdf->setphoto($imi);		  
				//if($_status=='P')
				  // {
					// $imi ='stamp_paid.png'; 
					//$imi .='stamp_paid.png';
					//$pdf->setphoto($x);
					
				   //}
				 // $pdf->setphoto($imi);
               
				 }
 //$pdf->setphoto($imi);

$account_debid .= '</table>';
$account_debid .= '</td></tr>';



$account_debid .= '<tr>

<td style=""> ';
$account_debid .='<table style="" >';
          

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, '.', '');
											
					$account_debid .='<tr>
					                  <td style="width: 50%;font-size:12px;height:8px;border-top: 1px solid black;border-right: 1px solid black;" >Net Payable</td>
					                  
									  <td style="width: 50%;font-size:12px;height:13px;border-top: 1px solid black;text-align:Right;" colspan="2">'.$nt.'</td>
									  </tr>';
				//$imi ='';	
          //$imi ='stamp_paid.png';
            //$pdf->setphoto($imi);		  
				//if($_status=='P')
				  // {
					// $imi ='stamp_paid.png'; 
					//$imi .='stamp_paid.png';
					//$pdf->setphoto($x);
					
				   //}
				 // $pdf->setphoto($imi);
               
				 }
 //$pdf->setphoto($imi);

$account_debid .= '</table>';
$account_debid .= '</td></tr>';





$account_debid .= '</table>';//grand-father
$account_debid .= '</td>';


//----------------------------------------------------------
$account_debid .= '<td style="width: 2.8%; "> ';
$account_debid .= '</td> ';
//----------------------------------------------------------
$account_debid .= '<td style="width: 31%; "> ';
$account_debid .= '<table style="width: 100%; " border="1">';
$account_debid .= '<tr>

<td style="height:330px"> ';
 $account_debid .='<table style="" >';//child
			    $account_debid .='<tr><td style="width:50%;height:8px;font-size:12px;border-bottom: 1px solid black;text-align:center;" >Description</td>
				<td style="width:25%;height:8px;font-size:12px;border-bottom: 1px solid black;text-align:center;" >Amount</td>
				<td style="width:25%;height:8px;font-size:12px;border-bottom: 1px solid black;text-align:center;" >Discount</td>
				</tr>';
				 
			    foreach($obj->View_All_By_Cond(" _fee_details_invoice ","_br_id = '$br' AND _section_id = '$sc_id' AND _month = '$mnt'  AND _year = '$yr'  AND _std_id = '$std_id' AND _type='C'  AND _invoice_no='$invoice_id'") as $tes){
				extract($tes);
                
                $a= $tes['_amount'];
				$b = floatval($a);
                $deb = number_format( (float) $b, 2, '.', '');				
				$account_debid .='<tr>
						<td style="width: 50%;font-size:12px;height:8px;">
						'.$tes['_fee_head'].'</td>
						<td style="width: 25%;font-size:12px;height:13px;text-align:right;">'.$deb .' </td>
						<td style="width: 25%;font-size:12px;height:8px;"></td></tr>';
					 
				 }
				 
				  foreach($obj->View_All_By_Cond(" _fee_details_invoice ","_br_id = '$br' AND _section_id = '$sc_id' AND _month = '$mnt'  AND _year = '$yr'  AND _std_id = '$std_id' AND _type='D'  AND _invoice_no='$invoice_id'") as $tes1){
					extract($tes1);	
                         $a= $tes1['_amount'];
				        $b = floatval($a);
                        $cr = number_format( (float) $b, 2, '.', '');					
					$account_debid .='<tr>
					                  <td style="width: 50%;font-size:12px;height:8px;">'.$tes1['_fee_head'].'</td>
					                  <td style="width: 25%;font-size:12px;height:8px;"></td>
									  <td style="width: 25%;font-size:12px;height:13px;text-align:right;">'.$cr.'</td>
									  </tr>';
					 
				 }
				 
				 
				 
				 
				 
				 
                //$account .='<tr ><td style=""></td></tr>';			
			   /*  foreach($obj->total_cr_db($br ,$sc_id,$mnt,$yr,$std_id) as $val){
				extract($val);
				       $account_debid .='<tr>
										   <td style="width: 50%;font-size:10px;border-right: 1px solid black;text-align:center;">total</td>
										   <td style="width: 20%;font-size:10px;text-align:center;border-top: 1px solid black;border-left: 1px solid black;">'.$val['_cr_amount'].'</td>
										   <td style="width: 20%;font-size:10px;text-align:center;border-top: 1px solid black;border-left: 1px solid black;">'.$val['_dr_amount'].'</td>
										   </tr>';
				}
				 */
				/* 
				 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'") as $net){
					extract($net);	 
					$account_debid .='<tr>
					                  <td style="width: 50%;font-size:10px;height:8px;border-top: 1px solid black;border-right: 1px solid black;" >net payable</td>
					                  
									  <td style="width: 40%;font-size:10px;height:13px;border-top: 1px solid black;text-align:center;" colspan="3">'.$net['_amount'].'</td>
									  </tr>';
					 
				 } */
			$account_debid .= '</table>';   



$account_debid .= '</td>

</tr>';

//$account_debid .= '</table>';
//$account_debid .= '</td></tr>';
$account_debid .= '<tr>

<td style=""> ';
$account_debid .='<table style="" >';
foreach($obj->total_cr_db($br ,$sc_id,$mnt,$yr,$std_id,$invoice_id) as $val){
				extract($val);
				$a= $val['_cr_amount'];
				        $b = floatval($a);
                        $cr_am = number_format( (float) $b, 2, '.', '');
						
						$c= $val['_dr_amount'];
				        $d = floatval($c);
                        $dr_am = number_format( (float) $d, 2, '.', '');
				       $account_debid .='<tr>
										   <td style="width: 50%;font-size:12px;border-right: 1px solid black;text-align:center;">Total</td>
										   <td style="width: 25%;font-size:12px;text-align:right;border-top: 1px solid black;border-left: 1px solid black;">'.$cr_am.'</td>
										   <td style="width: 25%;font-size:12px;text-align:right;border-top: 1px solid black;border-left: 1px solid black;">'.$dr_am.'</td>
										   </tr>';
				}


$account_debid .= '</table>';
$account_debid .= '</td></tr>';



$account_debid .= '<tr>

<td style=""> ';
$account_debid .='<table style="" >';
          

foreach($obj->View_All_By_Cond(" _fee_master_invoice ","_br_id = '$br' AND _invoice_no = '$invoice_id'") as $net){
					extract($net);
					$_status;
                    $recv= $net['_paid_amount'];
				        $rcv = floatval($recv);
                        $recve = number_format( (float) $rcv, 2, '.', '');
											
					$account_debid .='<tr>
					                  <td style="width: 50%;font-size:12px;height:8px;border-top: 1px solid black;border-right: 1px solid black;" >Receive Amount</td>
					                  
									  <td style="width: 50%;font-size:12px;height:13px;border-top: 1px solid black;text-align:Right;" colspan="2">'.$recve.'</td>
									  </tr>';
				//$imi ='';	
          //$imi ='stamp_paid.png';
            //$pdf->setphoto($imi);		  
				//if($_status=='P')
				  // {
					// $imi ='stamp_paid.png'; 
					//$imi .='stamp_paid.png';
					//$pdf->setphoto($x);
					
				   //}
				 // $pdf->setphoto($imi);
               
				 }
 //$pdf->setphoto($imi);

$account_debid .= '</table>';
$account_debid .= '</td></tr>';





$account_debid .= '<tr>

<td style=""> ';
$account_debid .='<table style="" >';
foreach($obj->View_All_By_Cond(" _fee_master_invoice ","_br_id = '$br' AND _invoice_no = '$invoice_id'") as $net){
					extract($net);
                    $a= $net['_due_amount'];
				        $b = floatval($a);
                        $nt = number_format( (float) $b, 2, '.', '');
											
					$account_debid .='<tr>
					                  <td style="width: 50%;font-size:12px;height:8px;border-top: 1px solid black;border-right: 1px solid black;" >Net Payable</td>
					                  
									  <td style="width: 50%;font-size:12px;height:13px;border-top: 1px solid black;text-align:Right;" colspan="2">'.$nt.'</td>
									  </tr>';
					 
				 }


$account_debid .= '</table>';//child
$account_debid .= '</td></tr>';

$account_debid .= '</table>';//father
$account_debid .= '</td>';
//----------------------------------------------------------
$account_debid .= '<td style="width: 3.5%; "> ';
$account_debid .= '</td> ';
//----------------------------------------------------------
$account_debid .= '<td style="width: 31%; "> ';
$account_debid .= '<table style="width: 100%; " border="1">';
$account_debid .= '<tr>

<td style="height:330px"> ';
  $account_debid .='<table style="" >';//child
			    $account_debid .='<tr><td style="width:50%;height:8px;font-size:12px;border-bottom: 1px solid black;text-align:center;" >Description</td>
				<td style="width:25%;height:8px;font-size:12px;border-bottom: 1px solid black;text-align:center;" >Amount</td>
				<td style="width:25%;height:8px;font-size:12px;border-bottom: 1px solid black;text-align:center;" >Discount</td>
				</tr>';
				 
			    foreach($obj->View_All_By_Cond(" _fee_details_invoice ","_br_id = '$br' AND _section_id = '$sc_id' AND _month = '$mnt'  AND _year = '$yr'  AND _std_id = '$std_id' AND _type='C'  AND _invoice_no='$invoice_id'") as $tes){
				extract($tes);
                
                $a= $tes['_amount'];
				$b = floatval($a);
                $deb = number_format( (float) $b, 2, '.', '');				
				$account_debid .='<tr>
						<td style="width: 50%;font-size:12px;height:8px;">
						'.$tes['_fee_head'].'</td>
						<td style="width: 25%;font-size:12px;height:13px;text-align:right;">'.$deb .' </td>
						<td style="width: 25%;font-size:12px;height:8px;"></td></tr>';
					 
				 }
				 
				  foreach($obj->View_All_By_Cond(" _fee_details_invoice ","_br_id = '$br' AND _section_id = '$sc_id' AND _month = '$mnt'  AND _year = '$yr'  AND _std_id = '$std_id' AND _type='D'  AND _invoice_no='$invoice_id'") as $tes1){
					extract($tes1);	
                         $a= $tes1['_amount'];
				        $b = floatval($a);
                        $cr = number_format( (float) $b, 2, '.', '');					
					$account_debid .='<tr>
					                  <td style="width: 50%;font-size:12px;height:8px;">'.$tes1['_fee_head'].'</td>
					                  <td style="width: 25%;font-size:12px;height:8px;"></td>
									  <td style="width: 25%;font-size:12px;height:13px;text-align:right;">'.$cr.'</td>
									  </tr>';
					 
				 }
				 
				 
				 
				 
				 
				 
                //$account .='<tr ><td style=""></td></tr>';			
			   /*  foreach($obj->total_cr_db($br ,$sc_id,$mnt,$yr,$std_id) as $val){
				extract($val);
				       $account_debid .='<tr>
										   <td style="width: 50%;font-size:10px;border-right: 1px solid black;text-align:center;">total</td>
										   <td style="width: 20%;font-size:10px;text-align:center;border-top: 1px solid black;border-left: 1px solid black;">'.$val['_cr_amount'].'</td>
										   <td style="width: 20%;font-size:10px;text-align:center;border-top: 1px solid black;border-left: 1px solid black;">'.$val['_dr_amount'].'</td>
										   </tr>';
				}
				 */
				/* 
				 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'") as $net){
					extract($net);	 
					$account_debid .='<tr>
					                  <td style="width: 50%;font-size:10px;height:8px;border-top: 1px solid black;border-right: 1px solid black;" >net payable</td>
					                  
									  <td style="width: 40%;font-size:10px;height:13px;border-top: 1px solid black;text-align:center;" colspan="3">'.$net['_amount'].'</td>
									  </tr>';
					 
				 } */
			$account_debid .= '</table>';   



$account_debid .= '</td>

</tr>';

//$account_debid .= '</table>';
//$account_debid .= '</td></tr>';
$account_debid .= '<tr>

<td style=""> ';
$account_debid .='<table style="" >';
foreach($obj->total_cr_db($br ,$sc_id,$mnt,$yr,$std_id,$invoice_id) as $val){
				extract($val);
				$a= $val['_cr_amount'];
				        $b = floatval($a);
                        $cr_am = number_format( (float) $b, 2, '.', '');
						
						$c= $val['_dr_amount'];
				        $d = floatval($c);
                        $dr_am = number_format( (float) $d, 2, '.', '');
				       $account_debid .='<tr>
										   <td style="width: 50%;font-size:12px;border-right: 1px solid black;text-align:center;">Total</td>
										   <td style="width: 25%;font-size:12px;text-align:right;border-top: 1px solid black;border-left: 1px solid black;">'.$cr_am.'</td>
										   <td style="width: 25%;font-size:12px;text-align:right;border-top: 1px solid black;border-left: 1px solid black;">'.$dr_am.'</td>
										   </tr>';
				}


$account_debid .= '</table>';
$account_debid .= '</td></tr>';



$account_debid .= '<tr>

<td style=""> ';
$account_debid .='<table style="" >';
          

foreach($obj->View_All_By_Cond(" _fee_master_invoice ","_br_id = '$br' AND _invoice_no = '$invoice_id'") as $net){
					extract($net);
					$_status;
                    $recv= $net['_paid_amount'];
				        $rcv = floatval($recv);
                        $recve = number_format( (float) $rcv, 2, '.', '');
											
					$account_debid .='<tr>
					                  <td style="width: 50%;font-size:12px;height:8px;border-top: 1px solid black;border-right: 1px solid black;" >Receive Amount</td>
					                  
									  <td style="width: 50%;font-size:12px;height:13px;border-top: 1px solid black;text-align:Right;" colspan="2">'.$recve.'</td>
									  </tr>';
				//$imi ='';	
          //$imi ='stamp_paid.png';
            //$pdf->setphoto($imi);		  
				//if($_status=='P')
				  // {
					// $imi ='stamp_paid.png'; 
					//$imi .='stamp_paid.png';
					//$pdf->setphoto($x);
					
				   //}
				 // $pdf->setphoto($imi);
               
				 }
 //$pdf->setphoto($imi);

$account_debid .= '</table>';
$account_debid .= '</td></tr>';




$account_debid .= '<tr>

<td style=""> ';
$account_debid .='<table style="" >';
foreach($obj->View_All_By_Cond(" _fee_master_invoice ","_br_id = '$br' AND _invoice_no = '$invoice_id'") as $net){
					extract($net);
                    $a= $net['_due_amount'];
				        $b = floatval($a);
                        $nt = number_format( (float) $b, 2, '.', '');
											
					$account_debid .='<tr>
					                  <td style="width: 50%;font-size:12px;height:8px;border-top: 1px solid black;border-right: 1px solid black;" >Net Payable</td>
					                  
									  <td style="width: 50%;font-size:12px;height:13px;border-top: 1px solid black;text-align:Right;" colspan="2">'.$nt.'</td>
									  </tr>';
					 
				 }


$account_debid .= '</table>';//child
$account_debid .= '</td></tr>';

$account_debid .= '</table>';

$account_debid .= '</td></tr> ';






$account_debid .= '</table>';//grand-grand

$pdf->writeHTML($account_debid, true, true, false, false, '');






$p = $value['_invoice_no'];


}


/////


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

//$pdf->Line(15, 280, 20, 280);



$pdf->Line(15, 285, 50, 285, $style3);
$pdf->Line(170, 285, 205, 285, $style3);
//$pdf->Text(15, 266.8, 'approved'); */

// 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
 $fileatt = $pdf->Output($p .'.pdf', 'D');














/* $to = 'jahid17788@gmail.com';
$subject = 'Receipt';
$repEmail = 'jahidcse18@gmail.com';

$fileName = 'receipt.pdf';
$fileatt = $pdf->Output($fileName, 'E');
$attachment = chunk_split($fileatt);
$eol = PHP_EOL;
$separator = md5(time());

$headers = 'From: Sender <'.$repEmail.'>'.$eol;
$headers .= 'MIME-Version: 1.0' .$eol;
$headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"";

$message = "--".$separator.$eol;
$message .= "Content-Transfer-Encoding: 7bit".$eol.$eol;
$message .= "This is a MIME encoded message.".$eol;

$message .= "--".$separator.$eol;
$message .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol;
$message .= "Content-Transfer-Encoding: 8bit".$eol.$eol;

$message .= "--".$separator.$eol;
$message .= "Content-Type: application/pdf; name=\"".$fileName."\"".$eol; 
$message .= "Content-Transfer-Encoding: base64".$eol;
$message .= "Content-Disposition: attachment".$eol.$eol;
$message .= $attachment.$eol;
$message .= "--".$separator."--";

if (mail($to, $subject, $message, $headers)){
echo "Email sent";
}

else {
echo "Email failed"; 
}
*/
//============================================================+
// END OF FILE
//============================================================+
