Revision 50fb51d9
Von Moritz Bunkus vor fast 5 Jahren hinzugefügt
bin/mozilla/io.pl | ||
---|---|---|
40 | 40 |
use Carp; |
41 | 41 |
use CGI; |
42 | 42 |
use List::MoreUtils qw(any uniq apply); |
43 |
use List::Util qw(min max first); |
|
43 |
use List::Util qw(sum min max first);
|
|
44 | 44 |
use List::UtilsBy qw(sort_by uniq_by); |
45 | 45 |
|
46 | 46 |
use SL::ClientJS; |
... | ... | |
1852 | 1852 |
# TODO: both of these are makeshift so that price sources can operate on rdbo objects. if |
1853 | 1853 |
# this ever gets rewritten in controller style, throw this out |
1854 | 1854 |
sub _make_record_item { |
1855 |
my ($row) = @_; |
|
1855 |
my ($row, %params) = @_;
|
|
1856 | 1856 |
|
1857 | 1857 |
my $class = { |
1858 | 1858 |
sales_order => 'OrderItem', |
... | ... | |
1922 | 1922 |
$obj->part(SL::DB::Part->load_cached($::form->{"id_$row"})); |
1923 | 1923 |
} |
1924 | 1924 |
|
1925 |
if ($obj->can('qty')) { |
|
1926 |
$obj->qty( $obj->qty * $params{factor}); |
|
1927 |
$obj->base_qty($obj->base_qty * $params{factor}); |
|
1928 |
} |
|
1929 |
|
|
1925 | 1930 |
return $obj; |
1926 | 1931 |
} |
1927 | 1932 |
|
... | ... | |
1941 | 1946 |
: do { die 'unknown invoice type' }; |
1942 | 1947 |
} |
1943 | 1948 |
|
1949 |
my $factor = $::form->{type} =~ m{credit_note} ? -1 : 1; |
|
1950 |
|
|
1944 | 1951 |
return unless $class; |
1945 | 1952 |
|
1946 | 1953 |
$class = 'SL::DB::' . $class; |
... | ... | |
1971 | 1978 |
my @items; |
1972 | 1979 |
for my $i (1 .. $::form->{rowcount}) { |
1973 | 1980 |
next unless $::form->{"id_$i"}; |
1974 |
push @items, _make_record_item($i); |
|
1981 |
push @items, _make_record_item($i, factor => $factor);
|
|
1975 | 1982 |
} |
1976 | 1983 |
|
1977 | 1984 |
$obj->items(@items) if @items; |
1978 | 1985 |
$obj->is_sales(!!$obj->customer_id) if $class eq 'SL::DB::DeliveryOrder'; |
1979 | 1986 |
|
1987 |
if ($class eq 'SL::DB::Invoice') { |
|
1988 |
my $paid = $factor * |
|
1989 |
sum |
|
1990 |
map { $::form->parse_amount(\%::myconfig, $::form->{$_}) } |
|
1991 |
grep { m{^paid_\d+$} } |
|
1992 |
keys %{ $::form }; |
|
1993 |
$obj->paid($paid); |
|
1994 |
} |
|
1995 |
|
|
1980 | 1996 |
return $obj; |
1981 | 1997 |
} |
1982 | 1998 |
|
Auch abrufbar als: Unified diff
make_record(_item): Unterstützung für Gutschriften
Bei Gutschriften stehen gewisse Werte in $::form positiv, die aber im
Rose-Objekt negativ sein müssen.