add_{ap|ar}_amount_row berücksichtigen gldate
authorG. Richardson <grichardson@kivitec.de>
Thu, 31 Oct 2019 14:06:44 +0000 (15:06 +0100)
committerG. Richardson <grichardson@kivitec.de>
Tue, 21 Jan 2020 11:51:20 +0000 (12:51 +0100)
Ansonsten konnte gldate in ar/ap und acc_trans abweichen, wenn gldate
explizit gesetzt war und nicht dem aktuellen Tag entsprach.

SL/DB/Invoice.pm
SL/DB/PurchaseInvoice.pm
t/ar/ar.t

index 0e27f8a..38ec9c0 100644 (file)
@@ -362,6 +362,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},
@@ -376,6 +377,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,
      );
index 93fc1fe..a50884c 100644 (file)
@@ -182,6 +182,7 @@ sub add_ap_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},
@@ -196,6 +197,7 @@ sub add_ap_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,
        project_id => $params{project_id},
index dfb8756..c5583f1 100644 (file)
--- a/t/ar/ar.t
+++ b/t/ar/ar.t
@@ -1,5 +1,5 @@
 use strict;
-use Test::More tests => 6;
+use Test::More tests => 7;
 
 use lib 't';
 use Support::TestSetup;
@@ -56,6 +56,7 @@ if ( $inv ) {
   is($number_of_acc_trans                , 5                             , "number of transactions");
   is($inv->datepaid->to_kivitendo        , DateTime->today->to_kivitendo , "datepaid");
   is($inv->amount - $inv->paid           , 0                             , "paid = amount ");
+  is($inv->gldate->to_kivitendo, $inv->transactions->[0]->gldate->to_kivitendo, "gldate matches in ar and acc_trans");
 } else {
   ok 0, "couldn't find first invoice";
 }
@@ -92,7 +93,8 @@ sub _ar {
 
   my $amount       = $params{amount}       || croak "ar needs param amount";
   my $customer     = $params{customer}     || croak "ar needs param customer";
-  my $date         = $params{date}         || DateTime->today;
+  my $transdate    = $params{transdate}    || DateTime->today;
+  my $gldate       = $params{gldate}       || DateTime->today->add(days => 1);
   my $with_payment = $params{with_payment} || 0;
 
   # SL::DB::Invoice has a _before_save_set_invnumber hook, so we don't need to pass invnumber
@@ -100,7 +102,8 @@ sub _ar {
       invoice          => 0,
       amount           => $amount,
       netamount        => $amount,
-      transdate        => $date,
+      transdate        => $transdate,
+      gldate           => $gldate,
       taxincluded      => 'f',
       customer_id      => $customer->id,
       taxzone_id       => $customer->taxzone_id,
@@ -144,14 +147,16 @@ sub _ar_with_tax {
 
   my $amount       = $params{amount}       || croak "ar needs param amount";
   my $customer     = $params{customer}     || croak "ar needs param customer";
-  my $date         = $params{date}         || DateTime->today;
+  my $transdate    = $params{transdate}    || DateTime->today;
+  my $gldate       = $params{gldate}       || DateTime->today->add(days => 1);
   my $with_payment = $params{with_payment} || 0;
 
   my $invoice = SL::DB::Invoice->new(
     invoice          => 0,
     amount           => $amount,
     netamount        => $amount,
-    transdate        => $date,
+    transdate        => $transdate,
+    gldate           => $gldate,
     taxincluded      => 'f',
     customer_id      => $customer->id,
     taxzone_id       => $customer->taxzone_id,