bed7e9cd6f4f0d7090fe2cb237c6b1f6bbadbcdb
[kivitendo-erp.git] / SL / DB / Contact.pm
1 package SL::DB::Contact;
2
3 use strict;
4
5 use SL::DB::MetaSetup::Contact;
6 use SL::DB::Manager::Contact;
7 use SL::DB::Helper::CustomVariables (
8   module      => 'Contacts',
9   cvars_alias => 1,
10 );
11
12 __PACKAGE__->meta->initialize;
13
14 sub used {
15   my ($self) = @_;
16
17   return unless $self->cp_id;
18
19   require SL::DB::Order;
20   require SL::DB::Invoice;
21   require SL::DB::PurchaseInvoice;
22   require SL::DB::DeliveryOrder;
23
24   return SL::DB::Manager::Order->get_all_count(query => [ cp_id => $self->cp_id ])
25        + SL::DB::Manager::Invoice->get_all_count(query => [ cp_id => $self->cp_id ])
26        + SL::DB::Manager::PurchaseInvoice->get_all_count(query => [ cp_id => $self->cp_id ])
27        + SL::DB::Manager::DeliveryOrder->get_all_count(query => [ cp_id => $self->cp_id ]);
28 }
29
30 sub detach {
31   $_[0]->cp_cv_id(undef);
32   $_[0];
33 }
34
35 sub full_name {
36   my ($self) = @_;
37   die 'not an accessor' if @_ > 1;
38   join ', ', grep $_, $self->cp_name, $self->cp_givenname;
39 }
40
41 sub full_name_dep {
42   my ($self) = @_;
43   die 'not an accessor' if @_ > 1;
44   $self->full_name
45     . join '', map { " ($_)" } grep $_, $self->cp_abteilung;
46 }
47
48 sub formal_greeting {
49   my ($self) = @_;
50   die 'not an accessor' if @_ > 1;
51   join ' ', grep $_, $self->cp_title, $self->cp_givenname, $self->cp_name;
52 }
53
54 1;