{ title => t8('Email'), type => 'email_journal', model => 'EmailJournal', number => 'id', description => 'subject', description_title => t8('Subject'), },
{ title => t8('AR Transaction'), type => 'ar_transaction', model => 'Invoice', number => 'invnumber', },
{ title => t8('AP Transaction'), type => 'ap_transaction', model => 'PurchaseInvoice', number => 'invnumber', },
+ { title => t8('Dunning'), type => 'dunning', model => 'Dunning', number => 'dunning_id', },
);
my @link_types = map { +{ %link_type_defaults, %{ $_ } } } @link_type_specifics;
use strict;
use SL::DB::MetaSetup::Dunning;
+use SL::DB::Helper::LinkedRecords;
__PACKAGE__->meta->initialize;
# Creates get_all, get_all_count, get_all_iterator, delete_all and update_all.
__PACKAGE__->meta->make_manager_class;
+
+sub date {
+ goto &transdate;
+}
+
1;
'SL::DB::Letter' => sub { $_[0]->letternumber },
'SL::DB::ShopOrder' => sub { $_[0]->shop_ordernumber },
'SL::DB::EmailJournal' => sub { $_[0]->id },
+ 'SL::DB::Dunning' => sub { $_[0]->dunning_id },
UNKNOWN => '9999999999999999',
);
my $number_xtor = sub {
'SL::DB::Letter' => 200,
'SL::DB::ShopOrder' => 250,
'SL::DB::EmailJournal' => 300,
+ 'SL::DB::Dunning' => 350,
UNKNOWN => 999,
);
my $score_xtor = sub {
AND (d_interest.dunning_id <> ?)
AND NOT (d_interest.fee_interest_ar_id ISNULL)
), 0)
- AS max_previous_interest
+ AS max_previous_interest,
+ d.id AS link_id
FROM dunning d
WHERE dunning_id = ?|;
@values = ($dunning_id, $dunning_id, $dunning_id);
my ($fee_remaining, $interest_remaining) = (0, 0);
my ($fee_total, $interest_total) = (0, 0);
+ my @link_ids;
+
while (my $ref = $sth->fetchrow_hashref()) {
$fee_remaining += $form->round_amount($ref->{fee}, 2);
$fee_remaining -= $form->round_amount($ref->{max_previous_fee}, 2);
$interest_remaining += $form->round_amount($ref->{interest}, 2);
$interest_remaining -= $form->round_amount($ref->{max_previous_interest}, 2);
$interest_total += $form->round_amount($ref->{interest}, 2);
+ push @link_ids, $ref->{link_id};
}
$sth->finish();
$::myconfig{login}); # employee_id
do_query($form, $dbh, $query, @values);
+ RecordLinks->create_links(
+ 'dbh' => $dbh,
+ 'mode' => 'ids',
+ 'from_table' => 'dunning',
+ 'from_ids' => \@link_ids,
+ 'to_table' => 'ar',
+ 'to_id' => $ar_id,
+ );
+
$query =
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, gldate, taxkey, tax_id, chart_link)
VALUES (?, ?, ?, current_date, current_date, 0,
my $h_update_ar = prepare_query($form, $dbh, $q_update_ar);
my $q_insert_dunning =
- qq|INSERT INTO dunning (dunning_id, dunning_config_id, dunning_level, trans_id,
- fee, interest, transdate, duedate)
- VALUES (?, ?,
+ qq|INSERT INTO dunning (id, dunning_id, dunning_config_id, dunning_level, trans_id,
+ fee, interest, transdate, duedate)
+ VALUES (?, ?, ?,
(SELECT dunning_level FROM dunning_config WHERE id = ?),
?,
(SELECT SUM(fee)
$send_email |= $row->{email};
$print_invoice |= $row->{print_invoice};
+ my ($row_id) = selectrow_query($form, $dbh, qq|SELECT nextval('id')|);
my $next_config_id = conv_i($row->{next_dunning_config_id});
my $invoice_id = conv_i($row->{invoice_id});
- @values = ($dunning_id, $next_config_id, $next_config_id,
- $invoice_id, $next_config_id, $invoice_id,
- $next_config_id, $next_config_id);
+ @values = ($row_id, $dunning_id, $next_config_id,
+ $next_config_id, $invoice_id, $next_config_id,
+ $invoice_id, $next_config_id, $next_config_id);
do_statement($form, $h_insert_dunning, $q_insert_dunning, @values);
+
+ RecordLinks->create_links(
+ 'dbh' => $dbh,
+ 'mode' => 'ids',
+ 'from_table' => 'ar',
+ 'from_ids' => $invoice_id,
+ 'to_table' => 'dunning',
+ 'to_id' => $row_id,
+ );
}
# die this transaction, because for this customer only credit notes are
# selected ...
use SL::Presenter::Chart;
use SL::Presenter::CustomerVendor;
use SL::Presenter::DeliveryOrder;
+use SL::Presenter::Dunning;
use SL::Presenter::EscapedText;
use SL::Presenter::Invoice;
use SL::Presenter::GL;
chart => 'SL::Presenter::Chart',
customer_vendor => 'SL::Presenter::CustomerVendor',
delivery_order => 'SL::Presenter::DeliveryOrder',
+ dunning => 'SL::Presenter::Dunning',
escaped_text => 'SL::Presenter::EscapedText',
invoice => 'SL::Presenter::Invoice',
gl => 'SL::Presenter::GL',
--- /dev/null
+package SL::Presenter::Dunning;
+
+use strict;
+
+use SL::Presenter::EscapedText qw(escape is_escaped);
+
+use Exporter qw(import);
+our @EXPORT_OK = qw(dunning);
+
+use Carp;
+
+sub dunning {
+ my ($dunning, $type, %params) = @_;
+
+ $params{display} ||= 'inline';
+
+ croak "Unknown display type '$params{display}'" unless $params{display} =~ m/^(?:inline|table-cell)$/;
+
+ my $invoice = SL::DB::Manager::Invoice->find_by( id => $dunning->trans_id );
+
+ my $text = join '', (
+ $params{no_link} ? '' : '<a href="dn.pl?action=print_dunning&format=pdf&media=screen&dunning_id=' . $dunning->dunning_id . '&language_id=' . $invoice->language_id . '">',
+ escape($dunning->dunning_config->dunning_description),
+ $params{no_link} ? '' : '</a>',
+ );
+
+ is_escaped($text);
+}
+
+1;
$output .= _letter_list( $groups{letters}, %params) if $groups{letters};
$output .= _email_journal_list( $groups{email_journals}, %params) if $groups{email_journals};
+ $output .= _dunning_list( $groups{dunnings}, %params) if $groups{dunnings};
+
$output = SL::Presenter->get->render('presenter/record/grouped_record_list', %params, output => $output);
return $output;
bank_transactions => sub { (ref($_[0]) eq 'SL::DB::BankTransaction') && $_[0]->id },
letters => sub { (ref($_[0]) eq 'SL::DB::Letter') && $_[0]->id },
email_journals => sub { (ref($_[0]) eq 'SL::DB::EmailJournal') && $_[0]->id },
+ dunnings => sub { (ref($_[0]) eq 'SL::DB::Dunning') },
);
my %groups;
%params,
);
}
+sub _dunning_list {
+ my ($list, %params) = @_;
+ return record_list(
+ $list,
+ title => $::locale->text('Dunnings'),
+ type => 'dunning',
+ columns => [
+ [ $::locale->text('Dunning Level'), sub { $_[0]->presenter->dunning(display => 'table-cell') } ],
+ [ $::locale->text('Dunning Date'), 'transdate' ],
+ [ $::locale->text('Dunning Duedate'), 'duedate' ],
+ [ $::locale->text('Total Fees'), 'fee' ],
+ [ $::locale->text('Interest'), 'interest' ],
+ ],
+ %params,
+ );
+}
1;