Projekt

Allgemein

Profil

Herunterladen (25,6 KB) Statistiken
| Zweig: | Markierung: | Revision:
54e4131e Moritz Bunkus
#=====================================================================
# LX-Office ERP
# Copyright (C) 2006
# Based on SQL-Ledger Version 2.1.9
# Web http://www.lx-office.org
#
#=====================================================================
# SQL-Ledger Accounting
# Copyright (c) 1998-2002
#
# Author: Dieter Simader
# Email: dsimader@sql-ledger.org
# Web: http://www.sql-ledger.org
#
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#======================================================================
#
# Dunning process module
#
#======================================================================

use SL::IS;
use SL::PE;
use SL::DN;
use Data::Dumper;

fec09045 Moritz Bunkus
require "bin/mozilla/common.pl";
d629acd8 Sven Schöling
require "bin/mozilla/io.pl";
require "bin/mozilla/arap.pl";
54e4131e Moritz Bunkus
1;

sub edit_config {
$lxdebug->enter_sub();

DN->get_config(\%myconfig, \%$form);

fec09045 Moritz Bunkus
$form->{title} = $locale->text('Edit Dunning Process Config');
$form->{callback} ||= build_std_url("action=edit_config");
$form->{rowcount} = 1 + scalar @{ $form->{DUNNING} };
$form->{rowcount_odd} = $form->{rowcount} % 2;
54e4131e Moritz Bunkus
fec09045 Moritz Bunkus
$form->header();
print $form->parse_html_template("dunning/edit_config");
54e4131e Moritz Bunkus
$lxdebug->leave_sub();
}

sub add {
$lxdebug->enter_sub();
# setup customer selection
$form->all_vc(\%myconfig, "customer", "AR");

DN->get_config(\%myconfig, \%$form);

if (@{ $form->{all_customer} }) {
map { $customer .= "<option>$_->{name}--$_->{id}\n" }
@{ $form->{all_customer} };
$customer = qq|<select name=customer><option>\n$customer</select>|;
} else {
$customer = qq|<input name=customer size=35>|;
}

# dunning levels
if (@{ $form->{DUNNING} }) {
$form->{selectdunning_level} = "<option></option\n";
map {
$form->{selectdunning_level} .=
"<option value=$_->{id}>$_->{dunning_description}</option>\n"
} (@{ $form->{DUNNING} });
}
$dunning_level = qq|
<tr>
<th align=right nowrap>| . $locale->text('Next Dunning Level') . qq|</th>
<td colspan=3><select name=dunning_level>$form->{selectdunning_level}</select></td>
</tr>
| if $form->{selectdunning_level};

# departments
if (@{ $form->{all_departments} }) {
$form->{selectdepartment} = "<option>\n";
map {
$form->{selectdepartment} .=
"<option>$_->{description}--$_->{id}\n"
} (@{ $form->{all_departments} });
}
$department = qq|
<tr>
<th align=right nowrap>| . $locale->text('Department') . qq|</th>
<td colspan=3><select name=department>$form->{selectdepartment}</select></td>
</tr>
| if $form->{selectdepartment};

fd6900cc Moritz Bunkus
$form->{title} = $locale->text('Start Dunning Process');
$form->{nextsub} = "show_invoices";
54e4131e Moritz Bunkus
fd6900cc Moritz Bunkus
$form->{jsscript} = 1;
$form->{fokus} = "search.customer";
be4e11d3 Thomas Kasulke
$form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
fd6900cc Moritz Bunkus
$form->header();

be4e11d3 Thomas Kasulke
$onload = qq|focus()|;
$onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
$onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
fd6900cc Moritz Bunkus
54e4131e Moritz Bunkus
print qq|
be4e11d3 Thomas Kasulke
<body onLoad="$onload">
54e4131e Moritz Bunkus
<form method=post name="search" action=$form->{script}>

<table width=100%>
<tr><th class=listtop>$form->{title}</th></tr>
<tr height="5"></tr>
<tr>
<td>
<table>
<tr>
<th align=right>| . $locale->text('Customer') . qq|</th>
<td colspan=3>$customer</td>
</tr>
$dunning_level
$department
<tr>
<th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
<td colspan=3><input name=invnumber size=20></td>
</tr>
<tr>
<th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
<td colspan=3><input name=ordnumber size=20></td>
</tr>
<tr>
<th align=right nowrap>| . $locale->text('Notes') . qq|</th>
<td colspan=3><input name=notes size=40></td>
</tr>
</table>
</td>
</tr>
<tr>
<td><hr size=3 noshade></td>
</tr>
<tr>
<td>
<table>
<tr>
<th align=right nowrap>| . $locale->text('Minimum Amount') . qq|</th>
<td><input name=minamount size=6></td>
</tr>
<tr>
<th align=right nowrap>| . $locale->text('Group Invoices') . qq|</th>
<td><input type=checkbox value=1 name=groupinvoices checked></td>
</tr>
</table>
</td>
</tr>
</table>

<input type=hidden name=nextsub value=$form->{nextsub}>

<input type=hidden name=login value=$form->{login}>
<input type=hidden name=password value=$form->{password}>

<br>
<input class=submit type=submit name=action value="|
. $locale->text('Continue') . qq|">

</form>

</body>

$jsscript

</html>
|;

$lxdebug->leave_sub();

}

