]> git.sesse.net Git - autoeconomy/blob - db-classify.pl
Initial checkin for move to Git (no prior version history available).
[autoeconomy] / db-classify.pl
1 #! /usr/bin/perl
2 use strict;
3 use warnings;
4 require './autoeconomy.pm';
5
6 my $dbh = autoeconomy::db_connect();
7 my $reference = $ARGV[0];
8 my $cssfile = $ARGV[1];
9
10 my $ref = $dbh->selectrow_hashref('SELECT * FROM transaction WHERE reference=?', undef,
11         $reference);
12 if (!defined($ref)) {
13         die "Couldn't find row '$reference'";
14 }
15         
16 my @parms = (
17         "--account=" . $ref->{'account'},
18         "--usedate=" . $ref->{'use_date'},
19         "--reference=" . $ref->{'reference'},
20         "--type=" . $ref->{'trans_type'},
21         "--text=" . $ref->{'text'},
22         "--direction=" . (defined($ref->{'amount_in'}) ? 'in' : 'out'),
23         "--amount=" . ($ref->{'amount_in'} || $ref->{'amount_out'})
24 );
25
26 if (defined($cssfile)) {
27         system("crm", "learn.crm",
28                 @parms,
29                 "--cssfile=" . $cssfile
30         );
31 } else {
32         system("crm", "classify.crm",
33                 @parms,
34                 "--cssfiles=" . join(' ', <*.css>)
35         );
36 }