Projekt

Allgemein

Profil

Herunterladen (43,1 KB) Statistiken
| Zweig: | Markierung: | Revision:
d319704a Moritz Bunkus
#=====================================================================
# Lx-Office ERP
# Copyright (c) 2004 by Udo Spallek, Aachen
#
# Author: Udo Spallek
# Email: udono@gmx.net
# Web: http://www.lx-office.org
#
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#======================================================================
# German Tax authority Module and later ELSTER Interface
#======================================================================

1b026c0b Sven Schöling
use strict;
05c6840d Moritz Bunkus
use utf8;

40782548 Moritz Bunkus
require "bin/mozilla/common.pl";
d319704a Moritz Bunkus
#use strict;
#no strict 'refs';
#use diagnostics;
63a1c75d Stephan Köhler
#use warnings; # FATAL=> 'all';
d319704a Moritz Bunkus
#use vars qw($locale $form %myconfig);
#our ($myconfig);
#use CGI::Carp "fatalsToBrowser";

f8779cd3 Moritz Bunkus
use List::Util qw(first);

d319704a Moritz Bunkus
use SL::PE;
use SL::RP;
use SL::USTVA;
use SL::User;
1;

# this is for our long dates
# $locale->text('January')
# $locale->text('February')
# $locale->text('March')
# $locale->text('April')
# $locale->text('May ')
# $locale->text('June')
# $locale->text('July')
# $locale->text('August')
# $locale->text('September')
# $locale->text('October')
# $locale->text('November')
# $locale->text('December')

# this is for our short month
# $locale->text('Jan')
# $locale->text('Feb')
# $locale->text('Mar')
# $locale->text('Apr')
# $locale->text('May')
# $locale->text('Jun')
# $locale->text('Jul')
# $locale->text('Aug')
# $locale->text('Sep')
# $locale->text('Oct')
# $locale->text('Nov')
# $locale->text('Dec')
a205ed21 Udo Spallek
d319704a Moritz Bunkus
#############################

sub report {
0279167d Sven Schöling
$::lxdebug->enter_sub();
a205ed21 Udo Spallek
0279167d Sven Schöling
my $form = $::form;
my $locale = $::locale;
my %myconfig = %::myconfig;
8c7e4493 Moritz Bunkus
0279167d Sven Schöling
$::auth->assert('advance_turnover_tax_return');
6c0e5cb7 Moritz Bunkus
d319704a Moritz Bunkus
$form->{title} = $locale->text('UStVA');
6c0e5cb7 Moritz Bunkus
$form->{kz10} = ''; #Berichtigte Anmeldung? Ja =1 Nein=0
d319704a Moritz Bunkus
6ab3da45 Udo Spallek
my $year = substr($form->datetonum($form->current_date(\%myconfig), \%myconfig ),
0, 4);
d319704a Moritz Bunkus
my $department = '';
0279167d Sven Schöling
my $hide = '';
d319704a Moritz Bunkus
$form->header;

# Einlesen der Finanzamtdaten
f8779cd3 Moritz Bunkus
my $ustva = USTVA->new();
0705a2b2 Sven Schöling
$ustva->get_config($::lx_office_conf{paths}{userspath}, 'finanzamt.ini');
081a4f97 Moritz Bunkus
4dd73ccf Stephan Köhler
# Hier Einlesen der user-config
05c6840d Moritz Bunkus
# steuernummer entfernt für prerelease
a205ed21 Udo Spallek
my @a = qw(
9fb8eec8 Moritz Bunkus
signature name company address businessnumber
tel fax email co_chief co_department
a205ed21 Udo Spallek
co_custom1 co_custom2 co_custom3 co_custom4 co_custom5
9fb8eec8 Moritz Bunkus
co_name1 co_name2 co_street co_street1 co_zip
co_city co_city1 co_country co_tel co_tel1
a205ed21 Udo Spallek
co_tel2 co_fax co_fax1 co_email co_email1
9fb8eec8 Moritz Bunkus
co_url co_url1 ustid duns co_bankname
a205ed21 Udo Spallek
co_bankname1 co_bankname2 co_bankname3 co_blz co_blz1
9fb8eec8 Moritz Bunkus
co_blz2 co_blz3 co_accountnr co_accountnr1 co_accountnr2
a205ed21 Udo Spallek
co_accountnr3
);
4dd73ccf Stephan Köhler
0279167d Sven Schöling
map { $form->{$_} = $myconfig{$_} } @a;
d319704a Moritz Bunkus
a205ed21 Udo Spallek
my $openings = $form->{FA_Oeffnungszeiten};
$openings =~ s/\\\\n/<br>/g;

9fb8eec8 Moritz Bunkus
my $company_given = ($form->{company} ne '')
a205ed21 Udo Spallek
? qq|<h3>$form->{company}</h3>\n|
75ac5779 Moritz Bunkus
: qq|<a href="am.pl?action=config">|
a205ed21 Udo Spallek
. $locale->text('No Company Name given') . qq|!</a><br>|;

081a4f97 Moritz Bunkus
4dd73ccf Stephan Köhler
# Anpassungen der Variablennamen auf pre 2.1.1 Namen
05c6840d Moritz Bunkus
# klären, ob $form->{company_street|_address} gesetzt sind
d319704a Moritz Bunkus
if ($form->{address} ne '') {
my $temp = $form->{address};
963c5048 Sven Schöling
$temp =~ s/\n/<br \/>/;
4dd73ccf Stephan Köhler
($form->{co_street}, $form->{co_city}) = split("<br \/>", $temp);
963c5048 Sven Schöling
$form->{co_city} =~ s/\n//g;
4dd73ccf Stephan Köhler
}

a205ed21 Udo Spallek
9fb8eec8 Moritz Bunkus
my $address_given =
($form->{co_street} && ($form->{co_zip} || $form->{co_city}))
a205ed21 Udo Spallek
? qq|$form->{co_street}<br>|
. qq|$form->{co_street1}<br>|
. qq|$form->{co_zip} $form->{co_city}|
8c7e4493 Moritz Bunkus
: qq|<a href="am.pl?action=config|
9fb8eec8 Moritz Bunkus
. qq|&level=Programm--Preferences">|
. $locale->text('No Company Address given')
a205ed21 Udo Spallek
. qq|!</a>\n|;

081a4f97 Moritz Bunkus
$form->{co_email} = $form->{email} unless $form->{co_email};
$form->{co_tel} = $form->{tel} unless $form->{co_tel};
$form->{co_fax} = $form->{fax} unless $form->{co_fax};
$form->{co_url} = $form->{urlx} unless $form->{co_url};

d338ab57 Moritz Bunkus
my $taxnumber_given = ($form->{steuernummer} ne '') ? $form->{steuernummer} : qq|<a href="ustva.pl?action=config_step1">Keine Steuernummer hinterlegt!</a><br>|;
d319704a Moritz Bunkus
a205ed21 Udo Spallek
my $ustva_vorauswahl = &ustva_vorauswahl();
d319704a Moritz Bunkus
a205ed21 Udo Spallek
my @all_years = $form->all_years(\%myconfig);
d319704a Moritz Bunkus
9fb8eec8 Moritz Bunkus
my $select_year = qq|<select name=year title="|
a205ed21 Udo Spallek
. $locale->text('Year') . qq|">|;
foreach my $key (@all_years) {
$select_year .= qq|<option |;
$select_year .= qq|selected| if ($key eq $form->{year});
$select_year .= qq| >$key</option>|;
d319704a Moritz Bunkus
}
a205ed21 Udo Spallek
$select_year .= qq|</select>|;

my $_checked = '';
$_checked = "checked" if ($form->{kz10} eq '1');
my $checkbox_kz_10 = qq|<input name="FA_10" id=FA_10 class=checkbox|
. qq| type=checkbox value="1" $_checked title = "|
. $locale->text('Amended Advance Turnover Tax Return (Nr. 10)')
9fb8eec8 Moritz Bunkus
. qq|">|
. $locale->text('Amended Advance Turnover Tax Return');
a205ed21 Udo Spallek
9fb8eec8 Moritz Bunkus
my $method_local = ($form->{method} eq 'accrual') ? $locale->text('accrual')
a205ed21 Udo Spallek
: ($form->{method} eq 'cash') ? $locale->text('cash')
: '';

my $period_local = ( $form->{FA_voranmeld} eq 'month') ? $locale->text('month')
: ( $form->{FA_voranmeld} eq 'quarter') ? $locale->text('quarter')
9fb8eec8 Moritz Bunkus
: '';
a205ed21 Udo Spallek
my $tax_office_banks_ref = [
{ BLZ => $form->{FA_BLZ_1},
Kontonummer => $form->{FA_Kontonummer_1},
Bankbezeichnung => $form->{FA_Bankbezeichnung_1}
},
{ BLZ => $form->{FA_BLZ_2},
Kontonummer => $form->{FA_Kontonummer_2},
Bankbezeichnung => $form->{FA_Bankbezeichnung_oertlich}
d319704a Moritz Bunkus
}
a205ed21 Udo Spallek
];
9fb8eec8 Moritz Bunkus
# Which COA is in use?

0279167d Sven Schöling
$ustva->get_coa($form, \%myconfig);
ccd0b365 Udo Spallek
a205ed21 Udo Spallek
my $template_ref = {
9fb8eec8 Moritz Bunkus
openings => $openings,
a205ed21 Udo Spallek
company_given => $company_given,
9fb8eec8 Moritz Bunkus
address_given => $address_given,
a205ed21 Udo Spallek
taxnumber_given => $taxnumber_given,
0279167d Sven Schöling
taxnumber => $myconfig{taxnumber},
9fb8eec8 Moritz Bunkus
select_year => $select_year,
a205ed21 Udo Spallek
period_local => $period_local,
method_local => $method_local,
ustva_vorauswahl => $ustva_vorauswahl,
checkbox_kz_10 => $checkbox_kz_10,
9fb8eec8 Moritz Bunkus
tax_office_banks => $tax_office_banks_ref,
select_options => &show_options,
ccd0b365 Udo Spallek
a205ed21 Udo Spallek
};
9fb8eec8 Moritz Bunkus
9aaca433 Moritz Bunkus
print($form->parse_html_template('ustva/report', $template_ref));
d319704a Moritz Bunkus


0279167d Sven Schöling
$::lxdebug->leave_sub();
d319704a Moritz Bunkus
}

