SIMITGROUP / phpjasperxml

This is a php wysiwyg report library
BSD 3-Clause "New" or "Revised" License
44 stars 45 forks source link

SimpleDateFormat not found on version 1.1 #48

Closed reisfira closed 5 years ago

reisfira commented 5 years ago

Hi again, so I tried a minimal setup like so. I'm using CSV btw:

        $input = config('custom.input').'invoice/invoice.jrxml'; // points to JRXML
        $output = config('custom.output'); // points to storage/ directory

        $PHPJasperXML = new PHPJasperXML('en', 'TCPDF');
        $PHPJasperXML->load_xml_file($input);
        $dbdriver="PDO"; // using csv from JSS
        $PHPJasperXML->outpage('I');

        return response()->file($output.'/invoice.pdf', $headers);

This looks like a Java error, so I don't really know where to go with this... simpledateformat not found

Is this because my $PHPJasperXML don't have $PHPJasperXML->transferDBtoArray() or $PHPJasperXML->arrayParameter ?

reisfira commented 5 years ago

Update, I tried the following:

        $PHPJasperXML = new PHPJasperXML('en', 'TCPDF');
        $PHPJasperXML->arrayParameter = [];
        $PHPJasperXML->load_xml_file($input);
        $PHPJasperXML->transferDBtoArray(env('DB_HOST'), env('DB_USERNAME'),env('DB_PASSWORD'),env('DB_DATABASE'), 'mysql');
        $PHPJasperXML->outpage('I'); // the error happens here btw

So I tried to include, everything as in the readme, still produce the same error... and when I change the driver from mysql to PDO (because I'm using csv), it says:

Failed to get DB handle: could not find driver
reisfira commented 5 years ago

Another update, I tried the example on readme, with some modification:

        $PHPJasperXML = new PHPJasperXML();
        // $PHPJasperXML->debugsql=true;
        $PHPJasperXML->arrayParameter=array("parameter1"=>1);
        $PHPJasperXML->load_xml_file(base_path()."/vendor/simitgroup/phpjasperxml/sample/sample1.jrxml");
        $PHPJasperXML->transferDBtoArray('127.0.0.1','root','','database_name');
        $PHPJasperXML->outpage("I");    //page output method I:standard output  D:Download file

I get an error:

TCPDF ERROR: [Image] Unable to get image: ./simitlogo.png

Does this mean that I need to put the PHPJasperXML in the Controller folder? (I'm using Laravel btw)

Right now, this is how I use it:

include_once base_path().'/vendor/simitgroup/phpjasperxml/version/1.1/PHPJasperXML.inc.php';
use PHPJasperXML;

class InvoiceController extends Controller
{
    public function testReport() {
        $PHPJasperXML = new PHPJasperXML();
        // $PHPJasperXML->debugsql=true;
        $PHPJasperXML->arrayParameter=array("parameter1"=>1);
        $PHPJasperXML->load_xml_file(base_path()."/vendor/simitgroup/phpjasperxml/sample/sample1.jrxml");
        $PHPJasperXML->transferDBtoArray('127.0.0.1','root','','database_name');
        $PHPJasperXML->outpage("I");    //page output method I:standard output  D:Download file
        $headers = [ 'Content-Type' => 'application/pdf' ];

        return response()->file($output.'/invoice.pdf', $headers);
    }
}

Maybe I'm doing it wrong?

reisfira commented 5 years ago
TCPDF ERROR: [Image] Unable to get image: ./simitlogo.png

Regarding the error, I decided to handle image by absolute path and pass the path by parameter (seems URL doesn't work). That worked.

However, using CSV instead of MySQL is still unresolved for me.

reisfira commented 5 years ago
        $input = config('custom.input').'invoice/invoice.jrxml';
        $output = config('custom.output');
        // $sample_xml = base_path()."/vendor/simitgroup/phpjasperxml/sample/sample1.jrxml";
        $PHPJasperXML = new PHPJasperXML("en","TCPDF");
        $PHPJasperXML->arrayParameter =array();
        $PHPJasperXML->load_xml_file($input);
        $PHPJasperXML->transferDBtoArray('127.0.0.1','root','','database_name');
        $PHPJasperXML->arraysqltable=$data;
        $PHPJasperXML->m=count($data);
        $PHPJasperXML->outpage('I');

This works now, I guess, just pass an array to arraysqltable did it. Regarding the Class SimpleDateFormat not found error, I simply parse it from php first then pass as string in $data. Closing it now

kstan79 commented 5 years ago

Great to see you finally solve the problem