+sub test_two_neg_ap_transaction {
+ my $testname='test_two_neg_ap_transaction';
+ my $netamount = -20;
+ my $amount = $::form->round_amount($netamount * 1.19,2);
+ my $invoice = SL::DB::PurchaseInvoice->new(
+ invoice => 0,
+ 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,
+ chart => $ap_amount_chart,
+ tax_id => $tax_9->id,
+ );
+
+ $invoice->create_ap_row(chart => $ap_chart);
+ $invoice->save;
+
+ is($invoice->netamount, -20 , "$testname: netamount ok");
+ is($invoice->amount , -23.8, "$testname: amount ok");
+
+ my $netamount_two = -1.14;
+ my $amount_two = $::form->round_amount($netamount_two * 1.19,2);
+ my $invoice_two = SL::DB::PurchaseInvoice->new(
+ invoice => 0,
+ invnumber => 'test_neg_ap_transaction_two',
+ amount => $amount_two,
+ netamount => $netamount_two,
+ transdate => $transdate1,
+ taxincluded => 0,
+ vendor_id => $vendor->id,
+ taxzone_id => $vendor->taxzone_id,
+ currency_id => $currency_id,
+ transactions => [],
+ notes => 'test_neg_ap_transaction_two',
+ );
+ $invoice_two->add_ap_amount_row(
+ amount => $invoice_two->netamount,
+ chart => $ap_amount_chart,
+ tax_id => $tax_9->id,
+ );
+
+ $invoice_two->create_ap_row(chart => $ap_chart);
+ $invoice_two->save;
+
+ is($invoice_two->netamount, -1.14 , "$testname: netamount ok");
+ is($invoice_two->amount , -1.36, "$testname: amount ok");
+
+
+ my $bt = create_bank_transaction(record => $invoice_two,
+ amount => $invoice_two->amount + $invoice->amount,
+ bank_chart_id => $bank->id,
+ transdate => DateTime->today->add(days => 10),
+ );
+ # my ($agreement, $rule_matches) = $bt->get_agreement_with_invoice($invoice_two);
+ # is($agreement, 15, "points for negative ap transaction ok");
+
+ $::form->{invoice_ids} = {
+ $bt->id => [ $invoice->id, $invoice_two->id ]
+ };
+
+ save_btcontroller_to_string();
+
+ $invoice->load;
+ $invoice_two->load;
+ $bt->load;
+
+ is($invoice->amount , '-23.80000', "$testname: first inv amount ok");
+ is($invoice->netamount, '-20.00000', "$testname: first inv netamount ok");
+ is($invoice->paid , '-23.80000', "$testname: first inv paid ok");
+ is($invoice_two->amount , '-1.36000', "$testname: second inv amount ok");
+ is($invoice_two->netamount, '-1.14000', "$testname: second inv netamount ok");
+ is($invoice_two->paid , '-1.36000', "$testname: second inv paid ok");
+ is($bt->invoice_amount, '25.16000', "$testname: bt invoice amount for both invoices were assigned");
+
+
+ return ($invoice, $invoice_two);
+};