Revision 1cc2d84b
Von Moritz Bunkus vor fast 11 Jahren hinzugefügt
SL/DB/Helper/TransNumberGenerator.pm | ||
---|---|---|
50 | 50 |
|
51 | 51 |
return $number if $self->id && $number; |
52 | 52 |
|
53 |
my %conditions = $scoping_conditions ? ( query => [ $scoping_conditions->($spec_type) ] ) : (); |
|
53 |
require SL::DB::Default; |
|
54 |
require SL::DB::Business; |
|
55 |
|
|
56 |
my %conditions = ( query => [ $scoping_conditions ? $scoping_conditions->($spec_type) : () ] ); |
|
57 |
|
|
58 |
my $business; |
|
59 |
if ($spec_type =~ m{^(?:customer|vendor)$}) { |
|
60 |
$business = $self->business_id ? SL::DB::Business->new(id => $self->business_id)->load : $self->business; |
|
61 |
if ($business && (($business->customernumberinit // '') ne '')) { |
|
62 |
$number_range_column = 'customernumberinit'; |
|
63 |
push @{ $conditions{query} }, ( business_id => $business->id ); |
|
64 |
|
|
65 |
} else { |
|
66 |
undef $business; |
|
67 |
push @{ $conditions{query} }, ( business_id => undef ); |
|
68 |
|
|
69 |
} |
|
70 |
} |
|
71 |
|
|
54 | 72 |
my @numbers = map { $_->$number_column } @{ $self->_get_manager_class->get_all(%conditions) }; |
55 | 73 |
my %numbers_in_use = map { ( $_ => 1 ) } @numbers; |
56 | 74 |
|
57 |
require SL::DB::Default;
|
|
58 |
my $defaults = SL::DB::Default->get;
|
|
59 |
$number_range_column = 'articlenumber' if $number_range_column eq 'assemblynumber' and length($defaults->$number_range_column) < 1;
|
|
60 |
my $sequence = SL::PrefixedNumber->new(number => ($defaults->$number_range_column || 1));
|
|
75 |
my $range_table = $business ? $business : SL::DB::Default->get;
|
|
76 |
my $start_number = $range_table->$number_range_column;
|
|
77 |
$start_number = $range_table->articlenumber if ($number_range_column eq 'assemblynumber') && (length($start_number) < 1);
|
|
78 |
my $sequence = SL::PrefixedNumber->new(number => $start_number);
|
|
61 | 79 |
|
62 | 80 |
$sequence->set_to_max(@numbers) if !$fill_holes_in_range; |
63 | 81 |
|
64 | 82 |
my $new_number = $sequence->get_next; |
65 | 83 |
$new_number = $sequence->get_next while $numbers_in_use{$new_number}; |
66 | 84 |
|
67 |
$defaults->update_attributes($number_range_column => $new_number) if $params{update_defaults};
|
|
68 |
$self->$number_column($new_number) if $params{update_record}; |
|
85 |
$range_table->update_attributes($number_range_column => $new_number) if $params{update_defaults};
|
|
86 |
$self->$number_column($new_number) if $params{update_record};
|
|
69 | 87 |
|
70 | 88 |
return $new_number; |
71 | 89 |
} |
Auch abrufbar als: Unified diff
TransNumberGenerator: Unterstützung für Kunden-/Lieferantennummernkreise
Behebt #2138.