From: Moritz Bunkus Date: Tue, 7 Jan 2014 10:34:18 +0000 (+0100) Subject: TransNumberGenerator: Unterstützung für Kunden-/Lieferantennummernkreise X-Git-Tag: release-3.1.0beta1~22^2~33^2 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=1cc2d84b58c54133d8d948d85994736f82f2fc88;p=kivitendo-erp.git TransNumberGenerator: Unterstützung für Kunden-/Lieferantennummernkreise Behebt #2138. --- diff --git a/SL/DB/Helper/TransNumberGenerator.pm b/SL/DB/Helper/TransNumberGenerator.pm index a6f4e2e85..6cdc281a8 100644 --- a/SL/DB/Helper/TransNumberGenerator.pm +++ b/SL/DB/Helper/TransNumberGenerator.pm @@ -50,22 +50,40 @@ sub get_next_trans_number { return $number if $self->id && $number; - my %conditions = $scoping_conditions ? ( query => [ $scoping_conditions->($spec_type) ] ) : (); + require SL::DB::Default; + require SL::DB::Business; + + my %conditions = ( query => [ $scoping_conditions ? $scoping_conditions->($spec_type) : () ] ); + + my $business; + if ($spec_type =~ m{^(?:customer|vendor)$}) { + $business = $self->business_id ? SL::DB::Business->new(id => $self->business_id)->load : $self->business; + if ($business && (($business->customernumberinit // '') ne '')) { + $number_range_column = 'customernumberinit'; + push @{ $conditions{query} }, ( business_id => $business->id ); + + } else { + undef $business; + push @{ $conditions{query} }, ( business_id => undef ); + + } + } + my @numbers = map { $_->$number_column } @{ $self->_get_manager_class->get_all(%conditions) }; my %numbers_in_use = map { ( $_ => 1 ) } @numbers; - require SL::DB::Default; - my $defaults = SL::DB::Default->get; - $number_range_column = 'articlenumber' if $number_range_column eq 'assemblynumber' and length($defaults->$number_range_column) < 1; - my $sequence = SL::PrefixedNumber->new(number => ($defaults->$number_range_column || 1)); + my $range_table = $business ? $business : SL::DB::Default->get; + my $start_number = $range_table->$number_range_column; + $start_number = $range_table->articlenumber if ($number_range_column eq 'assemblynumber') && (length($start_number) < 1); + my $sequence = SL::PrefixedNumber->new(number => $start_number); $sequence->set_to_max(@numbers) if !$fill_holes_in_range; my $new_number = $sequence->get_next; $new_number = $sequence->get_next while $numbers_in_use{$new_number}; - $defaults->update_attributes($number_range_column => $new_number) if $params{update_defaults}; - $self->$number_column($new_number) if $params{update_record}; + $range_table->update_attributes($number_range_column => $new_number) if $params{update_defaults}; + $self->$number_column($new_number) if $params{update_record}; return $new_number; }