From 5c03b316c349b081a165f0c8b45348b70e712565 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sven=20Sch=C3=B6ling?= Date: Fri, 1 Oct 2021 19:45:08 +0200 Subject: [PATCH] =?utf8?q?do:=20neue=20Nummerkreise=20f=C3=BCr=20supplier?= =?utf8?q?=20und=20rma=20Lieferscheine?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/DB/DeliveryOrder/TypeData.pm | 4 ++++ SL/DB/Helper/TransNumberGenerator.pm | 2 ++ SL/DB/Manager/DeliveryOrder.pm | 7 +++---- SL/DB/MetaSetup/Default.pm | 2 ++ SL/TransNumber.pm | 17 +++++++++++------ sql/Pg-upgrade2/deliveryorder_transnumbers.sql | 11 +++++++++++ 6 files changed, 33 insertions(+), 10 deletions(-) create mode 100644 sql/Pg-upgrade2/deliveryorder_transnumbers.sql diff --git a/SL/DB/DeliveryOrder/TypeData.pm b/SL/DB/DeliveryOrder/TypeData.pm index 079e4942b..5f359736f 100644 --- a/SL/DB/DeliveryOrder/TypeData.pm +++ b/SL/DB/DeliveryOrder/TypeData.pm @@ -43,6 +43,7 @@ my %type_data = ( is_customer => 1, nr_key => "donumber", transfer => 'out', + transnumber => 'sdonumber', }, part_classification_query => [ "used_for_sale" => 1 ], right => "sales_delivery_order_edit", @@ -70,6 +71,7 @@ my %type_data = ( is_customer => 0, nr_key => "donumber", transfer => 'in', + transnumber => 'pdonumber', }, part_classification_query => [ "used_for_purchase" => 1 ], right => "purchase_delivery_order_edit", @@ -97,6 +99,7 @@ my %type_data = ( is_customer => 0, nr_key => "donumber", transfer => 'out', + transnumber => 'sudonumber', }, part_classification_query => [ "used_for_purchase" => 1 ], right => "purchase_delivery_order_edit", @@ -124,6 +127,7 @@ my %type_data = ( is_customer => 0, nr_key => "donumber", transfer => 'in', + transnumber => 'rdonumber', }, part_classification_query => [ "used_for_sale" => 1 ], right => "sales_delivery_order_edit", diff --git a/SL/DB/Helper/TransNumberGenerator.pm b/SL/DB/Helper/TransNumberGenerator.pm index 5b45853db..eb89ea8b3 100644 --- a/SL/DB/Helper/TransNumberGenerator.pm +++ b/SL/DB/Helper/TransNumberGenerator.pm @@ -30,6 +30,8 @@ my %specs = ( ar => { number_column => 'invnumber', purchase_order => { number_column => 'ordnumber', number_range_column => 'ponumber', scoping => \&oe_scoping, }, sales_delivery_order => { number_column => 'donumber', number_range_column => 'sdonumber', scoping => \&do_scoping, }, purchase_delivery_order => { number_column => 'donumber', number_range_column => 'pdonumber', scoping => \&do_scoping, }, + supplier_delivery_order => { number_column => 'donumber', number_range_column => 'sudonumber', scoping => \&do_scoping, }, + rma_delivery_order => { number_column => 'donumber', number_range_column => 'rdonumber', scoping => \&do_scoping, }, customer => { number_column => 'customernumber', number_range_column => 'customernumber', }, vendor => { number_column => 'vendornumber', number_range_column => 'vendornumber', }, part => { number_column => 'partnumber', number_range_column => 'articlenumber', scoping => \&parts_scoping, }, diff --git a/SL/DB/Manager/DeliveryOrder.pm b/SL/DB/Manager/DeliveryOrder.pm index 156ca7b2d..9f45ca0c9 100644 --- a/SL/DB/Manager/DeliveryOrder.pm +++ b/SL/DB/Manager/DeliveryOrder.pm @@ -8,6 +8,8 @@ use SL::DB::Helper::Paginated; use SL::DB::Helper::Sorted; use SL::DB::Helper::Filtered; +use SL::DB::DeliveryOrder::TypeData qw(validate_type); + sub object_class { 'SL::DB::DeliveryOrder' } __PACKAGE__->make_manager_methods; @@ -27,10 +29,7 @@ sub type_filter { my $class = shift; my $type = lc(shift || ''); - return ('!customer_id' => undef) if $type eq 'sales_delivery_order'; - return ('!vendor_id' => undef) if $type eq 'purchase_delivery_order'; - - die "Unknown type $type"; + return type => validate_type($type); } sub _sort_spec { diff --git a/SL/DB/MetaSetup/Default.pm b/SL/DB/MetaSetup/Default.pm index b7fe2b1e2..ba8cf3228 100644 --- a/SL/DB/MetaSetup/Default.pm +++ b/SL/DB/MetaSetup/Default.pm @@ -148,6 +148,7 @@ __PACKAGE__->meta->columns( purchase_delivery_order_show_delete => { type => 'boolean', default => 'true' }, purchase_order_show_delete => { type => 'boolean', default => 'true' }, quick_search_modules => { type => 'array' }, + rdonumber => { type => 'text' }, reqdate_interval => { type => 'integer', default => '0' }, reqdate_on => { type => 'boolean', default => 'true' }, require_transaction_description_ps => { type => 'boolean', default => 'false', not_null => 1 }, @@ -182,6 +183,7 @@ __PACKAGE__->meta->columns( stocktaking_cutoff_date => { type => 'date' }, stocktaking_qty_threshold => { type => 'numeric', default => '0', precision => 25, scale => 5 }, stocktaking_warehouse_id => { type => 'integer' }, + sudonumber => { type => 'text' }, taxnumber => { type => 'text' }, templates => { type => 'text' }, transfer_default => { type => 'boolean', default => 'true' }, diff --git a/SL/TransNumber.pm b/SL/TransNumber.pm index 25646dafb..8e87d3b7c 100644 --- a/SL/TransNumber.pm +++ b/SL/TransNumber.pm @@ -9,13 +9,16 @@ use List::MoreUtils qw(any none); use SL::DBUtils; use SL::PrefixedNumber; use SL::DB; +use SL::DB::DeliveryOrder::TypeData; use Rose::Object::MakeMethods::Generic ( scalar => [ qw(type id number save dbh dbh_provided business_id) ], ); -my @SUPPORTED_TYPES = qw(invoice invoice_for_advance_payment final_invoice credit_note customer vendor sales_delivery_order purchase_delivery_order sales_order purchase_order sales_quotation request_quotation part service assembly assortment letter); +my @SUPPORTED_TYPES = qw(invoice invoice_for_advance_payment final_invoice credit_note customer vendor sales_delivery_order purchase_delivery_order sales_order purchase_order sales_quotation request_quotation part service assembly assortment letter), + @{ SL::DB::DeliveryOrder::TypeData::valid_types() }, +); sub new { my $class = shift; @@ -47,11 +50,12 @@ sub _get_filters { $filters{numberfield} = "${type}number"; $filters{table} = $type; - } elsif ($type =~ /_delivery_order$/) { - $filters{trans_number} = "donumber"; - $filters{numberfield} = $type eq 'sales_delivery_order' ? "sdonumber" : "pdonumber"; + } elsif ($type =~ /_delivery_order$/ && SL::DB::DeliveryOrder::TypeData::is_valid_type($type)) { + $filters{trans_number} = SL::DB::DeliveryOrder::TypeData::get3($type, 'properties', 'nr_key'), + $filters{numberfield} = SL::DB::DeliveryOrder::TypeData::get3($type, 'properties', 'transnumber'), $filters{table} = "delivery_orders"; - $filters{where} = $type =~ /^sales/ ? '(customer_id IS NOT NULL)' : '(vendor_id IS NOT NULL)'; + $filters{where} = "order_type = ?"; + $filters{values} = [ $::form->{type} ]; } elsif ($type =~ /_order$/) { $filters{trans_number} = "ordnumber"; @@ -96,6 +100,7 @@ sub is_unique { my @values = ($self->number); push @where, $filters{where} if $filters{where}; + push @values, @{ $filters{values} } if $filters{values}; if ($self->id) { push @where, qq|id <> ?|; @@ -131,7 +136,7 @@ sub create_unique { SQL do_query($form, $self->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 %numbers_in_use = selectall_as_map($form, $self->dbh, $query, $filters{trans_number}, 'in_use', @{ $filters{values} // [] }); my $business_number; ($business_number) = selectfirst_array_query($form, $self->dbh, qq|SELECT customernumberinit FROM business WHERE id = ? FOR UPDATE|, $self->business_id) if $self->business_id; diff --git a/sql/Pg-upgrade2/deliveryorder_transnumbers.sql b/sql/Pg-upgrade2/deliveryorder_transnumbers.sql new file mode 100644 index 000000000..3e03150d9 --- /dev/null +++ b/sql/Pg-upgrade2/deliveryorder_transnumbers.sql @@ -0,0 +1,11 @@ +-- @tag: deliveryorder_transnumbers +-- @description: Nummernkreise für neue lieferscheintypen +-- @depends: release_3_5_8 + +ALTER TABLE defaults ADD COLUMN sudonumber TEXT; +ALTER TABLE defaults ADD COLUMN rdonumber TEXT; + +UPDATE defaults SET + sudonumber = '0', + rdonumber = '0'; + -- 2.20.1