summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcos <cos>2012-10-30 18:27:47 +0100
committercos <cos>2012-12-17 21:52:54 +0100
commitf4f4f6dda068e18cfd66ceff59e9696a69675d16 (patch)
tree3c3888a5e8c9a4f0c40e4c7637093beb09052a8d
parent06648964bedb6428ea2fdf9cc70fe2a98bde6807 (diff)
downloadmat-f4f4f6dda068e18cfd66ceff59e9696a69675d16.zip
Improved upon inventory support.
-rwxr-xr-xmat25
1 files changed, 15 insertions, 10 deletions
diff --git a/mat b/mat
index d6c6cfd..4c37bc6 100755
--- a/mat
+++ b/mat
@@ -184,11 +184,16 @@ sub cmd_inventory {
my $sql = "SELECT recipe_id, count(recipe_id), storage FROM inventory";
$sql .= " WHERE storage='$storage'" if ( $storage );
- $sql .= " GROUP BY storage";
+ $sql .= " GROUP BY storage, recipe_id";
my $all = $db->selectall_arrayref($sql);
foreach my $row (@$all) {
- printf "%3d %-55s %s\n", @$row[1], get_recipe_name(@$row[0]), @$row[2];
+ printf "%3d x %s (%s)", @$row[1], get_recipe_name(@$row[0]), @$row[0];
+ if ( $storage ) {
+ print "\n";
+ } else {
+ print @$row[2], "\n";
+ }
}
}
@@ -260,7 +265,7 @@ 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 $row0 = `date +%Y%m%d|tr -d '\n'`.' '.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
@@ -297,11 +302,11 @@ sub print_label {
system("convert -density 300 label.png label.ps && lp -d Brother_QL-720NW label.ps");
}
-sub cmd_storemeal {
+sub cmd_storeportion {
my ( $recipe_id, $amount, $storage ) = @_;
my $sql = "INSERT INTO inventory (recipe_id, amount, storage ) VALUES (".
- "$recipe_id, $amount, $storage );";
+ "$recipe_id, $amount, '$storage' );";
$db->do($sql);
my $inventory_id = $db->last_insert_id(undef, undef, undef, undef);
@@ -384,9 +389,9 @@ 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 "storeportion <recipe_id> [amount] [storage]\n";
+ print "retrieveportion <portion_id> (unimplemented)\n";
+ print "relocate <portion_id> <new_storage>\n";
print "inventory [storage]\n";
print "shoppinglist <days_to_shop_for>\n";
}
@@ -659,8 +664,8 @@ if ($ARGV[0]) {
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 "storeportion") {
+ print "Command failed!\n" unless (cmd_storeportion($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") {