sub show_invoices {
$lxdebug->enter_sub();

DN->get_invoices(\%myconfig, \%$form);
$form->{title} = $locale->text('Start Dunning Process');

if (@{ $form->{DUNNING_CONFIG} }) {
foreach $item (@{ $form->{DUNNING_CONFIG} }) {
$form->{selectdunning} .=
"<option value=$item->{id}>$item->{dunning_description}</option>";
}
}


$form->{nextsub} = "save_dunning";
cd3dc84b Moritz Bunkus
$form->{jsscript} = 1;
$form->{javascript} .= qq|<script type="text/javascript" src="js/checkbox_utils.js"></script>|;

54e4131e Moritz Bunkus
$form->{callback} =
d629acd8 Sven Schöling
"$form->{script}?action=show_invoices&login=$form->{login}&password=$form->{password}&customer=$form->{customer}&invnumber=$form->{invnumber}&ordnumber=$form->{ordnumber}&paymentuntil=$form->{paymentuntil}&groupinvoices=$form->{groupinvoices}&minamount=$form->{minamount}&dunning_level=$form->{dunning_level}&notes=$form->{notes}"
54e4131e Moritz Bunkus
unless $form->{callback};

fd6900cc Moritz Bunkus
@column_index = qw(dunning_description dunning_description_next active email customername invnumber invdate inv_duedate amount next_duedate fee interest );
54e4131e Moritz Bunkus
$column_header{dunning_description} =
fd6900cc Moritz Bunkus
qq|<th class="listheading" colspan="2">|
54e4131e Moritz Bunkus
. $locale->text('Current / Next Level')
. qq|</th>|;
$column_header{active} =
qq|<th class=listheading>|
cd3dc84b Moritz Bunkus
. NTI($cgi->checkbox('-name' => 'selectall_active',
'-label' => $locale->text('Active?'),
fd6900cc Moritz Bunkus
'-checked' => 0,
cd3dc84b Moritz Bunkus
'-onclick' => "checkbox_check_all('selectall_active', 'active_', 1, " . scalar(@{ $form->{DUNNINGS} }) . ")"))
54e4131e Moritz Bunkus
. qq|</th>|;
$column_header{email} =
qq|<th class=listheading>|
cd3dc84b Moritz Bunkus
. NTI($cgi->checkbox('-name' => 'selectall_email',
'-label' => $locale->text('eMail?'),
'-checked' => 0,
'-onclick' => "checkbox_check_all('selectall_email', 'email_', 1, " . scalar(@{ $form->{DUNNINGS} }) . ")"))
54e4131e Moritz Bunkus
. qq|</th>|;
$column_header{customername} =
qq|<th class=listheading>|
. $locale->text('Customername')
. qq|</th>|;
$column_header{invnumber} =
qq|<th class=listheading>|
. $locale->text('Invno.')
. qq|</th>|;
$column_header{inv_duedate} =
qq|<th class=listheading>|
. $locale->text('Inv. Duedate')
. qq|</th>|;
$column_header{next_duedate} =
qq|<th class=listheading>|
. $locale->text('Dunning Duedate')
. qq|</th>|;
$column_header{invdate} =
qq|<th class=listheading>|
. $locale->text('Invdate')
. qq|</th>|;
fd6900cc Moritz Bunkus
$column_header{amount} =
54e4131e Moritz Bunkus
qq|<th class=listheading>|
. $locale->text('Amount')
. qq|</th>|;
$column_header{fee} =
qq|<th class=listheading>|
. $locale->text('Total Fees')
. qq|</th>|;
$column_header{interest} =
qq|<th class=listheading>|
fd6900cc Moritz Bunkus
. $locale->text('Interest')
54e4131e Moritz Bunkus
. qq|</th>|;

$form->header;


print qq|
<body>
<script type="text/javascript" src="js/common.js"></script>
<script type="text/javascript" src="js/dunning.js"></script>
142891a0 Philip Reetz
<form name=Form method=post action=$form->{script}>
54e4131e Moritz Bunkus

<table width=100%>
<tr>
fd6900cc Moritz Bunkus
<th class=listtop colspan=12>$form->{title}</th>
54e4131e Moritz Bunkus
</tr>
<tr height="5"></tr>
<tr>|;
fd6900cc Moritz Bunkus
map { print "$column_header{$_}\n" if $column_header{$_}; } @column_index;
54e4131e Moritz Bunkus
print qq|
</tr>
|;
my $i = 0;
foreach $ref (@{ $form->{DUNNINGS} }) {

$i++;
my $j = $i % 2;

print qq|
<tr valign=top class=listrow$j>
|;

fd6900cc Moritz Bunkus
$form->{selectdunning} =~ s/ selected//g;
if ($ref->{next_dunning_config_id} ne "") {
$form->{selectdunning} =~ s/value=$ref->{next_dunning_config_id}/value=$ref->{next_dunning_config_id} selected/;
}
54e4131e Moritz Bunkus
fd6900cc Moritz Bunkus
$column_data{dunning_description} =
qq|<td>|
. qq|<input type=hidden name=inv_id_$i size=2 value="$ref->{id}">|
. qq|<input type=hidden name=customer_id_$i size=2 value="$ref->{customer_id}">|
. ($ref->{dunning_level} ? $ref->{dunning_level} : "&nbsp;")
. qq|</td>|;
$column_data{dunning_description_next} =
qq|<td>|
. qq|<select name=next_dunning_config_id_$i>$form->{selectdunning}</select>|
. qq|</td>|;
7743b3ab Philip Reetz
my $active = ($ref->{active}) ? "checked" : "";
54e4131e Moritz Bunkus
$column_data{active} =
qq|<td><input type=checkbox name=active_$i value=1 $active></td>|;
7743b3ab Philip Reetz
my $email = ($ref->{email}) ? "checked" : "";
fd6900cc Moritz Bunkus
$column_data{email} =
qq|<td><input type=checkbox name=email_$i value=1 $email></td>|;
$column_data{next_duedate} = qq|<td>$ref->{next_duedate}</td>|;
54e4131e Moritz Bunkus
$column_data{inv_duedate} = qq|<td><input type=hidden name=inv_duedate_$i size=6 value="$ref->{duedate}">$ref->{duedate}</td>|;
$column_data{invdate} = qq|<td><input type=hidden name=invdate_$i size=6 value="$ref->{transdate}">$ref->{transdate}</td>|;
$column_data{invnumber} = qq|<td><input type=hidden name=invnumber_$i size=6 value="$ref->{invnumber}">$ref->{invnumber}</td>|;
$column_data{customername} = qq|<td><input type=hidden name=customername_$i size=6 value="$ref->{customername}">$ref->{customername}</td>|;

fd6900cc Moritz Bunkus
map { $column_data{$_} =
qq|<td align="right">|
. H($form->format_amount(\%myconfig, $ref->{$_} * 1, -2))
. qq|</td>|
} qw(amount fee interest);
54e4131e Moritz Bunkus
map { print "$column_data{$_}\n" } @column_index;

print qq|
</tr>
|;
}

$form->{rowcount} = $i;

print qq|
</table>
</td>
</tr>
<tr>
<td><hr size=3 noshade></td>
</tr>
</table>|;
1514a9d0 Moritz Bunkus
print_options();
8ec0d29a Moritz Bunkus
print qq|
54e4131e Moritz Bunkus
<br>
<form method=post action=$form->{script}>

<input name=callback type=hidden value="$form->{callback}">
<input name=rowcount type=hidden value="$form->{rowcount}">
<input name=nextsub type=hidden value="$form->{nextsub}">
<input name=groupinvoices type=hidden value="$form->{groupinvoices}">


<input type=hidden name=login value=$form->{login}>
8ec0d29a Moritz Bunkus
<input type=hidden name=password value=$form->{password}>
142891a0 Philip Reetz
<input type="hidden" name="action">
<input type="submit" name="dummy" value="|
8ec0d29a Moritz Bunkus
. $locale->text('Continue') . qq|" onclick="this.disabled=true; this.value='| . $locale->text("The dunning process started") . qq|'; document.Form.action.value='| . $locale->text('Continue') . qq|'; document.Form.submit()">
54e4131e Moritz Bunkus
</form>

</body>
</html>
|;


$lxdebug->leave_sub();

}

