Revert "Bugfix zu manuelle Lieferadresse im Auftrag wird nicht in wiederkehrende...
[kivitendo-erp.git] / SL / DB / Shipto.pm
1 package SL::DB::Shipto;
2
3 use strict;
4
5 use SL::DB::MetaSetup::Shipto;
6 use SL::DB::Manager::Shipto;
7
8 our @SHIPTO_VARIABLES = qw(shiptoname shiptostreet shiptozipcode shiptocity shiptocountry shiptogln shiptocontact
9                            shiptophone shiptofax shiptoemail shiptodepartment_1 shiptodepartment_2);
10
11 __PACKAGE__->meta->initialize;
12
13 sub displayable_id {
14   my $self = shift;
15   my $text = join('; ', grep { $_ } (map({ $self->$_ } qw(shiptoname shiptostreet)),
16                                      join(' ', grep { $_ }
17                                                map  { $self->$_ }
18                                                qw(shiptozipcode shiptocity))));
19
20   return $text;
21 }
22
23 sub used {
24   my ($self) = @_;
25
26   return unless $self->shipto_id;
27
28   require SL::DB::Order;
29   require SL::DB::Invoice;
30   require SL::DB::DeliveryOrder;
31
32   return SL::DB::Manager::Order->get_all_count(query => [ shipto_id => $self->shipto_id ])
33       || SL::DB::Manager::Invoice->get_all_count(query => [ shipto_id => $self->shipto_id ])
34       || SL::DB::Manager::DeliveryOrder->get_all_count(query => [ shipto_id => $self->shipto_id ]);
35 }
36
37 sub detach {
38   $_[0]->trans_id(undef);
39   $_[0];
40 }
41
42 1;