1 package SL::Controller::AccTrans;
3 use parent qw(SL::Controller::Base);
4 use SL::DB::AccTransaction;
6 __PACKAGE__->run_before('check_auth');
8 sub action_list_transactions {
11 return $self->render('generic/error', { layout => 0 }, label_error => "list_transactions needs a trans_id") unless $::form->{trans_id};
13 my $transactions = SL::DB::Manager::AccTransaction->get_all(query => [ trans_id => $::form->{trans_id} ], sort_by => 'acc_trans_id ASC');
15 return $self->render(\'', { type => 'json' }) unless scalar @{$transactions};
17 my $acc_trans_table = $self->_mini_ledger($transactions);
18 my $balances_table = $self->_mini_trial_balance($transactions);
20 return $self->render('acc_trans/acc_trans', { header => 0 }, acc_trans_table => $acc_trans_table, balances_table => $balances_table);
24 my ($self, $transactions) = @_;
26 $::auth->assert('invoice_edit');
31 foreach my $t ( @{ $transactions } ) {
32 $debit_sum += $t->amount if $t->amount < 0;
33 $credit_sum += $t->amount if $t->amount > 0;
36 return $self->render('acc_trans/_mini_ledger', { output => 0 }, TRANSACTIONS => $transactions, debit_sum => $debit_sum, credit_sum => $credit_sum, title => $::locale->text('Transactions') );
39 sub _mini_trial_balance {
40 my ($self, $transactions) = @_;
42 $::auth->assert('invoice_edit');
45 foreach my $t ( @{ $transactions } ) {
46 $rec->{$t->chart->accno}->{description} = $t->chart->description;
47 $rec->{$t->chart->accno}->{accno} = $t->chart->accno;
48 $rec->{$t->chart->accno}->{balance} += $t->amount;
52 foreach ( sort keys %{ $rec } ) {
53 push @balances, $rec->{$_} if $rec->{$_}->{balance} != 0;
56 return $self->render('acc_trans/_mini_trial_balance', { output => 0 }, BALANCES => \@balances, title => $::locale->text('Balances') );
60 $::auth->assert('invoice_edit');
73 SL::Controller::AccTrans - module to list all transactions and balances of an invoice
77 list_transactions takes an id of an invoice and displays all the transactions in two HTML tables:
79 * 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.
81 * mini_trial_balance: list of all charts from the transactions with their current sum, shown as debit or credit.
83 The two tables are returned as an HTML div blob.
85 # sample code for console:
86 use SL::Controller::AccTrans;
87 # get an invoice (ar/ap/is/ir)
88 my $invoice = SL::DB::Manager::Invoice->find_by( invnumber => 1 );
89 # the function is called from an opened invoice and needs the trans_id as a parameter
90 $::form->{trans_id} = $invoice->id;
91 SL::Controller::AccTrans->action_list_transactions();
93 The HTML blob can also be opened directly as a url:
94 controller.pl?action=AccTrans/print_table&trans_id=7
104 G. Richardson E<lt>grichardson@kivitendo-premium.deE<gt>