sub save {
$lxdebug->enter_sub();

for my $i (1 .. $form->{rowcount}) {
if ($form->{"dunning_description_$i"} ne "") {
$form->isblank("dunning_level_$i", $locale->text('Dunning Level missing in row '). $i);
$form->isblank("dunning_description_$i", $locale->text('Dunning Description missing in row '). $i);
$form->isblank("terms_$i", $locale->text('Terms missing in row '). $i);
$form->isblank("payment_terms_$i", $locale->text('Payment Terms missing in row '). $i);
}
}

DN->save_config(\%myconfig, \%$form);
2b89ec97 Thomas Kasulke
# saving the history
if(!exists $form->{addition} && $form->{id} ne "") {
8cef58b2 Thomas Kasulke
$form->{snumbers} = qq|dunning_id_| . $form->{"dunning_id"};
$form->{addition} = "SAVED FOR DUNNING";
2b89ec97 Thomas Kasulke
$form->save_history($form->dbconnect(\%myconfig));
}
# /saving the history
54e4131e Moritz Bunkus
$form->redirect($locale->text('Dunning Process Config saved!'));

$lxdebug->leave_sub();
}

sub save_dunning {
$lxdebug->enter_sub();

my $active=1;
my @rows = ();
undef($form->{DUNNING_PDFS});
fd6900cc Moritz Bunkus
54e4131e Moritz Bunkus
if ($form->{groupinvoices}) {
fd6900cc Moritz Bunkus
my %dunnings_for;

for my $i (1 .. $form->{rowcount}) {
next unless ($form->{"active_$i"});

$dunnings_for{$form->{"customer_id_$i"}} ||= {};
my $dunning_levels = $dunnings_for{$form->{"customer_id_$i"}};

$dunning_levels->{$form->{"next_dunning_config_id_$i"}} ||= [];
my $level = $dunning_levels->{$form->{"next_dunning_config_id_$i"}};

push @{ $level }, { "row" => $i,
"invoice_id" => $form->{"inv_id_$i"},
"customer_id" => $form->{"customer_id_$i"},
"next_dunning_config_id" => $form->{"next_dunning_config_id_$i"},
"email" => $form->{"email_$i"}, };
}

foreach my $levels (values %dunnings_for) {
foreach my $level (values %{ $levels }) {
next unless scalar @{ $level };

DN->save_dunning(\%myconfig, \%$form, $level, $userspath, $spool, $sendmail);
54e4131e Moritz Bunkus
}
}
fd6900cc Moritz Bunkus
54e4131e Moritz Bunkus
} else {
for my $i (1 .. $form->{rowcount}) {
fd6900cc Moritz Bunkus
next unless $form->{"active_$i"};

my $level = [ { "row" => $i,
"invoice_id" => $form->{"inv_id_$i"},
"customer_id" => $form->{"customer_id_$i"},
"next_dunning_config_id" => $form->{"next_dunning_config_id_$i"},
"email" => $form->{"email_$i"}, } ];
DN->save_dunning(\%myconfig, \%$form, $level, $userspath, $spool, $sendmail);
54e4131e Moritz Bunkus
}
}
fd6900cc Moritz Bunkus
54e4131e Moritz Bunkus
if($form->{DUNNING_PDFS}) {
DN->melt_pdfs(\%myconfig, \%$form,$spool);
}
fd6900cc Moritz Bunkus
2b89ec97 Thomas Kasulke
# saving the history
if(!exists $form->{addition} && $form->{id} ne "") {
8cef58b2 Thomas Kasulke
$form->{snumbers} = qq|dunning_id_| . $form->{"dunning_id"};
$form->{addition} = "DUNNING STARTED";
2b89ec97 Thomas Kasulke
$form->save_history($form->dbconnect(\%myconfig));
}
fd6900cc Moritz Bunkus
# /saving the history

54e4131e Moritz Bunkus
$form->redirect($locale->text('Dunning Process started for selected invoices!'));

$lxdebug->leave_sub();
}
fd6900cc Moritz Bunkus
54e4131e Moritz Bunkus
sub set_email {
$lxdebug->enter_sub();


my $callback = "$form->{script}?action=set_email&";
map({ $callback .= "$_=" . $form->escape($form->{$_}) . "&" }
d629acd8 Sven Schöling
(qw(login password name input_subject input_body input_attachment email_subject email_body email_attachment), grep({ /^[fl]_/ } keys %$form)));
54e4131e Moritz Bunkus
if ($form->{email_attachment}) {
$form->{email_attachment} = "checked";
}
$form->{"title"} = $locale->text("Set eMail text");
$form->header();
print($form->parse_html_template("dunning/set_email"));

$lxdebug->leave_sub();
}

