Added support for visible/invisible items
[infodrom.org/service.infodrom.org] / src / InfoCon / buch / infocon
index 5d24747..767b93e 100755 (executable)
@@ -75,13 +75,33 @@ sub date_to_string
     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";
@@ -99,6 +119,14 @@ sub sales_list
     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'";
@@ -277,9 +305,11 @@ sub usage
     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";
@@ -289,6 +319,7 @@ sub usage
 
 $term = new Term::ReadLine '';
 $i = 0;
+$opt_all = 0;
 $opt_verbose = 0;
 $opt_year = 0;
 &usage() if ($#ARGV == -1);
@@ -298,6 +329,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 "-lc") {
        $ARGV[$i] = "--list-categories";
     }
@@ -320,6 +353,11 @@ 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 "input") {
            &buchung_input();
        } elsif ($ARGV[$i] eq "unpaid") {
@@ -367,6 +405,8 @@ while ($i <= $#ARGV) {
        }
     } 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;
     }