From 4e1e8352aed6d02c28116ea5afe82bf93d62bcba Mon Sep 17 00:00:00 2001 From: "G. Richardson" Date: Mon, 13 Oct 2014 16:29:12 +0200 Subject: [PATCH] Buchungen in ar/ap/is/ir in eigenem Tabreiter anzeigen MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Neuer Reiter "Buchungen", wo zu einer Rechnung/Buchung die Buchungen laut acc_trans angezeigt werden. In einer Tabelle "Buchungen" werden alle Buchungen laut acc_trans angezeigt. In einer Tabelle "Salden" werden die aktuellen Salden der bebuchten Konten angezeigt, ausgeglichene Konten werden herausgefiltert. Nicht für Dialogbuchungen umgesetzt. Es wird auf das FiBu-Recht (general_ledger) geprüft, ansonsten wird der Reiter nicht angezeigt --- SL/Controller/AccTrans.pm | 106 ++++++++++++++++++++ locale/de/all | 2 + templates/webpages/acc_trans/acc_trans.html | 4 + templates/webpages/ap/form_header.html | 1 + templates/webpages/ar/form_header.html | 1 + templates/webpages/ir/form_header.html | 1 + templates/webpages/is/form_header.html | 1 + 7 files changed, 116 insertions(+) create mode 100644 SL/Controller/AccTrans.pm create mode 100644 templates/webpages/acc_trans/acc_trans.html diff --git a/SL/Controller/AccTrans.pm b/SL/Controller/AccTrans.pm new file mode 100644 index 000000000..baf435560 --- /dev/null +++ b/SL/Controller/AccTrans.pm @@ -0,0 +1,106 @@ +package SL::Controller::AccTrans; +use strict; +use parent qw(SL::Controller::Base); +use SL::DB::AccTransaction; + +__PACKAGE__->run_before('check_auth'); + +sub action_list_transactions { + my ($self) = @_; + + return $self->render('generic/error', { layout => 0 }, label_error => "list_transactions needs a trans_id") unless $::form->{trans_id}; + + my $transactions = SL::DB::Manager::AccTransaction->get_all(query => [ trans_id => $::form->{trans_id} ], sort_by => 'acc_trans_id ASC'); + + return $self->render(\'', { type => 'json' }) unless scalar @{$transactions}; + + my $acc_trans_table = $self->_mini_ledger($transactions); + my $balances_table = $self->_mini_trial_balance($transactions); + + return $self->render('acc_trans/acc_trans', { header => 0 }, acc_trans_table => $acc_trans_table, balances_table => $balances_table); +} + +sub _mini_ledger { + my ($self, $transactions) = @_; + + $::auth->assert('general_ledger'); + + my $debit_sum = 0; + my $credit_sum = 0; + + foreach my $t ( @{ $transactions } ) { + $debit_sum += $t->amount if $t->amount < 0; + $credit_sum += $t->amount if $t->amount > 0; + }; + + return $self->render('acc_trans/_mini_ledger', { output => 0 }, TRANSACTIONS => $transactions, debit_sum => $debit_sum, credit_sum => $credit_sum, title => $::locale->text('Transactions') ); +} + +sub _mini_trial_balance { + my ($self, $transactions) = @_; + + $::auth->assert('general_ledger'); + + my $rec = {}; + foreach my $t ( @{ $transactions } ) { + $rec->{$t->chart->accno}->{description} = $t->chart->description; + $rec->{$t->chart->accno}->{accno} = $t->chart->accno; + $rec->{$t->chart->accno}->{balance} += $t->amount; + }; + + my @balances; + foreach ( sort keys %{ $rec } ) { + push @balances, $rec->{$_} if $rec->{$_}->{balance} != 0; + }; + + return $self->render('acc_trans/_mini_trial_balance', { output => 0 }, BALANCES => \@balances, title => $::locale->text('Balances') ); +} + +sub check_auth { + $::auth->assert('general_ledger'); +} + +1; + +__END__ + +=pod + +=encoding utf8 + +=head1 NAME + +SL::Controller::AccTrans - module to list all transactions and balances of an invoice + +=head1 SYNOPSIS + + list_transactions takes an id of an invoice and displays all the transactions in two HTML tables: + + * mini_ledger: list of all transactions of the invoice, showing date, chart info and the amount as debit or credit, like a small general ledger just for this invoice. + + * mini_trial_balance: list of all charts from the transactions with their current sum, shown as debit or credit. + + The two tables are returned as an HTML div blob. + + # sample code for console: + use SL::Controller::AccTrans; + # get an invoice (ar/ap/is/ir) + my $invoice = SL::DB::Manager::Invoice->find_by( invnumber => 1 ); + # the function is called from an opened invoice and needs the trans_id as a parameter + $::form->{trans_id} = $invoice->id; + SL::Controller::AccTrans->action_list_transactions(); + + The HTML blob can also be opened directly as a url: + controller.pl?action=AccTrans/print_table&trans_id=7 + +=head1 TODO + +=head1 BUGS + +Nothing here yet. + +=head1 AUTHOR + +G. Richardson Egrichardson@kivitendo-premium.deE + +=cut diff --git a/locale/de/all b/locale/de/all index 295ee31e2..3458a2738 100755 --- a/locale/de/all +++ b/locale/de/all @@ -305,6 +305,7 @@ $self->{texts} = { 'Balance Sheet' => 'Bilanz', 'Balance sheet date' => 'Bilanzstichtag', 'Balance startdate method' => 'Methode zur Ermittlung des Startdatums für Bilanz', + 'Balances' => 'Salden', 'Balancing' => 'Bilanzierung', 'Bank' => 'Bank', 'Bank Code' => 'BLZ', @@ -2714,6 +2715,7 @@ $self->{texts} = { 'Transaction has already been cancelled!' => 'Diese Buchung wurde bereits storniert.', 'Transaction has been split on both the credit and the debit side' => 'Sowohl auf der Soll- als auch auf der Haben-Seite gesplittete Buchung', 'Transaction posted!' => 'Buchung verbucht!', + 'Transactions' => 'Buchungen', 'Transactions without account:' => 'Buchungen ohne Konto:', 'Transactions without reference:' => 'Buchungen ohne Referenz:', 'Transactions, AR transactions, AP transactions' => 'Dialogbuchen, Debitorenrechnungen, Kreditorenrechnungen', diff --git a/templates/webpages/acc_trans/acc_trans.html b/templates/webpages/acc_trans/acc_trans.html new file mode 100644 index 000000000..2c7fc1ac4 --- /dev/null +++ b/templates/webpages/acc_trans/acc_trans.html @@ -0,0 +1,4 @@ +[% acc_trans_table %] +

