Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 02c95ae1

Von Moritz Bunkus vor fast 14 Jahren hinzugefügt

  • ID 02c95ae1b7e9f46951854f6a105f9cd39b98e3bb
  • Vorgänger 62bb3c51
  • Nachfolger 78600d89

Dokumentation

Unterschiede anzeigen:

SL/DB/Helper/TransNumberGenerator.pm
78 78
}
79 79

  
80 80
1;
81

  
82
__END__
83

  
84
=pod
85

  
86
=encoding utf8
87

  
88
=head1 NAME
89

  
90
SL::DB::Helper::TransNumberGenerator - A mixin for creating unique record numbers
91

  
92
=head1 FUNCTIONS
93

  
94
=over 4
95

  
96
=item C<get_mext_trams_number %params>
97

  
98
Generates a new unique record number for the mixing class. Each record
99
type (invoices, sales quotations, purchase orders etc) has its own
100
number range. Within these ranges all numbers should be unique. The
101
table C<defaults> contains the last record number assigned for all of
102
the number ranges.
103

  
104
This function contains hard-coded knowledge about the modules it can
105
be mixed into. This way the models themselves don't have to contain
106
boilerplate code for the details like the the number range column's
107
name in the C<defaults> table.
108

  
109
The process of creating a unique number involves the following steps:
110

  
111
At first all existing record numbers for the current type are
112
retrieved from the database as well as the last number assigned from
113
the table C<defaults>.
114

  
115
The next step is separating the number range from C<defaults> into two
116
parts: an optional non-numeric prefix and its numeric suffix. The
117
prefix, if present, will be kept intact.
118

  
119
Now the number itself is increased as often as neccessary to create a
120
unique one by comparing the generated numbers with the existing ones
121
retrieved in the first step. In this step gaps in the assigned numbers
122
are filled for some tables (e.g. invoices) but not for others
123
(e.g. sales orders).
124

  
125
After creating the unique record number this function can update
126
C<$self> and the C<defaults> table if requested. This is controlled
127
with the following parameters:
128

  
129
=over 2
130

  
131
=item * C<update_record>
132

  
133
Determines whether or not C<$self>'s record number field is set to the
134
newly generated number. C<$self> will not be saved even if this
135
parameter is trueish. Defaults to false.
136

  
137
=item * C<update_defaults>
138

  
139
Determines whether or not the number range value in the C<defaults>
140
table should be updated. Unlike C<$self> the C<defaults> table will be
141
saved. Defaults to false.
142

  
143
=back
144

  
145
Always returns the newly generated number. This function cannot fail
146
and return a value. If it fails then it is due to exceptions.
147

  
148
=item C<create_trans_number %params>
149

  
150
Calls and returns L</get_next_trans_number> with the parameters
151
C<update_defaults = 1> and C<update_record = 1>. C<%params> is passed
152
to it as well.
153

  
154
=back
155

  
156
=head1 EXPORTS
157

  
158
This mixin exports all of its functions: L</get_next_trans_number> and
159
L</create_trans_number>. There are no optional exports.
160

  
161
=head1 BUGS
162

  
163
Nothing here yet.
164

  
165
=head1 AUTHOR
166

  
167
Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>
168

  
169
=cut

Auch abrufbar als: Unified diff