]> wagnertech.de Git - mfinanz.git/commitdiff
Dateimanagement: PDF Buchungsjournal mit Anhängen der Buchungen
authorMartin Helmling martin.helmling@octosoft.eu <martin.helmling@octosoft.eu>
Thu, 29 Dec 2016 11:20:49 +0000 (12:20 +0100)
committerMartin Helmling martin.helmling@octosoft.eu <martin.helmling@octosoft.eu>
Wed, 1 Feb 2017 07:52:11 +0000 (08:52 +0100)
Optinal kann beim Erzeugen eines PDF alle an den einzelnen Buchungen
angehängte PDF-Belege/Dokumente angehängt werden.
In der HTML/CSV/PDF-Tabelle gibt es eine weitere Spalte über die Anzahl der Belege.
Somit kann gesehen werden wo noch Belege fehlen.

Die Spalte wird implizit dazugeschaltet wenn "Beleg" in der Liste miterscheinen soll.

Die zusätzlichen Methoden ist in einem Helper ausgelagert.

SL/Helper/GlAttachments.pm [new file with mode: 0644]
SL/ReportGenerator.pm
bin/mozilla/gl.pl
bin/mozilla/reportgenerator.pl
locale/de/all
templates/webpages/report_generator/pdf_export_options.html

diff --git a/SL/Helper/GlAttachments.pm b/SL/Helper/GlAttachments.pm
new file mode 100644 (file)
index 0000000..aee71a4
--- /dev/null
@@ -0,0 +1,101 @@
+#
+# Helper for General Ledger Reports
+#
+# 1. Fetch the Count of PDF-Documents of one item of a General Ledger Report
+# 2. Append the contents of all items of a General Ledger Report
+
+package SL::Helper::GlAttachments;
+
+use strict;
+
+use Exporter 'import';
+our @EXPORT_OK = qw(count_gl_attachments append_gl_pdf_attachments);
+our %EXPORT_TAGS = (
+  all => \@EXPORT_OK,
+);
+use SL::File;
+
+my %gl_types = (
+  'ar' => 'invoice',
+  'ap' => 'purchase_invoice',
+  'gl' => 'gl_transaction',
+);
+
+#
+# Fetch the Count of PDF-Documents with are related to the $id parameter
+# The parameter $gltype may be 'ar','ap' or 'gl'.
+#
+sub count_gl_pdf_attachments {
+  my ($self,$id,$gltype) = @_;
+  return SL::File->get_all_count(object_id   => $id,
+                                 object_type => $gl_types{$gltype},
+                                 mime_type   => 'application/pdf',
+                                 );
+}
+
+# Append the contents of all PDF-Documents to the base $content
+# This Method is only used in SL/Reportgenerator.pm if the $form->{GD} array is set.
+# The elements of the array need the two elements $ref->{type},$ref->{id}
+#
+sub append_gl_pdf_attachments {
+  my ($self,$form,$content) = @_;
+  my @filelist;
+  foreach my $ref (@{ $form->{GL} }) {
+    my @files = SL::File->get_all(object_id   => $ref->{id},
+                                  object_type => $gl_types{$ref->{type}},
+                                  mime_type   => 'application/pdf',
+                                 );
+    push @filelist, $_->get_file for @files;
+  }
+  return $self->merge_pdfs(file_names => \@filelist , inp_content => $content );
+}
+
+1;
+
+__END__
+
+=encoding utf-8
+
+=head1 NAME
+
+SL::Helper::GlAttachments - Helper for General Ledger Reports
+
+=head1 SYNOPSIS
+
+   $self->count_gl_pdf_attachments($ref->{id},$ref->{type});
+   $self->append_gl_pdf_attachments($form,$base_content);
+
+
+=head1 DESCRIPTION
+
+Helper for General Ledger Reports
+
+1. Fetch the Count of PDF-Documents of one item of a General Ledger Report
+
+2. Append the contents of all items of a General Ledger Report
+
+
+=head1 METHODS
+
+=head2 C<count_gl_pdf_attachments>
+
+count_gl_pdf_attachments($id,$type);
+
+Fetch the Count of PDF-Documents with are related to the $id parameter
+The parameter $type may be 'ar','ap' or 'gl'.
+
+=head2 C<append_gl_pdf_attachments>
+
+append_gl_pdf_attachments($form,$content);
+
+Append the contents of all PDF-Documents to the base $content
+This Method is only used in SL/Reportgenerator.pm if the $form->{GD} array is set.
+The elements of the array need the two elements $ref->{type},$ref->{id}
+
+=head1 AUTHOR
+
+Martin Helmling E<lt>martin.helmling@opendynamic.deE<gt>
+
+
+=cut
+
index 2e12a2acc51dabf9fb74b1bdfbea016de3fb1cfd..30517a19949a3a81e5fd2be15795afb1230c230f 100644 (file)
@@ -7,6 +7,8 @@ use Text::CSV_XS;
 #use PDF::Table;
 
 use strict;
