flash_later('info', $::locale->text('The order has been deleted'));
my @redirect_params = (
- action => 'edit',
+ action => 'add',
type => $self->type,
);
$self->redirect_to(@redirect_params);
}
-# set form elements in respect of a changed customer or vendor
+# set form elements in respect to a changed customer or vendor
#
# This action is called on an change of the customer/vendor picker.
sub action_customer_vendor_changed {
return unless $form_attr->{parts_id};
my $item = _new_item($self->order, $form_attr);
+
$self->order->add_items($item);
$self->_recalc();
);
$self->js
- ->append('#row_table_id', $row_as_html)
+ ->append('#row_table_id', $row_as_html);
+
+ if ( $item->part->is_assortment ) {
+ $form_attr->{qty_as_number} = 1 unless $form_attr->{qty_as_number};
+ foreach my $assortment_item ( @{$item->part->assortment_items} ) {
+ my $attr = { parts_id => $assortment_item->parts_id,
+ qty => $assortment_item->qty * $::form->parse_amount(\%::myconfig, $form_attr->{qty_as_number}), # TODO $form_attr->{unit}
+ unit => $assortment_item->unit,
+ description => $assortment_item->part->description,
+ };
+ my $item = _new_item($self->order, $attr);
+
+ # set discount to 100% if item isn't supposed to be charged, overwriting any customer discount
+ $item->discount(1) unless $assortment_item->charge;
+
+ $self->order->add_items( $item );
+ $self->_recalc();
+ my $item_id = join('_', 'new', Time::HiRes::gettimeofday(), int rand 1000000000000);
+ my $row_as_html = $self->p->render('order/tabs/_row',
+ ITEM => $item,
+ ID => $item_id,
+ ALL_PRICE_FACTORS => $self->all_price_factors
+ );
+ $self->js
+ ->append('#row_table_id', $row_as_html);
+ };
+ };
+
+ $self->js
->val('.add_item_input', '')
->run('kivi.Order.init_row_handlers')
->run('kivi.Order.row_table_scroll_down')
}
}
-# add item rows for multiple items add once
+# add item rows for multiple items at once
sub action_add_multi_items {
my ($self) = @_;
my @items;
foreach my $attr (@form_attr) {
- push @items, _new_item($self->order, $attr);
+ my $item = _new_item($self->order, $attr);
+ push @items, $item;
+ if ( $item->part->is_assortment ) {
+ foreach my $assortment_item ( @{$item->part->assortment_items} ) {
+ my $attr = { parts_id => $assortment_item->parts_id,
+ qty => $assortment_item->qty * $item->qty, # TODO $form_attr->{unit}
+ unit => $assortment_item->unit,
+ description => $assortment_item->part->description,
+ };
+ my $item = _new_item($self->order, $attr);
+
+ # set discount to 100% if item isn't supposed to be charged, overwriting any customer discount
+ $item->discount(1) unless $assortment_item->charge;
+ push @items, $assortment_item;
+ }
+ }
}
$self->order->add_items(@items);
$self->js->render();
}
-# redisplay item rows if the are sorted by an attribute
+# redisplay item rows if they are sorted by an attribute
sub action_reorder_items {
my ($self) = @_;
# longdescription was opened and the longdescription is empty
#
# If this item is new, get the longdescription from Part.
-# Get it from OrderItem else.
+# Otherwise get it from OrderItem.
sub action_get_item_longdescription {
my $longdescription;
$item->assign_attributes(%$attr);
$item->longdescription($item->part->notes) if $is_new && !defined $attr->{longdescription};
# item fields that currently can't be set in in row but are needed:
- $item->lastcost($item->part->lastcost);
+ $item->lastcost($item->part->lastcost) if $is_new;
return $item;
}
$item->unit($part->unit) if !$item->unit;
my $price_src;
- if ($item->sellprice) {
+ if ( $part->is_assortment ) {
+ # add assortment items with price 0, as the components carry the price
+ $price_src = $price_source->price_from_source("");
+ $price_src->price(0);
+ } elsif ($item->sellprice) {
$price_src = $price_source->price_from_source("");
$price_src->price($item->sellprice);
} else {