#!/usr/bin/perl
use strict;

use lib "/opt/kivitendo-erp";
use lib "perl";
use SL::LXDebug;
use SL::mebil::Mapping;
use ErrorChannel;

$::lxdebug = new LXDebug;

SL::DB->register_db(
  domain   => 'KIVITENDO',
  type     => 'KIVITENDO',
  driver   => 'Pg',
  database => 'firma',
  host     => 'localhost',
  username => 'kivitendo',
  password => 'kivitendo',
);

my $db = SL::DB->new(domain   => 'KIVITENDO',
  type     => 'KIVITENDO',);
my $dbh = $db->dbh;

my $errch = new ErrorChannel;
my $mapper = new SL::mebil::Mapping($errch, $dbh);

my $command = $ARGV[0];
if ($command eq "ShowMapping") {
	my $mapping = $mapper->get_mapping();
	foreach (@$mapping) {
		print $_->{fromacc}."\n";
	}
	die ("Kein Mapping vorhanden.") unless (scalar(@$mapping) > 0);
} elsif ($command eq "CalcMapping") {
	(my $fromacc, my $toacc) = $mapper->calc_mapping(2022);
} else {
	die "Invalid command: $command";
}
