my $q_insert_dunning =
qq|INSERT INTO dunning (id, dunning_id, dunning_config_id, dunning_level, trans_id,
- fee, interest, transdate, duedate)
+ fee, interest, transdate, duedate, original_invoice_printed)
VALUES (?, ?, ?,
(SELECT dunning_level FROM dunning_config WHERE id = ?),
?,
* (SELECT interest_rate FROM dunning_config WHERE id = ?)
/ 360,
current_date,
- current_date + (SELECT payment_terms FROM dunning_config WHERE id = ?))|;
+ current_date + (SELECT payment_terms FROM dunning_config WHERE id = ?),
+ ?)|;
my $h_insert_dunning = prepare_query($form, $dbh, $q_insert_dunning);
my @invoice_ids;
@values = ($row_id, $dunning_id, $next_config_id,
$next_config_id, $invoice_id, $next_config_id,
- $invoice_id, $next_config_id, $next_config_id);
+ $invoice_id, $next_config_id, $next_config_id,
+ $print_invoice);
do_statement($form, $h_insert_dunning, $q_insert_dunning, @values);
RecordLinks->create_links(
$form->{dunning_id} = $dunning_id;
DN->print_invoice_for_fees(\%myconfig, $form, $dunning_id);
DN->print_dunning(\%myconfig, $form, $dunning_id);
+
+ # print original dunned invoices, if they where printed on dunning run
+ my $dunnings = SL::DB::Manager::Dunning->get_all(where => [dunning_id => $dunning_id, original_invoice_printed => 1]);
+ DN->print_original_invoice(\%myconfig, $form, $_->trans_id) for @$dunnings;
+
$i++;
}
$form->{language_id} = $saved_language_id;