diff options
-rw-r--r-- | README | 1 | ||||
-rwxr-xr-x | mat | 43 |
2 files changed, 38 insertions, 6 deletions
@@ -11,6 +11,7 @@ CREATE TABLE contents (recipe_id INTEGER, ingredient_id INTEGER, quantity FLOAT, CREATE TABLE plan (date DATETIME, mealtype, recipe_id INTEGER, state, comment_id); CREATE TABLE comments (id INTEGER PRIMARY KEY AUTOINCREMENT, comment); CREATE TABLE inventory (id INTEGER PRIMARY KEY AUTOINCREMENT, recipe_id INTEGER, preparation_date DATETIME, amount INTEGER, storage); +CREATE TABLE queue (id INTEGER PRIMARY KEY, recipe_id INTEGER, servings INTEGER); All basic operations are performed using the perl script mat. It is possible to get a crude list of commands available by running: "mat help". @@ -467,8 +467,8 @@ sub cmd_help() { print "relocate <portion_id> <new_storage>\n"; print "inventory [storage]\n"; print "shoppinglist <days_to_shop_for>\n"; - print "queueshow (Yet to be implemented)\n"; - print "queueadd (Yet to be implemented)\n"; + print "queueshow\n"; + print "queueadd <recipe_id> <servings>\n"; print "queuerm (Yet to be implemented)\n"; print "queuemv (Yet to be implemented)\n"; } @@ -636,11 +636,34 @@ sub cmd_searchrecipes { } sub cmd_queueadd { - print "Yet to be implemented!\n"; + my ( $recipe_id, $servings ) = @_; + + my $sql = "SELECT COUNT(id) FROM queue;"; + my $id = $db->selectrow_arrayref($sql); + + return -1 unless $recipe_id =~ "^[0-9]+\$"; + return -1 unless $servings =~ "^[0-9]+\$"; + if (get_recipe_name($recipe_id) ne 'NULL') { + $sql = "INSERT INTO queue (id, recipe_id, servings) VALUES (@$id[0], ". + "$recipe_id, $servings)"; + $db->do($sql); + } + + return 0; } sub cmd_queueshow { - print "Yet to be implemented!\n"; + my $sql = "SELECT id, recipe_id, servings FROM queue"; + + my $sth = $db->prepare($sql); + my $rv = $sth->execute; + $db->{RaiseError} = 0; + while (my @row_ary = $sth->fetchrow_array) { + printf "%3s|%2d x %s (%d)\n", $row_ary[0], $row_ary[2], + get_recipe_name($row_ary[1]), $row_ary[1]; + + } + $db->{RaiseError} = 1; } sub cmd_queuerm { @@ -672,13 +695,14 @@ sub cmd_shoppinglist { # print $i, "\n"; # } - my $entries = $db->selectall_arrayref("SELECT recipe_id FROM plan WHERE recipe_id AND date ". + my $plan_entries = $db->selectall_arrayref("SELECT recipe_id FROM plan WHERE recipe_id AND date ". "BETWEEN '".$startdate."' AND '".$enddate."' AND ". "IFNULL(state, 'null') != 'frozen' AND ". "IFNULL(state, 'null') != 'ready' AND ". "IFNULL(state, 'null') != 'sourced'", { Slice => {} }); + my $queue_entries = $db->selectall_arrayref("SELECT recipe_id FROM queue;"); my %recipe_count; - for my $entry ( @$entries ) { + for my $entry ( @$plan_entries ) { $recipe_count{$entry->{recipe_id}}++; # print $recipe_count{$entry->{recipe_id}}, " ", $entry->{recipe_id}, "\n"; ## print $entry->{recipe_id}.""; @@ -689,6 +713,13 @@ sub cmd_shoppinglist { ## TODO Loop through recipes to add ingredients to a list ## TODO Print ingredients } + for my $entry ( @$queue_entries ) { + my @s = $db->selectrow_array("SELECT servings FROM queue WHERE ". + "recipe_id=@$entry[0]"); +# $recipe_count{@$entry[0]} += $s[0]; FIXME Take number of servings into account + print "WARNING ignoring servings for recipe @$entry[0]!\n" if($s[0] != 1); + $recipe_count{@$entry[0]}++; + } # map {print "| $_ = ${recipe_count{$_}}\n"} sort keys(%recipe_count); my @shop_recipes; |