X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=t%2Fbank%2Fbank_transactions.t;h=fd975751867347619a050b14cfb271b2fd63da40;hb=0399bdb1fcfbb8f7fd1a48771e4fa995037eb4b7;hp=b49dc4ac9cf6b09968980c8d5515d47914cad08d;hpb=8f7fe4a497b1fba104db0471fe6704c5625f5e89;p=kivitendo-erp.git diff --git a/t/bank/bank_transactions.t b/t/bank/bank_transactions.t index b49dc4ac9..fd9757518 100644 --- a/t/bank/bank_transactions.t +++ b/t/bank/bank_transactions.t @@ -1,4 +1,4 @@ -use Test::More tests => 74; +use Test::More tests => 105; use strict; @@ -66,13 +66,18 @@ clear_up(); reset_state(); # initialise customers/vendors/bank/currency/... test1(); + test_overpayment_with_partialpayment(); test_overpayment(); test_skonto_exact(); test_two_invoices(); test_partial_payment(); test_credit_note(); +test_ap_transaction(); test_neg_ap_transaction(); +test_ap_payment_transaction(); +test_ap_payment_part_transaction(); +test_neg_sales_invoice(); # remove all created data at end of test clear_up(); @@ -117,6 +122,7 @@ sub reset_state { bank => 'Geizkasse', bank_code => 'G1235', depositor => 'Test Customer', + customernumber => 'CUST1704', )->save; $payment_terms = SL::Dev::Payment::create_payment_terms; @@ -130,6 +136,7 @@ sub reset_state { bank => 'Geizkasse', bank_code => 'G1235', depositor => 'Test Vendor', + vendornumber => 'VEND1704', )->save; $ar_chart = SL::DB::Manager::Chart->find_by( accno => '1400' ); # Forderungen @@ -180,11 +187,13 @@ sub test_ar_transaction { sub test_ap_transaction { my (%params) = @_; + my $testname = 'test_ap_transaction'; + my $netamount = 100; my $amount = $::form->round_amount($netamount * 1.19,2); my $invoice = SL::DB::PurchaseInvoice->new( invoice => 0, - invnumber => $params{invnumber} || 'test_ap_transaction', + invnumber => $params{invnumber} || $testname, amount => $amount, netamount => $netamount, transdate => $transdate1, @@ -204,10 +213,10 @@ sub test_ap_transaction { $invoice->create_ap_row(chart => $ap_chart); $invoice->save; - is($invoice->currency_id , $currency_id , 'currency_id has been saved'); - is($invoice->netamount , 100 , 'ap amount has been converted'); - is($invoice->amount , 119 , 'ap amount has been converted'); - is($invoice->taxincluded , 0 , 'ap transaction doesn\'t have taxincluded'); + is($invoice->currency_id , $currency_id , "$testname: currency_id has been saved"); + is($invoice->netamount , 100 , "$testname: ap amount has been converted"); + is($invoice->amount , 119 , "$testname: ap amount has been converted"); + is($invoice->taxincluded , 0 , "$testname: ap transaction doesn\'t have taxincluded"); is(SL::DB::Manager::AccTransaction->find_by(chart_id => $ap_amount_chart->id , trans_id => $invoice->id)->amount , '-100.00000' , $ap_amount_chart->accno . ': has been converted for currency'); is(SL::DB::Manager::AccTransaction->find_by(chart_id => $ap_chart->id , trans_id => $invoice->id)->amount , '119.00000' , $ap_chart->accno . ': has been converted for currency'); @@ -433,6 +442,7 @@ sub test_credit_note { } sub test_neg_ap_transaction { + my (%params) = @_; my $testname = 'test_neg_ap_transaction'; my $netamount = -20; my $amount = $::form->round_amount($netamount * 1.19,2); @@ -476,12 +486,174 @@ sub test_neg_ap_transaction { save_btcontroller_to_string(); $invoice->load; + $bt->load; is($invoice->amount , '-23.80000', "$testname: amount ok"); is($invoice->netamount, '-20.00000', "$testname: netamount ok"); is($invoice->paid , '-23.80000', "$testname: paid ok"); + is($bt->invoice_amount, '23.80000', "$testname: bt invoice amount for ap was assigned"); + + return $invoice; +}; + +sub test_ap_payment_transaction { + my (%params) = @_; + my $testname = 'test_ap_payment_transaction'; + my $netamount = 115; + my $amount = $::form->round_amount($netamount * 1.19,2); + my $invoice = SL::DB::PurchaseInvoice->new( + invoice => 0, + invnumber => $params{invnumber} || $testname, + amount => $amount, + netamount => $netamount, + transdate => $transdate1, + taxincluded => 0, + vendor_id => $vendor->id, + taxzone_id => $vendor->taxzone_id, + currency_id => $currency_id, + transactions => [], + notes => $testname, + ); + $invoice->add_ap_amount_row( + amount => $invoice->netamount, + chart => $ap_amount_chart, + tax_id => $tax_9->id, + ); + + $invoice->create_ap_row(chart => $ap_chart); + $invoice->save; + + is($invoice->netamount, 115 , "$testname: netamount ok"); + is($invoice->amount , 136.85, "$testname: amount ok"); + + my $bt = SL::Dev::Payment::create_bank_transaction(record => $invoice, + amount => $invoice->amount, + bank_chart_id => $bank->id, + transdate => DateTime->today->add(days => 10), + ); + $::form->{invoice_ids} = { + $bt->id => [ $invoice->id ] + }; + + save_btcontroller_to_string(); + + $invoice->load; + $bt->load; + + is($invoice->amount , '136.85000', "$testname: amount ok"); + is($invoice->netamount, '115.00000', "$testname: netamount ok"); + is($bt->amount, '-136.85000', "$testname: bt amount ok"); + is($invoice->paid , '136.85000', "$testname: paid ok"); + is($bt->invoice_amount, '-136.85000', "$testname: bt invoice amount for ap was assigned"); + + return $invoice; +}; + +sub test_ap_payment_part_transaction { + my (%params) = @_; + my $testname = 'test_ap_payment_p_transaction'; + my $netamount = 115; + my $amount = $::form->round_amount($netamount * 1.19,2); + my $invoice = SL::DB::PurchaseInvoice->new( + invoice => 0, + invnumber => $params{invnumber} || $testname, + amount => $amount, + netamount => $netamount, + transdate => $transdate1, + taxincluded => 0, + vendor_id => $vendor->id, + taxzone_id => $vendor->taxzone_id, + currency_id => $currency_id, + transactions => [], + notes => $testname, + ); + $invoice->add_ap_amount_row( + amount => $invoice->netamount, + chart => $ap_amount_chart, + tax_id => $tax_9->id, + ); + + $invoice->create_ap_row(chart => $ap_chart); + $invoice->save; + + is($invoice->netamount, 115 , "$testname: netamount ok"); + is($invoice->amount , 136.85, "$testname: amount ok"); + + my $bt = SL::Dev::Payment::create_bank_transaction(record => $invoice, + amount => $invoice->amount-100, + bank_chart_id => $bank->id, + transdate => DateTime->today->add(days => 10), + ); + $::form->{invoice_ids} = { + $bt->id => [ $invoice->id ] + }; + + save_btcontroller_to_string(); + + $invoice->load; + $bt->load; + + is($invoice->amount , '136.85000', "$testname: amount ok"); + is($invoice->netamount, '115.00000', "$testname: netamount ok"); + is($bt->amount, '-36.85000', "$testname: bt amount ok"); + is($invoice->paid , '36.85000', "$testname: paid ok"); + is($bt->invoice_amount, '-36.85000', "$testname: bt invoice amount for ap was assigned"); + + my $bt2 = SL::Dev::Payment::create_bank_transaction(record => $invoice, + amount => 100, + bank_chart_id => $bank->id, + transdate => DateTime->today->add(days => 10), + ); + $::form->{invoice_ids} = { + $bt2->id => [ $invoice->id ] + }; + + save_btcontroller_to_string(); + $invoice->load; + $bt2->load; + + is($invoice->amount , '136.85000', "$testname: amount ok"); + is($invoice->netamount, '115.00000', "$testname: netamount ok"); + is($bt2->amount, '-100.00000',"$testname: bt amount ok"); + is($invoice->paid , '136.85000', "$testname: paid ok"); + is($bt2->invoice_amount,'-100.00000', "$testname: bt invoice amount for ap was assigned"); return $invoice; }; +sub test_neg_sales_invoice { + + my $testname = 'test_neg_sales_invoice'; + + my $part1 = SL::Dev::Part::create_part( partnumber => 'Funkenhaube öhm')->save; + my $part2 = SL::Dev::Part::create_service(partnumber => 'Service-Pauschale Pasch!')->save; + + my $neg_sales_inv = SL::Dev::Record::create_sales_invoice( + invnumber => '20172201', + customer => $customer, + taxincluded => 0, + invoiceitems => [ SL::Dev::Record::create_invoice_item(part => $part1, qty => 3, sellprice => 70), + SL::Dev::Record::create_invoice_item(part => $part2, qty => 10, sellprice => -50), + ] + ); + my $bt = SL::Dev::Payment::create_bank_transaction(record => $neg_sales_inv, + amount => $neg_sales_inv->amount, + bank_chart_id => $bank->id, + transdate => DateTime->today, + ); + $::form->{invoice_ids} = { + $bt->id => [ $neg_sales_inv->id ] + }; + + save_btcontroller_to_string(); + + $neg_sales_inv->load; + $bt->load; + is($neg_sales_inv->amount , '-345.10000', "$testname: amount ok"); + is($neg_sales_inv->netamount, '-290.00000', "$testname: netamount ok"); + is($neg_sales_inv->paid , '-345.10000', "$testname: paid ok"); + is($bt->amount , '-345.10000', "$testname: bt amount ok"); + is($bt->invoice_amount , '-345.10000', "$testname: bt invoice_amount ok"); +} + 1;