Properly filter year
[infodrom.org/service.infodrom.org] / src / InfoCon / buch / infocon
index 49cd230..a8bfaca 100755 (executable)
@@ -1,7 +1,7 @@
 #! /usr/bin/perl
 
 #  infocon - Administration tool for InfoCon
-#  Copyright (c) 1998-2003,2005-8  Martin Schulze <joey@infodrom.org>
+#  Copyright (c) 1998-2003,2005-8,10  Martin Schulze <joey@infodrom.org>
 #
 #  This program is free software; you can redistribute it and/or modify
 #  it under the terms of the GNU General Public License as published by
@@ -132,9 +132,9 @@ sub sales_list
 
     if ($opt_year) {
        if ($where) {
-           $where .= " AND date ~* '$opt_year'";
+           $where .= " AND date LIKE '$opt_year%'";
        } else {
-           $where .= "date ~* '$opt_year'";
+           $where .= "date LIKE '$opt_year%'";
        }
     }
 
@@ -152,9 +152,15 @@ sub sales_list
        }
     }
 
+    if ($where !~ /visible/) {
+       $where .= " AND " if $where;
+       $where .= "visible = 1";
+    }
+
     $query  = "SELECT nr,date,description,price FROM $table";
     $query .= " WHERE $where" if ($where);
     $query .= " ORDER by date,nr";
+
     $sth = $dbh->prepare($query);
     if ($sth && (my $rc = $sth->execute) > 0) {
        print " Nr.   Datum  Bezeichnung                                 Betrag\n";
@@ -408,6 +414,7 @@ sub usage
     'unpay' => undef,
     'hide' => undef,
     'unhide' => undef,
+    'mailto' => undef,
     'buchung-input' => undef,
     'buchung-unpaid' => undef,
     'buchung-hidden' => undef,
@@ -420,7 +427,8 @@ my %options = (
     'hide=s' => \$data{hide},
     'unhide=s' => \$data{unhide},
     'year=i' => \$opt_year,
-    'direction=s' => \$opt_direction,
+    'direction|d=s' => \$opt_direction,
+    'mailto:s' => \$data{mailto},
     'all' => \$opt_all,
     'verbose' => \$opt_verbose,
     'help' => \&usage,
@@ -431,6 +439,7 @@ my %options = (
     'list-categories|lc' => \$data{'list-categories'},
     );
 
+my $cmdln = 'infocon ' . join (' ', @ARGV);
 GetOptions(%options);
 
 if ($opt_year != 0 && $opt_year < 2002) {
@@ -441,6 +450,19 @@ if (defined $opt_direction) {
     usage unless $opt_direction =~ /^(in|out)$/i;
 }
 
+if (defined $data{mailto}) {
+    if (open(STDOUT, "| /usr/sbin/sendmail -t")) {
+       print  "From: Joey Schulze <joey\@infodrom.org>\n";
+       printf "To: %s\n", length($data{mailto})?$data{mailto}:'Joey Schulze <joey@infodrom.org>';
+       printf "Subject: %s\n", $cmdln;
+       print  "MIME-Version: 1.0\n";
+       print  "Content-type: text/plain; charset=iso-8859-1\n";
+       print  "Content-Disposition: inline\n";
+       print  "Content-Transfer-Encoding: 8bit\n";
+       print  "\n";
+    }
+}
+
 if (defined $data{category}) {
     if (length($data{category})) {
        sales_list("category = '".$data{category}."'");
@@ -457,13 +479,13 @@ if (defined $data{category}) {
 } elsif (defined $data{'list-categories'}) {
     list_categories;
 } elsif (defined $data{pay}) {
-    pay_invoce($data{pay}, 1);
+    pay_invoice($data{pay}, 1);
 } elsif (defined $data{unpay}) {
-    pay_invoce($data{unpay}, 0);
+    pay_invoice($data{unpay}, 0);
 } elsif (defined $data{hide}) {
-    hide_invoce($data{hide}, 1);
+    hide_invoice($data{hide}, 1);
 } elsif (defined $data{unhide}) {
-    hide_invoce($data{unhide}, 0);
+    hide_invoice($data{unhide}, 0);
+} else {
+    usage;
 }
-
-usage;