+sub test_bt_rule1 {
+
+ my $testname = 'test_bt_rule1';
+
+ $ar_transaction = test_ar_transaction(invnumber => 'bt_rule1');
+
+ my $bt = create_bank_transaction(record => $ar_transaction) or die "Couldn't create bank_transaction";
+
+ $ar_transaction->load;
+ $bt->load;
+ is($ar_transaction->paid , '0.00000' , "$testname: not paid");
+ is($bt->invoice_amount , '0.00000' , "$testname: bt invoice amount was not assigned");
+
+ my $bt_controller = SL::Controller::BankTransaction->new;
+ $::form->{dont_render_for_test} = 1;
+ $::form->{filter}{bank_account} = $bank_account->id;
+ my $bt_transactions = $bt_controller->action_list;
+
+ is(scalar(@$bt_transactions) , 1 , "$testname: one bank_transaction");
+ is($bt_transactions->[0]->{agreement}, 20 , "$testname: agreement == 20");
+ my $match = join ( ' ',@{$bt_transactions->[0]->{rule_matches}});
+ #print "rule_matches='".$match."'\n";
+ is($match,
+ "remote_account_number(3) exact_amount(4) own_invnumber_in_purpose(5) depositor_matches(2) remote_name(2) payment_within_30_days(1) datebonus0(3) ",
+ "$testname: rule_matches ok");
+ $bt->invoice_amount($bt->amount);
+ $bt->save;
+ is($bt->invoice_amount , '119.00000' , "$testname: bt invoice amount now set");
+};
+
+sub test_sepa_export {
+
+ my $testname = 'test_sepa_export';
+
+ $ar_transaction = test_ar_transaction(invnumber => 'sepa1');
+
+ my $bt = create_bank_transaction(record => $ar_transaction) or die "Couldn't create bank_transaction";
+ my $se = create_sepa_export();
+ my $sei = create_sepa_export_item(
+ chart_id => $bank->id,
+ ar_id => $ar_transaction->id,
+ sepa_export_id => $se->id,
+ vc_iban => $customer->iban,
+ vc_bic => $customer->bic,
+ vc_mandator_id => $customer->mandator_id,
+ vc_depositor => $customer->depositor,
+ amount => $ar_transaction->amount,
+ );
+ require SL::SEPA::XML;
+ my $sepa_xml = SL::SEPA::XML->new('company' => $customer->name,
+ 'creditor_id' => "id",
+ 'src_charset' => 'UTF-8',
+ 'message_id' => "test",
+ 'grouped' => 1,
+ 'collection' => 1,
+ );
+ is($sepa_xml->{company} , 'Test Customer OLE S.L. Ardbaerg AB');
+
+ $ar_transaction->load;
+ $bt->load;
+ $sei->load;
+ is($ar_transaction->paid , '0.00000' , "$testname: sepa1 not paid");
+ is($bt->invoice_amount , '0.00000' , "$testname: bt invoice amount was not assigned");
+ is($bt->amount , '119.00000' , "$testname: bt amount ok");
+ is($sei->amount , '119.00000' , "$testname: sepa export amount ok");
+
+ my $bt_controller = SL::Controller::BankTransaction->new;
+ $::form->{dont_render_for_test} = 1;
+ $::form->{filter}{bank_account} = $bank_account->id;
+ my $bt_transactions = $bt_controller->action_list;
+
+ is(scalar(@$bt_transactions) , 1 , "$testname: one bank_transaction");
+ is($bt_transactions->[0]->{agreement}, 25 , "$testname: agreement == 25");
+ my $match = join ( ' ',@{$bt_transactions->[0]->{rule_matches}});
+ is($match,
+ "remote_account_number(3) exact_amount(4) own_invnumber_in_purpose(5) depositor_matches(2) remote_name(2) payment_within_30_days(1) datebonus0(3) sepa_export_item(5) ",
+ "$testname: rule_matches ok");
+};
+
+