Revision e13733db
Von Tamino Steinert vor etwa 1 Jahr hinzugefügt
SL/DB/Manager/Part.pm | ||
---|---|---|
90 | 90 |
return %qty_by_id; |
91 | 91 |
} |
92 | 92 |
|
93 |
sub get_open_ordered_qty { |
|
94 |
my $class = shift; |
|
95 |
my $part_id = shift; |
|
96 |
return () unless $part_id; |
|
97 |
|
|
98 |
my $query = <<SQL; |
|
99 |
WITH |
|
100 |
open_qty AS ( |
|
101 |
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 |
|
|
113 |
open_orderitems_ids AS ( |
|
114 |
SELECT oi.id, parts_id |
|
115 |
FROM orderitems oi |
|
116 |
LEFT OUTER JOIN oe o ON (oi.trans_id = o.id) |
|
117 |
WHERE |
|
118 |
oi.parts_id = ? |
|
119 |
AND (NOT COALESCE(o.quotation, FALSE)) |
|
120 |
AND (NOT COALESCE(o.closed, FALSE)) |
|
121 |
AND (NOT COALESCE(o.delivered, FALSE)) |
|
122 |
AND (o.vendor_id is not null) |
|
123 |
), |
|
124 |
|
|
125 |
delivered_qty AS ( |
|
126 |
SELECT parts_id, sum(qty) AS sum |
|
127 |
FROM delivery_order_items |
|
128 |
WHERE id IN ( |
|
129 |
SELECT to_id from record_links |
|
130 |
WHERE |
|
131 |
from_id IN ( SELECT id FROM open_orderitems_ids) |
|
132 |
AND from_table = 'orderitems' |
|
133 |
AND to_table = 'delivery_order_items' |
|
134 |
) AND parts_id = ? |
|
135 |
GROUP BY parts_id |
|
136 |
), |
|
137 |
|
|
138 |
open_ordered_qty AS ( |
|
139 |
SELECT |
|
140 |
oq.parts_id, |
|
141 |
oq.sum AS ordered_sum, |
|
142 |
COALESCE(dq.sum,0.00) AS sum, |
|
143 |
sum(COALESCE(oq.sum,0.00) - COALESCE(dq.sum,0.00)) AS open_qty |
|
144 |
FROM open_qty oq |
|
145 |
LEFT JOIN delivered_qty dq ON dq.parts_id = oq.parts_id |
|
146 |
GROUP BY oq.parts_id, oq.sum, dq.sum |
|
147 |
) |
|
148 |
|
|
149 |
SELECT open_qty FROM open_ordered_qty |
|
150 |
|
|
151 |
SQL |
|
152 |
|
|
153 |
my ($open_qty) = selectfirst_array_query( |
|
154 |
$::form, $class->object_class->init_db->dbh, |
|
155 |
$query, $part_id, $part_id, $part_id |
|
156 |
); |
|
157 |
|
|
158 |
$open_qty ||= 0; |
|
159 |
return $open_qty |
|
160 |
} |
|
161 |
|
|
93 | 162 |
sub _sort_spec { |
94 | 163 |
( |
95 | 164 |
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
Part: um Helferfunktionen für den Warenstand erweitert