+ if ($exchangerate == 0) {
+ $exchangerate = 1;
+ }
+
+ $main::lxdebug->leave_sub();
+
+ return $exchangerate;
+}
+
+sub set_payment_options {
+ $main::lxdebug->enter_sub();
+
+ my ($self, $myconfig, $transdate) = @_;
+
+ if ($self->{payment_id}) {
+
+ my $dbh = $self->dbconnect($myconfig);
+
+
+ my $query = qq|SELECT p.terms_netto, p.terms_skonto, p.percent_skonto, p.description_long FROM payment_terms p
+ WHERE p.id = $self->{payment_id}|;
+ my $sth = $dbh->prepare($query);
+ $sth->execute || $self->dberror($query);
+
+ ($self->{terms_netto}, $self->{terms_skonto}, $self->{percent_skonto}, $self->{payment_terms}) = $sth->fetchrow_array;
+
+ if ($transdate eq "") {
+ if ($self->{invdate}) {
+ $transdate = $self->{invdate};
+ } else {
+ $transdate = $self->{transdate};
+ }
+ }
+
+ $sth->finish;
+ my $query = qq|SELECT date '$transdate' + $self->{terms_netto} AS netto_date,date '$transdate' + $self->{terms_skonto} AS skonto_date FROM payment_terms
+ LIMIT 1|;
+ my $sth = $dbh->prepare($query);
+ $sth->execute || $self->dberror($query);
+ ($self->{netto_date}, $self->{skonto_date}) = $sth->fetchrow_array;
+ $sth->finish;
+
+ my $total = ($self->{invtotal}) ? $self->{invtotal} : $self->{ordtotal};
+
+ $self->{skonto_amount} = $self->format_amount($myconfig, ($self->parse_amount($myconfig, $total) * $self->{percent_skonto}), 2);
+
+ $self->{payment_terms} =~ s/<%netto_date%>/$self->{netto_date}/g;
+ $self->{payment_terms} =~ s/<%skonto_date%>/$self->{skonto_date}/g;
+ $self->{payment_terms} =~ s/<%skonto_amount%>/$self->{skonto_amount}/g;
+ $self->{payment_terms} =~ s/<%total%>/$self->{total}/g;
+ $self->{payment_terms} =~ s/<%invtotal%>/$self->{invtotal}/g;
+ $self->{payment_terms} =~ s/<%currency%>/$self->{currency}/g;
+ $self->{payment_terms} =~ s/<%terms_netto%>/$self->{terms_netto}/g;
+ $self->{payment_terms} =~ s/<%account_number%>/$self->{account_number}/g;
+ $self->{payment_terms} =~ s/<%bank%>/$self->{bank}/g;
+ $self->{payment_terms} =~ s/<%bank_code%>/$self->{bank_code}/g;
+
+ $dbh->disconnect;
+ }
+
+ $main::lxdebug->leave_sub();
+
+}
+
+sub check_exchangerate {
+ $main::lxdebug->enter_sub();
+
+ my ($self, $myconfig, $currency, $transdate, $fld) = @_;
+
+ unless ($transdate) {
+ $main::lxdebug->leave_sub();
+ return "";
+ }
+
+ my $dbh = $self->dbconnect($myconfig);
+
+ my $query = qq|SELECT e.$fld FROM exchangerate e
+ WHERE e.curr = '$currency'
+ AND e.transdate = '$transdate'|;
+ my $sth = $dbh->prepare($query);
+ $sth->execute || $self->dberror($query);
+
+ my ($exchangerate) = $sth->fetchrow_array;
+ $sth->finish;
+ $dbh->disconnect;
+
+ $main::lxdebug->leave_sub();
+
+ return $exchangerate;
+}
+
+sub get_template_language {
+ $main::lxdebug->enter_sub();
+
+ my ($self, $myconfig) = @_;
+
+ my $template_code = "";
+
+ if ($self->{language_id}) {
+
+ my $dbh = $self->dbconnect($myconfig);
+
+
+ my $query = qq|SELECT l.template_code FROM language l
+ WHERE l.id = $self->{language_id}|;
+ my $sth = $dbh->prepare($query);
+ $sth->execute || $self->dberror($query);
+
+ ($template_code) = $sth->fetchrow_array;
+ $sth->finish;
+ $dbh->disconnect;
+ }
+
+ $main::lxdebug->leave_sub();
+
+ return $template_code;
+}
+
+sub get_printer_code {
+ $main::lxdebug->enter_sub();
+
+ my ($self, $myconfig) = @_;
+
+ my $template_code = "";
+
+ if ($self->{printer_id}) {
+
+ my $dbh = $self->dbconnect($myconfig);
+
+
+ my $query = qq|SELECT p.template_code,p.printer_command FROM printers p
+ WHERE p.id = $self->{printer_id}|;
+ my $sth = $dbh->prepare($query);
+ $sth->execute || $self->dberror($query);
+
+ ($template_code, $self->{printer_command}) = $sth->fetchrow_array;
+ $sth->finish;
+ $dbh->disconnect;
+ }
+