Projekt

Allgemein

Profil

Herunterladen (18,6 KB) Statistiken
| Zweig: | Markierung: | Revision:
db64ed3a Geoffrey Richardson
use strict;
use Test::More;
0ad87689 Jan Büren
use Test::Deep qw(cmp_deeply cmp_bag);
db64ed3a Geoffrey Richardson
use lib 't';
1e30359a Jan Büren
use utf8;
db64ed3a Geoffrey Richardson
use_ok 'Support::TestSetup';
use SL::DATEV qw(:CONSTANTS);
63410aa6 Sven Schöling
use SL::Dev::ALL qw(:ALL);
db64ed3a Geoffrey Richardson
use List::Util qw(sum);
use SL::DB::Buchungsgruppe;
use SL::DB::Chart;
use DateTime;

Support::TestSetup::login();

clear_up();

1a3b9961 Geoffrey Richardson
my $dbh = SL::DB->client->dbh;

db64ed3a Geoffrey Richardson
my $buchungsgruppe7 = SL::DB::Manager::Buchungsgruppe->find_by(description => 'Standard 7%') || die "No accounting group for 7\%";
my $bank = SL::DB::Manager::Chart->find_by(description => 'Bank') || die 'Can\'t find chart "Bank"';
my $date = DateTime->new(year => 2017, month => 1, day => 1);
my $payment_date = DateTime->new(year => 2017, month => 1, day => 5);
1a3b9961 Geoffrey Richardson
my $gldate = DateTime->new(year => 2017, month => 2, day => 9); # simulate bookings for Jan being made in Feb
c21b3764 Jan Büren
my $department = create_department(description => 'Kostenstelle DATEV-Schnittstelle 2018');
my $project = create_project(projectnumber => 2017, description => 'Crowd-Funding September 2017');
d76eb69e Geoffrey Richardson
my $customer = new_customer(customernumber => '10001', name => 'Testcustomer')->save;
my $vendor = new_vendor(vendornumber => '70001', name => 'Testvendor')->save;
db64ed3a Geoffrey Richardson
63410aa6 Sven Schöling
my $part1 = new_part(partnumber => '19', description => 'Part 19%')->save;
my $part2 = new_part(
db64ed3a Geoffrey Richardson
partnumber => '7',
description => 'Part 7%',
buchungsgruppen_id => $buchungsgruppe7->id,
)->save;

