X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/6ee486a53d467fe2cb5aa5a971e5de0755ab6d0c..2aecf487d4afd29f13007b927fec624c2f45d3ce:/SL/DB/Invoice.pm diff --git a/SL/DB/Invoice.pm b/SL/DB/Invoice.pm index 9cf52a24c..502654ba2 100644 --- a/SL/DB/Invoice.pm +++ b/SL/DB/Invoice.pm @@ -130,7 +130,10 @@ sub new_from { require SL::DB::Employee; - my $terms = $source->can('payment_id') && $source->payment_id ? $source->payment_terms->terms_netto : 0; + my $terms = $source->can('payment_id') && $source->payment_id ? $source->payment_terms + : $source->customer_id ? $source ->customer->payment_terms + : undef; + my (@columns, @item_columns, $item_parent_id_column, $item_parent_column); if (ref($source) eq 'SL::DB::Order') { @@ -151,7 +154,8 @@ sub new_from { cp_id language_id taxzone_id shipto_id globalproject_id transaction_description currency_id delivery_term_id), @columns), transdate => DateTime->today_local, gldate => DateTime->today_local, - duedate => DateTime->today_local->add(days => $terms * 1), + duedate => DateTime->today_local->add(days => ($terms ? $terms->terms_netto * 1 : 1)), + payment_id => $terms ? $terms->id : undef, invoice => 1, type => 'invoice', storno => 0, @@ -166,7 +170,8 @@ sub new_from { $args{quodate} = $source->transdate; } - my $invoice = $class->new(%args, %{ $params{attributes} || {} }); + my $invoice = $class->new(%args); + $invoice->assign_attributes(%{ $params{attributes} }) if $params{attributes}; my $items = delete($params{items}) || $source->items_sorted; my %item_parents; @@ -315,6 +320,15 @@ sub date { goto &transdate; } +sub transactions { + my ($self) = @_; + + return unless $self->id; + + require SL::DB::AccTransaction; + SL::DB::Manager::AccTransaction->get_all(query => [ trans_id => $self->id ]); +} + 1; __END__