From: Moritz Bunkus Date: Mon, 17 Jan 2011 11:29:39 +0000 (+0100) Subject: Unterstützung für das Erzeugen von Kundennummern, wenn Kundentyp gesetzt ist X-Git-Tag: release-2.6.2beta2~15 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=b2c6d5a803fc4a3e38dac3cd46edda82baabd7d5;p=kivitendo-erp.git Unterstützung für das Erzeugen von Kundennummern, wenn Kundentyp gesetzt ist --- diff --git a/SL/TransNumber.pm b/SL/TransNumber.pm index 14795e4f7..e2bec7685 100644 --- a/SL/TransNumber.pm +++ b/SL/TransNumber.pm @@ -11,16 +11,9 @@ use SL::DBUtils; use Rose::Object::MakeMethods::Generic ( - scalar => [ qw(type id number save dbh dbh_provided) ], + scalar => [ qw(type id number save dbh dbh_provided business_id) ], ); -# has 'type' => ( is => 'rw', required => 1 ); -# has 'id' => ( is => 'rw' ); -# has 'number' => ( is => 'rw' ); -# has 'save' => ( is => 'rw', default => 1 ); -# has 'dbh' => ( is => 'rw' ); -# has 'dbh_provided' => ( is => 'rw' ); - Readonly my @SUPPORTED_TYPES => qw(invoice credit_note customer vendor sales_delivery_order purchase_delivery_order sales_order purchase_order sales_quotation request_quotation); sub new { @@ -32,6 +25,7 @@ sub new { $self->dbh_provided($self->dbh); $self->dbh($::form->get_standard_dbh) if !$self->dbh; $self->save(1) unless defined $self->save; + $self->business_id(undef) if $self->type ne 'customer'; return $self; } @@ -113,6 +107,7 @@ sub create_unique { my %filters = $self->_get_filters(); do_query($form, $self->dbh, qq|LOCK TABLE defaults|); + do_query($form, $self->dbh, qq|LOCK TABLE business|) if $self->business_id; my $where = $filters{where} ? ' WHERE ' . $filters{where} : ''; my $query = <dbh, $query, $filters{trans_number}, 'in_use'); - my ($number) = selectfirst_array_query($form, $self->dbh, qq|SELECT $filters{numberfield} FROM defaults|); - $number ||= ''; + my $number; + ($number) = selectfirst_array_query($form, $self->dbh, qq|SELECT customernumberinit FROM business WHERE id = ?|, $self->business_id) if $self->business_id; + ($number) = selectfirst_array_query($form, $self->dbh, qq|SELECT $filters{numberfield} FROM defaults|) if !$number; + $number ||= ''; do { if ($number =~ m/\d+$/) { @@ -138,7 +135,11 @@ SQL } while ($numbers_in_use{$number}); if ($self->save) { - do_query($form, $self->dbh, qq|UPDATE defaults SET $filters{numberfield} = ?|, $number); + if ($self->business_id) { + do_query($form, $self->dbh, qq|UPDATE business SET customernumberinit = ? WHERE id = ?|, $number, $self->business_id); + } else { + do_query($form, $self->dbh, qq|UPDATE defaults SET $filters{numberfield} = ?|, $number); + } $self->dbh->commit if !$self->dbh_provided; }