Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 4b8e5682

Von Tamino Steinert vor mehr als 1 Jahr hinzugefügt

  • ID 4b8e56821eac8b83856dca20e2ca8371081c13f5
  • Vorgänger 72b80f91

Separate Tabelle für onhand (stocks) für Artikel

Jetzt führt Ein- und Auslagern nicht mehr zu einer Änderung des
Artikels in der Datenbank.

Unterschiede anzeigen:

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 (stocks.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 stocks.onhand > 0|;
127 127

  
128 128
  } elsif ($filter->{itemstatus} eq 'short') {
129
    $where .= qq| AND p.onhand < p.rop|;
129
    $where .= qq| AND stocks.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 stocks ON (stocks.part_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 stocks ON (stocks.part_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 stocks ON (stocks.part_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 stocks ON (stocks.part_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 stocks ON (stocks.part_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/ALL.pm
140 140
use SL::DB::ShopOrderItem;
141 141
use SL::DB::ShopPart;
142 142
use SL::DB::Status;
143
use SL::DB::Stock;
143 144
use SL::DB::Stocktaking;
144 145
use SL::DB::Tax;
145 146
use SL::DB::TaxKey;
SL/DB/Helper/Mappings.pm
220 220
  shop_parts                     => 'shop_part',
221 221
  status                         => 'status',
222 222
  stocktakings                   => 'stocktaking',
223
  stocks                         => 'Stock',
223 224
  tax                            => 'tax',
224 225
  taxkeys                        => 'tax_key',
225 226
  tax_zones                      => 'tax_zone',
SL/DB/Manager/Stock.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::Stock;
5

  
6
use strict;
7

  
8
use parent qw(SL::DB::Helper::Manager);
9

  
10
sub object_class { 'SL::DB::Stock' }
11

  
12
__PACKAGE__->make_manager_methods;
13

  
14
1;
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/MetaSetup/Stock.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::Stock;
4

  
5
use strict;
6

  
7
use parent qw(SL::DB::Object);
8

  
9
__PACKAGE__->meta->table('stocks');
10

  
11
__PACKAGE__->meta->columns(
12
  id      => { type => 'integer', not_null => 1, sequence => 'id' },
13
  onhand  => { type => 'numeric', precision => 25, scale => 5 },
14
  part_id => { type => 'integer' },
15
);
16

  
17
__PACKAGE__->meta->primary_key_columns([ 'id' ]);
18

  
19
__PACKAGE__->meta->unique_keys([ 'part_id' ]);
20

  
21
__PACKAGE__->meta->foreign_keys(
22
  part => {
23
    class       => 'SL::DB::Part',
24
    key_columns => { part_id => 'id' },
25
    rel_type    => 'one to one',
26
  },
27
);
28

  
29
1;
30
;
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
  stock => {
86
    type => 'one to one',
87
    class => 'SL::DB::Stock',
88
    column_map => {id => 'part_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->stock->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/DB/Stock.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::Stock;
5

  
6
use strict;
7

  
8
use SL::DB::MetaSetup::Stock;
9
use SL::DB::Manager::Stock;
10

  
11
__PACKAGE__->meta->initialize;
12

  
13
1;
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, stocks.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 stocks ON (stocks.part_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       => 'stocks.',
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, 'stocks.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, 'stocks.onhand > 0',           if /onhand/;
400
    push @where_tokens, 'stocks.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 stocks ON (stocks.part_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.* stocks.onhand FROM parts p LEFT JOIN stocks ON (stocks.part_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, stocks.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 stocks ON (stocks.part_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, stocks.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 stocks ON (stocks.part_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 stocks (
5
  id INT NOT NULL DEFAULT nextval('id'),
6
  part_id INT UNIQUE references parts(id) ON DELETE CASCADE,
7
  onhand NUMERIC(25,5),
8
  PRIMARY KEY (id)
9
);
10

  
11
-- lock all tables while updating values
12
LOCK TABLE stocks IN EXCLUSIVE MODE;
13
LOCK TABLE inventory IN EXCLUSIVE MODE;
14
LOCK TABLE parts IN EXCLUSIVE MODE;
15

  
16
-- delete old trigger
17
DROP TRIGGER  IF EXISTS trig_update_onhand ON inventory;
18
DROP FUNCTION IF EXISTS update_onhand();
19

  
20
CREATE OR REPLACE FUNCTION update_stock()
21
  RETURNS trigger
22
  LANGUAGE plpgsql
23
AS '
24
BEGIN
25
  IF tg_op = ''INSERT'' THEN
26
    UPDATE stocks SET onhand = COALESCE(onhand, 0) + new.qty WHERE part_id = new.parts_id;
27
    RETURN new;
28
  ELSIF tg_op = ''DELETE'' THEN
29
    UPDATE stocks SET onhand = COALESCE(onhand, 0) - old.qty WHERE part_id = old.parts_id;
30
    RETURN old;
31
  ELSE
32
    UPDATE stocks SET onhand = COALESCE(onhand, 0) - old.qty + new.qty WHERE part_id = old.parts_id;
33
    RETURN new;
34
  END IF;
35
END;
36
';
37

  
38
CREATE OR REPLACE TRIGGER trig_update_stock
39
  AFTER INSERT OR UPDATE OR DELETE ON inventory
40
  FOR EACH ROW EXECUTE PROCEDURE update_stock();
41

  
42
-- All parts get a onhand value;
43
CREATE OR REPLACE FUNCTION create_stock()
44
  RETURNS trigger
45
  LANGUAGE plpgsql
46
AS '
47
BEGIN
48
  INSERT INTO stocks (part_id, onhand) values (new.id, 0);
49
  RETURN new;
50
END;
51
';
52
CREATE OR REPLACE TRIGGER trig_create_stock
53
  AFTER INSERT ON parts
54
  FOR EACH ROW EXECUTE PROCEDURE create_stock();
55

  
56

  
57
INSERT INTO stocks (part_id, onhand) SELECT id, onhand FROM parts;
58
-- neu berechnen? UPDATE parts SET onhand = COALESCE((SELECT SUM(qty) FROM inventory WHERE inventory.parts_id = parts.id), 0);
59

  
60
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) -%]&nbsp;[%- 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>&nbsp;
20 20
      <span[%- IF ITEM.part.onhand < ITEM.part.rop -%] class="numeric plus0"[%- END -%]>
21
        [%- ITEM.part.onhand_as_number -%]&nbsp;[%- ITEM.part.unit -%]
21
        [%- LxERP.format_amount(ITEM.part.onhand, 2) -%]&nbsp;[%- ITEM.part.unit -%]
22 22
      </span>&nbsp;
23 23
  </td></tr>
24 24

  
templates/webpages/order/tabs/_second_row.html
36 36
    [%- END %]
37 37
    <b>[%- 'On Hand' | $T8 %]</b>&nbsp;
38 38
      <span class="numeric[%- IF ITEM.part.onhand < ITEM.part.rop -%] plus0[%- END -%]">
39
        [%- ITEM.part.onhand_as_number -%]&nbsp;[%- ITEM.part.unit -%]
39
        [%- LxERP.format_amount(ITEM.part.onhand, 2) -%]&nbsp;[%- ITEM.part.unit -%]
40 40
      </span>&nbsp;
41 41
    <b>[%- 'Optional' | $T8 %]</b>&nbsp;
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>&nbsp;
25 25
      <span[%- IF ITEM.part.onhand < ITEM.part.rop -%] class="numeric plus0"[%- END -%]>
26
        [%- ITEM.part.onhand_as_number -%]&nbsp;[%- ITEM.part.unit -%]
26
        [%- LxERP.format_amount(ITEM.part.onhand, 2) -%]&nbsp;[%- ITEM.part.unit -%]
27 27
      </span>&nbsp;
28 28
  </td></tr>
29 29

  

Auch abrufbar als: Unified diff