Revision 86f5b962
Von Sven Schöling vor fast 11 Jahren hinzugefügt
SL/Controller/DeliveryPlan.pm | ||
---|---|---|
179 | 179 |
|
180 | 180 |
UNION ALL |
181 | 181 |
|
182 |
-- 5. In case someone deleted a line of the delivery_order there will be a record_link (4 fails) |
|
183 |
-- but there won't be a delivery_order_items to find (3 fails too). Search for orphaned orderitems this way |
|
184 |
SELECT oi.id FROM orderitems AS oi, oe, record_links AS rl |
|
185 |
WHERE |
|
186 |
rl.from_table = 'oe' AND |
|
187 |
rl.to_table = 'delivery_orders' AND |
|
182 |
-- 5. now for the really nasty cases. |
|
183 |
-- If someone partially delivered an order in several delivery orders, |
|
184 |
-- there will be lots of record_links (4 doesn't catch those) but those |
|
185 |
-- won't have matching part_ids in delivery_order_items, so 1-3 can't |
|
186 |
-- find anything |
|
187 |
-- In this case aggreg record_links - delivery_order - delivery_order_items |
|
188 |
-- slice only oe.id, parts_id and sum of of qty |
|
189 |
-- left join that onto orderitems to get matching qtys in doi while retaining |
|
190 |
-- entrys without matches and then throw out those without record_links |
|
191 |
-- TODO: join this and 1-3 into a general case |
|
192 |
-- need debug info? uncomment these: |
|
193 |
SELECT oi.id -- ,oi.trans_id, oi.parts_id, coalesce(sum, 0), agg.parts_id |
|
194 |
FROM orderitems oi LEFT JOIN ( |
|
195 |
SELECT rl.from_id as oid, doi.parts_id, sum(doi.qty) FROM ( |
|
196 |
SELECT from_id, to_id |
|
197 |
FROM record_links rl |
|
198 |
LEFT JOIN oe ON oe.id = from_id |
|
199 |
WHERE |
|
200 |
rl.from_table = 'oe' AND |
|
201 |
rl.to_table = 'delivery_orders' AND |
|
188 | 202 |
|
189 |
oi.trans_id = rl.from_id AND |
|
190 |
oi.parts_id NOT IN ( |
|
191 |
SELECT doi.parts_id FROM delivery_order_items AS doi WHERE doi.delivery_order_id = rl.to_id |
|
203 |
oe.customer_id IS NOT NULL AND |
|
204 |
$oe_owner |
|
205 |
(oe.quotation = 'f' OR oe.quotation IS NULL) AND NOT oe.closed |
|
206 |
) rl |
|
207 |
LEFT JOIN delivery_order_items doi ON (rl.to_id = doi.delivery_order_id) |
|
208 |
GROUP BY rl.from_id, doi.parts_id |
|
209 |
) agg ON (agg.oid = oi.trans_id AND agg.parts_id = oi.parts_id) |
|
210 |
LEFT JOIN oe ON oe.id = oi.trans_id |
|
211 |
WHERE |
|
212 |
EXISTS ( |
|
213 |
SELECT to_id |
|
214 |
FROM record_links rl |
|
215 |
WHERE oi.trans_id = rl.from_id AND rl.from_table = 'oe' AND rl.to_table = 'delivery_orders' |
|
192 | 216 |
) AND |
193 |
|
|
194 |
oe.id = oi.trans_id AND |
|
195 |
|
|
217 |
coalesce(sum, 0) < oi.qty AND |
|
196 | 218 |
oe.customer_id IS NOT NULL AND |
197 |
(oe.quotation = 'f' OR oe.quotation IS NULL) AND |
|
198 | 219 |
$oe_owner |
199 |
NOT oe.closed |
|
220 |
(oe.quotation = 'f' OR oe.quotation IS NULL) AND NOT oe.closed
|
|
200 | 221 |
" ], |
201 | 222 |
] |
202 | 223 |
} |
Auch abrufbar als: Unified diff
Neue version vom lieferplan, die Splitlieferungen besser unterstützt.
- Stresstest in 2 Livedatenbanken mit je ~100000 Aufträgen liefert einen
erwarten Load von 5000 in Postgresql.
- In verschiedenen Lieferscheinen gelieferte Positionen sollten jetzt
korrekt behandelt werden.