Merge branch 'master' of git@vc.linet-services.de:public/lx-office-erp
[kivitendo-erp.git] / SL / DB / Contact.pm
1 # This file has been auto-generated only because it didn't exist.
2 # Feel free to modify it at will; it will not be overwritten automatically.
3
4 package SL::DB::Contact;
5
6 use strict;
7
8 use SL::DB::MetaSetup::Contact;
9 use SL::DB::Helper::CustomVariables (
10   module      => 'Contacts',
11   cvars_alias => 1,
12 );
13
14 # Creates get_all, get_all_count, get_all_iterator, delete_all and update_all.
15 __PACKAGE__->meta->make_manager_class;
16
17 __PACKAGE__->meta->initialize;
18
19 sub used {
20   my ($self) = @_;
21
22   return unless $self->cp_id;
23
24   require SL::DB::Order;
25   require SL::DB::Invoice;
26   require SL::DB::PurchaseInvoice;
27   require SL::DB::DeliveryOrder;
28
29   return SL::DB::Manager::Order->get_all_count(query => [ cp_id => $self->cp_id ])
30        + SL::DB::Manager::Invoice->get_all_count(query => [ cp_id => $self->cp_id ])
31        + SL::DB::Manager::PurchaseInvoice->get_all_count(query => [ cp_id => $self->cp_id ])
32        + SL::DB::Manager::DeliveryOrder->get_all_count(query => [ cp_id => $self->cp_id ]);
33 }
34
35 sub detach {
36   $_[0]->cp_cv_id(undef);
37   $_[0];
38 }
39
40 sub full_name {
41   my ($self) = @_;
42   die 'not an accessor' if @_ > 1;
43   join ', ', grep $_, $self->cp_name, $self->cp_givenname;
44 }
45
46 sub full_name_dep {
47   my ($self) = @_;
48   die 'not an accessor' if @_ > 1;
49   $self->full_name
50     . join '', map { " ($_)" } grep $_, $self->cp_abteilung;
51 }
52
53 1;