Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 4dabc760

Von Tamino Steinert vor mehr als 1 Jahr hinzugefügt

  • ID 4dabc7602af4ebd6da44eed0dfab0e75672f502b
  • Vorgänger 44e85149
  • Nachfolger ad7cae2d

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 ],
SL/DB/Part.pm
8 8
use Rose::DB::Object::Helpers qw(as_tree);
9 9

  
10 10
use SL::Locale::String qw(t8);
11
use SL::Helper::Inventory;
11 12
use SL::DBUtils;
12 13
use SL::DB::MetaSetup::Part;
13 14
use SL::DB::Manager::Part;
......
91 92

  
92 93
__PACKAGE__->meta->initialize;
93 94

  
95
use Rose::Object::MakeMethods::Generic (
96
  'scalar --get_set_init' => [ qw(onhandqty stockqty get_open_ordered_qty) ],
97
);
94 98
__PACKAGE__->attr_html('notes');
95 99
__PACKAGE__->attr_sorted({ unsorted => 'makemodels',     position => 'sortorder' });
96 100
__PACKAGE__->attr_sorted({ unsorted => 'customerprices', position => 'sortorder' });
......
578 582
  return 1;
579 583
}
580 584

  
585
sub init_onhandqty{
586
  my ($self) = @_;
587
  my $qty = SL::Helper::Inventory::get_onhand(part => $self->id) || 0;
588
  return $qty;
589
}
590

  
591
sub init_stockqty{
592
  my ($self) = @_;
593
  my $qty = SL::Helper::Inventory::get_stock(part => $self->id) || 0;
594
  return $qty;
595
}
596

  
597
sub init_get_open_ordered_qty {
598
  my ($self) = @_;
599
  my $result = SL::DB::Manager::Part->get_open_ordered_qty($self->id);
600

  
601
  return $result;
602
}
603

  
581 604
1;
582 605

  
583 606
__END__

Auch abrufbar als: Unified diff