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);
}
$cmd .= ' "'.$tmpreportpath.'/'.$template.'.html"';
$cmd .= ' "'.$output.'"';
- print $cmd."\n";
+ #print $cmd."\n";
$r = system($cmd);
}
if (-e $output){
open(CFG,$self->{tmplpath}.'/'.$template.'.conf');
while (my $l = <CFG>){
chomp($l);
- print $l."\n";
+ #print $l."\n";
$l =~ s/^\s+//;
if (($l =~ /^#/) || ($l eq "")) {next;}
if ($l =~ /\w+=.+/){
# 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;
# $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})){
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){
}
}
elsif (exists($p->{generate})){
+ print $cgi->header(-type=>"application/json", -charset => "utf-8");
+ #we need: generate=> invoices/dks-deutsch
+ # filename=>DKS_<reference>.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 (<DLD>){
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);