X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FTransNumber.pm;h=1e62cfb073b2e377a35e7a5f4fda492dfcaca755;hb=ea507623073ea48951f1c1ba38f2a0841b14d47a;hp=859ca68659246868619b4b11a149ac732b7ce6d8;hpb=6c0a55aca160c95f56fd52196d946a0708a2c7b5;p=kivitendo-erp.git diff --git a/SL/TransNumber.pm b/SL/TransNumber.pm index 859ca6865..1e62cfb07 100644 --- a/SL/TransNumber.pm +++ b/SL/TransNumber.pm @@ -14,7 +14,7 @@ use Rose::Object::MakeMethods::Generic scalar => [ qw(type id number save dbh dbh_provided business_id) ], ); -my @SUPPORTED_TYPES = qw(invoice credit_note customer vendor sales_delivery_order purchase_delivery_order sales_order purchase_order sales_quotation request_quotation part service assembly); +my @SUPPORTED_TYPES = qw(invoice credit_note customer vendor sales_delivery_order purchase_delivery_order sales_order purchase_order sales_quotation request_quotation part service assembly letter); sub new { my $class = shift; @@ -71,7 +71,10 @@ sub _get_filters { $filters{numberfield} = $type eq 'service' ? 'servicenumber' : 'articlenumber'; $filters{numberfield} = $type eq 'assembly' ? 'assemblynumber' : $filters{numberfield}; $filters{table} = "parts"; - $filters{where} = 'COALESCE(inventory_accno_id, 0) ' . ($type eq 'service' ? '= 0' : '<> 0 OR assembly'); + } elsif ($type =~ /letter/) { + $filters{trans_number} = "letternumber"; + $filters{numberfield} = "letternumber"; + $filters{table} = "letter"; } return %filters; @@ -114,8 +117,6 @@ sub create_unique { my %filters = $self->_get_filters(); $self->dbh->begin_work if $self->dbh->{AutoCommit}; - 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, "LOCK TABLE " . $filters{table}) || die $self->dbh->errstr; my %numbers_in_use = selectall_as_map($form, $self->dbh, $query, $filters{trans_number}, 'in_use'); my $business_number; - ($business_number) = selectfirst_array_query($form, $self->dbh, qq|SELECT customernumberinit FROM business WHERE id = ?|, $self->business_id) if $self->business_id; + ($business_number) = selectfirst_array_query($form, $self->dbh, qq|SELECT customernumberinit FROM business WHERE id = ? FOR UPDATE|, $self->business_id) if $self->business_id; my $number = $business_number; - ($number) = selectfirst_array_query($form, $self->dbh, qq|SELECT $filters{numberfield} FROM defaults|) if !$number; + ($number) = selectfirst_array_query($form, $self->dbh, qq|SELECT $filters{numberfield} FROM defaults FOR UPDATE|) if !$number; if ($filters{numberfield} eq 'assemblynumber' and length($number) < 1) { $filters{numberfield} = 'articlenumber'; - ($number) = selectfirst_array_query($form, $self->dbh, qq|SELECT $filters{numberfield} FROM defaults|) if !$number; + ($number) = selectfirst_array_query($form, $self->dbh, qq|SELECT $filters{numberfield} FROM defaults FOR UPDATE|) if !$number; } $number ||= ''; my $sequence = SL::PrefixedNumber->new(number => $number);