Support for --hide/--unhide instead of --buchung-visible.
authorJoey Schulze <joey@infodrom.org>
Sat, 21 Jan 2006 18:04:25 +0000 (18:04 +0000)
committerJoey Schulze <joey@infodrom.org>
Sat, 21 Jan 2006 18:04:25 +0000 (18:04 +0000)
Support for --buchung-hidden to display only hidden lines

src/InfoCon/buch/infocon

index 877d024..878495d 100755 (executable)
@@ -75,36 +75,27 @@ sub date_to_string
     return sprintf("%4d%02d%02d", $year,$mon,$day);
 }
 
-# --buchung-visible
-#
-sub toggle_visibility
+sub pay_invoice
 {
     my $nr = shift;
+    my $pay = shift;
+    my $value = $pay==1?1:0;
     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);
-    }
+    $query  = "UPDATE sales SET paid=$value WHERE nr = $nr";
+    $sth = $dbh->do($query);
 }
 
-sub pay_invoice
+sub hide_invoice
 {
     my $nr = shift;
-    my $pay = shift;
-    my $value = $pay==1?1:0;
+    my $hide = shift;
+    my $value = $hide==1?0:1;
     my $query;
     my $sth;
 
-    $query  = "UPDATE sales SET paid=$value WHERE nr = $nr";
+    $query  = "UPDATE sales SET visible=$value WHERE nr = $nr";
     $sth = $dbh->do($query);
 }
 
@@ -119,7 +110,7 @@ sub sales_list
     my $sth;
     my $d;
 
-    if (!$opt_all || $opt_all == 0) {
+    if ($where !~ /visible/ && (!$opt_all || $opt_all == 0)) {
        if ($where) {
            $where .= " AND visible = 1";
        } else {
@@ -305,8 +296,9 @@ sub usage
     print "  --buchung-category|-bc [category]\n";
     print "  --buchung-input|-bi\n";
     print "  --buchung-unpaid\n";
-    print "  --buchung-visible|-bv <nr>\n";
+    print "  --buchung-hidden\n";
     print "  --pay <nr> | --unpay <nr>\n";
+    print "  --hide <nr> | --unhide <nr>\n";
     print "  --list-categories|-lc\n";
     print "  Options:\n";
     print "    --all|-a\n";
@@ -329,8 +321,8 @@ while ($i <= $#ARGV) {
        $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 "-bh") {
+       $ARGV[$i] = "--buchung-hidden";
     } elsif ($ARGV[$i] eq "-lc") {
        $ARGV[$i] = "--list-categories";
     }
@@ -353,11 +345,13 @@ while ($i <= $#ARGV) {
            } else {
                &sales_list();
            }
-       } elsif ($ARGV[$i] eq "visible") {
-           if ($i+1 <= $#ARGV && ($ARGV[$i+1] !~ /^-/)) {
-               $i++;
-               &toggle_visibility($ARGV[$i]);
-           }
+       } elsif ($ARGV[$i] eq "hidden") {
+           $saved_table = $table;
+           $table = "sales_dm";
+           &sales_list("visible = 0");
+           $table = "sales";
+           &sales_list("visible = 0");
+           $table = $table_saved;
        } elsif ($ARGV[$i] eq "input") {
            &buchung_input();
        } elsif ($ARGV[$i] eq "unpaid") {
@@ -382,6 +376,18 @@ while ($i <= $#ARGV) {
            $i++;
            &pay_invoice ($ARGV[$i], 0);
        }
+    } elsif ($ARGV[$i] eq "--hide") {
+       if ($i+1 <= $#ARGV && ($ARGV[$i+1] !~ /^-/)
+           && ($ARGV[$i+1] =~ /^\d+$/)) {
+           $i++;
+           &hide_invoice ($ARGV[$i], 1);
+       }
+    } elsif ($ARGV[$i] eq "--unhide") {
+       if ($i+1 <= $#ARGV && ($ARGV[$i+1] !~ /^-/)
+           && ($ARGV[$i+1] =~ /^\d+$/)) {
+           $i++;
+           &hide_invoice ($ARGV[$i], 0);
+       }
     } elsif ($ARGV[$i] eq "--year" || $ARGV[$i] eq "-y") {
        if ($i+1 <= $#ARGV && ($ARGV[$i+1] =~ /^(\d+)$/)) {
            $i++;