a205ed21 Udo Spallek
d319704a Moritz Bunkus
sub help {
0279167d Sven Schöling
$::lxdebug->enter_sub();
081a4f97 Moritz Bunkus
0279167d Sven Schöling
$::auth->assert('advance_turnover_tax_return');
8c7e4493 Moritz Bunkus
d319704a Moritz Bunkus
# parse help documents under doc
0279167d Sven Schöling
my $tmp = $::form->{templates};
$::form->{templates} = 'doc';
$::form->{help} = 'ustva';
$::form->{type} = 'help';
$::form->{format} = 'html';
generate_ustva();
d319704a Moritz Bunkus
#$form->{templates} = $tmp;
0279167d Sven Schöling
$::lxdebug->leave_sub();
d319704a Moritz Bunkus
}

sub show {
0279167d Sven Schöling
$::lxdebug->enter_sub();
081a4f97 Moritz Bunkus
0279167d Sven Schöling
$::auth->assert('advance_turnover_tax_return');
8c7e4493 Moritz Bunkus
d319704a Moritz Bunkus
#&generate_ustva();
0279167d Sven Schöling
$::lxdebug->leave_sub();
call_sub($::form->{"nextsub"});
d319704a Moritz Bunkus
}

sub ustva_vorauswahl {
0279167d Sven Schöling
$::lxdebug->enter_sub();
081a4f97 Moritz Bunkus
0279167d Sven Schöling
my $form = $::form;
my $locale = $::locale;
my %myconfig = %::myconfig;

$::auth->assert('advance_turnover_tax_return');
8c7e4493 Moritz Bunkus
a205ed21 Udo Spallek
my $select_vorauswahl;

d319704a Moritz Bunkus
#Aktuelles Datum zerlegen:
63a1c75d Stephan Köhler
my $date = $form->datetonum($form->current_date(\%myconfig), \%myconfig);
d319704a Moritz Bunkus
#$locale->date($myconfig, $form->current_date($myconfig), 0)=~ /(\d\d).(\d\d).(\d\d\d\d)/;
63a1c75d Stephan Köhler
$form->{day} = substr($date, 6, 2);
$form->{month} = substr($date, 4, 2);
$form->{year} = substr($date, 0, 4);
0279167d Sven Schöling
$::lxdebug->message(LXDebug->DEBUG1, qq|
9fb8eec8 Moritz Bunkus
Actual date from Database: $date\n
63a1c75d Stephan Köhler
Actual year from Database: $form->{year}\n
Actual day from Database: $form->{day}\n
Actual month from Database: $form->{month}\n|);
081a4f97 Moritz Bunkus
d319704a Moritz Bunkus
my $sel = '';
my $yymmdd = '';

# Testdaten erzeugen:
#$form->{day}= '11';
#$form->{month}= '01';
#$form->{year}= 2004;
a205ed21 Udo Spallek
$select_vorauswahl = qq|
d319704a Moritz Bunkus
<input type=hidden name=day value=$form->{day}>
<input type=hidden name=month value=$form->{month}>
<input type=hidden name=yymmdd value=$yymmdd>
<input type=hidden name=sel value=$sel>
a205ed21 Udo Spallek
|;
d319704a Moritz Bunkus
if ($form->{FA_voranmeld} eq 'month') {

# Vorauswahl bei monatlichem Voranmeldungszeitraum

6c0e5cb7 Moritz Bunkus
my %liste = ('01' => $locale->text('January'),
'02' => $locale->text('February'),
'03' => $locale->text('March'),
'04' => $locale->text('April'),
'05' => $locale->text('May'),
'06' => $locale->text('June'),
'07' => $locale->text('July'),
'08' => $locale->text('August'),
'09' => $locale->text('September'),
'10' => $locale->text('October'),
'11' => $locale->text('November'),
'12' => $locale->text('December'),
'13' => $locale->text('Yearly'),
);
081a4f97 Moritz Bunkus
d319704a Moritz Bunkus
my $yy = $form->{year} * 10000;
$yymmdd = "$form->{year}$form->{month}$form->{day}" * 1;
$sel = '';
6c0e5cb7 Moritz Bunkus
my $dfv = '';
081a4f97 Moritz Bunkus
05c6840d Moritz Bunkus
# Offset für Dauerfristverlängerung
63a1c75d Stephan Köhler
$dfv = '100' if ($form->{FA_dauerfrist} eq '1');
d319704a Moritz Bunkus
SWITCH: {
$yymmdd <= ($yy + 110 + $dfv) && do {
$form->{year} = $form->{year} - 1;
$sel = '12';
last SWITCH;
};
$yymmdd <= ($yy + 210 + $dfv) && do {
$sel = '01';
last SWITCH;
};
$yymmdd <= ($yy + 310 + $dfv) && do {
$sel = '02';
last SWITCH;
};
$yymmdd <= ($yy + 410 + $dfv) && do {
$sel = '03';
last SWITCH;
};
$yymmdd <= ($yy + 510 + $dfv) && do {
$sel = '04';
last SWITCH;
};
$yymmdd <= ($yy + 610 + $dfv) && do {
$sel = '05';
last SWITCH;
};
$yymmdd <= ($yy + 710 + $dfv) && do {
$sel = '06';
last SWITCH;
};
$yymmdd <= ($yy + 810 + $dfv) && do {
$sel = '07';
last SWITCH;
};
$yymmdd <= ($yy + 910 + $dfv) && do {
$sel = '08';
last SWITCH;
};
$yymmdd <= ($yy + 1010 + $dfv) && do {
$sel = '09';
last SWITCH;
};
$yymmdd <= ($yy + 1110 + $dfv) && do {
$sel = '10';
last SWITCH;
};
$yymmdd <= ($yy + 1210) && do {
$sel = '11';
last SWITCH;
};
$yymmdd <= ($yy + 1231) && do {
$sel = '12';
last SWITCH;
};

}
a205ed21 Udo Spallek
$select_vorauswahl .= qq|<select id="zeitraum" name="period" title="|
6c0e5cb7 Moritz Bunkus
. $locale->text('Select a period') . qq|" >|;

d319704a Moritz Bunkus
my $key = '';
foreach $key (sort keys %liste) {
my $selected = '';
$selected = 'selected' if ($sel eq $key);
a205ed21 Udo Spallek
$select_vorauswahl .= qq|
6c0e5cb7 Moritz Bunkus
<option value="$key" $selected> $liste{$key}</option>
a205ed21 Udo Spallek
|;
d319704a Moritz Bunkus
}
a205ed21 Udo Spallek
$select_vorauswahl .= qq|</select>|;
d319704a Moritz Bunkus
} elsif ($form->{FA_voranmeld} eq 'quarter') {

# Vorauswahl bei quartalsweisem Voranmeldungszeitraum
2e2e8ce6 Udo Spallek
my %liste = ('41' => $locale->text('1. Quarter'),
'42' => $locale->text('2. Quarter'),
'43' => $locale->text('3. Quarter'),
'44' => $locale->text('4. Quarter'),
081a4f97 Moritz Bunkus
'13' => $locale->text('Yearly'),);
d319704a Moritz Bunkus
my $yy = $form->{year} * 10000;
$yymmdd = "$form->{year}$form->{month}$form->{day}" * 1;
$sel = '';
05c6840d Moritz Bunkus
my $dfv = ''; # Offset für Dauerfristverlängerung
d319704a Moritz Bunkus
$dfv = '100' if ($form->{FA_dauerfrist} eq '1');

SWITCH: {
$yymmdd <= ($yy + 110 + $dfv) && do {
$form->{year} = $form->{year} - 1;
6ab3da45 Udo Spallek
$sel = '44';
d319704a Moritz Bunkus
last SWITCH;
};
$yymmdd <= ($yy + 410 + $dfv) && do {
6ab3da45 Udo Spallek
$sel = '41';
d319704a Moritz Bunkus
last SWITCH;
};
$yymmdd <= ($yy + 710 + $dfv) && do {
6ab3da45 Udo Spallek
$sel = '42';
d319704a Moritz Bunkus
last SWITCH;
};
$yymmdd <= ($yy + 1010 + $dfv) && do {
6ab3da45 Udo Spallek
$sel = '43';
d319704a Moritz Bunkus
last SWITCH;
};
$yymmdd <= ($yy + 1231) && do {
6ab3da45 Udo Spallek
$sel = '44';
d319704a Moritz Bunkus
};
}

a205ed21 Udo Spallek
$select_vorauswahl .= qq|<select id="zeitraum" name="period" title="|
d319704a Moritz Bunkus
. $locale->text('Select a period') . qq|" >|;
my $key = '';
foreach $key (sort keys %liste) {
my $selected = '';
$selected = 'selected' if ($sel eq $key);
a205ed21 Udo Spallek
$select_vorauswahl .= qq|
f575aa99 Stephan Köhler
<option value="$key" $selected>$liste{$key}</option>
d319704a Moritz Bunkus
|;
}
a205ed21 Udo Spallek
$select_vorauswahl .= qq|\n</select>
d319704a Moritz Bunkus
|;

} else {

# keine Vorauswahl bei Voranmeldungszeitraum
a205ed21 Udo Spallek
$select_vorauswahl .= qq|<select id="zeitraum" name="period" title="|
d319704a Moritz Bunkus
. $locale->text('Select a period') . qq|" >|;

2e2e8ce6 Udo Spallek
my %listea = ('41' => '1. Quarter',
'42' => '2. Quarter',
'43' => '3. Quarter',
'44' => '4. Quarter',);
d319704a Moritz Bunkus
my %listeb = ('01' => 'January',
'02' => 'February',
'03' => 'March',
'04' => 'April',
'05' => 'May',
'06' => 'June',
'07' => 'July',
'08' => 'August',
'09' => 'September',
'10' => 'October',
'11' => 'November',
f575aa99 Stephan Köhler
'12' => 'December',
081a4f97 Moritz Bunkus
'13' => 'Yearly',);
d319704a Moritz Bunkus
my $key = '';
foreach $key (sort keys %listea) {
a205ed21 Udo Spallek
$select_vorauswahl .= qq|
081a4f97 Moritz Bunkus
<option value="$key">|
. $locale->text("$listea{$key}")
. qq|</option>\n|;
d319704a Moritz Bunkus
}

foreach $key (sort keys %listeb) {
a205ed21 Udo Spallek
$select_vorauswahl .= qq|
081a4f97 Moritz Bunkus
<option value="$key">|
. $locale->text("$listeb{$key}")
. qq|</option>\n|;
d319704a Moritz Bunkus
}
a205ed21 Udo Spallek
$select_vorauswahl .= qq|</select>|;
d319704a Moritz Bunkus
}
0279167d Sven Schöling
$::lxdebug->leave_sub();
9fb8eec8 Moritz Bunkus
a205ed21 Udo Spallek
return $select_vorauswahl;
d319704a Moritz Bunkus
}

