sub grouped_record_list {
my ($self, $list, %params) = @_;
- %params = map { exists $params{$_} ? ($_ => $params{$_}) : () } qw(selectable with_columns);
+ %params = map { exists $params{$_} ? ($_ => $params{$_}) : () } qw(edit_record_links with_columns object_id object_model);
- my %groups = _group_records($list);
+ my %groups = _sort_grouped_lists(_group_records($list));
my $output = '';
$output .= _sales_quotation_list( $self, $groups{sales_quotations}, %params) if $groups{sales_quotations};
$output .= _purchase_invoice_list( $self, $groups{purchase_invoices}, %params) if $groups{purchase_invoices};
$output .= _ar_transaction_list( $self, $groups{ar_transactions}, %params) if $groups{ar_transactions};
- return $output || $self->empty_record_list;
+ $output = $self->render('presenter/record/grouped_record_list', %params, output => $output);
+
+ return $output;
}
sub empty_record_list {
- my ($self) = @_;
- return $self->render('presenter/record/empty_record_list');
+ my ($self, %params) = @_;
+ return $self->grouped_record_list([], %params);
}
sub record_list {
push @row, \%cell;
}
- push @data, \@row;
+ push @data, { columns => \@row, record_link => $obj->{_record_link} };
}
my @header =
map +{ value => $columns[$_]->{title},
- alignment => $data[0]->[$_]->{alignment},
+ alignment => $data[0]->{columns}->[$_]->{alignment},
}, (0..scalar(@columns) - 1);
return $self->render(
return %groups;
}
+sub _sort_grouped_lists {
+ my (%groups) = @_;
+
+ $groups{$_} = [ sort { $a->date <=> $b->date } @{ $groups{$_} } ] for keys %groups;
+
+ return %groups;
+}
+
sub _sales_quotation_list {
my ($self, $list, %params) = @_;
return $self->record_list(
$list,
title => $::locale->text('Sales Quotations'),
+ type => 'sales_quotation',
columns => [
[ $::locale->text('Quotation Date'), 'transdate' ],
[ $::locale->text('Quotation Number'), sub { $self->sales_quotation($_[0], display => 'table-cell') } ],
return $self->record_list(
$list,
title => $::locale->text('Request Quotations'),
+ type => 'request_quotation',
columns => [
[ $::locale->text('Quotation Date'), 'transdate' ],
- [ $::locale->text('Quotation Number'), sub { $self->sales_quotation($_[0], display => 'table-cell') } ],
+ [ $::locale->text('Quotation Number'), sub { $self->request_quotation($_[0], display => 'table-cell') } ],
[ $::locale->text('Vendor'), 'vendor' ],
[ $::locale->text('Net amount'), 'netamount' ],
[ $::locale->text('Transaction description'), 'transaction_description' ],
return $self->record_list(
$list,
title => $::locale->text('Sales Orders'),
+ type => 'sales_order',
columns => [
[ $::locale->text('Order Date'), 'transdate' ],
[ $::locale->text('Order Number'), sub { $self->sales_order($_[0], display => 'table-cell') } ],
return $self->record_list(
$list,
title => $::locale->text('Purchase Orders'),
+ type => 'purchase_order',
columns => [
[ $::locale->text('Order Date'), 'transdate' ],
- [ $::locale->text('Order Number'), sub { $self->sales_order($_[0], display => 'table-cell') } ],
+ [ $::locale->text('Order Number'), sub { $self->purchase_order($_[0], display => 'table-cell') } ],
[ $::locale->text('Request for Quotation'), 'quonumber' ],
[ $::locale->text('Vendor'), 'vendor' ],
[ $::locale->text('Net amount'), 'netamount' ],
return $self->record_list(
$list,
title => $::locale->text('Sales Delivery Orders'),
+ type => 'sales_delivery_order',
columns => [
[ $::locale->text('Delivery Order Date'), 'transdate' ],
[ $::locale->text('Delivery Order Number'), sub { $self->sales_delivery_order($_[0], display => 'table-cell') } ],
return $self->record_list(
$list,
title => $::locale->text('Purchase Delivery Orders'),
+ type => 'purchase_delivery_order',
columns => [
[ $::locale->text('Delivery Order Date'), 'transdate' ],
- [ $::locale->text('Delivery Order Number'), sub { $self->sales_delivery_order($_[0], display => 'table-cell') } ],
+ [ $::locale->text('Delivery Order Number'), sub { $self->purchase_delivery_order($_[0], display => 'table-cell') } ],
[ $::locale->text('Order Number'), 'ordnumber' ],
[ $::locale->text('Vendor'), 'vendor' ],
[ $::locale->text('Transaction description'), 'transaction_description' ],
return $self->record_list(
$list,
title => $::locale->text('Sales Invoices'),
+ type => 'sales_invoice',
columns => [
[ $::locale->text('Invoice Date'), 'transdate' ],
[ $::locale->text('Invoice Number'), sub { $self->sales_invoice($_[0], display => 'table-cell') } ],
return $self->record_list(
$list,
title => $::locale->text('Purchase Invoices'),
+ type => 'purchase_invoice',
columns => [
[ $::locale->text('Invoice Date'), 'transdate' ],
- [ $::locale->text('Invoice Number'), sub { $self->sales_invoice($_[0], display => 'table-cell') } ],
+ [ $::locale->text('Invoice Number'), sub { $self->purchase_invoice($_[0], display => 'table-cell') } ],
[ $::locale->text('Request for Quotation Number'), 'quonumber' ],
[ $::locale->text('Order Number'), 'ordnumber' ],
[ $::locale->text('Vendor'), 'vendor' ],
return $self->record_list(
$list,
title => $::locale->text('AR Transactions'),
+ type => 'ar_transaction',
columns => [
[ $::locale->text('Invoice Date'), 'transdate' ],
[ $::locale->text('Invoice Number'), sub { $self->ar_transaction($_[0], display => 'table-cell') } ],
return $self->record_list(
$list,
title => $::locale->text('AP Transactions'),
+ type => 'ap_transaction',
columns => [
[ $::locale->text('Invoice Date'), 'transdate' ],
- [ $::locale->text('Invoice Number'), sub { $self->ar_transaction($_[0 ], display => 'table-cell') } ],
+ [ $::locale->text('Invoice Number'), sub { $self->ap_transaction($_[0 ], display => 'table-cell') } ],
[ $::locale->text('Vendor'), 'vendor' ],
[ $::locale->text('Net amount'), 'netamount' ],
[ $::locale->text('Paid'), 'paid' ],
Objects of unknown types are skipped.
+Parameters are passed to C<record_list> include C<with_objects> and
+C<edit_record_links>.
+
=item C<record_list $list, %params>
Returns a rendered version (actually an instance of
expected. The corresponding hash keys are C<title>, C<data> and
C<link>.
+=item C<with_columns>
+
+Can be set by the caller to indicate additional columns to
+list. Currently supported:
+
+=over 2
+
+=item C<record_link_destination>
+
+The record link destination. Requires that the records to list have
+been retrieved via the L<SL::DB::Helper::LinkedRecords> helper.
+
+=back
+
+=item C<edit_record_links>
+
+If trueish additional controls will be rendered that allow the user to
+remove and add record links. Requires that the records to list have
+been retrieved via the L<SL::DB::Helper::LinkedRecords> helper.
+
=back
=back