Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 104ebdfd

Von wernerh vor mehr als 1 Jahr hinzugefügt

  • ID 104ebdfd7c450a622651571b2f23975599553eac
  • Vorgänger 76bfa214
  • Nachfolger 280f80fa

Dispositionsmanager Abfrage von Rose auf SQL umgestellt wg Schnelligkeit

Unterschiede anzeigen:

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

  
99 99
  my $query = <<SQL;
100
 SELECT
101
   sum(oi.qty) as sum
102
   FROM
103
   orderitems oi
104
   LEFT OUTER JOIN oe o ON (oi.trans_id = o.id)
105
   WHERE
106
   oi.parts_id = ?
107
   AND (NOT COALESCE(o.quotation, FALSE))
108
   AND (NOT COALESCE(o.closed,    FALSE))
109
   AND (NOT COALESCE(o.delivered, FALSE))
110
   AND (COALESCE(o.vendor_id, 0) <> 0)
111
   GROUP BY oi.parts_id
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
137
FROM orderitems oi
138
LEFT OUTER JOIN oe o ON (oi.trans_id = o.id)
139
WHERE
140
oi.parts_id = ?
141
AND (NOT COALESCE(o.quotation, FALSE))
142
AND (NOT COALESCE(o.closed,    FALSE))
143
AND (NOT COALESCE(o.delivered, FALSE))
144
AND (COALESCE(o.vendor_id, 0) <> 0)
145
GROUP BY oi.parts_id),
146

  
147
open_orderitems_ids as ( SELECT oi.id, parts_id
148
FROM orderitems oi
149
LEFT OUTER JOIN oe o ON (oi.trans_id = o.id)
150
WHERE
151
oi.parts_id = ?
152
AND (NOT COALESCE(o.quotation, FALSE))
153
AND (NOT COALESCE(o.closed,    FALSE))
154
AND (NOT COALESCE(o.delivered, FALSE))
155
AND (COALESCE(o.vendor_id, 0) <> 0)
156
),
157

  
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),
160

  
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)
165

  
166
select open_qty from open_ordered_qty
167

  
112 168
SQL
113 169

  
114
  my ($ordered_qty) = selectrow_query($::form, $class->object_class->init_db->dbh, $query, $part_id);
115
  return $ordered_qty;
170
  my ($open_qty) = selectrow_query($::form, $class->object_class->init_db->dbh, $query, $part_id, $part_id, $part_id);
171
#    my $openitems = SL::DB::Manager::OrderItem->get_all(where => [
172
#                                                            parts_id => $part_id,
173
#                                                            'order.closed' => 0,
174
#                                                            'order.quotation' => 0,
175
#                                                            'order.delivered' => 0,
176
#                                                            #  'order.type' => { ilike => 'purchase_order' },
177
#                                                            'order.vendor_id' => { ne => 0 }
178
#                                                          ],
179
#                                                           with_objects => ['order'],
180
#                                                         );
181
#                                                         $main::lxdebug->dump(0, 'WH:OPEN ', $openitems);
182

  
183
#  return 0 unless $openitems;
184
#  my $open_qty        = 0;
185
#  my $ordered_qty     = 0;
186
#  my $delivered_qty   = 0;
187
#  for my $openitem (@{ $openitems }) {
188
##      if($openitem->order->type eq 'purchase_order') {
189
#        $ordered_qty   += $openitem->qty;
190
#        $delivered_qty += $openitem->delivered_qty;
191
##      }
192
#    }
193
##   $open_qty = map{ $_->qty - $_->delivered_qty } @{$openitems};
194
#      $open_qty = $ordered_qty - $delivered_qty;
195

  
196
#  return $open_qty;
197

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

  
200
  return $open_qty;
116 201
}
117 202

  
118 203
sub _sort_spec {

Auch abrufbar als: Unified diff