From f4f4f6dda068e18cfd66ceff59e9696a69675d16 Mon Sep 17 00:00:00 2001 From: cos Date: Tue, 30 Oct 2012 18:27:47 +0100 Subject: Improved upon inventory support. --- mat | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/mat b/mat index d6c6cfd..4c37bc6 100755 --- a/mat +++ b/mat @@ -184,11 +184,16 @@ sub cmd_inventory { my $sql = "SELECT recipe_id, count(recipe_id), storage FROM inventory"; $sql .= " WHERE storage='$storage'" if ( $storage ); - $sql .= " GROUP BY storage"; + $sql .= " GROUP BY storage, recipe_id"; my $all = $db->selectall_arrayref($sql); foreach my $row (@$all) { - printf "%3d %-55s %s\n", @$row[1], get_recipe_name(@$row[0]), @$row[2]; + printf "%3d x %s (%s)", @$row[1], get_recipe_name(@$row[0]), @$row[0]; + if ( $storage ) { + print "\n"; + } else { + print @$row[2], "\n"; + } } } @@ -260,7 +265,7 @@ sub print_label { my ( $id, $dish_name, $amount ) = @_; my $iconv = Text::Iconv->new("UTF8", "ISO-8859-1"); - my $row0 = `date +%Y%m%d`.' '.LABEL_NAME; + my $row0 = `date +%Y%m%d|tr -d '\n'`.' '.LABEL_NAME; my $row1 = $iconv->convert($dish_name).' ('.$amount.'g)'; # 300 dpi & 29 x 90 mm ger: 300*2.9/2.54 = 343, 300*9.0/2.54 = 1063 @@ -297,11 +302,11 @@ sub print_label { system("convert -density 300 label.png label.ps && lp -d Brother_QL-720NW label.ps"); } -sub cmd_storemeal { +sub cmd_storeportion { my ( $recipe_id, $amount, $storage ) = @_; my $sql = "INSERT INTO inventory (recipe_id, amount, storage ) VALUES (". - "$recipe_id, $amount, $storage );"; + "$recipe_id, $amount, '$storage' );"; $db->do($sql); my $inventory_id = $db->last_insert_id(undef, undef, undef, undef); @@ -384,9 +389,9 @@ sub cmd_help() { print "randmeal \n"; print "showplan [date]\n"; print "postpone \n"; - print "storemeal [amount] [storage]\n"; - print "retrievemeal (unimplemented)\n"; - print "relocate \n"; + print "storeportion [amount] [storage]\n"; + print "retrieveportion (unimplemented)\n"; + print "relocate \n"; print "inventory [storage]\n"; print "shoppinglist \n"; } @@ -659,8 +664,8 @@ if ($ARGV[0]) { print "Command failed!\n" unless (cmd_postpone($ARGV[1]) >= 0); } elsif ( $ARGV[0] eq "inventory") { print "Command failed!\n" unless (cmd_inventory($ARGV[1]) >= 0); - } elsif ( $ARGV[0] eq "storemeal") { - print "Command failed!\n" unless (cmd_storemeal($ARGV[1], $ARGV[2], $ARGV[3]) >= 0); + } elsif ( $ARGV[0] eq "storeportion") { + print "Command failed!\n" unless (cmd_storeportion($ARGV[1], $ARGV[2], $ARGV[3]) >= 0); } elsif ( $ARGV[0] eq "relocate") { print "Command failed!\n" unless (cmd_relocate($ARGV[1], $ARGV[2]) >= 0); } elsif ( $ARGV[0] eq "shoppinglist") { -- cgit v1.2.3