63410aa6 Sven Schöling
my $invoice = create_sales_invoice(
ef5b4b39 Jan Büren
invnumber => "Þ sales ¥& invöice",
d76eb69e Geoffrey Richardson
customer => $customer,
1a3b9961 Geoffrey Richardson
itime => $gldate,
gldate => $gldate,
intnotes => 'booked in February',
db64ed3a Geoffrey Richardson
taxincluded => 0,
transdate => $date,
63410aa6 Sven Schöling
invoiceitems => [ create_invoice_item(part => $part1, qty => 3, sellprice => 70),
create_invoice_item(part => $part2, qty => 10, sellprice => 50),
c21b3764 Jan Büren
],
department_id => $department->id,
globalproject_id => $project->id,
db64ed3a Geoffrey Richardson
);
$invoice->pay_invoice(chart_id => $bank->id,
amount => $invoice->open_amount,
transdate => $payment_date->to_kivitendo,
memo => 'foobar',
source => 'barfoo',
);
my $datev1 = SL::DATEV->new(
dbh => $invoice->db->dbh,
trans_id => $invoice->id,
);
dd33b4ae Geoffrey Richardson
db64ed3a Geoffrey Richardson
$datev1->generate_datev_data;
dd33b4ae Geoffrey Richardson
1e30359a Jan Büren
my @data_datev = sort { $a->{umsatz} <=> $b->{umsatz} } @{ $datev1->generate_datev_lines() };
0ad87689 Jan Büren
cmp_deeply \@data_datev, [
db64ed3a Geoffrey Richardson
{
1e30359a Jan Büren
'belegfeld1' => "\x{de} sales \x{a5}& inv\x{f6}ice",
db64ed3a Geoffrey Richardson
'buchungstext' => 'Testcustomer',
'datum' => '01.01.2017',
'gegenkonto' => '8400',
'konto' => '1400',
c21b3764 Jan Büren
'kost1' => 'Kostenstelle DATEV-Schnittstelle 2018',
'kost2' => 'Crowd-Funding September 2017',
2d9b08c7 Bernd Bleßmann
'locked' => undef,
db64ed3a Geoffrey Richardson
'umsatz' => '249.9',
ef5b4b39 Jan Büren
'waehrung' => 'EUR',
db64ed3a Geoffrey Richardson
},
{
1e30359a Jan Büren
'belegfeld1' => "\x{de} sales \x{a5}& inv\x{f6}ice",
db64ed3a Geoffrey Richardson
'buchungstext' => 'Testcustomer',
'datum' => '01.01.2017',
'gegenkonto' => '8300',
'konto' => '1400',
c21b3764 Jan Büren
'kost1' => 'Kostenstelle DATEV-Schnittstelle 2018',
'kost2' => 'Crowd-Funding September 2017',
2d9b08c7 Bernd Bleßmann
'locked' => undef,
db64ed3a Geoffrey Richardson
'umsatz' => 535,
ef5b4b39 Jan Büren
'waehrung' => 'EUR',
db64ed3a Geoffrey Richardson
},
{
1e30359a Jan Büren
'belegfeld1' => "\x{de} sales \x{a5}& inv\x{f6}ice",
1207c91c Bernd Bleßmann
'buchungstext' => 'Testcustomer',
db64ed3a Geoffrey Richardson
'buchungstext' => 'Testcustomer',
'datum' => '05.01.2017',
'gegenkonto' => '1400',
'konto' => '1200',
c21b3764 Jan Büren
'kost1' => 'Kostenstelle DATEV-Schnittstelle 2018',
'kost2' => 'Crowd-Funding September 2017',
db64ed3a Geoffrey Richardson
'umsatz' => '784.9',
2d9b08c7 Bernd Bleßmann
'locked' => undef,
ef5b4b39 Jan Büren
'waehrung' => 'EUR',
db64ed3a Geoffrey Richardson
},
], "trans_id datev check ok";

d76eb69e Geoffrey Richardson
$datev1->use_pk(1);
$datev1->generate_datev_data;
0ad87689 Jan Büren
# TODO for cmp_deeply we need to sort the incoming data structure (see below)
d76eb69e Geoffrey Richardson
cmp_bag $datev1->generate_datev_lines, [
{
1e30359a Jan Büren
'belegfeld1' => "\x{de} sales \x{a5}& inv\x{f6}ice",
d76eb69e Geoffrey Richardson
'buchungstext' => 'Testcustomer',
'datum' => '01.01.2017',
'gegenkonto' => '8400',
'konto' => $customer->customernumber,
'kost1' => 'Kostenstelle DATEV-Schnittstelle 2018',
'kost2' => 'Crowd-Funding September 2017',
'umsatz' => '249.9',
2d9b08c7 Bernd Bleßmann
'locked' => undef,
d76eb69e Geoffrey Richardson
'waehrung' => 'EUR',
},
{
1e30359a Jan Büren
'belegfeld1' => "\x{de} sales \x{a5}& inv\x{f6}ice",
d76eb69e Geoffrey Richardson
'buchungstext' => 'Testcustomer',
'datum' => '01.01.2017',
'gegenkonto' => '8300',
'konto' => $customer->customernumber,
'kost1' => 'Kostenstelle DATEV-Schnittstelle 2018',
'kost2' => 'Crowd-Funding September 2017',
'umsatz' => 535,
2d9b08c7 Bernd Bleßmann
'locked' => undef,
d76eb69e Geoffrey Richardson
'waehrung' => 'EUR',
},
{
1e30359a Jan Büren
'belegfeld1' => "\x{de} sales \x{a5}& inv\x{f6}ice",
d76eb69e Geoffrey Richardson
'buchungstext' => 'Testcustomer',
'datum' => '05.01.2017',
'gegenkonto' => $customer->customernumber,
'konto' => '1200',
'kost1' => 'Kostenstelle DATEV-Schnittstelle 2018',
'kost2' => 'Crowd-Funding September 2017',
'umsatz' => '784.9',
2d9b08c7 Bernd Bleßmann
'locked' => undef,
d76eb69e Geoffrey Richardson
'waehrung' => 'EUR',
},
], "trans_id datev check use_pk ok";


