From: Udo Spallek Date: Wed, 11 Jul 2007 11:52:03 +0000 (+0000) Subject: Neues Modul 'Steuern Bearbeiten'. Mit diesem Modul ist es moeglich, die Eintraege... X-Git-Tag: release-2.4.3^2~17 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=d38be021dde6dae352b0d755d9574dfe2de9898d;p=kivitendo-erp.git Neues Modul 'Steuern Bearbeiten'. Mit diesem Modul ist es moeglich, die Eintraege der Tabelle tax, bzw. _tax anpassen zu koennen. --- diff --git a/SL/AM.pm b/SL/AM.pm index af52ae9a9..dc6774d87 100644 --- a/SL/AM.pm +++ b/SL/AM.pm @@ -2055,4 +2055,181 @@ sub swap_units { $main::lxdebug->leave_sub(); } +sub taxes { + $main::lxdebug->enter_sub(); + + my ($self, $myconfig, $form) = @_; + + # connect to database + my $dbh = $form->dbconnect($myconfig); + + my $query = qq|SELECT + t.id, + t.taxkey, + t.taxdescription, + round(t.rate, 2) * 100 AS rate, + c.accno AS taxnumber, + c.description AS account_description + FROM tax t + JOIN chart c on (chart_id = c.id) + ORDER BY taxkey|; + + $sth = $dbh->prepare($query); + $sth->execute || $form->dberror($query); + + $form->{TAX} = []; + while (my $ref = $sth->fetchrow_hashref(NAME_lc)) { + push @{ $form->{TAX} }, $ref; + } + + $sth->finish; + $dbh->disconnect; + + $main::lxdebug->leave_sub(); +} + +sub get_tax_accounts { + $main::lxdebug->enter_sub(); + + my ($self, $myconfig, $form) = @_; + + my $dbh = $form->dbconnect($myconfig); + + # get Accounts from chart + my $query = qq{ SELECT + id, + accno || ' - ' || description AS _taxaccount + FROM chart + WHERE link LIKE '%_tax%' + ORDER BY accno + }; + + $sth = $dbh->prepare($query); + $sth->execute || $form->dberror($query); + + $form->{ACCOUNTS} = []; + while (my $ref = $sth->fetchrow_hashref(NAME_lc)) { + push @{ $form->{ACCOUNTS} }, $ref; + } + + $sth->finish; + + $dbh->disconnect; + + $main::lxdebug->leave_sub(); +} + +sub get_tax { + $main::lxdebug->enter_sub(); + + my ($self, $myconfig, $form) = @_; + + # connect to database + my $dbh = $form->dbconnect($myconfig); + + my $query = qq|SELECT + taxkey, + taxdescription, + round(rate, 2) * 100 AS rate, + chart_id + FROM tax + WHERE id = ? |; + + my $sth = $dbh->prepare($query); + $sth->execute($form->{id}) || $form->dberror($query . " ($form->{id})"); + + my $ref = $sth->fetchrow_hashref(NAME_lc); + + map { $form->{$_} = $ref->{$_} } keys %$ref; + + $sth->finish; + + # see if it is used by a taxkey + $query = qq|SELECT count(*) FROM taxkeys + WHERE tax_id = ?|; + + ($form->{orphaned}) = selectrow_query($form, $dbh, $query, $form->{id}); + + $form->{orphaned} = !$form->{orphaned}; + $sth->finish; + + if (!$form->{orphaned} ) { + $query = qq|SELECT DISTINCT c.id, c.accno + FROM taxkeys tk + LEFT JOIN tax t ON (t.id = tk.tax_id) + LEFT JOIN chart c ON (c.id = tk.chart_id) + WHERE tk.tax_id = ?|; + + $sth = $dbh->prepare($query); + $sth->execute($form->{id}) || $form->dberror($query . " ($form->{id})"); + + $form->{TAXINUSE} = []; + while (my $ref = $sth->fetchrow_hashref(NAME_lc)) { + push @{ $form->{TAXINUSE} }, $ref; + } + + $sth->finish; + } + + $dbh->disconnect; + + $main::lxdebug->leave_sub(); +} + +sub save_tax { + $main::lxdebug->enter_sub(); + + my ($self, $myconfig, $form) = @_; + + # connect to database + my $dbh = $form->dbconnect($myconfig); + + $form->{rate} = $form->{rate} / 100; + + my @values = ($form->{taxkey}, $form->{taxdescription}, $form->{rate}, $form->{chart_id} ); + if ($form->{id}) { + $query = qq|UPDATE _tax SET + taxkey = ?, + taxdescription = ?, + rate = ?, + chart_id = ? + WHERE id = ?|; + push(@values, $form->{id}); + } + else { + #ok + $query = qq|INSERT INTO _tax ( + taxkey, + taxdescription, + rate, + chart_id + ) + VALUES (?, ?, ?, ? )|; + } + do_query($form, $dbh, $query, @values); + + $dbh->disconnect; + + $main::lxdebug->leave_sub(); +} + +sub delete_tax { + $main::lxdebug->enter_sub(); + + my ($self, $myconfig, $form) = @_; + + # connect to database + my $dbh = $form->dbconnect($myconfig); + + $query = qq|DELETE FROM _tax + WHERE id = ?|; + do_query($form, $dbh, $query, $form->{id}); + + $dbh->disconnect; + + $main::lxdebug->leave_sub(); +} + + + 1; diff --git a/bin/mozilla/am.pl b/bin/mozilla/am.pl index 02290c7b2..95bea4dcd 100644 --- a/bin/mozilla/am.pl +++ b/bin/mozilla/am.pl @@ -3137,3 +3137,120 @@ sub swap_units { $lxdebug->leave_sub(); } + +sub add_tax { + $lxdebug->enter_sub(); + + $form->{title} = $locale->text('Add'); + + $form->{callback} = + "$form->{script}?action=add_tax&login=$form->{login}&password=$form->{password}" + unless $form->{callback}; + + _get_taxaccount_selection(); + + $form->header(); + + my $parameters_ref = { +# ChartTypeIsAccount => $ChartTypeIsAccount, + }; + + # Ausgabe des Templates + print($form->parse_html_template('am/edit_tax', $parameters_ref)); + + $lxdebug->leave_sub(); +} + +sub edit_tax { + $lxdebug->enter_sub(); + + $form->{title} = $locale->text('Edit'); + + AM->get_tax(\%myconfig, \%$form); + _get_taxaccount_selection(); + + $form->header(); + + my $parameters_ref = { + }; + + # Ausgabe des Templates + print($form->parse_html_template('am/edit_tax', $parameters_ref)); + + $lxdebug->leave_sub(); +} + +sub list_tax { + $lxdebug->enter_sub(); + + AM->taxes(\%myconfig, \%$form); + + $form->{callback} = + "$form->{script}?action=list_tax&login=$form->{login}&password=$form->{password}"; + + $form->{title} = $locale->text('Tax-O-Matic'); + + $form->header(); + + # Ausgabe des Templates + print($form->parse_html_template('am/list_tax', $parameters_ref)); + + $lxdebug->leave_sub(); +} + +sub _get_taxaccount_selection{ + $lxdebug->enter_sub(); + + AM->get_tax_accounts(\%myconfig, \%$form); + + my $i = 0; + foreach my $taxaccount (@{ $form->{ACCOUNTS} } ) { + + # Fill in the Taxaxxounts as select options + if ($form->{chart_id} == $taxaccount->{id}) { + $form->{ACCOUNTS}[$i]{select_taxaccount} .= + qq|