Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 32dc7476

Von Moritz Bunkus vor fast 8 Jahren hinzugefügt

  • ID 32dc7476d46dc7b6991e8d0c203deaea727c7413
  • Vorgänger 24097357
  • Nachfolger 9468ce7d

Bankauszug verbuchen: Umstellung auf Belegvorlagen & Filter-Fixes

Unterschiede anzeigen:

SL/Controller/BankTransaction.pm
21 21
use SL::DB::Chart;
22 22
use SL::DB::AccTransaction;
23 23
use SL::DB::Tax;
24
use SL::DB::Draft;
25 24
use SL::DB::BankAccount;
25
use SL::DB::RecordTemplate;
26 26
use SL::DB::SepaExportItem;
27 27
use SL::DBUtils qw(like);
28 28
use SL::Presenter;
......
32 32

  
33 33
use Rose::Object::MakeMethods::Generic
34 34
(
35
  scalar                  => [ qw(callback transaction) ],
35 36
  'scalar --get_set_init' => [ qw(models problems) ],
36 37
);
37 38

  
......
284 285
  my ($self) = @_;
285 286
  my %myconfig = %main::myconfig;
286 287

  
287
  $self->{transaction} = SL::DB::Manager::BankTransaction->find_by(id => $::form->{bt_id});
288
  my $vendor_of_transaction = SL::DB::Manager::Vendor->find_by(account_number => $self->{transaction}->{remote_account_number});
289

  
290
  my $use_vendor_filter = $self->{transaction}->{remote_account_number} && $vendor_of_transaction;
288
  $self->transaction(SL::DB::Manager::BankTransaction->find_by(id => $::form->{bt_id}));
291 289

  
292
  my $drafts = SL::DB::Manager::Draft->get_all(where => [ module => 'ap'] , with_objects => 'employee');
290
  my $vendor_of_transaction = SL::DB::Manager::Vendor->find_by(account_number => $self->transaction->{remote_account_number});
291
  my $use_vendor_filter     = $self->transaction->{remote_account_number} && $vendor_of_transaction;
293 292

  
294
  my @filtered_drafts;
295

  
296
  foreach my $draft ( @{ $drafts } ) {
297
    my $draft_as_object = YAML::Load($draft->form);
298
    my $vendor = SL::DB::Manager::Vendor->find_by(id => $draft_as_object->{vendor_id});
299
    $draft->{vendor} = $vendor->name;
300
    $draft->{vendor_id} = $vendor->id;
301
    push @filtered_drafts, $draft;
302
  }
293
  my $templates             = SL::DB::Manager::RecordTemplate->get_all(
294
    where        => [ template_type => 'ap_transaction' ],
295
    with_objects => [ qw(employee vendor) ],
296
  );
303 297

  
304
  #Filter drafts
305
  @filtered_drafts = grep { $_->{vendor_id} == $vendor_of_transaction->id } @filtered_drafts if $use_vendor_filter;
298
  #Filter templates
299
  $templates = [ grep { $_->vendor_id == $vendor_of_transaction->id } @{ $templates } ] if $use_vendor_filter;
306 300

  
307
  my $all_vendors = SL::DB::Manager::Vendor->get_all();
308
  my $callback    = $self->url_for(action                => 'list',
309
                                   'filter.bank_account' => $::form->{filter}->{bank_account},
310
                                   'filter.todate'       => $::form->{filter}->{todate},
311
                                   'filter.fromdate'     => $::form->{filter}->{fromdate});
301
  $self->callback($self->url_for(
302
    action                => 'list',
303
    'filter.bank_account' => $::form->{filter}->{bank_account},
304
    'filter.todate'       => $::form->{filter}->{todate},
305
    'filter.fromdate'     => $::form->{filter}->{fromdate},
306
  ));
312 307

  
313 308
  $self->render(
314 309
    'bank_transactions/create_invoice',
315 310
    { layout => 0 },
316 311
    title       => t8('Create invoice'),
317
    DRAFTS      => \@filtered_drafts,
312
    TEMPLATES   => $templates,
318 313
    vendor_id   => $use_vendor_filter ? $vendor_of_transaction->id   : undef,
319 314
    vendor_name => $use_vendor_filter ? $vendor_of_transaction->name : undef,
320
    ALL_VENDORS => $all_vendors,
321
    callback    => $callback,
322 315
  );
323 316
}
324 317

  
......
348 341
  $self->render(\ SL::JSON::to_json( { 'html' => "$html" } ), { layout => 0, type => 'json', process => 0 });