+[% balances_table %] + diff --git a/templates/webpages/ap/form_header.html b/templates/webpages/ap/form_header.html index 81861fcf6..b686d04d4 100644 --- a/templates/webpages/ap/form_header.html +++ b/templates/webpages/ap/form_header.html @@ -83,6 +83,7 @@
  • [% 'Basic Data' | $T8 %]
  • [%- IF id %]
  • [% 'Linked Records' | $T8 %]
  • +
  • [% 'Transactions' | $T8 %]
  • [%- END %] diff --git a/templates/webpages/ar/form_header.html b/templates/webpages/ar/form_header.html index 538863138..ba4fa351c 100644 --- a/templates/webpages/ar/form_header.html +++ b/templates/webpages/ar/form_header.html @@ -24,6 +24,7 @@
  • [% 'Basic Data' | $T8 %]
  • [%- IF id %]
  • [% 'Linked Records' | $T8 %]
  • +
  • [% 'Transactions' | $T8 %]
  • [%- END %] diff --git a/templates/webpages/ir/form_header.html b/templates/webpages/ir/form_header.html index f5af2b451..e36c12002 100644 --- a/templates/webpages/ir/form_header.html +++ b/templates/webpages/ir/form_header.html @@ -34,6 +34,7 @@ [%- END %] [%- IF id %]
  • [% 'Linked Records' | $T8 %]
  • +
  • [% 'Transactions' | $T8 %]
  • [%- END %] diff --git a/templates/webpages/is/form_header.html b/templates/webpages/is/form_header.html index d0c645194..028cc1e84 100644 --- a/templates/webpages/is/form_header.html +++ b/templates/webpages/is/form_header.html @@ -35,6 +35,7 @@ [%- END %] [%- IF id %]
  • [% 'Linked Records' | $T8 %]
  • +
  • [% 'Transactions' | $T8 %]
  • [%- END %] -- 2.20.1