Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 96c33451

Von Moritz Bunkus vor fast 8 Jahren hinzugefügt

  • ID 96c33451796e314aa0ec0e48fecdd76674c94796
  • Vorgänger 18709591
  • Nachfolger 04a484b3

Kontoauszug verbuchen: JavaScript-Code in eigene js-Datei ausgelagert

Unterschiede anzeigen:

SL/Controller/BankTransaction.pm
252 252
  $bank_transactions = [ sort { $a->{agreement} <=> $b->{agreement} } @{ $bank_transactions } ] if $::form->{sort_by} eq 'proposal' and $::form->{sort_dir} == 1;
253 253
  $bank_transactions = [ sort { $b->{agreement} <=> $a->{agreement} } @{ $bank_transactions } ] if $::form->{sort_by} eq 'proposal' and $::form->{sort_dir} == 0;
254 254

  
255

  
255
  $::request->layout->add_javascripts("kivi.BankTransaction.js");
256 256
  $self->render('bank_transactions/list',
257 257
                title             => t8('Bank transactions MT940'),
258 258
                BANK_TRANSACTIONS => $bank_transactions,
......
337 337
                                     value_key => 'payment_type',
338 338
                                     title_key => 'display' )
339 339
    if @select_options;
340
  $html .= '<a href=# onclick="delete_invoice(' . $::form->{bt_id} . ',' . $::form->{prop_id} . ');">x</a>';
340
  $html .= '<a href=# onclick="kivi.BankTransaction.delete_invoice(' . $::form->{bt_id} . ',' . $::form->{prop_id} . ');">x</a>';
341 341
  $html = SL::Presenter->html_tag('div', $html, id => $::form->{bt_id} . '.' . $::form->{prop_id});
342 342

  
343 343
  $self->render(\ SL::JSON::to_json( { 'html' => $html } ), { layout => 0, type => 'json', process => 0 });
js/kivi.BankTransaction.js
1
namespace('kivi.BankTransaction', function(ns) {
2
  "use strict";
3

  
4
  ns.assign_invoice = function(bank_transaction_id) {
5
    kivi.popup_dialog({
6
      url:    'controller.pl?action=BankTransaction/assign_invoice',
7
      data:   '&bt_id=' + bank_transaction_id,
8
      type:   'POST',
9
      id:     'assign_invoice_window',
10
      dialog: { title: kivi.t8('Assign invoice') }
11
    });
12
    return true;
13
  };
14

  
15
  ns.add_invoices = function(bank_transaction_id, proposal_id) {
16
    $('[name=' + proposal_id + ']').remove();
17

  
18
    $.ajax({
19
      url: 'controller.pl?action=BankTransaction/ajax_payment_suggestion&bt_id=' + bank_transaction_id  + '&prop_id=' + proposal_id,
20
      success: function(data) {
21
        $('#assigned_invoices_' + bank_transaction_id).append(data.html);
22
      }
23
    });
24
  };
25

  
26
  ns.delete_invoice = function(bank_transaction_id, proposal_id) {
27
    $( "#" + bank_transaction_id + "\\." + proposal_id ).remove();
28
  };
29

  
30
  ns.create_invoice = function(bank_transaction_id) {
31
    kivi.popup_dialog({
32
      url:    'controller.pl?action=BankTransaction/create_invoice',
33
      data:   '&bt_id=' + bank_transaction_id + "&filter.bank_account=" + $('#filter_bankaccount').val() + '&filter.fromdate=' + $('#filter_fromdate').val() + '&filter.todate=' + $('#filter_todate').val(),
34
      type:   'POST',
35
      id:     'create_invoice_window',
36
      dialog: { title: kivi.t8('Create invoice') }
37
    });
38
    return true;
39
  };
40

  
41

  
42
  ns.filter_invoices = function() {
43
    var url="controller.pl?action=BankTransaction/ajax_add_list&" + $("#assign_invoice_window form").serialize();
44
    $.ajax({
45
      url: url,
46
      success: function(data) {
47
        $("#record_list_filtered_list").html(data.html);
48
      }
49
    });
50
  }
51

  
52
  ns.add_selected_invoices = function() {
53
    var bank_transaction_id = $("#assign_invoice_window_form").data("bank-transaction-id");
54
    var url                 ="controller.pl?action=BankTransaction/ajax_accept_invoices&bt_id=" + bank_transaction_id + '&' + $("#assign_invoice_window form").serialize();
55

  
56
    $.ajax({
57
      url: url,
58
      success: function(new_html) {
59
        $('#assigned_invoices_' + bank_transaction_id).append(new_html);
60
        $('#assign_invoice_window').dialog('close');
61
      }
62
    });
63
  }
64

  
65
  ns.init_list = function(ui_tab) {
66
    $('#check_all').checkall('INPUT[name^="proposal_ids"]');
67
    $('.sort_link').each(function() {
68
      var _href = $(this).attr("href");
69
      $(this).attr("href", _href + "&filter.fromdate=" + $('#filter_fromdate').val() + "&filter.todate=" + $('#filter_todate').val());
70
    });
71

  
72
    $.cookie('jquery_ui_tab_bt_tabs', ui_tab);
73
  };
74
});
templates/webpages/bank_transactions/assign_invoice.html
2 2

  
3 3
[% SET debug = 0 %]
4 4

  
5
<form method="post" action="javascript:filter_invoices();" id="assign_invoice_window_form">
5
<form method="post" action="javascript:kivi.BankTransaction.filter_invoices();" id="assign_invoice_window_form" data-bank-transaction-id="[% HTML.escape(SELF.transaction.id) %]">
6 6
  <b>[%- LxERP.t8("Bank transaction") %]:</b>
