my $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,
+ exchangerate => $self->order->daily_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 $form_exchangerate_as_null_number = delete $::form->{order}->{exchangerate_as_null_number};
$order->assign_attributes(%{$::form->{order}});
$periodic_invoices_config->assign_attributes(%$periodic_invoices_config_attrs);
}
- # set exchangerate after transdate and currency_id
- $order->assign_attributes(exchangerate_as_null_number => $form_exchangerate_as_null_number) if $order->currency_id;
-
# remove deleted items
$self->item_ids_to_delete([]);
foreach my $idx (reverse 0..$#{$order->orderitems}) {
($vc eq 'customer')? 'c_vendor_id': 'v_customer_id');
my @vc_prefixed_fields = qw(email fax notes number phone);
- _copy($self, $form, '', '', 1, qw(amount netamount marge_total marge_percent container_remaining_weight container_remaining_volume paid));
+ _copy($self, $form, '', '', 1, qw(amount netamount marge_total marge_percent container_remaining_weight container_remaining_volume paid exchangerate));
_copy($self->$vc, $form, '', '', 0, @vc_fields);
_copy($self->$vc, $form, $vc, '', 0, @vc_prefixed_fields);
_copy($self->contact, $form, '', '', 0, grep { /^cp_/ } map { $_->name } SL::DB::Contact->meta->columns) if _has($self, 'cp_id');
}
my %args = ( map({ ( $_ => $source->$_ ) } qw(amount cp_id currency_id cusordnumber customer_id delivery_customer_id delivery_term_id delivery_vendor_id
- department_id employee_id globalproject_id intnotes marge_percent marge_total language_id netamount notes
+ department_id employee_id exchangerate globalproject_id intnotes marge_percent marge_total language_id netamount notes
ordnumber payment_id quonumber reqdate salesman_id shippingpoint shipvia taxincluded taxzone_id
transaction_description vendor_id
)),
}
foreach my $attr (qw(cp_id currency_id employee_id salesman_id department_id
delivery_customer_id delivery_vendor_id shipto_id
- globalproject_id)) {
+ globalproject_id exchangerate)) {
$attributes{$attr} = undef if any { ($sources->[0]->$attr||0) != ($_->$attr||0) } @$sources;
}
use SL::Presenter::Part;
use SL::DB::Contact;
+use SL::DB::Currency;
use SL::DB::Customer;
use SL::DB::Default;
use SL::DB::Language;
_order();
if ($::instance_conf->get_feature_experimental_order) {
+
+ # At this point, the record is saved and the exchangerate contains
+ # an unformatted value. _make_record uses RDBO attributes (i.e. _as_number)
+ # to assign values and thus expects an formatted value.
+ $::form->{exchangerate} = $::form->format_amount(\%::myconfig, $::form->{exchangerate});
+
my $order = _make_record();
- $order->globalproject_id(undef) if !$order->globalproject_id;
- $order->payment_id(undef) if !$order->payment_id;
+
+ $order->currency(SL::DB::Currency->new(name => $::form->{currency})->load) if $::form->{currency};
+ $order->globalproject_id(undef) if !$order->globalproject_id;
+ $order->payment_id(undef) if !$order->payment_id;
+
my $row = 1;
foreach my $item (@{$order->items_sorted}) {
$item->custom_variables([]);
$(event.target).val(kivi.format_amount(kivi.parse_amount($(event.target).val()), -2));
};
+ ns.reformat_number_as_null_number = function(event) {
+ if ($(event.target).val() === '') {
+ return;
+ }
+ ns.reformat_number(event);
+ };
+
ns.update_exchangerate = function(event) {
if (!ns.check_cv()) {
$('#order_currency_id').val($('#old_currency_id').val());
}
var rate_input = $('#order_exchangerate_as_null_number');
- rate_input.prop('disabled', true);
+ // unset exchangerate if currency changed
+ if ($('#order_currency_id').val() !== $('#old_currency_id').val()) {
+ rate_input.val('');
+ }
+
+ // only set exchangerate if unset
+ if (rate_input.val() !== '') {
+ return;
+ }
var data = $('#order_form').serializeArray();
data.push({ name: 'action', value: 'Order/update_exchangerate' });
success: function(data){
if (!data.is_standard) {
$('#currency_name').text(data.currency_name);
- var rate_text = $('#exchangerate_text');
if (data.exchangerate) {
- rate_text.text(data.exchangerate);
- rate_input.hide();
+ rate_input.val(data.exchangerate);
} else {
- rate_text.text('');
- rate_input.prop('disabled', false);
- rate_input.show().val('');
+ rate_input.val('');
}
$('#exchangerate_settings').show();
} else {
+ rate_input.val('');
$('#exchangerate_settings').hide();
}
if ($('#order_currency_id').val() != $('#old_currency_id').val() ||
return false;
});
+ $('.reformat_number_as_null_number').change(kivi.Order.reformat_number_as_null_number);
+
});
</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=currency_id, value_key='id', title_key='name') %]</td>
</tr>
- <tr id="exchangerate_settings" [%- IF currency_id==INSTANCE_CONF.get_currency_id %]style='display:none'[%- END %]>
+ <tr id="exchangerate_settings" [%- IF SELF.order.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 exchangerate %]
- [% HTML.escape(exchangerate) %]
- [% END %]
- </span>
- [% IF currency_id==INSTANCE_CONF.get_currency_id || SELF.order.exchangerate %]
- [% L.input_tag('order.exchangerate_as_null_number', '', size="15", class="reformat_number numeric", style='display:none', disabled=1) %]
- [% ELSE %]
- [% L.input_tag('order.exchangerate_as_null_number', '', size="15", class="reformat_number numeric") %]
- [% END %]
+ [% L.input_tag('order.exchangerate_as_null_number', SELF.order.exchangerate_as_null_number, size="15", class="reformat_number_as_null_number numeric") %]
[% INSTANCE_CONF.default_currency %]
[% L.hidden_tag('old_currency_id', currency_id) %]
- [% L.hidden_tag('old_exchangerate', exchangerate) %]
+ [% L.hidden_tag('old_exchangerate', SELF.order.exchangerate_as_null_number) %]
</td>
</tr>