Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 5e213cbd

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

  • ID 5e213cbd85d09fff3b43c5026d6c65cf2676cd3d
  • Vorgänger 9f28f178
  • Nachfolger 4c338034

Code bisschen aufgeräumt und anfällige Einheitenkonvertierung ersetzt.

Unterschiede anzeigen:

SL/ARAP.pm
51 51

  
52 52
  my @oe_ids = keys %oe_id_map;
53 53

  
54
#   $main::lxdebug->dump(0, "oe_ids", \@oe_ids);
55

  
56 54
  # No orders found? Nothing to do then, so let's return.
57
  return $main::lxdebug->leave_sub() if (!scalar @oe_ids);
55
  return $main::lxdebug->leave_sub unless @oe_ids;
58 56

  
59
  my $all_units = AM->retrieve_all_units();
57
  my $all_units = AM->retrieve_all_units;
60 58

  
61 59
  my $qtyfactor = $params{table} eq 'ap' ? '* -1' : '';
62 60
  my $q_billed  = qq|SELECT i.parts_id, i.qty ${qtyfactor} AS qty, i.unit, p.unit AS partunit
......
101 99

  
102 100
    my @arap_ids = keys %arap_id_map;
103 101

  
104
#     $main::lxdebug->dump(0, "for $oe_id arap_ids", \@arap_ids);
105

  
106 102
    next if (!scalar @arap_ids);
107 103

  
108 104
    # Retrieve all positions for this order. Calculate the ordered quantity for each position.
......
111 107
    do_statement($form, $h_ordered, $q_ordered, $oe_id);
112 108

  
113 109
    while (my $ref = $h_ordered->fetchrow_hashref()) {
114
      $ref->{baseqty} = $ref->{qty} * $all_units->{$ref->{unit}}->{factor} / $all_units->{$ref->{partunit}}->{factor};
110
      $ref->{baseqty} = $ref->{qty} * AM->convert_unit($ref->{unit}, $ref->{partunit}, $all_units);
115 111

  
116 112
      if ($ordered{$ref->{parts_id}}) {
117 113
        $ordered{$ref->{parts_id}}->{baseqty} += $ref->{baseqty};
......
127 123
      do_statement($form, $h_billed, $q_billed, $arap_id);
128 124

  
129 125
      while (my $ref = $h_billed->fetchrow_hashref()) {
130
        $ref->{baseqty} = $ref->{qty} * $all_units->{$ref->{unit}}->{factor} / $all_units->{$ref->{partunit}}->{factor};
126
        $ref->{baseqty} = $ref->{qty} * AM->convert_unit($ref->{unit}, $ref->{partunit}, $all_units);
131 127

  
132 128
        if ($billed{$ref->{parts_id}}) {
133 129
          $billed{$ref->{parts_id}}->{baseqty} += $ref->{baseqty};
......
146 142
      }
147 143
    }
148 144

  
149
#     $main::lxdebug->message(0, "all_billed $all_billed");
150
#     $main::lxdebug->dump(0, "ordered", \%ordered);
151
#     $main::lxdebug->dump(0, "billed", \%billed);
152

  
153 145
    push @close_oe_ids, $oe_id if ($all_billed);
154 146
  }
155 147

  
156
  $h_billed->finish();
157
  $h_ordered->finish();
148
  $h_billed->finish;
149
  $h_ordered->finish;
158 150

  
159 151
  # Close orders that have been billed fully.
160 152
  if (scalar @close_oe_ids) {
161 153
    my $query = qq|UPDATE oe SET closed = TRUE WHERE id IN (| . join(', ', ('?') x scalar @close_oe_ids) . qq|)|;
162 154
    do_query($form, $dbh, $query, @close_oe_ids);
163 155

  
164
    $dbh->commit() unless ($params{dbh});
156
    $dbh->commit unless $params{dbh};
165 157
  }
166 158

  
167 159
  $main::lxdebug->leave_sub();

Auch abrufbar als: Unified diff