use Test::Exception;
use List::Util qw(sum);
-use SL::Dev::Record;
-use SL::Dev::CustomerVendor;
-use SL::Dev::Part;
+use SL::Dev::Record qw(create_invoice_item create_sales_invoice create_credit_note);
+use SL::Dev::CustomerVendor qw(new_customer new_vendor);
+use SL::Dev::Part qw(new_part);
use SL::DB::Buchungsgruppe;
use SL::DB::Currency;
use SL::DB::Exchangerate;
currency_id => $currency->id,
)->save;
- $customer = SL::Dev::CustomerVendor::create_customer(
+ $customer = new_customer(
name => 'Test Customer',
currency_id => $currency_id,
taxzone_id => $taxzone->id,
auto_calculation => 1,
)->save;
- $vendor = SL::Dev::CustomerVendor::create_vendor(
+ $vendor = new_vendor(
name => 'Test Vendor',
currency_id => $currency_id,
taxzone_id => $taxzone->id,
@parts = ();
- push @parts, SL::Dev::Part::create_part(
+ push @parts, new_part(
partnumber => 'T4254',
description => 'Fourty-two fifty-four',
lastcost => 1.93,
%{ $params{part1} }
)->save;
- push @parts, SL::Dev::Part::create_part(
+ push @parts, new_part(
partnumber => 'T0815',
description => 'Zero EIGHT fifteeN @ 7%',
lastcost => 5.473,
unit => $unit->name,
%{ $params{part2} }
)->save;
- push @parts, SL::Dev::Part::create_part(
+ push @parts, new_part(
partnumber => '19%',
description => 'Testware 19%',
lastcost => 0,
unit => $unit->name,
%{ $params{part3} }
)->save;
- push @parts, SL::Dev::Part::create_part(
+ push @parts, new_part(
partnumber => '7%',
description => 'Testware 7%',
lastcost => 0,
sub test_default_invoice_one_item_19_without_skonto() {
reset_state() if $ALWAYS_RESET;
- my $item = SL::Dev::Record::create_invoice_item(part => $parts[0], qty => 2.5);
- my $invoice = SL::Dev::Record::create_sales_invoice(
+ my $item = create_invoice_item(part => $parts[0], qty => 2.5);
+ my $invoice = create_sales_invoice(
taxincluded => 0,
invoiceitems => [ $item ],
payment_id => $payment_terms->id,
sub test_default_invoice_one_item_19_without_skonto_overpaid() {
reset_state() if $ALWAYS_RESET;
- my $item = SL::Dev::Record::create_invoice_item(part => $parts[0], qty => 2.5);
- my $invoice = SL::Dev::Record::create_sales_invoice(
+ my $item = create_invoice_item(part => $parts[0], qty => 2.5);
+ my $invoice = create_sales_invoice(
taxincluded => 0,
invoiceitems => [ $item ],
payment_id => $payment_terms->id,
sub test_default_invoice_two_items_19_7_tax_with_skonto() {
reset_state() if $ALWAYS_RESET;
- my $item1 = SL::Dev::Record::create_invoice_item(part => $parts[0], qty => 2.5);
- my $item2 = SL::Dev::Record::create_invoice_item(part => $parts[1], qty => 1.2);
- my $invoice = SL::Dev::Record::create_sales_invoice(
+ my $item1 = create_invoice_item(part => $parts[0], qty => 2.5);
+ my $item2 = create_invoice_item(part => $parts[1], qty => 1.2);
+ my $invoice = create_sales_invoice(
taxincluded => 0,
invoiceitems => [ $item1, $item2 ],
payment_id => $payment_terms->id,
sub test_default_invoice_two_items_19_7_tax_with_skonto_tax_included() {
reset_state() if $ALWAYS_RESET;
- my $item1 = SL::Dev::Record::create_invoice_item(part => $parts[0], qty => 2.5);
- my $item2 = SL::Dev::Record::create_invoice_item(part => $parts[1], qty => 1.2);
- my $invoice = SL::Dev::Record::create_sales_invoice(
+ my $item1 = create_invoice_item(part => $parts[0], qty => 2.5);
+ my $item2 = create_invoice_item(part => $parts[1], qty => 1.2);
+ my $invoice = create_sales_invoice(
taxincluded => 1,
invoiceitems => [ $item1, $item2 ],
payment_id => $payment_terms->id,
sub test_default_invoice_two_items_19_7_without_skonto() {
reset_state() if $ALWAYS_RESET;
- my $item1 = SL::Dev::Record::create_invoice_item(part => $parts[0], qty => 2.5);
- my $item2 = SL::Dev::Record::create_invoice_item(part => $parts[1], qty => 1.2);
- my $invoice = SL::Dev::Record::create_sales_invoice(
+ my $item1 = create_invoice_item(part => $parts[0], qty => 2.5);
+ my $item2 = create_invoice_item(part => $parts[1], qty => 1.2);
+ my $invoice = create_sales_invoice(
taxincluded => 0,
invoiceitems => [ $item1, $item2 ],
payment_id => $payment_terms->id,
sub test_default_invoice_two_items_19_7_without_skonto_incomplete_payment() {
reset_state() if $ALWAYS_RESET;
- my $item1 = SL::Dev::Record::create_invoice_item(part => $parts[0], qty => 2.5);
- my $item2 = SL::Dev::Record::create_invoice_item(part => $parts[1], qty => 1.2);
- my $invoice = SL::Dev::Record::create_sales_invoice(
+ my $item1 = create_invoice_item(part => $parts[0], qty => 2.5);
+ my $item2 = create_invoice_item(part => $parts[1], qty => 1.2);
+ my $invoice = create_sales_invoice(
taxincluded => 0,
invoiceitems => [ $item1, $item2 ],
payment_id => $payment_terms->id,
sub test_default_invoice_two_items_19_7_tax_without_skonto_multiple_payments() {
reset_state() if $ALWAYS_RESET;
- my $item1 = SL::Dev::Record::create_invoice_item(part => $parts[0], qty => 2.5);
- my $item2 = SL::Dev::Record::create_invoice_item(part => $parts[1], qty => 1.2);
- my $invoice = SL::Dev::Record::create_sales_invoice(
+ my $item1 = create_invoice_item(part => $parts[0], qty => 2.5);
+ my $item2 = create_invoice_item(part => $parts[1], qty => 1.2);
+ my $invoice = create_sales_invoice(
taxincluded => 0,
invoiceitems => [ $item1, $item2 ],
payment_id => $payment_terms->id,
sub test_default_invoice_two_items_19_7_tax_without_skonto_multiple_payments_final_difference_as_skonto() {
reset_state() if $ALWAYS_RESET;
- my $item1 = SL::Dev::Record::create_invoice_item(part => $parts[0], qty => 2.5);
- my $item2 = SL::Dev::Record::create_invoice_item(part => $parts[1], qty => 1.2);
- my $invoice = SL::Dev::Record::create_sales_invoice(
+ my $item1 = create_invoice_item(part => $parts[0], qty => 2.5);
+ my $item2 = create_invoice_item(part => $parts[1], qty => 1.2);
+ my $invoice = create_sales_invoice(
taxincluded => 0,
invoiceitems => [ $item1, $item2 ],
payment_id => $payment_terms->id,
# (11.66) rather than the 19% account (5.85). The actual tax amount is
# higher for the 19% case, though (1.11 compared to 0.82)
- my $item1 = SL::Dev::Record::create_invoice_item(part => $parts[0], qty => 2.5);
- my $item2 = SL::Dev::Record::create_invoice_item(part => $parts[1], qty => 1.2);
- my $invoice = SL::Dev::Record::create_sales_invoice(
+ my $item1 = create_invoice_item(part => $parts[0], qty => 2.5);
+ my $item2 = create_invoice_item(part => $parts[1], qty => 1.2);
+ my $invoice = create_sales_invoice(
taxincluded => 0,
invoiceitems => [ $item1, $item2 ],
payment_id => $payment_terms->id,
reset_state() if $ALWAYS_RESET;
# if there are two cents left there will be two skonto bookings, 1 cent each
- my $item1 = SL::Dev::Record::create_invoice_item(part => $parts[0], qty => 2.5);
- my $item2 = SL::Dev::Record::create_invoice_item(part => $parts[1], qty => 1.2);
- my $invoice = SL::Dev::Record::create_sales_invoice(
+ my $item1 = create_invoice_item(part => $parts[0], qty => 2.5);
+ my $item2 = create_invoice_item(part => $parts[1], qty => 1.2);
+ my $invoice = create_sales_invoice(
taxincluded => 0,
invoiceitems => [ $item1, $item2 ],
payment_id => $payment_terms->id,
sub test_default_invoice_one_item_19_multiple_payment_final_difference_as_skonto() {
reset_state() if $ALWAYS_RESET;
- my $item = SL::Dev::Record::create_invoice_item(part => $parts[0], qty => 2.5);
- my $invoice = SL::Dev::Record::create_sales_invoice(
+ my $item = create_invoice_item(part => $parts[0], qty => 2.5);
+ my $invoice = create_sales_invoice(
taxincluded => 0,
invoiceitems => [ $item ],
payment_id => $payment_terms->id,
sub test_default_invoice_one_item_19_multiple_payment_final_difference_as_skonto_1cent() {
reset_state() if $ALWAYS_RESET;
- my $item = SL::Dev::Record::create_invoice_item(part => $parts[0], qty => 2.5);
- my $invoice = SL::Dev::Record::create_sales_invoice(
+ my $item = create_invoice_item(part => $parts[0], qty => 2.5);
+ my $invoice = create_sales_invoice(
taxincluded => 0,
invoiceitems => [ $item ],
payment_id => $payment_terms->id,
sub test_default_invoice_two_items_19_7_tax_with_skonto_50_50() {
reset_state() if $ALWAYS_RESET;
- my $item1 = SL::Dev::Record::create_invoice_item(part => $parts[2], qty => 1);
- my $item2 = SL::Dev::Record::create_invoice_item(part => $parts[3], qty => 1);
- my $invoice = SL::Dev::Record::create_sales_invoice(
+ my $item1 = create_invoice_item(part => $parts[2], qty => 1);
+ my $item2 = create_invoice_item(part => $parts[3], qty => 1);
+ my $invoice = create_sales_invoice(
taxincluded => 0,
invoiceitems => [ $item1, $item2 ],
payment_id => $payment_terms->id,
sub test_default_invoice_four_items_19_7_tax_with_skonto_4x_25() {
reset_state() if $ALWAYS_RESET;
- my $item1 = SL::Dev::Record::create_invoice_item(part => $parts[2], qty => 0.5);
- my $item2 = SL::Dev::Record::create_invoice_item(part => $parts[3], qty => 0.5);
- my $item3 = SL::Dev::Record::create_invoice_item(part => $parts[2], qty => 0.5);
- my $item4 = SL::Dev::Record::create_invoice_item(part => $parts[3], qty => 0.5);
- my $invoice = SL::Dev::Record::create_sales_invoice(
+ my $item1 = create_invoice_item(part => $parts[2], qty => 0.5);
+ my $item2 = create_invoice_item(part => $parts[3], qty => 0.5);
+ my $item3 = create_invoice_item(part => $parts[2], qty => 0.5);
+ my $item4 = create_invoice_item(part => $parts[3], qty => 0.5);
+ my $invoice = create_sales_invoice(
taxincluded => 0,
invoiceitems => [ $item1, $item2, $item3, $item4 ],
payment_id => $payment_terms->id,
sub test_default_invoice_four_items_19_7_tax_with_skonto_4x_25_tax_included() {
reset_state() if $ALWAYS_RESET;
- my $item1 = SL::Dev::Record::create_invoice_item(part => $parts[2], qty => 0.5);
- my $item2 = SL::Dev::Record::create_invoice_item(part => $parts[3], qty => 0.5);
- my $item3 = SL::Dev::Record::create_invoice_item(part => $parts[2], qty => 0.5);
- my $item4 = SL::Dev::Record::create_invoice_item(part => $parts[3], qty => 0.5);
- my $invoice = SL::Dev::Record::create_sales_invoice(
+ my $item1 = create_invoice_item(part => $parts[2], qty => 0.5);
+ my $item2 = create_invoice_item(part => $parts[3], qty => 0.5);
+ my $item3 = create_invoice_item(part => $parts[2], qty => 0.5);
+ my $item4 = create_invoice_item(part => $parts[3], qty => 0.5);
+ my $invoice = create_sales_invoice(
taxincluded => 1,
invoiceitems => [ $item1, $item2, $item3, $item4 ],
payment_id => $payment_terms->id,
sub test_default_invoice_four_items_19_7_tax_with_skonto_4x_25_multiple() {
reset_state() if $ALWAYS_RESET;
- my $item1 = SL::Dev::Record::create_invoice_item(part => $parts[2], qty => 0.5);
- my $item2 = SL::Dev::Record::create_invoice_item(part => $parts[3], qty => 0.5);
- my $item3 = SL::Dev::Record::create_invoice_item(part => $parts[2], qty => 0.5);
- my $item4 = SL::Dev::Record::create_invoice_item(part => $parts[3], qty => 0.5);
- my $invoice = SL::Dev::Record::create_sales_invoice(
+ my $item1 = create_invoice_item(part => $parts[2], qty => 0.5);
+ my $item2 = create_invoice_item(part => $parts[3], qty => 0.5);
+ my $item3 = create_invoice_item(part => $parts[2], qty => 0.5);
+ my $item4 = create_invoice_item(part => $parts[3], qty => 0.5);
+ my $invoice = create_sales_invoice(
taxincluded => 0,
invoiceitems => [ $item1, $item2, $item3, $item4 ],
payment_id => $payment_terms->id,
is(total_amount($invoice), 0, "$title: even balance");
};
+sub test_credit_note_two_items_19_7_tax_tax_not_included() {
+ reset_state() if $ALWAYS_RESET;
+
+ my $item1 = create_invoice_item(part => $parts[0], qty => 5);
+ my $item2 = create_invoice_item(part => $parts[1], qty => 3);
+ my $invoice = create_credit_note(
+ invnumber => 'cn1',
+ taxincluded => 0,
+ invoiceitems => [ $item1, $item2 ],
+ );
+
+ # default values
+ my %params = ( chart_id => $bank_account->chart_id,
+ transdate => DateTime->today_local->to_kivitendo,
+ );
+
+ $params{amount} = $invoice->amount,
+
+ $invoice->pay_invoice( %params );
+
+ my ($number_of_payments, $paid_amount) = number_of_payments($invoice);
+ my $total = total_amount($invoice);
+
+ my $title = 'credit_note, two items, 19/7%, tax not included';
+
+ is($invoice->netamount, -40.84, "${title}: netamount");
+ is($invoice->amount, -45.10, "${title}: amount");
+ is($paid_amount, 45.10, "${title}: paid amount according to acc_trans is positive (Haben)");
+ is($invoice->paid, -45.10, "${title}: paid");
+ is($number_of_payments, 1, "${title}: 1 AR_paid bookings");
+ is($total, 0, "${title}: even balance");
+}
+
Support::TestSetup::login();
# test cases: without_skonto
test_default_purchase_invoice_two_charts_19_7_without_skonto();
test_default_purchase_invoice_two_charts_19_7_tax_partial_unrounded_payment_without_skonto();
test_default_invoice_one_item_19_without_skonto_overpaid();
+test_credit_note_two_items_19_7_tax_tax_not_included();
# test cases: difference_as_skonto
test_default_invoice_two_items_19_7_tax_without_skonto_multiple_payments_final_difference_as_skonto();