a205ed21 Udo Spallek
#sub config {
0279167d Sven Schöling
# $::lxdebug->enter_sub();
a205ed21 Udo Spallek
# config_step1();
0279167d Sven Schöling
# $::lxdebug->leave_sub();
a205ed21 Udo Spallek
#}
d319704a Moritz Bunkus
sub debug {
0279167d Sven Schöling
$::lxdebug->enter_sub();
$::form->debug();
$::lxdebug->leave_sub();
d319704a Moritz Bunkus
}

sub show_options {
0279167d Sven Schöling
$::lxdebug->enter_sub();
d319704a Moritz Bunkus
0279167d Sven Schöling
$::auth->assert('advance_turnover_tax_return');
8c7e4493 Moritz Bunkus
d319704a Moritz Bunkus
# $form->{PD}{$form->{type}} = "selected";
# $form->{DF}{$form->{format}} = "selected";
# $form->{OP}{$form->{media}} = "selected";
# $form->{SM}{$form->{sendmode}} = "selected";
my $type = qq| <input type=hidden name="type" value="ustva">|;
my $media = qq| <input type=hidden name="media" value="screen">|;
my $format =
qq| <option value=html selected>|
0279167d Sven Schöling
. $::locale->text('Preview')
d319704a Moritz Bunkus
. qq|</option>|;
0705a2b2 Sven Schöling
if ($::lx_office_conf{print_templates}{latex}) {
d319704a Moritz Bunkus
$format .=
qq| <option value=pdf>|
0279167d Sven Schöling
. $::locale->text('UStVA (PDF-Dokument)')
d319704a Moritz Bunkus
. qq|</option>|;
}

#my $disabled= qq|disabled="disabled"|;
#$disabled='' if ($form->{elster} eq '1' );
0279167d Sven Schöling
if ($::form->{elster} eq '1') {
d319704a Moritz Bunkus
$format .=
2e2e8ce6 Udo Spallek
qq|<option value=elsterwinston>|
0279167d Sven Schöling
. $::locale->text('ELSTER Export (Winston)')
2e2e8ce6 Udo Spallek
. qq|</option>|
. qq|<option value=elstertaxbird>|
0279167d Sven Schöling
. $::locale->text('ELSTER Export (Taxbird)')
9fb8eec8 Moritz Bunkus
. qq|</option>|;
d319704a Moritz Bunkus
}

#$format .= qq|<option value=elster>|.$locale->text('ELSTER Export nach Winston').qq|</option>|;
a205ed21 Udo Spallek
my $show_options = qq|
d319704a Moritz Bunkus
$type
$media
<select name=format title = "|
0279167d Sven Schöling
. $::locale->text('Choose Outputformat') . qq|">$format</select>
d319704a Moritz Bunkus
|;
0279167d Sven Schöling
$::lxdebug->leave_sub();
9fb8eec8 Moritz Bunkus
a205ed21 Udo Spallek
return $show_options;
d319704a Moritz Bunkus
}

