5 require './autoeconomy.pm';
7 binmode STDIN, ':utf8';
8 binmode STDOUT, ':utf8';
10 my $csv = Text::CSV_XS->new({ sep_char => "\t", binary => 1 });
11 my $dbh = autoeconomy::db_connect();
14 my $account = $ARGV[0];
18 my ($accounting_date,$interest_date,$use_date,$reference,$type,$text,$out,$in) = $csv->fields;
19 next if ($interest_date eq 'RENTEDATO');
21 # Find out if it's there already (FIXME: might need a text+type update?)
22 my ($count) = $dbh->selectrow_array('SELECT COUNT(*) AS cnt FROM transaction WHERE reference=?', undef, $reference);
25 $type = Encode::decode("iso8859-1", $type);
26 $text = Encode::decode("iso8859-1", $text);
29 $out = undef if ($out eq '');
30 $in = undef if ($in eq '');
33 my $q = $dbh->prepare('INSERT INTO transaction (account,accounting_date,interest_date,use_date,reference,trans_type,text,amount_out,amount_in) VALUES (?,?,?,?,?,?,?,?,?)');
34 $q->execute($account,$accounting_date,$interest_date,$use_date,$reference,$type,$text,$out,$in);
39 print "$num records inserted.\n";