use strict;
use SL::DB::MetaSetup::DeliveryOrderItem;
+use SL::DB::Helper::ActsAsList;
use SL::DB::Helper::CustomVariables (
sub_module => 'delivery_order_items',
cvars_alias => 1,
__PACKAGE__->meta->initialize;
+__PACKAGE__->configure_acts_as_list(group_by => [qw(delivery_order_id)]);
+
# methods
1;
mtime => { type => 'timestamp' },
ordnumber => { type => 'text' },
parts_id => { type => 'integer', not_null => 1 },
+ position => { type => 'integer', not_null => 1 },
price_factor => { type => 'numeric', default => 1, precision => 15, scale => 5 },
price_factor_id => { type => 'integer' },
pricegroup_id => { type => 'integer' },
mtime => { type => 'timestamp' },
ordnumber => { type => 'text' },
parts_id => { type => 'integer' },
+ position => { type => 'integer', not_null => 1 },
price_factor => { type => 'numeric', default => 1, precision => 15, scale => 5 },
price_factor_id => { type => 'integer' },
pricegroup_id => { type => 'integer' },
use SL::DB::MetaSetup::OrderItem;
use SL::DB::Manager::OrderItem;
use SL::DB::DeliveryOrderItemsStock;
+use SL::DB::Helper::ActsAsList;
use SL::DB::Helper::CustomVariables (
sub_module => 'orderitems',
cvars_alias => 1,
__PACKAGE__->meta->initialize;
+__PACKAGE__->configure_acts_as_list(group_by => [qw(trans_id)]);
+
sub is_price_update_available {
my $self = shift;
return $self->origprice > $self->part->sellprice;
--- /dev/null
+# @tag: orderitems_delivery_order_items_positions
+# @description: Spalte für Positionen der Einträge in Angeboten/Auftträgen und Lieferscheinen.
+# @depends: release_3_1_0
+# @encoding: utf-8
+package SL::DBUpgrade2::orderitems_delivery_order_items_positions;
+
+use strict;
+use utf8;
+
+use parent qw(SL::DBUpgrade2::Base);
+
+sub run {
+ my ($self) = @_;
+
+ my %order_id_cols = (
+ orderitems => 'trans_id',
+ delivery_order_items => 'delivery_order_id',
+ );
+
+ foreach my $table ( keys %order_id_cols ) {
+
+ my $query = qq|ALTER TABLE $table ADD position INTEGER|;
+ $self->db_query($query);
+
+
+ my $order_id_col = $order_id_cols{ $table };
+ $query = qq|SELECT * FROM $table ORDER BY $order_id_col, id|;
+
+ my $sth = $self->dbh->prepare($query);
+ $sth->execute || $::form->dberror($query);
+
+ # set new postition field in order of ids, starting by one for each order
+ my $last_order_id;
+ my $position;
+ while (my $ref = $sth->fetchrow_hashref("NAME_lc")) {
+ if ($ref->{ $order_id_col } != $last_order_id) {
+ $position = 1;
+ } else {
+ $position++;
+ }
+ $last_order_id = $ref->{ $order_id_col };
+
+ $query = qq|UPDATE $table SET position = ? WHERE id = ?|;
+ $self->db_query($query, bind => [ $position, $ref->{id} ]);
+ }
+ $sth->finish;
+
+
+ $query = qq|ALTER TABLE $table ALTER COLUMN position SET NOT NULL|;
+ $self->db_query($query);
+ }
+
+ return 1;
+}
+
+1;