diff options
author | cos <cos> | 2012-10-14 20:23:50 +0200 |
---|---|---|
committer | cos <cos> | 2012-12-17 21:50:44 +0100 |
commit | 06648964bedb6428ea2fdf9cc70fe2a98bde6807 (patch) | |
tree | 6acc10bf0bfa79eaa82fa18d0817cab22f7dddaa | |
parent | bf44103ca43d4ad95f626a1941431c7b166bd1f7 (diff) | |
download | mat-06648964bedb6428ea2fdf9cc70fe2a98bde6807.zip |
Happy road trip backseat n900 hacking...
-rwxr-xr-x | mat | 91 | ||||
-rwxr-xr-x | sts | 4 |
2 files changed, 94 insertions, 1 deletions
@@ -6,6 +6,13 @@ use strict; use DBI; use DateTime; use DateTime::Format::ISO8601; +use GD; +use GD::Barcode; +use GD::Barcode::EAN13; +use Text::Iconv; + +use constant LABEL_NAME => `sed --silent 's/^label_name //p' < config|tr -d '\\n'`; +use constant LABEL_ID_PREFIX => `sed --silent 's/^label_id_prefix //p' < config|tr -d '\\n'`; #use Data::Dumper; @@ -165,6 +172,26 @@ sub cmd_movemeal { return 0; } +sub cmd_relocate { + my ( $inventory_id, $storage ) = @_; + + my $sql = "UPDATE inventory SET storage='$storage' WHERE id=$inventory_id;"; + $db->do($sql); +} + +sub cmd_inventory { + my ( $storage ) = @_; + + my $sql = "SELECT recipe_id, count(recipe_id), storage FROM inventory"; + $sql .= " WHERE storage='$storage'" if ( $storage ); + $sql .= " GROUP BY storage"; + + my $all = $db->selectall_arrayref($sql); + foreach my $row (@$all) { + printf "%3d %-55s %s\n", @$row[1], get_recipe_name(@$row[0]), @$row[2]; + } +} + sub cmd_setstate { my ( $date, $state ) = @_; my $mealtype = "lunch"; @@ -229,6 +256,58 @@ sub cmd_postpone { } } +sub print_label { + my ( $id, $dish_name, $amount ) = @_; + + my $iconv = Text::Iconv->new("UTF8", "ISO-8859-1"); + my $row0 = `date +%Y%m%d`.' '.LABEL_NAME; + my $row1 = $iconv->convert($dish_name).' ('.$amount.'g)'; + + # 300 dpi & 29 x 90 mm ger: 300*2.9/2.54 = 343, 300*9.0/2.54 = 1063 + my $label = new GD::Image(343, 1063); + my $x_border = 25; + my $y_border = 80; + + my $white = $label->colorAllocate(255,255,255); + my $black = $label->colorAllocate(0,0,0); + + $label->fill(0, 0, $white); + + my $idbarcode = GD::Barcode::EAN13->new(sprintf("%05d%07d", LABEL_ID_PREFIX, $id)); + my $idbarcode_image=$idbarcode->plot()->copyRotate90(); + $label->copyResized($idbarcode_image, $x_border, $y_border, 0, 0, $idbarcode_image->width() * 3, $idbarcode_image->height() * 6, $idbarcode_image->width(), $idbarcode_image->height()); + + my $text = new GD::Image(500, gdGiantFont->height()); + $white = $text->colorAllocate(255,255,255); + $black = $text->colorAllocate(0,0,0); + $text->fill(1, 1, $white); + $text->string(gdGiantFont, 0, 0, $row0, $black); + my $text_image=$text->copyRotate90(); + $text_image->line(0, 0, 100, 100, $white); + + $label->copyResized($text_image, $label->width() - $text_image->width() * 4 - $x_border, $y_border, 0, 0, $text_image->width() * 4, $text_image->height() * 3, $text_image->width(), $text_image->height()); + + $text->filledRectangle(0, 0, $text->width(), $text->height(), $white); + $text->string(gdGiantFont, 0, 0, $row1, $black); + $text_image=$text->copyRotate90(); + $label->copyResized($text_image, $label->width() - $text_image->width() * 4 - 4 * gdGiantFont->height() - $x_border, $y_border, 0, 0, $text_image->width() * 4, $text_image->height() * 3, $text_image->width(), $text_image->height()); + + open(PNGFILE, ">label.png"); + print PNGFILE $label->png; + system("convert -density 300 label.png label.ps && lp -d Brother_QL-720NW label.ps"); +} + +sub cmd_storemeal { + my ( $recipe_id, $amount, $storage ) = @_; + + my $sql = "INSERT INTO inventory (recipe_id, amount, storage ) VALUES (". + "$recipe_id, $amount, $storage );"; + + $db->do($sql); + my $inventory_id = $db->last_insert_id(undef, undef, undef, undef); + print_label($inventory_id, get_recipe_name($recipe_id), $amount); +} + sub get_plan_state { my ( $date ) = @_; @@ -251,7 +330,7 @@ sub cmd_showplan { # FIXME now() is not start of day, set hour, minute and such to 0 } - for (my $i = 0; $i < 28; $i++) { + for (my $i = 0; $i < 14; $i++) { my $sql = "SELECT recipe_id, mealtype, comment_id FROM plan WHERE date='". $dt->ymd()."';"; my @ids = $db->selectrow_array($sql); @@ -305,6 +384,10 @@ sub cmd_help() { print "randmeal <date>\n"; print "showplan [date]\n"; print "postpone <date> <gap>\n"; + print "storemeal <recipe_id> [amount] [storage]\n"; + print "retrievemeal <meal_id> (unimplemented)\n"; + print "relocate <meal_id> <new_storage>\n"; + print "inventory [storage]\n"; print "shoppinglist <days_to_shop_for>\n"; } @@ -574,6 +657,12 @@ if ($ARGV[0]) { print "Command failed!\n" unless (cmd_showplan($ARGV[1]) >= 0); } elsif ( $ARGV[0] eq "postpone") { print "Command failed!\n" unless (cmd_postpone($ARGV[1]) >= 0); + } elsif ( $ARGV[0] eq "inventory") { + print "Command failed!\n" unless (cmd_inventory($ARGV[1]) >= 0); + } elsif ( $ARGV[0] eq "storemeal") { + print "Command failed!\n" unless (cmd_storemeal($ARGV[1], $ARGV[2], $ARGV[3]) >= 0); + } elsif ( $ARGV[0] eq "relocate") { + print "Command failed!\n" unless (cmd_relocate($ARGV[1], $ARGV[2]) >= 0); } elsif ( $ARGV[0] eq "shoppinglist") { print "Command failed!\n" unless (cmd_shoppinglist($ARGV[1]) >= 0); } else { @@ -0,0 +1,4 @@ +#!/bin/sh +# scale triggered store + +mat storemeal `cat $HOME/mat/matplan/currently_cooking` "$1" y0 |