summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcos <cos>2015-08-16 16:38:28 +0200
committercos <cos>2015-08-16 16:38:28 +0200
commitf766d3ab76b29b4d7125ee724ac6a0ce13185571 (patch)
tree0eb0d5a4735af1233d9dffa6089ed9fa71322399
parent8da4fc1b825748208d5de50a9250ddd4314c139d (diff)
downloadmat-f766d3ab76b29b4d7125ee724ac6a0ce13185571.zip
Output suitable mealtypes when showing inventory.
-rwxr-xr-xmat28
1 files changed, 25 insertions, 3 deletions
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 {