X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FDB%2FInvoice.pm;h=93c17e4ec819d3c3fdc72d235bcef4e19ce81331;hb=393cef65daf67853ed468b4778b7c738773d48f1;hp=4caafc0b003267b3aded43d3bdf5297eaaecbd36;hpb=a5e4f9ca835489c2250db39f2c3abe6ac4ba04e6;p=kivitendo-erp.git diff --git a/SL/DB/Invoice.pm b/SL/DB/Invoice.pm index 4caafc0b0..93c17e4ec 100644 --- a/SL/DB/Invoice.pm +++ b/SL/DB/Invoice.pm @@ -13,9 +13,11 @@ use SL::DB::Helper::AttrHTML; use SL::DB::Helper::AttrSorted; use SL::DB::Helper::FlattenToForm; use SL::DB::Helper::LinkedRecords; +use SL::DB::Helper::PDF_A; use SL::DB::Helper::PriceTaxCalculator; use SL::DB::Helper::PriceUpdater; use SL::DB::Helper::TransNumberGenerator; +use SL::DB::Helper::ZUGFeRD; use SL::Locale::String qw(t8); use SL::DB::CustomVariable; @@ -60,6 +62,12 @@ __PACKAGE__->meta->add_relationship( sort_by => 'acc_trans_id ASC', }, }, + dunnings => { + type => 'one to many', + class => 'SL::DB::Dunning', + column_map => { id => 'trans_id' }, + manager_args => { with_objects => [ 'dunnings' ] } + }, ); __PACKAGE__->meta->initialize; @@ -166,7 +174,7 @@ sub new_from { my %args = ( map({ ( $_ => $source->$_ ) } qw(customer_id taxincluded shippingpoint shipvia notes intnotes salesman_id cusordnumber ordnumber department_id cp_id language_id taxzone_id globalproject_id transaction_description currency_id delivery_term_id), @columns), - transdate => DateTime->today_local, + transdate => $params{transdate} // DateTime->today_local, gldate => DateTime->today_local, duedate => $terms ? $terms->calc_date(reference_date => DateTime->today_local) : DateTime->today_local, invoice => 1, @@ -178,9 +186,16 @@ sub new_from { $args{payment_id} = ( $terms ? $terms->id : $source->payment_id); - if ($source->type =~ /_order$/) { + if ($source->type =~ /_delivery_order$/) { + $args{deliverydate} = $source->reqdate; + if (my $order = SL::DB::Manager::Order->find_by(ordnumber => $source->ordnumber)) { + $args{orddate} = $order->transdate; + } + + } elsif ($source->type =~ /_order$/) { $args{deliverydate} = $source->reqdate; $args{orddate} = $source->transdate; + } else { $args{quodate} = $source->transdate; } @@ -260,7 +275,7 @@ sub post { $self->_post_add_acctrans($data{amounts_cogs}); $self->_post_add_acctrans($data{amounts}); - $self->_post_add_acctrans($data{taxes}); + $self->_post_add_acctrans($data{taxes_by_chart_id}); $self->_post_add_acctrans({ $params{ar_id} => $self->amount * -1 }); @@ -290,14 +305,16 @@ sub _post_add_acctrans { $chart_link = SL::DB::Manager::Chart->find_by(id => $chart_id)->{'link'}; $chart_link ||= ''; - SL::DB::AccTransaction->new(trans_id => $self->id, - chart_id => $chart_id, - amount => $spec->{amount}, - tax_id => $spec->{tax_id}, - taxkey => $spec->{taxkey}, - project_id => $self->globalproject_id, - transdate => $self->transdate, - chart_link => $chart_link)->save; + if ($spec->{amount} != 0) { + SL::DB::AccTransaction->new(trans_id => $self->id, + chart_id => $chart_id, + amount => $spec->{amount}, + tax_id => $spec->{tax_id}, + taxkey => $spec->{taxkey}, + project_id => $self->globalproject_id, + transdate => $self->transdate, + chart_link => $chart_link)->save; + } } } @@ -349,6 +366,7 @@ sub add_ar_amount_row { chart_id => $params{chart}->id, chart_link => $params{chart}->link, transdate => $self->transdate, + gldate => $self->gldate, taxkey => $tax->taxkey, tax_id => $tax->id, project_id => $params{project_id}, @@ -363,6 +381,7 @@ sub add_ar_amount_row { chart_id => $tax->chart_id, chart_link => $tax->chart->link, transdate => $self->transdate, + gldate => $self->gldate, taxkey => $tax->taxkey, tax_id => $tax->id, ); @@ -558,7 +577,8 @@ sub abbreviation { sub oneline_summary { my $self = shift; - return sprintf("%s: %s %s (%s)", $self->abbreviation, $self->invnumber, $self->customer->name, $self->transdate->to_kivitendo); + return sprintf("%s: %s %s %s (%s)", $self->abbreviation, $self->invnumber, $self->customer->name, + $::form->format_amount(\%::myconfig, $self->amount,2), $self->transdate->to_kivitendo); } sub date { @@ -577,8 +597,8 @@ sub link { my ($self) = @_; my $html; - $html = SL::Presenter->get->sales_invoice($self, display => 'inline') if $self->invoice; - $html = SL::Presenter->get->ar_transaction($self, display => 'inline') if !$self->invoice; + $html = $self->presenter->sales_invoice(display => 'inline') if $self->invoice; + $html = $self->presenter->ar_transaction(display => 'inline') if !$self->invoice; return $html; } @@ -713,7 +733,7 @@ See L. =item C Returns 1 or 0, depending on whether the invoice is closed or not. Currently -invoices that are overpaid also count as closed. +invoices that are overpaid also count as closed and credit notes in general. =item C