1 #=====================================================================
 
   3 # Copyright (c) 2004 by Udo Spallek, Aachen
 
   7 #     Web: http://www.lx-office.org
 
  10 # This program is free software; you can redistribute it and/or modify
 
  11 # it under the terms of the GNU General Public License as published by
 
  12 # the Free Software Foundation; either version 2 of the License, or
 
  13 # (at your option) any later version.
 
  15 # This program is distributed in the hope that it will be useful,
 
  16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 
  17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
  18 # GNU General Public License for more details.
 
  19 # You should have received a copy of the GNU General Public License
 
  20 # along with this program; if not, write to the Free Software
 
  21 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
  22 #======================================================================
 
  23 # German Tax authority Module and later ELSTER Interface
 
  24 # 08.01.14  ELSTER Interface software (taxbird/winston) removed
 
  25 #======================================================================
 
  30 require "bin/mozilla/common.pl";
 
  35 #use warnings; # FATAL=> 'all';
 
  36 #use vars qw($locale $form %myconfig);
 
  38 #use CGI::Carp "fatalsToBrowser";
 
  40 use List::Util qw(first);
 
  49 # this is for our long dates
 
  50 # $locale->text('January')
 
  51 # $locale->text('February')
 
  52 # $locale->text('March')
 
  53 # $locale->text('April')
 
  54 # $locale->text('May ')
 
  55 # $locale->text('June')
 
  56 # $locale->text('July')
 
  57 # $locale->text('August')
 
  58 # $locale->text('September')
 
  59 # $locale->text('October')
 
  60 # $locale->text('November')
 
  61 # $locale->text('December')
 
  63 # this is for our short month
 
  64 # $locale->text('Jan')
 
  65 # $locale->text('Feb')
 
  66 # $locale->text('Mar')
 
  67 # $locale->text('Apr')
 
  68 # $locale->text('May')
 
  69 # $locale->text('Jun')
 
  70 # $locale->text('Jul')
 
  71 # $locale->text('Aug')
 
  72 # $locale->text('Sep')
 
  73 # $locale->text('Oct')
 
  74 # $locale->text('Nov')
 
  75 # $locale->text('Dec')
 
  77 #############################
 
  80   $::lxdebug->enter_sub();
 
  83   my $locale   = $::locale;
 
  84   my %myconfig = %::myconfig;
 
  86   $::auth->assert('advance_turnover_tax_return');
 
  88   my $defaults   = SL::DB::Default->get;
 
  89   $form->{title} = $locale->text('UStVA');
 
  90   $form->{kz10}  = '';                       #Berichtigte Anmeldung? Ja =1 Nein=0
 
  92   my $year = substr($form->datetonum($form->current_date(\%myconfig), \%myconfig ),
 
  99   # Einlesen der Finanzamtdaten
 
 100   my $ustva = USTVA->new();
 
 101   $ustva->get_config($::lx_office_conf{paths}{userspath}, 'finanzamt.ini');
 
 103   # Hier Einlesen der user-config
 
 104   # steuernummer entfernt für prerelease
 
 107     tel            fax           email         co_chief       co_department
 
 108     co_custom1     co_custom2    co_custom3    co_custom4     co_custom5
 
 109     co_name1       co_name2      co_street     co_street1     co_zip
 
 110     co_city        co_city1      co_country    co_tel         co_tel1
 
 111     co_tel2        co_fax        co_fax1       co_email       co_email1
 
 112     co_url         co_url1       co_bankname
 
 113     co_bankname1   co_bankname2  co_bankname3  co_blz         co_blz1
 
 114     co_blz2        co_blz3       co_accountnr  co_accountnr1  co_accountnr2
 
 118   $form->{$_} = $myconfig{$_} for @a;
 
 119   $form->{$_} = $defaults->$_ for qw(company address co_ustid duns);
 
 121   my $openings = $form->{FA_Oeffnungszeiten};
 
 122   $openings =~ s/\\\\n/<br>/g;
 
 124   my $company_given = ($form->{company} ne '')
 
 125     ? qq|<h3>$form->{company}</h3>\n|
 
 126     : qq|<a href="am.pl?action=config">|
 
 127       . $locale->text('No Company Name given') . qq|!</a><br>|;
 
 130   # Anpassungen der Variablennamen auf pre 2.1.1 Namen
 
 131   # klären, ob $form->{company_street|_address} gesetzt sind
 
 132   if ($form->{address} ne '') {
 
 133     my $temp = $form->{address};
 
 134     $temp =~ s/\n/<br \/>/;
 
 135     ($form->{co_street}, $form->{co_city}) = split("<br \/>", $temp);
 
 136     $form->{co_city} =~ s/\n//g;
 
 141     ($form->{co_street} && ($form->{co_zip} || $form->{co_city}))
 
 142     ? qq|$form->{co_street}<br>|
 
 143         . qq|$form->{co_street1}<br>|
 
 144         . qq|$form->{co_zip} $form->{co_city}|
 
 145     : qq|<a href="am.pl?action=config|
 
 146         . qq|&level=Programm--Preferences">|
 
 147         . $locale->text('No Company Address given')
 
 150   $form->{co_email} = $form->{email} unless $form->{co_email};
 
 151   $form->{co_tel}   = $form->{tel}   unless $form->{co_tel};
 
 152   $form->{co_fax}   = $form->{fax}   unless $form->{co_fax};
 
 153   $form->{co_url}   = $form->{urlx}  unless $form->{co_url};
 
 155   my $taxnumber_given = ($form->{steuernummer} ne '') ? $form->{steuernummer} : qq|<a href="ustva.pl?action=config_step1">Keine Steuernummer hinterlegt!</a><br>|;
 
 157   my $ustva_vorauswahl = &ustva_vorauswahl();
 
 159   my @all_years = $form->all_years(\%myconfig);
 
 161   my $select_year = qq|<select name=year title="|
 
 162     . $locale->text('Year') . qq|">|;
 
 163   foreach my $key (@all_years) {
 
 164     $select_year .= qq|<option |;
 
 165     $select_year .= qq|selected| if ($key eq $form->{year});
 
 166     $select_year .= qq| >$key</option>|;
 
 168   $select_year   .=  qq|</select>|;
 
 171   $_checked = "checked" if ($form->{kz10} eq '1');
 
 172   my $checkbox_kz_10 = qq|<input name="FA_10" id=FA_10 class=checkbox|
 
 173     . qq| type=checkbox value="1" $_checked title = "|
 
 174     . $locale->text('Amended Advance Turnover Tax Return (Nr. 10)')
 
 176     . $locale->text('Amended Advance Turnover Tax Return');
 
 178   my $method_local = ($form->{method} eq 'accrual') ? $locale->text('accrual')
 
 179                    : ($form->{method} eq 'cash')    ? $locale->text('cash')
 
 182   my $period_local = ( $form->{FA_voranmeld} eq 'month')   ? $locale->text('month')
 
 183                    : ( $form->{FA_voranmeld} eq 'quarter') ? $locale->text('quarter')
 
 186   my $tax_office_banks_ref = [
 
 187     { BLZ             => $form->{FA_BLZ_1},
 
 188       Kontonummer     => $form->{FA_Kontonummer_1},
 
 189       Bankbezeichnung => $form->{FA_Bankbezeichnung_1}
 
 191     { BLZ             => $form->{FA_BLZ_2},
 
 192       Kontonummer     => $form->{FA_Kontonummer_2},
 
 193       Bankbezeichnung => $form->{FA_Bankbezeichnung_oertlich}
 
 197   # Which COA is in use?
 
 199   $ustva->get_coa($form); # fetches coa and modifies some form variables
 
 202     openings         => $openings,
 
 203     company_given    => $company_given,
 
 204     address_given    => $address_given,
 
 205     taxnumber_given  => $taxnumber_given,
 
 206     taxnumber        => $defaults->taxnumber,
 
 207     select_year      => $select_year,
 
 208     period_local     => $period_local,
 
 209     method_local     => $method_local,
 
 210     ustva_vorauswahl => $ustva_vorauswahl,
 
 211     checkbox_kz_10   => $checkbox_kz_10,
 
 212     tax_office_banks => $tax_office_banks_ref,
 
 213     select_options   => &show_options,
 
 217   print($form->parse_html_template('ustva/report', $template_ref));
 
 221   $::lxdebug->leave_sub();
 
 227   $::lxdebug->enter_sub();
 
 229   $::auth->assert('advance_turnover_tax_return');
 
 231   # parse help documents under doc
 
 232   $::form->{templates} = 'doc';
 
 233   $::form->{help}      = 'ustva';
 
 234   $::form->{type}      = 'help';
 
 235   $::form->{format}    = 'html';
 
 238   $::lxdebug->leave_sub();
 
 242   $::lxdebug->enter_sub();
 
 244   $::auth->assert('advance_turnover_tax_return');
 
 247   $::lxdebug->leave_sub();
 
 248   call_sub($::form->{"nextsub"});
 
 251 sub ustva_vorauswahl {
 
 252   $::lxdebug->enter_sub();
 
 255   my $locale   = $::locale;
 
 256   my %myconfig = %::myconfig;
 
 258   $::auth->assert('advance_turnover_tax_return');
 
 260   my $select_vorauswahl;
 
 262   #Aktuelles Datum zerlegen:
 
 263   my $date = $form->datetonum($form->current_date(\%myconfig), \%myconfig);
 
 265   #$locale->date($myconfig, $form->current_date($myconfig), 0)=~ /(\d\d).(\d\d).(\d\d\d\d)/;
 
 266   $form->{day}   = substr($date, 6, 2);
 
 267   $form->{month} = substr($date, 4, 2);
 
 268   $form->{year}  = substr($date, 0, 4);
 
 269   $::lxdebug->message(LXDebug->DEBUG1, qq|
 
 270     Actual date from Database: $date\n
 
 271     Actual year from Database: $form->{year}\n
 
 272     Actual day from Database: $form->{day}\n
 
 273     Actual month from Database: $form->{month}\n|);
 
 278   # Testdaten erzeugen:
 
 280   #$form->{month}= '01';
 
 281   #$form->{year}= 2004;
 
 282   $select_vorauswahl = qq|
 
 283      <input type=hidden name=day value=$form->{day}>
 
 284      <input type=hidden name=month value=$form->{month}>
 
 285      <input type=hidden name=yymmdd value=$yymmdd>
 
 286      <input type=hidden name=sel value=$sel>
 
 289   if ($form->{FA_voranmeld} eq 'month') {
 
 291     # Vorauswahl bei monatlichem Voranmeldungszeitraum
 
 293     my %liste = ('01' => $locale->text('January'),
 
 294                  '02' => $locale->text('February'),
 
 295                  '03' => $locale->text('March'),
 
 296                  '04' => $locale->text('April'),
 
 297                  '05' => $locale->text('May'),
 
 298                  '06' => $locale->text('June'),
 
 299                  '07' => $locale->text('July'),
 
 300                  '08' => $locale->text('August'),
 
 301                  '09' => $locale->text('September'),
 
 302                  '10' => $locale->text('October'),
 
 303                  '11' => $locale->text('November'),
 
 304                  '12' => $locale->text('December'),
 
 305                  '13' => $locale->text('Yearly'),
 
 308     my $yy = $form->{year} * 10000;
 
 309     $yymmdd = "$form->{year}$form->{month}$form->{day}" * 1;
 
 313     # Offset für Dauerfristverlängerung
 
 314     $dfv = '100' if ($form->{FA_dauerfrist} eq '1');
 
 317       $yymmdd <= ($yy + 110 + $dfv) && do {
 
 318         $form->{year} = $form->{year} - 1;
 
 322       $yymmdd <= ($yy + 210 + $dfv) && do {
 
 326       $yymmdd <= ($yy + 310 + $dfv) && do {
 
 330       $yymmdd <= ($yy + 410 + $dfv) && do {
 
 334       $yymmdd <= ($yy + 510 + $dfv) && do {
 
 338       $yymmdd <= ($yy + 610 + $dfv) && do {
 
 342       $yymmdd <= ($yy + 710 + $dfv) && do {
 
 346       $yymmdd <= ($yy + 810 + $dfv) && do {
 
 350       $yymmdd <= ($yy + 910 + $dfv) && do {
 
 354       $yymmdd <= ($yy + 1010 + $dfv) && do {
 
 358       $yymmdd <= ($yy + 1110 + $dfv) && do {
 
 362       $yymmdd <= ($yy + 1210) && do {
 
 366       $yymmdd <= ($yy + 1231) && do {
 
 372     $select_vorauswahl .= qq|<select id="zeitraum" name="period" title="|
 
 373   . $locale->text('Select a period') . qq|" >|;
 
 376     foreach $key (sort keys %liste) {
 
 378       $selected = 'selected' if ($sel eq $key);
 
 379       $select_vorauswahl .= qq|
 
 380          <option value="$key" $selected> $liste{$key}</option>
 
 383     $select_vorauswahl .= qq|</select>|;
 
 385   } elsif ($form->{FA_voranmeld} eq 'quarter') {
 
 387     # Vorauswahl bei quartalsweisem Voranmeldungszeitraum
 
 388     my %liste = ('41'  => $locale->text('1. Quarter'),
 
 389                  '42'  => $locale->text('2. Quarter'),
 
 390                  '43'  => $locale->text('3. Quarter'),
 
 391                  '44'  => $locale->text('4. Quarter'),
 
 392                  '13' => $locale->text('Yearly'),);
 
 394     my $yy = $form->{year} * 10000;
 
 395     $yymmdd = "$form->{year}$form->{month}$form->{day}" * 1;
 
 397     my $dfv = '';    # Offset für Dauerfristverlängerung
 
 398     $dfv = '100' if ($form->{FA_dauerfrist} eq '1');
 
 401       $yymmdd <= ($yy + 110 + $dfv) && do {
 
 402         $form->{year} = $form->{year} - 1;
 
 406       $yymmdd <= ($yy + 410 + $dfv) && do {
 
 410       $yymmdd <= ($yy + 710 + $dfv) && do {
 
 414       $yymmdd <= ($yy + 1010 + $dfv) && do {
 
 418       $yymmdd <= ($yy + 1231) && do {
 
 423     $select_vorauswahl .= qq|<select id="zeitraum" name="period" title="|
 
 424       . $locale->text('Select a period') . qq|" >|;
 
 426     foreach $key (sort keys %liste) {
 
 428       $selected = 'selected' if ($sel eq $key);
 
 429       $select_vorauswahl .= qq|
 
 430          <option value="$key" $selected>$liste{$key}</option>
 
 433     $select_vorauswahl .= qq|\n</select>
 
 438     # keine Vorauswahl bei Voranmeldungszeitraum
 
 439     $select_vorauswahl .= qq|<select id="zeitraum" name="period" title="|
 
 440       . $locale->text('Select a period') . qq|" >|;
 
 442     my %listea = ('41' => '1. Quarter',
 
 443                   '42' => '2. Quarter',
 
 444                   '43' => '3. Quarter',
 
 445                   '44' => '4. Quarter',);
 
 447     my %listeb = ('01' => 'January',
 
 461     foreach $key (sort keys %listea) {
 
 462       $select_vorauswahl .= qq|
 
 463          <option value="$key">|
 
 464         . $locale->text("$listea{$key}")
 
 468     foreach $key (sort keys %listeb) {
 
 469       $select_vorauswahl .= qq|
 
 470          <option value="$key">|
 
 471         . $locale->text("$listeb{$key}")
 
 474     $select_vorauswahl .= qq|</select>|;
 
 476   $::lxdebug->leave_sub();
 
 478   return $select_vorauswahl;
 
 482 #  $::lxdebug->enter_sub();
 
 484 #  $::lxdebug->leave_sub();
 
 488   $::lxdebug->enter_sub();
 
 490   $::lxdebug->leave_sub();
 
 494   $::lxdebug->enter_sub();
 
 496   $::auth->assert('advance_turnover_tax_return');
 
 498   #  $form->{PD}{$form->{type}} = "selected";
 
 499   #  $form->{DF}{$form->{format}} = "selected";
 
 500   #  $form->{OP}{$form->{media}} = "selected";
 
 501   #  $form->{SM}{$form->{sendmode}} = "selected";
 
 502   my $type   = qq|      <input type=hidden name="type" value="ustva">|;
 
 503   my $media  = qq|      <input type=hidden name="media" value="screen">|;
 
 505       qq|       <option value=html selected>|
 
 506     . $::locale->text('HTML')
 
 509   my $show_options = qq|
 
 512     <select name=format title = "|
 
 513     . $::locale->text('Choose Outputformat') . qq|">$format</select>
 
 515   $::lxdebug->leave_sub();
 
 517   return $show_options;
 
 521   $::lxdebug->enter_sub();
 
 524   my $locale   = $::locale;
 
 525   my %myconfig = %::myconfig;
 
 527   $::auth->assert('advance_turnover_tax_return');
 
 529   my $defaults = SL::DB::Default->get;
 
 530   $form->error($::locale->text('No print templates have been created for this client yet. Please do so in the client configuration.')) if !$defaults->templates;
 
 531   $form->{templates} = $defaults->templates;
 
 533   # Aufruf von get_config zum Einlesen der Finanzamtdaten aus finanzamt.ini
 
 535   my $ustva = USTVA->new();
 
 536   $ustva->get_config($::lx_office_conf{paths}{userspath}, 'finanzamt.ini');
 
 538   # init some form vars
 
 539   my @anmeldungszeitraum =
 
 540     qw('0401' '0402' '0403'
 
 544        '0441' '0442' '0443' '0444');
 
 546   foreach my $item (@anmeldungszeitraum) {
 
 550     #forgotten the year --> thisyear
 
 551     if ($form->{year} !~ m/^\d\d\d\d$/) {
 
 552       $form->{year} = substr(
 
 554                                     $form->current_date(\%myconfig), \%myconfig
 
 557       $::lxdebug->message(LXDebug->DEBUG1,
 
 558                         qq|Actual year from Database: $form->{year}\n|);
 
 562     # using dates in ISO-8601 format: yyyymmmdd  for Postgres...
 
 566     if ($form->{period} eq "13") {
 
 567       $form->{fromdate} = "$form->{year}0101";
 
 568       $form->{todate}   = "$form->{year}1231";
 
 572     if ($form->{period} eq "41") {
 
 573       $form->{fromdate} = "$form->{year}0101";
 
 574       $form->{todate}   = "$form->{year}0331";
 
 575       $form->{'0441'}   = "X";
 
 577     if ($form->{period} eq "42") {
 
 578       $form->{fromdate} = "$form->{year}0401";
 
 579       $form->{todate}   = "$form->{year}0630";
 
 580       $form->{'0442'}   = "X";
 
 582     if ($form->{period} eq "43") {
 
 583       $form->{fromdate} = "$form->{year}0701";
 
 584       $form->{todate}   = "$form->{year}0930";
 
 585       $form->{'0443'}   = "X";
 
 587     if ($form->{period} eq "44") {
 
 588       $form->{fromdate} = "$form->{year}1001";
 
 589       $form->{todate}   = "$form->{year}1231";
 
 590       $form->{'0444'}   = "X";
 
 595       $form->{period} eq "01" && do {
 
 596         $form->{fromdate} = "$form->{year}0101";
 
 597         $form->{todate}   = "$form->{year}0131";
 
 598         $form->{'0401'}   = "X";
 
 601       $form->{period} eq "02" && do {
 
 602         $form->{fromdate} = "$form->{year}0201";
 
 604         #this works from 1901 to 2099, 1900 and 2100 fail.
 
 605         my $leap = ($form->{year} % 4 == 0) ? "29" : "28";
 
 606         $form->{todate} = "$form->{year}02$leap";
 
 607         $form->{"0402"} = "X";
 
 610       $form->{period} eq "03" && do {
 
 611         $form->{fromdate} = "$form->{year}0301";
 
 612         $form->{todate}   = "$form->{year}0331";
 
 613         $form->{"0403"}   = "X";
 
 616       $form->{period} eq "04" && do {
 
 617         $form->{fromdate} = "$form->{year}0401";
 
 618         $form->{todate}   = "$form->{year}0430";
 
 619         $form->{"0404"}   = "X";
 
 622       $form->{period} eq "05" && do {
 
 623         $form->{fromdate} = "$form->{year}0501";
 
 624         $form->{todate}   = "$form->{year}0531";
 
 625         $form->{"0405"}   = "X";
 
 628       $form->{period} eq "06" && do {
 
 629         $form->{fromdate} = "$form->{year}0601";
 
 630         $form->{todate}   = "$form->{year}0630";
 
 631         $form->{"0406"}   = "X";
 
 634       $form->{period} eq "07" && do {
 
 635         $form->{fromdate} = "$form->{year}0701";
 
 636         $form->{todate}   = "$form->{year}0731";
 
 637         $form->{"0407"}   = "X";
 
 640       $form->{period} eq "08" && do {
 
 641         $form->{fromdate} = "$form->{year}0801";
 
 642         $form->{todate}   = "$form->{year}0831";
 
 643         $form->{"0408"}   = "X";
 
 646       $form->{period} eq "09" && do {
 
 647         $form->{fromdate} = "$form->{year}0901";
 
 648         $form->{todate}   = "$form->{year}0930";
 
 649         $form->{"0409"}   = "X";
 
 652       $form->{period} eq "10" && do {
 
 653         $form->{fromdate} = "$form->{year}1001";
 
 654         $form->{todate}   = "$form->{year}1031";
 
 655         $form->{"0410"}   = "X";
 
 658       $form->{period} eq "11" && do {
 
 659         $form->{fromdate} = "$form->{year}1101";
 
 660         $form->{todate}   = "$form->{year}1130";
 
 661         $form->{"0411"}   = "X";
 
 664       $form->{period} eq "12" && do {
 
 665         $form->{fromdate} = "$form->{year}1201";
 
 666         $form->{todate}   = "$form->{year}1231";
 
 667         $form->{"0412"}   = "X";
 
 672   # Kontrollvariablen für die Templates
 
 673   $form->{"year$_"} = ($form->{year} >= $_ ) ? "1":"0" for 2007..2107;
 
 676   $ustva->ustva(\%myconfig, \%$form);
 
 678   # reformat Dates to dateformat
 
 679   $form->{fromdate} = $locale->date(\%myconfig, $form->{fromdate}, 0, 0, 0);
 
 681   $form->{todate} = $form->current_date(\%myconfig) unless $form->{todate};
 
 682   $form->{todate} = $locale->date(\%myconfig, $form->{todate}, 0, 0, 0);
 
 684   $form->{longperiod} =
 
 685     $locale->date(\%myconfig, $form->current_date(\%myconfig), 1, 0, 0);
 
 687   # if there are any dates construct a where
 
 688   if ($form->{fromdate} || $form->{todate}) {
 
 690     $form->{todate} = $form->current_date(\%myconfig)  unless ($form->{todate});
 
 692     my $longtodate  = $locale->date(\%myconfig, $form->{todate}, 1, 0, 0);
 
 693     my $shorttodate = $locale->date(\%myconfig, $form->{todate}, 0, 0, 0);
 
 695     my $longfromdate  = $locale->date(\%myconfig, $form->{fromdate}, 1, 0, 0);
 
 696     my $shortfromdate = $locale->date(\%myconfig, $form->{fromdate}, 0, 0, 0);
 
 698     $form->{this_period} = "$shortfromdate<br>\n$shorttodate";
 
 699     $form->{longperiod}      =
 
 700         $locale->text('for Period')
 
 701       . qq|<br>\n$longfromdate |
 
 702       . $locale->text('to (date)')
 
 706   if ($form->{comparefromdate} || $form->{comparetodate}) {
 
 707     my $longcomparefromdate =
 
 708       $locale->date(\%myconfig, $form->{comparefromdate}, 1, 0, 0);
 
 709     my $shortcomparefromdate =
 
 710       $locale->date(\%myconfig, $form->{comparefromdate}, 0, 0, 0);
 
 712     my $longcomparetodate =
 
 713       $locale->date(\%myconfig, $form->{comparetodate}, 1, 0, 0);
 
 714     my $shortcomparetodate =
 
 715       $locale->date(\%myconfig, $form->{comparetodate}, 0, 0, 0);
 
 717     $form->{last_period} = "$shortcomparefromdate<br>\n$shortcomparetodate";
 
 718     $form->{longperiod} .=
 
 719         "<br>\n$longcomparefromdate "
 
 720       . $locale->text('to (date)')
 
 721       . qq| $longcomparetodate|;
 
 724   $form->{Datum_heute} =
 
 725     $locale->date(\%myconfig, $form->current_date(\%myconfig), 0, 0, 0);
 
 727   # setup variables for the form
 
 728   my @a = qw(tel fax email
 
 729     co_chief co_department co_custom1 co_custom2 co_custom3 co_custom4 co_custom5
 
 730     co_name1 co_name2  co_street co_street1 co_zip co_city co_city1 co_country co_tel co_tel1 co_tel2
 
 731     co_fax co_fax1 co_email co_email1 co_url co_url1
 
 732     co_bankname co_bankname1 co_bankname2 co_bankname3 co_blz co_blz1
 
 733     co_blz2 co_blz3 co_accountnr co_accountnr1 co_accountnr2 co_accountnr3);
 
 735   $form->{$_} = $myconfig{$_} for @a;
 
 736   $form->{$_} = $defaults->$_ for qw(company address co_ustid duns);
 
 738   if ($form->{address} ne '') {
 
 739     my $temp = $form->{address};
 
 740     $temp =~ s/\\n/<br \/>/;
 
 741     ($form->{co_street}, $form->{co_city}) = split("<br \/>", $temp);
 
 742     $form->{co_city} =~ s/\\n//g;
 
 745   ################################
 
 747   # Nation specific customisations
 
 749   ################################
 
 753   if ( $form->{coa} eq 'Germany-DATEV-SKR03EU' or $form->{coa} eq 'Germany-DATEV-SKR04EU') {
 
 756     # Outputformat specific customisation's
 
 759     my @category_cent = $ustva->report_variables({
 
 760         myconfig    => \%myconfig,
 
 763         attribute   => 'position',
 
 767     push @category_cent, qw(Z43  Z45  Z53  Z62  Z65  Z67);
 
 769     my @category_euro = $ustva->report_variables({
 
 770         myconfig    => \%myconfig,
 
 773         attribute   => 'position',
 
 778     $form->{amount} = [];
 
 780     if ( $form->{format} eq 'pdf' or $form->{format} eq 'postscript') {
 
 782       $form->{IN} = "$form->{type}-$form->{year}.tex";
 
 783       $form->{padding} = "~~";
 
 784       $form->{bold}    = "\textbf{";
 
 785       $form->{endbold} = "}";
 
 786       $form->{br}      = '\\\\';
 
 788       # Zahlenformatierung für Latex USTVA Formulare
 
 790       foreach my $number (@category_euro) {
 
 791         $form->{$number} = $form->format_amount(\%myconfig, $form->{$number}, '0', '');
 
 794       my ${decimal_comma} = ( $myconfig{numberformat} eq '1.000,00'
 
 795            or $myconfig{numberformat} eq '1000,00' ) ? ',':'.';
 
 797       foreach my $number (@category_cent) {
 
 798         $form->{$number} = $form->format_amount(\%myconfig, $form->{$number}, '2', '');
 
 799         $form->{$number} =~ s/${decimal_comma}/~~/g;
 
 802     } elsif ( $form->{format} eq 'html') { # Formatierungen für HTML Ausgabe
 
 804       $form->{IN} = $form->{type} . '.html';
 
 805       $form->{padding} = "  ";
 
 806       $form->{bold}    = "<b>";
 
 807       $form->{endbold} = "</b>";
 
 808       $form->{br}      = "<br>";
 
 809       $form->{address} =~ s/\\n/\n/g;
 
 811       foreach my $number (@category_cent) {
 
 812         $form->{$number} = $form->format_amount(\%myconfig, $form->{$number}, '2', '0');
 
 815       foreach my $number (@category_euro) {
 
 816         $form->{$number} = $form->format_amount(\%myconfig, $form->{$number}, '0', '0');
 
 818     } elsif ( $form->{format} eq '' ){ # No format error.
 
 820       USTVA::error( $locale->text('Application Error. No Format given' ) . "!");
 
 823     } else { # All other Formats are wrong
 
 825       USTVA::error( $locale->text('Application Error. Wrong Format') . ": " . $form->{format} );
 
 830   } else  # Outputformat for generic output
 
 833     my @category_cent = $ustva->report_variables({
 
 834         myconfig    => \%myconfig,
 
 837         attribute   => 'position',
 
 841     my @category_euro = $ustva->report_variables({
 
 842         myconfig    => \%myconfig,
 
 845         attribute   => 'position',
 
 851     if ( $form->{format} eq 'generic') { # Formatierungen für HTML Ausgabe
 
 854       for my $kennziffer (@category_cent, @category_euro) {
 
 856         $rec_ref->{id} = $kennziffer;
 
 857         $rec_ref->{amount} = $form->format_amount(\%myconfig, $form->{$kennziffer}, 2, '0');
 
 859         $::lxdebug->message($LXDebug::DEBUG, "Kennziffer $kennziffer: '$form->{$kennziffer}'" );
 
 860         $::lxdebug->dump($LXDebug::DEBUG, $rec_ref );
 
 861         push @ { $form->{USTVA} }, $rec_ref;
 
 868   if ( $form->{period} eq '13' and $form->{format} ne 'html') {
 
 872       'Yearly taxreport not yet implemented')
 
 876   $form->{templates} = "doc" if ( $form->{type} eq 'help' );
 
 878   if ($form->{format} eq 'generic'){
 
 883         taxnumber => $defaults->taxnumber,
 
 886     print($form->parse_html_template('ustva/generic_taxreport', $template_ref));
 
 890    # add a prefix for ustva pos numbers, i.e.: 81 ->  post_ustva_81
 
 891    $form->{"pos_ustva_$_"} = $form->{$_} for grep { m{^\d+} } keys %{ $form };
 
 892    $form->{title} = $locale->text('Advance turnover tax return');
 
 895    print $form->parse_html_template('ustva/ustva');
 
 900   $::lxdebug->leave_sub();
 
 904   $::lxdebug->enter_sub();
 
 906   $::auth->assert('advance_turnover_tax_return');
 
 908 $::form->{title} = $::locale->text('Tax Office Preferences');
 
 910   # edit all taxauthority prefs
 
 914   my $ustva = USTVA->new();
 
 915   $ustva->get_config($::lx_office_conf{paths}{userspath}, 'finanzamt.ini');
 
 917   my $land = $::form->{elsterland};
 
 918   my $amt  = $::form->{elsterFFFF};
 
 921   $::form->{title} = $::locale->text('Tax Office Preferences');
 
 924   my $select_tax_office               = $ustva->fa_auswahl($land, $amt, $ustva->query_finanzamt(\%::myconfig, $::form));
 
 925   my $checked_accrual                 = $::form->{method}        eq 'accrual' ? q|checked="checked"| : '';
 
 926   my $checked_cash                    = $::form->{method}        eq 'cash'    ? q|checked="checked"| : '';
 
 927   my $checked_monthly                 = $::form->{FA_voranmeld}  eq 'month'   ? "checked"            : '';
 
 928   my $checked_quarterly               = $::form->{FA_voranmeld}  eq 'quarter' ? "checked"            : '';
 
 929   my $checked_dauerfristverlaengerung = $::form->{FA_dauerfrist} eq '1'       ? "checked"            : '';
 
 930   my $checked_kz_71                   = $::form->{FA_71}         eq 'X'       ? "checked"            : '';
 
 932   my $_hidden_variables_ref;
 
 934   my %_hidden_local_variables = (
 
 935     'saved'       => $::locale->text('Check Details'),
 
 936     'nextsub'     => 'config_step2',
 
 940   foreach my $variable (keys %_hidden_local_variables) {
 
 941     push @{ $_hidden_variables_ref },
 
 942         { 'variable' => $variable, 'value' => $_hidden_local_variables{$variable} };
 
 945   my @_hidden_form_variables = qw(
 
 946     FA_Name             FA_Strasse        FA_PLZ
 
 947     FA_Ort              FA_Telefon        FA_Fax
 
 948     FA_PLZ_Grosskunden  FA_PLZ_Postfach   FA_Postfach
 
 949     FA_BLZ_1            FA_Kontonummer_1  FA_Bankbezeichnung_1
 
 950     FA_BLZ_2            FA_Kontonummer_2  FA_Bankbezeichnung_oertlich
 
 951     FA_Oeffnungszeiten  FA_Email          FA_Internet
 
 952     steuernummer        elsterland        elstersteuernummer
 
 956   foreach my $variable (@_hidden_form_variables) {
 
 957     push @{ $_hidden_variables_ref},
 
 958         { 'variable' => $variable, 'value' => $::form->{$variable} };
 
 961 # Which COA is in use?
 
 963   $ustva->get_coa($::form); # fetches coa and modifies some form variables
 
 966   my $steuernummer_new = '';
 
 968   # Variablen für das Template zur Verfügung stellen
 
 970      select_tax_office               => $select_tax_office,
 
 971      checked_accrual                 => $checked_accrual,
 
 972      checked_cash                    => $checked_cash,
 
 973      checked_monthly                 => $checked_monthly,
 
 974      checked_quarterly               => $checked_quarterly,
 
 975      checked_dauerfristverlaengerung => $checked_dauerfristverlaengerung,
 
 976      hidden_variables                => $_hidden_variables_ref,
 
 980   # Ausgabe des Templates
 
 981   print($::form->parse_html_template('ustva/config_step1', $template_ref));
 
 983   $::lxdebug->leave_sub();
 
 987   $::lxdebug->enter_sub();
 
 990   my $locale   = $::locale;
 
 991   my %myconfig = %::myconfig;
 
 993   $::auth->assert('advance_turnover_tax_return');
 
1000   my $elstersteuernummer = '';
 
1002   my $ustva = USTVA->new();
 
1003   $ustva->get_config($::lx_office_conf{paths}{userspath}, 'finanzamt.ini')
 
1004     if ($form->{saved} eq $locale->text('saved'));
 
1006   # Auf Übergabefehler checken
 
1007   USTVA::info(  $locale->text('Missing Tax Authoritys Preferences') . "\n"
 
1008               . $locale->text('USTVA-Hint: Tax Authoritys'))
 
1009     if (   $form->{elsterFFFF_new} eq 'Auswahl'
 
1010         || $form->{elsterland_new} eq 'Auswahl');
 
1011   USTVA::info(  $locale->text('Missing Method!') . "\n"
 
1012               . $locale->text('USTVA-Hint: Method'))
 
1013     if ($form->{method} eq '');
 
1015   # Klären, ob Variablen bereits befüllt sind UND ob veräderungen auf
 
1016   # der vorherigen Maske stattfanden: $change = 1(in der edit sub,
 
1017   # mittels get_config)
 
1019   my $change = $form->{elsterland} eq $form->{elsterland_new}
 
1020     && $form->{elsterFFFF} eq $form->{elsterFFFF_new} ? '0' : '1';
 
1021   $change = '0' if ($form->{saved} eq $locale->text('saved'));
 
1022   my $elster_init = $ustva->query_finanzamt(\%myconfig, $form);
 
1024   my %elster_init = %$elster_init;
 
1026   if ($change eq '1') {
 
1029     $elsterland           = $form->{elsterland_new};
 
1030     $elsterFFFF           = $form->{elsterFFFF_new};
 
1031     $form->{elsterland}   = $elsterland;
 
1032     $form->{elsterFFFF}   = $elsterFFFF;
 
1033     $form->{steuernummer} = '';
 
1035     create_steuernummer();
 
1037     # rebuild elster_amt
 
1038     my $amt = $elster_init{$elsterFFFF};
 
1040     # load the predefined hash data into the FA_* Vars
 
1041     my @variables = qw(FA_Name FA_Strasse FA_PLZ FA_Ort
 
1042       FA_Telefon FA_Fax FA_PLZ_Grosskunden FA_PLZ_Postfach
 
1044       FA_BLZ_1 FA_Kontonummer_1 FA_Bankbezeichnung_1
 
1045       FA_BLZ_2 FA_Kontonummer_2 FA_Bankbezeichnung_oertlich
 
1046       FA_Oeffnungszeiten FA_Email FA_Internet);
 
1048     for (my $i = 0; $i <= 20; $i++) {
 
1049       $form->{ $variables[$i] } =
 
1050         $elster_init->{$elsterland}->{$elsterFFFF}->[$i];
 
1055     $elsterland = $form->{elsterland};
 
1056     $elsterFFFF = $form->{elsterFFFF};
 
1059   my $stnr = $form->{steuernummer};
 
1061   my $patterncount   = $form->{patterncount};
 
1062   my $elster_pattern = $form->{elster_pattern};
 
1063   my $delimiter      = $form->{delimiter};
 
1064   my $steuernummer   = $stnr eq '' ? $form->{steuernummer} : '';
 
1066   $form->{FA_Oeffnungszeiten} =~ s/\\\\n/\n/g;
 
1069   $ustva->get_coa($form); # fetches coa and modifies some form variables
 
1071   my $input_steuernummer = $ustva->steuernummer_input(
 
1072                              $form->{elsterland},
 
1073                              $form->{elsterFFFF},
 
1074                              $form->{steuernummer}
 
1077   $::lxdebug->message(LXDebug->DEBUG1, qq|$input_steuernummer|);
 
1080   my $_hidden_variables_ref;
 
1082   my %_hidden_local_variables = (
 
1083       'elsterland'          => $elsterland,
 
1084       'elsterFFFF'          => $elsterFFFF,
 
1086       'elstersteuernummer'  => $elstersteuernummer,
 
1087       'steuernummer'        => $stnr,
 
1088       'lastsub'             => 'config_step1',
 
1089       'nextsub'             => 'save',
 
1093   foreach my $variable (keys %_hidden_local_variables) {
 
1094     push @{ $_hidden_variables_ref },
 
1095         { 'variable' => $variable, 'value' => $_hidden_local_variables{$variable} };
 
1098   my @_hidden_form_variables = qw(
 
1099     FA_steuerberater_name   FA_steuerberater_street
 
1100     FA_steuerberater_city   FA_steuerberater_tel
 
1108   foreach my $variable (@_hidden_form_variables) {
 
1109     push @{ $_hidden_variables_ref},
 
1110         { 'variable' => $variable, 'value' => $form->{$variable} };
 
1113   my $template_ref = {
 
1114      input_steuernummer              => $input_steuernummer,
 
1115      readonly                        => '', #q|disabled="disabled"|,
 
1116      callback                        => $form->{callback},
 
1117      hidden_variables                => $_hidden_variables_ref,
 
1120   # Ausgabe des Templates
 
1121   print($form->parse_html_template('ustva/config_step2', $template_ref));
 
1124   $::lxdebug->leave_sub();
 
1127 sub create_steuernummer {
 
1128   $::lxdebug->enter_sub();
 
1130   $::auth->assert('advance_turnover_tax_return');
 
1132   my $part           = $::form->{part};
 
1133   my $patterncount   = $::form->{patterncount};
 
1134   my $delimiter      = $::form->{delimiter};
 
1135   my $elster_pattern = $::form->{elster_pattern};
 
1137   # rebuild steuernummer and elstersteuernummer
 
1138   # es gibt eine gespeicherte steuernummer $form->{steuernummer}
 
1139   # und die parts und delimiter
 
1144   my $steuernummer_new       = $part;
 
1145   my $elstersteuernummer_new = $::form->{elster_FFFF};
 
1146   $elstersteuernummer_new .= '0';
 
1148   for ($h = 1; $h < $patterncount; $h++) {
 
1149     $steuernummer_new .= qq|$delimiter|;
 
1150     for (my $i = 1; $i <= length($elster_pattern); $i++) {
 
1151       $steuernummer_new       .= $::form->{"part_$h\_$i"};
 
1152       $elstersteuernummer_new .= $::form->{"part_$h\_$i"};
 
1155   if ($::form->{steuernummer} ne $steuernummer_new) {
 
1156     $::form->{steuernummer}       = $steuernummer_new;
 
1157     $::form->{elstersteuernummer} = $elstersteuernummer_new;
 
1158     $::form->{steuernummer_new}   = $steuernummer_new;
 
1160     $::form->{steuernummer_new}       = '';
 
1161     $::form->{elstersteuernummer_new} = '';
 
1163   $::lxdebug->leave_sub();
 
1167   $::lxdebug->enter_sub();
 
1169   $::auth->assert('advance_turnover_tax_return');
 
1171   my $filename = "$::myconfig{login}_$::form->{filename}";
 
1172   $filename =~ s|.*/||;
 
1174   #zuerst die steuernummer aus den part, parts_X_Y und delimiter herstellen
 
1175   create_steuernummer();
 
1177   # Textboxen formatieren: Linebreaks entfernen
 
1179   $::form->{FA_Oeffnungszeiten} =~ s/\r\n/\\n/g;
 
1181   #URL mit http:// davor?
 
1182   $::form->{FA_Internet} =~ s/^http:\/\///;
 
1183   $::form->{FA_Internet} = 'http://' . $::form->{FA_Internet};
 
1186     elster              elsterland            elstersteuernummer  steuernummer
 
1187     elsteramt           elsterFFFF            FA_Name             FA_Strasse
 
1188     FA_PLZ              FA_Ort                FA_Telefon          FA_Fax
 
1189     FA_PLZ_Grosskunden  FA_PLZ_Postfach       FA_Postfach         FA_BLZ_1
 
1190     FA_Kontonummer_1    FA_Bankbezeichnung_1  FA_BLZ_2            FA_Kontonummer_2
 
1191     FA_Bankbezeichnung_oertlich FA_Oeffnungszeiten
 
1192     FA_Email FA_Internet FA_voranmeld method FA_steuerberater_name
 
1193     FA_steuerberater_street FA_steuerberater_city FA_steuerberater_tel
 
1194     FA_71 FA_dauerfrist);
 
1196   # Hier kommt dann die Plausibilitätsprüfung der ELSTERSteuernummer
 
1197   if ($::form->{elstersteuernummer} ne '000000000') {
 
1199     $::form->{elster} = '1';
 
1201     open my $ustvaconfig, ">", "$::lx_office_conf{paths}{userspath}/$filename" or $::form->error("$filename : $!");
 
1203     # create the config file
 
1204     print {$ustvaconfig} qq|# Configuration file for USTVA\n\n|;
 
1206     foreach $key (sort @config) {
 
1207       $::form->{$key} =~ s/\\/\\\\/g;
 
1209       $::form->{$key} =~ s/\r\n/\n/g;
 
1211       print {$ustvaconfig} qq|$key=|;
 
1212       if ($::form->{$key} ne 'Y') {
 
1213         print {$ustvaconfig} qq|$::form->{$key}\n|;
 
1215       if ($::form->{$key} eq 'Y') {
 
1216         print {$ustvaconfig} qq|checked \n|;
 
1219     print {$ustvaconfig} qq|\n\n|;
 
1221     $::form->{saved} = $::locale->text('saved');
 
1225     $::form->{saved} = $::locale->text('Choose a Tax Number');
 
1229   $::lxdebug->leave_sub();
 
1234   $::lxdebug->enter_sub();
 
1236   # allow Symbolic references just here:
 
1237   call_sub($::form->{"nextsub"});
 
1238   $::lxdebug->leave_sub();
 
1242   $::lxdebug->enter_sub();
 
1243   call_sub($::form->{"lastsub"});
 
1244   $::lxdebug->leave_sub();