1 package SL::DB::Vendor;
5 use Rose::DB::Object::Helpers qw(as_tree);
8 use SL::DB::MetaSetup::Vendor;
9 use SL::DB::Manager::Vendor;
10 use SL::DB::Helper::IBANValidation;
11 use SL::DB::Helper::TransNumberGenerator;
12 use SL::DB::Helper::CustomVariables (
19 __PACKAGE__->meta->add_relationship(
21 type => 'one to many',
22 class => 'SL::DB::Shipto',
23 column_map => { id => 'trans_id' },
24 manager_args => { sort_by => 'lower(shipto.shiptoname)' },
25 query_args => [ module => 'CT' ],
28 type => 'one to many',
29 class => 'SL::DB::Contact',
30 column_map => { id => 'cp_cv_id' },
31 manager_args => { sort_by => 'lower(contacts.cp_name)' },
35 __PACKAGE__->meta->initialize;
37 __PACKAGE__->before_save('_before_save_set_vendornumber');
39 sub _before_save_set_vendornumber {
42 $self->create_trans_number if !defined $self->vendornumber || $self->vendornumber eq '';
50 push @errors, $::locale->text('The vendor name is missing.') if !$self->name;
51 push @errors, $self->validate_ibans;
56 sub displayable_name {
59 return join ' ', grep $_, $self->vendornumber, $self->name;
62 sub is_customer { 0 };
64 sub payment_terms { goto &payment }
65 sub number { goto &vendornumber }
67 sub last_used_ap_chart {
73 JOIN acc_trans ac ON (ac.chart_id = c.id)
74 JOIN ap a ON (a.id = ac.trans_id)
75 WHERE (a.vendor_id = ?)
76 AND (c.category = 'E')
77 AND (c.link !~ '_(paid|tax)')
78 AND (a.id IN (SELECT max(a2.id) FROM ap a2 WHERE a2.vendor_id = ?))
79 ORDER BY ac.acc_trans_id ASC
83 my ($chart_id) = SL::DBUtils::selectfirst_array_query($::form, $self->db->dbh, $query, ($self->id) x 2);
86 return SL::DB::Chart->load_cached($chart_id);