Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision fc3b49d6

Von Tamino Steinert vor fast 2 Jahren hinzugefügt

  • ID fc3b49d655fe696caa1fc338c116b9a5a429991e
  • Vorgänger c6df901c
  • Nachfolger da784064

InvoiceItem: Hinzufügen der Felder für Konten und Steuer

Es werden die Wert von relink_accounts als Default genommen und der
Nutzer kann dies ändern. Es werden alle nötigen Steuerdaten in die Form
geschrieben.

Unterschiede anzeigen:

SL/IC.pm
811 811
    }
812 812

  
813 813
    $form->{"${_}_accno_$index"} = $accounts{"${_}_accno"} for qw(inventory income expense);
814
    $form->{"${_}_accno_id_$index"} = $accounts{"${_}_accno_id"} for qw(inventory expense); # only for purchase_invoice
814 815

  
815 816
    $sth_tax->execute($accounts{$inc_exp}, quote_db_date($transdate)) || $::form->dberror($query_tax);
816
    $ref = $sth_tax->fetchrow_hashref or next;
817
    my $tax_ref;
818
    $tax_ref = $sth_tax->fetchrow_hashref or next;
817 819

  
818
    $form->{"taxaccounts_$index"} = $ref->{"accno"};
819
    $form->{"taxaccounts"} .= "$ref->{accno} "if $form->{"taxaccounts"} !~ /$ref->{accno}/;
820
    $form->{"expense_accno_tax_id_$index"} = $tax_ref->{tax_id}; # only for purchase_invoice
820 821

  
821
    $form->{"$ref->{accno}_${_}"} = $ref->{$_} for qw(rate description taxnumber tax_id);
822
    $form->{"taxaccounts_$index"} = $tax_ref->{"accno"};
823
    $form->{"taxaccounts"} .= "$tax_ref->{accno} "if $form->{"taxaccounts"} !~ /$ref->{accno}/;
824

  
825
    $form->{"$tax_ref->{accno}_${_}"} = $tax_ref->{$_} for qw(rate description taxnumber tax_id);
822 826
  }
823 827

  
824 828
  $sth_tax->finish;
SL/IO.pm
77 77
  $main::lxdebug->leave_sub();
78 78
}
79 79

  
80
sub get_active_taxes_for_chart {
81
  my ($self, $chart_id, $transdate, $tax_id) = @_;
82

  
83
  my $chart         = SL::DB::Chart->new(id => $chart_id)->load;
84
  my $active_taxkey = $chart->get_active_taxkey($transdate);
85

  
86
  my $where = [ chart_categories => { like => '%' . $chart->category . '%' } ];
87

  
88
  if ( defined $tax_id && $tax_id >= 0 ) {
89
    $where = [ or => [ chart_categories => { like => '%' . $chart->category . '%' },
90
                       id               => $tax_id
91
                     ]
92
             ];
93
  }
94

  
95
  my $taxes         = SL::DB::Manager::Tax->get_all(
96
    where   => $where,
97
    sort_by => 'taxkey, rate',
98
  );
99

  
100
  my $default_tax            = first { $active_taxkey->tax_id == $_->id } @{ $taxes };
101
  $default_tax->{is_default} = 1 if $default_tax;
102

  
103
  return @{ $taxes };
104
}
80 105

  
81 106
1;
SL/IR.pm
1669 1669
  return $duedate;
1670 1670
}
1671 1671

  
1672

  
1673
sub get_taxes_dropdown {
1674
  my $transdate         = $::form->{transdate}    ? DateTime->from_kivitendo($::form->{transdate}) : DateTime->today_local;
1675
  my $deliverydate      = $::form->{deliverydate} ? DateTime->from_kivitendo($::form->{deliverydate}) : undef;
1676
  my $item_deliverydate = $::form->{item_deliverydate} ? DateTime->from_kivitendo($::form->{item_deliverydate}) : undef;
1677

  
1678
  my @taxes = IO->get_active_taxes_for_chart($::form->{chart_id},
1679
    $item_deliverydate // $deliverydate // $transdate);
1680
  my $html  = $::form->parse_html_template("ir/update_taxes", { TAXES => \@taxes });
1681

  
1682
  print $::form->ajax_response_header, $html;
1683
}
1684

  
1685

  
1672 1686
1;
bin/mozilla/io.pl
54 54
use SL::File;
55 55
use SL::PriceSource;
56 56
use SL::Presenter::Part;
57
use SL::Presenter::Chart;
58
use SL::Presenter::Tag;
57 59
use SL::Util qw(trim);
58 60

  
59 61
use SL::DB::AuthUser;
......
171 173
    bin stock_in_out
172 174
  );
