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|;
20 my $query2 = qq|UPDATE invoice SET position = ? WHERE id = ?|;
22 my $sth = $self->dbh->prepare($query);
23 my $sth2 = $self->dbh->prepare($query2);
24 $sth->execute || $::form->dberror($query);
26 # set new position field in order of ids, starting by one for each invoice
29 while (my $ref = $sth->fetchrow_hashref("NAME_lc")) {
30 if ($ref->{trans_id} != $last_invoice_id) {
35 $last_invoice_id = $ref->{trans_id};
37 $sth2->execute($position, $ref->{id});
42 $query = qq|ALTER TABLE invoice ALTER COLUMN position SET NOT NULL|;
43 $self->db_query($query);