Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision db06bb90

Von Sven Schöling vor fast 10 Jahren hinzugefügt

  • ID db06bb909aa58d7c6482c7ea1acf7fa3bcf7e858
  • Vorgänger 271e8829
  • Nachfolger 65b7c724

DeliveryPlan: qtys manuell aus der Datenbank holen

Objektmethoden sind bei grossen Datenbanken zu langsam

Unterschiede anzeigen:

SL/Controller/DeliveryPlan.pm
9 9
use SL::Controller::Helper::GetModels;
10 10
use SL::Controller::Helper::ReportGenerator;
11 11
use SL::Locale::String;
12
use SL::AM;
13
use SL::DBUtils ();
12 14
use Carp;
13 15

  
14 16
use Rose::Object::MakeMethods::Generic (
......
41 43

  
42 44
  my $orderitems = $self->models->get;
43 45

  
46
  $self->calc_qtys($orderitems);
44 47
  $self->report_generator_list_objects(report => $self->{report}, objects => $orderitems);
45 48
}
46 49

  
......
70 73
                                             ($rp_csv_mod ? '' : ' ' .  $_[0]->unit)                                         } },
71 74
    unit              => {      sub => sub {  $_[0]->unit                                                                    },
72 75
                            visible => $rp_csv_mod                                                                           },
73
    shipped_qty       => {      sub => sub { $::form->format_amount(\%::myconfig, $_[0]->shipped_qty, 2) .
76
    shipped_qty       => {      sub => sub { $::form->format_amount(\%::myconfig, $_[0]{shipped_qty}, 2) .
74 77
                                             ($rp_csv_mod ? '' : ' ' .  $_[0]->unit)                                         } },
75
    not_shipped_qty   => {      sub => sub { $::form->format_amount(\%::myconfig, $_[0]->qty - $_[0]->shipped_qty, 2) .
78
    not_shipped_qty   => {      sub => sub { $::form->format_amount(\%::myconfig, $_[0]->qty - $_[0]{shipped_qty}, 2) .
76 79
                                             ($rp_csv_mod ? '' : ' ' .  $_[0]->unit)                                         } },
77
    delivered_qty     => {      sub => sub { $::form->format_amount(\%::myconfig, $_[0]->delivered_qty, 2) .
80
    delivered_qty     => {      sub => sub { $::form->format_amount(\%::myconfig, $_[0]{delivered_qty}, 2) .
78 81
                                             ($rp_csv_mod ? '' : ' ' .  $_[0]->unit)                                         } },
79 82
    ordnumber         => {      sub => sub { $_[0]->order->ordnumber                                                         },
80 83
                           obj_link => sub { $self->link_to($_[0]->order)                                                    } },
......
115 118
  );
116 119
}
117 120

  
121
sub calc_qtys {
122
  my ($self, $orderitems) = @_;
123
  # using $orderitem->shipped_qty 40 times is far too slow. need to do it manually
124
  #
125
  my %orderitems_by_id = map { $_->id => $_ } @$orderitems;
126

  
127
  my $query = <<SQL;
128
    SELECT oi.id, doi.qty, doi.qty, doi.unit, doe.delivered
129
    FROM record_links rl
130
    INNER JOIN delivery_order_items doi ON (doi.delivery_order_id = rl.to_id)
131
    INNER JOIN delivery_orders doe ON (doe.id = rl.to_id)
132
    INNER JOIN orderitems oi ON (oi.trans_id = rl.from_id)
133
    WHERE rl.from_table = 'oe'
134
      AND rl.to_table   = 'delivery_orders'
135
      AND oi.parts_id   = doi.parts_id
136
      AND oi.id IN (@{[ join ', ', ("?")x @$orderitems ]})
137
SQL
138

  
139
  my $result = SL::DBUtils::selectall_hashref_query($::form, $::form->get_standard_dbh, $query, map { $_->id } @$orderitems);
140

  
141
  for my $row (@$result) {
142
    my $item = $orderitems_by_id{ $row->{id} };
143
    $item->{shipped_qty}   ||= 0;
144
    $item->{delivered_qty} ||= 0;
145
    $item->{shipped_qty}    += AM->convert_unit($row->{unit} => $item->unit) * $row->{qty};
146
    $item->{delivered_qty}  += AM->convert_unit($row->{unit} => $item->unit) * $row->{qty} if $row->{delivered};
147
  }
148
}
149

  
118 150
sub make_filter_summary {
119 151
  my ($self) = @_;
120 152
  my $vc     = $self->vc;

Auch abrufbar als: Unified diff