349 342
};
350 343

  
351
sub action_filter_drafts {
344
sub action_filter_templates {
352 345
  my ($self) = @_;
353 346

  
354 347
  $self->{transaction}      = SL::DB::Manager::BankTransaction->find_by(id => $::form->{bt_id});
355 348
  my $vendor_of_transaction = SL::DB::Manager::Vendor->find_by(account_number => $self->{transaction}->{remote_account_number});
356 349

  
357
  my $drafts                = SL::DB::Manager::Draft->get_all(with_objects => 'employee');
358

  
359
  my @filtered_drafts;
360

  
361
  foreach my $draft ( @{ $drafts } ) {
362
    my $draft_as_object = YAML::Load($draft->form);
363
    next unless $draft_as_object->{vendor_id};  # we cannot filter for vendor name, if this is a gl draft
364

  
365
    my $vendor          = SL::DB::Manager::Vendor->find_by(id => $draft_as_object->{vendor_id});
366
    $draft->{vendor}    = $vendor->name;
367
    $draft->{vendor_id} = $vendor->id;
350
  my @filter;
351
  push @filter, ('vendor.id'   => $::form->{vendor_id})                       if $::form->{vendor_id};
352
  push @filter, ('vendor.name' => { ilike => '%' . $::form->{vendor} . '%' }) if $::form->{vendor};
368 353

  
369
    push @filtered_drafts, $draft;
370
  }
354
  my $templates = SL::DB::Manager::RecordTemplate->get_all(
355
    where        => [ template_type => 'ap_transaction', (or => \@filter) x !!@filter ],
356
    with_objects => [ qw(employee vendor) ],
357
  );
371 358

  
372
  my $vendor_name = $::form->{vendor};
373
  my $vendor_id   = $::form->{vendor_id};
359
  $::form->{filter} //= {};
374 360

  
375
  #Filter drafts
376
  @filtered_drafts = grep { $_->{vendor_id} == $vendor_id      } @filtered_drafts if $vendor_id;
377
  @filtered_drafts = grep { $_->{vendor}    =~ /$vendor_name/i } @filtered_drafts if $vendor_name;
361
  $self->callback($self->url_for(
362
    action                => 'list',
363
    'filter.bank_account' => $::form->{filter}->{bank_account},
364
    'filter.todate'       => $::form->{filter}->{todate},
365
    'filter.fromdate'     => $::form->{filter}->{fromdate},
366
  ));
378 367

  
379 368
  my $output  = $self->render(
380
    'bank_transactions/filter_drafts',
369
    'bank_transactions/_template_list',
381 370
    { output => 0 },
382
    DRAFTS => \@filtered_drafts,
371
    TEMPLATES => $templates,
383 372
  );
384 373

  
385
  my %result = ( count => 0, html => $output );
386

  
387
  $self->render(\to_json(\%result), { type => 'json', process => 0 });
374
  $self->render(\to_json({ html => $output }), { type => 'json', process => 0 });
388 375
}
389 376

  
390 377
sub action_ajax_add_list {
......
883 870
  );
884 871
}
885 872

  
873
sub load_ap_record_template_url {
874
  my ($self, $template) = @_;
875

  
876
  return $self->url_for(
877
    controller                 => 'ap.pl',
878
    action                     => 'load_record_template',
879
    id                         => $template->id,
880
    'form_defaults.amount_1'   => $::form->format_amount(\%::myconfig, -1 * $self->transaction->amount, 2),
881
    'form_defaults.transdate'  => $self->transaction->transdate_as_date,
882
    'form_defaults.duedate'    => $self->transaction->transdate_as_date,
883
    'form_defaults.datepaid_1' => $self->transaction->transdate_as_date,
884
    'form_defaults.paid_1'     => $::form->format_amount(\%::myconfig, -1 * $self->transaction->amount, 2),
885
    'form_defaults.currency'   => $self->transaction->currency->name,
886
    'form_defaults.AP_paid_1'  => $self->transaction->local_bank_account->chart->accno,
887
    'form_defaults.callback'   => $self->callback,
888
  );
889
}
890

  
886 891
1;
887 892
__END__
888 893

  
js/kivi.BankTransaction.js
44 44
  ns.create_invoice = function(bank_transaction_id) {
45 45
    kivi.popup_dialog({
46 46
      url:    'controller.pl?action=BankTransaction/create_invoice',
47
      data:   '&bt_id=' + bank_transaction_id + "&filter.bank_account=" + $('#filter_bankaccount').val() + '&filter.fromdate=' + $('#filter_fromdate').val() + '&filter.todate=' + $('#filter_todate').val(),
47
      data:   '&bt_id=' + bank_transaction_id + "&filter.bank_account=" + $('#filter_bank_account').val() + '&filter.fromdate=' + $('#filter_fromdate').val() + '&filter.todate=' + $('#filter_todate').val(),
48 48
      type:   'POST',
49 49
      id:     'create_invoice_window',
50 50
      dialog: { title: kivi.t8('Create invoice') }
......
130 130

  
131 131
    $dlg.dialog('close');
132 132
  };
133

  
134
  ns.filter_templates = function() {
135
    var url="controller.pl?action=BankTransaction/filter_templates&" + $("#create_invoice_window form").serialize();
136
    $.ajax({
137
      url: url,
138
      success: function(new_data) {
139
        $("#templates").html(new_data.error || new_data.html);
140
      }
141
    });
142
  };
133 143
});
templates/webpages/bank_transactions/_template_list.html
1
[%- USE HTML -%][%- USE LxERP -%][%- USE P -%][% IF TEMPLATES.size %]
2
 [% LxERP.t8('Template suggestions') %]:
