Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision bcda7a48

Von wernerh vor mehr als 1 Jahr hinzugefügt

  • ID bcda7a48d2f70cc38f72a9fda6fc624d094c17e0
  • Vorgänger 650e6036
  • Nachfolger 45d80d98

Dispositionsmanager Abfrage auf SQL und übergabe 0 oder Menge

Unterschiede anzeigen:

SL/DB/Manager/Part.pm
97 97
  return () unless $part_id;
98 98

  
99 99
  my $query = <<SQL;
100
--  WITH
101
--  open_qty as ( 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
--  open_orderitems_ids AS ( SELECT oi.id, parts_id
113
--  FROM orderitems oi
114
--  LEFT OUTER JOIN oe o ON (oi.trans_id = o.id)
115
--  WHERE
116
--  oi.parts_id = ?
117
--  AND (NOT COALESCE(o.quotation, FALSE))
118
--  AND (NOT COALESCE(o.closed,    FALSE))
119
--  AND (NOT COALESCE(o.delivered, FALSE))
120
--  AND (COALESCE(o.vendor_id, 0) <> 0)
121
--  ),
122

  
123
--  delivered_qty AS ( SELECT parts_id, sum(qty) AS sum FROM delivery_order_items
124
--  WHERE id IN (SELECT to_id FROM record_links WHERE from_id IN (select id FROM open_orderitems_ids) AND from_table = 'orderitems' AND to_table = 'delivery_order_items') AND parts_id = ? GROUP BY parts_id),
125

  
126
--  open_ordered_qty AS ( SELECT dq.parts_id, oq.sum AS ordered_sum, dq.sum, sum(oq.sum - dq.sum) AS open_qty
127
--  FROM open_qty oq
128
--  RIGHT JOIN delivered_qty dq ON dq.parts_id = oq.parts_id
129
--  GROUP BY dq.parts_id, oq.sum, dq.sum)
130

  
131
--  SELECT open_qty FROM open_ordered_qty
132

  
133

  
134

  
135
with
136
open_qty as ( SELECT parts_id, sum(oi.qty) as sum
100
WITH
101
open_qty AS ( SELECT parts_id, sum(oi.qty) as sum
137 102
FROM orderitems oi
138 103
LEFT OUTER JOIN oe o ON (oi.trans_id = o.id)
139 104
WHERE
......
144 109
AND (COALESCE(o.vendor_id, 0) <> 0)
145 110
GROUP BY oi.parts_id),
146 111

  
147
open_orderitems_ids as ( SELECT oi.id, parts_id
112
open_orderitems_ids AS ( SELECT oi.id, parts_id
148 113
FROM orderitems oi
149 114
LEFT OUTER JOIN oe o ON (oi.trans_id = o.id)
150 115
WHERE
......
155 120
AND (COALESCE(o.vendor_id, 0) <> 0)
156 121
),
157 122

  
158
delivered_qty as ( select parts_id, sum(qty) as sum from delivery_order_items
159
where id in (select to_id from record_links where from_id in (select id from open_orderitems_ids) and from_table = 'orderitems' and to_table = 'delivery_order_items') and parts_id = ? group by parts_id),
123
delivered_qty AS ( select parts_id, sum(qty) AS sum FROM delivery_order_items
124
WHERE id IN (select to_id from record_links WHERE from_id IN (SELECT id FROM open_orderitems_ids) AND from_table = 'orderitems' AND to_table = 'delivery_order_items') AND parts_id = ? GROUP BY parts_id),
160 125

  
161
open_ordered_qty as ( select oq.parts_id, oq.sum as ordered_sum, iif(dq.sum is null,0.00,dq.sum) as sum, sum(iif(oq.sum is null,0.00,oq.sum) - iif(dq.sum is null,0.00,dq.sum)) as open_qty
162
from open_qty oq
163
left join delivered_qty dq on dq.parts_id = oq.parts_id
164
group by oq.parts_id, oq.sum, dq.sum)
126
open_ordered_qty AS ( select oq.parts_id, oq.sum AS ordered_sum, iif(dq.sum is null,0.00,dq.sum) AS sum, sum(iif(oq.sum is null,0.00,oq.sum) - iif(dq.sum is null,0.00,dq.sum)) AS open_qty
127
FROM open_qty oq
128
LEFT JOIN delivered_qty dq ON dq.parts_id = oq.parts_id
129
GROUP BY oq.parts_id, oq.sum, dq.sum)
165 130

  
166
select open_qty from open_ordered_qty
131
SELECT open_qty FROM open_ordered_qty
167 132

  
168 133
SQL
169 134

  
170 135
  my ($open_qty) = selectrow_query($::form, $class->object_class->init_db->dbh, $query, $part_id, $part_id, $part_id);
136
### Über Rose dauert das ganze 3 minuten
171 137
#    my $openitems = SL::DB::Manager::OrderItem->get_all(where => [
172 138
#                                                            parts_id => $part_id,
173 139
#                                                            'order.closed' => 0,
......
195 161

  
196 162
#  return $open_qty;
197 163

  
198
  $main::lxdebug->dump(0, 'WH: iOPENQTY', $open_qty);
199

  
200
  return $open_qty;
164
  return $open_qty if $open_qty > 0;
165
  return 0;
201 166
}
202 167

  
203 168
sub _sort_spec {

Auch abrufbar als: Unified diff