Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision a2820962

Von Moritz Bunkus vor fast 12 Jahren hinzugefügt

  • ID a28209621fe9aab10b764551a8a4427faec2006d
  • Vorgänger a93f1e39
  • Nachfolger fd0a62ab

Umwandlung Angebot/Auftrag -> Lieferschein/Rechnung: nur nicht gelieferte/berechnete Mengen vorgeben

Unterschiede anzeigen:

bin/mozilla/io.pl
1898 1898

  
1899 1899
  $main::lxdebug->leave_sub(2);
1900 1900
}
1901

  
1902
sub _remove_billed_or_delivered_rows {
1903
  my (%params) = @_;
1904

  
1905
  croak "Missing parameter 'quantities'" if !$params{quantities};
1906

  
1907
  my @fields = map { s/_1$//; $_ } grep { m/_1$/ } keys %{ $::form };
1908
  my @new_rows;
1909

  
1910
  my $removed_rows = 0;
1911
  my $row          = 0;
1912
  while ($row < $::form->{rowcount}) {
1913
    $row++;
1914
    next unless $::form->{"id_$row"};
1915

  
1916
    my $parts_id                      = $::form->{"id_$row"};
1917
    my $base_qty                      = $::form->parse_amount(\%::myconfig, $::form->{"qty_$row"}) * SL::DB::Manager::Unit->find_by(name => $::form->{"unit_$row"})->base_factor;
1918

  
1919
    my $sub_qty                       = min($base_qty, $params{quantities}->{$parts_id});
1920
    $params{quantities}->{$parts_id} -= $sub_qty;
1921

  
1922
    if (!$sub_qty || ($sub_qty != $base_qty)) {
1923
      $::form->{"qty_${row}"} = $::form->format_amount(\%::myconfig, ($base_qty - $sub_qty) / SL::DB::Manager::Unit->find_by(name => $::form->{"unit_$row"})->base_factor);
1924
      push @new_rows, { map { $_ => $::form->{"${_}_${row}"} } @fields };
1925

  
1926
    } else {
1927
      $removed_rows++;
1928
    }
1929
  }
1930

  
1931
  $::form->redo_rows(\@fields, \@new_rows, scalar(@new_rows), $::form->{rowcount});
1932
  $::form->{rowcount} -= $removed_rows;
1933
}
bin/mozilla/oe.pl
31 31
# Quotation module
32 32
#======================================================================
33 33

  
34

  
35
use Carp;
34 36
use POSIX qw(strftime);
35 37

  
36 38
use SL::DO;
......
42 44
use SL::PE;
43 45
use SL::ReportGenerator;
44 46
use List::MoreUtils qw(any none);
45
use List::Util qw(max reduce sum);
47
use List::Util qw(min max reduce sum);
46 48
use Data::Dumper;
47 49

  
48 50
require "bin/mozilla/io.pl";
......
1335 1337
    ::end_of_request();
1336 1338
  }
1337 1339

  
1340
  _oe_remove_delivered_or_billed_rows(id => $form->{id}, type => 'billed');
1341

  
1338 1342
  $form->{cp_id} *= 1;
1339 1343

  
1340 1344
  for my $i (1 .. $form->{rowcount}) {
......
1870 1874
  $form->{old_employee_id}  = $form->{employee_id};
1871 1875
  $form->{old_salesman_id}  = $form->{salesman_id};
1872 1876

  
1877
  _oe_remove_delivered_or_billed_rows(id => $form->{id}, type => 'delivered');
1878

  
1873 1879
  # reset
1874 1880
  delete @{$form}{qw(id subject message cc bcc printed emailed queued creditlimit creditremaining discount tradediscount oldinvtotal closed delivered)};
1875 1881

  
......
2043 2049
  $::lxdebug->leave_sub();
2044 2050
}
2045 2051

  
2052
sub _oe_remove_delivered_or_billed_rows {
2053
  my (%params) = @_;
2054

  
2055
  return if !$params{id} || !$params{type};
2056

  
2057
  my $ord_quot = SL::DB::Order->new(id => $params{id})->load;
2058
  return if !$ord_quot;
2059

  
2060
  my %args    = (
2061
    direction => 'to',
2062
    to        =>   $params{type} eq 'delivered' ? 'DeliveryOrder' : 'Invoice',
2063
    via       => [ $params{type} eq 'delivered' ? qw(Order)       : qw(Order DeliveryOrder) ],
2064
  );
2065

  
2066
  my %handled_base_qtys;
2067
  foreach my $record (@{ $ord_quot->linked_records(%args) }) {
2068
    next if $ord_quot->is_sales != $record->is_sales;
2069

  
2070
    foreach my $item (@{ $record->items }) {
2071
      $handled_base_qtys{ $item->parts_id } += $item->qty * $item->unit_obj->base_factor;
2072
    }
2073
  }
2074

  
2075
  _remove_billed_or_delivered_rows(quantities => \%handled_base_qtys);
2076
}
2077

  
2046 2078
sub dispatcher {
2047 2079
  foreach my $action (qw(delete delivery_order e_mail invoice print purchase_order purchase_order quotation
2048 2080
                         request_for_quotation sales_order sales_order save save_and_close save_as_new ship_to update)) {

Auch abrufbar als: Unified diff