ef5b4b39 Jan Büren
my $startdate = DateTime->new(year => 2017, month => 1, day => 1);
my $enddate = DateTime->new(year => 2017, month => 12, day => 31);

# check conversion to csv
$datev1->from($startdate);
$datev1->to($enddate);
1d559eff Jan Büren
# reset use_pk for csv_buchungsexport
$datev1->use_pk(0);
$datev1->generate_datev_data;


18a2ca33 Jan Büren
my $datev_csv = SL::DATEV::CSV->new(datev_lines => $datev1->generate_datev_lines,
from => $startdate,
to => $enddate,
locked => $datev1->locked,
1d559eff Jan Büren
);
18a2ca33 Jan Büren
$datev_csv->lines;

ef5b4b39 Jan Büren
# we need sort, because pay_invoice is not acc_trans_id order safe
18a2ca33 Jan Büren
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);

ef5b4b39 Jan Büren
981979b5 Sven Schöling
cmp_deeply($data_csv[1], [ '535', 'S', 'EUR', '', '', '', '1400', '8300', '', '0101', "\x{de} sales \x{a5}& i",
'', '', 'Testcustomer', '', '', '', '', '', '', '', '',
e428a414 Jan Büren
'', '', '', '', '', '', '', '', '', '', '', '', '',
0ad87689 Jan Büren
'', 'Kostenst', 'Crowd-Fu', '', '', '', '', '', '', '', '',
e428a414 Jan Büren
'', '', '', '', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '', '', '', '',
2d9b08c7 Bernd Bleßmann
'', '', '1', '', '', '', '', '', '' ]
ef5b4b39 Jan Büren
);

0ad87689 Jan Büren
cmp_deeply($data_csv[0], [ '249,9', 'S', 'EUR', '', '', '', '1400', '8400', '', '0101', "\x{de} sales \x{a5}& i",
981979b5 Sven Schöling
'', '', 'Testcustomer', '', '', '', '', '', '', '', '',
e428a414 Jan Büren
'', '', '', '', '', '', '', '', '', '', '', '', '',
0ad87689 Jan Büren
'', 'Kostenst', 'Crowd-Fu', '', '', '', '', '', '', '', '',
e428a414 Jan Büren
'', '', '', '', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '', '', '', '',
2d9b08c7 Bernd Bleßmann
'', '', '1', '', '', '', '', '', '' ]
ef5b4b39 Jan Büren
);
0ad87689 Jan Büren
cmp_deeply($data_csv[2], [ '784,9', 'S', 'EUR', '', '', '', '1200', '1400', '', '0501', "\x{de} sales \x{a5}& i",
981979b5 Sven Schöling
'', '', 'Testcustomer', '', '', '', '', '', '', '', '',
e428a414 Jan Büren
'', '', '', '', '', '', '', '', '', '', '', '', '',
0ad87689 Jan Büren
'', 'Kostenst', 'Crowd-Fu', '', '', '', '', '', '', '', '',
e428a414 Jan Büren
'', '', '', '', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '', '', '', '',
2d9b08c7 Bernd Bleßmann
'', '', '1', '', '', '', '', '', '' ]
ef5b4b39 Jan Büren
);
1a3b9961 Geoffrey Richardson
my $march_9 = DateTime->new(year => 2017, month => 3, day => 9);
63410aa6 Sven Schöling
my $invoice2 = create_sales_invoice(
db64ed3a Geoffrey Richardson
invnumber => "2 sales invoice",
d76eb69e Geoffrey Richardson
customer => $customer,
1a3b9961 Geoffrey Richardson
itime => $march_9,
gldate => $march_9,
intnotes => 'booked in March',
db64ed3a Geoffrey Richardson
taxincluded => 0,
transdate => $date,
63410aa6 Sven Schöling
invoiceitems => [ create_invoice_item(part => $part1, qty => 6, sellprice => 70),
create_invoice_item(part => $part2, qty => 20, sellprice => 50),
db64ed3a Geoffrey Richardson
]
);

