Merge branch 'after-262'
[kivitendo-erp.git] / bin / mozilla / rp.pl
index 663a20e..1d84469 100644 (file)
@@ -85,6 +85,8 @@ use strict;
 # $locale->text('Trial Balance')
 # $locale->text('AR Aging')
 # $locale->text('AP Aging')
+# $locale->text('Search AR Aging')
+# $locale->text('Search AP Aging')
 # $locale->text('Tax collected')
 # $locale->text('Tax paid')
 # $locale->text('Receipts')
@@ -92,6 +94,7 @@ use strict;
 # $locale->text('Project Transactions')
 # $locale->text('Non-taxable Sales')
 # $locale->text('Non-taxable Purchases')
+# $locale->text('Business evaluation')
 
 # $form->parse_html_template('rp/html_report_susa')
 
@@ -107,10 +110,6 @@ my $rp_access_map = {
   'balance_sheet'    => 'report',
 };
 
-# subs use these pretty freely, so declare them here
-our (%column_data, @column_index);
-our ($subtotalnetamount, $subtotaltax, $subtotal);
-
 sub check_rp_access {
   my $form     = $main::form;
 
@@ -133,8 +132,8 @@ sub report {
             'balance_sheet'        => 'Balance Sheet',
             'income_statement'     => 'Income Statement',
             'trial_balance'        => 'Trial Balance',
-            'ar_aging'             => 'AR Aging',
-            'ap_aging'             => 'Offene Verbindlichkeiten',
+            'ar_aging'             => 'Search AR Aging',
+            'ap_aging'             => 'Search AP Aging',
             'tax_collected'        => 'Tax collected',
             'tax_paid'             => 'Tax paid',
             'nontaxable_sales'     => 'Non-taxable Sales',
@@ -142,13 +141,13 @@ sub report {
             'receipts'             => 'Receipts',
             'payments'             => 'Payments',
             'projects'             => 'Project Transactions',
-            'bwa'                  => 'Betriebswirtschaftliche Auswertung',
+            'bwa'                  => 'Business evaluation',
   );
 
   $form->{title} = $locale->text($title{ $form->{report} });
 
-  my $accrual = ($main::eur) ? ""        : "checked";
-  my $cash    = ($main::eur) ? "checked" : "";
+  my $accrual = $::lx_office_conf{system}->{eur} ? ""        : "checked";
+  my $cash    = $::lx_office_conf{system}->{eur} ? "checked" : "";
 
   my $year = (localtime)[5] + 1900;
 
@@ -266,14 +265,14 @@ sub report {
 
 <input type=hidden name=title value="$form->{title}">
 
-<table width=100%>
+<table width=100% border="0">
   <tr>
     <th class=listtop>$form->{title}</th>
   </tr>
   <tr height="5"></tr>
   <tr>
     <td>
-      <table>
+      <table border="0">
       $department
 |;
 
@@ -806,6 +805,18 @@ $jsscript
           <th align=right>| . $locale->text($label) . qq|</th>
           <td>$vc</td>
         </tr>
+        <tr>
+          <td>| . $locale->text('Review of Aging list') . qq|</td>
+          <td><select name="review_of_aging_list">
+              <option></option>
+              <option>0-30</option>
+              <option>30-60</option>
+              <option>60-90</option>
+              <option>90-120</option>
+              <option>> 120</option>
+              </select>
+          </td>
+        </tr>
         <tr>
           <td align=left colspan=4>| . $locale->text('From') . qq|&nbsp;
               $button1
@@ -1053,7 +1064,8 @@ sub generate_income_statement {
         last SWITCH;
       };
     }
-  }
+    hotfix_reformat_date();
+  } # Ende Bericht für vorgewählten Zeitraum (warum auch immer die Prüfung (custom eq true) ist ...
 
   RP->income_statement(\%myconfig, \%$form);
 
@@ -1283,6 +1295,7 @@ sub generate_trial_balance {
         last SWITCH;
       };
     }
+    hotfix_reformat_date();
   }
 
 
@@ -1357,6 +1370,7 @@ sub generate_trial_balance {
                        'pdf_template'         => 'rp/html_report_susa',
     );
   $report->set_options_from_form();
