From f6ed86efee2a0a38b6e88e98fd9d4403fa64ff5e Mon Sep 17 00:00:00 2001 From: "G. Richardson" Date: Fri, 4 Apr 2014 13:09:26 +0200 Subject: [PATCH] FiBu Schellsuche in Headerzeile MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit neues Ajax Autocompletefeld im Header für Benutzer mit FiBu-Rechten, welches Rechnungsnummern und Kunden-/Lieferantennamen durchsucht. Durch die Auswahl im Dropdown gelangt man direkt zu dem Beleg. --- SL/Controller/GL.pm | 107 +++++++++++++++++++++++++++ SL/DB/GLTransaction.pm | 9 +++ SL/DB/Invoice.pm | 12 +++ SL/DB/PurchaseInvoice.pm | 11 +++ doc/changelog | 3 + js/glquicksearch.js | 14 ++++ locale/de/all | 2 + templates/webpages/menu/header.html | 6 ++ templates/webpages/menu/menunew.html | 7 +- templates/webpages/menu/menuv3.html | 6 ++ 10 files changed, 176 insertions(+), 1 deletion(-) create mode 100644 SL/Controller/GL.pm create mode 100644 js/glquicksearch.js diff --git a/SL/Controller/GL.pm b/SL/Controller/GL.pm new file mode 100644 index 000000000..ce3799de2 --- /dev/null +++ b/SL/Controller/GL.pm @@ -0,0 +1,107 @@ +package SL::Controller::GL; + +use strict; +use parent qw(SL::Controller::Base); + +use SL::DB::GLTransaction; +use SL::DB::Invoice; +use SL::DB::PurchaseInvoice; +use SL::DB::AccTransaction; +use SL::Locale::String qw(t8); + +__PACKAGE__->run_before('check_auth'); + +sub action_quicksearch { + + my ($self, %params) = @_; + + my $limit = $::form->{limit} || 40; # max number of results per type (AR/AP/GL) + my $term = $::form->{term} || ''; + + my $descriptionquery = { ilike => '%' . $term . '%' }; + my $referencequery = { ilike => '%' . $term . '%' }; + my $apinvnumberquery = { ilike => '%' . $term . '%' }; + my $namequery = { ilike => '%' . $term . '%' }; + my $arinvnumberquery = { ilike => '%' . $term }; + # ar match is more restrictive. Left fuzzy beginning so it also matches "Storno zu $INVNUMBER" + # and numbers like 000123 if you only enter 123. + # When used in quicksearch short numbers like 1 or 11 won't match because of the + # ajax autocomplete minlimit of 3 characters + + my (@glfilter, @arfilter, @apfilter); + + push( @glfilter, (or => [ description => $descriptionquery, reference => $referencequery ] ) ); + push( @arfilter, (or => [ invnumber => $arinvnumberquery, name => $namequery ] ) ); + push( @apfilter, (or => [ invnumber => $apinvnumberquery, name => $namequery ] ) ); + + my $gls = SL::DB::Manager::GLTransaction->get_all( query => [ @glfilter ], limit => $limit, sort_by => 'transdate DESC'); + my $ars = SL::DB::Manager::Invoice->get_all( query => [ @arfilter ], limit => $limit, sort_by => 'transdate DESC', with_objects => [ 'customer' ]); + my $aps = SL::DB::Manager::PurchaseInvoice->get_all(query => [ @apfilter ], limit => $limit, sort_by => 'transdate DESC', with_objects => [ 'vendor' ]); + + # calculate an amount to be displayed for gl transaction + foreach my $gl ( @$gls ) { + my $amount = 0; + my $acc_trans_lines = SL::DB::Manager::AccTransaction->get_all(query => [ trans_id => $gl->id ]); + foreach my $acc_trans_line ( @$acc_trans_lines ) { + $amount += $acc_trans_line->amount if $acc_trans_line->amount > 0 ; + }; + $gl->{'amount'} = $amount; + }; + + my $gldata = [ + map( + { + { + transdate => DateTime->from_object(object => $_->transdate)->ymd(), + label => $_->abbreviation. ": " . $_->description . " " . $_->reference . " " . $::form->format_amount(\%::myconfig, $_->{'amount'},2). " (" . $_->transdate->to_lxoffice . ")" , + value => '', + url => 'gl.pl?action=edit&id=' . $_->id, + } + } + @{$gls} + ), + ]; + + my $ardata = [ + map( + { + { + transdate => DateTime->from_object(object => $_->transdate)->ymd(), + label => $_->abbreviation . ": " . $_->invnumber . " " . $_->customer->name . " " . $::form->format_amount(\%::myconfig, $_->amount,2) . " (" . $_->transdate->to_lxoffice . ")" , + value => "", + url => ($_->invoice ? "is" : "ar" ) . '.pl?action=edit&id=' . $_->id, + } + } + @{$ars} + ), + ]; + + my $apdata = [ + map( + { + { + transdate => DateTime->from_object(object => $_->transdate)->ymd(), + label => $_->abbreviation . ": " . $_->invnumber . " " . $_->vendor->name . " " . $::form->format_amount(\%::myconfig, $_->amount,2) . " (" . $_->transdate->to_lxoffice . ")" , + value => "", + url => ($_->invoice ? "ir" : "ap" ) . '.pl?action=edit&id=' . $_->id, + } + } + @{$aps} + ), + ]; + + my $data; + push(@{$data},@{$gldata}); + push(@{$data},@{$ardata}); + push(@{$data},@{$apdata}); + + @$data = reverse sort { $a->{'transdate_sort'} cmp $b->{'transdate_sort'} } @$data; + + $self->render(\SL::JSON::to_json($data), { layout => 0, type => 'json' }); +} + +sub check_auth { + $::auth->assert('general_ledger'); +} + +1; diff --git a/SL/DB/GLTransaction.pm b/SL/DB/GLTransaction.pm index 352de036d..078e2b981 100644 --- a/SL/DB/GLTransaction.pm +++ b/SL/DB/GLTransaction.pm @@ -9,4 +9,13 @@ __PACKAGE__->meta->initialize; # Creates get_all, get_all_count, get_all_iterator, delete_all and update_all. __PACKAGE__->meta->make_manager_class; +sub abbreviation { + my $self = shift; + + my $abbreviation = $::locale->text('GL Transaction (abbreviation)'); + $abbreviation .= "(" . $::locale->text('Storno (one letter abbreviation)') . ")" if $self->storno; + return $abbreviation; + +} + 1; diff --git a/SL/DB/Invoice.pm b/SL/DB/Invoice.pm index f0f3d0a1d..d734003a1 100644 --- a/SL/DB/Invoice.pm +++ b/SL/DB/Invoice.pm @@ -17,6 +17,7 @@ use SL::DB::Helper::LinkedRecords; use SL::DB::Helper::PriceTaxCalculator; use SL::DB::Helper::PriceUpdater; use SL::DB::Helper::TransNumberGenerator; +use SL::Locale::String qw(t8); __PACKAGE__->meta->add_relationship( invoiceitems => { @@ -317,6 +318,17 @@ sub displayable_state { return $self->closed ? $::locale->text('closed') : $::locale->text('open'); } +sub abbreviation { + my $self = shift; + + return t8('AR Transaction (abbreviation)') if !$self->invoice; + return t8('Credit note (one letter abbreviation)') if $self->type eq 'credit_note' && $self->amount < 0 && !$self->storno; + return t8('Invoice (one letter abbreviation)') . "(" . t8('Storno (one letter abbreviation)') . ")" if $self->type ne 'credit_note' && $self->amount < 0 && $self->storno; + return t8('Credit note (one letter abbreviation)') . "(" . t8('Storno (one letter abbreviation)') . ")" if $self->type eq 'credit_note' && $self->amount > 0 && $self->storno; + return t8('Invoice (one letter abbreviation)'); + +} + sub date { goto &transdate; } diff --git a/SL/DB/PurchaseInvoice.pm b/SL/DB/PurchaseInvoice.pm index 3245e4b91..b3d3500ee 100644 --- a/SL/DB/PurchaseInvoice.pm +++ b/SL/DB/PurchaseInvoice.pm @@ -7,6 +7,8 @@ use Carp; use SL::DB::MetaSetup::PurchaseInvoice; use SL::DB::Manager::PurchaseInvoice; use SL::DB::Helper::LinkedRecords; +use SL::Locale::String qw(t8); + # The calculator hasn't been adjusted for purchase invoices yet. # use SL::DB::Helper::PriceTaxCalculator; @@ -52,4 +54,13 @@ sub date { goto &transdate; } +sub abbreviation { + my $self = shift; + + return t8('AP Transaction (abbreviation)') if !$self->invoice && !$self->storno; + return t8('AP Transaction (abbreviation)') . '(' . t8('Storno (one letter abbreviation)') . ')' if !$self->invoice && $self->storno; + return t8('Invoice (one letter abbreviation)'). '(' . t8('Storno (one letter abbreviation)') . ')' if $self->storno; + return t8('Invoice (one letter abbreviation)'); + +} 1; diff --git a/doc/changelog b/doc/changelog index a4377a56e..e5809f5ad 100644 --- a/doc/changelog +++ b/doc/changelog @@ -77,6 +77,9 @@ Kleinere neue Features und Detailverbesserungen: - Verkaufsangebotsgültigkeit konfigurierbar per Intervall (nächster Werktag + x Tage) - Schnelllöschen von einzelnen Positionen (Ein X vor jeder Zeile) + +- FiBu Schnellsuche in Headerzeile, um nach Belegen zu suchen + 2014-02-28 - Release 3.1.0 Größere neue Features: diff --git a/js/glquicksearch.js b/js/glquicksearch.js new file mode 100644 index 000000000..2b8b3dfd9 --- /dev/null +++ b/js/glquicksearch.js @@ -0,0 +1,14 @@ +$(function() { + $( "#glquicksearch" ).autocomplete({ + source: "controller.pl?action=GL/quicksearch", + minLength: 3, + select: function(event, ui) { + var url = ui.item.url; + if(url != '#') { + location.href = url; + } + }, + html: false, + autoFocus: true + }); +}); diff --git a/locale/de/all b/locale/de/all index edad43686..295ee31e2 100755 --- a/locale/de/all +++ b/locale/de/all @@ -1158,6 +1158,8 @@ $self->{texts} = { 'Function/position' => 'Funktion/Position', 'Fwd' => 'Vorwärts', 'GL Transaction' => 'Dialogbuchung', + 'GL Transaction (abbreviation)' => 'DB', + 'GL search' => 'FiBu Suche', 'GL transactions changeable' => 'Änderbarkeit von Dialogbuchungen', 'Gegenkonto' => 'Gegenkonto', 'Gender' => 'Geschlecht', diff --git a/templates/webpages/menu/header.html b/templates/webpages/menu/header.html index b798c11b8..95004383f 100644 --- a/templates/webpages/menu/header.html +++ b/templates/webpages/menu/header.html @@ -7,6 +7,9 @@ [[% 'Print' | $T8 %]] [[% 'Back' | $T8 %]] [[% 'Fwd' | $T8 %]] +[%- IF AUTH.assert('general_ledger', 1) %] + [[% 'GL search' | $T8 %]: ] +[%- END %] [%- END %] @@ -20,3 +23,6 @@ [% LxERP.t8('Loading...') %] +[% IF AUTH.assert('general_ledger', 1) %] + +[% END %] diff --git a/templates/webpages/menu/menunew.html b/templates/webpages/menu/menunew.html index 55fcab82b..fc0e32675 100644 --- a/templates/webpages/menu/menunew.html +++ b/templates/webpages/menu/menunew.html @@ -19,7 +19,9 @@ $(clockon); [[% 'new Window' | $T8 %]] [[% 'print' | $T8 %]] - [[% 'Search contacts' | $T8 %] ] +[%- IF AUTH.assert('general_ledger', 1) %] + [[% 'GL search' | $T8 %]: ] +[%- END %] [[% 'User' | $T8 %]: [% MYCONFIG.login | html %] - @@ -98,3 +100,6 @@ function open_url(url, target) { --> +[% IF AUTH.assert('general_ledger', 1) %] + +[% END %] diff --git a/templates/webpages/menu/menuv3.html b/templates/webpages/menu/menuv3.html index cb7231c1f..5e6fcf09d 100644 --- a/templates/webpages/menu/menuv3.html +++ b/templates/webpages/menu/menuv3.html @@ -20,6 +20,9 @@ $(clockon); [[% 'new Window' | $T8 %]] [[% 'print' | $T8 %]] [[% 'Search contacts' | $T8 %] ] +[%- IF AUTH.assert('general_ledger', 1) %] + [[% 'GL search' | $T8 %]: ] +[%- END %] [[% 'User' | $T8 %]: [% MYCONFIG.login | html %] - @@ -38,3 +41,6 @@ $(clockon);
+[% IF AUTH.assert('general_ledger', 1) %] + +[% END %] -- 2.20.1