63410aa6 Sven Schöling
my $credit_note = create_credit_note(
db64ed3a Geoffrey Richardson
invnumber => 'Gutschrift 34',
d76eb69e Geoffrey Richardson
customer => $customer,
1a3b9961 Geoffrey Richardson
itime => $gldate,
gldate => $gldate,
intnotes => 'booked in February',
db64ed3a Geoffrey Richardson
taxincluded => 0,
transdate => $date,
63410aa6 Sven Schöling
invoiceitems => [ create_invoice_item(part => $part1, qty => 3, sellprice => 70),
create_invoice_item(part => $part2, qty => 10, sellprice => 50),
db64ed3a Geoffrey Richardson
]
);

my $datev = SL::DATEV->new(
1a3b9961 Geoffrey Richardson
dbh => $dbh,
from => $startdate,
to => $enddate,
);
$datev->generate_datev_data(from_to => $datev->fromto);
my $datev_lines = $datev->generate_datev_lines;
my $umsatzsumme = sum map { $_->{umsatz} } @{ $datev_lines };
cmp_ok($::form->round_amount($umsatzsumme,2), '==', 3924.5, "Sum of all bookings ok");

d76eb69e Geoffrey Richardson
$datev->generate_datev_data(use_pk => 1, from_to => $datev->fromto);
$datev_lines = $datev->generate_datev_lines;

note('testing purchase invoice');
578a40ba Geoffrey Richardson
my $purchase_invoice = create_ap_transaction(
vendor => $vendor,
invnumber => 'ap1',
amount => '226',
netamount => '200',
transdate => $date,
gldate => $date,
itime => $date, # make sure itime is 1.1., as gldatefrom tests for itime!
taxincluded => 0,
bookings => [
{
chart => SL::DB::Manager::Chart->find_by(accno => '3400'),
amount => 100,
},
{
chart => SL::DB::Manager::Chart->find_by(accno => '3300'),
amount => 100,
},
],
);

d76eb69e Geoffrey Richardson
$datev1 = SL::DATEV->new(
dbh => $purchase_invoice->db->dbh,
trans_id => $purchase_invoice->id,
);

