Revision 72528ede
Von Tamino Steinert vor fast 2 Jahren hinzugefügt
- ID 72528edece18f8ac73ff702e83050c674db69b38
- Vorgänger 72b80f91
SL/Controller/PartsPriceUpdate.pm | ||
---|---|---|
104 | 104 |
# items which were never bought, sold or on an order |
105 | 105 |
if ($filter->{itemstatus} eq 'orphaned') { |
106 | 106 |
$where .= |
107 |
qq| AND (p.onhand = 0)
|
|
107 |
qq| AND (onhands.onhand = 0)
|
|
108 | 108 |
AND p.id NOT IN |
109 | 109 |
( |
110 | 110 |
SELECT DISTINCT parts_id FROM invoice |
... | ... | |
123 | 123 |
$where .= qq| AND p.obsolete = '1'|; |
124 | 124 |
|
125 | 125 |
} elsif ($filter->{itemstatus} eq 'onhand') { |
126 |
$where .= qq| AND p.onhand > 0|;
|
|
126 |
$where .= qq| AND onhands.onhand > 0|;
|
|
127 | 127 |
|
128 | 128 |
} elsif ($filter->{itemstatus} eq 'short') { |
129 |
$where .= qq| AND p.onhand < p.rop|;
|
|
129 |
$where .= qq| AND onhands.onhand < p.rop|;
|
|
130 | 130 |
|
131 | 131 |
} |
132 | 132 |
|
... | ... | |
162 | 162 |
(SELECT p.id |
163 | 163 |
FROM parts p |
164 | 164 |
LEFT JOIN partsgroup pg ON (p.partsgroup_id = pg.id) |
165 |
LEFT JOIN onhands ON (onhands.parts_id = p.id) |
|
165 | 166 |
WHERE $where)|; |
166 | 167 |
my ($result) = selectfirst_array_query($::form, $dbh, $query, @where_values); |
167 | 168 |
$num_updated += $result if (0 <= $result); |
... | ... | |
176 | 177 |
(SELECT p.id |
177 | 178 |
FROM parts p |
178 | 179 |
LEFT JOIN partsgroup pg ON (p.partsgroup_id = pg.id) |
180 |
LEFT JOIN onhands ON (onhands.parts_id = p.id) |
|
179 | 181 |
WHERE $where) |
180 | 182 |
AND pricegroup_id IN (@{[ join ',', ('?')x@ids ]})|; |
181 | 183 |
|
... | ... | |
221 | 223 |
(SELECT p.id |
222 | 224 |
FROM parts p |
223 | 225 |
LEFT JOIN partsgroup pg ON (p.partsgroup_id = pg.id) |
226 |
LEFT JOIN onhands ON (onhands.parts_id = p.id) |
|
224 | 227 |
WHERE $where)|; |
225 | 228 |
my $result = do_query($::form, $dbh, $query, $value, @where_values); |
226 | 229 |
$num_updated += $result if 0 <= $result; |
... | ... | |
232 | 235 |
(SELECT p.id |
233 | 236 |
FROM parts p |
234 | 237 |
LEFT JOIN partsgroup pg ON (p.partsgroup_id = pg.id) |
238 |
LEFT JOIN onhands ON (onhands.parts_id = p.id) |
|
235 | 239 |
WHERE $where) AND (pricegroup_id = ?)|; |
236 | 240 |
my $sth_add = prepare_query($::form, $dbh, $q_add); |
237 | 241 |
|
... | ... | |
241 | 245 |
(SELECT p.id |
242 | 246 |
FROM parts p |
243 | 247 |
LEFT JOIN partsgroup pg ON (p.partsgroup_id = pg.id) |
248 |
LEFT JOIN onhands ON (onhands.parts_id = p.id) |
|
244 | 249 |
WHERE $where) AND (pricegroup_id = ?)|; |
245 | 250 |
my $sth_multiply = prepare_query($::form, $dbh, $q_multiply); |
246 | 251 |
|
SL/DB/Helper/Mappings.pm | ||
---|---|---|
166 | 166 |
orderitems => 'order_item', |
167 | 167 |
oe => 'order', |
168 | 168 |
oe_version => 'order_version', |
169 |
onhands => 'Onhand', |
|
169 | 170 |
parts => 'part', |
170 | 171 |
partsgroup => 'parts_group', |
171 | 172 |
part_classifications => 'PartClassification', |
SL/DB/Manager/Onhand.pm | ||
---|---|---|
1 |
# This file has been auto-generated only because it didn't exist. |
|
2 |
# Feel free to modify it at will; it will not be overwritten automatically. |
|
3 |
|
|
4 |
package SL::DB::Manager::Onhand; |
|
5 |
|
|
6 |
use strict; |
|
7 |
|
|
8 |
use parent qw(SL::DB::Helper::Manager); |
|
9 |
|
|
10 |
sub object_class { 'SL::DB::Onhand' } |
|
11 |
|
|
12 |
__PACKAGE__->make_manager_methods; |
|
13 |
|
|
14 |
1; |
SL/DB/MetaSetup/Onhand.pm | ||
---|---|---|
1 |
# This file has been auto-generated. Do not modify it; it will be overwritten |
|
2 |
# by rose_auto_create_model.pl automatically. |
|
3 |
package SL::DB::Onhand; |
|
4 |
|
|
5 |
use strict; |
|
6 |
|
|
7 |
use parent qw(SL::DB::Object); |
|
8 |
|
|
9 |
__PACKAGE__->meta->table('onhands'); |
|
10 |
|
|
11 |
__PACKAGE__->meta->columns( |
|
12 |
id => { type => 'integer', not_null => 1, sequence => 'id' }, |
|
13 |
onhand => { type => 'numeric', precision => 25, scale => 5 }, |
|
14 |
parts_id => { type => 'integer' }, |
|
15 |
); |
|
16 |
|
|
17 |
__PACKAGE__->meta->primary_key_columns([ 'id' ]); |
|
18 |
|
|
19 |
__PACKAGE__->meta->unique_keys([ 'parts_id' ]); |
|
20 |
|
|
21 |
__PACKAGE__->meta->foreign_keys( |
|
22 |
parts => { |
|
23 |
class => 'SL::DB::Part', |
|
24 |
key_columns => { parts_id => 'id' }, |
|
25 |
rel_type => 'one to one', |
|
26 |
}, |
|
27 |
); |
|
28 |
|
|
29 |
1; |
|
30 |
; |
SL/DB/MetaSetup/Part.pm | ||
---|---|---|
30 | 30 |
not_discountable => { type => 'boolean', default => 'false' }, |
31 | 31 |
notes => { type => 'text' }, |
32 | 32 |
obsolete => { type => 'boolean', default => 'false' }, |
33 |
onhand => { type => 'numeric', default => '0', precision => 25, scale => 5 }, |
|
34 | 33 |
part_type => { type => 'enum', check_in => [ 'part', 'service', 'assembly', 'assortment' ], db_type => 'part_type_enum', not_null => 1 }, |
35 | 34 |
partnumber => { type => 'text', not_null => 1 }, |
36 | 35 |
partsgroup_id => { type => 'integer' }, |
SL/DB/Onhand.pm | ||
---|---|---|
1 |
# This file has been auto-generated only because it didn't exist. |
|
2 |
# Feel free to modify it at will; it will not be overwritten automatically. |
|
3 |
|
|
4 |
package SL::DB::Onhand; |
|
5 |
|
|
6 |
use strict; |
|
7 |
|
|
8 |
use SL::DB::MetaSetup::Onhand; |
|
9 |
use SL::DB::Manager::Onhand; |
|
10 |
|
|
11 |
__PACKAGE__->meta->initialize; |
|
12 |
|
|
13 |
1; |
SL/DB/Part.pm | ||
---|---|---|
82 | 82 |
column_map => { id => 'part_id' }, |
83 | 83 |
manager_args => { sort_by => 'valid_from DESC', limit => 1 }, |
84 | 84 |
}, |
85 |
onhands => { |
|
86 |
type => 'one to one', |
|
87 |
class => 'SL::DB::Onhand', |
|
88 |
column_map => {id => 'parts_id' }, |
|
89 |
}, |
|
85 | 90 |
); |
86 | 91 |
|
87 | 92 |
__PACKAGE__->meta->initialize; |
... | ... | |
358 | 363 |
return $stock || 0; # never return undef |
359 | 364 |
}; |
360 | 365 |
|
366 |
sub onhand { |
|
367 |
my ($self) = @_; |
|
368 |
return 0 unless $self->id; |
|
369 |
return $self->onhands->onhand; |
|
370 |
} |
|
361 | 371 |
|
362 | 372 |
# this is designed to ignore chargenumbers, expiration dates and just give a list of how much <-> where |
363 | 373 |
sub get_simple_stock { |
SL/IC.pm | ||
---|---|---|
103 | 103 |
my $query = |
104 | 104 |
qq|SELECT p.id, p.partnumber, p.description, p.sellprice, |
105 | 105 |
p.classification_id, |
106 |
p.weight, p.onhand, p.unit, pg.partsgroup, p.lastcost,
|
|
106 |
p.weight, onhands.onhand, p.unit, pg.partsgroup, p.lastcost,
|
|
107 | 107 |
p.price_factor_id, pfac.factor AS price_factor, p.notes as longdescription |
108 | 108 |
FROM parts p |
109 | 109 |
LEFT JOIN partsgroup pg ON (p.partsgroup_id = pg.id) |
110 | 110 |
LEFT JOIN price_factors pfac ON pfac.id = p.price_factor_id |
111 |
LEFT JOIN onhands ON (onhands.parts_id = p.id) |
|
111 | 112 |
WHERE $where|; |
112 | 113 |
$form->{item_list} = selectall_hashref_query($form, SL::DB->client->dbh, $query, @values); |
113 | 114 |
|
... | ... | |
248 | 249 |
cv => 'cv.', |
249 | 250 |
"ioi.id" => ' ', |
250 | 251 |
"ioi.ioi" => ' ', |
252 |
onhand => 'onhands.', |
|
251 | 253 |
); |
252 | 254 |
|
253 | 255 |
# if the join condition in these blocks are met, the column |
... | ... | |
391 | 393 |
(SELECT DISTINCT parts_id FROM invoice UNION |
392 | 394 |
SELECT DISTINCT parts_id FROM assembly UNION |
393 | 395 |
SELECT DISTINCT parts_id FROM orderitems)' if /orphaned/; |
394 |
push @where_tokens, 'p.onhand = 0' if /orphaned/;
|
|
396 |
push @where_tokens, 'onhands.onhand = 0' if /orphaned/;
|
|
395 | 397 |
push @where_tokens, 'NOT p.obsolete' if /active/; |
396 | 398 |
push @where_tokens, ' p.obsolete', if /obsolete/; |
397 |
push @where_tokens, 'p.onhand > 0', if /onhand/;
|
|
398 |
push @where_tokens, 'p.onhand < p.rop', if /short/;
|
|
399 |
push @where_tokens, 'onhands.onhand > 0', if /onhand/;
|
|
400 |
push @where_tokens, 'onhands.onhand < p.rop', if /short/;
|
|
399 | 401 |
} |
400 | 402 |
|
401 | 403 |
my $q_assembly_lastcost = |
... | ... | |
549 | 551 |
my $query = <<" SQL"; |
550 | 552 |
SELECT DISTINCT $select_clause |
551 | 553 |
FROM parts p |
554 |
LEFT JOIN onhands ON (onhands.parts_id = p.id) |
|
552 | 555 |
$join_clause |
553 | 556 |
WHERE $where_clause |
554 | 557 |
$group_clause |
... | ... | |
846 | 849 |
|
847 | 850 |
my $dbh = $form->get_standard_dbh($myconfig); |
848 | 851 |
|
849 |
my $query = qq|SELECT * FROM parts WHERE id IN (| . join(', ', ('?') x scalar(@ids)) . qq|)|;
|
|
852 |
my $query = qq|SELECT p.* onhands.onhand FROM parts p LEFT JOIN onhands ON (onhands.parts_id = p.id) WHERE p.id IN (| . join(', ', ('?') x scalar(@ids)) . qq|)|;
|
|
850 | 853 |
|
851 | 854 |
my $info = selectall_hashref_query($form, $dbh, $query, map { conv_i($_) } @ids); |
852 | 855 |
|
SL/IR.pm | ||
---|---|---|
1255 | 1255 |
my $query = |
1256 | 1256 |
qq|SELECT |
1257 | 1257 |
p.id, p.partnumber, p.description, p.lastcost AS sellprice, p.listprice, |
1258 |
p.unit, p.part_type, p.onhand, p.formel,
|
|
1258 |
p.unit, p.part_type, onhands.onhand, p.formel,
|
|
1259 | 1259 |
p.notes AS partnotes, p.notes AS longdescription, p.not_discountable, |
1260 | 1260 |
p.price_factor_id, |
1261 | 1261 |
p.ean, |
... | ... | |
1279 | 1279 |
pg.partsgroup |
1280 | 1280 |
|
1281 | 1281 |
FROM parts p |
1282 |
LEFT JOIN onhands ON (onhands.parts_id = p.id) |
|
1282 | 1283 |
LEFT JOIN chart c1 ON |
1283 | 1284 |
((SELECT inventory_accno_id |
1284 | 1285 |
FROM buchungsgruppen |
SL/IS.pm | ||
---|---|---|
2630 | 2630 |
c3.new_chart_id AS expense_new_chart, |
2631 | 2631 |
date($transdate) - c3.valid_from AS expense_valid, |
2632 | 2632 |
|
2633 |
p.unit, p.part_type, p.onhand,
|
|
2633 |
p.unit, p.part_type, onhands.onhand,
|
|
2634 | 2634 |
p.notes AS partnotes, p.notes AS longdescription, |
2635 | 2635 |
p.not_discountable, p.formel, p.payment_id AS part_payment_id, |
2636 | 2636 |
p.price_factor_id, p.weight, |
... | ... | |
2640 | 2640 |
pg.partsgroup |
2641 | 2641 |
|
2642 | 2642 |
FROM parts p |
2643 |
LEFT JOIN onhands ON (onhands.parts_id = p.id) |
|
2643 | 2644 |
LEFT JOIN chart c1 ON |
2644 | 2645 |
((SELECT inventory_accno_id |
2645 | 2646 |
FROM buchungsgruppen |
sql/Pg-upgrade2/seperate_table_for_onhand.sql | ||
---|---|---|
1 |
-- @tag: seperate_table_for_onhand |
|
2 |
-- @description: Verschiebe onhand in extra Tabelle |
|
3 |
-- @depends: release_3_6_1 |
|
4 |
CREATE TABLE onhands ( |
|
5 |
id INT NOT NULL DEFAULT nextval('id'), |
|
6 |
parts_id INT UNIQUE references parts(id) ON DELETE CASCADE, |
|
7 |
onhand NUMERIC(25,5), |
|
8 |
PRIMARY KEY (id) |
|
9 |
); |
|
10 |
-- lock all tables while updating values |
|
11 |
LOCK TABLE onhands IN EXCLUSIVE MODE; |
|
12 |
LOCK TABLE inventory IN EXCLUSIVE MODE; |
|
13 |
LOCK TABLE parts IN EXCLUSIVE MODE; |
|
14 |
|
|
15 |
CREATE OR REPLACE FUNCTION public.update_onhand() |
|
16 |
RETURNS trigger |
|
17 |
LANGUAGE plpgsql |
|
18 |
AS ' |
|
19 |
BEGIN |
|
20 |
IF tg_op = "INSERT" THEN |
|
21 |
UPDATE onhands SET onhand = COALESCE(onhand, 0) + new.qty WHERE parts_id = new.parts_id; |
|
22 |
RETURN new; |
|
23 |
ELSIF tg_op = "DELETE" THEN |
|
24 |
UPDATE onhands SET onhand = COALESCE(onhand, 0) - old.qty WHERE parts_id = old.parts_id; |
|
25 |
RETURN old; |
|
26 |
ELSE |
|
27 |
UPDATE onhands SET onhand = COALESCE(onhand, 0) - old.qty + new.qty WHERE parts_id = old.parts_id; |
|
28 |
RETURN new; |
|
29 |
END IF; |
|
30 |
END; |
|
31 |
'; |
|
32 |
|
|
33 |
-- All parts get a onhand value; |
|
34 |
CREATE OR REPLACE FUNCTION public.create_onhand() |
|
35 |
RETURNS trigger |
|
36 |
LANGUAGE plpgsql |
|
37 |
AS ' |
|
38 |
BEGIN |
|
39 |
INSERT INTO onhands (parts_id, onhand) values (new.parts_id, 0); |
|
40 |
END; |
|
41 |
'; |
|
42 |
|
|
43 |
CREATE TRIGGER trig_create_onhand |
|
44 |
AFTER INSERT ON parts |
|
45 |
FOR EACH ROW EXECUTE PROCEDURE create_onhand(); |
|
46 |
|
|
47 |
|
|
48 |
INSERT INTO onhands (parts_id, onhand) SELECT id, onhand FROM parts; |
|
49 |
|
|
50 |
ALTER TABLE parts DROP COLUMN onhand; |
templates/design40_webpages/order/tabs/_second_row.html | ||
---|---|---|
33 | 33 |
[% END %] |
34 | 34 |
<b>[% 'On Hand' | $T8 %]</b> |
35 | 35 |
<span class="numeric[% IF ITEM.part.onhand < ITEM.part.rop %] plus0[% END %]"> |
36 |
[% ITEM.part.onhand_as_number %] [% ITEM.part.unit %]
|
|
36 |
[%- LxERP.format_amount(ITEM.part.onhand, 2) -%] [%- ITEM.part.unit -%]
|
|
37 | 37 |
</span> |
38 | 38 |
</td> |
39 | 39 |
</tr> |
templates/webpages/delivery_order/tabs/_second_row.html | ||
---|---|---|
18 | 18 |
[%- END %] |
19 | 19 |
<b>[%- 'On Hand' | $T8 %]</b> |
20 | 20 |
<span[%- IF ITEM.part.onhand < ITEM.part.rop -%] class="numeric plus0"[%- END -%]> |
21 |
[%- ITEM.part.onhand_as_number -%] [%- ITEM.part.unit -%]
|
|
21 |
[%- LxERP.format_amount(ITEM.part.onhand, 2) -%] [%- ITEM.part.unit -%]
|
|
22 | 22 |
</span> |
23 | 23 |
</td></tr> |
24 | 24 |
|
templates/webpages/order/tabs/_second_row.html | ||
---|---|---|
36 | 36 |
[%- END %] |
37 | 37 |
<b>[%- 'On Hand' | $T8 %]</b> |
38 | 38 |
<span class="numeric[%- IF ITEM.part.onhand < ITEM.part.rop -%] plus0[%- END -%]"> |
39 |
[%- ITEM.part.onhand_as_number -%] [%- ITEM.part.unit -%]
|
|
39 |
[%- LxERP.format_amount(ITEM.part.onhand, 2) -%] [%- ITEM.part.unit -%]
|
|
40 | 40 |
</span> |
41 | 41 |
<b>[%- 'Optional' | $T8 %]</b> |
42 | 42 |
[%- L.yes_no_tag("order.orderitems[].optional", ITEM.optional |
templates/webpages/reclamation/tabs/basic_data/_second_row.html | ||
---|---|---|
23 | 23 |
[%- END %] |
24 | 24 |
<b>[%- 'On Hand' | $T8 %]</b> |
25 | 25 |
<span[%- IF ITEM.part.onhand < ITEM.part.rop -%] class="numeric plus0"[%- END -%]> |
26 |
[%- ITEM.part.onhand_as_number -%] [%- ITEM.part.unit -%]
|
|
26 |
[%- LxERP.format_amount(ITEM.part.onhand, 2) -%] [%- ITEM.part.unit -%]
|
|
27 | 27 |
</span> |
28 | 28 |
</td></tr> |
29 | 29 |
|
Auch abrufbar als: Unified diff
Separate Tabelle für onhand (onhands) für Artikel