From be449ba8e28c1d603e0e3a1ac96f185fa6b870d9 Mon Sep 17 00:00:00 2001 From: cos Date: Sun, 26 Nov 2017 21:20:48 +0100 Subject: Add some code changes made during the last year or so. --- mat | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/mat b/mat index 2ec9415..451c9b0 100755 --- a/mat +++ b/mat @@ -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; } -- cgit v1.2.3