sub search {
$lxdebug->enter_sub();
# setup customer selection
$form->all_vc(\%myconfig, "customer", "AR");

DN->get_config(\%myconfig, \%$form);

if (@{ $form->{all_customer} }) {
map { $customer .= "<option>$_->{name}--$_->{id}\n" }
@{ $form->{all_customer} };
$customer = qq|<select name=customer><option>\n$customer</select>|;
} else {
$customer = qq|<input name=customer size=35>|;
}

# dunning levels
if (@{ $form->{DUNNING} }) {
$form->{selectdunning_level} = "<option></option\n";
map {
$form->{selectdunning_level} .=
"<option value=$_->{id}>$_->{dunning_description}</option>\n"
} (@{ $form->{DUNNING} });
}
$dunning_level = qq|
<tr>
<th align=right nowrap>| . $locale->text('Next Dunning Level') . qq|</th>
<td colspan=3><select name=dunning_level>$form->{selectdunning_level}</select></td>
</tr>
| if $form->{selectdunning_level};

# departments
if (@{ $form->{all_departments} }) {
$form->{selectdepartment} = "<option>\n";
map {
$form->{selectdepartment} .=
"<option>$_->{description}--$_->{id}\n"
} (@{ $form->{all_departments} });
}
$department = qq|
<tr>
<th align=right nowrap>| . $locale->text('Department') . qq|</th>
<td colspan=3><select name=department>$form->{selectdepartment}</select></td>
</tr>
| if $form->{selectdepartment};
$form->{title} = $locale->text('Search Dunning');
$form->{nextsub} = "show_dunning";

# use JavaScript Calendar or not
$form->{jsscript} = $jscalendar;
$jsscript = "";
if ($form->{jsscript}) {

# with JavaScript Calendar
$button1 = qq|
be4e11d3 Thomas Kasulke
<td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
54e4131e Moritz Bunkus
<input type=button name=transdatefrom id="trigger1" value=|
. $locale->text('button') . qq|></td>
|;
$button2 = qq|
be4e11d3 Thomas Kasulke
<td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
54e4131e Moritz Bunkus
<input type=button name=transdateto id="trigger2" value=|
. $locale->text('button') . qq|></td>
|;
$button3 = qq|
be4e11d3 Thomas Kasulke
<td><input name=dunningfrom id=dunningfrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
54e4131e Moritz Bunkus
<input type=button name=dunningfrom id="trigger3" value=|
. $locale->text('button') . qq|></td>
|;
$button4 = qq|
be4e11d3 Thomas Kasulke
<td><input name=dunningto id=dunningto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
54e4131e Moritz Bunkus
<input type=button name=dunningto id="trigger4" value=|
. $locale->text('button') . qq|></td>
|;

#write Trigger
$jsscript =
Form->write_trigger(\%myconfig, "4", "transdatefrom", "BR", "trigger1", "transdateto", "BR", "trigger2", "dunningfrom", "BR", "trigger3", "dunningto", "BR", "trigger4");
} else {

# without JavaScript Calendar
$button1 =
be4e11d3 Thomas Kasulke
qq|<td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
54e4131e Moritz Bunkus
$button2 =
be4e11d3 Thomas Kasulke
qq|<td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
$button3 =
qq|<td><input name=dunningfrom id=dunningfrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
$button4 =
qq|<td><input name=dunningfrom id=dunningto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
54e4131e Moritz Bunkus
}

$form->{fokus} = "search.customer";
be4e11d3 Thomas Kasulke
$form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
54e4131e Moritz Bunkus
$form->header;
be4e11d3 Thomas Kasulke
$onload = qq|focus()|;
$onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
$onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;

54e4131e Moritz Bunkus
print qq|
be4e11d3 Thomas Kasulke
<body onLoad="$onload">
54e4131e Moritz Bunkus
<form method=post name="search" action=$form->{script}>

<table width=100%>
<tr><th class=listtop>$form->{title}</th></tr>
<tr height="5"></tr>
<tr>
<td>
<table>
<tr>
<th align=right>| . $locale->text('Customer') . qq|</th>
<td colspan=3>$customer</td>
</tr>
$dunning_level
$department
<tr>
<th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
<td colspan=3><input name=invnumber size=20></td>
</tr>
<tr>
<th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
<td colspan=3><input name=ordnumber size=20></td>
</tr>
<tr>
<th align=right nowrap>| . $locale->text('Notes') . qq|</th>
<td colspan=3><input name=notes size=40></td>
</tr>
<tr>
<th align=right nowrap>| . $locale->text('Invdate from') . qq|</th>
$button1
<th align=right nowrap>| . $locale->text('To') . qq|</th>
$button2
</tr>
<tr>
<th align=right nowrap>| . $locale->text('Dunning Date from') . qq|</th>
$button3
<th align=right nowrap>| . $locale->text('To') . qq|</th>
$button4
</tr>

</table>
</td>
</tr>
<tr>
<td><hr size=3 noshade></td>
</tr>
<tr>
<td>
<table>
<tr>
<th align=right nowrap>| . $locale->text('Show old dunnings') . qq|</th>
<td><input type=checkbox value=1 name=showold></td>
</tr>
</table>
</td>
</tr>
</table>

<input type=hidden name=nextsub value=$form->{nextsub}>

<input type=hidden name=login value=$form->{login}>
<input type=hidden name=password value=$form->{password}>

<br>
<input class=submit type=submit name=action value="|
. $locale->text('Continue') . qq|">

</form>

</body>

$jsscript

</html>
|;

$lxdebug->leave_sub();

}

