From b5b366c932e2a8118cafa0d27432fa268099d419 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Mon, 25 Oct 2021 14:51:33 +0200 Subject: [PATCH] =?utf8?q?Zus=C3=A4tzliche=20Rechnungsadressen:=20Datenban?= =?utf8?q?kupgrade,=20MetaSetup,=20Rose-Models?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/DB/AdditionalBillingAddress.pm | 41 +++++++++++++++++ SL/DB/Customer.pm | 6 +++ SL/DB/Helper/ALL.pm | 1 + SL/DB/Helper/Mappings.pm | 1 + SL/DB/Manager/AdditionalBillingAddress.pm | 14 ++++++ SL/DB/MetaSetup/AdditionalBillingAddress.pm | 43 ++++++++++++++++++ SL/DB/MetaSetup/DeliveryOrder.pm | 6 +++ SL/DB/MetaSetup/Invoice.pm | 6 +++ SL/DB/MetaSetup/Order.pm | 6 +++ .../customer_additional_billing_addresses.sql | 45 +++++++++++++++++++ 10 files changed, 169 insertions(+) create mode 100644 SL/DB/AdditionalBillingAddress.pm create mode 100644 SL/DB/Manager/AdditionalBillingAddress.pm create mode 100644 SL/DB/MetaSetup/AdditionalBillingAddress.pm create mode 100644 sql/Pg-upgrade2/customer_additional_billing_addresses.sql diff --git a/SL/DB/AdditionalBillingAddress.pm b/SL/DB/AdditionalBillingAddress.pm new file mode 100644 index 000000000..940dce876 --- /dev/null +++ b/SL/DB/AdditionalBillingAddress.pm @@ -0,0 +1,41 @@ +package SL::DB::AdditionalBillingAddress; + +use strict; + +use SL::DB::MetaSetup::AdditionalBillingAddress; +use SL::DB::Manager::AdditionalBillingAddress; + +__PACKAGE__->meta->initialize; + +sub displayable_id { + my $self = shift; + my $text = join('; ', grep { $_ } (map({ $self->$_ } qw(name street)), + join(' ', grep { $_ } + map { $self->$_ } + qw(zipcode city)))); + + return $text; +} + +sub used { + my ($self) = @_; + + return unless $self->id; + + require SL::DB::Order; + require SL::DB::Invoice; + require SL::DB::DeliveryOrder; + + my %args = (query => [ billing_address_id => $self->id ]); + + return SL::DB::Manager::Invoice->get_all_count(%args) + || SL::DB::Manager::Order->get_all_count(%args) + || SL::DB::Manager::DeliveryOrder->get_all_count(%args); +} + +sub detach { + $_[0]->customer_id(undef); + return $_[0]; +} + +1; diff --git a/SL/DB/Customer.pm b/SL/DB/Customer.pm index 71c762a5e..2032a4179 100644 --- a/SL/DB/Customer.pm +++ b/SL/DB/Customer.pm @@ -29,6 +29,12 @@ use SL::DB::Helper::DisplayableNamePreferences ( use SL::DB::VC; __PACKAGE__->meta->add_relationship( + additional_billing_addresses => { + type => 'one to many', + class => 'SL::DB::AdditionalBillingAddress', + column_map => { id => 'customer_id' }, + manager_args => { sort_by => 'lower(additional_billing_addresses.name)' }, + }, shipto => { type => 'one to many', class => 'SL::DB::Shipto', diff --git a/SL/DB/Helper/ALL.pm b/SL/DB/Helper/ALL.pm index e0ab57845..aff03d914 100644 --- a/SL/DB/Helper/ALL.pm +++ b/SL/DB/Helper/ALL.pm @@ -3,6 +3,7 @@ package SL::DB::Helper::ALL; use strict; use SL::DB::AccTransaction; +use SL::DB::AdditionalBillingAddress; use SL::DB::Assembly; use SL::DB::AssortmentItem; use SL::DB::AuthClient; diff --git a/SL/DB/Helper/Mappings.pm b/SL/DB/Helper/Mappings.pm index 94f7e4744..0e9f23075 100644 --- a/SL/DB/Helper/Mappings.pm +++ b/SL/DB/Helper/Mappings.pm @@ -84,6 +84,7 @@ my @kivitendo_blacklist = (@kivitendo_blacklist_permanent, @kivitendo_blacklist_ my %kivitendo_package_names = ( # TABLE # MODEL (given in C style) acc_trans => 'acc_transaction', + additional_billing_addresses => 'additional_billing_address', 'auth.clients' => 'auth_client', 'auth.clients_users' => 'auth_client_user', 'auth.clients_groups' => 'auth_client_group', diff --git a/SL/DB/Manager/AdditionalBillingAddress.pm b/SL/DB/Manager/AdditionalBillingAddress.pm new file mode 100644 index 000000000..297d53446 --- /dev/null +++ b/SL/DB/Manager/AdditionalBillingAddress.pm @@ -0,0 +1,14 @@ +# This file has been auto-generated only because it didn't exist. +# Feel free to modify it at will; it will not be overwritten automatically. + +package SL::DB::Manager::AdditionalBillingAddress; + +use strict; + +use parent qw(SL::DB::Helper::Manager); + +sub object_class { 'SL::DB::AdditionalBillingAddress' } + +__PACKAGE__->make_manager_methods; + +1; diff --git a/SL/DB/MetaSetup/AdditionalBillingAddress.pm b/SL/DB/MetaSetup/AdditionalBillingAddress.pm new file mode 100644 index 000000000..3e37db98a --- /dev/null +++ b/SL/DB/MetaSetup/AdditionalBillingAddress.pm @@ -0,0 +1,43 @@ +# This file has been auto-generated. Do not modify it; it will be overwritten +# by rose_auto_create_model.pl automatically. +package SL::DB::AdditionalBillingAddress; + +use strict; + +use parent qw(SL::DB::Object); + +__PACKAGE__->meta->table('additional_billing_addresses'); + +__PACKAGE__->meta->columns( + city => { type => 'text' }, + contact => { type => 'text' }, + country => { type => 'text' }, + customer_id => { type => 'integer' }, + default_address => { type => 'boolean', default => 'false', not_null => 1 }, + department_1 => { type => 'text' }, + department_2 => { type => 'text' }, + email => { type => 'text' }, + fax => { type => 'text' }, + gln => { type => 'text' }, + id => { type => 'serial', not_null => 1 }, + itime => { type => 'timestamp', default => 'now()', not_null => 1 }, + mtime => { type => 'timestamp', default => 'now()', not_null => 1 }, + name => { type => 'text' }, + phone => { type => 'text' }, + street => { type => 'text' }, + zipcode => { type => 'text' }, +); + +__PACKAGE__->meta->primary_key_columns([ 'id' ]); + +__PACKAGE__->meta->allow_inline_column_values(1); + +__PACKAGE__->meta->foreign_keys( + customer => { + class => 'SL::DB::Customer', + key_columns => { customer_id => 'id' }, + }, +); + +1; +; diff --git a/SL/DB/MetaSetup/DeliveryOrder.pm b/SL/DB/MetaSetup/DeliveryOrder.pm index 780f4318c..f24fc9f64 100644 --- a/SL/DB/MetaSetup/DeliveryOrder.pm +++ b/SL/DB/MetaSetup/DeliveryOrder.pm @@ -9,6 +9,7 @@ use parent qw(SL::DB::Object); __PACKAGE__->meta->table('delivery_orders'); __PACKAGE__->meta->columns( + billing_address_id => { type => 'integer' }, closed => { type => 'boolean', default => 'false' }, cp_id => { type => 'integer' }, currency_id => { type => 'integer', not_null => 1 }, @@ -48,6 +49,11 @@ __PACKAGE__->meta->primary_key_columns([ 'id' ]); __PACKAGE__->meta->allow_inline_column_values(1); __PACKAGE__->meta->foreign_keys( + billing_address => { + class => 'SL::DB::AdditionalBillingAddress', + key_columns => { billing_address_id => 'id' }, + }, + contact => { class => 'SL::DB::Contact', key_columns => { cp_id => 'cp_id' }, diff --git a/SL/DB/MetaSetup/Invoice.pm b/SL/DB/MetaSetup/Invoice.pm index 9b10c938c..441f9c590 100644 --- a/SL/DB/MetaSetup/Invoice.pm +++ b/SL/DB/MetaSetup/Invoice.pm @@ -10,6 +10,7 @@ __PACKAGE__->meta->table('ar'); __PACKAGE__->meta->columns( amount => { type => 'numeric', default => '0', not_null => 1, precision => 15, scale => 5 }, + billing_address_id => { type => 'integer' }, cp_id => { type => 'integer' }, currency_id => { type => 'integer', not_null => 1 }, cusordnumber => { type => 'text' }, @@ -64,6 +65,11 @@ __PACKAGE__->meta->primary_key_columns([ 'id' ]); __PACKAGE__->meta->allow_inline_column_values(1); __PACKAGE__->meta->foreign_keys( + billing_address => { + class => 'SL::DB::AdditionalBillingAddress', + key_columns => { billing_address_id => 'id' }, + }, + contact => { class => 'SL::DB::Contact', key_columns => { cp_id => 'cp_id' }, diff --git a/SL/DB/MetaSetup/Order.pm b/SL/DB/MetaSetup/Order.pm index 6e707ae65..5dda64254 100644 --- a/SL/DB/MetaSetup/Order.pm +++ b/SL/DB/MetaSetup/Order.pm @@ -10,6 +10,7 @@ __PACKAGE__->meta->table('oe'); __PACKAGE__->meta->columns( amount => { type => 'numeric', precision => 15, scale => 5 }, + billing_address_id => { type => 'integer' }, closed => { type => 'boolean', default => 'false' }, cp_id => { type => 'integer' }, currency_id => { type => 'integer', not_null => 1 }, @@ -57,6 +58,11 @@ __PACKAGE__->meta->primary_key_columns([ 'id' ]); __PACKAGE__->meta->allow_inline_column_values(1); __PACKAGE__->meta->foreign_keys( + billing_address => { + class => 'SL::DB::AdditionalBillingAddress', + key_columns => { billing_address_id => 'id' }, + }, + contact => { class => 'SL::DB::Contact', key_columns => { cp_id => 'cp_id' }, diff --git a/sql/Pg-upgrade2/customer_additional_billing_addresses.sql b/sql/Pg-upgrade2/customer_additional_billing_addresses.sql new file mode 100644 index 000000000..11fcfb033 --- /dev/null +++ b/sql/Pg-upgrade2/customer_additional_billing_addresses.sql @@ -0,0 +1,45 @@ +-- @tag: customer_additional_billing_addresses +-- @description: Kundenstammdaten: zusätzliche Rechnungsadressen +-- @depends: release_3_5_8 +CREATE TABLE additional_billing_addresses ( + id SERIAL, + customer_id INTEGER, + name TEXT, + department_1 TEXT, + department_2 TEXT, + contact TEXT, + street TEXT, + zipcode TEXT, + city TEXT, + country TEXT, + gln TEXT, + email TEXT, + phone TEXT, + fax TEXT, + default_address BOOLEAN NOT NULL DEFAULT FALSE, + + itime TIMESTAMP NOT NULL DEFAULT now(), + mtime TIMESTAMP NOT NULL DEFAULT now(), + + PRIMARY KEY (id), + FOREIGN KEY (customer_id) REFERENCES customer (id) +); + +CREATE TRIGGER mtime_additional_billing_addresses +BEFORE UPDATE ON additional_billing_addresses +FOR EACH ROW EXECUTE PROCEDURE set_mtime(); + +ALTER TABLE oe + ADD COLUMN billing_address_id INTEGER, + ADD FOREIGN KEY (billing_address_id) + REFERENCES additional_billing_addresses (id); + +ALTER TABLE delivery_orders + ADD COLUMN billing_address_id INTEGER, + ADD FOREIGN KEY (billing_address_id) + REFERENCES additional_billing_addresses (id); + +ALTER TABLE ar + ADD COLUMN billing_address_id INTEGER, + ADD FOREIGN KEY (billing_address_id) + REFERENCES additional_billing_addresses (id); -- 2.20.1