Revision e13733db
Von Tamino Steinert vor etwa 1 Jahr hinzugefügt
SL/DB/Manager/Part.pm | ||
---|---|---|
90 | 90 |
return %qty_by_id; |
91 | 91 |
} |
92 | 92 |
|
93 |
sub get_open_ordered_qty { |
|
94 |
my $class = shift; |
|
95 |
my $part_id = shift; |
|
96 |
return () unless $part_id; |
|
97 |
|
|
98 |
my $query = <<SQL; |
|
99 |
WITH |
|
100 |
open_qty AS ( |
|
101 |
SELECT parts_id, sum(oi.qty) as sum |
|
102 |
FROM orderitems oi |
|
103 |
LEFT OUTER JOIN oe o ON (oi.trans_id = o.id) |
|
104 |
WHERE |
|
105 |
oi.parts_id = ? |
|
106 |
AND (NOT COALESCE(o.quotation, FALSE)) |
|
107 |
AND (NOT COALESCE(o.closed, FALSE)) |
|
108 |
AND (NOT COALESCE(o.delivered, FALSE)) |
|
109 |
AND (COALESCE(o.vendor_id, 0) <> 0) |
|
110 |
GROUP BY oi.parts_id |
|
111 |
), |
|
112 |
|
|
113 |
open_orderitems_ids AS ( |
|
114 |
SELECT oi.id, parts_id |
|
115 |
FROM orderitems oi |
|
116 |
LEFT OUTER JOIN oe o ON (oi.trans_id = o.id) |
|
117 |
WHERE |
|
118 |
oi.parts_id = ? |
|
119 |
AND (NOT COALESCE(o.quotation, FALSE)) |
|
120 |
AND (NOT COALESCE(o.closed, FALSE)) |
|
121 |
AND (NOT COALESCE(o.delivered, FALSE)) |
|
122 |
AND (o.vendor_id is not null) |
|
123 |
), |
|
124 |
|
|
125 |
delivered_qty AS ( |
|
126 |
SELECT parts_id, sum(qty) AS sum |
|
127 |
FROM delivery_order_items |
|
128 |
WHERE id IN ( |
|
129 |
SELECT to_id from record_links |
|
130 |
WHERE |
|
131 |
from_id IN ( SELECT id FROM open_orderitems_ids) |
|
132 |
AND from_table = 'orderitems' |
|
133 |
AND to_table = 'delivery_order_items' |
|
134 |
) AND parts_id = ? |
|
135 |
GROUP BY parts_id |
|
136 |
), |
|
137 |
|
|
138 |
open_ordered_qty AS ( |
|
139 |
SELECT |
|
140 |
oq.parts_id, |
|
141 |
oq.sum AS ordered_sum, |
|
142 |
COALESCE(dq.sum,0.00) AS sum, |
|
143 |
sum(COALESCE(oq.sum,0.00) - COALESCE(dq.sum,0.00)) AS open_qty |
|
144 |
FROM open_qty oq |
|
145 |
LEFT JOIN delivered_qty dq ON dq.parts_id = oq.parts_id |
|
146 |
GROUP BY oq.parts_id, oq.sum, dq.sum |
|
147 |
) |
|
148 |
|
|
149 |
SELECT open_qty FROM open_ordered_qty |
|
150 |
|
|
151 |
SQL |
|
152 |
|
|
153 |
my ($open_qty) = selectfirst_array_query( |
|
154 |
$::form, $class->object_class->init_db->dbh, |
|
155 |
$query, $part_id, $part_id, $part_id |
|
156 |
); |
|
157 |
|
|
158 |
$open_qty ||= 0; |
|
159 |
return $open_qty |
|
160 |
} |
|
161 |
|
|
93 | 162 |
sub _sort_spec { |
94 | 163 |
( |
95 | 164 |
default => [ 'partnumber', 1 ], |
Auch abrufbar als: Unified diff
Part: um Helferfunktionen für den Warenstand erweitert