sub generate_ustva {
0279167d Sven Schöling
$::lxdebug->enter_sub();

my $form = $::form;
my $locale = $::locale;
my %myconfig = %::myconfig;
d319704a Moritz Bunkus
0279167d Sven Schöling
$::auth->assert('advance_turnover_tax_return');
8c7e4493 Moritz Bunkus
0246e125 Moritz Bunkus
# Aufruf von get_config zum Einlesen der Finanzamtdaten aus finanzamt.ini
d319704a Moritz Bunkus
f8779cd3 Moritz Bunkus
my $ustva = USTVA->new();
0705a2b2 Sven Schöling
$ustva->get_config($::lx_office_conf{paths}{userspath}, 'finanzamt.ini');
d319704a Moritz Bunkus
6ab3da45 Udo Spallek
# init some form vars
d319704a Moritz Bunkus
my @anmeldungszeitraum =
9fb8eec8 Moritz Bunkus
qw('0401' '0402' '0403'
'0404' '0405' '0406'
'0407' '0408' '0409'
'0410' '0411' '0412'
b85b47c5 Udo Spallek
'0441' '0442' '0443' '0444');

2e2e8ce6 Udo Spallek
foreach my $item (@anmeldungszeitraum) {
d319704a Moritz Bunkus
$form->{$item} = "";
}

#forgotten the year --> thisyear
if ($form->{year} !~ m/^\d\d\d\d$/) {
081a4f97 Moritz Bunkus
$form->{year} = substr(
$form->datetonum(
$form->current_date(\%myconfig), \%myconfig
),
0, 4);
0279167d Sven Schöling
$::lxdebug->message(LXDebug->DEBUG1,
081a4f97 Moritz Bunkus
qq|Actual year from Database: $form->{year}\n|);
d319704a Moritz Bunkus
}

6ab3da45 Udo Spallek
#
# using dates in ISO-8601 format: yyyymmmdd for Postgres...
#
9fb8eec8 Moritz Bunkus
d319704a Moritz Bunkus
#yearly report
2e2e8ce6 Udo Spallek
if ($form->{period} eq "13") {
63a1c75d Stephan Köhler
$form->{fromdate} = "$form->{year}0101";
$form->{todate} = "$form->{year}1231";
d319704a Moritz Bunkus
}

#Quater reports
2e2e8ce6 Udo Spallek
if ($form->{period} eq "41") {
63a1c75d Stephan Köhler
$form->{fromdate} = "$form->{year}0101";
$form->{todate} = "$form->{year}0331";
d319704a Moritz Bunkus
$form->{'0441'} = "X";
}
2e2e8ce6 Udo Spallek
if ($form->{period} eq "42") {
63a1c75d Stephan Köhler
$form->{fromdate} = "$form->{year}0401";
$form->{todate} = "$form->{year}0630";
d319704a Moritz Bunkus
$form->{'0442'} = "X";
}
2e2e8ce6 Udo Spallek
if ($form->{period} eq "43") {
63a1c75d Stephan Köhler
$form->{fromdate} = "$form->{year}0701";
$form->{todate} = "$form->{year}0930";
d319704a Moritz Bunkus
$form->{'0443'} = "X";
}
2e2e8ce6 Udo Spallek
if ($form->{period} eq "44") {
63a1c75d Stephan Köhler
$form->{fromdate} = "$form->{year}1001";
$form->{todate} = "$form->{year}1231";
d319704a Moritz Bunkus
$form->{'0444'} = "X";
}

#Monthly reports
SWITCH: {
2e2e8ce6 Udo Spallek
$form->{period} eq "01" && do {
63a1c75d Stephan Köhler
$form->{fromdate} = "$form->{year}0101";
$form->{todate} = "$form->{year}0131";
d319704a Moritz Bunkus
$form->{'0401'} = "X";
last SWITCH;
};
2e2e8ce6 Udo Spallek
$form->{period} eq "02" && do {
63a1c75d Stephan Köhler
$form->{fromdate} = "$form->{year}0201";
d319704a Moritz Bunkus
#this works from 1901 to 2099, 1900 and 2100 fail.
my $leap = ($form->{year} % 4 == 0) ? "29" : "28";
63a1c75d Stephan Köhler
$form->{todate} = "$form->{year}02$leap";
d319704a Moritz Bunkus
$form->{"0402"} = "X";
last SWITCH;
};
2e2e8ce6 Udo Spallek
$form->{period} eq "03" && do {
63a1c75d Stephan Köhler
$form->{fromdate} = "$form->{year}0301";
$form->{todate} = "$form->{year}0331";
d319704a Moritz Bunkus
$form->{"0403"} = "X";
last SWITCH;
};
2e2e8ce6 Udo Spallek
$form->{period} eq "04" && do {
63a1c75d Stephan Köhler
$form->{fromdate} = "$form->{year}0401";
$form->{todate} = "$form->{year}0430";
d319704a Moritz Bunkus
$form->{"0404"} = "X";
last SWITCH;
};
2e2e8ce6 Udo Spallek
$form->{period} eq "05" && do {
63a1c75d Stephan Köhler
$form->{fromdate} = "$form->{year}0501";
$form->{todate} = "$form->{year}0531";
d319704a Moritz Bunkus
$form->{"0405"} = "X";
last SWITCH;
};
2e2e8ce6 Udo Spallek
$form->{period} eq "06" && do {
63a1c75d Stephan Köhler
$form->{fromdate} = "$form->{year}0601";
$form->{todate} = "$form->{year}0630";
d319704a Moritz Bunkus
$form->{"0406"} = "X";
last SWITCH;
};
2e2e8ce6 Udo Spallek
$form->{period} eq "07" && do {
63a1c75d Stephan Köhler
$form->{fromdate} = "$form->{year}0701";
$form->{todate} = "$form->{year}0731";
d319704a Moritz Bunkus
$form->{"0407"} = "X";
last SWITCH;
};
2e2e8ce6 Udo Spallek
$form->{period} eq "08" && do {
63a1c75d Stephan Köhler
$form->{fromdate} = "$form->{year}0801";
$form->{todate} = "$form->{year}0831";
d319704a Moritz Bunkus
$form->{"0408"} = "X";
last SWITCH;
};
2e2e8ce6 Udo Spallek
$form->{period} eq "09" && do {
63a1c75d Stephan Köhler
$form->{fromdate} = "$form->{year}0901";
$form->{todate} = "$form->{year}0930";
d319704a Moritz Bunkus
$form->{"0409"} = "X";
last SWITCH;
};
2e2e8ce6 Udo Spallek
$form->{period} eq "10" && do {
63a1c75d Stephan Köhler
$form->{fromdate} = "$form->{year}1001";
$form->{todate} = "$form->{year}1031";
d319704a Moritz Bunkus
$form->{"0410"} = "X";
last SWITCH;
};
2e2e8ce6 Udo Spallek
$form->{period} eq "11" && do {
63a1c75d Stephan Köhler
$form->{fromdate} = "$form->{year}1101";
$form->{todate} = "$form->{year}1130";
d319704a Moritz Bunkus
$form->{"0411"} = "X";
last SWITCH;
};
2e2e8ce6 Udo Spallek
$form->{period} eq "12" && do {
63a1c75d Stephan Köhler
$form->{fromdate} = "$form->{year}1201";
$form->{todate} = "$form->{year}1231";
d319704a Moritz Bunkus
$form->{"0412"} = "X";
last SWITCH;
};
}

596cb5d6 Sven Schöling
# Kontrollvariablen für die Templates
$form->{"year$_"} = ($form->{year} >= $_ ) ? "1":"0" for 2007..2107;
6ab3da45 Udo Spallek
# Get the USTVA
f8779cd3 Moritz Bunkus
$ustva->ustva(\%myconfig, \%$form);
081a4f97 Moritz Bunkus
63a1c75d Stephan Köhler
# reformat Dates to dateformat
081a4f97 Moritz Bunkus
$form->{fromdate} = $locale->date(\%myconfig, $form->{fromdate}, 0, 0, 0);

6ab3da45 Udo Spallek
$form->{todate} = $form->current_date(\%myconfig) unless $form->{todate};
081a4f97 Moritz Bunkus
$form->{todate} = $locale->date(\%myconfig, $form->{todate}, 0, 0, 0);
d319704a Moritz Bunkus
2e2e8ce6 Udo Spallek
$form->{longperiod} =
d319704a Moritz Bunkus
$locale->date(\%myconfig, $form->current_date(\%myconfig), 1, 0, 0);
63a1c75d Stephan Köhler
d319704a Moritz Bunkus
# if there are any dates construct a where
if ($form->{fromdate} || $form->{todate}) {

0279167d Sven Schöling
$form->{todate} = $form->current_date(\%myconfig) unless ($form->{todate});
d319704a Moritz Bunkus
0279167d Sven Schöling
my $longtodate = $locale->date(\%myconfig, $form->{todate}, 1, 0, 0);
my $shorttodate = $locale->date(\%myconfig, $form->{todate}, 0, 0, 0);
d319704a Moritz Bunkus
0279167d Sven Schöling
my $longfromdate = $locale->date(\%myconfig, $form->{fromdate}, 1, 0, 0);
my $shortfromdate = $locale->date(\%myconfig, $form->{fromdate}, 0, 0, 0);
d319704a Moritz Bunkus
$form->{this_period} = "$shortfromdate<br>\n$shorttodate";
2e2e8ce6 Udo Spallek
$form->{longperiod} =
d319704a Moritz Bunkus
$locale->text('for Period')
. qq|<br>\n$longfromdate |
6c3f16ab Udo Spallek
. $locale->text('to (date)')
d319704a Moritz Bunkus
. qq| $longtodate|;
}

if ($form->{comparefromdate} || $form->{comparetodate}) {
my $longcomparefromdate =
$locale->date(\%myconfig, $form->{comparefromdate}, 1, 0, 0);
my $shortcomparefromdate =
$locale->date(\%myconfig, $form->{comparefromdate}, 0, 0, 0);

my $longcomparetodate =
$locale->date(\%myconfig, $form->{comparetodate}, 1, 0, 0);
my $shortcomparetodate =
$locale->date(\%myconfig, $form->{comparetodate}, 0, 0, 0);

$form->{last_period} = "$shortcomparefromdate<br>\n$shortcomparetodate";
2e2e8ce6 Udo Spallek
$form->{longperiod} .=
d319704a Moritz Bunkus
"<br>\n$longcomparefromdate "
6c3f16ab Udo Spallek
. $locale->text('to (date)')
d319704a Moritz Bunkus
. qq| $longcomparetodate|;
}

$form->{Datum_heute} =
$locale->date(\%myconfig, $form->current_date(\%myconfig), 0, 0, 0);

# setup variables for the form
4dd73ccf Stephan Köhler
my @a = qw(company businessnumber 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_bankname1 co_bankname2 co_bankname3 co_blz co_blz1
co_blz2 co_blz3 co_accountnr co_accountnr1 co_accountnr2 co_accountnr3);

d319704a Moritz Bunkus
map { $form->{$_} = $myconfig{$_} } @a;

if ($form->{address} ne '') {
my $temp = $form->{address};
$temp =~ s/\\n/<br \/>/;
4dd73ccf Stephan Köhler
($form->{co_street}, $form->{co_city}) = split("<br \/>", $temp);
b39c8ce9 Moritz Bunkus
$form->{co_city} =~ s/\\n//g;
d319704a Moritz Bunkus
}

18942bd7 Udo Spallek
################################
6ab3da45 Udo Spallek
#
18942bd7 Udo Spallek
# Nation specific customisations
6ab3da45 Udo Spallek
#
18942bd7 Udo Spallek
################################
9fb8eec8 Moritz Bunkus
18942bd7 Udo Spallek
# Germany
9fb8eec8 Moritz Bunkus
18942bd7 Udo Spallek
if ( $form->{coa} eq 'Germany-DATEV-SKR03EU' or $form->{coa} eq 'Germany-DATEV-SKR04EU') {
9fb8eec8 Moritz Bunkus
18942bd7 Udo Spallek
#
# Outputformat specific customisation's
#
6ab3da45 Udo Spallek
f8779cd3 Moritz Bunkus
my @category_cent = $ustva->report_variables({
c1d8418b Udo Spallek
myconfig => \%myconfig,
form => $form,
type => '',
attribute => 'position',
dec_places => '2',
});
9fb8eec8 Moritz Bunkus
e3f9ee43 Sven Schöling
push @category_cent, qw(Z43 Z45 Z53 Z62 Z65 Z67);
c1d8418b Udo Spallek
f8779cd3 Moritz Bunkus
my @category_euro = $ustva->report_variables({
c1d8418b Udo Spallek
myconfig => \%myconfig,
form => $form,
type => '',
attribute => 'position',
dec_places => '0',
});

18942bd7 Udo Spallek
$form->{id} = [];
$form->{amount} = [];
6ab3da45 Udo Spallek
18942bd7 Udo Spallek
if ( $form->{format} eq 'pdf' or $form->{format} eq 'postscript') {
2e2e8ce6 Udo Spallek
18942bd7 Udo Spallek
$form->{IN} = "$form->{type}-$form->{year}.tex";
$form->{padding} = "~~";
$form->{bold} = "\textbf{";
$form->{endbold} = "}";
$form->{br} = '\\\\';
d319704a Moritz Bunkus
05c6840d Moritz Bunkus
# Zahlenformatierung für Latex USTVA Formulare
6ab3da45 Udo Spallek
18942bd7 Udo Spallek
foreach my $number (@category_euro) {
$form->{$number} = $form->format_amount(\%myconfig, $form->{$number}, '0', '');
}
6ab3da45 Udo Spallek
18942bd7 Udo Spallek
my ${decimal_comma} = ( $myconfig{numberformat} eq '1.000,00'
or $myconfig{numberformat} eq '1000,00' ) ? ',':'.';
6ab3da45 Udo Spallek
18942bd7 Udo Spallek
foreach my $number (@category_cent) {
$form->{$number} = $form->format_amount(\%myconfig, $form->{$number}, '2', '');
$form->{$number} =~ s/${decimal_comma}/~~/g;
}
6ab3da45 Udo Spallek
05c6840d Moritz Bunkus
} elsif ( $form->{format} eq 'html') { # Formatierungen für HTML Ausgabe
081a4f97 Moritz Bunkus
18942bd7 Udo Spallek
$form->{IN} = $form->{type} . '.html';
$form->{padding} = "&nbsp;&nbsp;";
$form->{bold} = "<b>";
$form->{endbold} = "</b>";
$form->{br} = "<br>";
$form->{address} =~ s/\\n/\n/g;
d319704a Moritz Bunkus
0279167d Sven Schöling
foreach my $number (@category_cent) {
18942bd7 Udo Spallek
$form->{$number} = $form->format_amount(\%myconfig, $form->{$number}, '2', '0');
}
9fb8eec8 Moritz Bunkus
0279167d Sven Schöling
foreach my $number (@category_euro) {
18942bd7 Udo Spallek
$form->{$number} = $form->format_amount(\%myconfig, $form->{$number}, '0', '0');
}
081a4f97 Moritz Bunkus
18942bd7 Udo Spallek
} elsif ( $form->{format} eq 'elsterwinston' ) {
6ab3da45 Udo Spallek
18942bd7 Udo Spallek
$form->{IN} = 'winston.xml';
9fb8eec8 Moritz Bunkus
18942bd7 Udo Spallek
#
# Build Winston filename
#
9fb8eec8 Moritz Bunkus
18942bd7 Udo Spallek
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
05c6840d Moritz Bunkus
#111/222/33334 ergibt für UStVA Jan 2004: U01049111022233334
18942bd7 Udo Spallek
$file .= $form->{elsterFFFF};
$file .= $form->{elstersteuernummer};
#file suffix
$file .= '.xml';
e1e19a48 Moritz Bunkus
$file =~ s|.*/||;
18942bd7 Udo Spallek
468b6bcf Udo Spallek
$form->{attachment_filename} = $file;
9fb8eec8 Moritz Bunkus
05c6840d Moritz Bunkus
# Zahlenformatierung für Winston
18942bd7 Udo Spallek
my $temp_numberformat = $myconfig{numberformat};

f03b6821 Sven Schöling
# Numberformat must be '1000,00' for Winston
18942bd7 Udo Spallek
f03b6821 Sven Schöling
$myconfig{numberformat} = '1000,00';
18942bd7 Udo Spallek
foreach my $number (@category_cent) {
$form->{$number} = ( $form->{$number} !=0 ) ? $form->format_amount(\%myconfig, $form->{$number}, '2', '') : '';
}
9fb8eec8 Moritz Bunkus
18942bd7 Udo Spallek
foreach my $number (@category_euro) {
$form->{$number} = ( $form->{$number} !=0 ) ? $form->format_amount(\%myconfig, $form->{$number}, '0', '') : '';
}
# Re-set Numberformat
$myconfig{numberformat} = $temp_numberformat;
6ab3da45 Udo Spallek
18942bd7 Udo Spallek
# push Kennziffern to <%foreach Array fo easyer
# output in xml format. Thx to Moritz.
my %winston_id_for = (
e9e216f5 Udo Spallek
# No Winston remap?!
18942bd7 Udo Spallek
);
6ab3da45 Udo Spallek
18942bd7 Udo Spallek
foreach my $kennziffer (@category_cent, @category_euro) {
9fb8eec8 Moritz Bunkus
18942bd7 Udo Spallek
next if ( $kennziffer =~ m/Z\d\d/);
next if ( $form->{$kennziffer} == 0 );
9fb8eec8 Moritz Bunkus
18942bd7 Udo Spallek
if (defined $winston_id_for{$kennziffer} ) {
push(@{ $form->{id}}, $winston_id_for{$kennziffer});
} else {
9fb8eec8 Moritz Bunkus
push(@{ $form->{id}}, "Kz$kennziffer");
18942bd7 Udo Spallek
}
push(@{ $form->{amount}}, $form->{$kennziffer});
9fb8eec8 Moritz Bunkus
}
6ab3da45 Udo Spallek
18942bd7 Udo Spallek
} elsif ( $form->{format} eq 'elstertaxbird' ) {
b9c7197f Udo Spallek
18942bd7 Udo Spallek
# Define serveral filenames
$form->{IN} = 'taxbird.txb';
b9c7197f Udo Spallek
b3b1b699 Moritz Bunkus
$form->{attachment_filename} = "USTVA-" . ($form->{period} * 1) . sprintf("%02d", $form->{year} % 100) . ".txb";
9fb8eec8 Moritz Bunkus
e1e19a48 Moritz Bunkus
$form->{attachment_filename} =~ s|.*/||;
18942bd7 Udo Spallek
# 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',
);
9fb8eec8 Moritz Bunkus
18942bd7 Udo Spallek
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};
0279167d Sven Schöling
$period *= 1;
18942bd7 Udo Spallek
$period--;
4eb1e2ea Sven Schöling
$form->{taxbird_period} = $period;
b9c7197f Udo Spallek
} else {
18942bd7 Udo Spallek
$form->header;
USTVA::error( $locale->text('Wrong Period' ));
b2945bf6 Sven Schöling
::end_of_request();
b9c7197f Udo Spallek
}
9fb8eec8 Moritz Bunkus
9a1c5b19 Sven Schöling
# 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;
}

