Skip to content

Commit

Permalink
filter online payments with new -t option
Browse files Browse the repository at this point in the history
git-svn-id: svn://svn.mongueurs.net/act/trunk@999 67b57a05-4208-db11-a765-00306e02d86a
  • Loading branch information
Éric Cholet committed Jan 25, 2007
1 parent a50ee4a commit e0d4952
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions bin/paymentreport
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
#!/usr/bin/perl
use strict;
use DBI;
use Getopt::Std qw(getopts);
use Text::xSV;

use Act::Config;
use Act::Email;
use Act::Util;

# command line arguments
my %opts;
getopts('t:', \%opts);
my $recipient = shift or usage();
my @confs = @ARGV or usage();

Expand All @@ -16,14 +19,19 @@ Act::Util::db_connect();

# CSV file
my $csv = Text::xSV->new;
my $sth = $Request{dbh}->prepare(
my $sql =
'SELECT o.order_id, o.user_id, o.conf_id, o.datetime, u.first_name, u.last_name, u.email, o.amount, o.currency, o.means'
. ' FROM orders o, users u'
. ' WHERE o.user_id = u.user_id AND o.status = ?'
. ' AND o.conf_id IN (' . join(',', map '?', @confs) . ')'
. ' ORDER BY o.datetime'
);
$sth->execute('paid', @confs);
. ' WHERE o.user_id = u.user_id AND o.status = ?';
$sql .= ' AND o.means = ?' if $opts{t};
$sql .= ' AND o.conf_id IN (' . join(',', map '?', @confs) . ') ORDER BY o.datetime';
my $sth = $Request{dbh}->prepare($sql);
if ($opts{t}) {
$sth->execute('paid', $opts{t}, @confs);
}
else {
$sth->execute('paid', @confs);
}
my $body = $csv->format_row(qw(order_id user_id conf_id datetime first_name last_name email amount currency means));
while (my @row = $sth->fetchrow_array) {
$body .= $csv->format_row(@row);
Expand All @@ -41,5 +49,12 @@ Act::Email::send(

sub usage
{
die "Usage: $0 email conf_id [conf_id...]\n"
die <<EOF;
Usage: $0 [-t type] email conf_id [conf_id...]
Options:
-t type only report on transactions of type 'type',
where type if one of CASH, CHQ, ONLINE.
EOF
}

0 comments on commit e0d4952

Please sign in to comment.