From 0c09beb40eea289ceebb36aa53b447051fb82857 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Thu, 11 Feb 2016 14:25:29 +0100 Subject: [PATCH] =?utf8?q?Briefe=20mit=20anderen=20Dokumenten=20verkn?= =?utf8?q?=C3=BCpfen=20k=C3=B6nnen?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/Controller/RecordLinks.pm | 26 ++++-- SL/DB/Helper/LinkedRecords.pm | 3 + SL/DB/Letter.pm | 1 + SL/Presenter.pm | 1 + SL/Presenter/Letter.pm | 82 +++++++++++++++++++ SL/Presenter/Record.pm | 21 +++++ js/locale/de.js | 1 + templates/webpages/letter/edit.html | 16 ++++ .../webpages/record_links/add_filter.html | 24 ++++-- templates/webpages/record_links/add_list.html | 10 ++- 10 files changed, 168 insertions(+), 17 deletions(-) create mode 100644 SL/Presenter/Letter.pm diff --git a/SL/Controller/RecordLinks.pm b/SL/Controller/RecordLinks.pm index 08a95bd8b..3d48b0586 100644 --- a/SL/Controller/RecordLinks.pm +++ b/SL/Controller/RecordLinks.pm @@ -10,6 +10,7 @@ use SL::DB::Helper::Mappings; use SL::DB::Order; use SL::DB::DeliveryOrder; use SL::DB::Invoice; +use SL::DB::Letter; use SL::DB::PurchaseInvoice; use SL::DB::RecordLink; use SL::DB::RequirementSpec; @@ -25,14 +26,15 @@ __PACKAGE__->run_before('check_object_params', only => [ qw(ajax_list ajax_delet __PACKAGE__->run_before('check_link_params', only => [ qw( ajax_add_list ajax_add_do) ]); my %link_type_defaults = ( - filter => 'type_filter', - project => 'globalproject', - description => 'transaction_description', - date => 'transdate', + filter => 'type_filter', + project => 'globalproject', + description => 'transaction_description', + description_title => t8('Transaction description'), + date => 'transdate', ); my @link_type_specifics = ( - { title => t8('Requirement spec'), type => 'requirement_spec', model => 'RequirementSpec', number => 'id', project => 'project', description => 'title', date => undef, filter => 'working_copy_filter', }, + { title => t8('Requirement spec'), type => 'requirement_spec', model => 'RequirementSpec', number => 'id', description => 'title', description_title => t8('Title'), date => undef, project => 'project', filter => 'working_copy_filter', }, { title => t8('Sales quotation'), type => 'sales_quotation', model => 'Order', number => 'quonumber', }, { title => t8('Sales Order'), type => 'sales_order', model => 'Order', number => 'ordnumber', }, { title => t8('Sales delivery order'), type => 'sales_delivery_order', model => 'DeliveryOrder', number => 'donumber', }, @@ -41,6 +43,7 @@ my @link_type_specifics = ( { title => t8('Purchase Order'), type => 'purchase_order', model => 'Order', number => 'ordnumber', }, { title => t8('Purchase delivery order'), type => 'purchase_delivery_order', model => 'DeliveryOrder', number => 'donumber', }, { title => t8('Purchase Invoice'), type => 'purchase_invoice', model => 'PurchaseInvoice', number => 'invnumber', }, + { title => t8('Letter'), type => 'letter', model => 'Letter', number => 'letternumber', description => 'subject', description_title => t8('Subject'), date => 'date', project => undef }, ); my @link_types = map { +{ %link_type_defaults, %{ $_ } } } @link_type_specifics; @@ -114,18 +117,22 @@ sub action_ajax_add_list { my ($self) = @_; my $manager = 'SL::DB::Manager::' . $self->link_type_desc->{model}; - my $vc = $self->link_type =~ m/sales_|^invoice|requirement_spec$/ ? 'customer' : 'vendor'; + my $vc = $self->link_type =~ m/sales_|^invoice|requirement_spec|letter/ ? 'customer' : 'vendor'; my $project = $self->link_type_desc->{project}; + my $project_id = "${project}_id"; my $description = $self->link_type_desc->{description}; my $filter = $self->link_type_desc->{filter}; - my @where = $filter ? $manager->$filter($self->link_type) : (); + my @where = $filter && $manager->can($filter) ? $manager->$filter($self->link_type) : (); push @where, ("${vc}.${vc}number" => { ilike => '%' . $::form->{vc_number} . '%' }) if $::form->{vc_number}; push @where, ("${vc}.name" => { ilike => '%' . $::form->{vc_name} . '%' }) if $::form->{vc_name}; push @where, ($description => { ilike => '%' . $::form->{transaction_description} . '%' }) if $::form->{transaction_description}; - push @where, ("${project}_id" => $::form->{globalproject_id}) if $::form->{globalproject_id}; + push @where, ($project_id => $::form->{globalproject_id}) if $::form->{globalproject_id} && $manager->can($project_id); - my $objects = $manager->get_all_sorted(where => \@where, with_objects => [ $vc, $project ]); + my @with_objects = ($vc); + push @with_objects, $project if $manager->can($project_id); + + my $objects = $manager->get_all_sorted(where => \@where, with_objects => \@with_objects); my $output = $self->render( 'record_links/add_list', { output => 0 }, @@ -133,6 +140,7 @@ sub action_ajax_add_list { vc => $vc, number_column => $self->link_type_desc->{number}, description_column => $description, + description_title => $self->link_type_desc->{description_title}, project_column => $project, date_column => $self->link_type_desc->{date}, ); diff --git a/SL/DB/Helper/LinkedRecords.pm b/SL/DB/Helper/LinkedRecords.pm index 115198124..c7de25b74 100644 --- a/SL/DB/Helper/LinkedRecords.pm +++ b/SL/DB/Helper/LinkedRecords.pm @@ -207,6 +207,7 @@ sub sort_linked_records { 'SL::DB::Invoice' => sub { $_[0]->invnumber }, 'SL::DB::PurchaseInvoice' => sub { $_[0]->invnumber }, 'SL::DB::RequirementSpec' => sub { $_[0]->id }, + 'SL::DB::Letter' => sub { $_[0]->letternumber }, UNKNOWN => '9999999999999999', ); my $number_xtor = sub { @@ -234,6 +235,8 @@ sub sort_linked_records { purchase_order => 130, purchase_delivery_order => 140, 'SL::DB::PurchaseInvoice' => 150, + 'SL::DB::PurchaseInvoice' => 150, + 'SL::DB::Letter' => 200, UNKNOWN => 999, ); my $score_xtor = sub { diff --git a/SL/DB/Letter.pm b/SL/DB/Letter.pm index 02b54cde8..63a00108b 100644 --- a/SL/DB/Letter.pm +++ b/SL/DB/Letter.pm @@ -3,6 +3,7 @@ package SL::DB::Letter; use strict; use SL::DB::Helper::AttrHTML; +use SL::DB::Helper::LinkedRecords; use SL::DB::MetaSetup::Letter; use SL::DB::Manager::Letter; diff --git a/SL/Presenter.pm b/SL/Presenter.pm index deeed1eb4..5067b7717 100644 --- a/SL/Presenter.pm +++ b/SL/Presenter.pm @@ -13,6 +13,7 @@ use SL::Presenter::DeliveryOrder; use SL::Presenter::EscapedText; use SL::Presenter::Invoice; use SL::Presenter::GL; +use SL::Presenter::Letter; use SL::Presenter::Order; use SL::Presenter::Part; use SL::Presenter::Project; diff --git a/SL/Presenter/Letter.pm b/SL/Presenter/Letter.pm new file mode 100644 index 000000000..28de4b2dd --- /dev/null +++ b/SL/Presenter/Letter.pm @@ -0,0 +1,82 @@ +package SL::Presenter::Letter; + +use strict; + +use parent qw(Exporter); + +use Exporter qw(import); +our @EXPORT = qw(letter); + +use Carp; + +sub letter { + my ($self, $letter, %params) = @_; + + $params{display} ||= 'inline'; + + croak "Unknown display type '$params{display}'" unless $params{display} =~ m/^(?:inline|table-cell)$/; + + my $text = join '', ( + $params{no_link} ? '' : '', + $self->escape($letter->letternumber), + $params{no_link} ? '' : '', + ); + + return $self->escaped_text($text); +} + +1; + +__END__ + +=pod + +=encoding utf8 + +=head1 NAME + +SL::Presenter::Letter - Presenter module for letter objects + +=head1 SYNOPSIS + + my $letter = SL::DB::Manager::Letter->get_first(where => [ … ]); + my $html = SL::Presenter->get->letter($letter, display => 'inline'); + +=head1 FUNCTIONS + +=over 4 + +=item C + +Returns a rendered version (actually an instance of +L) of the letter object C<$object> +. + +C<%params> can include: + +=over 2 + +=item * display + +Either C (the default) or C. At the moment both +representations are identical and produce the invoice number linked +to the corresponding 'edit' action. + +=item * no_link + +If falsish (the default) then the invoice number will be linked to the +"edit invoice" dialog from the general ledger menu. + +=back + +=back + +=head1 BUGS + +Nothing here yet. + +=head1 AUTHOR + +Moritz Bunkus Em.bunkus@linet-services.deE + +=cut diff --git a/SL/Presenter/Record.pm b/SL/Presenter/Record.pm index b395e822a..40f220454 100644 --- a/SL/Presenter/Record.pm +++ b/SL/Presenter/Record.pm @@ -60,6 +60,8 @@ sub grouped_record_list { $output .= _sepa_collection_list( $self, $groups{sepa_collections}, %params) if $groups{sepa_collections}; $output .= _sepa_transfer_list( $self, $groups{sepa_transfers}, %params) if $groups{sepa_transfers}; + $output .= _letter_list( $self, $groups{letters}, %params) if $groups{letters}; + $output = $self->render('presenter/record/grouped_record_list', %params, output => $output); return $output; @@ -180,6 +182,7 @@ sub _group_records { sepa_transfers => sub { (ref($_[0]) eq 'SL::DB::SepaExportItem') && $_[0]->ap_id }, gl_transactions => sub { (ref($_[0]) eq 'SL::DB::GLTransaction') }, bank_transactions => sub { (ref($_[0]) eq 'SL::DB::BankTransaction') && $_[0]->id }, + letters => sub { (ref($_[0]) eq 'SL::DB::Letter') && $_[0]->id }, ); my %groups; @@ -490,6 +493,24 @@ sub _sepa_collection_list { _sepa_export_list($self, $list, %params, type => 'sepa_collection'); } +sub _letter_list { + my ($self, $list, %params) = @_; + + return $self->record_list( + $list, + title => $::locale->text('Letters'), + type => 'letter', + columns => [ + [ $::locale->text('Date'), 'date' ], + [ $::locale->text('Letternumber'), sub { $self->letter($_[0], display => 'table-cell') } ], + [ $::locale->text('Customer'), 'customer' ], + [ $::locale->text('Reference'), 'reference' ], + [ $::locale->text('Subject'), 'subject' ], + ], + %params, + ); +} + 1; __END__ diff --git a/js/locale/de.js b/js/locale/de.js index 7c95e2220..4aa60e136 100644 --- a/js/locale/de.js +++ b/js/locale/de.js @@ -65,6 +65,7 @@ namespace("kivi").setupLocale({ "Save and keep open":"Speichern und geöffnet lassen", "Section/Function block actions":"Abschnitts-/Funktionsblockaktionen", "Select template to paste":"Einzufügende Vorlage auswählen", +"Subject":"Betreff", "Text block actions":"Textblockaktionen", "Text block picture actions":"Aktionen für Textblockbilder", "The IBAN is missing.":"Die IBAN fehlt.", diff --git a/templates/webpages/letter/edit.html b/templates/webpages/letter/edit.html index a43f310af..31f6f1f3e 100644 --- a/templates/webpages/letter/edit.html +++ b/templates/webpages/letter/edit.html @@ -12,6 +12,16 @@ [%- PROCESS 'common/flash.html' %] +
+ + +
+
@@ -125,6 +135,12 @@
+
+
+ [%- LxERP.t8("Loading...") %] +
+
+ diff --git a/templates/webpages/record_links/add_filter.html b/templates/webpages/record_links/add_filter.html index a455840de..b2ee69155 100644 --- a/templates/webpages/record_links/add_filter.html +++ b/templates/webpages/record_links/add_filter.html @@ -31,7 +31,7 @@ [% L.input_tag('vc_name', is_sales ? SELF.object.customer.name : SELF.object.vendor.name, style=style) %] - + [%- LxERP.t8("Project") %]: [% L.select_tag('globalproject_id', PROJECTS, default=SELF.object.globalproject_id, with_empty=1, style=style) %] @@ -59,10 +59,8 @@ diff --git a/templates/webpages/record_links/add_list.html b/templates/webpages/record_links/add_list.html index edbadb248..6ac59e18f 100644 --- a/templates/webpages/record_links/add_list.html +++ b/templates/webpages/record_links/add_list.html @@ -10,8 +10,10 @@ [% IF date_column %] [%- LxERP.t8("Date") %] [% END %] - [% IF SELF.link_type == 'requirement_spec' %][%- LxERP.t8("Title") %][% ELSE %][%- LxERP.t8("Transaction description") %][% END %] - [%- LxERP.t8("Project") %] + [% HTML.escape(description_title) %] + [% IF project_column %] + [%- LxERP.t8("Project") %] + [% END %] [%- FOREACH object = OBJECTS %] @@ -23,7 +25,9 @@ [%- HTML.escape(object.$date_column.to_kivitendo) %] [% END %] [%- HTML.escape(object.$description_column) %] - [%- P.project(object.$project_column, no_link=1) %] + [% IF project_column %] + [%- P.project(object.$project_column, no_link=1) %] + [% END %] [%- END %] -- 2.20.1