From: Moritz Bunkus Date: Fri, 10 Feb 2017 10:21:45 +0000 (+0100) Subject: Bankauszug verbuchen: Umstellung auf Belegvorlagen & Filter-Fixes X-Git-Tag: release-3.5.4~1515 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=32dc7476d46dc7b6991e8d0c203deaea727c7413;p=kivitendo-erp.git Bankauszug verbuchen: Umstellung auf Belegvorlagen & Filter-Fixes --- diff --git a/SL/Controller/BankTransaction.pm b/SL/Controller/BankTransaction.pm index 13b65b798..871572783 100644 --- a/SL/Controller/BankTransaction.pm +++ b/SL/Controller/BankTransaction.pm @@ -21,8 +21,8 @@ use SL::JSON; use SL::DB::Chart; use SL::DB::AccTransaction; use SL::DB::Tax; -use SL::DB::Draft; use SL::DB::BankAccount; +use SL::DB::RecordTemplate; use SL::DB::SepaExportItem; use SL::DBUtils qw(like); use SL::Presenter; @@ -32,6 +32,7 @@ use List::Util qw(max); use Rose::Object::MakeMethods::Generic ( + scalar => [ qw(callback transaction) ], 'scalar --get_set_init' => [ qw(models problems) ], ); @@ -284,41 +285,33 @@ sub action_create_invoice { my ($self) = @_; my %myconfig = %main::myconfig; - $self->{transaction} = SL::DB::Manager::BankTransaction->find_by(id => $::form->{bt_id}); - my $vendor_of_transaction = SL::DB::Manager::Vendor->find_by(account_number => $self->{transaction}->{remote_account_number}); - - my $use_vendor_filter = $self->{transaction}->{remote_account_number} && $vendor_of_transaction; + $self->transaction(SL::DB::Manager::BankTransaction->find_by(id => $::form->{bt_id})); - my $drafts = SL::DB::Manager::Draft->get_all(where => [ module => 'ap'] , with_objects => 'employee'); + my $vendor_of_transaction = SL::DB::Manager::Vendor->find_by(account_number => $self->transaction->{remote_account_number}); + my $use_vendor_filter = $self->transaction->{remote_account_number} && $vendor_of_transaction; - my @filtered_drafts; - - foreach my $draft ( @{ $drafts } ) { - my $draft_as_object = YAML::Load($draft->form); - my $vendor = SL::DB::Manager::Vendor->find_by(id => $draft_as_object->{vendor_id}); - $draft->{vendor} = $vendor->name; - $draft->{vendor_id} = $vendor->id; - push @filtered_drafts, $draft; - } + my $templates = SL::DB::Manager::RecordTemplate->get_all( + where => [ template_type => 'ap_transaction' ], + with_objects => [ qw(employee vendor) ], + ); - #Filter drafts - @filtered_drafts = grep { $_->{vendor_id} == $vendor_of_transaction->id } @filtered_drafts if $use_vendor_filter; + #Filter templates + $templates = [ grep { $_->vendor_id == $vendor_of_transaction->id } @{ $templates } ] if $use_vendor_filter; - my $all_vendors = SL::DB::Manager::Vendor->get_all(); - my $callback = $self->url_for(action => 'list', - 'filter.bank_account' => $::form->{filter}->{bank_account}, - 'filter.todate' => $::form->{filter}->{todate}, - 'filter.fromdate' => $::form->{filter}->{fromdate}); + $self->callback($self->url_for( + action => 'list', + 'filter.bank_account' => $::form->{filter}->{bank_account}, + 'filter.todate' => $::form->{filter}->{todate}, + 'filter.fromdate' => $::form->{filter}->{fromdate}, + )); $self->render( 'bank_transactions/create_invoice', { layout => 0 }, title => t8('Create invoice'), - DRAFTS => \@filtered_drafts, + TEMPLATES => $templates, vendor_id => $use_vendor_filter ? $vendor_of_transaction->id : undef, vendor_name => $use_vendor_filter ? $vendor_of_transaction->name : undef, - ALL_VENDORS => $all_vendors, - callback => $callback, ); } @@ -348,43 +341,37 @@ sub action_ajax_payment_suggestion { $self->render(\ SL::JSON::to_json( { 'html' => "$html" } ), { layout => 0, type => 'json', process => 0 }); }; -sub action_filter_drafts { +sub action_filter_templates { my ($self) = @_; $self->{transaction} = SL::DB::Manager::BankTransaction->find_by(id => $::form->{bt_id}); my $vendor_of_transaction = SL::DB::Manager::Vendor->find_by(account_number => $self->{transaction}->{remote_account_number}); - my $drafts = SL::DB::Manager::Draft->get_all(with_objects => 'employee'); - - my @filtered_drafts; - - foreach my $draft ( @{ $drafts } ) { - my $draft_as_object = YAML::Load($draft->form); - next unless $draft_as_object->{vendor_id}; # we cannot filter for vendor name, if this is a gl draft - - my $vendor = SL::DB::Manager::Vendor->find_by(id => $draft_as_object->{vendor_id}); - $draft->{vendor} = $vendor->name; - $draft->{vendor_id} = $vendor->id; + my @filter; + push @filter, ('vendor.id' => $::form->{vendor_id}) if $::form->{vendor_id}; + push @filter, ('vendor.name' => { ilike => '%' . $::form->{vendor} . '%' }) if $::form->{vendor}; - push @filtered_drafts, $draft; - } + my $templates = SL::DB::Manager::RecordTemplate->get_all( + where => [ template_type => 'ap_transaction', (or => \@filter) x !!@filter ], + with_objects => [ qw(employee vendor) ], + ); - my $vendor_name = $::form->{vendor}; - my $vendor_id = $::form->{vendor_id}; + $::form->{filter} //= {}; - #Filter drafts - @filtered_drafts = grep { $_->{vendor_id} == $vendor_id } @filtered_drafts if $vendor_id; - @filtered_drafts = grep { $_->{vendor} =~ /$vendor_name/i } @filtered_drafts if $vendor_name; + $self->callback($self->url_for( + action => 'list', + 'filter.bank_account' => $::form->{filter}->{bank_account}, + 'filter.todate' => $::form->{filter}->{todate}, + 'filter.fromdate' => $::form->{filter}->{fromdate}, + )); my $output = $self->render( - 'bank_transactions/filter_drafts', + 'bank_transactions/_template_list', { output => 0 }, - DRAFTS => \@filtered_drafts, + TEMPLATES => $templates, ); - my %result = ( count => 0, html => $output ); - - $self->render(\to_json(\%result), { type => 'json', process => 0 }); + $self->render(\to_json({ html => $output }), { type => 'json', process => 0 }); } sub action_ajax_add_list { @@ -883,6 +870,24 @@ sub init_models { ); } +sub load_ap_record_template_url { + my ($self, $template) = @_; + + return $self->url_for( + controller => 'ap.pl', + action => 'load_record_template', + id => $template->id, + 'form_defaults.amount_1' => $::form->format_amount(\%::myconfig, -1 * $self->transaction->amount, 2), + 'form_defaults.transdate' => $self->transaction->transdate_as_date, + 'form_defaults.duedate' => $self->transaction->transdate_as_date, + 'form_defaults.datepaid_1' => $self->transaction->transdate_as_date, + 'form_defaults.paid_1' => $::form->format_amount(\%::myconfig, -1 * $self->transaction->amount, 2), + 'form_defaults.currency' => $self->transaction->currency->name, + 'form_defaults.AP_paid_1' => $self->transaction->local_bank_account->chart->accno, + 'form_defaults.callback' => $self->callback, + ); +} + 1; __END__ diff --git a/js/kivi.BankTransaction.js b/js/kivi.BankTransaction.js index 838b98aff..0c1346340 100644 --- a/js/kivi.BankTransaction.js +++ b/js/kivi.BankTransaction.js @@ -44,7 +44,7 @@ namespace('kivi.BankTransaction', function(ns) { ns.create_invoice = function(bank_transaction_id) { kivi.popup_dialog({ url: 'controller.pl?action=BankTransaction/create_invoice', - data: '&bt_id=' + bank_transaction_id + "&filter.bank_account=" + $('#filter_bankaccount').val() + '&filter.fromdate=' + $('#filter_fromdate').val() + '&filter.todate=' + $('#filter_todate').val(), + data: '&bt_id=' + bank_transaction_id + "&filter.bank_account=" + $('#filter_bank_account').val() + '&filter.fromdate=' + $('#filter_fromdate').val() + '&filter.todate=' + $('#filter_todate').val(), type: 'POST', id: 'create_invoice_window', dialog: { title: kivi.t8('Create invoice') } @@ -130,4 +130,14 @@ namespace('kivi.BankTransaction', function(ns) { $dlg.dialog('close'); }; + + ns.filter_templates = function() { + var url="controller.pl?action=BankTransaction/filter_templates&" + $("#create_invoice_window form").serialize(); + $.ajax({ + url: url, + success: function(new_data) { + $("#templates").html(new_data.error || new_data.html); + } + }); + }; }); diff --git a/templates/webpages/bank_transactions/_template_list.html b/templates/webpages/bank_transactions/_template_list.html new file mode 100644 index 000000000..9bd54e333 --- /dev/null +++ b/templates/webpages/bank_transactions/_template_list.html @@ -0,0 +1,26 @@ +[%- USE HTML -%][%- USE LxERP -%][%- USE P -%][% IF TEMPLATES.size %] + [% LxERP.t8('Template suggestions') %]: + + + + + + + + + + + + [% FOREACH template = TEMPLATES %] + + + + + + + [% END %] + +
[% LxERP.t8('Description') %][% LxERP.t8('Vendor') %][% LxERP.t8('Employee') %][% LxERP.t8('Template date') %]
[% P.link(SELF.load_ap_record_template_url(template), template.template_name) %][% HTML.escape(template.vendor.name) %][% HTML.escape(template.employee.name || template.employee.login) %][% HTML.escape(template.itime_as_date) %]
+[% ELSE %] +

[% LxERP.t8('No template was found.') %]

+[% END %] diff --git a/templates/webpages/bank_transactions/create_invoice.html b/templates/webpages/bank_transactions/create_invoice.html index 818f01f28..25b32b395 100644 --- a/templates/webpages/bank_transactions/create_invoice.html +++ b/templates/webpages/bank_transactions/create_invoice.html @@ -1,4 +1,4 @@ -[%- USE HTML %][%- USE L %][%- USE LxERP %][%- USE T8 %][%- USE P -%] +[%- USE HTML %][%- USE L %][%- USE LxERP %][%- USE P -%] Transaction @@ -25,61 +25,27 @@
-[% 'Vendor filter for AP transaction drafts' | $T8 %]: - - -[% L.hidden_tag('bt_id', SELF.transaction.id) %] -
- - - - -
[%- LxERP.t8("Vendor") %][% P.input_tag("vendor", vendor_name, class="initial_focus", style="width: 250px") %]
+[% LxERP.t8('Vendor filter for AP transaction templates') %]: + + + [% L.hidden_tag("bt_id", SELF.transaction.id) %] + [% L.hidden_tag("filter.bank_account", FORM.filter.bank_account) %] + [% L.hidden_tag("filter.fromdate", FORM.filter.fromdate) %] + [% L.hidden_tag("filter.todate", FORM.filter.todate) %] + + + + + +
[%- LxERP.t8("Vendor") %][% P.input_tag("vendor", vendor_name, class="initial_focus", style="width: 250px") %]

+ [% P.button_tag("kivi.BankTransaction.filter_templates()", LxERP.t8("Filter vendors")) %] [% LxERP.t8("Cancel") %]


-
-[% IF DRAFTS.size %] -[% 'Draft suggestions' | $T8 %]: - - - - - - - - - - - [% FOREACH draft = DRAFTS %] - - - - - - - [% END %] -
[% 'Description' | $T8 %][% 'Vendor' | $T8 %][% 'Employee' | $T8 %][% 'Draft from:' | $T8 %]
[% HTML.escape(draft.description) %][% HTML.escape(draft.vendor) %][% HTML.escape(draft.employee.name) %][% HTML.escape(draft.itime_as_date) %]
-[% ELSE %] -

[% 'No draft was found.' | $T8 %]

-[% END %] +
+ [% PROCESS "bank_transactions/_template_list.html" %]
- - diff --git a/templates/webpages/bank_transactions/filter_drafts.html b/templates/webpages/bank_transactions/filter_drafts.html deleted file mode 100644 index 7f08d26a0..000000000 --- a/templates/webpages/bank_transactions/filter_drafts.html +++ /dev/null @@ -1,23 +0,0 @@ -[%- USE T8 -%][%- USE HTML -%][%- USE LxERP -%][%- USE P -%][%- USE L -%] -[%- IF !DRAFTS.size %] -

[% 'No draft was found.' | $T8 %]

-[%- ELSE %] - - - - - - - - - [% FOREACH draft = DRAFTS %] - - - - - - - [% END %] -
[% 'Date' | $T8 %][% 'Description' | $T8 %][% 'Employee' | $T8 %][% 'Vendor' | $T8 %]
[% HTML.escape(draft.itime_as_date) %][% HTML.escape(draft.description) %][% HTML.escape(draft.employee.name) %][% HTML.escape(draft.vendor) %]
-[%- END %] - diff --git a/templates/webpages/bank_transactions/list.html b/templates/webpages/bank_transactions/list.html index 2727ba443..2828d5481 100644 --- a/templates/webpages/bank_transactions/list.html +++ b/templates/webpages/bank_transactions/list.html @@ -12,9 +12,9 @@

[% IF FORM.filter.fromdate %] [% 'From' | $T8 %] [% FORM.filter.fromdate %] [% END %] [% IF FORM.filter.todate %] [% 'to (date)' | $T8 %] [% FORM.filter.todate %][% END %] -[% L.hidden_tag("filter_bankaccount", FORM.filter.bankaccount) %] -[% L.hidden_tag("filter_fromdate", FORM.filter.fromdate) %] -[% L.hidden_tag("filter_todate", FORM.filter.todate) %] +[% L.hidden_tag("filter.bank_account", FORM.filter.bank_account) %] +[% L.hidden_tag("filter.fromdate", FORM.filter.fromdate) %] +[% L.hidden_tag("filter.todate", FORM.filter.todate) %]