X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FDB%2FOrder.pm;h=194431dcd31fea66da7143f9216daf49830fc072;hb=49be66cdf74882abde5a93832a959e27baddd925;hp=6b31cd235437961d9f2e0137aeca10edca43a854;hpb=d80ffb811b20a9bba4da4fd18815fa1e3275d17d;p=kivitendo-erp.git diff --git a/SL/DB/Order.pm b/SL/DB/Order.pm index 6b31cd235..194431dcd 100644 --- a/SL/DB/Order.pm +++ b/SL/DB/Order.pm @@ -9,7 +9,6 @@ use List::Util qw(max); use SL::DB::MetaSetup::Order; use SL::DB::Manager::Order; -use SL::DB::Invoice; use SL::DB::Helper::FlattenToForm; use SL::DB::Helper::LinkedRecords; use SL::DB::Helper::PriceTaxCalculator; @@ -31,44 +30,37 @@ __PACKAGE__->meta->add_relationship( class => 'SL::DB::PeriodicInvoicesConfig', column_map => { id => 'oe_id' }, }, - periodic_invoices => { - type => 'one to many', - class => 'SL::DB::PeriodicInvoice', - column_map => { id => 'oe_id' }, - }, - payment_term => { - type => 'one to one', - class => 'SL::DB::PaymentTerm', - column_map => { payment_id => 'id' }, - }, - contact => { - type => 'one to one', - class => 'SL::DB::Contact', - column_map => { cp_id => 'cp_id' }, - }, - shipto => { - type => 'one to one', - class => 'SL::DB::Shipto', - column_map => { shipto_id => 'shipto_id' }, - }, - department => { - type => 'one to one', - class => 'SL::DB::Department', - column_map => { department_id => 'id' }, - }, - language => { - type => 'one to one', - class => 'SL::DB::Language', - column_map => { language_id => 'id' }, - }, ); __PACKAGE__->meta->initialize; +__PACKAGE__->before_save('_before_save_set_ord_quo_number'); + +# hooks + +sub _before_save_set_ord_quo_number { + my ($self) = @_; + + # ordnumber is 'NOT NULL'. Therefore make sure it's always set to at + # least an empty string, even if we're saving a quotation. + $self->ordnumber('') if !$self->ordnumber; + + my $field = $self->quotation ? 'quonumber' : 'ordnumber'; + $self->create_trans_number if !$self->$field; + + return 1; +} + # methods sub items { goto &orderitems; } +sub items_sorted { + my ($self) = @_; + + return [ sort {$a->id <=> $b->id } @{ $self->items } ]; +} + sub type { my $self = shift; @@ -84,6 +76,23 @@ sub is_type { return shift->type eq shift; } +sub displayable_type { + my $type = shift->type; + + return $::locale->text('Sales quotation') if $type eq 'sales_quotation'; + return $::locale->text('Request quotation') if $type eq 'request_quotation'; + return $::locale->text('Sales Order') if $type eq 'sales_order'; + return $::locale->text('Purchase Order') if $type eq 'purchase_order'; + + die 'invalid type'; +} + + +sub is_sales { + croak 'not an accessor' if @_ > 1; + return !!shift->customer_id; +} + sub invoices { my $self = shift; my %params = @_; @@ -91,6 +100,7 @@ sub invoices { if ($self->quotation) { return []; } else { + require SL::DB::Invoice; return SL::DB::Manager::Invoice->get_all( query => [ ordnumber => $self->ordnumber, @@ -100,6 +110,12 @@ sub invoices { } } +sub displayable_state { + my ($self) = @_; + + return $self->closed ? $::locale->text('closed') : $::locale->text('open'); +} + sub abschlag_invoices { return shift()->invoices(query => [ abschlag => 1 ]); } @@ -126,6 +142,23 @@ sub convert_to_invoice { return $invoice; } +sub number { + my $self = shift; + + my %number_method = ( + sales_order => 'ordnumber', + sales_quotation => 'quonumber', + purchase_order => 'ordnumber', + request_quotation => 'quonumber', + ); + + return $self->${ \ $number_method{$self->type} }(@_); +} + +sub date { + goto &transdate; +} + 1; __END__