From 794785667b5e16178f1840ef4b2f25ef3459fc21 Mon Sep 17 00:00:00 2001 From: cos Date: Sun, 25 Jan 2015 21:59:22 +0100 Subject: Include recipe name for ingredients on shopping list. --- mat | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/mat b/mat index b23abe2..f1d0fd7 100755 --- a/mat +++ b/mat @@ -11,13 +11,15 @@ use GD; use GD::Barcode; use GD::Barcode::QRcode; use Text::Iconv; +use utf8; +binmode(STDOUT, 'utf8:'); tie my %Config, "Config::Simple", '/etc/mat.conf'; #use Data::Dumper; my $db = DBI->connect($Config{'database'}, "", "", {RaiseError => 1, - AutoCommit => 1}); + AutoCommit => 1, sqlite_unicode => 1}); my @recipes; my @ingredients; @@ -772,6 +774,7 @@ sub cmd_shoppinglist { # $shop{shop_position} = $shop{unit} = $$contents{$content}{unit}; $shop{ingredient} = @$ingredientcol[0]; + $shop{recipe}[0] = $recipe; push @shop_ingredients, \%shop; } } @@ -781,6 +784,7 @@ sub cmd_shoppinglist { { if (exists($squeezed_ingredients[-1]) and $squeezed_ingredients[-1]{ingredient} eq $squeeze->{ingredient} and $squeezed_ingredients[-1]{unit} eq $squeeze->{unit}) { $squeezed_ingredients[-1]{quantity} += $squeeze->{quantity}; + push @{$squeezed_ingredients[-1]{recipe}}, $squeeze->{recipe}[0] unless grep(/$squeeze->{recipe}[0]/, @{$squeezed_ingredients[-1]{recipe}}); } else { push @squeezed_ingredients, $squeeze; } @@ -788,7 +792,11 @@ sub cmd_shoppinglist { # for my $shop ( @sorted_ingredients ) for my $shop ( @squeezed_ingredients ) { - printf "%4s %-8s %s\n", $shop->{quantity}, $shop->{unit}, $shop->{ingredient}; + printf "%4s %-8s %-40s", $shop->{quantity}, $shop->{unit}, $shop->{ingredient}; + for ( @{$shop->{recipe}} ) { + print get_recipe_name($_), ", "; + } + print "\n"; } return 1; } -- cgit v1.2.3