- my $query = <<SQL;
- SELECT oi.id, doi.qty, doi.qty, doi.unit, doe.delivered, doe.closed, -- dois.qty as qty_stocked,
- oi.sellprice, oi.discount, oi.price_factor
- FROM record_links rl
- INNER JOIN delivery_order_items doi ON (doi.id = rl.to_id)
- INNER JOIN orderitems oi ON (oi.id = rl.from_id)
- INNER JOIN delivery_orders doe ON (doe.id = doi.delivery_order_id)
- --INNER JOIN delivery_order_items_stock dois ON (doi.id = dois.delivery_order_item_id)
- WHERE rl.from_table = 'orderitems'
- AND rl.to_table = 'delivery_order_items'
- AND oi.id IN (@{[ join ', ', ("?")x @$orderitems ]})
-SQL
-
- my $result = SL::DBUtils::selectall_hashref_query($::form, $::form->get_standard_dbh, $query, map { $_->id } @$orderitems);
-
- for my $row (@$result) {
- my $item = $orderitems_by_id{ $row->{id} };
- $item->{shipped_qty} ||= 0;
- $item->{delivered_qty} ||= 0;
- $item->{do_closed_qty} ||= 0;
- $item->{shipped_qty} += AM->convert_unit($row->{unit} => $item->unit) * $row->{qty} unless ($row->{delivered} || $row->{closed});
- $item->{delivered_qty} += AM->convert_unit($row->{unit} => $item->unit) * $row->{qty} if ($row->{delivered} && !$row->{closed});
- $item->{do_closed_qty} += AM->convert_unit($row->{unit} => $item->unit) * $row->{qty} if ($row->{closed});
- #$item->{do_closed_qty} += AM->convert_unit($row->{unit} => $item->unit) * $row->{qty_stocked} if ($row->{closed});
- $item->{not_shipped_qty} += AM->convert_unit($row->{unit} => $item->unit) * $row->{qty} unless ($row->{delivered});
- # my $price_factor = $self->price_factor || 1;
- #$self->_delivered_qty;
- #$item->{netto_qty} += $row->{qty} * $row->{sellprice} * (1 - $row->{discount} ) / ($row->{price_factor} || 1);
- # no sum
- $item->{netto_shipped_qty} = $item->{shipped_qty} * $row->{sellprice} * (1 - $row->{discount} ) / ($row->{price_factor} || 1);
-# $item->{netto_not_shipped_qty} += $item->{shipped_qty} * $row->{sellprice} * (1 - $row->{discount} ) / ($row->{price_factor} || 1);
- $item->{netto_delivered_qty} = $item->{delivered_qty} * $row->{sellprice} * (1 - $row->{discount} ) / ($row->{price_factor} || 1);
- $item->{netto_do_closed_qty} = $item->{do_closed_qty} * $row->{sellprice} * (1 - $row->{discount} ) / ($row->{price_factor} || 1);