f8779cd3 Moritz Bunkus
my $tax_office = first { $_->{name} eq $form->{elsterland} } @{ $ustva->{tax_office_information} };
$form->{taxbird_land_nr} = $tax_office->{taxbird_nr} if $tax_office;
9fb8eec8 Moritz Bunkus
18942bd7 Udo Spallek
($form->{co_phone_prefix}, $form->{co_phone}) = split("-", $form->{tel});
$form->{co_phone_prefix} =~ s/\s//g;
$form->{co_phone} =~ s/\s//g;
9fb8eec8 Moritz Bunkus
18942bd7 Udo Spallek
$form->{taxbird_steuernummer} = $form->{steuernummer};
# $form->{taxbird_steuernummer} =~ s/\D//g;
2906e829 Sven Schöling
# $form->{taxbird_steuernummer} =~ s/\///; # ersten Querstrich ersetzen
9fb8eec8 Moritz Bunkus
18942bd7 Udo Spallek
# 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', '') : '';
}
9fb8eec8 Moritz Bunkus
18942bd7 Udo Spallek
foreach my $number (@category_euro) {
$form->{$number} = ( $form->{$number} !=0 ) ? $form->format_amount(\%myconfig, $form->{$number}, '0', '') : '';
}
# Re-set Numberformat
$myconfig{numberformat} = $temp_numberformat;
9fb8eec8 Moritz Bunkus
18942bd7 Udo Spallek
# push Kennziffern to <%foreach Array fo easyer
# output in xml format. Thx to Moritz.
my %taxbird_id_for = (
9fb8eec8 Moritz Bunkus
18942bd7 Udo Spallek
'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',
);
9fb8eec8 Moritz Bunkus

