Merge branch 'b-3.6.1' into mebil
[kivitendo-erp.git] / SL / DB / Customer.pm
index 71c762a..d72d0c9 100644 (file)
@@ -2,6 +2,7 @@ package SL::DB::Customer;
 
 use strict;
 
+use List::Util qw(first);
 use Rose::DB::Object::Helpers qw(as_tree);
 
 use SL::Locale::String qw(t8);
@@ -29,6 +30,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',
@@ -108,4 +115,11 @@ sub create_zugferd_invoices_for_this_customer {
   return $self->create_zugferd_invoices;
 }
 
+sub default_billing_address {
+  my $self = shift;
+
+  die 'not an accessor' if @_ > 1;
+  return first { $_->default_address } @{ $self->additional_billing_addresses };
+}
+
 1;