1 # @tag: invoice_positions
2 # @description: Spalte für Positionen der Einträge in Rechnungen
3 # @depends: release_3_1_0
5 package SL::DBUpgrade2::invoice_positions;
10 use parent qw(SL::DBUpgrade2::Base);
15 my $query = qq|ALTER TABLE invoice ADD position INTEGER|;
16 $self->db_query($query);
19 $query = qq|SELECT * FROM invoice ORDER BY trans_id, id|;
21 my $sth = $self->dbh->prepare($query);
22 $sth->execute || $::form->dberror($query);
24 # set new position field in order of ids, starting by one for each invoice
27 while (my $ref = $sth->fetchrow_hashref("NAME_lc")) {
28 if ($ref->{trans_id} != $last_invoice_id) {
33 $last_invoice_id = $ref->{trans_id};
35 $query = qq|UPDATE invoice SET position = ? WHERE id = ?|;
36 $self->db_query($query, bind => [ $position, $ref->{id} ]);
40 $query = qq|ALTER TABLE invoice ALTER COLUMN position SET NOT NULL|;
41 $self->db_query($query);