18942bd7 Udo Spallek
for my $kennziffer (@category_cent, @category_euro) {
6ab3da45 Udo Spallek
18942bd7 Udo Spallek
next if ($kennziffer eq 'Z43');
6ab3da45 Udo Spallek
18942bd7 Udo Spallek
if ($form->{$kennziffer} != 0){
if (defined $taxbird_id_for{$kennziffer}) {
push(@{ $form->{id}}, $taxbird_id_for{$kennziffer});
} else {
9fb8eec8 Moritz Bunkus
push(@{ $form->{id}}, "Kz$kennziffer");
18942bd7 Udo Spallek
}
push(@{ $form->{amount}}, $form->{$kennziffer});
}
9fb8eec8 Moritz Bunkus
}

18942bd7 Udo Spallek
} elsif ( $form->{format} eq '' ){ # No format error.
6ab3da45 Udo Spallek
$form->header;
18942bd7 Udo Spallek
USTVA::error( $locale->text('Application Error. No Format given' ) . "!");
b2945bf6 Sven Schöling
::end_of_request();
9fb8eec8 Moritz Bunkus
18942bd7 Udo Spallek
} else { # All other Formats are wrong
$form->header;
USTVA::error( $locale->text('Application Error. Wrong Format') . ": " . $form->{format} );
b2945bf6 Sven Schöling
::end_of_request();
2e2e8ce6 Udo Spallek
}
18942bd7 Udo Spallek
9fb8eec8 Moritz Bunkus
ccd0b365 Udo Spallek
} else # Outputformat for generic output
{
18942bd7 Udo Spallek
f8779cd3 Moritz Bunkus
my @category_cent = $ustva->report_variables({
ccd0b365 Udo Spallek
myconfig => \%myconfig,
form => $form,
type => '',
attribute => 'position',
dec_places => '2',
});
11e6f144 Udo Spallek
f8779cd3 Moritz Bunkus
my @category_euro = $ustva->report_variables({
ccd0b365 Udo Spallek
myconfig => \%myconfig,
form => $form,
type => '',
attribute => 'position',
dec_places => '0',
});
11e6f144 Udo Spallek
ccd0b365 Udo Spallek
$form->{USTVA} = [];
18942bd7 Udo Spallek
05c6840d Moritz Bunkus
if ( $form->{format} eq 'generic') { # Formatierungen für HTML Ausgabe
9fb8eec8 Moritz Bunkus
ccd0b365 Udo Spallek
my $rec_ref = {};
for my $kennziffer (@category_cent, @category_euro) {
$rec_ref = {};
$rec_ref->{id} = $kennziffer;
$rec_ref->{amount} = $form->format_amount(\%myconfig, $form->{$kennziffer}, 2, '0');
9fb8eec8 Moritz Bunkus
0279167d Sven Schöling
$::lxdebug->message($LXDebug::DEBUG, "Kennziffer $kennziffer: '$form->{$kennziffer}'" );
$::lxdebug->dump($LXDebug::DEBUG, $rec_ref );
ccd0b365 Udo Spallek
push @ { $form->{USTVA} }, $rec_ref;
11e6f144 Udo Spallek
}
9fb8eec8 Moritz Bunkus
18942bd7 Udo Spallek
}
6ab3da45 Udo Spallek
ccd0b365 Udo Spallek
}
9fb8eec8 Moritz Bunkus
6ab3da45 Udo Spallek
if ( $form->{period} eq '13' and $form->{format} ne 'html') {
$form->header;
USTVA::info(
$locale->text(
'Yearly taxreport not yet implemented')
. '!');
}
9fb8eec8 Moritz Bunkus
2e2e8ce6 Udo Spallek
$form->{templates} = $myconfig{templates};
$form->{templates} = "doc" if ( $form->{type} eq 'help' );
d319704a Moritz Bunkus
ccd0b365 Udo Spallek
if ($form->{format} eq 'generic'){

$form->header();

0279167d Sven Schöling
my $template_ref = {
ccd0b365 Udo Spallek
taxnumber => $myconfig{taxnumber},
};

9aaca433 Moritz Bunkus
print($form->parse_html_template('ustva/generic_taxreport', $template_ref));
ccd0b365 Udo Spallek
} else
9fb8eec8 Moritz Bunkus
{
ccd0b365 Udo Spallek
0705a2b2 Sven Schöling
$form->parse_template(\%myconfig, $::lx_office_conf{paths}{userspath});
ccd0b365 Udo Spallek
}
d319704a Moritz Bunkus
0279167d Sven Schöling
$::lxdebug->leave_sub();
d319704a Moritz Bunkus
}

