#! /usr/bin/perl
# infocon - Administration tool for InfoCon
-# Copyright (c) 1998-2003,2005-8,10,11,12,14,15,16 Martin Schulze <joey@infodrom.org>
+# Copyright (c) 1998-2003,2005-8,10,11,12,14,15,16,18 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
my @categories = ();
my $term = undef;
my $opt_all = 0;
+my $opt_csv = 0;
my $opt_verbose = 0;
my $opt_year = 0;
my $opt_date = undef;
+my $opt_grep = undef;
my $opt_direction = undef;
sub sdate
return sprintf ("%d.%02d.%02d", $3,$2,$1);
}
+sub isodate
+{
+ $_[0] =~ /(\d{4})(\d{2})(\d{2})/;
+ return sprintf ("%04d-%02d-%02d", $1,$2,$3);
+}
+
# Wandelt einen lesbaren Datumsstring in die Form um, in der er in der
# Datenbank gespeichert werden kann.
#
my $sum_pos=0;
my $sum_neg=0;
my $query;
- my @row;
+ my $row;
my $sth;
my $d;
$where .= sprintf("year = %d", $opt_year);
}
+ if (defined $data{category} && length $data{category}) {
+ $where .= " AND " if $where;
+ $where .= sprintf("category = %s", $dbh->quote($data{category}));
+ }
+
if ($opt_direction) {
if ($opt_direction eq "in") {
$d = "price >= 0"
}
}
- if ($where !~ /visible/) {
+ if ($opt_grep) {
+ $where .= " AND " if $where;
+ $where .= sprintf("description ILIKE '%%%s%%'", $opt_grep);
+ }
+
+ if (defined $where && $where !~ /visible/) {
$where .= " AND " if $where;
$where .= "visible = 1";
}
- $query = "SELECT nr,date,description,price FROM $table";
+ $query = "SELECT nr,date,description,price,tax_percent,tax_assigned 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";
- print "----------------------------------------------------------------------------\n";
- while (@row = $sth->fetchrow_array) {
- $descr = substr($row[2],0,50);
- printf "%4d %8s %-50s %9.2f\n", $row[0], sdate($row[1]), $descr, $row[3];
- if ($row[3] < 0.0) {
- $sum_neg -= $row[3];
+ if ($opt_csv) {
+ print '"nr","date","description","taxrate","tax","value"'."\n";
+ } else {
+ print " Nr. Datum Bezeichnung Betrag\n";
+ print "----------------------------------------------------------------------------\n";
+ }
+ while ($row = $sth->fetchrow_hashref) {
+ $descr = substr($row->{description},0,50);
+ if ($opt_csv) {
+ printf '"%d","%s","%s","%.2f","%.2f","%.2f"'."\n", $row->{nr}, isodate($row->{date}), $descr,
+ $row->{tax_percent}, $row->{tax_assigned}, $row->{price};
+ } else {
+ printf "%4d %8s %-50s %9.2f\n", $row->{nr}, sdate($row->{date}), $descr, $row->{price};
+ }
+ if ($row->{price} < 0.0) {
+ $sum_neg -= $row->{price};
} else {
- $sum_pos += $row[3];
+ $sum_pos += $row->{price};
}
}
- print "---------------------------------------------------------------------------\n"
- if ($sum_neg > 0 || $sum_pos > 0) ;
- printf " Zahlungseingänge %9.2f\n", $sum_pos
- if ($sum_pos > 0);
- printf " Zahlungsausgänge %9.2f\n", -$sum_neg
- if ($sum_neg > 0);
- print "============================================================================\n";
- printf " Summe %9.2f\n\n", $sum_pos - $sum_neg;
+ if (!$opt_csv) {
+ print "---------------------------------------------------------------------------\n"
+ if ($sum_neg > 0 || $sum_pos > 0) ;
+ printf " Zahlungseingänge %9.2f\n", $sum_pos
+ if ($sum_pos > 0);
+ printf " Zahlungsausgänge %9.2f\n", -$sum_neg
+ if ($sum_neg > 0);
+ print "============================================================================\n";
+ printf " Summe %9.2f\n\n", $sum_pos - $sum_neg;
+ }
}
$data{'done'} = 1;
}
'title' => 'bezahlt',
'type' => 'boolean',
'default' => 0},
+ 'billing_date' => {
+ 'title' => 'wann',
+ 'type' => 'date',
+ 'validate' => \&validate_date},
'weiter' => {
'title' => 'Weiter',
'type' => 'boolean',
if ($f eq 'tax_assigned' && $answers->{'tax_percent'} == 0) {
$answers->{$f} = 0;
next;
- } elsif ($f eq 'paid') {
+ }
+ $ans = read_input($f, $fields->{$f});
+ $answers->{$f} = $ans;
+
+ if ($f eq 'paid') {
if ($answers->{paid}) {
- my @now = localtime(time);
- $answers->{billing_date} = sprintf('%04d-%02d-%02d', $now[5]+1900, $now[4]+1, $now[3]);
+ $fields->{'billing_date'}{'default'} = $answers->{'date'};
+ $ans = read_input('billing_date', $fields->{'billing_date'});
+ $answers->{billing_date} = $ans;
} else {
$answers->{billing_date} = undef;
}
}
- $ans = read_input($f, $fields->{$f});
- $answers->{$f} = $ans;
}
$sth->execute(get_next_nr(),
$answers->{tax_percent},
$answers->{tax_assigned},
$answers->{price},
- $answers->{billing_date},
+ defined $answers->{billing_date} ? date_to_string($answers->{billing_date}) : undef,
$answers->{paid});
$weiter = $answers->{weiter};
print "infocon [options] [-h|--help] commands\n";
print " --buchung-category|-bc [category]\n";
print " --buchung-input|-bi\n";
- print " --buchung-unpaid\n";
+ print " --buchung-unpaid|-bu\n";
print " --buchung-hidden\n";
print " --date [yyyy-mm-dd|dd.mm.] (for --pay)\n";
print " --pay <nr> | --unpay <nr>\n";
print " --list-categories|-lc\n";
print " Options:\n";
print " --all|-a\n";
+ print " --csv\n";
print " --verbose|-v\n";
+ print " --grep|-g keyword\n";
print " --year|-y year\n";
print " --direction|--dir|-d in|out\n";
print " --dm\n";
'year=i' => \$opt_year,
'date=s' => \$opt_date,
'direction|d=s' => \$opt_direction,
+ 'grep|g=s' => \$opt_grep,
'mailto:s' => \$data{mailto},
'all' => \$opt_all,
+ 'csv' => \$opt_csv,
'verbose' => \$opt_verbose,
'help' => \&usage,
'dm' => sub {$table = "sales_dm"},
- 'buchung-input|bi' => \$data{'buchung-input'},
- 'buchung-unpaid|bu' => \$data{'buchung-unpaid'},
- 'buchung-hidden|bh' => \$data{'buchung-hidden'},
+ 'buchung-input|bi' => \&buchung_input,
+ 'buchung-unpaid|bu' => \&buchung_unpaid,
+ 'buchung-hidden|bh' => \&buchung_hidden,
'list-categories|lc' => \$data{'list-categories'},
);
}
if (defined $data{category}) {
- if (length($data{category})) {
- sales_list("category = '".$data{category}."'");
- } else {
- sales_list;
- }
+ sales_list;
exit;
-} elsif (defined $data{'buchung-input'}) {
- buchung_input;
-} elsif (defined $data{'buchung-unpaid'}) {
- buchung_unpaid;
-} elsif (defined $data{'buchung-hidden'}) {
- buchung_hidden;
} elsif (defined $data{'list-categories'}) {
list_categories;
} elsif (defined $data{pay}) {