Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision d90699ef

Von Tamino Steinert vor mehr als 1 Jahr hinzugefügt

Part: um Helferfunktionen für den Warenstand erweitert

Unterschiede anzeigen:

SL/DB/Manager/Part.pm
91 91
  return %qty_by_id;
92 92
}
93 93

  
94
sub get_open_ordered_qty {
95
  my $class    = shift;
96
  my $part_id  = shift;
97
  return () unless $part_id;
98

  
99
  my $query = <<SQL;
100
WITH
101
open_qty AS (
102
  SELECT parts_id, sum(oi.qty) as sum
103
  FROM 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
112
),
113

  
114
open_orderitems_ids AS (
115
  SELECT oi.id, parts_id
116
  FROM orderitems oi
117
  LEFT OUTER JOIN oe o ON (oi.trans_id = o.id)
118
  WHERE
119
    oi.parts_id = ?
120
    AND (NOT COALESCE(o.quotation, FALSE))
121
    AND (NOT COALESCE(o.closed,    FALSE))
122
    AND (NOT COALESCE(o.delivered, FALSE))
123
    AND (o.vendor_id is not null)
124
),
125

  
126
delivered_qty AS (
127
  SELECT parts_id, sum(qty) AS sum
128
  FROM delivery_order_items
129
  WHERE id IN (
130
    SELECT to_id from record_links
131
    WHERE
132
      from_id IN ( SELECT id FROM open_orderitems_ids)
133
      AND from_table = 'orderitems'
134
      AND to_table = 'delivery_order_items'
135
  ) AND parts_id = ?
136
  GROUP BY parts_id
137
),
138

  
139
open_ordered_qty AS (
140
  SELECT
141
    oq.parts_id,
142
    oq.sum AS ordered_sum,
143
    COALESCE(dq.sum,0.00) AS sum,
144
    sum(COALESCE(oq.sum,0.00) - COALESCE(dq.sum,0.00)) AS open_qty
145
  FROM open_qty oq
146
  LEFT JOIN delivered_qty dq ON dq.parts_id = oq.parts_id
147
  GROUP BY oq.parts_id, oq.sum, dq.sum
148
)
149

  
150
SELECT open_qty FROM open_ordered_qty
151

  
152
SQL
153

  
154
  my ($open_qty) = selectfirst_array_query(
155
    $::form, $class->object_class->init_db->dbh,
156
    $query, $part_id, $part_id, $part_id
157
  );
158

  
159
  $open_qty ||= 0;
160
  return $open_qty
161
}
162

  
94 163
sub _sort_spec {
95 164
  (
96 165
    default  => [ 'partnumber', 1 ],

Auch abrufbar als: Unified diff