Limit descriptions in history to relevant ones according to the category
authorJoey Schulze <joey@infodrom.org>
Sat, 7 Jun 2008 12:40:55 +0000 (12:40 +0000)
committerJoey Schulze <joey@infodrom.org>
Sat, 7 Jun 2008 12:40:55 +0000 (12:40 +0000)
src/InfoCon/buch/infocon

index a1c6819..47c2f9a 100755 (executable)
@@ -182,6 +182,7 @@ sub sales_list
 
 sub get_descriptions
 {
+    my $category = shift;
     my $query;
     my @row;
     my $sth;
@@ -189,8 +190,10 @@ sub get_descriptions
     my ($date_sec,$date_min,$date_hour,$date_mday,$date_mon,$date_year,$date_wday,$date_isdst)
        = localtime;
 
-    $query  = sprintf("SELECT DISTINCT description FROM %s WHERE date LIKE '%d%%' ORDER by description",
+    $query  = sprintf("SELECT DISTINCT description FROM %s WHERE date LIKE '%d%%' ",
                      $table, $date_year+1900);
+    $query .= sprintf("AND category = '%s' ", $category) if defined $category;
+    $query .= "ORDER by description";
     $sth = $dbh->prepare($query);
     if ($sth && (my $rc = $sth->execute) > 0) {
        while (@row = $sth->fetchrow_array) {
@@ -276,11 +279,12 @@ sub buchung_input
     my $i;
     my $ans;
     my $query;
+    my @descriptions;
     my ($date_sec,$date_min,$date_hour,$date_mday,$date_mon,$date_year,$date_wday,$date_isdst)
        = localtime;
 
     @categories = get_categories unless @categories;
-    my @descriptions = get_descriptions;
+    @descriptions = get_descriptions;
 
     $term = new Term::ReadLine '' unless $term;
 
@@ -299,6 +303,7 @@ sub buchung_input
                $attribs->{completion_word} = \@categories;
            } elsif ($fieldname[$i] eq "Description") {
                $attribs->{completion_entry_function} = $attribs->{list_completion_function};
+               @descriptions = get_descriptions $input[1];
                $attribs->{completion_word} = \@descriptions;
            } elsif ($fieldname[$i] eq "Tax assigned") {
                if ($input[$i-1] == 0) {