Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 4b1666b7

Von Felix Eichler vor mehr als 4 Jahren hinzugefügt

  • ID 4b1666b74b0fa70077c64144a57526a1d64b4e64
  • Vorgänger 59626ee2
  • Nachfolger 82098575

Auftragsschnellerfassung: Währung und Wechselkurs definierbar

impl. #9491

(cherry picked from commit 6cdc5a4a33df4530ce4e141151e83138320e27a2)
(cherry pick von odyn)

Unterschiede anzeigen:

SL/Controller/Order.pm
926 926
  $self->js->render();
927 927
}
928 928

  
929
sub action_update_exchangerate {
930
  my ($self) = @_;
931
  my $data = {};
932
  if ($self->order->currency_id != $::instance_conf->get_currency_id) {
933
    $data = {
934
      currency_name => $self->order->currency->name,
935
      exchangerate  => $self->order->exchangerate_as_number,
936
    };
937
  }
938
  $self->render(\SL::JSON::to_json($data), { type => 'json', process => 0 });
939
}
940

  
929 941
# redisplay item rows if they are sorted by an attribute
930 942
sub action_reorder_items {
931 943
  my ($self) = @_;
......
1509 1521
sub recalc {
1510 1522
  my ($self) = @_;
1511 1523

  
1512
  # bb: todo: currency later
1513
  $self->order->currency_id($::instance_conf->get_currency_id());
1524
  $self->order->currency_id($::instance_conf->get_currency_id()) unless $self->order->currency_id;
1514 1525

  
1515 1526
  my %pat = $self->order->calculate_prices_and_taxes();
1516 1527

  
......
1657 1668
  my ($self) = @_;
1658 1669

  
1659 1670
  $self->{all_taxzones}               = SL::DB::Manager::TaxZone->get_all_sorted();
1671
  $self->{all_currencies}             = SL::DB::Manager::Currency->get_all_sorted();
1660 1672
  $self->{all_departments}            = SL::DB::Manager::Department->get_all_sorted();
1661 1673
  $self->{all_employees}              = SL::DB::Manager::Employee->get_all(where => [ or => [ id => $self->order->employee_id,
1662 1674
                                                                                              deleted => 0 ] ],
SL/DB/Order.pm
10 10

  
11 11
use SL::DB::MetaSetup::Order;
12 12
use SL::DB::Manager::Order;
13
use SL::DB::Helper::Attr;
13 14
use SL::DB::Helper::AttrHTML;
14 15
use SL::DB::Helper::AttrSorted;
15 16
use SL::DB::Helper::FlattenToForm;
......
40 41
    column_map             => { id => 'trans_id' },
41 42
    query_args             => [ module => 'OE' ],
42 43
  },
44
  exchangerate_obj         => {
45
    type                   => 'one to one',
46
    class                  => 'SL::DB::Exchangerate',
47
    column_map             => { currency_id => 'currency_id', transdate => 'transdate' },
48
  },
43 49
);
44 50

  
51
SL::DB::Helper::Attr::make(__PACKAGE__, exchangerate => 'numeric');
52

  
45 53
__PACKAGE__->meta->initialize;
46 54

  
47 55
__PACKAGE__->attr_html('notes');
......
111 119
  return !!shift->customer_id;
112 120
}
113 121

  
122
sub exchangerate {
123
  my ($self, $val) = @_;
124

  
125
  return 1 if $self->currency_id == $::instance_conf->get_currency_id;
126

  
127
  my $rate = $self->is_sales ? 'buy' : 'sell';
128

  
129
  if (defined $val) {
130
    croak 'exchange rate has to be positive' if $val <= 0;
131
    if (!$self->exchangerate_obj) {
132
      $self->exchangerate_obj(SL::DB::Exchangerate->new(
133
        currency_id => $self->currency_id,
134
        transdate   => $self->transdate,
135
        $rate       => $val,
136
      ));
137
    } elsif (!defined $self->exchangerate_obj->$rate) {
138
      $self->exchangerate_obj->$rate($val);
139
    } else {
140
      croak 'exchange rate already exists, no update allowed';
141
    }
142
  }
143
  return $self->exchangerate_obj->$rate if $self->exchangerate_obj;
144
}
145

  
114 146
sub invoices {
115 147
  my $self   = shift;
116 148
  my %params = @_;
js/kivi.Order.js
174 174
    $(event.target).val(kivi.format_amount(kivi.parse_amount($(event.target).val()), -2));
175 175
  };
