Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision ecb95993

Von Sven Schöling vor mehr als 7 Jahren hinzugefügt

  • ID ecb95993cd0a1635dc759e0733cac883be3fdc0c
  • Vorgänger 400d16e3
  • Nachfolger e80aa4c8

DeliveryPlan: calc_qtys mit SL::Helper::ShippedQty berechnen

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::Helper::ShippedQty;
12 13
use SL::AM;
13 14
use SL::DBUtils ();
14 15
use Carp;
......
26 27
  partnumber        => t8('Part Number'),
27 28
  qty               => t8('Qty'),
28 29
  shipped_qty       => t8('shipped'),
29
  delivered_qty     => t8('transferred in / out'),
30 30
  not_shipped_qty   => t8('not shipped'),
31 31
  ordnumber         => t8('Order'),
32 32
  customer          => t8('Customer'),
......
54 54
  my $report      = SL::ReportGenerator->new(\%::myconfig, $::form);
55 55
  $self->{report} = $report;
56 56

  
57
  my @columns     = qw(reqdate customer vendor ordnumber partnumber description qty shipped_qty not_shipped_qty delivered_qty);
57
  my @columns     = qw(reqdate customer vendor ordnumber partnumber description qty shipped_qty not_shipped_qty);
58 58

  
59 59
  my @sortable    = qw(reqdate customer vendor ordnumber partnumber description);
60 60

  
......
67 67
    qty               => {      sub => sub { $_[0]->qty_as_number . ' ' . $_[0]->unit                                        } },
68 68
    shipped_qty       => {      sub => sub { $::form->format_amount(\%::myconfig, $_[0]{shipped_qty}, 2) . ' ' . $_[0]->unit } },
69 69
    not_shipped_qty   => {      sub => sub { $::form->format_amount(\%::myconfig, $_[0]->qty - $_[0]{shipped_qty}, 2) . ' ' . $_[0]->unit } },
70
    delivered_qty     => {      sub => sub { $::form->format_amount(\%::myconfig, $_[0]{delivered_qty}, 2) .' ' . $_[0]->unit } },
71 70
    ordnumber         => {      sub => sub { $_[0]->order->ordnumber                                                         },
72 71
                           obj_link => sub { $self->link_to($_[0]->order)                                                    } },
73 72
    vendor            => {      sub => sub { $_[0]->order->vendor->name                                                      },
......
105 104

  
106 105
sub calc_qtys {
107 106
  my ($self, $orderitems) = @_;
108
  # using $orderitem->shipped_qty 40 times is far too slow. need to do it manually
109
  #
110 107

  
111 108
  return unless scalar @$orderitems;
112 109

  
113
  my %orderitems_by_id = map { $_->id => $_ } @$orderitems;
114

  
115
  my $query = $self->use_linked_items ? _calc_qtys_query_linked_items(scalar @$orderitems)
116
            :                           _calc_qtys_query_match_parts(scalar @$orderitems);
117

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

  
120
  for my $row (@$result) {
121
    my $item = $orderitems_by_id{ $row->{id} };
122
    $item->{shipped_qty}   ||= 0;
123
    $item->{delivered_qty} ||= 0;
124
    $item->{shipped_qty}    += AM->convert_unit($row->{unit} => $item->unit) * $row->{qty};
125
    $item->{delivered_qty}  += AM->convert_unit($row->{unit} => $item->unit) * $row->{qty} if $row->{delivered};
126
  }
127
}
128

  
129
sub _calc_qtys_query_match_parts {
130
  my ($num_items) = @_;
131

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

  
144
  return $query;
145
}
146

  
147
sub _calc_qtys_query_linked_items {
148
  my ($num_items) = @_;
149

  
150
  my $query = <<SQL;
151
    SELECT rl.from_id as id, doi.qty, doi.unit, doe.delivered
152
    FROM record_links rl
153
    INNER JOIN delivery_order_items doi ON (doi.id = rl.to_id)
154
    INNER JOIN delivery_orders doe ON (doe.id = doi.delivery_order_id)
155
    WHERE rl.from_table LIKE 'orderitems'
156
      AND rl.to_table   LIKE 'delivery_order_items'
157
      AND rl.from_id IN (@{[ join ', ', ("?")x $num_items ]})
158
SQL
159

  
160
  return $query;
110
  SL::Helper::ShippedQty
111
    ->new(fill_up => !$self->use_linked_items)
112
    ->calculate($orderitems)
113
    ->write_to_objects;
161 114
}
162 115

  
163 116
sub make_filter_summary {

Auch abrufbar als: Unified diff