--- /dev/null
+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;
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',
use strict;
use SL::DB::AccTransaction;
+use SL::DB::AdditionalBillingAddress;
use SL::DB::Assembly;
use SL::DB::AssortmentItem;
use SL::DB::AuthClient;
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',
--- /dev/null
+# 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;
--- /dev/null
+# 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;
+;
__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 },
__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' },
__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' },
__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' },
__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 },
__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' },
--- /dev/null
+-- @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);