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