#!/usr/bin/perl -w use strict; use Apache::Request; use Apache::Okcomputer qw(:all); use Okcomputer::Qofbux qw(:all); use Okcomputer::User; use HTML::Template; my $r = Apache::Request->new(Apache->request); my $user = Okcomputer::User->new($r->connection->user); warn "no user object!" unless $user; my $use_tables = $r->param('tables') || 1; my $templ_file = $use_tables ? 'status-tables.html' : 'status.html'; my $template = HTML::Template->new(filename => $templ_file); $r->content_type('text/html'); $r->send_http_header; my $uid = $user->uid; warn "no uid!" unless $uid; my (@owes, @owed); for my $group (0, $user->groups('qofbux')) { my ($realm, $groupname); if ($group == 0) { $realm = 0; $groupname = 'all'; } else { $realm = $group->id; $groupname = $group->name; } # FIXME sort these overall, not just within each realm push @owes, @{money_owed_by_user($uid, $realm)}; push @owed, @{money_owed_to_user($uid, $realm)}; } # show a total if more than one person is involved my ($owes_total, $owed_total); if (@owes > 1) { $owes_total += $_->{amount} for @owes } if (@owed > 1) { $owed_total += $_->{amount} for @owed } # ugh... format the numbers, but only if !0 $owes_total = sprintf("%.2f", $owes_total) if $owes_total; $owed_total = sprintf("%.2f", $owed_total) if $owed_total; $template->param(title => 'status', name => $user->name, menu => qofbux_menu('status'), owes => \@owes, owed => \@owed, owes_total => $owes_total, owed_total => $owed_total, purchases_by => purchases_by_user($uid, 10), purchases_for => purchases_for_user($uid, 10), ); print $template->output;