Permalink
Browse files

filter online payments with new -t option

git-svn-id: svn://svn.mongueurs.net/act/trunk@999 67b57a05-4208-db11-a765-00306e02d86a
  • Loading branch information...
1 parent a50ee4a commit e0d49523b538cd9ed82c31a98566593e9c36a391 Éric Cholet committed Jan 25, 2007
Showing with 22 additions and 7 deletions.
  1. +22 −7 bin/paymentreport
View
@@ -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();
@@ -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);
@@ -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.