Refactoring
[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 use Rose::DB::Object::Helpers qw(clone_and_reset clone);
8
9 our @SHIPTO_VARIABLES = qw(shiptoname shiptostreet shiptozipcode shiptocity shiptocountry shiptocontact
10                            shiptophone shiptofax shiptoemail shiptodepartment_1 shiptodepartment_2);
11
12 __PACKAGE__->meta->initialize;
13
14 sub displayable_id {
15   my $self = shift;
16   my $text = join('; ', grep { $_ } (map({ $self->$_ } qw(shiptoname shiptostreet)),
17                                      join(' ', grep { $_ }
18                                                map  { $self->$_ }
19                                                qw(shiptozipcode shiptocity))));
20
21   return $text;
22 }
23
24 sub used {
25   my ($self) = @_;
26
27   return unless $self->shipto_id;
28
29   require SL::DB::Order;
30   require SL::DB::Invoice;
31   require SL::DB::DeliveryOrder;
32
33   return SL::DB::Manager::Order->get_all_count(query => [ shipto_id => $self->shipto_id ])
34       || SL::DB::Manager::Invoice->get_all_count(query => [ shipto_id => $self->shipto_id ])
35       || SL::DB::Manager::DeliveryOrder->get_all_count(query => [ shipto_id => $self->shipto_id ]);
36 }
37
38 sub detach {
39   $_[0]->trans_id(undef);
40   $_[0];
41 }
42
43 1;