7 7
  <table>
8 8
   <tr class="listheading">
......
55 55

  
56 56
  <p>
57 57
   [% L.submit_tag('', LxERP.t8("Search")) %]
58
   [% L.button_tag('add_selected_invoices()', LxERP.t8("Add invoices"), id='add_selected_record_links_button') %]
58
   [% L.button_tag('kivi.BankTransaction.add_selected_invoices()', LxERP.t8("Add invoices"), id='add_selected_record_links_button') %]
59 59
   [% L.button_tag('$("#assign_invoice_window_form").resetForm()', LxERP.t8('Reset')) %]
60 60
   <a href="#" onclick="$('#assign_invoice_window').dialog('close');">[% LxERP.t8("Cancel") %]</a>
61 61
  </p>
......
68 68

  
69 69
<script type="text/javascript">
70 70
<!--
71

  
72
function filter_invoices() {
73
  var url="controller.pl?action=BankTransaction/ajax_add_list&" + $("#assign_invoice_window form").serialize();
74
  $.ajax({
75
    url: url,
76
    success: function(new_data) {
77
      $("#record_list_filtered_list").html(new_data['html']);
78
    }
79
  });
80
}
81

  
82
function add_selected_invoices() {
83
  var url="controller.pl?action=BankTransaction/ajax_accept_invoices&" + 'bt_id=[% SELF.transaction.id %]&' + $("#assign_invoice_window form").serialize();
84
  $.ajax({
85
    url: url,
86
    success: function(new_html) {
87
      var invoices = document.getElementById('assigned_invoices_[% SELF.transaction.id %]');
88
      if (invoices.innerHTML == '') {
89
        invoices.innerHTML = new_html;
90
      } else {
91
        invoices.innerHTML += '<br />' + new_html;
92
      }
93
      $('#assign_invoice_window').dialog('close');
94
    }
95
  });
96
}
97

  
98 71
$(function() {
99 72
  $('#invnumber').focus();
100 73
});
templates/webpages/bank_transactions/invoices.html
6 6
    [% L.hidden_tag('invoice_ids.' _ bt_id _'[]', invoice.id) %]
7 7
    [% 'Invno.' | $T8 %]: [% invoice.invnumber %]
8 8
    [% 'Open amount' | $T8 %]: [% LxERP.format_amount(invoice.open_amount, 2) %]
9
    <a href=# onclick="delete_invoice([% bt_id %], [% invoice.id %])">x</a>
9
    <a href=# onclick="kivi.BankTransaction.delete_invoice([% bt_id %], [% invoice.id %])">x</a>
10 10
  </div>
11 11
[% END %]
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 18
</p>
16 19

  
17 20
<div id="bt_tabs" class="tabwidget">
......
27 30

  
28 31
<script type="text/javascript">
29 32
<!--
30

  
31 33
$(function() {
32
  $('#check_all').checkall('INPUT[name^="proposal_ids"]');
34
  kivi.BankTransaction.init_list([% ui_tab %]);
33 35
});
34

  
35
$(function() {
36
  $('.sort_link').each(function() {
37
    var _href = $(this).attr("href");
38
    $(this).attr("href", _href + "&filter.fromdate=" + "[% FORM.filter.fromdate %]" + "&filter.todate=" + "[% FORM.filter.todate %]");
39
  });
40
});
41

  
42
function assign_invoice(bt_id) {
43
  kivi.popup_dialog({
44
    url:    'controller.pl?action=BankTransaction/assign_invoice',
45
    data:   '&bt_id=' + bt_id,
46
    type:   'POST',
47
    id:     'assign_invoice_window',
48
    dialog: { title: kivi.t8('Assign invoice') }
49
  });
50
  return true;
51
}
52

  
53
function add_invoices(bt_id, prop_id, prop_invnumber) {
54
  // prop_id is a proposed invoice_id
55
  // remove the added invoice from all the other suggestions
56
  var number_of_elements = document.getElementsByName(prop_id).length;
57
  for( var i = 0; i < number_of_elements; i++ ) {
58
    var node = document.getElementsByName(prop_id)[0];
59
    node.parentNode.removeChild(node);
60
  }
61
  var invoices = document.getElementById('assigned_invoices_' + bt_id);
62

  
63
  $.ajax({
64
    url: 'controller.pl?action=BankTransaction/ajax_payment_suggestion&bt_id=' + bt_id  + '&prop_id=' + prop_id,
65
    success: function(data) {
66
      invoices.innerHTML += data.html;
67
    }
68
  });
69
}
70

  
71
function delete_invoice(bt_id, prop_id) {
72
  $( "#" + bt_id + "\\." + prop_id ).remove();
73
}
74

  
75
function create_invoice(bt_id) {
76
  kivi.popup_dialog({
77
    url:    'controller.pl?action=BankTransaction/create_invoice',
78
    data:   '&bt_id=' + bt_id + "&filter.bank_account=[% FORM.filter.bank_account %]&filter.todate=[% FORM.filter.todate %]&filter.fromdate=[% FORM.filter.fromdate %]",
79
    type:   'POST',
80
    id:     'create_invoice_window',
81
    dialog: { title: kivi.t8('Create invoice') }
82
  });
83
  return true;
84
}
85

  
86
$.cookie('jquery_ui_tab_bt_tabs', [% ui_tab %] );
87 36
//-->
88 37
</script>
templates/webpages/bank_transactions/tabs/all.html
83 83
  <tbody>
