Um die Benutzung des Template Systems mal ein wenig zu foerdern.
[kivitendo-erp.git] / bin / mozilla / dn.pl
index 94af950..e530050 100644 (file)
@@ -36,8 +36,10 @@ use POSIX;
 use SL::IS;
 use SL::PE;
 use SL::DN;
+use SL::ReportGenerator;
 
 require "bin/mozilla/common.pl";
+require "bin/mozilla/reportgenerator.pl";
 require "bin/mozilla/io.pl";
 require "bin/mozilla/arap.pl";
 
@@ -68,10 +70,8 @@ sub edit_config {
     }
   }
 
-  $form->{title}          = $locale->text('Edit Dunning Process Config');
-  $form->{callback}     ||= build_std_url("action=edit_config");
-  $form->{rowcount}       = 1 + scalar @{ $form->{DUNNING} };
-  $form->{rowcount_odd}   = $form->{rowcount} % 2;
+  $form->{title}      = $locale->text('Edit Dunning Process Config');
+  $form->{callback} ||= build_std_url("action=edit_config");
 
   $form->header();
   print $form->parse_html_template("dunning/edit_config");
@@ -124,11 +124,11 @@ sub show_invoices {
   $form->{jsscript}       = 1;
   $form->{callback}     ||= build_std_url("action=show_invoices", qw(login password customer invnumber ordnumber groupinvoices minamount dunning_level notes));
 
-  $form->{PRINT_OPTIONS}  = print_options('inline'          => 1,
-                                            'no_queue'        => 1,
-                                            'no_postscript'   => 1,
-                                            'no_html'         => 1,
-                                            'no_opendocument' => 1, });
+  $form->{PRINT_OPTIONS}  = print_options('inline'          => 1,
+                                          'no_queue'        => 1,
+                                          'no_postscript'   => 1,
+                                          'no_html'         => 1,
+                                          'no_opendocument' => 1,);
 
   $form->header();
   print $form->parse_html_template("dunning/show_invoices");
@@ -155,7 +155,7 @@ sub save {
     $form->{addition} = "SAVED FOR DUNNING";
        $form->save_history($form->dbconnect(\%myconfig));
   }
-  # /saving the history 
+  # /saving the history
   $form->redirect($locale->text('Dunning Process Config saved!'));
 
   $lxdebug->leave_sub();
@@ -209,7 +209,7 @@ sub save_dunning {
   }
 
   if($form->{DUNNING_PDFS}) {
-    DN->melt_pdfs(\%myconfig, $form);
+    DN->melt_pdfs(\%myconfig, $form, $form->{copies});
   }
 
   # saving the history
@@ -220,7 +220,10 @@ sub save_dunning {
   }
   # /saving the history
 
-  $form->redirect($locale->text('Dunning Process started for selected invoices!')) if ($form->{media} eq 'printer');
+  if ($form->{media} eq 'printer') {
+    delete $form->{callback};
+    $form->redirect($locale->text('Dunning Process started for selected invoices!'));
+  }
 
   $lxdebug->leave_sub();
 }
