Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 8a3f13c3

Von Kivitendo Admin vor etwa 8 Jahren hinzugefügt

  • ID 8a3f13c32ee7b9f65d6a06d1330cfc983e51594e
  • Vorgänger fd3d9c3c
  • Nachfolger 201c9038

Neue OrderItem Methoden

für Verknüpfungen per RecordLinks zu DeliveryOrderItem.

Unterschiede anzeigen:

SL/DB/OrderItem.pm
40 40
  return sum(map { AM->convert_unit($_->unit => $self->unit) * $_->qty } @doi);
41 41
}
42 42

  
43
sub linked_delivery_order_items {
44
  my ($self) = @_;
45

  
46
  return $self->linked_records(direction => 'to', to => 'SL::DB::DeliveryOrderItem');
47
}
48

  
49
sub delivered_qty {
50
  # checks for delivery_order_stock_id entries, which have been converted to inventory entries
51
  # uses several rose relationships
52
  # doesn't differentiate between sales and orders
53

  
54
  my ($self) = @_;
55
  my $delivered_qty = 0;
56
  foreach my $doi ( @{$self->linked_delivery_order_items} ) {
57
    next unless scalar @{$doi->delivery_order_stock_entries};
58
    $delivered_qty += sum map { $_->inventory ? $_->qty : 0 } @{$doi->delivery_order_stock_entries};
59
  };
60
  return $delivered_qty;
61
};
62

  
63
sub delivered_qty_sql {
64
  # checks for delivery_order_stock_id entries, which have been converted to inventory entries
65
  my ($self) = @_;
66

  
67
my $query = <<SQL;
68
SELECT (sum(i.qty) * CASE WHEN oe.customer_id IS NULL THEN 1 ELSE -1 END) AS delivered
69
 FROM orderitems oi
70
 INNER JOIN record_links rl                 ON (    oi.id             = rl.FROM_id
71
                                                and rl.FROM_table     = 'orderitems'
72
                                                and rl.to_table::text = 'delivery_order_items'::text
73
                                               )
74
 INNER JOIN delivery_order_items doi        ON (doi.id =rl.to_id)
75
 INNER JOIN delivery_order_items_stock dois ON (dois.delivery_order_item_id = doi.id)
76
 INNER JOIN inventory i                     ON (dois.id = i.delivery_order_items_stock_id)
77
 INNER JOIN oe                              ON (oe.id = oi.trans_id)
78
 WHERE oi.id = ?
79
 GROUP BY oi.id, oe.id
80
SQL
81
  my ($delivered_qty) = selectfirst_array_query($::form, $self->db->dbh, $query, $self->id);
82

  
83
  return $delivered_qty;
84
};
85

  
86
sub delivered_qty_sql_multi {
87
  # checks for delivery_order_stock_id entries, which have been converted to inventory entries
88
  my ($self) = @_;
89

  
90
my $query = <<SQL;
91
SELECT sum(dois.qty) from delivery_order_items_stock dois
92
  LEFT OUTER JOIN inventory i ON (dois.id = i.delivery_order_items_stock_id)
93
WHERE
94
  dois.delivery_order_item_id in (
95
SELECT
96
  to_id
97
FROM
98
  record_links
99
WHERE
100
  (
101
    from_id = in AND
102
    from_table = 'orderitems' AND
103
    to_table = 'delivery_order_items'
104
  )
105
)
106
SQL
107
  my ($delivered_qty) = selectfirst_array_query($::form, $self->db->dbh, $query, $self->id);
108

  
109
  return $delivered_qty;
110
};
111

  
43 112
sub record { goto &order }
44 113

  
45 114
1;
......
58 127

  
59 128
=item C<shipped_qty>
60 129

  
130
=item C<shipped_qty>
131

  
61 132
returns the number of orderitems which are already linked to Delivery Orders.
62 133
The linked key is parts_id and not orderitems (id) -> delivery_order_items (id).
63 134
Therefore this function is not safe for identical parts_id.
64 135
Sample call:
65 136
C<$::form-E<gt>format_amount(\%::myconfig, $_[0]-E<gt>shipped_qty);>
66 137

  
138
=item C<delivered_qty>
139

  
140
Returns the amount of this orderitem that has been delivered, meaning it
141
appears in a delivery order AND has been transferred. The delivery order items
142
are found by direct record_links from orderitems to delivery order items.
143
Delivery order items that were added manually and not via the record workflow
144
will therefore not be calculated correctly.
145

  
146
Orders that were created before the individual items were linked (this feature
147
was added in kivitendo 3.2.0) will therefore return incorrect results.
148

  
149
=item C<delivered_qty_sql>
150

  
151
Does the same as delivered_qty, but via sql.
152

  
153

  
154

  
155
=item C<delivered_qty_sql>
156

  
157
Returns the amount of the orderitem that has actually been shipped, not just where delivery_order_items exist (how delivered_qty works).
158

  
159
Doesn't deal with different units yet.
160

  
67 161
=back
68 162

  
69 163
=head1 TODO
......
85 179
In general the function C<shipped_qty> and all (project) related functions should be marked deprecate,
86 180
 because of the better linked item to item data in the record_links table.
87 181

  
182
=head1 AUTHORS
183

  
184
G. Richardson E<lt>grichardson@kivitendo-premium.deE<gt>
88 185

  
186
=cut
89 187

  
90 188

  

Auch abrufbar als: Unified diff