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 #======================================================================
 
  26 require "bin/mozilla/common.pl";
 
  31 #use warnings; # FATAL=> 'all';
 
  32 #use vars qw($locale $form %myconfig);
 
  34 #use CGI::Carp "fatalsToBrowser";
 
  36 use List::Util qw(first);
 
  44 # this is for our long dates
 
  45 # $locale->text('January')
 
  46 # $locale->text('February')
 
  47 # $locale->text('March')
 
  48 # $locale->text('April')
 
  49 # $locale->text('May ')
 
  50 # $locale->text('June')
 
  51 # $locale->text('July')
 
  52 # $locale->text('August')
 
  53 # $locale->text('September')
 
  54 # $locale->text('October')
 
  55 # $locale->text('November')
 
  56 # $locale->text('December')
 
  58 # this is for our short month
 
  59 # $locale->text('Jan')
 
  60 # $locale->text('Feb')
 
  61 # $locale->text('Mar')
 
  62 # $locale->text('Apr')
 
  63 # $locale->text('May')
 
  64 # $locale->text('Jun')
 
  65 # $locale->text('Jul')
 
  66 # $locale->text('Aug')
 
  67 # $locale->text('Sep')
 
  68 # $locale->text('Oct')
 
  69 # $locale->text('Nov')
 
  70 # $locale->text('Dec')
 
  72 #############################
 
  75   $lxdebug->enter_sub();
 
  77   $auth->assert('advance_turnover_tax_return');
 
  79   my $myconfig = \%myconfig;
 
  81   $form->{title} = $locale->text('UStVA');
 
  82   $form->{kz10}  = '';                       #Berichtigte Anmeldung? Ja =1 Nein=0
 
  84   my $year = substr($form->datetonum($form->current_date(\%myconfig), \%myconfig ),
 
  91   # Einlesen der Finanzamtdaten
 
  92   my $ustva = USTVA->new();
 
  93   $ustva->get_config($userspath, 'finanzamt.ini');
 
  95   # Hier Einlesen der user-config
 
  96   # steuernummer entfernt für prerelease
 
  98     signature      name          company       address        businessnumber
 
  99     tel            fax           email         co_chief       co_department
 
 100     co_custom1     co_custom2    co_custom3    co_custom4     co_custom5
 
 101     co_name1       co_name2      co_street     co_street1     co_zip
 
 102     co_city        co_city1      co_country    co_tel         co_tel1
 
 103     co_tel2        co_fax        co_fax1       co_email       co_email1
 
 104     co_url         co_url1       ustid         duns           co_bankname
 
 105     co_bankname1   co_bankname2  co_bankname3  co_blz         co_blz1
 
 106     co_blz2        co_blz3       co_accountnr  co_accountnr1  co_accountnr2
 
 110   map { $form->{$_} = $myconfig->{$_} } @a;
 
 112   my $openings = $form->{FA_Oeffnungszeiten};
 
 113   $openings =~ s/\\\\n/<br>/g;
 
 115   my $company_given = ($form->{company} ne '')
 
 116     ? qq|<h3>$form->{company}</h3>\n|
 
 117     : qq|<a href="am.pl?action=config|
 
 118       . qq|&level=Programm--Preferences">|
 
 119       . $locale->text('No Company Name given') . qq|!</a><br>|;
 
 122   # Anpassungen der Variablennamen auf pre 2.1.1 Namen
 
 123   # klären, ob $form->{company_street|_address} gesetzt sind
 
 124   if ($form->{address} ne '') {
 
 125     my $temp = $form->{address};
 
 126     $temp =~ s/\n/<br \/>/;
 
 127     ($form->{co_street}, $form->{co_city}) = split("<br \/>", $temp);
 
 128     $form->{co_city} =~ s/\n//g;
 
 133     ($form->{co_street} && ($form->{co_zip} || $form->{co_city}))
 
 134     ? qq|$form->{co_street}<br>|
 
 135         . qq|$form->{co_street1}<br>|
 
 136         . qq|$form->{co_zip} $form->{co_city}|
 
 137     : qq|<a href="am.pl?action=config|
 
 138         . qq|&level=Programm--Preferences">|
 
 139         . $locale->text('No Company Address given')
 
 142   $form->{co_email} = $form->{email} unless $form->{co_email};
 
 143   $form->{co_tel}   = $form->{tel}   unless $form->{co_tel};
 
 144   $form->{co_fax}   = $form->{fax}   unless $form->{co_fax};
 
 145   $form->{co_url}   = $form->{urlx}  unless $form->{co_url};
 
 147   my $taxnumber_given = ($form->{steuernummer} ne '') ? $form->{steuernummer} : qq|<a href="ustva.pl?action=config_step1">Keine Steuernummer hinterlegt!</a><br>|;
 
 149   my $ustva_vorauswahl = &ustva_vorauswahl();
 
 151   my @all_years = $form->all_years(\%myconfig);
 
 153   my $select_year = qq|<select name=year title="|
 
 154     . $locale->text('Year') . qq|">|;
 
 155   foreach my $key (@all_years) {
 
 156     $select_year .= qq|<option |;
 
 157     $select_year .= qq|selected| if ($key eq $form->{year});
 
 158     $select_year .= qq| >$key</option>|;
 
 160   $select_year   .=  qq|</select>|;
 
 163   $_checked = "checked" if ($form->{kz10} eq '1');
 
 164   my $checkbox_kz_10 = qq|<input name="FA_10" id=FA_10 class=checkbox|
 
 165     . qq| type=checkbox value="1" $_checked title = "|
 
 166     . $locale->text('Amended Advance Turnover Tax Return (Nr. 10)')
 
 168     . $locale->text('Amended Advance Turnover Tax Return');
 
 170   my $method_local = ($form->{method} eq 'accrual') ? $locale->text('accrual')
 
 171                    : ($form->{method} eq 'cash')    ? $locale->text('cash')
 
 174   my $period_local = ( $form->{FA_voranmeld} eq 'month')   ? $locale->text('month')
 
 175                    : ( $form->{FA_voranmeld} eq 'quarter') ? $locale->text('quarter')
 
 178   my $tax_office_banks_ref = [
 
 179     { BLZ             => $form->{FA_BLZ_1},
 
 180       Kontonummer     => $form->{FA_Kontonummer_1},
 
 181       Bankbezeichnung => $form->{FA_Bankbezeichnung_1}
 
 183     { BLZ             => $form->{FA_BLZ_2},
 
 184       Kontonummer     => $form->{FA_Kontonummer_2},
 
 185       Bankbezeichnung => $form->{FA_Bankbezeichnung_oertlich}
 
 189   # Which COA is in use?
 
 191   $ustva->get_coa($form, $myconfig);
 
 194     openings         => $openings,
 
 195     company_given    => $company_given,
 
 196     address_given    => $address_given,
 
 197     taxnumber_given  => $taxnumber_given,
 
 198     taxnumber        => $myconfig->{taxnumber},
 
 199     select_year      => $select_year,
 
 200     period_local     => $period_local,
 
 201     method_local     => $method_local,
 
 202     ustva_vorauswahl => $ustva_vorauswahl,
 
 203     checkbox_kz_10   => $checkbox_kz_10,
 
 204     tax_office_banks => $tax_office_banks_ref,
 
 205     select_options   => &show_options,
 
 209   print($form->parse_html_template('ustva/report', $template_ref));
 
 213   $lxdebug->leave_sub();
 
 219   $lxdebug->enter_sub();
 
 221   $auth->assert('advance_turnover_tax_return');
 
 223   # parse help documents under doc
 
 224   my $tmp = $form->{templates};
 
 225   $form->{templates} = 'doc';
 
 226   $form->{help}      = 'ustva';
 
 227   $form->{type}      = 'help';
 
 228   $form->{format}    = 'html';
 
 231   #$form->{templates} = $tmp;
 
 232   $lxdebug->leave_sub();
 
 236   $lxdebug->enter_sub();
 
 238   $auth->assert('advance_turnover_tax_return');
 
 242   $lxdebug->leave_sub();
 
 243   call_sub($form->{"nextsub"});
 
 247 sub ustva_vorauswahl {
 
 248   $lxdebug->enter_sub();
 
 250   $auth->assert('advance_turnover_tax_return');
 
 252   my $select_vorauswahl;
 
 254   #Aktuelles Datum zerlegen:
 
 255   my $date = $form->datetonum($form->current_date(\%myconfig), \%myconfig);
 
 257   #$locale->date($myconfig, $form->current_date($myconfig), 0)=~ /(\d\d).(\d\d).(\d\d\d\d)/;
 
 258   $form->{day}   = substr($date, 6, 2);
 
 259   $form->{month} = substr($date, 4, 2);
 
 260   $form->{year}  = substr($date, 0, 4);
 
 261   $lxdebug->message(LXDebug::DEBUG1, qq|
 
 262     Actual date from Database: $date\n
 
 263     Actual year from Database: $form->{year}\n
 
 264     Actual day from Database: $form->{day}\n
 
 265     Actual month from Database: $form->{month}\n|);
 
 270   # Testdaten erzeugen:
 
 272   #$form->{month}= '01';
 
 273   #$form->{year}= 2004;
 
 274   $select_vorauswahl = qq|
 
 275      <input type=hidden name=day value=$form->{day}>
 
 276      <input type=hidden name=month value=$form->{month}>
 
 277      <input type=hidden name=yymmdd value=$yymmdd>
 
 278      <input type=hidden name=sel value=$sel>
 
 281   if ($form->{FA_voranmeld} eq 'month') {
 
 283     # Vorauswahl bei monatlichem Voranmeldungszeitraum
 
 285     my %liste = ('01' => $locale->text('January'),
 
 286                  '02' => $locale->text('February'),
 
 287                  '03' => $locale->text('March'),
 
 288                  '04' => $locale->text('April'),
 
 289                  '05' => $locale->text('May'),
 
 290                  '06' => $locale->text('June'),
 
 291                  '07' => $locale->text('July'),
 
 292                  '08' => $locale->text('August'),
 
 293                  '09' => $locale->text('September'),
 
 294                  '10' => $locale->text('October'),
 
 295                  '11' => $locale->text('November'),
 
 296                  '12' => $locale->text('December'),
 
 297                  '13' => $locale->text('Yearly'),
 
 300     my $yy = $form->{year} * 10000;
 
 301     $yymmdd = "$form->{year}$form->{month}$form->{day}" * 1;
 
 305     # Offset für Dauerfristverlängerung
 
 306     $dfv = '100' if ($form->{FA_dauerfrist} eq '1');
 
 309       $yymmdd <= ($yy + 110 + $dfv) && do {
 
 310         $form->{year} = $form->{year} - 1;
 
 314       $yymmdd <= ($yy + 210 + $dfv) && do {
 
 318       $yymmdd <= ($yy + 310 + $dfv) && do {
 
 322       $yymmdd <= ($yy + 410 + $dfv) && do {
 
 326       $yymmdd <= ($yy + 510 + $dfv) && do {
 
 330       $yymmdd <= ($yy + 610 + $dfv) && do {
 
 334       $yymmdd <= ($yy + 710 + $dfv) && do {
 
 338       $yymmdd <= ($yy + 810 + $dfv) && do {
 
 342       $yymmdd <= ($yy + 910 + $dfv) && do {
 
 346       $yymmdd <= ($yy + 1010 + $dfv) && do {
 
 350       $yymmdd <= ($yy + 1110 + $dfv) && do {
 
 354       $yymmdd <= ($yy + 1210) && do {
 
 358       $yymmdd <= ($yy + 1231) && do {
 
 364     $select_vorauswahl .= qq|<select id="zeitraum" name="period" title="|
 
 365   . $locale->text('Select a period') . qq|" >|;
 
 368     foreach $key (sort keys %liste) {
 
 370       $selected = 'selected' if ($sel eq $key);
 
 371       $select_vorauswahl .= qq|
 
 372          <option value="$key" $selected> $liste{$key}</option>
 
 375     $select_vorauswahl .= qq|</select>|;
 
 377   } elsif ($form->{FA_voranmeld} eq 'quarter') {
 
 379     # Vorauswahl bei quartalsweisem Voranmeldungszeitraum
 
 380     my %liste = ('41'  => $locale->text('1. Quarter'),
 
 381                  '42'  => $locale->text('2. Quarter'),
 
 382                  '43'  => $locale->text('3. Quarter'),
 
 383                  '44'  => $locale->text('4. Quarter'),
 
 384                  '13' => $locale->text('Yearly'),);
 
 386     my $yy = $form->{year} * 10000;
 
 387     $yymmdd = "$form->{year}$form->{month}$form->{day}" * 1;
 
 389     my $dfv = '';    # Offset für Dauerfristverlängerung
 
 390     $dfv = '100' if ($form->{FA_dauerfrist} eq '1');
 
 393       $yymmdd <= ($yy + 110 + $dfv) && do {
 
 394         $form->{year} = $form->{year} - 1;
 
 398       $yymmdd <= ($yy + 410 + $dfv) && do {
 
 402       $yymmdd <= ($yy + 710 + $dfv) && do {
 
 406       $yymmdd <= ($yy + 1010 + $dfv) && do {
 
 410       $yymmdd <= ($yy + 1231) && do {
 
 415     $select_vorauswahl .= qq|<select id="zeitraum" name="period" title="|
 
 416       . $locale->text('Select a period') . qq|" >|;
 
 418     foreach $key (sort keys %liste) {
 
 420       $selected = 'selected' if ($sel eq $key);
 
 421       $select_vorauswahl .= qq|
 
 422          <option value="$key" $selected>$liste{$key}</option>
 
 425     $select_vorauswahl .= qq|\n</select>
 
 430     # keine Vorauswahl bei Voranmeldungszeitraum
 
 431     $select_vorauswahl .= qq|<select id="zeitraum" name="period" title="|
 
 432       . $locale->text('Select a period') . qq|" >|;
 
 434     my %listea = ('41' => '1. Quarter',
 
 435                   '42' => '2. Quarter',
 
 436                   '43' => '3. Quarter',
 
 437                   '44' => '4. Quarter',);
 
 439     my %listeb = ('01' => 'January',
 
 453     foreach $key (sort keys %listea) {
 
 454       $select_vorauswahl .= qq|
 
 455          <option value="$key">|
 
 456         . $locale->text("$listea{$key}")
 
 460     foreach $key (sort keys %listeb) {
 
 461       $select_vorauswahl .= qq|
 
 462          <option value="$key">|
 
 463         . $locale->text("$listeb{$key}")
 
 466     $select_vorauswahl .= qq|</select>|;
 
 468   $lxdebug->leave_sub();
 
 470   return $select_vorauswahl;
 
 474 #  $lxdebug->enter_sub();
 
 476 #  $lxdebug->leave_sub();
 
 480   $lxdebug->enter_sub();
 
 482   $lxdebug->leave_sub();
 
 486   $lxdebug->enter_sub();
 
 488   $auth->assert('advance_turnover_tax_return');
 
 490   #  $form->{PD}{$form->{type}} = "selected";
 
 491   #  $form->{DF}{$form->{format}} = "selected";
 
 492   #  $form->{OP}{$form->{media}} = "selected";
 
 493   #  $form->{SM}{$form->{sendmode}} = "selected";
 
 494   my $type   = qq|      <input type=hidden name="type" value="ustva">|;
 
 495   my $media  = qq|      <input type=hidden name="media" value="screen">|;
 
 497       qq|       <option value=html selected>|
 
 498     . $locale->text('Preview')
 
 500   if ($latex_templates) {
 
 502         qq|    <option value=pdf>|
 
 503       . $locale->text('UStVA (PDF-Dokument)')
 
 507   #my $disabled= qq|disabled="disabled"|;
 
 508   #$disabled='' if ($form->{elster} eq '1' );
 
 509   if ($form->{elster} eq '1') {
 
 511         qq|<option value=elsterwinston>|
 
 512       . $locale->text('ELSTER Export (Winston)')
 
 514       . qq|<option value=elstertaxbird>|
 
 515       . $locale->text('ELSTER Export (Taxbird)')
 
 519   #$format .= qq|<option value=elster>|.$locale->text('ELSTER Export nach Winston').qq|</option>|;
 
 520   my $show_options = qq|
 
 523     <select name=format title = "|
 
 524     . $locale->text('Choose Outputformat') . qq|">$format</select>
 
 526   $lxdebug->leave_sub();
 
 528   return $show_options;
 
 532   $lxdebug->enter_sub();
 
 534   $auth->assert('advance_turnover_tax_return');
 
 536   # Aufruf von get_config zum Einlesen der Finanzamtdaten aus finanzamt.ini
 
 538   my $ustva = USTVA->new();
 
 539   $ustva->get_config($userspath, 'finanzamt.ini');
 
 541   # init some form vars
 
 542   my @anmeldungszeitraum =
 
 543     qw('0401' '0402' '0403'
 
 547        '0441' '0442' '0443' '0444');
 
 549   foreach my $item (@anmeldungszeitraum) {
 
 553     #forgotten the year --> thisyear
 
 554     if ($form->{year} !~ m/^\d\d\d\d$/) {
 
 555       $form->{year} = substr(
 
 557                                     $form->current_date(\%myconfig), \%myconfig
 
 560       $lxdebug->message(LXDebug::DEBUG1,
 
 561                         qq|Actual year from Database: $form->{year}\n|);
 
 565     # using dates in ISO-8601 format: yyyymmmdd  for Postgres...
 
 569     if ($form->{period} eq "13") {
 
 570       $form->{fromdate} = "$form->{year}0101";
 
 571       $form->{todate}   = "$form->{year}1231";
 
 575     if ($form->{period} eq "41") {
 
 576       $form->{fromdate} = "$form->{year}0101";
 
 577       $form->{todate}   = "$form->{year}0331";
 
 578       $form->{'0441'}   = "X";
 
 580     if ($form->{period} eq "42") {
 
 581       $form->{fromdate} = "$form->{year}0401";
 
 582       $form->{todate}   = "$form->{year}0630";
 
 583       $form->{'0442'}   = "X";
 
 585     if ($form->{period} eq "43") {
 
 586       $form->{fromdate} = "$form->{year}0701";
 
 587       $form->{todate}   = "$form->{year}0930";
 
 588       $form->{'0443'}   = "X";
 
 590     if ($form->{period} eq "44") {
 
 591       $form->{fromdate} = "$form->{year}1001";
 
 592       $form->{todate}   = "$form->{year}1231";
 
 593       $form->{'0444'}   = "X";
 
 598       $form->{period} eq "01" && do {
 
 599         $form->{fromdate} = "$form->{year}0101";
 
 600         $form->{todate}   = "$form->{year}0131";
 
 601         $form->{'0401'}   = "X";
 
 604       $form->{period} eq "02" && do {
 
 605         $form->{fromdate} = "$form->{year}0201";
 
 607         #this works from 1901 to 2099, 1900 and 2100 fail.
 
 608         my $leap = ($form->{year} % 4 == 0) ? "29" : "28";
 
 609         $form->{todate} = "$form->{year}02$leap";
 
 610         $form->{"0402"} = "X";
 
 613       $form->{period} eq "03" && do {
 
 614         $form->{fromdate} = "$form->{year}0301";
 
 615         $form->{todate}   = "$form->{year}0331";
 
 616         $form->{"0403"}   = "X";
 
 619       $form->{period} eq "04" && do {
 
 620         $form->{fromdate} = "$form->{year}0401";
 
 621         $form->{todate}   = "$form->{year}0430";
 
 622         $form->{"0404"}   = "X";
 
 625       $form->{period} eq "05" && do {
 
 626         $form->{fromdate} = "$form->{year}0501";
 
 627         $form->{todate}   = "$form->{year}0531";
 
 628         $form->{"0405"}   = "X";
 
 631       $form->{period} eq "06" && do {
 
 632         $form->{fromdate} = "$form->{year}0601";
 
 633         $form->{todate}   = "$form->{year}0630";
 
 634         $form->{"0406"}   = "X";
 
 637       $form->{period} eq "07" && do {
 
 638         $form->{fromdate} = "$form->{year}0701";
 
 639         $form->{todate}   = "$form->{year}0731";
 
 640         $form->{"0407"}   = "X";
 
 643       $form->{period} eq "08" && do {
 
 644         $form->{fromdate} = "$form->{year}0801";
 
 645         $form->{todate}   = "$form->{year}0831";
 
 646         $form->{"0408"}   = "X";
 
 649       $form->{period} eq "09" && do {
 
 650         $form->{fromdate} = "$form->{year}0901";
 
 651         $form->{todate}   = "$form->{year}0930";
 
 652         $form->{"0409"}   = "X";
 
 655       $form->{period} eq "10" && do {
 
 656         $form->{fromdate} = "$form->{year}1001";
 
 657         $form->{todate}   = "$form->{year}1031";
 
 658         $form->{"0410"}   = "X";
 
 661       $form->{period} eq "11" && do {
 
 662         $form->{fromdate} = "$form->{year}1101";
 
 663         $form->{todate}   = "$form->{year}1130";
 
 664         $form->{"0411"}   = "X";
 
 667       $form->{period} eq "12" && do {
 
 668         $form->{fromdate} = "$form->{year}1201";
 
 669         $form->{todate}   = "$form->{year}1231";
 
 670         $form->{"0412"}   = "X";
 
 675   # Kontrollvariable für die Templates
 
 676   $form->{'year2007'} = ($form->{year} >= 2007 ) ? "1":"0";
 
 680   $ustva->ustva(\%myconfig, \%$form);
 
 682   # reformat Dates to dateformat
 
 683   $form->{fromdate} = $locale->date(\%myconfig, $form->{fromdate}, 0, 0, 0);
 
 685   $form->{todate} = $form->current_date(\%myconfig) unless $form->{todate};
 
 686   $form->{todate} = $locale->date(\%myconfig, $form->{todate}, 0, 0, 0);
 
 688   $form->{longperiod} =
 
 689     $locale->date(\%myconfig, $form->current_date(\%myconfig), 1, 0, 0);
 
 691   # if there are any dates construct a where
 
 692   if ($form->{fromdate} || $form->{todate}) {
 
 694     $form->{todate} = $form->current_date($myconfig)  unless ($form->{todate});
 
 696     my $longtodate  = $locale->date($myconfig, $form->{todate}, 1, 0, 0);
 
 697     my $shorttodate = $locale->date($myconfig, $form->{todate}, 0, 0, 0);
 
 699     my $longfromdate  = $locale->date($myconfig, $form->{fromdate}, 1, 0, 0);
 
 700     my $shortfromdate = $locale->date($myconfig, $form->{fromdate}, 0, 0, 0);
 
 702     $form->{this_period} = "$shortfromdate<br>\n$shorttodate";
 
 703     $form->{longperiod}      =
 
 704         $locale->text('for Period')
 
 705       . qq|<br>\n$longfromdate |
 
 706       . $locale->text('to (date)')
 
 710   if ($form->{comparefromdate} || $form->{comparetodate}) {
 
 711     my $longcomparefromdate =
 
 712       $locale->date(\%myconfig, $form->{comparefromdate}, 1, 0, 0);
 
 713     my $shortcomparefromdate =
 
 714       $locale->date(\%myconfig, $form->{comparefromdate}, 0, 0, 0);
 
 716     my $longcomparetodate =
 
 717       $locale->date(\%myconfig, $form->{comparetodate}, 1, 0, 0);
 
 718     my $shortcomparetodate =
 
 719       $locale->date(\%myconfig, $form->{comparetodate}, 0, 0, 0);
 
 721     $form->{last_period} = "$shortcomparefromdate<br>\n$shortcomparetodate";
 
 722     $form->{longperiod} .=
 
 723         "<br>\n$longcomparefromdate "
 
 724       . $locale->text('to (date)')
 
 725       . qq| $longcomparetodate|;
 
 728   $form->{Datum_heute} =
 
 729     $locale->date(\%myconfig, $form->current_date(\%myconfig), 0, 0, 0);
 
 731   # setup variables for the form
 
 732   my @a = qw(company businessnumber tel fax email
 
 733     co_chief co_department co_custom1 co_custom2 co_custom3 co_custom4 co_custom5
 
 734     co_name1 co_name2  co_street co_street1 co_zip co_city co_city1 co_country co_tel co_tel1 co_tel2
 
 735     co_fax co_fax1 co_email co_email1 co_url co_url1 ustid duns
 
 736     co_bankname co_bankname1 co_bankname2 co_bankname3 co_blz co_blz1
 
 737     co_blz2 co_blz3 co_accountnr co_accountnr1 co_accountnr2 co_accountnr3);
 
 739   map { $form->{$_} = $myconfig{$_} } @a;
 
 741   if ($form->{address} ne '') {
 
 742     my $temp = $form->{address};
 
 743     $temp =~ s/\\n/<br \/>/;
 
 744     ($form->{co_street}, $form->{co_city}) = split("<br \/>", $temp);
 
 745     $form->{co_city} =~ s/\\n//g;
 
 748   ################################
 
 750   # Nation specific customisations
 
 752   ################################
 
 756   if ( $form->{coa} eq 'Germany-DATEV-SKR03EU' or $form->{coa} eq 'Germany-DATEV-SKR04EU') {
 
 759     # Outputformat specific customisation's
 
 762     my @category_cent = $ustva->report_variables({
 
 763         myconfig    => \%myconfig,
 
 766         attribute   => 'position',
 
 770     push @category_cent, qw(83  Z43  Z45  Z53  Z62  Z65  Z67);
 
 772     my @category_euro = $ustva->report_variables({
 
 773         myconfig    => \%myconfig,
 
 776         attribute   => 'position',
 
 781     $form->{amount} = [];
 
 783     if ( $form->{format} eq 'pdf' or $form->{format} eq 'postscript') {
 
 785       $form->{IN} = "$form->{type}-$form->{year}.tex";
 
 786       $form->{padding} = "~~";
 
 787       $form->{bold}    = "\textbf{";
 
 788       $form->{endbold} = "}";
 
 789       $form->{br}      = '\\\\';
 
 791       # Zahlenformatierung für Latex USTVA Formulare
 
 793       foreach my $number (@category_euro) {
 
 794         $form->{$number} = $form->format_amount(\%myconfig, $form->{$number}, '0', '');
 
 797       my ${decimal_comma} = ( $myconfig{numberformat} eq '1.000,00'
 
 798            or $myconfig{numberformat} eq '1000,00' ) ? ',':'.';
 
 800       foreach my $number (@category_cent) {
 
 801         $form->{$number} = $form->format_amount(\%myconfig, $form->{$number}, '2', '');
 
 802         $form->{$number} =~ s/${decimal_comma}/~~/g;
 
 805     } elsif ( $form->{format} eq 'html') { # Formatierungen für HTML Ausgabe
 
 807       $form->{IN} = $form->{type} . '.html';
 
 808       $form->{padding} = "  ";
 
 809       $form->{bold}    = "<b>";
 
 810       $form->{endbold} = "</b>";
 
 811       $form->{br}      = "<br>";
 
 812       $form->{address} =~ s/\\n/\n/g;
 
 814       foreach $number (@category_cent) {
 
 815         $form->{$number} = $form->format_amount(\%myconfig, $form->{$number}, '2', '0');
 
 818       foreach $number (@category_euro) {
 
 819         $form->{$number} = $form->format_amount(\%myconfig, $form->{$number}, '0', '0');
 
 822     } elsif ( $form->{format} eq 'elsterwinston' ) {
 
 824       $form->{IN} = 'winston.xml';
 
 827       # Build Winston filename
 
 830       my $file = 'U';     # 1. char 'U' = USTVA
 
 831       $file .= $form->{period};
 
 832       #4. and 5. char = year modulo 100
 
 833       $file .= sprintf("%02d", $form->{year} % 100);
 
 834       #6. to 18. char = Elstersteuernummer
 
 835       #Beispiel: Steuernummer in Bayern
 
 836       #111/222/33334 ergibt für UStVA Jan 2004: U01049111022233334
 
 837       $file .= $form->{elsterFFFF};
 
 838       $file .= $form->{elstersteuernummer};
 
 842       $form->{tmpfile} = "$userspath/$file";
 
 844       $form->{attachment_filename} = $file;
 
 846       # Zahlenformatierung für Winston
 
 848       my $temp_numberformat = $myconfig{numberformat};
 
 850       # Numberformat must be '1000.00' for Winston
 
 852       $myconfig{numberformat} = '1000.00';
 
 854       foreach my $number (@category_cent) {
 
 855         $form->{$number} = ( $form->{$number} !=0 ) ? $form->format_amount(\%myconfig, $form->{$number}, '2', '') : '';
 
 858       foreach my $number (@category_euro) {
 
 859         $form->{$number} = ( $form->{$number} !=0 ) ? $form->format_amount(\%myconfig, $form->{$number}, '0', '') : '';
 
 861       # Re-set Numberformat
 
 862       $myconfig{numberformat} = $temp_numberformat;
 
 864       # push Kennziffern to <%foreach Array fo easyer
 
 865       # output in xml format. Thx to Moritz.
 
 866       my %winston_id_for = (
 
 870       foreach my $kennziffer (@category_cent, @category_euro) {
 
 872         next if ( $kennziffer =~ m/Z\d\d/);
 
 873         next if (   $form->{$kennziffer} == 0 );
 
 875         if (defined $winston_id_for{$kennziffer} ) {
 
 876           push(@{ $form->{id}}, $winston_id_for{$kennziffer});
 
 878           push(@{ $form->{id}}, "Kz$kennziffer");
 
 880         push(@{ $form->{amount}}, $form->{$kennziffer});
 
 883     } elsif ( $form->{format} eq 'elstertaxbird' ) {
 
 885       # Define serveral filenames
 
 886       $form->{IN} = 'taxbird.txb';
 
 888       $form->{attachment_filename} = "USTVA-" . $form->{period}
 
 889       . sprintf("%02d", $form->{year} % 100) . ".txb";
 
 891       $form->{attachment_filename} =~ s|.*/||;
 
 892       $form->{tmpfile} = "$userspath/" . $form->{attachment_filename};
 
 894       # TODO: set Output to UTF-8 or system Preference
 
 895       #$form->{"iconv"} = Text::Iconv->new($myconfig{dbcharset}, "UTF-8");
 
 896       #my $iconv = $self->{"iconv"};
 
 897       #$iconv->convert($variable);
 
 898       if ($form->{period} =~ /^[4]\d$/ ){
 
 899         my %periods = ( # Lx => taxbird
 
 906         foreach my $quarter ( keys %periods ) {
 
 907           $form->{taxbird_period} = $periods{$quarter} if ( $form->{period} eq $quarter);
 
 909       } elsif ($form->{period} =~ /^\d+$/ ) {
 
 910         $form->{period} =~ s/^0//g;
 
 911         my $period = $form->{period};
 
 914         $form->{period} = $period;
 
 917         USTVA::error( $locale->text('Wrong Period' ));
 
 921       my $tax_office           = first { $_->{name} eq $form->{elsterland} } @{ $ustva->{tax_office_information} };
 
 922       $form->{taxbird_land_nr} = $tax_office->{taxbird_nr} if $tax_office;
 
 924       $form->{co_zip} = $form->{co_city};
 
 925       $form->{co_zip} =~ s/\D//g;
 
 926       $form->{co_city} =~ s/\d//g;
 
 927       $form->{co_city} =~ s/^\s//g;
 
 929       ($form->{co_phone_prefix}, $form->{co_phone}) = split("-", $form->{tel});
 
 930       $form->{co_phone_prefix} =~ s/\s//g;
 
 931       $form->{co_phone} =~ s/\s//g;
 
 933        $form->{taxbird_steuernummer} = $form->{steuernummer};
 
 934       #      $form->{taxbird_steuernummer} =~ s/\D//g;
 
 935       $form->{taxbird_steuernummer} =~ s/\///; # ersten Querstrich ersetzen
 
 937       # Numberformatting for Taxbird
 
 938       my $temp_numberformat = $myconfig{numberformat};
 
 939       # Numberformat must be '1000,00' for Taxbird ?!
 
 940       $myconfig{numberformat} = '1000,00';
 
 941       foreach my $number (@category_cent) {
 
 942         $form->{$number} = ( $form->{$number} !=0 ) ? $form->format_amount(\%myconfig, $form->{$number}, '2', '') : '';
 
 945       foreach my $number (@category_euro) {
 
 946         $form->{$number} = ( $form->{$number} !=0 ) ? $form->format_amount(\%myconfig, $form->{$number}, '0', '') : '';
 
 948       # Re-set Numberformat
 
 949       $myconfig{numberformat} = $temp_numberformat;
 
 951       # push Kennziffern to <%foreach Array fo easyer
 
 952       # output in xml format. Thx to Moritz.
 
 953       my %taxbird_id_for = (
 
 955           '511'  =>  'Kz51-calc',
 
 956           '861'  =>  'Kz86-calc',
 
 957           '971'  =>  'Kz97-calc',
 
 958           '931'  =>  'Kz93-calc',
 
 959           '811'  =>  'Kz81-calc',
 
 960           '891'  =>  'Kz89-calc',
 
 961           'Z45'  =>  'uebertrag',
 
 963           'Z62'  =>  'ust-minus-vost',
 
 964           'Z65'  =>  'ust-sum+69',
 
 969       for my $kennziffer (@category_cent, @category_euro) {
 
 971         next if ($kennziffer eq 'Z43');
 
 973         if ($form->{$kennziffer} != 0){
 
 974           if (defined $taxbird_id_for{$kennziffer}) {
 
 975             push(@{ $form->{id}}, $taxbird_id_for{$kennziffer});
 
 977             push(@{ $form->{id}}, "Kz$kennziffer");
 
 979           push(@{ $form->{amount}}, $form->{$kennziffer});
 
 983     } elsif ( $form->{format} eq '' ){ # No format error.
 
 985       USTVA::error( $locale->text('Application Error. No Format given' ) . "!");
 
 988     } else { # All other Formats are wrong
 
 990       USTVA::error( $locale->text('Application Error. Wrong Format') . ": " . $form->{format} );
 
 995   } else  # Outputformat for generic output
 
 998     my @category_cent = $ustva->report_variables({
 
 999         myconfig    => \%myconfig,
 
1002         attribute   => 'position',
 
1006     my @category_euro = $ustva->report_variables({
 
1007         myconfig    => \%myconfig,
 
1010         attribute   => 'position',
 
1014     $form->{USTVA} = [];
 
1016     if ( $form->{format} eq 'generic') { # Formatierungen für HTML Ausgabe
 
1019       for my $kennziffer (@category_cent, @category_euro) {
 
1021         $rec_ref->{id} = $kennziffer;
 
1022         $rec_ref->{amount} = $form->format_amount(\%myconfig, $form->{$kennziffer}, 2, '0');
 
1024         $lxdebug->message($LXDebug::DEBUG, "Kennziffer $kennziffer: '$form->{$kennziffer}'" );
 
1025         $lxdebug->dump($LXDebug::DEBUG, $rec_ref );
 
1026         push @ { $form->{USTVA} }, $rec_ref;
 
1033   if ( $form->{period} eq '13' and $form->{format} ne 'html') {
 
1037       'Yearly taxreport not yet implemented')
 
1041   $form->{templates} = $myconfig{templates};
 
1042   $form->{templates} = "doc" if ( $form->{type} eq 'help' );
 
1044   if ($form->{format} eq 'generic'){
 
1049         taxnumber => $myconfig{taxnumber},
 
1052     print($form->parse_html_template('ustva/generic_taxreport', $template_ref));
 
1057     $form->parse_template(\%myconfig, $userspath);
 
1061   $lxdebug->leave_sub();
 
1065   $lxdebug->enter_sub();
 
1067   $auth->assert('advance_turnover_tax_return');
 
1069 $form->{title} = $locale->text('Tax Office Preferences');
 
1071   # edit all taxauthority prefs
 
1075   my $ustva = USTVA->new();
 
1076   $ustva->get_config($userspath, 'finanzamt.ini');
 
1078   my $land = $form->{elsterland};
 
1079   my $amt  = $form->{elsterFFFF};
 
1082   $form->{title} = $locale->text('Tax Office Preferences');
 
1085   my $select_tax_office = $ustva->fa_auswahl($land, $amt, $ustva->query_finanzamt(\%myconfig, $form));
 
1086   my $checked_accrual = q|checked="checked"| if ($form->{method} eq 'accrual');
 
1087   my $checked_cash = q|checked="checked"| if ($form->{method} eq 'cash');
 
1088   my $checked_monthly = "checked" if ($form->{FA_voranmeld} eq 'month');
 
1089   my $checked_quarterly = "checked" if ($form->{FA_voranmeld} eq 'quarter');
 
1090   my $checked_dauerfristverlaengerung = "checked" if ($form->{FA_dauerfrist} eq '1');
 
1091   my $checked_kz_71 = "checked" if ($form->{FA_71} eq 'X');
 
1093   my $_hidden_variables_ref;
 
1095   my %_hidden_local_variables = (
 
1096     'saved'       => $locale->text('Check Details'),
 
1097     'nextsub'     => 'config_step2',
 
1101   foreach my $variable (keys %_hidden_local_variables) {
 
1102     push @{ $_hidden_variables_ref },
 
1103         { 'variable' => $variable, 'value' => $_hidden_local_variables{$variable} };
 
1106   my @_hidden_form_variables = qw(
 
1107     FA_Name             FA_Strasse        FA_PLZ
 
1108     FA_Ort              FA_Telefon        FA_Fax
 
1109     FA_PLZ_Grosskunden  FA_PLZ_Postfach   FA_Postfach
 
1110     FA_BLZ_1            FA_Kontonummer_1  FA_Bankbezeichnung_1
 
1111     FA_BLZ_2            FA_Kontonummer_2  FA_Bankbezeichnung_oertlich
 
1112     FA_Oeffnungszeiten  FA_Email          FA_Internet
 
1113     steuernummer        elsterland        elstersteuernummer
 
1117   foreach my $variable (@_hidden_form_variables) {
 
1118     push @{ $_hidden_variables_ref},
 
1119         { 'variable' => $variable, 'value' => $form->{$variable} };
 
1122 # Which COA is in use?
 
1124   $ustva->get_coa($form, \%myconfig);
 
1127   my $steuernummer_new = '';
 
1129   # Variablen für das Template zur Verfügung stellen
 
1130   my $template_ref = {
 
1131      select_tax_office               => $select_tax_office,
 
1132      checked_accrual                 => $checked_accrual,
 
1133      checked_cash                    => $checked_cash,
 
1134      checked_monthly                 => $checked_monthly,
 
1135      checked_quarterly               => $checked_quarterly,
 
1136      checked_dauerfristverlaengerung => $checked_dauerfristverlaengerung,
 
1137      hidden_variables                => $_hidden_variables_ref,
 
1141   # Ausgabe des Templates
 
1142   print($form->parse_html_template('ustva/config_step1', $template_ref));
 
1144   $lxdebug->leave_sub();
 
1148   $lxdebug->enter_sub();
 
1150   $auth->assert('advance_turnover_tax_return');
 
1158   my $elsterland         = '';
 
1159   my $elster_amt         = '';
 
1160   my $elsterFFFF         = '';
 
1161   my $elstersteuernummer = '';
 
1163   my $ustva = USTVA->new();
 
1164   $ustva->get_config($userspath, 'finanzamt.ini')
 
1165     if ($form->{saved} eq $locale->text('saved'));
 
1167   # Auf Übergabefehler checken
 
1168   USTVA::info(  $locale->text('Missing Tax Authoritys Preferences') . "\n"
 
1169               . $locale->text('USTVA-Hint: Tax Authoritys'))
 
1170     if (   $form->{elsterFFFF_new} eq 'Auswahl'
 
1171         || $form->{elsterland_new} eq 'Auswahl');
 
1172   USTVA::info(  $locale->text('Missing Method!') . "\n"
 
1173               . $locale->text('USTVA-Hint: Method'))
 
1174     if ($form->{method} eq '');
 
1176   # Klären, ob Variablen bereits befüllt sind UND ob veräderungen auf
 
1177   # der vorherigen Maske stattfanden: $change = 1(in der edit sub,
 
1178   # mittels get_config)
 
1180   my $change = $form->{elsterland} eq $form->{elsterland_new}
 
1181     && $form->{elsterFFFF} eq $form->{elsterFFFF_new} ? '0' : '1';
 
1182   $change = '0' if ($form->{saved} eq $locale->text('saved'));
 
1183   my $elster_init = $ustva->query_finanzamt(\%myconfig, $form);
 
1185   my %elster_init = %$elster_init;
 
1187   if ($change eq '1') {
 
1190     $elsterland           = $form->{elsterland_new};
 
1191     $elsterFFFF           = $form->{elsterFFFF_new};
 
1192     $form->{elsterland}   = $elsterland;
 
1193     $form->{elsterFFFF}   = $elsterFFFF;
 
1194     $form->{steuernummer} = '';
 
1196     create_steuernummer();
 
1198     # rebuild elster_amt
 
1200     foreach $amt (keys %{ $elster_init{ $form->{elsterland} } }) {
 
1202         if ($elster_init{ $form->{elsterland}{$amt} eq $form->{elsterFFFF} });
 
1205     # load the predefined hash data into the FA_* Vars
 
1206     my @variables = qw(FA_Name FA_Strasse FA_PLZ FA_Ort
 
1207       FA_Telefon FA_Fax FA_PLZ_Grosskunden FA_PLZ_Postfach
 
1209       FA_BLZ_1 FA_Kontonummer_1 FA_Bankbezeichnung_1
 
1210       FA_BLZ_2 FA_Kontonummer_2 FA_Bankbezeichnung_oertlich
 
1211       FA_Oeffnungszeiten FA_Email FA_Internet);
 
1213     for (my $i = 0; $i <= 20; $i++) {
 
1214       $form->{ $variables[$i] } =
 
1215         $elster_init->{$elsterland}->{$elsterFFFF}->[$i];
 
1220     $elsterland = $form->{elsterland};
 
1221     $elsterFFFF = $form->{elsterFFFF};
 
1224   my $stnr = $form->{steuernummer};
 
1226   my $patterncount   = $form->{patterncount};
 
1227   my $elster_pattern = $form->{elster_pattern};
 
1228   my $delimiter      = $form->{delimiter};
 
1229   my $steuernummer = $form->{steuernummer} if ($steuernummer eq '');
 
1231   $form->{FA_Oeffnungszeiten} =~ s/\\\\n/\n/g;
 
1234   $ustva->get_coa($form, \%myconfig);
 
1236   my $input_steuernummer = $ustva->steuernummer_input(
 
1237                              $form->{elsterland},
 
1238                              $form->{elsterFFFF},
 
1239                              $form->{steuernummer}
 
1242   $lxdebug->message(LXDebug::DEBUG1, qq|$input_steuernummer|);
 
1245   my $_hidden_variables_ref;
 
1247   my %_hidden_local_variables = (
 
1248       'elsterland'          => $elsterland,
 
1249       'elsterFFFF'          => $elsterFFFF,
 
1250       'warnung'             => $warnung,
 
1251       'elstersteuernummer'  => $elstersteuernummer,
 
1252       'steuernummer'        => $stnr,
 
1253       'lastsub'             => 'config_step1',
 
1254       'nextsub'             => 'save',
 
1258   foreach my $variable (keys %_hidden_local_variables) {
 
1259     push @{ $_hidden_variables_ref },
 
1260         { 'variable' => $variable, 'value' => $_hidden_local_variables{$variable} };
 
1263   my @_hidden_form_variables = qw(
 
1264     FA_steuerberater_name   FA_steuerberater_street
 
1265     FA_steuerberater_city   FA_steuerberater_tel
 
1273   foreach my $variable (@_hidden_form_variables) {
 
1274     push @{ $_hidden_variables_ref},
 
1275         { 'variable' => $variable, 'value' => $form->{$variable} };
 
1278   my $template_ref = {
 
1279      tax_office_data                 => $tax_office_data,
 
1280      input_steuernummer              => $input_steuernummer,
 
1281      readonly                        => '', #q|disabled="disabled"|,
 
1282      callback                        => $callback,
 
1283      hidden_variables                => $_hidden_variables_ref,
 
1286   # Ausgabe des Templates
 
1287   print($form->parse_html_template('ustva/config_step2', $template_ref));
 
1290   $lxdebug->leave_sub();
 
1293 sub create_steuernummer {
 
1294   $lxdebug->enter_sub();
 
1296   $auth->assert('advance_turnover_tax_return');
 
1298   my $part           = $form->{part};
 
1299   my $patterncount   = $form->{patterncount};
 
1300   my $delimiter      = $form->{delimiter};
 
1301   my $elster_pattern = $form->{elster_pattern};
 
1303   # rebuild steuernummer and elstersteuernummer
 
1304   # es gibt eine gespeicherte steuernummer $form->{steuernummer}
 
1305   # und die parts und delimiter
 
1310   my $steuernummer_new       = $part;
 
1311   my $elstersteuernummer_new = $form->{elster_FFFF};
 
1312   $elstersteuernummer_new .= '0';
 
1314   for ($h = 1; $h < $patterncount; $h++) {
 
1315     $steuernummer_new .= qq|$delimiter|;
 
1316     for (my $i = 1; $i <= length($elster_pattern); $i++) {
 
1317       $steuernummer_new       .= $form->{"part_$h\_$i"};
 
1318       $elstersteuernummer_new .= $form->{"part_$h\_$i"};
 
1321   if ($form->{steuernummer} ne $steuernummer_new) {
 
1322     $form->{steuernummer}       = $steuernummer_new;
 
1323     $form->{elstersteuernummer} = $elstersteuernummer_new;
 
1324     $form->{steuernummer_new}   = $steuernummer_new;
 
1326     $form->{steuernummer_new}       = '';
 
1327     $form->{elstersteuernummer_new} = '';
 
1329   $lxdebug->leave_sub();
 
1333   $lxdebug->enter_sub();
 
1335   $auth->assert('advance_turnover_tax_return');
 
1337   my $filename = "$form->{login}_$form->{filename}";
 
1338   $filename =~ s|.*/||;
 
1340   #zuerst die steuernummer aus den part, parts_X_Y und delimiter herstellen
 
1341   create_steuernummer();
 
1343   # Textboxen formatieren: Linebreaks entfernen
 
1345   $form->{FA_Oeffnungszeiten} =~ s/\r\n/\\n/g;
 
1347   #URL mit http:// davor?
 
1348   $form->{FA_Internet} =~ s/^http:\/\///;
 
1349   $form->{FA_Internet} = 'http://' . $form->{FA_Internet};
 
1352     elster              elsterland            elstersteuernummer  steuernummer
 
1353     elsteramt           elsterFFFF            FA_Name             FA_Strasse
 
1354     FA_PLZ              FA_Ort                FA_Telefon          FA_Fax
 
1355     FA_PLZ_Grosskunden  FA_PLZ_Postfach       FA_Postfach         FA_BLZ_1
 
1356     FA_Kontonummer_1    FA_Bankbezeichnung_1  FA_BLZ_2            FA_Kontonummer_2
 
1357     FA_Bankbezeichnung_oertlich FA_Oeffnungszeiten
 
1358     FA_Email FA_Internet FA_voranmeld method FA_steuerberater_name
 
1359     FA_steuerberater_street FA_steuerberater_city FA_steuerberater_tel
 
1360     FA_71 FA_dauerfrist);
 
1362   # Hier kommt dann die Plausibilitätsprüfung der ELSTERSteuernummer
 
1363   if ($form->{elstersteuernummer} ne '000000000') {
 
1365     $form->{elster} = '1';
 
1367     open my $ustvaconfig, ">", "$userspath/$filename" or $form->error("$filename : $!");
 
1369     # create the config file
 
1370     print {$ustvaconfig} qq|# Configuration file for USTVA\n\n|;
 
1372     foreach $key (sort @config) {
 
1373       $form->{$key} =~ s/\\/\\\\/g;
 
1375       $form->{$key} =~ s/\r\n/\n/g;
 
1377       print {$ustvaconfig} qq|$key=|;
 
1378       if ($form->{$key} ne 'Y') {
 
1379         print {$ustvaconfig} qq|$form->{$key}\n|;
 
1381       if ($form->{$key} eq 'Y') {
 
1382         print {$ustvaconfig} qq|checked \n|;
 
1385     print {$ustvaconfig} qq|\n\n|;
 
1387     $form->{saved} = $locale->text('saved');
 
1391     $form->{saved} = $locale->text('Choose a Tax Number');
 
1395   $lxdebug->leave_sub();
 
1400   $lxdebug->enter_sub();
 
1402   # allow Symbolic references just here:
 
1404   call_sub($form->{"nextsub"});
 
1406   $lxdebug->leave_sub();
 
1410   $lxdebug->enter_sub();
 
1411   call_sub($form->{"lastsub"});
 
1412   $lxdebug->leave_sub();