1 package SL::DB::Vendor;
5 use Rose::DB::Object::Helpers qw(as_tree);
7 use SL::Locale::String qw(t8);
9 use SL::DB::MetaSetup::Vendor;
10 use SL::DB::Manager::Vendor;
11 use SL::DB::Helper::IBANValidation;
12 use SL::DB::Helper::TransNumberGenerator;
13 use SL::DB::Helper::VATIDNrValidation;
14 use SL::DB::Helper::CustomVariables (
18 use SL::DB::Helper::DisplayableNamePreferences (
19 title => t8('Vendor'),
20 options => [ {name => 'vendornumber', title => t8('Vendor Number') },
21 {name => 'name', title => t8('Name') },
22 {name => 'street', title => t8('Street') },
23 {name => 'city', title => t8('City') },
24 {name => 'zipcode', title => t8('Zipcode')},
25 {name => 'email', title => t8('E-Mail') },
26 {name => 'phone', title => t8('Phone') }, ]
31 __PACKAGE__->meta->add_relationship(
33 type => 'one to many',
34 class => 'SL::DB::Shipto',
35 column_map => { id => 'trans_id' },
36 manager_args => { sort_by => 'lower(shipto.shiptoname)' },
37 query_args => [ module => 'CT' ],
40 type => 'one to many',
41 class => 'SL::DB::Contact',
42 column_map => { id => 'cp_cv_id' },
43 manager_args => { sort_by => 'lower(contacts.cp_name)' },
47 __PACKAGE__->meta->initialize;
49 __PACKAGE__->before_save('_before_save_set_vendornumber');
51 sub _before_save_set_vendornumber {
54 $self->create_trans_number if !defined $self->vendornumber || $self->vendornumber eq '';
62 push @errors, $::locale->text('The vendor name is missing.') if !$self->name;
63 push @errors, $self->validate_ibans;
64 push @errors, $self->validate_vat_id_numbers;
69 sub is_customer { 0 };
71 sub payment_terms { goto &payment }
72 sub number { goto &vendornumber }
74 sub last_used_ap_chart {
80 JOIN acc_trans ac ON (ac.chart_id = c.id)
81 JOIN ap a ON (a.id = ac.trans_id)
82 WHERE (a.vendor_id = ?)
83 AND (c.category = 'E')
84 AND (c.link !~ '_(paid|tax)')
85 AND (a.id IN (SELECT max(a2.id) FROM ap a2 WHERE a2.vendor_id = ?))
86 ORDER BY ac.acc_trans_id ASC
90 my ($chart_id) = SL::DBUtils::selectfirst_array_query($::form, $self->db->dbh, $query, ($self->id) x 2);
93 return SL::DB::Chart->load_cached($chart_id);