a205ed21 Udo Spallek
sub config_step1 {
0279167d Sven Schöling
$::lxdebug->enter_sub();
081a4f97 Moritz Bunkus
0279167d Sven Schöling
$::auth->assert('advance_turnover_tax_return');
8c7e4493 Moritz Bunkus
0279167d Sven Schöling
$::form->{title} = $::locale->text('Tax Office Preferences');
1de53cbf Sven Donath
d319704a Moritz Bunkus
# edit all taxauthority prefs

0279167d Sven Schöling
$::form->header;
f8779cd3 Moritz Bunkus
my $ustva = USTVA->new();
0705a2b2 Sven Schöling
$ustva->get_config($::lx_office_conf{paths}{userspath}, 'finanzamt.ini');
d319704a Moritz Bunkus
0279167d Sven Schöling
my $land = $::form->{elsterland};
my $amt = $::form->{elsterFFFF};
d319704a Moritz Bunkus
a205ed21 Udo Spallek
0279167d Sven Schöling
$::form->{title} = $::locale->text('Tax Office Preferences');
d319704a Moritz Bunkus

74fca575 Sven Schöling
my $select_tax_office = $ustva->fa_auswahl($land, $amt, $ustva->query_finanzamt(\%::myconfig, $::form));
my $checked_accrual = $::form->{method} eq 'accrual' ? q|checked="checked"| : '';
my $checked_cash = $::form->{method} eq 'cash' ? q|checked="checked"| : '';
my $checked_monthly = $::form->{FA_voranmeld} eq 'month' ? "checked" : '';
my $checked_quarterly = $::form->{FA_voranmeld} eq 'quarter' ? "checked" : '';
my $checked_dauerfristverlaengerung = $::form->{FA_dauerfrist} eq '1' ? "checked" : '';
my $checked_kz_71 = $::form->{FA_71} eq 'X' ? "checked" : '';
d319704a Moritz Bunkus
a205ed21 Udo Spallek
my $_hidden_variables_ref;
d319704a Moritz Bunkus
9fb8eec8 Moritz Bunkus
my %_hidden_local_variables = (
0279167d Sven Schöling
'saved' => $::locale->text('Check Details'),
a205ed21 Udo Spallek
'nextsub' => 'config_step2',
'warnung' => '0',
);

foreach my $variable (keys %_hidden_local_variables) {
9fb8eec8 Moritz Bunkus
push @{ $_hidden_variables_ref },
a205ed21 Udo Spallek
{ 'variable' => $variable, 'value' => $_hidden_local_variables{$variable} };
}
d319704a Moritz Bunkus
a205ed21 Udo Spallek
my @_hidden_form_variables = qw(
9fb8eec8 Moritz Bunkus
FA_Name FA_Strasse FA_PLZ
FA_Ort FA_Telefon FA_Fax
FA_PLZ_Grosskunden FA_PLZ_Postfach FA_Postfach
FA_BLZ_1 FA_Kontonummer_1 FA_Bankbezeichnung_1
a205ed21 Udo Spallek
FA_BLZ_2 FA_Kontonummer_2 FA_Bankbezeichnung_oertlich
FA_Oeffnungszeiten FA_Email FA_Internet
steuernummer elsterland elstersteuernummer
8c7e4493 Moritz Bunkus
elsterFFFF
a205ed21 Udo Spallek
);
d319704a Moritz Bunkus
a205ed21 Udo Spallek
foreach my $variable (@_hidden_form_variables) {
9fb8eec8 Moritz Bunkus
push @{ $_hidden_variables_ref},
0279167d Sven Schöling
{ 'variable' => $variable, 'value' => $::form->{$variable} };
d319704a Moritz Bunkus
}

9fb8eec8 Moritz Bunkus
# Which COA is in use?

0279167d Sven Schöling
$ustva->get_coa($::form, \%::myconfig);
ccd0b365 Udo Spallek
05c6840d Moritz Bunkus
# hä? kann die weg?
a205ed21 Udo Spallek
my $steuernummer_new = '';

05c6840d Moritz Bunkus
# Variablen für das Template zur Verfügung stellen
a205ed21 Udo Spallek
my $template_ref = {
select_tax_office => $select_tax_office,
checked_accrual => $checked_accrual,
checked_cash => $checked_cash,
checked_monthly => $checked_monthly,
checked_quarterly => $checked_quarterly,
checked_dauerfristverlaengerung => $checked_dauerfristverlaengerung,
hidden_variables => $_hidden_variables_ref,
9fb8eec8 Moritz Bunkus
a205ed21 Udo Spallek
};
9fb8eec8 Moritz Bunkus
a205ed21 Udo Spallek
# Ausgabe des Templates
0279167d Sven Schöling
print($::form->parse_html_template('ustva/config_step1', $template_ref));
a205ed21 Udo Spallek
0279167d Sven Schöling
$::lxdebug->leave_sub();
d319704a Moritz Bunkus
}

a205ed21 Udo Spallek
sub config_step2 {
0279167d Sven Schöling
$::lxdebug->enter_sub();

my $form = $::form;
my $locale = $::locale;
my %myconfig = %::myconfig;
8c7e4493 Moritz Bunkus
0279167d Sven Schöling
$::auth->assert('advance_turnover_tax_return');
8c7e4493 Moritz Bunkus
d319704a Moritz Bunkus
$form->header();
a205ed21 Udo Spallek
d319704a Moritz Bunkus
my $elsterland = '';
my $elster_amt = '';
my $elsterFFFF = '';
my $elstersteuernummer = '';
f8779cd3 Moritz Bunkus
my $ustva = USTVA->new();
0705a2b2 Sven Schöling
$ustva->get_config($::lx_office_conf{paths}{userspath}, 'finanzamt.ini')
d319704a Moritz Bunkus
if ($form->{saved} eq $locale->text('saved'));

05c6840d Moritz Bunkus
# Auf Übergabefehler checken
081a4f97 Moritz Bunkus
USTVA::info( $locale->text('Missing Tax Authoritys Preferences') . "\n"
. $locale->text('USTVA-Hint: Tax Authoritys'))
d319704a Moritz Bunkus
if ( $form->{elsterFFFF_new} eq 'Auswahl'
|| $form->{elsterland_new} eq 'Auswahl');
081a4f97 Moritz Bunkus
USTVA::info( $locale->text('Missing Method!') . "\n"
. $locale->text('USTVA-Hint: Method'))
d319704a Moritz Bunkus
if ($form->{method} eq '');

05c6840d Moritz Bunkus
# Klären, ob Variablen bereits befüllt sind UND ob veräderungen auf
d319704a Moritz Bunkus
# der vorherigen Maske stattfanden: $change = 1(in der edit sub,
# mittels get_config)

081a4f97 Moritz Bunkus
my $change = $form->{elsterland} eq $form->{elsterland_new}
d319704a Moritz Bunkus
&& $form->{elsterFFFF} eq $form->{elsterFFFF_new} ? '0' : '1';
$change = '0' if ($form->{saved} eq $locale->text('saved'));
f8779cd3 Moritz Bunkus
my $elster_init = $ustva->query_finanzamt(\%myconfig, $form);
d319704a Moritz Bunkus
my %elster_init = %$elster_init;

if ($change eq '1') {

05c6840d Moritz Bunkus
# Daten ändern
d319704a Moritz Bunkus
$elsterland = $form->{elsterland_new};
$elsterFFFF = $form->{elsterFFFF_new};
$form->{elsterland} = $elsterland;
$form->{elsterFFFF} = $elsterFFFF;
$form->{steuernummer} = '';
9fb8eec8 Moritz Bunkus
a205ed21 Udo Spallek
create_steuernummer();
d319704a Moritz Bunkus
# rebuild elster_amt
d7a9612c Sven Schöling
my $amt = $elster_init{$elsterFFFF};
d319704a Moritz Bunkus
# load the predefined hash data into the FA_* Vars
my @variables = qw(FA_Name FA_Strasse FA_PLZ FA_Ort
FA_Telefon FA_Fax FA_PLZ_Grosskunden FA_PLZ_Postfach
FA_Postfach
FA_BLZ_1 FA_Kontonummer_1 FA_Bankbezeichnung_1
FA_BLZ_2 FA_Kontonummer_2 FA_Bankbezeichnung_oertlich
FA_Oeffnungszeiten FA_Email FA_Internet);

for (my $i = 0; $i <= 20; $i++) {
$form->{ $variables[$i] } =
$elster_init->{$elsterland}->{$elsterFFFF}->[$i];
}

} else {

$elsterland = $form->{elsterland};
$elsterFFFF = $form->{elsterFFFF};

}
my $stnr = $form->{steuernummer};
$stnr =~ s/\D+//g;
my $patterncount = $form->{patterncount};
my $elster_pattern = $form->{elster_pattern};
my $delimiter = $form->{delimiter};
74fca575 Sven Schöling
my $steuernummer = $stnr eq '' ? $form->{steuernummer} : '';
d319704a Moritz Bunkus
a205ed21 Udo Spallek
$form->{FA_Oeffnungszeiten} =~ s/\\\\n/\n/g;
9fb8eec8 Moritz Bunkus

f8779cd3 Moritz Bunkus
$ustva->get_coa($form, \%myconfig);
a205ed21 Udo Spallek
f8779cd3 Moritz Bunkus
my $input_steuernummer = $ustva->steuernummer_input(
9fb8eec8 Moritz Bunkus
$form->{elsterland},
a205ed21 Udo Spallek
$form->{elsterFFFF},
$form->{steuernummer}
);

0279167d Sven Schöling
$::lxdebug->message(LXDebug->DEBUG1, qq|$input_steuernummer|);
9fb8eec8 Moritz Bunkus
a205ed21 Udo Spallek
my $_hidden_variables_ref;
d319704a Moritz Bunkus
a205ed21 Udo Spallek
my %_hidden_local_variables = (
'elsterland' => $elsterland,
'elsterFFFF' => $elsterFFFF,
0279167d Sven Schöling
'warnung' => 0,
a205ed21 Udo Spallek
'elstersteuernummer' => $elstersteuernummer,
'steuernummer' => $stnr,
'lastsub' => 'config_step1',
'nextsub' => 'save',
9fb8eec8 Moritz Bunkus
d319704a Moritz Bunkus
);
9fb8eec8 Moritz Bunkus
a205ed21 Udo Spallek
foreach my $variable (keys %_hidden_local_variables) {
9fb8eec8 Moritz Bunkus
push @{ $_hidden_variables_ref },
a205ed21 Udo Spallek
{ 'variable' => $variable, 'value' => $_hidden_local_variables{$variable} };
d319704a Moritz Bunkus
}
9fb8eec8 Moritz Bunkus
a205ed21 Udo Spallek
my @_hidden_form_variables = qw(
9fb8eec8 Moritz Bunkus
FA_steuerberater_name FA_steuerberater_street
a205ed21 Udo Spallek
FA_steuerberater_city FA_steuerberater_tel
FA_voranmeld method
9fb8eec8 Moritz Bunkus
FA_dauerfrist FA_71
elster
type elster_init
a205ed21 Udo Spallek
saved callback
);

foreach my $variable (@_hidden_form_variables) {
9fb8eec8 Moritz Bunkus
push @{ $_hidden_variables_ref},
a205ed21 Udo Spallek
{ 'variable' => $variable, 'value' => $form->{$variable} };
}

my $template_ref = {
input_steuernummer => $input_steuernummer,
readonly => '', #q|disabled="disabled"|,
0279167d Sven Schöling
callback => $form->{callback},
a205ed21 Udo Spallek
hidden_variables => $_hidden_variables_ref,
};
9fb8eec8 Moritz Bunkus
a205ed21 Udo Spallek
# Ausgabe des Templates
9aaca433 Moritz Bunkus
print($form->parse_html_template('ustva/config_step2', $template_ref));
a205ed21 Udo Spallek

0279167d Sven Schöling
$::lxdebug->leave_sub();
d319704a Moritz Bunkus
}

