sub action_update_exchangerate {
my ($self) = @_;
my $data = {};
- if ($self->order->currency_id != $::instance_conf->get_currency_id) {
- $data = {
- currency_name => $self->order->currency->name,
- exchangerate => $self->order->exchangerate_as_number,
- };
- }
+
+ $data = {
+ is_standard => $self->order->currency_id == $::instance_conf->get_currency_id,
+ currency_name => $self->order->currency->name,
+ exchangerate => $self->order->exchangerate_as_null_number,
+ };
+
$self->render(\SL::JSON::to_json($data), { type => 'json', process => 0 });
}
my $form_orderitems = delete $::form->{order}->{orderitems};
my $form_periodic_invoices_config = delete $::form->{order}->{periodic_invoices_config};
- my $exchangerate = delete $::form->{order}->{exchangerate};
+ my $exchangerate_as_null_number = delete $::form->{order}->{exchangerate_as_null_number};
$order->assign_attributes(%{$::form->{order}});
}
# set exchangerate after transdate and currency_id
- $order->assign_attributes(exchangerate => $exchangerate);
+ $order->assign_attributes(exchangerate_as_null_number => $exchangerate_as_null_number) if $order->currency_id;
# remove deleted items
$self->item_ids_to_delete([]);
use SL::DB::Helper::PriceTaxCalculator;
use SL::DB::Helper::PriceUpdater;
use SL::DB::Helper::TransNumberGenerator;
+use SL::Locale::String qw(t8);
use SL::RecordLinks;
use Rose::DB::Object::Helpers qw(as_tree);
return 1 if $self->currency_id == $::instance_conf->get_currency_id;
+ # unable to determine if sales or purchase
+ return undef if !$self->has_customervendor;
+
my $rate = $self->is_sales ? 'buy' : 'sell';
if (defined $val) {
- croak 'exchange rate has to be positive' if $val <= 0;
+ croak t8('exchange rate has to be positive') if $val <= 0;
if (!$self->exchangerate_obj) {
$self->exchangerate_obj(SL::DB::Exchangerate->new(
currency_id => $self->currency_id,
} elsif (!defined $self->exchangerate_obj->$rate) {
$self->exchangerate_obj->$rate($val);
} else {
- croak 'exchange rate already exists, no update allowed';
+ croak t8('exchange rate already exists, no update allowed');
}
}
return $self->exchangerate_obj->$rate if $self->exchangerate_obj;
};
ns.update_exchangerate = function(event) {
- var rate_input = $('#order_exchangerate_as_number');
- rate_input.attr('name', '');
+ var rate_input = $('#order_exchangerate_as_null_number');
+ rate_input.prop('disabled', true);
var data = $('#order_form').serializeArray();
data.push({ name: 'action', value: 'Order/update_exchangerate' });
method: 'POST',
dataType: 'json',
success: function(data){
- if (data.currency_name) {
+ if (!data.is_standard) {
$('#currency_name').text(data.currency_name);
var rate_text = $('#exchangerate_text');
if (data.exchangerate) {
rate_input.hide();
} else {
rate_text.text('');
- rate_input.show().attr('name', rate_input.data('name')).val(0);
+ rate_input.prop('disabled', false);
+ rate_input.show().val(0);
}
$('#exchangerate_settings').show();
} else {
$('#exchangerate_settings').hide();
}
- if ($('#order_currency_id').val() != $('#old_currency_id').val() || data.exchangerate != $('#old_exchangerate').val()) {
+ console.log(data.is_standard);
+ console.log(data.exchangerate);
+ console.log($('#old_exchangerate').val());
+ if ($('#order_currency_id').val() != $('#old_currency_id').val() ||
+ !data.is_standard && data.exchangerate != $('#old_exchangerate').val()) {
kivi.display_flash('warning', kivi.t8('You have changed the currency or exchange rate. Please update prices.'));
}
$('#old_currency_id').val($('#order_currency_id').val());
};
ns.exchangerate_changed = function(event) {
- if (kivi.parse_amount($('#order_exchangerate_as_number').val()) != kivi.parse_amount($('#old_exchangerate').val())) {
+ if (kivi.parse_amount($('#order_exchangerate_as_null_number').val()) != kivi.parse_amount($('#old_exchangerate').val())) {
kivi.display_flash('warning', kivi.t8('You have changed the currency or exchange rate. Please update prices.'));
- $('#old_exchangerate').val($('#order_exchangerate_as_number').val());
+ $('#old_exchangerate').val($('#order_exchangerate_as_null_number').val());
}
};
$('#order_currency_id').change(kivi.Order.update_exchangerate);
$('#order_transdate_as_date').change(kivi.Order.update_exchangerate);
- $('#order_exchangerate_as_number').change(kivi.Order.exchangerate_changed);
+ $('#order_exchangerate_as_null_number').change(kivi.Order.exchangerate_changed);
if ($('#type').val() == 'sales_order' || $('#type').val() == 'sales_quotation' ) {
$('#add_item_parts_id').on('set_item:PartPicker', function(e,o) { $('#add_item_sellprice_as_number').val(kivi.format_amount(o.sellprice, -2)) });
'error while unlinking payment #1 : ' => 'Fehler beim Zurücksetzen von Zahlung #1:',
'every third month' => 'vierteljährlich',
'every time' => 'immer',
+ 'exchange rate already exists, no update allowed' => 'Wechselkurs existiert bereits und kann nicht geändert werden',
+ 'exchange rate has to be positive' => 'Wechselkurs muss positiv sein',
'executed' => 'ausgeführt',
'execution as user \'#1\'' => 'Ausführung als User »#1«',
'failed' => 'fehlgeschlagen',
<td>[% L.select_tag('order.taxzone_id', SELF.all_taxzones, default=SELF.order.taxzone_id, title_key='description', style='width: 300px', class='recalc') %]</td>
</tr>
+ [% SET currency_id = SELF.order.currency_id || INSTANCE_CONF.get_currency_id # use default currency for new order %]
+ [% IF SELF.order.exchangerate %]
+ [% SET exchangerate = SELF.order.exchangerate_as_null_number %]
+ [% END %]
<tr id="currency_settings">
<th align="right">[% 'Currency' | $T8 %]</th>
- <td>[% L.select_tag('order.currency_id', SELF.all_currencies, default=SELF.order.currency_id, value_key='id', title_key='name') %]</td>
+ <td>[% L.select_tag('order.currency_id', SELF.all_currencies, default=currency_id, value_key='id', title_key='name') %]</td>
</tr>
- <tr id="exchangerate_settings" [%- IF !SELF.order.currency_id || SELF.order.currency_id==INSTANCE_CONF.get_currency_id %]style='display:none'[%- END %]>
+ <tr id="exchangerate_settings" [%- IF currency_id==INSTANCE_CONF.get_currency_id %]style='display:none'[%- END %]>
<th align="right">[% 'Exchangerate' | $T8 %]</th>
<td> 1 <span id="currency_name">[% SELF.order.currency.name %]</span> =
<span id="exchangerate_text">
- [% IF SELF.order.exchangerate %]
- [% HTML.escape(SELF.order.exchangerate_as_number) %]
+ [% IF exchangerate %]
+ [% HTML.escape(exchangerate) %]
[% END %]
</span>
- [% IF !SELF.order.currency_id || SELF.order.currency_id==INSTANCE_CONF.get_currency_id || SELF.order.exchangerate %]
- [% L.input_tag('', '', size="15", id='order_exchangerate_as_number', 'data-name'='order.exchangerate_as_number', style='display:none') %]
+ [% IF currency_id==INSTANCE_CONF.get_currency_id || SELF.order.exchangerate %]
+ [% L.input_tag('order.exchangerate_as_null_number', '', size="15", style='display:none', disabled=1) %]
[% ELSE %]
- [% L.input_tag('order.exchangerate_as_number', 0, size="15") %]
+ [% L.input_tag('order.exchangerate_as_null_number', 0, size="15") %]
[% END %]
[% INSTANCE_CONF.default_currency %]
- [% L.hidden_tag('old_currency_id', SELF.order.currency_id) %]
- [% L.hidden_tag('old_exchangerate', SELF.order.exchangerate_as_number) %]
+ [% L.hidden_tag('old_currency_id', currency_id) %]
+ [% L.hidden_tag('old_exchangerate', exchangerate) %]
</td>
</tr>