From f766d3ab76b29b4d7125ee724ac6a0ce13185571 Mon Sep 17 00:00:00 2001 From: cos Date: Sun, 16 Aug 2015 16:38:28 +0200 Subject: Output suitable mealtypes when showing inventory. --- mat | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'mat') diff --git a/mat b/mat index b0a309d..707a675 100755 --- a/mat +++ b/mat @@ -143,6 +143,8 @@ sub convert_to_unit { $convert{'volume'} = $in_amount * 0.015; } elsif ($in_unit eq "tsk") { $convert{'volume'} = $in_amount * 0.005; + } elsif ($in_unit eq "krm") { + $convert{'volume'} = $in_amount * 0.001; } elsif ($in_unit eq "g") { $convert{'weight'} = $in_amount; } elsif ($in_unit eq "kg") { @@ -289,7 +291,7 @@ sub cmd_relocate { sub cmd_inventory { my ( $storage ) = @_; - my $total = 0; + my %total; my $sql = "SELECT recipe_id, count(recipe_id), storage FROM inventory"; $sql .= " WHERE storage='$storage'" if ( $storage ); @@ -297,15 +299,35 @@ sub cmd_inventory { my $all = $db->selectall_arrayref($sql); foreach my $row (@$all) { - $total += @$row[1]; + $total{'all'} += @$row[1]; + $sql = "SELECT m.mealtype FROM typemap AS t JOIN mealtypes AS m ON ". + "t.mealtype_id=m.id WHERE t.recipe_id=".@$row[0]." ORDER by m.id;"; + my $mealtypes = $db->selectcol_arrayref($sql); printf "%3d x %s (%s)", @$row[1], get_recipe_name(@$row[0]), @$row[0]; + foreach my $mealtype ( @$mealtypes ) { + if($mealtype eq $$mealtypes[0]) { + print " [" if($mealtype eq $$mealtypes[0]); + } else { + print " "; + } + print "$mealtype"; + print "]" if($mealtype eq $$mealtypes[scalar(@$mealtypes)-1]); + $total{$mealtype} += @$row[1] / scalar(@$mealtypes); + } if ( $storage ) { print "\n"; } else { print " ", @$row[2], "\n"; } } - printf "----\n%3d\n", $total; + printf "----\n%3d (", $total{'all'}; + delete $total{'all'}; + my $s = ""; + foreach my $mealtype ( keys(%total) ) { + printf "$s%s %3d", $mealtype, $total{$mealtype}; + $s = ', '; + } + printf ")\n"; } sub cmd_randmeal { -- cgit v1.2.3