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