pdfreport modified and tested
authorkilian (ksmachome) <ksaffran@dks.lu>
Tue, 14 Jan 2020 08:48:55 +0000 (09:48 +0100)
committerkilian (ksmachome) <ksaffran@dks.lu>
Tue, 14 Jan 2020 08:48:55 +0000 (09:48 +0100)
.gitignore
CGI/api/lib/pdfreport.pm
CGI/api/report.cgi
data/invoicejournal/templates/invoices/dks-deutsch.header.tt

index 125f14d..d7aaf69 100644 (file)
@@ -11,4 +11,6 @@ data/invoicejournal/invoices/*
 data/invoicejournal/offers/*
 data/invoicejournal/tmp/*
 data/rpinas/*
+data/invoicejournal/output/*
+data/invoicejournal/templates/tmp/*
 
index 7c1b7ca..87e16f7 100644 (file)
@@ -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 = <CFG>){
     chomp($l);
-    print $l."\n";
+    #print $l."\n";
     $l =~ s/^\s+//;
     if (($l =~ /^#/) || ($l eq "")) {next;}
     if ($l =~ /\w+=.+/){
index d00a63d..3720f83 100755 (executable)
@@ -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_<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>){
@@ -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);
index 8e40350..495b4c8 100644 (file)
@@ -4,7 +4,7 @@
 </head><body style="border:0; margin: 0;" o>
 <table style="width: 100%;">
   <tr>
-    <td style="width: 150mm; margin-top:5mm;"><img src="ttinvoice/sitc.png" style="height: 35mm;"/></td>
+    <td style="width: 150mm; margin-top:5mm;"><img src="dks-deutsch/sitc.png" style="height: 25mm;"/></td>
     <td style="width: 60mm;text-align: right;">
       <div style="text-align: left;width: 60mm; font-size: 12pt;font: sans;">
           <b>SAFFRAN IT Consulting S.à r.l.</b><br/>