From: Moritz Bunkus Date: Tue, 10 Nov 2020 10:35:45 +0000 (+0100) Subject: Einkauf/Verkauf: Feld »Leistungsdatum« für Steuerberechnung X-Git-Tag: kivitendo-mebil_0.1-0~9^2~577^2~8 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=0b36b2259c1300ee5360a9c8d5aee1f321abd364;p=kivitendo-erp.git Einkauf/Verkauf: Feld »Leistungsdatum« für Steuerberechnung --- diff --git a/SL/DB/Helper/PriceTaxCalculator.pm b/SL/DB/Helper/PriceTaxCalculator.pm index f5bc61c4a..15850d558 100644 --- a/SL/DB/Helper/PriceTaxCalculator.pm +++ b/SL/DB/Helper/PriceTaxCalculator.pm @@ -54,7 +54,7 @@ sub calculate_prices_and_taxes { $self->netamount( 0); $self->marge_total(0); - SL::DB::Manager::Chart->cache_taxkeys(date => $self->deliverydate // $self->transdate); + SL::DB::Manager::Chart->cache_taxkeys(date => $self->effective_tax_point); my $idx = 0; foreach my $item (@{ $self->items_sorted }) { @@ -110,7 +110,7 @@ sub _calculate_item { $data->{invoicediff} += $sellprice * (1 - $item->discount) * $item->qty * $data->{exchangerate} / $item->price_factor - $linetotal if $self->taxincluded; - my $taxkey = $part->get_taxkey(date => $self->deliverydate // $self->transdate, is_sales => $data->{is_sales}, taxzone => $self->taxzone_id); + my $taxkey = $part->get_taxkey(date => $self->effective_tax_point, is_sales => $data->{is_sales}, taxzone => $self->taxzone_id); my $tax_rate = $taxkey->tax->rate; my $tax_amount = undef; diff --git a/SL/DB/Invoice.pm b/SL/DB/Invoice.pm index 93c17e4ec..0a6079885 100644 --- a/SL/DB/Invoice.pm +++ b/SL/DB/Invoice.pm @@ -609,6 +609,12 @@ sub mark_as_paid { $self->update_attributes(paid => $self->amount); } +sub effective_tax_point { + my ($self) = @_; + + return $self->tax_point || $self->deliverydate || $self->transdate; +} + 1; __END__ diff --git a/SL/DB/MetaSetup/Invoice.pm b/SL/DB/MetaSetup/Invoice.pm index b88c2f57c..9b10c938c 100644 --- a/SL/DB/MetaSetup/Invoice.pm +++ b/SL/DB/MetaSetup/Invoice.pm @@ -51,6 +51,7 @@ __PACKAGE__->meta->columns( shipvia => { type => 'text' }, storno => { type => 'boolean', default => 'false' }, storno_id => { type => 'integer' }, + tax_point => { type => 'date' }, taxincluded => { type => 'boolean' }, taxzone_id => { type => 'integer', not_null => 1 }, transaction_description => { type => 'text' }, diff --git a/SL/DB/MetaSetup/Order.pm b/SL/DB/MetaSetup/Order.pm index d6922bd53..6e707ae65 100644 --- a/SL/DB/MetaSetup/Order.pm +++ b/SL/DB/MetaSetup/Order.pm @@ -44,6 +44,7 @@ __PACKAGE__->meta->columns( shippingpoint => { type => 'text' }, shipto_id => { type => 'integer' }, shipvia => { type => 'text' }, + tax_point => { type => 'date' }, taxincluded => { type => 'boolean' }, taxzone_id => { type => 'integer', not_null => 1 }, transaction_description => { type => 'text' }, diff --git a/SL/DB/MetaSetup/PurchaseInvoice.pm b/SL/DB/MetaSetup/PurchaseInvoice.pm index c9c74f0d4..4a443ac61 100644 --- a/SL/DB/MetaSetup/PurchaseInvoice.pm +++ b/SL/DB/MetaSetup/PurchaseInvoice.pm @@ -39,6 +39,7 @@ __PACKAGE__->meta->columns( shipvia => { type => 'text' }, storno => { type => 'boolean', default => 'false' }, storno_id => { type => 'integer' }, + tax_point => { type => 'date' }, taxincluded => { type => 'boolean', default => 'false' }, taxzone_id => { type => 'integer', not_null => 1 }, transaction_description => { type => 'text' }, diff --git a/SL/DB/Order.pm b/SL/DB/Order.pm index d996d13b6..43acce5a1 100644 --- a/SL/DB/Order.pm +++ b/SL/DB/Order.pm @@ -144,6 +144,12 @@ sub deliverydate { return shift->transdate; } +sub effective_tax_point { + my ($self) = @_; + + return $self->tax_point || $self->transdate; +} + sub displayable_type { my $type = shift->type; diff --git a/SL/DB/PurchaseInvoice.pm b/SL/DB/PurchaseInvoice.pm index a50884cb1..dd49433c6 100644 --- a/SL/DB/PurchaseInvoice.pm +++ b/SL/DB/PurchaseInvoice.pm @@ -214,6 +214,12 @@ sub mark_as_paid { $self->update_attributes(paid => $self->amount); } +sub effective_tax_point { + my ($self) = @_; + + return $self->tax_point || $self->deliverydate || $self->transdate; +} + 1; diff --git a/SL/Form.pm b/SL/Form.pm index 92d32e76f..a596a7561 100644 --- a/SL/Form.pm +++ b/SL/Form.pm @@ -3229,7 +3229,7 @@ sub prepare_for_printing { # Format dates. $self->format_dates($output_dateformat, $output_longdates, - qw(invdate orddate quodate pldate duedate reqdate transdate shippingdate deliverydate validitydate paymentdate datepaid + qw(invdate orddate quodate pldate duedate reqdate transdate tax_point shippingdate deliverydate validitydate paymentdate datepaid transdate_oe deliverydate_oe employee_startdate employee_enddate), grep({ /^(?:datepaid|transdate_oe|reqdate|deliverydate|deliverydate_oe|transdate)_\d+$/ } keys(%{$self}))); diff --git a/SL/IC.pm b/SL/IC.pm index 868fb7417..46f0f542c 100644 --- a/SL/IC.pm +++ b/SL/IC.pm @@ -739,37 +739,12 @@ sub retrieve_accounts { # transdate madness. my $transdate = ""; - if ($form->{type} eq "invoice" or $form->{type} eq "credit_note") { + if (($form->{type} eq "invoice") or ($form->{type} eq "credit_note") or ($form->{script} eq 'ir.pl')) { # use deliverydate for sales and purchase invoice, if it exists # also use deliverydate for credit notes - if (!$form->{deliverydate}) { - $transdate = $form->{invdate}; - } else { - $transdate = $form->{deliverydate}; - } - } elsif ($form->{script} eq 'ir.pl') { - # when a purchase invoice is opened from the report of purchase invoices - # $form->{type} isn't set, but $form->{script} is, not sure why this is or - # whether this distinction matters in some other scenario. Otherwise one - # could probably take out this elsif and add a - # " or $form->{script} eq 'ir.pl' " - # to the above if-statement - if (!$form->{deliverydate}) { - $transdate = $form->{invdate}; - } else { - $transdate = $form->{deliverydate}; - } - } elsif (($form->{type} eq "credit_note") and $form->{deliverydate}) { - # if credit_note has a deliverydate, use this instead of invdate - # useful for credit_notes of invoices from an old period with different tax - # if there is no deliverydate then invdate is used, old default (see next elsif) - # Falls hier der Stichtag für Steuern anders bestimmt wird, - # entsprechend auch bei Taxkeys.pm anpassen - $transdate = $form->{deliverydate}; - } elsif (($form->{type} eq "credit_note") || ($form->{script} eq 'ir.pl')) { - $transdate = $form->{invdate}; + $transdate = $form->{tax_point} || $form->{deliverydate} || $form->{invdate}; } else { - $transdate = $form->{transdate}; + $transdate = $form->{tax_point} || $form->{transdate}; } if ($transdate eq "") { diff --git a/SL/IR.pm b/SL/IR.pm index 5c768cf8a..2663ad676 100644 --- a/SL/IR.pm +++ b/SL/IR.pm @@ -549,7 +549,7 @@ SQL if ($form->{currency} ne $defaultcurrency) && !$exchangerate; # record acc_trans transactions - my $taxdate = $form->{deliverydate} ? $form->{deliverydate} : $form->{invdate}; + my $taxdate = $form->{tax_point} || $form->{deliverydate} || $form->{invdate}; foreach my $trans_id (keys %{ $form->{amount} }) { foreach my $accno (keys %{ $form->{amount}{$trans_id} }) { $form->{amount}{$trans_id}{$accno} = $form->round_amount($form->{amount}{$trans_id}{$accno}, 2); @@ -735,7 +735,7 @@ SQL orddate = ?, quodate = ?, vendor_id = ?, amount = ?, netamount = ?, paid = ?, duedate = ?, deliverydate = ?, invoice = ?, taxzone_id = ?, notes = ?, taxincluded = ?, - intnotes = ?, storno_id = ?, storno = ?, + intnotes = ?, storno_id = ?, storno = ?, tax_point = ?, cp_id = ?, employee_id = ?, department_id = ?, delivery_term_id = ?, payment_id = ?, currency_id = (SELECT id FROM currencies WHERE name = ?), @@ -746,7 +746,7 @@ SQL conv_date($form->{orddate}), conv_date($form->{quodate}), conv_i($form->{vendor_id}), $amount, $netamount, $form->{paid}, conv_date($form->{duedate}), conv_date($form->{deliverydate}), '1', $taxzone_id, $restricter->process($form->{notes}), $form->{taxincluded} ? 't' : 'f', - $form->{intnotes}, conv_i($form->{storno_id}), $form->{storno} ? 't' : 'f', + $form->{intnotes}, conv_i($form->{storno_id}), $form->{storno} ? 't' : 'f', conv_date($form->{tax_point}), conv_i($form->{cp_id}), conv_i($form->{employee_id}), conv_i($form->{department_id}), conv_i($form->{delivery_term_id}), conv_i($form->{payment_id}), $form->{"currency"}, @@ -1002,7 +1002,7 @@ sub retrieve_invoice { # retrieve invoice $query = qq|SELECT cp_id, invnumber, transdate AS invdate, duedate, - orddate, quodate, deliverydate, globalproject_id, + orddate, quodate, deliverydate, tax_point, globalproject_id, ordnumber, quonumber, paid, taxincluded, notes, taxzone_id, storno, gldate, mtime, itime, intnotes, (SELECT cu.name FROM currencies cu WHERE cu.id=ap.currency_id) AS currency, direct_debit, @@ -1022,7 +1022,7 @@ sub retrieve_invoice { delete $ref->{id}; map { $form->{$_} = $ref->{$_} } keys %$ref; - my $transdate = $form->{invdate} ? $dbh->quote($form->{invdate}) : "current_date"; + my $transdate = $form->{tax_point} ? $dbh->quote($form->{tax_point}) :$form->{invdate} ? $dbh->quote($form->{invdate}) : "current_date"; my $taxzone_id = $form->{taxzone_id} * 1; $taxzone_id = SL::DB::Manager::TaxZone->get_default->id unless SL::DB::Manager::TaxZone->find_by(id => $taxzone_id); diff --git a/SL/IS.pm b/SL/IS.pm index e9e9144d4..5fe66cf47 100644 --- a/SL/IS.pm +++ b/SL/IS.pm @@ -1037,7 +1037,7 @@ SQL $project_id = conv_i($form->{"globalproject_id"}); # entsprechend auch beim Bestimmen des Steuerschlüssels in Taxkey.pm berücksichtigen - my $taxdate = $form->{deliverydate} ? $form->{deliverydate} : $form->{invdate}; + my $taxdate = $form->{tax_point} ||$form->{deliverydate} || $form->{invdate}; foreach my $trans_id (keys %{ $form->{amount_cogs} }) { foreach my $accno (keys %{ $form->{amount_cogs}{$trans_id} }) { @@ -1312,7 +1312,7 @@ SQL $query = qq|UPDATE ar set invnumber = ?, ordnumber = ?, quonumber = ?, cusordnumber = ?, - transdate = ?, orddate = ?, quodate = ?, customer_id = ?, + transdate = ?, orddate = ?, quodate = ?, tax_point = ?, customer_id = ?, amount = ?, netamount = ?, paid = ?, duedate = ?, deliverydate = ?, invoice = ?, shippingpoint = ?, shipvia = ?, notes = ?, intnotes = ?, @@ -1327,7 +1327,7 @@ SQL delivery_term_id = ? WHERE id = ?|; @values = ( $form->{"invnumber"}, $form->{"ordnumber"}, $form->{"quonumber"}, $form->{"cusordnumber"}, - conv_date($form->{"invdate"}), conv_date($form->{"orddate"}), conv_date($form->{"quodate"}), conv_i($form->{"customer_id"}), + conv_date($form->{"invdate"}), conv_date($form->{"orddate"}), conv_date($form->{"quodate"}), conv_date($form->{tax_point}), conv_i($form->{"customer_id"}), $amount, $netamount, $form->{"paid"}, conv_date($form->{"duedate"}), conv_date($form->{"deliverydate"}), '1', $form->{"shippingpoint"}, $form->{"shipvia"}, $restricter->process($form->{"notes"}), $form->{"intnotes"}, @@ -2012,7 +2012,7 @@ sub _retrieve_invoice { qq|SELECT a.invnumber, a.ordnumber, a.quonumber, a.cusordnumber, a.orddate, a.quodate, a.globalproject_id, - a.transdate AS invdate, a.deliverydate, a.paid, a.storno, a.storno_id, a.gldate, + a.transdate AS invdate, a.deliverydate, a.tax_point, a.paid, a.storno, a.storno_id, a.gldate, a.shippingpoint, a.shipvia, a.notes, a.intnotes, a.taxzone_id, a.duedate, a.taxincluded, (SELECT cu.name FROM currencies cu WHERE cu.id=a.currency_id) AS currency, a.shipto_id, a.cp_id, a.employee_id, a.salesman_id, a.payment_id, @@ -2055,7 +2055,8 @@ sub _retrieve_invoice { $sth->finish; map { $form->{$_} =~ s/ +$//g } qw(printed emailed queued); - my $transdate = $form->{deliverydate} ? $dbh->quote($form->{deliverydate}) + my $transdate = $form->{tax_point} ? $dbh->quote($form->{tax_point}) + : $form->{deliverydate} ? $dbh->quote($form->{deliverydate}) : $form->{invdate} ? $dbh->quote($form->{invdate}) : "current_date"; diff --git a/SL/OE.pm b/SL/OE.pm index 974a1a1bd..759f96265 100644 --- a/SL/OE.pm +++ b/SL/OE.pm @@ -743,7 +743,7 @@ SQL $query = qq|UPDATE oe SET ordnumber = ?, quonumber = ?, cusordnumber = ?, transdate = ?, vendor_id = ?, - customer_id = ?, amount = ?, netamount = ?, reqdate = ?, taxincluded = ?, + customer_id = ?, amount = ?, netamount = ?, reqdate = ?, tax_point = ?, taxincluded = ?, shippingpoint = ?, shipvia = ?, notes = ?, intnotes = ?, currency_id = (SELECT id FROM currencies WHERE name=?), closed = ?, delivered = ?, proforma = ?, quotation = ?, department_id = ?, language_id = ?, taxzone_id = ?, shipto_id = ?, payment_id = ?, delivery_vendor_id = ?, delivery_customer_id = ?,delivery_term_id = ?, @@ -754,7 +754,7 @@ SQL @values = ($form->{ordnumber} || '', $form->{quonumber}, $form->{cusordnumber}, conv_date($form->{transdate}), conv_i($form->{vendor_id}), conv_i($form->{customer_id}), - $amount, $netamount, conv_date($reqdate), + $amount, $netamount, conv_date($reqdate), conv_date($form->{tax_point}), $form->{taxincluded} ? 't' : 'f', $form->{shippingpoint}, $form->{shipvia}, $restricter->process($form->{notes}), $form->{intnotes}, $form->{currency}, $form->{closed} ? 't' : 'f', @@ -1017,7 +1017,7 @@ sub _retrieve { o.taxincluded, o.shippingpoint, o.shipvia, o.notes, o.intnotes, (SELECT cu.name FROM currencies cu WHERE cu.id=o.currency_id) AS currency, e.name AS employee, o.employee_id, o.salesman_id, o.${vc}_id, cv.name AS ${vc}, o.amount AS invtotal, - o.closed, o.reqdate, o.quonumber, o.department_id, o.cusordnumber, + o.closed, o.reqdate, o.tax_point, o.quonumber, o.department_id, o.cusordnumber, o.mtime, o.itime, d.description AS department, o.payment_id, o.language_id, o.taxzone_id, o.delivery_customer_id, o.delivery_vendor_id, o.proforma, o.shipto_id, @@ -1096,7 +1096,7 @@ sub _retrieve { map { $form->{$_} =~ s/ +$//g } qw(printed emailed queued); } # if !@ids - my $transdate = $form->{transdate} ? $dbh->quote($form->{transdate}) : "current_date"; + my $transdate = $form->{tax_point} ? $dbh->quote($form->{tax_point}) : $form->{transdate} ? $dbh->quote($form->{transdate}) : "current_date"; $form->{taxzone_id} = 0 unless ($form->{taxzone_id}); unshift @values, ($form->{taxzone_id}) x 2; diff --git a/bin/mozilla/io.pl b/bin/mozilla/io.pl index 0362e13ae..62a1d1dee 100644 --- a/bin/mozilla/io.pl +++ b/bin/mozilla/io.pl @@ -1409,7 +1409,7 @@ sub print_form { # Format dates. format_dates($output_dateformat, $output_longdates, - qw(invdate orddate quodate pldate duedate reqdate transdate + qw(invdate orddate quodate pldate duedate reqdate transdate tax_point shippingdate deliverydate validitydate paymentdate datepaid transdate_oe transdate_do transdate_quo deliverydate_oe dodate employee_startdate employee_enddate diff --git a/locale/de/all b/locale/de/all index 6ebd46cc4..5dc069070 100755 --- a/locale/de/all +++ b/locale/de/all @@ -3177,6 +3177,7 @@ $self->{texts} = { 'Tax deleted!' => 'Steuer gelöscht!', 'Tax number' => 'Steuernummer', 'Tax paid' => 'Vorsteuer', + 'Tax point' => 'Leistungsdatum', 'Tax rate' => 'Steuersatz', 'Tax saved!' => 'Steuer gespeichert!', 'Tax zone' => 'Steuerzone', diff --git a/sql/Pg-upgrade2/tax_point.sql b/sql/Pg-upgrade2/tax_point.sql new file mode 100644 index 000000000..e0cd3809c --- /dev/null +++ b/sql/Pg-upgrade2/tax_point.sql @@ -0,0 +1,6 @@ +-- @tag: tax_point +-- @description: Feld Leistungsdatum in Einkaufs- & Verkaufsbelegen +-- @depends: release_3_5_6_1 +ALTER TABLE ap ADD COLUMN tax_point DATE; +ALTER TABLE ar ADD COLUMN tax_point DATE; +ALTER TABLE oe ADD COLUMN tax_point DATE; diff --git a/templates/webpages/ir/form_header.html b/templates/webpages/ir/form_header.html index d146c7b38..4fcfa3b3c 100644 --- a/templates/webpages/ir/form_header.html +++ b/templates/webpages/ir/form_header.html @@ -154,6 +154,10 @@ + + [% LxERP.t8('Tax point') %] + [% L.date_tag('tax_point', tax_point, id='tax_point') %] + [% 'Delivery Date' | $T8 %] [% L.date_tag('deliverydate', deliverydate) %] diff --git a/templates/webpages/is/form_header.html b/templates/webpages/is/form_header.html index e30974023..c23c16229 100644 --- a/templates/webpages/is/form_header.html +++ b/templates/webpages/is/form_header.html @@ -238,8 +238,14 @@ +[%- END %] + + [% LxERP.t8('Tax point') %] + [% L.date_tag('tax_point', tax_point, id='tax_point') %] + +[%- IF !is_type_credit_note %] - [% 'Delivery Order Number' | $T8 %] + [% 'Delivery Order Number' | $T8 %] [%- END %] diff --git a/templates/webpages/oe/form_header.html b/templates/webpages/oe/form_header.html index 556987417..2390718f3 100644 --- a/templates/webpages/oe/form_header.html +++ b/templates/webpages/oe/form_header.html @@ -225,6 +225,10 @@ [% L.date_tag('transdate', transdate, id='transdate') %] + + [% LxERP.t8('Tax point') %] + [% L.date_tag('tax_point', tax_point, id='tax_point') %] + [%- IF is_sales_quo %]