epic-ts
[kivitendo-erp.git] / bin / mozilla / ustva.pl
index 89818c9..b66fead 100644 (file)
@@ -1,5 +1,5 @@
 #=====================================================================
-# Lx-Office ERP
+# kivitendo ERP
 # Copyright (c) 2004 by Udo Spallek, Aachen
 #
 #  Author: Udo Spallek
@@ -21,6 +21,7 @@
 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 #======================================================================
 # German Tax authority Module and later ELSTER Interface
+# 08.01.14  ELSTER Interface software (taxbird/winston) removed
 #======================================================================
 
 use strict;
@@ -38,6 +39,7 @@ require "bin/mozilla/common.pl";
 
 use List::Util qw(first);
 
+use SL::DB::Default;
 use SL::PE;
 use SL::RP;
 use SL::USTVA;
@@ -83,6 +85,7 @@ sub report {
 
   $::auth->assert('advance_turnover_tax_return');
 
+  my $defaults   = SL::DB::Default->get;
   $form->{title} = $locale->text('UStVA');
   $form->{kz10}  = '';                       #Berichtigte Anmeldung? Ja =1 Nein=0
 
@@ -100,19 +103,20 @@ sub report {
   # Hier Einlesen der user-config
   # steuernummer entfernt für prerelease
   my @a = qw(
-    signature      name          company       address        businessnumber
+    signature      name
     tel            fax           email         co_chief       co_department
     co_custom1     co_custom2    co_custom3    co_custom4     co_custom5
     co_name1       co_name2      co_street     co_street1     co_zip
     co_city        co_city1      co_country    co_tel         co_tel1
     co_tel2        co_fax        co_fax1       co_email       co_email1
-    co_url         co_url1       ustid         duns           co_bankname
+    co_url         co_url1       co_bankname
     co_bankname1   co_bankname2  co_bankname3  co_blz         co_blz1
     co_blz2        co_blz3       co_accountnr  co_accountnr1  co_accountnr2
     co_accountnr3
   );
 
-  map { $form->{$_} = $myconfig{$_} } @a;
+  $form->{$_} = $myconfig{$_} for @a;
+  $form->{$_} = $defaults->$_ for qw(company address co_ustid duns);
 
   my $openings = $form->{FA_Oeffnungszeiten};
   $openings =~ s/\\\\n/<br>/g;
@@ -192,14 +196,14 @@ sub report {
 
   # Which COA is in use?
 
-  $ustva->get_coa($form, \%myconfig);
+  $ustva->get_coa($form); # fetches coa and modifies some form variables
 
   my $template_ref = {
     openings         => $openings,
     company_given    => $company_given,
     address_given    => $address_given,
     taxnumber_given  => $taxnumber_given,
-    taxnumber        => $myconfig{taxnumber},
+    taxnumber        => $defaults->taxnumber,
     select_year      => $select_year,
     period_local     => $period_local,
     method_local     => $method_local,
@@ -225,14 +229,12 @@ sub help {
   $::auth->assert('advance_turnover_tax_return');
 
   # parse help documents under doc
-  my $tmp = $::form->{templates};
   $::form->{templates} = 'doc';
   $::form->{help}      = 'ustva';
   $::form->{type}      = 'help';
   $::form->{format}    = 'html';
   generate_ustva();
 
-  #$form->{templates} = $tmp;
   $::lxdebug->leave_sub();
 }
 
@@ -501,28 +503,9 @@ sub show_options {
   my $media  = qq|      <input type=hidden name="media" value="screen">|;
   my $format =
       qq|       <option value=html selected>|
-    . $::locale->text('Preview')
+    . $::locale->text('HTML')
     . qq|</option>|;
-  if ($::lx_office_conf{print_templates}{latex}) {
-    $format .=
-        qq|    <option value=pdf>|
-      . $::locale->text('UStVA (PDF-Dokument)')
-      . qq|</option>|;
-  }
-
-  #my $disabled= qq|disabled="disabled"|;
-  #$disabled='' if ($form->{elster} eq '1' );
-  if ($::form->{elster} eq '1') {
-    $format .=
-        qq|<option value=elsterwinston>|
-      . $::locale->text('ELSTER Export (Winston)')
-      . qq|</option>|
-      . qq|<option value=elstertaxbird>|
-      . $::locale->text('ELSTER Export (Taxbird)')
-      . qq|</option>|;
-  }
 
-  #$format .= qq|<option value=elster>|.$locale->text('ELSTER Export nach Winston').qq|</option>|;
   my $show_options = qq|
     $type
     $media
@@ -543,6 +526,10 @@ sub generate_ustva {
 
   $::auth->assert('advance_turnover_tax_return');
 
+  my $defaults = SL::DB::Default->get;
+  $form->error($::locale->text('No print templates have been created for this client yet. Please do so in the client configuration.')) if !$defaults->templates;
+  $form->{templates} = $defaults->templates;
+
   # Aufruf von get_config zum Einlesen der Finanzamtdaten aus finanzamt.ini
 
   my $ustva = USTVA->new();
@@ -738,14 +725,15 @@ sub generate_ustva {
     $locale->date(\%myconfig, $form->current_date(\%myconfig), 0, 0, 0);
 
   # setup variables for the form
-  my @a = qw(company businessnumber tel fax email
+  my @a = qw(tel fax email
     co_chief co_department co_custom1 co_custom2 co_custom3 co_custom4 co_custom5
     co_name1 co_name2  co_street co_street1 co_zip co_city co_city1 co_country co_tel co_tel1 co_tel2
-    co_fax co_fax1 co_email co_email1 co_url co_url1 ustid duns
+    co_fax co_fax1 co_email co_email1 co_url co_url1
     co_bankname co_bankname1 co_bankname2 co_bankname3 co_blz co_blz1
     co_blz2 co_blz3 co_accountnr co_accountnr1 co_accountnr2 co_accountnr3);
 
-  map { $form->{$_} = $myconfig{$_} } @a;
+  $form->{$_} = $myconfig{$_} for @a;
+  $form->{$_} = $defaults->$_ for qw(company address co_ustid duns);
 
   if ($form->{address} ne '') {
     my $temp = $form->{address};
@@ -776,7 +764,7 @@ sub generate_ustva {
         dec_places  => '2',
     });
 
-    push @category_cent, qw(83  Z43  Z45  Z53  Z62  Z65  Z67);
+    push @category_cent, qw(Z43  Z45  Z53  Z62  Z65  Z67);
 
     my @category_euro = $ustva->report_variables({
         myconfig    => \%myconfig,
@@ -827,181 +815,6 @@ sub generate_ustva {
       foreach my $number (@category_euro) {
         $form->{$number} = $form->format_amount(\%myconfig, $form->{$number}, '0', '0');
       }
-
-    } elsif ( $form->{format} eq 'elsterwinston' ) {
-
-      $form->{IN} = 'winston.xml';
-
-      #
-      # Build Winston filename
-      #
-
-      my $file = 'U';     # 1. char 'U' = USTVA
-      $file .= $form->{period};
-      #4. and 5. char = year modulo 100
-      $file .= sprintf("%02d", $form->{year} % 100);
-      #6. to 18. char = Elstersteuernummer
-      #Beispiel: Steuernummer in Bayern
-      #111/222/33334 ergibt für UStVA Jan 2004: U01049111022233334
-      $file .= $form->{elsterFFFF};
-      $file .= $form->{elstersteuernummer};
-      #file suffix
-      $file .= '.xml';
-      $file =~ s|.*/||;
-
-      $form->{attachment_filename} = $file;
-
-      # Zahlenformatierung für Winston
-
-      my $temp_numberformat = $myconfig{numberformat};
-
-      # Numberformat must be '1000,00' for Winston
-
-      $myconfig{numberformat} = '1000,00';
-
-      foreach my $number (@category_cent) {
-        $form->{$number} = ( $form->{$number} !=0 ) ? $form->format_amount(\%myconfig, $form->{$number}, '2', '') : '';
-      }
-
-      foreach my $number (@category_euro) {
-        $form->{$number} = ( $form->{$number} !=0 ) ? $form->format_amount(\%myconfig, $form->{$number}, '0', '') : '';
-      }
-      # Re-set Numberformat
-      $myconfig{numberformat} = $temp_numberformat;
-
-      # push Kennziffern to <%foreach Array fo easyer
-      # output in xml format. Thx to Moritz.
-      my %winston_id_for = (
-         # No Winston remap?!
-      );
-
-      foreach my $kennziffer (@category_cent, @category_euro) {
-
-        next if ( $kennziffer =~ m/Z\d\d/);
-        next if (   $form->{$kennziffer} == 0 );
-
-        if (defined $winston_id_for{$kennziffer} ) {
-          push(@{ $form->{id}}, $winston_id_for{$kennziffer});
-        } else {
-          push(@{ $form->{id}}, "Kz$kennziffer");
-        }
-        push(@{ $form->{amount}}, $form->{$kennziffer});
-      }
-
-    } elsif ( $form->{format} eq 'elstertaxbird' ) {
-
-      # Define serveral filenames
-      $form->{IN} = 'taxbird.txb';
-
-      $form->{attachment_filename} = "USTVA-" . ($form->{period} * 1) . sprintf("%02d", $form->{year} % 100) . ".txb";
-
-      $form->{attachment_filename} =~ s|.*/||;
-
-      # TODO: set Output to UTF-8 or system Preference
-      #$form->{"iconv"} = Text::Iconv->new($myconfig{dbcharset}, "UTF-8");
-      #my $iconv = $self->{"iconv"};
-      #$iconv->convert($variable);
-      if ($form->{period} =~ /^[4]\d$/ ){
-        my %periods = ( # Lx => taxbird
-                     '41' => '12',
-                     '42' => '13',
-                     '43' => '14',
-                     '44' => '15',
-                   );
-
-        foreach my $quarter ( keys %periods ) {
-          $form->{taxbird_period} = $periods{$quarter} if ( $form->{period} eq $quarter);
-        }
-      } elsif ($form->{period} =~ /^\d+$/ ) {
-        $form->{period} =~ s/^0//g;
-        my $period = $form->{period};
-        $period *= 1;
-        $period--;
-        $form->{taxbird_period} = $period;
-      } else {
-        $form->header;
-        USTVA::error( $locale->text('Wrong Period' ));
-        ::end_of_request();
-      }
-
-      # heuristics for address splitting
-      # lx-office holds the entire address in a single field.
-      # taxbird expects it to be splitted into street, zipcode and city
-      if ($form->{co_street} =~ /\n/) {
-        my $new_co_street;
-        for (split /\n/, $form->{co_street}) {
-          if (/(\d{3,5})\s+(\w+)/) {
-            $form->{co_zip}  = $1;
-            $form->{co_city} = $2;
-          } else {
-            $new_co_street .= $_;
-          }
-        }
-        $form->{co_street} = $new_co_street;
-      } else {
-        $form->{co_zip} = $form->{co_city};
-        $form->{co_zip} =~ s/\D//g;
-        $form->{co_city} =~ s/\d//g;
-        $form->{co_city} =~ s/^\s//g;
-      }
-
-      my $tax_office           = first { $_->{name} eq $form->{elsterland} } @{ $ustva->{tax_office_information} };
-      $form->{taxbird_land_nr} = $tax_office->{taxbird_nr} if $tax_office;
-
-      ($form->{co_phone_prefix}, $form->{co_phone}) = split("-", $form->{tel});
-      $form->{co_phone_prefix} =~ s/\s//g;
-      $form->{co_phone} =~ s/\s//g;
-
-       $form->{taxbird_steuernummer} = $form->{steuernummer};
-      #      $form->{taxbird_steuernummer} =~ s/\D//g;
-#      $form->{taxbird_steuernummer} =~ s/\///; # ersten Querstrich ersetzen
-
-      # Numberformatting for Taxbird
-      my $temp_numberformat = $myconfig{numberformat};
-      # Numberformat must be '1000,00' for Taxbird ?!
-      $myconfig{numberformat} = '1000,00';
-      foreach my $number (@category_cent) {
-        $form->{$number} = ( $form->{$number} !=0 ) ? $form->format_amount(\%myconfig, $form->{$number}, '2', '') : '';
-      }
-
-      foreach my $number (@category_euro) {
-        $form->{$number} = ( $form->{$number} !=0 ) ? $form->format_amount(\%myconfig, $form->{$number}, '0', '') : '';
-      }
-      # Re-set Numberformat
-      $myconfig{numberformat} = $temp_numberformat;
-
-      # push Kennziffern to <%foreach Array fo easyer
-      # output in xml format. Thx to Moritz.
-      my %taxbird_id_for = (
-
-          '511'  =>  'Kz51-calc',
-          '861'  =>  'Kz86-calc',
-          '971'  =>  'Kz97-calc',
-          '931'  =>  'Kz93-calc',
-          '811'  =>  'Kz81-calc',
-          '891'  =>  'Kz89-calc',
-          'Z45'  =>  'uebertrag',
-          'Z53'  =>  'ust-sum',
-          'Z62'  =>  'ust-minus-vost',
-          'Z65'  =>  'ust-sum+69',
-          'Z67'  =>  'ust-vz',
-      );
-
-
-      for my $kennziffer (@category_cent, @category_euro) {
-
-        next if ($kennziffer eq 'Z43');
-
-        if ($form->{$kennziffer} != 0){
-          if (defined $taxbird_id_for{$kennziffer}) {
-            push(@{ $form->{id}}, $taxbird_id_for{$kennziffer});
-          } else {
-            push(@{ $form->{id}}, "Kz$kennziffer");
-          }
-          push(@{ $form->{amount}}, $form->{$kennziffer});
-        }
-      }
-
     } elsif ( $form->{format} eq '' ){ # No format error.
       $form->header;
       USTVA::error( $locale->text('Application Error. No Format given' ) . "!");
@@ -1060,7 +873,6 @@ sub generate_ustva {
       . '!');
   }
 
-  $form->{templates} = $myconfig{templates};
   $form->{templates} = "doc" if ( $form->{type} eq 'help' );
 
   if ($form->{format} eq 'generic'){
@@ -1068,15 +880,20 @@ sub generate_ustva {
     $form->header();
 
     my $template_ref = {
-        taxnumber => $myconfig{taxnumber},
+        taxnumber => $defaults->taxnumber,
     };
 
     print($form->parse_html_template('ustva/generic_taxreport', $template_ref));
 
   } else
   {
+   # add a prefix for ustva pos numbers, i.e.: 81 ->  post_ustva_81
+   $form->{"pos_ustva_$_"} = $form->{$_} for grep { m{^\d+} } keys %{ $form };
+   $form->{title} = $locale->text('Advance turnover tax return');
+
+   $form->header;
+   print $form->parse_html_template('ustva/ustva');
 
-    $form->parse_template(\%myconfig, $::lx_office_conf{paths}{userspath});
 
   }
 
@@ -1143,7 +960,7 @@ $::form->{title} = $::locale->text('Tax Office Preferences');
 
 # Which COA is in use?
 
-  $ustva->get_coa($::form, \%::myconfig);
+  $ustva->get_coa($::form); # fetches coa and modifies some form variables
 
   # hä? kann die weg?
   my $steuernummer_new = '';
@@ -1177,10 +994,6 @@ sub config_step2 {
 
   $form->header();
 
-#  print qq|
-#    <body>
-#  |;
-
   my $elsterland         = '';
   my $elster_amt         = '';
   my $elsterFFFF         = '';
@@ -1253,7 +1066,7 @@ sub config_step2 {
   $form->{FA_Oeffnungszeiten} =~ s/\\\\n/\n/g;
 
 
-  $ustva->get_coa($form, \%myconfig);
+  $ustva->get_coa($form); # fetches coa and modifies some form variables
 
   my $input_steuernummer = $ustva->steuernummer_input(
                              $form->{elsterland},
@@ -1355,7 +1168,7 @@ sub save {
 
   $::auth->assert('advance_turnover_tax_return');
 
-  my $filename = "$::form->{login}_$::form->{filename}";
+  my $filename = "$::myconfig{login}_$::form->{filename}";
   $filename =~ s|.*/||;
 
   #zuerst die steuernummer aus den part, parts_X_Y und delimiter herstellen
@@ -1430,4 +1243,3 @@ sub back {
   call_sub($::form->{"lastsub"});
   $::lxdebug->leave_sub();
 }
-