$datev1->generate_datev_data;
0ad87689 Jan Büren
cmp_deeply $datev1->generate_datev_lines, [
d76eb69e Geoffrey Richardson
{
'belegfeld1' => 'ap1',
'buchungstext' => 'Testvendor',
'datum' => '01.01.2017',
'gegenkonto' => '1600',
'konto' => '3400',
'kost1' => undef,
'kost2' => undef,
'umsatz' => 119,
2d9b08c7 Bernd Bleßmann
'locked' => undef,
d76eb69e Geoffrey Richardson
'waehrung' => 'EUR'
},
{
'belegfeld1' => 'ap1',
'buchungstext' => 'Testvendor',
'datum' => '01.01.2017',
'gegenkonto' => '1600',
'konto' => '3300',
'kost1' => undef,
'kost2' => undef,
'umsatz' => 107,
2d9b08c7 Bernd Bleßmann
'locked' => undef,
d76eb69e Geoffrey Richardson
'waehrung' => 'EUR'
}
], "trans_id datev check purchase_invoice ok";
$datev1->use_pk(1);
$datev1->generate_datev_data;
0ad87689 Jan Büren
cmp_deeply $datev1->generate_datev_lines, [
d76eb69e Geoffrey Richardson
{
'belegfeld1' => 'ap1',
'buchungstext' => 'Testvendor',
'datum' => '01.01.2017',
'gegenkonto' => $vendor->vendornumber,
'konto' => '3400',
'kost1' => undef,
'kost2' => undef,
'umsatz' => 119,
2d9b08c7 Bernd Bleßmann
'locked' => undef,
d76eb69e Geoffrey Richardson
'waehrung' => 'EUR'
},
{
'belegfeld1' => 'ap1',
'buchungstext' => 'Testvendor',
'datum' => '01.01.2017',
'gegenkonto' => $vendor->vendornumber,
'konto' => '3300',
'kost1' => undef,
'kost2' => undef,
'umsatz' => 107,
2d9b08c7 Bernd Bleßmann
'locked' => undef,
d76eb69e Geoffrey Richardson
'waehrung' => 'EUR'
}
], "trans_id datev check purchase_invoice use_pk ok";

1a3b9961 Geoffrey Richardson
note('testing gldatefrom');
578a40ba Geoffrey Richardson
# test an order with transdate in january, but that was booked in march
# gldatefrom in DATEV.pm checks for itime, not gldate!!!
8abfdcfc Sven Schöling
$datev = SL::DATEV->new(
1a3b9961 Geoffrey Richardson
dbh => $dbh,
db64ed3a Geoffrey Richardson
from => $startdate,
1a3b9961 Geoffrey Richardson
to => DateTime->new(year => 2017, month => 01, day => 31),
db64ed3a Geoffrey Richardson
);
1a3b9961 Geoffrey Richardson
$::form = Support::TestSetup->create_new_form;
$::form->{gldatefrom} = DateTime->new(year => 2017, month => 3, day => 1)->to_kivitendo;

db64ed3a Geoffrey Richardson
$datev->generate_datev_data(from_to => $datev->fromto);
8abfdcfc Sven Schöling
$datev_lines = $datev->generate_datev_lines;
$umsatzsumme = sum map { $_->{umsatz} } @{ $datev_lines };
1a3b9961 Geoffrey Richardson
cmp_ok($umsatzsumme, '==', 1569.8, "Sum of bookings made after March 1st (only invoice2) ok");

$::form->{gldatefrom} = DateTime->new(year => 2017, month => 5, day => 1)->to_kivitendo;
$datev->generate_datev_data(from_to => $datev->fromto);
0ad87689 Jan Büren
cmp_deeply $datev->generate_datev_lines, [], "no bookings for January made after May 1st: ok";
db64ed3a Geoffrey Richardson
done_testing();
fbd33694 Bernd Bleßmann
clear_up();
d76eb69e Geoffrey Richardson
db64ed3a Geoffrey Richardson
sub clear_up {
SL::DB::Manager::AccTransaction->delete_all(all => 1);
SL::DB::Manager::InvoiceItem->delete_all( all => 1);
SL::DB::Manager::Invoice->delete_all( all => 1);
d76eb69e Geoffrey Richardson
SL::DB::Manager::PurchaseInvoice->delete_all(all => 1);
db64ed3a Geoffrey Richardson
SL::DB::Manager::Customer->delete_all( all => 1);
SL::DB::Manager::Part->delete_all( all => 1);
c21b3764 Jan Büren
SL::DB::Manager::Project->delete_all( all => 1);
SL::DB::Manager::Department->delete_all( all => 1);
ef5b4b39 Jan Büren
SL::DATEV->clean_temporary_directories;
db64ed3a Geoffrey Richardson
};

1;