use SL::MoreCommon;
use SL::Template;
+use strict;
+
sub get_config {
$main::lxdebug->enter_sub();
(SELECT SUM(fee)
FROM dunning_config
WHERE dunning_level <= (SELECT dunning_level FROM dunning_config WHERE id = ?)),
- (SELECT (amount - paid) * (current_date - transdate) FROM ar WHERE id = ?)
+ (SELECT (amount - paid) * (current_date - duedate) FROM ar WHERE id = ?)
* (SELECT interest_rate FROM dunning_config WHERE id = ?)
/ 360,
current_date,
return;
}
- my $template = PlainTextTemplate->new(undef, $form, $myconfig);
+ my $template = SL::Template::create(type => 'PlainText', form => $form, myconfig => $myconfig);
my $mail = Mailer->new();
$mail->{from} = $myconfig->{email};
$mail->{to} = $ref->{recipient};
push(@values, $form->{minamount});
}
- $query =
+ my $query =
qq|SELECT id
FROM dunning_config
WHERE dunning_level = (SELECT MAX(dunning_level) FROM dunning_config)|;
qq|SELECT
a.id, a.ordnumber, a.transdate, a.invnumber, a.amount,
ct.name AS customername, a.customer_id, a.duedate,
+ a.amount - a.paid AS open_amount,
cfg.dunning_description, cfg.dunning_level,
$form->{DUNNINGS} = [];
- while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
+ while (my $ref = $sth->fetchrow_hashref("NAME_lc")) {
next if ($ref->{pastdue} < $ref->{terms});
$ref->{interest} = $form->round_amount($ref->{interest}, 2);
# connect to database
my $dbh = $form->dbconnect($myconfig);
- $where = qq| WHERE (da.trans_id = a.id)|;
+ my $where = qq| WHERE (da.trans_id = a.id)|;
my @values;
push(@values, $form->{dunningto});
}
+ if ($form->{salesman_id}) {
+ $where .= qq| AND a.salesman_id = ?|;
+ push(@values, conv_i($form->{salesman_id}));
+ }
+
my %sort_columns = (
'dunning_description' => [ qw(dn.dunning_description customername invnumber) ],
'customername' => [ qw(customername invnumber) ],
'duedate' => [ qw(a.duedate a.invnumber) ],
'dunning_date' => [ qw(dunning_date a.invnumber) ],
'dunning_duedate' => [ qw(dunning_duedate a.invnumber) ],
+ 'salesman' => [ qw(salesman) ],
);
my $sortdir = !defined $form->{sortdir} ? 'ASC' : $form->{sortdir} ? 'ASC' : 'DESC';
qq|SELECT a.id, a.ordnumber, a.invoice, a.transdate, a.invnumber, a.amount,
ct.name AS customername, ct.id AS customer_id, a.duedate, da.fee,
da.interest, dn.dunning_description, da.transdate AS dunning_date,
- da.duedate AS dunning_duedate, da.dunning_id, da.dunning_config_id
+ da.duedate AS dunning_duedate, da.dunning_id, da.dunning_config_id,
+ e2.name AS salesman
FROM ar a
- JOIN customer ct ON (a.customer_id = ct.id), dunning da
+ JOIN customer ct ON (a.customer_id = ct.id)
+ LEFT JOIN employee e2 ON (a.salesman_id = e2.id), dunning da
LEFT JOIN dunning_config dn ON (da.dunning_config_id = dn.id)
$where
ORDER BY $sortorder|;
my $in = IO::File->new("gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=- $inputfiles |");
$form->error($main::locale->text('Could not spawn ghostscript.')) unless $in;
- my $out;
-
if ($form->{media} eq 'printer') {
$form->get_printer_code($myconfig);
+ my $out;
if ($form->{printer_command}) {
$out = IO::File->new("| $form->{printer_command}");
}
+ $::locale->with_raw_io($out, sub { $out->print($_) while <$in> });
+
$form->error($main::locale->text('Could not spawn the printer command.')) unless $out;
} else {
- $out = IO::File->new('>-');
- $out->print(qq|Content-Type: Application/PDF\n| .
- qq|Content-Disposition: attachment; filename="dunning_${dunning_id}.pdf"\n\n|);
- }
+ my $dunning_filename = $form->get_formname_translation('dunning');
+ print qq|Content-Type: Application/PDF\n| .
+ qq|Content-Disposition: attachment; filename="${dunning_filename}_${dunning_id}.pdf"\n\n|;
- while (my $line = <$in>) {
- $out->print($line);
+ $::locale->with_raw_io(\*STDOUT, sub { print while <$in> });
}
$in->close();
- $out->close();
map { unlink("${main::spool}/$_") } @{ $form->{DUNNING_PDFS} };
my $sth = prepare_execute_query($form, $dbh, $query, $dunning_id);
my $first = 1;
- while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
+ while (my $ref = $sth->fetchrow_hashref("NAME_lc")) {
if ($first) {
- map({ $form->{"dn_$_"} = []; } keys(%{$ref}));
+ $form->{TEMPLATE_ARRAYS} = {};
+ map({ $form->{TEMPLATE_ARRAYS}->{"dn_$_"} = []; } keys(%{$ref}));
$first = 0;
}
map { $ref->{$_} = $form->format_amount($myconfig, $ref->{$_}, 2) } qw(amount netamount paid open_amount fee interest linetotal);
map { $form->{$_} = $ref->{$_} } keys %$ref;
- map { push @{ $form->{"dn_$_"} }, $ref->{$_}} keys %$ref;
+ map { push @{ $form->{TEMPLATE_ARRAYS}->{"dn_$_"} }, $ref->{$_} } keys %$ref;
}
$sth->finish();
$query =
qq|SELECT
- c.id AS customer_id, c.name, c.street, c.zipcode, c.city,
- c.country, c.department_1, c.department_2, c.email, c.customernumber,
- -- contact information
+ c.id AS customer_id, c.name, c.street, c.zipcode, c.city,
+ c.country, c.department_1, c.department_2, c.email, c.customernumber,
+ c.greeting, c.contact, c.phone, c.fax, c.homepage,
+ c.email, c.taxincluded, c.business_id, c.taxnumber, c.iban,
co.*
FROM dunning d
LEFT JOIN ar ON (d.trans_id = ar.id)
LEFT JOIN contacts co ON (ar.cp_id = co.cp_id)
WHERE (d.dunning_id = ?)
LIMIT 1|;
- $ref = selectfirst_hashref_query($form, $dbh, $query, $dunning_id);
+ my $ref = selectfirst_hashref_query($form, $dbh, $query, $dunning_id);
map { $form->{$_} = $ref->{$_} } keys %{ $ref };
$query =
c.name, c.department_1, c.department_2, c.street, c.zipcode, c.city, c.country,
c.contact, c.customernumber, c.phone, c.fax, c.email,
- c.taxnumber, c.sic_code, c.greeting
+ c.taxnumber, c.greeting
FROM ar
LEFT JOIN customer c ON (ar.customer_id = c.id)
WHERE ar.id = ?|;
- $ref = selectfirst_hashref_query($form, $dbh, $query, $ar_id);
+ my $ref = selectfirst_hashref_query($form, $dbh, $query, $ar_id);
map { $form->{$_} = $ref->{$_} } keys %{ $ref };
$query = qq|SELECT * FROM employee WHERE login = ?|;
$ref = selectfirst_hashref_query($form, $dbh, $query, $form->{login});
map { $form->{"employee_${_}"} = $ref->{$_} } keys %{ $ref };
- $query = qq|SELECT * FROM acc_trans WHERE trans_id = ? ORDER BY oid ASC|;
+ $query = qq|SELECT * FROM acc_trans WHERE trans_id = ? ORDER BY acc_trans_id ASC|;
$sth = prepare_execute_query($form, $dbh, $query, $ar_id);
my ($row, $fee, $interest) = (0, 0, 0);