173 175
  my @row2_sort   = qw(
174
    serialnr projectnr reqdate subtotal recurring_billing_mode marge listprice lastcost onhand
176
    expense_chart tax inventory_chart serialnr projectnr reqdate subtotal recurring_billing_mode marge listprice lastcost onhand
175 177
  );
176 178
  # serialnr is important for delivery_orders
177 179
  if ($form->{type} eq 'sales_delivery_order') {
......
207 209
    lastcost      => {                 value => $locale->text('EK'),                   display => $show_marge, },
208 210
    onhand        => {                 value => $locale->text('On Hand'),              display => 1, },
209 211
    vendor_partnumber => { width => 8, value => $locale->text('Vendor Part Number'),   display => $is_delivery_order && $is_purchase, },
212
    expense_chart => {                 value => $locale->text('Expense Account'),      display => $is_purchase && $is_invoice },
213
    tax           => {                 value => $locale->text('Tax'),                  display => $is_purchase && $is_invoice },
214
    inventory_chart => {               value => "",                                    display => $is_purchase && $is_invoice }, # only disply for type='part'
210 215
  );
211 216
  my @HEADER = map { $column_def{$_} } @header_sort;
212 217

  
......
398 403
      $column_data{stock_in_out} =  calculate_stock_in_out($i);
399 404
    }
400 405

  
406
    $column_data{expense_chart} = SL::Presenter::Chart::chart_picker(
407
      "expense_chart_id_$i", $form->{"expense_chart_id_$i"},
408
      type => "AP_amount", style => "width: 150px") .
409
      '<script type="text/javascript">
410
      <!--
411
      $(document).ready(function() {
412
        $("#expense_chart_id_' . $i . q'").on("set_item:ChartPicker", function(e, item) {
413
          kivi.io.update_tax_ids(this);
414
        });
415
      });
416
      -->
417
      </script>
418
      '; # change tax dropdown after change
419

  
420
    my $tax_value_title_sub = sub {
421
      my $item = shift;
422
      return [
423
        $item->{id},
424
        $item->{taxkey} . ' - ' . $item->{taxdescription} .' '. ($item->{rate} * 100) .' %',
425
      ];
426
    };
427

  
428
    my @taxes = ();
