OrderController: reorder mit Sort::Naturally damit nach Preis ordentlich
[kivitendo-erp.git] / t / datev / invoices.t
index 68acb05..3625f88 100644 (file)
@@ -1,6 +1,6 @@
 use strict;
 use Test::More;
-use Test::Deep qw(cmp_bag);
+use Test::Deep qw(cmp_deeply cmp_bag);
 
 use lib 't';
 use utf8;
@@ -64,7 +64,7 @@ my $datev1 = SL::DATEV->new(
 $datev1->generate_datev_data;
 
 my @data_datev   = sort { $a->{umsatz} <=> $b->{umsatz} } @{ $datev1->generate_datev_lines() };
-cmp_bag \@data_datev, [
+cmp_deeply \@data_datev, [
                                          {
                                            'belegfeld1'   => "\x{de} sales \x{a5}& inv\x{f6}ice",
                                            'buchungstext' => 'Testcustomer',
@@ -75,7 +75,6 @@ cmp_bag \@data_datev, [
                                            'kost2'        => 'Crowd-Funding September 2017',
                                            'umsatz'       => '249.9',
                                            'waehrung'     => 'EUR',
-                                           'soll_haben_kennzeichen' => 'S',
                                          },
                                          {
                                            'belegfeld1'   => "\x{de} sales \x{a5}& inv\x{f6}ice",
@@ -87,7 +86,6 @@ cmp_bag \@data_datev, [
                                            'kost2'        => 'Crowd-Funding September 2017',
                                            'umsatz'       => 535,
                                            'waehrung'     => 'EUR',
-                                           'soll_haben_kennzeichen' => 'S',
                                          },
                                          {
                                            'belegfeld1'   => "\x{de} sales \x{a5}& inv\x{f6}ice",
@@ -102,12 +100,12 @@ cmp_bag \@data_datev, [
                                            'kost2'        => 'Crowd-Funding September 2017',
                                            'umsatz'       => '784.9',
                                            'waehrung'     => 'EUR',
-                                           'soll_haben_kennzeichen' => 'S',
                                          },
                                        ], "trans_id datev check ok";
 
 $datev1->use_pk(1);
 $datev1->generate_datev_data;
+# TODO for cmp_deeply we need to sort the incoming data structure (see below)
 cmp_bag $datev1->generate_datev_lines, [
                                          {
                                            'belegfeld1'   => "\x{de} sales \x{a5}& inv\x{f6}ice",
@@ -119,7 +117,6 @@ cmp_bag $datev1->generate_datev_lines, [
                                            'kost2'        => 'Crowd-Funding September 2017',
                                            'umsatz'       => '249.9',
                                            'waehrung'     => 'EUR',
-                                           'soll_haben_kennzeichen' => 'S',
                                          },
                                          {
                                            'belegfeld1'   => "\x{de} sales \x{a5}& inv\x{f6}ice",
@@ -131,7 +128,6 @@ cmp_bag $datev1->generate_datev_lines, [
                                            'kost2'        => 'Crowd-Funding September 2017',
                                            'umsatz'       => 535,
                                            'waehrung'     => 'EUR',
-                                           'soll_haben_kennzeichen' => 'S',
                                          },
                                          {
                                            'belegfeld1'   => "\x{de} sales \x{a5}& inv\x{f6}ice",
@@ -143,7 +139,6 @@ cmp_bag $datev1->generate_datev_lines, [
                                            'kost2'        => 'Crowd-Funding September 2017',
                                            'umsatz'       => '784.9',
                                            'waehrung'     => 'EUR',
-                                           'soll_haben_kennzeichen' => 'S',
                                          },
                                        ], "trans_id datev check use_pk ok";
 
@@ -159,55 +154,53 @@ $datev1->use_pk(0);
 $datev1->generate_datev_data;
 
 
-my ($datev_ref, $w_ref) = SL::DATEV::CSV->new(datev_lines  => $datev1->generate_datev_lines,
-                                              from         => $startdate,
-                                              to           => $enddate,
-                                              locked       => $datev1->locked,
+my $datev_csv = SL::DATEV::CSV->new(datev_lines  => $datev1->generate_datev_lines,
+                                    from         => $startdate,
+                                    to           => $enddate,
+                                    locked       => $datev1->locked,
                                    );
-# warnings should be undef -> no array elements at all
-is(scalar @{ $w_ref }, 0);
+$datev_csv->lines;
+
 
-# splice away the header, because sort won't do
 # we need sort, because pay_invoice is not acc_trans_id order safe
-my @data_csv = splice @{ $datev_ref }, 2, 5;
-@data_csv    = sort { $a->[0] cmp $b->[0] } @data_csv;
-
-my $cp1252_belegfeld1   = SL::Iconv::convert("UTF-8", "CP1252", 'Þ sales ¥& i');
-my $cp1252_buchungstext = SL::Iconv::convert("UTF-8", "CP1252", 'Þ sales ¥& invöice');
-
-cmp_bag($data_csv[1], [ 535, 'S', 'EUR', undef, undef, undef, '1400', '8300', undef, '0101', $cp1252_belegfeld1,
-                     undef, undef, $cp1252_buchungstext, undef, undef, undef, undef, undef, undef, undef, undef,
-                     undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef,
-                     undef, 'Crowd-Fu', 'Kostenst', undef, undef, undef, undef, undef, undef, undef, undef,
-                     undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef,
-                     undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef,
-                     undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef,
-                     undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef,
-                     undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef,
-                     undef, undef, undef, undef, undef ]
+my @data_csv    = sort { $a->[0] cmp $b->[0] } @{ $datev_csv->lines };
+# warnings should be undef -> no array elements at all
+is(scalar @{ $datev_csv->warnings }, 0);
+
+
+cmp_deeply($data_csv[1], [ '535', 'S', 'EUR', '', '', '', '1400', '8300', '', '0101', "\x{de} sales \x{a5}& i",
+                     '', '', 'Testcustomer', '', '', '', '', '', '', '', '',
+                     '', '', '', '', '', '', '', '', '', '', '', '', '',
+                     '', 'Kostenst', 'Crowd-Fu', '', '', '', '', '', '', '', '',
+                     '', '', '', '', '', '', '', '', '', '', '', '', '',
+                     '', '', '', '', '', '', '', '', '', '', '', '', '',
+                     '', '', '', '', '', '', '', '', '', '', '', '', '',
+                     '', '', '', '', '', '', '', '', '', '', '', '', '',
+                     '', '', '', '', '', '', '', '', '', '', '', '', '',
+                     '', '', '', '', '' ]
        );
 
-cmp_bag($data_csv[0], [ '249,9', 'S', 'EUR', undef, undef, undef, '1400', '8400', undef, '0101', $cp1252_belegfeld1,
-                     undef, undef, $cp1252_buchungstext, undef, undef, undef, undef, undef, undef, undef, undef,
-                     undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef,
-                     undef, 'Crowd-Fu', 'Kostenst', undef, undef, undef, undef, undef, undef, undef, undef,
-                     undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef,
-                     undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef,
-                     undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef,
-                     undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef,
-                     undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef,
-                     undef, undef, undef, undef, undef ]
+cmp_deeply($data_csv[0], [ '249,9', 'S', 'EUR', '', '', '', '1400', '8400', '', '0101', "\x{de} sales \x{a5}& i",
+                     '', '', 'Testcustomer', '', '', '', '', '', '', '', '',
+                     '', '', '', '', '', '', '', '', '', '', '', '', '',
+                     '', 'Kostenst', 'Crowd-Fu', '', '', '', '', '', '', '', '',
+                     '', '', '', '', '', '', '', '', '', '', '', '', '',
+                     '', '', '', '', '', '', '', '', '', '', '', '', '',
+                     '', '', '', '', '', '', '', '', '', '', '', '', '',
+                     '', '', '', '', '', '', '', '', '', '', '', '', '',
+                     '', '', '', '', '', '', '', '', '', '', '', '', '',
+                     '', '', '', '', '' ]
        );
-cmp_bag($data_csv[2], [ '784,9', 'S', 'EUR', undef, undef, undef, '1200', '1400', undef, '0501', $cp1252_belegfeld1,
-                     undef, undef, $cp1252_buchungstext, undef, undef, undef, undef, undef, undef, undef, undef,
-                     undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef,
-                     undef, 'Crowd-Fu', 'Kostenst', undef, undef, undef, undef, undef, undef, undef, undef,
-                     undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef,
-                     undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef,
-                     undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef,
-                     undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef,
-                     undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef,
-                     undef, undef, undef, undef, undef ]
+cmp_deeply($data_csv[2], [ '784,9', 'S', 'EUR', '', '', '', '1200', '1400', '', '0501', "\x{de} sales \x{a5}& i",
+                     '', '', 'Testcustomer', '', '', '', '', '', '', '', '',
+                     '', '', '', '', '', '', '', '', '', '', '', '', '',
+                     '', 'Kostenst', 'Crowd-Fu', '', '', '', '', '', '', '', '',
+                     '', '', '', '', '', '', '', '', '', '', '', '', '',
+                     '', '', '', '', '', '', '', '', '', '', '', '', '',
+                     '', '', '', '', '', '', '', '', '', '', '', '', '',
+                     '', '', '', '', '', '', '', '', '', '', '', '', '',
+                     '', '', '', '', '', '', '', '', '', '', '', '', '',
+                     '', '', '', '', '' ]
         );
 my $march_9 = DateTime->new(year => 2017, month =>  3, day => 9);
 my $invoice2 = create_sales_invoice(
@@ -257,7 +250,7 @@ $datev1 = SL::DATEV->new(
 );
 
 $datev1->generate_datev_data;
-cmp_bag $datev1->generate_datev_lines, [
+cmp_deeply $datev1->generate_datev_lines, [
                                         {
                                           'belegfeld1'             => 'ap1',
                                           'buchungstext'           => 'Testvendor',
@@ -266,7 +259,6 @@ cmp_bag $datev1->generate_datev_lines, [
                                           'konto'                  => '3400',
                                           'kost1'                  => undef,
                                           'kost2'                  => undef,
-                                          'soll_haben_kennzeichen' => 'H',
                                           'umsatz'                 => 119,
                                           'waehrung'               => 'EUR'
                                         },
@@ -278,14 +270,13 @@ cmp_bag $datev1->generate_datev_lines, [
                                           'konto'                  => '3300',
                                           'kost1'                  => undef,
                                           'kost2'                  => undef,
-                                          'soll_haben_kennzeichen' => 'H',
                                           'umsatz'                 => 107,
                                           'waehrung'               => 'EUR'
                                         }
                                        ], "trans_id datev check purchase_invoice ok";
 $datev1->use_pk(1);
 $datev1->generate_datev_data;
-cmp_bag $datev1->generate_datev_lines, [
+cmp_deeply $datev1->generate_datev_lines, [
                                         {
                                           'belegfeld1'             => 'ap1',
                                           'buchungstext'           => 'Testvendor',
@@ -294,7 +285,6 @@ cmp_bag $datev1->generate_datev_lines, [
                                           'konto'                  => '3400',
                                           'kost1'                  => undef,
                                           'kost2'                  => undef,
-                                          'soll_haben_kennzeichen' => 'H',
                                           'umsatz'                 => 119,
                                           'waehrung'               => 'EUR'
                                         },
@@ -306,7 +296,6 @@ cmp_bag $datev1->generate_datev_lines, [
                                           'konto'                  => '3300',
                                           'kost1'                  => undef,
                                           'kost2'                  => undef,
-                                          'soll_haben_kennzeichen' => 'H',
                                           'umsatz'                 => 107,
                                           'waehrung'               => 'EUR'
                                         }
@@ -329,10 +318,10 @@ cmp_ok($umsatzsumme, '==', 1569.8, "Sum of bookings made after March 1st (only i
 
 $::form->{gldatefrom} = DateTime->new(year => 2017, month => 5, day => 1)->to_kivitendo;
 $datev->generate_datev_data(from_to => $datev->fromto);
-cmp_bag $datev->generate_datev_lines, [], "no bookings for January made after May 1st: ok";
+cmp_deeply $datev->generate_datev_lines, [], "no bookings for January made after May 1st: ok";
 
 done_testing();
-clear_up();
+clear_up();
 
 sub new_purchase_invoice {
   # manually create a Kreditorenbuchung from scratch, ap + acc_trans bookings, as no helper exists yet, like $invoice->post.