+ # connect to database
+ my $dbh = $form->dbconnect($myconfig);
+
+ if ($form->{id}) {
+ my $query =
+ qq|SELECT description, inventory_accno_id, (select accno from chart where id=inventory_accno_id) as inventory_accno, income_accno_id_0, (select accno from chart where id=income_accno_id_0) as income_accno_0, expense_accno_id_0, (select accno from chart where id=expense_accno_id_0) as expense_accno_0, income_accno_id_1, (select accno from chart where id=income_accno_id_1) as income_accno_1, expense_accno_id_1, (select accno from chart where id=expense_accno_id_1) as expense_accno_1, income_accno_id_2, (select accno from chart where id=income_accno_id_2) as income_accno_2, expense_accno_id_2, (select accno from chart where id=expense_accno_id_2) as expense_accno_2, income_accno_id_3, (select accno from chart where id=income_accno_id_3) as income_accno_3, expense_accno_id_3, (select accno from chart where id=expense_accno_id_3) as expense_accno_3
+ FROM buchungsgruppen
+ WHERE id = $form->{id}|;
+ my $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
+
+ my $ref = $sth->fetchrow_hashref(NAME_lc);
+
+ map { $form->{$_} = $ref->{$_} } keys %$ref;
+
+ $sth->finish;
+
+ my $query =
+ qq|SELECT count(id) as anzahl
+ FROM parts
+ WHERE buchungsgruppen_id = $form->{id}|;
+ my $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
+
+ my $ref = $sth->fetchrow_hashref(NAME_lc);
+ if (!$ref->{anzahl}) {
+ $form->{orphaned} = 1;
+ }
+ $sth->finish;
+
+ }
+ my $module = "IC";
+ $query = qq|SELECT c.accno, c.description, c.link, c.id,
+ d.inventory_accno_id, d.income_accno_id, d.expense_accno_id
+ FROM chart c, defaults d
+ WHERE c.link LIKE '%$module%'
+ ORDER BY c.accno|;
+
+
+ my $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
+ while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
+ foreach my $key (split /:/, $ref->{link}) {
+ if ($key =~ /$module/) {
+ if ( ($ref->{id} eq $ref->{inventory_accno_id})
+ || ($ref->{id} eq $ref->{income_accno_id})
+ || ($ref->{id} eq $ref->{expense_accno_id})) {
+ push @{ $form->{"${module}_links"}{$key} },
+ { accno => $ref->{accno},
+ description => $ref->{description},
+ selected => "selected",
+ id => $ref->{id} };
+ } else {
+ push @{ $form->{"${module}_links"}{$key} },
+ { accno => $ref->{accno},
+ description => $ref->{description},
+ selected => "",
+ id => $ref->{id} };
+ }
+ }
+ }
+ }
+ $sth->finish;
+
+
+ $dbh->disconnect;
+
+ $main::lxdebug->leave_sub();
+}
+
+sub save_buchungsgruppe {
+ $main::lxdebug->enter_sub();
+
+ my ($self, $myconfig, $form) = @_;
+
+ # connect to database
+ my $dbh = $form->dbconnect($myconfig);
+
+ $form->{description} =~ s/\'/\'\'/g;
+
+
+ # id is the old record
+ if ($form->{id}) {
+ $query = qq|UPDATE buchungsgruppen SET
+ description = '$form->{description}',
+ inventory_accno_id = '$form->{inventory_accno_id}',
+ income_accno_id_0 = '$form->{income_accno_id_0}',
+ expense_accno_id_0 = '$form->{expense_accno_id_0}',
+ income_accno_id_1 = '$form->{income_accno_id_1}',
+ expense_accno_id_1 = '$form->{expense_accno_id_1}',
+ income_accno_id_2 = '$form->{income_accno_id_2}',
+ expense_accno_id_2 = '$form->{expense_accno_id_2}',
+ income_accno_id_3 = '$form->{income_accno_id_3}',
+ expense_accno_id_3 = '$form->{expense_accno_id_3}'
+ WHERE id = $form->{id}|;
+ } else {
+ $query = qq|INSERT INTO buchungsgruppen
+ (description, inventory_accno_id, income_accno_id_0, expense_accno_id_0, income_accno_id_1, expense_accno_id_1, income_accno_id_2, expense_accno_id_2, income_accno_id_3, expense_accno_id_3)
+ VALUES ('$form->{description}', '$form->{inventory_accno_id}', '$form->{income_accno_id_0}', '$form->{expense_accno_id_0}', '$form->{income_accno_id_1}', '$form->{expense_accno_id_1}', '$form->{income_accno_id_2}', '$form->{expense_accno_id_2}', '$form->{income_accno_id_3}', '$form->{expense_accno_id_3}')|;
+ }
+ $dbh->do($query) || $form->dberror($query);
+
+ $dbh->disconnect;
+
+ $main::lxdebug->leave_sub();
+}
+
+sub delete_buchungsgruppe {
+ $main::lxdebug->enter_sub();
+
+ my ($self, $myconfig, $form) = @_;
+
+ # connect to database
+ my $dbh = $form->dbconnect($myconfig);
+
+ $query = qq|DELETE FROM buchungsgruppe
+ WHERE id = $form->{id}|;
+ $dbh->do($query) || $form->dberror($query);
+
+ $dbh->disconnect;
+
+ $main::lxdebug->leave_sub();
+}
+
+sub printer {
+ $main::lxdebug->enter_sub();
+
+ my ($self, $myconfig, $form) = @_;
+
+ # connect to database
+ my $dbh = $form->dbconnect($myconfig);
+
+ my $query = qq|SELECT id, printer_description, template_code, printer_command
+ FROM printers
+ ORDER BY 2|;
+
+ $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
+
+ while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
+ push @{ $form->{ALL} }, $ref;
+ }
+
+ $sth->finish;
+ $dbh->disconnect;
+
+ $main::lxdebug->leave_sub();
+}
+
+sub get_printer {
+ $main::lxdebug->enter_sub();
+
+ my ($self, $myconfig, $form) = @_;
+
+ # connect to database
+ my $dbh = $form->dbconnect($myconfig);
+
+ my $query =
+ qq|SELECT p.printer_description, p.template_code, p.printer_command
+ FROM printers p
+ WHERE p.id = $form->{id}|;
+ my $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
+
+ my $ref = $sth->fetchrow_hashref(NAME_lc);
+
+ map { $form->{$_} = $ref->{$_} } keys %$ref;
+
+ $sth->finish;
+
+ $dbh->disconnect;
+
+ $main::lxdebug->leave_sub();
+}
+
+sub save_printer {
+ $main::lxdebug->enter_sub();
+
+ my ($self, $myconfig, $form) = @_;
+
+ # connect to database
+ my $dbh = $form->dbconnect($myconfig);
+
+ $form->{printer_description} =~ s/\'/\'\'/g;
+ $form->{printer_command} =~ s/\'/\'\'/g;
+ $form->{template_code} =~ s/\'/\'\'/g;
+
+
+ # id is the old record
+ if ($form->{id}) {
+ $query = qq|UPDATE printers SET
+ printer_description = '$form->{printer_description}',
+ template_code = '$form->{template_code}',
+ printer_command = '$form->{printer_command}'
+ WHERE id = $form->{id}|;
+ } else {
+ $query = qq|INSERT INTO printers
+ (printer_description, template_code, printer_command)
+ VALUES ('$form->{printer_description}', '$form->{template_code}', '$form->{printer_command}')|;
+ }
+ $dbh->do($query) || $form->dberror($query);
+
+ $dbh->disconnect;
+
+ $main::lxdebug->leave_sub();
+}
+
+sub delete_printer {
+ $main::lxdebug->enter_sub();
+
+ my ($self, $myconfig, $form) = @_;
+
+ # connect to database
+ my $dbh = $form->dbconnect($myconfig);
+
+ $query = qq|DELETE FROM printers
+ WHERE id = $form->{id}|;
+ $dbh->do($query) || $form->dberror($query);
+
+ $dbh->disconnect;
+
+ $main::lxdebug->leave_sub();
+}
+
+sub adr {
+ $main::lxdebug->enter_sub();
+
+ my ($self, $myconfig, $form) = @_;
+
+ # connect to database
+ my $dbh = $form->dbconnect($myconfig);
+
+ my $query = qq|SELECT id, adr_description, adr_code
+ FROM adr
+ ORDER BY adr_code|;
+
+ $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
+
+ while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
+ push @{ $form->{ALL} }, $ref;
+ }
+
+ $sth->finish;
+ $dbh->disconnect;
+
+ $main::lxdebug->leave_sub();
+}
+
+sub get_adr {
+ $main::lxdebug->enter_sub();
+
+ my ($self, $myconfig, $form) = @_;
+
+ # connect to database
+ my $dbh = $form->dbconnect($myconfig);
+
+ my $query =
+ qq|SELECT a.adr_description, a.adr_code
+ FROM adr a
+ WHERE a.id = $form->{id}|;
+ my $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
+
+ my $ref = $sth->fetchrow_hashref(NAME_lc);
+
+ map { $form->{$_} = $ref->{$_} } keys %$ref;
+
+ $sth->finish;
+
+ $dbh->disconnect;
+
+ $main::lxdebug->leave_sub();
+}
+
+sub save_adr {
+ $main::lxdebug->enter_sub();
+
+ my ($self, $myconfig, $form) = @_;
+
+ # connect to database
+ my $dbh = $form->dbconnect($myconfig);
+
+ $form->{adr_description} =~ s/\'/\'\'/g;
+ $form->{adr_code} =~ s/\'/\'\'/g;
+
+
+ # id is the old record
+ if ($form->{id}) {
+ $query = qq|UPDATE adr SET
+ adr_description = '$form->{adr_description}',
+ adr_code = '$form->{adr_code}'
+ WHERE id = $form->{id}|;
+ } else {
+ $query = qq|INSERT INTO adr
+ (adr_description, adr_code)
+ VALUES ('$form->{adr_description}', '$form->{adr_code}')|;
+ }
+ $dbh->do($query) || $form->dberror($query);
+
+ $dbh->disconnect;
+
+ $main::lxdebug->leave_sub();
+}
+
+sub delete_adr {
+ $main::lxdebug->enter_sub();
+
+ my ($self, $myconfig, $form) = @_;
+
+ # connect to database
+ my $dbh = $form->dbconnect($myconfig);
+
+ $query = qq|DELETE FROM adr
+ WHERE id = $form->{id}|;
+ $dbh->do($query) || $form->dberror($query);
+
+ $dbh->disconnect;
+
+ $main::lxdebug->leave_sub();
+}
+
+sub payment {
+ $main::lxdebug->enter_sub();
+
+ my ($self, $myconfig, $form) = @_;
+
+ # connect to database
+ my $dbh = $form->dbconnect($myconfig);
+
+ my $query = qq|SELECT *
+ FROM payment_terms
+ ORDER BY id|;
+
+ $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
+
+ while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
+ $ref->{percent_skonto} = $form->format_amount($myconfig,($ref->{percent_skonto} * 100));
+ push @{ $form->{ALL} }, $ref;
+ }
+
+ $sth->finish;
+ $dbh->disconnect;
+
+ $main::lxdebug->leave_sub();
+}
+
+sub get_payment {
+ $main::lxdebug->enter_sub();
+
+ my ($self, $myconfig, $form) = @_;
+
+ # connect to database
+ my $dbh = $form->dbconnect($myconfig);
+
+ my $query =
+ qq|SELECT *
+ FROM payment_terms
+ WHERE id = $form->{id}|;
+ my $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
+
+ my $ref = $sth->fetchrow_hashref(NAME_lc);
+ $ref->{percent_skonto} = $form->format_amount($myconfig,($ref->{percent_skonto} * 100));
+
+ map { $form->{$_} = $ref->{$_} } keys %$ref;
+
+ $sth->finish;
+
+ $dbh->disconnect;
+
+ $main::lxdebug->leave_sub();
+}
+
+sub save_payment {
+ $main::lxdebug->enter_sub();
+
+ my ($self, $myconfig, $form) = @_;
+
+ # connect to database
+ my $dbh = $form->dbconnect($myconfig);
+
+ $form->{description} =~ s/\'/\'\'/g;
+ $form->{description_long} =~ s/\'/\'\'/g;
+ $percentskonto = $form->parse_amount($myconfig, $form->{percent_skonto}) /100;
+ $form->{ranking} *= 1;
+ $form->{terms_netto} *= 1;
+ $form->{terms_skonto} *= 1;
+ $form->{percent_skonto} *= 1;
+
+
+
+ # id is the old record
+ if ($form->{id}) {
+ $query = qq|UPDATE payment_terms SET
+ description = '$form->{description}',
+ ranking = $form->{ranking},
+ description_long = '$form->{description_long}',
+ terms_netto = $form->{terms_netto},
+ terms_skonto = $form->{terms_skonto},
+ percent_skonto = $percentskonto
+ WHERE id = $form->{id}|;
+ } else {
+ $query = qq|INSERT INTO payment_terms
+ (description, ranking, description_long, terms_netto, terms_skonto, percent_skonto)
+ VALUES ('$form->{description}', $form->{ranking}, '$form->{description_long}', $form->{terms_netto}, $form->{terms_skonto}, $percentskonto)|;
+ }
+ $dbh->do($query) || $form->dberror($query);
+
+ $dbh->disconnect;
+
+ $main::lxdebug->leave_sub();
+}
+
+sub delete_payment {
+ $main::lxdebug->enter_sub();
+
+ my ($self, $myconfig, $form) = @_;
+
+ # connect to database
+ my $dbh = $form->dbconnect($myconfig);
+
+ $query = qq|DELETE FROM payment_terms
+ WHERE id = $form->{id}|;
+ $dbh->do($query) || $form->dberror($query);
+
+ $dbh->disconnect;
+
+ $main::lxdebug->leave_sub();
+}
+
+sub sic {
+ $main::lxdebug->enter_sub();
+
+ my ($self, $myconfig, $form) = @_;
+
+ # connect to database
+ my $dbh = $form->dbconnect($myconfig);
+
+ my $query = qq|SELECT code, sictype, description
+ FROM sic
+ ORDER BY code|;
+
+ $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
+
+ while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
+ push @{ $form->{ALL} }, $ref;
+ }
+
+ $sth->finish;
+ $dbh->disconnect;
+
+ $main::lxdebug->leave_sub();
+}
+
+sub get_sic {
+ $main::lxdebug->enter_sub();
+
+ my ($self, $myconfig, $form) = @_;
+
+ # connect to database
+ my $dbh = $form->dbconnect($myconfig);
+
+ my $query = qq|SELECT s.code, s.sictype, s.description
+ FROM sic s
+ WHERE s.code = '$form->{code}'|;
+ my $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
+
+ my $ref = $sth->fetchrow_hashref(NAME_lc);
+
+ map { $form->{$_} = $ref->{$_} } keys %$ref;
+
+ $sth->finish;
+
+ $dbh->disconnect;
+
+ $main::lxdebug->leave_sub();
+}
+
+sub save_sic {
+ $main::lxdebug->enter_sub();
+
+ my ($self, $myconfig, $form) = @_;
+
+ # connect to database
+ my $dbh = $form->dbconnect($myconfig);
+
+ $form->{code} =~ s/\'/\'\'/g;
+ $form->{description} =~ s/\'/\'\'/g;
+
+ # if there is an id
+ if ($form->{id}) {
+ $query = qq|UPDATE sic SET
+ code = '$form->{code}',
+ sictype = '$form->{sictype}',
+ description = '$form->{description}'
+ WHERE code = '$form->{id}'|;
+ } else {
+ $query = qq|INSERT INTO sic
+ (code, sictype, description)
+ VALUES ('$form->{code}', '$form->{sictype}', '$form->{description}')|;
+ }
+ $dbh->do($query) || $form->dberror($query);
+
+ $dbh->disconnect;
+
+ $main::lxdebug->leave_sub();
+}
+
+sub delete_sic {
+ $main::lxdebug->enter_sub();
+
+ my ($self, $myconfig, $form) = @_;
+
+ # connect to database
+ my $dbh = $form->dbconnect($myconfig);
+
+ $query = qq|DELETE FROM sic
+ WHERE code = '$form->{code}'|;
+ $dbh->do($query) || $form->dberror($query);
+
+ $dbh->disconnect;
+
+ $main::lxdebug->leave_sub();
+}
+
+sub load_template {
+ $main::lxdebug->enter_sub();
+
+ my ($self, $form) = @_;
+
+ open(TEMPLATE, "$form->{file}") or $form->error("$form->{file} : $!");
+
+ while (<TEMPLATE>) {
+ $form->{body} .= $_;
+ }
+
+ close(TEMPLATE);
+
+ $main::lxdebug->leave_sub();
+}
+
+sub save_template {
+ $main::lxdebug->enter_sub();
+
+ my ($self, $form) = @_;
+
+ open(TEMPLATE, ">$form->{file}") or $form->error("$form->{file} : $!");
+
+ # strip
+ $form->{body} =~ s/\r\n/\n/g;
+ print TEMPLATE $form->{body};
+
+ close(TEMPLATE);
+
+ $main::lxdebug->leave_sub();
+}
+
+sub save_preferences {
+ $main::lxdebug->enter_sub();
+
+ my ($self, $myconfig, $form, $memberfile, $userspath, $webdav) = @_;
+
+ map { ($form->{$_}) = split /--/, $form->{$_} }
+ qw(inventory_accno income_accno expense_accno fxgain_accno fxloss_accno);
+
+ my @a;
+ $form->{curr} =~ s/ //g;
+ map { push(@a, uc pack "A3", $_) if $_ } split /:/, $form->{curr};