+ $query =
+ qq|SELECT date '$transdate' + $self->{terms_netto} AS netto_date, | .
+ qq|date '$transdate' + $self->{terms_skonto} AS skonto_date | .
+ qq|FROM payment_terms LIMIT 1|;
+ ($self->{netto_date}, $self->{skonto_date}) =
+ selectrow_query($self, $dbh, $query);
+
+ my $total = ($self->{invtotal}) ? $self->{invtotal} : $self->{ordtotal};
+ my $skonto_amount = $self->parse_amount($myconfig, $total) *
+ $self->{percent_skonto};
+
+ $self->{skonto_amount} =
+ $self->format_amount($myconfig, $skonto_amount, 2);
+
+ if ($self->{"language_id"}) {
+ $query =
+ qq|SELECT t.description_long, | .
+ qq|l.output_numberformat, l.output_dateformat, l.output_longdates | .
+ qq|FROM translation_payment_terms t | .
+ qq|LEFT JOIN language l ON t.language_id = l.id | .
+ qq|WHERE (t.language_id = ?) AND (t.payment_terms_id = ?)|;
+ my ($description_long, $output_numberformat, $output_dateformat,
+ $output_longdates) =
+ selectrow_query($self, $dbh, $query,
+ $self->{"language_id"}, $self->{"payment_id"});
+
+ $self->{payment_terms} = $description_long if ($description_long);
+
+ if ($output_dateformat) {
+ foreach my $key (qw(netto_date skonto_date)) {
+ $self->{$key} =
+ $main::locale->reformat_date($myconfig, $self->{$key},
+ $output_dateformat,
+ $output_longdates);
+ }
+ }
+
+ if ($output_numberformat &&
+ ($output_numberformat ne $myconfig->{"numberformat"})) {
+ my $saved_numberformat = $myconfig->{"numberformat"};
+ $myconfig->{"numberformat"} = $output_numberformat;
+ $self->{skonto_amount} =
+ $self->format_amount($myconfig, $skonto_amount, 2);
+ $myconfig->{"numberformat"} = $saved_numberformat;
+ }
+ }
+
+ $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;
+ }
+
+ $main::lxdebug->leave_sub();
+
+ return $template_code;
+}
+
+sub get_shipto {
+ $main::lxdebug->enter_sub();
+
+ my ($self, $myconfig) = @_;
+
+ my $template_code = "";
+
+ if ($self->{shipto_id}) {
+
+ my $dbh = $self->dbconnect($myconfig);
+
+
+ my $query = qq|SELECT s.* FROM shipto s
+ WHERE s.shipto_id = $self->{shipto_id}|;
+ my $sth = $dbh->prepare($query);
+ $sth->execute || $self->dberror($query);
+ $ref = $sth->fetchrow_hashref(NAME_lc);
+ map { $self->{$_} = $ref->{$_} } keys %$ref;
+ $sth->finish;
+ $dbh->disconnect;
+ }
+
+ $main::lxdebug->leave_sub();
+
+}