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