sub create_steuernummer {
0279167d Sven Schöling
$::lxdebug->enter_sub();
8c7e4493 Moritz Bunkus
0279167d Sven Schöling
$::auth->assert('advance_turnover_tax_return');
8c7e4493 Moritz Bunkus
0279167d Sven Schöling
my $part = $::form->{part};
my $patterncount = $::form->{patterncount};
my $delimiter = $::form->{delimiter};
my $elster_pattern = $::form->{elster_pattern};
d319704a Moritz Bunkus
# rebuild steuernummer and elstersteuernummer
# es gibt eine gespeicherte steuernummer $form->{steuernummer}
# und die parts und delimiter

my $h = 0;
my $i = 0;

my $steuernummer_new = $part;
0279167d Sven Schöling
my $elstersteuernummer_new = $::form->{elster_FFFF};
d319704a Moritz Bunkus
$elstersteuernummer_new .= '0';

for ($h = 1; $h < $patterncount; $h++) {
$steuernummer_new .= qq|$delimiter|;
for (my $i = 1; $i <= length($elster_pattern); $i++) {
0279167d Sven Schöling
$steuernummer_new .= $::form->{"part_$h\_$i"};
$elstersteuernummer_new .= $::form->{"part_$h\_$i"};
d319704a Moritz Bunkus
}
}
0279167d Sven Schöling
if ($::form->{steuernummer} ne $steuernummer_new) {
$::form->{steuernummer} = $steuernummer_new;
$::form->{elstersteuernummer} = $elstersteuernummer_new;
$::form->{steuernummer_new} = $steuernummer_new;
d319704a Moritz Bunkus
} else {
0279167d Sven Schöling
$::form->{steuernummer_new} = '';
$::form->{elstersteuernummer_new} = '';
d319704a Moritz Bunkus
}
0279167d Sven Schöling
$::lxdebug->leave_sub();
d319704a Moritz Bunkus
}

sub save {
0279167d Sven Schöling
$::lxdebug->enter_sub();
81afc40a Moritz Bunkus
0279167d Sven Schöling
$::auth->assert('advance_turnover_tax_return');
8c7e4493 Moritz Bunkus
0279167d Sven Schöling
my $filename = "$::form->{login}_$::form->{filename}";
81afc40a Moritz Bunkus
$filename =~ s|.*/||;
d319704a Moritz Bunkus
#zuerst die steuernummer aus den part, parts_X_Y und delimiter herstellen
a205ed21 Udo Spallek
create_steuernummer();
d319704a Moritz Bunkus
# Textboxen formatieren: Linebreaks entfernen
#
0279167d Sven Schöling
$::form->{FA_Oeffnungszeiten} =~ s/\r\n/\\n/g;
d319704a Moritz Bunkus
#URL mit http:// davor?
0279167d Sven Schöling
$::form->{FA_Internet} =~ s/^http:\/\///;
$::form->{FA_Internet} = 'http://' . $::form->{FA_Internet};
d319704a Moritz Bunkus
785ef602 Udo Spallek
my @config = qw(
elster elsterland elstersteuernummer steuernummer
elsteramt elsterFFFF FA_Name FA_Strasse
9fb8eec8 Moritz Bunkus
FA_PLZ FA_Ort FA_Telefon FA_Fax
FA_PLZ_Grosskunden FA_PLZ_Postfach FA_Postfach FA_BLZ_1
785ef602 Udo Spallek
FA_Kontonummer_1 FA_Bankbezeichnung_1 FA_BLZ_2 FA_Kontonummer_2
d319704a Moritz Bunkus
FA_Bankbezeichnung_oertlich FA_Oeffnungszeiten
FA_Email FA_Internet FA_voranmeld method FA_steuerberater_name
FA_steuerberater_street FA_steuerberater_city FA_steuerberater_tel
FA_71 FA_dauerfrist);

05c6840d Moritz Bunkus
# Hier kommt dann die Plausibilitätsprüfung der ELSTERSteuernummer
0279167d Sven Schöling
if ($::form->{elstersteuernummer} ne '000000000') {
9fb8eec8 Moritz Bunkus
0279167d Sven Schöling
$::form->{elster} = '1';
9fb8eec8 Moritz Bunkus
0705a2b2 Sven Schöling
open my $ustvaconfig, ">", "$::lx_office_conf{paths}{userspath}/$filename" or $::form->error("$filename : $!");
d319704a Moritz Bunkus
# create the config file
86f876b6 Udo Spallek
print {$ustvaconfig} qq|# Configuration file for USTVA\n\n|;
d319704a Moritz Bunkus
my $key = '';
foreach $key (sort @config) {
0279167d Sven Schöling
$::form->{$key} =~ s/\\/\\\\/g;
d319704a Moritz Bunkus
# strip M
0279167d Sven Schöling
$::form->{$key} =~ s/\r\n/\n/g;
a205ed21 Udo Spallek
86f876b6 Udo Spallek
print {$ustvaconfig} qq|$key=|;
0279167d Sven Schöling
if ($::form->{$key} ne 'Y') {
print {$ustvaconfig} qq|$::form->{$key}\n|;
d319704a Moritz Bunkus
}
0279167d Sven Schöling
if ($::form->{$key} eq 'Y') {
86f876b6 Udo Spallek
print {$ustvaconfig} qq|checked \n|;
d319704a Moritz Bunkus
}
}
86f876b6 Udo Spallek
print {$ustvaconfig} qq|\n\n|;
close $ustvaconfig;
0279167d Sven Schöling
$::form->{saved} = $::locale->text('saved');
d319704a Moritz Bunkus
} else {

0279167d Sven Schöling
$::form->{saved} = $::locale->text('Choose a Tax Number');
d319704a Moritz Bunkus
}

a205ed21 Udo Spallek
config_step2();
0279167d Sven Schöling
$::lxdebug->leave_sub();
d319704a Moritz Bunkus
}


sub continue {
0279167d Sven Schöling
$::lxdebug->enter_sub();
081a4f97 Moritz Bunkus
d319704a Moritz Bunkus
# allow Symbolic references just here:
0279167d Sven Schöling
call_sub($::form->{"nextsub"});
$::lxdebug->leave_sub();
d319704a Moritz Bunkus
}

081a4f97 Moritz Bunkus
sub back {
0279167d Sven Schöling
$::lxdebug->enter_sub();
call_sub($::form->{"lastsub"});
$::lxdebug->leave_sub();
4dd73ccf Stephan Köhler
}