429
    if ($form->{"expense_chart_id_$i"}) {
430
      @taxes = IO->get_active_taxes_for_chart($form->{"expense_chart_id_$i"},
431
        $form->{"reqdate_$i"} // $form->{deliverydate} // $form->{transdate});
432
    }
433
    # tax_id_ is used in io.js->update_tax_ids
434
    $column_data{tax} = SL::Presenter::Tag::select_tag(
435
      "tax_id_$i", \@taxes, default => $form->{"tax_id_$i"},
436
      value_title_sub => $tax_value_title_sub,
437
      style => "width: 100px");
438

  
439
    if ($record_item && $record_item->part && ($record_item->part->type eq 'part')) {
440
      $column_data{inventory_chart} =
441
      '<b>' . $locale->text('Inventory Account') . '<b> ' .
442
      SL::Presenter::Chart::chart_picker(
443
        "inventory_chart_id_$i", $form->{"inventory_chart_id_$i"},
444
        type => "IC", style => "width: 150px");
445
    }
446

  
401 447
    $column_data{serialnr}  = qq|<input name="serialnumber_$i" size="15" value="$form->{"serialnumber_$i"}">|;
402 448
    $column_data{projectnr} = NTI($cgi->popup_menu(
403 449
      '-name' => "project_id_$i",
......
2291 2337

  
2292 2338
  $::locale->with_raw_io(\*STDOUT, sub { print $xml_content });
2293 2339
}
2340

  
2341
sub get_taxes_dropdown {
2342
  my $transdate         = $::form->{transdate}    ? DateTime->from_kivitendo($::form->{transdate}) : DateTime->today_local;
2343
  my $deliverydate      = $::form->{deliverydate} ? DateTime->from_kivitendo($::form->{deliverydate}) : undef;
2344
  my $item_deliverydate = $::form->{item_deliverydate} ? DateTime->from_kivitendo($::form->{item_deliverydate}) : undef;
2345

  
2346
  my @taxes = IO->get_active_taxes_for_chart($::form->{chart_id},
2347
    $item_deliverydate // $deliverydate // $transdate);
2348
  my $html  = $::form->parse_html_template("ir/update_taxes", { TAXES => \@taxes });
2349

  
2350
  print $::form->ajax_response_header, $html;
2351
}
2352

  
2353
1;
bin/mozilla/ir.pl
44 44
use SL::DB::PurchaseInvoice;
45 45
use SL::DB::ValidityToken;
46 46
use SL::DB::Vendor;
47
use SL::DB::Tax;
48
use SL::DB::Chart;
47 49
use List::MoreUtils qw(uniq);
48 50
use List::Util qw(max sum);
49 51
use List::UtilsBy qw(sort_by);
......
520 522
  $TMPL_VAR->{payment_terms_obj} = get_payment_terms_for_invoice();
521 523
  $form->{duedate}             = $TMPL_VAR->{payment_terms_obj}->calc_date(reference_date => $form->{invdate}, due_date => $form->{duedate})->to_kivitendo if $TMPL_VAR->{payment_terms_obj};
522 524

  
523
  $::request->{layout}->use_javascript(map { "${_}.js" } qw(kivi.Draft kivi.File kivi.SalesPurchase kivi.Part kivi.CustomerVendor kivi.Validator ckeditor/ckeditor ckeditor/adapters/jquery kivi.io autocomplete_project client_js));
525
  $::request->{layout}->use_javascript(map { "${_}.js" } qw(kivi.Draft kivi.File kivi.SalesPurchase kivi.Part kivi.CustomerVendor kivi.Validator ckeditor/ckeditor ckeditor/adapters/jquery kivi.io autocomplete_project client_js autocomplete_chart));
524 526

  
525 527
  setup_ir_action_bar($TMPL_VAR);
526 528

  
......
820 822
  invoice_links();
821 823
  prepare_invoice();
822 824
  relink_accounts();
825
  set_taxaccounts_and_accnos();
823 826

  
824 827
  # Payments must not be recorded for the new storno invoice.
825 828
  $form->{paidaccounts} = 0;
......
1021 1024
  $form->{storno}  ||= 0;
1022 1025

  
1023 1026
  relink_accounts();
1027
  set_taxaccounts_and_accnos();
1024 1028
  if (IR->post_invoice(\%myconfig, \%$form)){
1025 1029
    # saving the history
1026 1030
    if(!exists $form->{addition} && $form->{id} ne "") {
......
1094 1098
  _assert_access();
1095 1099

  
1096 1100
  relink_accounts();
1101
  set_taxaccounts_and_accnos();
1097 1102

  
1098 1103
  my $new_rowcount = $::form->{"rowcount"} * 1 + 1;
1099 1104
  $::form->{"project_id_${new_rowcount}"} = $::form->{"globalproject_id"};
......
1145 1150
  print $::form->ajax_response_header, $result;
1146 1151
  $::lxdebug->leave_sub;
1147 1152
}
1153

  
1154
# set values form relink_accounts as default
1155
# otherwiese override with user selected values
1156
# recalc taxaccounts string
1157
sub set_taxaccounts_and_accnos {
1158
  $main::lxdebug->enter_sub;
1159

  
1160
  for my $i (1 .. $::form->{rowcount}) {
1161

  
1162
    # fill with default, ids can be 0
1163
    if ('' eq $::form->{"expense_chart_id_$i"}) {
1164
      $::form->{"expense_chart_id_$i"} = $::form->{"expense_accno_id_$i"};
1165
    }
1166
    if ('' eq $::form->{"tax_id_$i"}) {
1167
      $::form->{"tax_id_$i"} = $::form->{"expense_accno_tax_id_$i"};
1168
    }
1169
    if ('' eq $::form->{"inventory_chart_id_$i"}) {
1170
      $::form->{"inventory_chart_id_$i"} = $::form->{"inventory_accno_id_$i"};
1171
    }
1172

  
1173
    # if changed override with user values
1174
    if ($::form->{"expense_chart_id_$i"} ne $::form->{"expense_accno_id_$i"}) {
1175
      $::form->{"expense_accno_id_$i"} = $::form->{"expense_chart_id_$i"};
1176
      my $chart = SL::DB::Chart->new(id => $::form->{"expense_chart_id_$i"})->load;
1177
      $::form->{"expense_accno_$i"}    = $chart->accno;
1178
    }
1179
    if ($::form->{"tax_id_$i"} ne $::form->{"expense_accno_tax_id_$i"}) {
1180
      $::form->{"expense_accno_tax_id_$i"} = $::form->{"tax_id_$i"};
1181
      my $tax = SL::DB::Tax->new(id => $::form->{"tax_id_$i"})->load;
1182
      my $tax_accno;
1183
      if (defined $tax->chart_id) {
1184
        my $chart  = SL::DB::Chart->new(id => $tax->chart_id)->load;
1185
        $tax_accno = $chart->accno;
1186
      } else {
1187
        $tax_accno = "NO_ACCNO_" . $tax->id;
1188
      }
1189
      $::form->{"taxaccounts_$i"} = $tax_accno;
1190
      if (!($::form->{taxaccounts} =~ /\Q$tax_accno\E/)) {
1191
        # add tax info if missing
1192
        $::form->{"${tax_accno}_rate"}        = $tax->rate;
1193
        $::form->{"${tax_accno}_description"} = $tax->taxdescription;
1194
        $::form->{"${tax_accno}_tax_id"}      = $tax->id;
1195
        $::form->{"${tax_accno}_taxnumber"}   = $::form->{"expense_accno_$i"};
1196
      }
1197
    }
1198
    if ($::form->{"inventory_chart_id_$i"} ne $::form->{"inventory_accno_id_$i"}) {
1199
      $::form->{"inventory_accno_id_$i"} = $::form->{"inventory_chart_id_$i"};
1200
      my $chart = SL::DB::Chart->new(id => $::form->{"inventory_chart_id_$i"})->load;
1201
      $::form->{"inventory_accno_$i"}    = $chart->accno;
1202
    }
1203

  
1204
  }
1205

  
1206
  # recalc taxaccounts string
1207
  $::form->{taxaccounts} = "";
1208
  for my $i (1 .. $::form->{rowcount}) {
1209
    my $taxaccounts_i = $::form->{"taxaccounts_$i"};
1210
    if (!($::form->{taxaccounts} =~ /\Q$taxaccounts_i\E/)) {
1211
      $::form->{taxaccounts} .= "$taxaccounts_i ";
1212
    }
1213
  }
1214

  
1215
  $::lxdebug->leave_sub;
1216
}
js/kivi.io.js
49 49
    if (discount_str) $('#discount_' + row).val(discount_str);
50 50
    $('#update_button').click();
51 51
  }
52

  
53
  ns.update_tax_ids = function(obj) {
54
    var row = $(obj).attr('name').replace(/.*_/, '');
55

  
56
    $.ajax({
57
      url: 'io.pl?action=get_taxes_dropdown',
58
      data: { chart_id:          $(obj).val(),
59
              transdate:         $('#transdate').val(),
60
              deliverydate:      $('#deliverydate').val() },
61
              item_deliverydate: $("[name='reqdate_" + row + "']").val(), // has no id
62
      dataType: 'html',
63
      success: function (new_html) {
64
        $("#tax_id_" + row).html(new_html);
65
      }
66
    });
67
  };
52 68
});
templates/design40_webpages/ir/update_taxes.html
1
[% USE L %][%- USE LxERP -%]
2
[% FOR row = TAXES %]
3
<option value='[% row.id %]'[% IF row.is_default %] selected[% END %]>[% row.taxkey _ " - " _ row.taxdescription %] [% LxERP.round_amount(row.rate * 100) %] %</option>
4
[% END %]
templates/webpages/ir/update_taxes.html
1
[% USE L %][%- USE LxERP -%]
2
[% FOR row = TAXES %]
3
<option value='[% row.id %]'[% IF row.is_default %] selected[% END %]>[% row.taxkey _ " - " _ row.taxdescription %] [% LxERP.round_amount(row.rate * 100) %] %</option>
4
[% END %]

Auch abrufbar als: Unified diff