From: G. Richardson Date: Mon, 17 Oct 2016 15:16:12 +0000 (+0200) Subject: Neue OrderItem Methoden X-Git-Tag: release-3.5.4~1993 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=8a3f13c32ee7b9f65d6a06d1330cfc983e51594e;p=kivitendo-erp.git Neue OrderItem Methoden für Verknüpfungen per RecordLinks zu DeliveryOrderItem. --- diff --git a/SL/DB/OrderItem.pm b/SL/DB/OrderItem.pm index 5fcb8be2a..d46fdcc36 100644 --- a/SL/DB/OrderItem.pm +++ b/SL/DB/OrderItem.pm @@ -40,6 +40,75 @@ sub shipped_qty { return sum(map { AM->convert_unit($_->unit => $self->unit) * $_->qty } @doi); } +sub linked_delivery_order_items { + my ($self) = @_; + + return $self->linked_records(direction => 'to', to => 'SL::DB::DeliveryOrderItem'); +} + +sub delivered_qty { + # checks for delivery_order_stock_id entries, which have been converted to inventory entries + # uses several rose relationships + # doesn't differentiate between sales and orders + + my ($self) = @_; + my $delivered_qty = 0; + foreach my $doi ( @{$self->linked_delivery_order_items} ) { + next unless scalar @{$doi->delivery_order_stock_entries}; + $delivered_qty += sum map { $_->inventory ? $_->qty : 0 } @{$doi->delivery_order_stock_entries}; + }; + return $delivered_qty; +}; + +sub delivered_qty_sql { + # checks for delivery_order_stock_id entries, which have been converted to inventory entries + my ($self) = @_; + +my $query = <db->dbh, $query, $self->id); + + return $delivered_qty; +}; + +sub delivered_qty_sql_multi { + # checks for delivery_order_stock_id entries, which have been converted to inventory entries + my ($self) = @_; + +my $query = <db->dbh, $query, $self->id); + + return $delivered_qty; +}; + sub record { goto &order } 1; @@ -58,12 +127,37 @@ SL::DB::OrderItems: Rose model for orderitems =item C +=item C + returns the number of orderitems which are already linked to Delivery Orders. The linked key is parts_id and not orderitems (id) -> delivery_order_items (id). Therefore this function is not safe for identical parts_id. Sample call: C<$::form-Eformat_amount(\%::myconfig, $_[0]-Eshipped_qty);> +=item C + +Returns the amount of this orderitem that has been delivered, meaning it +appears in a delivery order AND has been transferred. The delivery order items +are found by direct record_links from orderitems to delivery order items. +Delivery order items that were added manually and not via the record workflow +will therefore not be calculated correctly. + +Orders that were created before the individual items were linked (this feature +was added in kivitendo 3.2.0) will therefore return incorrect results. + +=item C + +Does the same as delivered_qty, but via sql. + + + +=item C + +Returns the amount of the orderitem that has actually been shipped, not just where delivery_order_items exist (how delivered_qty works). + +Doesn't deal with different units yet. + =back =head1 TODO @@ -85,6 +179,10 @@ return $self-E_delivered_qty; In general the function C and all (project) related functions should be marked deprecate, because of the better linked item to item data in the record_links table. +=head1 AUTHORS + +G. Richardson Egrichardson@kivitendo-premium.deE +=cut