Zusätzliche Rechnungsadressen: Datenbankupgrade, MetaSetup, Rose-Models
[kivitendo-erp.git] / SL / DB / AdditionalBillingAddress.pm
1 package SL::DB::AdditionalBillingAddress;
2
3 use strict;
4
5 use SL::DB::MetaSetup::AdditionalBillingAddress;
6 use SL::DB::Manager::AdditionalBillingAddress;
7
8 __PACKAGE__->meta->initialize;
9
10 sub displayable_id {
11   my $self = shift;
12   my $text = join('; ', grep { $_ } (map({ $self->$_ } qw(name street)),
13                                      join(' ', grep { $_ }
14                                                map  { $self->$_ }
15                                                qw(zipcode city))));
16
17   return $text;
18 }
19
20 sub used {
21   my ($self) = @_;
22
23   return unless $self->id;
24
25   require SL::DB::Order;
26   require SL::DB::Invoice;
27   require SL::DB::DeliveryOrder;
28
29   my %args = (query => [ billing_address_id => $self->id ]);
30
31   return SL::DB::Manager::Invoice->get_all_count(%args)
32       || SL::DB::Manager::Order->get_all_count(%args)
33       || SL::DB::Manager::DeliveryOrder->get_all_count(%args);
34 }
35
36 sub detach {
37   $_[0]->customer_id(undef);
38   return $_[0];
39 }
40
41 1;