Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 8baddc04

Von Tamino Steinert vor etwa 2 Jahren hinzugefügt

  • ID 8baddc04e4f657ce81c9566c7c1e2b48130f62f3
  • Vorgänger f2fbf58a
  • Nachfolger af8ebe5e

PriceTaxCalculator: adjusted for record items without marge fields

Unterschiede anzeigen:

SL/DB/Helper/PriceTaxCalculator.pm
19 19
  require SL::DB::PriceFactor;
20 20
  require SL::DB::Unit;
21 21

  
22
  my $marge_calculations = $self->can('marge_total');
23

  
22 24
  SL::DB::Part->load_cached(map { $_->parts_id } @{ $self->items }) if @{ $self->items || [] };
23 25

  
24 26
  my %units_by_name       = map { ( $_->name => $_ ) } @{ SL::DB::Manager::Unit->get_all        };
......
53 55
  };
54 56

  
55 57
  $self->netamount(  0);
56
  $self->marge_total(0);
58
  $self->marge_total(0) if $marge_calculations;
57 59

  
58 60
  SL::DB::Manager::Chart->cache_taxkeys(date => $self->effective_tax_point);
59 61

  
......
83 85

  
84 86
sub _calculate_item {
85 87
  my ($self, $item, $idx, $data, %params) = @_;
88
  my $marge_calculations = $self->can('marge_total');
86 89

  
87 90
  my $part       = SL::DB::Part->load_cached($item->parts_id);
88 91
  return unless $part;
......
105 108
  my $sellprice = $item->sellprice;
106 109

  
107 110
  $item->price_factor(      ! $item->price_factor_obj   ? 1 : ($item->price_factor_obj->factor   || 1));
108
  $item->marge_price_factor(! $part->price_factor ? 1 : ($part->price_factor->factor || 1));
111
  $item->marge_price_factor(! $part->price_factor ? 1 : ($part->price_factor->factor || 1)) if $marge_calculations;
109 112
  my $linetotal = _round($sellprice * (1 - $item->discount) * $item->qty / $item->price_factor, 2) * $data->{exchangerate};
110 113
  $linetotal    = _round($linetotal,                                                            2);
111 114

  
......
140 143
  my $linetotal_cost = 0;
141 144

  
142 145
  if (!$linetotal) {
143
    $item->marge_total(  0);
144
    $item->marge_percent(0);
146
    $item->marge_total(  0) if $marge_calculations;
147
    $item->marge_percent(0) if $marge_calculations;
145 148

  
146 149
  } else {
147 150
    my $lastcost       = !(($item->lastcost // 0) * 1) ? ($part->lastcost || 0) : $item->lastcost;
148
    $linetotal_cost    = _round($lastcost * $item->qty / $item->marge_price_factor, 2);
151
    $linetotal_cost    = _round($lastcost * $item->qty / ( $marge_calculations ? $item->marge_price_factor : 1 ), 2);
149 152
    my $linetotal_net  = $self->taxincluded ? $linetotal - $tax_amount : $linetotal;
150 153

  
151
    $item->marge_total(  $linetotal_net - $linetotal_cost);
152
    $item->marge_percent($item->marge_total * 100 / $linetotal_net);
154
    $item->marge_total(  $linetotal_net - $linetotal_cost) if $marge_calculations;
155
    $item->marge_percent($item->marge_total * 100 / $linetotal_net) if $marge_calculations;
153 156

  
154 157
    unless ($data->{allow_optional_items} && $item->optional) {
155
      $self->marge_total(  $self->marge_total + $item->marge_total);
158
      $self->marge_total(  $self->marge_total + $item->marge_total) if $marge_calculations;
156 159
      $data->{lastcost_total} += $linetotal_cost;
157 160
    }
158 161
  }
......
178 181
    taxkey_id      => $taxkey->id,
179 182
  };
180 183

  
181
  _dbg("CALCULATE! ${idx} i.qty " . $item->qty . " i.sellprice " . $item->sellprice . " sellprice $sellprice num_dec $num_dec taxamount $tax_amount " .
182
       "i.linetotal $linetotal netamount " . $self->netamount . " marge_total " . $item->marge_total . " marge_percent " . $item->marge_percent);
184
  #_dbg("CALCULATE! ${idx} i.qty " . $item->qty . " i.sellprice " . $item->sellprice . " sellprice $sellprice num_dec $num_dec taxamount $tax_amount " .
185
  #     "i.linetotal $linetotal netamount " . $self->netamount . " marge_total " . $item->marge_total . " marge_percent " . $item->marge_percent);
183 186
}
184 187

  
185 188
sub _calculate_amounts {
186 189
  my ($self, $data, %params) = @_;
190
  my $marge_calculations = $self->can('marge_total');
187 191

  
188 192
  my $tax_diff = 0;
189 193
  foreach my $chart_id (keys %{ $data->{taxes_by_chart_id} }) {
......
203 207
    $data->{amounts}->{ $data->{last_incex_chart_id} }->{amount} += $data->{invoicediff} if $data->{last_incex_chart_id};
204 208
  }
205 209

  
206
  _dbg("Sna " . $self->netamount . " idiff " . $data->{invoicediff} . " tdiff ${tax_diff}");
210
  #_dbg("Sna " . $self->netamount . " idiff " . $data->{invoicediff} . " tdiff ${tax_diff}");
207 211

  
208 212
  my $tax              = sum values %{ $data->{taxes_by_chart_id} };
209 213
  $amount              = $netamount + $tax;
......
213 217

  
214 218
  $self->netamount(    $netamount);
215 219
  $self->amount(       $grossamount);
216
  $self->marge_percent($self->netamount ? ($self->netamount - $data->{lastcost_total}) * 100 / $self->netamount : 0);
220
  $self->marge_percent($self->netamount ? ($self->netamount - $data->{lastcost_total}) * 100 / $self->netamount : 0) if $marge_calculations;
217 221
}
218 222

  
219 223
sub _calculate_assembly_item {

Auch abrufbar als: Unified diff