From 29564e8387a8f2d6769dec08425af6bcc54c42e9 Mon Sep 17 00:00:00 2001 From: "kilian (ksmachome)" Date: Tue, 14 Jan 2020 09:48:55 +0100 Subject: [PATCH] pdfreport modified and tested --- .gitignore | 2 + CGI/api/lib/pdfreport.pm | 12 ++--- CGI/api/report.cgi | 46 +++++++++++++++---- .../templates/invoices/dks-deutsch.header.tt | 2 +- 4 files changed, 45 insertions(+), 17 deletions(-) diff --git a/.gitignore b/.gitignore index 125f14d..d7aaf69 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,6 @@ data/invoicejournal/invoices/* data/invoicejournal/offers/* data/invoicejournal/tmp/* data/rpinas/* +data/invoicejournal/output/* +data/invoicejournal/templates/tmp/* diff --git a/CGI/api/lib/pdfreport.pm b/CGI/api/lib/pdfreport.pm index 7c1b7ca..87e16f7 100644 --- a/CGI/api/lib/pdfreport.pm +++ b/CGI/api/lib/pdfreport.pm @@ -24,13 +24,13 @@ sub createpdf(){ my $output = shift; my $inputdata = shift; my $r = -1; - print $self->{tmplpath}.'/'.$template.'.conf'."\n"; + #print $self->{tmplpath}.'/'.$template.'.conf'."\n"; if (-e $self->{tmplpath}.'/'.$template.'.conf'){ $self->readpdfconfig($template,$inputdata); - print Dumper($self->{template}); + #print Dumper($self->{template}); } - print Dumper($self->{pdf}); - print Dumper($self->{template}); + #print Dumper($self->{pdf}); + #print Dumper($self->{template}); my $tmpreportpath=$self->{tmplpath}; if (exists($self->{pdf}->{engine}) && ($self->{pdf}->{engine} eq "Template::Toolkit")){ $template = $self->createTTReport($template); @@ -53,7 +53,7 @@ sub createpdf(){ } $cmd .= ' "'.$tmpreportpath.'/'.$template.'.html"'; $cmd .= ' "'.$output.'"'; - print $cmd."\n"; + #print $cmd."\n"; $r = system($cmd); } if (-e $output){ @@ -96,7 +96,7 @@ sub readpdfconfig(){ open(CFG,$self->{tmplpath}.'/'.$template.'.conf'); while (my $l = ){ chomp($l); - print $l."\n"; + #print $l."\n"; $l =~ s/^\s+//; if (($l =~ /^#/) || ($l eq "")) {next;} if ($l =~ /\w+=.+/){ diff --git a/CGI/api/report.cgi b/CGI/api/report.cgi index d00a63d..3720f83 100755 --- a/CGI/api/report.cgi +++ b/CGI/api/report.cgi @@ -12,9 +12,11 @@ use CGI::Cookie; # use CGI::Carp qw/fatalsToBrowser/; use File::Basename; use JSON::PP; +use File::Path qw(make_path); use MIME::Type::FileName; use dksconfig qw/$sitecfg/; use dksdb; +use pdfreport; # use session; #use sendemail; @@ -29,7 +31,7 @@ my $html->{result} = (); # $p->{sid} = $cgi->cookie($sitecfg->{cookiename}); # my $se = session->new(); # my $sess = $se->getsession($p->{sid}); -print $cgi->header(-type=>"application/json", -charset => "utf-8"); + my $dbredirect = {}; if ($sitecfg->{dbtype} eq "SQLite"){ if (exists($p->{db})){ @@ -54,6 +56,7 @@ if (($cgi->request_method() eq "GET") || ($cgi->request_method() eq "POST")){ if (exists($p->{list})){ #$html->{param} = $p; + print $cgi->header(-type=>"application/json", -charset => "utf-8"); my $reppath = $sitecfg->{datapath}.'/'.$p->{app}.'/templates/'.$p->{list}; #$html->{path} = $reppath; if (-d $reppath){ @@ -83,25 +86,41 @@ if (($cgi->request_method() eq "GET") || ($cgi->request_method() eq "POST")){ } } elsif (exists($p->{generate})){ + print $cgi->header(-type=>"application/json", -charset => "utf-8"); + #we need: generate=> invoices/dks-deutsch + # filename=>DKS_.pdf + # app=>invoicejournal + # data=>{id_invoice:469} + # db=>dksbuchhaltung + my $data = JSON::PP::decode_json($p->{data}); + $data->{dsn} = 'DBI:SQLite:dbname='.$sitecfg->{datapath}.'/'.$p->{app}.'/'.$p->{db}.'.sqlite'; # my $data = { # id_invoice => "469", # dsn => 'DBI:SQLite:dbname='.$dbpath.'/invoicejournal/dksbuchhaltung.sqlite' # }; - # my $rep = pdfreport->new({tmplpath => $RealBin.'/report', tmp => $RealBin.'/tmp'}); - # my ($result,$file) = $rep->createpdf('ttinvoice',$RealBin.'/output/textinvoice.pdf',$data); + my $reportpath = $sitecfg->{datapath}.'/'.$p->{app}.'/templates/'.dirname($p->{generate}); + my $tmppath = $sitecfg->{datapath}.'/'.$p->{app}.'/templates/tmp/'; + my $output = $sitecfg->{datapath}.'/'.$p->{app}.'/output/'.dirname($p->{generate}).'/'.$p->{filename}; + if (! -d $sitecfg->{datapath}.'/'.$p->{app}.'/output/'.dirname($p->{generate})){ + make_path($sitecfg->{datapath}.'/'.$p->{app}.'/output/'.dirname($p->{generate})); + } + my $rep = pdfreport->new({tmplpath => $reportpath, tmp => $tmppath}); + my ($result,$file) = $rep->createpdf(basename($p->{generate}),$output,$data); + $html->{result}->{file} = dirname($p->{generate}).'/'.basename($file); # print "$result: $file\n"; } elsif (exists($p->{open})){ - if (exists($p->{file}) && -e ){ - - my $mimetype = MIME::Type::FileName::guess ($sitecfg->{data}.'/'.$p->{file}); - my @stat = stat($sitecfg->{data}.'/'.$p->{file}); + #open=>invoicejournal/output/ + my $file = $sitecfg->{datapath}.'/'.$p->{app}.'/output/'.$p->{open}; + if (-e $file){ + my $mimetype = MIME::Type::FileName::guess ($file); + my @stat = stat($file); print $cgi->header( -type => $mimetype, - -target => basename($p->{file}), - -attachment => basename($p->{file}) + -target => basename($p->{open}), + -attachment => basename($p->{open}) ); - open(DLD,$sitecfg->{data}.'/'.$p->{file}); + open(DLD,$file); binmode(DLD); local $/ = \1024; while (){ @@ -110,6 +129,13 @@ if (($cgi->request_method() eq "GET") || ($cgi->request_method() eq "POST")){ close(DLD); exit(0); } + else { + print $cgi->header(-type=>"application/json", -charset => "utf-8"); + $html->{result}->{file} = $file; + } + } + elsif (exists($p->{upload})){ + } } print JSON::PP::encode_json($html); diff --git a/data/invoicejournal/templates/invoices/dks-deutsch.header.tt b/data/invoicejournal/templates/invoices/dks-deutsch.header.tt index 8e40350..495b4c8 100644 --- a/data/invoicejournal/templates/invoices/dks-deutsch.header.tt +++ b/data/invoicejournal/templates/invoices/dks-deutsch.header.tt @@ -4,7 +4,7 @@ - +
SAFFRAN IT Consulting S.à r.l.
-- 2.39.5