Merge branch 'b-3.6.1' of ../kivitendo-erp_20220811
[kivitendo-erp.git] / SL / DB / Business.pm
1 package SL::DB::Business;
2
3 use strict;
4
5 use SL::DB::MetaSetup::Business;
6 use SL::DB::Manager::Business;
7
8 __PACKAGE__->meta->add_relationship(
9   customers      => {
10     type         => 'one to many',
11     class        => 'SL::DB::Customer',
12     column_map   => { id => 'business_id' },
13     query_args   => [ \' id IN ( SELECT id FROM customer ) ' ],
14   },
15   vendors      => {
16     type         => 'one to many',
17     class        => 'SL::DB::Vendor',
18     column_map   => { id => 'business_id' },
19     query_args   => [ \' id IN ( SELECT id FROM vendor ) ' ],
20   },
21 );
22
23 __PACKAGE__->meta->initialize;
24
25 sub validate {
26   my ($self) = @_;
27
28   my @errors;
29   push @errors, $::locale->text('The description is missing.')          if !$self->description;
30   push @errors, $::locale->text('The discount must not be negative.')   if $self->discount <  0;
31   push @errors, $::locale->text('The discount must be less than 100%.') if $self->discount >= 1;
32
33   return @errors;
34 }
35
36 sub displayable_name {
37   my $self = shift;
38
39   return join ' ', grep $_, $self->id, $self->description;
40 }
41
42 1;