diff options
-rwxr-xr-x | mat | 27 |
1 files changed, 22 insertions, 5 deletions
@@ -37,11 +37,9 @@ sub ceiling { sub read_ingredients { @ingredients = (); - my $all = $db->selectall_arrayref("SELECT * FROM ingredients"); - foreach my $row (@$all) { - my ($id) = @$row; - $ingredients[$id]->{'id'} = @$row[0]; - $ingredients[$id]->{'name'} = @$row[1]; + my $all = $db->selectall_hashref("SELECT * FROM ingredients", 'id'); + foreach my $id (keys($all)) { + $ingredients[$id] = $all->{$id}; } } @@ -157,6 +155,9 @@ sub convert_to_unit { } elsif ($in_unit eq "st") { $convert{'piece'} = $in_amount; } +# print $ingredients[$id]->{'name'}, " ", $id, " in_unit: ", $in_unit, "\n"; +# print " V:", $convert{'volume'}, " W:", $convert{'weight'}, " P:", +# $convert{'piece'}, " out_unit: ", $out_unit, " \n"; my $sql = "SELECT density, piece_weight FROM ingredients WHERE id=".$id.";"; my $ingredient = $db->selectrow_hashref($sql); @@ -189,6 +190,8 @@ sub convert_to_unit { } } +# print " ", " V:", $out_amount{'volume'}, " W:", $out_amount{'weight'}, " P:", $out_amount{'piece'}, " \n\n"; + if ($out_unit eq "g") { if($out_amount{'weight'}) { return $out_amount{'weight'}; @@ -201,6 +204,8 @@ sub convert_to_unit { return $out_amount{'piece'}; } elsif ($out_unit eq "l") { return $out_amount{'volume'}; + } elsif ($out_unit eq "dl") { + return $out_amount{'volume'}*10; } return undef; @@ -809,6 +814,18 @@ sub cmd_showrecipe { } printf " %s\n", @$ingredientcol[0]; } + + my $cooking_comments = $db->selectall_hashref("SELECT date, comment FROM cookings WHERE recipe_id=".$recipe_id." AND comment IS NOT NULL;", 'date'); + my $eating_comments = $db->selectall_hashref("SELECT date, comment FROM eatings AS e JOIN inventory AS i ON e.inventory_id=i.id WHERE recipe_id=".$recipe_id." AND comment IS NOT NULL;", 'date'); + if ( keys($cooking_comments) or keys($eating_comments) ) { + print "\n"; + } + for my $date ( keys(%$cooking_comments) ) { + printf "%10s %s\n", $date, $cooking_comments->{$date}{'comment'}; + } + for my $date ( keys(%$eating_comments) ) { + printf "%10s %s\n", $date, $eating_comments->{$date}{'comment'}; + } return 1; } |