84 84
   [%- FOREACH bt = BANK_TRANSACTIONS %]
85 85
    <tr class="listrow" id="bt_id_[% bt.id %]">
86
     <td><a href=# onclick="assign_invoice('[% bt.id %]'); return false;">[% 'Assign invoice' | $T8 %]</a></td>
87
     <td><a href=# onclick="create_invoice('[% bt.id %]'); return false;">[% 'Create invoice' | $T8 %]</a></td>
86
     <td><a href=# onclick="kivi.BankTransaction.assign_invoice('[% bt.id %]'); return false;">[% 'Assign invoice' | $T8 %]</a></td>
87
     <td><a href=# onclick="kivi.BankTransaction.create_invoice('[% bt.id %]'); return false;">[% 'Create invoice' | $T8 %]</a></td>
88 88
     <td id="assigned_invoices_[% bt.id %]" nowrap></td>
89 89
     [% IF debug %]
90 90
     <td class="tooltipster-html" title="[% FOREACH match = bt.rule_matches %] [% match %]<br> [% END %]">[% bt.agreement %]</td>
......
92 92
     <td>
93 93
      [% FOREACH prop = bt.proposals %]
94 94
        <div name='[% prop.id %]'>
95
         <a href=# onclick="add_invoices('[% bt.id %]', '[% prop.id %]', '[% HTML.escape(prop.invnumber) %]');"
95
         <a href=# onclick="kivi.BankTransaction.add_invoices('[% bt.id %]', '[% prop.id %]');"
96 96
            title="<table><tr><th></th><th>[% 'Suggested invoice' | $T8 %][% IF !prop.is_sales %] ([% 'AP' | $T8 %])[% END %]</th><th>[% 'Bank transaction' | $T8 %]</th></tr><tr><th>[% 'Amount' | $T8 %]</th><td>[% prop.realamount %] ([% 'open' | $T8 %]: [% LxERP.format_amount(prop.open_amount, 2) %])</td><td>[% LxERP.format_amount(bt.amount, 2) %]</td></tr>[% IF prop.skonto_date %]<tr><th>[% 'Payment terms' | $T8 %]</th><td>[% LxERP.format_amount(prop.amount_less_skonto, 2) %] [% 'until' | $T8 %] [% HTML.escape(prop.skonto_date.to_kivitendo) %] ([% prop.percent_skonto * 100 %] %)</td><td></td></tr>[% END %]<tr><th>[% 'Customer/Vendor' | $T8 %]</th><td>[% HTML.escape(prop.customer.displayable_name) %][% HTML.escape(prop.vendor.displayable_name) %]</td><td>[% HTML.escape(bt.remote_name) %]</td></tr><tr><th>[% 'Invoice Date' | $T8 %]</th><td>[% HTML.escape(prop.transdate_as_date) %]</td><td>[% HTML.escape(bt.transdate_as_date) %] ([% HTML.escape(bt.transdate.utc_rd_days - prop.transdate.utc_rd_days) %])</td></tr><tr><th>[% 'Invoice Number' | $T8 %]</th><td>[% HTML.escape(prop.invnumber) %]</td><td>[% HTML.escape(bt.purpose) %]</td></tr></table>"
97 97
              class="[% IF bt.agreement >= 5 %]green[% ELSIF bt.agreement < 5 and bt.agreement >= 3 %]orange[% ELSE %]red[% END %] tooltipster-html">&larr;[% HTML.escape(prop.invnumber)%]</a></div>
98 98
      [% END %]

Auch abrufbar als: Unified diff