+use SL::Helper::GlAttachments qw(append_gl_pdf_attachments);
+use SL::Helper::CreatePDF     qw(merge_pdfs);
 
 # Cause locales.pl to parse these files:
 # parse_html_template('report_generator/html_report')
@@ -656,6 +658,11 @@ sub generate_pdf_content {
 
   my $content = $pdf->stringify();
 
+  $main::lxdebug->message(LXDebug->DEBUG2(),"addattachments ?? =".$form->{report_generator_addattachments}." GL=".$form->{GL});
+  if ( $form->{report_generator_addattachments} eq 'yes' && $form->{GL}) {
+    $content = $self->append_gl_pdf_attachments($form,$content);
+  }
+
   my $printer_command;
   if ($pdfopts->{print} && $pdfopts->{printer_id}) {
     $form->{printer_id} = $pdfopts->{printer_id};
index fc8a162e659fd17d27fb7207fd5575e3647795aa..c2a2f02d57d07abc42d5892665d909d73e6c3f22 100644 (file)
@@ -48,6 +48,7 @@ use SL::ReportGenerator;
 use SL::DBUtils qw(selectrow_query selectall_hashref_query);
 use SL::Webdav;
 use SL::Locale::String qw(t8);
+use SL::Helper::GlAttachments qw(count_gl_attachments);
 
 require "bin/mozilla/common.pl";
 require "bin/mozilla/reportgenerator.pl";
@@ -411,7 +412,7 @@ sub generate_report {
 
   my @columns = qw(
     gldate         transdate        id             reference      description
-    notes          source           debit          debit_accno
+    notes          source   doccnt  debit          debit_accno
     credit         credit_accno     debit_tax      debit_tax_accno
     credit_tax     credit_tax_accno projectnumbers balance employee
   );
@@ -451,6 +452,7 @@ sub generate_report {
   $form->{l_datesort} = 'Y';
   $form->{l_debit_tax_accno}  = 'Y';
   $form->{l_balance}          = $form->{accno} ? 'Y' : '';
+  $form->{l_doccnt}           = $form->{l_source} ? 'Y' : '';
 
   my %column_defs = (
     'id'               => { 'text' => $locale->text('ID'), },
@@ -458,6 +460,7 @@ sub generate_report {
     'gldate'           => { 'text' => $locale->text('Booking Date'), },
     'reference'        => { 'text' => $locale->text('Reference'), },
     'source'           => { 'text' => $locale->text('Source'), },
+    'doccnt'           => { 'text' => $locale->text('Document Count'), },
     'description'      => { 'text' => $locale->text('Description'), },
     'notes'            => { 'text' => $locale->text('Notes'), },
     'debit'            => { 'text' => $locale->text('Debit'), },
@@ -493,7 +496,8 @@ sub generate_report {
   $report->set_columns(%column_defs);
   $report->set_column_order(@columns);
 
-  $report->set_export_options('generate_report', @hidden_variables, qw(sort sortdir));
+  $form->{l_attachments} = 'Y';
+  $report->set_export_options('generate_report', @hidden_variables, qw(sort sortdir l_attachments));
 
   $report->set_sort_indicator($form->{sort} eq 'accno' ? 'debit_accno' : $form->{sort}, $form->{sortdir});
 
@@ -542,6 +546,10 @@ sub generate_report {
     my $row = { };
     map { $row->{$_} = { 'data' => '', 'align' => $column_alignment{$_} } } @columns;
 
+    if ( $form->{l_doccnt} ) {
+      $row->{doccnt}->{data} = SL::Helper::GlAttachments->count_gl_pdf_attachments($ref->{id},$ref->{type});
+    }
+
     my $sh = "";
     if ($form->{balance} < 0) {
       $sh = " S";
index 5e39df1c1f8f62d7fad74b0dce1f67687d1fef48..2304e492d85ffb33edeebe4dc0fe8c2667239dee 100644 (file)
@@ -64,12 +64,15 @@ sub report_generator_export_as_pdf {
   $form->{copies} = max $myconfig{copies} * 1, 1;
 
   my $allow_font_selection = 1;
+  my $allow_attachments    = 0;
   eval { require PDF::API2; };
   $allow_font_selection = 0 if ($@);
+  $allow_attachments    = 1 if $form->{report_generator_hidden_l_attachments};
 
   $form->{title} = $locale->text('PDF export -- options');
   $form->header();
   print $form->parse_html_template('report_generator/pdf_export_options', { 'HIDDEN'               => \@form_values,
+                                                                            'ALLOW_ATTACHMENTS'    => $allow_attachments,
                                                                             'ALLOW_FONT_SELECTION' => $allow_font_selection, });
 
   $main::lxdebug->leave_sub();
index 52973e76d0c520ebd847ac4a40b714493e1c91dd..af182ec9980c73b7d995a99aa09fd66be28a44c9 100644 (file)
@@ -992,6 +992,7 @@ $self->{texts} = {
   'Do you want to set the account number "#1" to "#2" and the name "#3" to "#4"?' => 'Soll die Kontonummer "#1" zu "#2" und den Name "#3" zu "#4" geändert werden?',
   'Do you want to store the existing onhand values into a new warehouse?' => 'M&ouml;chten Sie die vorhandenen Mengendaten in ein Lager &uuml;bertragen?',
   'Document'                    => 'Dokument',
+  'Document Count'              => 'Anz. PDF Belege',
   'Document Project (database ID)' => 'Projektnummer des Belegs (Datenbank-ID)',
   'Document Project (description)' => 'Projektnummer des Belegs (Beschreibung)',
   'Document Project (number)'   => 'Projektnummer des Belegs',
@@ -1287,6 +1288,7 @@ $self->{texts} = {
   'Export Stammdaten'           => 'Export Stammdaten',
   'Export as CSV'               => 'Als CSV exportieren',
   'Export as PDF'               => 'Als PDF exportieren',
+  'Export as PDF with attachments' => 'Als PDF mit Anhängen exportieren',
   'Export date'                 => 'Exportdatum',
   'Export date from'            => 'Exportdatum von',
   'Export date to'              => 'Exportdatum bis',
@@ -3682,7 +3684,7 @@ $self->{texts} = {
   'found'                       => 'Gefunden',
   'found_br'                    => 'Gef.',
   'from (time)'                 => 'von',
-  'general_ledger_list'         => 'buchungsjournal',
+  'general_ledger_list'         => 'Buchungsjournal',
   'generate cb/ob transactions for selected charts' => 'Buchungen erstellen',
   'gobd-#1-#2.zip'              => 'gobd-#1-#2.zip',
   'h'                           => 'h',
index 444c0b60052cb1b92042ea27e708615e5f1c031e..5b2f68f3fbcd5f7ce60d116d5086470e79aa809f 100644 (file)
@@ -14,6 +14,7 @@
 
   <input type="hidden" name="report_generator_pdf_options_set" value="1">
   <input type="hidden" name="report_generator_dispatch_to" value="">
+  <input type="hidden" name="report_generator_addattachments" value="">
 
   <table>
    <tr>
 [%- ELSE %]
   <p>
    <input type="hidden" name="action" value="report_generator_dispatcher">
-   <input type="submit" class="submit" onclick="submit_report_generator_form('report_generator_export_as_pdf')" value="[% 'Export as PDF' | $T8 %]">
+   <input type="submit" class="submit" onclick="submit_report_generator_form('report_generator_export_as_pdf','')" value="[% 'Export as PDF' | $T8 %]">
+[%- IF ALLOW_ATTACHMENTS %]
+   <input type="submit" class="submit"
+      onclick="submit_report_generator_form('report_generator_export_as_pdf','yes')"
+      value="[% 'Export as PDF with attachments' | $T8 %]">
+[%- END %]
    <input type="submit" class="submit" onclick="submit_report_generator_form('report_generator_back')" value="[% 'Back' | $T8 %]">
   </p>
  <script type="text/javascript"><!--
-      function submit_report_generator_form(nextsub) {
+      function submit_report_generator_form(nextsub,att) {
         document.report_generator_form.report_generator_dispatch_to.value = nextsub;
+        document.report_generator_form.report_generator_addattachments.value = att;
         document.report_generator_form.submit();
       } // -->
  </script>