Revision b2c6d5a8
Von Moritz Bunkus vor fast 14 Jahren hinzugefügt
SL/TransNumber.pm | ||
---|---|---|
11 | 11 |
|
12 | 12 |
use Rose::Object::MakeMethods::Generic |
13 | 13 |
( |
14 |
scalar => [ qw(type id number save dbh dbh_provided) ], |
|
14 |
scalar => [ qw(type id number save dbh dbh_provided business_id) ],
|
|
15 | 15 |
); |
16 | 16 |
|
17 |
# has 'type' => ( is => 'rw', required => 1 ); |
|
18 |
# has 'id' => ( is => 'rw' ); |
|
19 |
# has 'number' => ( is => 'rw' ); |
|
20 |
# has 'save' => ( is => 'rw', default => 1 ); |
|
21 |
# has 'dbh' => ( is => 'rw' ); |
|
22 |
# has 'dbh_provided' => ( is => 'rw' ); |
|
23 |
|
|
24 | 17 |
Readonly my @SUPPORTED_TYPES => qw(invoice credit_note customer vendor sales_delivery_order purchase_delivery_order sales_order purchase_order sales_quotation request_quotation); |
25 | 18 |
|
26 | 19 |
sub new { |
... | ... | |
32 | 25 |
$self->dbh_provided($self->dbh); |
33 | 26 |
$self->dbh($::form->get_standard_dbh) if !$self->dbh; |
34 | 27 |
$self->save(1) unless defined $self->save; |
28 |
$self->business_id(undef) if $self->type ne 'customer'; |
|
35 | 29 |
|
36 | 30 |
return $self; |
37 | 31 |
} |
... | ... | |
113 | 107 |
my %filters = $self->_get_filters(); |
114 | 108 |
|
115 | 109 |
do_query($form, $self->dbh, qq|LOCK TABLE defaults|); |
110 |
do_query($form, $self->dbh, qq|LOCK TABLE business|) if $self->business_id; |
|
116 | 111 |
|
117 | 112 |
my $where = $filters{where} ? ' WHERE ' . $filters{where} : ''; |
118 | 113 |
my $query = <<SQL; |
... | ... | |
123 | 118 |
|
124 | 119 |
my %numbers_in_use = selectall_as_map($form, $self->dbh, $query, $filters{trans_number}, 'in_use'); |
125 | 120 |
|
126 |
my ($number) = selectfirst_array_query($form, $self->dbh, qq|SELECT $filters{numberfield} FROM defaults|); |
|
127 |
$number ||= ''; |
|
121 |
my $number; |
|
122 |
($number) = selectfirst_array_query($form, $self->dbh, qq|SELECT customernumberinit FROM business WHERE id = ?|, $self->business_id) if $self->business_id; |
|
123 |
($number) = selectfirst_array_query($form, $self->dbh, qq|SELECT $filters{numberfield} FROM defaults|) if !$number; |
|
124 |
$number ||= ''; |
|
128 | 125 |
|
129 | 126 |
do { |
130 | 127 |
if ($number =~ m/\d+$/) { |
... | ... | |
138 | 135 |
} while ($numbers_in_use{$number}); |
139 | 136 |
|
140 | 137 |
if ($self->save) { |
141 |
do_query($form, $self->dbh, qq|UPDATE defaults SET $filters{numberfield} = ?|, $number); |
|
138 |
if ($self->business_id) { |
|
139 |
do_query($form, $self->dbh, qq|UPDATE business SET customernumberinit = ? WHERE id = ?|, $number, $self->business_id); |
|
140 |
} else { |
|
141 |
do_query($form, $self->dbh, qq|UPDATE defaults SET $filters{numberfield} = ?|, $number); |
|
142 |
} |
|
142 | 143 |
$self->dbh->commit if !$self->dbh_provided; |
143 | 144 |
} |
144 | 145 |
|
Auch abrufbar als: Unified diff
Unterstützung für das Erzeugen von Kundennummern, wenn Kundentyp gesetzt ist