@@ -228,14 +231,6 @@ sub save_dunning {
 sub set_email {
   $lxdebug->enter_sub();
 
-
-  my $callback = "$form->{script}?action=set_email&";
-  map({ $callback .= "$_=" . $form->escape($form->{$_}) . "&" }
-      (qw(login password name input_subject input_body input_attachment email_subject email_body email_attachment), grep({ /^[fl]_/ } keys %$form)));
-
-  if ($form->{email_attachment}) {
-    $form->{email_attachment} = "checked";
-  }
   $form->{"title"} = $locale->text("Set eMail text");
   $form->header();
   print($form->parse_html_template("dunning/set_email"));
@@ -274,44 +269,107 @@ sub search {
 sub show_dunning {
   $lxdebug->enter_sub();
 
+  my @filter_field_list = qw(customer_id customer dunning_level department_id invnumber ordnumber
+                             transdatefrom transdateto dunningfrom dunningto notes showold);
+
   DN->get_dunning(\%myconfig, \%$form);
 
-  my $odd_even = 0;
-  my ($previous_dunning_id, $first_row_for_dunning);
+  if (!$form->{callback}) {
+    $form->{callback} = build_std_url("action=show_dunning", @filter_field_list);
+  }
+
+  $form->get_lists('printers'  => 'printers',
+                   'languages' => 'languages');
+
+  $form->{type}          = 'dunning';
+  $form->{PRINT_OPTIONS} = print_options('inline'          => 1,
+                                         'no_queue'        => 1,
+                                         'no_postscript'   => 1,
+                                         'no_html'         => 1,
+                                         'no_opendocument' => 1,);
+  $form->{title}         = $locale->text('Dunning overview');
+
+  my $report = SL::ReportGenerator->new(\%myconfig, $form);
+
+  $report->set_options('std_column_visibility' => 1,
+                       'title'                 => $form->{title});
+  $report->set_export_options('show_dunning', @filter_field_list);
+
+  $report->set_columns(
+    'checkbox'            => { 'text' => '', 'visible' => 'HTML' },
+    'dunning_description' => { 'text' => $locale->text('Dunning Level') },
+    'customername'        => { 'text' => $locale->text('Customername') },
+    'invnumber'           => { 'text' => $locale->text('Invnumber') },
+    'transdate'           => { 'text' => $locale->text('Invdate') },
+    'duedate'             => { 'text' => $locale->text('Invoice Duedate') },
+    'amount'              => { 'text' => $locale->text('Amount') },
+    'dunning_date'        => { 'text' => $locale->text('Dunning Date') },
+    'dunning_duedate'     => { 'text' => $locale->text('Dunning Duedate') },
+    'fee'                 => { 'text' => $locale->text('Total Fees') },
+    'interest'            => { 'text' => $locale->text('Interest') },
+  );
+
+  $report->set_column_order(qw(checkbox dunning_description customername invnumber transdate
+                               duedate amount dunning_date dunning_duedate fee interest));
+
+  my $edit_url  = build_std_url('script=is.pl', 'action=edit', 'callback') . '&id=';
+  my $print_url = build_std_url('action=print_dunning', 'format=pdf', 'media=screen') . '&dunning_id=';
+
+  my %alignment = map { $_ => 'right' } qw(transdate duedate amount dunning_date dunning_duedate fee interest);
+
+  my ($current_dunning_rows, $previous_dunning_id, $first_row_for_dunning);
+
+  $current_dunning_rows  = [];
+  $first_row_for_dunning = 1;
+  $form->{rowcount}      = scalar @{ $form->{DUNNINGS} };
+
+  my $i = 0;
 
   foreach $ref (@{ $form->{DUNNINGS} }) {
+    $i++;
+
     if ($previous_dunning_id != $ref->{dunning_id}) {
-      $odd_even = ($odd_even + 1) % 2;
-      $ref->{first_row_for_dunning} = 1;
+      $report->add_data($current_dunning_rows) if (scalar @{ $current_dunning_rows });
+      $current_dunning_rows  = [];
+      $first_row_for_dunning = 1;
+    }
+
+    my $row = { };
+    foreach my $column (keys %{ $ref }) {
+      $row->{$column} = {
+        'data'  => $first_row_for_dunning || (($column ne 'dunning_description') && ($column ne 'customername')) ? $ref->{$column} : '',
+
+        'align' => $alignment{$column},
 
-    } else {
-      $ref->{first_row_for_dunning} = 0;
+        'link'  => ($column eq 'invnumber'           ? $edit_url  . E($ref->{id})         :
+                    $column eq 'dunning_description' ? $print_url . E($ref->{dunning_id}) : ''),
+      };
     }
 
-    $previous_dunning_id     = $ref->{dunning_id};
-    $ref->{listrow_odd_even} = $odd_even;
-  }
+    $row->{checkbox} = !$first_row_for_dunning ? { } : {
+      'raw_data' =>   $cgi->hidden('-name' => "dunning_id_$i", '-value' => $ref->{dunning_id})
+                    . $cgi->checkbox('-name' => "selected_$i", '-value' => 1, '-label' => ''),
+      'valign'   => 'center',
+      'align'    => 'center',
+    };
 
-  if (!$form->{callback}) {
-    $form->{callback} =
-      build_std_url("action=show_dunning", qw(customer_id customer dunning_level department_id invnumber ordnumber
-                                              ransdatefrom transdateto dunningfrom dunningto notes showold));
+    push @{ $current_dunning_rows }, $row;
+
+    $previous_dunning_id   = $ref->{dunning_id};
+    $first_row_for_dunning = 0;
   }
 
-  $form->get_lists('printers'  => 'printers',
-                   'languages' => 'languages');
+  $report->add_data($current_dunning_rows) if (scalar @{ $current_dunning_rows });
 
-  $form->{type}          = 'dunning';
-  $form->{PRINT_OPTIONS} = print_options({ 'inline'          => 1,
-                                           'no_queue'        => 1,
-                                           'no_postscript'   => 1,
-                                           'no_html'         => 1,
-                                           'no_opendocument' => 1, });
-  $form->{title}         = $locale->text('Dunning overview');
+  $report->set_options('raw_top_info_text'    => $form->parse_html_template('dunning/show_dunning_top'),
+                       'raw_bottom_info_text' => $form->parse_html_template('dunning/show_dunning_bottom'),
+                       'output_format'        => 'HTML',
+                       'attachment_basename'  => $locale->text('dunning_list') . strftime('_%Y%m%d', localtime time),
+    );
 
-  $form->header();
+  $report->set_options_from_form();
 
-  print $form->parse_html_template("dunning/show_dunning");
+  $report->generate_with_headers();
 
   $lxdebug->leave_sub();
 
@@ -364,4 +422,3 @@ sub print_multiple {
 }
 
 # end of main
-