X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FDB%2FDeliveryOrder.pm;h=f4e630148e5eb0fa35cab589842b0d7ca799a7a6;hb=a3449070f9bb3621bf675b40510a324942e7117e;hp=3f2cd3e7ef175e4097d4121bd72366d142cb0d0c;hpb=b38219b3df1e6b4da804428152dc19ec4750385e;p=kivitendo-erp.git diff --git a/SL/DB/DeliveryOrder.pm b/SL/DB/DeliveryOrder.pm index 3f2cd3e7e..f4e630148 100644 --- a/SL/DB/DeliveryOrder.pm +++ b/SL/DB/DeliveryOrder.pm @@ -20,7 +20,7 @@ use SL::DB::Unit; use SL::Helper::Number qw(_format_total _round_total); use List::Util qw(first); -use List::MoreUtils qw(any); +use List::MoreUtils qw(any pairwise); use Math::Round qw(nhimult); __PACKAGE__->meta->add_relationship(orderitems => { type => 'one to many', @@ -127,7 +127,7 @@ sub new_from { } my %args = ( map({ ( $_ => $source->$_ ) } qw(cp_id currency_id customer_id cusordnumber delivery_term_id department_id employee_id globalproject_id intnotes language_id notes - ordnumber payment_id reqdate salesman_id shippingpoint shipvia taxincluded taxzone_id transaction_description vendor_id + ordnumber payment_id reqdate salesman_id shippingpoint shipvia taxincluded taxzone_id transaction_description vendor_id billing_address_id )), closed => 0, is_sales => !!$source->customer_id, @@ -185,39 +185,31 @@ sub new_from_time_recordings { croak("Unsupported object type in sources") if any { ref($_) ne 'SL::DB::TimeRecording' } @$sources; croak("Cannot create delivery order from source records of different customers") if any { $_->customer_id != $sources->[0]->customer_id } @$sources; - my %args = ( - is_sales => 1, - delivered => 0, - customer_id => $sources->[0]->customer_id, - taxzone_id => $sources->[0]->customer->taxzone_id, - currency_id => $sources->[0]->customer->currency_id, - employee_id => SL::DB::Manager::Employee->current->id, - salesman_id => SL::DB::Manager::Employee->current->id, - items => [], - ); - my $delivery_order = $class->new(%args); - $delivery_order->assign_attributes(%{ $params{attributes} }) if $params{attributes}; - # - one item per part (article) # - qty is sum of duration # - description goes to item longdescription # - ordered and summed by date # - each description goes to an ordered list # - (as time recording descriptions are formatted text by now, use stripped text) - # - merge same descriptions (todo) + # - merge same descriptions # - ### config - my $default_partnummer = 6; - my $default_part_id = SL::DB::Manager::Part->find_by(partnumber => $default_partnummer)->id; + my $default_part_id = $params{default_part_id} ? $params{default_part_id} + : $params{default_partnumber} ? SL::DB::Manager::Part->find_by(partnumber => $params{default_partnumber})->id + : undef; + my $override_part_id = $params{override_part_id} ? $params{override_part_id} + : $params{override_partnumber} ? SL::DB::Manager::Part->find_by(partnumber => $params{override_partnumber})->id + : undef; # check parts and collect entries my %part_by_part_id; my $entries; foreach my $source (@$sources) { - my $part_id = $source->part_id ? $source->part_id - : $default_part_id ? $default_part_id - : undef; + next if !$source->duration; + + my $part_id = $override_part_id; + $part_id ||= $source->part_id; + $part_id ||= $default_part_id; die 'article not found for entry "' . $source->displayable_times . '"' if !$part_id; @@ -226,8 +218,8 @@ sub new_from_time_recordings { die 'article unit must be time based for entry "' . $source->displayable_times . '"' if !$part_by_part_id{$part_id}->unit_obj->is_time_based; } - my $date = $source->start_time->to_kivitendo; - $entries->{$part_id}->{$date}->{duration} += $source->{rounding} + my $date = $source->date->to_kivitendo; + $entries->{$part_id}->{$date}->{duration} += $params{rounding} ? nhimult(0.25, ($source->duration_in_hours)) : _round_total($source->duration_in_hours); # add content if not already in description @@ -236,9 +228,11 @@ sub new_from_time_recordings { $entries->{$part_id}->{$date}->{content} .= '