sub show_dunning {
$lxdebug->enter_sub();

DN->get_dunning(\%myconfig, \%$form);
$form->{title} = $locale->text('Dunning overview');




$form->{callback} =
d629acd8 Sven Schöling
"$form->{script}?action=show_dunning&login=$form->{login}&password=$form->{password}&customer=$form->{customer}&invnumber=$form->{invnumber}&ordnumber=$form->{ordnumber}&transdatefrom=$form->{transdatefrom}&transdateto=$form->{transdateto}&dunningfrom=$form->{dunningfrom}&dunningto=$form->{dunningto}&notes=$form->{notes}&showold=$form->{showold}&dunning_level=$form->{dunning_level}"
54e4131e Moritz Bunkus
unless $form->{callback};

@column_index = qw(dunning_description customername invnumber invdate inv_duedate invamount dunning_date next_duedate fee interest );

$column_header{dunning_description} =
qq|<th class=listheading>|
. $locale->text('Dunning Level')
. qq|</th>|;
$column_header{customername} =
qq|<th class=listheading>|
. $locale->text('Customername')
. qq|</th>|;
$column_header{invnumber} =
qq|<th class=listheading>|
. $locale->text('Invnumber')
. qq|</th>|;
$column_header{inv_duedate} =
qq|<th class=listheading>|
. $locale->text('Invoice Duedate')
. qq|</th>|;
$column_header{dunning_date} =
qq|<th class=listheading>|
. $locale->text('Dunning Date')
. qq|</th>|;
$column_header{next_duedate} =
qq|<th class=listheading>|
. $locale->text('Dunning Duedate')
. qq|</th>|;
$column_header{invdate} =
qq|<th class=listheading>|
. $locale->text('Invdate')
. qq|</th>|;
$column_header{invamount} =
qq|<th class=listheading>|
. $locale->text('Amount')
. qq|</th>|;
$column_header{fee} =
qq|<th class=listheading>|
. $locale->text('Total Fees')
. qq|</th>|;
$column_header{interest} =
qq|<th class=listheading>|
fd6900cc Moritz Bunkus
. $locale->text('Interest')
54e4131e Moritz Bunkus
. qq|</th>|;

$form->header;


print qq|
<body>
<script type="text/javascript" src="js/common.js"></script>
<script type="text/javascript" src="js/dunning.js"></script>
<form method=post action=$form->{script}>


<table width=100%>
<tr>
7dab0cbd Moritz Bunkus
<th class=listtop colspan=10>$form->{title}</th>
54e4131e Moritz Bunkus
</tr>
<tr height="5"></tr>
<tr>|;
map { print "$column_header{$_}\n" } @column_index;

print qq|
</tr>
|;
840aea13 Moritz Bunkus
my %columns = (
"dunning_duedate" => "next_duedate",
"duedate" => "inv_duedate",
"transdate" => "invdate",
"amount" => "invamount",
);

54e4131e Moritz Bunkus
my $i = 0;
7dab0cbd Moritz Bunkus
my $j = 0;
840aea13 Moritz Bunkus
my ($previous_dunning_id, $first_row_for_dunning);
54e4131e Moritz Bunkus
foreach $ref (@{ $form->{DUNNINGS} }) {
$i++;
840aea13 Moritz Bunkus
if ($previous_dunning_id != $ref->{dunning_id}) {
$j++;
$j = $j % 2;
$first_row_for_dunning = 1;
} else {
$first_row_for_dunning = 0;
}
$previous_dunning_id = $ref->{dunning_id};
54e4131e Moritz Bunkus
print qq|
<tr valign=top class=listrow$j>
|;


fd6900cc Moritz Bunkus
foreach (qw(dunning_date dunning_duedate duedate transdate customername amount fee interest)) {
840aea13 Moritz Bunkus
my $col = $columns{$_} ? $columns{$_} : $_;
$column_data{$col} = "<td>" . H($ref->{$_}) . "</td>";
8f98fc19 Philip Reetz
}
54e4131e Moritz Bunkus
840aea13 Moritz Bunkus
if ($first_row_for_dunning) {
$column_data{dunning_description} =
qq|<td><a href="dn.pl?action=print_dunning&format=pdf&media=screen&| .
qq|dunning_id=| . E($ref->{dunning_id}) .
69239581 Moritz Bunkus
join("", map({ "&${_}=" . E($form->{$_}) } qw(login password callback))) .
840aea13 Moritz Bunkus
qq|">| . H($ref->{dunning_description}) . qq|</a></td>|;
} else {
$column_data{dunning_description} = qq|<td>&nbsp;</td>|;
$column_data{customername} = qq|<td>&nbsp;</td>|;
}
54e4131e Moritz Bunkus
840aea13 Moritz Bunkus
$column_data{invnumber} =
qq|<td><a href="| . ($ref->{invoice} ? "is.pl" : "ar.pl" ) .
qq|?action=edit&id=| . H($ref->{id}) .
69239581 Moritz Bunkus
join("", map({ "&${_}=" . E($form->{$_}) } qw(login password callback))) .
840aea13 Moritz Bunkus
qq|">| . H($ref->{invnumber}) . qq|</a></td>|;
54e4131e Moritz Bunkus
map { print "$column_data{$_}\n" } @column_index;

print qq|
</tr>
|;
}

$form->{rowcount} = $i;

print qq|
</table>
</td>
</tr>
<tr>
<td><hr size=3 noshade></td>
</tr>
</table>

<br>
<form method=post action=$form->{script}>

<input name=callback type=hidden value="$form->{callback}">
<input name=rowcount type=hidden value="$form->{rowcount}">
<input name=nextsub type=hidden value="$form->{nextsub}">


<input type=hidden name=login value=$form->{login}>
<input type=hidden name=password value=$form->{password}>

</form>

</body>
</html>
|;


$lxdebug->leave_sub();

}
4deefb65 Philip Reetz
sub print_dunning {
$lxdebug->enter_sub();

840aea13 Moritz Bunkus
DN->print_dunning(\%myconfig, \%$form, $form->{dunning_id}, $userspath, $spool, $sendmail);
4deefb65 Philip Reetz
if($form->{DUNNING_PDFS}) {
DN->melt_pdfs(\%myconfig, \%$form,$spool);
} else {
$form->redirect($locale->text('Could not create dunning copy!'));
}

$lxdebug->leave_sub();

}

54e4131e Moritz Bunkus
# end of main