diff options
author | cos <cos> | 2015-02-21 16:55:14 +0100 |
---|---|---|
committer | cos <cos> | 2015-04-04 13:28:19 +0200 |
commit | ebc7c4bc27694c25bd96806c2795f763e2273abb (patch) | |
tree | dbbcfe02d4f3c055252a5fc628879e2ebd53fefe | |
parent | fc4473cc51ff5e7b76b3c9f0a7b47c5ba165e1ab (diff) | |
download | mat-ebc7c4bc27694c25bd96806c2795f763e2273abb.zip |
Include energy information on label.
-rwxr-xr-x | mat | 33 |
1 files changed, 24 insertions, 9 deletions
@@ -272,7 +272,7 @@ sub cmd_postpone { } sub print_label { - my ( $id, $dish_name, $amount, $preparation_date ) = @_; + my ( $id, $dish_name, $amount, $preparation_date, $energy ) = @_; my $fontname = "/usr/share/fonts/truetype/freefont/FreeSans.ttf"; my $fontsize = 15; @@ -298,7 +298,12 @@ sub print_label { $row1 =~ s/(.{15,23}) .*/$1/; $row2 = substr($latin1_dish, (length $row1) + 1).' ('.$amount.'g)'; } - my $row3 = '<available label space>'; + my $row3; + if ($energy) { + $row3 = $energy.' kJ'; + } else { + $row3 = '<energy content unknown>'; + } my $idbarcode = GD::Barcode::QRcode->new(sprintf("%s%d", $Config{'label_id_prefix'}, $id), { Version=>3 }); my $idbarcode_image=$idbarcode->plot(); @@ -384,26 +389,34 @@ sub print_label { sub cmd_storeportion { my ( $recipe_id, $amount, $storage ) = @_; - my $sql = "INSERT INTO inventory (recipe_id, preparation_date, amount, ". - "storage ) VALUES ($recipe_id, ".`date +%Y%m%d|tr -d '\n'`.", $amount, ". - "'$storage' );"; + my $energy; + my $sql = "SELECT * FROM cookings WHERE recipe_id=$recipe_id AND ". + "julianday('now')-julianday(date) < 2;"; + my $row = $db->selectrow_hashref($sql); + if ($row) { + $energy = int($amount * $row->{'specific_energy'} / 100); + } + + $sql = "INSERT INTO inventory (recipe_id, preparation_date, amount, ". + "storage, energy ) VALUES ($recipe_id, ".`date +%Y%m%d|tr -d '\n'`.", + $amount, '$storage', ".(defined($energy) ? "$energy" : 'NULL').");"; $db->do($sql); my $inventory_id = $db->last_insert_id(undef, undef, undef, undef); print_label($inventory_id, get_recipe_name($recipe_id), $amount, - `date +%Y%m%d|tr -d '\n'`); + `date +%Y%m%d|tr -d '\n'`, $energy); } sub cmd_reprintlabel { my ( $id ) = @_; - my $sql = "SELECT recipe_id, preparation_date, amount, storage FROM inventory WHERE ". - "id=$id"; + my $sql = "SELECT recipe_id, preparation_date, amount, storage, energy FROM ". + "inventory WHERE id=$id"; my $row = $db->selectrow_hashref($sql); print_label($id, get_recipe_name($row->{'recipe_id'}), $row->{'amount'}, - $row->{'preparation_date'}); + $row->{'preparation_date'}, $row->{'energy'}); return 0; } @@ -861,6 +874,8 @@ if ($ARGV[0]) { print "Command failed!\n" unless (cmd_inventory($ARGV[1]) >= 0); } elsif ( $ARGV[0] eq "storeportion") { print "Command failed!\n" unless (cmd_storeportion($ARGV[1], $ARGV[2], $ARGV[3]) >= 0); + } elsif ( $ARGV[0] eq "labb") { + print "Command failed!\n" unless (cmd_labb($ARGV[1], $ARGV[2], $ARGV[3]) >= 0); } elsif ( $ARGV[0] eq "reprintlabel") { print "Command failed!\n" unless (cmd_reprintlabel($ARGV[1]) >= 0); } elsif ( $ARGV[0] eq "relocate") { |