Revision 2551fdb3
Von Tamino Steinert vor 11 Tagen hinzugefügt
- ID 2551fdb32d0c96bde94ab817813abd625ed05632
- Vorgänger 746ed36d
SL/Controller/EmailJournal.pm | ||
---|---|---|
4 | 4 |
|
5 | 5 |
use parent qw(SL::Controller::Base); |
6 | 6 |
|
7 |
use SL::ReportGenerator; |
|
8 |
use SL::Controller::Helper::ReportGenerator; |
|
7 | 9 |
use SL::ZUGFeRD; |
8 | 10 |
use SL::Controller::ZUGFeRD; |
9 | 11 |
use SL::Controller::Helper::GetModels; |
... | ... | |
11 | 13 |
use SL::DB::EmailJournal; |
12 | 14 |
use SL::DB::EmailJournalAttachment; |
13 | 15 |
use SL::Presenter::EmailJournal; |
16 |
use SL::Presenter::Filter::EmailJournal; |
|
14 | 17 |
use SL::Presenter::Record qw(grouped_record_list); |
15 | 18 |
use SL::Presenter::Tag qw(html_tag div_tag button_tag); |
16 | 19 |
use SL::Helper::Flash; |
... | ... | |
222 | 225 |
my ($self) = @_; |
223 | 226 |
|
224 | 227 |
$::auth->assert('email_journal'); |
225 |
# default filter |
|
226 |
$::form->{filter} ||= {"obsolete:eq_ignore_empty" => 0}; |
|
227 | 228 |
|
228 | 229 |
if ( $::instance_conf->get_email_journal == 0 ) { |
229 |
flash('info', $::locale->text('Storing the emails in the journal is currently disabled in the client configuration.'));
|
|
230 |
flash('info', t8('Storing the emails in the journal is currently disabled in the client configuration.'));
|
|
230 | 231 |
} |
232 |
|
|
233 |
$::form->{filter} ||= { |
|
234 |
'obsolete:eq_ignore_empty' => 0, |
|
235 |
}; |
|
236 |
|
|
231 | 237 |
$self->setup_list_action_bar; |
232 |
my @record_types_with_info = $self->get_record_types_with_info(); |
|
233 |
my %record_types_to_text = $self->get_record_types_to_text(); |
|
234 |
$self->render('email_journal/list', |
|
235 |
title => $::locale->text('Email journal'), |
|
236 |
ENTRIES => $self->models->get, |
|
237 |
MODELS => $self->models, |
|
238 |
RECORD_TYPES_WITH_INFO => \@record_types_with_info, |
|
239 |
RECORD_TYPES_TO_TEXT => \%record_types_to_text, |
|
240 |
); |
|
238 |
my $report = $self->prepare_report; |
|
239 |
$self->report_generator_list_objects( |
|
240 |
report => $report, |
|
241 |
objects => $self->models->get, |
|
242 |
); |
|
241 | 243 |
} |
242 | 244 |
|
243 | 245 |
sub action_show { |
... | ... | |
778 | 780 |
return $customer_vendor; |
779 | 781 |
} |
780 | 782 |
|
783 |
sub prepare_report { |
|
784 |
my ($self) = @_; |
|
785 |
|
|
786 |
my %record_types_to_text = $self->get_record_types_to_text(); |
|
787 |
my @record_types_with_info = $self->get_record_types_with_info(); |
|
788 |
|
|
789 |
my $report = SL::ReportGenerator->new(\%::myconfig, $::form); |
|
790 |
|
|
791 |
my $callback = $self->models->get_callback; |
|
792 |
|
|
793 |
my @columns_order = qw( |
|
794 |
id |
|
795 |
sender |
|
796 |
from |
|
797 |
recipients |
|
798 |
subject |
|
799 |
sent_on |
|
800 |
attachment_names |
|
801 |
has_unprocessed_attachments |
|
802 |
unprocessed_attachment_names |
|
803 |
status |
|
804 |
extended_status |
|
805 |
record_type |
|
806 |
linked_to |
|
807 |
obsolete |
|
808 |
); |
|
809 |
|
|
810 |
my @default_columns = qw( |
|
811 |
from |
|
812 |
recipients |
|
813 |
subject |
|
814 |
sent_on |
|
815 |
); |
|
816 |
|
|
817 |
my %column_defs = ( |
|
818 |
id => { |
|
819 |
obj_link => sub {$self->url_for( |
|
820 |
action => 'show', id => $_[0]->id, callback => $callback |
|
821 |
)}, |
|
822 |
sub => sub { $_[0]->id }, |
|
823 |
}, |
|
824 |
sender => { |
|
825 |
sub => sub { $_[0]->sender ? $_[0]->sender->name : '' }, |
|
826 |
}, |
|
827 |
from => { |
|
828 |
obj_link => sub {$self->url_for( |
|
829 |
action => 'show', id => $_[0]->id, callback => $callback |
|
830 |
)}, |
|
831 |
sub => sub { $_[0]->from }, |
|
832 |
}, |
|
833 |
recipients => { |
|
834 |
obj_link => sub {$self->url_for( |
|
835 |
action => 'show', id => $_[0]->id, callback => $callback |
|
836 |
)}, |
|
837 |
sub => sub { $_[0]->recipients }, |
|
838 |
}, |
|
839 |
subject => { |
|
840 |
obj_link => sub {$self->url_for( |
|
841 |
action => 'show', id => $_[0]->id, callback => $callback |
|
842 |
)}, |
|
843 |
sub => sub { $_[0]->subject }, |
|
844 |
}, |
|
845 |
sent_on => { |
|
846 |
obj_link => sub {$self->url_for( |
|
847 |
action => 'show', id => $_[0]->id, callback => $callback |
|
848 |
)}, |
|
849 |
sub => sub { $_[0]->sent_on->to_kivitendo(precision => 'minute') }, |
|
850 |
}, |
|
851 |
attachment_names => { |
|
852 |
sub => sub {join(', ', |
|
853 |
map {$_->name} |
|
854 |
sort {$a->position <=> $b->position} |
|
855 |
@{$_[0]->attachments} |
|
856 |
)}, |
|
857 |
}, |
|
858 |
has_unprocessed_attachments => { |
|
859 |
sub => sub { $_[0]->has_unprocessed_attachments } |
|
860 |
}, |
|
861 |
unprocessed_attachment_names => { |
|
862 |
sub => sub {join(', ', |
|
863 |
map {$_->name} |
|
864 |
sort {$a->position <=> $b->position} |
|
865 |
grep {$_->processed == 0} |
|
866 |
@{$_[0]->attachments} |
|
867 |
)}, |
|
868 |
}, |
|
869 |
status => { |
|
870 |
sub => sub { SL::Presenter::EmailJournal::entry_status($_[0]) }, |
|
871 |
}, |
|
872 |
extended_status => { |
|
873 |
sub => sub { $_[0]->extended_status }, |
|
874 |
}, |
|
875 |
record_type => { |
|
876 |
sub => sub { $record_types_to_text{$_[0]->record_type} }, |
|
877 |
}, |
|
878 |
linked_to => { |
|
879 |
raw_data => sub { |
|
880 |
SL::Presenter::Record::simple_grouped_record_list($_[0]->linked_records) |
|
881 |
} |
|
882 |
}, |
|
883 |
obsolete => { |
|
884 |
sub => sub { $_[0]->obsolete_as_bool_yn } |
|
885 |
}, |
|
886 |
); |
|
887 |
$column_defs{$_}->{text} ||= |
|
888 |
t8( $self->models->get_sort_spec->{$_}->{title} || $_ ) |
|
889 |
for keys %column_defs; |
|
890 |
|
|
891 |
# make all sortable |
|
892 |
my @sortable = keys %column_defs; |
|
893 |
|
|
894 |
unless ($::form->{active_in_report}) { |
|
895 |
$::form->{active_in_report}->{$_} = 1 foreach @default_columns; |
|
896 |
} |
|
897 |
|
|
898 |
$column_defs{$_}->{visible} = $::form->{active_in_report}->{"$_"} || 0 |
|
899 |
foreach keys %column_defs; |
|
900 |
|
|
901 |
my $filter_html = SL::Presenter::Filter::EmailJournal::filter( |
|
902 |
$::form->{filter}, |
|
903 |
active_in_report => $::form->{active_in_report}, |
|
904 |
record_types_with_info => \@record_types_with_info, |
|
905 |
); |
|
906 |
|
|
907 |
$self->models->disable_plugin('paginated') |
|
908 |
if $report->{options}{output_format} =~ /^(pdf|csv)$/i; |
|
909 |
$self->models->add_additional_url_params( |
|
910 |
active_in_report => $::form->{active_in_report} |
|
911 |
); |
|
912 |
$self->models->finalize; # for filter laundering |
|
913 |
|
|
914 |
$report->set_options( |
|
915 |
std_column_visibility => 1, |
|
916 |
controller_class => 'EmailJournal', |
|
917 |
output_format => 'HTML', |
|
918 |
raw_top_info_text => $self->render( |
|
919 |
'email_journal/_report_top', |
|
920 |
{ output => 0 }, |
|
921 |
FILTER_HTML => $filter_html, |
|
922 |
), |
|
923 |
raw_bottom_info_text => $self->render( |
|
924 |
'email_journal/_report_bottom', |
|
925 |
{ output => 0 }, |
|
926 |
models => $self->models |
|
927 |
), |
|
928 |
title => t8('Email journal'), |
|
929 |
allow_pdf_export => 1, |
|
930 |
allow_csv_export => 1, |
|
931 |
); |
|
932 |
$report->set_columns(%column_defs); |
|
933 |
$report->set_column_order(@columns_order); |
|
934 |
$report->set_export_options('list', qw(filter active_in_report)); |
|
935 |
$report->set_options_from_form; |
|
936 |
|
|
937 |
$self->models->set_report_generator_sort_options( |
|
938 |
report => $report, |
|
939 |
sortable_columns => \@sortable |
|
940 |
); |
|
941 |
|
|
942 |
return $report; |
|
943 |
} |
|
944 |
|
|
781 | 945 |
sub add_js { |
782 | 946 |
$::request->{layout}->use_javascript("${_}.js") for qw( |
783 | 947 |
kivi.EmailJournal |
... | ... | |
797 | 961 |
query => \@where, |
798 | 962 |
with_objects => [ 'sender' ], |
799 | 963 |
sorted => { |
964 |
_default => { |
|
965 |
by => 'sent_on', |
|
966 |
dir => 0, |
|
967 |
}, |
|
800 | 968 |
sender => t8('Sender'), |
801 | 969 |
from => t8('From'), |
802 | 970 |
recipients => t8('Recipients'), |
803 | 971 |
subject => t8('Subject'), |
804 |
attachments => t8('Attachments'), |
|
972 |
attachment_names => t8('Attachments'), |
|
973 |
has_unprocessed_attachments => t8('Has unprocessed attachments'), |
|
974 |
unprocessed_attachment_names => t8('Unprocessed Attachments'), |
|
805 | 975 |
sent_on => t8('Sent on'), |
806 | 976 |
status => t8('Status'), |
807 | 977 |
extended_status => t8('Extended status'), |
808 | 978 |
record_type => t8('Record Type'), |
809 | 979 |
obsolete => t8('Obsolete'), |
810 | 980 |
linked_to => t8('Linked to'), |
811 |
has_unprocessed_attachments => t8('Has unprocessed attachments'), |
|
812 | 981 |
}, |
813 | 982 |
); |
814 | 983 |
} |
Auch abrufbar als: Unified diff
EmailJournal: Komplexer Bericht mit komplexen Filter