3
 <table>
4
  <thead>
5
   <tr>
6
    <th class="listheading">[% LxERP.t8('Description') %]</th>
7
    <th class="listheading">[% LxERP.t8('Vendor') %]</th>
8
    <th class="listheading">[% LxERP.t8('Employee') %]</th>
9
    <th class="listheading">[% LxERP.t8('Template date') %]</th>
10
   </tr>
11
  </thead>
12

  
13
  <tbody>
14
   [% FOREACH template = TEMPLATES %]
15
    <tr class="listrow">
16
     <td>[% P.link(SELF.load_ap_record_template_url(template), template.template_name) %]</td>
17
     <td>[% HTML.escape(template.vendor.name) %]</td>
18
     <td>[% HTML.escape(template.employee.name || template.employee.login) %]</td>
19
     <td>[% HTML.escape(template.itime_as_date) %]</td>
20
    </tr>
21
   [% END %]
22
  </tbody>
23
 </table>
24
[% ELSE %]
25
 <p class="message_hint">[% LxERP.t8('No template was found.') %]</p>
26
[% END %]
templates/webpages/bank_transactions/create_invoice.html
1
[%- USE HTML %][%- USE L %][%- USE LxERP %][%- USE T8 %][%- USE P -%]
1
[%- USE HTML %][%- USE L %][%- USE LxERP %][%- USE P -%]
2 2

  
3 3
  <b>Transaction</b>
4 4
  <table>
......
25 25

  
26 26

  
27 27
<br>
28
[% 'Vendor filter for AP transaction drafts' | $T8 %]:
29

  
30
<form method="post" action="javascript:filter_drafts();">
31
[% L.hidden_tag('bt_id', SELF.transaction.id) %]
32
  <table>
33
   <tr>
34
    <th align="right">[%- LxERP.t8("Vendor") %]</th>
35
    <td>[% P.input_tag("vendor", vendor_name, class="initial_focus", style="width: 250px") %]</td>
36
   </tr>
37
  </table>
28
[% LxERP.t8('Vendor filter for AP transaction templates') %]:
29

  
30
<form method="post" action="javascript:kivi.BankTransaction.filter_templates()">
31
 [% L.hidden_tag("bt_id",               SELF.transaction.id) %]
32
 [% L.hidden_tag("filter.bank_account", FORM.filter.bank_account) %]
33
 [% L.hidden_tag("filter.fromdate",     FORM.filter.fromdate) %]
34
 [% L.hidden_tag("filter.todate",      FORM.filter.todate) %]
35
 <table>
36
  <tr>
37
   <th align="right">[%- LxERP.t8("Vendor") %]</th>
38
   <td>[% P.input_tag("vendor", vendor_name, class="initial_focus", style="width: 250px") %]</td>
39
  </tr>
40
 </table>
38 41
</form>
39 42

  
40 43
  <p>
44
   [% P.button_tag("kivi.BankTransaction.filter_templates()", LxERP.t8("Filter vendors")) %]
41 45
   <a href="#" onclick="$('#create_invoice_window').dialog('close');">[% LxERP.t8("Cancel") %]</a>
42 46
  </p>
43 47

  
44 48
  <hr>
45
<div id="drafts">
46
[% IF DRAFTS.size %]
47
[% 'Draft suggestions' | $T8 %]:
48

  
49

  
50
  <table>
51
   <tr>
52
    <th class="listheading">[% 'Description' | $T8 %]</th>
53
    <th class="listheading">[% 'Vendor' | $T8 %]</th>
54
    <th class="listheading">[% 'Employee' | $T8 %]</th>
55
    <th class="listheading">[% 'Draft from:' | $T8 %]</th>