176 176

  
177
  ns.update_exchangerate = function(event) {
178
    var rate_input = $('#order_exchangerate_as_number');
179
    rate_input.attr('name', '');
180

  
181
    var data = $('#order_form').serializeArray();
182
    data.push({ name: 'action', value: 'Order/update_exchangerate' });
183

  
184
    $.ajax({
185
      url: 'controller.pl',
186
      data: data,
187
      method: 'POST',
188
      dataType: 'json',
189
      success: function(data){
190
        if (data.currency_name) {
191
          $('#currency_name').text(data.currency_name);
192
          var rate_text = $('#exchangerate_text');
193
          if (data.exchangerate) {
194
            rate_text.text(data.exchangerate);
195
            rate_input.hide();
196
          } else {
197
            rate_text.text('');
198
            rate_input.show().attr('name', rate_input.data('name')).val(0);
199
          }
200
          $('#exchangerate_settings').show();
201
        } else {
202
          $('#exchangerate_settings').hide();
203
        }
204
        if ($('#order_currency_id').val() != $('#old_currency_id').val() || data.exchangerate != $('#old_exchangerate').val()) {
205
          kivi.display_flash('warning', kivi.t8('You have changed the currency. Please update prices.'));
206
        }
207
        $('#old_currency_id').val($('#order_currency_id').val());
208
        $('#old_exchangerate').val(data.exchangerate);
209
      }
210
    });
211
  };
212

  
177 213
  ns.recalc_amounts_and_taxes = function() {
178 214
    var data = $('#order_form').serializeArray();
179 215
    data.push({ name: 'action', value: 'Order/recalc_amounts_and_taxes' });
......
792 828
    $('#order_vendor_id').change(kivi.Order.reload_cv_dependent_selections);
793 829
  }
794 830

  
831
  $('#order_currency_id').change(kivi.Order.update_exchangerate);
832
  $('#order_transdate').change(kivi.Order.update_exchangerate);
833

  
795 834
  if ($('#type').val() == 'sales_order' || $('#type').val() == 'sales_quotation' ) {
796 835
    $('#add_item_parts_id').on('set_item:PartPicker', function(e,o) { $('#add_item_sellprice_as_number').val(kivi.format_amount(o.sellprice, -2)) });
797 836
  } else {
js/locale/de.js
143 143
"Wrong number format (#1)":"Falsches Zahlenformat (#1)",
144 144
"Wrong time format (#1)":"Falsches Zeitformat (#1)",
145 145
"Yes":"Ja",
146
"You have changed the currency. Please update prices.":"Währungswechsel/Kurswechsel haben Einfluss auf den Preis der Position. Überprüfen Sie diesen oder aktualisieren Sie den Preis über \"Artikel aktualisieren\".",
146 147
"filename has not uploadable characters ":"Bitte Dateinamen ändern. Er hat für den Upload nicht verwendbare Sonderzeichen ",
147 148
"filesize too big: ":"Datei zu groß: ",
148 149
"flat-rate position":"Pauschalposition",
js/locale/en.js
143 143
"Wrong number format (#1)":"",
144 144
"Wrong time format (#1)":"",
145 145
"Yes":"",
146
"You have changed the currency. Please update prices.":"",
146 147
"filename has not uploadable characters ":"",
147 148
"filesize too big: ":"",
148 149
"flat-rate position":"",
templates/webpages/order/tabs/basic_data.html
49 49
            <td>[% L.select_tag('order.taxzone_id', SELF.all_taxzones, default=SELF.order.taxzone_id, title_key='description', style='width: 300px', class='recalc') %]</td>
50 50
          </tr>
51 51

  
52
          <tr id="currency_settings">
53
            <th align="right">[% 'Currency' | $T8 %]</th>
54
            <td>[% L.select_tag('order.currency_id', SELF.all_currencies, default=SELF.order.currency_id, value_key='id', title_key='name') %]</td>
55
          </tr>
56
          <tr id="exchangerate_settings" [%- IF !SELF.order.currency_id || SELF.order.currency_id==INSTANCE_CONF.get_currency_id %]style='display:none'[%- END %]>
57
            <th align="right">[% 'Exchangerate' | $T8 %]</th>
58
            <td> 1 <span id="currency_name">[% SELF.order.currency.name %]</span> =
59
              <span id="exchangerate_text">
60
              [% IF SELF.order.exchangerate %]
61
                [% HTML.escape(SELF.order.exchangerate_as_number) %]
62
              [% END %]
63
              </span>
64
              [% IF !SELF.order.currency_id || SELF.order.currency_id==INSTANCE_CONF.get_currency_id || SELF.order.exchangerate %]
65
                [% L.input_tag('', '', size="15", id='order_exchangerate_as_number', 'data-name'='order.exchangerate_as_number', style='display:none') %]
66
              [% ELSE %]
67
                [% L.input_tag('order.exchangerate_as_number', 0, size="15") %]
68
              [% END %]
69
              [% INSTANCE_CONF.default_currency %]
70
              [% L.hidden_tag('old_currency_id', SELF.order.currency_id) %]
71
              [% L.hidden_tag('old_exchangerate', SELF.order.exchangerate_as_number) %]
72
            </td>
73
          </tr>
74

  
52 75
[%- IF SELF.all_departments.size %]
53 76
          <tr>
54 77
            <th align="right">[% 'Department' | $T8 %]</th>

Auch abrufbar als: Unified diff