X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/b8741ec3f7f9723d1226fcdee60635ccb992f41e..b6f37661d8b244fb55f27f9d77cfab6ed6a165e6:/t/bank/bank_transactions.t diff --git a/t/bank/bank_transactions.t b/t/bank/bank_transactions.t index f36c35595..687a64636 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 => 100; use strict; @@ -66,13 +66,17 @@ 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(); # remove all created data at end of test clear_up(); @@ -117,6 +121,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 +135,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,20 +186,22 @@ 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', - amount => $amount, - netamount => $netamount, - transdate => $transdate1, - taxincluded => 0, - vendor_id => $vendor->id, - taxzone_id => $vendor->taxzone_id, - currency_id => $currency_id, - transactions => [], - notes => 'test_ap_transaction', + 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 => 'test_ap_transaction', ); $invoice->add_ap_amount_row( amount => $invoice->netamount, @@ -204,10 +212,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'); @@ -226,8 +234,8 @@ sub test1 { my $bt = SL::Dev::Payment::create_bank_transaction(record => $ar_transaction) or die "Couldn't create bank_transaction"; $::form->{invoice_ids} = { - $bt->id => [ $ar_transaction->id ] - }; + $bt->id => [ $ar_transaction->id ] + }; save_btcontroller_to_string(); @@ -253,11 +261,11 @@ sub test_skonto_exact { ) or die "Couldn't create bank_transaction"; $::form->{invoice_ids} = { - $bt->id => [ $ar_transaction->id ] - }; + $bt->id => [ $ar_transaction->id ] + }; $::form->{invoice_skontos} = { - $bt->id => [ 'with_skonto_pt' ] - }; + $bt->id => [ 'with_skonto_pt' ] + }; save_btcontroller_to_string(); @@ -286,8 +294,8 @@ sub test_two_invoices { is($agreement, 16, "points for ar_transaction_1 in test_two_invoices ok"); $::form->{invoice_ids} = { - $bt->id => [ $ar_transaction_1->id, $ar_transaction_2->id ] - }; + $bt->id => [ $ar_transaction_1->id, $ar_transaction_2->id ] + }; save_btcontroller_to_string(); @@ -316,8 +324,8 @@ sub test_overpayment { ) or die "Couldn't create bank_transaction"; $::form->{invoice_ids} = { - $bt->id => [ $ar_transaction->id ] - }; + $bt->id => [ $ar_transaction->id ] + }; save_btcontroller_to_string(); @@ -351,13 +359,13 @@ sub test_overpayment_with_partialpayment { ) or die "Couldn't create bank_transaction"; $::form->{invoice_ids} = { - $bt_1->id => [ $ar_transaction->id ] - }; + $bt_1->id => [ $ar_transaction->id ] + }; save_btcontroller_to_string(); $::form->{invoice_ids} = { - $bt_2->id => [ $ar_transaction->id ] - }; + $bt_2->id => [ $ar_transaction->id ] + }; save_btcontroller_to_string(); $ar_transaction->load; @@ -383,8 +391,8 @@ sub test_partial_payment { ) or die "Couldn't create bank_transaction"; $::form->{invoice_ids} = { - $bt->id => [ $ar_transaction->id ] - }; + $bt->id => [ $ar_transaction->id ] + }; save_btcontroller_to_string(); @@ -420,7 +428,7 @@ sub test_credit_note { is($rule_matches, 'remote_account_number(3) exact_amount(4) wrong_sign(-1) depositor_matches(2) remote_name(2) payment_within_30_days(1) datebonus14(2) ', "rules_matches for credit note ok"); $::form->{invoice_ids} = { - $bt->id => [ $credit_note->id ] + $bt->id => [ $credit_note->id ] }; save_btcontroller_to_string(); @@ -438,17 +446,17 @@ sub test_neg_ap_transaction { my $netamount = -20; my $amount = $::form->round_amount($netamount * 1.19,2); my $invoice = SL::DB::PurchaseInvoice->new( - invoice => 0, - invnumber => $params{invnumber} || 'test_neg_ap_transaction', - amount => $amount, - netamount => $netamount, - transdate => $transdate1, - taxincluded => 0, - vendor_id => $vendor->id, - taxzone_id => $vendor->taxzone_id, - currency_id => $currency_id, - transactions => [], - notes => 'test_neg_ap_transaction', + invoice => 0, + invnumber => $params{invnumber} || 'test_neg_ap_transaction', + amount => $amount, + netamount => $netamount, + transdate => $transdate1, + taxincluded => 0, + vendor_id => $vendor->id, + taxzone_id => $vendor->taxzone_id, + currency_id => $currency_id, + transactions => [], + notes => 'test_neg_ap_transaction', ); $invoice->add_ap_amount_row( amount => $invoice->netamount, @@ -459,8 +467,8 @@ sub test_neg_ap_transaction { $invoice->create_ap_row(chart => $ap_chart); $invoice->save; - is($invoice->netamount , -20 , "$testname: netamount ok"); - is($invoice->amount , -23.8 , "$testname: amount ok"); + is($invoice->netamount, -20 , "$testname: netamount ok"); + is($invoice->amount , -23.8, "$testname: amount ok"); my $bt = SL::Dev::Payment::create_bank_transaction(record => $invoice, amount => $invoice->amount, @@ -471,19 +479,145 @@ sub test_neg_ap_transaction { is($agreement, 15, "points for negative ap transaction ok"); $::form->{invoice_ids} = { - $bt->id => [ $invoice->id ] + $bt->id => [ $invoice->id ] }; 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; +}; 1;