56
   </tr>
57

  
58
   [% FOREACH draft = DRAFTS %]
59
    <tr class="listrow[% loop.count % 2 %]">
60
     <td><a href="controller.pl?action=Draft/load&id=[% HTML.url(draft.id) %]&form.amount_1=[% LxERP.format_amount(-1 * SELF.transaction.amount, 2) %]&form.transdate=[% HTML.url(SELF.transaction.transdate_as_date) %]&form.duedate=[% HTML.url(SELF.transaction.transdate_as_date) %]&form.datepaid_1=[% HTML.url(SELF.transaction.transdate_as_date) %]&form.paid_1=[% LxERP.format_amount(-1 * SELF.transaction.amount, 2) %]&form.currency=[% HTML.url(SELF.transaction.currency.name) %]&form.AP_paid_1=[% HTML.url(SELF.transaction.local_bank_account.chart.accno) %]&form.callback=[% HTML.url(callback) %]">[% HTML.escape(draft.description) %]</a></td>
61
     <td>[% HTML.escape(draft.vendor) %]</td>
62
     <td>[% HTML.escape(draft.employee.name) %]</td>
63
     <td>[% HTML.escape(draft.itime_as_date) %]</td>
64
    </tr>
65
   [% END %]
66
  </table>
67
[% ELSE %]
68
  <p class="message_hint">[% 'No draft was found.' | $T8 %]</p>
69
[% END %]
49
<div id="templates">
50
 [% PROCESS "bank_transactions/_template_list.html" %]
70 51
</div>
71

  
72
<script type="text/javascript">
73
<!--
74

  
75
function filter_drafts() {
76
  var url="controller.pl?action=BankTransaction/filter_drafts&" + $("#create_invoice_window form").serialize();
77
  $.ajax({
78
    url: url,
79
    success: function(new_data) {
80
      $("#drafts").html(new_data['html']);
81
    }
82
  });
83
}
84
//-->
85
</script>
templates/webpages/bank_transactions/filter_drafts.html
1
[%- USE T8 -%][%- USE HTML -%][%- USE LxERP -%][%- USE P -%][%- USE L -%]
2
[%- IF !DRAFTS.size %]
3
  <p class="message_hint">[% 'No draft was found.' | $T8 %]</p>
4
[%- ELSE %]
5
  <table>
6
   <tr>
7
    <th class="listheading">[% 'Date' | $T8 %]</th>
8
    <th class="listheading">[% 'Description' | $T8 %]</th>
9
    <th class="listheading">[% 'Employee' | $T8 %]</th>
10
    <th class="listheading">[% 'Vendor' | $T8 %]</th>
11
   </tr>
12

  
13
   [% FOREACH draft = DRAFTS %]
14
    <tr class="listrow[% loop.count % 2 %]">
15
     <td>[% HTML.escape(draft.itime_as_date) %]</td>
16
     <td><a href="controller.pl?action=Draft/load&id=[% HTML.url(draft.id) %]&form.amount_1=[% LxERP.format_amount(-1 * SELF.transaction.amount, 2) %]&form.datepaid_1=[% HTML.url(SELF.transaction.transdate_as_date) %]&form.paid_1=[% LxERP.format_amount(-1 * SELF.transaction.amount, 2) %]&form.callback=[% HTML.url(callback) %]">[% HTML.escape(draft.description) %]</a></td>
17
     <td>[% HTML.escape(draft.employee.name) %]</td>
18
     <td>[% HTML.escape(draft.vendor) %]</td>
19
    </tr>
20
   [% END %]
21
  </table>
22
[%- END %]
23

  
templates/webpages/bank_transactions/list.html
12 12
<p>
13 13
[% IF FORM.filter.fromdate %] [% 'From' | $T8 %] [% FORM.filter.fromdate %] [% END %]
14 14
[% IF FORM.filter.todate %]   [% 'to (date)' | $T8 %] [% FORM.filter.todate %][% END %]
15
[% L.hidden_tag("filter_bankaccount", FORM.filter.bankaccount) %]
16
[% L.hidden_tag("filter_fromdate", FORM.filter.fromdate) %]
17
[% L.hidden_tag("filter_todate", FORM.filter.todate) %]
15
[% L.hidden_tag("filter.bank_account", FORM.filter.bank_account) %]
16
[% L.hidden_tag("filter.fromdate",     FORM.filter.fromdate) %]
17
[% L.hidden_tag("filter.todate",       FORM.filter.todate) %]
18 18
</p>
19 19

  
20 20
<div id="bt_tabs" class="tabwidget">

Auch abrufbar als: Unified diff