
<?php
$m="select 
a.ftbankrcp_no as hdr_ftbankrcp_no,a.ftjournal_no as hdr_ftjournal_no, 
a.fdtrans_date as hdr_fdtrans_date,
a.ftacc_no1 as hdr_ftacc_no1, c.ftdescription as hdr_ftacc_desc, a.fcamount as hdr_fcamount,
a.fccomparison_amount as hdr_fccomparison_amount,a.ftremarks as hdr_ftremarks,
a.fnstatus as hdr_fnstatus,
b.ftacc_no as det_ftacc_no,d.ftdescription as det_ftacc_desc,
b.ftgiro_no as det_ftgiro_no,b.fdgiro_date as det_fdgiro_date , b.fdgiro_cliring_date as det_fdgiro_cliring_date,
E.fttrans_status_name AS ftpayment_method,
b.ftdescription as det_ftdescription,
b.fcamount as det_fcamount
from txbankrcp_hdr a,txbankrcp_det b,
(select ftcode, ftdescription from tlmaster_cast 
union all 
select ftcode,ftdescription from tlmaster_bank) c
,
(select ftcode, ftdescription from tlmaster_cast 
union all 
select ftcode,ftdescription from tlmaster_bank) d
,tstransaction_status e 
where  b.fnpayment_method=e.fntrans_status_code AND e.fntrans_group_code=8 AND a.ftbankrcp_no=b.ftbankrcp_no and a.ftacc_no1=c.ftcode and b.ftacc_no=d.ftcode 
order by b.fnindex";
#die(nl2br(strtolower($m)));
function convertValue($value, $className)  
{  
    // if we are a string, just use the normal conversion  
    // methods from the java extension...  
    try   
    {  
        if ($className == 'java.lang.String')  
        {  
            $temp = new Java('java.lang.String', $value);  
            return $temp;  
        }  
        else if ($className == 'java.lang.Boolean' ||  
            $className == 'java.lang.Integer' ||  
            $className == 'java.lang.Long' ||  
            $className == 'java.lang.Short' ||  
            $className == 'java.lang.Double' ||  
            $className == 'java.math.BigDecimal')  
        {  
            $temp = new Java($className, $value);  
            return $temp;  
        }  
        else if ($className == 'java.sql.Timestamp' ||  
            $className == 'java.sql.Time')  
        {  
            $temp = new Java($className);  
            $javaObject = $temp->valueOf($value);  
            return $javaObject;  
        }  
    }  
    catch (Exception $err)  
    {  
        echo (  'unable to convert value, ' . $value .  
                ' could not be converted to ' . $className);  
        return false;  
    }
  
    echo (  'unable to convert value, class name '.$className.  
            ' not recognised');  
    return false;  
}

	
                require_once("http://localhost:8080/JavaBridge/java/Java.inc");
		$reportsPath =_APP_PATH;
		$reportFileName = "report/test";
		$jasperReportsLib = "C:/Program Files/JasperSoft/iReport-3.0.0/lib";
			$handle = @opendir($jasperReportsLib);

			while(($new_item = readdir($handle))!==false) {
				
				$java_library_path .= 'file:'.$jasperReportsLib.'/'.$new_item .';';
			}
		
		
			try {

				java_require($java_library_path);
				$Conn = new Java("org.altic.jasperReports.JdbcConnection");	
				$Conn->setDriver("com.mysql.jdbc.Driver");
				$Conn->setConnectString(_CONNECTION_STRING);
				$Conn->setUser(_USER_DB);
				$Conn->setPassword(_PASS_DB);
				$sJcm = new JavaClass("net.sf.jasperreports.engine.JasperCompileManager");
				$report = $sJcm->compileReport($reportsPath .$reportFileName.".jrxml");

                                $params = new Java("java.util.HashMap");
//                                $params->put("trans_no", convertValue("cr081100001","java.lang.String"));
	
				$sJfm = new JavaClass("net.sf.jasperreports.engine.JasperFillManager");

				$print = $sJfm->fillReport($report,$params,$Conn->getConnection());

				$sJem = new JavaClass("net.sf.jasperreports.engine.JasperExportManager");
//				
                                  $r="pdf";
//                                   $r="html";
                                if($r=="pdf") {
                                     @unlink($reportsPath .$reportFileName.".pdf");
                                    $sJem->exportReportToPdfFile($print, $reportsPath .$reportFileName.".pdf");
//                                    if (file_exists($reportsPath .$reportFileName.".pdf")){
//
//                                         header("Content-type: application/pdf");
//                                         header('Content-disposition: attachment; filename="'.$reportFileName.'.pdf"');
//                                         header('Content-Type: application/pdf');
//                                         header('Content-Transfer-Encoding: binary');
//                                         header('Content-Length: '. @filesize($reportsPath . $reportFileName.".pdf"));
//                                         header('Pragma: no-cache');
//                                         header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
//                                         header('Expires: 0');
//                                         set_time_limit(0);
//                                         @readfile($reportsPath .$reportFileName.".pdf") or die("problem occurs.");
//                                          unlink($reportsPath .$reportFileName.".pdf");
//                                     }
                                }
                                else {
                                    @unlink($reportsPath .$reportFileName.".html");
                                     $sJem->exportReportToHtmlFile($print, $reportsPath .$reportFileName.".html");
                              
                                      include  $reportsPath .$reportFileName.".html";
                                }
                               
			} catch (JavaException $ex) {
				 $trace = new Java("java.io.ByteArrayOutputStream");
				$ex->printStackTrace(new Java("java.io.PrintStream", $trace));
				print "java stack trace: $trace\n";
			}
		//}