summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcos <cos>2015-01-25 21:59:22 +0100
committercos <cos>2015-01-25 22:32:38 +0100
commit794785667b5e16178f1840ef4b2f25ef3459fc21 (patch)
treede5098e4396c2efe833621fa4089324caa0ee612
parent3088815bb6cb75b9bd84d1df79808eca43318cf2 (diff)
downloadmat-feature/queue.zip
Include recipe name for ingredients on shopping list.feature/queue
-rwxr-xr-xmat12
1 files 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;
}