Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 942291e4

Von Bernd Bleßmann vor fast 10 Jahren hinzugefügt

  • ID 942291e4ee3bacc216839d2989a63123f87b6bcd
  • Vorgänger 2f9a5220
  • Nachfolger 8b17f06f

Item-Positionen für Rechnungen in DB: DB-Upgrade-Skript; Rose

Positionen der Artikelzeilen für Rechnungen in der Datenbank speichern.

Unterschiede anzeigen:

SL/DB/InvoiceItem.pm
3 3
use strict;
4 4

  
5 5
use SL::DB::MetaSetup::InvoiceItem;
6
use SL::DB::Helper::ActsAsList;
6 7
use SL::DB::Helper::CustomVariables (
7 8
  sub_module  => 'invoice',
8 9
  cvars_alias => 1,
......
16 17

  
17 18
__PACKAGE__->meta->make_manager_class;
18 19

  
20
__PACKAGE__->configure_acts_as_list(group_by => [qw(trans_id)]);
21

  
19 22
__PACKAGE__->meta->add_relationships(
20 23
  invoice          => {
21 24
    type           => 'one to one',
SL/DB/MetaSetup/InvoiceItem.pm
30 30
  mtime                  => { type => 'timestamp' },
31 31
  ordnumber              => { type => 'text' },
32 32
  parts_id               => { type => 'integer' },
33
  position               => { type => 'integer', not_null => 1 },
33 34
  price_factor           => { type => 'numeric', default => 1, precision => 15, scale => 5 },
34 35
  price_factor_id        => { type => 'integer' },
35 36
  pricegroup_id          => { type => 'integer' },
sql/Pg-upgrade2/invoice_positions.pl
1
# @tag: invoice_positions
2
# @description: Spalte für Positionen der Einträge in Rechnungen
3
# @depends: release_3_1_0
4
# @encoding: utf-8
5
package SL::DBUpgrade2::invoice_positions;
6

  
7
use strict;
8
use utf8;
9

  
10
use parent qw(SL::DBUpgrade2::Base);
11

  
12
sub run {
13
  my ($self) = @_;
14

  
15
  my $query = qq|ALTER TABLE invoice ADD position INTEGER|;
16
  $self->db_query($query);
17

  
18

  
19
  $query = qq|SELECT * FROM invoice ORDER BY trans_id, id|;
20

  
21
  my $sth = $self->dbh->prepare($query);
22
  $sth->execute || $::form->dberror($query);
23

  
24
  # set new postition field in order of ids, starting by one for each invoice
25
  my $last_invoice_id;
26
  my $position;
27
  while (my $ref = $sth->fetchrow_hashref("NAME_lc")) {
28
    if ($ref->{trans_id} != $last_invoice_id) {
29
      $position = 1;
30
    } else {
31
      $position++;
32
    }
33
    $last_invoice_id = $ref->{trans_id};
34

  
35
    $query = qq|UPDATE invoice SET position = ? WHERE id = ?|;
36
    $self->db_query($query, bind => [ $position, $ref->{id} ]);
37
  }
38
  $sth->finish;
39

  
40
  $query = qq|ALTER TABLE invoice ALTER COLUMN position SET NOT NULL|;
41
  $self->db_query($query);
42

  
43
  return 1;
44
}
45

  
46
1;

Auch abrufbar als: Unified diff