|;
- $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/;
- }
-
-
- $dunning = qq||;
-
+ $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/;
+ }
- $column_data{dunning_description} = qq|$ref->{dunning_level}: $dunning | |;
+ $column_data{dunning_description} =
+ qq||
+ . qq||
+ . qq||
+ . ($ref->{dunning_level} ? $ref->{dunning_level} : " ")
+ . qq| | |;
+ $column_data{dunning_description_next} =
+ qq||
+ . qq||
+ . qq| | |;
my $active = ($ref->{active}) ? "checked" : "";
$column_data{active} =
qq| | |;
my $email = ($ref->{email}) ? "checked" : "";
- $column_data{email} =
- qq| | |;
- $column_data{next_duedate} = qq|$ref->{next_duedate} | |;
+ $column_data{email} =
+ qq| | |;
+ $column_data{next_duedate} = qq|$ref->{next_duedate} | |;
$column_data{inv_duedate} = qq|$ref->{duedate} | |;
$column_data{invdate} = qq|$ref->{transdate} | |;
$column_data{invnumber} = qq|$ref->{invnumber} | |;
$column_data{customername} = qq|$ref->{customername} | |;
- $column_data{invamount} = qq|$ref->{amount} | |;
- $column_data{fee} = qq|$ref->{fee} | |;
- $column_data{interest} = qq|$ref->{interest} | |;
-
+ map { $column_data{$_} =
+ qq||
+ . H($form->format_amount(\%myconfig, $ref->{$_} * 1, -2))
+ . qq| | |
+ } qw(amount fee interest);
map { print "$column_data{$_}\n" } @column_index;
@@ -519,7 +515,6 @@ sub show_invoices {
-{path}>
{login}>
{password}>
@@ -552,7 +547,8 @@ sub save {
DN->save_config(\%myconfig, \%$form);
# saving the history
if(!exists $form->{addition} && $form->{id} ne "") {
- $form->{addition} = "SAVED FOR DUNNING";
+ $form->{snumbers} = qq|dunning_id_| . $form->{"dunning_id"};
+ $form->{addition} = "SAVED FOR DUNNING";
$form->save_history($form->dbconnect(\%myconfig));
}
# /saving the history
@@ -567,61 +563,71 @@ sub save_dunning {
my $active=1;
my @rows = ();
undef($form->{DUNNING_PDFS});
+
if ($form->{groupinvoices}) {
- while ($active) {
- $lastcustomer = 0;
- $form->{inv_ids} = [];
- $active = 0;
- @rows = ();
- for my $i (1 .. $form->{rowcount}) {
- $form->{"active_$i"} *= 1;
- $lastcustomer = $form->{"customer_id_$i"} unless ($lastcustomer);
- if ($form->{"active_$i"} && ($form->{"customer_id_$i"} == $lastcustomer)) {
- push(@{ $form->{inv_ids} }, $form->{"inv_id_$i"});
- $form->{"active_$i"} = 0;
- $form->{"customer_id_$i"} = 0;
- push(@rows, $i);
- } elsif ($form->{"active_$i"}) {
- $active = 1;
- } else {
- $form->{"customer_id_$i"} = 0;
- }
- }
- if (scalar(@{ $form->{inv_ids} }) != 0) {
- DN->save_dunning(\%myconfig, \%$form, \@rows, $userspath, $spool, $sendmail);
+ 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);
}
}
+
} else {
for my $i (1 .. $form->{rowcount}) {
- if ($form->{"active_$i"}) {
- @rows = ();
- $form->{inv_ids} = [ $form->{"inv_id_$i"} ];
- push(@rows, $i);
- DN->save_dunning(\%myconfig, \%$form, \@rows, $userspath, $spool, $sendmail);
- }
+ 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);
}
}
+
if($form->{DUNNING_PDFS}) {
DN->melt_pdfs(\%myconfig, \%$form,$spool);
}
+
# saving the history
if(!exists $form->{addition} && $form->{id} ne "") {
- $form->{addition} = "DUNNING STARTED";
+ $form->{snumbers} = qq|dunning_id_| . $form->{"dunning_id"};
+ $form->{addition} = "DUNNING STARTED";
$form->save_history($form->dbconnect(\%myconfig));
}
- # /saving the history
+ # /saving the history
+
$form->redirect($locale->text('Dunning Process started for selected invoices!'));
$lxdebug->leave_sub();
}
-
+
sub set_email {
$lxdebug->enter_sub();
my $callback = "$form->{script}?action=set_email&";
map({ $callback .= "$_=" . $form->escape($form->{$_}) . "&" }
- (qw(login path password name input_subject input_body input_attachment email_subject email_body email_attachment), grep({ /^[fl]_/ } keys %$form)));
+ (qw(login password name input_subject input_body input_attachment email_subject email_body email_attachment), grep({ /^[fl]_/ } keys %$form)));
if ($form->{email_attachment}) {
$form->{email_attachment} = "checked";
@@ -687,22 +693,22 @@ sub search {
# with JavaScript Calendar
$button1 = qq|
-
+ |
text('button') . qq|> |
|;
$button2 = qq|
-
+ |
text('button') . qq|> |
|;
$button3 = qq|
-
+ |
text('button') . qq|> |
|;
$button4 = qq|
-
+ |
text('button') . qq|> |
|;
@@ -714,19 +720,24 @@ sub search {
# without JavaScript Calendar
$button1 =
- qq| | |;
+ qq| | |;
$button2 =
- qq| | |;
- $button1 =
- qq| | |;
- $button1 =
- qq| | |;
+ qq| | |;
+ $button3 =
+ qq| | |;
+ $button4 =
+ qq| | |;
}
$form->{fokus} = "search.customer";
+ $form->{javascript} .= qq||;
$form->header;
+ $onload = qq|focus()|;
+ $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
+ $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
+
print qq|
-
+