#! /usr/bin/perl
# infocon - Admin-Tool for InfoCon
-# Copyright (c) 1998-2002 Martin Schulze <joey@infodrom.org>
-
+# Copyright (c) 1998-2002,2003 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
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
-
+#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
-
+#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
# $Id$
use DBI;
+use Term::ReadLine;
$table = "sales";
$engine = "dbi:Pg:dbname=infocon";
return sprintf("%4d%02d%02d", $year,$mon,$day);
}
+# --buchung-visible
+#
+sub toggle_visibility
+{
+ my $nr = shift;
+ my $query;
+ my @row;
+ my $sth;
+ my $value;
+
+ $query = "SELECT nr,visible FROM sales WHERE nr = $nr";
+ $sth = $dbh->prepare($query);
+ if ($sth && ($rc = $sth->execute) > 0) {
+ @row = $sth->fetchrow_array;
+ $value = $row[1]==1?0:1;
+
+ $query = "UPDATE sales SET visible=$value WHERE nr = $nr";
+ $sth = $dbh->do($query);
+ }
+}
+
sub pay_invoice
{
my $nr = shift;
my $pay = shift;
my $value = $pay==1?1:0;
my $query;
- my @row;
my $sth;
$query = "UPDATE sales SET paid=$value WHERE nr = $nr";
my $sth;
my $d;
+ if (!$opt_all || $opt_all == 0) {
+ if ($where) {
+ $where .= " AND visible = 1";
+ } else {
+ $where .= "visible = 1";
+ }
+ }
+
if ($opt_year) {
if ($where) {
$where .= " AND date ~* '$opt_year'";
my $default = shift;
my $ans;
- print $prompt;
- printf " [%s]", $default if ($default);
- print ": ";
- $ans = <STDIN>;
- chop ($ans) if ($ans);
+ if ($default) {
+ $ans = $term->readline ($prompt . " [" . $default . "]: ");
+ } else {
+ $ans = $term->readline ($prompt . ": ");
+ }
if (length ($ans) == 0) {
$ans = $default;
} elsif ($ans eq ".") {
my $weiter = 'y';
my $i;
my $query;
+ my ($date_sec,$date_min,$date_hour,$date_mday,$date_mon,$date_year,$date_wday,$date_isdst)
+ = localtime();
print "Buchungseingabe\n\n";
while ($weiter =~ /[JjYy]/) {
if ($fieldname[$i] eq "Category" && $ans eq "?") {
@categories = &get_categories() if ($#categories);
printf " %s\n", join (", ",@categories);
+ } elsif ($fieldname[$i] eq "Datum") {
+ if ($ans =~ /^\d+\.\d+.\d+$/) {
+ $input[$i] = $ans;
+ $i++;
+ } elsif ($ans =~ /^\d+\.\d+.$/) {
+ $ans .= $date_year + 1900;
+ $input[$i] = $ans;
+ $i++;
+ } elsif ($ans =~ /^\d+\.$/) {
+ $ans .= sprintf ("%d.%d", $date_mon + 1, $date_year + 1900);
+ $input[$i] = $ans;
+ $i++;
+ }
} else {
$input[$i] = $ans;
$i++;
print " --buchung-category|-bc [category]\n";
print " --buchung-input|-bi\n";
print " --buchung-unpaid\n";
+ print " --buchung-visible|-bv <nr>\n";
print " --pay <nr> | --unpay <nr>\n";
print " --list-categories|-lc\n";
print " Options:\n";
+ print " --all|-a\n";
print " --verbose|-v\n";
print " --year|-y year\n";
print " --direction|--dir|-d in|out\n";
exit 0;
}
+$term = new Term::ReadLine '';
$i = 0;
+$opt_all = 0;
$opt_verbose = 0;
$opt_year = 0;
&usage() if ($#ARGV == -1);
$ARGV[$i] = "--buchung-category";
} elsif ($ARGV[$i] eq "-bi") {
$ARGV[$i] = "--buchung-input";
+ } elsif ($ARGV[$i] eq "-bv") {
+ $ARGV[$i] = "--buchung-visible";
} elsif ($ARGV[$i] eq "-lc") {
$ARGV[$i] = "--list-categories";
}
} else {
&sales_list();
}
+ } elsif ($ARGV[$i] eq "visible") {
+ if ($i+1 <= $#ARGV && ($ARGV[$i+1] !~ /^-/)) {
+ $i++;
+ &toggle_visibility($ARGV[$i]);
+ }
} elsif ($ARGV[$i] eq "input") {
&buchung_input();
} elsif ($ARGV[$i] eq "unpaid") {
}
} elsif ($ARGV[$i] eq "--dm") {
$table = "sales_dm";
+ } elsif ($ARGV[$i] eq "-a" || $ARGV[$i] eq "--all") {
+ $opt_all = 1;
} elsif ($ARGV[$i] eq "-v" || $ARGV[$i] eq "--verbose") {
$opt_verbose = 1;
}