kivitendo/SL/DB/Letter.pm @ 4b1666b7
4b7f17c8 | Geoffrey Richardson | package SL::DB::Letter;
|
||
use strict;
|
||||
e83604f2 | Moritz Bunkus | use SL::DB::Helper::AttrHTML;
|
||
0c09beb4 | Moritz Bunkus | use SL::DB::Helper::LinkedRecords;
|
||
4b7f17c8 | Geoffrey Richardson | use SL::DB::MetaSetup::Letter;
|
||
ea5d75b5 | Sven Schöling | use SL::DB::Manager::Letter;
|
||
4b7f17c8 | Geoffrey Richardson | __PACKAGE__->meta->initialize;
|
||
e83604f2 | Moritz Bunkus | __PACKAGE__->attr_html('body');
|
||
ea5d75b5 | Sven Schöling | sub new_from_draft {
|
||
my ($class, $draft) = @_;
|
||||
my $self = $class->new;
|
||||
if (!ref $draft) {
|
||||
require SL::DB::LetterDraft;
|
||||
$draft = SL::DB::LetterDraft->new(id => $draft)->load;
|
||||
}
|
||||
$self->assign_attributes(map { $_ => $draft->$_ } $draft->meta->columns);
|
||||
$self->id(undef);
|
||||
$self;
|
||||
}
|
||||
4b7f17c8 | Geoffrey Richardson | |||
db7a2e79 | Sven Schöling | sub is_sales {
|
||
die 'not an accessor' if @_ > 1;
|
||||
$_[0]{customer_id} * 1;
|
||||
}
|
||||
sub has_customer_vendor {
|
||||
my ($self) = @_;
|
||||
die 'not an accessor' if @_ > 1;
|
||||
return $self->is_sales
|
||||
? ($self->customer_id && $self->customer)
|
||||
: ($self->vendor_id && $self->vendor);
|
||||
}
|
||||
sub customer_vendor {
|
||||
die 'not an accessor' if @_ > 1;
|
||||
$_[0]->is_sales ? $_[0]->customer : $_[0]->vendor;
|
||||
}
|
||||
sub customer_vendor_id {
|
||||
die 'not an accessor' if @_ > 1;
|
||||
$_[0]->customer_id || $_[0]->vendor_id;
|
||||
}
|
||||
4b7f17c8 | Geoffrey Richardson | 1;
|