# safety
__PACKAGE__->run_before('check_auth');
-__PACKAGE__->run_before('recalc',
- only => [ qw(save save_as_new save_and_delivery_order save_and_invoice save_and_ap_transaction
- print send_email) ]);
-
__PACKAGE__->run_before('get_unalterable_data',
only => [ qw(save save_as_new save_and_delivery_order save_and_invoice save_and_ap_transaction
print send_email) ]);
$_->{render_second_row} = 1 for @{ $self->order->items_sorted };
}
- $self->recalc();
$self->pre_render();
$self->render(
'order/form',
my ($self) = @_;
setup_order_from_cv($self->order);
- $self->recalc();
my $cv_method = $self->cv;
->focus( '#order_' . $self->cv . '_id')
->run('kivi.Order.update_exchangerate');
- $self->js_redisplay_amounts_and_taxes;
$self->js_redisplay_cvpartnumbers;
$self->js->render();
}
my $old_unit_obj = SL::DB::Unit->new(name => $::form->{old_unit})->load;
$item->sellprice($item->unit_obj->convert_to($item->sellprice, $old_unit_obj));
- $self->recalc();
-
$self->js
->run('kivi.Order.update_sellprice', $::form->{item_id}, $item->sellprice_as_number);
$self->js_redisplay_line_values;
- $self->js_redisplay_amounts_and_taxes;
$self->js->render();
}
$self->order->add_items($item);
- $self->recalc();
-
$self->get_item_cvpartnumber($item);
my $item_id = join('_', 'new', Time::HiRes::gettimeofday(), int rand 1000000000000);
$item->discount(1) unless $assortment_item->charge;
$self->order->add_items( $item );
- $self->recalc();
$self->get_item_cvpartnumber($item);
my $item_id = join('_', 'new', Time::HiRes::gettimeofday(), int rand 1000000000000);
my $row_as_html = $self->p->render('order/tabs/_row',
$self->js->run('kivi.Order.row_table_scroll_down') if !$::form->{insert_before_item_id};
- $self->js_redisplay_amounts_and_taxes;
$self->js->render();
}
}
$self->order->add_items(@items);
- $self->recalc();
-
foreach my $item (@items) {
$self->get_item_cvpartnumber($item);
my $item_id = join('_', 'new', Time::HiRes::gettimeofday(), int rand 1000000000000);
$self->js->run('kivi.Order.row_table_scroll_down') if !$::form->{insert_before_item_id};
- $self->js_redisplay_amounts_and_taxes;
- $self->js->render();
-}
-
-# recalculate all linetotals, amounts and taxes and redisplay them
-sub action_recalc_amounts_and_taxes {
- my ($self) = @_;
-
- $self->recalc();
-
- $self->js_redisplay_line_values;
- $self->js_redisplay_amounts_and_taxes;
$self->js->render();
}
$item->{new_fake_id} = join('_', 'new', Time::HiRes::gettimeofday(), int rand 1000000000000);
}
- $self->recalc();
$self->get_unalterable_data();
$self->pre_render();
sub action_load_second_rows {
my ($self) = @_;
- $self->recalc() if $self->order->is_sales; # for margin calculation
-
foreach my $item_id (@{ $::form->{item_ids} }) {
my $idx = first_index { $_ eq $item_id } @{ $::form->{orderitem_ids} };
my $item = $self->order->items_sorted->[$idx];
}
}
- $self->recalc();
$self->js_redisplay_line_values;
- $self->js_redisplay_amounts_and_taxes;
$self->js->render();
}
->run('kivi.Order.redisplay_line_values', $is_sales, \@data);
}
-sub js_redisplay_amounts_and_taxes {
- my ($self) = @_;
-
- if (scalar @{ $self->{taxes} }) {
- $self->js->show('#taxincluded_row_id');
- } else {
- $self->js->hide('#taxincluded_row_id');
- }
-
- if ($self->order->taxincluded) {
- $self->js->hide('#subtotal_row_id');
- } else {
- $self->js->show('#subtotal_row_id');
- }
-
- if ($self->order->is_sales) {
- my $is_neg = $self->order->marge_total < 0;
- $self->js
- ->html('#marge_total_id', $::form->format_amount(\%::myconfig, $self->order->marge_total, 2))
- ->html('#marge_percent_id', $::form->format_amount(\%::myconfig, $self->order->marge_percent, 2))
- ->action_if( $is_neg, 'addClass', '#marge_total_id', 'plus0')
- ->action_if( $is_neg, 'addClass', '#marge_percent_id', 'plus0')
- ->action_if( $is_neg, 'addClass', '#marge_percent_sign_id', 'plus0')
- ->action_if(!$is_neg, 'removeClass', '#marge_total_id', 'plus0')
- ->action_if(!$is_neg, 'removeClass', '#marge_percent_id', 'plus0')
- ->action_if(!$is_neg, 'removeClass', '#marge_percent_sign_id', 'plus0');
- }
-
- $self->js
- ->html('#netamount_id', $::form->format_amount(\%::myconfig, $self->order->netamount, -2))
- ->html('#amount_id', $::form->format_amount(\%::myconfig, $self->order->amount, -2))
- ->remove('.tax_row')
- ->insertBefore($self->build_tax_rows, '#amount_row_id');
-}
-
sub js_redisplay_cvpartnumbers {
my ($self) = @_;
$_[0]->p->render('order/tabs/_business_info_row', SELF => $_[0]);
}
-# build the rows for displaying taxes
-#
-# Called if amounts where recalculated and redisplayed.
-sub build_tax_rows {
- my ($self) = @_;
-
- my $rows_as_html;
- foreach my $tax (sort { $a->{tax}->rate cmp $b->{tax}->rate } @{ $self->{taxes} }) {
- $rows_as_html .= $self->p->render('order/tabs/_tax_row', TAX => $tax, TAXINCLUDED => $self->order->taxincluded);
- }
- return $rows_as_html;
-}
-
sub render_price_dialog {
my ($self, $record_item) = @_;
}
}
-# recalculate prices and taxes
-#
-# Using the PriceTaxCalculator. Store linetotals in the item objects.
-sub recalc {
- my ($self) = @_;
-
- my %pat = $self->order->calculate_prices_and_taxes();
-
- $self->{taxes} = [];
- foreach my $tax_id (keys %{ $pat{taxes_by_tax_id} }) {
- my $netamount = sum0 map { $pat{amounts}->{$_}->{amount} } grep { $pat{amounts}->{$_}->{tax_id} == $tax_id } keys %{ $pat{amounts} };
-
- push(@{ $self->{taxes} }, { amount => $pat{taxes_by_tax_id}->{$tax_id},
- netamount => $netamount,
- tax => SL::DB::Tax->new(id => $tax_id)->load });
- }
- pairwise { $a->{linetotal} = $b->{linetotal} } @{$self->order->items_sorted}, @{$pat{items}};
-}
-
# get data for saving, printing, ..., that is not changed in the form
#
# Only cvars for now.
$self->cv ($self->init_cv);
$self->check_auth;
- $self->recalc();
$self->get_unalterable_data();
$self->pre_render();
$self->cv ($self->init_cv);
$self->check_auth;
- $self->recalc();
$self->get_unalterable_data();
$self->pre_render();
}
};
- ns.recalc_amounts_and_taxes = function() {
- var data = $('#order_form').serializeArray();
- data.push({ name: 'action', value: 'Order/recalc_amounts_and_taxes' });
-
- $.post("controller.pl", data, kivi.eval_json_result);
- };
-
ns.unit_change = function(event) {
var row = $(event.target).parents("tbody").first();
var item_id_dom = $(row).find('[name="orderitem_ids[+]"]');
};
ns.init_row_handlers = function() {
- kivi.run_once_for('.recalc', 'on_change_recalc', function(elt) {
- $(elt).change(ns.recalc_amounts_and_taxes);
- });
-
kivi.run_once_for('.reformat_number', 'on_change_reformat', function(elt) {
$(elt).change(ns.reformat_number);
});
$(row).remove();
ns.renumber_positions();
- ns.recalc_amounts_and_taxes();
};
ns.row_table_scroll_down = function() {
var html_elt = $(row).find('[name="sellprice_text"]');
price_elt.val(price_str);
html_elt.html(price_str);
- ns.recalc_amounts_and_taxes();
}
kivi.io.close_dialog();
var html_elt = $(row).find('[name="discount_text"]');
discount_elt.val(discount_str);
html_elt.html(discount_str);
- ns.recalc_amounts_and_taxes();
}
kivi.io.close_dialog();
[%- L.input_tag("order.orderitems[].qty_as_number",
ITEM.qty_as_number,
size = 5,
- class="recalc reformat_number numeric") %]
+ class="reformat_number numeric") %]
[%- IF ITEM.part.formel -%]
[%- L.button_tag("kivi.Order.show_calculate_qty_dialog(this)", LxERP.t8("*/")) %]
[%- L.hidden_tag("formula[+]", ITEM.part.formel) -%]
SELF.all_price_factors,
default = ITEM.price_factor_id,
title_key = 'description',
- with_empty = 1,
- class="recalc") %]
+ with_empty = 1) %]
</td>
<td nowrap>
[%- L.select_tag("order.orderitems[].unit",
ITEM.sellprice_as_number,
size = 10,
disabled=(EDIT_PRICE? '' : 1),
- class="recalc reformat_number numeric") %]
+ class="reformat_number numeric") %]
</div>
<div name="not_editable_price" [%- IF EDIT_PRICE %]style="display:none"[%- END %]>
[%- L.div_tag(ITEM.sellprice_as_number, name="sellprice_text", class="numeric") %]
ITEM.discount_as_percent,
size = 5,
disabled=(EDIT_DISCOUNT? '' : 1),
- class="recalc reformat_number numeric") %]
+ class="reformat_number numeric") %]
</div>
<div name="not_editable_discount" [%- IF EDIT_DISCOUNT %]style="display:none"[%- END %]>
[%- L.div_tag(ITEM.discount_as_percent, name="discount_text", class="numeric") %]
</table>
</td>
- [%- IF (SELF.type == "sales_order" || SELF.type == "sales_quotation") -%]
- [%- SET marge_class = (SELF.order.marge_total < 0) ? 'plus0' : '' -%]
- <td>
- <table>
- <tr>
- <th align="left">[% 'Ertrag' | $T8 %]</th>
- <td align="right">
- [%- L.div_tag(SELF.order.marge_total_as_number, id='marge_total_id', class=marge_class) %]
- </td>
- </tr>
- <tr>
- <th align="left">[% 'Ertrag prozentual' | $T8 %]</th>
- <td align="right">
- [%- L.div_tag(LxERP.format_amount(SELF.order.marge_percent, 2), id='marge_percent_id', class=marge_class) %]
- </td>
- <td>[%- L.div_tag('%', id='marge_percent_sign_id', class=marge_class) %]</td>
- </tr>
- </table>
- </td>
- [%- END %]
-
- <td align="right">
- <table>
- <tr id="taxincluded_row_id" [%- IF !SELF.taxes.size %]style="display:none"[%- END %]>
- <td align=right colspan="2">
- <label for="order.taxincluded"><b>[% 'Tax Included' | $T8 %]</b></label>
- [% L.yes_no_tag('order.taxincluded', SELF.order.taxincluded, class='recalc') %]
- </td>
- </tr>
-
- <tr id="subtotal_row_id" [%- IF SELF.order.taxincluded %]style="display:none"[%- END %]>
- <th align="right">[%- 'Subtotal' | $T8 %]</th>
- <td align="right">
- [%- L.div_tag(SELF.order.netamount_as_number, id='netamount_id') %]
- </td>
- </tr>
- [%- FOREACH tax = SELF.taxes %]
- [%- PROCESS order/tabs/_tax_row.html TAX=tax TAXINCLUDED=SELF.order.taxincluded %]
- [%- END %]
- <tr id="amount_row_id">
- <th align="right">[%- 'Total' | $T8 %]</th>
- <td align="right">
- [%- L.div_tag(SELF.order.amount_as_number, id='amount_id') %]
- </td>
- </tr>
- </table>
- </td>
-
</tr>
</table>
</td>