1 package SL::DB::Customer;
5 use Rose::DB::Object::Helpers qw(as_tree);
7 use SL::DB::MetaSetup::Customer;
8 use SL::DB::Manager::Customer;
9 use SL::DB::Helper::IBANValidation;
10 use SL::DB::Helper::TransNumberGenerator;
11 use SL::DB::Helper::CustomVariables (
18 __PACKAGE__->meta->add_relationship(
20 type => 'one to many',
21 class => 'SL::DB::Shipto',
22 column_map => { id => 'trans_id' },
23 manager_args => { sort_by => 'lower(shipto.shiptoname)' },
24 query_args => [ module => 'CT' ],
27 type => 'one to many',
28 class => 'SL::DB::Contact',
29 column_map => { id => 'cp_cv_id' },
30 manager_args => { sort_by => 'lower(contacts.cp_name)' },
34 __PACKAGE__->meta->initialize;
36 __PACKAGE__->before_save('_before_save_set_customernumber');
38 sub _before_save_set_customernumber {
41 $self->create_trans_number if !defined $self->customernumber || $self->customernumber eq '';
49 push @errors, $::locale->text('The customer name is missing.') if !$self->name;
50 push @errors, $self->validate_ibans;
58 return join ', ', grep { $_ } $self->street, $self->zipcode, $self->city;
61 sub displayable_name {
64 return join ' ', grep $_, $self->customernumber, $self->name;
67 sub is_customer { 1 };
69 sub payment_terms { goto &payment }
70 sub number { goto &customernumber }