+  $locale->set_numberformat_wo_thousands_separator(\%myconfig) if lc($report->{options}->{output_format}) eq 'csv';
 
   # add sort and escape callback, this one we use for the add sub
   $form->{callback} = $href .= "&sort=$form->{sort}";
@@ -1371,7 +1385,7 @@ sub generate_trial_balance {
   my $edit_url = build_std_url('action=edit', 'type', 'vc');
 
   my $idx;
-  foreach my $accno (@{ $form->{TB} }) {
+  foreach my $accno (@{ $form->{TB} || [] }) {
 
     $accno->{soll} = $accno->{debit};
     $accno->{haben} = $accno->{credit};
@@ -1508,6 +1522,7 @@ sub list_accounts {
                        'std_column_visibility' => 1,
     );
   $report->set_options_from_form();
+  $locale->set_numberformat_wo_thousands_separator(\%myconfig) if lc($report->{options}->{output_format}) eq 'csv';
 
   $report->set_columns(%column_defs);
   $report->set_column_order(@columns);
@@ -1518,7 +1533,7 @@ sub list_accounts {
   my %subtotals      = map { $_ => 0 } @totals_columns;
   my %totals         = map { $_ => 0 } @totals_columns;
   my $found_heading  = 0;
-  my @tb             = sort { $a->{accno} cmp $b->{accno} } @{ $form->{TB} };
+  my @tb             = sort { $a->{accno} cmp $b->{accno} } @{ $form->{TB} || [] };
 
   # sort the whole thing by account numbers and display
   foreach my $idx (0 .. scalar(@tb) - 1) {
@@ -1708,6 +1723,8 @@ sub aging {
                        'title'                => $form->{title},
                        'attachment_basename'  => $attachment_basename . strftime('_%Y%m%d', localtime time),
     );
+  $report->set_options_from_form();
+  $locale->set_numberformat_wo_thousands_separator(\%myconfig) if lc($report->{options}->{output_format}) eq 'csv';
 
   my $previous_ctid = 0;
   my $row_idx       = 0;
@@ -1764,8 +1781,6 @@ sub aging {
                          'raw_bottom_info_text' => $raw_bottom_info_text);
   }
 
-  $report->set_options_from_form();
-
   $report->generate_with_headers();
 
   $main::lxdebug->leave_sub();
@@ -2056,7 +2071,7 @@ sub print_form {
         $form->{attachment_filename} =  $locale->quote_special_chars('filenames', $locale->text("Statement") . "_$form->{todate}.$attachment_suffix");
         $form->{attachment_filename} =~ s/\s+/_/g;
 
-        $form->parse_template(\%myconfig, $main::userspath);
+        $form->parse_template(\%myconfig);
 
       }
     }
@@ -2066,7 +2081,7 @@ sub print_form {
     $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
     $form->{addition} = "PRINTED";
     $form->{what_done} = $form->{type};
-    $form->save_history($form->dbconnect(\%myconfig));
+    $form->save_history;
   }
   # /saving the history
   $main::lxdebug->leave_sub();
@@ -2115,19 +2130,19 @@ sub generate_tax_report {
   my $descvar     = "$form->{accno}_description";
   my $description = $form->escape($form->{$descvar});
   my $ratevar     = "$form->{accno}_rate";
-  our $taxrate; # most likely error
+  my ($subtotalnetamount, $subtotaltax, $subtotal) = (0, 0, 0);
 
   my $department = $form->escape($form->{department});
 
   # construct href
   my $href =
-    "$form->{script}?&action=generate_tax_report&fromdate=$form->{fromdate}&todate=$form->{todate}&db=$form->{db}&method=$form->{method}&accno=$form->{accno}&$descvar=$description&department=$department&$ratevar=$taxrate&report=$form->{report}";
+    "$form->{script}?&action=generate_tax_report&fromdate=$form->{fromdate}&todate=$form->{todate}&db=$form->{db}&method=$form->{method}&accno=$form->{accno}&$descvar=$description&department=$department&report=$form->{report}";
 
   # construct callback
   $description = $form->escape($form->{$descvar},   1);
   $department  = $form->escape($form->{department}, 1);
   my $callback    =
-    "$form->{script}?&action=generate_tax_report&fromdate=$form->{fromdate}&todate=$form->{todate}&db=$form->{db}&method=$form->{method}&accno=$form->{accno}&$descvar=$description&department=$department&$ratevar=$taxrate&report=$form->{report}";
+    "$form->{script}?&action=generate_tax_report&fromdate=$form->{fromdate}&todate=$form->{todate}&db=$form->{db}&method=$form->{method}&accno=$form->{accno}&$descvar=$description&department=$department&report=$form->{report}";
 
   my $title = $form->escape($form->{title});
   $href .= "&title=$title";
@@ -2138,6 +2153,7 @@ sub generate_tax_report {
 
   my @columns =
     $form->sort_columns(qw(id transdate invnumber name netamount tax amount));
+  my @column_index;
 
   foreach my $item (@columns) {
     if ($form->{"l_$item"} eq "Y") {
@@ -2242,7 +2258,7 @@ sub generate_tax_report {
 
     if ($form->{l_subtotal} eq 'Y') {
       if ($sameitem ne $ref->{ $form->{sort} }) {
-        &tax_subtotal;
+        tax_subtotal(\@column_index, \$subtotalnetamount, \$subtotaltax, \$subtotal);
         $sameitem = $ref->{ $form->{sort} };
       }
     }
@@ -2258,6 +2274,7 @@ sub generate_tax_report {
       $ref->{$_} = $form->format_amount(\%myconfig, $ref->{$_}, 2, "&nbsp;");
     } qw(netamount tax amount);
 
+    my %column_data;
     $column_data{id}        = qq|<td>$ref->{id}</td>|;
     $column_data{invnumber} =
       qq|<td><a href=$module?action=edit&id=$ref->{id}&callback=$callback>$ref->{invnumber}</a></td>|;
@@ -2282,9 +2299,10 @@ sub generate_tax_report {
   }
 
   if ($form->{l_subtotal} eq 'Y') {
-    &tax_subtotal;
+    tax_subtotal(\@column_index, \$subtotalnetamount, \$subtotaltax, \$subtotal);
   }
 
+  my %column_data;
   map { $column_data{$_} = qq|<th>&nbsp;</th>| } @column_index;
 
   print qq|
@@ -2322,27 +2340,30 @@ sub generate_tax_report {
 sub tax_subtotal {
   $main::lxdebug->enter_sub();
 
+  my ($column_index, $subtotalnetamount, $subtotaltax, $subtotal) = @_;
+
   my $form     = $main::form;
   my %myconfig = %main::myconfig;
   my $locale   = $main::locale;
 
-  map { $column_data{$_} = "<td>&nbsp;</td>" } @column_index;
+  my %column_data;
+  map { $column_data{$_} = "<td>&nbsp;</td>" } @{ $column_index };
 
-  $subtotalnetamount = $form->format_amount(\%myconfig, $subtotalnetamount, 2, "&nbsp;");
-  $subtotaltax       = $form->format_amount(\%myconfig, $subtotaltax, 2, "&nbsp;");
-  $subtotal          = $form->format_amount(\%myconfig, $subtotalnetamount + $subtotaltax, 2, "&nbsp;");
+  $$subtotalnetamount = $form->format_amount(\%myconfig, $$subtotalnetamount, 2, "&nbsp;");
+  $$subtotaltax       = $form->format_amount(\%myconfig, $$subtotaltax, 2, "&nbsp;");
+  $$subtotal          = $form->format_amount(\%myconfig, $$subtotalnetamount + $$subtotaltax, 2, "&nbsp;");
 
-  $column_data{netamount} = "<th class=listsubtotal align=right>$subtotalnetamount</th>";
-  $column_data{tax}       = "<th class=listsubtotal align=right>$subtotaltax</th>";
-  $column_data{amount}    = "<th class=listsubtotal align=right>$subtotal</th>";
+  $column_data{netamount} = "<th class=listsubtotal align=right>$$subtotalnetamount</th>";
+  $column_data{tax}       = "<th class=listsubtotal align=right>$$subtotaltax</th>";
+  $column_data{amount}    = "<th class=listsubtotal align=right>$$subtotal</th>";
 
-  $subtotalnetamount = 0;
-  $subtotaltax       = 0;
+  $$subtotalnetamount = 0;
+  $$subtotaltax       = 0;
 
   print qq|
         <tr class=listsubtotal>
 |;
-  map { print "\n$column_data{$_}" } @column_index;
+  map { print "\n$column_data{$_}" } @{ $column_index };
 
   print qq|
         </tr>
@@ -2416,6 +2437,8 @@ sub list_payments {
     );
   $report->set_options_from_form();
 
+  $locale->set_numberformat_wo_thousands_separator(\%myconfig) if lc($report->{options}->{output_format}) eq 'csv';
+
   $report->set_columns(%column_defs);
   $report->set_column_order(@columns);
 
@@ -2519,14 +2542,14 @@ sub print_options {
   } else {
     $media = qq|
             <option value=screen $form->{OP}{screen}>| . $locale->text('Screen');
-    if ($myconfig{printer} && $main::latex_templates) {
+    if ($myconfig{printer} && $::lx_office_conf{print_templates}->{latex}) {
       $media .= qq|
             <option value=printer $form->{OP}{printer}>| . $locale->text('Printer');
     }
   }
 
   my $format;
-  if ($main::latex_templates) {
+  if ($::lx_office_conf{print_templates}->{latex}) {
     $format .= qq|
             <option value=html $form->{DF}{html}>| . $locale->text('HTML')
       . qq| <option value=pdf $form->{DF}{pdf}>| . $locale->text('PDF')
@@ -2541,7 +2564,7 @@ sub print_options {
     <td><select name=media>$media</select></td>
 |;
 
-  if ($myconfig{printer} && $main::latex_templates && $form->{media} ne 'email') {
+  if ($myconfig{printer} && $::lx_office_conf{print_templates}->{latex} && $form->{media} ne 'email') {
     $output .= qq|
       <td>| . $locale->text('Copies') . qq|
       <input name=copies size=2 value=$form->{copies}></td>
@@ -2707,6 +2730,7 @@ sub generate_bwa {
         last SWITCH;
       };
     }
+    hotfix_reformat_date();
   } else {
     # die konvertierungen nur dann durchführen, wenn auch daten gesetzt sind.
     # ansonsten ist die prüfung in RP.pm
@@ -2714,12 +2738,12 @@ sub generate_bwa {
     # immer wahr
     if ($form->{fromdate}){
       my ($yy, $mm, $dd) = $locale->parse_date(\%myconfig, $form->{fromdate});
-      $form->{fromdate} = "${dd}.${mm}.${yy}";
-      $form->{comparefromdate} = "01.01.$yy";
+      my $datetime = $locale->parse_date_to_object(\%myconfig, $form->{fromdate});
+      $datetime->set( month      => 1,
+                      day        => 1);
+      $form->{comparefromdate} = $locale->format_date(\%::myconfig, $datetime);
     }
     if ($form->{todate}){
-      my ($yy, $mm, $dd) = $locale->parse_date(\%myconfig, $form->{todate});
-      $form->{todate}          = "${dd}.${mm}.${yy}";
       $form->{comparetodate}   = $form->{todate};
     }
   }
@@ -2766,5 +2790,32 @@ sub generate_bwa {
 
   $main::lxdebug->leave_sub();
 }
+###
+# Hotfix, um das Datumsformat, die unten hart auf deutsches Datumsformat eingestellt
+# sind, entsprechend mit anderem Formaten (z.B. iso-kodiert) zum Laufen zu bringen (S.a.: Bug 1388)
+sub hotfix_reformat_date {
 
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
+
+  if ($myconfig{dateformat} ne 'dd.mm.yyyy'){
+    my $current_dateformat = $myconfig{dateformat};
+    $myconfig{dateformat} = 'dd.mm.yyyy';
+    $form->{fromdate} = $main::locale->reformat_date(\%myconfig, $form->{fromdate}, $current_dateformat);
+    $form->{todate} = $main::locale->reformat_date(\%myconfig, $form->{todate}, $current_dateformat);
+    $form->{comparefromdate} = $main::locale->reformat_date(\%myconfig, $form->{comparefromdate}, $current_dateformat)
+      unless (!defined ($form->{comparefromdate}));
+    $form->{comparetodate} = $main::locale->reformat_date(\%myconfig, $form->{comparetodate}, $current_dateformat)
+      unless (!defined ($form->{comparetodate}));
+
+    # Und wieder zurücksetzen
+    $myconfig{dateformat} =  $current_dateformat; #'dd.mm.yyyy';
+  } # Ende Hotifx Bug 1388
+
+  $main::lxdebug->leave_sub();
+
+}
 1;