X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/kivitendo-erp.git/blobdiff_plain/b9dbc9e3d4f8821d9fd324b52dafb81b699a776e..76da5bf5bf6929e4cc11a8eb48a53e078ff6e167:/SL/DB/Helper/TransNumberGenerator.pm diff --git a/SL/DB/Helper/TransNumberGenerator.pm b/SL/DB/Helper/TransNumberGenerator.pm index 2ac06edd0..c060a2f5d 100644 --- a/SL/DB/Helper/TransNumberGenerator.pm +++ b/SL/DB/Helper/TransNumberGenerator.pm @@ -3,7 +3,7 @@ package SL::DB::Helper::TransNumberGenerator; use strict; use parent qw(Exporter); -our @EXPORT = qw(get_next_trans_number); +our @EXPORT = qw(get_next_trans_number create_trans_number); use Carp; use List::Util qw(max); @@ -78,3 +78,92 @@ sub create_trans_number { } 1; + +__END__ + +=pod + +=encoding utf8 + +=head1 NAME + +SL::DB::Helper::TransNumberGenerator - A mixin for creating unique record numbers + +=head1 FUNCTIONS + +=over 4 + +=item C + +Generates a new unique record number for the mixing class. Each record +type (invoices, sales quotations, purchase orders etc) has its own +number range. Within these ranges all numbers should be unique. The +table C contains the last record number assigned for all of +the number ranges. + +This function contains hard-coded knowledge about the modules it can +be mixed into. This way the models themselves don't have to contain +boilerplate code for the details like the the number range column's +name in the C table. + +The process of creating a unique number involves the following steps: + +At first all existing record numbers for the current type are +retrieved from the database as well as the last number assigned from +the table C. + +The next step is separating the number range from C into two +parts: an optional non-numeric prefix and its numeric suffix. The +prefix, if present, will be kept intact. + +Now the number itself is increased as often as neccessary to create a +unique one by comparing the generated numbers with the existing ones +retrieved in the first step. In this step gaps in the assigned numbers +are filled for some tables (e.g. invoices) but not for others +(e.g. sales orders). + +After creating the unique record number this function can update +C<$self> and the C table if requested. This is controlled +with the following parameters: + +=over 2 + +=item * C + +Determines whether or not C<$self>'s record number field is set to the +newly generated number. C<$self> will not be saved even if this +parameter is trueish. Defaults to false. + +=item * C + +Determines whether or not the number range value in the C +table should be updated. Unlike C<$self> the C table will be +saved. Defaults to false. + +=back + +Always returns the newly generated number. This function cannot fail +and return a value. If it fails then it is due to exceptions. + +=item C + +Calls and returns L with the parameters +C and C. C<%params> is passed +to it as well. + +=back + +=head1 EXPORTS + +This mixin exports all of its functions: L and +L. There are no optional exports. + +=head1 BUGS + +Nothing here yet. + +=head1 AUTHOR + +Moritz Bunkus Em.bunkus@linet-services.deE + +=cut